/*++\r
\r
-Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available\r
under the terms and conditions of the BSD License which accompanies this\r
distribution. The full text of the license may be found at\r
EFI_HANDLE *DeviceHandleBuffer;\r
UINTN DeviceHandleCount;\r
UINTN Index;\r
+ VOID *ComponentName;\r
+ VOID *ComponentName2;\r
\r
Status = gBS->LocateHandleBuffer (\r
AllHandles,\r
&DeviceHandleCount,\r
&DeviceHandleBuffer\r
);\r
- if (!EFI_ERROR (Status)) {\r
- for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+ Status = EfiTestManagedDevice (DeviceHandleBuffer[Index], ImageHandle, &gEfiDiskIoProtocolGuid);\r
+ if (!EFI_ERROR (Status)) {\r
Status = gBS->DisconnectController (\r
DeviceHandleBuffer[Index],\r
ImageHandle,\r
NULL\r
);\r
+ if (EFI_ERROR (Status)) {\r
+ break;\r
+ }\r
}\r
+ }\r
\r
- if (DeviceHandleBuffer != NULL) {\r
- FreePool (DeviceHandleBuffer);\r
+ if (Index == DeviceHandleCount) {\r
+ //\r
+ // Driver is stopped successfully.\r
+ //\r
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentNameProtocolGuid, &ComponentName);\r
+ if (EFI_ERROR (Status)) {\r
+ ComponentName = NULL;\r
+ }\r
+\r
+ Status = gBS->HandleProtocol (ImageHandle, &gEfiComponentName2ProtocolGuid, &ComponentName2);\r
+ if (EFI_ERROR (Status)) {\r
+ ComponentName2 = NULL;\r
+ }\r
+\r
+ if (ComponentName == NULL) {\r
+ if (ComponentName2 == NULL) {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ ImageHandle,\r
+ &gEfiDriverBindingProtocolGuid, &gFatDriverBinding,\r
+ NULL\r
+ );\r
+ } else {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ ImageHandle,\r
+ &gEfiDriverBindingProtocolGuid, &gFatDriverBinding,\r
+ &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+ NULL\r
+ );\r
+ }\r
+ } else {\r
+ if (ComponentName2 == NULL) {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ ImageHandle,\r
+ &gEfiDriverBindingProtocolGuid, &gFatDriverBinding,\r
+ &gEfiComponentNameProtocolGuid, ComponentName,\r
+ NULL\r
+ );\r
+ } else {\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ ImageHandle,\r
+ &gEfiDriverBindingProtocolGuid, &gFatDriverBinding,\r
+ &gEfiComponentNameProtocolGuid, ComponentName,\r
+ &gEfiComponentName2ProtocolGuid, ComponentName2,\r
+ NULL\r
+ );\r
+ }\r
}\r
}\r
\r
+ if (DeviceHandleBuffer != NULL) {\r
+ FreePool (DeviceHandleBuffer);\r
+ }\r
+\r
return Status;\r
}\r
\r
EFI_STATUS Status;\r
EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
EFI_DISK_IO_PROTOCOL *DiskIo;\r
+ EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
+ BOOLEAN LockedByMe;\r
+\r
+ LockedByMe = FALSE;\r
+ //\r
+ // Acquire the lock.\r
+ // If caller has already acquired the lock, cannot lock it again.\r
+ //\r
+ Status = FatAcquireLockOrFail ();\r
+ if (!EFI_ERROR (Status)) {\r
+ LockedByMe = TRUE;\r
+ }\r
\r
Status = InitializeUnicodeCollationSupport (This->DriverBindingHandle);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
//\r
// Open our required BlockIo and DiskIo\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
\r
Status = gBS->OpenProtocol (\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiDiskIo2ProtocolGuid,\r
+ (VOID **) &DiskIo2,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ DiskIo2 = NULL;\r
+ }\r
+\r
//\r
// Allocate Volume structure. In FatAllocateVolume(), Resources\r
// are allocated with protocol installed and cached initialized\r
//\r
- Status = FatAllocateVolume (ControllerHandle, DiskIo, BlockIo);\r
+ Status = FatAllocateVolume (ControllerHandle, DiskIo, DiskIo2, BlockIo);\r
\r
//\r
// When the media changes on a device it will Reinstall the BlockIo interaface.\r
This->DriverBindingHandle,\r
ControllerHandle\r
);\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiDiskIo2ProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
}\r
}\r
\r
+Exit:\r
+ //\r
+ // Unlock if locked by myself.\r
+ //\r
+ if (LockedByMe) {\r
+ FatReleaseLock ();\r
+ }\r
return Status;\r
}\r
\r
EFI_STATUS Status;\r
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;\r
FAT_VOLUME *Volume;\r
+ EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
\r
+ DiskIo2 = NULL;\r
//\r
// Get our context back\r
//\r
);\r
\r
if (!EFI_ERROR (Status)) {\r
- Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem);\r
- Status = FatAbandonVolume (Volume);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
+ Volume = VOLUME_FROM_VOL_INTERFACE (FileSystem);\r
+ DiskIo2 = Volume->DiskIo2;\r
+ Status = FatAbandonVolume (Volume);\r
}\r
\r
- Status = gBS->CloseProtocol (\r
- ControllerHandle,\r
- &gEfiDiskIoProtocolGuid,\r
- This->DriverBindingHandle,\r
- ControllerHandle\r
- );\r
+ if (!EFI_ERROR (Status)) {\r
+ if (DiskIo2 != NULL) {\r
+ Status = gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiDiskIo2ProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+ Status = gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ &gEfiDiskIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ ControllerHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
\r
return Status;\r
}\r