2 Main file for map shell level 2 command.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
15 #include "UefiShellLevel2CommandsLib.h"
16 #include <Protocol/SimpleFileSystem.h>
17 #include <Protocol/BlockIo.h>
18 #include <Library/DevicePathLib.h>
19 #include <Library/HandleParsingLib.h>
20 #include <Library/SortLib.h>
25 IN CONST CHAR16
*List
,
26 IN CONST CHAR16
*MetaTarget
,
27 OUT CHAR16
**FullName OPTIONAL
,
28 IN CONST BOOLEAN Meta
,
29 IN CONST BOOLEAN SkipTrailingNumbers
,
30 IN CONST CHAR16
*Target
35 CONST CHAR16
*ListWalker
;
39 for (ListWalker
= List
, TempList
= NULL
40 ; ListWalker
!= NULL
&& *ListWalker
!= CHAR_NULL
43 TempList
= StrnCatGrow(&TempList
, NULL
, ListWalker
, 0);
44 ASSERT(TempList
!= NULL
);
45 TempSpot
= StrStr(TempList
, Target
);
46 if (TempSpot
!= NULL
) {
47 *TempSpot
= CHAR_NULL
;
50 while (SkipTrailingNumbers
&& (ShellIsDecimalDigitCharacter(TempList
[StrLen(TempList
)-1]) || TempList
[StrLen(TempList
)-1] == L
':')) {
51 TempList
[StrLen(TempList
)-1] = CHAR_NULL
;
54 ListWalker
= StrStr(ListWalker
, Target
);
55 while(ListWalker
!= NULL
&& *ListWalker
== *Target
) {
59 Result
= gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, (CHAR16
*)TempList
, (CHAR16
*)MetaTarget
);
61 Result
= (BOOLEAN
)(StrCmp(TempList
, MetaTarget
)==0);
64 if (FullName
!= NULL
) {
85 EFI_HANDLE
*HandleList
;
87 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
88 CHAR16
*NewDefaultName
;
89 CHAR16
*NewConsistName
;
90 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
96 // remove mappings that represent removed devices.
100 // Find each handle with Simple File System
102 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
103 if (HandleList
!= NULL
) {
105 // Do a count of the handles
107 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
110 // Get all Device Paths
112 DevicePathList
= AllocatePool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
113 ASSERT(DevicePathList
!= NULL
);
115 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
116 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
120 // Sort all DevicePaths
122 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
124 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
127 // Assign new Mappings to remainders
129 for (Count
= 0 ; HandleList
[Count
] != NULL
&& !EFI_ERROR(Status
); Count
++) {
131 // Skip ones that already have
133 if (gEfiShellProtocol
->GetMapFromDevicePath(&DevicePathList
[Count
]) != NULL
) {
139 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
140 ASSERT(NewDefaultName
!= NULL
);
143 // Call shell protocol SetMap function now...
145 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewDefaultName
);
147 if (!EFI_ERROR(Status
)) {
149 // Now do consistent name
151 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
152 if (NewConsistName
!= NULL
) {
153 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewConsistName
);
154 FreePool(NewConsistName
);
158 FreePool(NewDefaultName
);
160 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
161 SHELL_FREE_NON_NULL(HandleList
);
162 SHELL_FREE_NON_NULL(DevicePathList
);
169 // Do it all over again for gEfiBlockIoProtocolGuid
178 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
181 ACPI_HID_DEVICE_PATH
*Acpi
;
184 // Parse the device path:
185 // Devicepath sub type mediatype
186 // MEDIA_HANRDDRIVE_DP -> Hard Disk
187 // MEDIA_CDROM_DP -> CD Rom
188 // Acpi.HID = 0X0604 -> Floppy
190 if (NULL
== DevicePath
) {
191 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
194 for (;!IsDevicePathEndType (DevicePath
) ;DevicePath
= NextDevicePathNode (DevicePath
)) {
195 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
196 switch (DevicePathSubType (DevicePath
)) {
197 case MEDIA_HARDDRIVE_DP
:
198 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK
), NULL
);
200 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_CDROM
), NULL
);
202 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
203 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePath
;
204 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
205 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY
), NULL
);
210 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
214 Function to detemine if a handle has removable storage.
216 @param[in] DevicePath DevicePath to test.
218 @retval TRUE The handle has removable storage.
219 @retval FALSE The handle does not have removable storage.
224 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
227 if (NULL
== DevicePath
) {
231 while (!IsDevicePathEndType (DevicePath
)) {
232 if (DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) {
233 switch (DevicePathSubType (DevicePath
)) {
241 DevicePath
= NextDevicePathNode (DevicePath
);
247 Function to detemine if a something on the map list matches.
249 @param[in] MapList The pointer to the list to test.
250 @param[in] Specific The pointer to a specific name to test for.
251 @param[in] TypeString The pointer to the list of types.
252 @param[in] Normal Always show normal mappings.
253 @param[in] Consist Always show consistent mappings.
255 @retval TRUE The map should be displayed.
256 @retval FALSE The map should not be displayed.
261 IN CONST CHAR16
*MapList
,
262 IN CONST CHAR16
*Specific
,
263 IN CONST CHAR16
*TypeString
,
264 IN CONST BOOLEAN Normal
,
265 IN CONST BOOLEAN Consist
269 // specific has priority
271 if ( Specific
!= NULL
272 && SearchList(MapList
, Specific
, NULL
, TRUE
, FALSE
, L
";")) {
277 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
278 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
279 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
280 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
285 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
286 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
290 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
299 PerformSingleMappingDisplay(
300 IN CONST BOOLEAN Verbose
,
301 IN CONST BOOLEAN Consist
,
302 IN CONST BOOLEAN Normal
,
303 IN CONST CHAR16
*TypeString
,
304 IN CONST BOOLEAN SFO
,
305 IN CONST CHAR16
*Specific OPTIONAL
,
306 IN CONST EFI_HANDLE Handle
309 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
310 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
311 CONST CHAR16
*MapList
;
314 CHAR16
*DevPathString
;
318 CONST CHAR16
*TempSpot2
;
320 DevPath
= DevicePathFromHandle(Handle
);
321 DevPathCopy
= DevPath
;
322 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
323 if (MapList
== NULL
) {
327 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
332 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
333 TempSpot
= StrStr(CurrentName
, L
";");
334 if (TempSpot
!= NULL
) {
335 *TempSpot
= CHAR_NULL
;
337 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
339 TempLen
= StrLen(CurrentName
);
344 STRING_TOKEN (STR_MAP_ENTRY
),
345 gShellLevel2HiiHandle
,
347 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"",
352 // also print handle, media type, removable (y/n), and current directory
354 MediaType
= GetDeviceMediaType(DevPath
);
355 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
356 Removable
= IsRemoveableDevice(DevPath
);
357 TempSpot2
= ShellGetCurrentDir(CurrentName
);
362 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
363 gShellLevel2HiiHandle
,
364 ConvertHandleToHandleIndex(Handle
),
366 Removable
?L
"Yes":L
"No",
373 TempLen
= StrLen(CurrentName
);
378 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
379 gShellLevel2HiiHandle
,
382 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""
385 FreePool(DevPathString
);
386 FreePool(CurrentName
);
392 PerformSingleMappingDelete(
393 IN CONST CHAR16
*Specific
,
394 IN CONST EFI_HANDLE Handle
397 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
398 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
399 CONST CHAR16
*MapList
;
402 DevPath
= DevicePathFromHandle(Handle
);
403 DevPathCopy
= DevPath
;
404 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
407 if (MapList
== NULL
) {
408 return (EFI_NOT_FOUND
);
411 // if there is a specific and its not on the list...
413 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
414 return (EFI_NOT_FOUND
);
416 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
420 Function to display mapping information to the user.
422 if Specific is specified then Consist and Normal will be ignored since information will
423 be printed for the specific item only.
425 @param[in] Verbose TRUE to display (extra) verbose information
426 @param[in] Consist TRUE to display consistent mappings
427 @param[in] Normal TRUE to display normal (not consist) mappings
428 @param[in] TypeString pointer to string of filter types
429 @param[in] SFO TRUE to display output in Standard Output Format
430 @param[in] Specific pointer to string for specific map to display
432 @retval SHELL_SUCCESS the display was printed
433 @retval SHELL_INVALID_PARAMETER one of Consist or Normal must be TRUE if no Specific
436 CONST CHAR16 Cd
[] = L
"cd*";
437 CONST CHAR16 Hd
[] = L
"hd*";
438 CONST CHAR16 Fp
[] = L
"fp*";
439 CONST CHAR16 F
[] = L
"F*";
442 PerformMappingDisplay(
443 IN CONST BOOLEAN Verbose
,
444 IN CONST BOOLEAN Consist
,
445 IN CONST BOOLEAN Normal
,
446 IN CONST CHAR16
*TypeString
,
447 IN CONST BOOLEAN SFO
,
448 IN CONST CHAR16
*Specific OPTIONAL
,
449 IN CONST BOOLEAN Header
453 EFI_HANDLE
*HandleBuffer
;
458 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
459 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
460 return (SHELL_INVALID_PARAMETER
);
463 if (TypeString
!= NULL
) {
465 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
467 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
469 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
470 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, TypeString
);
471 return (SHELL_INVALID_PARAMETER
);
473 } else if (Test
== NULL
) {
486 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
488 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
496 // Look up all SimpleFileSystems in the platform
498 Status
= gBS
->LocateHandle(
500 &gEfiDevicePathProtocolGuid
,
504 if (Status
== EFI_BUFFER_TOO_SMALL
) {
505 HandleBuffer
= AllocatePool(BufferSize
);
506 if (HandleBuffer
== NULL
) {
507 return (SHELL_OUT_OF_RESOURCES
);
509 Status
= gBS
->LocateHandle(
511 &gEfiDevicePathProtocolGuid
,
516 ASSERT_EFI_ERROR(Status
);
517 ASSERT(HandleBuffer
!= NULL
);
520 // Get the map name(s) for each one.
523 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
))
526 PerformSingleMappingDisplay(
533 HandleBuffer
[LoopVar
]);
537 // Look up all BlockIo in the platform
539 Status
= gBS
->LocateHandle(
541 &gEfiBlockIoProtocolGuid
,
545 if (Status
== EFI_BUFFER_TOO_SMALL
) {
546 FreePool(HandleBuffer
);
547 HandleBuffer
= AllocatePool(BufferSize
);
548 if (HandleBuffer
== NULL
) {
549 return (SHELL_OUT_OF_RESOURCES
);
551 Status
= gBS
->LocateHandle(
553 &gEfiBlockIoProtocolGuid
,
558 if (!EFI_ERROR(Status
)) {
560 // Get the map name(s) for each one.
563 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
567 // Skip any that were already done...
569 if (gBS
->OpenProtocol(
570 HandleBuffer
[LoopVar
],
571 &gEfiDevicePathProtocolGuid
,
575 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
578 PerformSingleMappingDisplay(
585 HandleBuffer
[LoopVar
]);
587 FreePool(HandleBuffer
);
589 return (SHELL_SUCCESS
);
594 PerformMappingDisplay2(
595 IN CONST BOOLEAN Verbose
,
596 IN CONST BOOLEAN Consist
,
597 IN CONST BOOLEAN Normal
,
598 IN CONST CHAR16
*TypeString
,
599 IN CONST BOOLEAN SFO
,
600 IN CONST CHAR16
*Specific OPTIONAL
603 CONST CHAR16
*TypeWalker
;
604 SHELL_STATUS ShellStatus
;
608 if (TypeString
== NULL
) {
609 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
611 ShellStatus
= SHELL_SUCCESS
;
612 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
613 Comma
= StrStr(TypeWalker
, L
",");
615 if (ShellStatus
== SHELL_SUCCESS
) {
616 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
618 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
623 if (ShellStatus
== SHELL_SUCCESS
) {
624 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
626 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
629 TypeWalker
= Comma
+ 1;
633 return (ShellStatus
);
638 PerformMappingDelete(
639 IN CONST CHAR16
*Specific
643 EFI_HANDLE
*HandleBuffer
;
648 if (Specific
== NULL
) {
649 return (EFI_INVALID_PARAMETER
);
657 // Look up all SimpleFileSystems in the platform
659 Status
= gBS
->LocateHandle(
661 &gEfiDevicePathProtocolGuid
,
665 if (Status
== EFI_BUFFER_TOO_SMALL
) {
666 HandleBuffer
= AllocatePool(BufferSize
);
667 if (HandleBuffer
== NULL
) {
668 return (EFI_OUT_OF_RESOURCES
);
670 Status
= gBS
->LocateHandle(
672 &gEfiDevicePathProtocolGuid
,
677 if (EFI_ERROR(Status
)) {
678 SHELL_FREE_NON_NULL(HandleBuffer
);
683 // Get the map name(s) for each one.
686 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
689 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
695 // Look up all BlockIo in the platform
697 Status
= gBS
->LocateHandle(
699 &gEfiBlockIoProtocolGuid
,
703 if (Status
== EFI_BUFFER_TOO_SMALL
) {
704 FreePool(HandleBuffer
);
705 HandleBuffer
= AllocatePool(BufferSize
);
706 if (HandleBuffer
== NULL
) {
707 return (EFI_OUT_OF_RESOURCES
);
709 Status
= gBS
->LocateHandle(
711 &gEfiBlockIoProtocolGuid
,
716 if (EFI_ERROR(Status
)) {
717 SHELL_FREE_NON_NULL(HandleBuffer
);
722 // Get the map name(s) for each one.
725 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
729 // Skip any that were already done...
731 if (gBS
->OpenProtocol(
732 HandleBuffer
[LoopVar
],
733 &gEfiDevicePathProtocolGuid
,
737 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
740 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
744 FreePool(HandleBuffer
);
746 return (EFI_NOT_FOUND
);
748 return (EFI_SUCCESS
);
752 function to add a mapping from mapping.
754 This function will get the device path associated with the mapping and call SetMap.
756 @param[in] Map The Map to add a mapping for
757 @param[in] SName The name of the new mapping
759 @retval SHELL_SUCCESS the mapping was added
760 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
761 @return Shell version of a return value from EfiShellProtocol->SetMap
766 AddMappingFromMapping(
767 IN CONST CHAR16
*Map
,
768 IN CONST CHAR16
*SName
771 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
774 if (StrStr(SName
, L
"*") != NULL
775 ||StrStr(SName
, L
"?") != NULL
776 ||StrStr(SName
, L
"[") != NULL
777 ||StrStr(SName
, L
"]") != NULL
) {
778 return (SHELL_INVALID_PARAMETER
);
781 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
782 if (DevPath
== NULL
) {
783 return (SHELL_INVALID_PARAMETER
);
786 Status
= gEfiShellProtocol
->SetMap(DevPath
, SName
);
787 if (EFI_ERROR(Status
)) {
788 return (SHELL_DEVICE_ERROR
);
790 return (SHELL_SUCCESS
);
794 function to determine if a string has only numbers and letters
796 This is useful for such things as Map names which can only be letters and numbers
798 @param[in] String pointer to the string to analyze
800 @retval TRUE String has only numbers and letters
801 @retval FALSE String has at least one other character.
806 IN CONST CHAR16
*String
809 while(String
!= NULL
&& *String
!= CHAR_NULL
) {
810 if (! ((*String
>= L
'a' && *String
<= L
'z') ||
811 (*String
>= L
'A' && *String
<= L
'Z') ||
812 (*String
>= L
'0' && *String
<= L
'9'))
822 function to add a mapping from an EFI_HANDLE.
824 This function will get the device path associated with the Handle and call SetMap.
826 @param[in] Handle The handle to add a mapping for
827 @param[in] SName The name of the new mapping
829 @retval SHELL_SUCCESS the mapping was added
830 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
831 @return Shell version of a return value from either
832 gBS->OpenProtocol or EfiShellProtocol->SetMap
837 AddMappingFromHandle(
838 IN CONST EFI_HANDLE Handle
,
839 IN CONST CHAR16
*SName
842 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
845 if (!IsNumberLetterOnly(SName
)) {
846 return (SHELL_INVALID_PARAMETER
);
849 Status
= gBS
->OpenProtocol(
851 &gEfiDevicePathProtocolGuid
,
855 EFI_OPEN_PROTOCOL_GET_PROTOCOL
857 if (EFI_ERROR(Status
)) {
858 return (SHELL_DEVICE_ERROR
);
860 Status
= gEfiShellProtocol
->SetMap(DevPath
, SName
);
861 if (EFI_ERROR(Status
)) {
862 return (SHELL_DEVICE_ERROR
);
864 return (SHELL_SUCCESS
);
867 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
875 {L
"-sfo", TypeValue
},
880 Function for 'map' command.
882 @param[in] ImageHandle Handle to the Image (NULL if Internal).
883 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
888 IN EFI_HANDLE ImageHandle
,
889 IN EFI_SYSTEM_TABLE
*SystemTable
894 CHAR16
*ProblemParam
;
896 CONST CHAR16
*Mapping
;
897 EFI_HANDLE MappingAsHandle
;
898 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
899 SHELL_STATUS ShellStatus
;
903 CONST CHAR16
*Param1
;
904 CONST CHAR16
*TypeString
;
910 ShellStatus
= SHELL_SUCCESS
;
911 MappingAsHandle
= NULL
;
914 // initialize the shell lib (we must be in non-auto-init...)
916 Status
= ShellInitialize();
917 ASSERT_EFI_ERROR(Status
);
919 Status
= CommandInit();
920 ASSERT_EFI_ERROR(Status
);
923 // parse the command line
925 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
926 if (EFI_ERROR(Status
)) {
927 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
928 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
929 FreePool(ProblemParam
);
930 ShellStatus
= SHELL_INVALID_PARAMETER
;
938 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
939 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
940 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
941 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
943 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
944 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
945 ShellStatus
= SHELL_INVALID_PARAMETER
;
948 // Deleting a map name...
950 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
951 if ( ShellCommandLineGetFlag(Package
, L
"-r")
952 || ShellCommandLineGetFlag(Package
, L
"-v")
955 || ShellCommandLineGetFlag(Package
, L
"-u")
956 || ShellCommandLineGetFlag(Package
, L
"-t")
958 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
959 ShellStatus
= SHELL_INVALID_PARAMETER
;
961 SName
= ShellCommandLineGetValue(Package
, L
"-d");
963 Status
= PerformMappingDelete(SName
);
964 if (EFI_ERROR(Status
)) {
966 case EFI_ACCESS_DENIED
:
967 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
968 ShellStatus
= SHELL_ACCESS_DENIED
;
971 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
972 ShellStatus
= SHELL_INVALID_PARAMETER
;
975 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
976 ShellStatus
= SHELL_UNSUPPORTED
;
980 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
981 ShellStatus
= SHELL_INVALID_PARAMETER
;
984 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
985 // || ShellCommandLineGetFlag(Package, L"-v")
988 || ShellCommandLineGetFlag(Package
, L
"-u")
989 || ShellCommandLineGetFlag(Package
, L
"-t")
991 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
995 Status
= ShellCommandCreateInitialMappingsAndPaths();
996 if (EFI_ERROR(Status
)) {
997 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
998 ShellStatus
= SHELL_UNSUPPORTED
;
1001 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1005 Status
= UpdateMapping();
1006 if (EFI_ERROR(Status
)) {
1007 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1008 ShellStatus
= SHELL_UNSUPPORTED
;
1011 if (ShellStatus
== SHELL_SUCCESS
) {
1012 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1013 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1016 &&TypeString
== NULL
1019 // now do the display...
1021 ShellStatus
= PerformMappingDisplay(
1022 ShellCommandLineGetFlag(Package
, L
"-v"),
1032 // now do the display...
1034 ShellStatus
= PerformMappingDisplay2(
1035 ShellCommandLineGetFlag(Package
, L
"-v"),
1046 // adding or displaying (there were no flags)
1048 SName
= ShellCommandLineGetRawValue(Package
, 1);
1049 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1054 // display only since no flags
1056 ShellStatus
= PerformMappingDisplay(
1057 ShellCommandLineGetFlag(Package
, L
"-v"),
1065 } else if ( SName
== NULL
1069 // Display only the one specified
1071 ShellStatus
= PerformMappingDisplay(
1077 SName
, // note the variable here...
1081 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1082 MappingAsHandle
= ConvertHandleIndexToHandle(StrHexToUintn(Mapping
));
1084 MappingAsHandle
= NULL
;
1086 if (MappingAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1087 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1088 ShellStatus
= SHELL_INVALID_PARAMETER
;
1090 if (MappingAsHandle
!= NULL
) {
1091 ShellStatus
= AddMappingFromHandle(MappingAsHandle
, SName
);
1093 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1095 if (ShellStatus
!= SHELL_SUCCESS
) {
1096 switch (ShellStatus
) {
1097 case SHELL_ACCESS_DENIED
:
1098 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1100 case SHELL_INVALID_PARAMETER
:
1101 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1108 // now do the display...
1110 ShellStatus
= PerformMappingDisplay(
1119 } // we were sucessful so do an output
1120 } // got a valid map target
1121 } // got 2 variables
1122 } // we are adding a mapping
1123 } // got valid parameters
1127 // free the command line package
1129 ShellCommandLineFreeVarList (Package
);
1131 return (ShellStatus
);