From 8fb4efae6f5fabbe889bebbda60e9f7dce930f1f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 9 Jun 2011 22:04:24 +0200 Subject: build-sys: use top-level directory for libblkid rather than shlibs/blkid Signed-off-by: Karel Zak --- libblkid/samples/.gitignore | 4 ++ libblkid/samples/Makefile.am | 7 ++++ libblkid/samples/mkfs.c | 78 ++++++++++++++++++++++++++++++++++ libblkid/samples/partitions.c | 95 ++++++++++++++++++++++++++++++++++++++++++ libblkid/samples/superblocks.c | 67 +++++++++++++++++++++++++++++ libblkid/samples/topology.c | 86 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 337 insertions(+) create mode 100644 libblkid/samples/.gitignore create mode 100644 libblkid/samples/Makefile.am create mode 100644 libblkid/samples/mkfs.c create mode 100644 libblkid/samples/partitions.c create mode 100644 libblkid/samples/superblocks.c create mode 100644 libblkid/samples/topology.c (limited to 'libblkid/samples') diff --git a/libblkid/samples/.gitignore b/libblkid/samples/.gitignore new file mode 100644 index 000000000..409e5cff7 --- /dev/null +++ b/libblkid/samples/.gitignore @@ -0,0 +1,4 @@ +topology +partitions +mkfs +superblocks diff --git a/libblkid/samples/Makefile.am b/libblkid/samples/Makefile.am new file mode 100644 index 000000000..93588d57d --- /dev/null +++ b/libblkid/samples/Makefile.am @@ -0,0 +1,7 @@ +include $(top_srcdir)/config/include-Makefile.am + +AM_CPPFLAGS += -I$(ul_libblkid_incdir) +AM_LDFLAGS += $(ul_libblkid_la) + +noinst_PROGRAMS = topology partitions mkfs superblocks + diff --git a/libblkid/samples/mkfs.c b/libblkid/samples/mkfs.c new file mode 100644 index 000000000..5c3ebe79e --- /dev/null +++ b/libblkid/samples/mkfs.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2009 Karel Zak + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "c.h" + +int main(int argc, char *argv[]) +{ + int rc; + char *devname; + blkid_probe pr; + blkid_topology tp; + + if (argc < 2) { + fprintf(stderr, "usage: %s " + "-- checks based on libblkid for mkfs-like programs.\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); + + /* + * check Filesystems / Partitions overwrite + */ + + /* enable partitions probing (superblocks are enabled by default) */ + blkid_probe_enable_partitions(pr, TRUE); + + rc = blkid_do_fullprobe(pr); + if (rc == -1) + errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname); + else if (rc == 0) { + const char *type; + + if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) + errx(EXIT_FAILURE, "%s: appears to contain an existing " + "%s superblock", devname, type); + + if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL)) + errx(EXIT_FAILURE, "%s: appears to contain an partition " + "table (%s)", devname, type); + } + + /* + * get topology details + */ + tp = blkid_probe_get_topology(pr); + if (!tp) + errx(EXIT_FAILURE, "%s: failed to read topology", devname); + + + /* ... your mkfs. code or so ... + + off = blkid_topology_get_alignment_offset(tp); + + */ + + blkid_free_probe(pr); + + return EXIT_SUCCESS; +} diff --git a/libblkid/samples/partitions.c b/libblkid/samples/partitions.c new file mode 100644 index 000000000..3b5273649 --- /dev/null +++ b/libblkid/samples/partitions.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2009 Karel Zak + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include "c.h" + +int main(int argc, char *argv[]) +{ + int i, nparts; + char *devname; + blkid_probe pr; + blkid_partlist ls; + blkid_parttable root_tab; + + if (argc < 2) { + fprintf(stderr, "usage: %s " + "-- prints partitions\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); + /* Binary interface */ + ls = blkid_probe_get_partitions(pr); + if (!ls) + errx(EXIT_FAILURE, "%s: failed to read partitions\n", devname); + + /* + * Print info about the primary (root) partition table + */ + root_tab = blkid_partlist_get_table(ls); + if (!root_tab) + errx(EXIT_FAILURE, "%s: does not contains any " + "known partition table\n", devname); + + printf("size: %jd, sector size: %u, PT: %s, offset: %jd\n---\n", + blkid_probe_get_size(pr), + blkid_probe_get_sectorsize(pr), + blkid_parttable_get_type(root_tab), + blkid_parttable_get_offset(root_tab)); + + /* + * List partitions + */ + nparts = blkid_partlist_numof_partitions(ls); + if (!nparts) + goto done; + + for (i = 0; i < nparts; i++) { + const char *p; + blkid_partition par = blkid_partlist_get_partition(ls, i); + blkid_parttable tab = blkid_partition_get_table(par); + + printf("#%d: %10llu %10llu 0x%x", + blkid_partition_get_partno(par), + (unsigned long long) blkid_partition_get_start(par), + (unsigned long long) blkid_partition_get_size(par), + blkid_partition_get_type(par)); + + if (root_tab != tab) + /* subpartition (BSD, Minix, ...) */ + printf(" (%s)", blkid_parttable_get_type(tab)); + + p = blkid_partition_get_name(par); + if (p) + printf(" name='%s'", p); + p = blkid_partition_get_uuid(par); + if (p) + printf(" uuid='%s'", p); + p = blkid_partition_get_type_string(par); + if (p) + printf(" type='%s'", p); + + putc('\n', stdout); + } + +done: + blkid_free_probe(pr); + return EXIT_SUCCESS; +} diff --git a/libblkid/samples/superblocks.c b/libblkid/samples/superblocks.c new file mode 100644 index 000000000..20e39c97e --- /dev/null +++ b/libblkid/samples/superblocks.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 Karel Zak + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "c.h" + +int main(int argc, char *argv[]) +{ + int rc; + char *devname; + blkid_probe pr; + + if (argc < 2) { + fprintf(stderr, "usage: %s " + "-- 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; +} diff --git a/libblkid/samples/topology.c b/libblkid/samples/topology.c new file mode 100644 index 000000000..de1c3a5e3 --- /dev/null +++ b/libblkid/samples/topology.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009 Karel Zak + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "c.h" + +int main(int argc, char *argv[]) +{ + int rc; + char *devname; + blkid_probe pr; + blkid_topology tp; + + if (argc < 2) { + fprintf(stderr, "usage: %s " + "-- prints topology 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); + /* + * Binary interface + */ + tp = blkid_probe_get_topology(pr); + if (tp) { + printf("----- binary interface:\n"); + printf("\talignment offset : %lu\n", + blkid_topology_get_alignment_offset(tp)); + printf("\tminimum io size : %lu\n", + blkid_topology_get_minimum_io_size(tp)); + printf("\toptimal io size : %lu\n", + blkid_topology_get_optimal_io_size(tp)); + printf("\tlogical sector size : %lu\n", + blkid_topology_get_logical_sector_size(tp)); + printf("\tphysical sector size : %lu\n", + blkid_topology_get_physical_sector_size(tp)); + } + + /* + * NAME=value interface + */ + + /* enable topology probing */ + blkid_probe_enable_topology(pr, TRUE); + + /* disable superblocks probing (enabled by default) */ + blkid_probe_enable_superblocks(pr, FALSE); + + rc = blkid_do_fullprobe(pr); + if (rc == -1) + errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname); + else if (rc == 1) + warnx("%s: missing topology information", devname); + else { + int i, nvals = blkid_probe_numof_values(pr); + + printf("----- NAME=value interface (values: %d):\n", nvals); + + 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; +} -- cgit v1.2.3-55-g7522