sys: FspFsctlMountVolume

This commit is contained in:
Bill Zissimopoulos 2015-11-29 13:21:32 -08:00
parent 9e0c6461c8
commit f4de97f3c6
3 changed files with 43 additions and 6 deletions

View File

@ -48,7 +48,7 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
*ParamsBuf = *Params; *ParamsBuf = *Params;
DeviceHandle = CreateFileW(DevicePathBuf, DeviceHandle = CreateFileW(DevicePathBuf,
0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0); 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (INVALID_HANDLE_VALUE == DeviceHandle) if (INVALID_HANDLE_VALUE == DeviceHandle)
{ {
Result = FspNtStatusFromWin32(GetLastError()); Result = FspNtStatusFromWin32(GetLastError());
@ -84,7 +84,7 @@ FSP_API NTSTATUS FspFsctlOpenVolume(PWSTR VolumePath,
GlobalDevicePath(DevicePathBuf, sizeof DevicePathBuf, VolumePath); GlobalDevicePath(DevicePathBuf, sizeof DevicePathBuf, VolumePath);
VolumeHandle = CreateFileW(DevicePathBuf, VolumeHandle = CreateFileW(DevicePathBuf,
0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0); 0, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (INVALID_HANDLE_VALUE == VolumeHandle) if (INVALID_HANDLE_VALUE == VolumeHandle)
{ {
Result = FspNtStatusFromWin32(GetLastError()); Result = FspNtStatusFromWin32(GetLastError());

View File

@ -261,6 +261,7 @@ typedef struct
{ {
FSP_DEVICE_EXTENSION Base; FSP_DEVICE_EXTENSION Base;
PDEVICE_OBJECT FsvrtDeviceObject; PDEVICE_OBJECT FsvrtDeviceObject;
PVPB SwapVpb;
} FSP_FSVOL_DEVICE_EXTENSION; } FSP_FSVOL_DEVICE_EXTENSION;
static inline static inline
FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject)
@ -270,16 +271,19 @@ FSP_DEVICE_EXTENSION *FspDeviceExtension(PDEVICE_OBJECT DeviceObject)
static inline static inline
FSP_FSCTL_DEVICE_EXTENSION *FspFsctlDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_FSCTL_DEVICE_EXTENSION *FspFsctlDeviceExtension(PDEVICE_OBJECT DeviceObject)
{ {
ASSERT(FspFsctlDeviceExtensionKind == ((FSP_DEVICE_EXTENSION *)DeviceObject->DeviceExtension)->Kind);
return DeviceObject->DeviceExtension; return DeviceObject->DeviceExtension;
} }
static inline static inline
FSP_FSVRT_DEVICE_EXTENSION *FspFsvrtDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_FSVRT_DEVICE_EXTENSION *FspFsvrtDeviceExtension(PDEVICE_OBJECT DeviceObject)
{ {
ASSERT(FspFsvrtDeviceExtensionKind == ((FSP_DEVICE_EXTENSION *)DeviceObject->DeviceExtension)->Kind);
return DeviceObject->DeviceExtension; return DeviceObject->DeviceExtension;
} }
static inline static inline
FSP_FSVOL_DEVICE_EXTENSION *FspFsvolDeviceExtension(PDEVICE_OBJECT DeviceObject) FSP_FSVOL_DEVICE_EXTENSION *FspFsvolDeviceExtension(PDEVICE_OBJECT DeviceObject)
{ {
ASSERT(FspFsvolDeviceExtensionKind == ((FSP_DEVICE_EXTENSION *)DeviceObject->DeviceExtension)->Kind);
return DeviceObject->DeviceExtension; return DeviceObject->DeviceExtension;
} }

View File

@ -93,7 +93,7 @@ static NTSTATUS FspFsctlCreateVolume(
FspIoqInitialize(&FsvrtDeviceExtension->Ioq); FspIoqInitialize(&FsvrtDeviceExtension->Ioq);
RtlCopyMemory(FspFsvrtDeviceExtension(FsvrtDeviceObject)->SecurityDescriptorBuf, RtlCopyMemory(FspFsvrtDeviceExtension(FsvrtDeviceObject)->SecurityDescriptorBuf,
SecurityDescriptorBuf, SecurityDescriptorSize); SecurityDescriptorBuf, SecurityDescriptorSize);
ClearFlag(FsvrtDeviceObject->DO_DEVICE_INITIALIZING); ClearFlag(FsvrtDeviceObject->Flags, DO_DEVICE_INITIALIZING);
Irp->IoStatus.Information = DeviceName.Length + 1; Irp->IoStatus.Information = DeviceName.Length + 1;
} }
@ -109,10 +109,14 @@ static NTSTATUS FspFsctlMountVolume(
PAGED_CODE(); PAGED_CODE();
NTSTATUS Result; NTSTATUS Result;
PDEVICE_OBJECT RealDevice = IrpSp->Parameters.MountVolume.Vpb->RealDevice; PVPB Vpb = IrpSp->Parameters.MountVolume.Vpb;
PVPB SwapVpb = 0;
PDEVICE_OBJECT FsvrtDeviceObject = Vpb->RealDevice;
PDEVICE_OBJECT FsvolDeviceObject;
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension;
/* check the passed in volume object; it must be one of our own */ /* check the passed in volume object; it must be one of our own */
Result = FspHasDeviceObject(DeviceObject->DriverObject, RealDevice); Result = FspHasDeviceObject(DeviceObject->DriverObject, FsvrtDeviceObject);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
{ {
if (STATUS_NO_SUCH_DEVICE == Result) if (STATUS_NO_SUCH_DEVICE == Result)
@ -120,9 +124,38 @@ static NTSTATUS FspFsctlMountVolume(
else else
return Result; return Result;
} }
if (FILE_DEVICE_VIRTUAL_DISK != RealDevice->DeviceType) if (FILE_DEVICE_VIRTUAL_DISK != FsvrtDeviceObject->DeviceType)
return STATUS_UNRECOGNIZED_VOLUME; return STATUS_UNRECOGNIZED_VOLUME;
/* preallocate swap VPB */
SwapVpb = ExAllocatePoolWithTag(NonPagedPool, sizeof *SwapVpb, FSP_TAG);
if (0 == SwapVpb)
return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory(SwapVpb, sizeof *Vpb);
/* create the file system device object */
Result = IoCreateDevice(DeviceObject->DriverObject,
sizeof(FSP_FSVOL_DEVICE_EXTENSION), 0, DeviceObject->DeviceType,
0, FALSE,
&FsvolDeviceObject);
if (NT_SUCCESS(Result))
{
FsvolDeviceObject->SectorSize =
FspFsvrtDeviceExtension(FsvrtDeviceObject)->VolumeParams.SectorSize;
FsvolDeviceExtension = FspFsvolDeviceExtension(FsvolDeviceObject);
FsvolDeviceExtension->FsvrtDeviceObject = FsvrtDeviceObject;
FsvolDeviceExtension->SwapVpb = SwapVpb;
ClearFlag(FsvolDeviceObject->Flags, DO_DEVICE_INITIALIZING);
Vpb->VolumeLabelLength = 0;
Vpb->DeviceObject = FsvolDeviceObject;
Irp->IoStatus.Information = 0;
SwapVpb = 0;
}
/* free swap VPB if we failed */
if (0 != SwapVpb)
ExFreePoolWithTag(SwapVpb, FSP_TAG);
return Result; return Result;
} }