From 40e7b29af85af541967a18a24421e6d3b7a6ee04 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Fri, 8 Dec 2023 19:29:10 +0100 Subject: [PATCH] Implement BlpLoadConfigurationFile() routine --- xtldr2/config.c | 57 +++++++++++++++++++++++++++++++++++++++ xtldr2/includes/bootman.h | 6 +++++ 2 files changed, 63 insertions(+) diff --git a/xtldr2/config.c b/xtldr2/config.c index 45869f5..0ff3e73 100644 --- a/xtldr2/config.c +++ b/xtldr2/config.c @@ -9,6 +9,63 @@ #include +/** + * Loads configuration file from the specified directory on the FS0:/ drive. + * + * @param ConfigDirectory + * Specifies a path to the directory containing the configuration file. + * + * @param ConfigFile + * Specifies the name of the configuration file. + * + * @param ConfigData + * Provides a buffer to store the data read from the configuration file. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlpLoadConfigurationFile(IN CONST PWCHAR ConfigDirectory, + IN CONST PWCHAR ConfigFile, + OUT PCHAR *ConfigData) +{ + PEFI_FILE_HANDLE DirHandle, FsHandle; + EFI_HANDLE DiskHandle; + EFI_STATUS Status; + SIZE_T FileSize; + + /* Open EFI volume */ + Status = BlOpenVolume(NULL, &DiskHandle, &FsHandle); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to open a volume */ + return Status; + } + + /* Open specified directory, containing the configuration file and close the FS immediately */ + Status = FsHandle->Open(FsHandle, &DirHandle, ConfigDirectory, EFI_FILE_MODE_READ, 0); + FsHandle->Close(FsHandle); + + /* Check if directory opened successfully */ + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to open directory */ + BlCloseVolume(DiskHandle); + return Status; + } + + /* Read configuration file */ + Status = BlReadFile(DirHandle, ConfigFile, (PVOID *)ConfigData, &FileSize); + + /* Close EFI volume */ + BlCloseVolume(DiskHandle); + + /* Return read status */ + return STATUS_EFI_SUCCESS; +} + /** * Parses command line arguments and updates global configuration. * diff --git a/xtldr2/includes/bootman.h b/xtldr2/includes/bootman.h index cedf062..07aa835 100644 --- a/xtldr2/includes/bootman.h +++ b/xtldr2/includes/bootman.h @@ -141,6 +141,12 @@ BlpFindParentBlockDevice(IN PLIST_ENTRY BlockDevices, IN PEFI_BLOCK_DEVICE_DATA ChildNode, OUT PEFI_BLOCK_DEVICE_DATA ParentNode); +XTCDECL +EFI_STATUS +BlpLoadConfigurationFile(IN CONST PWCHAR ConfigDirectory, + IN CONST PWCHAR ConfigFile, + OUT PCHAR *ConfigData); + XTCDECL VOID BlpParseCommandLineOptions(VOID);