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 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellLevel2CommandsLib.h"
11 #include <Guid/FileSystemInfo.h>
13 UINTN mDayOfMonth
[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
16 print out the standard format output volume entry.
18 @param[in] TheList a list of files from the volume.
21 PrintSfoVolumeInfoTableEntry(
22 IN CONST EFI_SHELL_FILE_INFO
*TheList
26 EFI_SHELL_FILE_INFO
*Node
;
27 CHAR16
*DirectoryName
;
28 EFI_FILE_SYSTEM_INFO
*SysInfo
;
30 SHELL_FILE_HANDLE ShellFileHandle
;
31 EFI_FILE_PROTOCOL
*EfiFpHandle
;
34 // Get the first valid handle (directories)
36 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&TheList
->Link
)
37 ; !IsNull(&TheList
->Link
, &Node
->Link
) && Node
->Handle
== NULL
38 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&TheList
->Link
, &Node
->Link
)
41 if (Node
->Handle
== NULL
) {
42 DirectoryName
= GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO
*)GetFirstNode(&TheList
->Link
))->FullName
);
45 // We need to open something up to get system information
47 Status
= gEfiShellProtocol
->OpenFileByName(
53 ASSERT_EFI_ERROR(Status
);
54 FreePool(DirectoryName
);
57 // Get the Volume Info from ShellFileHandle
61 EfiFpHandle
= ConvertShellHandleToEfiFileProtocol(ShellFileHandle
);
62 Status
= EfiFpHandle
->GetInfo(
64 &gEfiFileSystemInfoGuid
,
69 if (Status
== EFI_BUFFER_TOO_SMALL
) {
70 SysInfo
= AllocateZeroPool(SysInfoSize
);
71 Status
= EfiFpHandle
->GetInfo(
73 &gEfiFileSystemInfoGuid
,
79 ASSERT_EFI_ERROR(Status
);
81 gEfiShellProtocol
->CloseFile(ShellFileHandle
);
84 // Get the Volume Info from Node->Handle
88 EfiFpHandle
= ConvertShellHandleToEfiFileProtocol(Node
->Handle
);
89 Status
= EfiFpHandle
->GetInfo(
91 &gEfiFileSystemInfoGuid
,
96 if (Status
== EFI_BUFFER_TOO_SMALL
) {
97 SysInfo
= AllocateZeroPool(SysInfoSize
);
98 Status
= EfiFpHandle
->GetInfo(
100 &gEfiFileSystemInfoGuid
,
106 ASSERT_EFI_ERROR(Status
);
113 STRING_TOKEN (STR_GEN_SFO_HEADER
),
114 gShellLevel2HiiHandle
,
118 // print VolumeInfo table
120 ASSERT(SysInfo
!= NULL
);
123 gST
->ConOut
->Mode
->CursorRow
,
125 STRING_TOKEN (STR_LS_SFO_VOLINFO
),
126 gShellLevel2HiiHandle
,
127 SysInfo
->VolumeLabel
,
129 SysInfo
->ReadOnly
?L
"TRUE":L
"FALSE",
134 SHELL_FREE_NON_NULL(SysInfo
);
140 print out the info on a single file.
142 @param[in] Sfo TRUE if in SFO, false otherwise.
143 @param[in] TheNode the EFI_SHELL_FILE_INFO node to print out information on.
144 @param[in] Files incremented if a file is printed.
145 @param[in] Size incremented by file size.
146 @param[in] Dirs incremented if a directory is printed.
150 PrintFileInformation(
151 IN CONST BOOLEAN Sfo
,
152 IN CONST EFI_SHELL_FILE_INFO
*TheNode
,
158 ASSERT(Files
!= NULL
);
159 ASSERT(Size
!= NULL
);
160 ASSERT(Dirs
!= NULL
);
161 ASSERT(TheNode
!= NULL
);
165 // Print the FileInfo Table
169 gST
->ConOut
->Mode
->CursorRow
,
171 STRING_TOKEN (STR_LS_SFO_FILEINFO
),
172 gShellLevel2HiiHandle
,
174 TheNode
->Info
->FileSize
,
175 TheNode
->Info
->PhysicalSize
,
176 (TheNode
->Info
->Attribute
& EFI_FILE_ARCHIVE
) != 0?L
"a":L
"",
177 (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) != 0?L
"d":L
"",
178 (TheNode
->Info
->Attribute
& EFI_FILE_HIDDEN
) != 0?L
"h":L
"",
179 (TheNode
->Info
->Attribute
& EFI_FILE_READ_ONLY
) != 0?L
"r":L
"",
180 (TheNode
->Info
->Attribute
& EFI_FILE_SYSTEM
) != 0?L
"s":L
"",
181 TheNode
->Info
->CreateTime
.Hour
,
182 TheNode
->Info
->CreateTime
.Minute
,
183 TheNode
->Info
->CreateTime
.Second
,
184 TheNode
->Info
->CreateTime
.Day
,
185 TheNode
->Info
->CreateTime
.Month
,
186 TheNode
->Info
->CreateTime
.Year
,
187 TheNode
->Info
->LastAccessTime
.Hour
,
188 TheNode
->Info
->LastAccessTime
.Minute
,
189 TheNode
->Info
->LastAccessTime
.Second
,
190 TheNode
->Info
->LastAccessTime
.Day
,
191 TheNode
->Info
->LastAccessTime
.Month
,
192 TheNode
->Info
->LastAccessTime
.Year
,
193 TheNode
->Info
->ModificationTime
.Hour
,
194 TheNode
->Info
->ModificationTime
.Minute
,
195 TheNode
->Info
->ModificationTime
.Second
,
196 TheNode
->Info
->ModificationTime
.Day
,
197 TheNode
->Info
->ModificationTime
.Month
,
198 TheNode
->Info
->ModificationTime
.Year
202 // print this one out...
203 // first print the universal start, next print the type specific name format, last print the CRLF
209 STRING_TOKEN (STR_LS_LINE_START_ALL
),
210 gShellLevel2HiiHandle
,
211 &TheNode
->Info
->ModificationTime
,
212 (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) != 0?L
"<DIR>":L
"",
213 (TheNode
->Info
->Attribute
& EFI_FILE_READ_ONLY
) != 0?L
'r':L
' ',
214 TheNode
->Info
->FileSize
216 if (TheNode
->Info
->Attribute
& EFI_FILE_DIRECTORY
) {
222 STRING_TOKEN (STR_LS_LINE_END_DIR
),
223 gShellLevel2HiiHandle
,
228 (*Size
) += TheNode
->Info
->FileSize
;
229 if ( (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)L
".nsh", (CHAR16
*)&(TheNode
->FileName
[StrLen (TheNode
->FileName
) - 4])) == 0)
230 || (gUnicodeCollation
->StriColl(gUnicodeCollation
, (CHAR16
*)L
".efi", (CHAR16
*)&(TheNode
->FileName
[StrLen (TheNode
->FileName
) - 4])) == 0)
236 STRING_TOKEN (STR_LS_LINE_END_EXE
),
237 gShellLevel2HiiHandle
,
245 STRING_TOKEN (STR_LS_LINE_END_FILE
),
246 gShellLevel2HiiHandle
,
255 print out the header when not using standard format output.
257 @param[in] Path String with starting path.
261 IN CONST CHAR16
*Path
264 CHAR16
*DirectoryName
;
267 // get directory name from path...
269 DirectoryName
= GetFullyQualifiedPath(Path
);
271 if (DirectoryName
!= NULL
) {
277 gST
->ConOut
->Mode
->CursorRow
,
279 STRING_TOKEN (STR_LS_HEADER_LINE1
),
280 gShellLevel2HiiHandle
,
284 SHELL_FREE_NON_NULL(DirectoryName
);
289 print out the footer when not using standard format output.
291 @param[in] Files The number of files.
292 @param[in] Size The size of files in bytes.
293 @param[in] Dirs The number of directories.
309 STRING_TOKEN (STR_LS_FOOTER_LINE
),
310 gShellLevel2HiiHandle
,
318 Change the file time to local time based on the timezone.
320 @param[in] Time The file time.
321 @param[in] LocalTimeZone Local time zone.
324 FileTimeToLocalTime (
326 IN INT16 LocalTimeZone
331 INTN HourNumberOfTempMinute
;
333 INTN DayNumberOfTempHour
;
335 INTN MonthNumberOfTempDay
;
337 INTN YearNumberOfTempMonth
;
340 ASSERT ((Time
->TimeZone
>= -1440) && (Time
->TimeZone
<=1440));
341 ASSERT ((LocalTimeZone
>= -1440) && (LocalTimeZone
<=1440));
342 ASSERT ((Time
->Month
>= 1) && (Time
->Month
<= 12));
344 if(Time
->TimeZone
== LocalTimeZone
) {
346 //if the file timezone is equal to the local timezone, there is no need to adjust the file time.
351 if((Time
->Year
% 4 == 0 && Time
->Year
/ 100 != 0)||(Time
->Year
% 400 == 0)) {
353 // Day in February of leap year is 29.
358 MinuteDiff
= Time
->TimeZone
- LocalTimeZone
;
359 TempMinute
= Time
->Minute
+ MinuteDiff
;
362 // Calculate Time->Minute
363 // TempHour will be used to calculate Time->Hour
365 HourNumberOfTempMinute
= TempMinute
/ 60;
367 HourNumberOfTempMinute
--;
369 TempHour
= Time
->Hour
+ HourNumberOfTempMinute
;
370 Time
->Minute
= (UINT8
)(TempMinute
- 60 * HourNumberOfTempMinute
);
373 // Calculate Time->Hour
374 // TempDay will be used to calculate Time->Day
376 DayNumberOfTempHour
= TempHour
/ 24 ;
378 DayNumberOfTempHour
--;
380 TempDay
= Time
->Day
+ DayNumberOfTempHour
;
381 Time
->Hour
= (UINT8
)(TempHour
- 24 * DayNumberOfTempHour
);
384 // Calculate Time->Day
385 // TempMonth will be used to calculate Time->Month
387 MonthNumberOfTempDay
= (TempDay
- 1) / (INTN
)mDayOfMonth
[Time
->Month
- 1];
388 MonthRecord
= (INTN
)(Time
->Month
) ;
390 MonthNumberOfTempDay
-- ;
393 TempMonth
= Time
->Month
+ MonthNumberOfTempDay
;
394 Time
->Day
= (UINT8
)(TempDay
- (INTN
)mDayOfMonth
[(MonthRecord
- 1 + 12) % 12] * MonthNumberOfTempDay
);
397 // Calculate Time->Month, Time->Year
399 YearNumberOfTempMonth
= (TempMonth
- 1) / 12;
400 if(TempMonth
- 1 < 0){
401 YearNumberOfTempMonth
--;
403 Time
->Month
= (UINT8
)(TempMonth
- 12 * (YearNumberOfTempMonth
));
404 Time
->Year
= (UINT16
)(Time
->Year
+ YearNumberOfTempMonth
);
408 print out the list of files and directories from the LS command
410 @param[in] Rec TRUE to automatically recurse into each found directory
411 FALSE to only list the specified directory.
412 @param[in] Attribs List of required Attribute for display.
413 If 0 then all non-system and non-hidden files will be printed.
414 @param[in] Sfo TRUE to use Standard Format Output, FALSE otherwise
415 @param[in] RootPath String with starting path to search in.
416 @param[in] SearchString String with search string.
417 @param[in] Found Set to TRUE, if anyone were found.
418 @param[in] Count The count of bits enabled in Attribs.
419 @param[in] TimeZone The current time zone offset.
421 @retval SHELL_SUCCESS the printing was sucessful.
425 IN CONST BOOLEAN Rec
,
426 IN CONST UINT64 Attribs
,
427 IN CONST BOOLEAN Sfo
,
428 IN CONST CHAR16
*RootPath
,
429 IN CONST CHAR16
*SearchString
,
431 IN CONST UINTN Count
,
432 IN CONST INT16 TimeZone
436 EFI_SHELL_FILE_INFO
*ListHead
;
437 EFI_SHELL_FILE_INFO
*Node
;
438 SHELL_STATUS ShellStatus
;
443 CHAR16
*CorrectedPath
;
445 BOOLEAN HeaderPrinted
;
448 HeaderPrinted
= FALSE
;
453 ShellStatus
= SHELL_SUCCESS
;
455 CorrectedPath
= NULL
;
463 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, RootPath
, 0);
464 if (CorrectedPath
== NULL
) {
465 return SHELL_OUT_OF_RESOURCES
;
467 if (CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'\\'
468 &&CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'/') {
469 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"\\", 0);
471 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, SearchString
, 0);
472 if (CorrectedPath
== NULL
) {
473 return (SHELL_OUT_OF_RESOURCES
);
476 PathCleanUpDirectories(CorrectedPath
);
478 Status
= ShellOpenFileMetaArg((CHAR16
*)CorrectedPath
, EFI_FILE_MODE_READ
, &ListHead
);
479 if (!EFI_ERROR(Status
)) {
480 if (ListHead
== NULL
|| IsListEmpty(&ListHead
->Link
)) {
481 SHELL_FREE_NON_NULL(CorrectedPath
);
482 return (SHELL_SUCCESS
);
485 if (Sfo
&& Found
== NULL
) {
486 PrintSfoVolumeInfoTableEntry(ListHead
);
489 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ListHead
->Link
), LongestPath
= 0
490 ; !IsNull(&ListHead
->Link
, &Node
->Link
)
491 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ListHead
->Link
, &Node
->Link
)
493 if (ShellGetExecutionBreakFlag ()) {
494 ShellStatus
= SHELL_ABORTED
;
497 ASSERT(Node
!= NULL
);
500 // Change the file time to local time.
502 Status
= gRT
->GetTime(&LocalTime
, NULL
);
503 if (!EFI_ERROR (Status
)) {
504 if ((Node
->Info
->CreateTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
505 (Node
->Info
->CreateTime
.Month
>= 1 && Node
->Info
->CreateTime
.Month
<= 12)) {
507 // FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
509 FileTimeToLocalTime (&Node
->Info
->CreateTime
, LocalTime
.TimeZone
);
511 if ((Node
->Info
->LastAccessTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
512 (Node
->Info
->LastAccessTime
.Month
>= 1 && Node
->Info
->LastAccessTime
.Month
<= 12)) {
513 FileTimeToLocalTime (&Node
->Info
->LastAccessTime
, LocalTime
.TimeZone
);
515 if ((Node
->Info
->ModificationTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) &&
516 (Node
->Info
->ModificationTime
.Month
>= 1 && Node
->Info
->ModificationTime
.Month
<= 12)) {
517 FileTimeToLocalTime (&Node
->Info
->ModificationTime
, LocalTime
.TimeZone
);
521 if (LongestPath
< StrSize(Node
->FullName
)) {
522 LongestPath
= StrSize(Node
->FullName
);
524 ASSERT(Node
->Info
!= NULL
);
525 ASSERT((Node
->Info
->Attribute
& EFI_FILE_VALID_ATTR
) == Node
->Info
->Attribute
);
528 // NOT system & NOT hidden
530 if ( (Node
->Info
->Attribute
& EFI_FILE_SYSTEM
)
531 || (Node
->Info
->Attribute
& EFI_FILE_HIDDEN
)
535 } else if ((Attribs
!= EFI_FILE_VALID_ATTR
) ||
538 // Only matches the bits which "Attribs" contains, not
539 // all files/directories with any of the bits.
540 // Count == 5 is used to tell the difference between a user
541 // specifying all bits (EX: -arhsda) and just specifying
542 // -a (means display all files with any attribute).
544 if ( (Node
->Info
->Attribute
& Attribs
) != Attribs
) {
549 if (!Sfo
&& !HeaderPrinted
) {
550 PathRemoveLastItem (CorrectedPath
);
551 PrintNonSfoHeader(CorrectedPath
);
553 PrintFileInformation(Sfo
, Node
, &FileCount
, &FileSize
, &DirCount
);
555 HeaderPrinted
= TRUE
;
558 if (!Sfo
&& ShellStatus
!= SHELL_ABORTED
) {
559 PrintNonSfoFooter(FileCount
, FileSize
, DirCount
);
563 if (Rec
&& ShellStatus
!= SHELL_ABORTED
) {
565 // Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
567 ShellCloseFileMetaArg(&ListHead
);
568 CorrectedPath
[0] = CHAR_NULL
;
569 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, RootPath
, 0);
570 if (CorrectedPath
== NULL
) {
571 return SHELL_OUT_OF_RESOURCES
;
573 if (CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'\\'
574 &&CorrectedPath
[StrLen(CorrectedPath
)-1] != L
'/') {
575 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"\\", 0);
577 CorrectedPath
= StrnCatGrow(&CorrectedPath
, &LongestPath
, L
"*", 0);
578 Status
= ShellOpenFileMetaArg((CHAR16
*)CorrectedPath
, EFI_FILE_MODE_READ
, &ListHead
);
580 if (!EFI_ERROR(Status
)) {
581 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ListHead
->Link
)
582 ; !IsNull(&ListHead
->Link
, &Node
->Link
) && ShellStatus
== SHELL_SUCCESS
583 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ListHead
->Link
, &Node
->Link
)
585 if (ShellGetExecutionBreakFlag ()) {
586 ShellStatus
= SHELL_ABORTED
;
591 // recurse on any directory except the traversing ones...
593 if (((Node
->Info
->Attribute
& EFI_FILE_DIRECTORY
) == EFI_FILE_DIRECTORY
)
594 && StrCmp(Node
->FileName
, L
".") != 0
595 && StrCmp(Node
->FileName
, L
"..") != 0
597 ShellStatus
= PrintLsOutput(
608 // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
610 if (ShellStatus
== SHELL_ABORTED
) {
618 SHELL_FREE_NON_NULL(CorrectedPath
);
619 ShellCloseFileMetaArg(&ListHead
);
621 if (Found
== NULL
&& !FoundOne
) {
622 return (SHELL_NOT_FOUND
);
629 return (ShellStatus
);
632 STATIC CONST SHELL_PARAM_ITEM LsParamList
[] = {
640 Function for 'ls' command.
642 @param[in] ImageHandle Handle to the Image (NULL if Internal).
643 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
648 IN EFI_HANDLE ImageHandle
,
649 IN EFI_SYSTEM_TABLE
*SystemTable
654 CHAR16
*ProblemParam
;
655 CONST CHAR16
*Attribs
;
656 SHELL_STATUS ShellStatus
;
657 UINT64 RequiredAttributes
;
658 CONST CHAR16
*PathName
;
659 CONST CHAR16
*CurDir
;
664 CHAR16
*SearchString
;
670 ShellStatus
= SHELL_SUCCESS
;
671 RequiredAttributes
= 0;
678 // initialize the shell lib (we must be in non-auto-init...)
680 Status
= ShellInitialize();
681 ASSERT_EFI_ERROR(Status
);
684 // Fix local copies of the protocol pointers
686 Status
= CommandInit();
687 ASSERT_EFI_ERROR(Status
);
690 // parse the command line
692 Status
= ShellCommandLineParse (LsParamList
, &Package
, &ProblemParam
, TRUE
);
693 if (EFI_ERROR(Status
)) {
694 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"ls", ProblemParam
);
696 FreePool(ProblemParam
);
697 ShellStatus
= SHELL_INVALID_PARAMETER
;
705 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
709 if (ShellCommandLineGetCount(Package
) > 2) {
710 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"ls");
711 ShellStatus
= SHELL_INVALID_PARAMETER
;
716 if (ShellCommandLineGetFlag(Package
, L
"-a")) {
717 for ( Attribs
= ShellCommandLineGetValue(Package
, L
"-a")
718 ; Attribs
!= NULL
&& *Attribs
!= CHAR_NULL
&& ShellStatus
== SHELL_SUCCESS
724 RequiredAttributes
|= EFI_FILE_ARCHIVE
;
729 RequiredAttributes
|= EFI_FILE_SYSTEM
;
734 RequiredAttributes
|= EFI_FILE_HIDDEN
;
739 RequiredAttributes
|= EFI_FILE_READ_ONLY
;
744 RequiredAttributes
|= EFI_FILE_DIRECTORY
;
748 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ATTRIBUTE
), gShellLevel2HiiHandle
, L
"ls", ShellCommandLineGetValue(Package
, L
"-a"));
749 ShellStatus
= SHELL_INVALID_PARAMETER
;
754 // if nothing is specified all are specified
756 if (RequiredAttributes
== 0) {
757 RequiredAttributes
= EFI_FILE_VALID_ATTR
;
760 if (ShellStatus
== SHELL_SUCCESS
) {
761 PathName
= ShellCommandLineGetRawValue(Package
, 1);
762 if (PathName
== NULL
) {
764 // Nothing specified... must start from current directory
766 CurDir
= gEfiShellProtocol
->GetCurDir(NULL
);
767 if (CurDir
== NULL
) {
768 ShellStatus
= SHELL_NOT_FOUND
;
769 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"ls");
772 // Copy to the 2 strings for starting path and file search string
774 ASSERT(SearchString
== NULL
);
775 ASSERT(FullPath
== NULL
);
776 StrnCatGrow(&SearchString
, NULL
, L
"*", 0);
777 StrnCatGrow(&FullPath
, NULL
, CurDir
, 0);
778 Size
= FullPath
!= NULL
? StrSize(FullPath
) : 0;
779 StrnCatGrow(&FullPath
, &Size
, L
"\\", 0);
781 if (StrStr(PathName
, L
":") == NULL
&& gEfiShellProtocol
->GetCurDir(NULL
) == NULL
) {
783 // If we got something and it doesnt have a fully qualified path, then we needed to have a CWD.
785 ShellStatus
= SHELL_NOT_FOUND
;
786 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"ls");
789 // We got a valid fully qualified path or we have a CWD
791 ASSERT((FullPath
== NULL
&& Size
== 0) || (FullPath
!= NULL
));
792 if (StrStr(PathName
, L
":") == NULL
) {
793 StrnCatGrow(&FullPath
, &Size
, gEfiShellProtocol
->GetCurDir(NULL
), 0);
794 if (FullPath
== NULL
) {
795 ShellCommandLineFreeVarList (Package
);
796 return SHELL_OUT_OF_RESOURCES
;
798 Size
= FullPath
!= NULL
? StrSize(FullPath
) : 0;
799 StrnCatGrow(&FullPath
, &Size
, L
"\\", 0);
801 StrnCatGrow(&FullPath
, &Size
, PathName
, 0);
802 if (FullPath
== NULL
) {
803 ShellCommandLineFreeVarList (Package
);
804 return SHELL_OUT_OF_RESOURCES
;
807 if (ShellIsDirectory(PathName
) == EFI_SUCCESS
) {
809 // is listing ends with a directory, then we list all files in that directory
811 StrnCatGrow(&SearchString
, NULL
, L
"*", 0);
814 // must split off the search part that applies to files from the end of the directory part
816 StrnCatGrow(&SearchString
, NULL
, FullPath
, 0);
817 if (SearchString
== NULL
) {
819 ShellCommandLineFreeVarList (Package
);
820 return SHELL_OUT_OF_RESOURCES
;
822 PathRemoveLastItem (FullPath
);
823 CopyMem (SearchString
, SearchString
+ StrLen (FullPath
), StrSize (SearchString
+ StrLen (FullPath
)));
827 Status
= gRT
->GetTime(&TheTime
, NULL
);
828 if (EFI_ERROR(Status
)) {
829 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"ls", L
"gRT->GetTime", Status
);
830 TheTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
833 if (ShellStatus
== SHELL_SUCCESS
) {
834 ShellStatus
= PrintLsOutput(
835 ShellCommandLineGetFlag(Package
, L
"-r"),
837 ShellCommandLineGetFlag(Package
, L
"-sfo"),
844 if (ShellStatus
== SHELL_NOT_FOUND
) {
845 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LS_FILE_NOT_FOUND
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
846 } else if (ShellStatus
== SHELL_INVALID_PARAMETER
) {
847 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
848 } else if (ShellStatus
== SHELL_ABORTED
) {
852 } else if (ShellStatus
!= SHELL_SUCCESS
) {
853 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"ls", FullPath
);
861 // Free memory allocated
863 SHELL_FREE_NON_NULL(SearchString
);
864 SHELL_FREE_NON_NULL(FullPath
);
865 ShellCommandLineFreeVarList (Package
);
867 return (ShellStatus
);