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);
471 TempSpot
= StrStr(Alias
, CurrentName
);
472 if (TempSpot
!= NULL
) {
473 TempSpot2
= StrStr(TempSpot
, L
";");
474 if (TempSpot2
!= NULL
) {
475 TempSpot2
++; // Move past ";" from CurrentName
476 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
478 *TempSpot
= CHAR_NULL
;
481 if (Alias
[StrLen(Alias
)-1] == L
';') {
482 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
488 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
490 TempLen
= StrLen(CurrentName
);
495 STRING_TOKEN (STR_MAP_ENTRY
),
496 gShellLevel2HiiHandle
,
498 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
503 // also print handle, media type, removable (y/n), and current directory
505 MediaType
= GetDeviceMediaType(DevPath
);
506 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
507 Removable
= IsRemoveableDevice(DevPath
);
508 TempSpot2
= ShellGetCurrentDir(CurrentName
);
513 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
514 gShellLevel2HiiHandle
,
515 ConvertHandleToHandleIndex(Handle
),
517 Removable
?L
"Yes":L
"No",
521 SHELL_FREE_NON_NULL(MediaType
);
524 TempLen
= StrLen(CurrentName
);
529 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
530 gShellLevel2HiiHandle
,
533 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
536 SHELL_FREE_NON_NULL(DevPathString
);
537 SHELL_FREE_NON_NULL(CurrentName
);
538 SHELL_FREE_NON_NULL(Alias
);
543 Delete Specific from the list of maps for device Handle.
545 @param[in] Specific The name to delete.
546 @param[in] Handle The device to look on.
548 @retval EFI_SUCCESS The delete was successful.
549 @retval EFI_NOT_FOUND Name was not a map on Handle.
553 PerformSingleMappingDelete(
554 IN CONST CHAR16
*Specific
,
555 IN CONST EFI_HANDLE Handle
558 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
559 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
560 CONST CHAR16
*MapList
;
563 DevPath
= DevicePathFromHandle(Handle
);
564 DevPathCopy
= DevPath
;
565 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
568 if (MapList
== NULL
) {
569 return (EFI_NOT_FOUND
);
572 // if there is a specific and its not on the list...
574 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
575 return (EFI_NOT_FOUND
);
577 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
580 CONST CHAR16 Cd
[] = L
"cd*";
581 CONST CHAR16 Hd
[] = L
"hd*";
582 CONST CHAR16 Fp
[] = L
"fp*";
583 CONST CHAR16 AnyF
[] = L
"F*";
585 Function to display mapping information to the user.
587 If Specific is specified then Consist and Normal will be ignored since information will
588 be printed for the specific item only.
590 @param[in] Verbose TRUE to display (extra) verbose information.
591 @param[in] Consist TRUE to display consistent mappings.
592 @param[in] Normal TRUE to display normal (not consist) mappings.
593 @param[in] TypeString Pointer to string of filter types.
594 @param[in] SFO TRUE to display output in Standard Output Format.
595 @param[in] Specific Pointer to string for specific map to display.
596 @param[in] Header TRUE to print the header block.
598 @retval SHELL_SUCCESS The display was printed.
599 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
604 PerformMappingDisplay(
605 IN CONST BOOLEAN Verbose
,
606 IN CONST BOOLEAN Consist
,
607 IN CONST BOOLEAN Normal
,
608 IN CONST CHAR16
*TypeString
,
609 IN CONST BOOLEAN SFO
,
610 IN CONST CHAR16
*Specific OPTIONAL
,
611 IN CONST BOOLEAN Header
615 EFI_HANDLE
*HandleBuffer
;
621 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
622 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
623 return (SHELL_INVALID_PARAMETER
);
626 if (TypeString
!= NULL
) {
628 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
630 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
632 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
633 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, TypeString
);
634 return (SHELL_INVALID_PARAMETER
);
636 } else if (Test
== NULL
) {
637 Test
= (CHAR16
*)AnyF
;
649 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
651 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
659 // Look up all SimpleFileSystems in the platform
661 Status
= gBS
->LocateHandle(
663 &gEfiSimpleFileSystemProtocolGuid
,
667 if (Status
== EFI_BUFFER_TOO_SMALL
) {
668 HandleBuffer
= AllocateZeroPool(BufferSize
);
669 if (HandleBuffer
== NULL
) {
670 return (SHELL_OUT_OF_RESOURCES
);
672 Status
= gBS
->LocateHandle(
674 &gEfiSimpleFileSystemProtocolGuid
,
681 // Get the map name(s) for each one.
683 for ( LoopVar
= 0, Found
= FALSE
684 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
687 Status
= PerformSingleMappingDisplay(
694 HandleBuffer
[LoopVar
]);
695 if (!EFI_ERROR(Status
)) {
701 // Look up all BlockIo in the platform
703 Status
= gBS
->LocateHandle(
705 &gEfiBlockIoProtocolGuid
,
709 if (Status
== EFI_BUFFER_TOO_SMALL
) {
710 SHELL_FREE_NON_NULL(HandleBuffer
);
711 HandleBuffer
= AllocateZeroPool(BufferSize
);
712 if (HandleBuffer
== NULL
) {
713 return (SHELL_OUT_OF_RESOURCES
);
715 Status
= gBS
->LocateHandle(
717 &gEfiBlockIoProtocolGuid
,
722 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
724 // Get the map name(s) for each one.
727 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
731 // Skip any that were already done...
733 if (gBS
->OpenProtocol(
734 HandleBuffer
[LoopVar
],
735 &gEfiSimpleFileSystemProtocolGuid
,
739 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
742 Status
= PerformSingleMappingDisplay(
749 HandleBuffer
[LoopVar
]);
750 if (!EFI_ERROR(Status
)) {
754 FreePool(HandleBuffer
);
757 if (Specific
!= NULL
) {
758 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, Specific
);
760 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
);
763 return (SHELL_SUCCESS
);
767 Perform a mapping display and parse for multiple types in the TypeString.
769 @param[in] Verbose TRUE to use verbose output.
770 @param[in] Consist TRUE to display consistent names.
771 @param[in] Normal TRUE to display normal names.
772 @param[in] TypeString An optional comma-delimited list of types.
773 @param[in] SFO TRUE to display in SFO format. See Spec.
774 @param[in] Specific An optional specific map name to display alone.
776 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
777 @retval SHELL_SUCCESS The display was successful.
778 @sa PerformMappingDisplay
782 PerformMappingDisplay2(
783 IN CONST BOOLEAN Verbose
,
784 IN CONST BOOLEAN Consist
,
785 IN CONST BOOLEAN Normal
,
786 IN CONST CHAR16
*TypeString
,
787 IN CONST BOOLEAN SFO
,
788 IN CONST CHAR16
*Specific OPTIONAL
791 CONST CHAR16
*TypeWalker
;
792 SHELL_STATUS ShellStatus
;
796 if (TypeString
== NULL
) {
797 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
799 ShellStatus
= SHELL_SUCCESS
;
800 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
801 Comma
= StrStr(TypeWalker
, L
",");
803 if (ShellStatus
== SHELL_SUCCESS
) {
804 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
806 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
811 if (ShellStatus
== SHELL_SUCCESS
) {
812 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
814 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
817 TypeWalker
= Comma
+ 1;
821 return (ShellStatus
);
825 Delete a specific map.
827 @param[in] Specific The pointer to the name of the map to delete.
829 @retval EFI_INVALID_PARAMETER Specific was NULL.
830 @retval EFI_SUCCESS The operation was successful.
831 @retval EFI_NOT_FOUND Specific could not be found.
835 PerformMappingDelete(
836 IN CONST CHAR16
*Specific
840 EFI_HANDLE
*HandleBuffer
;
845 if (Specific
== NULL
) {
846 return (EFI_INVALID_PARAMETER
);
854 // Look up all SimpleFileSystems in the platform
856 Status
= gBS
->LocateHandle(
858 &gEfiDevicePathProtocolGuid
,
862 if (Status
== EFI_BUFFER_TOO_SMALL
) {
863 HandleBuffer
= AllocateZeroPool(BufferSize
);
864 if (HandleBuffer
== NULL
) {
865 return (EFI_OUT_OF_RESOURCES
);
867 Status
= gBS
->LocateHandle(
869 &gEfiDevicePathProtocolGuid
,
874 if (EFI_ERROR(Status
)) {
875 SHELL_FREE_NON_NULL(HandleBuffer
);
879 if (HandleBuffer
!= NULL
) {
881 // Get the map name(s) for each one.
884 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
887 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
893 // Look up all BlockIo in the platform
895 Status
= gBS
->LocateHandle(
897 &gEfiBlockIoProtocolGuid
,
901 if (Status
== EFI_BUFFER_TOO_SMALL
) {
902 FreePool(HandleBuffer
);
903 HandleBuffer
= AllocateZeroPool(BufferSize
);
904 if (HandleBuffer
== NULL
) {
905 return (EFI_OUT_OF_RESOURCES
);
907 Status
= gBS
->LocateHandle(
909 &gEfiBlockIoProtocolGuid
,
914 if (EFI_ERROR(Status
)) {
915 SHELL_FREE_NON_NULL(HandleBuffer
);
919 if (HandleBuffer
!= NULL
) {
921 // Get the map name(s) for each one.
924 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
928 // Skip any that were already done...
930 if (gBS
->OpenProtocol(
931 HandleBuffer
[LoopVar
],
932 &gEfiDevicePathProtocolGuid
,
936 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
939 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
944 SHELL_FREE_NON_NULL(HandleBuffer
);
946 return (EFI_NOT_FOUND
);
948 return (EFI_SUCCESS
);
952 function to add a mapping from mapping.
954 This function will get the device path associated with the mapping and call SetMap.
956 @param[in] Map The Map to add a mapping for
957 @param[in] SName The name of the new mapping
959 @retval SHELL_SUCCESS the mapping was added
960 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
961 @return Shell version of a return value from EfiShellProtocol->SetMap
966 AddMappingFromMapping(
967 IN CONST CHAR16
*Map
,
968 IN CONST CHAR16
*SName
971 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
975 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
976 if (NewSName
== NULL
) {
977 return (SHELL_OUT_OF_RESOURCES
);
979 StrCpy(NewSName
, SName
);
980 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
981 StrCat(NewSName
, L
":");
984 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
986 return (SHELL_INVALID_PARAMETER
);
989 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
990 if (DevPath
== NULL
) {
992 return (SHELL_INVALID_PARAMETER
);
995 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
997 if (EFI_ERROR(Status
)) {
998 return (SHELL_DEVICE_ERROR
);
1000 return (SHELL_SUCCESS
);
1004 function to add a mapping from an EFI_HANDLE.
1006 This function will get the device path associated with the Handle and call SetMap.
1008 @param[in] Handle The handle to add a mapping for
1009 @param[in] SName The name of the new mapping
1011 @retval SHELL_SUCCESS the mapping was added
1012 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
1013 @return Shell version of a return value from either
1014 gBS->OpenProtocol or EfiShellProtocol->SetMap
1019 AddMappingFromHandle(
1020 IN CONST EFI_HANDLE Handle
,
1021 IN CONST CHAR16
*SName
1024 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
1028 NewSName
= AllocateZeroPool(StrSize(SName
) + sizeof(CHAR16
));
1029 if (NewSName
== NULL
) {
1030 return (SHELL_OUT_OF_RESOURCES
);
1032 StrCpy(NewSName
, SName
);
1033 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
1034 StrCat(NewSName
, L
":");
1037 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
1039 return (SHELL_INVALID_PARAMETER
);
1042 Status
= gBS
->OpenProtocol(
1044 &gEfiDevicePathProtocolGuid
,
1048 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1050 if (EFI_ERROR(Status
)) {
1052 return (SHELL_DEVICE_ERROR
);
1054 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
1056 if (EFI_ERROR(Status
)) {
1057 return (SHELL_DEVICE_ERROR
);
1059 return (SHELL_SUCCESS
);
1062 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
1070 {L
"-sfo", TypeValue
},
1075 Function for 'map' command.
1077 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1078 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1082 ShellCommandRunMap (
1083 IN EFI_HANDLE ImageHandle
,
1084 IN EFI_SYSTEM_TABLE
*SystemTable
1088 LIST_ENTRY
*Package
;
1089 CHAR16
*ProblemParam
;
1090 CONST CHAR16
*SName
;
1091 CONST CHAR16
*Mapping
;
1092 EFI_HANDLE MapAsHandle
;
1093 SHELL_STATUS ShellStatus
;
1097 CONST CHAR16
*Param1
;
1098 CONST CHAR16
*TypeString
;
1099 UINTN TempStringLength
;
1101 ProblemParam
= NULL
;
1104 ShellStatus
= SHELL_SUCCESS
;
1108 // initialize the shell lib (we must be in non-auto-init...)
1110 Status
= ShellInitialize();
1111 ASSERT_EFI_ERROR(Status
);
1113 Status
= CommandInit();
1114 ASSERT_EFI_ERROR(Status
);
1117 // parse the command line
1119 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1120 if (EFI_ERROR(Status
)) {
1121 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1122 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
1123 FreePool(ProblemParam
);
1124 ShellStatus
= SHELL_INVALID_PARAMETER
;
1132 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1133 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1134 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1135 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1137 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1138 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
1139 ShellStatus
= SHELL_INVALID_PARAMETER
;
1142 // Deleting a map name...
1144 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1145 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1146 || ShellCommandLineGetFlag(Package
, L
"-v")
1149 || ShellCommandLineGetFlag(Package
, L
"-u")
1150 || ShellCommandLineGetFlag(Package
, L
"-t")
1152 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
1153 ShellStatus
= SHELL_INVALID_PARAMETER
;
1155 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1156 if (SName
!= NULL
) {
1157 Status
= PerformMappingDelete(SName
);
1158 if (EFI_ERROR(Status
)) {
1159 if (Status
== EFI_ACCESS_DENIED
) {
1160 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1161 ShellStatus
= SHELL_ACCESS_DENIED
;
1162 } else if (Status
== EFI_NOT_FOUND
) {
1163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
1164 ShellStatus
= SHELL_INVALID_PARAMETER
;
1166 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1167 ShellStatus
= SHELL_UNSUPPORTED
;
1171 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
1172 ShellStatus
= SHELL_INVALID_PARAMETER
;
1175 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1176 // || ShellCommandLineGetFlag(Package, L"-v")
1179 || ShellCommandLineGetFlag(Package
, L
"-u")
1180 || ShellCommandLineGetFlag(Package
, L
"-t")
1182 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1186 Status
= ShellCommandCreateInitialMappingsAndPaths();
1187 if (EFI_ERROR(Status
)) {
1188 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1189 ShellStatus
= SHELL_UNSUPPORTED
;
1192 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1196 Status
= UpdateMapping();
1197 if (EFI_ERROR(Status
)) {
1198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1199 ShellStatus
= SHELL_UNSUPPORTED
;
1202 if (ShellStatus
== SHELL_SUCCESS
) {
1203 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1204 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1207 &&TypeString
== NULL
1210 // now do the display...
1212 ShellStatus
= PerformMappingDisplay(
1213 ShellCommandLineGetFlag(Package
, L
"-v"),
1223 // now do the display...
1225 ShellStatus
= PerformMappingDisplay2(
1226 ShellCommandLineGetFlag(Package
, L
"-v"),
1237 // adding or displaying (there were no flags)
1239 SName
= ShellCommandLineGetRawValue(Package
, 1);
1240 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1245 // display only since no flags
1247 ShellStatus
= PerformMappingDisplay(
1248 ShellCommandLineGetFlag(Package
, L
"-v"),
1256 } else if ( SName
== NULL
1260 // Display only the one specified
1262 ShellStatus
= PerformMappingDisplay(
1268 SName
, // note the variable here...
1272 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1273 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1277 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1278 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1279 ShellStatus
= SHELL_INVALID_PARAMETER
;
1281 if (MapAsHandle
!= NULL
) {
1282 TempStringLength
= StrLen(SName
);
1283 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1284 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1285 ShellStatus
= SHELL_INVALID_PARAMETER
;
1287 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1290 TempStringLength
= StrLen(SName
);
1291 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1292 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1293 ShellStatus
= SHELL_INVALID_PARAMETER
;
1295 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1298 if (ShellStatus
!= SHELL_SUCCESS
) {
1299 switch (ShellStatus
) {
1300 case SHELL_ACCESS_DENIED
:
1301 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1303 case SHELL_INVALID_PARAMETER
:
1304 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1306 case SHELL_DEVICE_ERROR
:
1307 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, Mapping
);
1310 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1314 // now do the display...
1316 ShellStatus
= PerformMappingDisplay(
1325 } // we were sucessful so do an output
1326 } // got a valid map target
1327 } // got 2 variables
1328 } // we are adding a mapping
1329 } // got valid parameters
1333 // free the command line package
1335 ShellCommandLineFreeVarList (Package
);
1337 return (ShellStatus
);