mirror of
https://github.com/reactos/reactos.git
synced 2025-03-01 03:45:16 +00:00
[NTOS:IO] IoVolumeDeviceToDosName(): Some stylistic changes.
Minor formatting and comments improvements (typo fixes etc.)
This commit is contained in:
parent
5c4fcd99d6
commit
5afb7ab003
1 changed files with 32 additions and 40 deletions
|
@ -9,13 +9,13 @@
|
||||||
* Pierre Schweitzer (pierre.schweitzer@reactos.org)
|
* Pierre Schweitzer (pierre.schweitzer@reactos.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES ******************************************************************/
|
||||||
|
|
||||||
#include <ntoskrnl.h>
|
#include <ntoskrnl.h>
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
/* GLOBALS ******************************************************************/
|
/* GLOBALS *******************************************************************/
|
||||||
|
|
||||||
ERESOURCE IopDatabaseResource;
|
ERESOURCE IopDatabaseResource;
|
||||||
LIST_ENTRY IopDiskFileSystemQueueHead, IopNetworkFileSystemQueueHead;
|
LIST_ENTRY IopDiskFileSystemQueueHead, IopNetworkFileSystemQueueHead;
|
||||||
|
@ -1279,10 +1279,10 @@ NTAPI
|
||||||
IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
OUT PUNICODE_STRING DosName)
|
OUT PUNICODE_STRING DosName)
|
||||||
{
|
{
|
||||||
PIRP Irp;
|
NTSTATUS Status;
|
||||||
ULONG Length;
|
ULONG Length;
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
NTSTATUS Status;
|
PIRP Irp;
|
||||||
PFILE_OBJECT FileObject;
|
PFILE_OBJECT FileObject;
|
||||||
PDEVICE_OBJECT DeviceObject;
|
PDEVICE_OBJECT DeviceObject;
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
@ -1290,10 +1290,10 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
MOUNTMGR_VOLUME_PATHS VolumePath;
|
MOUNTMGR_VOLUME_PATHS VolumePath;
|
||||||
PMOUNTMGR_VOLUME_PATHS VolumePathPtr;
|
PMOUNTMGR_VOLUME_PATHS VolumePathPtr;
|
||||||
/*
|
/*
|
||||||
* This variable with be required to query device name.
|
* This variable is used to query the device name.
|
||||||
* It's based on MOUNTDEV_NAME (mountmgr.h).
|
* It's based on MOUNTDEV_NAME (mountmgr.h).
|
||||||
* Doing it that way will prevent dyn memory allocation.
|
* Doing it this way prevents memory allocation.
|
||||||
* Device name won't be longer.
|
* The device name won't be longer.
|
||||||
*/
|
*/
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -1303,10 +1303,11 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* First step, getting device name */
|
/* First, retrieve the corresponding device name */
|
||||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||||
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
|
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
|
||||||
VolumeDeviceObject, NULL, 0,
|
VolumeDeviceObject,
|
||||||
|
NULL, 0,
|
||||||
&DeviceName, sizeof(DeviceName),
|
&DeviceName, sizeof(DeviceName),
|
||||||
FALSE, &Event, &IoStatusBlock);
|
FALSE, &Event, &IoStatusBlock);
|
||||||
if (!Irp)
|
if (!Irp)
|
||||||
|
@ -1320,15 +1321,12 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
||||||
Status = IoStatusBlock.Status;
|
Status = IoStatusBlock.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now that we have the device name, we can query the MountMgr
|
/* Now, query the MountMgr for the DOS path */
|
||||||
* So, get its device object first.
|
|
||||||
*/
|
|
||||||
RtlInitUnicodeString(&MountMgrDevice, MOUNTMGR_DEVICE_NAME);
|
RtlInitUnicodeString(&MountMgrDevice, MOUNTMGR_DEVICE_NAME);
|
||||||
Status = IoGetDeviceObjectPointer(&MountMgrDevice, FILE_READ_ATTRIBUTES,
|
Status = IoGetDeviceObjectPointer(&MountMgrDevice, FILE_READ_ATTRIBUTES,
|
||||||
&FileObject, &DeviceObject);
|
&FileObject, &DeviceObject);
|
||||||
|
@ -1337,16 +1335,16 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then, use the proper IOCTL to query the DOS name */
|
|
||||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||||
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH,
|
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH,
|
||||||
DeviceObject, &DeviceName, sizeof(DeviceName),
|
DeviceObject,
|
||||||
|
&DeviceName, sizeof(DeviceName),
|
||||||
&VolumePath, sizeof(VolumePath),
|
&VolumePath, sizeof(VolumePath),
|
||||||
FALSE, &Event, &IoStatusBlock);
|
FALSE, &Event, &IoStatusBlock);
|
||||||
if (!Irp)
|
if (!Irp)
|
||||||
{
|
{
|
||||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
goto DereferenceFO;
|
goto Quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = IoCallDriver(DeviceObject, Irp);
|
Status = IoCallDriver(DeviceObject, Irp);
|
||||||
|
@ -1356,41 +1354,37 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
Status = IoStatusBlock.Status;
|
Status = IoStatusBlock.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only tolerated failure here is buffer too small, which is
|
/* The only tolerated failure here is buffer too small, which is expected */
|
||||||
* expected.
|
if (!NT_SUCCESS(Status) && (Status != STATUS_BUFFER_OVERFLOW))
|
||||||
*/
|
|
||||||
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
|
|
||||||
{
|
{
|
||||||
goto DereferenceFO;
|
goto Quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute needed size to store DOS name.
|
/* Compute the needed size to store the DOS name.
|
||||||
* Even if MOUNTMGR_VOLUME_PATHS allows bigger
|
* Even if MOUNTMGR_VOLUME_PATHS allows bigger name lengths
|
||||||
* name lengths than MAXUSHORT, we can't use
|
* than MAXUSHORT, we can't use them, because we have to return
|
||||||
* them, because we have to return this in an UNICODE_STRING
|
* this in an UNICODE_STRING that stores length in a USHORT. */
|
||||||
* that stores length on USHORT.
|
Length = sizeof(VolumePath) + VolumePath.MultiSzLength;
|
||||||
*/
|
|
||||||
Length = VolumePath.MultiSzLength + sizeof(VolumePath);
|
|
||||||
if (Length > MAXUSHORT)
|
if (Length > MAXUSHORT)
|
||||||
{
|
{
|
||||||
Status = STATUS_INVALID_BUFFER_SIZE;
|
Status = STATUS_INVALID_BUFFER_SIZE;
|
||||||
goto DereferenceFO;
|
goto Quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reallocate memory, even in case of success, because
|
/* Reallocate the memory, even in case of success, because
|
||||||
* that's the buffer that will be returned to caller
|
* that's the buffer that will be returned to the caller */
|
||||||
*/
|
|
||||||
VolumePathPtr = ExAllocatePoolWithTag(PagedPool, Length, 'D2d ');
|
VolumePathPtr = ExAllocatePoolWithTag(PagedPool, Length, 'D2d ');
|
||||||
if (!VolumePathPtr)
|
if (!VolumePathPtr)
|
||||||
{
|
{
|
||||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
goto DereferenceFO;
|
goto Quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Requery DOS path with proper size */
|
/* Re-query the DOS path with the proper size */
|
||||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||||
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH,
|
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_QUERY_DOS_VOLUME_PATH,
|
||||||
DeviceObject, &DeviceName, sizeof(DeviceName),
|
DeviceObject,
|
||||||
|
&DeviceName, sizeof(DeviceName),
|
||||||
VolumePathPtr, Length,
|
VolumePathPtr, Length,
|
||||||
FALSE, &Event, &IoStatusBlock);
|
FALSE, &Event, &IoStatusBlock);
|
||||||
if (!Irp)
|
if (!Irp)
|
||||||
|
@ -1405,7 +1399,6 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
||||||
Status = IoStatusBlock.Status;
|
Status = IoStatusBlock.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
goto ReleaseMemory;
|
goto ReleaseMemory;
|
||||||
|
@ -1420,16 +1413,15 @@ IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject,
|
||||||
RtlMoveMemory(DosName->Buffer, VolumePathPtr->MultiSz, VolumePathPtr->MultiSzLength);
|
RtlMoveMemory(DosName->Buffer, VolumePathPtr->MultiSz, VolumePathPtr->MultiSzLength);
|
||||||
DosName->Buffer[DosName->Length / sizeof(WCHAR)] = UNICODE_NULL;
|
DosName->Buffer[DosName->Length / sizeof(WCHAR)] = UNICODE_NULL;
|
||||||
|
|
||||||
/* DON'T release buffer, just dereference FO, and return success */
|
/* Don't release the buffer, just dereference the FO and return success */
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
goto DereferenceFO;
|
goto Quit;
|
||||||
|
|
||||||
ReleaseMemory:
|
ReleaseMemory:
|
||||||
ExFreePoolWithTag(VolumePathPtr, 'D2d ');
|
ExFreePoolWithTag(VolumePathPtr, 'D2d ');
|
||||||
|
|
||||||
DereferenceFO:
|
Quit:
|
||||||
ObDereferenceObject(FileObject);
|
ObDereferenceObject(FileObject);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue