setos

拙OS
Log | Files | Refs | LICENSE

commit f2ea84ec00be847a393feb278064e9c521fb5dbe
parent 5e3ca3195da872d5ea0eedcc00522943de8af276
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 21 Mar 2024 16:30:52 +0900

write to test file

Diffstat:
Mloader.c | 26++++++++++++++++++++++++--
Muefi.h | 4++++
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/loader.c b/loader.c @@ -30,6 +30,7 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) mmap = (EFI_MEMORY_DESCRIPTOR *) mmbuf; stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver); if (stat != EFI_SUCCESS) { + efi_printf("get memory map: %d\n", stat); return stat; } @@ -42,9 +43,30 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) mmap->PhysicalStart, mmap->NumberOfPages, mmap->Attribute); } - EFI_FILE_PROTOCOL *root; + EFI_FILE_PROTOCOL *root, *test; stat = open_root(ImageHandle, &root); - efi_printf("open_root: %d\n", stat); + if (stat != EFI_SUCCESS) { + efi_printf("open_root: %d\n", stat); + return stat; + } + stat = root->Open(root, &test, L"test", + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + if (stat != EFI_SUCCESS) { + efi_printf("open file \"test\": %d\n", stat); + return stat; + } + char buf[10] = "01234567"; + UINTN bufsize = 10; + stat = test->Write(test, &bufsize, buf); + if (stat != EFI_SUCCESS) { + efi_printf("write to file: %d\n", stat); + return stat; + } + stat = test->Close(test); + if (stat != EFI_SUCCESS) { + efi_printf("close file: %d\n", stat); + return stat; + } // Echo back user input. EFI_INPUT_KEY Key; diff --git a/uefi.h b/uefi.h @@ -113,6 +113,10 @@ EFI_STATUS (EFIAPI *EFI_FILE_OPEN) ( IN UINT64 Attributes ); +#define EFI_FILE_MODE_READ 0x0000000000000001 +#define EFI_FILE_MODE_WRITE 0x0000000000000002 +#define EFI_FILE_MODE_CREATE 0x8000000000000000 + typedef EFI_STATUS (EFIAPI *EFI_FILE_CLOSE) ( IN EFI_FILE_PROTOCOL *This