/** @file\r
Main file for map shell level 2 command.\r
\r
- Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
+ Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
return (FALSE);\r
}\r
\r
-/**\r
- Add mappings for any devices without one. Do not change any existing maps.\r
-\r
- @retval EFI_SUCCESS The operation was successful.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UpdateMapping (\r
- VOID\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE *HandleList;\r
- UINTN Count;\r
- EFI_DEVICE_PATH_PROTOCOL **DevicePathList;\r
- CHAR16 *NewDefaultName;\r
- CHAR16 *NewConsistName;\r
- EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable;\r
-\r
- HandleList = NULL;\r
- Status = EFI_SUCCESS;\r
-\r
- //\r
- // remove mappings that represent removed devices.\r
- //\r
-\r
- //\r
- // Find each handle with Simple File System\r
- //\r
- HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);\r
- if (HandleList != NULL) {\r
- //\r
- // Do a count of the handles\r
- //\r
- for (Count = 0 ; HandleList[Count] != NULL ; Count++);\r
-\r
- //\r
- // Get all Device Paths\r
- //\r
- DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
- ASSERT(DevicePathList != NULL);\r
-\r
- for (Count = 0 ; HandleList[Count] != NULL ; Count++) {\r
- DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);\r
- }\r
-\r
- //\r
- // Sort all DevicePaths\r
- //\r
- PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);\r
-\r
- ShellCommandConsistMappingInitialize(&ConsistMappingTable);\r
-\r
- //\r
- // Assign new Mappings to remainders\r
- //\r
- for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {\r
- //\r
- // Skip ones that already have\r
- //\r
- if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {\r
- continue;\r
- }\r
- //\r
- // Get default name\r
- //\r
- NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);\r
- ASSERT(NewDefaultName != NULL);\r
-\r
- //\r
- // Call shell protocol SetMap function now...\r
- //\r
- Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);\r
-\r
- if (!EFI_ERROR(Status)) {\r
- //\r
- // Now do consistent name\r
- //\r
- NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);\r
- if (NewConsistName != NULL) {\r
- Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);\r
- FreePool(NewConsistName);\r
- }\r
- }\r
-\r
- FreePool(NewDefaultName);\r
- }\r
- ShellCommandConsistMappingUnInitialize(ConsistMappingTable);\r
- SHELL_FREE_NON_NULL(HandleList);\r
- SHELL_FREE_NON_NULL(DevicePathList);\r
-\r
- HandleList = NULL;\r
- } else {\r
- Count = (UINTN)-1;\r
- }\r
- //\r
- // Do it all over again for gEfiBlockIoProtocolGuid\r
- //\r
-\r
- return (Status);\r
-}\r
-\r
/**\r
Determine what type of device is represented and return it's string. The \r
string is in allocated memory and must be callee freed. The HII is is listed below.\r
// specific has priority\r
//\r
if (Specific != NULL) {\r
- NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));\r
+ NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific);\r
if (NewSpecific == NULL){\r
return FALSE;\r
}\r
- StrCpy(NewSpecific, Specific);\r
if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
- StrCat(NewSpecific, L":");\r
+ StrnCat(NewSpecific, L":", 2);\r
}\r
\r
if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {\r
FreePool(NewSpecific);\r
}\r
if ( Consist\r
+ && Specific == NULL\r
&& (SearchList(MapList, L"HD*", NULL, TRUE, TRUE, L";")\r
||SearchList(MapList, L"CD*", NULL, TRUE, TRUE, L";")\r
||SearchList(MapList, L"F*", NULL, TRUE, TRUE, L";")\r
}\r
\r
if ( Normal\r
+ && Specific == NULL\r
&& (SearchList(MapList, L"FS", NULL, FALSE, TRUE, L";")\r
||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){\r
return (TRUE);\r
return EFI_NOT_FOUND;\r
}\r
\r
- if (Normal) {\r
+ if (Normal || !Consist) {\r
+ //\r
+ // need the Normal here since people can use both on command line. otherwise unused.\r
+ //\r
+\r
//\r
// Allocate a name\r
//\r
if (TempSpot != NULL) {\r
*TempSpot = CHAR_NULL;\r
}\r
- } else if (Consist) {\r
+ } else {\r
CurrentName = NULL;\r
\r
//\r
Alias[StrLen(Alias)-1] = CHAR_NULL;\r
}\r
}\r
- } else {\r
- CurrentName = NULL;\r
- CurrentName = StrnCatGrow(&CurrentName, 0, L"", 0);\r
- if (CurrentName == NULL) {\r
- return (EFI_OUT_OF_RESOURCES);\r
- }\r
}\r
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+ TempLen = StrLen(CurrentName);\r
if (!SFO) {\r
- TempLen = StrLen(CurrentName);\r
ShellPrintHiiEx (\r
-1,\r
-1,\r
SHELL_FREE_NON_NULL(MediaType);\r
}\r
} else {\r
- TempLen = StrLen(CurrentName);\r
ShellPrintHiiEx (\r
-1,\r
-1,\r
EFI_STATUS Status;\r
CHAR16 *NewSName;\r
\r
- NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+ NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
if (NewSName == NULL) {\r
return (SHELL_OUT_OF_RESOURCES);\r
}\r
- StrCpy(NewSName, SName);\r
if (NewSName[StrLen(NewSName)-1] != L':') {\r
- StrCat(NewSName, L":");\r
+ StrnCat(NewSName, L":", 2);\r
}\r
\r
if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
EFI_STATUS Status;\r
CHAR16 *NewSName;\r
\r
- NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+ NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);\r
if (NewSName == NULL) {\r
return (SHELL_OUT_OF_RESOURCES);\r
}\r
- StrCpy(NewSName, SName);\r
if (NewSName[StrLen(NewSName)-1] != L':') {\r
- StrCat(NewSName, L":");\r
+ StrnCat(NewSName, L":", 2);\r
}\r
\r
if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
//\r
// Do the Update\r
//\r
- Status = UpdateMapping();\r
+ Status = ShellCommandUpdateMapping ();\r
if (EFI_ERROR(Status)) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);\r
ShellStatus = SHELL_UNSUPPORTED;\r