mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-28 16:14:04 +02:00
ShellPkg: Move UpdateMapping() out of Map command and added to UefiShellCommandLib library.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Tapan Shah <tapandshah@hp.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15580 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
b0fdce95f7
commit
e71cb45263
@ -4,7 +4,8 @@
|
|||||||
This library is for use ONLY by shell commands linked into the shell application.
|
This library is for use ONLY by shell commands linked into the shell application.
|
||||||
This library will not funciton if it is used for UEFI Shell 2.0 Applications.
|
This library will not funciton if it is used for UEFI Shell 2.0 Applications.
|
||||||
|
|
||||||
Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
|
(C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
|
||||||
|
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -583,6 +584,17 @@ ShellCommandCreateInitialMappingsAndPaths(
|
|||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Add mappings for any devices without one. Do not change any existing maps.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The operation was successful.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
ShellCommandUpdateMapping (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
|
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Provides interface to shell internal functions for shell commands.
|
Provides interface to shell internal functions for shell commands.
|
||||||
|
|
||||||
|
(C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
|
||||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
@ -1198,12 +1199,114 @@ ShellCommandCreateInitialMappingsAndPaths(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (EFI_SUCCESS);
|
return (EFI_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
|
Add mappings for any devices without one. Do not change any existing maps.
|
||||||
|
|
||||||
@param[in] Handle The SHELL_FILE_HANDLE to convert.
|
@retval EFI_SUCCESS The operation was successful.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
ShellCommandUpdateMapping (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_HANDLE *HandleList;
|
||||||
|
UINTN Count;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL **DevicePathList;
|
||||||
|
CHAR16 *NewDefaultName;
|
||||||
|
CHAR16 *NewConsistName;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable;
|
||||||
|
|
||||||
|
HandleList = NULL;
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
//
|
||||||
|
// remove mappings that represent removed devices.
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Find each handle with Simple File System
|
||||||
|
//
|
||||||
|
HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
|
||||||
|
if (HandleList != NULL) {
|
||||||
|
//
|
||||||
|
// Do a count of the handles
|
||||||
|
//
|
||||||
|
for (Count = 0 ; HandleList[Count] != NULL ; Count++);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get all Device Paths
|
||||||
|
//
|
||||||
|
DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
|
||||||
|
ASSERT(DevicePathList != NULL);
|
||||||
|
|
||||||
|
for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
|
||||||
|
DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Sort all DevicePaths
|
||||||
|
//
|
||||||
|
PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
|
||||||
|
|
||||||
|
ShellCommandConsistMappingInitialize(&ConsistMappingTable);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assign new Mappings to remainders
|
||||||
|
//
|
||||||
|
for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
|
||||||
|
//
|
||||||
|
// Skip ones that already have
|
||||||
|
//
|
||||||
|
if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Get default name
|
||||||
|
//
|
||||||
|
NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
|
||||||
|
ASSERT(NewDefaultName != NULL);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call shell protocol SetMap function now...
|
||||||
|
//
|
||||||
|
Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
|
||||||
|
|
||||||
|
if (!EFI_ERROR(Status)) {
|
||||||
|
//
|
||||||
|
// Now do consistent name
|
||||||
|
//
|
||||||
|
NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
|
||||||
|
if (NewConsistName != NULL) {
|
||||||
|
Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
|
||||||
|
FreePool(NewConsistName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreePool(NewDefaultName);
|
||||||
|
}
|
||||||
|
ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
|
||||||
|
SHELL_FREE_NON_NULL(HandleList);
|
||||||
|
SHELL_FREE_NON_NULL(DevicePathList);
|
||||||
|
|
||||||
|
HandleList = NULL;
|
||||||
|
} else {
|
||||||
|
Count = (UINTN)-1;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Do it all over again for gEfiBlockIoProtocolGuid
|
||||||
|
//
|
||||||
|
|
||||||
|
return (Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
|
||||||
|
|
||||||
|
@param[in] Handle The SHELL_FILE_HANDLE to convert.
|
||||||
|
|
||||||
@return a EFI_FILE_PROTOCOL* representing the same file.
|
@return a EFI_FILE_PROTOCOL* representing the same file.
|
||||||
**/
|
**/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Main file for map shell level 2 command.
|
Main file for map shell level 2 command.
|
||||||
|
|
||||||
|
(C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
|
||||||
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
@ -117,108 +118,6 @@ SearchList(
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Add mappings for any devices without one. Do not change any existing maps.
|
|
||||||
|
|
||||||
@retval EFI_SUCCESS The operation was successful.
|
|
||||||
**/
|
|
||||||
EFI_STATUS
|
|
||||||
EFIAPI
|
|
||||||
UpdateMapping (
|
|
||||||
VOID
|
|
||||||
)
|
|
||||||
{
|
|
||||||
EFI_STATUS Status;
|
|
||||||
EFI_HANDLE *HandleList;
|
|
||||||
UINTN Count;
|
|
||||||
EFI_DEVICE_PATH_PROTOCOL **DevicePathList;
|
|
||||||
CHAR16 *NewDefaultName;
|
|
||||||
CHAR16 *NewConsistName;
|
|
||||||
EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable;
|
|
||||||
|
|
||||||
HandleList = NULL;
|
|
||||||
Status = EFI_SUCCESS;
|
|
||||||
|
|
||||||
//
|
|
||||||
// remove mappings that represent removed devices.
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Find each handle with Simple File System
|
|
||||||
//
|
|
||||||
HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
|
|
||||||
if (HandleList != NULL) {
|
|
||||||
//
|
|
||||||
// Do a count of the handles
|
|
||||||
//
|
|
||||||
for (Count = 0 ; HandleList[Count] != NULL ; Count++);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get all Device Paths
|
|
||||||
//
|
|
||||||
DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
|
|
||||||
ASSERT(DevicePathList != NULL);
|
|
||||||
|
|
||||||
for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
|
|
||||||
DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Sort all DevicePaths
|
|
||||||
//
|
|
||||||
PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
|
|
||||||
|
|
||||||
ShellCommandConsistMappingInitialize(&ConsistMappingTable);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Assign new Mappings to remainders
|
|
||||||
//
|
|
||||||
for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
|
|
||||||
//
|
|
||||||
// Skip ones that already have
|
|
||||||
//
|
|
||||||
if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Get default name
|
|
||||||
//
|
|
||||||
NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
|
|
||||||
ASSERT(NewDefaultName != NULL);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Call shell protocol SetMap function now...
|
|
||||||
//
|
|
||||||
Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
|
|
||||||
|
|
||||||
if (!EFI_ERROR(Status)) {
|
|
||||||
//
|
|
||||||
// Now do consistent name
|
|
||||||
//
|
|
||||||
NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
|
|
||||||
if (NewConsistName != NULL) {
|
|
||||||
Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
|
|
||||||
FreePool(NewConsistName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FreePool(NewDefaultName);
|
|
||||||
}
|
|
||||||
ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
|
|
||||||
SHELL_FREE_NON_NULL(HandleList);
|
|
||||||
SHELL_FREE_NON_NULL(DevicePathList);
|
|
||||||
|
|
||||||
HandleList = NULL;
|
|
||||||
} else {
|
|
||||||
Count = (UINTN)-1;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Do it all over again for gEfiBlockIoProtocolGuid
|
|
||||||
//
|
|
||||||
|
|
||||||
return (Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine what type of device is represented and return it's string. The
|
Determine what type of device is represented and return it's string. The
|
||||||
string is in allocated memory and must be callee freed. The HII is is listed below.
|
string is in allocated memory and must be callee freed. The HII is is listed below.
|
||||||
@ -1199,7 +1098,7 @@ ShellCommandRunMap (
|
|||||||
//
|
//
|
||||||
// Do the Update
|
// Do the Update
|
||||||
//
|
//
|
||||||
Status = UpdateMapping();
|
Status = ShellCommandUpdateMapping ();
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
|
||||||
ShellStatus = SHELL_UNSUPPORTED;
|
ShellStatus = SHELL_UNSUPPORTED;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user