From a927f1d071f9315c97bcbfa23e27aef73a4e07ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 13 Sep 2013 22:02:07 +0000 Subject: [PATCH] [MOUNTMGR] - Clarify the code (use properly RtlPrefixUnicodeString) - 'if' level--; svn path=/trunk/; revision=60083 --- reactos/drivers/filters/mountmgr/device.c | 10 +++- reactos/drivers/filters/mountmgr/mountmgr.c | 17 ++++--- reactos/drivers/filters/mountmgr/symlink.c | 51 ++++++++++----------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/reactos/drivers/filters/mountmgr/device.c b/reactos/drivers/filters/mountmgr/device.c index f898bfa5b74..9efdf076e41 100644 --- a/reactos/drivers/filters/mountmgr/device.c +++ b/reactos/drivers/filters/mountmgr/device.c @@ -555,13 +555,21 @@ MountMgrNextDriveLetterWorker(IN PDEVICE_EXTENSION DeviceExtension, } /* Now everything is fine, start processing */ + if (RtlPrefixUnicodeString(&DeviceFloppy, &TargetDeviceName, TRUE)) { + /* If the device is a floppy, start with letter A */ DriveLetter = 'A'; } + else if (RtlPrefixUnicodeString(&DeviceCdRom, &TargetDeviceName, TRUE)) + { + /* If the device is a CD-ROM, start with letter D */ + DriveLetter = 'D'; + } else { - DriveLetter = 'C' + RtlPrefixUnicodeString(&DeviceCdRom, &TargetDeviceName, TRUE); + /* Finally, if it's a disk, use C */ + DriveLetter = 'C'; } /* We cannot set NO drive letter */ diff --git a/reactos/drivers/filters/mountmgr/mountmgr.c b/reactos/drivers/filters/mountmgr/mountmgr.c index b0a2b31428a..2e78d4e3cbc 100644 --- a/reactos/drivers/filters/mountmgr/mountmgr.c +++ b/reactos/drivers/filters/mountmgr/mountmgr.c @@ -169,19 +169,22 @@ CreateNewDriveLetterName(OUT PUNICODE_STRING DriveLetter, } } - /* If caller didn't provide a letter, let's find one for him. - * If device is a floppy, start with letter A - */ + /* If caller didn't provide a letter, let's find one for him */ + if (RtlPrefixUnicodeString(&DeviceFloppy, DeviceName, TRUE)) { + /* If the device is a floppy, start with letter A */ Letter = 'A'; } + else if (RtlPrefixUnicodeString(&DeviceCdRom, DeviceName, TRUE)) + { + /* If the device is a CD-ROM, start with letter D */ + Letter = 'D'; + } else { - /* Otherwise, if device is a cd rom, then, start with D. - * Finally, if a disk, use C - */ - Letter = RtlPrefixUnicodeString(&DeviceCdRom, DeviceName, TRUE) + 'C'; + /* Finally, if it's a disk, use C */ + Letter = 'C'; } /* Try to affect a letter (up to Z, ofc) until it's possible */ diff --git a/reactos/drivers/filters/mountmgr/symlink.c b/reactos/drivers/filters/mountmgr/symlink.c index 99d5fa4977a..f5b76e69bc8 100644 --- a/reactos/drivers/filters/mountmgr/symlink.c +++ b/reactos/drivers/filters/mountmgr/symlink.c @@ -67,38 +67,35 @@ CreateStringWithGlobal(IN PUNICODE_STRING DosName, DosName->Length - DosDevices.Length); IntGlobal.Buffer[IntGlobal.Length / sizeof(WCHAR)] = UNICODE_NULL; } + else if (RtlPrefixUnicodeString(&Global, DosName, TRUE)) + { + /* Switch to DOS global */ + IntGlobal.Length = DosName->Length - Global.Length + DosGlobal.Length; + IntGlobal.MaximumLength = IntGlobal.Length + sizeof(WCHAR); + IntGlobal.Buffer = AllocatePool(IntGlobal.MaximumLength); + if (!IntGlobal.Buffer) + { + return STATUS_INSUFFICIENT_RESOURCES; + } + + RtlCopyMemory(IntGlobal.Buffer, DosGlobal.Buffer, DosGlobal.Length); + RtlCopyMemory(IntGlobal.Buffer + (DosGlobal.Length / sizeof(WCHAR)), + DosName->Buffer + (Global.Length / sizeof(WCHAR)), + DosName->Length - Global.Length); + IntGlobal.Buffer[IntGlobal.Length / sizeof(WCHAR)] = UNICODE_NULL; + } else { - if (RtlPrefixUnicodeString(&Global, DosName, TRUE)) + /* Simply duplicate string */ + IntGlobal.Length = DosName->Length; + IntGlobal.MaximumLength = DosName->MaximumLength; + IntGlobal.Buffer = AllocatePool(IntGlobal.MaximumLength); + if (!IntGlobal.Buffer) { - /* Switch to DOS global */ - IntGlobal.Length = DosName->Length - Global.Length + DosGlobal.Length; - IntGlobal.MaximumLength = IntGlobal.Length + sizeof(WCHAR); - IntGlobal.Buffer = AllocatePool(IntGlobal.MaximumLength); - if (!IntGlobal.Buffer) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - - RtlCopyMemory(IntGlobal.Buffer, DosGlobal.Buffer, DosGlobal.Length); - RtlCopyMemory(IntGlobal.Buffer + (DosGlobal.Length / sizeof(WCHAR)), - DosName->Buffer + (Global.Length / sizeof(WCHAR)), - DosName->Length - Global.Length); - IntGlobal.Buffer[IntGlobal.Length / sizeof(WCHAR)] = UNICODE_NULL; + return STATUS_INSUFFICIENT_RESOURCES; } - else - { - /* Simply duplicate string */ - IntGlobal.Length = DosName->Length; - IntGlobal.MaximumLength = DosName->MaximumLength; - IntGlobal.Buffer = AllocatePool(IntGlobal.MaximumLength); - if (!IntGlobal.Buffer) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - RtlCopyMemory(IntGlobal.Buffer, DosName->Buffer, IntGlobal.MaximumLength); - } + RtlCopyMemory(IntGlobal.Buffer, DosName->Buffer, IntGlobal.MaximumLength); } /* Return string */