3 Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Fat File System driver routines that support EFI driver model
28 IN EFI_HANDLE ImageHandle
,
29 IN EFI_SYSTEM_TABLE
*SystemTable
35 IN EFI_HANDLE ImageHandle
40 FatDriverBindingSupported (
41 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
42 IN EFI_HANDLE Controller
,
43 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
48 FatDriverBindingStart (
49 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
50 IN EFI_HANDLE Controller
,
51 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
56 FatDriverBindingStop (
57 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
58 IN EFI_HANDLE Controller
,
59 IN UINTN NumberOfChildren
,
60 IN EFI_HANDLE
*ChildHandleBuffer
64 // DriverBinding protocol instance
66 EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
= {
67 FatDriverBindingSupported
,
68 FatDriverBindingStart
,
78 IN EFI_HANDLE ImageHandle
,
79 IN EFI_SYSTEM_TABLE
*SystemTable
85 Register Driver Binding protocol for this driver.
89 ImageHandle - Handle for the image of this driver.
90 SystemTable - Pointer to the EFI System Table.
94 EFI_SUCCESS - Driver loaded.
95 other - Driver not loaded.
102 // Initialize the EFI Driver Library
104 Status
= EfiLibInstallDriverBindingComponentName2 (
112 ASSERT_EFI_ERROR (Status
);
120 IN EFI_HANDLE ImageHandle
126 Unload function for this image. Uninstall DriverBinding protocol.
130 ImageHandle - Handle for the image of this driver.
134 EFI_SUCCESS - Driver unloaded successfully.
135 other - Driver can not unloaded.
140 EFI_HANDLE
*DeviceHandleBuffer
;
141 UINTN DeviceHandleCount
;
144 Status
= gBS
->LocateHandleBuffer (
151 if (!EFI_ERROR (Status
)) {
152 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
153 Status
= gBS
->DisconnectController (
154 DeviceHandleBuffer
[Index
],
160 if (DeviceHandleBuffer
!= NULL
) {
161 FreePool (DeviceHandleBuffer
);
170 FatDriverBindingSupported (
171 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
172 IN EFI_HANDLE ControllerHandle
,
173 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
179 Test to see if this driver can add a file system to ControllerHandle.
180 ControllerHandle must support both Disk IO and Block IO protocols.
184 This - Protocol instance pointer.
185 ControllerHandle - Handle of device to test.
186 RemainingDevicePath - Not used.
190 EFI_SUCCESS - This driver supports this device.
191 EFI_ALREADY_STARTED - This driver is already running on this device.
192 other - This driver does not support this device.
197 EFI_DISK_IO_PROTOCOL
*DiskIo
;
200 // Open the IO Abstraction(s) needed to perform the supported test
202 Status
= gBS
->OpenProtocol (
204 &gEfiDiskIoProtocolGuid
,
206 This
->DriverBindingHandle
,
208 EFI_OPEN_PROTOCOL_BY_DRIVER
211 if (EFI_ERROR (Status
)) {
215 // Close the I/O Abstraction(s) used to perform the supported test
219 &gEfiDiskIoProtocolGuid
,
220 This
->DriverBindingHandle
,
225 // Open the IO Abstraction(s) needed to perform the supported test
227 Status
= gBS
->OpenProtocol (
229 &gEfiBlockIoProtocolGuid
,
231 This
->DriverBindingHandle
,
233 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
241 FatDriverBindingStart (
242 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
243 IN EFI_HANDLE ControllerHandle
,
244 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
250 Start this driver on ControllerHandle by opening a Block IO and Disk IO
251 protocol, reading Device Path. Add a Simple File System protocol to
252 ControllerHandle if the media contains a valid file system.
256 This - Protocol instance pointer.
257 ControllerHandle - Handle of device to bind driver to.
258 RemainingDevicePath - Not used.
262 EFI_SUCCESS - This driver is added to DeviceHandle.
263 EFI_ALREADY_STARTED - This driver is already running on DeviceHandle.
264 EFI_OUT_OF_RESOURCES - Can not allocate the memory.
265 other - This driver does not support this device.
270 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
271 EFI_DISK_IO_PROTOCOL
*DiskIo
;
277 // If caller has already acquired the lock, cannot lock it again.
279 Status
= FatAcquireLockOrFail ();
280 if (!EFI_ERROR (Status
)) {
284 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
285 if (EFI_ERROR (Status
)) {
289 // Open our required BlockIo and DiskIo
291 Status
= gBS
->OpenProtocol (
293 &gEfiBlockIoProtocolGuid
,
295 This
->DriverBindingHandle
,
297 EFI_OPEN_PROTOCOL_GET_PROTOCOL
299 if (EFI_ERROR (Status
)) {
303 Status
= gBS
->OpenProtocol (
305 &gEfiDiskIoProtocolGuid
,
307 This
->DriverBindingHandle
,
309 EFI_OPEN_PROTOCOL_BY_DRIVER
311 if (EFI_ERROR (Status
)) {
315 // Allocate Volume structure. In FatAllocateVolume(), Resources
316 // are allocated with protocol installed and cached initialized
318 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, BlockIo
);
321 // When the media changes on a device it will Reinstall the BlockIo interaface.
322 // This will cause a call to our Stop(), and a subsequent reentrant call to our
323 // Start() successfully. We should leave the device open when this happen.
325 if (EFI_ERROR (Status
)) {
326 Status
= gBS
->OpenProtocol (
328 &gEfiSimpleFileSystemProtocolGuid
,
330 This
->DriverBindingHandle
,
332 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
334 if (EFI_ERROR (Status
)) {
337 &gEfiDiskIoProtocolGuid
,
338 This
->DriverBindingHandle
,
346 // Unlock if locked by myself.
356 FatDriverBindingStop (
357 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
358 IN EFI_HANDLE ControllerHandle
,
359 IN UINTN NumberOfChildren
,
360 IN EFI_HANDLE
*ChildHandleBuffer
365 Stop this driver on ControllerHandle.
368 This - Protocol instance pointer.
369 ControllerHandle - Handle of device to stop driver on.
370 NumberOfChildren - Not used.
371 ChildHandleBuffer - Not used.
374 EFI_SUCCESS - This driver is removed DeviceHandle.
375 other - This driver was not removed from this device.
380 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
384 // Get our context back
386 Status
= gBS
->OpenProtocol (
388 &gEfiSimpleFileSystemProtocolGuid
,
389 (VOID
**) &FileSystem
,
390 This
->DriverBindingHandle
,
392 EFI_OPEN_PROTOCOL_GET_PROTOCOL
395 if (!EFI_ERROR (Status
)) {
396 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
397 Status
= FatAbandonVolume (Volume
);
398 if (EFI_ERROR (Status
)) {
403 Status
= gBS
->CloseProtocol (
405 &gEfiDiskIoProtocolGuid
,
406 This
->DriverBindingHandle
,