From b5f79593de3e80a62f709f0130724dab218b9da4 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 8 Oct 2006 21:16:20 +0000 Subject: [PATCH] - Optimize IopApplyRosCdromArcHack by not searching for the second copy of ntoskrnl if we already found the first. - Also optimize stack usage by only using an ANSI buffer instead of having another Unicode buffer and unicode strings. Saves 530 bytes of stack. svn path=/trunk/; revision=24457 --- reactos/ntoskrnl/io/iomgr/arcname.c | 64 ++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/reactos/ntoskrnl/io/iomgr/arcname.c b/reactos/ntoskrnl/io/iomgr/arcname.c index 85f0a5d7b9f..f3ed85b48b8 100644 --- a/reactos/ntoskrnl/io/iomgr/arcname.c +++ b/reactos/ntoskrnl/io/iomgr/arcname.c @@ -28,9 +28,9 @@ IopApplyRosCdromArcHack(IN ULONG i) { ULONG DeviceNumber = -1; OBJECT_ATTRIBUTES ObjectAttributes; + ANSI_STRING InstallName; UNICODE_STRING DeviceName; - WCHAR Buffer[MAX_PATH]; - CHAR AnsiBuffer[MAX_PATH]; + CHAR Buffer[MAX_PATH]; FILE_BASIC_INFORMATION FileInfo; NTSTATUS Status; PCHAR p, q; @@ -39,29 +39,53 @@ IopApplyRosCdromArcHack(IN ULONG i) p = strstr(KeLoaderBlock->ArcBootDeviceName, "cdrom"); if (p) { - /* Try to find the installer */ - swprintf(Buffer, L"\\Device\\CdRom%lu\\reactos\\ntoskrnl.exe", i); - RtlInitUnicodeString(&DeviceName, Buffer); - InitializeObjectAttributes(&ObjectAttributes, - &DeviceName, - 0, - NULL, - NULL); - Status = ZwQueryAttributesFile(&ObjectAttributes, &FileInfo); - if (NT_SUCCESS(Status)) DeviceNumber = i; + /* Build installer name */ + sprintf(Buffer, "\\Device\\CdRom%lu\\reactos\\ntoskrnl.exe", i); + RtlInitAnsiString(&InstallName, Buffer); + Status = RtlAnsiStringToUnicodeString(&DeviceName, &InstallName, TRUE); + if (!NT_SUCCESS(Status)) return FALSE; - /* Try to find live CD boot */ - swprintf(Buffer, - L"\\Device\\CdRom%lu\\reactos\\system32\\ntoskrnl.exe", - i); - RtlInitUnicodeString(&DeviceName, Buffer); + /* Try to find the installer */ InitializeObjectAttributes(&ObjectAttributes, &DeviceName, 0, NULL, NULL); Status = ZwQueryAttributesFile(&ObjectAttributes, &FileInfo); - if (NT_SUCCESS(Status)) DeviceNumber = i; + + /* Free the string */ + RtlFreeUnicodeString(&DeviceName); + + /* Check if we found the file */ + if (NT_SUCCESS(Status)) + { + /* We did, save the device number */ + DeviceNumber = i; + } + else + { + /* Build live CD kernel name */ + sprintf(Buffer, + "\\Device\\CdRom%lu\\reactos\\system32\\ntoskrnl.exe", + i); + RtlInitAnsiString(&InstallName, Buffer); + Status = RtlAnsiStringToUnicodeString(&DeviceName, + &InstallName, + TRUE); + if (!NT_SUCCESS(Status)) return FALSE; + + /* Try to find it */ + InitializeObjectAttributes(&ObjectAttributes, + &DeviceName, + 0, + NULL, + NULL); + Status = ZwQueryAttributesFile(&ObjectAttributes, &FileInfo); + if (NT_SUCCESS(Status)) DeviceNumber = i; + + /* Free the string */ + RtlFreeUnicodeString(&DeviceName); + } /* Build the name */ sprintf(p, "cdrom(%lu)", DeviceNumber); @@ -71,9 +95,9 @@ IopApplyRosCdromArcHack(IN ULONG i) if (q) { q++; - strcpy(AnsiBuffer, q); + strcpy(Buffer, q); sprintf(p, "cdrom(%lu)", DeviceNumber); - strcat(p, AnsiBuffer); + strcat(p, Buffer); } }