sys: decide on device hierarchy: fsctl, fsvrt, fsvol

This commit is contained in:
Bill Zissimopoulos 2015-11-20 23:39:20 -08:00
parent 4d910c7fa8
commit 93be122c91
5 changed files with 48 additions and 25 deletions

View File

@ -21,7 +21,7 @@ FspCleanup(
ASSERT(IRP_MJ_CLEANUP == IrpSp->MajorFunction); ASSERT(IRP_MJ_CLEANUP == IrpSp->MajorFunction);
if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind)
FSP_RETURN(Irp->IoStatus.Information = 0); FSP_RETURN(Irp->IoStatus.Information = 0);
Result = STATUS_INVALID_DEVICE_REQUEST; Result = STATUS_INVALID_DEVICE_REQUEST;

View File

@ -21,7 +21,7 @@ FspClose(
ASSERT(IRP_MJ_CLOSE == IrpSp->MajorFunction); ASSERT(IRP_MJ_CLOSE == IrpSp->MajorFunction);
if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind)
FSP_RETURN(Irp->IoStatus.Information = 0); FSP_RETURN(Irp->IoStatus.Information = 0);
Result = STATUS_INVALID_DEVICE_REQUEST; Result = STATUS_INVALID_DEVICE_REQUEST;

View File

@ -21,7 +21,7 @@ FspCreate(
ASSERT(IRP_MJ_CREATE == IrpSp->MajorFunction); ASSERT(IRP_MJ_CREATE == IrpSp->MajorFunction);
if (FspFileSystemDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind) if (FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind)
FSP_RETURN(Irp->IoStatus.Information = FILE_OPENED); FSP_RETURN(Irp->IoStatus.Information = FILE_OPENED);
Result = STATUS_INVALID_DEVICE_REQUEST; Result = STATUS_INVALID_DEVICE_REQUEST;

View File

@ -21,15 +21,22 @@ DriverEntry(
{ {
FSP_ENTER(); FSP_ENTER();
/* create the file system device object */ /* create the file system control device objects */
UNICODE_STRING DeviceName; UNICODE_STRING DeviceName;
RtlInitUnicodeString(&DeviceName, L"\\Device\\" DEVICE_NAME); RtlInitUnicodeString(&DeviceName, L"\\Device\\" DISK_DEVICE_NAME);
Result = IoCreateDevice(DriverObject, Result = IoCreateDevice(DriverObject,
sizeof(FSP_FILE_SYSTEM_DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_FILE_SYSTEM, 0, FALSE, sizeof(FSP_FSCTL_DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_DISK_FILE_SYSTEM, 0, FALSE,
&FspFileSystemDeviceObject); &FspFsctlDiskDeviceObject);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
FSP_RETURN(); 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 */ /* setup the driver object */
DriverObject->DriverUnload = FspUnload; DriverObject->DriverUnload = FspUnload;
@ -94,11 +101,9 @@ DriverEntry(
FspFastIoDispatch.ReleaseForCcFlush = FspReleaseForCcFlush; FspFastIoDispatch.ReleaseForCcFlush = FspReleaseForCcFlush;
DriverObject->FastIoDispatch = &FspFastIoDispatch; DriverObject->FastIoDispatch = &FspFastIoDispatch;
/* /* register our device objects as file systems */
* Register as a file system; this informs all filter drivers. IoRegisterFileSystem(FspFsctlDiskDeviceObject);
* Future drivers will *not* be informed because we are a FILE_DEVICE_FILE_SYSTEM! IoRegisterFileSystem(FspFsctlNetDeviceObject);
*/
IoRegisterFileSystem(FspFileSystemDeviceObject);
FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"", FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"",
&DriverObject->DriverName, RegistryPath); &DriverObject->DriverName, RegistryPath);
@ -110,14 +115,20 @@ FspUnload(
{ {
FSP_ENTER_VOID(PAGED_CODE()); FSP_ENTER_VOID(PAGED_CODE());
if (0 != FspFileSystemDeviceObject) if (0 != FspFsctlDiskDeviceObject)
{ {
IoDeleteDevice(FspFileSystemDeviceObject); IoDeleteDevice(FspFsctlDiskDeviceObject);
FspFileSystemDeviceObject = 0; FspFsctlDiskDeviceObject = 0;
}
if (0 != FspFsctlNetDeviceObject)
{
IoDeleteDevice(FspFsctlNetDeviceObject);
FspFsctlNetDeviceObject = 0;
} }
FSP_LEAVE_VOID("DriverName=\"%wZ\"", FSP_LEAVE_VOID("DriverName=\"%wZ\"",
&DriverObject->DriverName); &DriverObject->DriverName);
} }
PDEVICE_OBJECT FspFileSystemDeviceObject; PDEVICE_OBJECT FspFsctlDiskDeviceObject;
PDEVICE_OBJECT FspFsctlNetDeviceObject;

View File

@ -10,7 +10,8 @@
#include <ntifs.h> #include <ntifs.h>
#define DRIVER_NAME "WinFsp" #define DRIVER_NAME "WinFsp"
#define DEVICE_NAME "WinFsp" #define DISK_DEVICE_NAME "WinFsp.Disk"
#define NET_DEVICE_NAME "WinFsp.Net"
/* DEBUGLOG */ /* DEBUGLOG */
#if DBG #if DBG
@ -100,8 +101,9 @@
/* types */ /* types */
enum enum
{ {
FspFileSystemDeviceExtensionKind = 'F', FspFsctlDeviceExtensionKind = 'C', /* file system control device (e.g. \Device\WinFsp.Disk) */
FspVolumeDeviceExtensionKind = 'V', FspFsvrtDeviceExtensionKind = 'V', /* virtual volume device (e.g. \Device\Volume{GUID}) */
FspFsvolDeviceExtensionKind = 'F', /* file system volume device (unnamed) */
}; };
typedef struct typedef struct
{ {
@ -110,23 +112,32 @@ typedef struct
typedef struct typedef struct
{ {
FSP_DEVICE_EXTENSION Base; FSP_DEVICE_EXTENSION Base;
} FSP_FILE_SYSTEM_DEVICE_EXTENSION; } FSP_FSCTL_DEVICE_EXTENSION;
typedef struct typedef struct
{ {
FSP_DEVICE_EXTENSION Base; FSP_DEVICE_EXTENSION Base;
} FSP_VOLUME_DEVICE_EXTENSION; } FSP_FSVRT_DEVICE_EXTENSION;
typedef struct
{
FSP_DEVICE_EXTENSION Base;
} FSP_FSVOL_DEVICE_EXTENSION;
static inline static inline
FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject)
{ {
return DeviceObject->DeviceExtension; return DeviceObject->DeviceExtension;
} }
static inline static inline
FSP_FILE_SYSTEM_DEVICE_EXTENSION *FspFileSystemDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_FSCTL_DEVICE_EXTENSION *FspFsctlDeviceExtension(PDEVICE_OBJECT DeviceObject)
{ {
return DeviceObject->DeviceExtension; return DeviceObject->DeviceExtension;
} }
static inline 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; return DeviceObject->DeviceExtension;
} }
@ -172,7 +183,8 @@ const char *IrpMinorFunctionSym(UCHAR MajorFunction, UCHAR MinorFunction);
#endif #endif
/* extern */ /* extern */
extern PDEVICE_OBJECT FspFileSystemDeviceObject; extern PDEVICE_OBJECT FspFsctlDiskDeviceObject;
extern PDEVICE_OBJECT FspFsctlNetDeviceObject;
/* I/O increment */ /* I/O increment */
#define FSP_IO_INCREMENT IO_NETWORK_INCREMENT #define FSP_IO_INCREMENT IO_NETWORK_INCREMENT