2 Main file for map shell level 2 command.
4 (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel2CommandsLib.h"
17 #include <Protocol/SimpleFileSystem.h>
18 #include <Protocol/BlockIo.h>
19 #include <Library/DevicePathLib.h>
20 #include <Library/HandleParsingLib.h>
21 #include <Library/SortLib.h>
24 Determine if a string has only numbers and letters.
26 This is useful for such things as Map names which can only be letters and numbers.
28 @param[in] String pointer to the string to analyze,
29 @param[in] Len Number of characters to analyze.
31 @retval TRUE String has only numbers and letters
32 @retval FALSE String has at least one other character.
37 IN CONST CHAR16
*String
,
42 for (Count
= 0 ; Count
< Len
&& String
!= NULL
&& *String
!= CHAR_NULL
; String
++,Count
++) {
43 if (! ((*String
>= L
'a' && *String
<= L
'z') ||
44 (*String
>= L
'A' && *String
<= L
'Z') ||
45 (*String
>= L
'0' && *String
<= L
'9'))
54 Do a search in the Target delimited list.
56 @param[in] List The list to seatch in.
57 @param[in] MetaTarget The item to search for. MetaMatching supported.
58 @param[out] FullName Optional pointer to an allocated buffer containing
60 @param[in] Meta TRUE to use MetaMatching.
61 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.
62 @param[in] Target The single character that delimits list
68 IN CONST CHAR16
*List
,
69 IN CONST CHAR16
*MetaTarget
,
70 OUT CHAR16
**FullName OPTIONAL
,
71 IN CONST BOOLEAN Meta
,
72 IN CONST BOOLEAN SkipTrailingNumbers
,
73 IN CONST CHAR16
*Target
78 CONST CHAR16
*ListWalker
;
82 for (ListWalker
= List
, TempList
= NULL
83 ; ListWalker
!= NULL
&& *ListWalker
!= CHAR_NULL
86 TempList
= StrnCatGrow(&TempList
, NULL
, ListWalker
, 0);
87 ASSERT(TempList
!= NULL
);
88 TempSpot
= StrStr(TempList
, Target
);
89 if (TempSpot
!= NULL
) {
90 *TempSpot
= CHAR_NULL
;
93 while (SkipTrailingNumbers
&& (ShellIsDecimalDigitCharacter(TempList
[StrLen(TempList
)-1]) || TempList
[StrLen(TempList
)-1] == L
':')) {
94 TempList
[StrLen(TempList
)-1] = CHAR_NULL
;
97 ListWalker
= StrStr(ListWalker
, Target
);
98 while(ListWalker
!= NULL
&& *ListWalker
== *Target
) {
102 Result
= gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, (CHAR16
*)TempList
, (CHAR16
*)MetaTarget
);
104 Result
= (BOOLEAN
)(StrCmp(TempList
, MetaTarget
)==0);
107 if (FullName
!= NULL
) {
108 *FullName
= TempList
;
122 Determine what type of device is represented and return it's string. The
123 string is in allocated memory and must be callee freed. The HII is is listed below.
124 The actual string cannot be determined.
126 @param[in] DevicePath The device to analyze.
128 @retval STR_MAP_MEDIA_UNKNOWN The media type is unknown.
129 @retval STR_MAP_MEDIA_HARDDISK The media is a hard drive.
130 @retval STR_MAP_MEDIA_CDROM The media is a CD ROM.
131 @retval STR_MAP_MEDIA_FLOPPY The media is a floppy drive.
136 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
139 ACPI_HID_DEVICE_PATH
*Acpi
;
142 // Parse the device path:
143 // Devicepath sub type mediatype
144 // MEDIA_HANRDDRIVE_DP -> Hard Disk
145 // MEDIA_CDROM_DP -> CD Rom
146 // Acpi.HID = 0X0604 -> Floppy
148 if (NULL
== DevicePath
) {
149 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
152 for (;!IsDevicePathEndType (DevicePath
) ;DevicePath
= NextDevicePathNode (DevicePath
)) {
153 if (DevicePathType (DevicePath
) == MEDIA_DEVICE_PATH
) {
154 switch (DevicePathSubType (DevicePath
)) {
155 case MEDIA_HARDDRIVE_DP
:
156 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK
), NULL
);
158 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_CDROM
), NULL
);
160 } else if (DevicePathType (DevicePath
) == ACPI_DEVICE_PATH
) {
161 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePath
;
162 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
163 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY
), NULL
);
168 return HiiGetString(gShellLevel2HiiHandle
, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN
), NULL
);
172 Function to detemine if a handle has removable storage.
174 @param[in] DevicePath DevicePath to test.
176 @retval TRUE The handle has removable storage.
177 @retval FALSE The handle does not have removable storage.
182 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
185 if (NULL
== DevicePath
) {
189 while (!IsDevicePathEndType (DevicePath
)) {
190 if (DevicePathType (DevicePath
) == MESSAGING_DEVICE_PATH
) {
191 switch (DevicePathSubType (DevicePath
)) {
199 DevicePath
= NextDevicePathNode (DevicePath
);
205 Function to detemine if a something on the map list matches.
207 @param[in] MapList The pointer to the list to test.
208 @param[in] Specific The pointer to a specific name to test for.
209 @param[in] TypeString The pointer to the list of types.
210 @param[in] Normal Always show normal mappings.
211 @param[in] Consist Always show consistent mappings.
213 @retval TRUE The map should be displayed.
214 @retval FALSE The map should not be displayed.
219 IN CONST CHAR16
*MapList
,
220 IN CONST CHAR16
*Specific
,
221 IN CONST CHAR16
*TypeString
,
222 IN CONST BOOLEAN Normal
,
223 IN CONST BOOLEAN Consist
228 // specific has priority
230 if (Specific
!= NULL
) {
231 NewSpecific
= AllocateCopyPool(StrSize(Specific
) + sizeof(CHAR16
), Specific
);
232 if (NewSpecific
== NULL
){
235 if (NewSpecific
[StrLen(NewSpecific
)-1] != L
':') {
236 StrnCat(NewSpecific
, L
":", 2);
239 if (SearchList(MapList
, NewSpecific
, NULL
, TRUE
, FALSE
, L
";")) {
240 FreePool(NewSpecific
);
243 FreePool(NewSpecific
);
247 && (SearchList(MapList
, L
"HD*", NULL
, TRUE
, TRUE
, L
";")
248 ||SearchList(MapList
, L
"CD*", NULL
, TRUE
, TRUE
, L
";")
249 ||SearchList(MapList
, L
"F*", NULL
, TRUE
, TRUE
, L
";")
250 ||SearchList(MapList
, L
"FP*", NULL
, TRUE
, TRUE
, L
";"))){
256 && (SearchList(MapList
, L
"FS", NULL
, FALSE
, TRUE
, L
";")
257 ||SearchList(MapList
, L
"BLK", NULL
, FALSE
, TRUE
, L
";"))){
261 if (TypeString
!= NULL
&& SearchList(MapList
, TypeString
, NULL
, TRUE
, TRUE
, L
";")) {
269 Display a single map line for device Handle if conditions are met.
271 @param[in] Verbose TRUE to display (extra) verbose information.
272 @param[in] Consist TRUE to display consistent mappings.
273 @param[in] Normal TRUE to display normal (not consist) mappings.
274 @param[in] TypeString pointer to string of filter types.
275 @param[in] SFO TRUE to display output in Standard Output Format.
276 @param[in] Specific pointer to string for specific map to display.
277 @param[in] Handle The handle to display from.
279 @retval EFI_SUCCESS The mapping was displayed.
283 PerformSingleMappingDisplay(
284 IN CONST BOOLEAN Verbose
,
285 IN CONST BOOLEAN Consist
,
286 IN CONST BOOLEAN Normal
,
287 IN CONST CHAR16
*TypeString
,
288 IN CONST BOOLEAN SFO
,
289 IN CONST CHAR16
*Specific OPTIONAL
,
290 IN CONST EFI_HANDLE Handle
293 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
294 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
295 CONST CHAR16
*MapList
;
298 CHAR16
*DevPathString
;
303 CONST CHAR16
*TempSpot2
;
308 DevPath
= DevicePathFromHandle(Handle
);
309 DevPathCopy
= DevPath
;
310 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
311 if (MapList
== NULL
) {
312 return EFI_NOT_FOUND
;
315 if (!MappingListHasType(MapList
, Specific
, TypeString
, Normal
, Consist
)){
316 return EFI_NOT_FOUND
;
319 if (Normal
|| !Consist
) {
321 // need the Normal here since people can use both on command line. otherwise unused.
328 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
329 if (CurrentName
== NULL
) {
330 return (EFI_OUT_OF_RESOURCES
);
334 // Chop off the other names that become "Alias(s)"
335 // leaving just the normal name
337 TempSpot
= StrStr(CurrentName
, L
";");
338 if (TempSpot
!= NULL
) {
339 *TempSpot
= CHAR_NULL
;
345 // Skip the first name. This is the standard name.
347 TempSpot
= StrStr(MapList
, L
";");
348 if (TempSpot
!= NULL
) {
351 SearchList(TempSpot
, L
"HD*", &CurrentName
, TRUE
, FALSE
, L
";");
352 if (CurrentName
== NULL
) {
353 SearchList(TempSpot
, L
"CD*", &CurrentName
, TRUE
, FALSE
, L
";");
355 if (CurrentName
== NULL
) {
356 SearchList(TempSpot
, L
"FP*", &CurrentName
, TRUE
, FALSE
, L
";");
358 if (CurrentName
== NULL
) {
359 SearchList(TempSpot
, L
"F*", &CurrentName
, TRUE
, FALSE
, L
";");
361 if (CurrentName
== NULL
) {
363 // We didnt find anything, so just the first one in the list...
365 CurrentName
= StrnCatGrow(&CurrentName
, 0, MapList
, 0);
366 if (CurrentName
== NULL
) {
367 return (EFI_OUT_OF_RESOURCES
);
369 TempSpot
= StrStr(CurrentName
, L
";");
370 if (TempSpot
!= NULL
) {
371 *TempSpot
= CHAR_NULL
;
374 Alias
= StrnCatGrow(&Alias
, 0, MapList
, 0);
376 return EFI_OUT_OF_RESOURCES
;
378 TempSpot
= StrStr(Alias
, CurrentName
);
379 if (TempSpot
!= NULL
) {
380 TempSpot2
= StrStr(TempSpot
, L
";");
381 if (TempSpot2
!= NULL
) {
382 TempSpot2
++; // Move past ";" from CurrentName
383 CopyMem(TempSpot
, TempSpot2
, StrSize(TempSpot2
));
385 *TempSpot
= CHAR_NULL
;
388 if (Alias
[StrLen(Alias
)-1] == L
';') {
389 Alias
[StrLen(Alias
)-1] = CHAR_NULL
;
393 DevPathString
= ConvertDevicePathToText(DevPath
, TRUE
, FALSE
);
394 TempLen
= StrLen(CurrentName
);
400 STRING_TOKEN (STR_MAP_ENTRY
),
401 gShellLevel2HiiHandle
,
403 Alias
!=NULL
?Alias
:(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
""),
408 // also print handle, media type, removable (y/n), and current directory
410 MediaType
= GetDeviceMediaType(DevPath
);
411 if ((TypeString
!= NULL
&&MediaType
!= NULL
&& StrStr(TypeString
, MediaType
) != NULL
) || TypeString
== NULL
) {
412 Removable
= IsRemoveableDevice(DevPath
);
413 TempSpot2
= ShellGetCurrentDir(CurrentName
);
418 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE
),
419 gShellLevel2HiiHandle
,
420 ConvertHandleToHandleIndex(Handle
),
422 Removable
?L
"Yes":L
"No",
426 SHELL_FREE_NON_NULL(MediaType
);
433 STRING_TOKEN (STR_MAP_SFO_MAPPINGS
),
434 gShellLevel2HiiHandle
,
437 Consist
?L
"":(TempLen
< StrLen(MapList
)?MapList
+ TempLen
+1:L
"")
440 SHELL_FREE_NON_NULL(DevPathString
);
441 SHELL_FREE_NON_NULL(CurrentName
);
442 SHELL_FREE_NON_NULL(Alias
);
447 Delete Specific from the list of maps for device Handle.
449 @param[in] Specific The name to delete.
450 @param[in] Handle The device to look on.
452 @retval EFI_SUCCESS The delete was successful.
453 @retval EFI_NOT_FOUND Name was not a map on Handle.
457 PerformSingleMappingDelete(
458 IN CONST CHAR16
*Specific
,
459 IN CONST EFI_HANDLE Handle
462 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
463 EFI_DEVICE_PATH_PROTOCOL
*DevPathCopy
;
464 CONST CHAR16
*MapList
;
467 DevPath
= DevicePathFromHandle(Handle
);
468 DevPathCopy
= DevPath
;
469 MapList
= gEfiShellProtocol
->GetMapFromDevicePath(&DevPathCopy
);
472 if (MapList
== NULL
) {
473 return (EFI_NOT_FOUND
);
476 // if there is a specific and its not on the list...
478 if (!SearchList(MapList
, Specific
, &CurrentName
, TRUE
, FALSE
, L
";")) {
479 return (EFI_NOT_FOUND
);
481 return (gEfiShellProtocol
->SetMap(NULL
, CurrentName
));
484 CONST CHAR16 Cd
[] = L
"cd*";
485 CONST CHAR16 Hd
[] = L
"hd*";
486 CONST CHAR16 Fp
[] = L
"fp*";
487 CONST CHAR16 AnyF
[] = L
"F*";
489 Function to display mapping information to the user.
491 If Specific is specified then Consist and Normal will be ignored since information will
492 be printed for the specific item only.
494 @param[in] Verbose TRUE to display (extra) verbose information.
495 @param[in] Consist TRUE to display consistent mappings.
496 @param[in] Normal TRUE to display normal (not consist) mappings.
497 @param[in] TypeString Pointer to string of filter types.
498 @param[in] SFO TRUE to display output in Standard Output Format.
499 @param[in] Specific Pointer to string for specific map to display.
500 @param[in] Header TRUE to print the header block.
502 @retval SHELL_SUCCESS The display was printed.
503 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
508 PerformMappingDisplay(
509 IN CONST BOOLEAN Verbose
,
510 IN CONST BOOLEAN Consist
,
511 IN CONST BOOLEAN Normal
,
512 IN CONST CHAR16
*TypeString
,
513 IN CONST BOOLEAN SFO
,
514 IN CONST CHAR16
*Specific OPTIONAL
,
515 IN CONST BOOLEAN Header
519 EFI_HANDLE
*HandleBuffer
;
525 if (!Consist
&& !Normal
&& Specific
== NULL
&& TypeString
== NULL
) {
526 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
527 return (SHELL_INVALID_PARAMETER
);
530 if (TypeString
!= NULL
) {
532 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
534 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
536 if (StrnCmp(TypeString
, Test
, StrLen(Test
)-1) != 0) {
537 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, TypeString
);
538 return (SHELL_INVALID_PARAMETER
);
540 } else if (Test
== NULL
) {
541 Test
= (CHAR16
*)AnyF
;
553 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_HEADER
), gShellLevel2HiiHandle
);
555 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"map");
563 // Look up all SimpleFileSystems in the platform
565 Status
= gBS
->LocateHandle(
567 &gEfiSimpleFileSystemProtocolGuid
,
571 if (Status
== EFI_BUFFER_TOO_SMALL
) {
572 HandleBuffer
= AllocateZeroPool(BufferSize
);
573 if (HandleBuffer
== NULL
) {
574 return (SHELL_OUT_OF_RESOURCES
);
576 Status
= gBS
->LocateHandle(
578 &gEfiSimpleFileSystemProtocolGuid
,
585 // Get the map name(s) for each one.
587 for ( LoopVar
= 0, Found
= FALSE
588 ; LoopVar
< (BufferSize
/ sizeof(EFI_HANDLE
)) && HandleBuffer
!= NULL
591 Status
= PerformSingleMappingDisplay(
598 HandleBuffer
[LoopVar
]);
599 if (!EFI_ERROR(Status
)) {
605 // Look up all BlockIo in the platform
607 Status
= gBS
->LocateHandle(
609 &gEfiBlockIoProtocolGuid
,
613 if (Status
== EFI_BUFFER_TOO_SMALL
) {
614 SHELL_FREE_NON_NULL(HandleBuffer
);
615 HandleBuffer
= AllocateZeroPool(BufferSize
);
616 if (HandleBuffer
== NULL
) {
617 return (SHELL_OUT_OF_RESOURCES
);
619 Status
= gBS
->LocateHandle(
621 &gEfiBlockIoProtocolGuid
,
626 if (!EFI_ERROR(Status
) && HandleBuffer
!= NULL
) {
628 // Get the map name(s) for each one.
631 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
635 // Skip any that were already done...
637 if (gBS
->OpenProtocol(
638 HandleBuffer
[LoopVar
],
639 &gEfiSimpleFileSystemProtocolGuid
,
643 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
646 Status
= PerformSingleMappingDisplay(
653 HandleBuffer
[LoopVar
]);
654 if (!EFI_ERROR(Status
)) {
658 FreePool(HandleBuffer
);
661 if (Specific
!= NULL
) {
662 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, Specific
);
664 ShellPrintHiiEx(gST
->ConOut
->Mode
->CursorColumn
, gST
->ConOut
->Mode
->CursorRow
-1, NULL
, STRING_TOKEN (STR_CD_NF
), gShellLevel2HiiHandle
);
667 return (SHELL_SUCCESS
);
671 Perform a mapping display and parse for multiple types in the TypeString.
673 @param[in] Verbose TRUE to use verbose output.
674 @param[in] Consist TRUE to display consistent names.
675 @param[in] Normal TRUE to display normal names.
676 @param[in] TypeString An optional comma-delimited list of types.
677 @param[in] SFO TRUE to display in SFO format. See Spec.
678 @param[in] Specific An optional specific map name to display alone.
680 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
681 @retval SHELL_SUCCESS The display was successful.
682 @sa PerformMappingDisplay
686 PerformMappingDisplay2(
687 IN CONST BOOLEAN Verbose
,
688 IN CONST BOOLEAN Consist
,
689 IN CONST BOOLEAN Normal
,
690 IN CONST CHAR16
*TypeString
,
691 IN CONST BOOLEAN SFO
,
692 IN CONST CHAR16
*Specific OPTIONAL
695 CONST CHAR16
*TypeWalker
;
696 SHELL_STATUS ShellStatus
;
700 if (TypeString
== NULL
) {
701 return (PerformMappingDisplay(Verbose
, Consist
, Normal
, NULL
, SFO
, Specific
, TRUE
));
703 ShellStatus
= SHELL_SUCCESS
;
704 for (TypeWalker
= TypeString
; TypeWalker
!= NULL
&& *TypeWalker
!= CHAR_NULL
;) {
705 Comma
= StrStr(TypeWalker
, L
",");
707 if (ShellStatus
== SHELL_SUCCESS
) {
708 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
710 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
715 if (ShellStatus
== SHELL_SUCCESS
) {
716 ShellStatus
= PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
718 PerformMappingDisplay(Verbose
, Consist
, Normal
, TypeWalker
, SFO
, Specific
, (BOOLEAN
)(TypeWalker
== TypeString
));
721 TypeWalker
= Comma
+ 1;
725 return (ShellStatus
);
729 Delete a specific map.
731 @param[in] Specific The pointer to the name of the map to delete.
733 @retval EFI_INVALID_PARAMETER Specific was NULL.
734 @retval EFI_SUCCESS The operation was successful.
735 @retval EFI_NOT_FOUND Specific could not be found.
739 PerformMappingDelete(
740 IN CONST CHAR16
*Specific
744 EFI_HANDLE
*HandleBuffer
;
749 if (Specific
== NULL
) {
750 return (EFI_INVALID_PARAMETER
);
758 // Look up all SimpleFileSystems in the platform
760 Status
= gBS
->LocateHandle(
762 &gEfiDevicePathProtocolGuid
,
766 if (Status
== EFI_BUFFER_TOO_SMALL
) {
767 HandleBuffer
= AllocateZeroPool(BufferSize
);
768 if (HandleBuffer
== NULL
) {
769 return (EFI_OUT_OF_RESOURCES
);
771 Status
= gBS
->LocateHandle(
773 &gEfiDevicePathProtocolGuid
,
778 if (EFI_ERROR(Status
)) {
779 SHELL_FREE_NON_NULL(HandleBuffer
);
783 if (HandleBuffer
!= NULL
) {
785 // Get the map name(s) for each one.
788 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
791 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
797 // Look up all BlockIo in the platform
799 Status
= gBS
->LocateHandle(
801 &gEfiBlockIoProtocolGuid
,
805 if (Status
== EFI_BUFFER_TOO_SMALL
) {
806 FreePool(HandleBuffer
);
807 HandleBuffer
= AllocateZeroPool(BufferSize
);
808 if (HandleBuffer
== NULL
) {
809 return (EFI_OUT_OF_RESOURCES
);
811 Status
= gBS
->LocateHandle(
813 &gEfiBlockIoProtocolGuid
,
818 if (EFI_ERROR(Status
)) {
819 SHELL_FREE_NON_NULL(HandleBuffer
);
823 if (HandleBuffer
!= NULL
) {
825 // Get the map name(s) for each one.
828 ; LoopVar
< BufferSize
/ sizeof(EFI_HANDLE
)
832 // Skip any that were already done...
834 if (gBS
->OpenProtocol(
835 HandleBuffer
[LoopVar
],
836 &gEfiDevicePathProtocolGuid
,
840 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
) == EFI_SUCCESS
) {
843 if (PerformSingleMappingDelete(Specific
,HandleBuffer
[LoopVar
]) == SHELL_SUCCESS
) {
848 SHELL_FREE_NON_NULL(HandleBuffer
);
850 return (EFI_NOT_FOUND
);
852 return (EFI_SUCCESS
);
856 function to add a mapping from mapping.
858 This function will get the device path associated with the mapping and call SetMap.
860 @param[in] Map The Map to add a mapping for
861 @param[in] SName The name of the new mapping
863 @retval SHELL_SUCCESS the mapping was added
864 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
865 @return Shell version of a return value from EfiShellProtocol->SetMap
870 AddMappingFromMapping(
871 IN CONST CHAR16
*Map
,
872 IN CONST CHAR16
*SName
875 CONST EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
879 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
880 if (NewSName
== NULL
) {
881 return (SHELL_OUT_OF_RESOURCES
);
883 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
884 StrnCat(NewSName
, L
":", 2);
887 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
889 return (SHELL_INVALID_PARAMETER
);
892 DevPath
= gEfiShellProtocol
->GetDevicePathFromMap(Map
);
893 if (DevPath
== NULL
) {
895 return (SHELL_INVALID_PARAMETER
);
898 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
900 if (EFI_ERROR(Status
)) {
901 return (SHELL_DEVICE_ERROR
);
903 return (SHELL_SUCCESS
);
907 function to add a mapping from an EFI_HANDLE.
909 This function will get the device path associated with the Handle and call SetMap.
911 @param[in] Handle The handle to add a mapping for
912 @param[in] SName The name of the new mapping
914 @retval SHELL_SUCCESS the mapping was added
915 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
916 @return Shell version of a return value from either
917 gBS->OpenProtocol or EfiShellProtocol->SetMap
922 AddMappingFromHandle(
923 IN CONST EFI_HANDLE Handle
,
924 IN CONST CHAR16
*SName
927 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
931 NewSName
= AllocateCopyPool(StrSize(SName
) + sizeof(CHAR16
), SName
);
932 if (NewSName
== NULL
) {
933 return (SHELL_OUT_OF_RESOURCES
);
935 if (NewSName
[StrLen(NewSName
)-1] != L
':') {
936 StrnCat(NewSName
, L
":", 2);
939 if (!IsNumberLetterOnly(NewSName
, StrLen(NewSName
)-1)) {
941 return (SHELL_INVALID_PARAMETER
);
944 Status
= gBS
->OpenProtocol(
946 &gEfiDevicePathProtocolGuid
,
950 EFI_OPEN_PROTOCOL_GET_PROTOCOL
952 if (EFI_ERROR(Status
)) {
954 return (SHELL_DEVICE_ERROR
);
956 Status
= gEfiShellProtocol
->SetMap(DevPath
, NewSName
);
958 if (EFI_ERROR(Status
)) {
959 return (SHELL_DEVICE_ERROR
);
961 return (SHELL_SUCCESS
);
964 STATIC CONST SHELL_PARAM_ITEM MapParamList
[] = {
972 {L
"-sfo", TypeValue
},
977 Function for 'map' command.
979 @param[in] ImageHandle Handle to the Image (NULL if Internal).
980 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
985 IN EFI_HANDLE ImageHandle
,
986 IN EFI_SYSTEM_TABLE
*SystemTable
991 CHAR16
*ProblemParam
;
993 CONST CHAR16
*Mapping
;
994 EFI_HANDLE MapAsHandle
;
995 SHELL_STATUS ShellStatus
;
999 CONST CHAR16
*Param1
;
1000 CONST CHAR16
*TypeString
;
1001 UINTN TempStringLength
;
1003 ProblemParam
= NULL
;
1006 ShellStatus
= SHELL_SUCCESS
;
1010 // initialize the shell lib (we must be in non-auto-init...)
1012 Status
= ShellInitialize();
1013 ASSERT_EFI_ERROR(Status
);
1015 Status
= CommandInit();
1016 ASSERT_EFI_ERROR(Status
);
1019 // parse the command line
1021 Status
= ShellCommandLineParse (MapParamList
, &Package
, &ProblemParam
, TRUE
);
1022 if (EFI_ERROR(Status
)) {
1023 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
1024 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
1025 FreePool(ProblemParam
);
1026 ShellStatus
= SHELL_INVALID_PARAMETER
;
1034 SfoMode
= ShellCommandLineGetFlag(Package
, L
"-sfo");
1035 ConstMode
= ShellCommandLineGetFlag(Package
, L
"-c");
1036 NormlMode
= ShellCommandLineGetFlag(Package
, L
"-f");
1037 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
1039 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
1040 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
1041 ShellStatus
= SHELL_INVALID_PARAMETER
;
1044 // Deleting a map name...
1046 if (ShellCommandLineGetFlag(Package
, L
"-d")) {
1047 if ( ShellCommandLineGetFlag(Package
, L
"-r")
1048 || ShellCommandLineGetFlag(Package
, L
"-v")
1051 || ShellCommandLineGetFlag(Package
, L
"-u")
1052 || ShellCommandLineGetFlag(Package
, L
"-t")
1054 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
1055 ShellStatus
= SHELL_INVALID_PARAMETER
;
1057 SName
= ShellCommandLineGetValue(Package
, L
"-d");
1058 if (SName
!= NULL
) {
1059 Status
= PerformMappingDelete(SName
);
1060 if (EFI_ERROR(Status
)) {
1061 if (Status
== EFI_ACCESS_DENIED
) {
1062 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1063 ShellStatus
= SHELL_ACCESS_DENIED
;
1064 } else if (Status
== EFI_NOT_FOUND
) {
1065 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NF
), gShellLevel2HiiHandle
, SName
);
1066 ShellStatus
= SHELL_INVALID_PARAMETER
;
1068 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1069 ShellStatus
= SHELL_UNSUPPORTED
;
1073 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
1074 ShellStatus
= SHELL_INVALID_PARAMETER
;
1077 } else if ( ShellCommandLineGetFlag(Package
, L
"-r")
1078 // || ShellCommandLineGetFlag(Package, L"-v")
1081 || ShellCommandLineGetFlag(Package
, L
"-u")
1082 || ShellCommandLineGetFlag(Package
, L
"-t")
1084 if ( ShellCommandLineGetFlag(Package
, L
"-r")) {
1088 Status
= ShellCommandCreateInitialMappingsAndPaths();
1089 if (EFI_ERROR(Status
)) {
1090 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1091 ShellStatus
= SHELL_UNSUPPORTED
;
1094 if ( ShellStatus
== SHELL_SUCCESS
&& ShellCommandLineGetFlag(Package
, L
"-u")) {
1098 Status
= ShellCommandUpdateMapping ();
1099 if (EFI_ERROR(Status
)) {
1100 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
1101 ShellStatus
= SHELL_UNSUPPORTED
;
1104 if (ShellStatus
== SHELL_SUCCESS
) {
1105 Param1
= ShellCommandLineGetRawValue(Package
, 1);
1106 TypeString
= ShellCommandLineGetValue(Package
, L
"-t");
1109 &&TypeString
== NULL
1112 // now do the display...
1114 ShellStatus
= PerformMappingDisplay(
1115 ShellCommandLineGetFlag(Package
, L
"-v"),
1125 // now do the display...
1127 ShellStatus
= PerformMappingDisplay2(
1128 ShellCommandLineGetFlag(Package
, L
"-v"),
1139 // adding or displaying (there were no flags)
1141 SName
= ShellCommandLineGetRawValue(Package
, 1);
1142 Mapping
= ShellCommandLineGetRawValue(Package
, 2);
1147 // display only since no flags
1149 ShellStatus
= PerformMappingDisplay(
1150 ShellCommandLineGetFlag(Package
, L
"-v"),
1158 } else if ( SName
== NULL
1162 // Display only the one specified
1164 ShellStatus
= PerformMappingDisplay(
1170 SName
, // note the variable here...
1174 if (ShellIsHexOrDecimalNumber(Mapping
, TRUE
, FALSE
)) {
1175 MapAsHandle
= ConvertHandleIndexToHandle(ShellStrToUintn(Mapping
));
1179 if (MapAsHandle
== NULL
&& Mapping
[StrLen(Mapping
)-1] != L
':') {
1180 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Mapping
);
1181 ShellStatus
= SHELL_INVALID_PARAMETER
;
1183 if (MapAsHandle
!= NULL
) {
1184 TempStringLength
= StrLen(SName
);
1185 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1186 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1187 ShellStatus
= SHELL_INVALID_PARAMETER
;
1189 ShellStatus
= AddMappingFromHandle(MapAsHandle
, SName
);
1192 TempStringLength
= StrLen(SName
);
1193 if (!IsNumberLetterOnly(SName
, TempStringLength
-(SName
[TempStringLength
-1]==L
':'?1:0))) {
1194 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, SName
);
1195 ShellStatus
= SHELL_INVALID_PARAMETER
;
1197 ShellStatus
= AddMappingFromMapping(Mapping
, SName
);
1200 if (ShellStatus
!= SHELL_SUCCESS
) {
1201 switch (ShellStatus
) {
1202 case SHELL_ACCESS_DENIED
:
1203 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel2HiiHandle
);
1205 case SHELL_INVALID_PARAMETER
:
1206 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
);
1208 case SHELL_DEVICE_ERROR
:
1209 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MAP_NOF
), gShellLevel2HiiHandle
, Mapping
);
1212 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, ShellStatus
|MAX_BIT
);
1216 // now do the display...
1218 ShellStatus
= PerformMappingDisplay(
1227 } // we were sucessful so do an output
1228 } // got a valid map target
1229 } // got 2 variables
1230 } // we are adding a mapping
1231 } // got valid parameters
1235 // free the command line package
1237 ShellCommandLineFreeVarList (Package
);
1239 return (ShellStatus
);