static int efifs_readdir(struct open_file *f, struct dirent *d) { EFI_FILE *file = f->f_fsdata; union fileinfo fi; EFI_STATUS status; UINTN sz; int i; if (file == NULL) return (EBADF); sz = sizeof(fi); status = file->Read(file, &sz, &fi); if (EFI_ERROR(status)) return (efi_status_to_errno(status)); if (sz == 0) return (ENOENT); d->d_fileno = 0; d->d_reclen = sizeof(*d); if (fi.info.Attribute & EFI_FILE_DIRECTORY) d->d_type = DT_DIR; else d->d_type = DT_REG; for (i = 0; fi.info.FileName[i] != 0; i++) d->d_name[i] = fi.info.FileName[i]; d->d_name[i] = 0; d->d_namlen = i; return (0); }
EFI_STATUS readFile( IN EFI_FILE *dir, IN INT32 index, IN EFI_SYSTEM_TABLE *systab, IN VOID *buf ) { EFI_STATUS status; EFI_FILE *file; CHAR16 filename[10]; // Allow up to 9999 stories (Probably going to have to increase buffer size when this engine gets super popular :) INT32 index tostring(index, filename); Status=dir->Open(dir, &file, filename, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY); // open the file EFI_FILE_INFO *fileinfo; UINTN infosize = SIZE_OF_EFI_FILE_INFO; EFI_GUID info_type = EFI_FILE_INFO_ID; status = file->GetInfo(file, &info_type, &infosize, NULL); // get the info size of file systab->BootServices->AllocatePool(AllocateAnyPages, infosize, (VOID **)&fileinfo); status=file->GetInfo(file, &info_type, &infosize, fileinfo); // get info of file UINTN filesize = fileinfo->FileSize; // get filesize from info systab->BootServices->AllocatePool(AllocateAnyPages, filesize, (VOID **)&buf); // Allocate some room status=file->Read(file, &filesize, buf); systab->BootServices->FreePool(buf); systab->BootServices->FreePool(fileinfo); return EFI_SUCCESS; }
static int efifs_read(struct open_file *f, void *buf, size_t size, size_t *resid) { EFI_FILE *file = f->f_fsdata; EFI_STATUS status; UINTN sz = size; char *bufp; if (file == NULL) return (EBADF); bufp = buf; while (size > 0) { sz = size; if (sz > EFI_BLOCK_SIZE) sz = EFI_BLOCK_SIZE; status = file->Read(file, &sz, bufp); if (EFI_ERROR(status)) return (efi_status_to_errno(status)); if (sz == 0) break; size -= sz; bufp += sz; } if (resid) *resid = size; return (0); }