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 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "UefiShellLevel2CommandsLib.h"
19 #include <Protocol/SimpleFileSystem.h>
20 #include <Protocol/BlockIo.h>
21 #include <Library/DevicePathLib.h>
22 #include <Library/HandleParsingLib.h>
23 #include <Library/SortLib.h>
26 Determine if a string has only numbers and letters.
28 This is useful for such things as Map names which can only be letters and numbers.
30 @param[in] String pointer to the string to analyze,
31 @param[in] Len Number of characters to analyze.
33 @retval TRUE String has only numbers and letters
34 @retval FALSE String has at least one other character.
38 IN CONST CHAR16
*String
,
43 for (Count
= 0 ; Count
< Len
&& String
!= NULL
&& *String
!= CHAR_NULL
; String
++,Count
++) {
44 if (! ((*String
>= L
'a' && *String
<= L
'z') ||
45 (*String
>= L
'A' && *String
<= L
'Z') ||
46 (*String
>= L
'0' && *String
<= L
'9'))
55 Do a search in the Target delimited list.
57 @param[in] List The list to seatch in.
58 @param[in] MetaTarget The item to search for. MetaMatching supported.
59 @param[out] FullName Optional pointer to an allocated buffer containing
61 @param[in] Meta TRUE to use MetaMatching.
62 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.
63 @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.
135 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
138 ACPI_HID_DEVICE_PATH
*Acpi
;
141 // Parse the device path:
142 // Devicepath sub type mediatype
143 // MEDIA_HANRDDRIVE_DP -> Hard Disk
144 // MEDIA_CDROM_DP -> CD Rom
145 // Acpi.HID = 0X0604 -> Floppy
147 if (NULL
== DevicePath
) {
148 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
151 for (;!IsDevicePathEndType (DevicePath
) ;DevicePath
= NextDevicePathNode (DevicePath
)) {
152 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
153 switch (DevicePathSubType (DevicePath
)) {
154 case MEDIA_HARDDRIVE_DP
:
155 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK
), NULL
);
157 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_CDROM
), NULL
);
159 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
160 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePath
;
161 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
162 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY
), NULL
);
167 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
171 Function to detemine if a handle has removable storage.
173 @param[in] DevicePath DevicePath to test.
175 @retval TRUE The handle has removable storage.
176 @retval FALSE The handle does not have removable storage.
180 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
183 if (NULL
== DevicePath
) {
187 while (!IsDevicePathEndType (DevicePath
)) {
188 if (DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) {
189 switch (DevicePathSubType (DevicePath
)) {
197 DevicePath
= NextDevicePathNode (DevicePath
);
203 Function to detemine if a something on the map list matches.
205 @param[in] MapList The pointer to the list to test.
206 @param[in] Specific The pointer to a specific name to test for.
207 @param[in] TypeString The pointer to the list of types.
208 @param[in] Normal Always show normal mappings.
209 @param[in] Consist Always show consistent mappings.
211 @retval TRUE The map should be displayed.
212 @retval FALSE The map should not be displayed.
216 IN CONST CHAR16
*MapList
,
217 IN CONST CHAR16
*Specific
,
218 IN CONST CHAR16
*TypeString
,
219 IN CONST BOOLEAN Normal
,
220 IN CONST BOOLEAN Consist
224 RETURN_STATUS Status
;
228 // specific has priority
230 if (Specific
!= NULL
) {
231 Length
= StrLen (Specific
);
233 // Allocate enough buffer for Specific and potential ":"
235 NewSpecific
= AllocatePool ((Length
+ 2) * sizeof(CHAR16
));
236 if (NewSpecific
== NULL
){
239 StrCpyS (NewSpecific
, Length
+ 2, Specific
);
240 if (Specific
[Length
- 1] != L
':') {
241 Status
= StrnCatS(NewSpecific
, Length
+ 2, L
":", StrLen(L
":"));
242 if (EFI_ERROR (Status
)) {
243 FreePool(NewSpecific
);
248 if (SearchList(MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
249 FreePool(NewSpecific
);
252 FreePool(NewSpecific
);
256 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
257 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
258 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
259 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
265 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
266 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
270 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
278 Display a single map line for device Handle if conditions are met.
280 @param[in] Verbose TRUE to display (extra) verbose information.
281 @param[in] Consist TRUE to display consistent mappings.
282 @param[in] Normal TRUE to display normal (not consist) mappings.
283 @param[in] TypeString pointer to string of filter types.
284 @param[in] SFO TRUE to display output in Standard Output Format.
285 @param[in] Specific pointer to string for specific map to display.
286 @param[in] Handle The handle to display from.
288 @retval EFI_SUCCESS The mapping was displayed.
291 PerformSingleMappingDisplay(
292 IN CONST BOOLEAN Verbose
,
293 IN CONST BOOLEAN Consist
,
294 IN CONST BOOLEAN Normal
,
295 IN CONST CHAR16
*TypeString
,
296 IN CONST BOOLEAN SFO
,
297 IN CONST CHAR16
*Specific OPTIONAL
,
298 IN CONST EFI_HANDLE Handle
301 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
302 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
303 CONST CHAR16
*MapList
;
306 CHAR16
*DevPathString
;
311 CONST CHAR16
*TempSpot2
;
316 DevPath
= DevicePathFromHandle(Handle
);
317 DevPathCopy
= DevPath
;
318 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
319 if (MapList
== NULL
) {
320 return EFI_NOT_FOUND
;
323 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
324 return EFI_NOT_FOUND
;
327 if (Normal
|| !Consist
) {
329 // need the Normal here since people can use both on command line. otherwise unused.
336 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
337 if (CurrentName
== NULL
) {
338 return (EFI_OUT_OF_RESOURCES
);
342 // Chop off the other names that become "Alias(s)"
343 // leaving just the normal name
345 TempSpot
= StrStr(CurrentName
, L
";");
346 if (TempSpot
!= NULL
) {
347 *TempSpot
= CHAR_NULL
;
353 // Skip the first name. This is the standard name.
355 TempSpot
= StrStr(MapList
, L
";");
356 if (TempSpot
!= NULL
) {
359 SearchList(TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
360 if (CurrentName
== NULL
) {
361 SearchList(TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
363 if (CurrentName
== NULL
) {
364 SearchList(TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
366 if (CurrentName
== NULL
) {
367 SearchList(TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
369 if (CurrentName
== NULL
) {
371 // We didnt find anything, so just the first one in the list...
373 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
374 if (CurrentName
== NULL
) {
375 return (EFI_OUT_OF_RESOURCES
);
377 TempSpot
= StrStr(CurrentName
, L
";");
378 if (TempSpot
!= NULL
) {
379 *TempSpot
= CHAR_NULL
;
382 Alias
= StrnCatGrow(&Alias
, 0, MapList
, 0);
384 return EFI_OUT_OF_RESOURCES
;
386 TempSpot
= StrStr(Alias
, CurrentName
);
387 if (TempSpot
!= NULL
) {
388 TempSpot2
= StrStr(TempSpot
, L
";");
389 if (TempSpot2
!= NULL
) {
390 TempSpot2
++; // Move past ";" from CurrentName
391 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
393 *TempSpot
= CHAR_NULL
;
396 if (Alias
[StrLen(Alias
)-1] == L
';') {
397 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
401 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
402 TempLen
= StrLen(CurrentName
);
408 STRING_TOKEN (STR_MAP_ENTRY
),
409 gShellLevel2HiiHandle
,
411 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
416 // also print handle, media type, removable (y/n), and current directory
418 MediaType
= GetDeviceMediaType(DevPath
);
419 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
420 Removable
= IsRemoveableDevice(DevPath
);
421 TempSpot2
= ShellGetCurrentDir(CurrentName
);
426 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
427 gShellLevel2HiiHandle
,
428 ConvertHandleToHandleIndex(Handle
),
430 Removable
?L
"Yes":L
"No",
434 SHELL_FREE_NON_NULL(MediaType
);
441 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
442 gShellLevel2HiiHandle
,
445 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
448 SHELL_FREE_NON_NULL(DevPathString
);
449 SHELL_FREE_NON_NULL(CurrentName
);
450 SHELL_FREE_NON_NULL(Alias
);
455 Delete Specific from the list of maps for device Handle.
457 @param[in] Specific The name to delete.
458 @param[in] Handle The device to look on.
460 @retval EFI_SUCCESS The delete was successful.
461 @retval EFI_NOT_FOUND Name was not a map on Handle.
464 PerformSingleMappingDelete(
465 IN CONST CHAR16
*Specific
,
466 IN CONST EFI_HANDLE Handle
469 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
470 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
471 CONST CHAR16
*MapList
;
474 DevPath
= DevicePathFromHandle(Handle
);
475 DevPathCopy
= DevPath
;
476 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
479 if (MapList
== NULL
) {
480 return (EFI_NOT_FOUND
);
483 // if there is a specific and its not on the list...
485 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
486 return (EFI_NOT_FOUND
);
488 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
491 CONST CHAR16 Cd
[] = L
"cd*";
492 CONST CHAR16 Hd
[] = L
"hd*";
493 CONST CHAR16 Fp
[] = L
"fp*";
494 CONST CHAR16 AnyF
[] = L
"F*";
496 Function to display mapping information to the user.
498 If Specific is specified then Consist and Normal will be ignored since information will
499 be printed for the specific item only.
501 @param[in] Verbose TRUE to display (extra) verbose information.
502 @param[in] Consist TRUE to display consistent mappings.
503 @param[in] Normal TRUE to display normal (not consist) mappings.
504 @param[in] TypeString Pointer to string of filter types.
505 @param[in] SFO TRUE to display output in Standard Output Format.
506 @param[in] Specific Pointer to string for specific map to display.
507 @param[in] Header TRUE to print the header block.
509 @retval SHELL_SUCCESS The display was printed.
510 @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
691 PerformMappingDisplay2(
692 IN CONST BOOLEAN Verbose
,
693 IN CONST BOOLEAN Consist
,
694 IN CONST BOOLEAN Normal
,
695 IN CONST CHAR16
*TypeString
,
696 IN CONST BOOLEAN SFO
,
697 IN CONST CHAR16
*Specific OPTIONAL
700 CONST CHAR16
*TypeWalker
;
701 SHELL_STATUS ShellStatus
;
705 if (TypeString
== NULL
) {
706 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
708 ShellStatus
= SHELL_SUCCESS
;
709 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
710 Comma
= StrStr(TypeWalker
, L
",");
712 if (ShellStatus
== SHELL_SUCCESS
) {
713 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
715 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
720 if (ShellStatus
== SHELL_SUCCESS
) {
721 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
723 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
726 TypeWalker
= Comma
+ 1;
730 return (ShellStatus
);
734 Delete a specific map.
736 @param[in] Specific The pointer to the name of the map to delete.
738 @retval EFI_INVALID_PARAMETER Specific was NULL.
739 @retval EFI_SUCCESS The operation was successful.
740 @retval EFI_NOT_FOUND Specific could not be found.
743 PerformMappingDelete(
744 IN CONST CHAR16
*Specific
748 EFI_HANDLE
*HandleBuffer
;
753 if (Specific
== NULL
) {
754 return (EFI_INVALID_PARAMETER
);
762 // Look up all SimpleFileSystems in the platform
764 Status
= gBS
->LocateHandle(
766 &gEfiDevicePathProtocolGuid
,
770 if (Status
== EFI_BUFFER_TOO_SMALL
) {
771 HandleBuffer
= AllocateZeroPool(BufferSize
);
772 if (HandleBuffer
== NULL
) {
773 return (EFI_OUT_OF_RESOURCES
);
775 Status
= gBS
->LocateHandle(
777 &gEfiDevicePathProtocolGuid
,
782 if (EFI_ERROR(Status
)) {
783 SHELL_FREE_NON_NULL(HandleBuffer
);
787 if (HandleBuffer
!= NULL
) {
789 // Get the map name(s) for each one.
792 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
795 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
801 // Look up all BlockIo in the platform
803 Status
= gBS
->LocateHandle(
805 &gEfiBlockIoProtocolGuid
,
809 if (Status
== EFI_BUFFER_TOO_SMALL
) {
810 FreePool(HandleBuffer
);
811 HandleBuffer
= AllocateZeroPool(BufferSize
);
812 if (HandleBuffer
== NULL
) {
813 return (EFI_OUT_OF_RESOURCES
);
815 Status
= gBS
->LocateHandle(
817 &gEfiBlockIoProtocolGuid
,
822 if (EFI_ERROR(Status
)) {
823 SHELL_FREE_NON_NULL(HandleBuffer
);
827 if (HandleBuffer
!= NULL
) {
829 // Get the map name(s) for each one.
832 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
836 // Skip any that were already done...
838 if (gBS
->OpenProtocol(
839 HandleBuffer
[LoopVar
],
840 &gEfiDevicePathProtocolGuid
,
844 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
847 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
852 SHELL_FREE_NON_NULL(HandleBuffer
);
854 return (EFI_NOT_FOUND
);
856 return (EFI_SUCCESS
);
860 function to add a mapping from mapping.
862 This function will get the device path associated with the mapping and call SetMap.
864 @param[in] Map The Map to add a mapping for
865 @param[in] SName The name of the new mapping
867 @retval SHELL_SUCCESS the mapping was added
868 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
869 @return Shell version of a return value from EfiShellProtocol->SetMap
873 AddMappingFromMapping(
874 IN CONST CHAR16
*Map
,
875 IN CONST CHAR16
*SName
878 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
881 RETURN_STATUS StrRetStatus
;
883 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
884 if (NewSName
== NULL
) {
885 return (SHELL_OUT_OF_RESOURCES
);
887 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
888 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
889 if (EFI_ERROR(StrRetStatus
)) {
891 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
895 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
897 return (SHELL_INVALID_PARAMETER
);
900 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
901 if (DevPath
== NULL
) {
903 return (SHELL_INVALID_PARAMETER
);
906 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
908 if (EFI_ERROR(Status
)) {
909 return (SHELL_DEVICE_ERROR
);
911 return (SHELL_SUCCESS
);
915 function to add a mapping from an EFI_HANDLE.
917 This function will get the device path associated with the Handle and call SetMap.
919 @param[in] Handle The handle to add a mapping for
920 @param[in] SName The name of the new mapping
922 @retval SHELL_SUCCESS the mapping was added
923 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
924 @return Shell version of a return value from either
925 gBS->OpenProtocol or EfiShellProtocol->SetMap
929 AddMappingFromHandle(
930 IN CONST EFI_HANDLE Handle
,
931 IN CONST CHAR16
*SName
934 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
937 RETURN_STATUS StrRetStatus
;
939 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
940 if (NewSName
== NULL
) {
941 return (SHELL_OUT_OF_RESOURCES
);
943 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
944 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
945 if (EFI_ERROR(StrRetStatus
)) {
947 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
951 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
953 return (SHELL_INVALID_PARAMETER
);
956 Status
= gBS
->OpenProtocol(
958 &gEfiDevicePathProtocolGuid
,
962 EFI_OPEN_PROTOCOL_GET_PROTOCOL
964 if (EFI_ERROR(Status
)) {
966 return (SHELL_DEVICE_ERROR
);
968 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
970 if (EFI_ERROR(Status
)) {
971 return (SHELL_DEVICE_ERROR
);
973 return (SHELL_SUCCESS
);
976 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
984 {L
"-sfo", TypeValue
},
989 The routine issues dummy read for every physical block device to cause
990 the BlockIo re-installed if media change happened.
993 ProbeForMediaChange (
1000 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
1003 gBS
->LocateHandleBuffer (
1005 &gEfiBlockIoProtocolGuid
,
1011 // Probe for media change for every physical block io
1013 for (Index
= 0; Index
< HandleCount
; Index
++) {
1014 Status
= gBS
->HandleProtocol (
1016 &gEfiBlockIoProtocolGuid
,
1019 if (!EFI_ERROR (Status
)) {
1020 if (!BlockIo
->Media
->LogicalPartition
) {
1023 // The function (ReadBlocks) must return EFI_NO_MEDIA or
1024 // EFI_MEDIA_CHANGED even if LBA, BufferSize, or Buffer are invalid so the caller can probe
1025 // for changes in media state.
1027 BlockIo
->ReadBlocks (
1029 BlockIo
->Media
->MediaId
,
1040 Function for 'map' command.
1042 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1043 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1047 ShellCommandRunMap (
1048 IN EFI_HANDLE ImageHandle
,
1049 IN EFI_SYSTEM_TABLE
*SystemTable
1053 LIST_ENTRY
*Package
;
1054 CHAR16
*ProblemParam
;
1055 CONST CHAR16
*SName
;
1056 CONST CHAR16
*Mapping
;
1057 EFI_HANDLE MapAsHandle
;
1058 SHELL_STATUS ShellStatus
;
1062 CONST CHAR16
*Param1
;
1063 CONST CHAR16
*TypeString
;
1064 UINTN TempStringLength
;
1066 ProblemParam
= NULL
;
1069 ShellStatus
= SHELL_SUCCESS
;
1073 // initialize the shell lib (we must be in non-auto-init...)
1075 Status
= ShellInitialize();
1076 ASSERT_EFI_ERROR(Status
);
1078 Status
= CommandInit();
1079 ASSERT_EFI_ERROR(Status
);
1082 // parse the command line
1084 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1085 if (EFI_ERROR(Status
)) {
1086 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1087 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"map", ProblemParam
);
1088 FreePool(ProblemParam
);
1089 ShellStatus
= SHELL_INVALID_PARAMETER
;
1097 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1098 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1099 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1100 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1102 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1103 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"map");
1104 ShellStatus
= SHELL_INVALID_PARAMETER
;
1107 // Deleting a map name...
1109 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1110 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1111 || ShellCommandLineGetFlag(Package
, L
"-v")
1114 || ShellCommandLineGetFlag(Package
, L
"-u")
1115 || ShellCommandLineGetFlag(Package
, L
"-t")
1117 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
, L
"map");
1118 ShellStatus
= SHELL_INVALID_PARAMETER
;
1120 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1121 if (SName
!= NULL
) {
1122 Status
= PerformMappingDelete(SName
);
1123 if (EFI_ERROR(Status
)) {
1124 if (Status
== EFI_ACCESS_DENIED
) {
1125 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1126 ShellStatus
= SHELL_ACCESS_DENIED
;
1127 } else if (Status
== EFI_NOT_FOUND
) {
1128 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", SName
);
1129 ShellStatus
= SHELL_INVALID_PARAMETER
;
1131 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1132 ShellStatus
= SHELL_UNSUPPORTED
;
1136 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
1137 ShellStatus
= SHELL_INVALID_PARAMETER
;
1140 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1141 // || ShellCommandLineGetFlag(Package, L"-v")
1144 || ShellCommandLineGetFlag(Package
, L
"-u")
1145 || ShellCommandLineGetFlag(Package
, L
"-t")
1147 ProbeForMediaChange ();
1148 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1152 Status
= ShellCommandCreateInitialMappingsAndPaths();
1153 if (EFI_ERROR(Status
)) {
1154 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1155 ShellStatus
= SHELL_UNSUPPORTED
;
1158 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1162 Status
= ShellCommandUpdateMapping ();
1163 if (EFI_ERROR(Status
)) {
1164 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1165 ShellStatus
= SHELL_UNSUPPORTED
;
1168 if (ShellStatus
== SHELL_SUCCESS
) {
1169 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1170 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1173 &&TypeString
== NULL
1176 // now do the display...
1178 ShellStatus
= PerformMappingDisplay(
1179 ShellCommandLineGetFlag(Package
, L
"-v"),
1189 // now do the display...
1191 ShellStatus
= PerformMappingDisplay2(
1192 ShellCommandLineGetFlag(Package
, L
"-v"),
1203 // adding or displaying (there were no flags)
1205 SName
= ShellCommandLineGetRawValue(Package
, 1);
1206 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1211 // display only since no flags
1213 ShellStatus
= PerformMappingDisplay(
1214 ShellCommandLineGetFlag(Package
, L
"-v"),
1222 } else if ( SName
== NULL
1226 // Display only the one specified
1228 ShellStatus
= PerformMappingDisplay(
1234 SName
, // note the variable here...
1238 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1239 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1243 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1244 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1245 ShellStatus
= SHELL_INVALID_PARAMETER
;
1247 TempStringLength
= StrLen(SName
);
1248 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1249 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", SName
);
1250 ShellStatus
= SHELL_INVALID_PARAMETER
;
1253 if (ShellStatus
== SHELL_SUCCESS
) {
1254 if (MapAsHandle
!= NULL
) {
1255 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1257 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1260 if (ShellStatus
!= SHELL_SUCCESS
) {
1261 switch (ShellStatus
) {
1262 case SHELL_ACCESS_DENIED
:
1263 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1265 case SHELL_INVALID_PARAMETER
:
1266 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1268 case SHELL_DEVICE_ERROR
:
1269 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1272 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", ShellStatus
|MAX_BIT
);
1276 // now do the display...
1278 ShellStatus
= PerformMappingDisplay(
1287 } // we were sucessful so do an output
1289 } // got a valid map target
1290 } // got 2 variables
1291 } // we are adding a mapping
1292 } // got valid parameters
1296 // free the command line package
1298 ShellCommandLineFreeVarList (Package
);
1300 return (ShellStatus
);