2 Main file for map shell level 2 command.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2015, 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 <Protocol/SimpleFileSystem.h>
18 #include <Protocol/BlockIo.h>
19 #include <Library/DevicePathLib.h>
20 #include <Library/HandleParsingLib.h>
21 #include <Library/SortLib.h>
24 Determine if a string has only numbers and letters.
26 This is useful for such things as Map names which can only be letters and numbers.
28 @param[in] String pointer to the string to analyze,
29 @param[in] Len Number of characters to analyze.
31 @retval TRUE String has only numbers and letters
32 @retval FALSE String has at least one other character.
37 IN CONST CHAR16
*String
,
42 for (Count
= 0 ; Count
< Len
&& String
!= NULL
&& *String
!= CHAR_NULL
; String
++,Count
++) {
43 if (! ((*String
>= L
'a' && *String
<= L
'z') ||
44 (*String
>= L
'A' && *String
<= L
'Z') ||
45 (*String
>= L
'0' && *String
<= L
'9'))
54 Do a search in the Target delimited list.
56 @param[in] List The list to seatch in.
57 @param[in] MetaTarget The item to search for. MetaMatching supported.
58 @param[out] FullName Optional pointer to an allocated buffer containing
60 @param[in] Meta TRUE to use MetaMatching.
61 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.
62 @param[in] Target The single character that delimits list
68 IN CONST CHAR16
*List
,
69 IN CONST CHAR16
*MetaTarget
,
70 OUT CHAR16
**FullName OPTIONAL
,
71 IN CONST BOOLEAN Meta
,
72 IN CONST BOOLEAN SkipTrailingNumbers
,
73 IN CONST CHAR16
*Target
78 CONST CHAR16
*ListWalker
;
82 for (ListWalker
= List
, TempList
= NULL
83 ; ListWalker
!= NULL
&& *ListWalker
!= CHAR_NULL
86 TempList
= StrnCatGrow(&TempList
, NULL
, ListWalker
, 0);
87 ASSERT(TempList
!= NULL
);
88 TempSpot
= StrStr(TempList
, Target
);
89 if (TempSpot
!= NULL
) {
90 *TempSpot
= CHAR_NULL
;
93 while (SkipTrailingNumbers
&& (ShellIsDecimalDigitCharacter(TempList
[StrLen(TempList
)-1]) || TempList
[StrLen(TempList
)-1] == L
':')) {
94 TempList
[StrLen(TempList
)-1] = CHAR_NULL
;
97 ListWalker
= StrStr(ListWalker
, Target
);
98 while(ListWalker
!= NULL
&& *ListWalker
== *Target
) {
102 Result
= gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, (CHAR16
*)TempList
, (CHAR16
*)MetaTarget
);
104 Result
= (BOOLEAN
)(StrCmp(TempList
, MetaTarget
)==0);
107 if (FullName
!= NULL
) {
108 *FullName
= TempList
;
122 Determine what type of device is represented and return it's string. The
123 string is in allocated memory and must be callee freed. The HII is is listed below.
124 The actual string cannot be determined.
126 @param[in] DevicePath The device to analyze.
128 @retval STR_MAP_MEDIA_UNKNOWN The media type is unknown.
129 @retval STR_MAP_MEDIA_HARDDISK The media is a hard drive.
130 @retval STR_MAP_MEDIA_CDROM The media is a CD ROM.
131 @retval STR_MAP_MEDIA_FLOPPY The media is a floppy drive.
136 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
139 ACPI_HID_DEVICE_PATH
*Acpi
;
142 // Parse the device path:
143 // Devicepath sub type mediatype
144 // MEDIA_HANRDDRIVE_DP -> Hard Disk
145 // MEDIA_CDROM_DP -> CD Rom
146 // Acpi.HID = 0X0604 -> Floppy
148 if (NULL
== DevicePath
) {
149 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
152 for (;!IsDevicePathEndType (DevicePath
) ;DevicePath
= NextDevicePathNode (DevicePath
)) {
153 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
154 switch (DevicePathSubType (DevicePath
)) {
155 case MEDIA_HARDDRIVE_DP
:
156 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK
), NULL
);
158 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_CDROM
), NULL
);
160 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
161 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePath
;
162 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
163 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY
), NULL
);
168 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
172 Function to detemine if a handle has removable storage.
174 @param[in] DevicePath DevicePath to test.
176 @retval TRUE The handle has removable storage.
177 @retval FALSE The handle does not have removable storage.
182 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
185 if (NULL
== DevicePath
) {
189 while (!IsDevicePathEndType (DevicePath
)) {
190 if (DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) {
191 switch (DevicePathSubType (DevicePath
)) {
199 DevicePath
= NextDevicePathNode (DevicePath
);
205 Function to detemine if a something on the map list matches.
207 @param[in] MapList The pointer to the list to test.
208 @param[in] Specific The pointer to a specific name to test for.
209 @param[in] TypeString The pointer to the list of types.
210 @param[in] Normal Always show normal mappings.
211 @param[in] Consist Always show consistent mappings.
213 @retval TRUE The map should be displayed.
214 @retval FALSE The map should not be displayed.
219 IN CONST CHAR16
*MapList
,
220 IN CONST CHAR16
*Specific
,
221 IN CONST CHAR16
*TypeString
,
222 IN CONST BOOLEAN Normal
,
223 IN CONST BOOLEAN Consist
227 RETURN_STATUS Status
;
230 // specific has priority
232 if (Specific
!= NULL
) {
233 NewSpecific
= AllocateCopyPool(StrSize(Specific
) + sizeof(CHAR16
), Specific
);
234 if (NewSpecific
== NULL
){
237 if (NewSpecific
[StrLen(NewSpecific
)-1] != L
':') {
238 Status
= StrnCatS(NewSpecific
, (StrSize(Specific
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
239 if (EFI_ERROR (Status
)) {
240 FreePool(NewSpecific
);
245 if (SearchList(MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
246 FreePool(NewSpecific
);
249 FreePool(NewSpecific
);
253 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
254 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
255 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
256 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
262 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
263 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
267 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
275 Display a single map line for device Handle if conditions are met.
277 @param[in] Verbose TRUE to display (extra) verbose information.
278 @param[in] Consist TRUE to display consistent mappings.
279 @param[in] Normal TRUE to display normal (not consist) mappings.
280 @param[in] TypeString pointer to string of filter types.
281 @param[in] SFO TRUE to display output in Standard Output Format.
282 @param[in] Specific pointer to string for specific map to display.
283 @param[in] Handle The handle to display from.
285 @retval EFI_SUCCESS The mapping was displayed.
289 PerformSingleMappingDisplay(
290 IN CONST BOOLEAN Verbose
,
291 IN CONST BOOLEAN Consist
,
292 IN CONST BOOLEAN Normal
,
293 IN CONST CHAR16
*TypeString
,
294 IN CONST BOOLEAN SFO
,
295 IN CONST CHAR16
*Specific OPTIONAL
,
296 IN CONST EFI_HANDLE Handle
299 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
300 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
301 CONST CHAR16
*MapList
;
304 CHAR16
*DevPathString
;
309 CONST CHAR16
*TempSpot2
;
314 DevPath
= DevicePathFromHandle(Handle
);
315 DevPathCopy
= DevPath
;
316 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
317 if (MapList
== NULL
) {
318 return EFI_NOT_FOUND
;
321 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
322 return EFI_NOT_FOUND
;
325 if (Normal
|| !Consist
) {
327 // need the Normal here since people can use both on command line. otherwise unused.
334 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
335 if (CurrentName
== NULL
) {
336 return (EFI_OUT_OF_RESOURCES
);
340 // Chop off the other names that become "Alias(s)"
341 // leaving just the normal name
343 TempSpot
= StrStr(CurrentName
, L
";");
344 if (TempSpot
!= NULL
) {
345 *TempSpot
= CHAR_NULL
;
351 // Skip the first name. This is the standard name.
353 TempSpot
= StrStr(MapList
, L
";");
354 if (TempSpot
!= NULL
) {
357 SearchList(TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
358 if (CurrentName
== NULL
) {
359 SearchList(TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
361 if (CurrentName
== NULL
) {
362 SearchList(TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
364 if (CurrentName
== NULL
) {
365 SearchList(TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
367 if (CurrentName
== NULL
) {
369 // We didnt find anything, so just the first one in the list...
371 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
372 if (CurrentName
== NULL
) {
373 return (EFI_OUT_OF_RESOURCES
);
375 TempSpot
= StrStr(CurrentName
, L
";");
376 if (TempSpot
!= NULL
) {
377 *TempSpot
= CHAR_NULL
;
380 Alias
= StrnCatGrow(&Alias
, 0, MapList
, 0);
382 return EFI_OUT_OF_RESOURCES
;
384 TempSpot
= StrStr(Alias
, CurrentName
);
385 if (TempSpot
!= NULL
) {
386 TempSpot2
= StrStr(TempSpot
, L
";");
387 if (TempSpot2
!= NULL
) {
388 TempSpot2
++; // Move past ";" from CurrentName
389 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
391 *TempSpot
= CHAR_NULL
;
394 if (Alias
[StrLen(Alias
)-1] == L
';') {
395 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
399 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
400 TempLen
= StrLen(CurrentName
);
406 STRING_TOKEN (STR_MAP_ENTRY
),
407 gShellLevel2HiiHandle
,
409 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
414 // also print handle, media type, removable (y/n), and current directory
416 MediaType
= GetDeviceMediaType(DevPath
);
417 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
418 Removable
= IsRemoveableDevice(DevPath
);
419 TempSpot2
= ShellGetCurrentDir(CurrentName
);
424 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
425 gShellLevel2HiiHandle
,
426 ConvertHandleToHandleIndex(Handle
),
428 Removable
?L
"Yes":L
"No",
432 SHELL_FREE_NON_NULL(MediaType
);
439 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
440 gShellLevel2HiiHandle
,
443 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
446 SHELL_FREE_NON_NULL(DevPathString
);
447 SHELL_FREE_NON_NULL(CurrentName
);
448 SHELL_FREE_NON_NULL(Alias
);
453 Delete Specific from the list of maps for device Handle.
455 @param[in] Specific The name to delete.
456 @param[in] Handle The device to look on.
458 @retval EFI_SUCCESS The delete was successful.
459 @retval EFI_NOT_FOUND Name was not a map on Handle.
463 PerformSingleMappingDelete(
464 IN CONST CHAR16
*Specific
,
465 IN CONST EFI_HANDLE Handle
468 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
469 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
470 CONST CHAR16
*MapList
;
473 DevPath
= DevicePathFromHandle(Handle
);
474 DevPathCopy
= DevPath
;
475 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
478 if (MapList
== NULL
) {
479 return (EFI_NOT_FOUND
);
482 // if there is a specific and its not on the list...
484 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
485 return (EFI_NOT_FOUND
);
487 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
490 CONST CHAR16 Cd
[] = L
"cd*";
491 CONST CHAR16 Hd
[] = L
"hd*";
492 CONST CHAR16 Fp
[] = L
"fp*";
493 CONST CHAR16 AnyF
[] = L
"F*";
495 Function to display mapping information to the user.
497 If Specific is specified then Consist and Normal will be ignored since information will
498 be printed for the specific item only.
500 @param[in] Verbose TRUE to display (extra) verbose information.
501 @param[in] Consist TRUE to display consistent mappings.
502 @param[in] Normal TRUE to display normal (not consist) mappings.
503 @param[in] TypeString Pointer to string of filter types.
504 @param[in] SFO TRUE to display output in Standard Output Format.
505 @param[in] Specific Pointer to string for specific map to display.
506 @param[in] Header TRUE to print the header block.
508 @retval SHELL_SUCCESS The display was printed.
509 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
514 PerformMappingDisplay(
515 IN CONST BOOLEAN Verbose
,
516 IN CONST BOOLEAN Consist
,
517 IN CONST BOOLEAN Normal
,
518 IN CONST CHAR16
*TypeString
,
519 IN CONST BOOLEAN SFO
,
520 IN CONST CHAR16
*Specific OPTIONAL
,
521 IN CONST BOOLEAN Header
525 EFI_HANDLE
*HandleBuffer
;
531 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
532 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
533 return (SHELL_INVALID_PARAMETER
);
536 if (TypeString
!= NULL
) {
538 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
540 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
542 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
543 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", TypeString
);
544 return (SHELL_INVALID_PARAMETER
);
546 } else if (Test
== NULL
) {
547 Test
= (CHAR16
*)AnyF
;
559 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
561 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
569 // Look up all SimpleFileSystems in the platform
571 Status
= gBS
->LocateHandle(
573 &gEfiSimpleFileSystemProtocolGuid
,
577 if (Status
== EFI_BUFFER_TOO_SMALL
) {
578 HandleBuffer
= AllocateZeroPool(BufferSize
);
579 if (HandleBuffer
== NULL
) {
580 return (SHELL_OUT_OF_RESOURCES
);
582 Status
= gBS
->LocateHandle(
584 &gEfiSimpleFileSystemProtocolGuid
,
591 // Get the map name(s) for each one.
593 for ( LoopVar
= 0, Found
= FALSE
594 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
597 Status
= PerformSingleMappingDisplay(
604 HandleBuffer
[LoopVar
]);
605 if (!EFI_ERROR(Status
)) {
611 // Look up all BlockIo in the platform
613 Status
= gBS
->LocateHandle(
615 &gEfiBlockIoProtocolGuid
,
619 if (Status
== EFI_BUFFER_TOO_SMALL
) {
620 SHELL_FREE_NON_NULL(HandleBuffer
);
621 HandleBuffer
= AllocateZeroPool(BufferSize
);
622 if (HandleBuffer
== NULL
) {
623 return (SHELL_OUT_OF_RESOURCES
);
625 Status
= gBS
->LocateHandle(
627 &gEfiBlockIoProtocolGuid
,
632 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
634 // Get the map name(s) for each one.
637 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
641 // Skip any that were already done...
643 if (gBS
->OpenProtocol(
644 HandleBuffer
[LoopVar
],
645 &gEfiSimpleFileSystemProtocolGuid
,
649 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
652 Status
= PerformSingleMappingDisplay(
659 HandleBuffer
[LoopVar
]);
660 if (!EFI_ERROR(Status
)) {
664 FreePool(HandleBuffer
);
667 if (Specific
!= NULL
) {
668 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", Specific
);
670 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
, L
"map");
673 return (SHELL_SUCCESS
);
677 Perform a mapping display and parse for multiple types in the TypeString.
679 @param[in] Verbose TRUE to use verbose output.
680 @param[in] Consist TRUE to display consistent names.
681 @param[in] Normal TRUE to display normal names.
682 @param[in] TypeString An optional comma-delimited list of types.
683 @param[in] SFO TRUE to display in SFO format. See Spec.
684 @param[in] Specific An optional specific map name to display alone.
686 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
687 @retval SHELL_SUCCESS The display was successful.
688 @sa PerformMappingDisplay
692 PerformMappingDisplay2(
693 IN CONST BOOLEAN Verbose
,
694 IN CONST BOOLEAN Consist
,
695 IN CONST BOOLEAN Normal
,
696 IN CONST CHAR16
*TypeString
,
697 IN CONST BOOLEAN SFO
,
698 IN CONST CHAR16
*Specific OPTIONAL
701 CONST CHAR16
*TypeWalker
;
702 SHELL_STATUS ShellStatus
;
706 if (TypeString
== NULL
) {
707 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
709 ShellStatus
= SHELL_SUCCESS
;
710 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
711 Comma
= StrStr(TypeWalker
, L
",");
713 if (ShellStatus
== SHELL_SUCCESS
) {
714 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
716 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
721 if (ShellStatus
== SHELL_SUCCESS
) {
722 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
724 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
727 TypeWalker
= Comma
+ 1;
731 return (ShellStatus
);
735 Delete a specific map.
737 @param[in] Specific The pointer to the name of the map to delete.
739 @retval EFI_INVALID_PARAMETER Specific was NULL.
740 @retval EFI_SUCCESS The operation was successful.
741 @retval EFI_NOT_FOUND Specific could not be found.
745 PerformMappingDelete(
746 IN CONST CHAR16
*Specific
750 EFI_HANDLE
*HandleBuffer
;
755 if (Specific
== NULL
) {
756 return (EFI_INVALID_PARAMETER
);
764 // Look up all SimpleFileSystems in the platform
766 Status
= gBS
->LocateHandle(
768 &gEfiDevicePathProtocolGuid
,
772 if (Status
== EFI_BUFFER_TOO_SMALL
) {
773 HandleBuffer
= AllocateZeroPool(BufferSize
);
774 if (HandleBuffer
== NULL
) {
775 return (EFI_OUT_OF_RESOURCES
);
777 Status
= gBS
->LocateHandle(
779 &gEfiDevicePathProtocolGuid
,
784 if (EFI_ERROR(Status
)) {
785 SHELL_FREE_NON_NULL(HandleBuffer
);
789 if (HandleBuffer
!= NULL
) {
791 // Get the map name(s) for each one.
794 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
797 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
803 // Look up all BlockIo in the platform
805 Status
= gBS
->LocateHandle(
807 &gEfiBlockIoProtocolGuid
,
811 if (Status
== EFI_BUFFER_TOO_SMALL
) {
812 FreePool(HandleBuffer
);
813 HandleBuffer
= AllocateZeroPool(BufferSize
);
814 if (HandleBuffer
== NULL
) {
815 return (EFI_OUT_OF_RESOURCES
);
817 Status
= gBS
->LocateHandle(
819 &gEfiBlockIoProtocolGuid
,
824 if (EFI_ERROR(Status
)) {
825 SHELL_FREE_NON_NULL(HandleBuffer
);
829 if (HandleBuffer
!= NULL
) {
831 // Get the map name(s) for each one.
834 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
838 // Skip any that were already done...
840 if (gBS
->OpenProtocol(
841 HandleBuffer
[LoopVar
],
842 &gEfiDevicePathProtocolGuid
,
846 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
849 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
854 SHELL_FREE_NON_NULL(HandleBuffer
);
856 return (EFI_NOT_FOUND
);
858 return (EFI_SUCCESS
);
862 function to add a mapping from mapping.
864 This function will get the device path associated with the mapping and call SetMap.
866 @param[in] Map The Map to add a mapping for
867 @param[in] SName The name of the new mapping
869 @retval SHELL_SUCCESS the mapping was added
870 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
871 @return Shell version of a return value from EfiShellProtocol->SetMap
876 AddMappingFromMapping(
877 IN CONST CHAR16
*Map
,
878 IN CONST CHAR16
*SName
881 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
884 RETURN_STATUS StrRetStatus
;
886 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
887 if (NewSName
== NULL
) {
888 return (SHELL_OUT_OF_RESOURCES
);
890 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
891 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
892 if (EFI_ERROR(StrRetStatus
)) {
894 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
898 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
900 return (SHELL_INVALID_PARAMETER
);
903 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
904 if (DevPath
== NULL
) {
906 return (SHELL_INVALID_PARAMETER
);
909 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
911 if (EFI_ERROR(Status
)) {
912 return (SHELL_DEVICE_ERROR
);
914 return (SHELL_SUCCESS
);
918 function to add a mapping from an EFI_HANDLE.
920 This function will get the device path associated with the Handle and call SetMap.
922 @param[in] Handle The handle to add a mapping for
923 @param[in] SName The name of the new mapping
925 @retval SHELL_SUCCESS the mapping was added
926 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
927 @return Shell version of a return value from either
928 gBS->OpenProtocol or EfiShellProtocol->SetMap
933 AddMappingFromHandle(
934 IN CONST EFI_HANDLE Handle
,
935 IN CONST CHAR16
*SName
938 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
941 RETURN_STATUS StrRetStatus
;
943 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
944 if (NewSName
== NULL
) {
945 return (SHELL_OUT_OF_RESOURCES
);
947 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
948 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
949 if (EFI_ERROR(StrRetStatus
)) {
951 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
955 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
957 return (SHELL_INVALID_PARAMETER
);
960 Status
= gBS
->OpenProtocol(
962 &gEfiDevicePathProtocolGuid
,
966 EFI_OPEN_PROTOCOL_GET_PROTOCOL
968 if (EFI_ERROR(Status
)) {
970 return (SHELL_DEVICE_ERROR
);
972 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
974 if (EFI_ERROR(Status
)) {
975 return (SHELL_DEVICE_ERROR
);
977 return (SHELL_SUCCESS
);
980 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
988 {L
"-sfo", TypeValue
},
993 Function for 'map' command.
995 @param[in] ImageHandle Handle to the Image (NULL if Internal).
996 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1000 ShellCommandRunMap (
1001 IN EFI_HANDLE ImageHandle
,
1002 IN EFI_SYSTEM_TABLE
*SystemTable
1006 LIST_ENTRY
*Package
;
1007 CHAR16
*ProblemParam
;
1008 CONST CHAR16
*SName
;
1009 CONST CHAR16
*Mapping
;
1010 EFI_HANDLE MapAsHandle
;
1011 SHELL_STATUS ShellStatus
;
1015 CONST CHAR16
*Param1
;
1016 CONST CHAR16
*TypeString
;
1017 UINTN TempStringLength
;
1019 ProblemParam
= NULL
;
1022 ShellStatus
= SHELL_SUCCESS
;
1026 // initialize the shell lib (we must be in non-auto-init...)
1028 Status
= ShellInitialize();
1029 ASSERT_EFI_ERROR(Status
);
1031 Status
= CommandInit();
1032 ASSERT_EFI_ERROR(Status
);
1035 // parse the command line
1037 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1038 if (EFI_ERROR(Status
)) {
1039 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1040 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"map", ProblemParam
);
1041 FreePool(ProblemParam
);
1042 ShellStatus
= SHELL_INVALID_PARAMETER
;
1050 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1051 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1052 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1053 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1055 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1056 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"map");
1057 ShellStatus
= SHELL_INVALID_PARAMETER
;
1060 // Deleting a map name...
1062 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1063 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1064 || ShellCommandLineGetFlag(Package
, L
"-v")
1067 || ShellCommandLineGetFlag(Package
, L
"-u")
1068 || ShellCommandLineGetFlag(Package
, L
"-t")
1070 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
, L
"map");
1071 ShellStatus
= SHELL_INVALID_PARAMETER
;
1073 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1074 if (SName
!= NULL
) {
1075 Status
= PerformMappingDelete(SName
);
1076 if (EFI_ERROR(Status
)) {
1077 if (Status
== EFI_ACCESS_DENIED
) {
1078 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1079 ShellStatus
= SHELL_ACCESS_DENIED
;
1080 } else if (Status
== EFI_NOT_FOUND
) {
1081 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", SName
);
1082 ShellStatus
= SHELL_INVALID_PARAMETER
;
1084 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1085 ShellStatus
= SHELL_UNSUPPORTED
;
1089 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
1090 ShellStatus
= SHELL_INVALID_PARAMETER
;
1093 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1094 // || ShellCommandLineGetFlag(Package, L"-v")
1097 || ShellCommandLineGetFlag(Package
, L
"-u")
1098 || ShellCommandLineGetFlag(Package
, L
"-t")
1100 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1104 Status
= ShellCommandCreateInitialMappingsAndPaths();
1105 if (EFI_ERROR(Status
)) {
1106 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1107 ShellStatus
= SHELL_UNSUPPORTED
;
1110 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1114 Status
= ShellCommandUpdateMapping ();
1115 if (EFI_ERROR(Status
)) {
1116 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1117 ShellStatus
= SHELL_UNSUPPORTED
;
1120 if (ShellStatus
== SHELL_SUCCESS
) {
1121 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1122 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1125 &&TypeString
== NULL
1128 // now do the display...
1130 ShellStatus
= PerformMappingDisplay(
1131 ShellCommandLineGetFlag(Package
, L
"-v"),
1141 // now do the display...
1143 ShellStatus
= PerformMappingDisplay2(
1144 ShellCommandLineGetFlag(Package
, L
"-v"),
1155 // adding or displaying (there were no flags)
1157 SName
= ShellCommandLineGetRawValue(Package
, 1);
1158 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1163 // display only since no flags
1165 ShellStatus
= PerformMappingDisplay(
1166 ShellCommandLineGetFlag(Package
, L
"-v"),
1174 } else if ( SName
== NULL
1178 // Display only the one specified
1180 ShellStatus
= PerformMappingDisplay(
1186 SName
, // note the variable here...
1190 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1191 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1195 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1196 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1197 ShellStatus
= SHELL_INVALID_PARAMETER
;
1199 if (MapAsHandle
!= NULL
) {
1200 TempStringLength
= StrLen(SName
);
1201 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1202 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", SName
);
1203 ShellStatus
= SHELL_INVALID_PARAMETER
;
1205 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1208 TempStringLength
= StrLen(SName
);
1209 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1210 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", SName
);
1211 ShellStatus
= SHELL_INVALID_PARAMETER
;
1213 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1216 if (ShellStatus
!= SHELL_SUCCESS
) {
1217 switch (ShellStatus
) {
1218 case SHELL_ACCESS_DENIED
:
1219 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1221 case SHELL_INVALID_PARAMETER
:
1222 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1224 case SHELL_DEVICE_ERROR
:
1225 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1228 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", ShellStatus
|MAX_BIT
);
1232 // now do the display...
1234 ShellStatus
= PerformMappingDisplay(
1243 } // we were sucessful so do an output
1244 } // got a valid map target
1245 } // got 2 variables
1246 } // we are adding a mapping
1247 } // got valid parameters
1251 // free the command line package
1253 ShellCommandLineFreeVarList (Package
);
1255 return (ShellStatus
);