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
"AnyF*", 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 TempSpot
= StrStr(CurrentName
, L
";");
418 if (TempSpot
!= NULL
) {
419 *TempSpot
= CHAR_NULL
;
421 DevPathString
= gDevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
423 TempLen
= StrLen(CurrentName
);
428 STRING_TOKEN (STR_MAP_ENTRY
),
429 gShellLevel2HiiHandle
,
431 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"",
436 // also print handle, media type, removable (y/n), and current directory
438 MediaType
= GetDeviceMediaType(DevPath
);
439 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
440 Removable
= IsRemoveableDevice(DevPath
);
441 TempSpot2
= ShellGetCurrentDir(CurrentName
);
446 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
447 gShellLevel2HiiHandle
,
448 ConvertHandleToHandleIndex(Handle
),
450 Removable
?L
"Yes":L
"No",
457 TempLen
= StrLen(CurrentName
);
462 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
463 gShellLevel2HiiHandle
,
466 TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""
469 FreePool(DevPathString
);
470 FreePool(CurrentName
);
475 Delete Specific from the list of maps for device Handle.
477 @param[in] Specific The name to delete.
478 @param[in] Handle The device to look on.
480 @retval EFI_SUCCESS The delete was successful.
481 @retval EFI_NOT_FOUND Name was not a map on Handle.
485 PerformSingleMappingDelete(
486 IN CONST CHAR16
*Specific
,
487 IN CONST EFI_HANDLE Handle
490 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
491 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
492 CONST CHAR16
*MapList
;
495 DevPath
= DevicePathFromHandle(Handle
);
496 DevPathCopy
= DevPath
;
497 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
500 if (MapList
== NULL
) {
501 return (EFI_NOT_FOUND
);
504 // if there is a specific and its not on the list...
506 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
507 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*";
517 Function to display mapping information to the user.
519 If Specific is specified then Consist and Normal will be ignored since information will
520 be printed for the specific item only.
522 @param[in] Verbose TRUE to display (extra) verbose information.
523 @param[in] Consist TRUE to display consistent mappings.
524 @param[in] Normal TRUE to display normal (not consist) mappings.
525 @param[in] TypeString Pointer to string of filter types.
526 @param[in] SFO TRUE to display output in Standard Output Format.
527 @param[in] Specific Pointer to string for specific map to display.
528 @param[in] Header TRUE to print the header block.
530 @retval SHELL_SUCCESS The display was printed.
531 @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
);
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_PROBLEM
), gShellLevel2HiiHandle
, 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
,
599 if (Status
== EFI_BUFFER_TOO_SMALL
) {
600 HandleBuffer
= AllocateZeroPool(BufferSize
);
601 if (HandleBuffer
== NULL
) {
602 return (SHELL_OUT_OF_RESOURCES
);
604 Status
= gBS
->LocateHandle(
606 &gEfiSimpleFileSystemProtocolGuid
,
613 // Get the map name(s) for each one.
615 for ( LoopVar
= 0, Found
= FALSE
616 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
619 Status
= PerformSingleMappingDisplay(
626 HandleBuffer
[LoopVar
]);
627 if (!EFI_ERROR(Status
)) {
633 // Look up all BlockIo in the platform
635 Status
= gBS
->LocateHandle(
637 &gEfiBlockIoProtocolGuid
,
641 if (Status
== EFI_BUFFER_TOO_SMALL
) {
642 SHELL_FREE_NON_NULL(HandleBuffer
);
643 HandleBuffer
= AllocateZeroPool(BufferSize
);
644 if (HandleBuffer
== NULL
) {
645 return (SHELL_OUT_OF_RESOURCES
);
647 Status
= gBS
->LocateHandle(
649 &gEfiBlockIoProtocolGuid
,
654 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
656 // Get the map name(s) for each one.
659 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
663 // Skip any that were already done...
665 if (gBS
->OpenProtocol(
666 HandleBuffer
[LoopVar
],
667 &gEfiSimpleFileSystemProtocolGuid
,
671 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
674 Status
= PerformSingleMappingDisplay(
681 HandleBuffer
[LoopVar
]);
682 if (!EFI_ERROR(Status
)) {
686 FreePool(HandleBuffer
);
689 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, Specific
);
691 return (SHELL_SUCCESS
);
695 Perform a mapping display and parse for multiple types in the TypeString.
697 @param[in] Verbose TRUE to use verbose output.
698 @param[in] Consist TRUE to display consistent names.
699 @param[in] Normal TRUE to display normal names.
700 @param[in] TypeString An optional comma-delimited list of types.
701 @param[in] SFO TRUE to display in SFO format. See Spec.
702 @param[in] Specific An optional specific map name to display alone.
704 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
705 @retval SHELL_SUCCESS The display was successful.
706 @sa PerformMappingDisplay
710 PerformMappingDisplay2(
711 IN CONST BOOLEAN Verbose
,
712 IN CONST BOOLEAN Consist
,
713 IN CONST BOOLEAN Normal
,
714 IN CONST CHAR16
*TypeString
,
715 IN CONST BOOLEAN SFO
,
716 IN CONST CHAR16
*Specific OPTIONAL
719 CONST CHAR16
*TypeWalker
;
720 SHELL_STATUS ShellStatus
;
724 if (TypeString
== NULL
) {
725 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
727 ShellStatus
= SHELL_SUCCESS
;
728 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
729 Comma
= StrStr(TypeWalker
, L
",");
731 if (ShellStatus
== SHELL_SUCCESS
) {
732 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
734 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
739 if (ShellStatus
== SHELL_SUCCESS
) {
740 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
742 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
745 TypeWalker
= Comma
+ 1;
749 return (ShellStatus
);
753 Delete a specific map.
755 @param[in] Specific The pointer to the name of the map to delete.
757 @retval EFI_INVALID_PARAMETER Specific was NULL.
758 @retval EFI_SUCCESS The operation was successful.
759 @retval EFI_NOT_FOUND Specific could not be found.
763 PerformMappingDelete(
764 IN CONST CHAR16
*Specific
768 EFI_HANDLE
*HandleBuffer
;
773 if (Specific
== NULL
) {
774 return (EFI_INVALID_PARAMETER
);
782 // Look up all SimpleFileSystems in the platform
784 Status
= gBS
->LocateHandle(
786 &gEfiDevicePathProtocolGuid
,
790 if (Status
== EFI_BUFFER_TOO_SMALL
) {
791 HandleBuffer
= AllocateZeroPool(BufferSize
);
792 if (HandleBuffer
== NULL
) {
793 return (EFI_OUT_OF_RESOURCES
);
795 Status
= gBS
->LocateHandle(
797 &gEfiDevicePathProtocolGuid
,
802 if (EFI_ERROR(Status
)) {
803 SHELL_FREE_NON_NULL(HandleBuffer
);
807 if (HandleBuffer
!= NULL
) {
809 // Get the map name(s) for each one.
812 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
815 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
821 // Look up all BlockIo in the platform
823 Status
= gBS
->LocateHandle(
825 &gEfiBlockIoProtocolGuid
,
829 if (Status
== EFI_BUFFER_TOO_SMALL
) {
830 FreePool(HandleBuffer
);
831 HandleBuffer
= AllocateZeroPool(BufferSize
);
832 if (HandleBuffer
== NULL
) {
833 return (EFI_OUT_OF_RESOURCES
);
835 Status
= gBS
->LocateHandle(
837 &gEfiBlockIoProtocolGuid
,
842 if (EFI_ERROR(Status
)) {
843 SHELL_FREE_NON_NULL(HandleBuffer
);
847 if (HandleBuffer
!= NULL
) {
849 // Get the map name(s) for each one.
852 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
856 // Skip any that were already done...
858 if (gBS
->OpenProtocol(
859 HandleBuffer
[LoopVar
],
860 &gEfiDevicePathProtocolGuid
,
864 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
867 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
872 SHELL_FREE_NON_NULL(HandleBuffer
);
874 return (EFI_NOT_FOUND
);
876 return (EFI_SUCCESS
);
880 function to add a mapping from mapping.
882 This function will get the device path associated with the mapping and call SetMap.
884 @param[in] Map The Map to add a mapping for
885 @param[in] SName The name of the new mapping
887 @retval SHELL_SUCCESS the mapping was added
888 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
889 @return Shell version of a return value from EfiShellProtocol->SetMap
894 AddMappingFromMapping(
895 IN CONST CHAR16
*Map
,
896 IN CONST CHAR16
*SName
899 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
903 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
904 if (NewSName
== NULL
) {
905 return (SHELL_OUT_OF_RESOURCES
);
907 StrCpy(NewSName
, SName
);
908 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
909 StrCat(NewSName
, L
":");
912 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
914 return (SHELL_INVALID_PARAMETER
);
917 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
918 if (DevPath
== NULL
) {
920 return (SHELL_INVALID_PARAMETER
);
923 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
925 if (EFI_ERROR(Status
)) {
926 return (SHELL_DEVICE_ERROR
);
928 return (SHELL_SUCCESS
);
932 function to add a mapping from an EFI_HANDLE.
934 This function will get the device path associated with the Handle and call SetMap.
936 @param[in] Handle The handle to add a mapping for
937 @param[in] SName The name of the new mapping
939 @retval SHELL_SUCCESS the mapping was added
940 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
941 @return Shell version of a return value from either
942 gBS->OpenProtocol or EfiShellProtocol->SetMap
947 AddMappingFromHandle(
948 IN CONST EFI_HANDLE Handle
,
949 IN CONST CHAR16
*SName
952 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
956 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
957 if (NewSName
== NULL
) {
958 return (SHELL_OUT_OF_RESOURCES
);
960 StrCpy(NewSName
, SName
);
961 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
962 StrCat(NewSName
, L
":");
965 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
967 return (SHELL_INVALID_PARAMETER
);
970 Status
= gBS
->OpenProtocol(
972 &gEfiDevicePathProtocolGuid
,
976 EFI_OPEN_PROTOCOL_GET_PROTOCOL
978 if (EFI_ERROR(Status
)) {
980 return (SHELL_DEVICE_ERROR
);
982 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
984 if (EFI_ERROR(Status
)) {
985 return (SHELL_DEVICE_ERROR
);
987 return (SHELL_SUCCESS
);
990 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
998 {L
"-sfo", TypeValue
},
1003 Function for 'map' command.
1005 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1006 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1010 ShellCommandRunMap (
1011 IN EFI_HANDLE ImageHandle
,
1012 IN EFI_SYSTEM_TABLE
*SystemTable
1016 LIST_ENTRY
*Package
;
1017 CHAR16
*ProblemParam
;
1018 CONST CHAR16
*SName
;
1019 CONST CHAR16
*Mapping
;
1020 EFI_HANDLE MapAsHandle
;
1021 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
1022 SHELL_STATUS ShellStatus
;
1026 CONST CHAR16
*Param1
;
1027 CONST CHAR16
*TypeString
;
1028 UINTN TempStringLength
;
1030 ProblemParam
= NULL
;
1034 ShellStatus
= SHELL_SUCCESS
;
1038 // initialize the shell lib (we must be in non-auto-init...)
1040 Status
= ShellInitialize();
1041 ASSERT_EFI_ERROR(Status
);
1043 Status
= CommandInit();
1044 ASSERT_EFI_ERROR(Status
);
1047 // parse the command line
1049 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1050 if (EFI_ERROR(Status
)) {
1051 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1052 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
1053 FreePool(ProblemParam
);
1054 ShellStatus
= SHELL_INVALID_PARAMETER
;
1062 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1063 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1064 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1065 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1067 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1068 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
1069 ShellStatus
= SHELL_INVALID_PARAMETER
;
1072 // Deleting a map name...
1074 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1075 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1076 || ShellCommandLineGetFlag(Package
, L
"-v")
1079 || ShellCommandLineGetFlag(Package
, L
"-u")
1080 || ShellCommandLineGetFlag(Package
, L
"-t")
1082 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
1083 ShellStatus
= SHELL_INVALID_PARAMETER
;
1085 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1086 if (SName
!= NULL
) {
1087 Status
= PerformMappingDelete(SName
);
1088 if (EFI_ERROR(Status
)) {
1090 case EFI_ACCESS_DENIED
:
1091 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1092 ShellStatus
= SHELL_ACCESS_DENIED
;
1095 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
1096 ShellStatus
= SHELL_INVALID_PARAMETER
;
1099 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1100 ShellStatus
= SHELL_UNSUPPORTED
;
1104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
1105 ShellStatus
= SHELL_INVALID_PARAMETER
;
1108 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1109 // || ShellCommandLineGetFlag(Package, L"-v")
1112 || ShellCommandLineGetFlag(Package
, L
"-u")
1113 || ShellCommandLineGetFlag(Package
, L
"-t")
1115 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1119 Status
= ShellCommandCreateInitialMappingsAndPaths();
1120 if (EFI_ERROR(Status
)) {
1121 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1122 ShellStatus
= SHELL_UNSUPPORTED
;
1125 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1129 Status
= UpdateMapping();
1130 if (EFI_ERROR(Status
)) {
1131 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1132 ShellStatus
= SHELL_UNSUPPORTED
;
1135 if (ShellStatus
== SHELL_SUCCESS
) {
1136 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1137 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1140 &&TypeString
== NULL
1143 // now do the display...
1145 ShellStatus
= PerformMappingDisplay(
1146 ShellCommandLineGetFlag(Package
, L
"-v"),
1156 // now do the display...
1158 ShellStatus
= PerformMappingDisplay2(
1159 ShellCommandLineGetFlag(Package
, L
"-v"),
1170 // adding or displaying (there were no flags)
1172 SName
= ShellCommandLineGetRawValue(Package
, 1);
1173 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1178 // display only since no flags
1180 ShellStatus
= PerformMappingDisplay(
1181 ShellCommandLineGetFlag(Package
, L
"-v"),
1189 } else if ( SName
== NULL
1193 // Display only the one specified
1195 ShellStatus
= PerformMappingDisplay(
1201 SName
, // note the variable here...
1205 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1206 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1210 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1211 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1212 ShellStatus
= SHELL_INVALID_PARAMETER
;
1214 if (MapAsHandle
!= NULL
) {
1215 TempStringLength
= StrLen(SName
);
1216 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1217 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1218 ShellStatus
= SHELL_INVALID_PARAMETER
;
1220 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1223 TempStringLength
= StrLen(SName
);
1224 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1225 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1226 ShellStatus
= SHELL_INVALID_PARAMETER
;
1228 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1231 if (ShellStatus
!= SHELL_SUCCESS
) {
1232 switch (ShellStatus
) {
1233 case SHELL_ACCESS_DENIED
:
1234 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1236 case SHELL_INVALID_PARAMETER
:
1237 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1239 case SHELL_DEVICE_ERROR
:
1240 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, Mapping
);
1243 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1247 // now do the display...
1249 ShellStatus
= PerformMappingDisplay(
1258 } // we were sucessful so do an output
1259 } // got a valid map target
1260 } // got 2 variables
1261 } // we are adding a mapping
1262 } // got valid parameters
1266 // free the command line package
1268 ShellCommandLineFreeVarList (Package
);
1270 return (ShellStatus
);