From 140e567fdc3e5c979a395d4ec79294195c979e22 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Thu, 10 Dec 2015 16:31:01 -0800 Subject: [PATCH] sys: call IoRegisterFileSystem from DriverEntry --- src/sys/device.c | 8 ++++++++ src/sys/driver.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/sys/device.c b/src/sys/device.c index 0258300c..6c93e748 100644 --- a/src/sys/device.c +++ b/src/sys/device.c @@ -289,9 +289,13 @@ VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject) ASSERT(FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind); ASSERT(ExIsResourceAcquiredExclusiveLite(&FspDeviceExtension(DeviceObject)->Resource)); +#if 1 + FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount++; +#else ULONG FsvrtDeviceObjectCount = FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount++; if (0 == FsvrtDeviceObjectCount) IoRegisterFileSystem(DeviceObject); +#endif } VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject) @@ -301,9 +305,13 @@ VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject) ASSERT(FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind); ASSERT(ExIsResourceAcquiredExclusiveLite(&FspDeviceExtension(DeviceObject)->Resource)); +#if 1 + --FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount; +#else ULONG FsvrtDeviceObjectCount = --FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount; if (0 == FsvrtDeviceObjectCount) IoUnregisterFileSystem(DeviceObject); +#endif } PVOID FspFsvolDeviceLookupContext(PDEVICE_OBJECT DeviceObject, UINT64 Identifier) diff --git a/src/sys/driver.c b/src/sys/driver.c index 4e254929..10ae34c1 100644 --- a/src/sys/driver.c +++ b/src/sys/driver.c @@ -121,6 +121,20 @@ NTSTATUS DriverEntry( #pragma prefast(suppress:28175, "We are a filesystem: ok to access FastIoDispatch") DriverObject->FastIoDispatch = &FspFastIoDispatch; + /* + * Register our devices as file systems. We do this here to simplify file system + * registration/unregistration, although this makes our driver unloadable from the + * get go. + * + * Unfortunately a call to IoRegisterFileSystem(), even if followed by a call to + * IoUnregistreFileSystem(), makes the driver unloadable. We attempted to move + * the register/unregister calls to FspFsctlDeviceVolume{Created,Deleted}, but it + * did not make any difference with regards to making the driver unloadable. Hence + * we stick to the simpler scheme of doing registration here. + */ + IoRegisterFileSystem(FspFsctlDiskDeviceObject); + IoRegisterFileSystem(FspFsctlNetDeviceObject); + #pragma prefast(suppress:28175, "We are in DriverEntry: ok to access DriverName") FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"", &DriverObject->DriverName, RegistryPath);