2 Main file for map shell level 2 command.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "UefiShellLevel2CommandsLib.h"
13 #include <Protocol/SimpleFileSystem.h>
14 #include <Protocol/BlockIo.h>
15 #include <Library/DevicePathLib.h>
16 #include <Library/HandleParsingLib.h>
17 #include <Library/SortLib.h>
20 Determine if a string has only numbers and letters.
22 This is useful for such things as Map names which can only be letters and numbers.
24 @param[in] String pointer to the string to analyze,
25 @param[in] Len Number of characters to analyze.
27 @retval TRUE String has only numbers and letters
28 @retval FALSE String has at least one other character.
32 IN CONST CHAR16
*String
,
38 for (Count
= 0; Count
< Len
&& String
!= NULL
&& *String
!= CHAR_NULL
; String
++, Count
++) {
39 if (!(((*String
>= L
'a') && (*String
<= L
'z')) ||
40 ((*String
>= L
'A') && (*String
<= L
'Z')) ||
41 ((*String
>= L
'0') && (*String
<= L
'9')))
52 Do a search in the Target delimited list.
54 @param[in] List The list to seatch in.
55 @param[in] MetaTarget The item to search for. MetaMatching supported.
56 @param[out] FullName Optional pointer to an allocated buffer containing
58 @param[in] Meta TRUE to use MetaMatching.
59 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.
60 @param[in] Target The single character that delimits list
65 IN CONST CHAR16
*List
,
66 IN CONST CHAR16
*MetaTarget
,
67 OUT CHAR16
**FullName OPTIONAL
,
68 IN CONST BOOLEAN Meta
,
69 IN CONST BOOLEAN SkipTrailingNumbers
,
70 IN CONST CHAR16
*Target
75 CONST CHAR16
*ListWalker
;
79 for (ListWalker
= List
, TempList
= NULL
80 ; ListWalker
!= NULL
&& *ListWalker
!= CHAR_NULL
84 TempList
= StrnCatGrow (&TempList
, NULL
, ListWalker
, 0);
85 ASSERT (TempList
!= NULL
);
86 TempSpot
= StrStr (TempList
, Target
);
87 if (TempSpot
!= NULL
) {
88 *TempSpot
= CHAR_NULL
;
91 while (SkipTrailingNumbers
&& (ShellIsDecimalDigitCharacter (TempList
[StrLen (TempList
)-1]) || TempList
[StrLen (TempList
)-1] == L
':')) {
92 TempList
[StrLen (TempList
)-1] = CHAR_NULL
;
95 ListWalker
= StrStr (ListWalker
, Target
);
96 while (ListWalker
!= NULL
&& *ListWalker
== *Target
) {
101 Result
= gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, (CHAR16
*)TempList
, (CHAR16
*)MetaTarget
);
103 Result
= (BOOLEAN
)(StrCmp (TempList
, MetaTarget
) == 0);
107 if (FullName
!= NULL
) {
108 *FullName
= TempList
;
124 Determine what type of device is represented and return it's string. The
125 string is in allocated memory and must be callee freed. The HII is is listed below.
126 The actual string cannot be determined.
128 @param[in] DevicePath The device to analyze.
130 @retval STR_MAP_MEDIA_UNKNOWN The media type is unknown.
131 @retval STR_MAP_MEDIA_HARDDISK The media is a hard drive.
132 @retval STR_MAP_MEDIA_CDROM The media is a CD ROM.
133 @retval STR_MAP_MEDIA_FLOPPY The media is a floppy drive.
137 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
140 ACPI_HID_DEVICE_PATH
*Acpi
;
143 // Parse the device path:
144 // Devicepath sub type mediatype
145 // MEDIA_HANRDDRIVE_DP -> Hard Disk
146 // MEDIA_CDROM_DP -> CD Rom
147 // Acpi.HID = 0X0604 -> Floppy
149 if (NULL
== DevicePath
) {
150 return HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MAP_MEDIA_UNKNOWN
), NULL
);
153 for ( ; !IsDevicePathEndType (DevicePath
); DevicePath
= NextDevicePathNode (DevicePath
)) {
154 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
155 switch (DevicePathSubType (DevicePath
)) {
156 case MEDIA_HARDDRIVE_DP
:
157 return HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MAP_MEDIA_HARDDISK
), NULL
);
159 return HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MAP_MEDIA_CDROM
), NULL
);
161 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
162 Acpi
= (ACPI_HID_DEVICE_PATH
*)DevicePath
;
163 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
164 return HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MAP_MEDIA_FLOPPY
), NULL
);
169 return HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MAP_MEDIA_UNKNOWN
), NULL
);
173 Function to detemine if a handle has removable storage.
175 @param[in] DevicePath DevicePath to test.
177 @retval TRUE The handle has removable storage.
178 @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
)) {
200 DevicePath
= NextDevicePathNode (DevicePath
);
207 Function to detemine if a something on the map list matches.
209 @param[in] MapList The pointer to the list to test.
210 @param[in] Specific The pointer to a specific name to test for.
211 @param[in] TypeString The pointer to the list of types.
212 @param[in] Normal Always show normal mappings.
213 @param[in] Consist Always show consistent mappings.
215 @retval TRUE The map should be displayed.
216 @retval FALSE The map should not be displayed.
220 IN CONST CHAR16
*MapList
,
221 IN CONST CHAR16
*Specific
,
222 IN CONST CHAR16
*TypeString
,
223 IN CONST BOOLEAN Normal
,
224 IN CONST BOOLEAN Consist
228 RETURN_STATUS Status
;
232 // specific has priority
234 if (Specific
!= NULL
) {
235 Length
= StrLen (Specific
);
237 // Allocate enough buffer for Specific and potential ":"
239 NewSpecific
= AllocatePool ((Length
+ 2) * sizeof (CHAR16
));
240 if (NewSpecific
== NULL
) {
244 StrCpyS (NewSpecific
, Length
+ 2, Specific
);
245 if (Specific
[Length
- 1] != L
':') {
246 Status
= StrnCatS (NewSpecific
, Length
+ 2, L
":", StrLen (L
":"));
247 if (EFI_ERROR (Status
)) {
248 FreePool (NewSpecific
);
253 if (SearchList (MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
254 FreePool (NewSpecific
);
258 FreePool (NewSpecific
);
262 && (Specific
== NULL
)
263 && ( SearchList (MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
264 || SearchList (MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
265 || SearchList (MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
266 || SearchList (MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";")))
272 && (Specific
== NULL
)
273 && ( SearchList (MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
274 || SearchList (MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";")))
279 if ((TypeString
!= NULL
) && SearchList (MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
287 Display a single map line for device Handle if conditions are met.
289 @param[in] Verbose TRUE to display (extra) verbose information.
290 @param[in] Consist TRUE to display consistent mappings.
291 @param[in] Normal TRUE to display normal (not consist) mappings.
292 @param[in] TypeString pointer to string of filter types.
293 @param[in] SFO TRUE to display output in Standard Output Format.
294 @param[in] Specific pointer to string for specific map to display.
295 @param[in] Handle The handle to display from.
297 @retval EFI_SUCCESS The mapping was displayed.
300 PerformSingleMappingDisplay (
301 IN CONST BOOLEAN Verbose
,
302 IN CONST BOOLEAN Consist
,
303 IN CONST BOOLEAN Normal
,
304 IN CONST CHAR16
*TypeString
,
305 IN CONST BOOLEAN SFO
,
306 IN CONST CHAR16
*Specific OPTIONAL
,
307 IN CONST EFI_HANDLE Handle
310 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
311 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
312 CONST CHAR16
*MapList
;
315 CHAR16
*DevPathString
;
320 CONST CHAR16
*TempSpot2
;
325 DevPath
= DevicePathFromHandle (Handle
);
326 DevPathCopy
= DevPath
;
327 MapList
= gEfiShellProtocol
->GetMapFromDevicePath (&DevPathCopy
);
328 if (MapList
== NULL
) {
329 return EFI_NOT_FOUND
;
332 if (!MappingListHasType (MapList
, Specific
, TypeString
, Normal
, Consist
)) {
333 return EFI_NOT_FOUND
;
336 if (Normal
|| !Consist
) {
338 // need the Normal here since people can use both on command line. otherwise unused.
345 CurrentName
= StrnCatGrow (&CurrentName
, 0, MapList
, 0);
346 if (CurrentName
== NULL
) {
347 return (EFI_OUT_OF_RESOURCES
);
351 // Chop off the other names that become "Alias(s)"
352 // leaving just the normal name
354 TempSpot
= StrStr (CurrentName
, L
";");
355 if (TempSpot
!= NULL
) {
356 *TempSpot
= CHAR_NULL
;
362 // Skip the first name. This is the standard name.
364 TempSpot
= StrStr (MapList
, L
";");
365 if (TempSpot
!= NULL
) {
369 SearchList (TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
370 if (CurrentName
== NULL
) {
371 SearchList (TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
374 if (CurrentName
== NULL
) {
375 SearchList (TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
378 if (CurrentName
== NULL
) {
379 SearchList (TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
382 if (CurrentName
== NULL
) {
384 // We didnt find anything, so just the first one in the list...
386 CurrentName
= StrnCatGrow (&CurrentName
, 0, MapList
, 0);
387 if (CurrentName
== NULL
) {
388 return (EFI_OUT_OF_RESOURCES
);
391 TempSpot
= StrStr (CurrentName
, L
";");
392 if (TempSpot
!= NULL
) {
393 *TempSpot
= CHAR_NULL
;
396 Alias
= StrnCatGrow (&Alias
, 0, MapList
, 0);
398 return EFI_OUT_OF_RESOURCES
;
401 TempSpot
= StrStr (Alias
, CurrentName
);
402 if (TempSpot
!= NULL
) {
403 TempSpot2
= StrStr (TempSpot
, L
";");
404 if (TempSpot2
!= NULL
) {
405 TempSpot2
++; // Move past ";" from CurrentName
406 CopyMem (TempSpot
, TempSpot2
, StrSize (TempSpot2
));
408 *TempSpot
= CHAR_NULL
;
412 if (Alias
[StrLen (Alias
)-1] == L
';') {
413 Alias
[StrLen (Alias
)-1] = CHAR_NULL
;
418 DevPathString
= ConvertDevicePathToText (DevPath
, TRUE
, FALSE
);
419 TempLen
= StrLen (CurrentName
);
425 STRING_TOKEN (STR_MAP_ENTRY
),
426 gShellLevel2HiiHandle
,
428 Alias
!= NULL
? Alias
: (TempLen
< StrLen (MapList
) ? MapList
+ TempLen
+1 : L
""),
433 // also print handle, media type, removable (y/n), and current directory
435 MediaType
= GetDeviceMediaType (DevPath
);
436 if (((TypeString
!= NULL
) && (MediaType
!= NULL
) && (StrStr (TypeString
, MediaType
) != NULL
)) || (TypeString
== NULL
)) {
437 Removable
= IsRemoveableDevice (DevPath
);
438 TempSpot2
= ShellGetCurrentDir (CurrentName
);
443 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
444 gShellLevel2HiiHandle
,
445 ConvertHandleToHandleIndex (Handle
),
447 Removable
? L
"Yes" : L
"No",
452 SHELL_FREE_NON_NULL (MediaType
);
459 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
460 gShellLevel2HiiHandle
,
463 Consist
? L
"" : (TempLen
< StrLen (MapList
) ? MapList
+ TempLen
+1 : L
"")
467 SHELL_FREE_NON_NULL (DevPathString
);
468 SHELL_FREE_NON_NULL (CurrentName
);
469 SHELL_FREE_NON_NULL (Alias
);
474 Delete Specific from the list of maps for device Handle.
476 @param[in] Specific The name to delete.
477 @param[in] Handle The device to look on.
479 @retval EFI_SUCCESS The delete was successful.
480 @retval EFI_NOT_FOUND Name was not a map on Handle.
483 PerformSingleMappingDelete (
484 IN CONST CHAR16
*Specific
,
485 IN CONST EFI_HANDLE Handle
488 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
489 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
490 CONST CHAR16
*MapList
;
493 DevPath
= DevicePathFromHandle (Handle
);
494 DevPathCopy
= DevPath
;
495 MapList
= gEfiShellProtocol
->GetMapFromDevicePath (&DevPathCopy
);
498 if (MapList
== NULL
) {
499 return (EFI_NOT_FOUND
);
503 // if there is a specific and its not on the list...
505 if (!SearchList (MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
506 return (EFI_NOT_FOUND
);
509 return (gEfiShellProtocol
->SetMap (NULL
, CurrentName
));
512 CONST CHAR16 Cd
[] = L
"cd*";
513 CONST CHAR16 Hd
[] = L
"hd*";
514 CONST CHAR16 Fp
[] = L
"fp*";
515 CONST CHAR16 AnyF
[] = L
"F*";
518 Function to display mapping information to the user.
520 If Specific is specified then Consist and Normal will be ignored since information will
521 be printed for the specific item only.
523 @param[in] Verbose TRUE to display (extra) verbose information.
524 @param[in] Consist TRUE to display consistent mappings.
525 @param[in] Normal TRUE to display normal (not consist) mappings.
526 @param[in] TypeString Pointer to string of filter types.
527 @param[in] SFO TRUE to display output in Standard Output Format.
528 @param[in] Specific Pointer to string for specific map to display.
529 @param[in] Header TRUE to print the header block.
531 @retval SHELL_SUCCESS The display was printed.
532 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
536 PerformMappingDisplay (
537 IN CONST BOOLEAN Verbose
,
538 IN CONST BOOLEAN Consist
,
539 IN CONST BOOLEAN Normal
,
540 IN CONST CHAR16
*TypeString
,
541 IN CONST BOOLEAN SFO
,
542 IN CONST CHAR16
*Specific OPTIONAL
,
543 IN CONST BOOLEAN Header
547 EFI_HANDLE
*HandleBuffer
;
553 if (!Consist
&& !Normal
&& (Specific
== NULL
) && (TypeString
== NULL
)) {
554 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
555 return (SHELL_INVALID_PARAMETER
);
558 if (TypeString
!= NULL
) {
560 if (StrnCmp (TypeString
, Test
, StrLen (Test
)-1) != 0) {
562 if (StrnCmp (TypeString
, Test
, StrLen (Test
)-1) != 0) {
564 if (StrnCmp (TypeString
, Test
, StrLen (Test
)-1) != 0) {
565 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", TypeString
);
566 return (SHELL_INVALID_PARAMETER
);
568 } else if (Test
== NULL
) {
569 Test
= (CHAR16
*)AnyF
;
581 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
583 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
591 // Look up all SimpleFileSystems in the platform
593 Status
= gBS
->LocateHandle (
595 &gEfiSimpleFileSystemProtocolGuid
,
600 if (Status
== EFI_BUFFER_TOO_SMALL
) {
601 HandleBuffer
= AllocateZeroPool (BufferSize
);
602 if (HandleBuffer
== NULL
) {
603 return (SHELL_OUT_OF_RESOURCES
);
606 Status
= gBS
->LocateHandle (
608 &gEfiSimpleFileSystemProtocolGuid
,
616 // Get the map name(s) for each one.
618 for ( LoopVar
= 0, Found
= FALSE
619 ; LoopVar
< (BufferSize
/ sizeof (EFI_HANDLE
)) && HandleBuffer
!= NULL
623 Status
= PerformSingleMappingDisplay (
630 HandleBuffer
[LoopVar
]
632 if (!EFI_ERROR (Status
)) {
638 // Look up all BlockIo in the platform
640 Status
= gBS
->LocateHandle (
642 &gEfiBlockIoProtocolGuid
,
647 if (Status
== EFI_BUFFER_TOO_SMALL
) {
648 SHELL_FREE_NON_NULL (HandleBuffer
);
649 HandleBuffer
= AllocateZeroPool (BufferSize
);
650 if (HandleBuffer
== NULL
) {
651 return (SHELL_OUT_OF_RESOURCES
);
654 Status
= gBS
->LocateHandle (
656 &gEfiBlockIoProtocolGuid
,
663 if (!EFI_ERROR (Status
) && (HandleBuffer
!= NULL
)) {
665 // Get the map name(s) for each one.
668 ; LoopVar
< BufferSize
/ sizeof (EFI_HANDLE
)
673 // Skip any that were already done...
675 if (gBS
->OpenProtocol (
676 HandleBuffer
[LoopVar
],
677 &gEfiSimpleFileSystemProtocolGuid
,
681 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
687 Status
= PerformSingleMappingDisplay (
694 HandleBuffer
[LoopVar
]
696 if (!EFI_ERROR (Status
)) {
701 FreePool (HandleBuffer
);
705 if (Specific
!= NULL
) {
706 ShellPrintHiiEx (gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", Specific
);
708 ShellPrintHiiEx (gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
, L
"map");
712 return (SHELL_SUCCESS
);
716 Perform a mapping display and parse for multiple types in the TypeString.
718 @param[in] Verbose TRUE to use verbose output.
719 @param[in] Consist TRUE to display consistent names.
720 @param[in] Normal TRUE to display normal names.
721 @param[in] TypeString An optional comma-delimited list of types.
722 @param[in] SFO TRUE to display in SFO format. See Spec.
723 @param[in] Specific An optional specific map name to display alone.
725 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
726 @retval SHELL_SUCCESS The display was successful.
727 @sa PerformMappingDisplay
730 PerformMappingDisplay2 (
731 IN CONST BOOLEAN Verbose
,
732 IN CONST BOOLEAN Consist
,
733 IN CONST BOOLEAN Normal
,
734 IN CONST CHAR16
*TypeString
,
735 IN CONST BOOLEAN SFO
,
736 IN CONST CHAR16
*Specific OPTIONAL
739 CONST CHAR16
*TypeWalker
;
740 SHELL_STATUS ShellStatus
;
743 if (TypeString
== NULL
) {
744 return (PerformMappingDisplay (Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
747 ShellStatus
= SHELL_SUCCESS
;
748 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
749 Comma
= StrStr (TypeWalker
, L
",");
751 if (ShellStatus
== SHELL_SUCCESS
) {
752 ShellStatus
= PerformMappingDisplay (Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
754 PerformMappingDisplay (Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
760 if (ShellStatus
== SHELL_SUCCESS
) {
761 ShellStatus
= PerformMappingDisplay (Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
763 PerformMappingDisplay (Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
767 TypeWalker
= Comma
+ 1;
771 return (ShellStatus
);
775 Delete a specific map.
777 @param[in] Specific The pointer to the name of the map to delete.
779 @retval EFI_INVALID_PARAMETER Specific was NULL.
780 @retval EFI_SUCCESS The operation was successful.
781 @retval EFI_NOT_FOUND Specific could not be found.
784 PerformMappingDelete (
785 IN CONST CHAR16
*Specific
789 EFI_HANDLE
*HandleBuffer
;
794 if (Specific
== NULL
) {
795 return (EFI_INVALID_PARAMETER
);
803 // Look up all SimpleFileSystems in the platform
805 Status
= gBS
->LocateHandle (
807 &gEfiDevicePathProtocolGuid
,
812 if (Status
== EFI_BUFFER_TOO_SMALL
) {
813 HandleBuffer
= AllocateZeroPool (BufferSize
);
814 if (HandleBuffer
== NULL
) {
815 return (EFI_OUT_OF_RESOURCES
);
818 Status
= gBS
->LocateHandle (
820 &gEfiDevicePathProtocolGuid
,
827 if (EFI_ERROR (Status
)) {
828 SHELL_FREE_NON_NULL (HandleBuffer
);
832 if (HandleBuffer
!= NULL
) {
834 // Get the map name(s) for each one.
837 ; LoopVar
< BufferSize
/ sizeof (EFI_HANDLE
)
841 if (PerformSingleMappingDelete (Specific
, HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
848 // Look up all BlockIo in the platform
850 Status
= gBS
->LocateHandle (
852 &gEfiBlockIoProtocolGuid
,
857 if (Status
== EFI_BUFFER_TOO_SMALL
) {
858 FreePool (HandleBuffer
);
859 HandleBuffer
= AllocateZeroPool (BufferSize
);
860 if (HandleBuffer
== NULL
) {
861 return (EFI_OUT_OF_RESOURCES
);
864 Status
= gBS
->LocateHandle (
866 &gEfiBlockIoProtocolGuid
,
873 if (EFI_ERROR (Status
)) {
874 SHELL_FREE_NON_NULL (HandleBuffer
);
878 if (HandleBuffer
!= NULL
) {
880 // Get the map name(s) for each one.
883 ; LoopVar
< BufferSize
/ sizeof (EFI_HANDLE
)
888 // Skip any that were already done...
890 if (gBS
->OpenProtocol (
891 HandleBuffer
[LoopVar
],
892 &gEfiDevicePathProtocolGuid
,
896 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
902 if (PerformSingleMappingDelete (Specific
, HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
908 SHELL_FREE_NON_NULL (HandleBuffer
);
910 return (EFI_NOT_FOUND
);
913 return (EFI_SUCCESS
);
917 function to add a mapping from mapping.
919 This function will get the device path associated with the mapping and call SetMap.
921 @param[in] Map The Map to add a mapping for
922 @param[in] SName The name of the new mapping
924 @retval SHELL_SUCCESS the mapping was added
925 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
926 @return Shell version of a return value from EfiShellProtocol->SetMap
930 AddMappingFromMapping (
931 IN CONST CHAR16
*Map
,
932 IN CONST CHAR16
*SName
935 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
938 RETURN_STATUS StrRetStatus
;
940 NewSName
= AllocateCopyPool (StrSize (SName
) + sizeof (CHAR16
), SName
);
941 if (NewSName
== NULL
) {
942 return (SHELL_OUT_OF_RESOURCES
);
945 if (NewSName
[StrLen (NewSName
)-1] != L
':') {
946 StrRetStatus
= StrnCatS (NewSName
, (StrSize (SName
) + sizeof (CHAR16
))/sizeof (CHAR16
), L
":", StrLen (L
":"));
947 if (EFI_ERROR (StrRetStatus
)) {
949 return ((SHELL_STATUS
)(StrRetStatus
& (~MAX_BIT
)));
953 if (!IsNumberLetterOnly (NewSName
, StrLen (NewSName
)-1)) {
955 return (SHELL_INVALID_PARAMETER
);
958 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap (Map
);
959 if (DevPath
== NULL
) {
961 return (SHELL_INVALID_PARAMETER
);
964 Status
= gEfiShellProtocol
->SetMap (DevPath
, NewSName
);
966 if (EFI_ERROR (Status
)) {
967 return (SHELL_DEVICE_ERROR
);
970 return (SHELL_SUCCESS
);
974 function to add a mapping from an EFI_HANDLE.
976 This function will get the device path associated with the Handle and call SetMap.
978 @param[in] Handle The handle to add a mapping for
979 @param[in] SName The name of the new mapping
981 @retval SHELL_SUCCESS the mapping was added
982 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
983 @return Shell version of a return value from either
984 gBS->OpenProtocol or EfiShellProtocol->SetMap
988 AddMappingFromHandle (
989 IN CONST EFI_HANDLE Handle
,
990 IN CONST CHAR16
*SName
993 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
996 RETURN_STATUS StrRetStatus
;
998 NewSName
= AllocateCopyPool (StrSize (SName
) + sizeof (CHAR16
), SName
);
999 if (NewSName
== NULL
) {
1000 return (SHELL_OUT_OF_RESOURCES
);
1003 if (NewSName
[StrLen (NewSName
)-1] != L
':') {
1004 StrRetStatus
= StrnCatS (NewSName
, (StrSize (SName
) + sizeof (CHAR16
))/sizeof (CHAR16
), L
":", StrLen (L
":"));
1005 if (EFI_ERROR (StrRetStatus
)) {
1006 FreePool (NewSName
);
1007 return ((SHELL_STATUS
)(StrRetStatus
& (~MAX_BIT
)));
1011 if (!IsNumberLetterOnly (NewSName
, StrLen (NewSName
)-1)) {
1012 FreePool (NewSName
);
1013 return (SHELL_INVALID_PARAMETER
);
1016 Status
= gBS
->OpenProtocol (
1018 &gEfiDevicePathProtocolGuid
,
1022 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1024 if (EFI_ERROR (Status
)) {
1025 FreePool (NewSName
);
1026 return (SHELL_DEVICE_ERROR
);
1029 Status
= gEfiShellProtocol
->SetMap (DevPath
, NewSName
);
1030 FreePool (NewSName
);
1031 if (EFI_ERROR (Status
)) {
1032 return (SHELL_DEVICE_ERROR
);
1035 return (SHELL_SUCCESS
);
1038 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
1039 { L
"-d", TypeValue
},
1040 { L
"-r", TypeFlag
},
1041 { L
"-v", TypeFlag
},
1042 { L
"-c", TypeFlag
},
1043 { L
"-f", TypeFlag
},
1044 { L
"-u", TypeFlag
},
1045 { L
"-t", TypeValue
},
1046 { L
"-sfo", TypeValue
},
1051 The routine issues dummy read for every physical block device to cause
1052 the BlockIo re-installed if media change happened.
1055 ProbeForMediaChange (
1061 EFI_HANDLE
*Handles
;
1062 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
1065 gBS
->LocateHandleBuffer (
1067 &gEfiBlockIoProtocolGuid
,
1073 // Probe for media change for every physical block io
1075 for (Index
= 0; Index
< HandleCount
; Index
++) {
1076 Status
= gBS
->HandleProtocol (
1078 &gEfiBlockIoProtocolGuid
,
1081 if (!EFI_ERROR (Status
)) {
1082 if (!BlockIo
->Media
->LogicalPartition
) {
1085 // The function (ReadBlocks) must return EFI_NO_MEDIA or
1086 // EFI_MEDIA_CHANGED even if LBA, BufferSize, or Buffer are invalid so the caller can probe
1087 // for changes in media state.
1089 BlockIo
->ReadBlocks (
1091 BlockIo
->Media
->MediaId
,
1102 Function for 'map' command.
1104 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1105 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1109 ShellCommandRunMap (
1110 IN EFI_HANDLE ImageHandle
,
1111 IN EFI_SYSTEM_TABLE
*SystemTable
1115 LIST_ENTRY
*Package
;
1116 CHAR16
*ProblemParam
;
1117 CONST CHAR16
*SName
;
1118 CONST CHAR16
*Mapping
;
1119 EFI_HANDLE MapAsHandle
;
1120 SHELL_STATUS ShellStatus
;
1124 CONST CHAR16
*Param1
;
1125 CONST CHAR16
*TypeString
;
1126 UINTN TempStringLength
;
1128 ProblemParam
= NULL
;
1131 ShellStatus
= SHELL_SUCCESS
;
1135 // initialize the shell lib (we must be in non-auto-init...)
1137 Status
= ShellInitialize ();
1138 ASSERT_EFI_ERROR (Status
);
1140 Status
= CommandInit ();
1141 ASSERT_EFI_ERROR (Status
);
1144 // parse the command line
1146 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1147 if (EFI_ERROR (Status
)) {
1148 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
1149 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"map", ProblemParam
);
1150 FreePool (ProblemParam
);
1151 ShellStatus
= SHELL_INVALID_PARAMETER
;
1159 SfoMode
= ShellCommandLineGetFlag (Package
, L
"-sfo");
1160 ConstMode
= ShellCommandLineGetFlag (Package
, L
"-c");
1161 NormlMode
= ShellCommandLineGetFlag (Package
, L
"-f");
1162 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
1164 } else if (ShellCommandLineGetRawValue (Package
, 3) != NULL
) {
1165 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"map");
1166 ShellStatus
= SHELL_INVALID_PARAMETER
;
1169 // Deleting a map name...
1171 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
1172 if ( ShellCommandLineGetFlag (Package
, L
"-r")
1173 || ShellCommandLineGetFlag (Package
, L
"-v")
1176 || ShellCommandLineGetFlag (Package
, L
"-u")
1177 || ShellCommandLineGetFlag (Package
, L
"-t")
1180 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
, L
"map");
1181 ShellStatus
= SHELL_INVALID_PARAMETER
;
1183 SName
= ShellCommandLineGetValue (Package
, L
"-d");
1184 if (SName
!= NULL
) {
1185 Status
= PerformMappingDelete (SName
);
1186 if (EFI_ERROR (Status
)) {
1187 if (Status
== EFI_ACCESS_DENIED
) {
1188 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1189 ShellStatus
= SHELL_ACCESS_DENIED
;
1190 } else if (Status
== EFI_NOT_FOUND
) {
1191 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", SName
);
1192 ShellStatus
= SHELL_INVALID_PARAMETER
;
1194 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1195 ShellStatus
= SHELL_UNSUPPORTED
;
1199 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
1200 ShellStatus
= SHELL_INVALID_PARAMETER
;
1203 } else if ( ShellCommandLineGetFlag (Package
, L
"-r")
1204 // || ShellCommandLineGetFlag(Package, L"-v")
1207 || ShellCommandLineGetFlag (Package
, L
"-u")
1208 || ShellCommandLineGetFlag (Package
, L
"-t")
1211 ProbeForMediaChange ();
1212 if ( ShellCommandLineGetFlag (Package
, L
"-r")) {
1216 Status
= ShellCommandCreateInitialMappingsAndPaths ();
1217 if (EFI_ERROR (Status
)) {
1218 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1219 ShellStatus
= SHELL_UNSUPPORTED
;
1223 if ((ShellStatus
== SHELL_SUCCESS
) && ShellCommandLineGetFlag (Package
, L
"-u")) {
1227 Status
= ShellCommandUpdateMapping ();
1228 if (EFI_ERROR (Status
)) {
1229 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1230 ShellStatus
= SHELL_UNSUPPORTED
;
1234 if (ShellStatus
== SHELL_SUCCESS
) {
1235 Param1
= ShellCommandLineGetRawValue (Package
, 1);
1236 TypeString
= ShellCommandLineGetValue (Package
, L
"-t");
1239 && (TypeString
== NULL
)
1243 // now do the display...
1245 ShellStatus
= PerformMappingDisplay (
1246 ShellCommandLineGetFlag (Package
, L
"-v"),
1256 // now do the display...
1258 ShellStatus
= PerformMappingDisplay2 (
1259 ShellCommandLineGetFlag (Package
, L
"-v"),
1270 // adding or displaying (there were no flags)
1272 SName
= ShellCommandLineGetRawValue (Package
, 1);
1273 Mapping
= ShellCommandLineGetRawValue (Package
, 2);
1274 if ( (SName
== NULL
)
1275 && (Mapping
== NULL
)
1279 // display only since no flags
1281 ShellStatus
= PerformMappingDisplay (
1282 ShellCommandLineGetFlag (Package
, L
"-v"),
1290 } else if ( (SName
== NULL
)
1291 || (Mapping
== NULL
)
1295 // Display only the one specified
1297 ShellStatus
= PerformMappingDisplay (
1303 SName
, // note the variable here...
1307 if (ShellIsHexOrDecimalNumber (Mapping
, TRUE
, FALSE
)) {
1308 MapAsHandle
= ConvertHandleIndexToHandle (ShellStrToUintn (Mapping
));
1313 if ((MapAsHandle
== NULL
) && (Mapping
[StrLen (Mapping
)-1] != L
':')) {
1314 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1315 ShellStatus
= SHELL_INVALID_PARAMETER
;
1317 TempStringLength
= StrLen (SName
);
1318 if (!IsNumberLetterOnly (SName
, TempStringLength
-((SName
[TempStringLength
-1] == L
':') ? 1 : 0))) {
1319 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", SName
);
1320 ShellStatus
= SHELL_INVALID_PARAMETER
;
1323 if (ShellStatus
== SHELL_SUCCESS
) {
1324 if (MapAsHandle
!= NULL
) {
1325 ShellStatus
= AddMappingFromHandle (MapAsHandle
, SName
);
1327 ShellStatus
= AddMappingFromMapping (Mapping
, SName
);
1330 if (ShellStatus
!= SHELL_SUCCESS
) {
1331 switch (ShellStatus
) {
1332 case SHELL_ACCESS_DENIED
:
1333 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1335 case SHELL_INVALID_PARAMETER
:
1336 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1338 case SHELL_DEVICE_ERROR
:
1339 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1342 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", ShellStatus
|MAX_BIT
);
1346 // now do the display...
1348 ShellStatus
= PerformMappingDisplay (
1357 } // we were sucessful so do an output
1359 } // got a valid map target
1360 } // got 2 variables
1361 } // we are adding a mapping
1362 } // got valid parameters
1366 // free the command line package
1368 ShellCommandLineFreeVarList (Package
);
1370 return (ShellStatus
);