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.
19 Register Driver Binding protocol for this driver.
21 @param ImageHandle - Handle for the image of this driver.
22 @param SystemTable - Pointer to the EFI System Table.
24 @retval EFI_SUCCESS - Driver loaded.
25 @return other - Driver not loaded.
31 IN EFI_HANDLE ImageHandle
,
32 IN EFI_SYSTEM_TABLE
*SystemTable
37 Unload function for this image. Uninstall DriverBinding protocol.
39 @param ImageHandle - Handle for the image of this driver.
41 @retval EFI_SUCCESS - Driver unloaded successfully.
42 @return other - Driver can not unloaded.
48 IN EFI_HANDLE ImageHandle
53 Test to see if this driver can add a file system to ControllerHandle.
54 ControllerHandle must support both Disk IO and Block IO protocols.
56 @param This - Protocol instance pointer.
57 @param ControllerHandle - Handle of device to test.
58 @param RemainingDevicePath - Not used.
60 @retval EFI_SUCCESS - This driver supports this device.
61 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
62 @return other - This driver does not support this device.
67 FatDriverBindingSupported (
68 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
69 IN EFI_HANDLE Controller
,
70 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
75 Start this driver on ControllerHandle by opening a Block IO and Disk IO
76 protocol, reading Device Path. Add a Simple File System protocol to
77 ControllerHandle if the media contains a valid file system.
79 @param This - Protocol instance pointer.
80 @param ControllerHandle - Handle of device to bind driver to.
81 @param RemainingDevicePath - Not used.
83 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
84 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
85 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
86 @return other - This driver does not support this device.
91 FatDriverBindingStart (
92 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
93 IN EFI_HANDLE Controller
,
94 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
99 Stop this driver on ControllerHandle.
101 @param This - Protocol instance pointer.
102 @param ControllerHandle - Handle of device to stop driver on.
103 @param NumberOfChildren - Not used.
104 @param ChildHandleBuffer - Not used.
106 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
107 @return other - This driver was not removed from this device.
112 FatDriverBindingStop (
113 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
114 IN EFI_HANDLE Controller
,
115 IN UINTN NumberOfChildren
,
116 IN EFI_HANDLE
*ChildHandleBuffer
120 // DriverBinding protocol instance
122 EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
= {
123 FatDriverBindingSupported
,
124 FatDriverBindingStart
,
125 FatDriverBindingStop
,
133 Register Driver Binding protocol for this driver.
135 @param ImageHandle - Handle for the image of this driver.
136 @param SystemTable - Pointer to the EFI System Table.
138 @retval EFI_SUCCESS - Driver loaded.
139 @return other - Driver not loaded.
145 IN EFI_HANDLE ImageHandle
,
146 IN EFI_SYSTEM_TABLE
*SystemTable
152 // Initialize the EFI Driver Library
154 Status
= EfiLibInstallDriverBindingComponentName2 (
162 ASSERT_EFI_ERROR (Status
);
169 Unload function for this image. Uninstall DriverBinding protocol.
171 @param ImageHandle - Handle for the image of this driver.
173 @retval EFI_SUCCESS - Driver unloaded successfully.
174 @return other - Driver can not unloaded.
180 IN EFI_HANDLE ImageHandle
184 EFI_HANDLE
*DeviceHandleBuffer
;
185 UINTN DeviceHandleCount
;
188 VOID
*ComponentName2
;
190 Status
= gBS
->LocateHandleBuffer (
197 if (EFI_ERROR (Status
)) {
201 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
202 Status
= EfiTestManagedDevice (DeviceHandleBuffer
[Index
], ImageHandle
, &gEfiDiskIoProtocolGuid
);
203 if (!EFI_ERROR (Status
)) {
204 Status
= gBS
->DisconnectController (
205 DeviceHandleBuffer
[Index
],
209 if (EFI_ERROR (Status
)) {
215 if (Index
== DeviceHandleCount
) {
217 // Driver is stopped successfully.
219 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentNameProtocolGuid
, &ComponentName
);
220 if (EFI_ERROR (Status
)) {
221 ComponentName
= NULL
;
224 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiComponentName2ProtocolGuid
, &ComponentName2
);
225 if (EFI_ERROR (Status
)) {
226 ComponentName2
= NULL
;
229 if (ComponentName
== NULL
) {
230 if (ComponentName2
== NULL
) {
231 Status
= gBS
->UninstallMultipleProtocolInterfaces (
233 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
237 Status
= gBS
->UninstallMultipleProtocolInterfaces (
239 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
240 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
245 if (ComponentName2
== NULL
) {
246 Status
= gBS
->UninstallMultipleProtocolInterfaces (
248 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
249 &gEfiComponentNameProtocolGuid
, ComponentName
,
253 Status
= gBS
->UninstallMultipleProtocolInterfaces (
255 &gEfiDriverBindingProtocolGuid
, &gFatDriverBinding
,
256 &gEfiComponentNameProtocolGuid
, ComponentName
,
257 &gEfiComponentName2ProtocolGuid
, ComponentName2
,
264 if (DeviceHandleBuffer
!= NULL
) {
265 FreePool (DeviceHandleBuffer
);
273 Test to see if this driver can add a file system to ControllerHandle.
274 ControllerHandle must support both Disk IO and Block IO protocols.
276 @param This - Protocol instance pointer.
277 @param ControllerHandle - Handle of device to test.
278 @param RemainingDevicePath - Not used.
280 @retval EFI_SUCCESS - This driver supports this device.
281 @retval EFI_ALREADY_STARTED - This driver is already running on this device.
282 @return other - This driver does not support this device.
287 FatDriverBindingSupported (
288 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
289 IN EFI_HANDLE ControllerHandle
,
290 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
294 EFI_DISK_IO_PROTOCOL
*DiskIo
;
297 // Open the IO Abstraction(s) needed to perform the supported test
299 Status
= gBS
->OpenProtocol (
301 &gEfiDiskIoProtocolGuid
,
303 This
->DriverBindingHandle
,
305 EFI_OPEN_PROTOCOL_BY_DRIVER
308 if (EFI_ERROR (Status
)) {
312 // Close the I/O Abstraction(s) used to perform the supported test
316 &gEfiDiskIoProtocolGuid
,
317 This
->DriverBindingHandle
,
322 // Open the IO Abstraction(s) needed to perform the supported test
324 Status
= gBS
->OpenProtocol (
326 &gEfiBlockIoProtocolGuid
,
328 This
->DriverBindingHandle
,
330 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
338 Start this driver on ControllerHandle by opening a Block IO and Disk IO
339 protocol, reading Device Path. Add a Simple File System protocol to
340 ControllerHandle if the media contains a valid file system.
342 @param This - Protocol instance pointer.
343 @param ControllerHandle - Handle of device to bind driver to.
344 @param RemainingDevicePath - Not used.
346 @retval EFI_SUCCESS - This driver is added to DeviceHandle.
347 @retval EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
348 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
349 @return other - This driver does not support this device.
354 FatDriverBindingStart (
355 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
356 IN EFI_HANDLE ControllerHandle
,
357 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
361 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
362 EFI_DISK_IO_PROTOCOL
*DiskIo
;
363 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
369 // If caller has already acquired the lock, cannot lock it again.
371 Status
= FatAcquireLockOrFail ();
372 if (!EFI_ERROR (Status
)) {
376 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
377 if (EFI_ERROR (Status
)) {
381 // Open our required BlockIo and DiskIo
383 Status
= gBS
->OpenProtocol (
385 &gEfiBlockIoProtocolGuid
,
387 This
->DriverBindingHandle
,
389 EFI_OPEN_PROTOCOL_GET_PROTOCOL
391 if (EFI_ERROR (Status
)) {
395 Status
= gBS
->OpenProtocol (
397 &gEfiDiskIoProtocolGuid
,
399 This
->DriverBindingHandle
,
401 EFI_OPEN_PROTOCOL_BY_DRIVER
403 if (EFI_ERROR (Status
)) {
407 Status
= gBS
->OpenProtocol (
409 &gEfiDiskIo2ProtocolGuid
,
411 This
->DriverBindingHandle
,
413 EFI_OPEN_PROTOCOL_BY_DRIVER
415 if (EFI_ERROR (Status
)) {
420 // Allocate Volume structure. In FatAllocateVolume(), Resources
421 // are allocated with protocol installed and cached initialized
423 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, DiskIo2
, BlockIo
);
426 // When the media changes on a device it will Reinstall the BlockIo interaface.
427 // This will cause a call to our Stop(), and a subsequent reentrant call to our
428 // Start() successfully. We should leave the device open when this happen.
430 if (EFI_ERROR (Status
)) {
431 Status
= gBS
->OpenProtocol (
433 &gEfiSimpleFileSystemProtocolGuid
,
435 This
->DriverBindingHandle
,
437 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
439 if (EFI_ERROR (Status
)) {
442 &gEfiDiskIoProtocolGuid
,
443 This
->DriverBindingHandle
,
448 &gEfiDiskIo2ProtocolGuid
,
449 This
->DriverBindingHandle
,
457 // Unlock if locked by myself.
467 Stop this driver on ControllerHandle.
469 @param This - Protocol instance pointer.
470 @param ControllerHandle - Handle of device to stop driver on.
471 @param NumberOfChildren - Not used.
472 @param ChildHandleBuffer - Not used.
474 @retval EFI_SUCCESS - This driver is removed DeviceHandle.
475 @return other - This driver was not removed from this device.
480 FatDriverBindingStop (
481 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
482 IN EFI_HANDLE ControllerHandle
,
483 IN UINTN NumberOfChildren
,
484 IN EFI_HANDLE
*ChildHandleBuffer
488 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
490 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
494 // Get our context back
496 Status
= gBS
->OpenProtocol (
498 &gEfiSimpleFileSystemProtocolGuid
,
499 (VOID
**) &FileSystem
,
500 This
->DriverBindingHandle
,
502 EFI_OPEN_PROTOCOL_GET_PROTOCOL
505 if (!EFI_ERROR (Status
)) {
506 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
507 DiskIo2
= Volume
->DiskIo2
;
508 Status
= FatAbandonVolume (Volume
);
511 if (!EFI_ERROR (Status
)) {
512 if (DiskIo2
!= NULL
) {
513 Status
= gBS
->CloseProtocol (
515 &gEfiDiskIo2ProtocolGuid
,
516 This
->DriverBindingHandle
,
519 ASSERT_EFI_ERROR (Status
);
521 Status
= gBS
->CloseProtocol (
523 &gEfiDiskIoProtocolGuid
,
524 This
->DriverBindingHandle
,
527 ASSERT_EFI_ERROR (Status
);