]> err.no Git - util-linux/commitdiff
libblkid: add samples/topology.c
authorKarel Zak <kzak@redhat.com>
Thu, 30 Jul 2009 08:44:08 +0000 (10:44 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Sep 2009 13:07:07 +0000 (15:07 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
shlibs/blkid/Makefile.am
shlibs/blkid/samples/.gitignore [new file with mode: 0644]
shlibs/blkid/samples/Makefile.am [new file with mode: 0644]
shlibs/blkid/samples/topology.c [new file with mode: 0644]

index 1c914d1935d6611387edefe6aea7d25bd83cabff..68099324140a5785abc6b37888f363307b611a6f 100644 (file)
@@ -923,6 +923,7 @@ shlibs/blkid/Makefile
 shlibs/blkid/src/Makefile
 shlibs/blkid/src/superblocks/Makefile
 shlibs/blkid/src/topology/Makefile
+shlibs/blkid/samples/Makefile
 shlibs/uuid/uuid.pc
 shlibs/uuid/Makefile
 shlibs/uuid/man/Makefile
index a76b1fd8534749cd68fdcd5b2b4b34b4f79da37c..6ad42d8c32dbae82979106af237face93cc0b5ec 100644 (file)
@@ -1,6 +1,6 @@
 include $(top_srcdir)/config/include-Makefile.am
 
-SUBDIRS = src
+SUBDIRS = src samples
 
 # pkg-config stuff
 pkgconfigdir = $(usrlib_execdir)/pkgconfig
diff --git a/shlibs/blkid/samples/.gitignore b/shlibs/blkid/samples/.gitignore
new file mode 100644 (file)
index 0000000..e27df1c
--- /dev/null
@@ -0,0 +1 @@
+topology
diff --git a/shlibs/blkid/samples/Makefile.am b/shlibs/blkid/samples/Makefile.am
new file mode 100644 (file)
index 0000000..3b7de7d
--- /dev/null
@@ -0,0 +1,7 @@
+include $(top_srcdir)/config/include-Makefile.am
+
+AM_CPPFLAGS += -I$(ul_libblkid_srcdir)
+AM_LDFLAGS += $(ul_libblkid_la)
+
+noinst_PROGRAMS = topology
+
diff --git a/shlibs/blkid/samples/topology.c b/shlibs/blkid/samples/topology.c
new file mode 100644 (file)
index 0000000..c031b82
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * 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>
+
+#ifndef TRUE
+# define TRUE 1
+# define FALSE 0
+#endif
+
+int main(int argc, char *argv[])
+{
+       int fd, rc;
+       char *devname;
+       blkid_probe pr;
+       blkid_topology tp;
+
+       if (argc < 2) {
+               fprintf(stderr, "usage: %s <device>  "
+                               "-- prints topology details about the device\n",
+                               program_invocation_short_name);
+               return EXIT_FAILURE;
+       }
+
+       devname = argv[1];
+
+       fd = open(devname, O_RDONLY);
+       if (fd < 0)
+               err(EXIT_FAILURE, "%s: open() failed", devname);
+
+       pr = blkid_new_probe();
+       if (!pr)
+               err(EXIT_FAILURE, "faild to allocate a new libblkid probe");
+
+       if (blkid_probe_set_device(pr, fd, 0, 0) != 0)
+               err(EXIT_FAILURE, "failed to assign device to libblkid probe");
+
+       /*
+        * 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;
+
+               printf("----- NAME=value interface (values: %d):\n", nvals);
+
+               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);
+               }
+       }
+
+       /*
+        * Binary interface
+        */
+       tp = blkid_probe_get_topology(pr);
+       if (tp) {
+               printf("----- binary interface:\n");
+               printf("alignment offset : %lu\n",
+                               blkid_topology_get_alignment_offset(tp));
+               printf("minimum io size  : %lu\n",
+                               blkid_topology_get_minimum_io_size(tp));
+               printf("optimal io size  : %lu\n",
+                               blkid_topology_get_optimal_io_size(tp));
+       }
+
+       return EXIT_SUCCESS;
+}