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