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
,
232 Status
= gBS
->UninstallMultipleProtocolInterfaces (
234 &gEfiDriverBindingProtocolGuid
,
236 &gEfiComponentName2ProtocolGuid
,
242 if (ComponentName2
== NULL
) {
243 Status
= gBS
->UninstallMultipleProtocolInterfaces (
245 &gEfiDriverBindingProtocolGuid
,
247 &gEfiComponentNameProtocolGuid
,
252 Status
= gBS
->UninstallMultipleProtocolInterfaces (
254 &gEfiDriverBindingProtocolGuid
,
256 &gEfiComponentNameProtocolGuid
,
258 &gEfiComponentName2ProtocolGuid
,
266 if (DeviceHandleBuffer
!= NULL
) {
267 FreePool (DeviceHandleBuffer
);
275 Test to see if this driver can add a file system to ControllerHandle.
276 ControllerHandle must support both Disk IO and Block IO protocols.
278 @param This - Protocol instance pointer.
279 @param ControllerHandle - Handle of device to test.
280 @param RemainingDevicePath - Not used.
282 @retval EFI_SUCCESS - This driver supports this device.
283 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
284 @return other - This driver does not support this device.
289 FatDriverBindingSupported (
290 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
291 IN EFI_HANDLE ControllerHandle
,
292 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
296 EFI_DISK_IO_PROTOCOL
*DiskIo
;
299 // Open the IO Abstraction(s) needed to perform the supported test
301 Status
= gBS
->OpenProtocol (
303 &gEfiDiskIoProtocolGuid
,
305 This
->DriverBindingHandle
,
307 EFI_OPEN_PROTOCOL_BY_DRIVER
310 if (EFI_ERROR (Status
)) {
315 // Close the I/O Abstraction(s) used to perform the supported test
319 &gEfiDiskIoProtocolGuid
,
320 This
->DriverBindingHandle
,
325 // Open the IO Abstraction(s) needed to perform the supported test
327 Status
= gBS
->OpenProtocol (
329 &gEfiBlockIoProtocolGuid
,
331 This
->DriverBindingHandle
,
333 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
341 Start this driver on ControllerHandle by opening a Block IO and Disk IO
342 protocol, reading Device Path. Add a Simple File System protocol to
343 ControllerHandle if the media contains a valid file system.
345 @param This - Protocol instance pointer.
346 @param ControllerHandle - Handle of device to bind driver to.
347 @param RemainingDevicePath - Not used.
349 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
350 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
351 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
352 @return other - This driver does not support this device.
357 FatDriverBindingStart (
358 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
359 IN EFI_HANDLE ControllerHandle
,
360 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
364 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
365 EFI_DISK_IO_PROTOCOL
*DiskIo
;
366 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
372 // If caller has already acquired the lock, cannot lock it again.
374 Status
= FatAcquireLockOrFail ();
375 if (!EFI_ERROR (Status
)) {
379 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
380 if (EFI_ERROR (Status
)) {
385 // Open our required BlockIo and DiskIo
387 Status
= gBS
->OpenProtocol (
389 &gEfiBlockIoProtocolGuid
,
391 This
->DriverBindingHandle
,
393 EFI_OPEN_PROTOCOL_GET_PROTOCOL
395 if (EFI_ERROR (Status
)) {
399 Status
= gBS
->OpenProtocol (
401 &gEfiDiskIoProtocolGuid
,
403 This
->DriverBindingHandle
,
405 EFI_OPEN_PROTOCOL_BY_DRIVER
407 if (EFI_ERROR (Status
)) {
411 Status
= gBS
->OpenProtocol (
413 &gEfiDiskIo2ProtocolGuid
,
415 This
->DriverBindingHandle
,
417 EFI_OPEN_PROTOCOL_BY_DRIVER
419 if (EFI_ERROR (Status
)) {
424 // Allocate Volume structure. In FatAllocateVolume(), Resources
425 // are allocated with protocol installed and cached initialized
427 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
430 // When the media changes on a device it will Reinstall the BlockIo interface.
431 // This will cause a call to our Stop(), and a subsequent reentrant call to our
432 // Start() successfully. We should leave the device open when this happen.
434 if (EFI_ERROR (Status
)) {
435 Status
= gBS
->OpenProtocol (
437 &gEfiSimpleFileSystemProtocolGuid
,
439 This
->DriverBindingHandle
,
441 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
443 if (EFI_ERROR (Status
)) {
446 &gEfiDiskIoProtocolGuid
,
447 This
->DriverBindingHandle
,
452 &gEfiDiskIo2ProtocolGuid
,
453 This
->DriverBindingHandle
,
461 // Unlock if locked by myself.
472 Stop this driver on ControllerHandle.
474 @param This - Protocol instance pointer.
475 @param ControllerHandle - Handle of device to stop driver on.
476 @param NumberOfChildren - Not used.
477 @param ChildHandleBuffer - Not used.
479 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
480 @return other - This driver was not removed from this device.
485 FatDriverBindingStop (
486 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
487 IN EFI_HANDLE ControllerHandle
,
488 IN UINTN NumberOfChildren
,
489 IN EFI_HANDLE
*ChildHandleBuffer
493 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
495 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
499 // Get our context back
501 Status
= gBS
->OpenProtocol (
503 &gEfiSimpleFileSystemProtocolGuid
,
504 (VOID
**)&FileSystem
,
505 This
->DriverBindingHandle
,
507 EFI_OPEN_PROTOCOL_GET_PROTOCOL
510 if (!EFI_ERROR (Status
)) {
511 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
512 DiskIo2
= Volume
->DiskIo2
;
513 Status
= FatAbandonVolume (Volume
);
516 if (!EFI_ERROR (Status
)) {
517 if (DiskIo2
!= NULL
) {
518 Status
= gBS
->CloseProtocol (
520 &gEfiDiskIo2ProtocolGuid
,
521 This
->DriverBindingHandle
,
524 ASSERT_EFI_ERROR (Status
);
527 Status
= gBS
->CloseProtocol (
529 &gEfiDiskIoProtocolGuid
,
530 This
->DriverBindingHandle
,
533 ASSERT_EFI_ERROR (Status
);