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", Legacy
5 MBR, and GPT partition schemes are supported.
7 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Protocol/BlockIo.h>
23 #include <Protocol/BlockIo2.h>
25 #include <Protocol/ComponentName.h>
26 #include <Protocol/DevicePath.h>
27 #include <Protocol/DriverBinding.h>
28 #include <Protocol/DiskIo.h>
29 #include <Protocol/DiskIo2.h>
30 #include <Protocol/PartitionInfo.h>
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/BaseLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
40 #include <IndustryStandard/Mbr.h>
41 #include <IndustryStandard/ElTorito.h>
45 // Partition private data
47 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
52 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
53 EFI_BLOCK_IO_PROTOCOL BlockIo
;
54 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
55 EFI_BLOCK_IO_MEDIA Media
;
56 EFI_BLOCK_IO_MEDIA Media2
;//For BlockIO2
57 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
59 EFI_DISK_IO_PROTOCOL
*DiskIo
;
60 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
61 EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
;
62 EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
;
70 } PARTITION_PRIVATE_DATA
;
73 EFI_DISK_IO2_TOKEN DiskIo2Token
;
74 EFI_BLOCK_IO2_TOKEN
*BlockIo2Token
;
75 } PARTITION_ACCESS_TASK
;
77 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
78 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)
83 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding
;
84 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName
;
85 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2
;
88 // Extract INT32 from char array
90 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
91 (((UINT8 *) a)[1] << 8) | \
92 (((UINT8 *) a)[2] << 16) | \
93 (((UINT8 *) a)[3] << 24) )
96 // Extract UINT32 from char array
98 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
99 (((UINT8 *) a)[1] << 8) | \
100 (((UINT8 *) a)[2] << 16) | \
101 (((UINT8 *) a)[3] << 24) )
105 // GPT Partition Entry Status
111 } EFI_PARTITION_ENTRY_STATUS
;
114 // Function Prototypes
117 Test to see if this driver supports ControllerHandle. Any ControllerHandle
118 than contains a BlockIo and DiskIo protocol can be supported.
120 @param This Protocol instance pointer.
121 @param ControllerHandle Handle of device to test
122 @param RemainingDevicePath Optional parameter use to pick a specific child
125 @retval EFI_SUCCESS This driver supports this device
126 @retval EFI_ALREADY_STARTED This driver is already running on this device
127 @retval other This driver does not support this device
132 PartitionDriverBindingSupported (
133 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
134 IN EFI_HANDLE ControllerHandle
,
135 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 Start this driver on ControllerHandle by opening a Block IO and Disk IO
140 protocol, reading Device Path, and creating a child handle with a
141 Disk IO and device path protocol.
143 @param This Protocol instance pointer.
144 @param ControllerHandle Handle of device to bind driver to
145 @param RemainingDevicePath Optional parameter use to pick a specific child
148 @retval EFI_SUCCESS This driver is added to ControllerHandle
149 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
150 @retval other This driver does not support this device
155 PartitionDriverBindingStart (
156 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
157 IN EFI_HANDLE ControllerHandle
,
158 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
162 Stop this driver on ControllerHandle. Support stopping any child handles
163 created by this driver.
165 @param This Protocol instance pointer.
166 @param ControllerHandle Handle of device to stop driver on
167 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
168 children is zero stop the entire bus driver.
169 @param ChildHandleBuffer List of Child Handles to Stop.
171 @retval EFI_SUCCESS This driver is removed ControllerHandle
172 @retval other This driver was not removed from this device
177 PartitionDriverBindingStop (
178 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
179 IN EFI_HANDLE ControllerHandle
,
180 IN UINTN NumberOfChildren
,
181 IN EFI_HANDLE
*ChildHandleBuffer
185 // EFI Component Name Functions
188 Retrieves a Unicode string that is the user readable name of the driver.
190 This function retrieves the user readable name of a driver in the form of a
191 Unicode string. If the driver specified by This has a user readable name in
192 the language specified by Language, then a pointer to the driver name is
193 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
194 by This does not support the language specified by Language,
195 then EFI_UNSUPPORTED is returned.
197 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
198 EFI_COMPONENT_NAME_PROTOCOL instance.
200 @param Language[in] A pointer to a Null-terminated ASCII string
201 array indicating the language. This is the
202 language of the driver name that the caller is
203 requesting, and it must match one of the
204 languages specified in SupportedLanguages. The
205 number of languages supported by a driver is up
206 to the driver writer. Language is specified
207 in RFC 4646 or ISO 639-2 language code format.
209 @param DriverName[out] A pointer to the Unicode string to return.
210 This Unicode string is the name of the
211 driver specified by This in the language
212 specified by Language.
214 @retval EFI_SUCCESS The Unicode string for the Driver specified by
215 This and the language specified by Language was
216 returned in DriverName.
218 @retval EFI_INVALID_PARAMETER Language is NULL.
220 @retval EFI_INVALID_PARAMETER DriverName is NULL.
222 @retval EFI_UNSUPPORTED The driver specified by This does not support
223 the language specified by Language.
228 PartitionComponentNameGetDriverName (
229 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
231 OUT CHAR16
**DriverName
236 Retrieves a Unicode string that is the user readable name of the controller
237 that is being managed by a driver.
239 This function retrieves the user readable name of the controller specified by
240 ControllerHandle and ChildHandle in the form of a Unicode string. If the
241 driver specified by This has a user readable name in the language specified by
242 Language, then a pointer to the controller name is returned in ControllerName,
243 and EFI_SUCCESS is returned. If the driver specified by This is not currently
244 managing the controller specified by ControllerHandle and ChildHandle,
245 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
246 support the language specified by Language, then EFI_UNSUPPORTED is returned.
248 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
249 EFI_COMPONENT_NAME_PROTOCOL instance.
251 @param ControllerHandle[in] The handle of a controller that the driver
252 specified by This is managing. This handle
253 specifies the controller whose name is to be
256 @param ChildHandle[in] The handle of the child controller to retrieve
257 the name of. This is an optional parameter that
258 may be NULL. It will be NULL for device
259 drivers. It will also be NULL for a bus drivers
260 that wish to retrieve the name of the bus
261 controller. It will not be NULL for a bus
262 driver that wishes to retrieve the name of a
265 @param Language[in] A pointer to a Null-terminated ASCII string
266 array indicating the language. This is the
267 language of the driver name that the caller is
268 requesting, and it must match one of the
269 languages specified in SupportedLanguages. The
270 number of languages supported by a driver is up
271 to the driver writer. Language is specified in
272 RFC 4646 or ISO 639-2 language code format.
274 @param ControllerName[out] A pointer to the Unicode string to return.
275 This Unicode string is the name of the
276 controller specified by ControllerHandle and
277 ChildHandle in the language specified by
278 Language from the point of view of the driver
281 @retval EFI_SUCCESS The Unicode string for the user readable name in
282 the language specified by Language for the
283 driver specified by This was returned in
286 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
288 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
291 @retval EFI_INVALID_PARAMETER Language is NULL.
293 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
295 @retval EFI_UNSUPPORTED The driver specified by This is not currently
296 managing the controller specified by
297 ControllerHandle and ChildHandle.
299 @retval EFI_UNSUPPORTED The driver specified by This does not support
300 the language specified by Language.
305 PartitionComponentNameGetControllerName (
306 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
307 IN EFI_HANDLE ControllerHandle
,
308 IN EFI_HANDLE ChildHandle OPTIONAL
,
310 OUT CHAR16
**ControllerName
315 Create a child handle for a logical block device that represents the
316 bytes Start to End of the Parent Block IO device.
318 @param[in] This Protocol instance pointer.
319 @param[in] ParentHandle Parent Handle for new child.
320 @param[in] ParentDiskIo Parent DiskIo interface.
321 @param[in] ParentDiskIo2 Parent DiskIo2 interface.
322 @param[in] ParentBlockIo Parent BlockIo interface.
323 @param[in] ParentBlockIo2 Parent BlockIo2 interface.
324 @param[in] ParentDevicePath Parent Device Path.
325 @param[in] DevicePathNode Child Device Path node.
326 @param[in] PartitionInfo Child Partition Information interface.
327 @param[in] Start Start Block.
328 @param[in] End End Block.
329 @param[in] BlockSize Child block size.
331 @retval EFI_SUCCESS A child handle was added.
332 @retval other A child handle was not added.
336 PartitionInstallChildHandle (
337 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
338 IN EFI_HANDLE ParentHandle
,
339 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
340 IN EFI_DISK_IO2_PROTOCOL
*ParentDiskIo2
,
341 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
342 IN EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
,
343 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
344 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
345 IN EFI_PARTITION_INFO_PROTOCOL
*PartitionInfo
,
352 Test to see if there is any child on ControllerHandle.
354 @param[in] ControllerHandle Handle of device to test.
356 @retval TRUE There are children on the ControllerHandle.
357 @retval FALSE No child is on the ControllerHandle.
362 IN EFI_HANDLE ControllerHandle
366 Install child handles if the Handle supports GPT partition structure.
368 @param[in] This Calling context.
369 @param[in] Handle Parent Handle.
370 @param[in] DiskIo Parent DiskIo interface.
371 @param[in] DiskIo2 Parent DiskIo2 interface.
372 @param[in] BlockIo Parent BlockIo interface.
373 @param[in] BlockIo2 Parent BlockIo2 interface.
374 @param[in] DevicePath Parent Device Path.
376 @retval EFI_SUCCESS Valid GPT disk.
377 @retval EFI_MEDIA_CHANGED Media changed Detected.
378 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;
379 @retval other Not a valid GPT disk.
383 PartitionInstallGptChildHandles (
384 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
385 IN EFI_HANDLE Handle
,
386 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
387 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
388 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
389 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
390 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
394 Install child handles if the Handle supports El Torito format.
396 @param[in] This Calling context.
397 @param[in] Handle Parent Handle.
398 @param[in] DiskIo Parent DiskIo interface.
399 @param[in] DiskIo2 Parent DiskIo2 interface.
400 @param[in] BlockIo Parent BlockIo interface.
401 @param[in] BlockIo2 Parent BlockIo2 interface.
402 @param[in] DevicePath Parent Device Path
405 @retval EFI_SUCCESS Child handle(s) was added.
406 @retval EFI_MEDIA_CHANGED Media changed Detected.
407 @retval other no child handle was added.
411 PartitionInstallElToritoChildHandles (
412 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
413 IN EFI_HANDLE Handle
,
414 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
415 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
416 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
417 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
418 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
422 Install child handles if the Handle supports MBR format.
424 @param[in] This Calling context.
425 @param[in] Handle Parent Handle.
426 @param[in] DiskIo Parent DiskIo interface.
427 @param[in] DiskIo2 Parent DiskIo2 interface.
428 @param[in] BlockIo Parent BlockIo interface.
429 @param[in] BlockIo2 Parent BlockIo2 interface.
430 @param[in] DevicePath Parent Device Path.
432 @retval EFI_SUCCESS A child handle was added.
433 @retval EFI_MEDIA_CHANGED Media change was detected.
434 @retval Others MBR partition was not found.
438 PartitionInstallMbrChildHandles (
439 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
440 IN EFI_HANDLE Handle
,
441 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
442 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
443 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
444 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
445 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
450 (*PARTITION_DETECT_ROUTINE
) (
451 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
452 IN EFI_HANDLE Handle
,
453 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
454 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
455 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
456 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
457 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath