QuarkSocPkg: Remove X64 from SUPPORTED_ARCHITECTURES
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Map.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for map shell level 2 command.\r
3\r
c011b6c9 4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
db906063 5 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "UefiShellLevel2CommandsLib.h"\r
17#include <Protocol/SimpleFileSystem.h>\r
18#include <Protocol/BlockIo.h>\r
19#include <Library/DevicePathLib.h>\r
20#include <Library/HandleParsingLib.h>\r
21#include <Library/SortLib.h>\r
22\r
b54fd049 23/**\r
24 Determine if a string has only numbers and letters.\r
25\r
26 This is useful for such things as Map names which can only be letters and numbers.\r
27\r
28 @param[in] String pointer to the string to analyze,\r
29 @param[in] Len Number of characters to analyze.\r
30\r
31 @retval TRUE String has only numbers and letters\r
32 @retval FALSE String has at least one other character.\r
33**/\r
34BOOLEAN\r
35EFIAPI\r
36IsNumberLetterOnly(\r
37 IN CONST CHAR16 *String,\r
38 IN CONST UINTN Len\r
39 )\r
40{\r
41 UINTN Count;\r
42 for (Count = 0 ; Count < Len && String != NULL && *String != CHAR_NULL ; String++,Count++) {\r
43 if (! ((*String >= L'a' && *String <= L'z') ||\r
44 (*String >= L'A' && *String <= L'Z') ||\r
45 (*String >= L'0' && *String <= L'9'))\r
46 ){\r
47 return (FALSE);\r
48 }\r
49 }\r
50 return (TRUE);\r
51}\r
52\r
53/**\r
54 Do a search in the Target delimited list.\r
55\r
56 @param[in] List The list to seatch in.\r
57 @param[in] MetaTarget The item to search for. MetaMatching supported.\r
58 @param[out] FullName Optional pointer to an allocated buffer containing \r
59 the match.\r
60 @param[in] Meta TRUE to use MetaMatching.\r
61 @param[in] SkipTrailingNumbers TRUE to allow for numbers after the MetaTarget.\r
62 @param[in] Target The single character that delimits list \r
63 items (";" normally). \r
64**/\r
a405b86d 65BOOLEAN\r
66EFIAPI\r
67SearchList(\r
68 IN CONST CHAR16 *List,\r
69 IN CONST CHAR16 *MetaTarget,\r
70 OUT CHAR16 **FullName OPTIONAL,\r
71 IN CONST BOOLEAN Meta,\r
72 IN CONST BOOLEAN SkipTrailingNumbers,\r
73 IN CONST CHAR16 *Target\r
74\r
75 )\r
76{\r
77 CHAR16 *TempList;\r
78 CONST CHAR16 *ListWalker;\r
79 BOOLEAN Result;\r
80 CHAR16 *TempSpot;\r
81\r
82 for (ListWalker = List , TempList = NULL\r
83 ; ListWalker != NULL && *ListWalker != CHAR_NULL\r
84 ;\r
85 ) {\r
86 TempList = StrnCatGrow(&TempList, NULL, ListWalker, 0);\r
87 ASSERT(TempList != NULL);\r
88 TempSpot = StrStr(TempList, Target);\r
89 if (TempSpot != NULL) {\r
90 *TempSpot = CHAR_NULL;\r
91 }\r
92\r
93 while (SkipTrailingNumbers && (ShellIsDecimalDigitCharacter(TempList[StrLen(TempList)-1]) || TempList[StrLen(TempList)-1] == L':')) {\r
94 TempList[StrLen(TempList)-1] = CHAR_NULL;\r
95 }\r
96\r
97 ListWalker = StrStr(ListWalker, Target);\r
98 while(ListWalker != NULL && *ListWalker == *Target) {\r
99 ListWalker++;\r
100 }\r
101 if (Meta) {\r
102 Result = gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16*)TempList, (CHAR16*)MetaTarget);\r
103 } else {\r
104 Result = (BOOLEAN)(StrCmp(TempList, MetaTarget)==0);\r
105 }\r
106 if (Result) {\r
107 if (FullName != NULL) {\r
108 *FullName = TempList;\r
109 } else {\r
110 FreePool(TempList);\r
111 }\r
112 return (TRUE);\r
113 }\r
114 FreePool(TempList);\r
115 TempList = NULL;\r
116 }\r
117\r
118 return (FALSE);\r
119}\r
120\r
b54fd049 121/**\r
122 Determine what type of device is represented and return it's string. The \r
123 string is in allocated memory and must be callee freed. The HII is is listed below.\r
124 The actual string cannot be determined.\r
125\r
126 @param[in] DevicePath The device to analyze.\r
127\r
128 @retval STR_MAP_MEDIA_UNKNOWN The media type is unknown.\r
129 @retval STR_MAP_MEDIA_HARDDISK The media is a hard drive.\r
130 @retval STR_MAP_MEDIA_CDROM The media is a CD ROM.\r
131 @retval STR_MAP_MEDIA_FLOPPY The media is a floppy drive.\r
132**/\r
a405b86d 133CHAR16*\r
134EFIAPI\r
135GetDeviceMediaType (\r
136 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
137 )\r
138{\r
139 ACPI_HID_DEVICE_PATH *Acpi;\r
140\r
141 //\r
142 // Parse the device path:\r
143 // Devicepath sub type mediatype\r
144 // MEDIA_HANRDDRIVE_DP -> Hard Disk\r
145 // MEDIA_CDROM_DP -> CD Rom\r
146 // Acpi.HID = 0X0604 -> Floppy\r
147 //\r
148 if (NULL == DevicePath) {\r
149 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);\r
150 }\r
151\r
152 for (;!IsDevicePathEndType (DevicePath) ;DevicePath = NextDevicePathNode (DevicePath)) {\r
153 if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) {\r
154 switch (DevicePathSubType (DevicePath)) {\r
155 case MEDIA_HARDDRIVE_DP:\r
156 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK), NULL);\r
157 case MEDIA_CDROM_DP:\r
158 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_CDROM), NULL);\r
159 }\r
160 } else if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH) {\r
161 Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath;\r
162 if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r
163 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY), NULL);\r
164 }\r
165 }\r
166 }\r
167\r
168 return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);\r
169}\r
170\r
171/**\r
172 Function to detemine if a handle has removable storage.\r
173\r
174 @param[in] DevicePath DevicePath to test.\r
175\r
176 @retval TRUE The handle has removable storage.\r
177 @retval FALSE The handle does not have removable storage.\r
178**/\r
179BOOLEAN\r
180EFIAPI\r
181IsRemoveableDevice (\r
182 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
183 )\r
184{\r
185 if (NULL == DevicePath) {\r
186 return FALSE;\r
187 }\r
188\r
189 while (!IsDevicePathEndType (DevicePath)) {\r
190 if (DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) {\r
191 switch (DevicePathSubType (DevicePath)) {\r
192 case MSG_USB_DP:\r
193 case MSG_SCSI_DP:\r
194 return TRUE;\r
195 default:\r
196 return FALSE;\r
197 }\r
198 }\r
199 DevicePath = NextDevicePathNode (DevicePath);\r
200 }\r
201 return FALSE;\r
202}\r
203\r
204/**\r
205 Function to detemine if a something on the map list matches.\r
206\r
207 @param[in] MapList The pointer to the list to test.\r
208 @param[in] Specific The pointer to a specific name to test for.\r
209 @param[in] TypeString The pointer to the list of types.\r
210 @param[in] Normal Always show normal mappings.\r
211 @param[in] Consist Always show consistent mappings.\r
212\r
213 @retval TRUE The map should be displayed.\r
214 @retval FALSE The map should not be displayed.\r
215**/\r
216BOOLEAN\r
217EFIAPI\r
218MappingListHasType(\r
219 IN CONST CHAR16 *MapList,\r
220 IN CONST CHAR16 *Specific,\r
221 IN CONST CHAR16 *TypeString,\r
222 IN CONST BOOLEAN Normal,\r
223 IN CONST BOOLEAN Consist\r
224 )\r
225{\r
b54fd049 226 CHAR16 *NewSpecific;\r
db906063
QS
227 RETURN_STATUS Status;\r
228 \r
a405b86d 229 //\r
230 // specific has priority\r
231 //\r
b54fd049 232 if (Specific != NULL) {\r
81957f8d 233 NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific);\r
33c031ee 234 if (NewSpecific == NULL){\r
235 return FALSE;\r
236 }\r
b54fd049 237 if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
db906063
QS
238 Status = StrnCatS(NewSpecific, (StrSize(Specific) + sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":"));\r
239 if (EFI_ERROR (Status)) {\r
240 FreePool(NewSpecific);\r
241 return FALSE;\r
242 }\r
b54fd049 243 }\r
a405b86d 244\r
b54fd049 245 if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {\r
246 FreePool(NewSpecific);\r
247 return (TRUE);\r
248 }\r
249 FreePool(NewSpecific);\r
250 }\r
a405b86d 251 if ( Consist\r
022ed0d7 252 && Specific == NULL\r
a405b86d 253 && (SearchList(MapList, L"HD*", NULL, TRUE, TRUE, L";")\r
254 ||SearchList(MapList, L"CD*", NULL, TRUE, TRUE, L";")\r
77dd0c81 255 ||SearchList(MapList, L"F*", NULL, TRUE, TRUE, L";")\r
a405b86d 256 ||SearchList(MapList, L"FP*", NULL, TRUE, TRUE, L";"))){\r
257 return (TRUE);\r
258 }\r
259\r
260 if ( Normal\r
022ed0d7 261 && Specific == NULL\r
a405b86d 262 && (SearchList(MapList, L"FS", NULL, FALSE, TRUE, L";")\r
263 ||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){\r
264 return (TRUE);\r
265 }\r
266\r
267 if (TypeString != NULL && SearchList(MapList, TypeString, NULL, TRUE, TRUE, L";")) {\r
268 return (TRUE);\r
269 }\r
270 return (FALSE);\r
271}\r
272\r
273\r
b54fd049 274/**\r
275 Display a single map line for device Handle if conditions are met.\r
276\r
277 @param[in] Verbose TRUE to display (extra) verbose information.\r
278 @param[in] Consist TRUE to display consistent mappings.\r
279 @param[in] Normal TRUE to display normal (not consist) mappings.\r
280 @param[in] TypeString pointer to string of filter types.\r
281 @param[in] SFO TRUE to display output in Standard Output Format.\r
282 @param[in] Specific pointer to string for specific map to display.\r
283 @param[in] Handle The handle to display from.\r
284\r
285 @retval EFI_SUCCESS The mapping was displayed.\r
286**/\r
287EFI_STATUS\r
a405b86d 288EFIAPI\r
289PerformSingleMappingDisplay(\r
290 IN CONST BOOLEAN Verbose,\r
291 IN CONST BOOLEAN Consist,\r
292 IN CONST BOOLEAN Normal,\r
293 IN CONST CHAR16 *TypeString,\r
294 IN CONST BOOLEAN SFO,\r
295 IN CONST CHAR16 *Specific OPTIONAL,\r
296 IN CONST EFI_HANDLE Handle\r
297 )\r
298{\r
299 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
300 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;\r
301 CONST CHAR16 *MapList;\r
302 CHAR16 *CurrentName;\r
303 CHAR16 *MediaType;\r
304 CHAR16 *DevPathString;\r
305 CHAR16 *TempSpot;\r
64a5bae2 306 CHAR16 *Alias;\r
a405b86d 307 UINTN TempLen;\r
308 BOOLEAN Removable;\r
309 CONST CHAR16 *TempSpot2;\r
310\r
64a5bae2
JC
311 Alias = NULL;\r
312 TempSpot2 = NULL;\r
313 CurrentName = NULL;\r
a405b86d 314 DevPath = DevicePathFromHandle(Handle);\r
315 DevPathCopy = DevPath;\r
316 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);\r
317 if (MapList == NULL) {\r
b54fd049 318 return EFI_NOT_FOUND;\r
a405b86d 319 }\r
320\r
321 if (!MappingListHasType(MapList, Specific, TypeString, Normal, Consist)){\r
b54fd049 322 return EFI_NOT_FOUND;\r
a405b86d 323 }\r
324\r
f747c71e
JC
325 if (Normal || !Consist) {\r
326 //\r
327 // need the Normal here since people can use both on command line. otherwise unused.\r
328 //\r
329\r
64a5bae2
JC
330 //\r
331 // Allocate a name\r
332 //\r
333 CurrentName = NULL;\r
334 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);\r
335 if (CurrentName == NULL) {\r
336 return (EFI_OUT_OF_RESOURCES);\r
337 }\r
338\r
339 //\r
340 // Chop off the other names that become "Alias(s)"\r
341 // leaving just the normal name\r
342 //\r
343 TempSpot = StrStr(CurrentName, L";");\r
344 if (TempSpot != NULL) {\r
345 *TempSpot = CHAR_NULL;\r
346 }\r
f747c71e 347 } else {\r
64a5bae2
JC
348 CurrentName = NULL;\r
349\r
350 //\r
351 // Skip the first name. This is the standard name.\r
352 //\r
353 TempSpot = StrStr(MapList, L";");\r
354 if (TempSpot != NULL) {\r
355 TempSpot++;\r
356 }\r
357 SearchList(TempSpot, L"HD*", &CurrentName, TRUE, FALSE, L";");\r
358 if (CurrentName == NULL) {\r
359 SearchList(TempSpot, L"CD*", &CurrentName, TRUE, FALSE, L";");\r
360 }\r
361 if (CurrentName == NULL) {\r
362 SearchList(TempSpot, L"FP*", &CurrentName, TRUE, FALSE, L";");\r
363 }\r
364 if (CurrentName == NULL) {\r
365 SearchList(TempSpot, L"F*", &CurrentName, TRUE, FALSE, L";");\r
366 }\r
367 if (CurrentName == NULL) {\r
368 //\r
369 // We didnt find anything, so just the first one in the list...\r
370 //\r
371 CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);\r
372 if (CurrentName == NULL) {\r
373 return (EFI_OUT_OF_RESOURCES);\r
374 }\r
375 TempSpot = StrStr(CurrentName, L";");\r
376 if (TempSpot != NULL) {\r
377 *TempSpot = CHAR_NULL;\r
378 }\r
379 } else {\r
380 Alias = StrnCatGrow(&Alias, 0, MapList, 0);\r
c6cef635
SQ
381 if (Alias == NULL) {\r
382 return EFI_OUT_OF_RESOURCES;\r
383 }\r
64a5bae2
JC
384 TempSpot = StrStr(Alias, CurrentName);\r
385 if (TempSpot != NULL) {\r
386 TempSpot2 = StrStr(TempSpot, L";");\r
387 if (TempSpot2 != NULL) {\r
388 TempSpot2++; // Move past ";" from CurrentName\r
389 CopyMem(TempSpot, TempSpot2, StrSize(TempSpot2));\r
390 } else {\r
391 *TempSpot = CHAR_NULL;\r
392 }\r
393 }\r
394 if (Alias[StrLen(Alias)-1] == L';') {\r
395 Alias[StrLen(Alias)-1] = CHAR_NULL;\r
396 }\r
397 }\r
a405b86d 398 }\r
863986b3 399 DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
f747c71e 400 TempLen = StrLen(CurrentName);\r
a405b86d 401 if (!SFO) {\r
a405b86d 402 ShellPrintHiiEx (\r
403 -1,\r
404 -1,\r
405 NULL,\r
406 STRING_TOKEN (STR_MAP_ENTRY),\r
407 gShellLevel2HiiHandle,\r
408 CurrentName,\r
64a5bae2 409 Alias!=NULL?Alias:(TempLen < StrLen(MapList)?MapList + TempLen+1:L""),\r
a405b86d 410 DevPathString\r
411 );\r
412 if (Verbose) {\r
413 //\r
414 // also print handle, media type, removable (y/n), and current directory\r
415 //\r
416 MediaType = GetDeviceMediaType(DevPath);\r
417 if ((TypeString != NULL &&MediaType != NULL && StrStr(TypeString, MediaType) != NULL) || TypeString == NULL) {\r
418 Removable = IsRemoveableDevice(DevPath);\r
419 TempSpot2 = ShellGetCurrentDir(CurrentName);\r
420 ShellPrintHiiEx (\r
421 -1,\r
422 -1,\r
423 NULL,\r
424 STRING_TOKEN (STR_MAP_ENTRY_VERBOSE),\r
425 gShellLevel2HiiHandle,\r
426 ConvertHandleToHandleIndex(Handle),\r
427 MediaType,\r
428 Removable?L"Yes":L"No",\r
429 TempSpot2\r
430 );\r
431 }\r
64a5bae2 432 SHELL_FREE_NON_NULL(MediaType);\r
a405b86d 433 }\r
434 } else {\r
a405b86d 435 ShellPrintHiiEx (\r
436 -1,\r
437 -1,\r
438 NULL,\r
439 STRING_TOKEN (STR_MAP_SFO_MAPPINGS),\r
440 gShellLevel2HiiHandle,\r
441 CurrentName,\r
442 DevPathString,\r
64a5bae2 443 Consist?L"":(TempLen < StrLen(MapList)?MapList + TempLen+1:L"")\r
a405b86d 444 );\r
445 }\r
64a5bae2
JC
446 SHELL_FREE_NON_NULL(DevPathString);\r
447 SHELL_FREE_NON_NULL(CurrentName);\r
448 SHELL_FREE_NON_NULL(Alias);\r
b54fd049 449 return EFI_SUCCESS;\r
a405b86d 450}\r
451\r
b54fd049 452/**\r
453 Delete Specific from the list of maps for device Handle.\r
454\r
455 @param[in] Specific The name to delete.\r
456 @param[in] Handle The device to look on.\r
457\r
458 @retval EFI_SUCCESS The delete was successful.\r
459 @retval EFI_NOT_FOUND Name was not a map on Handle.\r
460**/\r
a405b86d 461EFI_STATUS\r
462EFIAPI\r
463PerformSingleMappingDelete(\r
464 IN CONST CHAR16 *Specific,\r
465 IN CONST EFI_HANDLE Handle\r
466 )\r
467{\r
468 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
469 EFI_DEVICE_PATH_PROTOCOL *DevPathCopy;\r
470 CONST CHAR16 *MapList;\r
471 CHAR16 *CurrentName;\r
472\r
473 DevPath = DevicePathFromHandle(Handle);\r
474 DevPathCopy = DevPath;\r
475 MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);\r
476 CurrentName = NULL;\r
477\r
478 if (MapList == NULL) {\r
479 return (EFI_NOT_FOUND);\r
480 }\r
481 //\r
482 // if there is a specific and its not on the list...\r
483 //\r
484 if (!SearchList(MapList, Specific, &CurrentName, TRUE, FALSE, L";")) {\r
485 return (EFI_NOT_FOUND);\r
486 }\r
487 return (gEfiShellProtocol->SetMap(NULL, CurrentName));\r
488}\r
489\r
b54fd049 490CONST CHAR16 Cd[] = L"cd*";\r
491CONST CHAR16 Hd[] = L"hd*";\r
492CONST CHAR16 Fp[] = L"fp*";\r
493CONST CHAR16 AnyF[] = L"F*";\r
a405b86d 494/**\r
495 Function to display mapping information to the user.\r
496\r
a1d4bfcc 497 If Specific is specified then Consist and Normal will be ignored since information will\r
a405b86d 498 be printed for the specific item only.\r
499\r
a1d4bfcc 500 @param[in] Verbose TRUE to display (extra) verbose information.\r
501 @param[in] Consist TRUE to display consistent mappings.\r
502 @param[in] Normal TRUE to display normal (not consist) mappings.\r
503 @param[in] TypeString Pointer to string of filter types.\r
504 @param[in] SFO TRUE to display output in Standard Output Format.\r
505 @param[in] Specific Pointer to string for specific map to display.\r
506 @param[in] Header TRUE to print the header block.\r
a405b86d 507\r
a1d4bfcc 508 @retval SHELL_SUCCESS The display was printed.\r
509 @retval SHELL_INVALID_PARAMETER One of Consist or Normal must be TRUE if no Specific.\r
a405b86d 510\r
511**/\r
a405b86d 512SHELL_STATUS\r
513EFIAPI\r
514PerformMappingDisplay(\r
515 IN CONST BOOLEAN Verbose,\r
516 IN CONST BOOLEAN Consist,\r
517 IN CONST BOOLEAN Normal,\r
518 IN CONST CHAR16 *TypeString,\r
519 IN CONST BOOLEAN SFO,\r
520 IN CONST CHAR16 *Specific OPTIONAL,\r
521 IN CONST BOOLEAN Header\r
522 )\r
523{\r
524 EFI_STATUS Status;\r
525 EFI_HANDLE *HandleBuffer;\r
526 UINTN BufferSize;\r
527 UINTN LoopVar;\r
528 CHAR16 *Test;\r
b54fd049 529 BOOLEAN Found;\r
a405b86d 530\r
531 if (!Consist && !Normal && Specific == NULL && TypeString == NULL) {\r
099e8ff5 532 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"map"); \r
a405b86d 533 return (SHELL_INVALID_PARAMETER);\r
534 }\r
535\r
536 if (TypeString != NULL) {\r
537 Test = (CHAR16*)Cd;\r
538 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {\r
539 Test = (CHAR16*)Hd;\r
540 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {\r
541 Test = (CHAR16*)Fp;\r
542 if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {\r
099e8ff5 543 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"map", TypeString); \r
a405b86d 544 return (SHELL_INVALID_PARAMETER);\r
545 }\r
546 } else if (Test == NULL) {\r
b54fd049 547 Test = (CHAR16*)AnyF;\r
a405b86d 548 }\r
549 }\r
550 } else {\r
551 Test = NULL;\r
552 }\r
553\r
554 if (Header) {\r
555 //\r
556 // Print the header\r
557 //\r
558 if (!SFO) {\r
559 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_HEADER), gShellLevel2HiiHandle);\r
560 } else {\r
561 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"map");\r
562 }\r
563 }\r
564\r
565 BufferSize = 0;\r
566 HandleBuffer = NULL;\r
567\r
568 //\r
569 // Look up all SimpleFileSystems in the platform\r
570 //\r
571 Status = gBS->LocateHandle(\r
572 ByProtocol,\r
b54fd049 573 &gEfiSimpleFileSystemProtocolGuid,\r
a405b86d 574 NULL,\r
575 &BufferSize,\r
576 HandleBuffer);\r
577 if (Status == EFI_BUFFER_TOO_SMALL) {\r
b54fd049 578 HandleBuffer = AllocateZeroPool(BufferSize);\r
9ea69f8a 579 if (HandleBuffer == NULL) {\r
580 return (SHELL_OUT_OF_RESOURCES);\r
581 }\r
a405b86d 582 Status = gBS->LocateHandle(\r
583 ByProtocol,\r
b54fd049 584 &gEfiSimpleFileSystemProtocolGuid,\r
a405b86d 585 NULL,\r
586 &BufferSize,\r
587 HandleBuffer);\r
588 }\r
a405b86d 589\r
590 //\r
591 // Get the map name(s) for each one.\r
592 //\r
b54fd049 593 for ( LoopVar = 0, Found = FALSE\r
33c031ee 594 ; LoopVar < (BufferSize / sizeof(EFI_HANDLE)) && HandleBuffer != NULL\r
a405b86d 595 ; LoopVar ++\r
596 ){\r
b54fd049 597 Status = PerformSingleMappingDisplay(\r
a405b86d 598 Verbose,\r
599 Consist,\r
600 Normal,\r
601 Test,\r
602 SFO,\r
603 Specific,\r
604 HandleBuffer[LoopVar]);\r
b54fd049 605 if (!EFI_ERROR(Status)) {\r
606 Found = TRUE;\r
607 }\r
a405b86d 608 }\r
609\r
610 //\r
611 // Look up all BlockIo in the platform\r
612 //\r
613 Status = gBS->LocateHandle(\r
614 ByProtocol,\r
615 &gEfiBlockIoProtocolGuid,\r
616 NULL,\r
617 &BufferSize,\r
618 HandleBuffer);\r
619 if (Status == EFI_BUFFER_TOO_SMALL) {\r
33c031ee 620 SHELL_FREE_NON_NULL(HandleBuffer);\r
b54fd049 621 HandleBuffer = AllocateZeroPool(BufferSize);\r
9ea69f8a 622 if (HandleBuffer == NULL) {\r
623 return (SHELL_OUT_OF_RESOURCES);\r
624 }\r
a405b86d 625 Status = gBS->LocateHandle(\r
626 ByProtocol,\r
627 &gEfiBlockIoProtocolGuid,\r
628 NULL,\r
629 &BufferSize,\r
630 HandleBuffer);\r
631 }\r
ae724571 632 if (!EFI_ERROR(Status) && HandleBuffer != NULL) {\r
a405b86d 633 //\r
9ea69f8a 634 // Get the map name(s) for each one.\r
a405b86d 635 //\r
9ea69f8a 636 for ( LoopVar = 0\r
637 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
638 ; LoopVar ++\r
639 ){\r
640 //\r
641 // Skip any that were already done...\r
642 //\r
643 if (gBS->OpenProtocol(\r
644 HandleBuffer[LoopVar],\r
b54fd049 645 &gEfiSimpleFileSystemProtocolGuid,\r
9ea69f8a 646 NULL,\r
647 gImageHandle,\r
648 NULL,\r
649 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {\r
650 continue;\r
651 }\r
b54fd049 652 Status = PerformSingleMappingDisplay(\r
9ea69f8a 653 Verbose,\r
654 Consist,\r
655 Normal,\r
656 Test,\r
657 SFO,\r
658 Specific,\r
659 HandleBuffer[LoopVar]);\r
b54fd049 660 if (!EFI_ERROR(Status)) {\r
661 Found = TRUE;\r
662 }\r
a405b86d 663 }\r
9ea69f8a 664 FreePool(HandleBuffer);\r
a405b86d 665 }\r
b54fd049 666 if (!Found) {\r
77dd0c81 667 if (Specific != NULL) {\r
099e8ff5 668 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, L"map", Specific); \r
77dd0c81 669 } else {\r
099e8ff5 670 ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle, L"map"); \r
77dd0c81 671 }\r
b54fd049 672 }\r
a405b86d 673 return (SHELL_SUCCESS);\r
674}\r
675\r
b54fd049 676/**\r
677 Perform a mapping display and parse for multiple types in the TypeString.\r
678\r
679 @param[in] Verbose TRUE to use verbose output.\r
680 @param[in] Consist TRUE to display consistent names.\r
681 @param[in] Normal TRUE to display normal names.\r
682 @param[in] TypeString An optional comma-delimited list of types.\r
683 @param[in] SFO TRUE to display in SFO format. See Spec.\r
684 @param[in] Specific An optional specific map name to display alone.\r
685\r
686 @retval SHELL_INVALID_PARAMETER A parameter was invalid.\r
687 @retval SHELL_SUCCESS The display was successful.\r
688 @sa PerformMappingDisplay\r
689**/\r
a405b86d 690SHELL_STATUS\r
691EFIAPI\r
692PerformMappingDisplay2(\r
693 IN CONST BOOLEAN Verbose,\r
694 IN CONST BOOLEAN Consist,\r
695 IN CONST BOOLEAN Normal,\r
696 IN CONST CHAR16 *TypeString,\r
697 IN CONST BOOLEAN SFO,\r
698 IN CONST CHAR16 *Specific OPTIONAL\r
699 )\r
700{\r
701 CONST CHAR16 *TypeWalker;\r
702 SHELL_STATUS ShellStatus;\r
703 CHAR16 *Comma;\r
704\r
705\r
706 if (TypeString == NULL) {\r
707 return (PerformMappingDisplay(Verbose, Consist, Normal, NULL, SFO, Specific, TRUE));\r
708 }\r
709 ShellStatus = SHELL_SUCCESS;\r
710 for (TypeWalker = TypeString ; TypeWalker != NULL && *TypeWalker != CHAR_NULL ;) {\r
711 Comma = StrStr(TypeWalker, L",");\r
712 if (Comma == NULL) {\r
713 if (ShellStatus == SHELL_SUCCESS) {\r
714 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));\r
715 } else {\r
716 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));\r
717 }\r
718 break;\r
719 } else {\r
720 *Comma = CHAR_NULL;\r
721 if (ShellStatus == SHELL_SUCCESS) {\r
722 ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));\r
723 } else {\r
724 PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));\r
725 }\r
726 *Comma = L',';\r
727 TypeWalker = Comma + 1;\r
728 }\r
729 }\r
730\r
731 return (ShellStatus);\r
732}\r
733\r
b54fd049 734/**\r
735 Delete a specific map.\r
736\r
737 @param[in] Specific The pointer to the name of the map to delete.\r
738\r
739 @retval EFI_INVALID_PARAMETER Specific was NULL.\r
740 @retval EFI_SUCCESS The operation was successful.\r
741 @retval EFI_NOT_FOUND Specific could not be found.\r
742**/\r
a405b86d 743EFI_STATUS\r
744EFIAPI\r
745PerformMappingDelete(\r
746 IN CONST CHAR16 *Specific\r
747 )\r
748{\r
749 EFI_STATUS Status;\r
750 EFI_HANDLE *HandleBuffer;\r
751 UINTN BufferSize;\r
752 UINTN LoopVar;\r
753 BOOLEAN Deleted;\r
754\r
755 if (Specific == NULL) {\r
756 return (EFI_INVALID_PARAMETER);\r
757 }\r
758\r
759 BufferSize = 0;\r
760 HandleBuffer = NULL;\r
761 Deleted = FALSE;\r
762\r
763 //\r
764 // Look up all SimpleFileSystems in the platform\r
765 //\r
766 Status = gBS->LocateHandle(\r
767 ByProtocol,\r
768 &gEfiDevicePathProtocolGuid,\r
769 NULL,\r
770 &BufferSize,\r
771 HandleBuffer);\r
772 if (Status == EFI_BUFFER_TOO_SMALL) {\r
b54fd049 773 HandleBuffer = AllocateZeroPool(BufferSize);\r
3e082d58 774 if (HandleBuffer == NULL) {\r
775 return (EFI_OUT_OF_RESOURCES);\r
776 }\r
a405b86d 777 Status = gBS->LocateHandle(\r
778 ByProtocol,\r
779 &gEfiDevicePathProtocolGuid,\r
780 NULL,\r
781 &BufferSize,\r
782 HandleBuffer);\r
783 }\r
3e082d58 784 if (EFI_ERROR(Status)) {\r
785 SHELL_FREE_NON_NULL(HandleBuffer);\r
786 return (Status);\r
787 }\r
a405b86d 788\r
c154b997 789 if (HandleBuffer != NULL) {\r
790 //\r
791 // Get the map name(s) for each one.\r
792 //\r
793 for ( LoopVar = 0\r
794 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
795 ; LoopVar ++\r
796 ){\r
797 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
798 Deleted = TRUE;\r
799 }\r
a405b86d 800 }\r
801 }\r
a405b86d 802 //\r
803 // Look up all BlockIo in the platform\r
804 //\r
805 Status = gBS->LocateHandle(\r
806 ByProtocol,\r
807 &gEfiBlockIoProtocolGuid,\r
808 NULL,\r
809 &BufferSize,\r
810 HandleBuffer);\r
811 if (Status == EFI_BUFFER_TOO_SMALL) {\r
812 FreePool(HandleBuffer);\r
b54fd049 813 HandleBuffer = AllocateZeroPool(BufferSize);\r
3e082d58 814 if (HandleBuffer == NULL) {\r
815 return (EFI_OUT_OF_RESOURCES);\r
816 }\r
a405b86d 817 Status = gBS->LocateHandle(\r
818 ByProtocol,\r
819 &gEfiBlockIoProtocolGuid,\r
820 NULL,\r
821 &BufferSize,\r
822 HandleBuffer);\r
823 }\r
3e082d58 824 if (EFI_ERROR(Status)) {\r
825 SHELL_FREE_NON_NULL(HandleBuffer);\r
826 return (Status);\r
827 }\r
a405b86d 828\r
c154b997 829 if (HandleBuffer != NULL) {\r
a405b86d 830 //\r
c154b997 831 // Get the map name(s) for each one.\r
a405b86d 832 //\r
c154b997 833 for ( LoopVar = 0\r
834 ; LoopVar < BufferSize / sizeof(EFI_HANDLE)\r
835 ; LoopVar ++\r
836 ){\r
837 //\r
838 // Skip any that were already done...\r
839 //\r
840 if (gBS->OpenProtocol(\r
841 HandleBuffer[LoopVar],\r
842 &gEfiDevicePathProtocolGuid,\r
843 NULL,\r
844 gImageHandle,\r
845 NULL,\r
846 EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {\r
847 continue;\r
848 }\r
849 if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {\r
850 Deleted = TRUE;\r
851 }\r
a405b86d 852 }\r
853 }\r
c154b997 854 SHELL_FREE_NON_NULL(HandleBuffer);\r
a405b86d 855 if (!Deleted) {\r
856 return (EFI_NOT_FOUND);\r
857 }\r
858 return (EFI_SUCCESS);\r
859}\r
860\r
861/**\r
862 function to add a mapping from mapping.\r
863\r
864 This function will get the device path associated with the mapping and call SetMap.\r
865\r
866 @param[in] Map The Map to add a mapping for\r
867 @param[in] SName The name of the new mapping\r
868\r
869 @retval SHELL_SUCCESS the mapping was added\r
870 @retval SHELL_INVALID_PARAMETER the device path for Map could not be retrieved.\r
871 @return Shell version of a return value from EfiShellProtocol->SetMap\r
872\r
873**/\r
874SHELL_STATUS\r
875EFIAPI\r
876AddMappingFromMapping(\r
877 IN CONST CHAR16 *Map,\r
878 IN CONST CHAR16 *SName\r
879 )\r
880{\r
881 CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
882 EFI_STATUS Status;\r
b54fd049 883 CHAR16 *NewSName;\r
db906063 884 RETURN_STATUS StrRetStatus;\r
b54fd049 885 \r
81957f8d 886 NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
33c031ee 887 if (NewSName == NULL) {\r
888 return (SHELL_OUT_OF_RESOURCES);\r
889 }\r
b54fd049 890 if (NewSName[StrLen(NewSName)-1] != L':') {\r
db906063
QS
891 StrRetStatus = StrnCatS(NewSName, (StrSize(SName) + sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":"));\r
892 if (EFI_ERROR(StrRetStatus)) {\r
893 FreePool(NewSName);\r
894 return ((SHELL_STATUS) (StrRetStatus & (~MAX_BIT)));\r
895 }\r
b54fd049 896 }\r
a405b86d 897\r
b54fd049 898 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
899 FreePool(NewSName);\r
a405b86d 900 return (SHELL_INVALID_PARAMETER);\r
901 }\r
902\r
903 DevPath = gEfiShellProtocol->GetDevicePathFromMap(Map);\r
904 if (DevPath == NULL) {\r
b54fd049 905 FreePool(NewSName);\r
a405b86d 906 return (SHELL_INVALID_PARAMETER);\r
907 }\r
908\r
b54fd049 909 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);\r
910 FreePool(NewSName);\r
a405b86d 911 if (EFI_ERROR(Status)) {\r
912 return (SHELL_DEVICE_ERROR);\r
913 }\r
914 return (SHELL_SUCCESS);\r
915}\r
916\r
a405b86d 917/**\r
918 function to add a mapping from an EFI_HANDLE.\r
919\r
920 This function will get the device path associated with the Handle and call SetMap.\r
921\r
922 @param[in] Handle The handle to add a mapping for\r
923 @param[in] SName The name of the new mapping\r
924\r
925 @retval SHELL_SUCCESS the mapping was added\r
926 @retval SHELL_INVALID_PARAMETER SName was not valid for a map name.\r
927 @return Shell version of a return value from either\r
928 gBS->OpenProtocol or EfiShellProtocol->SetMap\r
929\r
930**/\r
931SHELL_STATUS\r
932EFIAPI\r
933AddMappingFromHandle(\r
934 IN CONST EFI_HANDLE Handle,\r
935 IN CONST CHAR16 *SName\r
936 )\r
937{\r
938 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
939 EFI_STATUS Status;\r
b54fd049 940 CHAR16 *NewSName;\r
db906063 941 RETURN_STATUS StrRetStatus;\r
b54fd049 942 \r
81957f8d 943 NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
33c031ee 944 if (NewSName == NULL) {\r
945 return (SHELL_OUT_OF_RESOURCES);\r
946 }\r
b54fd049 947 if (NewSName[StrLen(NewSName)-1] != L':') {\r
db906063
QS
948 StrRetStatus = StrnCatS(NewSName, (StrSize(SName) + sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":"));\r
949 if (EFI_ERROR(StrRetStatus)) {\r
950 FreePool(NewSName);\r
951 return ((SHELL_STATUS) (StrRetStatus & (~MAX_BIT)));\r
952 }\r
b54fd049 953 }\r
a405b86d 954\r
b54fd049 955 if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
956 FreePool(NewSName);\r
a405b86d 957 return (SHELL_INVALID_PARAMETER);\r
958 }\r
959\r
960 Status = gBS->OpenProtocol(\r
961 Handle,\r
962 &gEfiDevicePathProtocolGuid,\r
963 (VOID**)&DevPath,\r
964 gImageHandle,\r
965 NULL,\r
966 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
967 );\r
968 if (EFI_ERROR(Status)) {\r
b54fd049 969 FreePool(NewSName);\r
a405b86d 970 return (SHELL_DEVICE_ERROR);\r
971 }\r
b54fd049 972 Status = gEfiShellProtocol->SetMap(DevPath, NewSName);\r
973 FreePool(NewSName);\r
a405b86d 974 if (EFI_ERROR(Status)) {\r
975 return (SHELL_DEVICE_ERROR);\r
976 }\r
977 return (SHELL_SUCCESS);\r
978}\r
979\r
980STATIC CONST SHELL_PARAM_ITEM MapParamList[] = {\r
981 {L"-d", TypeValue},\r
982 {L"-r", TypeFlag},\r
983 {L"-v", TypeFlag},\r
984 {L"-c", TypeFlag},\r
985 {L"-f", TypeFlag},\r
986 {L"-u", TypeFlag},\r
987 {L"-t", TypeValue},\r
988 {L"-sfo", TypeValue},\r
989 {NULL, TypeMax}\r
990 };\r
991\r
992/**\r
993 Function for 'map' command.\r
994\r
995 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
996 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
997**/\r
998SHELL_STATUS\r
999EFIAPI\r
1000ShellCommandRunMap (\r
1001 IN EFI_HANDLE ImageHandle,\r
1002 IN EFI_SYSTEM_TABLE *SystemTable\r
1003 )\r
1004{\r
1005 EFI_STATUS Status;\r
1006 LIST_ENTRY *Package;\r
1007 CHAR16 *ProblemParam;\r
1008 CONST CHAR16 *SName;\r
1009 CONST CHAR16 *Mapping;\r
b54fd049 1010 EFI_HANDLE MapAsHandle;\r
a405b86d 1011 SHELL_STATUS ShellStatus;\r
1012 BOOLEAN SfoMode;\r
1013 BOOLEAN ConstMode;\r
1014 BOOLEAN NormlMode;\r
1015 CONST CHAR16 *Param1;\r
1016 CONST CHAR16 *TypeString;\r
b54fd049 1017 UINTN TempStringLength;\r
a405b86d 1018\r
1019 ProblemParam = NULL;\r
1020 Mapping = NULL;\r
1021 SName = NULL;\r
a405b86d 1022 ShellStatus = SHELL_SUCCESS;\r
b54fd049 1023 MapAsHandle = NULL;\r
a405b86d 1024\r
1025 //\r
1026 // initialize the shell lib (we must be in non-auto-init...)\r
1027 //\r
1028 Status = ShellInitialize();\r
1029 ASSERT_EFI_ERROR(Status);\r
1030\r
1031 Status = CommandInit();\r
1032 ASSERT_EFI_ERROR(Status);\r
1033\r
1034 //\r
1035 // parse the command line\r
1036 //\r
1037 Status = ShellCommandLineParse (MapParamList, &Package, &ProblemParam, TRUE);\r
1038 if (EFI_ERROR(Status)) {\r
1039 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
099e8ff5 1040 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"map", ProblemParam); \r
a405b86d 1041 FreePool(ProblemParam);\r
1042 ShellStatus = SHELL_INVALID_PARAMETER;\r
1043 } else {\r
1044 ASSERT(FALSE);\r
1045 }\r
1046 } else {\r
1047 //\r
1048 // check for "-?"\r
1049 //\r
1050 SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");\r
1051 ConstMode = ShellCommandLineGetFlag(Package, L"-c");\r
1052 NormlMode = ShellCommandLineGetFlag(Package, L"-f");\r
1053 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
1054 ASSERT(FALSE);\r
1055 } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {\r
099e8ff5 1056 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"map"); \r
a405b86d 1057 ShellStatus = SHELL_INVALID_PARAMETER;\r
1058 } else {\r
1059 //\r
1060 // Deleting a map name...\r
1061 //\r
1062 if (ShellCommandLineGetFlag(Package, L"-d")) {\r
1063 if ( ShellCommandLineGetFlag(Package, L"-r")\r
1064 || ShellCommandLineGetFlag(Package, L"-v")\r
1065 || ConstMode\r
1066 || NormlMode\r
1067 || ShellCommandLineGetFlag(Package, L"-u")\r
1068 || ShellCommandLineGetFlag(Package, L"-t")\r
1069 ){\r
099e8ff5 1070 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle, L"map"); \r
a405b86d 1071 ShellStatus = SHELL_INVALID_PARAMETER;\r
1072 } else {\r
1073 SName = ShellCommandLineGetValue(Package, L"-d");\r
1074 if (SName != NULL) {\r
1075 Status = PerformMappingDelete(SName);\r
1076 if (EFI_ERROR(Status)) {\r
cbcccd2c 1077 if (Status == EFI_ACCESS_DENIED) {\r
099e8ff5 1078 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle, L"map"); \r
cbcccd2c
LG
1079 ShellStatus = SHELL_ACCESS_DENIED;\r
1080 } else if (Status == EFI_NOT_FOUND) {\r
099e8ff5 1081 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, L"map", SName); \r
cbcccd2c
LG
1082 ShellStatus = SHELL_INVALID_PARAMETER;\r
1083 } else {\r
099e8ff5 1084 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"map", Status); \r
cbcccd2c 1085 ShellStatus = SHELL_UNSUPPORTED;\r
a405b86d 1086 }\r
1087 }\r
1088 } else {\r
099e8ff5 1089 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"map"); \r
a405b86d 1090 ShellStatus = SHELL_INVALID_PARAMETER;\r
1091 }\r
1092 }\r
1093 } else if ( ShellCommandLineGetFlag(Package, L"-r")\r
1094// || ShellCommandLineGetFlag(Package, L"-v")\r
1095 || ConstMode\r
1096 || NormlMode\r
1097 || ShellCommandLineGetFlag(Package, L"-u")\r
1098 || ShellCommandLineGetFlag(Package, L"-t")\r
1099 ){\r
1100 if ( ShellCommandLineGetFlag(Package, L"-r")) {\r
1101 //\r
1102 // Do the reset\r
1103 //\r
1104 Status = ShellCommandCreateInitialMappingsAndPaths();\r
1105 if (EFI_ERROR(Status)) {\r
099e8ff5 1106 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"map", Status); \r
a405b86d 1107 ShellStatus = SHELL_UNSUPPORTED;\r
1108 }\r
1109 }\r
1110 if ( ShellStatus == SHELL_SUCCESS && ShellCommandLineGetFlag(Package, L"-u")) {\r
1111 //\r
1112 // Do the Update\r
1113 //\r
e71cb452 1114 Status = ShellCommandUpdateMapping ();\r
a405b86d 1115 if (EFI_ERROR(Status)) {\r
099e8ff5 1116 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"map", Status); \r
a405b86d 1117 ShellStatus = SHELL_UNSUPPORTED;\r
1118 }\r
1119 }\r
1120 if (ShellStatus == SHELL_SUCCESS) {\r
1121 Param1 = ShellCommandLineGetRawValue(Package, 1);\r
1122 TypeString = ShellCommandLineGetValue(Package, L"-t");\r
1123 if (!ConstMode\r
1124 &&!NormlMode\r
1125 &&TypeString == NULL\r
1126 ) {\r
1127 //\r
1128 // now do the display...\r
1129 //\r
1130 ShellStatus = PerformMappingDisplay(\r
1131 ShellCommandLineGetFlag(Package, L"-v"),\r
1132 TRUE,\r
1133 TRUE,\r
1134 NULL,\r
1135 SfoMode,\r
1136 Param1,\r
1137 TRUE\r
1138 );\r
1139 } else {\r
1140 //\r
1141 // now do the display...\r
1142 //\r
1143 ShellStatus = PerformMappingDisplay2(\r
1144 ShellCommandLineGetFlag(Package, L"-v"),\r
1145 ConstMode,\r
1146 NormlMode,\r
1147 TypeString,\r
1148 SfoMode,\r
1149 Param1\r
1150 );\r
1151 }\r
1152 }\r
1153 } else {\r
1154 //\r
1155 // adding or displaying (there were no flags)\r
1156 //\r
1157 SName = ShellCommandLineGetRawValue(Package, 1);\r
1158 Mapping = ShellCommandLineGetRawValue(Package, 2);\r
1159 if ( SName == NULL\r
1160 && Mapping == NULL\r
1161 ){\r
1162 //\r
1163 // display only since no flags\r
1164 //\r
1165 ShellStatus = PerformMappingDisplay(\r
1166 ShellCommandLineGetFlag(Package, L"-v"),\r
1167 TRUE,\r
1168 TRUE,\r
1169 NULL,\r
1170 SfoMode,\r
1171 NULL,\r
1172 TRUE\r
1173 );\r
1174 } else if ( SName == NULL\r
1175 || Mapping == NULL\r
1176 ){\r
1177 //\r
1178 // Display only the one specified\r
1179 //\r
1180 ShellStatus = PerformMappingDisplay(\r
1181 FALSE,\r
1182 FALSE,\r
1183 FALSE,\r
1184 NULL,\r
1185 SfoMode,\r
1186 SName, // note the variable here...\r
1187 TRUE\r
1188 );\r
1189 } else {\r
1190 if (ShellIsHexOrDecimalNumber(Mapping, TRUE, FALSE)) {\r
b54fd049 1191 MapAsHandle = ConvertHandleIndexToHandle(ShellStrToUintn(Mapping));\r
a405b86d 1192 } else {\r
b54fd049 1193 MapAsHandle = NULL;\r
a405b86d 1194 }\r
b54fd049 1195 if (MapAsHandle == NULL && Mapping[StrLen(Mapping)-1] != L':') {\r
099e8ff5 1196 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"map", Mapping); \r
a405b86d 1197 ShellStatus = SHELL_INVALID_PARAMETER;\r
1198 } else {\r
b54fd049 1199 if (MapAsHandle != NULL) {\r
1200 TempStringLength = StrLen(SName);\r
1201 if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {\r
099e8ff5 1202 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"map", SName);\r
b54fd049 1203 ShellStatus = SHELL_INVALID_PARAMETER;\r
1204 } else {\r
1205 ShellStatus = AddMappingFromHandle(MapAsHandle, SName);\r
1206 }\r
a405b86d 1207 } else {\r
b54fd049 1208 TempStringLength = StrLen(SName);\r
1209 if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {\r
099e8ff5 1210 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"map", SName);\r
b54fd049 1211 ShellStatus = SHELL_INVALID_PARAMETER;\r
1212 } else {\r
1213 ShellStatus = AddMappingFromMapping(Mapping, SName);\r
1214 }\r
a405b86d 1215 }\r
1216 if (ShellStatus != SHELL_SUCCESS) {\r
1217 switch (ShellStatus) {\r
1218 case SHELL_ACCESS_DENIED:\r
099e8ff5 1219 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle, L"map");\r
a405b86d 1220 break;\r
1221 case SHELL_INVALID_PARAMETER:\r
099e8ff5 1222 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"map", Mapping);\r
a405b86d 1223 break;\r
b54fd049 1224 case SHELL_DEVICE_ERROR:\r
099e8ff5 1225 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NOF), gShellLevel2HiiHandle, L"map", Mapping);\r
b54fd049 1226 break;\r
a405b86d 1227 default:\r
099e8ff5 1228 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"map", ShellStatus|MAX_BIT);\r
a405b86d 1229 }\r
1230 } else {\r
1231 //\r
1232 // now do the display...\r
1233 //\r
1234 ShellStatus = PerformMappingDisplay(\r
1235 FALSE,\r
1236 FALSE,\r
1237 FALSE,\r
1238 NULL,\r
1239 SfoMode,\r
1240 SName,\r
1241 TRUE\r
1242 );\r
1243 } // we were sucessful so do an output\r
1244 } // got a valid map target\r
1245 } // got 2 variables\r
1246 } // we are adding a mapping\r
1247 } // got valid parameters\r
1248 }\r
1249\r
1250 //\r
1251 // free the command line package\r
1252 //\r
1253 ShellCommandLineFreeVarList (Package);\r
1254\r
1255 return (ShellStatus);\r
1256}\r
1257\r