X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=FatPkg%2FEnhancedFatDxe%2FFat.c;h=2080005adc95321806ee03708a3883b4bce5d628;hb=5ce6fb99d481212b6b39e934efd40217530b88b1;hp=38b70882c5c5ca796af0216c9437e1ca9512030e;hpb=5251cb9d68ab96da99e284a3b01aa645c3dc7ddb;p=mirror_edk2.git diff --git a/FatPkg/EnhancedFatDxe/Fat.c b/FatPkg/EnhancedFatDxe/Fat.c index 38b70882c5..2080005adc 100644 --- a/FatPkg/EnhancedFatDxe/Fat.c +++ b/FatPkg/EnhancedFatDxe/Fat.c @@ -1,6 +1,6 @@ /*++ -Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials 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 @@ -140,6 +140,8 @@ Returns: EFI_HANDLE *DeviceHandleBuffer; UINTN DeviceHandleCount; UINTN Index; + VOID *ComponentName; + VOID *ComponentName2; Status = gBS->LocateHandleBuffer ( AllHandles, @@ -148,20 +150,77 @@ Returns: &DeviceHandleCount, &DeviceHandleBuffer ); - if (!EFI_ERROR (Status)) { - for (Index = 0; Index < DeviceHandleCount; Index++) { + if (EFI_ERROR (Status)) { + return Status; + } + + for (Index = 0; Index < DeviceHandleCount; Index++) { + Status = EfiTestManagedDevice (DeviceHandleBuffer[Index], ImageHandle, &gEfiDiskIoProtocolGuid); + if (!EFI_ERROR (Status)) { Status = gBS->DisconnectController ( DeviceHandleBuffer[Index], ImageHandle, NULL ); + if (EFI_ERROR (Status)) { + break; + } } + } - if (DeviceHandleBuffer != NULL) { - FreePool (DeviceHandleBuffer); + if (Index == DeviceHandleCount) { + // + // Driver is stopped successfully. + // + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName); + if (EFI_ERROR (Status)) { + ComponentName = NULL; + } + + Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2); + if (EFI_ERROR (Status)) { + ComponentName2 = NULL; + } + + if (ComponentName == NULL) { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } + } else { + if (ComponentName2 == NULL) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + NULL + ); + } else { + Status = gBS->UninstallMultipleProtocolInterfaces ( + ImageHandle, + &gEfiDriverBindingProtocolGuid, &gFatDriverBinding, + &gEfiComponentNameProtocolGuid, ComponentName, + &gEfiComponentName2ProtocolGuid, ComponentName2, + NULL + ); + } } } + if (DeviceHandleBuffer != NULL) { + FreePool (DeviceHandleBuffer); + } + return Status; } @@ -269,6 +328,7 @@ Returns: EFI_STATUS Status; EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_DISK_IO_PROTOCOL *DiskIo; + EFI_DISK_IO2_PROTOCOL *DiskIo2; BOOLEAN LockedByMe; LockedByMe = FALSE; @@ -311,11 +371,24 @@ Returns: if (EFI_ERROR (Status)) { goto Exit; } + + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiDiskIo2ProtocolGuid, + (VOID **) &DiskIo2, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + DiskIo2 = NULL; + } + // // Allocate Volume structure. In FatAllocateVolume(), Resources // are allocated with protocol installed and cached initialized // - Status = FatAllocateVolume (ControllerHandle, DiskIo, BlockIo); + Status = FatAllocateVolume (ControllerHandle, DiskIo, DiskIo2, BlockIo); // // When the media changes on a device it will Reinstall the BlockIo interaface. @@ -338,6 +411,12 @@ Returns: This->DriverBindingHandle, ControllerHandle ); + gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIo2ProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); } } @@ -379,7 +458,9 @@ Returns: EFI_STATUS Status; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; FAT_VOLUME *Volume; + EFI_DISK_IO2_PROTOCOL *DiskIo2; + DiskIo2 = NULL; // // Get our context back // @@ -393,19 +474,29 @@ Returns: ); if (!EFI_ERROR (Status)) { - Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem); - Status = FatAbandonVolume (Volume); - if (EFI_ERROR (Status)) { - return Status; - } + Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem); + DiskIo2 = Volume->DiskIo2; + Status = FatAbandonVolume (Volume); } - Status = gBS->CloseProtocol ( - ControllerHandle, - &gEfiDiskIoProtocolGuid, - This->DriverBindingHandle, - ControllerHandle - ); + if (!EFI_ERROR (Status)) { + if (DiskIo2 != NULL) { + Status = gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIo2ProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + ASSERT_EFI_ERROR (Status); + } + Status = gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIoProtocolGuid, + This->DriverBindingHandle, + ControllerHandle + ); + ASSERT_EFI_ERROR (Status); + } return Status; }