diff options
author | Karel Zak | 2009-11-02 14:59:23 +0100 |
---|---|---|
committer | Karel Zak | 2009-11-02 14:59:23 +0100 |
commit | 949130cbdfa8fd2db80940227b1c4a03c50a29aa (patch) | |
tree | 25fbe2196a48d653462bf5ac878535639e18ffdd /shlibs | |
parent | libblkid: add sector size funcs to blkid.h.in (diff) | |
download | kernel-qcow2-util-linux-949130cbdfa8fd2db80940227b1c4a03c50a29aa.tar.gz kernel-qcow2-util-linux-949130cbdfa8fd2db80940227b1c4a03c50a29aa.tar.xz kernel-qcow2-util-linux-949130cbdfa8fd2db80940227b1c4a03c50a29aa.zip |
libblkid: add superblocks.c sample
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs')
-rw-r--r-- | shlibs/blkid/samples/.gitignore | 1 | ||||
-rw-r--r-- | shlibs/blkid/samples/Makefile.am | 2 | ||||
-rw-r--r-- | shlibs/blkid/samples/superblocks.c | 68 |
3 files changed, 70 insertions, 1 deletions
diff --git a/shlibs/blkid/samples/.gitignore b/shlibs/blkid/samples/.gitignore index 5ee573935..409e5cff7 100644 --- a/shlibs/blkid/samples/.gitignore +++ b/shlibs/blkid/samples/.gitignore @@ -1,3 +1,4 @@ topology partitions mkfs +superblocks diff --git a/shlibs/blkid/samples/Makefile.am b/shlibs/blkid/samples/Makefile.am index cca01de0d..f7458616c 100644 --- a/shlibs/blkid/samples/Makefile.am +++ b/shlibs/blkid/samples/Makefile.am @@ -3,5 +3,5 @@ include $(top_srcdir)/config/include-Makefile.am AM_CPPFLAGS += -I$(ul_libblkid_srcdir) AM_LDFLAGS += $(ul_libblkid_la) -noinst_PROGRAMS = topology partitions mkfs +noinst_PROGRAMS = topology partitions mkfs superblocks diff --git a/shlibs/blkid/samples/superblocks.c b/shlibs/blkid/samples/superblocks.c new file mode 100644 index 000000000..276c29e6f --- /dev/null +++ b/shlibs/blkid/samples/superblocks.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009 Karel Zak <kzak@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <err.h> +#include <errno.h> + +#include <blkid.h> + +#include "c.h" + +int main(int argc, char *argv[]) +{ + int rc; + char *devname; + blkid_probe pr; + + if (argc < 2) { + fprintf(stderr, "usage: %s <device> " + "-- prints superblocks details about the device\n", + program_invocation_short_name); + return EXIT_FAILURE; + } + + devname = argv[1]; + pr = blkid_new_probe_from_filename(devname); + if (!pr) + err(EXIT_FAILURE, "%s: faild to create a new libblkid probe", + devname); + + /* enable topology probing */ + blkid_probe_enable_superblocks(pr, TRUE); + + /* set all flags */ + blkid_probe_set_superblocks_flags(pr, + BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW | + BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW | + BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE | + BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION | + BLKID_SUBLKS_MAGIC); + + rc = blkid_do_safeprobe(pr); + if (rc == -1) + errx(EXIT_FAILURE, "%s: blkid_do_safeprobe() failed", devname); + else if (rc == 1) + warnx("%s: cannot gather information about superblocks", devname); + else { + int i, nvals = blkid_probe_numof_values(pr); + + for (i = 0; i < nvals; i++) { + const char *name, *data; + + blkid_probe_get_value(pr, i, &name, &data, NULL); + printf("\t%s = %s\n", name, data); + } + } + + blkid_free_probe(pr); + return EXIT_SUCCESS; +} |