]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg: fix display for map command with filtering
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Map.c
1 /** @file
2 Main file for map shell level 2 command.
3
4 Copyright (c) 2009 - 2014, 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 && !Specific
349 && (SearchList(MapList, L"HD*", NULL, TRUE, TRUE, L";")
350 ||SearchList(MapList, L"CD*", NULL, TRUE, TRUE, L";")
351 ||SearchList(MapList, L"F*", NULL, TRUE, TRUE, L";")
352 ||SearchList(MapList, L"FP*", NULL, TRUE, TRUE, L";"))){
353 return (TRUE);
354 }
355
356 if ( Normal
357 && !Specific
358 && (SearchList(MapList, L"FS", NULL, FALSE, TRUE, L";")
359 ||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){
360 return (TRUE);
361 }
362
363 if (TypeString != NULL && SearchList(MapList, TypeString, NULL, TRUE, TRUE, L";")) {
364 return (TRUE);
365 }
366 return (FALSE);
367 }
368
369
370 /**
371 Display a single map line for device Handle if conditions are met.
372
373 @param[in] Verbose TRUE to display (extra) verbose information.
374 @param[in] Consist TRUE to display consistent mappings.
375 @param[in] Normal TRUE to display normal (not consist) mappings.
376 @param[in] TypeString pointer to string of filter types.
377 @param[in] SFO TRUE to display output in Standard Output Format.
378 @param[in] Specific pointer to string for specific map to display.
379 @param[in] Handle The handle to display from.
380
381 @retval EFI_SUCCESS The mapping was displayed.
382 **/
383 EFI_STATUS
384 EFIAPI
385 PerformSingleMappingDisplay(
386 IN CONST BOOLEAN Verbose,
387 IN CONST BOOLEAN Consist,
388 IN CONST BOOLEAN Normal,
389 IN CONST CHAR16 *TypeString,
390 IN CONST BOOLEAN SFO,
391 IN CONST CHAR16 *Specific OPTIONAL,
392 IN CONST EFI_HANDLE Handle
393 )
394 {
395 EFI_DEVICE_PATH_PROTOCOL *DevPath;
396 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;
397 CONST CHAR16 *MapList;
398 CHAR16 *CurrentName;
399 CHAR16 *MediaType;
400 CHAR16 *DevPathString;
401 CHAR16 *TempSpot;
402 CHAR16 *Alias;
403 UINTN TempLen;
404 BOOLEAN Removable;
405 CONST CHAR16 *TempSpot2;
406
407 Alias = NULL;
408 TempSpot2 = NULL;
409 CurrentName = NULL;
410 DevPath = DevicePathFromHandle(Handle);
411 DevPathCopy = DevPath;
412 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
413 if (MapList == NULL) {
414 return EFI_NOT_FOUND;
415 }
416
417 if (!MappingListHasType(MapList, Specific, TypeString, Normal, Consist)){
418 return EFI_NOT_FOUND;
419 }
420
421 if (Normal || !Consist) {
422 //
423 // need the Normal here since people can use both on command line. otherwise unused.
424 //
425
426 //
427 // Allocate a name
428 //
429 CurrentName = NULL;
430 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
431 if (CurrentName == NULL) {
432 return (EFI_OUT_OF_RESOURCES);
433 }
434
435 //
436 // Chop off the other names that become "Alias(s)"
437 // leaving just the normal name
438 //
439 TempSpot = StrStr(CurrentName, L";");
440 if (TempSpot != NULL) {
441 *TempSpot = CHAR_NULL;
442 }
443 } else {
444 CurrentName = NULL;
445
446 //
447 // Skip the first name. This is the standard name.
448 //
449 TempSpot = StrStr(MapList, L";");
450 if (TempSpot != NULL) {
451 TempSpot++;
452 }
453 SearchList(TempSpot, L"HD*", &CurrentName, TRUE, FALSE, L";");
454 if (CurrentName == NULL) {
455 SearchList(TempSpot, L"CD*", &CurrentName, TRUE, FALSE, L";");
456 }
457 if (CurrentName == NULL) {
458 SearchList(TempSpot, L"FP*", &CurrentName, TRUE, FALSE, L";");
459 }
460 if (CurrentName == NULL) {
461 SearchList(TempSpot, L"F*", &CurrentName, TRUE, FALSE, L";");
462 }
463 if (CurrentName == NULL) {
464 //
465 // We didnt find anything, so just the first one in the list...
466 //
467 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
468 if (CurrentName == NULL) {
469 return (EFI_OUT_OF_RESOURCES);
470 }
471 TempSpot = StrStr(CurrentName, L";");
472 if (TempSpot != NULL) {
473 *TempSpot = CHAR_NULL;
474 }
475 } else {
476 Alias = StrnCatGrow(&Alias, 0, MapList, 0);
477 if (Alias == NULL) {
478 return EFI_OUT_OF_RESOURCES;
479 }
480 TempSpot = StrStr(Alias, CurrentName);
481 if (TempSpot != NULL) {
482 TempSpot2 = StrStr(TempSpot, L";");
483 if (TempSpot2 != NULL) {
484 TempSpot2++; // Move past ";" from CurrentName
485 CopyMem(TempSpot, TempSpot2, StrSize(TempSpot2));
486 } else {
487 *TempSpot = CHAR_NULL;
488 }
489 }
490 if (Alias[StrLen(Alias)-1] == L';') {
491 Alias[StrLen(Alias)-1] = CHAR_NULL;
492 }
493 }
494 }
495 DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
496 TempLen = StrLen(CurrentName);
497 if (!SFO) {
498 ShellPrintHiiEx (
499 -1,
500 -1,
501 NULL,
502 STRING_TOKEN (STR_MAP_ENTRY),
503 gShellLevel2HiiHandle,
504 CurrentName,
505 Alias!=NULL?Alias:(TempLen < StrLen(MapList)?MapList + TempLen+1:L""),
506 DevPathString
507 );
508 if (Verbose) {
509 //
510 // also print handle, media type, removable (y/n), and current directory
511 //
512 MediaType = GetDeviceMediaType(DevPath);
513 if ((TypeString != NULL &&MediaType != NULL && StrStr(TypeString, MediaType) != NULL) || TypeString == NULL) {
514 Removable = IsRemoveableDevice(DevPath);
515 TempSpot2 = ShellGetCurrentDir(CurrentName);
516 ShellPrintHiiEx (
517 -1,
518 -1,
519 NULL,
520 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE),
521 gShellLevel2HiiHandle,
522 ConvertHandleToHandleIndex(Handle),
523 MediaType,
524 Removable?L"Yes":L"No",
525 TempSpot2
526 );
527 }
528 SHELL_FREE_NON_NULL(MediaType);
529 }
530 } else {
531 ShellPrintHiiEx (
532 -1,
533 -1,
534 NULL,
535 STRING_TOKEN (STR_MAP_SFO_MAPPINGS),
536 gShellLevel2HiiHandle,
537 CurrentName,
538 DevPathString,
539 Consist?L"":(TempLen < StrLen(MapList)?MapList + TempLen+1:L"")
540 );
541 }
542 SHELL_FREE_NON_NULL(DevPathString);
543 SHELL_FREE_NON_NULL(CurrentName);
544 SHELL_FREE_NON_NULL(Alias);
545 return EFI_SUCCESS;
546 }
547
548 /**
549 Delete Specific from the list of maps for device Handle.
550
551 @param[in] Specific The name to delete.
552 @param[in] Handle The device to look on.
553
554 @retval EFI_SUCCESS The delete was successful.
555 @retval EFI_NOT_FOUND Name was not a map on Handle.
556 **/
557 EFI_STATUS
558 EFIAPI
559 PerformSingleMappingDelete(
560 IN CONST CHAR16 *Specific,
561 IN CONST EFI_HANDLE Handle
562 )
563 {
564 EFI_DEVICE_PATH_PROTOCOL *DevPath;
565 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;
566 CONST CHAR16 *MapList;
567 CHAR16 *CurrentName;
568
569 DevPath = DevicePathFromHandle(Handle);
570 DevPathCopy = DevPath;
571 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
572 CurrentName = NULL;
573
574 if (MapList == NULL) {
575 return (EFI_NOT_FOUND);
576 }
577 //
578 // if there is a specific and its not on the list...
579 //
580 if (!SearchList(MapList, Specific, &CurrentName, TRUE, FALSE, L";")) {
581 return (EFI_NOT_FOUND);
582 }
583 return (gEfiShellProtocol->SetMap(NULL, CurrentName));
584 }
585
586 CONST CHAR16 Cd[] = L"cd*";
587 CONST CHAR16 Hd[] = L"hd*";
588 CONST CHAR16 Fp[] = L"fp*";
589 CONST CHAR16 AnyF[] = L"F*";
590 /**
591 Function to display mapping information to the user.
592
593 If Specific is specified then Consist and Normal will be ignored since information will
594 be printed for the specific item only.
595
596 @param[in] Verbose TRUE to display (extra) verbose information.
597 @param[in] Consist TRUE to display consistent mappings.
598 @param[in] Normal TRUE to display normal (not consist) mappings.
599 @param[in] TypeString Pointer to string of filter types.
600 @param[in] SFO TRUE to display output in Standard Output Format.
601 @param[in] Specific Pointer to string for specific map to display.
602 @param[in] Header TRUE to print the header block.
603
604 @retval SHELL_SUCCESS The display was printed.
605 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.
606
607 **/
608 SHELL_STATUS
609 EFIAPI
610 PerformMappingDisplay(
611 IN CONST BOOLEAN Verbose,
612 IN CONST BOOLEAN Consist,
613 IN CONST BOOLEAN Normal,
614 IN CONST CHAR16 *TypeString,
615 IN CONST BOOLEAN SFO,
616 IN CONST CHAR16 *Specific OPTIONAL,
617 IN CONST BOOLEAN Header
618 )
619 {
620 EFI_STATUS Status;
621 EFI_HANDLE *HandleBuffer;
622 UINTN BufferSize;
623 UINTN LoopVar;
624 CHAR16 *Test;
625 BOOLEAN Found;
626
627 if (!Consist && !Normal && Specific == NULL && TypeString == NULL) {
628 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
629 return (SHELL_INVALID_PARAMETER);
630 }
631
632 if (TypeString != NULL) {
633 Test = (CHAR16*)Cd;
634 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
635 Test = (CHAR16*)Hd;
636 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
637 Test = (CHAR16*)Fp;
638 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
639 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, TypeString);
640 return (SHELL_INVALID_PARAMETER);
641 }
642 } else if (Test == NULL) {
643 Test = (CHAR16*)AnyF;
644 }
645 }
646 } else {
647 Test = NULL;
648 }
649
650 if (Header) {
651 //
652 // Print the header
653 //
654 if (!SFO) {
655 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_HEADER), gShellLevel2HiiHandle);
656 } else {
657 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"map");
658 }
659 }
660
661 BufferSize = 0;
662 HandleBuffer = NULL;
663
664 //
665 // Look up all SimpleFileSystems in the platform
666 //
667 Status = gBS->LocateHandle(
668 ByProtocol,
669 &gEfiSimpleFileSystemProtocolGuid,
670 NULL,
671 &BufferSize,
672 HandleBuffer);
673 if (Status == EFI_BUFFER_TOO_SMALL) {
674 HandleBuffer = AllocateZeroPool(BufferSize);
675 if (HandleBuffer == NULL) {
676 return (SHELL_OUT_OF_RESOURCES);
677 }
678 Status = gBS->LocateHandle(
679 ByProtocol,
680 &gEfiSimpleFileSystemProtocolGuid,
681 NULL,
682 &BufferSize,
683 HandleBuffer);
684 }
685
686 //
687 // Get the map name(s) for each one.
688 //
689 for ( LoopVar = 0, Found = FALSE
690 ; LoopVar < (BufferSize / sizeof(EFI_HANDLE)) && HandleBuffer != NULL
691 ; LoopVar ++
692 ){
693 Status = PerformSingleMappingDisplay(
694 Verbose,
695 Consist,
696 Normal,
697 Test,
698 SFO,
699 Specific,
700 HandleBuffer[LoopVar]);
701 if (!EFI_ERROR(Status)) {
702 Found = TRUE;
703 }
704 }
705
706 //
707 // Look up all BlockIo in the platform
708 //
709 Status = gBS->LocateHandle(
710 ByProtocol,
711 &gEfiBlockIoProtocolGuid,
712 NULL,
713 &BufferSize,
714 HandleBuffer);
715 if (Status == EFI_BUFFER_TOO_SMALL) {
716 SHELL_FREE_NON_NULL(HandleBuffer);
717 HandleBuffer = AllocateZeroPool(BufferSize);
718 if (HandleBuffer == NULL) {
719 return (SHELL_OUT_OF_RESOURCES);
720 }
721 Status = gBS->LocateHandle(
722 ByProtocol,
723 &gEfiBlockIoProtocolGuid,
724 NULL,
725 &BufferSize,
726 HandleBuffer);
727 }
728 if (!EFI_ERROR(Status) && HandleBuffer != NULL) {
729 //
730 // Get the map name(s) for each one.
731 //
732 for ( LoopVar = 0
733 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
734 ; LoopVar ++
735 ){
736 //
737 // Skip any that were already done...
738 //
739 if (gBS->OpenProtocol(
740 HandleBuffer[LoopVar],
741 &gEfiSimpleFileSystemProtocolGuid,
742 NULL,
743 gImageHandle,
744 NULL,
745 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
746 continue;
747 }
748 Status = PerformSingleMappingDisplay(
749 Verbose,
750 Consist,
751 Normal,
752 Test,
753 SFO,
754 Specific,
755 HandleBuffer[LoopVar]);
756 if (!EFI_ERROR(Status)) {
757 Found = TRUE;
758 }
759 }
760 FreePool(HandleBuffer);
761 }
762 if (!Found) {
763 if (Specific != NULL) {
764 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, Specific);
765 } else {
766 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
767 }
768 }
769 return (SHELL_SUCCESS);
770 }
771
772 /**
773 Perform a mapping display and parse for multiple types in the TypeString.
774
775 @param[in] Verbose TRUE to use verbose output.
776 @param[in] Consist TRUE to display consistent names.
777 @param[in] Normal TRUE to display normal names.
778 @param[in] TypeString An optional comma-delimited list of types.
779 @param[in] SFO TRUE to display in SFO format. See Spec.
780 @param[in] Specific An optional specific map name to display alone.
781
782 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
783 @retval SHELL_SUCCESS The display was successful.
784 @sa PerformMappingDisplay
785 **/
786 SHELL_STATUS
787 EFIAPI
788 PerformMappingDisplay2(
789 IN CONST BOOLEAN Verbose,
790 IN CONST BOOLEAN Consist,
791 IN CONST BOOLEAN Normal,
792 IN CONST CHAR16 *TypeString,
793 IN CONST BOOLEAN SFO,
794 IN CONST CHAR16 *Specific OPTIONAL
795 )
796 {
797 CONST CHAR16 *TypeWalker;
798 SHELL_STATUS ShellStatus;
799 CHAR16 *Comma;
800
801
802 if (TypeString == NULL) {
803 return (PerformMappingDisplay(Verbose, Consist, Normal, NULL, SFO, Specific, TRUE));
804 }
805 ShellStatus = SHELL_SUCCESS;
806 for (TypeWalker = TypeString ; TypeWalker != NULL && *TypeWalker != CHAR_NULL ;) {
807 Comma = StrStr(TypeWalker, L",");
808 if (Comma == NULL) {
809 if (ShellStatus == SHELL_SUCCESS) {
810 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
811 } else {
812 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
813 }
814 break;
815 } else {
816 *Comma = CHAR_NULL;
817 if (ShellStatus == SHELL_SUCCESS) {
818 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
819 } else {
820 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
821 }
822 *Comma = L',';
823 TypeWalker = Comma + 1;
824 }
825 }
826
827 return (ShellStatus);
828 }
829
830 /**
831 Delete a specific map.
832
833 @param[in] Specific The pointer to the name of the map to delete.
834
835 @retval EFI_INVALID_PARAMETER Specific was NULL.
836 @retval EFI_SUCCESS The operation was successful.
837 @retval EFI_NOT_FOUND Specific could not be found.
838 **/
839 EFI_STATUS
840 EFIAPI
841 PerformMappingDelete(
842 IN CONST CHAR16 *Specific
843 )
844 {
845 EFI_STATUS Status;
846 EFI_HANDLE *HandleBuffer;
847 UINTN BufferSize;
848 UINTN LoopVar;
849 BOOLEAN Deleted;
850
851 if (Specific == NULL) {
852 return (EFI_INVALID_PARAMETER);
853 }
854
855 BufferSize = 0;
856 HandleBuffer = NULL;
857 Deleted = FALSE;
858
859 //
860 // Look up all SimpleFileSystems in the platform
861 //
862 Status = gBS->LocateHandle(
863 ByProtocol,
864 &gEfiDevicePathProtocolGuid,
865 NULL,
866 &BufferSize,
867 HandleBuffer);
868 if (Status == EFI_BUFFER_TOO_SMALL) {
869 HandleBuffer = AllocateZeroPool(BufferSize);
870 if (HandleBuffer == NULL) {
871 return (EFI_OUT_OF_RESOURCES);
872 }
873 Status = gBS->LocateHandle(
874 ByProtocol,
875 &gEfiDevicePathProtocolGuid,
876 NULL,
877 &BufferSize,
878 HandleBuffer);
879 }
880 if (EFI_ERROR(Status)) {
881 SHELL_FREE_NON_NULL(HandleBuffer);
882 return (Status);
883 }
884
885 if (HandleBuffer != NULL) {
886 //
887 // Get the map name(s) for each one.
888 //
889 for ( LoopVar = 0
890 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
891 ; LoopVar ++
892 ){
893 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
894 Deleted = TRUE;
895 }
896 }
897 }
898 //
899 // Look up all BlockIo in the platform
900 //
901 Status = gBS->LocateHandle(
902 ByProtocol,
903 &gEfiBlockIoProtocolGuid,
904 NULL,
905 &BufferSize,
906 HandleBuffer);
907 if (Status == EFI_BUFFER_TOO_SMALL) {
908 FreePool(HandleBuffer);
909 HandleBuffer = AllocateZeroPool(BufferSize);
910 if (HandleBuffer == NULL) {
911 return (EFI_OUT_OF_RESOURCES);
912 }
913 Status = gBS->LocateHandle(
914 ByProtocol,
915 &gEfiBlockIoProtocolGuid,
916 NULL,
917 &BufferSize,
918 HandleBuffer);
919 }
920 if (EFI_ERROR(Status)) {
921 SHELL_FREE_NON_NULL(HandleBuffer);
922 return (Status);
923 }
924
925 if (HandleBuffer != NULL) {
926 //
927 // Get the map name(s) for each one.
928 //
929 for ( LoopVar = 0
930 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
931 ; LoopVar ++
932 ){
933 //
934 // Skip any that were already done...
935 //
936 if (gBS->OpenProtocol(
937 HandleBuffer[LoopVar],
938 &gEfiDevicePathProtocolGuid,
939 NULL,
940 gImageHandle,
941 NULL,
942 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
943 continue;
944 }
945 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
946 Deleted = TRUE;
947 }
948 }
949 }
950 SHELL_FREE_NON_NULL(HandleBuffer);
951 if (!Deleted) {
952 return (EFI_NOT_FOUND);
953 }
954 return (EFI_SUCCESS);
955 }
956
957 /**
958 function to add a mapping from mapping.
959
960 This function will get the device path associated with the mapping and call SetMap.
961
962 @param[in] Map The Map to add a mapping for
963 @param[in] SName The name of the new mapping
964
965 @retval SHELL_SUCCESS the mapping was added
966 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.
967 @return Shell version of a return value from EfiShellProtocol->SetMap
968
969 **/
970 SHELL_STATUS
971 EFIAPI
972 AddMappingFromMapping(
973 IN CONST CHAR16 *Map,
974 IN CONST CHAR16 *SName
975 )
976 {
977 CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
978 EFI_STATUS Status;
979 CHAR16 *NewSName;
980
981 NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
982 if (NewSName == NULL) {
983 return (SHELL_OUT_OF_RESOURCES);
984 }
985 StrCpy(NewSName, SName);
986 if (NewSName[StrLen(NewSName)-1] != L':') {
987 StrCat(NewSName, L":");
988 }
989
990 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
991 FreePool(NewSName);
992 return (SHELL_INVALID_PARAMETER);
993 }
994
995 DevPath = gEfiShellProtocol->GetDevicePathFromMap(Map);
996 if (DevPath == NULL) {
997 FreePool(NewSName);
998 return (SHELL_INVALID_PARAMETER);
999 }
1000
1001 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
1002 FreePool(NewSName);
1003 if (EFI_ERROR(Status)) {
1004 return (SHELL_DEVICE_ERROR);
1005 }
1006 return (SHELL_SUCCESS);
1007 }
1008
1009 /**
1010 function to add a mapping from an EFI_HANDLE.
1011
1012 This function will get the device path associated with the Handle and call SetMap.
1013
1014 @param[in] Handle The handle to add a mapping for
1015 @param[in] SName The name of the new mapping
1016
1017 @retval SHELL_SUCCESS the mapping was added
1018 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.
1019 @return Shell version of a return value from either
1020 gBS->OpenProtocol or EfiShellProtocol->SetMap
1021
1022 **/
1023 SHELL_STATUS
1024 EFIAPI
1025 AddMappingFromHandle(
1026 IN CONST EFI_HANDLE Handle,
1027 IN CONST CHAR16 *SName
1028 )
1029 {
1030 EFI_DEVICE_PATH_PROTOCOL *DevPath;
1031 EFI_STATUS Status;
1032 CHAR16 *NewSName;
1033
1034 NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
1035 if (NewSName == NULL) {
1036 return (SHELL_OUT_OF_RESOURCES);
1037 }
1038 StrCpy(NewSName, SName);
1039 if (NewSName[StrLen(NewSName)-1] != L':') {
1040 StrCat(NewSName, L":");
1041 }
1042
1043 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
1044 FreePool(NewSName);
1045 return (SHELL_INVALID_PARAMETER);
1046 }
1047
1048 Status = gBS->OpenProtocol(
1049 Handle,
1050 &gEfiDevicePathProtocolGuid,
1051 (VOID**)&DevPath,
1052 gImageHandle,
1053 NULL,
1054 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1055 );
1056 if (EFI_ERROR(Status)) {
1057 FreePool(NewSName);
1058 return (SHELL_DEVICE_ERROR);
1059 }
1060 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
1061 FreePool(NewSName);
1062 if (EFI_ERROR(Status)) {
1063 return (SHELL_DEVICE_ERROR);
1064 }
1065 return (SHELL_SUCCESS);
1066 }
1067
1068 STATIC CONST SHELL_PARAM_ITEM MapParamList[] = {
1069 {L"-d", TypeValue},
1070 {L"-r", TypeFlag},
1071 {L"-v", TypeFlag},
1072 {L"-c", TypeFlag},
1073 {L"-f", TypeFlag},
1074 {L"-u", TypeFlag},
1075 {L"-t", TypeValue},
1076 {L"-sfo", TypeValue},
1077 {NULL, TypeMax}
1078 };
1079
1080 /**
1081 Function for 'map' command.
1082
1083 @param[in] ImageHandle Handle to the Image (NULL if Internal).
1084 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
1085 **/
1086 SHELL_STATUS
1087 EFIAPI
1088 ShellCommandRunMap (
1089 IN EFI_HANDLE ImageHandle,
1090 IN EFI_SYSTEM_TABLE *SystemTable
1091 )
1092 {
1093 EFI_STATUS Status;
1094 LIST_ENTRY *Package;
1095 CHAR16 *ProblemParam;
1096 CONST CHAR16 *SName;
1097 CONST CHAR16 *Mapping;
1098 EFI_HANDLE MapAsHandle;
1099 SHELL_STATUS ShellStatus;
1100 BOOLEAN SfoMode;
1101 BOOLEAN ConstMode;
1102 BOOLEAN NormlMode;
1103 CONST CHAR16 *Param1;
1104 CONST CHAR16 *TypeString;
1105 UINTN TempStringLength;
1106
1107 ProblemParam = NULL;
1108 Mapping = NULL;
1109 SName = NULL;
1110 ShellStatus = SHELL_SUCCESS;
1111 MapAsHandle = NULL;
1112
1113 //
1114 // initialize the shell lib (we must be in non-auto-init...)
1115 //
1116 Status = ShellInitialize();
1117 ASSERT_EFI_ERROR(Status);
1118
1119 Status = CommandInit();
1120 ASSERT_EFI_ERROR(Status);
1121
1122 //
1123 // parse the command line
1124 //
1125 Status = ShellCommandLineParse (MapParamList, &Package, &ProblemParam, TRUE);
1126 if (EFI_ERROR(Status)) {
1127 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
1128 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
1129 FreePool(ProblemParam);
1130 ShellStatus = SHELL_INVALID_PARAMETER;
1131 } else {
1132 ASSERT(FALSE);
1133 }
1134 } else {
1135 //
1136 // check for "-?"
1137 //
1138 SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
1139 ConstMode = ShellCommandLineGetFlag(Package, L"-c");
1140 NormlMode = ShellCommandLineGetFlag(Package, L"-f");
1141 if (ShellCommandLineGetFlag(Package, L"-?")) {
1142 ASSERT(FALSE);
1143 } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
1144 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
1145 ShellStatus = SHELL_INVALID_PARAMETER;
1146 } else {
1147 //
1148 // Deleting a map name...
1149 //
1150 if (ShellCommandLineGetFlag(Package, L"-d")) {
1151 if ( ShellCommandLineGetFlag(Package, L"-r")
1152 || ShellCommandLineGetFlag(Package, L"-v")
1153 || ConstMode
1154 || NormlMode
1155 || ShellCommandLineGetFlag(Package, L"-u")
1156 || ShellCommandLineGetFlag(Package, L"-t")
1157 ){
1158 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
1159 ShellStatus = SHELL_INVALID_PARAMETER;
1160 } else {
1161 SName = ShellCommandLineGetValue(Package, L"-d");
1162 if (SName != NULL) {
1163 Status = PerformMappingDelete(SName);
1164 if (EFI_ERROR(Status)) {
1165 if (Status == EFI_ACCESS_DENIED) {
1166 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
1167 ShellStatus = SHELL_ACCESS_DENIED;
1168 } else if (Status == EFI_NOT_FOUND) {
1169 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, SName);
1170 ShellStatus = SHELL_INVALID_PARAMETER;
1171 } else {
1172 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
1173 ShellStatus = SHELL_UNSUPPORTED;
1174 }
1175 }
1176 } else {
1177 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
1178 ShellStatus = SHELL_INVALID_PARAMETER;
1179 }
1180 }
1181 } else if ( ShellCommandLineGetFlag(Package, L"-r")
1182 // || ShellCommandLineGetFlag(Package, L"-v")
1183 || ConstMode
1184 || NormlMode
1185 || ShellCommandLineGetFlag(Package, L"-u")
1186 || ShellCommandLineGetFlag(Package, L"-t")
1187 ){
1188 if ( ShellCommandLineGetFlag(Package, L"-r")) {
1189 //
1190 // Do the reset
1191 //
1192 Status = ShellCommandCreateInitialMappingsAndPaths();
1193 if (EFI_ERROR(Status)) {
1194 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
1195 ShellStatus = SHELL_UNSUPPORTED;
1196 }
1197 }
1198 if ( ShellStatus == SHELL_SUCCESS && ShellCommandLineGetFlag(Package, L"-u")) {
1199 //
1200 // Do the Update
1201 //
1202 Status = UpdateMapping();
1203 if (EFI_ERROR(Status)) {
1204 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
1205 ShellStatus = SHELL_UNSUPPORTED;
1206 }
1207 }
1208 if (ShellStatus == SHELL_SUCCESS) {
1209 Param1 = ShellCommandLineGetRawValue(Package, 1);
1210 TypeString = ShellCommandLineGetValue(Package, L"-t");
1211 if (!ConstMode
1212 &&!NormlMode
1213 &&TypeString == NULL
1214 ) {
1215 //
1216 // now do the display...
1217 //
1218 ShellStatus = PerformMappingDisplay(
1219 ShellCommandLineGetFlag(Package, L"-v"),
1220 TRUE,
1221 TRUE,
1222 NULL,
1223 SfoMode,
1224 Param1,
1225 TRUE
1226 );
1227 } else {
1228 //
1229 // now do the display...
1230 //
1231 ShellStatus = PerformMappingDisplay2(
1232 ShellCommandLineGetFlag(Package, L"-v"),
1233 ConstMode,
1234 NormlMode,
1235 TypeString,
1236 SfoMode,
1237 Param1
1238 );
1239 }
1240 }
1241 } else {
1242 //
1243 // adding or displaying (there were no flags)
1244 //
1245 SName = ShellCommandLineGetRawValue(Package, 1);
1246 Mapping = ShellCommandLineGetRawValue(Package, 2);
1247 if ( SName == NULL
1248 && Mapping == NULL
1249 ){
1250 //
1251 // display only since no flags
1252 //
1253 ShellStatus = PerformMappingDisplay(
1254 ShellCommandLineGetFlag(Package, L"-v"),
1255 TRUE,
1256 TRUE,
1257 NULL,
1258 SfoMode,
1259 NULL,
1260 TRUE
1261 );
1262 } else if ( SName == NULL
1263 || Mapping == NULL
1264 ){
1265 //
1266 // Display only the one specified
1267 //
1268 ShellStatus = PerformMappingDisplay(
1269 FALSE,
1270 FALSE,
1271 FALSE,
1272 NULL,
1273 SfoMode,
1274 SName, // note the variable here...
1275 TRUE
1276 );
1277 } else {
1278 if (ShellIsHexOrDecimalNumber(Mapping, TRUE, FALSE)) {
1279 MapAsHandle = ConvertHandleIndexToHandle(ShellStrToUintn(Mapping));
1280 } else {
1281 MapAsHandle = NULL;
1282 }
1283 if (MapAsHandle == NULL && Mapping[StrLen(Mapping)-1] != L':') {
1284 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Mapping);
1285 ShellStatus = SHELL_INVALID_PARAMETER;
1286 } else {
1287 if (MapAsHandle != NULL) {
1288 TempStringLength = StrLen(SName);
1289 if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {
1290 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);
1291 ShellStatus = SHELL_INVALID_PARAMETER;
1292 } else {
1293 ShellStatus = AddMappingFromHandle(MapAsHandle, SName);
1294 }
1295 } else {
1296 TempStringLength = StrLen(SName);
1297 if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {
1298 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);
1299 ShellStatus = SHELL_INVALID_PARAMETER;
1300 } else {
1301 ShellStatus = AddMappingFromMapping(Mapping, SName);
1302 }
1303 }
1304 if (ShellStatus != SHELL_SUCCESS) {
1305 switch (ShellStatus) {
1306 case SHELL_ACCESS_DENIED:
1307 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
1308 break;
1309 case SHELL_INVALID_PARAMETER:
1310 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
1311 break;
1312 case SHELL_DEVICE_ERROR:
1313 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NOF), gShellLevel2HiiHandle, Mapping);
1314 break;
1315 default:
1316 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, ShellStatus|MAX_BIT);
1317 }
1318 } else {
1319 //
1320 // now do the display...
1321 //
1322 ShellStatus = PerformMappingDisplay(
1323 FALSE,
1324 FALSE,
1325 FALSE,
1326 NULL,
1327 SfoMode,
1328 SName,
1329 TRUE
1330 );
1331 } // we were sucessful so do an output
1332 } // got a valid map target
1333 } // got 2 variables
1334 } // we are adding a mapping
1335 } // got valid parameters
1336 }
1337
1338 //
1339 // free the command line package
1340 //
1341 ShellCommandLineFreeVarList (Package);
1342
1343 return (ShellStatus);
1344 }
1345