efi: add file_handle_read() helper that reads from a file handle

This commit is contained in:
Lennart Poettering
2024-09-02 14:20:49 +02:00
parent 4c4f6b9d40
commit 82d40110ae
2 changed files with 26 additions and 10 deletions
+25 -10
View File
@@ -105,26 +105,19 @@ EFI_STATUS chunked_read(EFI_FILE *file, size_t *size, void *buf) {
return EFI_SUCCESS;
}
EFI_STATUS file_read(
EFI_FILE *dir,
const char16_t *name,
EFI_STATUS file_handle_read(
EFI_FILE *handle,
uint64_t offset,
size_t size,
char **ret,
size_t *ret_size) {
_cleanup_(file_closep) EFI_FILE *handle = NULL;
_cleanup_free_ char *buf = NULL;
EFI_STATUS err;
assert(dir);
assert(name);
assert(handle);
assert(ret);
err = dir->Open(dir, &handle, (char16_t*) name, EFI_FILE_MODE_READ, 0ULL);
if (err != EFI_SUCCESS)
return err;
if (size == 0) {
_cleanup_free_ EFI_FILE_INFO *info = NULL;
@@ -165,6 +158,28 @@ EFI_STATUS file_read(
return err;
}
EFI_STATUS file_read(
EFI_FILE *dir,
const char16_t *name,
uint64_t offset,
size_t size,
char **ret,
size_t *ret_size) {
EFI_STATUS err;
assert(dir);
assert(name);
assert(ret);
_cleanup_(file_closep) EFI_FILE *handle = NULL;
err = dir->Open(dir, &handle, (char16_t*) name, EFI_FILE_MODE_READ, 0ULL);
if (err != EFI_SUCCESS)
return err;
return file_handle_read(handle, offset, size, ret, ret_size);
}
void print_at(size_t x, size_t y, size_t attr, const char16_t *str) {
assert(str);
ST->ConOut->SetCursorPosition(ST->ConOut, x, y);
+1
View File
@@ -87,6 +87,7 @@ char16_t *mangle_stub_cmdline(char16_t *cmdline);
EFI_STATUS chunked_read(EFI_FILE *file, size_t *size, void *buf);
EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, uint64_t offset, size_t size, char **content, size_t *content_size);
EFI_STATUS file_handle_read(EFI_FILE *handle, uint64_t offset, size_t size, char **ret, size_t *ret_size);
static inline void file_closep(EFI_FILE **handle) {
if (!*handle)