blob: 20e39c97ef142d1bbfa435eac39744a156b694f1 [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001/*
2 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <errno.h>
14
15#include <blkid.h>
16
17#include "c.h"
18
19int main(int argc, char *argv[])
20{
21 int rc;
22 char *devname;
23 blkid_probe pr;
24
25 if (argc < 2) {
26 fprintf(stderr, "usage: %s <device> "
27 "-- prints superblocks details about the device\n",
28 program_invocation_short_name);
29 return EXIT_FAILURE;
30 }
31
32 devname = argv[1];
33 pr = blkid_new_probe_from_filename(devname);
34 if (!pr)
35 err(EXIT_FAILURE, "%s: faild to create a new libblkid probe",
36 devname);
37
38 /* enable topology probing */
39 blkid_probe_enable_superblocks(pr, TRUE);
40
41 /* set all flags */
42 blkid_probe_set_superblocks_flags(pr,
43 BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW |
44 BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
45 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
46 BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
47 BLKID_SUBLKS_MAGIC);
48
49 rc = blkid_do_safeprobe(pr);
50 if (rc == -1)
51 errx(EXIT_FAILURE, "%s: blkid_do_safeprobe() failed", devname);
52 else if (rc == 1)
53 warnx("%s: cannot gather information about superblocks", devname);
54 else {
55 int i, nvals = blkid_probe_numof_values(pr);
56
57 for (i = 0; i < nvals; i++) {
58 const char *name, *data;
59
60 blkid_probe_get_value(pr, i, &name, &data, NULL);
61 printf("\t%s = %s\n", name, data);
62 }
63 }
64
65 blkid_free_probe(pr);
66 return EXIT_SUCCESS;
67}