blob: 7bd602752f18a2d6b4c9852992035bcfb127828f [file] [log] [blame]
Theodore Ts'o28595222003-03-01 20:01:27 -05001libblkid - a library to handle device identification and token extraction
2
3Basic usage is as follows - there are two normal usage patterns:
4
5For cases where a program wants information about multiple devices, or
6expects to be doing multiple token searches, the program should directly
7initialize cache file via (second parameter is cache filename, NULL = default):
8
9 blkid_cache cache = NULL;
10 if (blkid_get_cache(&cache, NULL) < 0)
11 /* error reading the cache file, not really fatal */
12
13Note that if no cache file exists, an empty cache struct is still allocated.
14Usage of libblkid functions will use the cache to avoid needless device scans.
15
16For cases where a program only wants to find a single token, or display
17information about a specific device, it is often not necessary to manually
18load the cache. For functions which deal with a single device, they will
19probe the device directly if no cache is given. For "get" functions which
20do searching, they will read/free the cache internally.
21
22
23How to use libblkid? Normally, you either want to find a device with a
24specific NAME=value token, or you want to output token(s) from a device.
25To locate a specific token, you can call:
26
27 if ((devname = blkid_get_devname(cache, token, value))) {
28 /* do something with devname */
29 string_free(devname);
30 }
31
32where cache is optionally loaded, token is either a "NAME=value" string,
33or "NAME" and value gives the desired value to look for. The return
34value is an allocated string which holds the resulting device name (if
35found) or "NAME" if we do not have a proper value, or NULL if a specific
36token was not found. This allows you to pass token = "/dev/hda1" or
37token = "LABEL=root" and get a valid device name back if possible. The
38returned string must be freed with "free(devname)".
39
40The other common usage is to want the value of a specific tag on a device.
41
42 if ((value = blkid_get_tag_value(cache, tagname, devname))) {
43 /* do something with value */
44 string_free(value);
45 }
46
47If you have directly loaded the cache from the program, you need to clean
48up by saving the cache (assuming you have write access to the cache, this
49happens automatically if you didn't load it directly), and freeing it (this
50will also free all associated devices/tags):
51
52 blkid_put_cache(cache);
53
54In all cases, any data returned by the searching functions from the cache
55is first verified from disk to ensure that it is still valid.