138 IN EXT4_PARTITION *Part
144 if (Part->DiskIo != NULL) {
145 FreePool (Part->DiskIo);
148 if (Part->BlockIo != NULL) {
149 if (Part->BlockIo->Media != NULL) {
150 FreePool (Part->BlockIo->Media);
153 FreePool (Part->BlockIo);
156 if (Part->Root != NULL) {
157 Ext4UnmountAndFreePartition (Part);
158 }
else if (Part != NULL) {
209 EFI_FILE_PROTOCOL *This;
210 EFI_DISK_IO_PROTOCOL *DiskIo;
211 EFI_BLOCK_IO_PROTOCOL *BlockIo;
212 EFI_HANDLE DeviceHandle;
213 EXT4_PARTITION *Part;
217 EFI_FILE_PROTOCOL *NewHandle;
221 DeviceHandle = (EFI_HANDLE)0xDEADBEAFULL;
225 if ((argc < 2) || (argc != 3)) {
226 DEBUG ((DEBUG_ERROR,
"Usage: ./ext4read ([image path] [file path])*\n"));
233 ImageFp = fopen (argv[1],
"rb");
235 if (ImageFp == NULL) {
236 DEBUG ((DEBUG_ERROR,
"Can't open image file\n"));
240 if (fseek (ImageFp, 0, SEEK_END) != 0) {
241 DEBUG ((DEBUG_ERROR,
"Can't set file position\n"));
246 ImageSize = ftell (ImageFp);
247 if (ImageSize <= 0) {
248 DEBUG ((DEBUG_ERROR,
"Incorrect file size\n"));
253 if (fseek (ImageFp, 0, SEEK_SET) != 0) {
254 DEBUG ((DEBUG_ERROR,
"Can't rewind file position to the start\n"));
265 FileName = AllocateZeroPool (strlen (argv[2]) *
sizeof (CHAR16) + 1);
267 if (FileName == NULL) {
268 DEBUG ((DEBUG_ERROR,
"Can't allocate space for unicode filename\n"));
272 Status = AsciiStrToUnicodeStrS (argv[2], FileName, strlen (argv[2]) + 1);
273 if (EFI_ERROR (Status)) {
274 DEBUG ((DEBUG_ERROR,
"Can't convert given filename into UnicodeStr\n"));
283 DiskIo = AllocateZeroPool (
sizeof (EFI_DISK_IO_PROTOCOL));
284 if (DiskIo == NULL) {
292 BlockIo = AllocateZeroPool (
sizeof (EFI_BLOCK_IO_PROTOCOL));
293 if (BlockIo == NULL) {
300 BlockIo->Media = AllocateZeroPool (
sizeof (EFI_BLOCK_IO_MEDIA));
301 if (BlockIo->Media == NULL) {
313 if (!Ext4SuperblockCheckMagic (DiskIo, BlockIo)) {
314 DEBUG ((DEBUG_WARN,
"[ext4] Superblock contains bad magic \n"));
321 Status = Ext4OpenPartition (DeviceHandle, DiskIo, NULL, BlockIo);
323 if (EFI_ERROR (Status)) {
324 DEBUG ((DEBUG_ERROR,
"[ext4] Error mounting: %r\n", Status));
327 FreePool (BlockIo->Media);
335 This = (EFI_FILE_PROTOCOL *)Part->Root;
337 Status = Ext4Open (This, &NewHandle, FileName, EFI_FILE_MODE_READ, 0);
338 if (EFI_ERROR (Status)) {
339 DEBUG ((DEBUG_ERROR,
"[ext4] Couldn't open file %s \n", FileName));
349 if (Status == EFI_BUFFER_TOO_SMALL) {
350 Info = AllocateZeroPool (
Len);
358 if (EFI_ERROR (Status)) {
359 DEBUG ((DEBUG_ERROR,
"Couldn't get file information \n"));
367 Buffer = AllocateZeroPool (Info->FileSize);
368 BufferSize = Info->FileSize;
379 Status = Ext4ReadFile (NewHandle, &BufferSize,
Buffer);
380 if (Status == EFI_BUFFER_TOO_SMALL) {
381 TmpBuffer = ReallocatePool (Info->FileSize, BufferSize,
Buffer);
382 if (TmpBuffer == NULL) {
392 Status = Ext4ReadFile (NewHandle, &BufferSize,
Buffer);
393 if (EFI_ERROR (Status)) {
394 DEBUG ((DEBUG_WARN,
"Couldn't read file with Status: %r \n", Status));
EFI_STATUS EFIAPI UserReadDisk(IN EFI_DISK_IO_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Offset, IN UINTN BufferSize, OUT VOID *Buffer)