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