2 Main file for map shell level 2 command.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel2CommandsLib.h"
16 #include <Protocol/SimpleFileSystem.h>
17 #include <Protocol/BlockIo.h>
18 #include <Library/DevicePathLib.h>
19 #include <Library/HandleParsingLib.h>
20 #include <Library/SortLib.h>
23 Determine if a string has only numbers and letters.
25 This is useful for such things as Map names which can only be letters and numbers.
27 @param[in] String pointer to the string to analyze,
28 @param[in] Len Number of characters to analyze.
30 @retval TRUE String has only numbers and letters
31 @retval FALSE String has at least one other character.
36 IN CONST CHAR16
*String
,
41 for (Count
= 0 ; Count
< Len
&& String
!= NULL
&& *String
!= CHAR_NULL
; String
++,Count
++) {
42 if (! ((*String
>= L
'a' && *String
<= L
'z') ||
43 (*String
>= L
'A' && *String
<= L
'Z') ||
44 (*String
>= L
'0' && *String
<= L
'9'))
53 Do a search in the Target delimited list.
55 @param[in] List The list to seatch in.
56 @param[in] MetaTarget The item to search for. MetaMatching supported.
57 @param[out] FullName Optional pointer to an allocated buffer containing
59 @param[in] Meta TRUE to use MetaMatching.
60 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.
61 @param[in] Target The single character that delimits list
67 IN CONST CHAR16
*List
,
68 IN CONST CHAR16
*MetaTarget
,
69 OUT CHAR16
**FullName OPTIONAL
,
70 IN CONST BOOLEAN Meta
,
71 IN CONST BOOLEAN SkipTrailingNumbers
,
72 IN CONST CHAR16
*Target
77 CONST CHAR16
*ListWalker
;
81 for (ListWalker
= List
, TempList
= NULL
82 ; ListWalker
!= NULL
&& *ListWalker
!= CHAR_NULL
85 TempList
= StrnCatGrow(&TempList
, NULL
, ListWalker
, 0);
86 ASSERT(TempList
!= NULL
);
87 TempSpot
= StrStr(TempList
, Target
);
88 if (TempSpot
!= NULL
) {
89 *TempSpot
= CHAR_NULL
;
92 while (SkipTrailingNumbers
&& (ShellIsDecimalDigitCharacter(TempList
[StrLen(TempList
)-1]) || TempList
[StrLen(TempList
)-1] == L
':')) {
93 TempList
[StrLen(TempList
)-1] = CHAR_NULL
;
96 ListWalker
= StrStr(ListWalker
, Target
);
97 while(ListWalker
!= NULL
&& *ListWalker
== *Target
) {
101 Result
= gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, (CHAR16
*)TempList
, (CHAR16
*)MetaTarget
);
103 Result
= (BOOLEAN
)(StrCmp(TempList
, MetaTarget
)==0);
106 if (FullName
!= NULL
) {
107 *FullName
= TempList
;
121 Add mappings for any devices without one. Do not change any existing maps.
123 @retval EFI_SUCCESS The operation was successful.
132 EFI_HANDLE
*HandleList
;
134 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
135 CHAR16
*NewDefaultName
;
136 CHAR16
*NewConsistName
;
137 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
140 Status
= EFI_SUCCESS
;
143 // remove mappings that represent removed devices.
147 // Find each handle with Simple File System
149 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
150 if (HandleList
!= NULL
) {
152 // Do a count of the handles
154 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
157 // Get all Device Paths
159 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
160 ASSERT(DevicePathList
!= NULL
);
162 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
163 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
167 // Sort all DevicePaths
169 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
171 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
174 // Assign new Mappings to remainders
176 for (Count
= 0 ; HandleList
[Count
] != NULL
&& !EFI_ERROR(Status
); Count
++) {
178 // Skip ones that already have
180 if (gEfiShellProtocol
->GetMapFromDevicePath(&DevicePathList
[Count
]) != NULL
) {
186 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
187 ASSERT(NewDefaultName
!= NULL
);
190 // Call shell protocol SetMap function now...
192 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewDefaultName
);
194 if (!EFI_ERROR(Status
)) {
196 // Now do consistent name
198 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
199 if (NewConsistName
!= NULL
) {
200 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewConsistName
);
201 FreePool(NewConsistName
);
205 FreePool(NewDefaultName
);
207 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
208 SHELL_FREE_NON_NULL(HandleList
);
209 SHELL_FREE_NON_NULL(DevicePathList
);
216 // Do it all over again for gEfiBlockIoProtocolGuid
223 Determine what type of device is represented and return it's string. The
224 string is in allocated memory and must be callee freed. The HII is is listed below.
225 The actual string cannot be determined.
227 @param[in] DevicePath The device to analyze.
229 @retval STR_MAP_MEDIA_UNKNOWN The media type is unknown.
230 @retval STR_MAP_MEDIA_HARDDISK The media is a hard drive.
231 @retval STR_MAP_MEDIA_CDROM The media is a CD ROM.
232 @retval STR_MAP_MEDIA_FLOPPY The media is a floppy drive.
237 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
240 ACPI_HID_DEVICE_PATH
*Acpi
;
243 // Parse the device path:
244 // Devicepath sub type mediatype
245 // MEDIA_HANRDDRIVE_DP -> Hard Disk
246 // MEDIA_CDROM_DP -> CD Rom
247 // Acpi.HID = 0X0604 -> Floppy
249 if (NULL
== DevicePath
) {
250 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
253 for (;!IsDevicePathEndType (DevicePath
) ;DevicePath
= NextDevicePathNode (DevicePath
)) {
254 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
255 switch (DevicePathSubType (DevicePath
)) {
256 case MEDIA_HARDDRIVE_DP
:
257 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK
), NULL
);
259 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_CDROM
), NULL
);
261 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
262 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePath
;
263 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
264 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY
), NULL
);
269 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
273 Function to detemine if a handle has removable storage.
275 @param[in] DevicePath DevicePath to test.
277 @retval TRUE The handle has removable storage.
278 @retval FALSE The handle does not have removable storage.
283 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
286 if (NULL
== DevicePath
) {
290 while (!IsDevicePathEndType (DevicePath
)) {
291 if (DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) {
292 switch (DevicePathSubType (DevicePath
)) {
300 DevicePath
= NextDevicePathNode (DevicePath
);
306 Function to detemine if a something on the map list matches.
308 @param[in] MapList The pointer to the list to test.
309 @param[in] Specific The pointer to a specific name to test for.
310 @param[in] TypeString The pointer to the list of types.
311 @param[in] Normal Always show normal mappings.
312 @param[in] Consist Always show consistent mappings.
314 @retval TRUE The map should be displayed.
315 @retval FALSE The map should not be displayed.
320 IN CONST CHAR16
*MapList
,
321 IN CONST CHAR16
*Specific
,
322 IN CONST CHAR16
*TypeString
,
323 IN CONST BOOLEAN Normal
,
324 IN CONST BOOLEAN Consist
329 // specific has priority
331 if (Specific
!= NULL
) {
332 NewSpecific
= AllocateZeroPool(StrSize(Specific
) + sizeof(CHAR16
));
333 if (NewSpecific
== NULL
){
336 StrCpy(NewSpecific
, Specific
);
337 if (NewSpecific
[StrLen(NewSpecific
)-1] != L
':') {
338 StrCat(NewSpecific
, L
":");
341 if (SearchList(MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
342 FreePool(NewSpecific
);
345 FreePool(NewSpecific
);
348 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
349 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
350 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
351 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
356 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
357 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
361 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
369 Display a single map line for device Handle if conditions are met.
371 @param[in] Verbose TRUE to display (extra) verbose information.
372 @param[in] Consist TRUE to display consistent mappings.
373 @param[in] Normal TRUE to display normal (not consist) mappings.
374 @param[in] TypeString pointer to string of filter types.
375 @param[in] SFO TRUE to display output in Standard Output Format.
376 @param[in] Specific pointer to string for specific map to display.
377 @param[in] Handle The handle to display from.
379 @retval EFI_SUCCESS The mapping was displayed.
383 PerformSingleMappingDisplay(
384 IN CONST BOOLEAN Verbose
,
385 IN CONST BOOLEAN Consist
,
386 IN CONST BOOLEAN Normal
,
387 IN CONST CHAR16
*TypeString
,
388 IN CONST BOOLEAN SFO
,
389 IN CONST CHAR16
*Specific OPTIONAL
,
390 IN CONST EFI_HANDLE Handle
393 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
394 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
395 CONST CHAR16
*MapList
;
398 CHAR16
*DevPathString
;
402 CONST CHAR16
*TempSpot2
;
404 DevPath
= DevicePathFromHandle(Handle
);
405 DevPathCopy
= DevPath
;
406 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
407 if (MapList
== NULL
) {
408 return EFI_NOT_FOUND
;
411 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
412 return EFI_NOT_FOUND
;
416 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
417 if (CurrentName
== NULL
) {
418 return (EFI_OUT_OF_RESOURCES
);
420 TempSpot
= StrStr(CurrentName
, L
";");
421 if (TempSpot
!= NULL
) {
422 *TempSpot
= CHAR_NULL
;
424 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
426 TempLen
= StrLen(CurrentName
);
431 STRING_TOKEN (STR_MAP_ENTRY
),
432 gShellLevel2HiiHandle
,
434 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"",
439 // also print handle, media type, removable (y/n), and current directory
441 MediaType
= GetDeviceMediaType(DevPath
);
442 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
443 Removable
= IsRemoveableDevice(DevPath
);
444 TempSpot2
= ShellGetCurrentDir(CurrentName
);
449 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
450 gShellLevel2HiiHandle
,
451 ConvertHandleToHandleIndex(Handle
),
453 Removable
?L
"Yes":L
"No",
460 TempLen
= StrLen(CurrentName
);
465 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
466 gShellLevel2HiiHandle
,
469 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""
472 FreePool(DevPathString
);
473 FreePool(CurrentName
);
478 Delete Specific from the list of maps for device Handle.
480 @param[in] Specific The name to delete.
481 @param[in] Handle The device to look on.
483 @retval EFI_SUCCESS The delete was successful.
484 @retval EFI_NOT_FOUND Name was not a map on Handle.
488 PerformSingleMappingDelete(
489 IN CONST CHAR16
*Specific
,
490 IN CONST EFI_HANDLE Handle
493 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
494 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
495 CONST CHAR16
*MapList
;
498 DevPath
= DevicePathFromHandle(Handle
);
499 DevPathCopy
= DevPath
;
500 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
503 if (MapList
== NULL
) {
504 return (EFI_NOT_FOUND
);
507 // if there is a specific and its not on the list...
509 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
510 return (EFI_NOT_FOUND
);
512 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
515 CONST CHAR16 Cd
[] = L
"cd*";
516 CONST CHAR16 Hd
[] = L
"hd*";
517 CONST CHAR16 Fp
[] = L
"fp*";
518 CONST CHAR16 AnyF
[] = L
"F*";
520 Function to display mapping information to the user.
522 If Specific is specified then Consist and Normal will be ignored since information will
523 be printed for the specific item only.
525 @param[in] Verbose TRUE to display (extra) verbose information.
526 @param[in] Consist TRUE to display consistent mappings.
527 @param[in] Normal TRUE to display normal (not consist) mappings.
528 @param[in] TypeString Pointer to string of filter types.
529 @param[in] SFO TRUE to display output in Standard Output Format.
530 @param[in] Specific Pointer to string for specific map to display.
531 @param[in] Header TRUE to print the header block.
533 @retval SHELL_SUCCESS The display was printed.
534 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
539 PerformMappingDisplay(
540 IN CONST BOOLEAN Verbose
,
541 IN CONST BOOLEAN Consist
,
542 IN CONST BOOLEAN Normal
,
543 IN CONST CHAR16
*TypeString
,
544 IN CONST BOOLEAN SFO
,
545 IN CONST CHAR16
*Specific OPTIONAL
,
546 IN CONST BOOLEAN Header
550 EFI_HANDLE
*HandleBuffer
;
556 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
557 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
558 return (SHELL_INVALID_PARAMETER
);
561 if (TypeString
!= NULL
) {
563 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
565 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
567 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
568 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, TypeString
);
569 return (SHELL_INVALID_PARAMETER
);
571 } else if (Test
== NULL
) {
572 Test
= (CHAR16
*)AnyF
;
584 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
586 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
594 // Look up all SimpleFileSystems in the platform
596 Status
= gBS
->LocateHandle(
598 &gEfiSimpleFileSystemProtocolGuid
,
602 if (Status
== EFI_BUFFER_TOO_SMALL
) {
603 HandleBuffer
= AllocateZeroPool(BufferSize
);
604 if (HandleBuffer
== NULL
) {
605 return (SHELL_OUT_OF_RESOURCES
);
607 Status
= gBS
->LocateHandle(
609 &gEfiSimpleFileSystemProtocolGuid
,
616 // Get the map name(s) for each one.
618 for ( LoopVar
= 0, Found
= FALSE
619 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
622 Status
= PerformSingleMappingDisplay(
629 HandleBuffer
[LoopVar
]);
630 if (!EFI_ERROR(Status
)) {
636 // Look up all BlockIo in the platform
638 Status
= gBS
->LocateHandle(
640 &gEfiBlockIoProtocolGuid
,
644 if (Status
== EFI_BUFFER_TOO_SMALL
) {
645 SHELL_FREE_NON_NULL(HandleBuffer
);
646 HandleBuffer
= AllocateZeroPool(BufferSize
);
647 if (HandleBuffer
== NULL
) {
648 return (SHELL_OUT_OF_RESOURCES
);
650 Status
= gBS
->LocateHandle(
652 &gEfiBlockIoProtocolGuid
,
657 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
659 // Get the map name(s) for each one.
662 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
666 // Skip any that were already done...
668 if (gBS
->OpenProtocol(
669 HandleBuffer
[LoopVar
],
670 &gEfiSimpleFileSystemProtocolGuid
,
674 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
677 Status
= PerformSingleMappingDisplay(
684 HandleBuffer
[LoopVar
]);
685 if (!EFI_ERROR(Status
)) {
689 FreePool(HandleBuffer
);
692 if (Specific
!= NULL
) {
693 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, Specific
);
695 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
);
698 return (SHELL_SUCCESS
);
702 Perform a mapping display and parse for multiple types in the TypeString.
704 @param[in] Verbose TRUE to use verbose output.
705 @param[in] Consist TRUE to display consistent names.
706 @param[in] Normal TRUE to display normal names.
707 @param[in] TypeString An optional comma-delimited list of types.
708 @param[in] SFO TRUE to display in SFO format. See Spec.
709 @param[in] Specific An optional specific map name to display alone.
711 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
712 @retval SHELL_SUCCESS The display was successful.
713 @sa PerformMappingDisplay
717 PerformMappingDisplay2(
718 IN CONST BOOLEAN Verbose
,
719 IN CONST BOOLEAN Consist
,
720 IN CONST BOOLEAN Normal
,
721 IN CONST CHAR16
*TypeString
,
722 IN CONST BOOLEAN SFO
,
723 IN CONST CHAR16
*Specific OPTIONAL
726 CONST CHAR16
*TypeWalker
;
727 SHELL_STATUS ShellStatus
;
731 if (TypeString
== NULL
) {
732 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
734 ShellStatus
= SHELL_SUCCESS
;
735 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
736 Comma
= StrStr(TypeWalker
, L
",");
738 if (ShellStatus
== SHELL_SUCCESS
) {
739 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
741 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
746 if (ShellStatus
== SHELL_SUCCESS
) {
747 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
749 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
752 TypeWalker
= Comma
+ 1;
756 return (ShellStatus
);
760 Delete a specific map.
762 @param[in] Specific The pointer to the name of the map to delete.
764 @retval EFI_INVALID_PARAMETER Specific was NULL.
765 @retval EFI_SUCCESS The operation was successful.
766 @retval EFI_NOT_FOUND Specific could not be found.
770 PerformMappingDelete(
771 IN CONST CHAR16
*Specific
775 EFI_HANDLE
*HandleBuffer
;
780 if (Specific
== NULL
) {
781 return (EFI_INVALID_PARAMETER
);
789 // Look up all SimpleFileSystems in the platform
791 Status
= gBS
->LocateHandle(
793 &gEfiDevicePathProtocolGuid
,
797 if (Status
== EFI_BUFFER_TOO_SMALL
) {
798 HandleBuffer
= AllocateZeroPool(BufferSize
);
799 if (HandleBuffer
== NULL
) {
800 return (EFI_OUT_OF_RESOURCES
);
802 Status
= gBS
->LocateHandle(
804 &gEfiDevicePathProtocolGuid
,
809 if (EFI_ERROR(Status
)) {
810 SHELL_FREE_NON_NULL(HandleBuffer
);
814 if (HandleBuffer
!= NULL
) {
816 // Get the map name(s) for each one.
819 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
822 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
828 // Look up all BlockIo in the platform
830 Status
= gBS
->LocateHandle(
832 &gEfiBlockIoProtocolGuid
,
836 if (Status
== EFI_BUFFER_TOO_SMALL
) {
837 FreePool(HandleBuffer
);
838 HandleBuffer
= AllocateZeroPool(BufferSize
);
839 if (HandleBuffer
== NULL
) {
840 return (EFI_OUT_OF_RESOURCES
);
842 Status
= gBS
->LocateHandle(
844 &gEfiBlockIoProtocolGuid
,
849 if (EFI_ERROR(Status
)) {
850 SHELL_FREE_NON_NULL(HandleBuffer
);
854 if (HandleBuffer
!= NULL
) {
856 // Get the map name(s) for each one.
859 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
863 // Skip any that were already done...
865 if (gBS
->OpenProtocol(
866 HandleBuffer
[LoopVar
],
867 &gEfiDevicePathProtocolGuid
,
871 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
874 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
879 SHELL_FREE_NON_NULL(HandleBuffer
);
881 return (EFI_NOT_FOUND
);
883 return (EFI_SUCCESS
);
887 function to add a mapping from mapping.
889 This function will get the device path associated with the mapping and call SetMap.
891 @param[in] Map The Map to add a mapping for
892 @param[in] SName The name of the new mapping
894 @retval SHELL_SUCCESS the mapping was added
895 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
896 @return Shell version of a return value from EfiShellProtocol->SetMap
901 AddMappingFromMapping(
902 IN CONST CHAR16
*Map
,
903 IN CONST CHAR16
*SName
906 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
910 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
911 if (NewSName
== NULL
) {
912 return (SHELL_OUT_OF_RESOURCES
);
914 StrCpy(NewSName
, SName
);
915 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
916 StrCat(NewSName
, L
":");
919 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
921 return (SHELL_INVALID_PARAMETER
);
924 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
925 if (DevPath
== NULL
) {
927 return (SHELL_INVALID_PARAMETER
);
930 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
932 if (EFI_ERROR(Status
)) {
933 return (SHELL_DEVICE_ERROR
);
935 return (SHELL_SUCCESS
);
939 function to add a mapping from an EFI_HANDLE.
941 This function will get the device path associated with the Handle and call SetMap.
943 @param[in] Handle The handle to add a mapping for
944 @param[in] SName The name of the new mapping
946 @retval SHELL_SUCCESS the mapping was added
947 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
948 @return Shell version of a return value from either
949 gBS->OpenProtocol or EfiShellProtocol->SetMap
954 AddMappingFromHandle(
955 IN CONST EFI_HANDLE Handle
,
956 IN CONST CHAR16
*SName
959 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
963 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
964 if (NewSName
== NULL
) {
965 return (SHELL_OUT_OF_RESOURCES
);
967 StrCpy(NewSName
, SName
);
968 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
969 StrCat(NewSName
, L
":");
972 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
974 return (SHELL_INVALID_PARAMETER
);
977 Status
= gBS
->OpenProtocol(
979 &gEfiDevicePathProtocolGuid
,
983 EFI_OPEN_PROTOCOL_GET_PROTOCOL
985 if (EFI_ERROR(Status
)) {
987 return (SHELL_DEVICE_ERROR
);
989 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
991 if (EFI_ERROR(Status
)) {
992 return (SHELL_DEVICE_ERROR
);
994 return (SHELL_SUCCESS
);
997 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
1005 {L
"-sfo", TypeValue
},
1010 Function for 'map' command.
1012 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1013 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1017 ShellCommandRunMap (
1018 IN EFI_HANDLE ImageHandle
,
1019 IN EFI_SYSTEM_TABLE
*SystemTable
1023 LIST_ENTRY
*Package
;
1024 CHAR16
*ProblemParam
;
1025 CONST CHAR16
*SName
;
1026 CONST CHAR16
*Mapping
;
1027 EFI_HANDLE MapAsHandle
;
1028 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
1029 SHELL_STATUS ShellStatus
;
1033 CONST CHAR16
*Param1
;
1034 CONST CHAR16
*TypeString
;
1035 UINTN TempStringLength
;
1037 ProblemParam
= NULL
;
1041 ShellStatus
= SHELL_SUCCESS
;
1045 // initialize the shell lib (we must be in non-auto-init...)
1047 Status
= ShellInitialize();
1048 ASSERT_EFI_ERROR(Status
);
1050 Status
= CommandInit();
1051 ASSERT_EFI_ERROR(Status
);
1054 // parse the command line
1056 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1057 if (EFI_ERROR(Status
)) {
1058 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1059 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
1060 FreePool(ProblemParam
);
1061 ShellStatus
= SHELL_INVALID_PARAMETER
;
1069 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1070 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1071 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1072 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1074 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1075 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
1076 ShellStatus
= SHELL_INVALID_PARAMETER
;
1079 // Deleting a map name...
1081 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1082 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1083 || ShellCommandLineGetFlag(Package
, L
"-v")
1086 || ShellCommandLineGetFlag(Package
, L
"-u")
1087 || ShellCommandLineGetFlag(Package
, L
"-t")
1089 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
1090 ShellStatus
= SHELL_INVALID_PARAMETER
;
1092 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1093 if (SName
!= NULL
) {
1094 Status
= PerformMappingDelete(SName
);
1095 if (EFI_ERROR(Status
)) {
1097 case EFI_ACCESS_DENIED
:
1098 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1099 ShellStatus
= SHELL_ACCESS_DENIED
;
1102 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
1103 ShellStatus
= SHELL_INVALID_PARAMETER
;
1106 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1107 ShellStatus
= SHELL_UNSUPPORTED
;
1111 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
1112 ShellStatus
= SHELL_INVALID_PARAMETER
;
1115 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1116 // || ShellCommandLineGetFlag(Package, L"-v")
1119 || ShellCommandLineGetFlag(Package
, L
"-u")
1120 || ShellCommandLineGetFlag(Package
, L
"-t")
1122 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1126 Status
= ShellCommandCreateInitialMappingsAndPaths();
1127 if (EFI_ERROR(Status
)) {
1128 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1129 ShellStatus
= SHELL_UNSUPPORTED
;
1132 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1136 Status
= UpdateMapping();
1137 if (EFI_ERROR(Status
)) {
1138 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1139 ShellStatus
= SHELL_UNSUPPORTED
;
1142 if (ShellStatus
== SHELL_SUCCESS
) {
1143 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1144 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1147 &&TypeString
== NULL
1150 // now do the display...
1152 ShellStatus
= PerformMappingDisplay(
1153 ShellCommandLineGetFlag(Package
, L
"-v"),
1163 // now do the display...
1165 ShellStatus
= PerformMappingDisplay2(
1166 ShellCommandLineGetFlag(Package
, L
"-v"),
1177 // adding or displaying (there were no flags)
1179 SName
= ShellCommandLineGetRawValue(Package
, 1);
1180 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1185 // display only since no flags
1187 ShellStatus
= PerformMappingDisplay(
1188 ShellCommandLineGetFlag(Package
, L
"-v"),
1196 } else if ( SName
== NULL
1200 // Display only the one specified
1202 ShellStatus
= PerformMappingDisplay(
1208 SName
, // note the variable here...
1212 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1213 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1217 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1218 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1219 ShellStatus
= SHELL_INVALID_PARAMETER
;
1221 if (MapAsHandle
!= NULL
) {
1222 TempStringLength
= StrLen(SName
);
1223 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1224 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1225 ShellStatus
= SHELL_INVALID_PARAMETER
;
1227 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1230 TempStringLength
= StrLen(SName
);
1231 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1233 ShellStatus
= SHELL_INVALID_PARAMETER
;
1235 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1238 if (ShellStatus
!= SHELL_SUCCESS
) {
1239 switch (ShellStatus
) {
1240 case SHELL_ACCESS_DENIED
:
1241 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1243 case SHELL_INVALID_PARAMETER
:
1244 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1246 case SHELL_DEVICE_ERROR
:
1247 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, Mapping
);
1250 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1254 // now do the display...
1256 ShellStatus
= PerformMappingDisplay(
1265 } // we were sucessful so do an output
1266 } // got a valid map target
1267 } // got 2 variables
1268 } // we are adding a mapping
1269 } // got valid parameters
1273 // free the command line package
1275 ShellCommandLineFreeVarList (Package
);
1277 return (ShellStatus
);