2 Partition driver that produces logical BlockIo devices from a physical
3 BlockIo device. The logical BlockIo devices are based on the format
4 of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy
5 MBR, and GPT partition schemes are supported.
7 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.
8 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include <Protocol/BlockIo.h>
24 #include <Protocol/BlockIo2.h>
26 #include <Protocol/ComponentName.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/DriverBinding.h>
29 #include <Protocol/DiskIo.h>
30 #include <Protocol/DiskIo2.h>
31 #include <Protocol/PartitionInfo.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/BaseLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/DevicePathLib.h>
41 #include <IndustryStandard/Mbr.h>
42 #include <IndustryStandard/ElTorito.h>
43 #include <IndustryStandard/Udf.h>
46 // Partition private data
48 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
53 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
54 EFI_BLOCK_IO_PROTOCOL BlockIo
;
55 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
56 EFI_BLOCK_IO_MEDIA Media
;
57 EFI_BLOCK_IO_MEDIA Media2
;//For BlockIO2
58 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
60 EFI_DISK_IO_PROTOCOL
*DiskIo
;
61 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
62 EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
;
63 EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
;
71 } PARTITION_PRIVATE_DATA
;
74 EFI_DISK_IO2_TOKEN DiskIo2Token
;
75 EFI_BLOCK_IO2_TOKEN
*BlockIo2Token
;
76 } PARTITION_ACCESS_TASK
;
78 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
79 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)
84 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding
;
85 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName
;
86 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2
;
89 // Extract INT32 from char array
91 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
92 (((UINT8 *) a)[1] << 8) | \
93 (((UINT8 *) a)[2] << 16) | \
94 (((UINT8 *) a)[3] << 24) )
97 // Extract UINT32 from char array
99 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
100 (((UINT8 *) a)[1] << 8) | \
101 (((UINT8 *) a)[2] << 16) | \
102 (((UINT8 *) a)[3] << 24) )
106 // GPT Partition Entry Status
112 } EFI_PARTITION_ENTRY_STATUS
;
115 // Function Prototypes
118 Test to see if this driver supports ControllerHandle. Any ControllerHandle
119 than contains a BlockIo and DiskIo protocol can be supported.
121 @param This Protocol instance pointer.
122 @param ControllerHandle Handle of device to test
123 @param RemainingDevicePath Optional parameter use to pick a specific child
126 @retval EFI_SUCCESS This driver supports this device
127 @retval EFI_ALREADY_STARTED This driver is already running on this device
128 @retval other This driver does not support this device
133 PartitionDriverBindingSupported (
134 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
135 IN EFI_HANDLE ControllerHandle
,
136 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
140 Start this driver on ControllerHandle by opening a Block IO and Disk IO
141 protocol, reading Device Path, and creating a child handle with a
142 Disk IO and device path protocol.
144 @param This Protocol instance pointer.
145 @param ControllerHandle Handle of device to bind driver to
146 @param RemainingDevicePath Optional parameter use to pick a specific child
149 @retval EFI_SUCCESS This driver is added to ControllerHandle
150 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
151 @retval other This driver does not support this device
156 PartitionDriverBindingStart (
157 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
158 IN EFI_HANDLE ControllerHandle
,
159 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
163 Stop this driver on ControllerHandle. Support stopping any child handles
164 created by this driver.
166 @param This Protocol instance pointer.
167 @param ControllerHandle Handle of device to stop driver on
168 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
169 children is zero stop the entire bus driver.
170 @param ChildHandleBuffer List of Child Handles to Stop.
172 @retval EFI_SUCCESS This driver is removed ControllerHandle
173 @retval other This driver was not removed from this device
178 PartitionDriverBindingStop (
179 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
180 IN EFI_HANDLE ControllerHandle
,
181 IN UINTN NumberOfChildren
,
182 IN EFI_HANDLE
*ChildHandleBuffer
186 // EFI Component Name Functions
189 Retrieves a Unicode string that is the user readable name of the driver.
191 This function retrieves the user readable name of a driver in the form of a
192 Unicode string. If the driver specified by This has a user readable name in
193 the language specified by Language, then a pointer to the driver name is
194 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
195 by This does not support the language specified by Language,
196 then EFI_UNSUPPORTED is returned.
198 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
199 EFI_COMPONENT_NAME_PROTOCOL instance.
201 @param Language[in] A pointer to a Null-terminated ASCII string
202 array indicating the language. This is the
203 language of the driver name that the caller is
204 requesting, and it must match one of the
205 languages specified in SupportedLanguages. The
206 number of languages supported by a driver is up
207 to the driver writer. Language is specified
208 in RFC 4646 or ISO 639-2 language code format.
210 @param DriverName[out] A pointer to the Unicode string to return.
211 This Unicode string is the name of the
212 driver specified by This in the language
213 specified by Language.
215 @retval EFI_SUCCESS The Unicode string for the Driver specified by
216 This and the language specified by Language was
217 returned in DriverName.
219 @retval EFI_INVALID_PARAMETER Language is NULL.
221 @retval EFI_INVALID_PARAMETER DriverName is NULL.
223 @retval EFI_UNSUPPORTED The driver specified by This does not support
224 the language specified by Language.
229 PartitionComponentNameGetDriverName (
230 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
232 OUT CHAR16
**DriverName
237 Retrieves a Unicode string that is the user readable name of the controller
238 that is being managed by a driver.
240 This function retrieves the user readable name of the controller specified by
241 ControllerHandle and ChildHandle in the form of a Unicode string. If the
242 driver specified by This has a user readable name in the language specified by
243 Language, then a pointer to the controller name is returned in ControllerName,
244 and EFI_SUCCESS is returned. If the driver specified by This is not currently
245 managing the controller specified by ControllerHandle and ChildHandle,
246 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
247 support the language specified by Language, then EFI_UNSUPPORTED is returned.
249 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
250 EFI_COMPONENT_NAME_PROTOCOL instance.
252 @param ControllerHandle[in] The handle of a controller that the driver
253 specified by This is managing. This handle
254 specifies the controller whose name is to be
257 @param ChildHandle[in] The handle of the child controller to retrieve
258 the name of. This is an optional parameter that
259 may be NULL. It will be NULL for device
260 drivers. It will also be NULL for a bus drivers
261 that wish to retrieve the name of the bus
262 controller. It will not be NULL for a bus
263 driver that wishes to retrieve the name of a
266 @param Language[in] A pointer to a Null-terminated ASCII string
267 array indicating the language. This is the
268 language of the driver name that the caller is
269 requesting, and it must match one of the
270 languages specified in SupportedLanguages. The
271 number of languages supported by a driver is up
272 to the driver writer. Language is specified in
273 RFC 4646 or ISO 639-2 language code format.
275 @param ControllerName[out] A pointer to the Unicode string to return.
276 This Unicode string is the name of the
277 controller specified by ControllerHandle and
278 ChildHandle in the language specified by
279 Language from the point of view of the driver
282 @retval EFI_SUCCESS The Unicode string for the user readable name in
283 the language specified by Language for the
284 driver specified by This was returned in
287 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
289 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
292 @retval EFI_INVALID_PARAMETER Language is NULL.
294 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
296 @retval EFI_UNSUPPORTED The driver specified by This is not currently
297 managing the controller specified by
298 ControllerHandle and ChildHandle.
300 @retval EFI_UNSUPPORTED The driver specified by This does not support
301 the language specified by Language.
306 PartitionComponentNameGetControllerName (
307 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
308 IN EFI_HANDLE ControllerHandle
,
309 IN EFI_HANDLE ChildHandle OPTIONAL
,
311 OUT CHAR16
**ControllerName
316 Create a child handle for a logical block device that represents the
317 bytes Start to End of the Parent Block IO device.
319 @param[in] This Protocol instance pointer.
320 @param[in] ParentHandle Parent Handle for new child.
321 @param[in] ParentDiskIo Parent DiskIo interface.
322 @param[in] ParentDiskIo2 Parent DiskIo2 interface.
323 @param[in] ParentBlockIo Parent BlockIo interface.
324 @param[in] ParentBlockIo2 Parent BlockIo2 interface.
325 @param[in] ParentDevicePath Parent Device Path.
326 @param[in] DevicePathNode Child Device Path node.
327 @param[in] PartitionInfo Child Partition Information interface.
328 @param[in] Start Start Block.
329 @param[in] End End Block.
330 @param[in] BlockSize Child block size.
331 @param[in] TypeGuid Parition Type Guid.
333 @retval EFI_SUCCESS A child handle was added.
334 @retval other A child handle was not added.
338 PartitionInstallChildHandle (
339 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
340 IN EFI_HANDLE ParentHandle
,
341 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
342 IN EFI_DISK_IO2_PROTOCOL
*ParentDiskIo2
,
343 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
344 IN EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
,
345 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
346 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
347 IN EFI_PARTITION_INFO_PROTOCOL
*PartitionInfo
,
351 IN EFI_GUID
*TypeGuid
355 Test to see if there is any child on ControllerHandle.
357 @param[in] ControllerHandle Handle of device to test.
359 @retval TRUE There are children on the ControllerHandle.
360 @retval FALSE No child is on the ControllerHandle.
365 IN EFI_HANDLE ControllerHandle
369 Install child handles if the Handle supports GPT partition structure.
371 @param[in] This Calling context.
372 @param[in] Handle Parent Handle.
373 @param[in] DiskIo Parent DiskIo interface.
374 @param[in] DiskIo2 Parent DiskIo2 interface.
375 @param[in] BlockIo Parent BlockIo interface.
376 @param[in] BlockIo2 Parent BlockIo2 interface.
377 @param[in] DevicePath Parent Device Path.
379 @retval EFI_SUCCESS Valid GPT disk.
380 @retval EFI_MEDIA_CHANGED Media changed Detected.
381 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;
382 @retval other Not a valid GPT disk.
386 PartitionInstallGptChildHandles (
387 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
388 IN EFI_HANDLE Handle
,
389 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
390 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
391 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
392 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
393 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
397 Install child handles if the Handle supports El Torito format.
399 @param[in] This Calling context.
400 @param[in] Handle Parent Handle.
401 @param[in] DiskIo Parent DiskIo interface.
402 @param[in] DiskIo2 Parent DiskIo2 interface.
403 @param[in] BlockIo Parent BlockIo interface.
404 @param[in] BlockIo2 Parent BlockIo2 interface.
405 @param[in] DevicePath Parent Device Path
408 @retval EFI_SUCCESS Child handle(s) was added.
409 @retval EFI_MEDIA_CHANGED Media changed Detected.
410 @retval other no child handle was added.
414 PartitionInstallElToritoChildHandles (
415 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
416 IN EFI_HANDLE Handle
,
417 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
418 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
419 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
420 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
421 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
425 Install child handles if the Handle supports MBR format.
427 @param[in] This Calling context.
428 @param[in] Handle Parent Handle.
429 @param[in] DiskIo Parent DiskIo interface.
430 @param[in] DiskIo2 Parent DiskIo2 interface.
431 @param[in] BlockIo Parent BlockIo interface.
432 @param[in] BlockIo2 Parent BlockIo2 interface.
433 @param[in] DevicePath Parent Device Path.
435 @retval EFI_SUCCESS A child handle was added.
436 @retval EFI_MEDIA_CHANGED Media change was detected.
437 @retval Others MBR partition was not found.
441 PartitionInstallMbrChildHandles (
442 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
443 IN EFI_HANDLE Handle
,
444 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
445 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
446 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
447 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
448 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
452 Install child handles if the Handle supports UDF/ECMA-167 volume format.
454 @param[in] This Calling context.
455 @param[in] Handle Parent Handle.
456 @param[in] DiskIo Parent DiskIo interface.
457 @param[in] DiskIo2 Parent DiskIo2 interface.
458 @param[in] BlockIo Parent BlockIo interface.
459 @param[in] BlockIo2 Parent BlockIo2 interface.
460 @param[in] DevicePath Parent Device Path
463 @retval EFI_SUCCESS Child handle(s) was added.
464 @retval EFI_MEDIA_CHANGED Media changed Detected.
465 @retval other no child handle was added.
469 PartitionInstallUdfChildHandles (
470 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
471 IN EFI_HANDLE Handle
,
472 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
473 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
474 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
475 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
476 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
481 (*PARTITION_DETECT_ROUTINE
) (
482 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
483 IN EFI_HANDLE Handle
,
484 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
485 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
486 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
487 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
488 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath