2 UDF/ECMA-167 file system driver.
4 Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
12 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // UDF filesystem driver's Global Variables.
20 EFI_DRIVER_BINDING_PROTOCOL gUdfDriverBinding
= {
21 UdfDriverBindingSupported
,
22 UdfDriverBindingStart
,
29 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gUdfSimpleFsTemplate
= {
30 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
,
35 Test to see if this driver supports ControllerHandle. Any ControllerHandle
36 than contains a BlockIo and DiskIo protocol or a BlockIo2 protocol can be
39 @param[in] This Protocol instance pointer.
40 @param[in] ControllerHandle Handle of device to test.
41 @param[in] RemainingDevicePath Optional parameter use to pick a specific
42 child device to start.
44 @retval EFI_SUCCESS This driver supports this device.
45 @retval EFI_ALREADY_STARTED This driver is already running on this device.
46 @retval other This driver does not support this device.
51 UdfDriverBindingSupported (
52 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
53 IN EFI_HANDLE ControllerHandle
,
54 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
58 EFI_DISK_IO_PROTOCOL
*DiskIo
;
61 // Open DiskIo protocol on ControllerHandle
63 Status
= gBS
->OpenProtocol (
65 &gEfiDiskIoProtocolGuid
,
67 This
->DriverBindingHandle
,
69 EFI_OPEN_PROTOCOL_BY_DRIVER
71 if (EFI_ERROR (Status
)) {
76 // Close DiskIo protocol on ControllerHandle
80 &gEfiDiskIoProtocolGuid
,
81 This
->DriverBindingHandle
,
86 // Test whether ControllerHandle supports BlockIo protocol
88 Status
= gBS
->OpenProtocol (
90 &gEfiBlockIoProtocolGuid
,
92 This
->DriverBindingHandle
,
94 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
101 Start this driver on ControllerHandle by opening a Block IO or a Block IO2
102 or both, and Disk IO protocol, reading Device Path, and creating a child
103 handle with a Disk IO and device path protocol.
105 @param[in] This Protocol instance pointer.
106 @param[in] ControllerHandle Handle of device to bind driver to
107 @param[in] RemainingDevicePath Optional parameter use to pick a specific
108 child device to start.
110 @retval EFI_SUCCESS This driver is added to ControllerHandle.
111 @retval EFI_ALREADY_STARTED This driver is already running on
113 @retval other This driver does not support this device.
118 UdfDriverBindingStart (
119 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
120 IN EFI_HANDLE ControllerHandle
,
121 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
126 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
127 EFI_DISK_IO_PROTOCOL
*DiskIo
;
128 PRIVATE_UDF_SIMPLE_FS_DATA
*PrivFsData
;
130 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
133 // Open BlockIo protocol on ControllerHandle
135 Status
= gBS
->OpenProtocol (
137 &gEfiBlockIoProtocolGuid
,
139 This
->DriverBindingHandle
,
141 EFI_OPEN_PROTOCOL_GET_PROTOCOL
143 ASSERT_EFI_ERROR (Status
);
146 // Open DiskIo protocol on ControllerHandle
148 Status
= gBS
->OpenProtocol (
150 &gEfiDiskIoProtocolGuid
,
152 This
->DriverBindingHandle
,
154 EFI_OPEN_PROTOCOL_BY_DRIVER
156 ASSERT_EFI_ERROR (Status
);
159 // Check if ControllerHandle supports an UDF file system
161 Status
= SupportUdfFileSystem (This
, ControllerHandle
);
162 if (EFI_ERROR (Status
)) {
167 // Initialize private file system structure
170 (PRIVATE_UDF_SIMPLE_FS_DATA
*)
171 AllocateZeroPool (sizeof (PRIVATE_UDF_SIMPLE_FS_DATA
));
172 if (PrivFsData
== NULL
) {
173 Status
= EFI_OUT_OF_RESOURCES
;
178 // Create new child handle
180 PrivFsData
->Signature
= PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE
;
181 PrivFsData
->BlockIo
= BlockIo
;
182 PrivFsData
->DiskIo
= DiskIo
;
183 PrivFsData
->Handle
= ControllerHandle
;
186 // Set up SimpleFs protocol
188 CopyMem ((VOID
*)&PrivFsData
->SimpleFs
, (VOID
*)&gUdfSimpleFsTemplate
,
189 sizeof (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
));
192 // Install child handle
194 Status
= gBS
->InstallMultipleProtocolInterfaces (
196 &gEfiSimpleFileSystemProtocolGuid
,
197 &PrivFsData
->SimpleFs
,
202 if (EFI_ERROR (Status
)) {
204 // Close DiskIo protocol on ControllerHandle
208 &gEfiDiskIoProtocolGuid
,
209 This
->DriverBindingHandle
,
213 // Close BlockIo protocol on ControllerHandle
217 &gEfiBlockIoProtocolGuid
,
218 This
->DriverBindingHandle
,
223 gBS
->RestoreTPL (OldTpl
);
229 Stop this driver on ControllerHandle. Support stopping any child handles
230 created by this driver.
232 @param This Protocol instance pointer.
233 @param ControllerHandle Handle of device to stop driver on
234 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
235 children is zero stop the entire bus driver.
236 @param ChildHandleBuffer List of Child Handles to Stop.
238 @retval EFI_SUCCESS This driver is removed ControllerHandle
239 @retval other This driver was not removed from this device
244 UdfDriverBindingStop (
245 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
246 IN EFI_HANDLE ControllerHandle
,
247 IN UINTN NumberOfChildren
,
248 IN EFI_HANDLE
*ChildHandleBuffer
251 PRIVATE_UDF_SIMPLE_FS_DATA
*PrivFsData
;
253 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFs
;
256 // Open SimpleFs protocol on ControllerHandle
258 Status
= gBS
->OpenProtocol (
260 &gEfiSimpleFileSystemProtocolGuid
,
262 This
->DriverBindingHandle
,
264 EFI_OPEN_PROTOCOL_GET_PROTOCOL
266 if (!EFI_ERROR (Status
)) {
267 PrivFsData
= PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (SimpleFs
);
270 // Uninstall child handle
272 Status
= gBS
->UninstallMultipleProtocolInterfaces (
274 &gEfiSimpleFileSystemProtocolGuid
,
275 &PrivFsData
->SimpleFs
,
279 FreePool ((VOID
*)PrivFsData
);
282 if (!EFI_ERROR (Status
)) {
284 // Close DiskIo protocol on ControllerHandle
288 &gEfiDiskIoProtocolGuid
,
289 This
->DriverBindingHandle
,
293 // Close BlockIo protocol on ControllerHandle
297 &gEfiBlockIoProtocolGuid
,
298 This
->DriverBindingHandle
,
307 The user Entry Point for UDF file system driver. The user code starts with
310 @param[in] ImageHandle The firmware allocated handle for the EFI image.
311 @param[in] SystemTable A pointer to the EFI System Table.
313 @retval EFI_SUCCESS The entry point is executed successfully.
314 @retval other Some error occurs when executing this entry point.
320 IN EFI_HANDLE ImageHandle
,
321 IN EFI_SYSTEM_TABLE
*SystemTable
326 Status
= EfiLibInstallDriverBindingComponentName2 (
334 ASSERT_EFI_ERROR (Status
);