]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UdfDxe / Udf.c
1 /** @file
2 UDF/ECMA-167 file system driver.
3
4 Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 **/
8
9 #include "Udf.h"
10
11 //
12 // UDF filesystem driver's Global Variables.
13 //
14 EFI_DRIVER_BINDING_PROTOCOL gUdfDriverBinding = {
15 UdfDriverBindingSupported,
16 UdfDriverBindingStart,
17 UdfDriverBindingStop,
18 0x10,
19 NULL,
20 NULL
21 };
22
23 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gUdfSimpleFsTemplate = {
24 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
25 UdfOpenVolume
26 };
27
28 /**
29 Test to see if this driver supports ControllerHandle. Any ControllerHandle
30 than contains a BlockIo and DiskIo protocol or a BlockIo2 protocol can be
31 supported.
32
33 @param[in] This Protocol instance pointer.
34 @param[in] ControllerHandle Handle of device to test.
35 @param[in] RemainingDevicePath Optional parameter use to pick a specific
36 child device to start.
37
38 @retval EFI_SUCCESS This driver supports this device.
39 @retval EFI_ALREADY_STARTED This driver is already running on this device.
40 @retval other This driver does not support this device.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 UdfDriverBindingSupported (
46 IN EFI_DRIVER_BINDING_PROTOCOL *This,
47 IN EFI_HANDLE ControllerHandle,
48 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
49 )
50 {
51 EFI_STATUS Status;
52 EFI_DISK_IO_PROTOCOL *DiskIo;
53
54 //
55 // Open DiskIo protocol on ControllerHandle
56 //
57 Status = gBS->OpenProtocol (
58 ControllerHandle,
59 &gEfiDiskIoProtocolGuid,
60 (VOID **)&DiskIo,
61 This->DriverBindingHandle,
62 ControllerHandle,
63 EFI_OPEN_PROTOCOL_BY_DRIVER
64 );
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 //
70 // Close DiskIo protocol on ControllerHandle
71 //
72 gBS->CloseProtocol (
73 ControllerHandle,
74 &gEfiDiskIoProtocolGuid,
75 This->DriverBindingHandle,
76 ControllerHandle
77 );
78
79 //
80 // Test whether ControllerHandle supports BlockIo protocol
81 //
82 Status = gBS->OpenProtocol (
83 ControllerHandle,
84 &gEfiBlockIoProtocolGuid,
85 NULL,
86 This->DriverBindingHandle,
87 ControllerHandle,
88 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
89 );
90
91 return Status;
92 }
93
94 /**
95 Start this driver on ControllerHandle by opening a Block IO or a Block IO2
96 or both, and Disk IO protocol, reading Device Path, and creating a child
97 handle with a Disk IO and device path protocol.
98
99 @param[in] This Protocol instance pointer.
100 @param[in] ControllerHandle Handle of device to bind driver to
101 @param[in] RemainingDevicePath Optional parameter use to pick a specific
102 child device to start.
103
104 @retval EFI_SUCCESS This driver is added to ControllerHandle.
105 @retval EFI_ALREADY_STARTED This driver is already running on
106 ControllerHandle.
107 @retval other This driver does not support this device.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 UdfDriverBindingStart (
113 IN EFI_DRIVER_BINDING_PROTOCOL *This,
114 IN EFI_HANDLE ControllerHandle,
115 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
116 )
117 {
118 EFI_TPL OldTpl;
119 EFI_STATUS Status;
120 EFI_BLOCK_IO_PROTOCOL *BlockIo;
121 EFI_DISK_IO_PROTOCOL *DiskIo;
122 PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData;
123
124 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
125
126 //
127 // Open BlockIo protocol on ControllerHandle
128 //
129 Status = gBS->OpenProtocol (
130 ControllerHandle,
131 &gEfiBlockIoProtocolGuid,
132 (VOID **)&BlockIo,
133 This->DriverBindingHandle,
134 ControllerHandle,
135 EFI_OPEN_PROTOCOL_GET_PROTOCOL
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 //
140 // Open DiskIo protocol on ControllerHandle
141 //
142 Status = gBS->OpenProtocol (
143 ControllerHandle,
144 &gEfiDiskIoProtocolGuid,
145 (VOID **)&DiskIo,
146 This->DriverBindingHandle,
147 ControllerHandle,
148 EFI_OPEN_PROTOCOL_BY_DRIVER
149 );
150 ASSERT_EFI_ERROR (Status);
151
152 //
153 // Check if ControllerHandle supports an UDF file system
154 //
155 Status = SupportUdfFileSystem (This, ControllerHandle);
156 if (EFI_ERROR (Status)) {
157 goto Exit;
158 }
159
160 //
161 // Initialize private file system structure
162 //
163 PrivFsData =
164 (PRIVATE_UDF_SIMPLE_FS_DATA *)
165 AllocateZeroPool (sizeof (PRIVATE_UDF_SIMPLE_FS_DATA));
166 if (PrivFsData == NULL) {
167 Status = EFI_OUT_OF_RESOURCES;
168 goto Exit;
169 }
170
171 //
172 // Create new child handle
173 //
174 PrivFsData->Signature = PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE;
175 PrivFsData->BlockIo = BlockIo;
176 PrivFsData->DiskIo = DiskIo;
177 PrivFsData->Handle = ControllerHandle;
178
179 //
180 // Set up SimpleFs protocol
181 //
182 CopyMem ((VOID *)&PrivFsData->SimpleFs, (VOID *)&gUdfSimpleFsTemplate,
183 sizeof (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL));
184
185 //
186 // Install child handle
187 //
188 Status = gBS->InstallMultipleProtocolInterfaces (
189 &PrivFsData->Handle,
190 &gEfiSimpleFileSystemProtocolGuid,
191 &PrivFsData->SimpleFs,
192 NULL
193 );
194
195 Exit:
196 if (EFI_ERROR (Status)) {
197 //
198 // Close DiskIo protocol on ControllerHandle
199 //
200 gBS->CloseProtocol (
201 ControllerHandle,
202 &gEfiDiskIoProtocolGuid,
203 This->DriverBindingHandle,
204 ControllerHandle
205 );
206 //
207 // Close BlockIo protocol on ControllerHandle
208 //
209 gBS->CloseProtocol (
210 ControllerHandle,
211 &gEfiBlockIoProtocolGuid,
212 This->DriverBindingHandle,
213 ControllerHandle
214 );
215 }
216
217 gBS->RestoreTPL (OldTpl);
218
219 return Status;
220 }
221
222 /**
223 Stop this driver on ControllerHandle. Support stopping any child handles
224 created by this driver.
225
226 @param This Protocol instance pointer.
227 @param ControllerHandle Handle of device to stop driver on
228 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
229 children is zero stop the entire bus driver.
230 @param ChildHandleBuffer List of Child Handles to Stop.
231
232 @retval EFI_SUCCESS This driver is removed ControllerHandle
233 @retval other This driver was not removed from this device
234
235 **/
236 EFI_STATUS
237 EFIAPI
238 UdfDriverBindingStop (
239 IN EFI_DRIVER_BINDING_PROTOCOL *This,
240 IN EFI_HANDLE ControllerHandle,
241 IN UINTN NumberOfChildren,
242 IN EFI_HANDLE *ChildHandleBuffer
243 )
244 {
245 PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData;
246 EFI_STATUS Status;
247 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs;
248
249 //
250 // Open SimpleFs protocol on ControllerHandle
251 //
252 Status = gBS->OpenProtocol (
253 ControllerHandle,
254 &gEfiSimpleFileSystemProtocolGuid,
255 (VOID **)&SimpleFs,
256 This->DriverBindingHandle,
257 ControllerHandle,
258 EFI_OPEN_PROTOCOL_GET_PROTOCOL
259 );
260 if (!EFI_ERROR (Status)) {
261 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (SimpleFs);
262
263 //
264 // Uninstall child handle
265 //
266 Status = gBS->UninstallMultipleProtocolInterfaces (
267 PrivFsData->Handle,
268 &gEfiSimpleFileSystemProtocolGuid,
269 &PrivFsData->SimpleFs,
270 NULL
271 );
272
273 FreePool ((VOID *)PrivFsData);
274 }
275
276 if (!EFI_ERROR (Status)) {
277 //
278 // Close DiskIo protocol on ControllerHandle
279 //
280 gBS->CloseProtocol (
281 ControllerHandle,
282 &gEfiDiskIoProtocolGuid,
283 This->DriverBindingHandle,
284 ControllerHandle
285 );
286 //
287 // Close BlockIo protocol on ControllerHandle
288 //
289 gBS->CloseProtocol (
290 ControllerHandle,
291 &gEfiBlockIoProtocolGuid,
292 This->DriverBindingHandle,
293 ControllerHandle
294 );
295 }
296
297 return Status;
298 }
299
300 /**
301 The user Entry Point for UDF file system driver. The user code starts with
302 this function.
303
304 @param[in] ImageHandle The firmware allocated handle for the EFI image.
305 @param[in] SystemTable A pointer to the EFI System Table.
306
307 @retval EFI_SUCCESS The entry point is executed successfully.
308 @retval other Some error occurs when executing this entry point.
309
310 **/
311 EFI_STATUS
312 EFIAPI
313 InitializeUdf (
314 IN EFI_HANDLE ImageHandle,
315 IN EFI_SYSTEM_TABLE *SystemTable
316 )
317 {
318 EFI_STATUS Status;
319
320 Status = EfiLibInstallDriverBindingComponentName2 (
321 ImageHandle,
322 SystemTable,
323 &gUdfDriverBinding,
324 ImageHandle,
325 &gUdfComponentName,
326 &gUdfComponentName2
327 );
328 ASSERT_EFI_ERROR (Status);
329
330 return Status;
331 }