sys: FspFsctlDeviceVolumeCreated, FspFsctlDeviceVolumeDeleted

This commit is contained in:
Bill Zissimopoulos 2015-12-01 21:48:03 -08:00
parent 763d4666a7
commit 1312754016
4 changed files with 61 additions and 19 deletions

View File

@ -22,6 +22,8 @@ static NTSTATUS FspFsvolDeviceInit(PDEVICE_OBJECT DeviceObject);
static VOID FspFsvolDeviceFini(PDEVICE_OBJECT DeviceObject); static VOID FspFsvolDeviceFini(PDEVICE_OBJECT DeviceObject);
BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject); BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject);
VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject); VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject);
VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject);
VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject);
NTSTATUS FspDeviceCopyList( NTSTATUS FspDeviceCopyList(
PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount); PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount);
VOID FspDeviceDeleteList( VOID FspDeviceDeleteList(
@ -38,6 +40,8 @@ VOID FspDeviceDeleteAll(VOID);
#pragma alloc_text(PAGE, FspFsvrtDeviceFini) #pragma alloc_text(PAGE, FspFsvrtDeviceFini)
#pragma alloc_text(PAGE, FspFsvolDeviceInit) #pragma alloc_text(PAGE, FspFsvolDeviceInit)
#pragma alloc_text(PAGE, FspFsvolDeviceFini) #pragma alloc_text(PAGE, FspFsvolDeviceFini)
#pragma alloc_text(PAGE, FspFsctlDeviceVolumeCreated)
#pragma alloc_text(PAGE, FspFsctlDeviceVolumeDeleted)
#pragma alloc_text(PAGE, FspDeviceCopyList) #pragma alloc_text(PAGE, FspDeviceCopyList)
#pragma alloc_text(PAGE, FspDeviceDeleteList) #pragma alloc_text(PAGE, FspDeviceDeleteList)
#pragma alloc_text(PAGE, FspDeviceDeleteAll) #pragma alloc_text(PAGE, FspDeviceDeleteAll)
@ -241,6 +245,30 @@ VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject)
FspDeviceDelete(DeviceObject); FspDeviceDelete(DeviceObject);
} }
VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject)
{
PAGED_CODE();
ASSERT(FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind);
ASSERT(ExIsResourceAcquiredExclusiveLite(&FspDeviceExtension(DeviceObject)->Resource));
ULONG FsvrtDeviceObjectCount = FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount++;
if (0 == FsvrtDeviceObjectCount)
IoRegisterFileSystem(DeviceObject);
}
VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject)
{
PAGED_CODE();
ASSERT(FspFsctlDeviceExtensionKind == FspDeviceExtension(DeviceObject)->Kind);
ASSERT(ExIsResourceAcquiredExclusiveLite(&FspDeviceExtension(DeviceObject)->Resource));
ULONG FsvrtDeviceObjectCount = --FspFsctlDeviceExtension(DeviceObject)->FsvrtDeviceObjectCount;
if (0 == FsvrtDeviceObjectCount)
IoUnregisterFileSystem(DeviceObject);
}
NTSTATUS FspDeviceCopyList( NTSTATUS FspDeviceCopyList(
PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount) PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount)
{ {
@ -250,7 +278,7 @@ NTSTATUS FspDeviceCopyList(
ULONG DeviceObjectCount = 0; ULONG DeviceObjectCount = 0;
while (STATUS_BUFFER_TOO_SMALL == IoEnumerateDeviceObjectList(FspDriverObject, while (STATUS_BUFFER_TOO_SMALL == IoEnumerateDeviceObjectList(FspDriverObject,
DeviceObjects, DeviceObjectCount, &DeviceObjectCount)) DeviceObjects, sizeof *DeviceObjects * DeviceObjectCount, &DeviceObjectCount))
{ {
if (0 != DeviceObjects) if (0 != DeviceObjects)
ExFreePoolWithTag(DeviceObjects, FSP_TAG); ExFreePoolWithTag(DeviceObjects, FSP_TAG);

View File

@ -116,10 +116,6 @@ NTSTATUS DriverEntry(
#pragma prefast(suppress:28175, "We are a filesystem: ok to access FastIoDispatch") #pragma prefast(suppress:28175, "We are a filesystem: ok to access FastIoDispatch")
DriverObject->FastIoDispatch = &FspFastIoDispatch; DriverObject->FastIoDispatch = &FspFastIoDispatch;
/* register our device objects as file systems */
IoRegisterFileSystem(FspFsctlDiskDeviceObject);
IoRegisterFileSystem(FspFsctlNetDeviceObject);
#pragma prefast(suppress:28175, "We are in DriverEntry: ok to access DriverName") #pragma prefast(suppress:28175, "We are in DriverEntry: ok to access DriverName")
FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"", FSP_LEAVE("DriverName=\"%wZ\", RegistryPath=\"%wZ\"",
&DriverObject->DriverName, RegistryPath); &DriverObject->DriverName, RegistryPath);

View File

@ -261,6 +261,7 @@ typedef struct
typedef struct typedef struct
{ {
FSP_DEVICE_EXTENSION Base; FSP_DEVICE_EXTENSION Base;
ULONG FsvrtDeviceObjectCount;
} FSP_FSCTL_DEVICE_EXTENSION; } FSP_FSCTL_DEVICE_EXTENSION;
typedef struct typedef struct
{ {
@ -311,6 +312,8 @@ NTSTATUS FspDeviceCreate(UINT32 Kind, ULONG ExtraSize,
VOID FspDeviceDelete(PDEVICE_OBJECT DeviceObject); VOID FspDeviceDelete(PDEVICE_OBJECT DeviceObject);
BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject); BOOLEAN FspDeviceRetain(PDEVICE_OBJECT DeviceObject);
VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject); VOID FspDeviceRelease(PDEVICE_OBJECT DeviceObject);
VOID FspFsctlDeviceVolumeCreated(PDEVICE_OBJECT DeviceObject);
VOID FspFsctlDeviceVolumeDeleted(PDEVICE_OBJECT DeviceObject);
NTSTATUS FspDeviceCopyList( NTSTATUS FspDeviceCopyList(
PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount); PDEVICE_OBJECT **PDeviceObjects, PULONG PDeviceObjectCount);
VOID FspDeviceDeleteList( VOID FspDeviceDeleteList(

View File

@ -133,7 +133,7 @@ static NTSTATUS FspFsctlCreateVolume(
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
RtlCopyMemory(SecurityDescriptorBuf, SecurityDescriptor, SecurityDescriptorSize); RtlCopyMemory(SecurityDescriptorBuf, SecurityDescriptor, SecurityDescriptorSize);
/* create the virtual volume device */ /* prepare the device name and SDDL */
PDEVICE_OBJECT FsvrtDeviceObject; PDEVICE_OBJECT FsvrtDeviceObject;
UNICODE_STRING DeviceSddl; UNICODE_STRING DeviceSddl;
UNICODE_STRING DeviceName; UNICODE_STRING DeviceName;
@ -145,6 +145,12 @@ static NTSTATUS FspFsctlCreateVolume(
Guid.Data4[0], Guid.Data4[1], Guid.Data4[2], Guid.Data4[3], Guid.Data4[0], Guid.Data4[1], Guid.Data4[2], Guid.Data4[3],
Guid.Data4[4], Guid.Data4[5], Guid.Data4[6], Guid.Data4[7]); Guid.Data4[4], Guid.Data4[5], Guid.Data4[6], Guid.Data4[7]);
ASSERT(NT_SUCCESS(Result)); ASSERT(NT_SUCCESS(Result));
/* create the virtual volume device */
FSP_FSCTL_DEVICE_EXTENSION *FsctlDeviceExtension = FspFsctlDeviceExtension(DeviceObject);
ExAcquireResourceExclusiveLite(&FsctlDeviceExtension->Base.Resource, TRUE);
try
{
Result = FspDeviceCreateSecure(FspFsvrtDeviceExtensionKind, SecurityDescriptorSize, Result = FspDeviceCreateSecure(FspFsvrtDeviceExtensionKind, SecurityDescriptorSize,
&DeviceName, FILE_DEVICE_VIRTUAL_DISK, &DeviceName, FILE_DEVICE_VIRTUAL_DISK,
&DeviceSddl, &FspFsvrtDeviceClassGuid, &DeviceSddl, &FspFsvrtDeviceClassGuid,
@ -160,6 +166,12 @@ static NTSTATUS FspFsctlCreateVolume(
SecurityDescriptorBuf, SecurityDescriptorSize); SecurityDescriptorBuf, SecurityDescriptorSize);
ClearFlag(FsvrtDeviceObject->Flags, DO_DEVICE_INITIALIZING); ClearFlag(FsvrtDeviceObject->Flags, DO_DEVICE_INITIALIZING);
Irp->IoStatus.Information = DeviceName.Length + sizeof(WCHAR); Irp->IoStatus.Information = DeviceName.Length + sizeof(WCHAR);
FspFsctlDeviceVolumeCreated(DeviceObject);
}
}
finally
{
ExReleaseResourceLite(&FsctlDeviceExtension->Base.Resource);
} }
/* free the temporary security descriptor */ /* free the temporary security descriptor */
@ -292,12 +304,15 @@ static NTSTATUS FspFsvrtDeleteVolume(
#pragma prefast(pop) #pragma prefast(pop)
/* release the file system device and virtual volume objects */ /* release the file system device and virtual volume objects */
PDEVICE_OBJECT FsctlDeviceObject = FsvrtDeviceExtension->FsctlDeviceObject;
PDEVICE_OBJECT FsvolDeviceObject = FsvrtDeviceExtension->FsvolDeviceObject; PDEVICE_OBJECT FsvolDeviceObject = FsvrtDeviceExtension->FsvolDeviceObject;
FsvrtDeviceExtension->FsvolDeviceObject = 0; FsvrtDeviceExtension->FsvolDeviceObject = 0;
if (0 != FsvolDeviceObject) if (0 != FsvolDeviceObject)
FspDeviceRelease(FsvolDeviceObject); FspDeviceRelease(FsvolDeviceObject);
FspDeviceRelease(DeviceObject); FspDeviceRelease(DeviceObject);
FspFsctlDeviceVolumeDeleted(FsctlDeviceObject);
Result = STATUS_SUCCESS; Result = STATUS_SUCCESS;
exit:; exit:;