[SETUPLIB][USETUP] Bring some suggestions from PR #59 in.

- Use OBJ_CASE_INSENSITIVE when initializing object attributes
  (no actual reason why to keep case sensitivity there).

- Check the success of a RtlStringCchPrintfW call in EnumerateReactOSEntries().

- Explicitly check for returned STATUS_NOT_SUPPORTED from ChkdskPartition()
  or FormatPartition(), and display an appropriate error message.

- Remove some left-over comments but also explain why I kept some
  commented code (mainly for future reference).
This commit is contained in:
Hermès Bélusca-Maïto 2017-12-23 20:17:38 +01:00
parent a7a11dd60d
commit 765994c9e3
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
7 changed files with 99 additions and 54 deletions

View file

@ -341,6 +341,7 @@ EnumerateReactOSEntries(
IN PBOOT_STORE_ENTRY BootEntry,
IN PVOID Parameter OPTIONAL)
{
NTSTATUS Status;
PENUM_REACTOS_ENTRIES_DATA Data = (PENUM_REACTOS_ENTRIES_DATA)Parameter;
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
WCHAR SystemPath[MAX_PATH];
@ -372,16 +373,19 @@ EnumerateReactOSEntries(
goto SkipThisEntry;
}
RtlStringCchPrintfW(SystemPath, ARRAYSIZE(SystemPath), L"\"%s\"", Data->ArcPath);
if ((_wcsicmp(Options->OsLoadPath, Data->ArcPath) != 0) &&
(_wcsicmp(Options->OsLoadPath, SystemPath) != 0))
if (_wcsicmp(Options->OsLoadPath, Data->ArcPath) != 0)
{
/*
* This entry is a ReactOS entry, but the SystemRoot
* does not match the one we are looking for.
*/
/* Continue the enumeration */
goto SkipThisEntry;
/* Not found, retry with a quoted path */
Status = RtlStringCchPrintfW(SystemPath, ARRAYSIZE(SystemPath), L"\"%s\"", Data->ArcPath);
if (!NT_SUCCESS(Status) || _wcsicmp(Options->OsLoadPath, SystemPath) != 0)
{
/*
* This entry is a ReactOS entry, but the SystemRoot
* does not match the one we are looking for.
*/
/* Continue the enumeration */
goto SkipThisEntry;
}
}
DPRINT1(" Found a candidate Win2k3 install '%S' with ARC path '%S'\n",
@ -668,10 +672,9 @@ SaveBootSector(
/* Write bootsector to DstPath */
RtlInitUnicodeString(&Name, DstPath);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@ -780,7 +783,6 @@ InstallMbrBootCodeToDiskHelper(
/* Read new bootsector from SrcPath */
RtlInitUnicodeString(&Name, SrcPath);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_CASE_INSENSITIVE,
@ -835,7 +837,7 @@ InstallMbrBootCodeToDiskHelper(
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@ -882,6 +884,12 @@ InstallMbrBootCodeToDisk(
WCHAR DstPath[MAX_PATH];
#if 0
/*
* The DestinationDevicePathBuffer parameter has been built with
* the following instruction by the caller; I'm not yet sure whether
* I actually want this function to build the path instead, hence
* I keep this code here but disabled for now...
*/
WCHAR DestinationDevicePathBuffer[MAX_PATH];
RtlStringCchPrintfW(DestinationDevicePathBuffer, ARRAYSIZE(DestinationDevicePathBuffer),
L"\\Device\\Harddisk%d\\Partition0",
@ -1038,7 +1046,7 @@ InstallFat12BootCodeToFloppy(
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@ -1127,6 +1135,7 @@ InstallFat16BootCode(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&FileHandle,
GENERIC_READ | SYNCHRONIZE,
&ObjectAttributes,
@ -1211,6 +1220,7 @@ InstallFat16BootCodeToFile(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&PartitionHandle,
GENERIC_READ | SYNCHRONIZE,
&ObjectAttributes,
@ -1224,9 +1234,10 @@ InstallFat16BootCodeToFile(
RtlInitUnicodeString(&Name, DstPath);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0, // OBJ_CASE_INSENSITIVE,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtCreateFile(&FileHandle,
GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
@ -1280,6 +1291,7 @@ InstallFat16BootCodeToDisk(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&PartitionHandle,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
@ -1353,6 +1365,7 @@ InstallFat32BootCode(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&FileHandle,
GENERIC_READ | SYNCHRONIZE,
&ObjectAttributes,
@ -1503,6 +1516,7 @@ InstallFat32BootCodeToFile(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&PartitionHandle,
GENERIC_READ | SYNCHRONIZE,
&ObjectAttributes,
@ -1516,9 +1530,10 @@ InstallFat32BootCodeToFile(
RtlInitUnicodeString(&Name, DstPath);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0, // OBJ_CASE_INSENSITIVE,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtCreateFile(&FileHandle,
GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
@ -1572,6 +1587,7 @@ InstallFat32BootCodeToDisk(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&PartitionHandle,
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
&ObjectAttributes,
@ -1721,7 +1737,7 @@ InstallBtrfsBootCodeToDisk(
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);

View file

@ -34,9 +34,11 @@
FILE_SYSTEM RegisteredFileSystems[] =
{
/* NOTE: The FAT formatter automatically determines
* whether it will use FAT-16 or FAT-32. */
{ L"FAT" , VfatFormat, VfatChkdsk },
// { L"FAT32", VfatFormat, VfatChkdsk },
#if 0
{ L"FAT32", VfatFormat, VfatChkdsk }, // Do we support specific FAT sub-formats specifications?
{ L"FATX" , VfatxFormat, VfatxChkdsk },
{ L"NTFS" , NtfsFormat, NtfsChkdsk },

View file

@ -212,8 +212,8 @@ InstallSetupInfFile(
PINICACHE UnattendCache;
PINICACHEITERATOR Iterator;
#else
// PCWSTR CrLf = L"\r\n";
PCSTR CrLf = "\r\n";
// WCHAR CrLf[] = {L'\r', L'\n'};
CHAR CrLf[] = {'\r', '\n'};
HANDLE FileHandle, UnattendFileHandle, SectionHandle;
FILE_STANDARD_INFORMATION FileInfo;
ULONG FileSize;
@ -360,7 +360,7 @@ Quit:
NULL,
&IoStatusBlock,
(PVOID)CrLf,
2 * sizeof(CHAR), // 2 * sizeof(WCHAR),
sizeof(CrLf),
&FileInfo.EndOfFile,
NULL);

View file

@ -135,7 +135,6 @@ SetupCopyFile(
LARGE_INTEGER ByteOffset;
RtlInitUnicodeString(&FileName, SourceFileName);
InitializeObjectAttributes(&ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
@ -206,7 +205,6 @@ SetupCopyFile(
}
RtlInitUnicodeString(&FileName, DestinationFileName);
InitializeObjectAttributes(&ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
@ -594,7 +592,6 @@ DoesPathExist(
IO_STATUS_BLOCK IoStatusBlock;
RtlInitUnicodeString(&Name, PathName);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
OBJ_CASE_INSENSITIVE,
@ -756,7 +753,6 @@ OpenAndMapFile(
/* Open the file */
RtlInitUnicodeString(&FileName, PathNameToFile);
InitializeObjectAttributes(&ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,

View file

@ -1249,7 +1249,7 @@ CreatePartitionList(VOID)
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@ -2777,9 +2777,10 @@ WritePartitions(
L"\\Device\\Harddisk%lu\\Partition0",
DiskEntry->DiskNumber);
RtlInitUnicodeString(&Name, DstPath);
InitializeObjectAttributes(&ObjectAttributes,
&Name,
0,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
@ -2882,6 +2883,7 @@ SetMountedDeviceValue(
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenKey(&KeyHandle,
KEY_ALL_ACCESS,
&ObjectAttributes);

View file

@ -107,7 +107,7 @@ InstallDriver(
/* Create service key */
RtlInitUnicodeString(&StringU, Driver);
InitializeObjectAttributes(&ObjectAttributes, &StringU, 0, hServices, NULL);
InitializeObjectAttributes(&ObjectAttributes, &StringU, OBJ_CASE_INSENSITIVE, hServices, NULL);
Status = NtCreateKey(&hService, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition);
if (!NT_SUCCESS(Status))
{
@ -218,7 +218,7 @@ InstallDevice(
NTSTATUS Status;
RtlInitUnicodeString(&DeviceIdU, DeviceId);
InitializeObjectAttributes(&ObjectAttributes, &DeviceIdU, 0, hEnum, NULL);
InitializeObjectAttributes(&ObjectAttributes, &DeviceIdU, OBJ_CASE_INSENSITIVE, hEnum, NULL);
Status = NtOpenKey(&hDeviceKey, KEY_QUERY_VALUE | KEY_SET_VALUE, &ObjectAttributes);
if (!NT_SUCCESS(Status))
{

View file

@ -2915,12 +2915,13 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
static PAGE_NUMBER
FormatPartitionPage(PINPUT_RECORD Ir)
{
UNICODE_STRING PartitionRootPath;
WCHAR PathBuffer[MAX_PATH];
NTSTATUS Status;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PFILE_SYSTEM_ITEM SelectedFileSystem;
NTSTATUS Status;
UNICODE_STRING PartitionRootPath;
WCHAR PathBuffer[MAX_PATH];
CHAR Buffer[MAX_PATH];
#ifndef NDEBUG
ULONG Line;
@ -3016,7 +3017,38 @@ FormatPartitionPage(PINPUT_RECORD Ir)
{
Status = FormatPartition(&PartitionRootPath,
SelectedFileSystem);
if (!NT_SUCCESS(Status))
if (Status == STATUS_NOT_SUPPORTED)
{
sprintf(Buffer,
"Setup is currently unable to format a partition in %S.\n"
"\n"
" \x07 Press ENTER to continue Setup.\n"
" \x07 Press F3 to quit Setup.",
SelectedFileSystem->FileSystem->FileSystemName);
PopupError(Buffer,
MUIGetString(STRING_QUITCONTINUE),
NULL, POPUP_WAIT_NONE);
while (TRUE)
{
CONSOLE_ConInKey(Ir);
if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x00 &&
Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3) /* F3 */
{
if (ConfirmQuit(Ir))
return QUIT_PAGE;
else
return SELECT_FILE_SYSTEM_PAGE;
}
else if (Ir->Event.KeyEvent.uChar.AsciiChar == VK_RETURN) /* ENTER */
{
return SELECT_FILE_SYSTEM_PAGE;
}
}
}
else if (!NT_SUCCESS(Status))
{
DPRINT1("FormatPartition() failed with status 0x%08lx\n", Status);
MUIDisplayError(ERROR_FORMATTING_PARTITION, Ir, POPUP_WAIT_ANY_KEY, PathBuffer);
@ -3057,13 +3089,13 @@ FormatPartitionPage(PINPUT_RECORD Ir)
static PAGE_NUMBER
CheckFileSystemPage(PINPUT_RECORD Ir)
{
NTSTATUS Status;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PFILE_SYSTEM CurrentFileSystem;
UNICODE_STRING PartitionRootPath;
WCHAR PathBuffer[MAX_PATH];
CHAR Buffer[MAX_PATH];
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
NTSTATUS Status;
if (PartitionList == NULL)
{
@ -3099,7 +3131,8 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
return CHECK_FILE_SYSTEM_PAGE;
}
if (CurrentFileSystem->ChkdskFunc == NULL)
Status = ChkdskPartition(&PartitionRootPath, CurrentFileSystem);
if (Status == STATUS_NOT_SUPPORTED)
{
sprintf(Buffer,
"Setup is currently unable to check a partition formatted in %S.\n"
@ -3131,26 +3164,22 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
}
}
}
else
else if (!NT_SUCCESS(Status))
{
Status = ChkdskPartition(&PartitionRootPath, CurrentFileSystem);
if (!NT_SUCCESS(Status))
{
DPRINT("ChkdskPartition() failed with status 0x%08lx\n", Status);
// sprintf(Buffer, "Setup failed to verify the selected partition.\n"
sprintf(Buffer, "ChkDsk detected some disk errors.\n"
"(Status 0x%08lx).\n", Status);
PopupError(Buffer,
// MUIGetString(STRING_REBOOTCOMPUTER),
MUIGetString(STRING_CONTINUE),
Ir, POPUP_WAIT_ENTER);
DPRINT("ChkdskPartition() failed with status 0x%08lx\n", Status);
// sprintf(Buffer, "Setup failed to verify the selected partition.\n"
sprintf(Buffer, "ChkDsk detected some disk errors.\n"
"(Status 0x%08lx).\n", Status);
PopupError(Buffer,
// MUIGetString(STRING_REBOOTCOMPUTER),
MUIGetString(STRING_CONTINUE),
Ir, POPUP_WAIT_ENTER);
// return QUIT_PAGE;
}
PartEntry->NeedsCheck = FALSE;
return CHECK_FILE_SYSTEM_PAGE;
// return QUIT_PAGE;
}
PartEntry->NeedsCheck = FALSE;
return CHECK_FILE_SYSTEM_PAGE;
}