3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. 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
;
273 Status
= InitializeUnicodeCollationSupport (This
->DriverBindingHandle
);
274 if (EFI_ERROR (Status
)) {
278 // Open our required BlockIo and DiskIo
280 Status
= gBS
->OpenProtocol (
282 &gEfiBlockIoProtocolGuid
,
284 This
->DriverBindingHandle
,
286 EFI_OPEN_PROTOCOL_GET_PROTOCOL
288 if (EFI_ERROR (Status
)) {
292 Status
= gBS
->OpenProtocol (
294 &gEfiDiskIoProtocolGuid
,
296 This
->DriverBindingHandle
,
298 EFI_OPEN_PROTOCOL_BY_DRIVER
300 if (EFI_ERROR (Status
)) {
304 // Allocate Volume structure. In FatAllocateVolume(), Resources
305 // are allocated with protocol installed and cached initialized
307 Status
= FatAllocateVolume (ControllerHandle
, DiskIo
, BlockIo
);
310 // When the media changes on a device it will Reinstall the BlockIo interaface.
311 // This will cause a call to our Stop(), and a subsequent reentrant call to our
312 // Start() successfully. We should leave the device open when this happen.
314 if (EFI_ERROR (Status
)) {
315 Status
= gBS
->OpenProtocol (
317 &gEfiSimpleFileSystemProtocolGuid
,
319 This
->DriverBindingHandle
,
321 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
323 if (EFI_ERROR (Status
)) {
326 &gEfiDiskIoProtocolGuid
,
327 This
->DriverBindingHandle
,
338 FatDriverBindingStop (
339 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
340 IN EFI_HANDLE ControllerHandle
,
341 IN UINTN NumberOfChildren
,
342 IN EFI_HANDLE
*ChildHandleBuffer
347 Stop this driver on ControllerHandle.
350 This - Protocol instance pointer.
351 ControllerHandle - Handle of device to stop driver on.
352 NumberOfChildren - Not used.
353 ChildHandleBuffer - Not used.
356 EFI_SUCCESS - This driver is removed DeviceHandle.
357 other - This driver was not removed from this device.
362 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*FileSystem
;
366 // Get our context back
368 Status
= gBS
->OpenProtocol (
370 &gEfiSimpleFileSystemProtocolGuid
,
371 (VOID
**) &FileSystem
,
372 This
->DriverBindingHandle
,
374 EFI_OPEN_PROTOCOL_GET_PROTOCOL
377 if (!EFI_ERROR (Status
)) {
378 Volume
= VOLUME_FROM_VOL_INTERFACE (FileSystem
);
379 Status
= FatAbandonVolume (Volume
);
380 if (EFI_ERROR (Status
)) {
385 Status
= gBS
->CloseProtocol (
387 &gEfiDiskIoProtocolGuid
,
388 This
->DriverBindingHandle
,