]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/BdsLib/BdsFilePathFs.c
Remove tabs from all text files in the package.
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsFilePathFs.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #include "BdsInternal.h"
16
17 EFI_STATUS BdsLoadFileFromSimpleFileSystem(
18 IN EFI_HANDLE Handle,
19 IN CHAR16 *FilePath,
20 OUT BDS_FILE *File
21 ) {
22 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
23 EFI_FILE_PROTOCOL *Fs;
24 EFI_STATUS Status;
25 EFI_FILE_PROTOCOL *FileHandle = NULL;
26
27 if (File == NULL) {
28 return EFI_INVALID_PARAMETER;
29 }
30
31 Status = gBS->HandleProtocol(Handle,&gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
32 if (EFI_ERROR(Status)) {
33 return Status;
34 }
35
36 //Try to Open the volume and get root directory
37 \s\sStatus = FsProtocol->OpenVolume(FsProtocol, &Fs);
38 \s\sif (EFI_ERROR(Status)) {
39 return Status;
40 }
41
42 Status = Fs->Open(Fs, &FileHandle, FilePath, EFI_FILE_MODE_READ, 0);
43
44 File->Type = BDS_FILETYPE_FS;
45 File->FilePath = FilePath;
46 File->File.Fs.Handle = FileHandle;
47
48 return Status;
49 }
50
51 EFI_STATUS BdsCopyRawFileToRuntimeMemoryFS(
52 IN EFI_FILE_PROTOCOL *File,
53 OUT VOID **FileImage,
54 OUT UINTN *FileSize
55 ) {
56 EFI_FILE_INFO *FileInfo;
57 UINTN Size;
58 VOID* Image;
59 EFI_STATUS Status;
60
61 Size = 0;
62 File->GetInfo(File, &gEfiFileInfoGuid, &Size, NULL);
63 FileInfo = AllocatePool (Size);
64 Status = File->GetInfo(File, &gEfiFileInfoGuid, &Size, FileInfo);
65 if (EFI_ERROR(Status)) {
66 return Status;
67 }
68
69 // Get the file size
70 Size = FileInfo->FileSize;
71 if (FileSize) {
72 *FileSize = Size;
73 }
74 FreePool(FileInfo);
75
76 Image = AllocateRuntimePool(Size);
77 if (Image == NULL) {
78 return EFI_OUT_OF_RESOURCES;
79 }
80
81 Status = File->Read(File, &Size, Image);
82 if (!EFI_ERROR(Status)) {
83 *FileImage = Image;
84 }
85 return Status;
86 }