2 Fat File System driver routines that support EFI driver model.
4 Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 IN EFI_HANDLE ImageHandle
,
21 IN EFI_SYSTEM_TABLE
*SystemTable
27 IN EFI_HANDLE ImageHandle
32 FatDriverBindingSupported (
33 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
34 IN EFI_HANDLE Controller
,
35 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
40 FatDriverBindingStart (
41 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
42 IN EFI_HANDLE Controller
,
43 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
48 FatDriverBindingStop (
49 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
50 IN EFI_HANDLE Controller
,
51 IN UINTN NumberOfChildren
,
52 IN EFI_HANDLE
*ChildHandleBuffer
56 // DriverBinding protocol instance
58 EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
= {
59 FatDriverBindingSupported
,
60 FatDriverBindingStart
,
69 Register Driver Binding protocol for this driver.
71 @param ImageHandle - Handle for the image of this driver.
72 @param SystemTable - Pointer to the EFI System Table.
74 @retval EFI_SUCCESS - Driver loaded.
75 @return other - Driver not loaded.
81 IN EFI_HANDLE ImageHandle
,
82 IN EFI_SYSTEM_TABLE
*SystemTable
88 // Initialize the EFI Driver Library
90 Status
= EfiLibInstallDriverBindingComponentName2 (
98 ASSERT_EFI_ERROR (Status
);
105 Unload function for this image. Uninstall DriverBinding protocol.
107 @param ImageHandle - Handle for the image of this driver.
109 @retval EFI_SUCCESS - Driver unloaded successfully.
110 @return other - Driver can not unloaded.
116 IN EFI_HANDLE ImageHandle
120 EFI_HANDLE
*DeviceHandleBuffer
;
121 UINTN DeviceHandleCount
;
124 VOID
*ComponentName2
;
126 Status
= gBS
->LocateHandleBuffer (
133 if (EFI_ERROR (Status
)) {
137 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
138 Status
= EfiTestManagedDevice (DeviceHandleBuffer
[Index
], ImageHandle
, &gEfiDiskIoProtocolGuid
);
139 if (!EFI_ERROR (Status
)) {
140 Status
= gBS
->DisconnectController (
141 DeviceHandleBuffer
[Index
],
145 if (EFI_ERROR (Status
)) {
151 if (Index
== DeviceHandleCount
) {
153 // Driver is stopped successfully.
155 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentNameProtocolGuid
, &ComponentName
);
156 if (EFI_ERROR (Status
)) {
157 ComponentName
= NULL
;
160 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentName2ProtocolGuid
, &ComponentName2
);
161 if (EFI_ERROR (Status
)) {
162 ComponentName2
= NULL
;
165 if (ComponentName
== NULL
) {
166 if (ComponentName2
== NULL
) {
167 Status
= gBS
->UninstallMultipleProtocolInterfaces (
169 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
173 Status
= gBS
->UninstallMultipleProtocolInterfaces (
175 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
176 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
181 if (ComponentName2
== NULL
) {
182 Status
= gBS
->UninstallMultipleProtocolInterfaces (
184 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
185 &gEfiComponentNameProtocolGuid
, ComponentName
,
189 Status
= gBS
->UninstallMultipleProtocolInterfaces (
191 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
192 &gEfiComponentNameProtocolGuid
, ComponentName
,
193 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
200 if (DeviceHandleBuffer
!= NULL
) {
201 FreePool (DeviceHandleBuffer
);
209 Test to see if this driver can add a file system to ControllerHandle.
210 ControllerHandle must support both Disk IO and Block IO protocols.
212 @param This - Protocol instance pointer.
213 @param ControllerHandle - Handle of device to test.
214 @param RemainingDevicePath - Not used.
216 @retval EFI_SUCCESS - This driver supports this device.
217 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
218 @return other - This driver does not support this device.
223 FatDriverBindingSupported (
224 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
225 IN EFI_HANDLE ControllerHandle
,
226 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
230 EFI_DISK_IO_PROTOCOL
*DiskIo
;
233 // Open the IO Abstraction(s) needed to perform the supported test
235 Status
= gBS
->OpenProtocol (
237 &gEfiDiskIoProtocolGuid
,
239 This
->DriverBindingHandle
,
241 EFI_OPEN_PROTOCOL_BY_DRIVER
244 if (EFI_ERROR (Status
)) {
248 // Close the I/O Abstraction(s) used to perform the supported test
252 &gEfiDiskIoProtocolGuid
,
253 This
->DriverBindingHandle
,
258 // Open the IO Abstraction(s) needed to perform the supported test
260 Status
= gBS
->OpenProtocol (
262 &gEfiBlockIoProtocolGuid
,
264 This
->DriverBindingHandle
,
266 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
274 Start this driver on ControllerHandle by opening a Block IO and Disk IO
275 protocol, reading Device Path. Add a Simple File System protocol to
276 ControllerHandle if the media contains a valid file system.
278 @param This - Protocol instance pointer.
279 @param ControllerHandle - Handle of device to bind driver to.
280 @param RemainingDevicePath - Not used.
282 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
283 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
284 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
285 @return other - This driver does not support this device.
290 FatDriverBindingStart (
291 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
292 IN EFI_HANDLE ControllerHandle
,
293 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
297 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
298 EFI_DISK_IO_PROTOCOL
*DiskIo
;
299 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
305 // If caller has already acquired the lock, cannot lock it again.
307 Status
= FatAcquireLockOrFail ();
308 if (!EFI_ERROR (Status
)) {
312 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
313 if (EFI_ERROR (Status
)) {
317 // Open our required BlockIo and DiskIo
319 Status
= gBS
->OpenProtocol (
321 &gEfiBlockIoProtocolGuid
,
323 This
->DriverBindingHandle
,
325 EFI_OPEN_PROTOCOL_GET_PROTOCOL
327 if (EFI_ERROR (Status
)) {
331 Status
= gBS
->OpenProtocol (
333 &gEfiDiskIoProtocolGuid
,
335 This
->DriverBindingHandle
,
337 EFI_OPEN_PROTOCOL_BY_DRIVER
339 if (EFI_ERROR (Status
)) {
343 Status
= gBS
->OpenProtocol (
345 &gEfiDiskIo2ProtocolGuid
,
347 This
->DriverBindingHandle
,
349 EFI_OPEN_PROTOCOL_BY_DRIVER
351 if (EFI_ERROR (Status
)) {
356 // Allocate Volume structure. In FatAllocateVolume(), Resources
357 // are allocated with protocol installed and cached initialized
359 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
362 // When the media changes on a device it will Reinstall the BlockIo interaface.
363 // This will cause a call to our Stop(), and a subsequent reentrant call to our
364 // Start() successfully. We should leave the device open when this happen.
366 if (EFI_ERROR (Status
)) {
367 Status
= gBS
->OpenProtocol (
369 &gEfiSimpleFileSystemProtocolGuid
,
371 This
->DriverBindingHandle
,
373 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
375 if (EFI_ERROR (Status
)) {
378 &gEfiDiskIoProtocolGuid
,
379 This
->DriverBindingHandle
,
384 &gEfiDiskIo2ProtocolGuid
,
385 This
->DriverBindingHandle
,
393 // Unlock if locked by myself.
403 Stop this driver on ControllerHandle.
405 @param This - Protocol instance pointer.
406 @param ControllerHandle - Handle of device to stop driver on.
407 @param NumberOfChildren - Not used.
408 @param ChildHandleBuffer - Not used.
410 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
411 @return other - This driver was not removed from this device.
416 FatDriverBindingStop (
417 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
418 IN EFI_HANDLE ControllerHandle
,
419 IN UINTN NumberOfChildren
,
420 IN EFI_HANDLE
*ChildHandleBuffer
424 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
426 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
430 // Get our context back
432 Status
= gBS
->OpenProtocol (
434 &gEfiSimpleFileSystemProtocolGuid
,
435 (VOID
**) &FileSystem
,
436 This
->DriverBindingHandle
,
438 EFI_OPEN_PROTOCOL_GET_PROTOCOL
441 if (!EFI_ERROR (Status
)) {
442 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
443 DiskIo2
= Volume
->DiskIo2
;
444 Status
= FatAbandonVolume (Volume
);
447 if (!EFI_ERROR (Status
)) {
448 if (DiskIo2
!= NULL
) {
449 Status
= gBS
->CloseProtocol (
451 &gEfiDiskIo2ProtocolGuid
,
452 This
->DriverBindingHandle
,
455 ASSERT_EFI_ERROR (Status
);
457 Status
= gBS
->CloseProtocol (
459 &gEfiDiskIoProtocolGuid
,
460 This
->DriverBindingHandle
,
463 ASSERT_EFI_ERROR (Status
);