2 Main file for map shell level 2 command.
4 Copyright (c) 2009 - 2013, 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
;
403 CONST CHAR16
*TempSpot2
;
408 DevPath
= DevicePathFromHandle(Handle
);
409 DevPathCopy
= DevPath
;
410 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
411 if (MapList
== NULL
) {
412 return EFI_NOT_FOUND
;
415 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
416 return EFI_NOT_FOUND
;
424 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
425 if (CurrentName
== NULL
) {
426 return (EFI_OUT_OF_RESOURCES
);
430 // Chop off the other names that become "Alias(s)"
431 // leaving just the normal name
433 TempSpot
= StrStr(CurrentName
, L
";");
434 if (TempSpot
!= NULL
) {
435 *TempSpot
= CHAR_NULL
;
437 } else if (Consist
) {
441 // Skip the first name. This is the standard name.
443 TempSpot
= StrStr(MapList
, L
";");
444 if (TempSpot
!= NULL
) {
447 SearchList(TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
448 if (CurrentName
== NULL
) {
449 SearchList(TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
451 if (CurrentName
== NULL
) {
452 SearchList(TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
454 if (CurrentName
== NULL
) {
455 SearchList(TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
457 if (CurrentName
== NULL
) {
459 // We didnt find anything, so just the first one in the list...
461 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
462 if (CurrentName
== NULL
) {
463 return (EFI_OUT_OF_RESOURCES
);
465 TempSpot
= StrStr(CurrentName
, L
";");
466 if (TempSpot
!= NULL
) {
467 *TempSpot
= CHAR_NULL
;
470 Alias
= StrnCatGrow(&Alias
, 0, MapList
, 0);
472 return EFI_OUT_OF_RESOURCES
;
474 TempSpot
= StrStr(Alias
, CurrentName
);
475 if (TempSpot
!= NULL
) {
476 TempSpot2
= StrStr(TempSpot
, L
";");
477 if (TempSpot2
!= NULL
) {
478 TempSpot2
++; // Move past ";" from CurrentName
479 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
481 *TempSpot
= CHAR_NULL
;
484 if (Alias
[StrLen(Alias
)-1] == L
';') {
485 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
490 CurrentName
= StrnCatGrow(&CurrentName
, 0, L
"", 0);
491 if (CurrentName
== NULL
) {
492 return (EFI_OUT_OF_RESOURCES
);
495 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
497 TempLen
= StrLen(CurrentName
);
502 STRING_TOKEN (STR_MAP_ENTRY
),
503 gShellLevel2HiiHandle
,
505 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
510 // also print handle, media type, removable (y/n), and current directory
512 MediaType
= GetDeviceMediaType(DevPath
);
513 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
514 Removable
= IsRemoveableDevice(DevPath
);
515 TempSpot2
= ShellGetCurrentDir(CurrentName
);
520 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
521 gShellLevel2HiiHandle
,
522 ConvertHandleToHandleIndex(Handle
),
524 Removable
?L
"Yes":L
"No",
528 SHELL_FREE_NON_NULL(MediaType
);
531 TempLen
= StrLen(CurrentName
);
536 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
537 gShellLevel2HiiHandle
,
540 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
543 SHELL_FREE_NON_NULL(DevPathString
);
544 SHELL_FREE_NON_NULL(CurrentName
);
545 SHELL_FREE_NON_NULL(Alias
);
550 Delete Specific from the list of maps for device Handle.
552 @param[in] Specific The name to delete.
553 @param[in] Handle The device to look on.
555 @retval EFI_SUCCESS The delete was successful.
556 @retval EFI_NOT_FOUND Name was not a map on Handle.
560 PerformSingleMappingDelete(
561 IN CONST CHAR16
*Specific
,
562 IN CONST EFI_HANDLE Handle
565 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
566 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
567 CONST CHAR16
*MapList
;
570 DevPath
= DevicePathFromHandle(Handle
);
571 DevPathCopy
= DevPath
;
572 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
575 if (MapList
== NULL
) {
576 return (EFI_NOT_FOUND
);
579 // if there is a specific and its not on the list...
581 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
582 return (EFI_NOT_FOUND
);
584 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
587 CONST CHAR16 Cd
[] = L
"cd*";
588 CONST CHAR16 Hd
[] = L
"hd*";
589 CONST CHAR16 Fp
[] = L
"fp*";
590 CONST CHAR16 AnyF
[] = L
"F*";
592 Function to display mapping information to the user.
594 If Specific is specified then Consist and Normal will be ignored since information will
595 be printed for the specific item only.
597 @param[in] Verbose TRUE to display (extra) verbose information.
598 @param[in] Consist TRUE to display consistent mappings.
599 @param[in] Normal TRUE to display normal (not consist) mappings.
600 @param[in] TypeString Pointer to string of filter types.
601 @param[in] SFO TRUE to display output in Standard Output Format.
602 @param[in] Specific Pointer to string for specific map to display.
603 @param[in] Header TRUE to print the header block.
605 @retval SHELL_SUCCESS The display was printed.
606 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
611 PerformMappingDisplay(
612 IN CONST BOOLEAN Verbose
,
613 IN CONST BOOLEAN Consist
,
614 IN CONST BOOLEAN Normal
,
615 IN CONST CHAR16
*TypeString
,
616 IN CONST BOOLEAN SFO
,
617 IN CONST CHAR16
*Specific OPTIONAL
,
618 IN CONST BOOLEAN Header
622 EFI_HANDLE
*HandleBuffer
;
628 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
629 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
630 return (SHELL_INVALID_PARAMETER
);
633 if (TypeString
!= NULL
) {
635 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
637 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
639 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
640 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, TypeString
);
641 return (SHELL_INVALID_PARAMETER
);
643 } else if (Test
== NULL
) {
644 Test
= (CHAR16
*)AnyF
;
656 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
658 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
666 // Look up all SimpleFileSystems in the platform
668 Status
= gBS
->LocateHandle(
670 &gEfiSimpleFileSystemProtocolGuid
,
674 if (Status
== EFI_BUFFER_TOO_SMALL
) {
675 HandleBuffer
= AllocateZeroPool(BufferSize
);
676 if (HandleBuffer
== NULL
) {
677 return (SHELL_OUT_OF_RESOURCES
);
679 Status
= gBS
->LocateHandle(
681 &gEfiSimpleFileSystemProtocolGuid
,
688 // Get the map name(s) for each one.
690 for ( LoopVar
= 0, Found
= FALSE
691 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
694 Status
= PerformSingleMappingDisplay(
701 HandleBuffer
[LoopVar
]);
702 if (!EFI_ERROR(Status
)) {
708 // Look up all BlockIo in the platform
710 Status
= gBS
->LocateHandle(
712 &gEfiBlockIoProtocolGuid
,
716 if (Status
== EFI_BUFFER_TOO_SMALL
) {
717 SHELL_FREE_NON_NULL(HandleBuffer
);
718 HandleBuffer
= AllocateZeroPool(BufferSize
);
719 if (HandleBuffer
== NULL
) {
720 return (SHELL_OUT_OF_RESOURCES
);
722 Status
= gBS
->LocateHandle(
724 &gEfiBlockIoProtocolGuid
,
729 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
731 // Get the map name(s) for each one.
734 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
738 // Skip any that were already done...
740 if (gBS
->OpenProtocol(
741 HandleBuffer
[LoopVar
],
742 &gEfiSimpleFileSystemProtocolGuid
,
746 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
749 Status
= PerformSingleMappingDisplay(
756 HandleBuffer
[LoopVar
]);
757 if (!EFI_ERROR(Status
)) {
761 FreePool(HandleBuffer
);
764 if (Specific
!= NULL
) {
765 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, Specific
);
767 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
);
770 return (SHELL_SUCCESS
);
774 Perform a mapping display and parse for multiple types in the TypeString.
776 @param[in] Verbose TRUE to use verbose output.
777 @param[in] Consist TRUE to display consistent names.
778 @param[in] Normal TRUE to display normal names.
779 @param[in] TypeString An optional comma-delimited list of types.
780 @param[in] SFO TRUE to display in SFO format. See Spec.
781 @param[in] Specific An optional specific map name to display alone.
783 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
784 @retval SHELL_SUCCESS The display was successful.
785 @sa PerformMappingDisplay
789 PerformMappingDisplay2(
790 IN CONST BOOLEAN Verbose
,
791 IN CONST BOOLEAN Consist
,
792 IN CONST BOOLEAN Normal
,
793 IN CONST CHAR16
*TypeString
,
794 IN CONST BOOLEAN SFO
,
795 IN CONST CHAR16
*Specific OPTIONAL
798 CONST CHAR16
*TypeWalker
;
799 SHELL_STATUS ShellStatus
;
803 if (TypeString
== NULL
) {
804 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
806 ShellStatus
= SHELL_SUCCESS
;
807 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
808 Comma
= StrStr(TypeWalker
, L
",");
810 if (ShellStatus
== SHELL_SUCCESS
) {
811 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
813 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
818 if (ShellStatus
== SHELL_SUCCESS
) {
819 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
821 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
824 TypeWalker
= Comma
+ 1;
828 return (ShellStatus
);
832 Delete a specific map.
834 @param[in] Specific The pointer to the name of the map to delete.
836 @retval EFI_INVALID_PARAMETER Specific was NULL.
837 @retval EFI_SUCCESS The operation was successful.
838 @retval EFI_NOT_FOUND Specific could not be found.
842 PerformMappingDelete(
843 IN CONST CHAR16
*Specific
847 EFI_HANDLE
*HandleBuffer
;
852 if (Specific
== NULL
) {
853 return (EFI_INVALID_PARAMETER
);
861 // Look up all SimpleFileSystems in the platform
863 Status
= gBS
->LocateHandle(
865 &gEfiDevicePathProtocolGuid
,
869 if (Status
== EFI_BUFFER_TOO_SMALL
) {
870 HandleBuffer
= AllocateZeroPool(BufferSize
);
871 if (HandleBuffer
== NULL
) {
872 return (EFI_OUT_OF_RESOURCES
);
874 Status
= gBS
->LocateHandle(
876 &gEfiDevicePathProtocolGuid
,
881 if (EFI_ERROR(Status
)) {
882 SHELL_FREE_NON_NULL(HandleBuffer
);
886 if (HandleBuffer
!= NULL
) {
888 // Get the map name(s) for each one.
891 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
894 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
900 // Look up all BlockIo in the platform
902 Status
= gBS
->LocateHandle(
904 &gEfiBlockIoProtocolGuid
,
908 if (Status
== EFI_BUFFER_TOO_SMALL
) {
909 FreePool(HandleBuffer
);
910 HandleBuffer
= AllocateZeroPool(BufferSize
);
911 if (HandleBuffer
== NULL
) {
912 return (EFI_OUT_OF_RESOURCES
);
914 Status
= gBS
->LocateHandle(
916 &gEfiBlockIoProtocolGuid
,
921 if (EFI_ERROR(Status
)) {
922 SHELL_FREE_NON_NULL(HandleBuffer
);
926 if (HandleBuffer
!= NULL
) {
928 // Get the map name(s) for each one.
931 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
935 // Skip any that were already done...
937 if (gBS
->OpenProtocol(
938 HandleBuffer
[LoopVar
],
939 &gEfiDevicePathProtocolGuid
,
943 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
946 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
951 SHELL_FREE_NON_NULL(HandleBuffer
);
953 return (EFI_NOT_FOUND
);
955 return (EFI_SUCCESS
);
959 function to add a mapping from mapping.
961 This function will get the device path associated with the mapping and call SetMap.
963 @param[in] Map The Map to add a mapping for
964 @param[in] SName The name of the new mapping
966 @retval SHELL_SUCCESS the mapping was added
967 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
968 @return Shell version of a return value from EfiShellProtocol->SetMap
973 AddMappingFromMapping(
974 IN CONST CHAR16
*Map
,
975 IN CONST CHAR16
*SName
978 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
982 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
983 if (NewSName
== NULL
) {
984 return (SHELL_OUT_OF_RESOURCES
);
986 StrCpy(NewSName
, SName
);
987 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
988 StrCat(NewSName
, L
":");
991 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
993 return (SHELL_INVALID_PARAMETER
);
996 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
997 if (DevPath
== NULL
) {
999 return (SHELL_INVALID_PARAMETER
);
1002 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
1004 if (EFI_ERROR(Status
)) {
1005 return (SHELL_DEVICE_ERROR
);
1007 return (SHELL_SUCCESS
);
1011 function to add a mapping from an EFI_HANDLE.
1013 This function will get the device path associated with the Handle and call SetMap.
1015 @param[in] Handle The handle to add a mapping for
1016 @param[in] SName The name of the new mapping
1018 @retval SHELL_SUCCESS the mapping was added
1019 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
1020 @return Shell version of a return value from either
1021 gBS->OpenProtocol or EfiShellProtocol->SetMap
1026 AddMappingFromHandle(
1027 IN CONST EFI_HANDLE Handle
,
1028 IN CONST CHAR16
*SName
1031 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
1035 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
1036 if (NewSName
== NULL
) {
1037 return (SHELL_OUT_OF_RESOURCES
);
1039 StrCpy(NewSName
, SName
);
1040 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
1041 StrCat(NewSName
, L
":");
1044 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
1046 return (SHELL_INVALID_PARAMETER
);
1049 Status
= gBS
->OpenProtocol(
1051 &gEfiDevicePathProtocolGuid
,
1055 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1057 if (EFI_ERROR(Status
)) {
1059 return (SHELL_DEVICE_ERROR
);
1061 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
1063 if (EFI_ERROR(Status
)) {
1064 return (SHELL_DEVICE_ERROR
);
1066 return (SHELL_SUCCESS
);
1069 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
1077 {L
"-sfo", TypeValue
},
1082 Function for 'map' command.
1084 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1085 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1089 ShellCommandRunMap (
1090 IN EFI_HANDLE ImageHandle
,
1091 IN EFI_SYSTEM_TABLE
*SystemTable
1095 LIST_ENTRY
*Package
;
1096 CHAR16
*ProblemParam
;
1097 CONST CHAR16
*SName
;
1098 CONST CHAR16
*Mapping
;
1099 EFI_HANDLE MapAsHandle
;
1100 SHELL_STATUS ShellStatus
;
1104 CONST CHAR16
*Param1
;
1105 CONST CHAR16
*TypeString
;
1106 UINTN TempStringLength
;
1108 ProblemParam
= NULL
;
1111 ShellStatus
= SHELL_SUCCESS
;
1115 // initialize the shell lib (we must be in non-auto-init...)
1117 Status
= ShellInitialize();
1118 ASSERT_EFI_ERROR(Status
);
1120 Status
= CommandInit();
1121 ASSERT_EFI_ERROR(Status
);
1124 // parse the command line
1126 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1127 if (EFI_ERROR(Status
)) {
1128 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1129 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
1130 FreePool(ProblemParam
);
1131 ShellStatus
= SHELL_INVALID_PARAMETER
;
1139 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1140 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1141 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1142 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1144 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1145 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
1146 ShellStatus
= SHELL_INVALID_PARAMETER
;
1149 // Deleting a map name...
1151 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1152 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1153 || ShellCommandLineGetFlag(Package
, L
"-v")
1156 || ShellCommandLineGetFlag(Package
, L
"-u")
1157 || ShellCommandLineGetFlag(Package
, L
"-t")
1159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
1160 ShellStatus
= SHELL_INVALID_PARAMETER
;
1162 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1163 if (SName
!= NULL
) {
1164 Status
= PerformMappingDelete(SName
);
1165 if (EFI_ERROR(Status
)) {
1166 if (Status
== EFI_ACCESS_DENIED
) {
1167 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1168 ShellStatus
= SHELL_ACCESS_DENIED
;
1169 } else if (Status
== EFI_NOT_FOUND
) {
1170 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
1171 ShellStatus
= SHELL_INVALID_PARAMETER
;
1173 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1174 ShellStatus
= SHELL_UNSUPPORTED
;
1178 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
1179 ShellStatus
= SHELL_INVALID_PARAMETER
;
1182 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1183 // || ShellCommandLineGetFlag(Package, L"-v")
1186 || ShellCommandLineGetFlag(Package
, L
"-u")
1187 || ShellCommandLineGetFlag(Package
, L
"-t")
1189 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1193 Status
= ShellCommandCreateInitialMappingsAndPaths();
1194 if (EFI_ERROR(Status
)) {
1195 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1196 ShellStatus
= SHELL_UNSUPPORTED
;
1199 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1203 Status
= UpdateMapping();
1204 if (EFI_ERROR(Status
)) {
1205 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1206 ShellStatus
= SHELL_UNSUPPORTED
;
1209 if (ShellStatus
== SHELL_SUCCESS
) {
1210 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1211 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1214 &&TypeString
== NULL
1217 // now do the display...
1219 ShellStatus
= PerformMappingDisplay(
1220 ShellCommandLineGetFlag(Package
, L
"-v"),
1230 // now do the display...
1232 ShellStatus
= PerformMappingDisplay2(
1233 ShellCommandLineGetFlag(Package
, L
"-v"),
1244 // adding or displaying (there were no flags)
1246 SName
= ShellCommandLineGetRawValue(Package
, 1);
1247 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1252 // display only since no flags
1254 ShellStatus
= PerformMappingDisplay(
1255 ShellCommandLineGetFlag(Package
, L
"-v"),
1263 } else if ( SName
== NULL
1267 // Display only the one specified
1269 ShellStatus
= PerformMappingDisplay(
1275 SName
, // note the variable here...
1279 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1280 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1284 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1285 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1286 ShellStatus
= SHELL_INVALID_PARAMETER
;
1288 if (MapAsHandle
!= NULL
) {
1289 TempStringLength
= StrLen(SName
);
1290 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1291 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1292 ShellStatus
= SHELL_INVALID_PARAMETER
;
1294 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1297 TempStringLength
= StrLen(SName
);
1298 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1299 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1300 ShellStatus
= SHELL_INVALID_PARAMETER
;
1302 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1305 if (ShellStatus
!= SHELL_SUCCESS
) {
1306 switch (ShellStatus
) {
1307 case SHELL_ACCESS_DENIED
:
1308 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1310 case SHELL_INVALID_PARAMETER
:
1311 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1313 case SHELL_DEVICE_ERROR
:
1314 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, Mapping
);
1317 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1321 // now do the display...
1323 ShellStatus
= PerformMappingDisplay(
1332 } // we were sucessful so do an output
1333 } // got a valid map target
1334 } // got 2 variables
1335 } // we are adding a mapping
1336 } // got valid parameters
1340 // free the command line package
1342 ShellCommandLineFreeVarList (Package
);
1344 return (ShellStatus
);