3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Vol
,
28 OUT UINTN
*BufferSize
,
39 Vol - File System Volume
40 FileName - The file to be read.
41 BufferSize - The file buffer size
42 Buffer - The file buffer
46 EFI_SUCCESS - read file successfully
47 EFI_NOT_FOUND - file not found
52 EFI_FILE_HANDLE RootDir
;
53 EFI_FILE_HANDLE Handle
;
55 EFI_FILE_INFO
*FileInfo
;
60 // Open the root directory
62 Status
= Vol
->OpenVolume (Vol
, &RootDir
);
63 if (EFI_ERROR (Status
)) {
70 Status
= RootDir
->Open (
77 if (EFI_ERROR (Status
)) {
78 RootDir
->Close (RootDir
);
82 RootDir
->Close (RootDir
);
85 // Get the file information
87 FileInfoSize
= sizeof(EFI_FILE_INFO
) + 1024;
89 FileInfo
= AllocateZeroPool (FileInfoSize
);
90 if (FileInfo
== NULL
) {
91 Handle
->Close (Handle
);
95 Status
= Handle
->GetInfo (
101 if (EFI_ERROR (Status
)) {
102 Handle
->Close (Handle
);
103 gBS
->FreePool (FileInfo
);
108 // Allocate buffer for the file data. The last CHAR16 is for L'\0'
110 TempBufferSize
= (UINTN
) FileInfo
->FileSize
+ sizeof(CHAR16
);
111 TempBuffer
= AllocateZeroPool (TempBufferSize
);
112 if (TempBuffer
== NULL
) {
113 Handle
->Close (Handle
);
114 gBS
->FreePool (FileInfo
);
118 gBS
->FreePool (FileInfo
);
121 // Read the file data to the buffer
123 Status
= Handle
->Read (
128 if (EFI_ERROR (Status
)) {
129 Handle
->Close (Handle
);
130 gBS
->FreePool (TempBuffer
);
134 Handle
->Close (Handle
);
136 *BufferSize
= TempBufferSize
;
137 *Buffer
= TempBuffer
;
144 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
146 OUT UINTN
*BufferSize
,
155 If ScanFs is FLASE, it will use DebuggerPrivate->Vol as default Fs.
156 If ScanFs is TRUE, it will scan all FS and check the file.
157 If there is only one file match the name, it will be read.
158 If there is more than one file match the name, it will return Error.
162 DebuggerPrivate - EBC Debugger private data structure
163 FileName - The file to be read.
164 BufferSize - The file buffer size
165 Buffer - The file buffer
166 ScanFs - Need Scan all FS
170 EFI_SUCCESS - read file successfully
171 EFI_NOT_FOUND - file not found
172 EFI_NO_MAPPING - there is duplicated files found
177 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Vol
;
178 UINTN TempBufferSize
;
181 EFI_HANDLE
*HandleBuffer
;
187 if ((FileName
== NULL
) || (Buffer
== NULL
)) {
188 return EFI_INVALID_PARAMETER
;
195 if (DebuggerPrivate
->Vol
== NULL
) {
196 return EFI_INVALID_PARAMETER
;
199 // Read file directly from Vol
201 return ReadFileFromVol (DebuggerPrivate
->Vol
, FileName
, BufferSize
, Buffer
);
209 // Get all Vol handle
211 Status
= gBS
->LocateHandleBuffer (
213 &gEfiSimpleFileSystemProtocolGuid
,
218 if (EFI_ERROR (Status
) && (NoHandles
== 0)) {
219 return EFI_NOT_FOUND
;
223 // Walk through each Vol
225 DebuggerPrivate
->Vol
= NULL
;
228 for (Index
= 0; Index
< NoHandles
; Index
++) {
229 Status
= gBS
->HandleProtocol (
231 &gEfiSimpleFileSystemProtocolGuid
,
234 if (EFI_ERROR(Status
)) {
238 Status
= ReadFileFromVol (Vol
, FileName
, &TempBufferSize
, &TempBuffer
);
239 if (!EFI_ERROR (Status
)) {
241 // Read file OK, check duplication
243 if (DebuggerPrivate
->Vol
!= NULL
) {
245 // Find the duplicated file
247 gBS
->FreePool (TempBuffer
);
248 gBS
->FreePool (*Buffer
);
249 EDBPrint (L
"Duplicated FileName found!\n");
250 return EFI_NO_MAPPING
;
255 DebuggerPrivate
->Vol
= Vol
;
256 *BufferSize
= TempBufferSize
;
257 *Buffer
= TempBuffer
;
265 if (DebuggerPrivate
->Vol
== NULL
) {
266 return EFI_NOT_FOUND
;
277 GetFileNameUnderDir (
278 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
287 Get file name under this dir with index
291 DebuggerPrivate - EBC Debugger private data structure
292 DirName - The dir to be read.
293 FileName - The file name pattern under this dir
294 Index - The file index under this dir
298 File Name which match the pattern and index.
303 EFI_FILE_HANDLE RootDir
;
304 EFI_FILE_HANDLE Handle
;
306 EFI_FILE_INFO
*FileInfo
;
307 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Vol
;
311 if (DebuggerPrivate
->Vol
== NULL
) {
312 Status
= gBS
->LocateProtocol (
313 &gEfiSimpleFileSystemProtocolGuid
,
315 (VOID
**) &DebuggerPrivate
->Vol
317 if (EFI_ERROR(Status
)) {
321 Vol
= DebuggerPrivate
->Vol
;
324 // Open the root directory
326 Status
= Vol
->OpenVolume (Vol
, &RootDir
);
327 if (EFI_ERROR (Status
)) {
334 Status
= RootDir
->Open (
341 if (EFI_ERROR (Status
)) {
342 RootDir
->Close (RootDir
);
345 RootDir
->Close (RootDir
);
350 Status
= Handle
->SetPosition (Handle
, 0);
351 if (EFI_ERROR (Status
)) {
352 Handle
->Close (Handle
);
357 // Get the file information
359 FileInfoSize
= sizeof(EFI_FILE_INFO
) + 1024;
361 FileInfo
= AllocateZeroPool (FileInfoSize
);
362 if (FileInfo
== NULL
) {
363 Handle
->Close (Handle
);
368 // Walk through each file in the directory
376 FileInfoSize
= sizeof(EFI_FILE_INFO
) + 1024;
378 Status
= Handle
->Read (
383 if (EFI_ERROR (Status
) || (FileInfoSize
== 0)) {
387 if ((FileInfo
->Attribute
& EFI_FILE_DIRECTORY
) == 0) {
393 // Only deal with the EFI key file
395 if (!StrEndWith (FileInfo
->FileName
, FileName
)) {
399 if (FileIndex
== *Index
) {
400 TempName
= StrDuplicate (FileInfo
->FileName
);
411 gBS
->FreePool (FileInfo
);
412 Handle
->Close (Handle
);