]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
MdeModulePkg/PartitionDxe: Add partition type guid to installed handle
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.h
... / ...
CommitLineData
1/** @file\r
2 Partition driver that produces logical BlockIo devices from a physical \r
3 BlockIo device. The logical BlockIo devices are based on the format\r
4 of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy\r
5 MBR, and GPT partition schemes are supported.\r
6\r
7Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.\r
8Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
9This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19#ifndef _PARTITION_H_ \r
20#define _PARTITION_H_ \r
21\r
22#include <Uefi.h>\r
23#include <Protocol/BlockIo.h>\r
24#include <Protocol/BlockIo2.h>\r
25#include <Guid/Gpt.h>\r
26#include <Protocol/ComponentName.h>\r
27#include <Protocol/DevicePath.h>\r
28#include <Protocol/DriverBinding.h>\r
29#include <Protocol/DiskIo.h>\r
30#include <Protocol/DiskIo2.h>\r
31#include <Protocol/PartitionInfo.h>\r
32#include <Library/DebugLib.h>\r
33#include <Library/UefiDriverEntryPoint.h>\r
34#include <Library/BaseLib.h>\r
35#include <Library/UefiLib.h>\r
36#include <Library/BaseMemoryLib.h>\r
37#include <Library/MemoryAllocationLib.h>\r
38#include <Library/UefiBootServicesTableLib.h>\r
39#include <Library/DevicePathLib.h>\r
40\r
41#include <IndustryStandard/Mbr.h>\r
42#include <IndustryStandard/ElTorito.h>\r
43#include <IndustryStandard/Udf.h>\r
44\r
45//\r
46// Partition private data\r
47//\r
48#define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')\r
49typedef struct {\r
50 UINT64 Signature;\r
51\r
52 EFI_HANDLE Handle;\r
53 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
54 EFI_BLOCK_IO_PROTOCOL BlockIo;\r
55 EFI_BLOCK_IO2_PROTOCOL BlockIo2;\r
56 EFI_BLOCK_IO_MEDIA Media;\r
57 EFI_BLOCK_IO_MEDIA Media2;//For BlockIO2\r
58 EFI_PARTITION_INFO_PROTOCOL PartitionInfo;\r
59\r
60 EFI_DISK_IO_PROTOCOL *DiskIo;\r
61 EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
62 EFI_BLOCK_IO_PROTOCOL *ParentBlockIo;\r
63 EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2;\r
64 UINT64 Start;\r
65 UINT64 End;\r
66 UINT32 BlockSize;\r
67 BOOLEAN InStop;\r
68\r
69 EFI_GUID TypeGuid;\r
70\r
71} PARTITION_PRIVATE_DATA;\r
72\r
73typedef struct {\r
74 EFI_DISK_IO2_TOKEN DiskIo2Token;\r
75 EFI_BLOCK_IO2_TOKEN *BlockIo2Token;\r
76} PARTITION_ACCESS_TASK;\r
77\r
78#define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)\r
79#define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)\r
80\r
81//\r
82// Global Variables\r
83//\r
84extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding;\r
85extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName;\r
86extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2;\r
87\r
88//\r
89// Extract INT32 from char array\r
90//\r
91#define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \\r
92 (((UINT8 *) a)[1] << 8) | \\r
93 (((UINT8 *) a)[2] << 16) | \\r
94 (((UINT8 *) a)[3] << 24) )\r
95\r
96//\r
97// Extract UINT32 from char array\r
98//\r
99#define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \\r
100 (((UINT8 *) a)[1] << 8) | \\r
101 (((UINT8 *) a)[2] << 16) | \\r
102 (((UINT8 *) a)[3] << 24) )\r
103\r
104\r
105//\r
106// GPT Partition Entry Status\r
107//\r
108typedef struct {\r
109 BOOLEAN OutOfRange;\r
110 BOOLEAN Overlap;\r
111 BOOLEAN OsSpecific;\r
112} EFI_PARTITION_ENTRY_STATUS;\r
113\r
114//\r
115// Function Prototypes\r
116//\r
117/**\r
118 Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
119 than contains a BlockIo and DiskIo protocol can be supported.\r
120\r
121 @param This Protocol instance pointer.\r
122 @param ControllerHandle Handle of device to test\r
123 @param RemainingDevicePath Optional parameter use to pick a specific child\r
124 device to start.\r
125\r
126 @retval EFI_SUCCESS This driver supports this device\r
127 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
128 @retval other This driver does not support this device\r
129\r
130**/\r
131EFI_STATUS\r
132EFIAPI\r
133PartitionDriverBindingSupported (\r
134 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
135 IN EFI_HANDLE ControllerHandle,\r
136 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
137 );\r
138\r
139/**\r
140 Start this driver on ControllerHandle by opening a Block IO and Disk IO\r
141 protocol, reading Device Path, and creating a child handle with a\r
142 Disk IO and device path protocol.\r
143\r
144 @param This Protocol instance pointer.\r
145 @param ControllerHandle Handle of device to bind driver to\r
146 @param RemainingDevicePath Optional parameter use to pick a specific child\r
147 device to start.\r
148\r
149 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
150 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
151 @retval other This driver does not support this device\r
152\r
153**/\r
154EFI_STATUS\r
155EFIAPI\r
156PartitionDriverBindingStart (\r
157 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
158 IN EFI_HANDLE ControllerHandle,\r
159 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
160 );\r
161\r
162/**\r
163 Stop this driver on ControllerHandle. Support stopping any child handles\r
164 created by this driver.\r
165\r
166 @param This Protocol instance pointer.\r
167 @param ControllerHandle Handle of device to stop driver on\r
168 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
169 children is zero stop the entire bus driver.\r
170 @param ChildHandleBuffer List of Child Handles to Stop.\r
171\r
172 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
173 @retval other This driver was not removed from this device\r
174\r
175**/\r
176EFI_STATUS\r
177EFIAPI\r
178PartitionDriverBindingStop (\r
179 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
180 IN EFI_HANDLE ControllerHandle,\r
181 IN UINTN NumberOfChildren,\r
182 IN EFI_HANDLE *ChildHandleBuffer\r
183 );\r
184\r
185//\r
186// EFI Component Name Functions\r
187//\r
188/**\r
189 Retrieves a Unicode string that is the user readable name of the driver.\r
190\r
191 This function retrieves the user readable name of a driver in the form of a\r
192 Unicode string. If the driver specified by This has a user readable name in\r
193 the language specified by Language, then a pointer to the driver name is\r
194 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
195 by This does not support the language specified by Language,\r
196 then EFI_UNSUPPORTED is returned.\r
197\r
198 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
199 EFI_COMPONENT_NAME_PROTOCOL instance.\r
200\r
201 @param Language[in] A pointer to a Null-terminated ASCII string\r
202 array indicating the language. This is the\r
203 language of the driver name that the caller is\r
204 requesting, and it must match one of the\r
205 languages specified in SupportedLanguages. The\r
206 number of languages supported by a driver is up\r
207 to the driver writer. Language is specified\r
208 in RFC 4646 or ISO 639-2 language code format.\r
209\r
210 @param DriverName[out] A pointer to the Unicode string to return.\r
211 This Unicode string is the name of the\r
212 driver specified by This in the language\r
213 specified by Language.\r
214\r
215 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
216 This and the language specified by Language was\r
217 returned in DriverName.\r
218\r
219 @retval EFI_INVALID_PARAMETER Language is NULL.\r
220\r
221 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
222\r
223 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
224 the language specified by Language.\r
225\r
226**/\r
227EFI_STATUS\r
228EFIAPI\r
229PartitionComponentNameGetDriverName (\r
230 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
231 IN CHAR8 *Language,\r
232 OUT CHAR16 **DriverName\r
233 );\r
234\r
235\r
236/**\r
237 Retrieves a Unicode string that is the user readable name of the controller\r
238 that is being managed by a driver.\r
239\r
240 This function retrieves the user readable name of the controller specified by\r
241 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
242 driver specified by This has a user readable name in the language specified by\r
243 Language, then a pointer to the controller name is returned in ControllerName,\r
244 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
245 managing the controller specified by ControllerHandle and ChildHandle,\r
246 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
247 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
248\r
249 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
250 EFI_COMPONENT_NAME_PROTOCOL instance.\r
251\r
252 @param ControllerHandle[in] The handle of a controller that the driver\r
253 specified by This is managing. This handle\r
254 specifies the controller whose name is to be\r
255 returned.\r
256\r
257 @param ChildHandle[in] The handle of the child controller to retrieve\r
258 the name of. This is an optional parameter that\r
259 may be NULL. It will be NULL for device\r
260 drivers. It will also be NULL for a bus drivers\r
261 that wish to retrieve the name of the bus\r
262 controller. It will not be NULL for a bus\r
263 driver that wishes to retrieve the name of a\r
264 child controller.\r
265\r
266 @param Language[in] A pointer to a Null-terminated ASCII string\r
267 array indicating the language. This is the\r
268 language of the driver name that the caller is\r
269 requesting, and it must match one of the\r
270 languages specified in SupportedLanguages. The\r
271 number of languages supported by a driver is up\r
272 to the driver writer. Language is specified in\r
273 RFC 4646 or ISO 639-2 language code format.\r
274\r
275 @param ControllerName[out] A pointer to the Unicode string to return.\r
276 This Unicode string is the name of the\r
277 controller specified by ControllerHandle and\r
278 ChildHandle in the language specified by\r
279 Language from the point of view of the driver\r
280 specified by This.\r
281\r
282 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
283 the language specified by Language for the\r
284 driver specified by This was returned in\r
285 DriverName.\r
286\r
287 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
288\r
289 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
290 EFI_HANDLE.\r
291\r
292 @retval EFI_INVALID_PARAMETER Language is NULL.\r
293\r
294 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
295\r
296 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
297 managing the controller specified by\r
298 ControllerHandle and ChildHandle.\r
299\r
300 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
301 the language specified by Language.\r
302\r
303**/\r
304EFI_STATUS\r
305EFIAPI\r
306PartitionComponentNameGetControllerName (\r
307 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
308 IN EFI_HANDLE ControllerHandle,\r
309 IN EFI_HANDLE ChildHandle OPTIONAL,\r
310 IN CHAR8 *Language,\r
311 OUT CHAR16 **ControllerName\r
312 );\r
313\r
314\r
315/**\r
316 Create a child handle for a logical block device that represents the\r
317 bytes Start to End of the Parent Block IO device.\r
318\r
319 @param[in] This Protocol instance pointer.\r
320 @param[in] ParentHandle Parent Handle for new child.\r
321 @param[in] ParentDiskIo Parent DiskIo interface.\r
322 @param[in] ParentDiskIo2 Parent DiskIo2 interface.\r
323 @param[in] ParentBlockIo Parent BlockIo interface.\r
324 @param[in] ParentBlockIo2 Parent BlockIo2 interface.\r
325 @param[in] ParentDevicePath Parent Device Path.\r
326 @param[in] DevicePathNode Child Device Path node.\r
327 @param[in] PartitionInfo Child Partition Information interface.\r
328 @param[in] Start Start Block.\r
329 @param[in] End End Block.\r
330 @param[in] BlockSize Child block size.\r
331 @param[in] TypeGuid Parition Type Guid.\r
332\r
333 @retval EFI_SUCCESS A child handle was added.\r
334 @retval other A child handle was not added.\r
335\r
336**/\r
337EFI_STATUS\r
338PartitionInstallChildHandle (\r
339 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
340 IN EFI_HANDLE ParentHandle,\r
341 IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,\r
342 IN EFI_DISK_IO2_PROTOCOL *ParentDiskIo2,\r
343 IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,\r
344 IN EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2,\r
345 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
346 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r
347 IN EFI_PARTITION_INFO_PROTOCOL *PartitionInfo,\r
348 IN EFI_LBA Start,\r
349 IN EFI_LBA End,\r
350 IN UINT32 BlockSize,\r
351 IN EFI_GUID *TypeGuid\r
352 );\r
353\r
354/**\r
355 Test to see if there is any child on ControllerHandle.\r
356\r
357 @param[in] ControllerHandle Handle of device to test.\r
358\r
359 @retval TRUE There are children on the ControllerHandle.\r
360 @retval FALSE No child is on the ControllerHandle.\r
361\r
362**/\r
363BOOLEAN\r
364HasChildren (\r
365 IN EFI_HANDLE ControllerHandle\r
366 );\r
367\r
368/**\r
369 Install child handles if the Handle supports GPT partition structure.\r
370\r
371 @param[in] This Calling context.\r
372 @param[in] Handle Parent Handle.\r
373 @param[in] DiskIo Parent DiskIo interface.\r
374 @param[in] DiskIo2 Parent DiskIo2 interface.\r
375 @param[in] BlockIo Parent BlockIo interface.\r
376 @param[in] BlockIo2 Parent BlockIo2 interface.\r
377 @param[in] DevicePath Parent Device Path.\r
378\r
379 @retval EFI_SUCCESS Valid GPT disk.\r
380 @retval EFI_MEDIA_CHANGED Media changed Detected.\r
381 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;\r
382 @retval other Not a valid GPT disk.\r
383\r
384**/\r
385EFI_STATUS\r
386PartitionInstallGptChildHandles (\r
387 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
388 IN EFI_HANDLE Handle,\r
389 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
390 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
391 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
392 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
393 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
394 );\r
395\r
396/**\r
397 Install child handles if the Handle supports El Torito format.\r
398\r
399 @param[in] This Calling context.\r
400 @param[in] Handle Parent Handle.\r
401 @param[in] DiskIo Parent DiskIo interface.\r
402 @param[in] DiskIo2 Parent DiskIo2 interface.\r
403 @param[in] BlockIo Parent BlockIo interface.\r
404 @param[in] BlockIo2 Parent BlockIo2 interface.\r
405 @param[in] DevicePath Parent Device Path\r
406\r
407\r
408 @retval EFI_SUCCESS Child handle(s) was added.\r
409 @retval EFI_MEDIA_CHANGED Media changed Detected.\r
410 @retval other no child handle was added.\r
411\r
412**/\r
413EFI_STATUS\r
414PartitionInstallElToritoChildHandles (\r
415 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
416 IN EFI_HANDLE Handle,\r
417 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
418 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
419 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
420 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
421 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
422 );\r
423\r
424/**\r
425 Install child handles if the Handle supports MBR format.\r
426\r
427 @param[in] This Calling context.\r
428 @param[in] Handle Parent Handle.\r
429 @param[in] DiskIo Parent DiskIo interface.\r
430 @param[in] DiskIo2 Parent DiskIo2 interface.\r
431 @param[in] BlockIo Parent BlockIo interface.\r
432 @param[in] BlockIo2 Parent BlockIo2 interface.\r
433 @param[in] DevicePath Parent Device Path.\r
434 \r
435 @retval EFI_SUCCESS A child handle was added.\r
436 @retval EFI_MEDIA_CHANGED Media change was detected.\r
437 @retval Others MBR partition was not found.\r
438\r
439**/\r
440EFI_STATUS\r
441PartitionInstallMbrChildHandles (\r
442 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
443 IN EFI_HANDLE Handle,\r
444 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
445 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
446 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
447 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
448 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
449 );\r
450\r
451/**\r
452 Install child handles if the Handle supports UDF/ECMA-167 volume format.\r
453\r
454 @param[in] This Calling context.\r
455 @param[in] Handle Parent Handle.\r
456 @param[in] DiskIo Parent DiskIo interface.\r
457 @param[in] DiskIo2 Parent DiskIo2 interface.\r
458 @param[in] BlockIo Parent BlockIo interface.\r
459 @param[in] BlockIo2 Parent BlockIo2 interface.\r
460 @param[in] DevicePath Parent Device Path\r
461\r
462\r
463 @retval EFI_SUCCESS Child handle(s) was added.\r
464 @retval EFI_MEDIA_CHANGED Media changed Detected.\r
465 @retval other no child handle was added.\r
466\r
467**/\r
468EFI_STATUS\r
469PartitionInstallUdfChildHandles (\r
470 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
471 IN EFI_HANDLE Handle,\r
472 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
473 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
474 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
475 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
476 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
477 );\r
478\r
479typedef\r
480EFI_STATUS\r
481(*PARTITION_DETECT_ROUTINE) (\r
482 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
483 IN EFI_HANDLE Handle,\r
484 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
485 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
486 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
487 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
488 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
489 );\r
490\r
491#endif\r