Skip to content

Commit

Permalink
[MOUNTMGR] Introduce MountMgrSendSyncDeviceIoCtl() to replace repeate…
Browse files Browse the repository at this point in the history
…d code (reactos#6960)

See https://www.osr.com/blog/2018/02/14/beware-iobuilddeviceiocontrolrequest/
for some details about IRQL requirements.
  • Loading branch information
HBelusca committed Jun 13, 2024
1 parent 5027194 commit ab0e04c
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 448 deletions.
36 changes: 7 additions & 29 deletions drivers/storage/mountmgr/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,8 @@ MountMgrCheckUnprocessedVolumes(IN PDEVICE_EXTENSION DeviceExtension,
BOOLEAN
IsFtVolume(IN PUNICODE_STRING SymbolicName)
{
PIRP Irp;
KEVENT Event;
NTSTATUS Status;
PFILE_OBJECT FileObject;
IO_STATUS_BLOCK IoStatusBlock;
PARTITION_INFORMATION PartitionInfo;
PDEVICE_OBJECT DeviceObject, FileDeviceObject;

Expand All @@ -344,9 +341,7 @@ IsFtVolume(IN PUNICODE_STRING SymbolicName)
&FileObject,
&DeviceObject);
if (!NT_SUCCESS(Status))
{
return FALSE;
}

/* Get attached device */
FileDeviceObject = FileObject->DeviceObject;
Expand All @@ -363,34 +358,17 @@ IsFtVolume(IN PUNICODE_STRING SymbolicName)
ObDereferenceObject(FileObject);

/* Get partition information */
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO,
DeviceObject,
NULL,
0,
&PartitionInfo,
sizeof(PartitionInfo),
FALSE,
&Event,
&IoStatusBlock);
if (!Irp)
{
ObDereferenceObject(DeviceObject);
return FALSE;
}

Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
Status = IoStatusBlock.Status;
}
Status = MountMgrSendSyncDeviceIoCtl(IOCTL_DISK_GET_PARTITION_INFO,
DeviceObject,
NULL,
0,
&PartitionInfo,
sizeof(PartitionInfo),
NULL);

ObDereferenceObject(DeviceObject);
if (!NT_SUCCESS(Status))
{
return FALSE;
}

/* Check if this is a FT volume */
return IsFTPartition(PartitionInfo.PartitionType);
Expand Down
11 changes: 11 additions & 0 deletions drivers/storage/mountmgr/mntmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ extern LONG Unloading;
CODE_SEG("INIT")
DRIVER_INITIALIZE DriverEntry;

_IRQL_requires_(PASSIVE_LEVEL)
NTSTATUS
MountMgrSendSyncDeviceIoCtl(
_In_ ULONG IoControlCode,
_In_ PDEVICE_OBJECT DeviceObject,
_In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer,
_In_ ULONG InputBufferLength,
_Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
_In_ ULONG OutputBufferLength,
_In_opt_ PFILE_OBJECT FileObject);

VOID
NTAPI
MountMgrCancel(
Expand Down
Loading

0 comments on commit ab0e04c

Please sign in to comment.