2 Main file for map shell level 2 command.
4 Copyright (c) 2009 - 2015, 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
;
227 // specific has priority
229 if (Specific
!= NULL
) {
230 NewSpecific
= AllocateCopyPool(StrSize(Specific
) + sizeof(CHAR16
), Specific
);
231 if (NewSpecific
== NULL
){
234 if (NewSpecific
[StrLen(NewSpecific
)-1] != L
':') {
235 Status
= StrnCatS(NewSpecific
, (StrSize(Specific
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
236 if (EFI_ERROR (Status
)) {
237 FreePool(NewSpecific
);
242 if (SearchList(MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
243 FreePool(NewSpecific
);
246 FreePool(NewSpecific
);
250 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
251 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
252 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
253 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
259 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
260 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
264 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
272 Display a single map line for device Handle if conditions are met.
274 @param[in] Verbose TRUE to display (extra) verbose information.
275 @param[in] Consist TRUE to display consistent mappings.
276 @param[in] Normal TRUE to display normal (not consist) mappings.
277 @param[in] TypeString pointer to string of filter types.
278 @param[in] SFO TRUE to display output in Standard Output Format.
279 @param[in] Specific pointer to string for specific map to display.
280 @param[in] Handle The handle to display from.
282 @retval EFI_SUCCESS The mapping was displayed.
285 PerformSingleMappingDisplay(
286 IN CONST BOOLEAN Verbose
,
287 IN CONST BOOLEAN Consist
,
288 IN CONST BOOLEAN Normal
,
289 IN CONST CHAR16
*TypeString
,
290 IN CONST BOOLEAN SFO
,
291 IN CONST CHAR16
*Specific OPTIONAL
,
292 IN CONST EFI_HANDLE Handle
295 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
296 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
297 CONST CHAR16
*MapList
;
300 CHAR16
*DevPathString
;
305 CONST CHAR16
*TempSpot2
;
310 DevPath
= DevicePathFromHandle(Handle
);
311 DevPathCopy
= DevPath
;
312 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
313 if (MapList
== NULL
) {
314 return EFI_NOT_FOUND
;
317 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
318 return EFI_NOT_FOUND
;
321 if (Normal
|| !Consist
) {
323 // need the Normal here since people can use both on command line. otherwise unused.
330 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
331 if (CurrentName
== NULL
) {
332 return (EFI_OUT_OF_RESOURCES
);
336 // Chop off the other names that become "Alias(s)"
337 // leaving just the normal name
339 TempSpot
= StrStr(CurrentName
, L
";");
340 if (TempSpot
!= NULL
) {
341 *TempSpot
= CHAR_NULL
;
347 // Skip the first name. This is the standard name.
349 TempSpot
= StrStr(MapList
, L
";");
350 if (TempSpot
!= NULL
) {
353 SearchList(TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
354 if (CurrentName
== NULL
) {
355 SearchList(TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
357 if (CurrentName
== NULL
) {
358 SearchList(TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
360 if (CurrentName
== NULL
) {
361 SearchList(TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
363 if (CurrentName
== NULL
) {
365 // We didnt find anything, so just the first one in the list...
367 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
368 if (CurrentName
== NULL
) {
369 return (EFI_OUT_OF_RESOURCES
);
371 TempSpot
= StrStr(CurrentName
, L
";");
372 if (TempSpot
!= NULL
) {
373 *TempSpot
= CHAR_NULL
;
376 Alias
= StrnCatGrow(&Alias
, 0, MapList
, 0);
378 return EFI_OUT_OF_RESOURCES
;
380 TempSpot
= StrStr(Alias
, CurrentName
);
381 if (TempSpot
!= NULL
) {
382 TempSpot2
= StrStr(TempSpot
, L
";");
383 if (TempSpot2
!= NULL
) {
384 TempSpot2
++; // Move past ";" from CurrentName
385 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
387 *TempSpot
= CHAR_NULL
;
390 if (Alias
[StrLen(Alias
)-1] == L
';') {
391 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
395 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
396 TempLen
= StrLen(CurrentName
);
402 STRING_TOKEN (STR_MAP_ENTRY
),
403 gShellLevel2HiiHandle
,
405 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
410 // also print handle, media type, removable (y/n), and current directory
412 MediaType
= GetDeviceMediaType(DevPath
);
413 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
414 Removable
= IsRemoveableDevice(DevPath
);
415 TempSpot2
= ShellGetCurrentDir(CurrentName
);
420 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
421 gShellLevel2HiiHandle
,
422 ConvertHandleToHandleIndex(Handle
),
424 Removable
?L
"Yes":L
"No",
428 SHELL_FREE_NON_NULL(MediaType
);
435 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
436 gShellLevel2HiiHandle
,
439 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
442 SHELL_FREE_NON_NULL(DevPathString
);
443 SHELL_FREE_NON_NULL(CurrentName
);
444 SHELL_FREE_NON_NULL(Alias
);
449 Delete Specific from the list of maps for device Handle.
451 @param[in] Specific The name to delete.
452 @param[in] Handle The device to look on.
454 @retval EFI_SUCCESS The delete was successful.
455 @retval EFI_NOT_FOUND Name was not a map on Handle.
458 PerformSingleMappingDelete(
459 IN CONST CHAR16
*Specific
,
460 IN CONST EFI_HANDLE Handle
463 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
464 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
465 CONST CHAR16
*MapList
;
468 DevPath
= DevicePathFromHandle(Handle
);
469 DevPathCopy
= DevPath
;
470 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
473 if (MapList
== NULL
) {
474 return (EFI_NOT_FOUND
);
477 // if there is a specific and its not on the list...
479 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
480 return (EFI_NOT_FOUND
);
482 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
485 CONST CHAR16 Cd
[] = L
"cd*";
486 CONST CHAR16 Hd
[] = L
"hd*";
487 CONST CHAR16 Fp
[] = L
"fp*";
488 CONST CHAR16 AnyF
[] = L
"F*";
490 Function to display mapping information to the user.
492 If Specific is specified then Consist and Normal will be ignored since information will
493 be printed for the specific item only.
495 @param[in] Verbose TRUE to display (extra) verbose information.
496 @param[in] Consist TRUE to display consistent mappings.
497 @param[in] Normal TRUE to display normal (not consist) mappings.
498 @param[in] TypeString Pointer to string of filter types.
499 @param[in] SFO TRUE to display output in Standard Output Format.
500 @param[in] Specific Pointer to string for specific map to display.
501 @param[in] Header TRUE to print the header block.
503 @retval SHELL_SUCCESS The display was printed.
504 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
508 PerformMappingDisplay(
509 IN CONST BOOLEAN Verbose
,
510 IN CONST BOOLEAN Consist
,
511 IN CONST BOOLEAN Normal
,
512 IN CONST CHAR16
*TypeString
,
513 IN CONST BOOLEAN SFO
,
514 IN CONST CHAR16
*Specific OPTIONAL
,
515 IN CONST BOOLEAN Header
519 EFI_HANDLE
*HandleBuffer
;
525 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
526 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
527 return (SHELL_INVALID_PARAMETER
);
530 if (TypeString
!= NULL
) {
532 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
534 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
536 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
537 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", TypeString
);
538 return (SHELL_INVALID_PARAMETER
);
540 } else if (Test
== NULL
) {
541 Test
= (CHAR16
*)AnyF
;
553 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
555 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
563 // Look up all SimpleFileSystems in the platform
565 Status
= gBS
->LocateHandle(
567 &gEfiSimpleFileSystemProtocolGuid
,
571 if (Status
== EFI_BUFFER_TOO_SMALL
) {
572 HandleBuffer
= AllocateZeroPool(BufferSize
);
573 if (HandleBuffer
== NULL
) {
574 return (SHELL_OUT_OF_RESOURCES
);
576 Status
= gBS
->LocateHandle(
578 &gEfiSimpleFileSystemProtocolGuid
,
585 // Get the map name(s) for each one.
587 for ( LoopVar
= 0, Found
= FALSE
588 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
591 Status
= PerformSingleMappingDisplay(
598 HandleBuffer
[LoopVar
]);
599 if (!EFI_ERROR(Status
)) {
605 // Look up all BlockIo in the platform
607 Status
= gBS
->LocateHandle(
609 &gEfiBlockIoProtocolGuid
,
613 if (Status
== EFI_BUFFER_TOO_SMALL
) {
614 SHELL_FREE_NON_NULL(HandleBuffer
);
615 HandleBuffer
= AllocateZeroPool(BufferSize
);
616 if (HandleBuffer
== NULL
) {
617 return (SHELL_OUT_OF_RESOURCES
);
619 Status
= gBS
->LocateHandle(
621 &gEfiBlockIoProtocolGuid
,
626 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
628 // Get the map name(s) for each one.
631 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
635 // Skip any that were already done...
637 if (gBS
->OpenProtocol(
638 HandleBuffer
[LoopVar
],
639 &gEfiSimpleFileSystemProtocolGuid
,
643 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
646 Status
= PerformSingleMappingDisplay(
653 HandleBuffer
[LoopVar
]);
654 if (!EFI_ERROR(Status
)) {
658 FreePool(HandleBuffer
);
661 if (Specific
!= NULL
) {
662 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", Specific
);
664 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
, L
"map");
667 return (SHELL_SUCCESS
);
671 Perform a mapping display and parse for multiple types in the TypeString.
673 @param[in] Verbose TRUE to use verbose output.
674 @param[in] Consist TRUE to display consistent names.
675 @param[in] Normal TRUE to display normal names.
676 @param[in] TypeString An optional comma-delimited list of types.
677 @param[in] SFO TRUE to display in SFO format. See Spec.
678 @param[in] Specific An optional specific map name to display alone.
680 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
681 @retval SHELL_SUCCESS The display was successful.
682 @sa PerformMappingDisplay
685 PerformMappingDisplay2(
686 IN CONST BOOLEAN Verbose
,
687 IN CONST BOOLEAN Consist
,
688 IN CONST BOOLEAN Normal
,
689 IN CONST CHAR16
*TypeString
,
690 IN CONST BOOLEAN SFO
,
691 IN CONST CHAR16
*Specific OPTIONAL
694 CONST CHAR16
*TypeWalker
;
695 SHELL_STATUS ShellStatus
;
699 if (TypeString
== NULL
) {
700 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
702 ShellStatus
= SHELL_SUCCESS
;
703 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
704 Comma
= StrStr(TypeWalker
, L
",");
706 if (ShellStatus
== SHELL_SUCCESS
) {
707 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
709 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
714 if (ShellStatus
== SHELL_SUCCESS
) {
715 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
717 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
720 TypeWalker
= Comma
+ 1;
724 return (ShellStatus
);
728 Delete a specific map.
730 @param[in] Specific The pointer to the name of the map to delete.
732 @retval EFI_INVALID_PARAMETER Specific was NULL.
733 @retval EFI_SUCCESS The operation was successful.
734 @retval EFI_NOT_FOUND Specific could not be found.
737 PerformMappingDelete(
738 IN CONST CHAR16
*Specific
742 EFI_HANDLE
*HandleBuffer
;
747 if (Specific
== NULL
) {
748 return (EFI_INVALID_PARAMETER
);
756 // Look up all SimpleFileSystems in the platform
758 Status
= gBS
->LocateHandle(
760 &gEfiDevicePathProtocolGuid
,
764 if (Status
== EFI_BUFFER_TOO_SMALL
) {
765 HandleBuffer
= AllocateZeroPool(BufferSize
);
766 if (HandleBuffer
== NULL
) {
767 return (EFI_OUT_OF_RESOURCES
);
769 Status
= gBS
->LocateHandle(
771 &gEfiDevicePathProtocolGuid
,
776 if (EFI_ERROR(Status
)) {
777 SHELL_FREE_NON_NULL(HandleBuffer
);
781 if (HandleBuffer
!= NULL
) {
783 // Get the map name(s) for each one.
786 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
789 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
795 // Look up all BlockIo in the platform
797 Status
= gBS
->LocateHandle(
799 &gEfiBlockIoProtocolGuid
,
803 if (Status
== EFI_BUFFER_TOO_SMALL
) {
804 FreePool(HandleBuffer
);
805 HandleBuffer
= AllocateZeroPool(BufferSize
);
806 if (HandleBuffer
== NULL
) {
807 return (EFI_OUT_OF_RESOURCES
);
809 Status
= gBS
->LocateHandle(
811 &gEfiBlockIoProtocolGuid
,
816 if (EFI_ERROR(Status
)) {
817 SHELL_FREE_NON_NULL(HandleBuffer
);
821 if (HandleBuffer
!= NULL
) {
823 // Get the map name(s) for each one.
826 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
830 // Skip any that were already done...
832 if (gBS
->OpenProtocol(
833 HandleBuffer
[LoopVar
],
834 &gEfiDevicePathProtocolGuid
,
838 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
841 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
846 SHELL_FREE_NON_NULL(HandleBuffer
);
848 return (EFI_NOT_FOUND
);
850 return (EFI_SUCCESS
);
854 function to add a mapping from mapping.
856 This function will get the device path associated with the mapping and call SetMap.
858 @param[in] Map The Map to add a mapping for
859 @param[in] SName The name of the new mapping
861 @retval SHELL_SUCCESS the mapping was added
862 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
863 @return Shell version of a return value from EfiShellProtocol->SetMap
867 AddMappingFromMapping(
868 IN CONST CHAR16
*Map
,
869 IN CONST CHAR16
*SName
872 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
875 RETURN_STATUS StrRetStatus
;
877 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
878 if (NewSName
== NULL
) {
879 return (SHELL_OUT_OF_RESOURCES
);
881 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
882 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
883 if (EFI_ERROR(StrRetStatus
)) {
885 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
889 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
891 return (SHELL_INVALID_PARAMETER
);
894 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
895 if (DevPath
== NULL
) {
897 return (SHELL_INVALID_PARAMETER
);
900 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
902 if (EFI_ERROR(Status
)) {
903 return (SHELL_DEVICE_ERROR
);
905 return (SHELL_SUCCESS
);
909 function to add a mapping from an EFI_HANDLE.
911 This function will get the device path associated with the Handle and call SetMap.
913 @param[in] Handle The handle to add a mapping for
914 @param[in] SName The name of the new mapping
916 @retval SHELL_SUCCESS the mapping was added
917 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
918 @return Shell version of a return value from either
919 gBS->OpenProtocol or EfiShellProtocol->SetMap
923 AddMappingFromHandle(
924 IN CONST EFI_HANDLE Handle
,
925 IN CONST CHAR16
*SName
928 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
931 RETURN_STATUS StrRetStatus
;
933 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
934 if (NewSName
== NULL
) {
935 return (SHELL_OUT_OF_RESOURCES
);
937 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
938 StrRetStatus
= StrnCatS(NewSName
, (StrSize(SName
) + sizeof(CHAR16
))/sizeof(CHAR16
), L
":", StrLen(L
":"));
939 if (EFI_ERROR(StrRetStatus
)) {
941 return ((SHELL_STATUS
) (StrRetStatus
& (~MAX_BIT
)));
945 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
947 return (SHELL_INVALID_PARAMETER
);
950 Status
= gBS
->OpenProtocol(
952 &gEfiDevicePathProtocolGuid
,
956 EFI_OPEN_PROTOCOL_GET_PROTOCOL
958 if (EFI_ERROR(Status
)) {
960 return (SHELL_DEVICE_ERROR
);
962 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
964 if (EFI_ERROR(Status
)) {
965 return (SHELL_DEVICE_ERROR
);
967 return (SHELL_SUCCESS
);
970 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
978 {L
"-sfo", TypeValue
},
983 Function for 'map' command.
985 @param[in] ImageHandle Handle to the Image (NULL if Internal).
986 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
991 IN EFI_HANDLE ImageHandle
,
992 IN EFI_SYSTEM_TABLE
*SystemTable
997 CHAR16
*ProblemParam
;
999 CONST CHAR16
*Mapping
;
1000 EFI_HANDLE MapAsHandle
;
1001 SHELL_STATUS ShellStatus
;
1005 CONST CHAR16
*Param1
;
1006 CONST CHAR16
*TypeString
;
1007 UINTN TempStringLength
;
1009 ProblemParam
= NULL
;
1012 ShellStatus
= SHELL_SUCCESS
;
1016 // initialize the shell lib (we must be in non-auto-init...)
1018 Status
= ShellInitialize();
1019 ASSERT_EFI_ERROR(Status
);
1021 Status
= CommandInit();
1022 ASSERT_EFI_ERROR(Status
);
1025 // parse the command line
1027 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1028 if (EFI_ERROR(Status
)) {
1029 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1030 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"map", ProblemParam
);
1031 FreePool(ProblemParam
);
1032 ShellStatus
= SHELL_INVALID_PARAMETER
;
1040 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1041 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1042 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1043 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1045 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1046 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"map");
1047 ShellStatus
= SHELL_INVALID_PARAMETER
;
1050 // Deleting a map name...
1052 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1053 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1054 || ShellCommandLineGetFlag(Package
, L
"-v")
1057 || ShellCommandLineGetFlag(Package
, L
"-u")
1058 || ShellCommandLineGetFlag(Package
, L
"-t")
1060 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
, L
"map");
1061 ShellStatus
= SHELL_INVALID_PARAMETER
;
1063 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1064 if (SName
!= NULL
) {
1065 Status
= PerformMappingDelete(SName
);
1066 if (EFI_ERROR(Status
)) {
1067 if (Status
== EFI_ACCESS_DENIED
) {
1068 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1069 ShellStatus
= SHELL_ACCESS_DENIED
;
1070 } else if (Status
== EFI_NOT_FOUND
) {
1071 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, L
"map", SName
);
1072 ShellStatus
= SHELL_INVALID_PARAMETER
;
1074 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1075 ShellStatus
= SHELL_UNSUPPORTED
;
1079 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"map");
1080 ShellStatus
= SHELL_INVALID_PARAMETER
;
1083 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1084 // || ShellCommandLineGetFlag(Package, L"-v")
1087 || ShellCommandLineGetFlag(Package
, L
"-u")
1088 || ShellCommandLineGetFlag(Package
, L
"-t")
1090 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1094 Status
= ShellCommandCreateInitialMappingsAndPaths();
1095 if (EFI_ERROR(Status
)) {
1096 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", Status
);
1097 ShellStatus
= SHELL_UNSUPPORTED
;
1100 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1104 Status
= ShellCommandUpdateMapping ();
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
) {
1111 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1112 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1115 &&TypeString
== NULL
1118 // now do the display...
1120 ShellStatus
= PerformMappingDisplay(
1121 ShellCommandLineGetFlag(Package
, L
"-v"),
1131 // now do the display...
1133 ShellStatus
= PerformMappingDisplay2(
1134 ShellCommandLineGetFlag(Package
, L
"-v"),
1145 // adding or displaying (there were no flags)
1147 SName
= ShellCommandLineGetRawValue(Package
, 1);
1148 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1153 // display only since no flags
1155 ShellStatus
= PerformMappingDisplay(
1156 ShellCommandLineGetFlag(Package
, L
"-v"),
1164 } else if ( SName
== NULL
1168 // Display only the one specified
1170 ShellStatus
= PerformMappingDisplay(
1176 SName
, // note the variable here...
1180 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1181 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1185 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1186 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1187 ShellStatus
= SHELL_INVALID_PARAMETER
;
1189 TempStringLength
= StrLen(SName
);
1190 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1191 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", SName
);
1192 ShellStatus
= SHELL_INVALID_PARAMETER
;
1195 if (ShellStatus
== SHELL_SUCCESS
) {
1196 if (MapAsHandle
!= NULL
) {
1197 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1199 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1202 if (ShellStatus
!= SHELL_SUCCESS
) {
1203 switch (ShellStatus
) {
1204 case SHELL_ACCESS_DENIED
:
1205 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
, L
"map");
1207 case SHELL_INVALID_PARAMETER
:
1208 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1210 case SHELL_DEVICE_ERROR
:
1211 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, L
"map", Mapping
);
1214 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"map", ShellStatus
|MAX_BIT
);
1218 // now do the display...
1220 ShellStatus
= PerformMappingDisplay(
1229 } // we were sucessful so do an output
1231 } // got a valid map target
1232 } // got 2 variables
1233 } // we are adding a mapping
1234 } // got valid parameters
1238 // free the command line package
1240 ShellCommandLineFreeVarList (Package
);
1242 return (ShellStatus
);