Partition API
-
constchar*disk_partition_type_guid(conststructdisk_partition*info)
get partition type GUID
Parameters
const struct disk_partition *info
partition information
Description
By using this function to get the partition type GUID we can use ‘if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))’ instead of ‘#ifdef CONFIG_PARTITION_TYPE_GUID’.
Return
partition type GUID
-
voiddisk_partition_set_type_guid(structdisk_partition*info, constchar*val)
set partition type GUID
Parameters
struct disk_partition *info
partition information
const char *val
partition type GUID as string
Description
By using this function to set the partition type GUID we can use ‘if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))’ instead of ‘#ifdef CONFIG_PARTITION_TYPE_GUID’.
-
structblk_desc*blk_get_dev(constchar*ifname, intdev)
get a pointer to a block device given its type and number
Parameters
const char *ifname
Interface name (e.g. "ide", "scsi")
int dev
Device number (0 for first device on that interface, 1 for second, etc.
Description
Each interface allocates its own devices and typically struct blk_desc is contained with the interface’s data structure. There is no global numbering for block devices, so the interface name must be provided.
Return
pointer to the block device, or NULL if not available, or an error occurred.
-
intpart_get_info_by_type(structblk_desc*desc, intpart, intpart_type, structdisk_partition*info)
Get partitions from a block device using a specific partition driver
Parameters
struct blk_desc *desc
Block device descriptor
int part
Partition number to read
int part_type
Partition driver to use, or PART_TYPE_UNKNOWN to automatically choose a driver
struct disk_partition *info
Returned partition information
Description
Each interface allocates its own devices and typically struct blk_desc is contained with the interface’s data structure. There is no global numbering for block devices, so the interface name must be provided.
Return
0 on success, negative errno on failure
-
intpart_get_info_whole_disk(structblk_desc*desc, structdisk_partition*info)
get partition info for the special case of a partition occupying the entire disk.
Parameters
struct blk_desc *desc
block device descriptor
struct disk_partition *info
returned partition information
Return
0 on success
-
intblk_get_device_by_str(constchar*ifname, constchar*dev_str, structblk_desc**desc)
Get a block device given its interface/hw partition
Parameters
const char *ifname
Interface name (e.g. "ide", "scsi")
const char *dev_str
Device and optional hw partition. This can either be a string containing the device number (e.g. "2") or the device number and hardware partition number (e.g. "2.4") for devices that support it (currently only MMC).
struct blk_desc **desc
Returns a pointer to the block device on success
Description
Each interface allocates its own devices and typically struct blk_desc is contained with the interface’s data structure. There is no global numbering for block devices, so the interface name must be provided.
The hardware parition is not related to the normal software partitioning of a device - each hardware partition is effectively a separately accessible block device. When a hardware parition is selected on MMC the other hardware partitions become inaccessible. The same block device is used to access all hardware partitions, but its capacity may change when a different hardware partition is selected.
When a hardware partition number is given, the block device switches to that hardware partition.
Return
block device number (local to the interface), or -1 on error
-
intblk_get_device_part_str(constchar*ifname, constchar*dev_part_str, structblk_desc**desc, structdisk_partition*info, intallow_whole_dev)
Get a block device and partition
Parameters
const char *ifname
Interface name (e.g. "ide", "scsi")
const char *dev_part_str
Device and partition string
struct blk_desc **desc
Returns a pointer to the block device on success
struct disk_partition *info
Returns partition information
int allow_whole_dev
true to allow the user to select partition 0 (which means the whole device), false to require a valid partition number >= 1
Description
This calls blk_get_device_by_str() to look up a device. It also looks up a partition and returns information about it.
dev_part_str is in the format <dev>.<hw_part>:<part> where
<dev> is the device number,
<hw_part> is the optional hardware partition number and
<part> is the partition number.
If ifname is "hostfs", then this function returns the sandbox host block device.
If ifname is "ubi", then this function returns 0, with info set to a special UBI device.
If dev_part_str is NULL or empty or "-", then this function looks up the "bootdevice" environment variable and uses that string instead.
If the partition string is empty then the first partition is used. If the partition string is "auto" then the first bootable partition is used.
Return
partition number, or -1 on error
-
intpart_get_info_by_name(structblk_desc*desc, constchar*name, structdisk_partition*info)
Search for a partition by name among all available registered partitions
Parameters
struct blk_desc *desc
block device descriptor
const char *name
the specified table entry name
struct disk_partition *info
returns the disk partition info
Return
the partition number on match (starting on 1), -1 on no match, otherwise error
-
intpart_get_info_by_dev_and_name_or_num(constchar*dev_iface, constchar*dev_part_str, structblk_desc**desc, structdisk_partition*part_info, intallow_whole_dev)
Get partition info from dev number and part name, or dev number and part number.
Parameters
const char *dev_iface
Device interface
const char *dev_part_str
Input partition description, like "0#misc" or "0:1"
struct blk_desc **desc
Place to store the device description pointer
struct disk_partition *part_info
Place to store the partition information
int allow_whole_dev
true to allow the user to select partition 0 (which means the whole device), false to require a valid partition number >= 1
Description
Parse a device number and partition description (either name or number) in the form of device number plus partition name separated by a "#" (like "device_num#partition_name") or a device number plus a partition number separated by a ":". For example both "0#misc" and "0:1" can be valid partition descriptions for a given interface. If the partition is found, sets desc and part_info accordingly with the information of the partition.
Return
the partition number on success, or negative errno on error
-
voidpart_set_generic_name(conststructblk_desc*desc, intpart_num, char*name)
create generic partition like hda1 or sdb2
Parameters
const struct blk_desc *desc
pointer to the block device
int part_num
partition number for which the name is generated
char *name
buffer where the name is written
Description
Helper function for partition tables, which don’t hold partition names (DOS, ISO). Generates partition name out of the device type and partition number.
-
ulongdisk_blk_read(structudevice *dev, lbaint_tstart, lbaint_tblkcnt, void*buffer)
read blocks from a disk partition
Parameters
struct udevice *dev
Device to read from (UCLASS_PARTITION)
lbaint_t start
Start block number to read in the partition (0=first)
lbaint_t blkcnt
Number of blocks to read
void *buffer
Destination buffer for data read
Return
number of blocks read, or -ve error number (see the IS_ERR_VALUE() macro
-
ulongdisk_blk_write(structudevice *dev, lbaint_tstart, lbaint_tblkcnt, constvoid*buffer)
write to a disk partition
Parameters
struct udevice *dev
Device to write to (UCLASS_PARTITION)
lbaint_t start
Start block number to write in the partition (0=first)
lbaint_t blkcnt
Number of blocks to write
const void *buffer
Source buffer for data to write
Return
number of blocks written, or -ve error number (see the IS_ERR_VALUE() macro
-
ulongdisk_blk_erase(structudevice *dev, lbaint_tstart, lbaint_tblkcnt)
erase a section of a disk partition
Parameters
struct udevice *dev
Device to (partially) erase (UCLASS_PARTITION)
lbaint_t start
Start block number to erase in the partition (0=first)
lbaint_t blkcnt
Number of blocks to erase
Return
number of blocks erased, or -ve error number (see the IS_ERR_VALUE() macro
-
structpart_driver
partition driver
Definition
struct part_driver { const char *name; int part_type; const int max_entries; int (*get_info)(struct blk_desc *desc, int part, struct disk_partition *info); void (*print)(struct blk_desc *desc); int (*test)(struct blk_desc *desc); };
Members
name
partition name
part_type
(MBR) partition type
max_entries
maximum number of partition table entries
get_info
Get information about a partition
get_info.desc: Block device descriptor get_info.part: Partition number (1 = first) get_info.info: Returns partition information
print
Print partition information
print.desc: Block device descriptor
test
Test if a device contains this partition type
test.desc: Block device descriptor test.Return: 0 if the block device appears to contain this partition type, -ve if not
-
intwrite_gpt_table(structblk_desc*desc, gpt_header*gpt_h, gpt_entry*gpt_e)
Write the GUID Partition Table to disk
Parameters
struct blk_desc *desc
block device descriptor
gpt_header *gpt_h
pointer to GPT header representation
gpt_entry *gpt_e
pointer to GPT partition table entries
Return
zero on success, otherwise error
-
intgpt_fill_pte(structblk_desc*desc, gpt_header*gpt_h, gpt_entry*gpt_e, structdisk_partition*partitions, intparts)
Fill the GPT partition table entry
Parameters
struct blk_desc *desc
block device descriptor
gpt_header *gpt_h
GPT header representation
gpt_entry *gpt_e
GPT partition table entries
struct disk_partition *partitions
list of partitions
int parts
number of partitions
Return
zero on success
-
intgpt_fill_header(structblk_desc*desc, gpt_header*gpt_h, char*str_guid, intparts_count)
Fill the GPT header
Parameters
struct blk_desc *desc
block device descriptor
gpt_header *gpt_h
GPT header representation
char *str_guid
disk guid string representation
int parts_count
number of partitions
Return
error on str_guid conversion error
-
intgpt_restore(structblk_desc*desc, char*str_disk_guid, structdisk_partition*partitions, constintparts_count)
Restore GPT partition table
Parameters
struct blk_desc *desc
block device descriptor
char *str_disk_guid
disk GUID
struct disk_partition *partitions
list of partitions
const int parts_count
number of partitions
Return
0 on success
-
intis_valid_gpt_buf(structblk_desc*desc, void*buf)
Ensure that the Primary GPT information is valid
Parameters
struct blk_desc *desc
block device descriptor
void *buf
buffer which contains the MBR and Primary GPT info
Return
0 on success, otherwise error
-
intwrite_mbr_and_gpt_partitions(structblk_desc*desc, void*buf)
write MBR, Primary GPT and Backup GPT
Parameters
struct blk_desc *desc
block device descriptor
void *buf
buffer which contains the MBR and Primary GPT info
Return
0 on success, otherwise error
-
intgpt_verify_headers(structblk_desc*desc, gpt_header*gpt_head, gpt_entry**gpt_pte)
Read and check CRC32 of the GPT’s header and partition table entries (PTE)
Parameters
struct blk_desc *desc
block device descriptor
gpt_header *gpt_head
pointer to GPT header data read from medium
gpt_entry **gpt_pte
pointer to GPT partition table enties read from medium
Description
As a side effect if sets gpt_head and gpt_pte so they point to GPT data.
Return
0 on success, otherwise error
-
intgpt_repair_headers(structblk_desc*desc)
Function to repair the GPT’s header and partition table entries (PTE)
Parameters
struct blk_desc *desc
block device descriptor
Return
0 on success, otherwise error
-
intgpt_verify_partitions(structblk_desc*desc, structdisk_partition*partitions, intparts, gpt_header*gpt_head, gpt_entry**gpt_pte)
Function to check if partitions’ name, start and size correspond to ‘$partitions’ env variable
Parameters
struct blk_desc *desc
block device descriptor
struct disk_partition *partitions
partition data read from ‘$partitions’ env variable
int parts
number of partitions read from ‘$partitions’ env variable
gpt_header *gpt_head
pointer to GPT header data read from medium
gpt_entry **gpt_pte
pointer to GPT partition table enties read from medium
Description
This function checks if on medium stored GPT data is in sync with information provided in ‘$partitions’ environment variable. Specificially, name, start and size of the partition is checked.
Return
0 on success, otherwise error
-
intget_disk_guid(structblk_desc*desc, char*guid)
Read the GUID string from a device’s GPT
Parameters
struct blk_desc *desc
block device descriptor
char *guid
pre-allocated string in which to return the GUID
Description
This function reads the GUID string from a block device whose descriptor is provided.
Return
0 on success, otherwise error
-
intis_valid_dos_buf(void*buf)
Ensure that a DOS MBR image is valid
Parameters
void *buf
buffer which contains the MBR
Return
0 on success, otherwise error
-
intwrite_mbr_sector(structblk_desc*desc, void*buf)
write DOS MBR
Parameters
struct blk_desc *desc
block device descriptor
void *buf
buffer which contains the MBR
Return
0 on success, otherwise error
-
intpart_driver_get_count(void)
get partition driver count
Parameters
void
no arguments
Return
number of partition drivers
-
structpart_driver *part_driver_get_first(void)
get first partition driver
Parameters
void
no arguments
Return
pointer to first partition driver on success, otherwise NULL
-
intpart_get_type_by_name(constchar*name)
Get partition type by name
Parameters
const char *name
Name of partition type to look up (not case-sensitive)
Return
Corresponding partition type (PART_TYPE_...) or PART_TYPE_UNKNOWN
-
intpart_get_bootable(structblk_desc*desc)
Find the first bootable partition
Parameters
struct blk_desc *desc
Block-device descriptor
Return
first bootable partition, or 0 if there is none