blob: fdbb5c99af9d638e7f57b40078b53bd5719c0321 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * devname.c - get a dev by its device inode name
3 *
4 * Copyright (C) Andries Brouwer
5 * Copyright (C) 1999, 2000, 2001, 2002, 2003 Theodore Ts'o
6 * Copyright (C) 2001 Andreas Dilger
7 *
8 * %Begin-Header%
9 * This file may be redistributed under the terms of the
10 * GNU Lesser General Public License.
11 * %End-Header%
12 */
13
14#define _GNU_SOURCE 1
15
16#include <stdio.h>
17#include <string.h>
18#include <limits.h>
19#ifdef HAVE_UNISTD_H
20#include <unistd.h>
21#endif
22#include <stdlib.h>
23#include <ctype.h>
24#include <fcntl.h>
25#ifdef HAVE_SYS_TYPES_H
26#include <sys/types.h>
27#endif
28#include <dirent.h>
29#ifdef HAVE_SYS_STAT_H
30#include <sys/stat.h>
31#endif
32#ifdef HAVE_ERRNO_H
33#include <errno.h>
34#endif
35#include <time.h>
36
37#include "blkidP.h"
38
39#include "canonicalize.h" /* $(top_srcdir)/include */
40#include "pathnames.h"
41#include "sysfs.h"
42#include "at.h"
43
44/*
45 * Find a dev struct in the cache by device name, if available.
46 *
47 * If there is no entry with the specified device name, and the create
48 * flag is set, then create an empty device entry.
49 */
50blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
51{
52 blkid_dev dev = NULL, tmp;
53 struct list_head *p, *pnext;
54
55 if (!cache || !devname)
56 return NULL;
57
58 list_for_each(p, &cache->bic_devs) {
59 tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
60 if (strcmp(tmp->bid_name, devname))
61 continue;
62
bigbiff7b4c7a62015-01-01 19:44:14 -050063 DBG(DEVNAME, ul_debug("found devname %s in cache", tmp->bid_name));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050064 dev = tmp;
65 break;
66 }
67
68 if (!dev && (flags & BLKID_DEV_CREATE)) {
69 if (access(devname, F_OK) < 0)
70 return NULL;
71 dev = blkid_new_dev();
72 if (!dev)
73 return NULL;
74 dev->bid_time = INT_MIN;
75 dev->bid_name = strdup(devname);
76 dev->bid_cache = cache;
77 list_add_tail(&dev->bid_devs, &cache->bic_devs);
78 cache->bic_flags |= BLKID_BIC_FL_CHANGED;
79 }
80
81 if (flags & BLKID_DEV_VERIFY) {
82 dev = blkid_verify(cache, dev);
83 if (!dev || !(dev->bid_flags & BLKID_BID_FL_VERIFIED))
84 return dev;
85 /*
86 * If the device is verified, then search the blkid
87 * cache for any entries that match on the type, uuid,
88 * and label, and verify them; if a cache entry can
89 * not be verified, then it's stale and so we remove
90 * it.
91 */
92 list_for_each_safe(p, pnext, &cache->bic_devs) {
93 blkid_dev dev2 = list_entry(p, struct blkid_struct_dev, bid_devs);
94 if (dev2->bid_flags & BLKID_BID_FL_VERIFIED)
95 continue;
96 if (!dev->bid_type || !dev2->bid_type ||
97 strcmp(dev->bid_type, dev2->bid_type))
98 continue;
99 if (dev->bid_label && dev2->bid_label &&
100 strcmp(dev->bid_label, dev2->bid_label))
101 continue;
102 if (dev->bid_uuid && dev2->bid_uuid &&
103 strcmp(dev->bid_uuid, dev2->bid_uuid))
104 continue;
105 if ((dev->bid_label && !dev2->bid_label) ||
106 (!dev->bid_label && dev2->bid_label) ||
107 (dev->bid_uuid && !dev2->bid_uuid) ||
108 (!dev->bid_uuid && dev2->bid_uuid))
109 continue;
110 dev2 = blkid_verify(cache, dev2);
111 if (dev2 && !(dev2->bid_flags & BLKID_BID_FL_VERIFIED))
112 blkid_free_dev(dev2);
113 }
114 }
115 return dev;
116}
117
118/* Directories where we will try to search for device names */
119static const char *dirlist[] = { "/dev", "/devfs", "/devices", NULL };
120
121static int is_dm_leaf(const char *devname)
122{
123 struct dirent *de, *d_de;
124 DIR *dir, *d_dir;
125 char path[256];
126 int ret = 1;
127
128 if ((dir = opendir("/sys/block")) == NULL)
129 return 0;
130 while ((de = readdir(dir)) != NULL) {
131 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") ||
132 !strcmp(de->d_name, devname) ||
133 strncmp(de->d_name, "dm-", 3) ||
134 strlen(de->d_name) > sizeof(path)-32)
135 continue;
136 sprintf(path, "/sys/block/%s/slaves", de->d_name);
137 if ((d_dir = opendir(path)) == NULL)
138 continue;
139 while ((d_de = readdir(d_dir)) != NULL) {
140 if (!strcmp(d_de->d_name, devname)) {
141 ret = 0;
142 break;
143 }
144 }
145 closedir(d_dir);
146 if (!ret)
147 break;
148 }
149 closedir(dir);
150 return ret;
151}
152
153/*
154 * Probe a single block device to add to the device cache.
155 */
156static void probe_one(blkid_cache cache, const char *ptname,
157 dev_t devno, int pri, int only_if_new, int removable)
158{
159 blkid_dev dev = NULL;
160 struct list_head *p, *pnext;
161 const char **dir;
162 char *devname = NULL;
163
164 /* See if we already have this device number in the cache. */
165 list_for_each_safe(p, pnext, &cache->bic_devs) {
166 blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
167 bid_devs);
168 if (tmp->bid_devno == devno) {
169 if (only_if_new && !access(tmp->bid_name, F_OK))
170 return;
171 dev = blkid_verify(cache, tmp);
172 if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED))
173 break;
174 dev = 0;
175 }
176 }
177 if (dev && dev->bid_devno == devno)
178 goto set_pri;
179
180 /* Try to translate private device-mapper dm-<N> names
181 * to standard /dev/mapper/<name>.
182 */
183 if (!strncmp(ptname, "dm-", 3) && isdigit(ptname[3])) {
184 devname = canonicalize_dm_name(ptname);
185 if (!devname)
186 blkid__scan_dir("/dev/mapper", devno, 0, &devname);
187 if (devname)
188 goto get_dev;
189 }
190
191 /*
192 * Take a quick look at /dev/ptname for the device number. We check
193 * all of the likely device directories. If we don't find it, or if
194 * the stat information doesn't check out, use blkid_devno_to_devname()
195 * to find it via an exhaustive search for the device major/minor.
196 */
197 for (dir = dirlist; *dir; dir++) {
198 struct stat st;
199 char device[256];
200
201 snprintf(device, sizeof(device), "%s/%s", *dir, ptname);
202 if ((dev = blkid_get_dev(cache, device, BLKID_DEV_FIND)) &&
203 dev->bid_devno == devno)
204 goto set_pri;
205
206 if (stat(device, &st) == 0 &&
207 (S_ISBLK(st.st_mode) ||
208 (S_ISCHR(st.st_mode) && !strncmp(ptname, "ubi", 3))) &&
209 st.st_rdev == devno) {
210 devname = strdup(device);
211 goto get_dev;
212 }
213 }
214 /* Do a short-cut scan of /dev/mapper first */
215 if (!devname)
216 blkid__scan_dir("/dev/mapper", devno, 0, &devname);
217 if (!devname) {
218 devname = blkid_devno_to_devname(devno);
219 if (!devname)
220 return;
221 }
222
223get_dev:
224 dev = blkid_get_dev(cache, devname, BLKID_DEV_NORMAL);
225 free(devname);
226
227set_pri:
228 if (dev) {
229 if (pri)
230 dev->bid_pri = pri;
231 else if (!strncmp(dev->bid_name, "/dev/mapper/", 11)) {
232 dev->bid_pri = BLKID_PRI_DM;
233 if (is_dm_leaf(ptname))
234 dev->bid_pri += 5;
235 } else if (!strncmp(ptname, "md", 2))
236 dev->bid_pri = BLKID_PRI_MD;
237 if (removable)
238 dev->bid_flags |= BLKID_BID_FL_REMOVABLE;
239 }
240 return;
241}
242
243#define PROC_PARTITIONS "/proc/partitions"
244#define VG_DIR "/proc/lvm/VGs"
245
246/*
247 * This function initializes the UUID cache with devices from the LVM
248 * proc hierarchy. We currently depend on the names of the LVM
249 * hierarchy giving us the device structure in /dev. (XXX is this a
250 * safe thing to do?)
251 */
252#ifdef VG_DIR
253static dev_t lvm_get_devno(const char *lvm_device)
254{
255 FILE *lvf;
256 char buf[1024];
257 int ma, mi;
258 dev_t ret = 0;
259
bigbiff7b4c7a62015-01-01 19:44:14 -0500260 DBG(DEVNAME, ul_debug("opening %s", lvm_device));
261 if ((lvf = fopen(lvm_device, "r" UL_CLOEXECSTR)) == NULL) {
262 DBG(DEVNAME, ul_debug("%s: (%d) %m", lvm_device, errno));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500263 return 0;
264 }
265
266 while (fgets(buf, sizeof(buf), lvf)) {
267 if (sscanf(buf, "device: %d:%d", &ma, &mi) == 2) {
268 ret = makedev(ma, mi);
269 break;
270 }
271 }
272 fclose(lvf);
273
274 return ret;
275}
276
277static void lvm_probe_all(blkid_cache cache, int only_if_new)
278{
279 DIR *vg_list;
280 struct dirent *vg_iter;
281 int vg_len = strlen(VG_DIR);
282 dev_t dev;
283
284 if ((vg_list = opendir(VG_DIR)) == NULL)
285 return;
286
bigbiff7b4c7a62015-01-01 19:44:14 -0500287 DBG(DEVNAME, ul_debug("probing LVM devices under %s", VG_DIR));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500288
289 while ((vg_iter = readdir(vg_list)) != NULL) {
290 DIR *lv_list;
291 char *vdirname;
292 char *vg_name;
293 struct dirent *lv_iter;
294
295 vg_name = vg_iter->d_name;
296 if (!strcmp(vg_name, ".") || !strcmp(vg_name, ".."))
297 continue;
298 vdirname = malloc(vg_len + strlen(vg_name) + 8);
299 if (!vdirname)
300 goto exit;
301 sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
302
303 lv_list = opendir(vdirname);
304 free(vdirname);
305 if (lv_list == NULL)
306 continue;
307
308 while ((lv_iter = readdir(lv_list)) != NULL) {
309 char *lv_name, *lvm_device;
310
311 lv_name = lv_iter->d_name;
312 if (!strcmp(lv_name, ".") || !strcmp(lv_name, ".."))
313 continue;
314
315 lvm_device = malloc(vg_len + strlen(vg_name) +
316 strlen(lv_name) + 8);
317 if (!lvm_device) {
318 closedir(lv_list);
319 goto exit;
320 }
321 sprintf(lvm_device, "%s/%s/LVs/%s", VG_DIR, vg_name,
322 lv_name);
323 dev = lvm_get_devno(lvm_device);
324 sprintf(lvm_device, "%s/%s", vg_name, lv_name);
bigbiff7b4c7a62015-01-01 19:44:14 -0500325 DBG(DEVNAME, ul_debug("LVM dev %s: devno 0x%04X",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500326 lvm_device,
327 (unsigned int) dev));
328 probe_one(cache, lvm_device, dev, BLKID_PRI_LVM,
329 only_if_new, 0);
330 free(lvm_device);
331 }
332 closedir(lv_list);
333 }
334exit:
335 closedir(vg_list);
336}
337#endif
338
339#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
340
341static int
342evms_probe_all(blkid_cache cache, int only_if_new)
343{
344 char line[100];
345 int ma, mi, sz, num = 0;
346 FILE *procpt;
347 char device[110];
348
bigbiff7b4c7a62015-01-01 19:44:14 -0500349 procpt = fopen(PROC_EVMS_VOLUMES, "r" UL_CLOEXECSTR);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500350 if (!procpt)
351 return 0;
352 while (fgets(line, sizeof(line), procpt)) {
353 if (sscanf (line, " %d %d %d %*s %*s %[^\n ]",
354 &ma, &mi, &sz, device) != 4)
355 continue;
356
bigbiff7b4c7a62015-01-01 19:44:14 -0500357 DBG(DEVNAME, ul_debug("Checking partition %s (%d, %d)",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500358 device, ma, mi));
359
360 probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS,
361 only_if_new, 0);
362 num++;
363 }
364 fclose(procpt);
365 return num;
366}
367
368static void
369ubi_probe_all(blkid_cache cache, int only_if_new)
370{
371 const char **dirname;
372
373 for (dirname = dirlist; *dirname; dirname++) {
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500374 DIR *dir;
375 struct dirent *iter;
376
bigbiff7b4c7a62015-01-01 19:44:14 -0500377 DBG(DEVNAME, ul_debug("probing UBI volumes under %s",
378 *dirname));
379
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500380 dir = opendir(*dirname);
381 if (dir == NULL)
382 continue ;
383
384 while ((iter = readdir(dir)) != NULL) {
385 char *name;
386 struct stat st;
387 dev_t dev;
388
389 name = iter->d_name;
390#ifdef _DIRENT_HAVE_D_TYPE
391 if (iter->d_type != DT_UNKNOWN &&
392 iter->d_type != DT_CHR && iter->d_type != DT_LNK)
393 continue;
394#endif
395 if (!strcmp(name, ".") || !strcmp(name, "..") ||
396 !strstr(name, "ubi"))
397 continue;
398 if (!strcmp(name, "ubi_ctrl"))
399 continue;
400 if (fstat_at(dirfd(dir), *dirname, name, &st, 0))
401 continue;
402
403 dev = st.st_rdev;
404
405 if (!S_ISCHR(st.st_mode) || !minor(dev))
406 continue;
bigbiff7b4c7a62015-01-01 19:44:14 -0500407 DBG(DEVNAME, ul_debug("UBI vol %s/%s: devno 0x%04X",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500408 *dirname, name, (int) dev));
409 probe_one(cache, name, dev, BLKID_PRI_UBI, only_if_new, 0);
410 }
411 closedir(dir);
412 }
413}
414
415/*
416 * Read the device data for all available block devices in the system.
417 */
418static int probe_all(blkid_cache cache, int only_if_new)
419{
420 FILE *proc;
421 char line[1024];
422 char ptname0[128 + 1], ptname1[128 + 1], *ptname = 0;
423 char *ptnames[2];
424 dev_t devs[2];
425 int ma, mi;
426 unsigned long long sz;
427 int lens[2] = { 0, 0 };
428 int which = 0, last = 0;
429 struct list_head *p, *pnext;
430
431 ptnames[0] = ptname0;
432 ptnames[1] = ptname1;
433
434 if (!cache)
435 return -BLKID_ERR_PARAM;
436
437 if (cache->bic_flags & BLKID_BIC_FL_PROBED &&
438 time(0) - cache->bic_time < BLKID_PROBE_INTERVAL)
439 return 0;
440
441 blkid_read_cache(cache);
442 evms_probe_all(cache, only_if_new);
443#ifdef VG_DIR
444 lvm_probe_all(cache, only_if_new);
445#endif
446 ubi_probe_all(cache, only_if_new);
447
bigbiff7b4c7a62015-01-01 19:44:14 -0500448 proc = fopen(PROC_PARTITIONS, "r" UL_CLOEXECSTR);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500449 if (!proc)
450 return -BLKID_ERR_PROC;
451
452 while (fgets(line, sizeof(line), proc)) {
453 last = which;
454 which ^= 1;
455 ptname = ptnames[which];
456
457 if (sscanf(line, " %d %d %llu %128[^\n ]",
458 &ma, &mi, &sz, ptname) != 4)
459 continue;
460 devs[which] = makedev(ma, mi);
461
bigbiff7b4c7a62015-01-01 19:44:14 -0500462 DBG(DEVNAME, ul_debug("read partition name %s", ptname));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500463
464 /* Skip whole disk devs unless they have no partitions.
465 * If base name of device has changed, also
466 * check previous dev to see if it didn't have a partn.
467 * heuristic: partition name ends in a digit, & partition
468 * names contain whole device name as substring.
469 *
470 * Skip extended partitions.
471 * heuristic: size is 1
472 *
473 * FIXME: skip /dev/{ida,cciss,rd} whole-disk devs
474 */
475
476 lens[which] = strlen(ptname);
477
478 /* ends in a digit, clearly a partition, so check */
479 if (isdigit(ptname[lens[which] - 1])) {
bigbiff7b4c7a62015-01-01 19:44:14 -0500480 DBG(DEVNAME, ul_debug("partition dev %s, devno 0x%04X",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500481 ptname, (unsigned int) devs[which]));
482
483 if (sz > 1)
484 probe_one(cache, ptname, devs[which], 0,
485 only_if_new, 0);
486 lens[which] = 0; /* mark as checked */
487 }
488
489 /*
490 * If last was a whole disk and we just found a partition
491 * on it, remove the whole-disk dev from the cache if
492 * it exists.
493 */
494 if (lens[last] && !strncmp(ptnames[last], ptname, lens[last])) {
495 list_for_each_safe(p, pnext, &cache->bic_devs) {
496 blkid_dev tmp;
497
498 /* find blkid dev for the whole-disk devno */
499 tmp = list_entry(p, struct blkid_struct_dev,
500 bid_devs);
501 if (tmp->bid_devno == devs[last]) {
bigbiff7b4c7a62015-01-01 19:44:14 -0500502 DBG(DEVNAME, ul_debug("freeing %s",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500503 tmp->bid_name));
504 blkid_free_dev(tmp);
505 cache->bic_flags |= BLKID_BIC_FL_CHANGED;
506 break;
507 }
508 }
509 lens[last] = 0;
510 }
511 /*
512 * If last was not checked because it looked like a whole-disk
513 * dev, and the device's base name has changed,
514 * check last as well.
515 */
516 if (lens[last] && strncmp(ptnames[last], ptname, lens[last])) {
bigbiff7b4c7a62015-01-01 19:44:14 -0500517 DBG(DEVNAME, ul_debug("whole dev %s, devno 0x%04X",
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500518 ptnames[last], (unsigned int) devs[last]));
519 probe_one(cache, ptnames[last], devs[last], 0,
520 only_if_new, 0);
521 lens[last] = 0;
522 }
523 }
524
525 /* Handle the last device if it wasn't partitioned */
526 if (lens[which])
527 probe_one(cache, ptname, devs[which], 0, only_if_new, 0);
528
529 fclose(proc);
530 blkid_flush_cache(cache);
531 return 0;
532}
533
534/* Don't use it by default -- it's pretty slow (because cdroms, floppy, ...)
535 */
536static int probe_all_removable(blkid_cache cache)
537{
538 DIR *dir;
539 struct dirent *d;
540
541 if (!cache)
542 return -BLKID_ERR_PARAM;
543
544 dir = opendir(_PATH_SYS_BLOCK);
545 if (!dir)
546 return -BLKID_ERR_PROC;
547
548 while((d = readdir(dir))) {
549 struct sysfs_cxt sysfs = UL_SYSFSCXT_EMPTY;
550 int removable = 0;
551 dev_t devno;
552
553#ifdef _DIRENT_HAVE_D_TYPE
554 if (d->d_type != DT_UNKNOWN && d->d_type != DT_LNK)
555 continue;
556#endif
557 if (d->d_name[0] == '.' &&
558 ((d->d_name[1] == 0) ||
559 ((d->d_name[1] == '.') && (d->d_name[2] == 0))))
560 continue;
561
562 devno = sysfs_devname_to_devno(d->d_name, NULL);
563 if (!devno)
564 continue;
565
566 if (sysfs_init(&sysfs, devno, NULL) == 0) {
bigbiff7b4c7a62015-01-01 19:44:14 -0500567 if (sysfs_read_int(&sysfs, "removable", &removable) != 0)
568 removable = 0;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500569 sysfs_deinit(&sysfs);
570 }
571
572 if (removable)
573 probe_one(cache, d->d_name, devno, 0, 0, 1);
574 }
575
576 closedir(dir);
577 return 0;
578}
579
580
581/**
582 * blkid_probe_all:
583 * @cache: cache handler
584 *
585 * Probes all block devices.
586 *
587 * Returns: 0 on success, or number less than zero in case of error.
588 */
589int blkid_probe_all(blkid_cache cache)
590{
591 int ret;
592
bigbiff7b4c7a62015-01-01 19:44:14 -0500593 DBG(PROBE, ul_debug("Begin blkid_probe_all()"));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500594 ret = probe_all(cache, 0);
595 if (ret == 0) {
596 cache->bic_time = time(0);
597 cache->bic_flags |= BLKID_BIC_FL_PROBED;
598 }
bigbiff7b4c7a62015-01-01 19:44:14 -0500599 DBG(PROBE, ul_debug("End blkid_probe_all() [rc=%d]", ret));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500600 return ret;
601}
602
603/**
604 * blkid_probe_all_new:
605 * @cache: cache handler
606 *
607 * Probes all new block devices.
608 *
609 * Returns: 0 on success, or number less than zero in case of error.
610 */
611int blkid_probe_all_new(blkid_cache cache)
612{
613 int ret;
614
bigbiff7b4c7a62015-01-01 19:44:14 -0500615 DBG(PROBE, ul_debug("Begin blkid_probe_all_new()"));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500616 ret = probe_all(cache, 1);
bigbiff7b4c7a62015-01-01 19:44:14 -0500617 DBG(PROBE, ul_debug("End blkid_probe_all_new() [rc=%d]", ret));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500618 return ret;
619}
620
621/**
622 * blkid_probe_all_removable:
623 * @cache: cache handler
624 *
625 * The libblkid probing is based on devices from /proc/partitions by default.
626 * This file usually does not contain removable devices (e.g. CDROMs) and this kind
627 * of devices are invisible for libblkid.
628 *
629 * This function adds removable block devices to @cache (probing is based on
630 * information from the /sys directory). Don't forget that removable devices
631 * (floppies, CDROMs, ...) could be pretty slow. It's very bad idea to call
632 * this function by default.
633 *
634 * Note that devices which were detected by this function won't be written to
635 * blkid.tab cache file.
636 *
637 * Returns: 0 on success, or number less than zero in case of error.
638 */
639int blkid_probe_all_removable(blkid_cache cache)
640{
641 int ret;
642
bigbiff7b4c7a62015-01-01 19:44:14 -0500643 DBG(PROBE, ul_debug("Begin blkid_probe_all_removable()"));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500644 ret = probe_all_removable(cache);
bigbiff7b4c7a62015-01-01 19:44:14 -0500645 DBG(PROBE, ul_debug("End blkid_probe_all_removable() [rc=%d]", ret));
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500646 return ret;
647}
648
649#ifdef TEST_PROGRAM
650int main(int argc, char **argv)
651{
652 blkid_cache cache = NULL;
653 int ret;
654
bigbiff7b4c7a62015-01-01 19:44:14 -0500655 blkid_init_debug(BLKID_DEBUG_ALL);
bigbiff bigbiffe60683a2013-02-22 20:55:50 -0500656 if (argc != 1) {
657 fprintf(stderr, "Usage: %s\n"
658 "Probe all devices and exit\n", argv[0]);
659 exit(1);
660 }
661 if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
662 fprintf(stderr, "%s: error creating cache (%d)\n",
663 argv[0], ret);
664 exit(1);
665 }
666 if (blkid_probe_all(cache) < 0)
667 printf("%s: error probing devices\n", argv[0]);
668
669 if (blkid_probe_all_removable(cache) < 0)
670 printf("%s: error probing removable devices\n", argv[0]);
671
672 blkid_put_cache(cache);
673 return (0);
674}
675#endif