EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c

Go to the documentation of this file.
00001 
00015 #include "UefiShellLevel2CommandsLib.h"
00016 #include <Protocol/SimpleFileSystem.h>
00017 #include <Protocol/BlockIo.h>
00018 #include <Library/DevicePathLib.h>
00019 #include <Library/HandleParsingLib.h>
00020 #include <Library/SortLib.h>
00021 
00033 BOOLEAN
00034 EFIAPI
00035 IsNumberLetterOnly(
00036   IN CONST CHAR16 *String,
00037   IN CONST UINTN  Len
00038   )
00039 {
00040   UINTN Count;
00041   for (Count = 0 ; Count < Len && String != NULL && *String != CHAR_NULL ; String++,Count++) {
00042     if (! ((*String >= L'a' && *String <= L'z') ||
00043            (*String >= L'A' && *String <= L'Z') ||
00044            (*String >= L'0' && *String <= L'9'))
00045         ){
00046       return (FALSE);
00047     }
00048   }
00049   return (TRUE);
00050 }
00051 
00064 BOOLEAN
00065 EFIAPI
00066 SearchList(
00067   IN CONST CHAR16   *List,
00068   IN CONST CHAR16   *MetaTarget,
00069   OUT CHAR16        **FullName OPTIONAL,
00070   IN CONST BOOLEAN  Meta,
00071   IN CONST BOOLEAN  SkipTrailingNumbers,
00072   IN CONST CHAR16   *Target
00073 
00074   )
00075 {
00076   CHAR16        *TempList;
00077   CONST CHAR16  *ListWalker;
00078   BOOLEAN       Result;
00079   CHAR16        *TempSpot;
00080 
00081   for (ListWalker = List , TempList = NULL
00082      ; ListWalker != NULL && *ListWalker != CHAR_NULL
00083      ;
00084    ) {
00085     TempList = StrnCatGrow(&TempList, NULL, ListWalker, 0);
00086     ASSERT(TempList != NULL);
00087     TempSpot = StrStr(TempList, Target);
00088     if (TempSpot != NULL) {
00089       *TempSpot = CHAR_NULL;
00090     }
00091 
00092     while (SkipTrailingNumbers && (ShellIsDecimalDigitCharacter(TempList[StrLen(TempList)-1]) || TempList[StrLen(TempList)-1] == L':')) {
00093       TempList[StrLen(TempList)-1] = CHAR_NULL;
00094     }
00095 
00096     ListWalker = StrStr(ListWalker, Target);
00097     while(ListWalker != NULL && *ListWalker == *Target) {
00098       ListWalker++;
00099     }
00100     if (Meta) {
00101       Result = gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16*)TempList, (CHAR16*)MetaTarget);
00102     } else {
00103       Result = (BOOLEAN)(StrCmp(TempList, MetaTarget)==0);
00104     }
00105     if (Result) {
00106       if (FullName != NULL) {
00107         *FullName = TempList;
00108       } else {
00109         FreePool(TempList);
00110       }
00111       return (TRUE);
00112     }
00113     FreePool(TempList);
00114     TempList = NULL;
00115   }
00116 
00117   return (FALSE);
00118 }
00119 
00125 EFI_STATUS
00126 EFIAPI
00127 UpdateMapping (
00128   VOID
00129   )
00130 {
00131   EFI_STATUS                Status;
00132   EFI_HANDLE                *HandleList;
00133   UINTN                     Count;
00134   EFI_DEVICE_PATH_PROTOCOL  **DevicePathList;
00135   CHAR16                    *NewDefaultName;
00136   CHAR16                    *NewConsistName;
00137   EFI_DEVICE_PATH_PROTOCOL  **ConsistMappingTable;
00138 
00139   HandleList  = NULL;
00140   Status      = EFI_SUCCESS;
00141 
00142   //
00143   // remove mappings that represent removed devices.
00144   //
00145 
00146   //
00147   // Find each handle with Simple File System
00148   //
00149   HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
00150   if (HandleList != NULL) {
00151     //
00152     // Do a count of the handles
00153     //
00154     for (Count = 0 ; HandleList[Count] != NULL ; Count++);
00155 
00156     //
00157     // Get all Device Paths
00158     //
00159     DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
00160     ASSERT(DevicePathList != NULL);
00161 
00162     for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
00163       DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
00164     }
00165 
00166     //
00167     // Sort all DevicePaths
00168     //
00169     PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
00170 
00171     ShellCommandConsistMappingInitialize(&ConsistMappingTable);
00172 
00173     //
00174     // Assign new Mappings to remainders
00175     //
00176     for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
00177       //
00178       // Skip ones that already have
00179       //
00180       if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
00181         continue;
00182       }
00183       //
00184       // Get default name
00185       //
00186       NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
00187       ASSERT(NewDefaultName != NULL);
00188 
00189       //
00190       // Call shell protocol SetMap function now...
00191       //
00192       Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
00193 
00194       if (!EFI_ERROR(Status)) {
00195         //
00196         // Now do consistent name
00197         //
00198         NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
00199         if (NewConsistName != NULL) {
00200           Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
00201           FreePool(NewConsistName);
00202         }
00203       }
00204 
00205       FreePool(NewDefaultName);
00206     }
00207     ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
00208     SHELL_FREE_NON_NULL(HandleList);
00209     SHELL_FREE_NON_NULL(DevicePathList);
00210 
00211     HandleList = NULL;
00212   } else {
00213     Count = (UINTN)-1;
00214   }
00215   //
00216   // Do it all over again for gEfiBlockIoProtocolGuid
00217   //
00218 
00219   return (Status);
00220 }
00221 
00234 CHAR16*
00235 EFIAPI
00236 GetDeviceMediaType (
00237   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath
00238   )
00239 {
00240   ACPI_HID_DEVICE_PATH  *Acpi;
00241 
00242   //
00243   //  Parse the device path:
00244   //  Devicepath sub type                 mediatype
00245   //    MEDIA_HANRDDRIVE_DP      ->       Hard Disk
00246   //    MEDIA_CDROM_DP           ->       CD Rom
00247   //    Acpi.HID = 0X0604        ->       Floppy
00248   //
00249   if (NULL == DevicePath) {
00250     return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);
00251   }
00252 
00253   for (;!IsDevicePathEndType (DevicePath) ;DevicePath = NextDevicePathNode (DevicePath)) {
00254     if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) {
00255       switch (DevicePathSubType (DevicePath)) {
00256       case MEDIA_HARDDRIVE_DP:
00257         return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_HARDDISK), NULL);
00258       case MEDIA_CDROM_DP:
00259         return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_CDROM), NULL);
00260       }
00261     } else if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH) {
00262       Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath;
00263       if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
00264         return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_FLOPPY), NULL);
00265       }
00266     }
00267   }
00268 
00269   return HiiGetString(gShellLevel2HiiHandle, STRING_TOKEN(STR_MAP_MEDIA_UNKNOWN), NULL);
00270 }
00271 
00280 BOOLEAN
00281 EFIAPI
00282 IsRemoveableDevice (
00283   IN EFI_DEVICE_PATH_PROTOCOL      *DevicePath
00284   )
00285 {
00286   if (NULL == DevicePath) {
00287     return FALSE;
00288   }
00289 
00290   while (!IsDevicePathEndType (DevicePath)) {
00291     if (DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) {
00292       switch (DevicePathSubType (DevicePath)) {
00293       case MSG_USB_DP:
00294       case MSG_SCSI_DP:
00295         return TRUE;
00296       default:
00297         return FALSE;
00298       }
00299     }
00300     DevicePath = NextDevicePathNode (DevicePath);
00301   }
00302   return FALSE;
00303 }
00304 
00317 BOOLEAN
00318 EFIAPI
00319 MappingListHasType(
00320   IN CONST CHAR16     *MapList,
00321   IN CONST CHAR16     *Specific,
00322   IN CONST CHAR16     *TypeString,
00323   IN CONST BOOLEAN    Normal,
00324   IN CONST BOOLEAN    Consist
00325   )
00326 {
00327   CHAR16 *NewSpecific;
00328   //
00329   // specific has priority
00330   //
00331   if (Specific != NULL) {
00332     NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));
00333     if (NewSpecific == NULL){
00334       return FALSE;
00335     }
00336     StrCpy(NewSpecific, Specific);
00337     if (NewSpecific[StrLen(NewSpecific)-1] != L':') {
00338       StrCat(NewSpecific, L":");
00339     }
00340 
00341     if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {
00342       FreePool(NewSpecific);
00343       return (TRUE);
00344     }
00345     FreePool(NewSpecific);
00346   }
00347   if (  Consist
00348     && (SearchList(MapList, L"HD*",  NULL, TRUE, TRUE, L";")
00349       ||SearchList(MapList, L"CD*",  NULL, TRUE, TRUE, L";")
00350       ||SearchList(MapList, L"F*",   NULL, TRUE, TRUE, L";")
00351       ||SearchList(MapList, L"FP*",  NULL, TRUE, TRUE, L";"))){
00352     return (TRUE);
00353   }
00354 
00355   if (  Normal
00356     && (SearchList(MapList, L"FS",  NULL, FALSE, TRUE, L";")
00357       ||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){
00358     return (TRUE);
00359   }
00360 
00361   if (TypeString != NULL && SearchList(MapList, TypeString,  NULL, TRUE, TRUE, L";")) {
00362     return (TRUE);
00363   }
00364   return (FALSE);
00365 }
00366 
00367 
00381 EFI_STATUS
00382 EFIAPI
00383 PerformSingleMappingDisplay(
00384   IN CONST BOOLEAN    Verbose,
00385   IN CONST BOOLEAN    Consist,
00386   IN CONST BOOLEAN    Normal,
00387   IN CONST CHAR16     *TypeString,
00388   IN CONST BOOLEAN    SFO,
00389   IN CONST CHAR16     *Specific OPTIONAL,
00390   IN CONST EFI_HANDLE Handle
00391   )
00392 {
00393   EFI_DEVICE_PATH_PROTOCOL  *DevPath;
00394   EFI_DEVICE_PATH_PROTOCOL  *DevPathCopy;
00395   CONST CHAR16              *MapList;
00396   CHAR16                    *CurrentName;
00397   CHAR16                    *MediaType;
00398   CHAR16                    *DevPathString;
00399   CHAR16                    *TempSpot;
00400   UINTN                     TempLen;
00401   BOOLEAN                   Removable;
00402   CONST CHAR16              *TempSpot2;
00403 
00404   DevPath = DevicePathFromHandle(Handle);
00405   DevPathCopy = DevPath;
00406   MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
00407   if (MapList == NULL) {
00408     return EFI_NOT_FOUND;
00409   }
00410 
00411   if (!MappingListHasType(MapList, Specific, TypeString, Normal, Consist)){
00412     return EFI_NOT_FOUND;
00413   }
00414 
00415   CurrentName = NULL;
00416   CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
00417   if (CurrentName == NULL) {
00418     return (EFI_OUT_OF_RESOURCES);
00419   }
00420   TempSpot = StrStr(CurrentName, L";");
00421   if (TempSpot != NULL) {
00422     *TempSpot = CHAR_NULL;
00423   }
00424   DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE);
00425   if (!SFO) {
00426     TempLen = StrLen(CurrentName);
00427     ShellPrintHiiEx (
00428       -1,
00429       -1,
00430       NULL,
00431       STRING_TOKEN (STR_MAP_ENTRY),
00432       gShellLevel2HiiHandle,
00433       CurrentName,
00434       TempLen < StrLen(MapList)?MapList + TempLen+1:L"",
00435       DevPathString
00436      );
00437     if (Verbose) {
00438       //
00439       // also print handle, media type, removable (y/n), and current directory
00440       //
00441       MediaType = GetDeviceMediaType(DevPath);
00442       if ((TypeString != NULL &&MediaType != NULL && StrStr(TypeString, MediaType) != NULL) || TypeString == NULL) {
00443         Removable = IsRemoveableDevice(DevPath);
00444         TempSpot2 = ShellGetCurrentDir(CurrentName);
00445         ShellPrintHiiEx (
00446           -1,
00447           -1,
00448           NULL,
00449           STRING_TOKEN (STR_MAP_ENTRY_VERBOSE),
00450           gShellLevel2HiiHandle,
00451           ConvertHandleToHandleIndex(Handle),
00452           MediaType,
00453           Removable?L"Yes":L"No",
00454           TempSpot2
00455          );
00456       }
00457       FreePool(MediaType);
00458     }
00459   } else {
00460     TempLen = StrLen(CurrentName);
00461     ShellPrintHiiEx (
00462       -1,
00463       -1,
00464       NULL,
00465       STRING_TOKEN (STR_MAP_SFO_MAPPINGS),
00466       gShellLevel2HiiHandle,
00467       CurrentName,
00468       DevPathString,
00469       TempLen < StrLen(MapList)?MapList + TempLen+1:L""
00470      );
00471   }
00472   FreePool(DevPathString);
00473   FreePool(CurrentName);
00474   return EFI_SUCCESS;
00475 }
00476 
00486 EFI_STATUS
00487 EFIAPI
00488 PerformSingleMappingDelete(
00489   IN CONST CHAR16     *Specific,
00490   IN CONST EFI_HANDLE Handle
00491   )
00492 {
00493   EFI_DEVICE_PATH_PROTOCOL  *DevPath;
00494   EFI_DEVICE_PATH_PROTOCOL  *DevPathCopy;
00495   CONST CHAR16              *MapList;
00496   CHAR16                    *CurrentName;
00497 
00498   DevPath     = DevicePathFromHandle(Handle);
00499   DevPathCopy = DevPath;
00500   MapList     = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);
00501   CurrentName = NULL;
00502 
00503   if (MapList == NULL) {
00504     return (EFI_NOT_FOUND);
00505   }
00506   //
00507   // if there is a specific and its not on the list...
00508   //
00509   if (!SearchList(MapList, Specific, &CurrentName, TRUE, FALSE, L";")) {
00510     return (EFI_NOT_FOUND);
00511   }
00512   return (gEfiShellProtocol->SetMap(NULL, CurrentName));
00513 }
00514 
00515 CONST CHAR16 Cd[] = L"cd*";
00516 CONST CHAR16 Hd[] = L"hd*";
00517 CONST CHAR16 Fp[] = L"fp*";
00518 CONST CHAR16 AnyF[] = L"F*";
00537 SHELL_STATUS
00538 EFIAPI
00539 PerformMappingDisplay(
00540   IN CONST BOOLEAN Verbose,
00541   IN CONST BOOLEAN Consist,
00542   IN CONST BOOLEAN Normal,
00543   IN CONST CHAR16  *TypeString,
00544   IN CONST BOOLEAN SFO,
00545   IN CONST CHAR16  *Specific OPTIONAL,
00546   IN CONST BOOLEAN Header
00547   )
00548 {
00549   EFI_STATUS                Status;
00550   EFI_HANDLE                *HandleBuffer;
00551   UINTN                     BufferSize;
00552   UINTN                     LoopVar;
00553   CHAR16                    *Test;
00554   BOOLEAN                   Found;
00555 
00556   if (!Consist && !Normal && Specific == NULL && TypeString == NULL) {
00557     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
00558     return (SHELL_INVALID_PARAMETER);
00559   }
00560 
00561   if (TypeString != NULL) {
00562     Test = (CHAR16*)Cd;
00563     if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
00564       Test = (CHAR16*)Hd;
00565       if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
00566         Test = (CHAR16*)Fp;
00567         if (StrnCmp(TypeString, Test, StrLen(Test)-1) != 0) {
00568           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, TypeString);
00569           return (SHELL_INVALID_PARAMETER);
00570         }
00571       } else if (Test == NULL) {
00572         Test = (CHAR16*)AnyF;
00573       }
00574     }
00575   } else {
00576     Test = NULL;
00577   }
00578 
00579   if (Header) {
00580     //
00581     // Print the header
00582     //
00583     if (!SFO) {
00584       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_HEADER), gShellLevel2HiiHandle);
00585     } else {
00586       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"map");
00587     }
00588   }
00589 
00590   BufferSize    = 0;
00591   HandleBuffer  = NULL;
00592 
00593   //
00594   // Look up all SimpleFileSystems in the platform
00595   //
00596   Status = gBS->LocateHandle(
00597     ByProtocol,
00598     &gEfiSimpleFileSystemProtocolGuid,
00599     NULL,
00600     &BufferSize,
00601     HandleBuffer);
00602   if (Status == EFI_BUFFER_TOO_SMALL) {
00603     HandleBuffer = AllocateZeroPool(BufferSize);
00604     if (HandleBuffer == NULL) {
00605       return (SHELL_OUT_OF_RESOURCES);
00606     }
00607     Status = gBS->LocateHandle(
00608       ByProtocol,
00609       &gEfiSimpleFileSystemProtocolGuid,
00610       NULL,
00611       &BufferSize,
00612       HandleBuffer);
00613   }
00614 
00615   //
00616   // Get the map name(s) for each one.
00617   //
00618   for ( LoopVar = 0, Found = FALSE
00619       ; LoopVar < (BufferSize / sizeof(EFI_HANDLE)) && HandleBuffer != NULL
00620       ; LoopVar ++
00621      ){
00622     Status = PerformSingleMappingDisplay(
00623       Verbose,
00624       Consist,
00625       Normal,
00626       Test,
00627       SFO,
00628       Specific,
00629       HandleBuffer[LoopVar]);
00630     if (!EFI_ERROR(Status)) {
00631       Found = TRUE;
00632     }
00633   }
00634 
00635   //
00636   // Look up all BlockIo in the platform
00637   //
00638   Status = gBS->LocateHandle(
00639     ByProtocol,
00640     &gEfiBlockIoProtocolGuid,
00641     NULL,
00642     &BufferSize,
00643     HandleBuffer);
00644   if (Status == EFI_BUFFER_TOO_SMALL) {
00645     SHELL_FREE_NON_NULL(HandleBuffer);
00646     HandleBuffer = AllocateZeroPool(BufferSize);
00647     if (HandleBuffer == NULL) {
00648       return (SHELL_OUT_OF_RESOURCES);
00649     }
00650     Status = gBS->LocateHandle(
00651       ByProtocol,
00652       &gEfiBlockIoProtocolGuid,
00653       NULL,
00654       &BufferSize,
00655       HandleBuffer);
00656   }
00657   if (!EFI_ERROR(Status) && HandleBuffer != NULL) {
00658     //
00659     // Get the map name(s) for each one.
00660     //
00661     for ( LoopVar = 0
00662         ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
00663         ; LoopVar ++
00664        ){
00665       //
00666       // Skip any that were already done...
00667       //
00668       if (gBS->OpenProtocol(
00669         HandleBuffer[LoopVar],
00670         &gEfiSimpleFileSystemProtocolGuid,
00671         NULL,
00672         gImageHandle,
00673         NULL,
00674         EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
00675           continue;
00676       }
00677       Status = PerformSingleMappingDisplay(
00678         Verbose,
00679         Consist,
00680         Normal,
00681         Test,
00682         SFO,
00683         Specific,
00684         HandleBuffer[LoopVar]);
00685       if (!EFI_ERROR(Status)) {
00686         Found = TRUE;
00687       }
00688     }
00689     FreePool(HandleBuffer);
00690   }
00691   if (!Found) {
00692     if (Specific != NULL) {
00693       ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, Specific);
00694     } else {
00695       ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
00696     }
00697   }
00698   return (SHELL_SUCCESS);
00699 }
00700 
00715 SHELL_STATUS
00716 EFIAPI
00717 PerformMappingDisplay2(
00718   IN CONST BOOLEAN Verbose,
00719   IN CONST BOOLEAN Consist,
00720   IN CONST BOOLEAN Normal,
00721   IN CONST CHAR16  *TypeString,
00722   IN CONST BOOLEAN SFO,
00723   IN CONST CHAR16  *Specific OPTIONAL
00724   )
00725 {
00726   CONST CHAR16  *TypeWalker;
00727   SHELL_STATUS  ShellStatus;
00728   CHAR16        *Comma;
00729 
00730 
00731   if (TypeString == NULL) {
00732     return (PerformMappingDisplay(Verbose, Consist, Normal, NULL, SFO, Specific, TRUE));
00733   }
00734   ShellStatus = SHELL_SUCCESS;
00735   for (TypeWalker = TypeString ; TypeWalker != NULL && *TypeWalker != CHAR_NULL ;) {
00736     Comma = StrStr(TypeWalker, L",");
00737     if (Comma == NULL) {
00738       if (ShellStatus == SHELL_SUCCESS) {
00739         ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
00740       } else {
00741         PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
00742       }
00743       break;
00744     } else {
00745       *Comma = CHAR_NULL;
00746       if (ShellStatus == SHELL_SUCCESS) {
00747         ShellStatus = PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
00748       } else {
00749         PerformMappingDisplay(Verbose, Consist, Normal, TypeWalker, SFO, Specific, (BOOLEAN)(TypeWalker == TypeString));
00750       }
00751       *Comma = L',';
00752       TypeWalker = Comma + 1;
00753     }
00754   }
00755 
00756   return (ShellStatus);
00757 }
00758 
00768 EFI_STATUS
00769 EFIAPI
00770 PerformMappingDelete(
00771   IN CONST CHAR16  *Specific
00772   )
00773 {
00774   EFI_STATUS                Status;
00775   EFI_HANDLE                *HandleBuffer;
00776   UINTN                     BufferSize;
00777   UINTN                     LoopVar;
00778   BOOLEAN                   Deleted;
00779 
00780   if (Specific == NULL) {
00781     return (EFI_INVALID_PARAMETER);
00782   }
00783 
00784   BufferSize    = 0;
00785   HandleBuffer  = NULL;
00786   Deleted       = FALSE;
00787 
00788   //
00789   // Look up all SimpleFileSystems in the platform
00790   //
00791   Status = gBS->LocateHandle(
00792     ByProtocol,
00793     &gEfiDevicePathProtocolGuid,
00794     NULL,
00795     &BufferSize,
00796     HandleBuffer);
00797   if (Status == EFI_BUFFER_TOO_SMALL) {
00798     HandleBuffer = AllocateZeroPool(BufferSize);
00799     if (HandleBuffer == NULL) {
00800       return (EFI_OUT_OF_RESOURCES);
00801     }
00802     Status = gBS->LocateHandle(
00803       ByProtocol,
00804       &gEfiDevicePathProtocolGuid,
00805       NULL,
00806       &BufferSize,
00807       HandleBuffer);
00808   }
00809   if (EFI_ERROR(Status)) {
00810     SHELL_FREE_NON_NULL(HandleBuffer);
00811     return (Status);
00812   }
00813 
00814   if (HandleBuffer != NULL) {
00815     //
00816     // Get the map name(s) for each one.
00817     //
00818     for ( LoopVar = 0
00819         ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
00820         ; LoopVar ++
00821        ){
00822       if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
00823           Deleted = TRUE;
00824       }
00825     }
00826   }
00827   //
00828   // Look up all BlockIo in the platform
00829   //
00830   Status = gBS->LocateHandle(
00831     ByProtocol,
00832     &gEfiBlockIoProtocolGuid,
00833     NULL,
00834     &BufferSize,
00835     HandleBuffer);
00836   if (Status == EFI_BUFFER_TOO_SMALL) {
00837     FreePool(HandleBuffer);
00838     HandleBuffer = AllocateZeroPool(BufferSize);
00839     if (HandleBuffer == NULL) {
00840       return (EFI_OUT_OF_RESOURCES);
00841     }
00842     Status = gBS->LocateHandle(
00843       ByProtocol,
00844       &gEfiBlockIoProtocolGuid,
00845       NULL,
00846       &BufferSize,
00847       HandleBuffer);
00848   }
00849   if (EFI_ERROR(Status)) {
00850     SHELL_FREE_NON_NULL(HandleBuffer);
00851     return (Status);
00852   }
00853 
00854   if (HandleBuffer != NULL) {
00855     //
00856     // Get the map name(s) for each one.
00857     //
00858     for ( LoopVar = 0
00859         ; LoopVar < BufferSize / sizeof(EFI_HANDLE)
00860         ; LoopVar ++
00861        ){
00862       //
00863       // Skip any that were already done...
00864       //
00865       if (gBS->OpenProtocol(
00866         HandleBuffer[LoopVar],
00867         &gEfiDevicePathProtocolGuid,
00868         NULL,
00869         gImageHandle,
00870         NULL,
00871         EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {
00872           continue;
00873       }
00874       if (PerformSingleMappingDelete(Specific,HandleBuffer[LoopVar]) == SHELL_SUCCESS) {
00875           Deleted = TRUE;
00876       }
00877     }
00878   }
00879   SHELL_FREE_NON_NULL(HandleBuffer);
00880   if (!Deleted) {
00881     return (EFI_NOT_FOUND);
00882   }
00883   return (EFI_SUCCESS);
00884 }
00885 
00899 SHELL_STATUS
00900 EFIAPI
00901 AddMappingFromMapping(
00902   IN CONST CHAR16     *Map,
00903   IN CONST CHAR16     *SName
00904   )
00905 {
00906   CONST EFI_DEVICE_PATH_PROTOCOL  *DevPath;
00907   EFI_STATUS                      Status;
00908   CHAR16                          *NewSName;
00909   
00910   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
00911   if (NewSName == NULL) {
00912     return (SHELL_OUT_OF_RESOURCES);
00913   }
00914   StrCpy(NewSName, SName);
00915   if (NewSName[StrLen(NewSName)-1] != L':') {
00916     StrCat(NewSName, L":");
00917   }
00918 
00919   if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
00920     FreePool(NewSName);
00921     return (SHELL_INVALID_PARAMETER);
00922   }
00923 
00924   DevPath = gEfiShellProtocol->GetDevicePathFromMap(Map);
00925   if (DevPath == NULL) {
00926     FreePool(NewSName);
00927     return (SHELL_INVALID_PARAMETER);
00928   }
00929 
00930   Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
00931   FreePool(NewSName);
00932   if (EFI_ERROR(Status)) {
00933     return (SHELL_DEVICE_ERROR);
00934   }
00935   return (SHELL_SUCCESS);
00936 }
00937 
00952 SHELL_STATUS
00953 EFIAPI
00954 AddMappingFromHandle(
00955   IN CONST EFI_HANDLE Handle,
00956   IN CONST CHAR16     *SName
00957   )
00958 {
00959   EFI_DEVICE_PATH_PROTOCOL  *DevPath;
00960   EFI_STATUS                Status;
00961   CHAR16                    *NewSName;
00962   
00963   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
00964   if (NewSName == NULL) {
00965     return (SHELL_OUT_OF_RESOURCES);
00966   }
00967   StrCpy(NewSName, SName);
00968   if (NewSName[StrLen(NewSName)-1] != L':') {
00969     StrCat(NewSName, L":");
00970   }
00971 
00972   if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {
00973     FreePool(NewSName);
00974     return (SHELL_INVALID_PARAMETER);
00975   }
00976 
00977   Status = gBS->OpenProtocol(
00978     Handle,
00979     &gEfiDevicePathProtocolGuid,
00980     (VOID**)&DevPath,
00981     gImageHandle,
00982     NULL,
00983     EFI_OPEN_PROTOCOL_GET_PROTOCOL
00984    );
00985   if (EFI_ERROR(Status)) {
00986     FreePool(NewSName);
00987     return (SHELL_DEVICE_ERROR);
00988   }
00989   Status = gEfiShellProtocol->SetMap(DevPath, NewSName);
00990   FreePool(NewSName);
00991   if (EFI_ERROR(Status)) {
00992     return (SHELL_DEVICE_ERROR);
00993   }
00994   return (SHELL_SUCCESS);
00995 }
00996 
00997 STATIC CONST SHELL_PARAM_ITEM MapParamList[] = {
00998   {L"-d", TypeValue},
00999   {L"-r", TypeFlag},
01000   {L"-v", TypeFlag},
01001   {L"-c", TypeFlag},
01002   {L"-f", TypeFlag},
01003   {L"-u", TypeFlag},
01004   {L"-t", TypeValue},
01005   {L"-sfo", TypeValue},
01006   {NULL, TypeMax}
01007   };
01008 
01015 SHELL_STATUS
01016 EFIAPI
01017 ShellCommandRunMap (
01018   IN EFI_HANDLE        ImageHandle,
01019   IN EFI_SYSTEM_TABLE  *SystemTable
01020   )
01021 {
01022   EFI_STATUS    Status;
01023   LIST_ENTRY    *Package;
01024   CHAR16        *ProblemParam;
01025   CONST CHAR16  *SName;
01026   CONST CHAR16  *Mapping;
01027   EFI_HANDLE    MapAsHandle;
01028   CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
01029   SHELL_STATUS  ShellStatus;
01030   BOOLEAN       SfoMode;
01031   BOOLEAN       ConstMode;
01032   BOOLEAN       NormlMode;
01033   CONST CHAR16  *Param1;
01034   CONST CHAR16  *TypeString;
01035   UINTN         TempStringLength;
01036 
01037   ProblemParam  = NULL;
01038   Mapping       = NULL;
01039   SName         = NULL;
01040   DevPath       = NULL;
01041   ShellStatus   = SHELL_SUCCESS;
01042   MapAsHandle = NULL;
01043 
01044   //
01045   // initialize the shell lib (we must be in non-auto-init...)
01046   //
01047   Status = ShellInitialize();
01048   ASSERT_EFI_ERROR(Status);
01049 
01050   Status = CommandInit();
01051   ASSERT_EFI_ERROR(Status);
01052 
01053   //
01054   // parse the command line
01055   //
01056   Status = ShellCommandLineParse (MapParamList, &Package, &ProblemParam, TRUE);
01057   if (EFI_ERROR(Status)) {
01058     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
01059       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
01060       FreePool(ProblemParam);
01061       ShellStatus = SHELL_INVALID_PARAMETER;
01062     } else {
01063       ASSERT(FALSE);
01064     }
01065   } else {
01066     //
01067     // check for "-?"
01068     //
01069     SfoMode   = ShellCommandLineGetFlag(Package, L"-sfo");
01070     ConstMode = ShellCommandLineGetFlag(Package, L"-c");
01071     NormlMode = ShellCommandLineGetFlag(Package, L"-f");
01072     if (ShellCommandLineGetFlag(Package, L"-?")) {
01073       ASSERT(FALSE);
01074     } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
01075       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
01076       ShellStatus = SHELL_INVALID_PARAMETER;
01077     } else {
01078       //
01079       // Deleting a map name...
01080       //
01081       if (ShellCommandLineGetFlag(Package, L"-d")) {
01082         if ( ShellCommandLineGetFlag(Package, L"-r")
01083           || ShellCommandLineGetFlag(Package, L"-v")
01084           || ConstMode
01085           || NormlMode
01086           || ShellCommandLineGetFlag(Package, L"-u")
01087           || ShellCommandLineGetFlag(Package, L"-t")
01088          ){
01089           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
01090           ShellStatus = SHELL_INVALID_PARAMETER;
01091         } else {
01092           SName = ShellCommandLineGetValue(Package, L"-d");
01093           if (SName != NULL) {
01094             Status = PerformMappingDelete(SName);
01095             if (EFI_ERROR(Status)) {
01096               switch (Status) {
01097                 case EFI_ACCESS_DENIED:
01098                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
01099                   ShellStatus = SHELL_ACCESS_DENIED;
01100                   break;
01101                 case EFI_NOT_FOUND:
01102                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, SName);
01103                   ShellStatus = SHELL_INVALID_PARAMETER;
01104                   break;
01105                 default:
01106                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
01107                   ShellStatus = SHELL_UNSUPPORTED;
01108               }
01109             }
01110           } else {
01111             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
01112             ShellStatus = SHELL_INVALID_PARAMETER;
01113           }
01114         }
01115       } else if ( ShellCommandLineGetFlag(Package, L"-r")
01116 //               || ShellCommandLineGetFlag(Package, L"-v")
01117                || ConstMode
01118                || NormlMode
01119                || ShellCommandLineGetFlag(Package, L"-u")
01120                || ShellCommandLineGetFlag(Package, L"-t")
01121               ){
01122         if ( ShellCommandLineGetFlag(Package, L"-r")) {
01123           //
01124           // Do the reset
01125           //
01126           Status = ShellCommandCreateInitialMappingsAndPaths();
01127           if (EFI_ERROR(Status)) {
01128             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
01129             ShellStatus = SHELL_UNSUPPORTED;
01130           }
01131         }
01132         if ( ShellStatus == SHELL_SUCCESS && ShellCommandLineGetFlag(Package, L"-u")) {
01133           //
01134           // Do the Update
01135           //
01136           Status = UpdateMapping();
01137           if (EFI_ERROR(Status)) {
01138             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
01139             ShellStatus = SHELL_UNSUPPORTED;
01140           }
01141         }
01142         if (ShellStatus == SHELL_SUCCESS) {
01143           Param1 = ShellCommandLineGetRawValue(Package, 1);
01144           TypeString = ShellCommandLineGetValue(Package, L"-t");
01145           if (!ConstMode
01146             &&!NormlMode
01147             &&TypeString  == NULL
01148             ) {
01149             //
01150             // now do the display...
01151             //
01152             ShellStatus = PerformMappingDisplay(
01153               ShellCommandLineGetFlag(Package, L"-v"),
01154               TRUE,
01155               TRUE,
01156               NULL,
01157               SfoMode,
01158               Param1,
01159               TRUE
01160              );
01161           } else {
01162             //
01163             // now do the display...
01164             //
01165             ShellStatus = PerformMappingDisplay2(
01166               ShellCommandLineGetFlag(Package, L"-v"),
01167               ConstMode,
01168               NormlMode,
01169               TypeString,
01170               SfoMode,
01171               Param1
01172              );
01173           }
01174         }
01175       } else {
01176         //
01177         // adding or displaying (there were no flags)
01178         //
01179         SName = ShellCommandLineGetRawValue(Package, 1);
01180         Mapping = ShellCommandLineGetRawValue(Package, 2);
01181         if ( SName == NULL
01182           && Mapping == NULL
01183          ){
01184           //
01185           // display only since no flags
01186           //
01187           ShellStatus = PerformMappingDisplay(
01188             ShellCommandLineGetFlag(Package, L"-v"),
01189             TRUE,
01190             TRUE,
01191             NULL,
01192             SfoMode,
01193             NULL,
01194             TRUE
01195            );
01196         } else if ( SName == NULL
01197           || Mapping == NULL
01198          ){
01199             //
01200             // Display only the one specified
01201             //
01202           ShellStatus = PerformMappingDisplay(
01203             FALSE,
01204             FALSE,
01205             FALSE,
01206             NULL,
01207             SfoMode,
01208             SName, // note the variable here...
01209             TRUE
01210            );
01211         } else {
01212           if (ShellIsHexOrDecimalNumber(Mapping, TRUE, FALSE)) {
01213             MapAsHandle = ConvertHandleIndexToHandle(ShellStrToUintn(Mapping));
01214           } else {
01215             MapAsHandle = NULL;
01216           }
01217           if (MapAsHandle == NULL && Mapping[StrLen(Mapping)-1] != L':') {
01218             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Mapping);
01219             ShellStatus = SHELL_INVALID_PARAMETER;
01220           } else {
01221             if (MapAsHandle != NULL) {
01222               TempStringLength = StrLen(SName);
01223               if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {
01224                 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);
01225                 ShellStatus = SHELL_INVALID_PARAMETER;
01226               } else {
01227                 ShellStatus = AddMappingFromHandle(MapAsHandle, SName);
01228               }
01229             } else {
01230               TempStringLength = StrLen(SName);
01231               if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {
01232                 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);
01233                 ShellStatus = SHELL_INVALID_PARAMETER;
01234               } else {
01235                 ShellStatus = AddMappingFromMapping(Mapping, SName);
01236               }
01237             }
01238             if (ShellStatus != SHELL_SUCCESS) {
01239               switch (ShellStatus) {
01240                 case SHELL_ACCESS_DENIED:
01241                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
01242                   break;
01243                 case SHELL_INVALID_PARAMETER:
01244                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
01245                   break;
01246                 case SHELL_DEVICE_ERROR:
01247                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NOF), gShellLevel2HiiHandle, Mapping);
01248                   break;
01249                 default:
01250                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, ShellStatus|MAX_BIT);
01251               }
01252             } else {
01253               //
01254               // now do the display...
01255               //
01256               ShellStatus = PerformMappingDisplay(
01257                 FALSE,
01258                 FALSE,
01259                 FALSE,
01260                 NULL,
01261                 SfoMode,
01262                 SName,
01263                 TRUE
01264                );
01265             } // we were sucessful so do an output
01266           } // got a valid map target
01267         } // got 2 variables
01268       } // we are adding a mapping
01269     } // got valid parameters
01270   }
01271 
01272   //
01273   // free the command line package
01274   //
01275   ShellCommandLineFreeVarList (Package);
01276 
01277   return (ShellStatus);
01278 }
01279 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines