https://git.reactos.org/?p=reactos.git;a=commitdiff;h=765994c9e34fc60b3b4f084cae8a3af1d7ef60c4

commit 765994c9e34fc60b3b4f084cae8a3af1d7ef60c4
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Dec 23 20:17:38 2017 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Oct 28 01:08:57 2018 +0200

    [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).
---
 base/setup/lib/bootsup.c        | 50 +++++++++++++++++---------
 base/setup/lib/fsutil.c         |  4 ++-
 base/setup/lib/setuplib.c       |  6 ++--
 base/setup/lib/utils/filesup.c  |  4 ---
 base/setup/lib/utils/partlist.c |  6 ++--
 base/setup/usetup/devinst.c     |  4 +--
 base/setup/usetup/usetup.c      | 79 ++++++++++++++++++++++++++++-------------
 7 files changed, 99 insertions(+), 54 deletions(-)

diff --git a/base/setup/lib/bootsup.c b/base/setup/lib/bootsup.c
index 5f0f694779..3059d0c884 100644
--- a/base/setup/lib/bootsup.c
+++ b/base/setup/lib/bootsup.c
@@ -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);
 
diff --git a/base/setup/lib/fsutil.c b/base/setup/lib/fsutil.c
index db1f3073be..2fb61bf0ea 100644
--- a/base/setup/lib/fsutil.c
+++ b/base/setup/lib/fsutil.c
@@ -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 },
 
diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c
index 38d5b58f1f..2d9a6bba80 100644
--- a/base/setup/lib/setuplib.c
+++ b/base/setup/lib/setuplib.c
@@ -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);
 
diff --git a/base/setup/lib/utils/filesup.c b/base/setup/lib/utils/filesup.c
index 61cc1b4c5e..7755ad38fc 100644
--- a/base/setup/lib/utils/filesup.c
+++ b/base/setup/lib/utils/filesup.c
@@ -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,
diff --git a/base/setup/lib/utils/partlist.c b/base/setup/lib/utils/partlist.c
index d9aa3b8469..6976e1ee97 100644
--- a/base/setup/lib/utils/partlist.c
+++ b/base/setup/lib/utils/partlist.c
@@ -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);
diff --git a/base/setup/usetup/devinst.c b/base/setup/usetup/devinst.c
index 3a8dec424d..15483a31d0 100644
--- a/base/setup/usetup/devinst.c
+++ b/base/setup/usetup/devinst.c
@@ -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))
     {
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index b9ba8eea2f..35d83ab2a5 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -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);
-
-            // return QUIT_PAGE;
-        }
+        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);
 
-        PartEntry->NeedsCheck = FALSE;
-        return CHECK_FILE_SYSTEM_PAGE;
+        // return QUIT_PAGE;
     }
+
+    PartEntry->NeedsCheck = FALSE;
+    return CHECK_FILE_SYSTEM_PAGE;
 }
 
 

Reply via email to