2 Fat File System driver routines that support EFI driver model.
4 Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Register Driver Binding protocol for this driver.
15 @param ImageHandle - Handle for the image of this driver.
16 @param SystemTable - Pointer to the EFI System Table.
18 @retval EFI_SUCCESS - Driver loaded.
19 @return other - Driver not loaded.
25 IN EFI_HANDLE ImageHandle
,
26 IN EFI_SYSTEM_TABLE
*SystemTable
31 Unload function for this image. Uninstall DriverBinding protocol.
33 @param ImageHandle - Handle for the image of this driver.
35 @retval EFI_SUCCESS - Driver unloaded successfully.
36 @return other - Driver can not unloaded.
42 IN EFI_HANDLE ImageHandle
47 Test to see if this driver can add a file system to ControllerHandle.
48 ControllerHandle must support both Disk IO and Block IO protocols.
50 @param This - Protocol instance pointer.
51 @param ControllerHandle - Handle of device to test.
52 @param RemainingDevicePath - Not used.
54 @retval EFI_SUCCESS - This driver supports this device.
55 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
56 @return other - This driver does not support this device.
61 FatDriverBindingSupported (
62 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
63 IN EFI_HANDLE Controller
,
64 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
69 Start this driver on ControllerHandle by opening a Block IO and Disk IO
70 protocol, reading Device Path. Add a Simple File System protocol to
71 ControllerHandle if the media contains a valid file system.
73 @param This - Protocol instance pointer.
74 @param ControllerHandle - Handle of device to bind driver to.
75 @param RemainingDevicePath - Not used.
77 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
78 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
79 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
80 @return other - This driver does not support this device.
85 FatDriverBindingStart (
86 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
87 IN EFI_HANDLE Controller
,
88 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
93 Stop this driver on ControllerHandle.
95 @param This - Protocol instance pointer.
96 @param ControllerHandle - Handle of device to stop driver on.
97 @param NumberOfChildren - Not used.
98 @param ChildHandleBuffer - Not used.
100 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
101 @return other - This driver was not removed from this device.
106 FatDriverBindingStop (
107 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
108 IN EFI_HANDLE Controller
,
109 IN UINTN NumberOfChildren
,
110 IN EFI_HANDLE
*ChildHandleBuffer
114 // DriverBinding protocol instance
116 EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
= {
117 FatDriverBindingSupported
,
118 FatDriverBindingStart
,
119 FatDriverBindingStop
,
127 Register Driver Binding protocol for this driver.
129 @param ImageHandle - Handle for the image of this driver.
130 @param SystemTable - Pointer to the EFI System Table.
132 @retval EFI_SUCCESS - Driver loaded.
133 @return other - Driver not loaded.
139 IN EFI_HANDLE ImageHandle
,
140 IN EFI_SYSTEM_TABLE
*SystemTable
146 // Initialize the EFI Driver Library
148 Status
= EfiLibInstallDriverBindingComponentName2 (
156 ASSERT_EFI_ERROR (Status
);
163 Unload function for this image. Uninstall DriverBinding protocol.
165 @param ImageHandle - Handle for the image of this driver.
167 @retval EFI_SUCCESS - Driver unloaded successfully.
168 @return other - Driver can not unloaded.
174 IN EFI_HANDLE ImageHandle
178 EFI_HANDLE
*DeviceHandleBuffer
;
179 UINTN DeviceHandleCount
;
182 VOID
*ComponentName2
;
184 Status
= gBS
->LocateHandleBuffer (
191 if (EFI_ERROR (Status
)) {
195 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
196 Status
= EfiTestManagedDevice (DeviceHandleBuffer
[Index
], ImageHandle
, &gEfiDiskIoProtocolGuid
);
197 if (!EFI_ERROR (Status
)) {
198 Status
= gBS
->DisconnectController (
199 DeviceHandleBuffer
[Index
],
203 if (EFI_ERROR (Status
)) {
209 if (Index
== DeviceHandleCount
) {
211 // Driver is stopped successfully.
213 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentNameProtocolGuid
, &ComponentName
);
214 if (EFI_ERROR (Status
)) {
215 ComponentName
= NULL
;
218 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentName2ProtocolGuid
, &ComponentName2
);
219 if (EFI_ERROR (Status
)) {
220 ComponentName2
= NULL
;
223 if (ComponentName
== NULL
) {
224 if (ComponentName2
== NULL
) {
225 Status
= gBS
->UninstallMultipleProtocolInterfaces (
227 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
231 Status
= gBS
->UninstallMultipleProtocolInterfaces (
233 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
234 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
239 if (ComponentName2
== NULL
) {
240 Status
= gBS
->UninstallMultipleProtocolInterfaces (
242 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
243 &gEfiComponentNameProtocolGuid
, ComponentName
,
247 Status
= gBS
->UninstallMultipleProtocolInterfaces (
249 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
250 &gEfiComponentNameProtocolGuid
, ComponentName
,
251 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
258 if (DeviceHandleBuffer
!= NULL
) {
259 FreePool (DeviceHandleBuffer
);
267 Test to see if this driver can add a file system to ControllerHandle.
268 ControllerHandle must support both Disk IO and Block IO protocols.
270 @param This - Protocol instance pointer.
271 @param ControllerHandle - Handle of device to test.
272 @param RemainingDevicePath - Not used.
274 @retval EFI_SUCCESS - This driver supports this device.
275 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
276 @return other - This driver does not support this device.
281 FatDriverBindingSupported (
282 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
283 IN EFI_HANDLE ControllerHandle
,
284 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
288 EFI_DISK_IO_PROTOCOL
*DiskIo
;
291 // Open the IO Abstraction(s) needed to perform the supported test
293 Status
= gBS
->OpenProtocol (
295 &gEfiDiskIoProtocolGuid
,
297 This
->DriverBindingHandle
,
299 EFI_OPEN_PROTOCOL_BY_DRIVER
302 if (EFI_ERROR (Status
)) {
306 // Close the I/O Abstraction(s) used to perform the supported test
310 &gEfiDiskIoProtocolGuid
,
311 This
->DriverBindingHandle
,
316 // Open the IO Abstraction(s) needed to perform the supported test
318 Status
= gBS
->OpenProtocol (
320 &gEfiBlockIoProtocolGuid
,
322 This
->DriverBindingHandle
,
324 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
332 Start this driver on ControllerHandle by opening a Block IO and Disk IO
333 protocol, reading Device Path. Add a Simple File System protocol to
334 ControllerHandle if the media contains a valid file system.
336 @param This - Protocol instance pointer.
337 @param ControllerHandle - Handle of device to bind driver to.
338 @param RemainingDevicePath - Not used.
340 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
341 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
342 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
343 @return other - This driver does not support this device.
348 FatDriverBindingStart (
349 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
350 IN EFI_HANDLE ControllerHandle
,
351 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
355 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
356 EFI_DISK_IO_PROTOCOL
*DiskIo
;
357 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
363 // If caller has already acquired the lock, cannot lock it again.
365 Status
= FatAcquireLockOrFail ();
366 if (!EFI_ERROR (Status
)) {
370 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
371 if (EFI_ERROR (Status
)) {
375 // Open our required BlockIo and DiskIo
377 Status
= gBS
->OpenProtocol (
379 &gEfiBlockIoProtocolGuid
,
381 This
->DriverBindingHandle
,
383 EFI_OPEN_PROTOCOL_GET_PROTOCOL
385 if (EFI_ERROR (Status
)) {
389 Status
= gBS
->OpenProtocol (
391 &gEfiDiskIoProtocolGuid
,
393 This
->DriverBindingHandle
,
395 EFI_OPEN_PROTOCOL_BY_DRIVER
397 if (EFI_ERROR (Status
)) {
401 Status
= gBS
->OpenProtocol (
403 &gEfiDiskIo2ProtocolGuid
,
405 This
->DriverBindingHandle
,
407 EFI_OPEN_PROTOCOL_BY_DRIVER
409 if (EFI_ERROR (Status
)) {
414 // Allocate Volume structure. In FatAllocateVolume(), Resources
415 // are allocated with protocol installed and cached initialized
417 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
420 // When the media changes on a device it will Reinstall the BlockIo interaface.
421 // This will cause a call to our Stop(), and a subsequent reentrant call to our
422 // Start() successfully. We should leave the device open when this happen.
424 if (EFI_ERROR (Status
)) {
425 Status
= gBS
->OpenProtocol (
427 &gEfiSimpleFileSystemProtocolGuid
,
429 This
->DriverBindingHandle
,
431 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
433 if (EFI_ERROR (Status
)) {
436 &gEfiDiskIoProtocolGuid
,
437 This
->DriverBindingHandle
,
442 &gEfiDiskIo2ProtocolGuid
,
443 This
->DriverBindingHandle
,
451 // Unlock if locked by myself.
461 Stop this driver on ControllerHandle.
463 @param This - Protocol instance pointer.
464 @param ControllerHandle - Handle of device to stop driver on.
465 @param NumberOfChildren - Not used.
466 @param ChildHandleBuffer - Not used.
468 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
469 @return other - This driver was not removed from this device.
474 FatDriverBindingStop (
475 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
476 IN EFI_HANDLE ControllerHandle
,
477 IN UINTN NumberOfChildren
,
478 IN EFI_HANDLE
*ChildHandleBuffer
482 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
484 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
488 // Get our context back
490 Status
= gBS
->OpenProtocol (
492 &gEfiSimpleFileSystemProtocolGuid
,
493 (VOID
**) &FileSystem
,
494 This
->DriverBindingHandle
,
496 EFI_OPEN_PROTOCOL_GET_PROTOCOL
499 if (!EFI_ERROR (Status
)) {
500 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
501 DiskIo2
= Volume
->DiskIo2
;
502 Status
= FatAbandonVolume (Volume
);
505 if (!EFI_ERROR (Status
)) {
506 if (DiskIo2
!= NULL
) {
507 Status
= gBS
->CloseProtocol (
509 &gEfiDiskIo2ProtocolGuid
,
510 This
->DriverBindingHandle
,
513 ASSERT_EFI_ERROR (Status
);
515 Status
= gBS
->CloseProtocol (
517 &gEfiDiskIoProtocolGuid
,
518 This
->DriverBindingHandle
,
521 ASSERT_EFI_ERROR (Status
);