Skip to content

Commit 29a0ff7

Browse files
committed
[FREELDR] fs.c: Move the filesystem mount routines list into a table (reactos#7385)
This allows to make the code better extendable: adding a new FS mount routine into the table, instead of duplicating also a whole `if (!FileFuncTable) ...` check. Later, this table will be made dynamic, so that new filesystems could be dynamically registered at runtime, and a filesystem could be forced to be mounted by the user (using a specific syntax).
1 parent 3a7fe56 commit 29a0ff7

File tree

1 file changed

+28
-20
lines changed
  • boot/freeldr/freeldr/lib/fs

1 file changed

+28
-20
lines changed

boot/freeldr/freeldr/lib/fs/fs.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ typedef struct tagDEVICE
5151
static FILEDATA FileData[MAX_FDS];
5252
static LIST_ENTRY DeviceListHead;
5353

54+
typedef const DEVVTBL* (*PFS_MOUNT)(ULONG DeviceId);
55+
56+
PFS_MOUNT FileSystems[] =
57+
{
58+
#ifndef _M_ARM
59+
IsoMount,
60+
#endif
61+
FatMount,
62+
BtrFsMount,
63+
#ifndef _M_ARM
64+
NtfsMount,
65+
Ext2Mount,
66+
#endif
67+
#if defined(_M_IX86) || defined(_M_AMD64)
68+
#ifndef UEFIBOOT
69+
PxeMount,
70+
#endif
71+
#endif
72+
};
73+
74+
5475
/* ARC FUNCTIONS **************************************************************/
5576

5677
ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
@@ -146,28 +167,15 @@ ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
146167
}
147168

148169
/* Try to detect the file system */
149-
#ifndef _M_ARM
150-
FileData[DeviceId].FileFuncTable = IsoMount(DeviceId);
151-
if (!FileData[DeviceId].FileFuncTable)
152-
#endif
153-
FileData[DeviceId].FileFuncTable = FatMount(DeviceId);
154-
if (!FileData[DeviceId].FileFuncTable)
155-
FileData[DeviceId].FileFuncTable = BtrFsMount(DeviceId);
156-
#ifndef _M_ARM
157-
if (!FileData[DeviceId].FileFuncTable)
158-
FileData[DeviceId].FileFuncTable = NtfsMount(DeviceId);
159-
if (!FileData[DeviceId].FileFuncTable)
160-
FileData[DeviceId].FileFuncTable = Ext2Mount(DeviceId);
161-
#endif
162-
#if defined(_M_IX86) || defined(_M_AMD64)
163-
#ifndef UEFIBOOT
164-
if (!FileData[DeviceId].FileFuncTable)
165-
FileData[DeviceId].FileFuncTable = PxeMount(DeviceId);
166-
#endif
167-
#endif
170+
for (ULONG fs = 0; fs < _countof(FileSystems); ++fs)
171+
{
172+
FileData[DeviceId].FileFuncTable = FileSystems[fs](DeviceId);
173+
if (FileData[DeviceId].FileFuncTable)
174+
break;
175+
}
168176
if (!FileData[DeviceId].FileFuncTable)
169177
{
170-
/* Error, unable to detect file system */
178+
/* Error, unable to detect the file system */
171179
pDevice->FuncTable->Close(DeviceId);
172180
FileData[DeviceId].FuncTable = NULL;
173181
return ENODEV;

0 commit comments

Comments
 (0)