From 93be122c9111496aea543c97049578f99144ad0d Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 20 Nov 2015 23:39:20 -0800 Subject: [PATCH] sys: decide on device hierarchy: fsctl, fsvrt, fsvol --- src/sys/cleanup.c | 2 +- src/sys/close.c | 2 +- src/sys/create.c | 2 +- src/sys/driver.c | 39 +++++++++++++++++++++++++-------------- src/sys/driver.h | 28 ++++++++++++++++++++-------- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/sys/cleanup.c b/src/sys/cleanup.c index 367cf373..97a591b0 100644 --- a/src/sys/cleanup.c +++ b/src/sys/cleanup.c @@ -21,7 +21,7 @@ FspCleanup( ASSERT(IRP_MJ_CLEANUP == IrpSp->MajorFunction); - if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) + if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) FSP_RETURN(Irp->IoStatus.Information = 0); Result = STATUS_INVALID_DEVICE_REQUEST; diff --git a/src/sys/close.c b/src/sys/close.c index 6a4ffb0a..94cec7e8 100644 --- a/src/sys/close.c +++ b/src/sys/close.c @@ -21,7 +21,7 @@ FspClose( ASSERT(IRP_MJ_CLOSE == IrpSp->MajorFunction); - if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) + if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) FSP_RETURN(Irp->IoStatus.Information = 0); Result = STATUS_INVALID_DEVICE_REQUEST; diff --git a/src/sys/create.c b/src/sys/create.c index a29ae47a..bcab9c25 100644 --- a/src/sys/create.c +++ b/src/sys/create.c @@ -21,7 +21,7 @@ FspCreate( ASSERT(IRP_MJ_CREATE == IrpSp->MajorFunction); - if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) + if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) FSP_RETURN(Irp->IoStatus.Information = FILE_OPENED); Result = STATUS_INVALID_DEVICE_REQUEST; diff --git a/src/sys/driver.c b/src/sys/driver.c index b93ed91e..dc8f2471 100644 --- a/src/sys/driver.c +++ b/src/sys/driver.c @@ -21,15 +21,22 @@ DriverEntry( { FSP_ENTER(); - /* create the file system device object */ + /* create the file system control device objects */ UNICODE_STRING DeviceName; - RtlInitUnicodeString(&DeviceName, L"\\Device\\" DEVICE_NAME); + RtlInitUnicodeString(&DeviceName, L"\\Device\\" DISK_DEVICE_NAME); Result = IoCreateDevice(DriverObject, - sizeof(FSP_FILE_SYSTEM_DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_FILE_SYSTEM, 0, FALSE, - &FspFileSystemDeviceObject); + sizeof(FSP_FSCTL_DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_DISK_FILE_SYSTEM, 0, FALSE, + &FspFsctlDiskDeviceObject); if (!NT_SUCCESS(Result)) FSP_RETURN(); - FspDeviceExtension(FspFileSystemDeviceObject)->Kind = FspFileSystemDeviceExtensionKind; + RtlInitUnicodeString(&DeviceName, L"\\Device\\" NET_DEVICE_NAME); + Result = IoCreateDevice(DriverObject, + sizeof(FSP_FSCTL_DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_NETWORK_FILE_SYSTEM, 0, FALSE, + &FspFsctlNetDeviceObject); + if (!NT_SUCCESS(Result)) + FSP_RETURN(IoDeleteDevice(FspFsctlDiskDeviceObject)); + FspDeviceExtension(FspFsctlDiskDeviceObject)->Kind = FspFsctlDeviceExtensionKind; + FspDeviceExtension(FspFsctlNetDeviceObject)->Kind = FspFsctlDeviceExtensionKind; /* setup the driver object */ DriverObject->DriverUnload = FspUnload; @@ -94,11 +101,9 @@ DriverEntry( FspFastIoDispatch.ReleaseForCcFlush = FspReleaseForCcFlush; DriverObject->FastIoDispatch = &FspFastIoDispatch; - /* - * Register as a file system; this informs all filter drivers. - * Future drivers will *not* be informed because we are a FILE_DEVICE_FILE_SYSTEM! - */ - IoRegisterFileSystem(FspFileSystemDeviceObject); + /* register our device objects as file systems */ + IoRegisterFileSystem(FspFsctlDiskDeviceObject); + IoRegisterFileSystem(FspFsctlNetDeviceObject); FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"", &DriverObject->DriverName, RegistryPath); @@ -110,14 +115,20 @@ FspUnload( { FSP_ENTER_VOID(PAGED_CODE()); - if (0 != FspFileSystemDeviceObject) + if (0 != FspFsctlDiskDeviceObject) { - IoDeleteDevice(FspFileSystemDeviceObject); - FspFileSystemDeviceObject = 0; + IoDeleteDevice(FspFsctlDiskDeviceObject); + FspFsctlDiskDeviceObject = 0; + } + if (0 != FspFsctlNetDeviceObject) + { + IoDeleteDevice(FspFsctlNetDeviceObject); + FspFsctlNetDeviceObject = 0; } FSP_LEAVE_VOID("DriverName=\"%wZ\"", &DriverObject->DriverName); } -PDEVICE_OBJECT FspFileSystemDeviceObject; +PDEVICE_OBJECT FspFsctlDiskDeviceObject; +PDEVICE_OBJECT FspFsctlNetDeviceObject; diff --git a/src/sys/driver.h b/src/sys/driver.h index 724ae4a4..e275b656 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -10,7 +10,8 @@ #include #define DRIVER_NAME "WinFsp" -#define DEVICE_NAME "WinFsp" +#define DISK_DEVICE_NAME "WinFsp.Disk" +#define NET_DEVICE_NAME "WinFsp.Net" /* DEBUGLOG */ #if DBG @@ -100,8 +101,9 @@ /* types */ enum { - FspFileSystemDeviceExtensionKind = 'F', - FspVolumeDeviceExtensionKind = 'V', + FspFsctlDeviceExtensionKind = 'C', /* file system control device (e.g. \Device\WinFsp.Disk) */ + FspFsvrtDeviceExtensionKind = 'V', /* virtual volume device (e.g. \Device\Volume{GUID}) */ + FspFsvolDeviceExtensionKind = 'F', /* file system volume device (unnamed) */ }; typedef struct { @@ -110,23 +112,32 @@ typedef struct typedef struct { FSP_DEVICE_EXTENSION Base; -} FSP_FILE_SYSTEM_DEVICE_EXTENSION; +} FSP_FSCTL_DEVICE_EXTENSION; typedef struct { FSP_DEVICE_EXTENSION Base; -} FSP_VOLUME_DEVICE_EXTENSION; +} FSP_FSVRT_DEVICE_EXTENSION; +typedef struct +{ + FSP_DEVICE_EXTENSION Base; +} FSP_FSVOL_DEVICE_EXTENSION; static inline FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject) { return DeviceObject->DeviceExtension; } static inline -FSP_FILE_SYSTEM_DEVICE_EXTENSION *FspFileSystemDeviceExtension(PDEVICE_OBJECT DeviceObject) +FSP_FSCTL_DEVICE_EXTENSION *FspFsctlDeviceExtension(PDEVICE_OBJECT DeviceObject) { return DeviceObject->DeviceExtension; } static inline -FSP_VOLUME_DEVICE_EXTENSION *FspVolumeDeviceExtension(PDEVICE_OBJECT DeviceObject) +FSP_FSVRT_DEVICE_EXTENSION *FspFsvrtDeviceExtension(PDEVICE_OBJECT DeviceObject) +{ + return DeviceObject->DeviceExtension; +} +static inline +FSP_FSVOL_DEVICE_EXTENSION *FspFsvolDeviceExtension(PDEVICE_OBJECT DeviceObject) { return DeviceObject->DeviceExtension; } @@ -172,7 +183,8 @@ const char *IrpMinorFunctionSym(UCHAR MajorFunction, UCHAR MinorFunction); #endif /* extern */ -extern PDEVICE_OBJECT FspFileSystemDeviceObject; +extern PDEVICE_OBJECT FspFsctlDiskDeviceObject; +extern PDEVICE_OBJECT FspFsctlNetDeviceObject; /* I/O increment */ #define FSP_IO_INCREMENT IO_NETWORK_INCREMENT