~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/blkid/samples/superblocks.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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 <err.h>
14
 
#include <errno.h>
15
 
 
16
 
#include <blkid.h>
17
 
 
18
 
#include "c.h"
19
 
 
20
 
int main(int argc, char *argv[])
21
 
{
22
 
        int rc;
23
 
        char *devname;
24
 
        blkid_probe pr;
25
 
 
26
 
        if (argc < 2) {
27
 
                fprintf(stderr, "usage: %s <device>  "
28
 
                                "-- prints superblocks details about the device\n",
29
 
                                program_invocation_short_name);
30
 
                return EXIT_FAILURE;
31
 
        }
32
 
 
33
 
        devname = argv[1];
34
 
        pr = blkid_new_probe_from_filename(devname);
35
 
        if (!pr)
36
 
                err(EXIT_FAILURE, "%s: faild to create a new libblkid probe",
37
 
                                devname);
38
 
 
39
 
        /* enable topology probing */
40
 
        blkid_probe_enable_superblocks(pr, TRUE);
41
 
 
42
 
        /* set all flags */
43
 
        blkid_probe_set_superblocks_flags(pr,
44
 
                        BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW |
45
 
                        BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
46
 
                        BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
47
 
                        BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
48
 
                        BLKID_SUBLKS_MAGIC);
49
 
 
50
 
        rc = blkid_do_safeprobe(pr);
51
 
        if (rc == -1)
52
 
                errx(EXIT_FAILURE, "%s: blkid_do_safeprobe() failed", devname);
53
 
        else if (rc == 1)
54
 
                warnx("%s: cannot gather information about superblocks", devname);
55
 
        else {
56
 
                int i, nvals = blkid_probe_numof_values(pr);
57
 
 
58
 
                for (i = 0; i < nvals; i++) {
59
 
                        const char *name, *data;
60
 
 
61
 
                        blkid_probe_get_value(pr, i, &name, &data, NULL);
62
 
                        printf("\t%s = %s\n", name, data);
63
 
                }
64
 
        }
65
 
 
66
 
        blkid_free_probe(pr);
67
 
        return EXIT_SUCCESS;
68
 
}