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