aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/UefiShellUfmCommandLib/fs.c47
-rw-r--r--Library/UefiShellUfmCommandLib/fs.h30
2 files changed, 77 insertions, 0 deletions
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 <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/ShellLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/ShellCommandLib.h>
+
+#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 <Uefi.h>
+
+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 */