libblkid Reference Manual | ||||
---|---|---|---|---|
Top | Description |
typedef blkid_partlist; typedef blkid_partition; typedef blkid_parttable; int blkid_probe_enable_partitions (blkid_probe pr
,int enable
); int blkid_probe_set_partitions_flags (blkid_probe pr
,int flags
); int blkid_probe_filter_partitions_type (blkid_probe pr
,int flag
,char *names[]
); int blkid_probe_invert_partitions_filter (blkid_probe pr
); int blkid_probe_reset_partitions_filter (blkid_probe pr
); int blkid_known_pttype (const char *pttype
); const char * blkid_partition_get_name (blkid_partition par
); unsigned long long blkid_partition_get_flags (blkid_partition par
); int blkid_partition_get_partno (blkid_partition par
); blkid_loff_t blkid_partition_get_size (blkid_partition par
); blkid_loff_t blkid_partition_get_start (blkid_partition par
); blkid_parttable blkid_partition_get_table (blkid_partition par
); int blkid_partition_get_type (blkid_partition par
); const char * blkid_partition_get_type_string (blkid_partition par
); const char * blkid_partition_get_uuid (blkid_partition par
); int blkid_partition_is_extended (blkid_partition par
); int blkid_partition_is_logical (blkid_partition par
); int blkid_partition_is_primary (blkid_partition par
); blkid_partition blkid_partlist_get_partition (blkid_partlist ls
,int n
); int blkid_partlist_numof_partitions (blkid_partlist ls
); blkid_partition blkid_partlist_devno_to_partition (blkid_partlist ls
,dev_t devno
); blkid_parttable blkid_partlist_get_table (blkid_partlist ls
); blkid_loff_t blkid_parttable_get_offset (blkid_parttable tab
); blkid_partition blkid_parttable_get_parent (blkid_parttable tab
); const char * blkid_parttable_get_type (blkid_parttable tab
); blkid_partlist blkid_probe_get_partitions (blkid_probe pr
);
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.).
PART_ENTRY_SCHEME
: partition table type
PART_ENTRY_NAME
: partition name (gpt and mac only)
PART_ENTRY_UUID
: partition UUID (gpt only)
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: faild 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: faild 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! |
typedef struct blkid_struct_partlist *blkid_partlist;
list of all detected partitions and partitions tables
typedef struct blkid_struct_partition *blkid_partition;
information about a partition
typedef struct blkid_struct_parttable *blkid_parttable;
information about a partition table
int blkid_probe_enable_partitions (blkid_probe pr
,int enable
);
Enables/disables the partitions probing for non-binary interface.
|
probe |
|
TRUE/FALSE |
Returns : |
0 on success, or -1 in case of error. |
int blkid_probe_set_partitions_flags (blkid_probe pr
,int flags
);
Sets probing flags to the partitions prober. This function is optional.
|
prober |
|
BLKID_PARTS_* flags |
Returns : |
0 on success, or -1 in case of error. |
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
|
prober |
|
filter BLKID_FLTR_{NOTIN,ONLYIN} flag |
|
NULL terminated array of probing function names (e.g. "vfat"). |
Returns : |
0 on success, or -1 in case of error. |
int blkid_probe_invert_partitions_filter
(blkid_probe pr
);
Inverts partitions probing filter
|
prober |
Returns : |
0 on success, or -1 in case of error. |
int blkid_probe_reset_partitions_filter (blkid_probe pr
);
Resets partitions probing filter
|
prober |
Returns : |
0 on success, or -1 in case of error. |
int blkid_known_pttype (const char *pttype
);
|
partiton name |
Returns : |
1 for known or 0 for unknown partition type. |
const char * blkid_partition_get_name (blkid_partition par
);
|
partition |
Returns : |
partition name string if supported by PT (e.g. Mac) or NULL. |
unsigned long long blkid_partition_get_flags (blkid_partition par
);
|
partition |
Returns : |
partition flags (or attributes for gpt). |
int blkid_partition_get_partno (blkid_partition par
);
|
partition |
Returns : |
proposed partitin number (e.g. 'N' from sda'N') or -1 in case of error. Note that the number is generate by library independenly on your OS. |
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 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 unaccessible 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.
|
partition |
Returns : |
size of the partition (in 512-sectors). |
blkid_loff_t blkid_partition_get_start (blkid_partition par
);
Be careful if you _not_ probe whole disk:
1) the offset is usully 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 releative 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 proble whole disk. In such a case libblkid always returns the offset relative to the begin of the disk.
|
partition |
Returns : |
start of the partition (in 512-sectors). |
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}().
|
partition |
Returns : |
partition table object or NULL in case of error. |
int blkid_partition_get_type (blkid_partition par
);
|
partition |
Returns : |
partition type. |
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.
|
partition |
Returns : |
partition type string or NULL. |
const char * blkid_partition_get_uuid (blkid_partition par
);
|
partition |
Returns : |
partition UUID string if supported by PT (e.g. GPT) or NULL. |
int blkid_partition_is_extended (blkid_partition par
);
|
partition |
Returns : |
1 if the partitions is extended (dos, windows or linux) partition or 0 if not. |
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).
|
partition |
Returns : |
1 if the partitions is logical partition or 0 if not. |
int blkid_partition_is_primary (blkid_partition par
);
Note, this function returns FALSE for DOS extended partitions and all partitions in nested partition tables.
|
partition |
Returns : |
1 if the partitions is primary partition or 0 if not. |
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()
.
|
partitions list |
|
partition number in range 0..N, where 'N' is blkid_partlist_numof_partitions() . |
Returns : |
partition object or NULL in case or error. |
int blkid_partlist_numof_partitions (blkid_partlist ls
);
|
partitions list |
Returns : |
number of partitions in the list or -1 in case of error. |
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 funtion is necessary when you want to make a relation between an entry
in the partition table (ls
) and block devices in your system.
|
partitions list |
|
requested partition |
Returns : |
partition object or NULL in case or error. |
blkid_parttable blkid_partlist_get_table (blkid_partlist ls
);
|
partitions list |
Returns : |
top-level partition table or NULL of there is not a partition table on the device. |
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 patition 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); |
|
partition table |
Returns : |
position (in bytes) of the partition table or -1 in case of error. |
blkid_partition blkid_parttable_get_parent (blkid_parttable tab
);
|
partition table |
Returns : |
parent for nexted partitition tables or NULL. |
const char * blkid_parttable_get_type (blkid_parttable tab
);
|
partition table |
Returns : |
partition table type (type name, e.g. "dos", "gpt", ...) |
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()
).
|
probe |
Returns : |
list of partitions, or NULL in case of error. |