2 Provides interface to shell functionality for shell commands and applications.
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. 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
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.
16 #include <Library/ShellLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/DevicePathLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/FileHandleLib.h>
25 #include <Library/PrintLib.h>
26 #include <Library/UefiLib.h>
27 #include <Library/HiiLib.h>
29 #include <Protocol/EfiShellEnvironment2.h>
30 #include <Protocol/EfiShellInterface.h>
31 #include <Protocol/EfiShell.h>
32 #include <Protocol/EfiShellParameters.h>
33 #include <Protocol/SimpleFileSystem.h>
35 #include "UefiShellLib.h"
37 #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
38 #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
41 // This is not static since it's extern in the .h file
43 SHELL_PARAM_ITEM EmptyParamList
[] = {
48 // Static file globals for the shell library
50 STATIC EFI_SHELL_ENVIRONMENT2
*mEfiShellEnvironment2
;
51 STATIC EFI_SHELL_INTERFACE
*mEfiShellInterface
;
52 STATIC EFI_SHELL_PROTOCOL
*mEfiShellProtocol
;
53 STATIC EFI_SHELL_PARAMETERS_PROTOCOL
*mEfiShellParametersProtocol
;
54 STATIC EFI_HANDLE mEfiShellEnvironment2Handle
;
55 STATIC FILE_HANDLE_FUNCTION_MAP FileFunctionMap
;
56 STATIC UINTN mTotalParameterCount
;
59 Check if a Unicode character is a hexadecimal character.
61 This internal function checks if a Unicode character is a
62 decimal character. The valid hexadecimal character is
63 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
66 @param Char The character to check against.
68 @retval TRUE If the Char is a hexadecmial character.
69 @retval FALSE If the Char is not a hexadecmial character.
74 ShellInternalIsHexaDecimalDigitCharacter (
77 return (BOOLEAN
) ((Char
>= L
'0' && Char
<= L
'9') || (Char
>= L
'A' && Char
<= L
'F') || (Char
>= L
'a' && Char
<= L
'f'));
81 helper function to find ShellEnvironment2 for constructor
86 IN EFI_HANDLE ImageHandle
95 Status
= gBS
->OpenProtocol(ImageHandle
,
96 &gEfiShellEnvironment2Guid
,
97 (VOID
**)&mEfiShellEnvironment2
,
100 EFI_OPEN_PROTOCOL_GET_PROTOCOL
103 // look for the mEfiShellEnvironment2 protocol at a higher level
105 if (EFI_ERROR (Status
) || !(CompareGuid (&mEfiShellEnvironment2
->SESGuid
, &gEfiShellEnvironment2ExtGuid
) != FALSE
)){
107 // figure out how big of a buffer we need.
109 Status
= gBS
->LocateHandle (ByProtocol
,
110 &gEfiShellEnvironment2Guid
,
111 NULL
, // ignored for ByProtocol
116 // maybe it's not there???
118 if (Status
== EFI_BUFFER_TOO_SMALL
) {
119 Buffer
= (EFI_HANDLE
*)AllocatePool(BufferSize
);
120 ASSERT(Buffer
!= NULL
);
121 Status
= gBS
->LocateHandle (ByProtocol
,
122 &gEfiShellEnvironment2Guid
,
123 NULL
, // ignored for ByProtocol
128 if (!EFI_ERROR (Status
)) {
130 // now parse the list of returned handles
132 Status
= EFI_NOT_FOUND
;
133 for (HandleIndex
= 0; HandleIndex
< (BufferSize
/sizeof(Buffer
[0])); HandleIndex
++) {
134 Status
= gBS
->OpenProtocol(Buffer
[HandleIndex
],
135 &gEfiShellEnvironment2Guid
,
136 (VOID
**)&mEfiShellEnvironment2
,
139 EFI_OPEN_PROTOCOL_GET_PROTOCOL
141 if (CompareGuid (&mEfiShellEnvironment2
->SESGuid
, &gEfiShellEnvironment2ExtGuid
) != FALSE
) {
142 mEfiShellEnvironment2Handle
= Buffer
[HandleIndex
];
143 Status
= EFI_SUCCESS
;
149 if (Buffer
!= NULL
) {
157 ShellLibConstructorWorker (
158 IN EFI_HANDLE ImageHandle
,
159 IN EFI_SYSTEM_TABLE
*SystemTable
164 // Set the parameter count to an invalid number
166 mTotalParameterCount
= (UINTN
)(-1);
169 // UEFI 2.0 shell interfaces (used preferentially)
171 Status
= gBS
->OpenProtocol(ImageHandle
,
172 &gEfiShellProtocolGuid
,
173 (VOID
**)&mEfiShellProtocol
,
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL
178 if (EFI_ERROR(Status
)) {
179 mEfiShellProtocol
= NULL
;
181 Status
= gBS
->OpenProtocol(ImageHandle
,
182 &gEfiShellParametersProtocolGuid
,
183 (VOID
**)&mEfiShellParametersProtocol
,
186 EFI_OPEN_PROTOCOL_GET_PROTOCOL
188 if (EFI_ERROR(Status
)) {
189 mEfiShellParametersProtocol
= NULL
;
192 if (mEfiShellParametersProtocol
== NULL
|| mEfiShellProtocol
== NULL
) {
194 // Moved to seperate function due to complexity
196 Status
= ShellFindSE2(ImageHandle
);
198 if (EFI_ERROR(Status
)) {
199 DEBUG((DEBUG_ERROR
, "Status: 0x%08x\r\n", Status
));
200 mEfiShellEnvironment2
= NULL
;
202 Status
= gBS
->OpenProtocol(ImageHandle
,
203 &gEfiShellInterfaceGuid
,
204 (VOID
**)&mEfiShellInterface
,
207 EFI_OPEN_PROTOCOL_GET_PROTOCOL
209 if (EFI_ERROR(Status
)) {
210 mEfiShellInterface
= NULL
;
214 // only success getting 2 of either the old or new, but no 1/2 and 1/2
216 if ((mEfiShellEnvironment2
!= NULL
&& mEfiShellInterface
!= NULL
) ||
217 (mEfiShellProtocol
!= NULL
&& mEfiShellParametersProtocol
!= NULL
) ) {
218 if (mEfiShellProtocol
!= NULL
) {
219 FileFunctionMap
.GetFileInfo
= mEfiShellProtocol
->GetFileInfo
;
220 FileFunctionMap
.SetFileInfo
= mEfiShellProtocol
->SetFileInfo
;
221 FileFunctionMap
.ReadFile
= mEfiShellProtocol
->ReadFile
;
222 FileFunctionMap
.WriteFile
= mEfiShellProtocol
->WriteFile
;
223 FileFunctionMap
.CloseFile
= mEfiShellProtocol
->CloseFile
;
224 FileFunctionMap
.DeleteFile
= mEfiShellProtocol
->DeleteFile
;
225 FileFunctionMap
.GetFilePosition
= mEfiShellProtocol
->GetFilePosition
;
226 FileFunctionMap
.SetFilePosition
= mEfiShellProtocol
->SetFilePosition
;
227 FileFunctionMap
.FlushFile
= mEfiShellProtocol
->FlushFile
;
228 FileFunctionMap
.GetFileSize
= mEfiShellProtocol
->GetFileSize
;
230 FileFunctionMap
.GetFileInfo
= FileHandleGetInfo
;
231 FileFunctionMap
.SetFileInfo
= FileHandleSetInfo
;
232 FileFunctionMap
.ReadFile
= FileHandleRead
;
233 FileFunctionMap
.WriteFile
= FileHandleWrite
;
234 FileFunctionMap
.CloseFile
= FileHandleClose
;
235 FileFunctionMap
.DeleteFile
= FileHandleDelete
;
236 FileFunctionMap
.GetFilePosition
= FileHandleGetPosition
;
237 FileFunctionMap
.SetFilePosition
= FileHandleSetPosition
;
238 FileFunctionMap
.FlushFile
= FileHandleFlush
;
239 FileFunctionMap
.GetFileSize
= FileHandleGetSize
;
241 return (EFI_SUCCESS
);
243 return (EFI_NOT_FOUND
);
246 Constructor for the Shell library.
248 Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
250 @param ImageHandle the image handle of the process
251 @param SystemTable the EFI System Table pointer
253 @retval EFI_SUCCESS the initialization was complete sucessfully
254 @return others an error ocurred during initialization
258 ShellLibConstructor (
259 IN EFI_HANDLE ImageHandle
,
260 IN EFI_SYSTEM_TABLE
*SystemTable
264 mEfiShellEnvironment2
= NULL
;
265 mEfiShellProtocol
= NULL
;
266 mEfiShellParametersProtocol
= NULL
;
267 mEfiShellInterface
= NULL
;
268 mEfiShellEnvironment2Handle
= NULL
;
271 // verify that auto initialize is not set false
273 if (PcdGetBool(PcdShellLibAutoInitialize
) == 0) {
274 return (EFI_SUCCESS
);
277 return (ShellLibConstructorWorker(ImageHandle
, SystemTable
));
281 Destructory for the library. free any resources.
286 IN EFI_HANDLE ImageHandle
,
287 IN EFI_SYSTEM_TABLE
*SystemTable
289 if (mEfiShellEnvironment2
!= NULL
) {
290 gBS
->CloseProtocol(mEfiShellEnvironment2Handle
==NULL
?ImageHandle
:mEfiShellEnvironment2Handle
,
291 &gEfiShellEnvironment2Guid
,
294 mEfiShellEnvironment2
= NULL
;
296 if (mEfiShellInterface
!= NULL
) {
297 gBS
->CloseProtocol(ImageHandle
,
298 &gEfiShellInterfaceGuid
,
301 mEfiShellInterface
= NULL
;
303 if (mEfiShellProtocol
!= NULL
) {
304 gBS
->CloseProtocol(ImageHandle
,
305 &gEfiShellProtocolGuid
,
308 mEfiShellProtocol
= NULL
;
310 if (mEfiShellParametersProtocol
!= NULL
) {
311 gBS
->CloseProtocol(ImageHandle
,
312 &gEfiShellParametersProtocolGuid
,
315 mEfiShellParametersProtocol
= NULL
;
317 mEfiShellEnvironment2Handle
= NULL
;
318 return (EFI_SUCCESS
);
322 This function causes the shell library to initialize itself. If the shell library
323 is already initialized it will de-initialize all the current protocol poitners and
324 re-populate them again.
326 When the library is used with PcdShellLibAutoInitialize set to true this function
327 will return EFI_SUCCESS and perform no actions.
329 This function is intended for internal access for shell commands only.
331 @retval EFI_SUCCESS the initialization was complete sucessfully
339 // if auto initialize is not false then skip
341 if (PcdGetBool(PcdShellLibAutoInitialize
) != 0) {
342 return (EFI_SUCCESS
);
346 // deinit the current stuff
348 ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle
, gST
));
351 // init the new stuff
353 return (ShellLibConstructorWorker(gImageHandle
, gST
));
357 This function will retrieve the information about the file for the handle
358 specified and store it in allocated pool memory.
360 This function allocates a buffer to store the file's information. It is the
361 caller's responsibility to free the buffer
363 @param FileHandle The file handle of the file for which information is
366 @retval NULL information could not be retrieved.
368 @return the information about the file
373 IN EFI_FILE_HANDLE FileHandle
375 return (FileFunctionMap
.GetFileInfo(FileHandle
));
379 This function will set the information about the file for the opened handle
382 @param FileHandle The file handle of the file for which information
385 @param FileInfo The infotmation to set.
387 @retval EFI_SUCCESS The information was set.
388 @retval EFI_UNSUPPORTED The InformationType is not known.
389 @retval EFI_NO_MEDIA The device has no medium.
390 @retval EFI_DEVICE_ERROR The device reported an error.
391 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
392 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
393 @retval EFI_ACCESS_DENIED The file was opened read only.
394 @retval EFI_VOLUME_FULL The volume is full.
399 IN EFI_FILE_HANDLE FileHandle
,
400 IN EFI_FILE_INFO
*FileInfo
402 return (FileFunctionMap
.SetFileInfo(FileHandle
, FileInfo
));
406 This function will open a file or directory referenced by DevicePath.
408 This function opens a file with the open mode according to the file path. The
409 Attributes is valid only for EFI_FILE_MODE_CREATE.
411 @param FilePath on input the device path to the file. On output
412 the remaining device path.
413 @param DeviceHandle pointer to the system device handle.
414 @param FileHandle pointer to the file handle.
415 @param OpenMode the mode to open the file with.
416 @param Attributes the file's file attributes.
418 @retval EFI_SUCCESS The information was set.
419 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
420 @retval EFI_UNSUPPORTED Could not open the file path.
421 @retval EFI_NOT_FOUND The specified file could not be found on the
422 device or the file system could not be found on
424 @retval EFI_NO_MEDIA The device has no medium.
425 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
426 medium is no longer supported.
427 @retval EFI_DEVICE_ERROR The device reported an error.
428 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
429 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
430 @retval EFI_ACCESS_DENIED The file was opened read only.
431 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
433 @retval EFI_VOLUME_FULL The volume is full.
437 ShellOpenFileByDevicePath(
438 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
439 OUT EFI_HANDLE
*DeviceHandle
,
440 OUT EFI_FILE_HANDLE
*FileHandle
,
446 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*EfiSimpleFileSystemProtocol
;
447 EFI_FILE_HANDLE LastHandle
;
450 // ASERT for FileHandle, FilePath, and DeviceHandle being NULL
452 ASSERT(FilePath
!= NULL
);
453 ASSERT(FileHandle
!= NULL
);
454 ASSERT(DeviceHandle
!= NULL
);
456 // which shell interface should we use
458 if (mEfiShellProtocol
!= NULL
) {
460 // use UEFI Shell 2.0 method.
462 FileName
= mEfiShellProtocol
->GetFilePathFromDevicePath(*FilePath
);
463 if (FileName
== NULL
) {
464 return (EFI_INVALID_PARAMETER
);
466 Status
= ShellOpenFileByName(FileName
, FileHandle
, OpenMode
, Attributes
);
473 // use old shell method.
475 Status
= gBS
->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid
,
478 if (EFI_ERROR (Status
)) {
481 Status
= gBS
->OpenProtocol(*DeviceHandle
,
482 &gEfiSimpleFileSystemProtocolGuid
,
483 (VOID
**)&EfiSimpleFileSystemProtocol
,
486 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
487 if (EFI_ERROR (Status
)) {
490 Status
= EfiSimpleFileSystemProtocol
->OpenVolume(EfiSimpleFileSystemProtocol
, FileHandle
);
491 if (EFI_ERROR (Status
)) {
497 // go down directories one node at a time.
499 while (!IsDevicePathEnd (*FilePath
)) {
501 // For file system access each node should be a file path component
503 if (DevicePathType (*FilePath
) != MEDIA_DEVICE_PATH
||
504 DevicePathSubType (*FilePath
) != MEDIA_FILEPATH_DP
507 return (EFI_INVALID_PARAMETER
);
510 // Open this file path node
512 LastHandle
= *FileHandle
;
516 // Try to test opening an existing file
518 Status
= LastHandle
->Open (
521 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
522 OpenMode
&~EFI_FILE_MODE_CREATE
,
527 // see if the error was that it needs to be created
529 if ((EFI_ERROR (Status
)) && (OpenMode
!= (OpenMode
&~EFI_FILE_MODE_CREATE
))) {
530 Status
= LastHandle
->Open (
533 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
539 // Close the last node
541 LastHandle
->Close (LastHandle
);
543 if (EFI_ERROR(Status
)) {
550 *FilePath
= NextDevicePathNode (*FilePath
);
552 return (EFI_SUCCESS
);
556 This function will open a file or directory referenced by filename.
558 If return is EFI_SUCCESS, the Filehandle is the opened file's handle;
559 otherwise, the Filehandle is NULL. The Attributes is valid only for
560 EFI_FILE_MODE_CREATE.
562 if FileNAme is NULL then ASSERT()
564 @param FileName pointer to file name
565 @param FileHandle pointer to the file handle.
566 @param OpenMode the mode to open the file with.
567 @param Attributes the file's file attributes.
569 @retval EFI_SUCCESS The information was set.
570 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
571 @retval EFI_UNSUPPORTED Could not open the file path.
572 @retval EFI_NOT_FOUND The specified file could not be found on the
573 device or the file system could not be found
575 @retval EFI_NO_MEDIA The device has no medium.
576 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
577 medium is no longer supported.
578 @retval EFI_DEVICE_ERROR The device reported an error.
579 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
580 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
581 @retval EFI_ACCESS_DENIED The file was opened read only.
582 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
584 @retval EFI_VOLUME_FULL The volume is full.
589 IN CONST CHAR16
*FileName
,
590 OUT EFI_FILE_HANDLE
*FileHandle
,
594 EFI_HANDLE DeviceHandle
;
595 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
597 EFI_FILE_INFO
*FileInfo
;
600 // ASSERT if FileName is NULL
602 ASSERT(FileName
!= NULL
);
604 if (mEfiShellProtocol
!= NULL
) {
606 // Use UEFI Shell 2.0 method
608 Status
= mEfiShellProtocol
->OpenFileByName(FileName
,
611 if (!EFI_ERROR(Status
) && ((OpenMode
& EFI_FILE_MODE_CREATE
) != 0)){
612 FileInfo
= FileFunctionMap
.GetFileInfo(*FileHandle
);
613 ASSERT(FileInfo
!= NULL
);
614 FileInfo
->Attribute
= Attributes
;
615 Status
= FileFunctionMap
.SetFileInfo(*FileHandle
, FileInfo
);
621 // Using EFI Shell version
622 // this means convert name to path and call that function
623 // since this will use EFI method again that will open it.
625 ASSERT(mEfiShellEnvironment2
!= NULL
);
626 FilePath
= mEfiShellEnvironment2
->NameToPath ((CHAR16
*)FileName
);
627 if (FileDevicePath
!= NULL
) {
628 return (ShellOpenFileByDevicePath(&FilePath
,
634 return (EFI_DEVICE_ERROR
);
637 This function create a directory
639 If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;
640 otherwise, the Filehandle is NULL. If the directory already existed, this
641 function opens the existing directory.
643 @param DirectoryName pointer to directory name
644 @param FileHandle pointer to the file handle.
646 @retval EFI_SUCCESS The information was set.
647 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
648 @retval EFI_UNSUPPORTED Could not open the file path.
649 @retval EFI_NOT_FOUND The specified file could not be found on the
650 device or the file system could not be found
652 @retval EFI_NO_MEDIA The device has no medium.
653 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
654 medium is no longer supported.
655 @retval EFI_DEVICE_ERROR The device reported an error.
656 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
657 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
658 @retval EFI_ACCESS_DENIED The file was opened read only.
659 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
661 @retval EFI_VOLUME_FULL The volume is full.
662 @sa ShellOpenFileByName
666 ShellCreateDirectory(
667 IN CONST CHAR16
*DirectoryName
,
668 OUT EFI_FILE_HANDLE
*FileHandle
670 if (mEfiShellProtocol
!= NULL
) {
672 // Use UEFI Shell 2.0 method
674 return (mEfiShellProtocol
->CreateFile(DirectoryName
,
679 return (ShellOpenFileByName(DirectoryName
,
681 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
688 This function reads information from an opened file.
690 If FileHandle is not a directory, the function reads the requested number of
691 bytes from the file at the file's current position and returns them in Buffer.
692 If the read goes beyond the end of the file, the read length is truncated to the
693 end of the file. The file's current position is increased by the number of bytes
694 returned. If FileHandle is a directory, the function reads the directory entry
695 at the file's current position and returns the entry in Buffer. If the Buffer
696 is not large enough to hold the current directory entry, then
697 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
698 BufferSize is set to be the size of the buffer needed to read the entry. On
699 success, the current position is updated to the next directory entry. If there
700 are no more directory entries, the read returns a zero-length buffer.
701 EFI_FILE_INFO is the structure returned as the directory entry.
703 @param FileHandle the opened file handle
704 @param BufferSize on input the size of buffer in bytes. on return
705 the number of bytes written.
706 @param Buffer the buffer to put read data into.
708 @retval EFI_SUCCESS Data was read.
709 @retval EFI_NO_MEDIA The device has no media.
710 @retval EFI_DEVICE_ERROR The device reported an error.
711 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
712 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
719 IN EFI_FILE_HANDLE FileHandle
,
720 IN OUT UINTN
*BufferSize
,
723 return (FileFunctionMap
.ReadFile(FileHandle
, BufferSize
, Buffer
));
728 Write data to a file.
730 This function writes the specified number of bytes to the file at the current
731 file position. The current file position is advanced the actual number of bytes
732 written, which is returned in BufferSize. Partial writes only occur when there
733 has been a data error during the write attempt (such as "volume space full").
734 The file is automatically grown to hold the data if required. Direct writes to
735 opened directories are not supported.
737 @param FileHandle The opened file for writing
738 @param BufferSize on input the number of bytes in Buffer. On output
739 the number of bytes written.
740 @param Buffer the buffer containing data to write is stored.
742 @retval EFI_SUCCESS Data was written.
743 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
744 @retval EFI_NO_MEDIA The device has no media.
745 @retval EFI_DEVICE_ERROR The device reported an error.
746 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
747 @retval EFI_WRITE_PROTECTED The device is write-protected.
748 @retval EFI_ACCESS_DENIED The file was open for read only.
749 @retval EFI_VOLUME_FULL The volume is full.
754 IN EFI_FILE_HANDLE FileHandle
,
755 IN OUT UINTN
*BufferSize
,
758 return (FileFunctionMap
.WriteFile(FileHandle
, BufferSize
, Buffer
));
762 Close an open file handle.
764 This function closes a specified file handle. All "dirty" cached file data is
765 flushed to the device, and the file is closed. In all cases the handle is
768 @param FileHandle the file handle to close.
770 @retval EFI_SUCCESS the file handle was closed sucessfully.
775 IN EFI_FILE_HANDLE
*FileHandle
777 return (FileFunctionMap
.CloseFile(*FileHandle
));
781 Delete a file and close the handle
783 This function closes and deletes a file. In all cases the file handle is closed.
784 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
785 returned, but the handle is still closed.
787 @param FileHandle the file handle to delete
789 @retval EFI_SUCCESS the file was closed sucessfully
790 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
792 @retval INVALID_PARAMETER One of the parameters has an invalid value.
797 IN EFI_FILE_HANDLE
*FileHandle
799 return (FileFunctionMap
.DeleteFile(*FileHandle
));
803 Set the current position in a file.
805 This function sets the current file position for the handle to the position
806 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
807 absolute positioning is supported, and seeking past the end of the file is
808 allowed (a subsequent write would grow the file). Seeking to position
809 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
810 If FileHandle is a directory, the only position that may be set is zero. This
811 has the effect of starting the read process of the directory entries over.
813 @param FileHandle The file handle on which the position is being set
814 @param Position Byte position from begining of file
816 @retval EFI_SUCCESS Operation completed sucessfully.
817 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
819 @retval INVALID_PARAMETER One of the parameters has an invalid value.
823 ShellSetFilePosition (
824 IN EFI_FILE_HANDLE FileHandle
,
827 return (FileFunctionMap
.SetFilePosition(FileHandle
, Position
));
831 Gets a file's current position
833 This function retrieves the current file position for the file handle. For
834 directories, the current file position has no meaning outside of the file
835 system driver and as such the operation is not supported. An error is returned
836 if FileHandle is a directory.
838 @param FileHandle The open file handle on which to get the position.
839 @param Position Byte position from begining of file.
841 @retval EFI_SUCCESS the operation completed sucessfully.
842 @retval INVALID_PARAMETER One of the parameters has an invalid value.
843 @retval EFI_UNSUPPORTED the request is not valid on directories.
847 ShellGetFilePosition (
848 IN EFI_FILE_HANDLE FileHandle
,
851 return (FileFunctionMap
.GetFilePosition(FileHandle
, Position
));
854 Flushes data on a file
856 This function flushes all modified data associated with a file to a device.
858 @param FileHandle The file handle on which to flush data
860 @retval EFI_SUCCESS The data was flushed.
861 @retval EFI_NO_MEDIA The device has no media.
862 @retval EFI_DEVICE_ERROR The device reported an error.
863 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
864 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
865 @retval EFI_ACCESS_DENIED The file was opened for read only.
870 IN EFI_FILE_HANDLE FileHandle
872 return (FileFunctionMap
.FlushFile(FileHandle
));
876 Retrieves the first file from a directory
878 This function opens a directory and gets the first file's info in the
879 directory. Caller can use ShellFindNextFile() to get other files. When
880 complete the caller is responsible for calling FreePool() on Buffer.
882 @param DirHandle The file handle of the directory to search
883 @param Buffer Pointer to buffer for file's information
885 @retval EFI_SUCCESS Found the first file.
886 @retval EFI_NOT_FOUND Cannot find the directory.
887 @retval EFI_NO_MEDIA The device has no media.
888 @retval EFI_DEVICE_ERROR The device reported an error.
889 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
890 @return Others status of ShellGetFileInfo, ShellSetFilePosition,
896 IN EFI_FILE_HANDLE DirHandle
,
897 OUT EFI_FILE_INFO
**Buffer
900 // pass to file handle lib
902 return (FileHandleFindFirstFile(DirHandle
, Buffer
));
905 Retrieves the next file in a directory.
907 To use this function, caller must call the LibFindFirstFile() to get the
908 first file, and then use this function get other files. This function can be
909 called for several times to get each file's information in the directory. If
910 the call of ShellFindNextFile() got the last file in the directory, the next
911 call of this function has no file to get. *NoFile will be set to TRUE and the
912 Buffer memory will be automatically freed.
914 @param DirHandle the file handle of the directory
915 @param Buffer pointer to buffer for file's information
916 @param NoFile pointer to boolean when last file is found
918 @retval EFI_SUCCESS Found the next file, or reached last file
919 @retval EFI_NO_MEDIA The device has no media.
920 @retval EFI_DEVICE_ERROR The device reported an error.
921 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
926 IN EFI_FILE_HANDLE DirHandle
,
927 OUT EFI_FILE_INFO
*Buffer
,
931 // pass to file handle lib
933 return (FileHandleFindNextFile(DirHandle
, Buffer
, NoFile
));
936 Retrieve the size of a file.
938 if FileHandle is NULL then ASSERT()
939 if Size is NULL then ASSERT()
941 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
944 @param FileHandle file handle from which size is retrieved
945 @param Size pointer to size
947 @retval EFI_SUCCESS operation was completed sucessfully
948 @retval EFI_DEVICE_ERROR cannot access the file
953 IN EFI_FILE_HANDLE FileHandle
,
956 return (FileFunctionMap
.GetFileSize(FileHandle
, Size
));
959 Retrieves the status of the break execution flag
961 this function is useful to check whether the application is being asked to halt by the shell.
963 @retval TRUE the execution break is enabled
964 @retval FALSE the execution break is not enabled
968 ShellGetExecutionBreakFlag(
973 // Check for UEFI Shell 2.0 protocols
975 if (mEfiShellProtocol
!= NULL
) {
978 // We are using UEFI Shell 2.0; see if the event has been triggered
980 if (gBS
->CheckEvent(mEfiShellProtocol
->ExecutionBreak
) != EFI_SUCCESS
) {
987 // using EFI Shell; call the function to check
989 ASSERT(mEfiShellEnvironment2
!= NULL
);
990 return (mEfiShellEnvironment2
->GetExecutionBreak());
993 return the value of an environment variable
995 this function gets the value of the environment variable set by the
996 ShellSetEnvironmentVariable function
998 @param EnvKey The key name of the environment variable.
1000 @retval NULL the named environment variable does not exist.
1001 @return != NULL pointer to the value of the environment variable
1005 ShellGetEnvironmentVariable (
1006 IN CONST CHAR16
*EnvKey
1010 // Check for UEFI Shell 2.0 protocols
1012 if (mEfiShellProtocol
!= NULL
) {
1013 return (mEfiShellProtocol
->GetEnv(EnvKey
));
1017 // ASSERT that we must have EFI shell
1019 ASSERT(mEfiShellEnvironment2
!= NULL
);
1024 return (mEfiShellEnvironment2
->GetEnv((CHAR16
*)EnvKey
));
1027 set the value of an environment variable
1029 This function changes the current value of the specified environment variable. If the
1030 environment variable exists and the Value is an empty string, then the environment
1031 variable is deleted. If the environment variable exists and the Value is not an empty
1032 string, then the value of the environment variable is changed. If the environment
1033 variable does not exist and the Value is an empty string, there is no action. If the
1034 environment variable does not exist and the Value is a non-empty string, then the
1035 environment variable is created and assigned the specified value.
1037 This is not supported pre-UEFI Shell 2.0.
1039 @param EnvKey The key name of the environment variable.
1040 @param EnvVal The Value of the environment variable
1041 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
1043 @retval EFI_SUCCESS the operation was completed sucessfully
1044 @retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments
1048 ShellSetEnvironmentVariable (
1049 IN CONST CHAR16
*EnvKey
,
1050 IN CONST CHAR16
*EnvVal
,
1055 // Check for UEFI Shell 2.0 protocols
1057 if (mEfiShellProtocol
!= NULL
) {
1058 return (mEfiShellProtocol
->SetEnv(EnvKey
, EnvVal
, Volatile
));
1062 // This feature does not exist under EFI shell
1064 return (EFI_UNSUPPORTED
);
1067 cause the shell to parse and execute a command line.
1069 This function creates a nested instance of the shell and executes the specified
1070 command (CommandLine) with the specified environment (Environment). Upon return,
1071 the status code returned by the specified command is placed in StatusCode.
1072 If Environment is NULL, then the current environment is used and all changes made
1073 by the commands executed will be reflected in the current environment. If the
1074 Environment is non-NULL, then the changes made will be discarded.
1075 The CommandLine is executed from the current working directory on the current
1078 EnvironmentVariables and Status are only supported for UEFI Shell 2.0.
1079 Output is only supported for pre-UEFI Shell 2.0
1081 @param ImageHandle Parent image that is starting the operation
1082 @param CommandLine pointer to null terminated command line.
1083 @param Output true to display debug output. false to hide it.
1084 @param EnvironmentVariables optional pointer to array of environment variables
1085 in the form "x=y". if NULL current set is used.
1086 @param Status the status of the run command line.
1088 @retval EFI_SUCCESS the operation completed sucessfully. Status
1089 contains the status code returned.
1090 @retval EFI_INVALID_PARAMETER a parameter contains an invalid value
1091 @retval EFI_OUT_OF_RESOURCES out of resources
1092 @retval EFI_UNSUPPORTED the operation is not allowed.
1097 IN EFI_HANDLE
*ParentHandle
,
1098 IN CHAR16
*CommandLine OPTIONAL
,
1099 IN BOOLEAN Output OPTIONAL
,
1100 IN CHAR16
**EnvironmentVariables OPTIONAL
,
1101 OUT EFI_STATUS
*Status OPTIONAL
1105 // Check for UEFI Shell 2.0 protocols
1107 if (mEfiShellProtocol
!= NULL
) {
1109 // Call UEFI Shell 2.0 version (not using Output parameter)
1111 return (mEfiShellProtocol
->Execute(ParentHandle
,
1113 EnvironmentVariables
,
1117 // ASSERT that we must have EFI shell
1119 ASSERT(mEfiShellEnvironment2
!= NULL
);
1121 // Call EFI Shell version (not using EnvironmentVariables or Status parameters)
1122 // Due to oddity in the EFI shell we want to dereference the ParentHandle here
1124 return (mEfiShellEnvironment2
->Execute(*ParentHandle
,
1129 Retreives the current directory path
1131 If the DeviceName is NULL, it returns the current device's current directory
1132 name. If the DeviceName is not NULL, it returns the current directory name
1135 @param DeviceName the name of the drive to get directory on
1137 @retval NULL the directory does not exist
1138 @return != NULL the directory
1142 ShellGetCurrentDir (
1143 IN CHAR16
*DeviceName OPTIONAL
1147 // Check for UEFI Shell 2.0 protocols
1149 if (mEfiShellProtocol
!= NULL
) {
1150 return (mEfiShellProtocol
->GetCurDir(DeviceName
));
1153 // ASSERT that we must have EFI shell
1155 ASSERT(mEfiShellEnvironment2
!= NULL
);
1156 return (mEfiShellEnvironment2
->CurDir(DeviceName
));
1159 sets (enabled or disabled) the page break mode
1161 when page break mode is enabled the screen will stop scrolling
1162 and wait for operator input before scrolling a subsequent screen.
1164 @param CurrentState TRUE to enable and FALSE to disable
1168 ShellSetPageBreakMode (
1169 IN BOOLEAN CurrentState
1173 // check for enabling
1175 if (CurrentState
!= 0x00) {
1177 // check for UEFI Shell 2.0
1179 if (mEfiShellProtocol
!= NULL
) {
1181 // Enable with UEFI 2.0 Shell
1183 mEfiShellProtocol
->EnablePageBreak();
1187 // ASSERT that must have EFI Shell
1189 ASSERT(mEfiShellEnvironment2
!= NULL
);
1191 // Enable with EFI Shell
1193 mEfiShellEnvironment2
->EnablePageBreak (DEFAULT_INIT_ROW
, DEFAULT_AUTO_LF
);
1198 // check for UEFI Shell 2.0
1200 if (mEfiShellProtocol
!= NULL
) {
1202 // Disable with UEFI 2.0 Shell
1204 mEfiShellProtocol
->DisablePageBreak();
1208 // ASSERT that must have EFI Shell
1210 ASSERT(mEfiShellEnvironment2
!= NULL
);
1212 // Disable with EFI Shell
1214 mEfiShellEnvironment2
->DisablePageBreak ();
1221 /// version of EFI_SHELL_FILE_INFO struct, except has no CONST pointers.
1222 /// This allows for the struct to be populated.
1229 EFI_FILE_HANDLE Handle
;
1230 EFI_FILE_INFO
*Info
;
1231 } EFI_SHELL_FILE_INFO_NO_CONST
;
1234 Converts a EFI shell list of structures to the coresponding UEFI Shell 2.0 type of list.
1236 if OldStyleFileList is NULL then ASSERT()
1238 this function will convert a SHELL_FILE_ARG based list into a callee allocated
1239 EFI_SHELL_FILE_INFO based list. it is up to the caller to free the memory via
1240 the ShellCloseFileMetaArg function.
1242 @param[in] FileList the EFI shell list type
1243 @param[in,out] ListHead the list to add to
1245 @retval the resultant head of the double linked new format list;
1249 InternalShellConvertFileListType (
1250 IN LIST_ENTRY
*FileList
,
1251 IN OUT LIST_ENTRY
*ListHead
1253 SHELL_FILE_ARG
*OldInfo
;
1255 EFI_SHELL_FILE_INFO_NO_CONST
*NewInfo
;
1260 ASSERT(FileList
!= NULL
);
1261 ASSERT(ListHead
!= NULL
);
1264 // enumerate through each member of the old list and copy
1266 for (Link
= FileList
->ForwardLink
; Link
!= FileList
; Link
= Link
->ForwardLink
) {
1267 OldInfo
= CR (Link
, SHELL_FILE_ARG
, Link
, SHELL_FILE_ARG_SIGNATURE
);
1270 // make sure the old list was valid
1272 ASSERT(OldInfo
!= NULL
);
1273 ASSERT(OldInfo
->Info
!= NULL
);
1274 ASSERT(OldInfo
->FullName
!= NULL
);
1275 ASSERT(OldInfo
->FileName
!= NULL
);
1278 // allocate a new EFI_SHELL_FILE_INFO object
1280 NewInfo
= AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
1283 // copy the simple items
1285 NewInfo
->Handle
= OldInfo
->Handle
;
1286 NewInfo
->Status
= OldInfo
->Status
;
1288 // old shell checks for 0 not NULL
1289 OldInfo
->Handle
= 0;
1292 // allocate new space to copy strings and structure
1294 NewInfo
->FullName
= AllocateZeroPool(StrSize(OldInfo
->FullName
));
1295 NewInfo
->FileName
= AllocateZeroPool(StrSize(OldInfo
->FileName
));
1296 NewInfo
->Info
= AllocateZeroPool((UINTN
)OldInfo
->Info
->Size
);
1299 // make sure all the memory allocations were sucessful
1301 ASSERT(NewInfo
->FullName
!= NULL
);
1302 ASSERT(NewInfo
->FileName
!= NULL
);
1303 ASSERT(NewInfo
->Info
!= NULL
);
1306 // Copt the strings and structure
1308 StrCpy(NewInfo
->FullName
, OldInfo
->FullName
);
1309 StrCpy(NewInfo
->FileName
, OldInfo
->FileName
);
1310 gBS
->CopyMem (NewInfo
->Info
, OldInfo
->Info
, (UINTN
)OldInfo
->Info
->Size
);
1313 // add that to the list
1315 InsertTailList(ListHead
, &NewInfo
->Link
);
1320 Opens a group of files based on a path.
1322 This function uses the Arg to open all the matching files. Each matched
1323 file has a SHELL_FILE_ARG structure to record the file information. These
1324 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
1325 structures from ListHead to access each file. This function supports wildcards
1326 and will process '?' and '*' as such. the list must be freed with a call to
1327 ShellCloseFileMetaArg().
1329 If you are NOT appending to an existing list *ListHead must be NULL. If
1330 *ListHead is NULL then it must be callee freed.
1332 @param Arg pointer to path string
1333 @param OpenMode mode to open files with
1334 @param ListHead head of linked list of results
1336 @retval EFI_SUCCESS the operation was sucessful and the list head
1337 contains the list of opened files
1338 #retval EFI_UNSUPPORTED a previous ShellOpenFileMetaArg must be closed first.
1339 *ListHead is set to NULL.
1340 @return != EFI_SUCCESS the operation failed
1342 @sa InternalShellConvertFileListType
1346 ShellOpenFileMetaArg (
1349 IN OUT EFI_SHELL_FILE_INFO
**ListHead
1353 LIST_ENTRY mOldStyleFileList
;
1356 // ASSERT that Arg and ListHead are not NULL
1358 ASSERT(Arg
!= NULL
);
1359 ASSERT(ListHead
!= NULL
);
1362 // Check for UEFI Shell 2.0 protocols
1364 if (mEfiShellProtocol
!= NULL
) {
1365 if (*ListHead
== NULL
) {
1366 *ListHead
= (EFI_SHELL_FILE_INFO
*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
1367 if (*ListHead
== NULL
) {
1368 return (EFI_OUT_OF_RESOURCES
);
1370 InitializeListHead(&((*ListHead
)->Link
));
1372 Status
= mEfiShellProtocol
->OpenFileList(Arg
,
1375 if (EFI_ERROR(Status
)) {
1376 mEfiShellProtocol
->RemoveDupInFileList(ListHead
);
1378 Status
= mEfiShellProtocol
->RemoveDupInFileList(ListHead
);
1384 // ASSERT that we must have EFI shell
1386 ASSERT(mEfiShellEnvironment2
!= NULL
);
1389 // make sure the list head is initialized
1391 InitializeListHead(&mOldStyleFileList
);
1394 // Get the EFI Shell list of files
1396 Status
= mEfiShellEnvironment2
->FileMetaArg(Arg
, &mOldStyleFileList
);
1397 if (EFI_ERROR(Status
)) {
1402 if (*ListHead
== NULL
) {
1403 *ListHead
= (EFI_SHELL_FILE_INFO
*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
1404 if (*ListHead
== NULL
) {
1405 return (EFI_OUT_OF_RESOURCES
);
1410 // Convert that to equivalent of UEFI Shell 2.0 structure
1412 InternalShellConvertFileListType(&mOldStyleFileList
, &(*ListHead
)->Link
);
1415 // Free the EFI Shell version that was converted.
1417 mEfiShellEnvironment2
->FreeFileList(&mOldStyleFileList
);
1422 Free the linked list returned from ShellOpenFileMetaArg
1424 if ListHead is NULL then ASSERT()
1426 @param ListHead the pointer to free
1428 @retval EFI_SUCCESS the operation was sucessful
1432 ShellCloseFileMetaArg (
1433 IN OUT EFI_SHELL_FILE_INFO
**ListHead
1439 // ASSERT that ListHead is not NULL
1441 ASSERT(ListHead
!= NULL
);
1444 // Check for UEFI Shell 2.0 protocols
1446 if (mEfiShellProtocol
!= NULL
) {
1447 return (mEfiShellProtocol
->FreeFileList(ListHead
));
1450 // Since this is EFI Shell version we need to free our internally made copy
1453 for ( Node
= GetFirstNode(&(*ListHead
)->Link
)
1454 ; IsListEmpty(&(*ListHead
)->Link
) == FALSE
1455 ; Node
= GetFirstNode(&(*ListHead
)->Link
)) {
1456 RemoveEntryList(Node
);
1457 ((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
)->Handle
->Close(((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
)->Handle
);
1458 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
)->FullName
);
1459 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
)->FileName
);
1460 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
)->Info
);
1461 FreePool((EFI_SHELL_FILE_INFO_NO_CONST
*)Node
);
1472 UINTN OriginalPosition
;
1473 } SHELL_PARAM_PACKAGE
;
1476 Checks the list of valid arguments and returns TRUE if the item was found. If the
1477 return value is TRUE then the type parameter is set also.
1479 if CheckList is NULL then ASSERT();
1480 if Name is NULL then ASSERT();
1481 if Type is NULL then ASSERT();
1483 @param Type pointer to type of parameter if it was found
1484 @param Name pointer to Name of parameter found
1485 @param CheckList List to check against
1487 @retval TRUE the Parameter was found. Type is valid.
1488 @retval FALSE the Parameter was not found. Type is not valid.
1492 InternalIsOnCheckList (
1493 IN CONST CHAR16
*Name
,
1494 IN CONST SHELL_PARAM_ITEM
*CheckList
,
1497 SHELL_PARAM_ITEM
*TempListItem
;
1500 // ASSERT that all 3 pointer parameters aren't NULL
1502 ASSERT(CheckList
!= NULL
);
1503 ASSERT(Type
!= NULL
);
1504 ASSERT(Name
!= NULL
);
1507 // question mark and page break mode are always supported
1509 if ((StrCmp(Name
, L
"-?") == 0) ||
1510 (StrCmp(Name
, L
"-b") == 0)
1516 // Enumerate through the list
1518 for (TempListItem
= (SHELL_PARAM_ITEM
*)CheckList
; TempListItem
->Name
!= NULL
; TempListItem
++) {
1520 // If the Type is TypeStart only check the first characters of the passed in param
1521 // If it matches set the type and return TRUE
1523 if (TempListItem
->Type
== TypeStart
&& StrnCmp(Name
, TempListItem
->Name
, StrLen(TempListItem
->Name
)) == 0) {
1524 *Type
= TempListItem
->Type
;
1526 } else if (StrCmp(Name
, TempListItem
->Name
) == 0) {
1527 *Type
= TempListItem
->Type
;
1535 Checks the string for indicators of "flag" status. this is a leading '/', '-', or '+'
1537 @param Name pointer to Name of parameter found
1539 @retval TRUE the Parameter is a flag.
1540 @retval FALSE the Parameter not a flag
1545 IN CONST CHAR16
*Name
,
1546 IN BOOLEAN AlwaysAllowNumbers
1550 // ASSERT that Name isn't NULL
1552 ASSERT(Name
!= NULL
);
1555 // If we accept numbers then dont return TRUE. (they will be values)
1557 if (((Name
[0] == L
'-' || Name
[0] == L
'+') && ShellInternalIsHexaDecimalDigitCharacter(Name
[1])) && AlwaysAllowNumbers
== TRUE
) {
1562 // If the Name has a / or - as the first character return TRUE
1564 if ((Name
[0] == L
'/') ||
1565 (Name
[0] == L
'-') ||
1574 Checks the command line arguments passed against the list of valid ones.
1576 If no initialization is required, then return RETURN_SUCCESS.
1578 @param CheckList pointer to list of parameters to check
1579 @param CheckPackage pointer to pointer to list checked values
1580 @param ProblemParam optional pointer to pointer to unicode string for
1581 the paramater that caused failure. If used then the
1582 caller is responsible for freeing the memory.
1583 @param AutoPageBreak will automatically set PageBreakEnabled for "b" parameter
1584 @param Argc Count of parameters in Argv
1585 @param Argv pointer to array of parameters
1587 @retval EFI_SUCCESS The operation completed sucessfully.
1588 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1589 @retval EFI_INVALID_PARAMETER A parameter was invalid
1590 @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was
1591 duplicated. the duplicated command line argument
1592 was returned in ProblemParam if provided.
1593 @retval EFI_NOT_FOUND a argument required a value that was missing.
1594 the invalid command line argument was returned in
1595 ProblemParam if provided.
1600 InternalCommandLineParse (
1601 IN CONST SHELL_PARAM_ITEM
*CheckList
,
1602 OUT LIST_ENTRY
**CheckPackage
,
1603 OUT CHAR16
**ProblemParam OPTIONAL
,
1604 IN BOOLEAN AutoPageBreak
,
1605 IN CONST CHAR16
**Argv
,
1607 IN BOOLEAN AlwaysAllowNumbers
1610 ParamType CurrentItemType
;
1611 SHELL_PARAM_PACKAGE
*CurrentItemPackage
;
1612 BOOLEAN GetItemValue
;
1614 CurrentItemPackage
= NULL
;
1615 mTotalParameterCount
= 0;
1616 GetItemValue
= FALSE
;
1619 // If there is only 1 item we dont need to do anything
1622 *CheckPackage
= NULL
;
1623 return (EFI_SUCCESS
);
1629 ASSERT(CheckList
!= NULL
);
1630 ASSERT(Argv
!= NULL
);
1633 // initialize the linked list
1635 *CheckPackage
= (LIST_ENTRY
*)AllocateZeroPool(sizeof(LIST_ENTRY
));
1636 InitializeListHead(*CheckPackage
);
1639 // loop through each of the arguments
1641 for (LoopCounter
= 0 ; LoopCounter
< Argc
; ++LoopCounter
) {
1642 if (Argv
[LoopCounter
] == NULL
) {
1644 // do nothing for NULL argv
1646 } else if (InternalIsOnCheckList(Argv
[LoopCounter
], CheckList
, &CurrentItemType
) == TRUE
) {
1648 // We might have leftover if last parameter didnt have optional value
1650 if (GetItemValue
== TRUE
) {
1651 GetItemValue
= FALSE
;
1652 InsertHeadList(*CheckPackage
, &CurrentItemPackage
->Link
);
1657 CurrentItemPackage
= AllocatePool(sizeof(SHELL_PARAM_PACKAGE
));
1658 ASSERT(CurrentItemPackage
!= NULL
);
1659 CurrentItemPackage
->Name
= AllocatePool(StrSize(Argv
[LoopCounter
]));
1660 ASSERT(CurrentItemPackage
->Name
!= NULL
);
1661 StrCpy(CurrentItemPackage
->Name
, Argv
[LoopCounter
]);
1662 CurrentItemPackage
->Type
= CurrentItemType
;
1663 CurrentItemPackage
->OriginalPosition
= (UINTN
)(-1);
1664 CurrentItemPackage
->Value
= NULL
;
1667 // Does this flag require a value
1669 if (CurrentItemPackage
->Type
== TypeValue
) {
1671 // trigger the next loop to populate the value of this item
1673 GetItemValue
= TRUE
;
1676 // this item has no value expected; we are done
1678 InsertHeadList(*CheckPackage
, &CurrentItemPackage
->Link
);
1680 } else if (GetItemValue
== TRUE
&& InternalIsFlag(Argv
[LoopCounter
], AlwaysAllowNumbers
) == FALSE
) {
1681 ASSERT(CurrentItemPackage
!= NULL
);
1683 // get the item VALUE for the previous flag
1685 GetItemValue
= FALSE
;
1686 CurrentItemPackage
->Value
= AllocateZeroPool(StrSize(Argv
[LoopCounter
]));
1687 ASSERT(CurrentItemPackage
->Value
!= NULL
);
1688 StrCpy(CurrentItemPackage
->Value
, Argv
[LoopCounter
]);
1689 InsertHeadList(*CheckPackage
, &CurrentItemPackage
->Link
);
1690 } else if (InternalIsFlag(Argv
[LoopCounter
], AlwaysAllowNumbers
) == FALSE
) {
1692 // add this one as a non-flag
1694 CurrentItemPackage
= AllocatePool(sizeof(SHELL_PARAM_PACKAGE
));
1695 ASSERT(CurrentItemPackage
!= NULL
);
1696 CurrentItemPackage
->Name
= NULL
;
1697 CurrentItemPackage
->Type
= TypePosition
;
1698 CurrentItemPackage
->Value
= AllocatePool(StrSize(Argv
[LoopCounter
]));
1699 ASSERT(CurrentItemPackage
->Value
!= NULL
);
1700 StrCpy(CurrentItemPackage
->Value
, Argv
[LoopCounter
]);
1701 CurrentItemPackage
->OriginalPosition
= mTotalParameterCount
++;
1702 InsertHeadList(*CheckPackage
, &CurrentItemPackage
->Link
);
1703 } else if (ProblemParam
) {
1705 // this was a non-recognised flag... error!
1707 *ProblemParam
= AllocatePool(StrSize(Argv
[LoopCounter
]));
1708 ASSERT(*ProblemParam
!= NULL
);
1709 StrCpy(*ProblemParam
, Argv
[LoopCounter
]);
1710 ShellCommandLineFreeVarList(*CheckPackage
);
1711 *CheckPackage
= NULL
;
1712 return (EFI_VOLUME_CORRUPTED
);
1714 ShellCommandLineFreeVarList(*CheckPackage
);
1715 *CheckPackage
= NULL
;
1716 return (EFI_VOLUME_CORRUPTED
);
1720 // support for AutoPageBreak
1722 if (AutoPageBreak
&& ShellCommandLineGetFlag(*CheckPackage
, L
"-b")) {
1723 ShellSetPageBreakMode(TRUE
);
1725 return (EFI_SUCCESS
);
1729 Checks the command line arguments passed against the list of valid ones.
1730 Optionally removes NULL values first.
1732 If no initialization is required, then return RETURN_SUCCESS.
1734 @param CheckList pointer to list of parameters to check
1735 @param CheckPackage pointer to pointer to list checked values
1736 @param ProblemParam optional pointer to pointer to unicode string for
1737 the paramater that caused failure.
1738 @param AutoPageBreak will automatically set PageBreakEnabled for "b" parameter
1740 @retval EFI_SUCCESS The operation completed sucessfully.
1741 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1742 @retval EFI_INVALID_PARAMETER A parameter was invalid
1743 @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was
1744 duplicated. the duplicated command line argument
1745 was returned in ProblemParam if provided.
1746 @retval EFI_DEVICE_ERROR the commands contained 2 opposing arguments. one
1747 of the command line arguments was returned in
1748 ProblemParam if provided.
1749 @retval EFI_NOT_FOUND a argument required a value that was missing.
1750 the invalid command line argument was returned in
1751 ProblemParam if provided.
1755 ShellCommandLineParseEx (
1756 IN CONST SHELL_PARAM_ITEM
*CheckList
,
1757 OUT LIST_ENTRY
**CheckPackage
,
1758 OUT CHAR16
**ProblemParam OPTIONAL
,
1759 IN BOOLEAN AutoPageBreak
,
1760 IN BOOLEAN AlwaysAllowNumbers
1763 // ASSERT that CheckList and CheckPackage aren't NULL
1765 ASSERT(CheckList
!= NULL
);
1766 ASSERT(CheckPackage
!= NULL
);
1769 // Check for UEFI Shell 2.0 protocols
1771 if (mEfiShellParametersProtocol
!= NULL
) {
1772 return (InternalCommandLineParse(CheckList
,
1776 (CONST CHAR16
**) mEfiShellParametersProtocol
->Argv
,
1777 mEfiShellParametersProtocol
->Argc
,
1778 AlwaysAllowNumbers
));
1782 // ASSERT That EFI Shell is not required
1784 ASSERT (mEfiShellInterface
!= NULL
);
1785 return (InternalCommandLineParse(CheckList
,
1789 (CONST CHAR16
**) mEfiShellInterface
->Argv
,
1790 mEfiShellInterface
->Argc
,
1791 AlwaysAllowNumbers
));
1795 Frees shell variable list that was returned from ShellCommandLineParse.
1797 This function will free all the memory that was used for the CheckPackage
1798 list of postprocessed shell arguments.
1800 this function has no return value.
1802 if CheckPackage is NULL, then return
1804 @param CheckPackage the list to de-allocate
1808 ShellCommandLineFreeVarList (
1809 IN LIST_ENTRY
*CheckPackage
1814 // check for CheckPackage == NULL
1816 if (CheckPackage
== NULL
) {
1821 // for each node in the list
1823 for ( Node
= GetFirstNode(CheckPackage
)
1824 ; IsListEmpty(CheckPackage
) == FALSE
1825 ; Node
= GetFirstNode(CheckPackage
)
1828 // Remove it from the list
1830 RemoveEntryList(Node
);
1833 // if it has a name free the name
1835 if (((SHELL_PARAM_PACKAGE
*)Node
)->Name
!= NULL
) {
1836 FreePool(((SHELL_PARAM_PACKAGE
*)Node
)->Name
);
1840 // if it has a value free the value
1842 if (((SHELL_PARAM_PACKAGE
*)Node
)->Value
!= NULL
) {
1843 FreePool(((SHELL_PARAM_PACKAGE
*)Node
)->Value
);
1847 // free the node structure
1849 FreePool((SHELL_PARAM_PACKAGE
*)Node
);
1852 // free the list head node
1854 FreePool(CheckPackage
);
1857 Checks for presence of a flag parameter
1859 flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key
1861 if CheckPackage is NULL then return FALSE.
1862 if KeyString is NULL then ASSERT()
1864 @param CheckPackage The package of parsed command line arguments
1865 @param KeyString the Key of the command line argument to check for
1867 @retval TRUE the flag is on the command line
1868 @retval FALSE the flag is not on the command line
1872 ShellCommandLineGetFlag (
1873 IN CONST LIST_ENTRY
*CheckPackage
,
1874 IN CHAR16
*KeyString
1879 // ASSERT that both CheckPackage and KeyString aren't NULL
1881 ASSERT(KeyString
!= NULL
);
1884 // return FALSE for no package
1886 if (CheckPackage
== NULL
) {
1891 // enumerate through the list of parametrs
1893 for ( Node
= GetFirstNode(CheckPackage
)
1894 ; !IsNull (CheckPackage
, Node
)
1895 ; Node
= GetNextNode(CheckPackage
, Node
)
1898 // If the Name matches, return TRUE (and there may be NULL name)
1900 if (((SHELL_PARAM_PACKAGE
*)Node
)->Name
!= NULL
) {
1902 // If Type is TypeStart then only compare the begining of the strings
1904 if ( ((SHELL_PARAM_PACKAGE
*)Node
)->Type
== TypeStart
1905 && StrnCmp(KeyString
, ((SHELL_PARAM_PACKAGE
*)Node
)->Name
, StrLen(KeyString
)) == 0
1908 } else if (StrCmp(KeyString
, ((SHELL_PARAM_PACKAGE
*)Node
)->Name
) == 0) {
1916 returns value from command line argument
1918 value parameters are in the form of "-<Key> value" or "/<Key> value"
1920 if CheckPackage is NULL, then return NULL;
1922 @param CheckPackage The package of parsed command line arguments
1923 @param KeyString the Key of the command line argument to check for
1925 @retval NULL the flag is not on the command line
1926 @return !=NULL pointer to unicode string of the value
1930 ShellCommandLineGetValue (
1931 IN CONST LIST_ENTRY
*CheckPackage
,
1932 IN CHAR16
*KeyString
1937 // check for CheckPackage == NULL
1939 if (CheckPackage
== NULL
) {
1944 // enumerate through the list of parametrs
1946 for ( Node
= GetFirstNode(CheckPackage
)
1947 ; !IsNull (CheckPackage
, Node
)
1948 ; Node
= GetNextNode(CheckPackage
, Node
)
1951 // If the Name matches, return the value (name can be NULL)
1953 if (((SHELL_PARAM_PACKAGE
*)Node
)->Name
!= NULL
) {
1955 // If Type is TypeStart then only compare the begining of the strings
1957 if ( ((SHELL_PARAM_PACKAGE
*)Node
)->Type
== TypeStart
1958 && StrnCmp(KeyString
, ((SHELL_PARAM_PACKAGE
*)Node
)->Name
, StrLen(KeyString
)) == 0
1961 // return the string part after the flag
1963 return (((SHELL_PARAM_PACKAGE
*)Node
)->Name
+ StrLen(KeyString
));
1964 } else if (StrCmp(KeyString
, ((SHELL_PARAM_PACKAGE
*)Node
)->Name
) == 0) {
1968 return (((SHELL_PARAM_PACKAGE
*)Node
)->Value
);
1975 returns raw value from command line argument
1977 raw value parameters are in the form of "value" in a specific position in the list
1979 if CheckPackage is NULL, then return NULL;
1981 @param CheckPackage The package of parsed command line arguments
1982 @param Position the position of the value
1984 @retval NULL the flag is not on the command line
1985 @return !=NULL pointer to unicode string of the value
1989 ShellCommandLineGetRawValue (
1990 IN CONST LIST_ENTRY
*CheckPackage
,
1996 // check for CheckPackage == NULL
1998 if (CheckPackage
== NULL
) {
2003 // enumerate through the list of parametrs
2005 for ( Node
= GetFirstNode(CheckPackage
)
2006 ; !IsNull (CheckPackage
, Node
)
2007 ; Node
= GetNextNode(CheckPackage
, Node
)
2010 // If the position matches, return the value
2012 if (((SHELL_PARAM_PACKAGE
*)Node
)->OriginalPosition
== Position
) {
2013 return (((SHELL_PARAM_PACKAGE
*)Node
)->Value
);
2020 returns the number of command line value parameters that were parsed.
2022 this will not include flags.
2024 @retval (UINTN)-1 No parsing has ocurred
2025 @return other The number of value parameters found
2029 ShellCommandLineGetCount(
2032 return (mTotalParameterCount
);
2036 This is a find and replace function. it will return the NewString as a copy of
2037 SourceString with each instance of FindTarget replaced with ReplaceWith.
2039 If the string would grow bigger than NewSize it will halt and return error.
2041 @param[in] SourceString String with source buffer
2042 @param[in,out] NewString String with resultant buffer
2043 @param[in] NewSize Size in bytes of NewString
2044 @param[in] FindTarget String to look for
2045 @param[in[ ReplaceWith String to replace FindTarget with
2047 @retval EFI_INVALID_PARAMETER SourceString was NULL
2048 @retval EFI_INVALID_PARAMETER NewString was NULL
2049 @retval EFI_INVALID_PARAMETER FindTarget was NULL
2050 @retval EFI_INVALID_PARAMETER ReplaceWith was NULL
2051 @retval EFI_INVALID_PARAMETER FindTarget had length < 1
2052 @retval EFI_INVALID_PARAMETER SourceString had length < 1
2053 @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
2054 the new string (truncation occurred)
2055 @retval EFI_SUCCESS the string was sucessfully copied with replacement
2061 IN CHAR16 CONST
*SourceString
,
2062 IN CHAR16
*NewString
,
2064 IN CONST CHAR16
*FindTarget
,
2065 IN CONST CHAR16
*ReplaceWith
2069 if ( (SourceString
== NULL
)
2070 || (NewString
== NULL
)
2071 || (FindTarget
== NULL
)
2072 || (ReplaceWith
== NULL
)
2073 || (StrLen(FindTarget
) < 1)
2074 || (StrLen(SourceString
) < 1)
2076 return (EFI_INVALID_PARAMETER
);
2078 NewString
= SetMem16(NewString
, NewSize
, CHAR_NULL
);
2079 while (*SourceString
!= CHAR_NULL
) {
2080 if (StrnCmp(SourceString
, FindTarget
, StrLen(FindTarget
)) == 0) {
2081 SourceString
+= StrLen(FindTarget
);
2082 Size
= StrSize(NewString
);
2083 if ((Size
+ (StrLen(ReplaceWith
)*sizeof(CHAR16
))) > NewSize
) {
2084 return (EFI_BUFFER_TOO_SMALL
);
2086 StrCat(NewString
, ReplaceWith
);
2088 Size
= StrSize(NewString
);
2089 if (Size
+ sizeof(CHAR16
) > NewSize
) {
2090 return (EFI_BUFFER_TOO_SMALL
);
2092 StrnCat(NewString
, SourceString
, 1);
2096 return (EFI_SUCCESS
);
2100 Print at a specific location on the screen.
2102 This function will move the cursor to a given screen location and print the specified string
2104 If -1 is specified for either the Row or Col the current screen location for BOTH
2107 if either Row or Col is out of range for the current console, then ASSERT
2108 if Format is NULL, then ASSERT
2110 In addition to the standard %-based flags as supported by UefiLib Print() this supports
2111 the following additional flags:
2112 %N - Set output attribute to normal
2113 %H - Set output attribute to highlight
2114 %E - Set output attribute to error
2115 %B - Set output attribute to blue color
2116 %V - Set output attribute to green color
2118 Note: The background color is controlled by the shell command cls.
2120 @param[in] Row the row to print at
2121 @param[in] Col the column to print at
2122 @param[in] Format the format string
2123 @param[in] Marker the marker for the variable argument list
2125 @return the number of characters printed to the screen
2130 InternalShellPrintWorker(
2131 IN INT32 Col OPTIONAL
,
2132 IN INT32 Row OPTIONAL
,
2133 IN CONST CHAR16
*Format
,
2138 CHAR16
*PostReplaceFormat
;
2139 CHAR16
*PostReplaceFormat2
;
2142 UINTN NormalAttribute
;
2143 CHAR16
*ResumeLocation
;
2144 CHAR16
*FormatWalker
;
2146 BufferSize
= (PcdGet32 (PcdUefiLibMaxPrintBufferSize
) + 1) * sizeof (CHAR16
);
2147 PostReplaceFormat
= AllocateZeroPool (BufferSize
);
2148 ASSERT (PostReplaceFormat
!= NULL
);
2149 PostReplaceFormat2
= AllocateZeroPool (BufferSize
);
2150 ASSERT (PostReplaceFormat2
!= NULL
);
2153 // Back and forth each time fixing up 1 of our flags...
2155 Status
= CopyReplace(Format
, PostReplaceFormat
, BufferSize
, L
"%N", L
"%%N");
2156 ASSERT_EFI_ERROR(Status
);
2157 Status
= CopyReplace(PostReplaceFormat
, PostReplaceFormat2
, BufferSize
, L
"%E", L
"%%E");
2158 ASSERT_EFI_ERROR(Status
);
2159 Status
= CopyReplace(PostReplaceFormat2
, PostReplaceFormat
, BufferSize
, L
"%H", L
"%%H");
2160 ASSERT_EFI_ERROR(Status
);
2161 Status
= CopyReplace(PostReplaceFormat
, PostReplaceFormat2
, BufferSize
, L
"%B", L
"%%B");
2162 ASSERT_EFI_ERROR(Status
);
2163 Status
= CopyReplace(PostReplaceFormat2
, PostReplaceFormat
, BufferSize
, L
"%V", L
"%%V");
2164 ASSERT_EFI_ERROR(Status
);
2167 // Use the last buffer from replacing to print from...
2169 Return
= UnicodeVSPrint (PostReplaceFormat2
, BufferSize
, PostReplaceFormat
, Marker
);
2171 FreePool(PostReplaceFormat
);
2173 if (Col
!= -1 && Row
!= -1) {
2174 Status
= gST
->ConOut
->SetCursorPosition(gST
->ConOut
, Col
, Row
);
2175 ASSERT_EFI_ERROR(Status
);
2178 NormalAttribute
= gST
->ConOut
->Mode
->Attribute
;
2179 FormatWalker
= PostReplaceFormat2
;
2180 while (*FormatWalker
!= CHAR_NULL
) {
2182 // Find the next attribute change request
2184 ResumeLocation
= StrStr(FormatWalker
, L
"%");
2185 if (ResumeLocation
!= NULL
) {
2186 *ResumeLocation
= CHAR_NULL
;
2189 // print the current FormatWalker string
2191 Status
= gST
->ConOut
->OutputString(gST
->ConOut
, FormatWalker
);
2192 ASSERT_EFI_ERROR(Status
);
2194 // update the attribute
2196 if (ResumeLocation
!= NULL
) {
2197 switch (*(ResumeLocation
+1)) {
2199 gST
->ConOut
->SetAttribute(gST
->ConOut
, NormalAttribute
);
2202 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR(EFI_YELLOW
, ((NormalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)));
2205 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR(EFI_WHITE
, ((NormalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)));
2208 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR(EFI_BLUE
, ((NormalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)));
2211 gST
->ConOut
->SetAttribute(gST
->ConOut
, EFI_TEXT_ATTR(EFI_GREEN
, ((NormalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)));
2219 // reset to normal now...
2221 gST
->ConOut
->SetAttribute(gST
->ConOut
, NormalAttribute
);
2226 // update FormatWalker to Resume + 2 (skip the % and the indicator)
2228 FormatWalker
= ResumeLocation
+ 2;
2231 FreePool(PostReplaceFormat2
);
2237 Print at a specific location on the screen.
2239 This function will move the cursor to a given screen location and print the specified string
2241 If -1 is specified for either the Row or Col the current screen location for BOTH
2244 if either Row or Col is out of range for the current console, then ASSERT
2245 if Format is NULL, then ASSERT
2247 In addition to the standard %-based flags as supported by UefiLib Print() this supports
2248 the following additional flags:
2249 %N - Set output attribute to normal
2250 %H - Set output attribute to highlight
2251 %E - Set output attribute to error
2252 %B - Set output attribute to blue color
2253 %V - Set output attribute to green color
2255 Note: The background color is controlled by the shell command cls.
2257 @param[in] Row the row to print at
2258 @param[in] Col the column to print at
2259 @param[in] Format the format string
2261 @return the number of characters printed to the screen
2267 IN INT32 Col OPTIONAL
,
2268 IN INT32 Row OPTIONAL
,
2269 IN CONST CHAR16
*Format
,
2274 VA_START (Marker
, Format
);
2275 return (InternalShellPrintWorker(Col
, Row
, Format
, Marker
));
2279 Print at a specific location on the screen.
2281 This function will move the cursor to a given screen location, print the specified string,
2282 and return the cursor to the original locaiton.
2284 If -1 is specified for either the Row or Col the current screen location for BOTH
2285 will be used and the cursor's position will not be moved back to an original location.
2287 if either Row or Col is out of range for the current console, then ASSERT
2288 if Format is NULL, then ASSERT
2290 In addition to the standard %-based flags as supported by UefiLib Print() this supports
2291 the following additional flags:
2292 %N - Set output attribute to normal
2293 %H - Set output attribute to highlight
2294 %E - Set output attribute to error
2295 %B - Set output attribute to blue color
2296 %V - Set output attribute to green color
2298 Note: The background color is controlled by the shell command cls.
2300 @param[in] Row the row to print at
2301 @param[in] Col the column to print at
2302 @param[in] HiiFormatStringId the format string Id for getting from Hii
2303 @param[in] HiiFormatHandle the format string Handle for getting from Hii
2305 @return the number of characters printed to the screen
2310 IN INT32 Col OPTIONAL
,
2311 IN INT32 Row OPTIONAL
,
2312 IN CONST EFI_STRING_ID HiiFormatStringId
,
2313 IN CONST EFI_HANDLE HiiFormatHandle
,
2318 CHAR16
*HiiFormatString
;
2321 VA_START (Marker
, HiiFormatHandle
);
2322 HiiFormatString
= HiiGetString(HiiFormatHandle
, HiiFormatStringId
, NULL
);
2323 ASSERT(HiiFormatString
!= NULL
);
2325 RetVal
= InternalShellPrintWorker(Col
, Row
, HiiFormatString
, Marker
);
2327 FreePool(HiiFormatString
);
2333 Function to determine if a given filename represents a file or a directory.
2335 @param[in] DirName Path to directory to test.
2337 @retval EFI_SUCCESS The Path represents a directory
2338 @retval EFI_NOT_FOUND The Path does not represent a directory
2339 @return other The path failed to open
2344 IN CONST CHAR16
*DirName
2348 EFI_FILE_HANDLE Handle
;
2352 Status
= ShellOpenFileByName(DirName
, &Handle
, EFI_FILE_MODE_READ
, 0);
2353 if (EFI_ERROR(Status
)) {
2357 if (FileHandleIsDirectory(Handle
) == EFI_SUCCESS
) {
2358 ShellCloseFile(&Handle
);
2359 return (EFI_SUCCESS
);
2361 ShellCloseFile(&Handle
);
2362 return (EFI_NOT_FOUND
);