From b9c0d81eac650a2b1df7d3cafe0d41caed33421f Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 17 Nov 2021 19:25:43 +0300 Subject: add routines to get filesystems --- Library/UefiShellUfmCommandLib/fs.c | 47 +++++++++++++++++++++++++++++++++++++ Library/UefiShellUfmCommandLib/fs.h | 30 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Library/UefiShellUfmCommandLib/fs.c create mode 100644 Library/UefiShellUfmCommandLib/fs.h diff --git a/Library/UefiShellUfmCommandLib/fs.c b/Library/UefiShellUfmCommandLib/fs.c new file mode 100644 index 0000000..edde591 --- /dev/null +++ b/Library/UefiShellUfmCommandLib/fs.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include + +#include "fs.h" + +struct fs_array *fsa_alloc(EFI_HANDLE *handles, UINTN count) +{ + UINTN i; + struct fs_array *fsa; + EFI_DEVICE_PATH_PROTOCOL *dev_path; + CONST CHAR16 *map_list; + + fsa = AllocatePool(sizeof(struct fs_array)); + if(!fsa) + return NULL; + + fsa->full_name = AllocateZeroPool(count * sizeof(CHAR16 *)); + if(!fsa->full_name) { + fsa_release(fsa); + return NULL; + } + + fsa->len = count; + for(i = 0; i < count; i++) { + dev_path = DevicePathFromHandle(handles[i]); + map_list = gEfiShellProtocol->GetMapFromDevicePath(&dev_path); + } + + return fsa; +} + +VOID fsa_release(struct fs_array *fsa) +{ + UINTN i; + if(fsa->full_name) { + for(i = 0; i < fsa->len; i++) { + if(fsa->full_name[i]) // safety measure and our good sleep + FreePool(fsa->full_name[i]); + } + FreePool(fsa->full_name); + } + FreePool(fsa); +} diff --git a/Library/UefiShellUfmCommandLib/fs.h b/Library/UefiShellUfmCommandLib/fs.h new file mode 100644 index 0000000..f7625b1 --- /dev/null +++ b/Library/UefiShellUfmCommandLib/fs.h @@ -0,0 +1,30 @@ +#ifndef UFM_FS_H +#define UFM_FS_H + +#include + +struct fs_array { + CHAR16 **full_name; + int len; // number of elements in array +}; + +/* + * Gets the mapped names of the filesystems + * + * handles: a pointer to the buffer to array of handles that support Simple FS Protocol + * count: the number of handles + * + * return: A pointer to the allocated structure or NULL if allocation fails +*/ +struct fs_array *fsa_alloc(EFI_HANDLE *handles, UINTN count); + +/* + * Deletes the array of filesystems, frees the structure + * + * fsa: the pointer to the array of filesystems + * + * return: VOID +*/ +VOID fsa_release(struct fs_array *fsa); + +#endif /* UFM_FS_H */ -- cgit v1.2.3-18-g5258