mirror of
				https://github.com/winfsp/winfsp.git
				synced 2025-10-31 03:58:38 -05:00 
			
		
		
		
	sys: decide on device hierarchy: fsctl, fsvrt, fsvol
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -10,7 +10,8 @@ | ||||
| #include <ntifs.h> | ||||
|  | ||||
| #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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user