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 - 2011, 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 <Library/DebugLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/BaseLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/DevicePathLib.h>
39 #include <IndustryStandard/Mbr.h>
40 #include <IndustryStandard/ElTorito.h>
44 // Partition private data
46 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
51 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
52 EFI_BLOCK_IO_PROTOCOL BlockIo
;
53 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
54 EFI_BLOCK_IO_MEDIA Media
;
55 EFI_BLOCK_IO_MEDIA Media2
;//For BlockIO2
57 EFI_DISK_IO_PROTOCOL
*DiskIo
;
58 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
59 EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
;
60 EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
;
68 } PARTITION_PRIVATE_DATA
;
71 EFI_DISK_IO2_TOKEN DiskIo2Token
;
72 EFI_BLOCK_IO2_TOKEN
*BlockIo2Token
;
73 } PARTITION_ACCESS_TASK
;
75 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
76 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)
81 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding
;
82 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName
;
83 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2
;
86 // Extract INT32 from char array
88 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
89 (((UINT8 *) a)[1] << 8) | \
90 (((UINT8 *) a)[2] << 16) | \
91 (((UINT8 *) a)[3] << 24) )
94 // Extract UINT32 from char array
96 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
97 (((UINT8 *) a)[1] << 8) | \
98 (((UINT8 *) a)[2] << 16) | \
99 (((UINT8 *) a)[3] << 24) )
103 // GPT Partition Entry Status
109 } EFI_PARTITION_ENTRY_STATUS
;
112 // Function Prototypes
115 Test to see if this driver supports ControllerHandle. Any ControllerHandle
116 than contains a BlockIo and DiskIo protocol can be supported.
118 @param This Protocol instance pointer.
119 @param ControllerHandle Handle of device to test
120 @param RemainingDevicePath Optional parameter use to pick a specific child
123 @retval EFI_SUCCESS This driver supports this device
124 @retval EFI_ALREADY_STARTED This driver is already running on this device
125 @retval other This driver does not support this device
130 PartitionDriverBindingSupported (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE ControllerHandle
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 Start this driver on ControllerHandle by opening a Block IO and Disk IO
138 protocol, reading Device Path, and creating a child handle with a
139 Disk IO and device path protocol.
141 @param This Protocol instance pointer.
142 @param ControllerHandle Handle of device to bind driver to
143 @param RemainingDevicePath Optional parameter use to pick a specific child
146 @retval EFI_SUCCESS This driver is added to ControllerHandle
147 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
148 @retval other This driver does not support this device
153 PartitionDriverBindingStart (
154 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
155 IN EFI_HANDLE ControllerHandle
,
156 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
160 Stop this driver on ControllerHandle. Support stopping any child handles
161 created by this driver.
163 @param This Protocol instance pointer.
164 @param ControllerHandle Handle of device to stop driver on
165 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
166 children is zero stop the entire bus driver.
167 @param ChildHandleBuffer List of Child Handles to Stop.
169 @retval EFI_SUCCESS This driver is removed ControllerHandle
170 @retval other This driver was not removed from this device
175 PartitionDriverBindingStop (
176 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
177 IN EFI_HANDLE ControllerHandle
,
178 IN UINTN NumberOfChildren
,
179 IN EFI_HANDLE
*ChildHandleBuffer
183 // EFI Component Name Functions
186 Retrieves a Unicode string that is the user readable name of the driver.
188 This function retrieves the user readable name of a driver in the form of a
189 Unicode string. If the driver specified by This has a user readable name in
190 the language specified by Language, then a pointer to the driver name is
191 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
192 by This does not support the language specified by Language,
193 then EFI_UNSUPPORTED is returned.
195 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
196 EFI_COMPONENT_NAME_PROTOCOL instance.
198 @param Language[in] A pointer to a Null-terminated ASCII string
199 array indicating the language. This is the
200 language of the driver name that the caller is
201 requesting, and it must match one of the
202 languages specified in SupportedLanguages. The
203 number of languages supported by a driver is up
204 to the driver writer. Language is specified
205 in RFC 4646 or ISO 639-2 language code format.
207 @param DriverName[out] A pointer to the Unicode string to return.
208 This Unicode string is the name of the
209 driver specified by This in the language
210 specified by Language.
212 @retval EFI_SUCCESS The Unicode string for the Driver specified by
213 This and the language specified by Language was
214 returned in DriverName.
216 @retval EFI_INVALID_PARAMETER Language is NULL.
218 @retval EFI_INVALID_PARAMETER DriverName is NULL.
220 @retval EFI_UNSUPPORTED The driver specified by This does not support
221 the language specified by Language.
226 PartitionComponentNameGetDriverName (
227 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
229 OUT CHAR16
**DriverName
234 Retrieves a Unicode string that is the user readable name of the controller
235 that is being managed by a driver.
237 This function retrieves the user readable name of the controller specified by
238 ControllerHandle and ChildHandle in the form of a Unicode string. If the
239 driver specified by This has a user readable name in the language specified by
240 Language, then a pointer to the controller name is returned in ControllerName,
241 and EFI_SUCCESS is returned. If the driver specified by This is not currently
242 managing the controller specified by ControllerHandle and ChildHandle,
243 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
244 support the language specified by Language, then EFI_UNSUPPORTED is returned.
246 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
247 EFI_COMPONENT_NAME_PROTOCOL instance.
249 @param ControllerHandle[in] The handle of a controller that the driver
250 specified by This is managing. This handle
251 specifies the controller whose name is to be
254 @param ChildHandle[in] The handle of the child controller to retrieve
255 the name of. This is an optional parameter that
256 may be NULL. It will be NULL for device
257 drivers. It will also be NULL for a bus drivers
258 that wish to retrieve the name of the bus
259 controller. It will not be NULL for a bus
260 driver that wishes to retrieve the name of a
263 @param Language[in] A pointer to a Null-terminated ASCII string
264 array indicating the language. This is the
265 language of the driver name that the caller is
266 requesting, and it must match one of the
267 languages specified in SupportedLanguages. The
268 number of languages supported by a driver is up
269 to the driver writer. Language is specified in
270 RFC 4646 or ISO 639-2 language code format.
272 @param ControllerName[out] A pointer to the Unicode string to return.
273 This Unicode string is the name of the
274 controller specified by ControllerHandle and
275 ChildHandle in the language specified by
276 Language from the point of view of the driver
279 @retval EFI_SUCCESS The Unicode string for the user readable name in
280 the language specified by Language for the
281 driver specified by This was returned in
284 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
286 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
289 @retval EFI_INVALID_PARAMETER Language is NULL.
291 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
293 @retval EFI_UNSUPPORTED The driver specified by This is not currently
294 managing the controller specified by
295 ControllerHandle and ChildHandle.
297 @retval EFI_UNSUPPORTED The driver specified by This does not support
298 the language specified by Language.
303 PartitionComponentNameGetControllerName (
304 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
305 IN EFI_HANDLE ControllerHandle
,
306 IN EFI_HANDLE ChildHandle OPTIONAL
,
308 OUT CHAR16
**ControllerName
313 Create a child handle for a logical block device that represents the
314 bytes Start to End of the Parent Block IO device.
316 @param[in] This Protocol instance pointer.
317 @param[in] ParentHandle Parent Handle for new child.
318 @param[in] ParentDiskIo Parent DiskIo interface.
319 @param[in] ParentDiskIo2 Parent DiskIo2 interface.
320 @param[in] ParentBlockIo Parent BlockIo interface.
321 @param[in] ParentBlockIo2 Parent BlockIo2 interface.
322 @param[in] ParentDevicePath Parent Device Path.
323 @param[in] DevicePathNode Child Device Path node.
324 @param[in] Start Start Block.
325 @param[in] End End Block.
326 @param[in] BlockSize Child block size.
327 @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle.
329 @retval EFI_SUCCESS A child handle was added.
330 @retval other A child handle was not added.
334 PartitionInstallChildHandle (
335 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
336 IN EFI_HANDLE ParentHandle
,
337 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
338 IN EFI_DISK_IO2_PROTOCOL
*ParentDiskIo2
,
339 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
340 IN EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
,
341 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
342 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
346 IN BOOLEAN InstallEspGuid
350 Test to see if there is any child on ControllerHandle.
352 @param[in] ControllerHandle Handle of device to test.
354 @retval TRUE There are children on the ControllerHandle.
355 @retval FALSE No child is on the ControllerHandle.
360 IN EFI_HANDLE ControllerHandle
364 Install child handles if the Handle supports GPT partition structure.
366 @param[in] This Calling context.
367 @param[in] Handle Parent Handle.
368 @param[in] DiskIo Parent DiskIo interface.
369 @param[in] DiskIo2 Parent DiskIo2 interface.
370 @param[in] BlockIo Parent BlockIo interface.
371 @param[in] BlockIo2 Parent BlockIo2 interface.
372 @param[in] DevicePath Parent Device Path.
374 @retval EFI_SUCCESS Valid GPT disk.
375 @retval EFI_MEDIA_CHANGED Media changed Detected.
376 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;
377 @retval other Not a valid GPT disk.
381 PartitionInstallGptChildHandles (
382 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
383 IN EFI_HANDLE Handle
,
384 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
385 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
386 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
387 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
388 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
392 Install child handles if the Handle supports El Torito format.
394 @param[in] This Calling context.
395 @param[in] Handle Parent Handle.
396 @param[in] DiskIo Parent DiskIo interface.
397 @param[in] DiskIo2 Parent DiskIo2 interface.
398 @param[in] BlockIo Parent BlockIo interface.
399 @param[in] BlockIo2 Parent BlockIo2 interface.
400 @param[in] DevicePath Parent Device Path
403 @retval EFI_SUCCESS Child handle(s) was added.
404 @retval EFI_MEDIA_CHANGED Media changed Detected.
405 @retval other no child handle was added.
409 PartitionInstallElToritoChildHandles (
410 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
411 IN EFI_HANDLE Handle
,
412 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
413 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
414 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
415 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
416 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
420 Install child handles if the Handle supports MBR format.
422 @param[in] This Calling context.
423 @param[in] Handle Parent Handle.
424 @param[in] DiskIo Parent DiskIo interface.
425 @param[in] DiskIo2 Parent DiskIo2 interface.
426 @param[in] BlockIo Parent BlockIo interface.
427 @param[in] BlockIo2 Parent BlockIo2 interface.
428 @param[in] DevicePath Parent Device Path.
430 @retval EFI_SUCCESS A child handle was added.
431 @retval EFI_MEDIA_CHANGED Media change was detected.
432 @retval Others MBR partition was not found.
436 PartitionInstallMbrChildHandles (
437 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
438 IN EFI_HANDLE Handle
,
439 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
440 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
441 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
442 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
443 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
448 (*PARTITION_DETECT_ROUTINE
) (
449 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
450 IN EFI_HANDLE Handle
,
451 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
452 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
453 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
454 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
455 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath