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_stat(struct open_file *f, struct stat *sb) { EFI_FILE *file = f->f_fsdata; union fileinfo fi; EFI_STATUS status; UINTN sz; if (file == NULL) return (EBADF); bzero(sb, sizeof(*sb)); sz = sizeof(fi); status = file->GetInfo(file, &fi_guid, &sz, &fi); if (EFI_ERROR(status)) return (efi_status_to_errno(status)); sb->st_mode = S_IRUSR | S_IRGRP | S_IROTH; if ((fi.info.Attribute & EFI_FILE_READ_ONLY) == 0) sb->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; if (fi.info.Attribute & EFI_FILE_DIRECTORY) sb->st_mode |= S_IFDIR; else sb->st_mode |= S_IFREG; sb->st_nlink = 1; sb->st_atime = efi_time(&fi.info.LastAccessTime); sb->st_mtime = efi_time(&fi.info.ModificationTime); sb->st_ctime = efi_time(&fi.info.CreateTime); sb->st_size = fi.info.FileSize; sb->st_blocks = fi.info.PhysicalSize / S_BLKSIZE; sb->st_blksize = S_BLKSIZE; sb->st_birthtime = sb->st_ctime; return (0); }
/* * Print information about disks */ static void efifs_dev_print(int verbose) { union { EFI_FILE_SYSTEM_INFO info; char buffer[1024]; } fi; char line[80]; EFI_FILE_IO_INTERFACE *fsif; EFI_FILE *volume; EFI_HANDLE h; EFI_STATUS status; UINTN sz; int i, unit; for (unit = 0, h = efi_find_handle(&efifs_dev, 0); h != NULL; h = efi_find_handle(&efifs_dev, ++unit)) { sprintf(line, " %s%d: ", efifs_dev.dv_name, unit); pager_output(line); status = BS->HandleProtocol(h, &sfs_guid, (VOID **)&fsif); if (EFI_ERROR(status)) goto err; status = fsif->OpenVolume(fsif, &volume); if (EFI_ERROR(status)) goto err; sz = sizeof(fi); status = volume->GetInfo(volume, &fs_guid, &sz, &fi); volume->Close(volume); if (EFI_ERROR(status)) goto err; if (fi.info.ReadOnly) pager_output("[RO] "); else pager_output(" "); for (i = 0; fi.info.VolumeLabel[i] != 0; i++) fi.buffer[i] = fi.info.VolumeLabel[i]; fi.buffer[i] = 0; if (fi.buffer[0] != 0) pager_output(fi.buffer); else pager_output("EFI filesystem"); pager_output("\n"); continue; err: sprintf(line, "[--] error %d: unable to obtain information\n", efi_status_to_errno(status)); pager_output(line); } }