From 29a0ff73e67e1229c57bc98bdf9261d69e62d3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 26 Sep 2024 20:11:23 +0200 Subject: [PATCH] [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;