Miscellaneous utils

Miscellaneous utils — mix of various utils for low-level and high-level API

Synopsis

typedef             blkid_loff_t;
char *              blkid_devno_to_devname              (dev_t devno);
int                 blkid_devno_to_wholedisk            (dev_t dev,
                                                         char *diskname,
                                                         size_t len,
                                                         dev_t *diskdevno);
blkid_loff_t        blkid_get_dev_size                  (int fd);
int                 blkid_get_library_version           (const char **ver_string,
                                                         const char **date_string);
int                 blkid_parse_tag_string              (const char *token,
                                                         char **ret_type,
                                                         char **ret_val);
int                 blkid_parse_version_string          (const char *ver_string);
int                 blkid_send_uevent                   (const char *devname,
                                                         const char *action);

Description

Details

blkid_loff_t

typedef int64_t blkid_loff_t;

64-bit signed number for offsets and sizes


blkid_devno_to_devname ()

char *              blkid_devno_to_devname              (dev_t devno);

This function finds the pathname to a block device with a given device number.

devno :

device number

Returns :

a pointer to allocated memory to the pathname on success, and NULL on failure.

blkid_devno_to_wholedisk ()

int                 blkid_devno_to_wholedisk            (dev_t dev,
                                                         char *diskname,
                                                         size_t len,
                                                         dev_t *diskdevno);

This function uses sysfs to convert the devno device number to the *name* of the whole disk. The function DOES NOT return full device name. The dev argument could be partition or whole disk -- both is converted.

For example: sda1, 0x0801 --> sda, 0x0800

For conversion to the full disk *path* use blkid_devno_to_devname(), for example:

1
2
3
4
5
6
7
8
9
10
11
dev_t dev = 0x0801, disk;       // sda1 = 8:1
char *diskpath, diskname[32];

blkid_devno_to_wholedisk(dev, diskname, sizeof(diskname), &disk);
diskpath = blkid_devno_to_devname(disk);

// print "0x0801: sda, /dev/sda, 8:0
printf("0x%x: %s, %s, %d:%d\n",
    dev, diskname, diskpath, major(disk), minor(disk));

free(diskpath);

dev :

device number

diskname :

buffer to return diskname (or NULL)

len :

diskname buffer size (or 0)

diskdevno :

pointer to returns devno of entire disk (or NULL)

Returns :

0 on success or -1 in case of error.

blkid_get_dev_size ()

blkid_loff_t        blkid_get_dev_size                  (int fd);

fd :

file descriptor

Returns :

size (in bytes) of the block device or size of the regular file or 0.

blkid_get_library_version ()

int                 blkid_get_library_version           (const char **ver_string,
                                                         const char **date_string);

ver_string :

returns relese version (!= SONAME version)

date_string :

returns date

Returns :

release version code.

blkid_parse_tag_string ()

int                 blkid_parse_tag_string              (const char *token,
                                                         char **ret_type,
                                                         char **ret_val);

token :

ret_type :

ret_val :

Returns :


blkid_parse_version_string ()

int                 blkid_parse_version_string          (const char *ver_string);

ver_string :

version string (e.g. "2.16.0")

Returns :

release version code.

blkid_send_uevent ()

int                 blkid_send_uevent                   (const char *devname,
                                                         const char *action);

devname :

absolute path to the device

action :

Returns :

-1 in case of failure, or 0 on success.