Top |
This chain supports binary and NAME=value interfaces, but complete PT description is provided by binary interface only. The libblkid prober is compatible with kernel partition tables parser. The parser does not return empty (size=0) partitions or special hidden partitions.
NAME=value interface, supported tags:
PTTYPE
: partition table type (dos, gpt, etc.).
PTUUID
: partition table id (uuid for gpt, hex for dos).
PART_ENTRY_SCHEME
: partition table type
PART_ENTRY_NAME
: partition name (gpt and mac only)
PART_ENTRY_UUID
: partition UUID (gpt, or pseudo IDs for MBR)
PART_ENTRY_TYPE
: partition type, 0xNN (e.g. 0x82) or type UUID (gpt only) or type string (mac)
PART_ENTRY_FLAGS
: partition flags (e.g. boot_ind) or attributes (e.g. gpt attributes)
PART_ENTRY_NUMBER
: partition number
PART_ENTRY_OFFSET
: the begin of the partition
PART_ENTRY_SIZE
: size of the partition
PART_ENTRY_DISK
: whole-disk maj:min
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
blkid_probe pr; const char *ptname; pr = blkid_new_probe_from_filename(devname); if (!pr) err("%s: failed to open device", devname); blkid_probe_enable_partitions(pr, TRUE); blkid_do_fullprobe(pr); blkid_probe_lookup_value(pr, "PTTYPE", &ptname, NULL); printf("%s partition type detected\n", pttype); blkid_free_probe(pr); // don't forget to check return codes in your code! |
Binary interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
blkid_probe pr; blkid_partlist ls; int nparts, i; pr = blkid_new_probe_from_filename(devname); if (!pr) err("%s: failed to open device", devname); ls = blkid_probe_get_partitions(pr); nparts = blkid_partlist_numof_partitions(ls); for (i = 0; i < nparts; i++) { blkid_partition par = blkid_partlist_get_partition(ls, i); printf("#%d: %llu %llu 0x%x", blkid_partition_get_partno(par), blkid_partition_get_start(par), blkid_partition_get_size(par), blkid_partition_get_type(par)); } blkid_free_probe(pr); // don't forget to check return codes in your code! |
int blkid_probe_enable_partitions (blkid_probe pr
,int enable
);
Enables/disables the partitions probing for non-binary interface.
int blkid_probe_set_partitions_flags (blkid_probe pr
,int flags
);
Sets probing flags to the partitions prober. This function is optional.
int blkid_probe_filter_partitions_type (blkid_probe pr
,int flag
,char *names[]
);
BLKID_FLTR_NOTIN
- probe for all items which are NOT IN names
BLKID_FLTR_ONLYIN
- probe for items which are IN names
int
blkid_probe_invert_partitions_filter (blkid_probe pr
);
Inverts partitions probing filter
int
blkid_probe_reset_partitions_filter (blkid_probe pr
);
Resets partitions probing filter
int blkid_partitions_get_name (const size_t idx
,const char **name
);
Since: 2.30
blkid_loff_t
blkid_partition_get_size (blkid_partition par
);
WARNING: be very careful when you work with MS-DOS extended partitions. The library always returns full size of the partition. If you want to add the partition to the Linux system (BLKPG_ADD_PARTITION ioctl) you need to reduce the size of the partition to 1 or 2 blocks. The rest of the partition has to be inaccessible for mkfs or mkswap programs, we need a small space for boot loaders only.
For some unknown reason this (safe) practice is not to used for nested BSD, Solaris, ..., partition tables in Linux kernel.
blkid_loff_t
blkid_partition_get_start (blkid_partition par
);
Be careful if you _not_ probe whole disk:
1) the offset is usually relative to begin of the disk -- but if you probe a fragment of the disk only -- then the offset could be still relative to the begin of the disk rather that relative to the fragment.
2) the offset for nested partitions could be relative to parent (e.g. Solaris) _or_ relative to the begin of the whole disk (e.g. bsd).
You don't have to care about such details if you probe whole disk. In such a case libblkid always returns the offset relative to the begin of the disk.
blkid_parttable
blkid_partition_get_table (blkid_partition par
);
The "parttable" describes partition table. The table is usually the same for all partitions -- except nested partition tables.
For example bsd, solaris, etc. use a nested partition table within standard primary dos partition:
1 2 3 4 5 6 |
-- dos partition table 0: sda1 dos primary partition 1: sda2 dos primary partition -- bsd partition table (with in sda2) 2: sda5 bds partition 3: sda6 bds partition |
The library does not to use a separate partition table object for dos logical partitions (partitions within extended partition). It's possible to differentiate between logical, extended and primary partitions by
blkid_partition_is_{extended,primary,logical}().
const char *
blkid_partition_get_type_string (blkid_partition par
);
The type string is supported by a small subset of partition tables (e.g. Mac and EFI GPT). Note that GPT uses type UUID and this function returns this UUID as string.
int
blkid_partition_is_logical (blkid_partition par
);
Note that this function returns TRUE for all partitions in all nested partition tables (e.g. BSD labels).
int
blkid_partition_is_primary (blkid_partition par
);
Note, this function returns FALSE for DOS extended partitions and all partitions in nested partition tables.
blkid_partition blkid_partlist_get_partition (blkid_partlist ls
,int n
);
It's possible that the list of partitions is *empty*, but there is a valid partition table on the disk. This happen when on-disk details about partitions are unknown or the partition table is empty.
See also blkid_partlist_get_table()
.
ls |
partitions list |
|
n |
partition number in range 0..N, where 'N' is |
blkid_partition blkid_partlist_get_partition_by_partno (blkid_partlist ls
,int n
);
This does not assume any order of the input blkid_partlist. And correctly handles "out of order" partition tables. partition N is located after partition N+1 on the disk.
blkid_partition blkid_partlist_devno_to_partition (blkid_partlist ls
,dev_t devno
);
This function tries to get start and size for devno
from sysfs and
returns a partition from ls
which matches with the values from sysfs.
This function is necessary when you want to make a relation between an entry
in the partition table (ls
) and block devices in your system.
const char *
blkid_parttable_get_id (blkid_parttable tab
);
The ID is GPT disk UUID or DOS disk ID (in hex format).
blkid_loff_t
blkid_parttable_get_offset (blkid_parttable tab
);
Note the position is relative to begin of the device as defined by
blkid_probe_set_device()
for primary partition table, and relative
to parental partition for nested partition tables.
1 2 3 4 5 6 7 8 |
off_t offset; blkid_partition parent = blkid_parttable_get_parent(tab); offset = blkid_parttable_get_offset(tab); if (parent) / * 'tab' is nested partition table * / offset += blkid_partition_get_start(parent); |
blkid_partlist
blkid_probe_get_partitions (blkid_probe pr
);
This is a binary interface for partitions. See also blkid_partlist_* functions.
This function is independent on blkid_do_[safe,full]probe()
and
blkid_probe_enable_partitions()
calls.
WARNING: the returned object will be overwritten by the next
blkid_probe_get_partitions()
call for the same pr
. If you want to
use more blkid_partlist objects in the same time you have to create
more blkid_probe handlers (see blkid_new_probe()
).