[USETUP] Display the chosen filesystem name in case of bootcode installation failure.
[reactos.git] / base / setup / usetup / fslist.c
index 0b190d4..6aa8c4e 100644 (file)
@@ -21,8 +21,7 @@
  * PROJECT:         ReactOS text-mode setup
  * FILE:            base/setup/usetup/fslist.c
  * PURPOSE:         Filesystem list functions
- * PROGRAMMER:      Eric Kohl
- *                  Casper S. Hornstrup (chorns@users.sourceforge.net)
+ * PROGRAMMER:      Casper S. Hornstrup (chorns@users.sourceforge.net)
  */
 
 #include "usetup.h"
 
 /* FUNCTIONS ****************************************************************/
 
-VOID
+static VOID
 AddProvider(
     IN OUT PFILE_SYSTEM_LIST List,
-    IN LPCWSTR FileSystemName,
-    IN FORMATEX FormatFunc,
-    IN CHKDSKEX ChkdskFunc)
+    IN PCWSTR FileSystemName, // Redundant, I need to check whether this is reaaaaally needed....
+    IN PFILE_SYSTEM FileSystem)
 {
     PFILE_SYSTEM_ITEM Item;
 
-    Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
+    Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item));
     if (!Item)
         return;
 
     Item->FileSystemName = FileSystemName;
-    Item->FormatFunc = FormatFunc;
-    Item->ChkdskFunc = ChkdskFunc;
+    Item->FileSystem = FileSystem;
     Item->QuickFormat = TRUE;
     InsertTailList(&List->ListHead, &Item->ListEntry);
 
-    if (!FormatFunc)
+    if (!FileSystem)
         return;
 
-    Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
+    Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item));
     if (!Item)
         return;
 
     Item->FileSystemName = FileSystemName;
-    Item->FormatFunc = FormatFunc;
-    Item->ChkdskFunc = ChkdskFunc;
+    Item->FileSystem = FileSystem;
     Item->QuickFormat = FALSE;
     InsertTailList(&List->ListHead, &Item->ListEntry);
 }
 
-
-PFILE_SYSTEM_ITEM
-GetFileSystemByName(
-    IN PFILE_SYSTEM_LIST List,
-    IN LPWSTR FileSystemName)
-{
-    PLIST_ENTRY ListEntry;
-    PFILE_SYSTEM_ITEM Item;
-
-    ListEntry = List->ListHead.Flink;
-    while (ListEntry != &List->ListHead)
-    {
-        Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
-        if (Item->FileSystemName && wcsicmp(FileSystemName, Item->FileSystemName) == 0)
-            return Item;
-
-        ListEntry = ListEntry->Flink;
-    }
-
-    return NULL;
-}
-
-
-PFILE_SYSTEM_ITEM
-GetFileSystem(
-    IN PFILE_SYSTEM_LIST FileSystemList,
-    IN struct _PARTENTRY* PartEntry)
+static VOID
+InitializeFileSystemList(
+    IN PFILE_SYSTEM_LIST List)
 {
-    PFILE_SYSTEM_ITEM CurrentFileSystem;
-    LPWSTR FileSystemName = NULL;
-
-    CurrentFileSystem = PartEntry->FileSystem;
-
-    /* We have a file system, return it */
-    if (CurrentFileSystem != NULL && CurrentFileSystem->FileSystemName != NULL)
-        return CurrentFileSystem;
+    ULONG Count;
+    PFILE_SYSTEM FileSystems;
 
-    DPRINT1("File system not found, try to guess one...\n");
-
-    CurrentFileSystem = NULL;
+    FileSystems = GetRegisteredFileSystems(&Count);
+    if (!FileSystems || Count == 0)
+        return;
 
-    /*
-     * We don't have one...
-     *
-     * Try to infer a preferred file system for this partition, given its ID.
-     *
-     * WARNING: This is partly a hack, since partitions with the same ID can
-     * be formatted with different file systems: for example, usual Linux
-     * partitions that are formatted in EXT2/3/4, ReiserFS, etc... have the
-     * same partition ID 0x83.
-     *
-     * The proper fix is to make a function that detects the existing FS
-     * from a given partition (not based on the partition ID).
-     * On the contrary, for unformatted partitions with a given ID, the
-     * following code is OK.
-     */
-    if ((PartEntry->PartitionType == PARTITION_FAT_12) ||
-        (PartEntry->PartitionType == PARTITION_FAT_16) ||
-        (PartEntry->PartitionType == PARTITION_HUGE  ) ||
-        (PartEntry->PartitionType == PARTITION_XINT13) ||
-        (PartEntry->PartitionType == PARTITION_FAT32 ) ||
-        (PartEntry->PartitionType == PARTITION_FAT32_XINT13))
+    while (Count--)
     {
-        FileSystemName = L"FAT";
+        AddProvider(List, FileSystems->FileSystemName, FileSystems);
+        ++FileSystems;
     }
-    else if (PartEntry->PartitionType == PARTITION_EXT2)
-    {
-        // WARNING: See the warning above.
-        FileSystemName = L"EXT2";
-    }
-    else if (PartEntry->PartitionType == PARTITION_IFS)
-    {
-        // WARNING: See the warning above.
-        FileSystemName = L"NTFS"; /* FIXME: Not quite correct! */
-    }
-
-    // HACK: WARNING: We cannot write on this FS yet!
-    if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS)
-        DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName);
-
-    DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed): %S\n",
-            PartEntry->PartitionType, FileSystemName);
-
-    if (FileSystemName != NULL)
-        CurrentFileSystem = GetFileSystemByName(FileSystemList, FileSystemName);
-
-    return CurrentFileSystem;
 }
 
-
 PFILE_SYSTEM_LIST
 CreateFileSystemList(
     IN SHORT Left,
     IN SHORT Top,
     IN BOOLEAN ForceFormat,
-    IN LPCWSTR ForceFileSystem)
+    IN PCWSTR SelectFileSystem)
 {
     PFILE_SYSTEM_LIST List;
     PFILE_SYSTEM_ITEM Item;
     PLIST_ENTRY ListEntry;
 
-    List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST));
+    List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(*List));
     if (List == NULL)
         return NULL;
 
@@ -175,24 +99,19 @@ CreateFileSystemList(
     List->Selected = NULL;
     InitializeListHead(&List->ListHead);
 
-    AddProvider(List, L"FAT", VfatFormat, VfatChkdsk);
-#if 0
-    AddProvider(List, L"EXT2", Ext2Format, Ext2Chkdsk);
-    AddProvider(List, L"NTFS", NtfsFormat, NtfsChkdsk);
-#endif
-
+    InitializeFileSystemList(List);
     if (!ForceFormat)
     {
-        /* Add 'Keep' provider */
-        AddProvider(List, NULL, NULL, NULL);
+        /* Add the 'Keep existing filesystem' dummy provider */
+        AddProvider(List, NULL, NULL);
     }
 
-    /* Search for ForceFileSystem in list */
+    /* Search for SelectFileSystem in list */
     ListEntry = List->ListHead.Flink;
     while (ListEntry != &List->ListHead)
     {
         Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
-        if (Item->FileSystemName && wcscmp(ForceFileSystem, Item->FileSystemName) == 0)
+        if (Item->FileSystemName && wcscmp(SelectFileSystem, Item->FileSystemName) == 0)
         {
             List->Selected = Item;
             break;
@@ -205,28 +124,24 @@ CreateFileSystemList(
     return List;
 }
 
-
 VOID
 DestroyFileSystemList(
     IN PFILE_SYSTEM_LIST List)
 {
-    PLIST_ENTRY ListEntry = List->ListHead.Flink;
+    PLIST_ENTRY ListEntry;
     PFILE_SYSTEM_ITEM Item;
-    PLIST_ENTRY Next;
 
-    while (ListEntry != &List->ListHead)
+    ListEntry = List->ListHead.Flink;
+    while (!IsListEmpty(&List->ListHead))
     {
+        ListEntry = RemoveHeadList(&List->ListHead);
         Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
-        Next = ListEntry->Flink;
-
         RtlFreeHeap(ProcessHeap, 0, Item);
-
-        ListEntry = Next;
     }
+
     RtlFreeHeap(ProcessHeap, 0, List);
 }
 
-
 VOID
 DrawFileSystemList(
     IN PFILE_SYSTEM_LIST List)
@@ -264,7 +179,9 @@ DrawFileSystemList(
                 snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2), Item->FileSystemName);
         }
         else
+        {
             snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT));
+        }
 
         if (ListEntry == &List->Selected->ListEntry)
             CONSOLE_SetInvertedTextXY(List->Left,
@@ -279,7 +196,6 @@ DrawFileSystemList(
     }
 }
 
-
 VOID
 ScrollDownFileSystemList(
     IN PFILE_SYSTEM_LIST List)
@@ -291,7 +207,6 @@ ScrollDownFileSystemList(
     }
 }
 
-
 VOID
 ScrollUpFileSystemList(
     IN PFILE_SYSTEM_LIST List)