_Dispatch_type_(IRP_MJ_CLOSE)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
device_extension* Vcb = DeviceObject->DeviceExtension;
_Dispatch_type_(IRP_MJ_FLUSH_BUFFERS)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
PFILE_OBJECT FileObject = IrpSp->FileObject;
_Dispatch_type_(IRP_MJ_QUERY_VOLUME_INFORMATION)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
ULONG BytesCopied = 0;
_Dispatch_type_(IRP_MJ_SET_VOLUME_INFORMATION)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
device_extension* Vcb = DeviceObject->DeviceExtension;
NTSTATUS Status;
_Dispatch_type_(IRP_MJ_CLEANUP)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = IrpSp->FileObject;
goto exit;
}
+ /* HACK: stream file object seems to get deleted at some point
+ * leading to use after free when installing ReactOS on
+ * BtrFS.
+ * Workaround: leak a handle to the fileobject
+ * XXX: Could be improved by storing it somewhere and releasing it
+ * on dismount. Or even by referencing again the file object.
+ */
+#ifndef __REACTOS__
Vcb->root_file = IoCreateStreamFileObject(NULL, DeviceToMount);
+#else
+ {
+ HANDLE Dummy;
+ Vcb->root_file = IoCreateStreamFileObjectEx(NULL, DeviceToMount, &Dummy);
+ }
+#endif
Vcb->root_file->FsContext = root_fcb;
Vcb->root_file->SectionObjectPointer = &root_fcb->nonpaged->segment_object;
Vcb->root_file->Vpb = DeviceObject->Vpb;
_Dispatch_type_(IRP_MJ_FILE_SYSTEM_CONTROL)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_file_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_file_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
device_extension* Vcb = DeviceObject->DeviceExtension;
_Dispatch_type_(IRP_MJ_LOCK_CONTROL)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_lock_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_lock_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
fcb* fcb = IrpSp->FileObject->FsContext;
_Dispatch_type_(IRP_MJ_SHUTDOWN)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
BOOL top_level;
device_extension* Vcb = DeviceObject->DeviceExtension;
+#ifdef __REACTOS__
+ LIST_ENTRY *Vcble, *le;
+#endif
FsRtlEnterFileSystem();
shutting_down = TRUE;
KeSetEvent(&mountmgr_thread_event, 0, FALSE);
+#ifndef __REACTOS__
while (!IsListEmpty(&VcbList)) {
Vcb = CONTAINING_RECORD(VcbList.Flink, device_extension, list_entry);
uninit(Vcb, TRUE);
}
+#else
+ Vcble = VcbList.Flink;
+ while (Vcble != &VcbList) {
+ Vcb = CONTAINING_RECORD(Vcble, device_extension, list_entry);
+
+ TRACE("shutting down Vcb %p\n", Vcb);
+
+ if (Vcb->balance.thread) {
+ Vcb->balance.paused = FALSE;
+ Vcb->balance.stopping = TRUE;
+ KeSetEvent(&Vcb->balance.event, 0, FALSE);
+ KeWaitForSingleObject(&Vcb->balance.finished, Executive, KernelMode, FALSE, NULL);
+ }
+
+ if (Vcb->scrub.thread) {
+ Vcb->scrub.paused = FALSE;
+ Vcb->scrub.stopping = TRUE;
+ KeSetEvent(&Vcb->scrub.event, 0, FALSE);
+ KeWaitForSingleObject(&Vcb->scrub.finished, Executive, KernelMode, FALSE, NULL);
+ }
+
+ if (Vcb->running_sends != 0) {
+ BOOL send_cancelled = FALSE;
+
+ ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);
+
+ le = Vcb->send_ops.Flink;
+ while (le != &Vcb->send_ops) {
+ send_info* send = CONTAINING_RECORD(le, send_info, list_entry);
+
+ if (!send->cancelling) {
+ send->cancelling = TRUE;
+ send_cancelled = TRUE;
+ send->ccb = NULL;
+ KeSetEvent(&send->cleared_event, 0, FALSE);
+ }
+
+ le = le->Flink;
+ }
+
+ ExReleaseResourceLite(&Vcb->send_load_lock);
+
+ if (send_cancelled) {
+ while (Vcb->running_sends != 0) {
+ ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);
+ ExReleaseResourceLite(&Vcb->send_load_lock);
+ }
+ }
+ }
+
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+
+ if (Vcb->need_write && !Vcb->readonly) {
+ Status = do_write(Vcb, Irp);
+
+ if (!NT_SUCCESS(Status))
+ ERR("do_write returned %08x\n", Status);
+ }
+
+ Vcb->removing = TRUE;
+
+ ExReleaseResourceLite(&Vcb->tree_lock);
+ Vcble = Vcble->Flink;
+ }
+#endif
#ifdef _DEBUG
if (comfo) {
_Dispatch_type_(IRP_MJ_POWER)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_power(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_power(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
device_extension* Vcb = DeviceObject->DeviceExtension;
BOOL top_level;
_Dispatch_type_(IRP_MJ_SYSTEM_CONTROL)
_Function_class_(DRIVER_DISPATCH)
+#ifdef __REACTOS__
+static NTSTATUS NTAPI drv_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#else
static NTSTATUS drv_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
+#endif
NTSTATUS Status;
device_extension* Vcb = DeviceObject->DeviceExtension;
BOOL top_level;
DriverObject->DriverExtension->AddDevice = AddDevice;
+#ifdef __REACTOS__
+ DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
+ DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
+ DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
+ DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
+ DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
+ DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
+ DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
+ DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
+ DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
+ DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
+ DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
+ DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
+ DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
+ DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
+ DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
+ DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
+ DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
+ DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
+ DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
+ DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
+ DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
+ DriverObject->MajorFunction[IRP_MJ_PNP] = drv_pnp;
+#else
DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)drv_create;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)drv_close;
DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)drv_read;
DriverObject->MajorFunction[IRP_MJ_POWER] = (PDRIVER_DISPATCH)drv_power;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)drv_system_control;
DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH)drv_pnp;
+#endif
init_fast_io_dispatch(&DriverObject->FastIoDispatch);