From a910385cb19b406ec1c3cc51f80697d1787ee8b8 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 13 Nov 2018 10:11:39 -0800 Subject: [PATCH 1/2] dll: ensure FspFileSystemFinalize is called --- src/dll/library.c | 1 + src/dll/library.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/dll/library.c b/src/dll/library.c index 4d755b1c..69bd91ae 100644 --- a/src/dll/library.c +++ b/src/dll/library.c @@ -46,6 +46,7 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved) Dynamic = 0 == Reserved; fsp_fuse_finalize(Dynamic); FspServiceFinalize(Dynamic); + FspFileSystemFinalize(Dynamic); FspEventLogFinalize(Dynamic); FspPosixFinalize(Dynamic); FspWksidFinalize(Dynamic); diff --git a/src/dll/library.h b/src/dll/library.h index 66018d72..0c86ded7 100644 --- a/src/dll/library.h +++ b/src/dll/library.h @@ -47,6 +47,7 @@ VOID FspWksidFinalize(BOOLEAN Dynamic); VOID FspPosixFinalize(BOOLEAN Dynamic); VOID FspEventLogFinalize(BOOLEAN Dynamic); +VOID FspFileSystemFinalize(BOOLEAN Dynamic); VOID FspServiceFinalize(BOOLEAN Dynamic); VOID fsp_fuse_finalize(BOOLEAN Dynamic); VOID fsp_fuse_finalize_thread(VOID); From 5d90c35e2083bd1cc3753166ef6301dfdfe983cf Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Wed, 21 Nov 2018 15:32:25 -0800 Subject: [PATCH 2/2] sys: FspFsvrtDeviceControl: STATUS_UNRECOGNIZED_VOLUME This fixes GitHub issue #177. All credit for the investigation and suggested workaround goes to @thinkport. --- src/sys/devctl.c | 27 +++++++++++++++++++++++++++ src/sys/driver.c | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/sys/devctl.c b/src/sys/devctl.c index 14de171c..d6d24568 100644 --- a/src/sys/devctl.c +++ b/src/sys/devctl.c @@ -21,6 +21,8 @@ #include +static NTSTATUS FspFsvrtDeviceControl( + PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp); static NTSTATUS FspFsvolDeviceControl( PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp); FSP_IOCMPL_DISPATCH FspFsvolDeviceControlComplete; @@ -28,6 +30,7 @@ static FSP_IOP_REQUEST_FINI FspFsvolDeviceControlRequestFini; FSP_DRIVER_DISPATCH FspDeviceControl; #ifdef ALLOC_PRAGMA +#pragma alloc_text(PAGE, FspFsvrtDeviceControl) #pragma alloc_text(PAGE, FspFsvolDeviceControl) #pragma alloc_text(PAGE, FspFsvolDeviceControlComplete) #pragma alloc_text(PAGE, FspFsvolDeviceControlRequestFini) @@ -39,6 +42,28 @@ enum RequestFileNode = 0, }; +static NTSTATUS FspFsvrtDeviceControl( + PDEVICE_OBJECT FsvolDeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp) +{ + PAGED_CODE(); + + /* + * Fix GitHub issue #177. All credit for the investigation of this issue + * and the suggested steps to reproduce and work around the problem goes + * to GitHub user @thinkport. + * + * When Windows attempts to mount a new volume it iterates over all disk file + * systems registered with IoRegisterFileSystem. Foreign (i.e. non-WinFsp) file + * systems would in some cases attempt to mount our Fsvrt volume device by + * sending it unknown IOCTL codes, which would then be failed with + * STATUS_INVALID_DEVICE_REQUEST. Unfortunately the file systems would then + * report this error code to the I/O Manager, which would cause it to abort the + * mounting process completely and thus WinFsp would never get a chance to + * mount its own volume device! + */ + return STATUS_UNRECOGNIZED_VOLUME; +} + static NTSTATUS FspFsvolDeviceControl( PDEVICE_OBJECT FsvolDeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp) { @@ -155,6 +180,8 @@ NTSTATUS FspDeviceControl( { case FspFsvolDeviceExtensionKind: FSP_RETURN(Result = FspFsvolDeviceControl(DeviceObject, Irp, IrpSp)); + case FspFsvrtDeviceExtensionKind: + FSP_RETURN(Result = FspFsvrtDeviceControl(DeviceObject, Irp, IrpSp)); default: FSP_RETURN(Result = STATUS_INVALID_DEVICE_REQUEST); } diff --git a/src/sys/driver.c b/src/sys/driver.c index ffab176f..558b93ae 100644 --- a/src/sys/driver.c +++ b/src/sys/driver.c @@ -169,6 +169,21 @@ NTSTATUS DriverEntry( &FspFsmupDeviceObject); if (!NT_SUCCESS(Result)) goto exit; + +#if DBG + /* + * Fix GitHub issue #177. All credit for the investigation of this issue + * and the suggested steps to reproduce and work around the problem goes + * to GitHub user @thinkport. + * + * On debug builds set DO_LOW_PRIORITY_FILESYSTEM to place the file system + * at the end of the file system list during IoRegisterFileSystem below. + * This allows us to test the behavior of our Fsvrt devices when foreign + * file systems attempt to use them for mounting. + */ + SetFlag(FspFsctlDiskDeviceObject->Flags, DO_LOW_PRIORITY_FILESYSTEM); +#endif + Result = FspDeviceInitialize(FspFsctlDiskDeviceObject); ASSERT(STATUS_SUCCESS == Result); Result = FspDeviceInitialize(FspFsctlNetDeviceObject);