https://git.reactos.org/?p=reactos.git;a=commitdiff;h=be97a36f25c3fec7ad8ca…
commit be97a36f25c3fec7ad8ca6c43aeadfe12d9eab34
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jan 19 22:23:56 2025 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Tue Jan 21 19:15:59 2025 +0100
[MOUNTMGR] Simplify MountMgrQueryDosVolumePath() code (#6990)
- Use a variable of correct type instead of casting every time.
- Remove one level of indentation by returning early.
---
drivers/storage/mountmgr/device.c | 66 ++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 32 deletions(-)
diff --git a/drivers/storage/mountmgr/device.c b/drivers/storage/mountmgr/device.c
index ca8ed5c1395..62d28cf7192 100644
--- a/drivers/storage/mountmgr/device.c
+++ b/drivers/storage/mountmgr/device.c
@@ -819,6 +819,7 @@ MountMgrQueryDosVolumePath(IN PDEVICE_EXTENSION DeviceExtension,
PLIST_ENTRY SymlinksEntry;
UNICODE_STRING SymbolicName;
PMOUNTMGR_TARGET_NAME Target;
+ PMOUNTMGR_VOLUME_PATHS Output;
PWSTR DeviceString, OldBuffer;
USHORT DeviceLength, OldLength;
PDEVICE_INFORMATION DeviceInformation;
@@ -992,46 +993,47 @@ TryWithVolumeName:
}
RtlCopyMemory(DeviceString, SymlinkInformation->Name.Buffer,
DeviceLength);
- /* Ensure we are in the right namespace; [1] can be ? */
+ /* Ensure we are in the Win32 namespace; [1] can be '?' */
DeviceString[1] = L'\\';
}
}
- /* If we found something */
- if (DeviceString)
- {
- /* At least, we will return our length */
- ((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSzLength =
DeviceLength;
- /* MOUNTMGR_VOLUME_PATHS is a string + a ULONG */
- Irp->IoStatus.Information = DeviceLength + sizeof(ULONG);
+ /* If we didn't find something, fail */
+ if (!DeviceString)
+ return STATUS_NOT_FOUND;
- /* If we have enough room for copying the string */
- if (sizeof(ULONG) + DeviceLength <=
Stack->Parameters.DeviceIoControl.OutputBufferLength)
- {
- /* Copy it */
- if (DeviceLength)
- {
-
RtlCopyMemory(((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz,
DeviceString, DeviceLength);
- }
+ /* Get the output buffer */
+ Output = (PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer;
- /* And double zero at its end - this is needed in case of multiple paths
which are separated by a single 0 */
- FreePool(DeviceString);
-
((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz[DeviceLength /
sizeof(WCHAR)] = 0;
-
((PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer)->MultiSz[DeviceLength /
sizeof(WCHAR) + 1] = 0;
+ /* At least, we will return our length */
+ Output->MultiSzLength = DeviceLength;
+ /* MOUNTMGR_VOLUME_PATHS is a string + a ULONG */
+ Irp->IoStatus.Information = DeviceLength + sizeof(ULONG);
- return STATUS_SUCCESS;
- }
- else
+ /* If we have enough room for copying the string */
+ if (sizeof(ULONG) + DeviceLength <=
Stack->Parameters.DeviceIoControl.OutputBufferLength)
+ {
+ /* Copy it */
+ if (DeviceLength)
{
- /* Just return appropriate size and leave */
- FreePool(DeviceString);
- Irp->IoStatus.Information = sizeof(ULONG);
- return STATUS_BUFFER_OVERFLOW;
+ RtlCopyMemory(Output->MultiSz, DeviceString, DeviceLength);
}
- }
- /* Fail */
- return STATUS_NOT_FOUND;
+ /* And double-NUL at its end - this is needed in case of
+ * multiple paths which are separated by a single NUL */
+ FreePool(DeviceString);
+ Output->MultiSz[DeviceLength / sizeof(WCHAR)] = UNICODE_NULL;
+ Output->MultiSz[DeviceLength / sizeof(WCHAR) + 1] = UNICODE_NULL;
+
+ return STATUS_SUCCESS;
+ }
+ else
+ {
+ /* Just return the size needed and leave */
+ FreePool(DeviceString);
+ Irp->IoStatus.Information = sizeof(ULONG);
+ return STATUS_BUFFER_OVERFLOW;
+ }
}
/*
@@ -1557,7 +1559,7 @@ MountMgrQueryDosVolumePaths(IN PDEVICE_EXTENSION DeviceExtension,
MountMgrNotifyNameChange(DeviceExtension, &SymbolicName, FALSE);
}
- /* Get output buffer */
+ /* Get the output buffer */
Output = (PMOUNTMGR_VOLUME_PATHS)Irp->AssociatedIrp.SystemBuffer;
/* Set required size */
@@ -1566,7 +1568,7 @@ MountMgrQueryDosVolumePaths(IN PDEVICE_EXTENSION DeviceExtension,
/* Compute total length */
OutputLength = Output->MultiSzLength + sizeof(ULONG);
- /* If it cannot fit, just return need size and quit */
+ /* If it cannot fit, just return the size needed and leave */
if (OutputLength > Stack->Parameters.DeviceIoControl.OutputBufferLength)
{
Irp->IoStatus.Information = sizeof(ULONG);