2 Main file for ls shell level 2 function.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel2CommandsLib.h"
17 #include <Guid/FileSystemInfo.h>
19 UINTN mDayOfMonth
[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
22 print out the standard format output volume entry.
24 @param[in] TheList a list of files from the volume.
27 PrintSfoVolumeInfoTableEntry(
28 IN CONST EFI_SHELL_FILE_INFO
*TheList
32 EFI_SHELL_FILE_INFO
*Node
;
33 CHAR16
*DirectoryName
;
34 EFI_FILE_SYSTEM_INFO
*SysInfo
;
36 SHELL_FILE_HANDLE ShellFileHandle
;
37 EFI_FILE_PROTOCOL
*EfiFpHandle
;
40 // Get the first valid handle (directories)
42 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&TheList
->Link
)
43 ; !IsNull(&TheList
->Link
, &Node
->Link
) && Node
->Handle
== NULL
44 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&TheList
->Link
, &Node
->Link
)
47 if (Node
->Handle
== NULL
) {
48 DirectoryName
= GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO
*)GetFirstNode(&TheList
->Link
))->FullName
);
51 // We need to open something up to get system information
53 Status
= gEfiShellProtocol
->OpenFileByName(
59 ASSERT_EFI_ERROR(Status
);
60 FreePool(DirectoryName
);
63 // Get the Volume Info from ShellFileHandle
67 EfiFpHandle
= ConvertShellHandleToEfiFileProtocol(ShellFileHandle
);
68 Status
= EfiFpHandle
->GetInfo(
70 &gEfiFileSystemInfoGuid
,
75 if (Status
== EFI_BUFFER_TOO_SMALL
) {
76 SysInfo
= AllocateZeroPool(SysInfoSize
);
77 Status
= EfiFpHandle
->GetInfo(
79 &gEfiFileSystemInfoGuid
,
85 ASSERT_EFI_ERROR(Status
);
87 gEfiShellProtocol
->CloseFile(ShellFileHandle
);
90 // Get the Volume Info from Node->Handle
94 EfiFpHandle
= ConvertShellHandleToEfiFileProtocol(Node
->Handle
);
95 Status
= EfiFpHandle
->GetInfo(
97 &gEfiFileSystemInfoGuid
,
102 if (Status
== EFI_BUFFER_TOO_SMALL
) {
103 SysInfo
= AllocateZeroPool(SysInfoSize
);
104 Status
= EfiFpHandle
->GetInfo(
106 &gEfiFileSystemInfoGuid
,
112 ASSERT_EFI_ERROR(Status
);
119 STRING_TOKEN (STR_GEN_SFO_HEADER
),
120 gShellLevel2HiiHandle
,
124 // print VolumeInfo table
126 ASSERT(SysInfo
!= NULL
);
129 gST
->ConOut
->Mode
->CursorRow
,
131 STRING_TOKEN (STR_LS_SFO_VOLINFO
),
132 gShellLevel2HiiHandle
,
133 SysInfo
->VolumeLabel
,
135 SysInfo
->ReadOnly
?L
"TRUE":L
"FALSE",
140 SHELL_FREE_NON_NULL(SysInfo
);
146 print out the info on a single file.
148 @param[in] Sfo TRUE if in SFO, false otherwise.
149 @param[in] TheNode the EFI_SHELL_FILE_INFO node to print out information on.
150 @param[in] Files incremented if a file is printed.
151 @param[in] Size incremented by file size.
152 @param[in] Dirs incremented if a directory is printed.
156 PrintFileInformation(
157 IN CONST BOOLEAN Sfo
,
158 IN CONST EFI_SHELL_FILE_INFO
*TheNode
,
164 ASSERT(Files
!= NULL
);
165 ASSERT(Size
!= NULL
);
166 ASSERT(Dirs
!= NULL
);
167 ASSERT(TheNode
!= NULL
);
171 // Print the FileInfo Table
175 gST
->ConOut
->Mode
->CursorRow
,
177 STRING_TOKEN (STR_LS_SFO_FILEINFO
),
178 gShellLevel2HiiHandle
,
180 TheNode
->Info
->FileSize
,
181 TheNode
->Info
->PhysicalSize
,
182 (TheNode
->Info
->Attribute
& EFI_FILE_ARCHIVE
) != 0?L
"a":L
"",
183 (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) != 0?L
"d":L
"",
184 (TheNode
->Info
->Attribute
& EFI_FILE_HIDDEN
) != 0?L
"h":L
"",
185 (TheNode
->Info
->Attribute
& EFI_FILE_READ_ONLY
) != 0?L
"r":L
"",
186 (TheNode
->Info
->Attribute
& EFI_FILE_SYSTEM
) != 0?L
"s":L
"",
187 TheNode
->Info
->CreateTime
.Hour
,
188 TheNode
->Info
->CreateTime
.Minute
,
189 TheNode
->Info
->CreateTime
.Second
,
190 TheNode
->Info
->CreateTime
.Day
,
191 TheNode
->Info
->CreateTime
.Month
,
192 TheNode
->Info
->CreateTime
.Year
,
193 TheNode
->Info
->LastAccessTime
.Hour
,
194 TheNode
->Info
->LastAccessTime
.Minute
,
195 TheNode
->Info
->LastAccessTime
.Second
,
196 TheNode
->Info
->LastAccessTime
.Day
,
197 TheNode
->Info
->LastAccessTime
.Month
,
198 TheNode
->Info
->LastAccessTime
.Year
,
199 TheNode
->Info
->ModificationTime
.Hour
,
200 TheNode
->Info
->ModificationTime
.Minute
,
201 TheNode
->Info
->ModificationTime
.Second
,
202 TheNode
->Info
->ModificationTime
.Day
,
203 TheNode
->Info
->ModificationTime
.Month
,
204 TheNode
->Info
->ModificationTime
.Year
208 // print this one out...
209 // first print the universal start, next print the type specific name format, last print the CRLF
215 STRING_TOKEN (STR_LS_LINE_START_ALL
),
216 gShellLevel2HiiHandle
,
217 &TheNode
->Info
->ModificationTime
,
218 (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) != 0?L
"<DIR>":L
"",
219 (TheNode
->Info
->Attribute
& EFI_FILE_READ_ONLY
) != 0?L
'r':L
' ',
220 TheNode
->Info
->FileSize
222 if (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) {
228 STRING_TOKEN (STR_LS_LINE_END_DIR
),
229 gShellLevel2HiiHandle
,
234 (*Size
) += TheNode
->Info
->FileSize
;
235 if ( (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)L
".nsh", (CHAR16
*)&(TheNode
->FileName
[StrLen (TheNode
->FileName
) - 4])) == 0)
236 || (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)L
".efi", (CHAR16
*)&(TheNode
->FileName
[StrLen (TheNode
->FileName
) - 4])) == 0)
242 STRING_TOKEN (STR_LS_LINE_END_EXE
),
243 gShellLevel2HiiHandle
,
251 STRING_TOKEN (STR_LS_LINE_END_FILE
),
252 gShellLevel2HiiHandle
,
261 print out the header when not using standard format output.
263 @param[in] Path String with starting path.
267 IN CONST CHAR16
*Path
270 CHAR16
*DirectoryName
;
273 // get directory name from path...
275 DirectoryName
= GetFullyQualifiedPath(Path
);
277 if (DirectoryName
!= NULL
) {
283 gST
->ConOut
->Mode
->CursorRow
,
285 STRING_TOKEN (STR_LS_HEADER_LINE1
),
286 gShellLevel2HiiHandle
,
290 SHELL_FREE_NON_NULL(DirectoryName
);
295 print out the footer when not using standard format output.
297 @param[in] Files The number of files.
298 @param[in] Size The size of files in bytes.
299 @param[in] Dirs The number of directories.
315 STRING_TOKEN (STR_LS_FOOTER_LINE
),
316 gShellLevel2HiiHandle
,
324 Change the file time to local time based on the timezone.
326 @param[in] Time The file time.
327 @param[in] LocalTimeZone Local time zone.
330 FileTimeToLocalTime (
332 IN INT16 LocalTimeZone
337 INTN HourNumberOfTempMinute
;
339 INTN DayNumberOfTempHour
;
341 INTN MonthNumberOfTempDay
;
343 INTN YearNumberOfTempMonth
;
346 ASSERT ((Time
->TimeZone
>= -1440) && (Time
->TimeZone
<=1440));
347 ASSERT ((LocalTimeZone
>= -1440) && (LocalTimeZone
<=1440));
348 ASSERT ((Time
->Month
>= 1) && (Time
->Month
<= 12));
350 if(Time
->TimeZone
== LocalTimeZone
) {
352 //if the file timezone is equal to the local timezone, there is no need to adjust the file time.
357 if((Time
->Year
% 4 == 0 && Time
->Year
/ 100 != 0)||(Time
->Year
% 400 == 0)) {
359 // Day in February of leap year is 29.
364 MinuteDiff
= Time
->TimeZone
- LocalTimeZone
;
365 TempMinute
= Time
->Minute
+ MinuteDiff
;
368 // Calculate Time->Minute
369 // TempHour will be used to calculate Time->Hour
371 HourNumberOfTempMinute
= TempMinute
/ 60;
373 HourNumberOfTempMinute
--;
375 TempHour
= Time
->Hour
+ HourNumberOfTempMinute
;
376 Time
->Minute
= (UINT8
)(TempMinute
- 60 * HourNumberOfTempMinute
);
379 // Calculate Time->Hour
380 // TempDay will be used to calculate Time->Day
382 DayNumberOfTempHour
= TempHour
/ 24 ;
384 DayNumberOfTempHour
--;
386 TempDay
= Time
->Day
+ DayNumberOfTempHour
;
387 Time
->Hour
= (UINT8
)(TempHour
- 24 * DayNumberOfTempHour
);
390 // Calculate Time->Day
391 // TempMonth will be used to calculate Time->Month
393 MonthNumberOfTempDay
= (TempDay
- 1) / (INTN
)mDayOfMonth
[Time
->Month
- 1];
394 MonthRecord
= (INTN
)(Time
->Month
) ;
396 MonthNumberOfTempDay
-- ;
399 TempMonth
= Time
->Month
+ MonthNumberOfTempDay
;
400 Time
->Day
= (UINT8
)(TempDay
- (INTN
)mDayOfMonth
[(MonthRecord
- 1 + 12) % 12] * MonthNumberOfTempDay
);
403 // Calculate Time->Month, Time->Year
405 YearNumberOfTempMonth
= (TempMonth
- 1) / 12;
406 if(TempMonth
- 1 < 0){
407 YearNumberOfTempMonth
--;
409 Time
->Month
= (UINT8
)(TempMonth
- 12 * (YearNumberOfTempMonth
));
410 Time
->Year
= (UINT16
)(Time
->Year
+ YearNumberOfTempMonth
);
414 print out the list of files and directories from the LS command
416 @param[in] Rec TRUE to automatically recurse into each found directory
417 FALSE to only list the specified directory.
418 @param[in] Attribs List of required Attribute for display.
419 If 0 then all non-system and non-hidden files will be printed.
420 @param[in] Sfo TRUE to use Standard Format Output, FALSE otherwise
421 @param[in] RootPath String with starting path to search in.
422 @param[in] SearchString String with search string.
423 @param[in] Found Set to TRUE, if anyone were found.
424 @param[in] Count The count of bits enabled in Attribs.
425 @param[in] TimeZone The current time zone offset.
427 @retval SHELL_SUCCESS the printing was sucessful.
431 IN CONST BOOLEAN Rec
,
432 IN CONST UINT64 Attribs
,
433 IN CONST BOOLEAN Sfo
,
434 IN CONST CHAR16
*RootPath
,
435 IN CONST CHAR16
*SearchString
,
437 IN CONST UINTN Count
,
438 IN CONST INT16 TimeZone
442 EFI_SHELL_FILE_INFO
*ListHead
;
443 EFI_SHELL_FILE_INFO
*Node
;
444 SHELL_STATUS ShellStatus
;
449 CHAR16
*CorrectedPath
;
451 BOOLEAN HeaderPrinted
;
454 HeaderPrinted
= FALSE
;
459 ShellStatus
= SHELL_SUCCESS
;
461 CorrectedPath
= NULL
;
469 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, RootPath
, 0);
470 if (CorrectedPath
== NULL
) {
471 return SHELL_OUT_OF_RESOURCES
;
473 if (CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'\\'
474 &&CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'/') {
475 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"\\", 0);
477 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, SearchString
, 0);
478 if (CorrectedPath
== NULL
) {
479 return (SHELL_OUT_OF_RESOURCES
);
482 PathCleanUpDirectories(CorrectedPath
);
484 Status
= ShellOpenFileMetaArg((CHAR16
*)CorrectedPath
, EFI_FILE_MODE_READ
, &ListHead
);
485 if (!EFI_ERROR(Status
)) {
486 if (ListHead
== NULL
|| IsListEmpty(&ListHead
->Link
)) {
487 SHELL_FREE_NON_NULL(CorrectedPath
);
488 return (SHELL_SUCCESS
);
491 if (Sfo
&& Found
== NULL
) {
492 PrintSfoVolumeInfoTableEntry(ListHead
);
495 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ListHead
->Link
), LongestPath
= 0
496 ; !IsNull(&ListHead
->Link
, &Node
->Link
)
497 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ListHead
->Link
, &Node
->Link
)
499 if (ShellGetExecutionBreakFlag ()) {
500 ShellStatus
= SHELL_ABORTED
;
503 ASSERT(Node
!= NULL
);
506 // Change the file time to local time.
508 Status
= gRT
->GetTime(&LocalTime
, NULL
);
509 if (!EFI_ERROR (Status
)) {
510 if ((Node
->Info
->CreateTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
511 (Node
->Info
->CreateTime
.Month
>= 1 && Node
->Info
->CreateTime
.Month
<= 12)) {
513 // FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
515 FileTimeToLocalTime (&Node
->Info
->CreateTime
, LocalTime
.TimeZone
);
517 if ((Node
->Info
->LastAccessTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
518 (Node
->Info
->LastAccessTime
.Month
>= 1 && Node
->Info
->LastAccessTime
.Month
<= 12)) {
519 FileTimeToLocalTime (&Node
->Info
->LastAccessTime
, LocalTime
.TimeZone
);
521 if ((Node
->Info
->ModificationTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
522 (Node
->Info
->ModificationTime
.Month
>= 1 && Node
->Info
->ModificationTime
.Month
<= 12)) {
523 FileTimeToLocalTime (&Node
->Info
->ModificationTime
, LocalTime
.TimeZone
);
527 if (LongestPath
< StrSize(Node
->FullName
)) {
528 LongestPath
= StrSize(Node
->FullName
);
530 ASSERT(Node
->Info
!= NULL
);
531 ASSERT((Node
->Info
->Attribute
& EFI_FILE_VALID_ATTR
) == Node
->Info
->Attribute
);
534 // NOT system & NOT hidden
536 if ( (Node
->Info
->Attribute
& EFI_FILE_SYSTEM
)
537 || (Node
->Info
->Attribute
& EFI_FILE_HIDDEN
)
541 } else if ((Attribs
!= EFI_FILE_VALID_ATTR
) ||
544 // Only matches the bits which "Attribs" contains, not
545 // all files/directories with any of the bits.
546 // Count == 5 is used to tell the difference between a user
547 // specifying all bits (EX: -arhsda) and just specifying
548 // -a (means display all files with any attribute).
550 if ( (Node
->Info
->Attribute
& Attribs
) != Attribs
) {
555 if (!Sfo
&& !HeaderPrinted
) {
556 PathRemoveLastItem (CorrectedPath
);
557 PrintNonSfoHeader(CorrectedPath
);
559 PrintFileInformation(Sfo
, Node
, &FileCount
, &FileSize
, &DirCount
);
561 HeaderPrinted
= TRUE
;
564 if (!Sfo
&& ShellStatus
!= SHELL_ABORTED
) {
565 PrintNonSfoFooter(FileCount
, FileSize
, DirCount
);
569 if (Rec
&& ShellStatus
!= SHELL_ABORTED
) {
571 // Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
573 ShellCloseFileMetaArg(&ListHead
);
574 CorrectedPath
[0] = CHAR_NULL
;
575 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, RootPath
, 0);
576 if (CorrectedPath
== NULL
) {
577 return SHELL_OUT_OF_RESOURCES
;
579 if (CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'\\'
580 &&CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'/') {
581 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"\\", 0);
583 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"*", 0);
584 Status
= ShellOpenFileMetaArg((CHAR16
*)CorrectedPath
, EFI_FILE_MODE_READ
, &ListHead
);
586 if (!EFI_ERROR(Status
)) {
587 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ListHead
->Link
)
588 ; !IsNull(&ListHead
->Link
, &Node
->Link
) && ShellStatus
== SHELL_SUCCESS
589 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ListHead
->Link
, &Node
->Link
)
591 if (ShellGetExecutionBreakFlag ()) {
592 ShellStatus
= SHELL_ABORTED
;
597 // recurse on any directory except the traversing ones...
599 if (((Node
->Info
->Attribute
& EFI_FILE_DIRECTORY
) == EFI_FILE_DIRECTORY
)
600 && StrCmp(Node
->FileName
, L
".") != 0
601 && StrCmp(Node
->FileName
, L
"..") != 0
603 ShellStatus
= PrintLsOutput(
614 // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
616 if (ShellStatus
== SHELL_ABORTED
) {
624 SHELL_FREE_NON_NULL(CorrectedPath
);
625 ShellCloseFileMetaArg(&ListHead
);
627 if (Found
== NULL
&& !FoundOne
) {
628 return (SHELL_NOT_FOUND
);
635 return (ShellStatus
);
638 STATIC CONST SHELL_PARAM_ITEM LsParamList
[] = {
646 Function for 'ls' command.
648 @param[in] ImageHandle Handle to the Image (NULL if Internal).
649 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
654 IN EFI_HANDLE ImageHandle
,
655 IN EFI_SYSTEM_TABLE
*SystemTable
660 CHAR16
*ProblemParam
;
661 CONST CHAR16
*Attribs
;
662 SHELL_STATUS ShellStatus
;
663 UINT64 RequiredAttributes
;
664 CONST CHAR16
*PathName
;
665 CONST CHAR16
*CurDir
;
670 CHAR16
*SearchString
;
676 ShellStatus
= SHELL_SUCCESS
;
677 RequiredAttributes
= 0;
684 // initialize the shell lib (we must be in non-auto-init...)
686 Status
= ShellInitialize();
687 ASSERT_EFI_ERROR(Status
);
690 // Fix local copies of the protocol pointers
692 Status
= CommandInit();
693 ASSERT_EFI_ERROR(Status
);
696 // parse the command line
698 Status
= ShellCommandLineParse (LsParamList
, &Package
, &ProblemParam
, TRUE
);
699 if (EFI_ERROR(Status
)) {
700 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
701 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"ls", ProblemParam
);
702 FreePool(ProblemParam
);
703 ShellStatus
= SHELL_INVALID_PARAMETER
;
711 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
715 if (ShellCommandLineGetCount(Package
) > 2) {
716 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"ls");
717 ShellStatus
= SHELL_INVALID_PARAMETER
;
722 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
723 for ( Attribs
= ShellCommandLineGetValue(Package
, L
"-a")
724 ; Attribs
!= NULL
&& *Attribs
!= CHAR_NULL
&& ShellStatus
== SHELL_SUCCESS
730 RequiredAttributes
|= EFI_FILE_ARCHIVE
;
735 RequiredAttributes
|= EFI_FILE_SYSTEM
;
740 RequiredAttributes
|= EFI_FILE_HIDDEN
;
745 RequiredAttributes
|= EFI_FILE_READ_ONLY
;
750 RequiredAttributes
|= EFI_FILE_DIRECTORY
;
754 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ATTRIBUTE
), gShellLevel2HiiHandle
, L
"ls", ShellCommandLineGetValue(Package
, L
"-a"));
755 ShellStatus
= SHELL_INVALID_PARAMETER
;
760 // if nothing is specified all are specified
762 if (RequiredAttributes
== 0) {
763 RequiredAttributes
= EFI_FILE_VALID_ATTR
;
766 if (ShellStatus
== SHELL_SUCCESS
) {
767 PathName
= ShellCommandLineGetRawValue(Package
, 1);
768 if (PathName
== NULL
) {
770 // Nothing specified... must start from current directory
772 CurDir
= gEfiShellProtocol
->GetCurDir(NULL
);
773 if (CurDir
== NULL
) {
774 ShellStatus
= SHELL_NOT_FOUND
;
775 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"ls");
778 // Copy to the 2 strings for starting path and file search string
780 ASSERT(SearchString
== NULL
);
781 ASSERT(FullPath
== NULL
);
782 StrnCatGrow(&SearchString
, NULL
, L
"*", 0);
783 StrnCatGrow(&FullPath
, NULL
, CurDir
, 0);
784 Size
= FullPath
!= NULL
? StrSize(FullPath
) : 0;
785 StrnCatGrow(&FullPath
, &Size
, L
"\\", 0);
787 if (StrStr(PathName
, L
":") == NULL
&& gEfiShellProtocol
->GetCurDir(NULL
) == NULL
) {
789 // If we got something and it doesnt have a fully qualified path, then we needed to have a CWD.
791 ShellStatus
= SHELL_NOT_FOUND
;
792 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"ls");
795 // We got a valid fully qualified path or we have a CWD
797 ASSERT((FullPath
== NULL
&& Size
== 0) || (FullPath
!= NULL
));
798 if (StrStr(PathName
, L
":") == NULL
) {
799 StrnCatGrow(&FullPath
, &Size
, gEfiShellProtocol
->GetCurDir(NULL
), 0);
800 if (FullPath
== NULL
) {
801 ShellCommandLineFreeVarList (Package
);
802 return SHELL_OUT_OF_RESOURCES
;
804 Size
= FullPath
!= NULL
? StrSize(FullPath
) : 0;
805 StrnCatGrow(&FullPath
, &Size
, L
"\\", 0);
807 StrnCatGrow(&FullPath
, &Size
, PathName
, 0);
808 if (FullPath
== NULL
) {
809 ShellCommandLineFreeVarList (Package
);
810 return SHELL_OUT_OF_RESOURCES
;
813 if (ShellIsDirectory(PathName
) == EFI_SUCCESS
) {
815 // is listing ends with a directory, then we list all files in that directory
817 StrnCatGrow(&SearchString
, NULL
, L
"*", 0);
820 // must split off the search part that applies to files from the end of the directory part
822 StrnCatGrow(&SearchString
, NULL
, FullPath
, 0);
823 if (SearchString
== NULL
) {
825 ShellCommandLineFreeVarList (Package
);
826 return SHELL_OUT_OF_RESOURCES
;
828 PathRemoveLastItem (FullPath
);
829 CopyMem (SearchString
, SearchString
+ StrLen (FullPath
), StrSize (SearchString
+ StrLen (FullPath
)));
833 Status
= gRT
->GetTime(&TheTime
, NULL
);
834 if (EFI_ERROR(Status
)) {
835 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"ls", L
"gRT->GetTime", Status
);
836 TheTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
839 if (ShellStatus
== SHELL_SUCCESS
) {
840 ShellStatus
= PrintLsOutput(
841 ShellCommandLineGetFlag(Package
, L
"-r"),
843 ShellCommandLineGetFlag(Package
, L
"-sfo"),
850 if (ShellStatus
== SHELL_NOT_FOUND
) {
851 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LS_FILE_NOT_FOUND
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
852 } else if (ShellStatus
== SHELL_INVALID_PARAMETER
) {
853 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
854 } else if (ShellStatus
== SHELL_ABORTED
) {
858 } else if (ShellStatus
!= SHELL_SUCCESS
) {
859 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
867 // Free memory allocated
869 SHELL_FREE_NON_NULL(SearchString
);
870 SHELL_FREE_NON_NULL(FullPath
);
871 ShellCommandLineFreeVarList (Package
);
873 return (ShellStatus
);