https://git.reactos.org/?p=reactos.git;a=commitdiff;h=29a0ff73e67e1229c57bc98bdf9261d69e62d3cf
commit 29a0ff73e67e1229c57bc98bdf9261d69e62d3cf Author: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> AuthorDate: Thu Sep 26 20:11:23 2024 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org> CommitDate: Tue Oct 1 22:13:51 2024 +0200 [FREELDR] fs.c: Move the filesystem mount routines list into a table (#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). --- boot/freeldr/freeldr/lib/fs/fs.c | 48 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/boot/freeldr/freeldr/lib/fs/fs.c b/boot/freeldr/freeldr/lib/fs/fs.c index 3326b1951d6..198982b0515 100644 --- a/boot/freeldr/freeldr/lib/fs/fs.c +++ b/boot/freeldr/freeldr/lib/fs/fs.c @@ -51,6 +51,27 @@ typedef struct tagDEVICE static FILEDATA FileData[MAX_FDS]; static LIST_ENTRY DeviceListHead; +typedef const DEVVTBL* (*PFS_MOUNT)(ULONG DeviceId); + +PFS_MOUNT FileSystems[] = +{ +#ifndef _M_ARM + IsoMount, +#endif + FatMount, + BtrFsMount, +#ifndef _M_ARM + NtfsMount, + Ext2Mount, +#endif +#if defined(_M_IX86) || defined(_M_AMD64) +#ifndef UEFIBOOT + PxeMount, +#endif +#endif +}; + + /* ARC FUNCTIONS **************************************************************/ ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId) @@ -146,28 +167,15 @@ ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId) } /* Try to detect the file system */ -#ifndef _M_ARM - FileData[DeviceId].FileFuncTable = IsoMount(DeviceId); - if (!FileData[DeviceId].FileFuncTable) -#endif - FileData[DeviceId].FileFuncTable = FatMount(DeviceId); - if (!FileData[DeviceId].FileFuncTable) - FileData[DeviceId].FileFuncTable = BtrFsMount(DeviceId); -#ifndef _M_ARM - if (!FileData[DeviceId].FileFuncTable) - FileData[DeviceId].FileFuncTable = NtfsMount(DeviceId); - if (!FileData[DeviceId].FileFuncTable) - FileData[DeviceId].FileFuncTable = Ext2Mount(DeviceId); -#endif -#if defined(_M_IX86) || defined(_M_AMD64) -#ifndef UEFIBOOT - if (!FileData[DeviceId].FileFuncTable) - FileData[DeviceId].FileFuncTable = PxeMount(DeviceId); -#endif -#endif + for (ULONG fs = 0; fs < _countof(FileSystems); ++fs) + { + FileData[DeviceId].FileFuncTable = FileSystems[fs](DeviceId); + if (FileData[DeviceId].FileFuncTable) + break; + } if (!FileData[DeviceId].FileFuncTable) { - /* Error, unable to detect file system */ + /* Error, unable to detect the file system */ pDevice->FuncTable->Close(DeviceId); FileData[DeviceId].FuncTable = NULL; return ENODEV;