]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg: Correctly support "map -c"
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Map.c
1 /** @file
2 Main file for map shell level 2 command.
3
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
9
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.
12
13 **/
14
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>
21
22 /**
23 Determine if a string has only numbers and letters.
24
25 This is useful for such things as Map names which can only be letters and numbers.
26
27 @param[in] String pointer to the string to analyze,
28 @param[in] Len Number of characters to analyze.
29
30 @retval TRUE String has only numbers and letters
31 @retval FALSE String has at least one other character.
32 **/
33 BOOLEAN
34 EFIAPI
35 IsNumberLetterOnly(
36 IN CONST CHAR16 *String,
37 IN CONST UINTN Len
38 )
39 {
40 UINTN Count;
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'))
45 ){
46 return (FALSE);
47 }
48 }
49 return (TRUE);
50 }
51
52 /**
53 Do a search in the Target delimited list.
54
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
58 the match.
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
62 items (";" normally).
63 **/
64 BOOLEAN
65 EFIAPI
66 SearchList(
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
73
74 )
75 {
76 CHAR16 *TempList;
77 CONST CHAR16 *ListWalker;
78 BOOLEAN Result;
79 CHAR16 *TempSpot;
80
81 for (ListWalker = List , TempList = NULL
82 ; ListWalker != NULL && *ListWalker != CHAR_NULL
83 ;
84 ) {
85 TempList = StrnCatGrow(&TempList, NULL, ListWalker, 0);
86 ASSERT(TempList != NULL);
87 TempSpot = StrStr(TempList, Target);
88 if (TempSpot != NULL) {
89 *TempSpot = CHAR_NULL;
90 }
91
92 while (SkipTrailingNumbers && (ShellIsDecimalDigitCharacter(TempList[StrLen(TempList)-1]) || TempList[StrLen(TempList)-1] == L':')) {
93 TempList[StrLen(TempList)-1] = CHAR_NULL;
94 }
95
96 ListWalker = StrStr(ListWalker, Target);
97 while(ListWalker != NULL && *ListWalker == *Target) {
98 ListWalker++;
99 }
100 if (Meta) {
101 Result = gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16*)TempList, (CHAR16*)MetaTarget);
102 } else {
103 Result = (BOOLEAN)(StrCmp(TempList, MetaTarget)==0);
104 }
105 if (Result) {
106 if (FullName != NULL) {
107 *FullName = TempList;
108 } else {
109 FreePool(TempList);
110 }
111 return (TRUE);
112 }
113 FreePool(TempList);
114 TempList = NULL;
115 }
116
117 return (FALSE);
118 }
119
120 /**
121 Add mappings for any devices without one. Do not change any existing maps.
122
123 @retval EFI_SUCCESS The operation was successful.
124 **/
125 EFI_STATUS
126 EFIAPI
127 UpdateMapping (
128 VOID
129 )
130 {
131 EFI_STATUS Status;
132 EFI_HANDLE *HandleList;
133 UINTN Count;
134 EFI_DEVICE_PATH_PROTOCOL **DevicePathList;
135 CHAR16 *NewDefaultName;
136 CHAR16 *NewConsistName;
137 EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable;
138
139 HandleList = NULL;
140 Status = EFI_SUCCESS;
141
142 //
143 // remove mappings that represent removed devices.
144 //
145
146 //
147 // Find each handle with Simple File System
148 //
149 HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
150 if (HandleList != NULL) {
151 //
152 // Do a count of the handles
153 //
154 for (Count = 0 ; HandleList[Count] != NULL ; Count++);
155
156 //
157 // Get all Device Paths
158 //
159 DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
160 ASSERT(DevicePathList != NULL);
161
162 for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
163 DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
164 }
165
166 //
167 // Sort all DevicePaths
168 //
169 PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
170
171 ShellCommandConsistMappingInitialize(&ConsistMappingTable);
172
173 //
174 // Assign new Mappings to remainders
175 //
176 for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
177 //
178 // Skip ones that already have
179 //
180 if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
181 continue;
182 }
183 //
184 // Get default name
185 //
186 NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
187 ASSERT(NewDefaultName != NULL);
188
189 //
190 // Call shell protocol SetMap function now...
191 //
192 Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
193
194 if (!EFI_ERROR(Status)) {
195 //
196 // Now do consistent name
197 //
198 NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
199 if (NewConsistName != NULL) {
200 Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
201 FreePool(NewConsistName);
202 }
203 }
204
205 FreePool(NewDefaultName);
206 }
207 ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
208 SHELL_FREE_NON_NULL(HandleList);
209 SHELL_FREE_NON_NULL(DevicePathList);
210
211 HandleList = NULL;
212 } else {
213 Count = (UINTN)-1;
214 }
215 //
216 // Do it all over again for gEfiBlockIoProtocolGuid
217 //
218
219 return (Status);
220 }
221
222 /**
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.
226
227 @param[in] DevicePath The device to analyze.
228
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.
233 **/
234 CHAR16*
235 EFIAPI
236 GetDeviceMediaType (
237 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
238 )
239 {
240 ACPI_HID_DEVICE_PATH *Acpi;
241
242 //
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
248 //
249 if (NULL == DevicePath) {
250 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);
251 }
252
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);
258 case MEDIA_CDROM_DP:
259 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_CDROM), NULL);
260 }
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);
265 }
266 }
267 }
268
269 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);
270 }
271
272 /**
273 Function to detemine if a handle has removable storage.
274
275 @param[in] DevicePath DevicePath to test.
276
277 @retval TRUE The handle has removable storage.
278 @retval FALSE The handle does not have removable storage.
279 **/
280 BOOLEAN
281 EFIAPI
282 IsRemoveableDevice (
283 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
284 )
285 {
286 if (NULL == DevicePath) {
287 return FALSE;
288 }
289
290 while (!IsDevicePathEndType (DevicePath)) {
291 if (DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) {
292 switch (DevicePathSubType (DevicePath)) {
293 case MSG_USB_DP:
294 case MSG_SCSI_DP:
295 return TRUE;
296 default:
297 return FALSE;
298 }
299 }
300 DevicePath = NextDevicePathNode (DevicePath);
301 }
302 return FALSE;
303 }
304
305 /**
306 Function to detemine if a something on the map list matches.
307
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.
313
314 @retval TRUE The map should be displayed.
315 @retval FALSE The map should not be displayed.
316 **/
317 BOOLEAN
318 EFIAPI
319 MappingListHasType(
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
325 )
326 {
327 CHAR16 *NewSpecific;
328 //
329 // specific has priority
330 //
331 if (Specific != NULL) {
332 NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));
333 if (NewSpecific == NULL){
334 return FALSE;
335 }
336 StrCpy(NewSpecific, Specific);
337 if (NewSpecific[StrLen(NewSpecific)-1] != L':') {
338 StrCat(NewSpecific, L":");
339 }
340
341 if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {
342 FreePool(NewSpecific);
343 return (TRUE);
344 }
345 FreePool(NewSpecific);
346 }
347 if ( Consist
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";"))){
352 return (TRUE);
353 }
354
355 if ( Normal
356 && (SearchList(MapList, L"FS", NULL, FALSE, TRUE, L";")
357 ||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){
358 return (TRUE);
359 }
360
361 if (TypeString != NULL && SearchList(MapList, TypeString, NULL, TRUE, TRUE, L";")) {
362 return (TRUE);
363 }
364 return (FALSE);
365 }
366
367
368 /**
369 Display a single map line for device Handle if conditions are met.
370
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.
378
379 @retval EFI_SUCCESS The mapping was displayed.
380 **/
381 EFI_STATUS
382 EFIAPI
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
391 )
392 {
393 EFI_DEVICE_PATH_PROTOCOL *DevPath;
394 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;
395 CONST CHAR16 *MapList;
396 CHAR16 *CurrentName;
397 CHAR16 *MediaType;
398 CHAR16 *DevPathString;
399 CHAR16 *TempSpot;
400 CHAR16 *Alias;
401 UINTN TempLen;
402 BOOLEAN Removable;
403 CONST CHAR16 *TempSpot2;
404
405 Alias = NULL;
406 TempSpot2 = NULL;
407 CurrentName = NULL;
408 DevPath = DevicePathFromHandle(Handle);
409 DevPathCopy = DevPath;
410 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
411 if (MapList == NULL) {
412 return EFI_NOT_FOUND;
413 }
414
415 if (!MappingListHasType(MapList, Specific, TypeString, Normal, Consist)){
416 return EFI_NOT_FOUND;
417 }
418
419 if (Normal) {
420 //
421 // Allocate a name
422 //
423 CurrentName = NULL;
424 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
425 if (CurrentName == NULL) {
426 return (EFI_OUT_OF_RESOURCES);
427 }
428
429 //
430 // Chop off the other names that become "Alias(s)"
431 // leaving just the normal name
432 //
433 TempSpot = StrStr(CurrentName, L";");
434 if (TempSpot != NULL) {
435 *TempSpot = CHAR_NULL;
436 }
437 } else if (Consist) {
438 CurrentName = NULL;
439
440 //
441 // Skip the first name. This is the standard name.
442 //
443 TempSpot = StrStr(MapList, L";");
444 if (TempSpot != NULL) {
445 TempSpot++;
446 }
447 SearchList(TempSpot, L"HD*", &CurrentName, TRUE, FALSE, L";");
448 if (CurrentName == NULL) {
449 SearchList(TempSpot, L"CD*", &CurrentName, TRUE, FALSE, L";");
450 }
451 if (CurrentName == NULL) {
452 SearchList(TempSpot, L"FP*", &CurrentName, TRUE, FALSE, L";");
453 }
454 if (CurrentName == NULL) {
455 SearchList(TempSpot, L"F*", &CurrentName, TRUE, FALSE, L";");
456 }
457 if (CurrentName == NULL) {
458 //
459 // We didnt find anything, so just the first one in the list...
460 //
461 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
462 if (CurrentName == NULL) {
463 return (EFI_OUT_OF_RESOURCES);
464 }
465 TempSpot = StrStr(CurrentName, L";");
466 if (TempSpot != NULL) {
467 *TempSpot = CHAR_NULL;
468 }
469 } else {
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));
477 } else {
478 *TempSpot = CHAR_NULL;
479 }
480 }
481 if (Alias[StrLen(Alias)-1] == L';') {
482 Alias[StrLen(Alias)-1] = CHAR_NULL;
483 }
484 }
485 } else {
486 CurrentName = NULL;
487 }
488 DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
489 if (!SFO) {
490 TempLen = StrLen(CurrentName);
491 ShellPrintHiiEx (
492 -1,
493 -1,
494 NULL,
495 STRING_TOKEN (STR_MAP_ENTRY),
496 gShellLevel2HiiHandle,
497 CurrentName,
498 Alias!=NULL?Alias:(TempLen < StrLen(MapList)?MapList + TempLen+1:L""),
499 DevPathString
500 );
501 if (Verbose) {
502 //
503 // also print handle, media type, removable (y/n), and current directory
504 //
505 MediaType = GetDeviceMediaType(DevPath);
506 if ((TypeString != NULL &&MediaType != NULL && StrStr(TypeString, MediaType) != NULL) || TypeString == NULL) {
507 Removable = IsRemoveableDevice(DevPath);
508 TempSpot2 = ShellGetCurrentDir(CurrentName);
509 ShellPrintHiiEx (
510 -1,
511 -1,
512 NULL,
513 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE),
514 gShellLevel2HiiHandle,
515 ConvertHandleToHandleIndex(Handle),
516 MediaType,
517 Removable?L"Yes":L"No",
518 TempSpot2
519 );
520 }
521 SHELL_FREE_NON_NULL(MediaType);
522 }
523 } else {
524 TempLen = StrLen(CurrentName);
525 ShellPrintHiiEx (
526 -1,
527 -1,
528 NULL,
529 STRING_TOKEN (STR_MAP_SFO_MAPPINGS),
530 gShellLevel2HiiHandle,
531 CurrentName,
532 DevPathString,
533 Consist?L"":(TempLen < StrLen(MapList)?MapList + TempLen+1:L"")
534 );
535 }
536 SHELL_FREE_NON_NULL(DevPathString);
537 SHELL_FREE_NON_NULL(CurrentName);
538 SHELL_FREE_NON_NULL(Alias);
539 return EFI_SUCCESS;
540 }
541
542 /**
543 Delete Specific from the list of maps for device Handle.
544
545 @param[in] Specific The name to delete.
546 @param[in] Handle The device to look on.
547
548 @retval EFI_SUCCESS The delete was successful.
549 @retval EFI_NOT_FOUND Name was not a map on Handle.
550 **/
551 EFI_STATUS
552 EFIAPI
553 PerformSingleMappingDelete(
554 IN CONST CHAR16 *Specific,
555 IN CONST EFI_HANDLE Handle
556 )
557 {
558 EFI_DEVICE_PATH_PROTOCOL *DevPath;
559 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;
560 CONST CHAR16 *MapList;
561 CHAR16 *CurrentName;
562
563 DevPath = DevicePathFromHandle(Handle);
564 DevPathCopy = DevPath;
565 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
566 CurrentName = NULL;
567
568 if (MapList == NULL) {
569 return (EFI_NOT_FOUND);
570 }
571 //
572 // if there is a specific and its not on the list...
573 //
574 if (!SearchList(MapList, Specific, &CurrentName, TRUE, FALSE, L";")) {
575 return (EFI_NOT_FOUND);
576 }
577 return (gEfiShellProtocol->SetMap(NULL, CurrentName));
578 }
579
580 CONST CHAR16 Cd[] = L"cd*";
581 CONST CHAR16 Hd[] = L"hd*";
582 CONST CHAR16 Fp[] = L"fp*";
583 CONST CHAR16 AnyF[] = L"F*";
584 /**
585 Function to display mapping information to the user.
586
587 If Specific is specified then Consist and Normal will be ignored since information will
588 be printed for the specific item only.
589
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.
597
598 @retval SHELL_SUCCESS The display was printed.
599 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
600
601 **/
602 SHELL_STATUS
603 EFIAPI
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
612 )
613 {
614 EFI_STATUS Status;
615 EFI_HANDLE *HandleBuffer;
616 UINTN BufferSize;
617 UINTN LoopVar;
618 CHAR16 *Test;
619 BOOLEAN Found;
620
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);
624 }
625
626 if (TypeString != NULL) {
627 Test = (CHAR16*)Cd;
628 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
629 Test = (CHAR16*)Hd;
630 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
631 Test = (CHAR16*)Fp;
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);
635 }
636 } else if (Test == NULL) {
637 Test = (CHAR16*)AnyF;
638 }
639 }
640 } else {
641 Test = NULL;
642 }
643
644 if (Header) {
645 //
646 // Print the header
647 //
648 if (!SFO) {
649 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_HEADER), gShellLevel2HiiHandle);
650 } else {
651 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"map");
652 }
653 }
654
655 BufferSize = 0;
656 HandleBuffer = NULL;
657
658 //
659 // Look up all SimpleFileSystems in the platform
660 //
661 Status = gBS->LocateHandle(
662 ByProtocol,
663 &gEfiSimpleFileSystemProtocolGuid,
664 NULL,
665 &BufferSize,
666 HandleBuffer);
667 if (Status == EFI_BUFFER_TOO_SMALL) {
668 HandleBuffer = AllocateZeroPool(BufferSize);
669 if (HandleBuffer == NULL) {
670 return (SHELL_OUT_OF_RESOURCES);
671 }
672 Status = gBS->LocateHandle(
673 ByProtocol,
674 &gEfiSimpleFileSystemProtocolGuid,
675 NULL,
676 &BufferSize,
677 HandleBuffer);
678 }
679
680 //
681 // Get the map name(s) for each one.
682 //
683 for ( LoopVar = 0, Found = FALSE
684 ; LoopVar < (BufferSize / sizeof(EFI_HANDLE)) && HandleBuffer != NULL
685 ; LoopVar ++
686 ){
687 Status = PerformSingleMappingDisplay(
688 Verbose,
689 Consist,
690 Normal,
691 Test,
692 SFO,
693 Specific,
694 HandleBuffer[LoopVar]);
695 if (!EFI_ERROR(Status)) {
696 Found = TRUE;
697 }
698 }
699
700 //
701 // Look up all BlockIo in the platform
702 //
703 Status = gBS->LocateHandle(
704 ByProtocol,
705 &gEfiBlockIoProtocolGuid,
706 NULL,
707 &BufferSize,
708 HandleBuffer);
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);
714 }
715 Status = gBS->LocateHandle(
716 ByProtocol,
717 &gEfiBlockIoProtocolGuid,
718 NULL,
719 &BufferSize,
720 HandleBuffer);
721 }
722 if (!EFI_ERROR(Status) && HandleBuffer != NULL) {
723 //
724 // Get the map name(s) for each one.
725 //
726 for ( LoopVar = 0
727 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
728 ; LoopVar ++
729 ){
730 //
731 // Skip any that were already done...
732 //
733 if (gBS->OpenProtocol(
734 HandleBuffer[LoopVar],
735 &gEfiSimpleFileSystemProtocolGuid,
736 NULL,
737 gImageHandle,
738 NULL,
739 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
740 continue;
741 }
742 Status = PerformSingleMappingDisplay(
743 Verbose,
744 Consist,
745 Normal,
746 Test,
747 SFO,
748 Specific,
749 HandleBuffer[LoopVar]);
750 if (!EFI_ERROR(Status)) {
751 Found = TRUE;
752 }
753 }
754 FreePool(HandleBuffer);
755 }
756 if (!Found) {
757 if (Specific != NULL) {
758 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, Specific);
759 } else {
760 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
761 }
762 }
763 return (SHELL_SUCCESS);
764 }
765
766 /**
767 Perform a mapping display and parse for multiple types in the TypeString.
768
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.
775
776 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
777 @retval SHELL_SUCCESS The display was successful.
778 @sa PerformMappingDisplay
779 **/
780 SHELL_STATUS
781 EFIAPI
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
789 )
790 {
791 CONST CHAR16 *TypeWalker;
792 SHELL_STATUS ShellStatus;
793 CHAR16 *Comma;
794
795
796 if (TypeString == NULL) {
797 return (PerformMappingDisplay(Verbose, Consist, Normal, NULL, SFO, Specific, TRUE));
798 }
799 ShellStatus = SHELL_SUCCESS;
800 for (TypeWalker = TypeString ; TypeWalker != NULL && *TypeWalker != CHAR_NULL ;) {
801 Comma = StrStr(TypeWalker, L",");
802 if (Comma == NULL) {
803 if (ShellStatus == SHELL_SUCCESS) {
804 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
805 } else {
806 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
807 }
808 break;
809 } else {
810 *Comma = CHAR_NULL;
811 if (ShellStatus == SHELL_SUCCESS) {
812 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
813 } else {
814 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
815 }
816 *Comma = L',';
817 TypeWalker = Comma + 1;
818 }
819 }
820
821 return (ShellStatus);
822 }
823
824 /**
825 Delete a specific map.
826
827 @param[in] Specific The pointer to the name of the map to delete.
828
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.
832 **/
833 EFI_STATUS
834 EFIAPI
835 PerformMappingDelete(
836 IN CONST CHAR16 *Specific
837 )
838 {
839 EFI_STATUS Status;
840 EFI_HANDLE *HandleBuffer;
841 UINTN BufferSize;
842 UINTN LoopVar;
843 BOOLEAN Deleted;
844
845 if (Specific == NULL) {
846 return (EFI_INVALID_PARAMETER);
847 }
848
849 BufferSize = 0;
850 HandleBuffer = NULL;
851 Deleted = FALSE;
852
853 //
854 // Look up all SimpleFileSystems in the platform
855 //
856 Status = gBS->LocateHandle(
857 ByProtocol,
858 &gEfiDevicePathProtocolGuid,
859 NULL,
860 &BufferSize,
861 HandleBuffer);
862 if (Status == EFI_BUFFER_TOO_SMALL) {
863 HandleBuffer = AllocateZeroPool(BufferSize);
864 if (HandleBuffer == NULL) {
865 return (EFI_OUT_OF_RESOURCES);
866 }
867 Status = gBS->LocateHandle(
868 ByProtocol,
869 &gEfiDevicePathProtocolGuid,
870 NULL,
871 &BufferSize,
872 HandleBuffer);
873 }
874 if (EFI_ERROR(Status)) {
875 SHELL_FREE_NON_NULL(HandleBuffer);
876 return (Status);
877 }
878
879 if (HandleBuffer != NULL) {
880 //
881 // Get the map name(s) for each one.
882 //
883 for ( LoopVar = 0
884 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
885 ; LoopVar ++
886 ){
887 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
888 Deleted = TRUE;
889 }
890 }
891 }
892 //
893 // Look up all BlockIo in the platform
894 //
895 Status = gBS->LocateHandle(
896 ByProtocol,
897 &gEfiBlockIoProtocolGuid,
898 NULL,
899 &BufferSize,
900 HandleBuffer);
901 if (Status == EFI_BUFFER_TOO_SMALL) {
902 FreePool(HandleBuffer);
903 HandleBuffer = AllocateZeroPool(BufferSize);
904 if (HandleBuffer == NULL) {
905 return (EFI_OUT_OF_RESOURCES);
906 }
907 Status = gBS->LocateHandle(
908 ByProtocol,
909 &gEfiBlockIoProtocolGuid,
910 NULL,
911 &BufferSize,
912 HandleBuffer);
913 }
914 if (EFI_ERROR(Status)) {
915 SHELL_FREE_NON_NULL(HandleBuffer);
916 return (Status);
917 }
918
919 if (HandleBuffer != NULL) {
920 //
921 // Get the map name(s) for each one.
922 //
923 for ( LoopVar = 0
924 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
925 ; LoopVar ++
926 ){
927 //
928 // Skip any that were already done...
929 //
930 if (gBS->OpenProtocol(
931 HandleBuffer[LoopVar],
932 &gEfiDevicePathProtocolGuid,
933 NULL,
934 gImageHandle,
935 NULL,
936 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
937 continue;
938 }
939 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
940 Deleted = TRUE;
941 }
942 }
943 }
944 SHELL_FREE_NON_NULL(HandleBuffer);
945 if (!Deleted) {
946 return (EFI_NOT_FOUND);
947 }
948 return (EFI_SUCCESS);
949 }
950
951 /**
952 function to add a mapping from mapping.
953
954 This function will get the device path associated with the mapping and call SetMap.
955
956 @param[in] Map The Map to add a mapping for
957 @param[in] SName The name of the new mapping
958
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
962
963 **/
964 SHELL_STATUS
965 EFIAPI
966 AddMappingFromMapping(
967 IN CONST CHAR16 *Map,
968 IN CONST CHAR16 *SName
969 )
970 {
971 CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
972 EFI_STATUS Status;
973 CHAR16 *NewSName;
974
975 NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
976 if (NewSName == NULL) {
977 return (SHELL_OUT_OF_RESOURCES);
978 }
979 StrCpy(NewSName, SName);
980 if (NewSName[StrLen(NewSName)-1] != L':') {
981 StrCat(NewSName, L":");
982 }
983
984 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
985 FreePool(NewSName);
986 return (SHELL_INVALID_PARAMETER);
987 }
988
989 DevPath = gEfiShellProtocol->GetDevicePathFromMap(Map);
990 if (DevPath == NULL) {
991 FreePool(NewSName);
992 return (SHELL_INVALID_PARAMETER);
993 }
994
995 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
996 FreePool(NewSName);
997 if (EFI_ERROR(Status)) {
998 return (SHELL_DEVICE_ERROR);
999 }
1000 return (SHELL_SUCCESS);
1001 }
1002
1003 /**
1004 function to add a mapping from an EFI_HANDLE.
1005
1006 This function will get the device path associated with the Handle and call SetMap.
1007
1008 @param[in] Handle The handle to add a mapping for
1009 @param[in] SName The name of the new mapping
1010
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
1015
1016 **/
1017 SHELL_STATUS
1018 EFIAPI
1019 AddMappingFromHandle(
1020 IN CONST EFI_HANDLE Handle,
1021 IN CONST CHAR16 *SName
1022 )
1023 {
1024 EFI_DEVICE_PATH_PROTOCOL *DevPath;
1025 EFI_STATUS Status;
1026 CHAR16 *NewSName;
1027
1028 NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
1029 if (NewSName == NULL) {
1030 return (SHELL_OUT_OF_RESOURCES);
1031 }
1032 StrCpy(NewSName, SName);
1033 if (NewSName[StrLen(NewSName)-1] != L':') {
1034 StrCat(NewSName, L":");
1035 }
1036
1037 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
1038 FreePool(NewSName);
1039 return (SHELL_INVALID_PARAMETER);
1040 }
1041
1042 Status = gBS->OpenProtocol(
1043 Handle,
1044 &gEfiDevicePathProtocolGuid,
1045 (VOID**)&DevPath,
1046 gImageHandle,
1047 NULL,
1048 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1049 );
1050 if (EFI_ERROR(Status)) {
1051 FreePool(NewSName);
1052 return (SHELL_DEVICE_ERROR);
1053 }
1054 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
1055 FreePool(NewSName);
1056 if (EFI_ERROR(Status)) {
1057 return (SHELL_DEVICE_ERROR);
1058 }
1059 return (SHELL_SUCCESS);
1060 }
1061
1062 STATIC CONST SHELL_PARAM_ITEM MapParamList[] = {
1063 {L"-d", TypeValue},
1064 {L"-r", TypeFlag},
1065 {L"-v", TypeFlag},
1066 {L"-c", TypeFlag},
1067 {L"-f", TypeFlag},
1068 {L"-u", TypeFlag},
1069 {L"-t", TypeValue},
1070 {L"-sfo", TypeValue},
1071 {NULL, TypeMax}
1072 };
1073
1074 /**
1075 Function for 'map' command.
1076
1077 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1078 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1079 **/
1080 SHELL_STATUS
1081 EFIAPI
1082 ShellCommandRunMap (
1083 IN EFI_HANDLE ImageHandle,
1084 IN EFI_SYSTEM_TABLE *SystemTable
1085 )
1086 {
1087 EFI_STATUS Status;
1088 LIST_ENTRY *Package;
1089 CHAR16 *ProblemParam;
1090 CONST CHAR16 *SName;
1091 CONST CHAR16 *Mapping;
1092 EFI_HANDLE MapAsHandle;
1093 SHELL_STATUS ShellStatus;
1094 BOOLEAN SfoMode;
1095 BOOLEAN ConstMode;
1096 BOOLEAN NormlMode;
1097 CONST CHAR16 *Param1;
1098 CONST CHAR16 *TypeString;
1099 UINTN TempStringLength;
1100
1101 ProblemParam = NULL;
1102 Mapping = NULL;
1103 SName = NULL;
1104 ShellStatus = SHELL_SUCCESS;
1105 MapAsHandle = NULL;
1106
1107 //
1108 // initialize the shell lib (we must be in non-auto-init...)
1109 //
1110 Status = ShellInitialize();
1111 ASSERT_EFI_ERROR(Status);
1112
1113 Status = CommandInit();
1114 ASSERT_EFI_ERROR(Status);
1115
1116 //
1117 // parse the command line
1118 //
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;
1125 } else {
1126 ASSERT(FALSE);
1127 }
1128 } else {
1129 //
1130 // check for "-?"
1131 //
1132 SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
1133 ConstMode = ShellCommandLineGetFlag(Package, L"-c");
1134 NormlMode = ShellCommandLineGetFlag(Package, L"-f");
1135 if (ShellCommandLineGetFlag(Package, L"-?")) {
1136 ASSERT(FALSE);
1137 } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
1138 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
1139 ShellStatus = SHELL_INVALID_PARAMETER;
1140 } else {
1141 //
1142 // Deleting a map name...
1143 //
1144 if (ShellCommandLineGetFlag(Package, L"-d")) {
1145 if ( ShellCommandLineGetFlag(Package, L"-r")
1146 || ShellCommandLineGetFlag(Package, L"-v")
1147 || ConstMode
1148 || NormlMode
1149 || ShellCommandLineGetFlag(Package, L"-u")
1150 || ShellCommandLineGetFlag(Package, L"-t")
1151 ){
1152 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
1153 ShellStatus = SHELL_INVALID_PARAMETER;
1154 } else {
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;
1165 } else {
1166 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
1167 ShellStatus = SHELL_UNSUPPORTED;
1168 }
1169 }
1170 } else {
1171 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
1172 ShellStatus = SHELL_INVALID_PARAMETER;
1173 }
1174 }
1175 } else if ( ShellCommandLineGetFlag(Package, L"-r")
1176 // || ShellCommandLineGetFlag(Package, L"-v")
1177 || ConstMode
1178 || NormlMode
1179 || ShellCommandLineGetFlag(Package, L"-u")
1180 || ShellCommandLineGetFlag(Package, L"-t")
1181 ){
1182 if ( ShellCommandLineGetFlag(Package, L"-r")) {
1183 //
1184 // Do the reset
1185 //
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;
1190 }
1191 }
1192 if ( ShellStatus == SHELL_SUCCESS && ShellCommandLineGetFlag(Package, L"-u")) {
1193 //
1194 // Do the Update
1195 //
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;
1200 }
1201 }
1202 if (ShellStatus == SHELL_SUCCESS) {
1203 Param1 = ShellCommandLineGetRawValue(Package, 1);
1204 TypeString = ShellCommandLineGetValue(Package, L"-t");
1205 if (!ConstMode
1206 &&!NormlMode
1207 &&TypeString == NULL
1208 ) {
1209 //
1210 // now do the display...
1211 //
1212 ShellStatus = PerformMappingDisplay(
1213 ShellCommandLineGetFlag(Package, L"-v"),
1214 TRUE,
1215 TRUE,
1216 NULL,
1217 SfoMode,
1218 Param1,
1219 TRUE
1220 );
1221 } else {
1222 //
1223 // now do the display...
1224 //
1225 ShellStatus = PerformMappingDisplay2(
1226 ShellCommandLineGetFlag(Package, L"-v"),
1227 ConstMode,
1228 NormlMode,
1229 TypeString,
1230 SfoMode,
1231 Param1
1232 );
1233 }
1234 }
1235 } else {
1236 //
1237 // adding or displaying (there were no flags)
1238 //
1239 SName = ShellCommandLineGetRawValue(Package, 1);
1240 Mapping = ShellCommandLineGetRawValue(Package, 2);
1241 if ( SName == NULL
1242 && Mapping == NULL
1243 ){
1244 //
1245 // display only since no flags
1246 //
1247 ShellStatus = PerformMappingDisplay(
1248 ShellCommandLineGetFlag(Package, L"-v"),
1249 TRUE,
1250 TRUE,
1251 NULL,
1252 SfoMode,
1253 NULL,
1254 TRUE
1255 );
1256 } else if ( SName == NULL
1257 || Mapping == NULL
1258 ){
1259 //
1260 // Display only the one specified
1261 //
1262 ShellStatus = PerformMappingDisplay(
1263 FALSE,
1264 FALSE,
1265 FALSE,
1266 NULL,
1267 SfoMode,
1268 SName, // note the variable here...
1269 TRUE
1270 );
1271 } else {
1272 if (ShellIsHexOrDecimalNumber(Mapping, TRUE, FALSE)) {
1273 MapAsHandle = ConvertHandleIndexToHandle(ShellStrToUintn(Mapping));
1274 } else {
1275 MapAsHandle = NULL;
1276 }
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;
1280 } else {
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;
1286 } else {
1287 ShellStatus = AddMappingFromHandle(MapAsHandle, SName);
1288 }
1289 } else {
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;
1294 } else {
1295 ShellStatus = AddMappingFromMapping(Mapping, SName);
1296 }
1297 }
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);
1302 break;
1303 case SHELL_INVALID_PARAMETER:
1304 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
1305 break;
1306 case SHELL_DEVICE_ERROR:
1307 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NOF), gShellLevel2HiiHandle, Mapping);
1308 break;
1309 default:
1310 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, ShellStatus|MAX_BIT);
1311 }
1312 } else {
1313 //
1314 // now do the display...
1315 //
1316 ShellStatus = PerformMappingDisplay(
1317 FALSE,
1318 FALSE,
1319 FALSE,
1320 NULL,
1321 SfoMode,
1322 SName,
1323 TRUE
1324 );
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
1330 }
1331
1332 //
1333 // free the command line package
1334 //
1335 ShellCommandLineFreeVarList (Package);
1336
1337 return (ShellStatus);
1338 }
1339