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 <Library/DebugLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/BaseLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/DevicePathLib.h>
38 #include <IndustryStandard/Mbr.h>
39 #include <IndustryStandard/ElTorito.h>
43 // Partition private data
45 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
50 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
51 EFI_BLOCK_IO_PROTOCOL BlockIo
;
52 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
53 EFI_BLOCK_IO_MEDIA Media
;
54 EFI_BLOCK_IO_MEDIA Media2
;//For BlockIO2
56 EFI_DISK_IO_PROTOCOL
*DiskIo
;
57 EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
;
58 EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
;
65 } PARTITION_PRIVATE_DATA
;
67 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
68 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)
73 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding
;
74 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName
;
75 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2
;
78 // Extract INT32 from char array
80 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
81 (((UINT8 *) a)[1] << 8) | \
82 (((UINT8 *) a)[2] << 16) | \
83 (((UINT8 *) a)[3] << 24) )
86 // Extract UINT32 from char array
88 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
89 (((UINT8 *) a)[1] << 8) | \
90 (((UINT8 *) a)[2] << 16) | \
91 (((UINT8 *) a)[3] << 24) )
95 // GPT Partition Entry Status
101 } EFI_PARTITION_ENTRY_STATUS
;
104 // Function Prototypes
107 Test to see if this driver supports ControllerHandle. Any ControllerHandle
108 than contains a BlockIo and DiskIo protocol can be supported.
110 @param This Protocol instance pointer.
111 @param ControllerHandle Handle of device to test
112 @param RemainingDevicePath Optional parameter use to pick a specific child
115 @retval EFI_SUCCESS This driver supports this device
116 @retval EFI_ALREADY_STARTED This driver is already running on this device
117 @retval other This driver does not support this device
122 PartitionDriverBindingSupported (
123 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
124 IN EFI_HANDLE ControllerHandle
,
125 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
129 Start this driver on ControllerHandle by opening a Block IO and Disk IO
130 protocol, reading Device Path, and creating a child handle with a
131 Disk IO and device path protocol.
133 @param This Protocol instance pointer.
134 @param ControllerHandle Handle of device to bind driver to
135 @param RemainingDevicePath Optional parameter use to pick a specific child
138 @retval EFI_SUCCESS This driver is added to ControllerHandle
139 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
140 @retval other This driver does not support this device
145 PartitionDriverBindingStart (
146 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
147 IN EFI_HANDLE ControllerHandle
,
148 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
152 Stop this driver on ControllerHandle. Support stopping any child handles
153 created by this driver.
155 @param This Protocol instance pointer.
156 @param ControllerHandle Handle of device to stop driver on
157 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
158 children is zero stop the entire bus driver.
159 @param ChildHandleBuffer List of Child Handles to Stop.
161 @retval EFI_SUCCESS This driver is removed ControllerHandle
162 @retval other This driver was not removed from this device
167 PartitionDriverBindingStop (
168 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
169 IN EFI_HANDLE ControllerHandle
,
170 IN UINTN NumberOfChildren
,
171 IN EFI_HANDLE
*ChildHandleBuffer
175 // EFI Component Name Functions
178 Retrieves a Unicode string that is the user readable name of the driver.
180 This function retrieves the user readable name of a driver in the form of a
181 Unicode string. If the driver specified by This has a user readable name in
182 the language specified by Language, then a pointer to the driver name is
183 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
184 by This does not support the language specified by Language,
185 then EFI_UNSUPPORTED is returned.
187 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
188 EFI_COMPONENT_NAME_PROTOCOL instance.
190 @param Language[in] A pointer to a Null-terminated ASCII string
191 array indicating the language. This is the
192 language of the driver name that the caller is
193 requesting, and it must match one of the
194 languages specified in SupportedLanguages. The
195 number of languages supported by a driver is up
196 to the driver writer. Language is specified
197 in RFC 4646 or ISO 639-2 language code format.
199 @param DriverName[out] A pointer to the Unicode string to return.
200 This Unicode string is the name of the
201 driver specified by This in the language
202 specified by Language.
204 @retval EFI_SUCCESS The Unicode string for the Driver specified by
205 This and the language specified by Language was
206 returned in DriverName.
208 @retval EFI_INVALID_PARAMETER Language is NULL.
210 @retval EFI_INVALID_PARAMETER DriverName is NULL.
212 @retval EFI_UNSUPPORTED The driver specified by This does not support
213 the language specified by Language.
218 PartitionComponentNameGetDriverName (
219 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
221 OUT CHAR16
**DriverName
226 Retrieves a Unicode string that is the user readable name of the controller
227 that is being managed by a driver.
229 This function retrieves the user readable name of the controller specified by
230 ControllerHandle and ChildHandle in the form of a Unicode string. If the
231 driver specified by This has a user readable name in the language specified by
232 Language, then a pointer to the controller name is returned in ControllerName,
233 and EFI_SUCCESS is returned. If the driver specified by This is not currently
234 managing the controller specified by ControllerHandle and ChildHandle,
235 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
236 support the language specified by Language, then EFI_UNSUPPORTED is returned.
238 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
239 EFI_COMPONENT_NAME_PROTOCOL instance.
241 @param ControllerHandle[in] The handle of a controller that the driver
242 specified by This is managing. This handle
243 specifies the controller whose name is to be
246 @param ChildHandle[in] The handle of the child controller to retrieve
247 the name of. This is an optional parameter that
248 may be NULL. It will be NULL for device
249 drivers. It will also be NULL for a bus drivers
250 that wish to retrieve the name of the bus
251 controller. It will not be NULL for a bus
252 driver that wishes to retrieve the name of a
255 @param Language[in] A pointer to a Null-terminated ASCII string
256 array indicating the language. This is the
257 language of the driver name that the caller is
258 requesting, and it must match one of the
259 languages specified in SupportedLanguages. The
260 number of languages supported by a driver is up
261 to the driver writer. Language is specified in
262 RFC 4646 or ISO 639-2 language code format.
264 @param ControllerName[out] A pointer to the Unicode string to return.
265 This Unicode string is the name of the
266 controller specified by ControllerHandle and
267 ChildHandle in the language specified by
268 Language from the point of view of the driver
271 @retval EFI_SUCCESS The Unicode string for the user readable name in
272 the language specified by Language for the
273 driver specified by This was returned in
276 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
278 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
281 @retval EFI_INVALID_PARAMETER Language is NULL.
283 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
285 @retval EFI_UNSUPPORTED The driver specified by This is not currently
286 managing the controller specified by
287 ControllerHandle and ChildHandle.
289 @retval EFI_UNSUPPORTED The driver specified by This does not support
290 the language specified by Language.
295 PartitionComponentNameGetControllerName (
296 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
297 IN EFI_HANDLE ControllerHandle
,
298 IN EFI_HANDLE ChildHandle OPTIONAL
,
300 OUT CHAR16
**ControllerName
305 Create a child handle for a logical block device that represents the
306 bytes Start to End of the Parent Block IO device.
308 @param[in] This Protocol instance pointer.
309 @param[in] ParentHandle Parent Handle for new child.
310 @param[in] ParentDiskIo Parent DiskIo interface.
311 @param[in] ParentBlockIo Parent BlockIo interface.
312 @param[in] ParentBlockIo2 Parent BlockIo2 interface.
313 @param[in] ParentDevicePath Parent Device Path.
314 @param[in] DevicePathNode Child Device Path node.
315 @param[in] Start Start Block.
316 @param[in] End End Block.
317 @param[in] BlockSize Child block size.
318 @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle.
320 @retval EFI_SUCCESS A child handle was added.
321 @retval other A child handle was not added.
325 PartitionInstallChildHandle (
326 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
327 IN EFI_HANDLE ParentHandle
,
328 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
329 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
330 IN EFI_BLOCK_IO2_PROTOCOL
*ParentBlockIo2
,
331 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
332 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
336 IN BOOLEAN InstallEspGuid
340 Install child handles if the Handle supports GPT partition structure.
342 @param[in] This Calling context.
343 @param[in] Handle Parent Handle.
344 @param[in] DiskIo Parent DiskIo interface.
345 @param[in] BlockIo Parent BlockIo interface.
346 @param[in] BlockIo2 Parent BlockIo2 interface.
347 @param[in] DevicePath Parent Device Path.
349 @retval EFI_SUCCESS Valid GPT disk.
350 @retval EFI_MEDIA_CHANGED Media changed Detected.
351 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;
352 @retval other Not a valid GPT disk.
356 PartitionInstallGptChildHandles (
357 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
358 IN EFI_HANDLE Handle
,
359 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
360 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
361 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
362 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
366 Install child handles if the Handle supports El Torito format.
368 @param[in] This Calling context.
369 @param[in] Handle Parent Handle.
370 @param[in] DiskIo Parent DiskIo interface.
371 @param[in] BlockIo Parent BlockIo interface.
372 @param[in] BlockIo2 Parent BlockIo2 interface.
373 @param[in] DevicePath Parent Device Path
376 @retval EFI_SUCCESS Child handle(s) was added.
377 @retval EFI_MEDIA_CHANGED Media changed Detected.
378 @retval other no child handle was added.
382 PartitionInstallElToritoChildHandles (
383 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
384 IN EFI_HANDLE Handle
,
385 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
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 MBR format.
394 @param[in] This Calling context.
395 @param[in] Handle Parent Handle.
396 @param[in] DiskIo Parent DiskIo interface.
397 @param[in] BlockIo Parent BlockIo interface.
398 @param[in] BlockIo2 Parent BlockIo2 interface.
399 @param[in] DevicePath Parent Device Path.
401 @retval EFI_SUCCESS A child handle was added.
402 @retval EFI_MEDIA_CHANGED Media change was detected.
403 @retval Others MBR partition was not found.
407 PartitionInstallMbrChildHandles (
408 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
409 IN EFI_HANDLE Handle
,
410 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
411 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
412 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
413 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
418 (*PARTITION_DETECT_ROUTINE
) (
419 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
420 IN EFI_HANDLE Handle
,
421 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
422 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
423 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
424 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath