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