RTEMS CPU Kit with SuperCore  4.10.99.0
Data Structures | Files | Defines | Typedefs | Enumerations | Functions
Block Device Partition Management
Block Device Library

This module provides functions to manage partitions of a disk device. More...

Collaboration diagram for Block Device Partition Management:

Data Structures

struct  rtems_bdpart_partition
 Partition description. More...
union  rtems_bdpart_format
 Disk format description. More...

Files

file  bdpart.h
 

Block Device Partition Management.


Defines

#define RTEMS_BDPART_PARTITION_NUMBER_HINT   16
 Recommended maximum partition table size.

Typedefs

typedef struct
rtems_bdpart_partition 
rtems_bdpart_partition
 Partition description.

Enumerations

enum  rtems_bdpart_format_type { RTEMS_BDPART_FORMAT_MBR, RTEMS_BDPART_FORMAT_GPT }
 Disk format for the partition tables. More...

Functions

rtems_status_code rtems_bdpart_read (const char *disk_name, rtems_bdpart_format *format, rtems_bdpart_partition *partitions, size_t *count)
 Reads the partition information from the physical disk device with name disk_name.
void rtems_bdpart_sort (rtems_bdpart_partition *partitions, size_t count)
 Sorts the partition table partitions with count partitions to have ascending begin blocks.
rtems_status_code rtems_bdpart_write (const char *disk_name, const rtems_bdpart_format *format, const rtems_bdpart_partition *partitions, size_t count)
 Writes the partition table to the physical disk device with name disk_name.
rtems_status_code rtems_bdpart_create (const char *disk_name, const rtems_bdpart_format *format, rtems_bdpart_partition *partitions, const unsigned *distribution, size_t count)
 Creates a partition table in partitions with count partitions for the physical disk device with name disk_name.
rtems_status_code rtems_bdpart_register (const char *disk_name, const rtems_bdpart_partition *partitions, size_t count)
 Registers the partitions as logical disks for the physical disk device with name disk_name.
rtems_status_code rtems_bdpart_register_from_disk (const char *disk_name)
 brief Reads the partition table from the disk device with name disk_name and registers the partitions as logical disks.
rtems_status_code rtems_bdpart_unregister (const char *disk_name, const rtems_bdpart_partition *partitions, size_t count)
 Deletes the logical disks associated with the partitions of the disk device with name disk_name.
rtems_status_code rtems_bdpart_mount (const char *disk_name, const rtems_bdpart_partition *partitions, size_t count, const char *mount_base)
 Mounts all supported file systems inside the logical disks derived from the partitions of the physical disk device with name disk_name.
rtems_status_code rtems_bdpart_unmount (const char *disk_name, const rtems_bdpart_partition *partitions, size_t count, const char *mount_base)
 Unmounts all file systems mounted with rtems_bdpart_mount().
void rtems_bdpart_dump (const rtems_bdpart_partition *partitions, size_t count)
 Prints the partition table partitions with count partitions to standard output.
void rtems_bdpart_to_partition_type (uint8_t mbr_type, uuid_t type)
 Returns the partition type for the MBR partition type value mbr_type in type.
bool rtems_bdpart_to_mbr_partition_type (const uuid_t type, uint8_t *mbr_type)
 Converts the partition type in type to the MBR partition type.

MBR Partition Types and Flags

#define RTEMS_BDPART_MBR_EMPTY   0x0U
#define RTEMS_BDPART_MBR_FAT_12   0x1U
#define RTEMS_BDPART_MBR_FAT_16   0x4U
#define RTEMS_BDPART_MBR_FAT_16_LBA   0xeU
#define RTEMS_BDPART_MBR_FAT_32   0xbU
#define RTEMS_BDPART_MBR_FAT_32_LBA   0xcU
#define RTEMS_BDPART_MBR_EXTENDED   0x5U
#define RTEMS_BDPART_MBR_DATA   0xdaU
#define RTEMS_BDPART_MBR_GPT   0xeeU
#define RTEMS_BDPART_MBR_FLAG_ACTIVE   0x80U

Detailed Description

This module provides functions to manage partitions of a disk device.

A disk is a set of blocks which are identified by a consecutive set of non-negative integers starting at zero. There are also logical disks which contain a subset of consecutive disk blocks. The logical disks are used to represent the partitions of a disk. The disk devices are accessed via the block device buffer module.

The partition format on the physical disk will be converted to an internal representation. It is possible to convert the internal representation into a specific output format and write it to the physical disk. One of the constrains for the internal representation was to support the GPT format easily.

Currently two physical partition formats are supported. These are the MBR and the GPT format. Please note that the GPT support is not implemented. With MBR format we mean the partition format of the wide spread IBM PC-compatible systems. The GPT format is defined in the Extensible Firmware Interface (EFI).

The most common task will be to read the partition information of a disk and register logical disks for each partition. This can be done with the rtems_bdpart_register_from_disk() function. Afterwards you can mount the file systems within the partitions.

You can read the partition information from a disk with rtems_bdpart_read() and write it to the disk with rtems_bdpart_write().

To create a partition table from scratch for a disk use rtems_bdpart_create().

You can access some disk functions with the shell command fdisk.

References used to create this module:


Enumeration Type Documentation

Disk format for the partition tables.

Enumerator:
RTEMS_BDPART_FORMAT_MBR 

Type value for MBR format.

RTEMS_BDPART_FORMAT_GPT 

Type value for GPT format.


Function Documentation

rtems_status_code rtems_bdpart_create ( const char *  disk_name,
const rtems_bdpart_format format,
rtems_bdpart_partition partitions,
const unsigned *  distribution,
size_t  count 
)

Creates a partition table in partitions with count partitions for the physical disk device with name disk_name.

The array of positive integer weights in distribution must have exactly count elements. The weights in the distribution array are summed up. Each weight is then divided by the sum to obtain the disk fraction which forms the corresponding partition. The partition boundaries are generated with respect to the output format in format.

rtems_status_code rtems_bdpart_mount ( const char *  disk_name,
const rtems_bdpart_partition partitions,
size_t  count,
const char *  mount_base 
)

Mounts all supported file systems inside the logical disks derived from the partitions of the physical disk device with name disk_name.

For each partition in the partition table partitions with count partitions it will be checked if it contains a supported file system. In this case a mount point derived from the disk name will be created in the mount base path mount_base. The file system will be mounted there. The partition number equals the partition table index plus one. The mount point name for each partition will be the concatenation of the mount base path, the disk device file name and the parition number.

See also:
rtems_bdpart_read().
rtems_status_code rtems_bdpart_read ( const char *  disk_name,
rtems_bdpart_format format,
rtems_bdpart_partition partitions,
size_t *  count 
)

Reads the partition information from the physical disk device with name disk_name.

The partition information will be stored in the partition table partitions with a maximum of count partitions. The number of actual partitions will be stored in count. If there are more partitions than space for storage an error status will be returned. The partition table format recognized on the disk will be stored in format.

rtems_status_code rtems_bdpart_register ( const char *  disk_name,
const rtems_bdpart_partition partitions,
size_t  count 
)

Registers the partitions as logical disks for the physical disk device with name disk_name.

For each partition of the partition table partitions with count partitions a logical disk is registered. The partition number equals the partition table index plus one. The name of the logical disk device is the concatenation of the physical disk device name and the partition number.

See also:
rtems_blkdev_create_partition().
rtems_status_code rtems_bdpart_register_from_disk ( const char *  disk_name)

brief Reads the partition table from the disk device with name disk_name and registers the partitions as logical disks.

See also:
rtems_bdpart_register() and rtems_fsmount().
bool rtems_bdpart_to_mbr_partition_type ( const uuid_t  type,
uint8_t *  mbr_type 
)

Converts the partition type in type to the MBR partition type.

The result will be stored in mbr_type. Returns true in case of a successful convertion and otherwise false. Both arguments must not be NULL.

rtems_status_code rtems_bdpart_unregister ( const char *  disk_name,
const rtems_bdpart_partition partitions,
size_t  count 
)

Deletes the logical disks associated with the partitions of the disk device with name disk_name.

The partition table partitions with count partitions will be used to determine which disks need to be deleted. It may be obtained from rtems_bdpart_read().

rtems_status_code rtems_bdpart_write ( const char *  disk_name,
const rtems_bdpart_format format,
const rtems_bdpart_partition partitions,
size_t  count 
)

Writes the partition table to the physical disk device with name disk_name.

The partition table partitions with count partitions will be written to the disk. The output format for the partition table on the disk is specified by format. There are some consistency checks applied to the partition table. The partition table must be sorted such that the begin blocks are in ascending order. This can be done with the rtems_bdpart_sort() function. The partitions must not overlap. The partitions must have a positive size. The partitions must be within the disk. Depending on the output format there are additional constrains.