X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel2CommandsLib%2FMap.c;h=9166ca2205ca2631a62c81aaf20505233c2ebdbc;hp=20eb528fa33916ac6cf4aad354802f7bbe8966ef;hb=4887443e4f03ec42ba422483f191ffe25a78eb3d;hpb=1c5cc5e5f72ce084aca05c36ccb5fde753dbd7c9 diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c index 20eb528fa3..9166ca2205 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c @@ -1,7 +1,7 @@ /** @file Main file for map shell level 2 command. - Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
@@ -220,19 +220,25 @@ MappingListHasType( IN CONST BOOLEAN Consist ) { - CHAR16 *NewSpecific; - RETURN_STATUS Status; + CHAR16 *NewSpecific; + RETURN_STATUS Status; + UINTN Length; // // specific has priority // if (Specific != NULL) { - NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific); + Length = StrLen (Specific); + // + // Allocate enough buffer for Specific and potential ":" + // + NewSpecific = AllocatePool ((Length + 2) * sizeof(CHAR16)); if (NewSpecific == NULL){ return FALSE; } - if (NewSpecific[StrLen(NewSpecific)-1] != L':') { - Status = StrnCatS(NewSpecific, (StrSize(Specific) + sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":")); + StrCpyS (NewSpecific, Length + 2, Specific); + if (Specific[Length - 1] != L':') { + Status = StrnCatS(NewSpecific, Length + 2, L":", StrLen(L":")); if (EFI_ERROR (Status)) { FreePool(NewSpecific); return FALSE; @@ -979,6 +985,57 @@ STATIC CONST SHELL_PARAM_ITEM MapParamList[] = { {NULL, TypeMax} }; +/** + The routine issues dummy read for every physical block device to cause + the BlockIo re-installed if media change happened. +**/ +VOID +ProbeForMediaChange ( + VOID + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + EFI_HANDLE *Handles; + EFI_BLOCK_IO_PROTOCOL *BlockIo; + UINTN Index; + + gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiBlockIoProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + // + // Probe for media change for every physical block io + // + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + Handles[Index], + &gEfiBlockIoProtocolGuid, + (VOID **) &BlockIo + ); + if (!EFI_ERROR (Status)) { + if (!BlockIo->Media->LogicalPartition) { + // + // Per spec: + // The function (ReadBlocks) must return EFI_NO_MEDIA or + // EFI_MEDIA_CHANGED even if LBA, BufferSize, or Buffer are invalid so the caller can probe + // for changes in media state. + // + BlockIo->ReadBlocks ( + BlockIo, + BlockIo->Media->MediaId, + 0, + 0, + NULL + ); + } + } + } +} + /** Function for 'map' command. @@ -1087,6 +1144,7 @@ ShellCommandRunMap ( || ShellCommandLineGetFlag(Package, L"-u") || ShellCommandLineGetFlag(Package, L"-t") ){ + ProbeForMediaChange (); if ( ShellCommandLineGetFlag(Package, L"-r")) { // // Do the reset