Block device identification library
#include <blkid.h>
cc file.c -lblkid
The libblkid library is used to identify block devices (disks) as to their content (e.g. filesystem type) as well as extracting additional information such as filesystem labels/volume names, unique identifiers/serial numbers. A common use is to allow use of LABEL= and UUID= tags instead of hard-coding specific block device names into configuration files.
The low-level part of the library also allows to extract information about partitions and block device topology.
The high-level part of the library keeps information about block devices in a cache file and is verified to still be valid before being returned to the user (if the user has read permission on the raw block device, otherwise not). The cache file also allows unprivileged users (normally anyone other than root, or those not in the "disk" group) to locate devices by label/id. The standard location of the cache file can be overridden by the environment variable BLKID_FILE.
In situations where one is getting information about a single known device, it does not impact performance whether the cache is used or not (unless you are not able to read the block device directly).
The high-level part of the library supports two methods to evaluate LABEL/UUID. It reads information directly from a block device or read information from /dev/disk/by-* udev symlinks. The udev is preferred method by default.
If you are dealing with multiple devices, use of the cache is highly recommended (even if empty) as devices will be scanned at most one time and the on-disk cache will be updated if possible.
In some cases (modular kernels), block devices are not even visible until after they are accessed the first time, so it is critical that there is some way to locate these devices without enumerating only visible devices, so the use of the cache file is required in this situation.
The standard location of the /etc/blkid.conf config file can be overridden by the environment variable BLKID_CONF. For more details about the config file see blkid(8) man page.
libblkid was written by Andreas Dilger for the ext2 filesystem utilties, with input from Ted Ts'o. The library was subsequently heavily modified by Ted Ts'o.
The low-level probing code was rewritten by Karel Zak.
libblkid is available under the terms of the GNU Library General Public License (LGPL), version 2 (or at your discretion any later version).
libblkid is part of the util-linux package since version 2.15 and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.