]> err.no Git - util-linux/commitdiff
libblkid: add support for topology ioctls
authorKarel Zak <kzak@redhat.com>
Mon, 19 Oct 2009 13:33:00 +0000 (15:33 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Oct 2009 13:33:00 +0000 (15:33 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/topology/Makefile.am
shlibs/blkid/src/topology/ioctl.c [new file with mode: 0644]
shlibs/blkid/src/topology/topology.c
shlibs/blkid/src/topology/topology.h

index 05a8ac9f249192a614329579916f5911208fb629..c0c3a9f6235a00a3cae9de5a778fe8de340ba9fc 100644 (file)
@@ -6,6 +6,7 @@ libblkid_topology_la_LIBADD =
 noinst_LTLIBRARIES = libblkid_topology.la
 libblkid_topology_la_SOURCES = topology.c \
                                topology.h \
+                               ioctl.c \
                                sysfs.c \
                                md.c \
                                dm.c \
diff --git a/shlibs/blkid/src/topology/ioctl.c b/shlibs/blkid/src/topology/ioctl.c
new file mode 100644 (file)
index 0000000..962b58a
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * ioctl based topology -- gathers topology information
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "blkdev.h"            /* top-level lib/ */
+#include "topology.h"
+
+/*
+ * ioctl topology values
+ */
+static struct topology_val {
+
+       long  ioc;
+
+       /* function to set probing resut */
+       int (*set_result)(blkid_probe, unsigned long);
+
+} topology_vals[] = {
+       { BLKALIGNOFF, blkid_topology_set_alignment_offset },
+       { BLKIOMIN, blkid_topology_set_minimum_io_size },
+       { BLKIOOPT, blkid_topology_set_optimal_io_size },
+};
+
+static int probe_ioctl_tp(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       int i;
+       int count = 0;
+
+       for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
+               struct topology_val *val = &topology_vals[i];
+               unsigned int data;
+               int rc;
+
+               if (ioctl(pr->fd, val->ioc, &data) == -1)
+                       goto nothing;
+               rc = val->set_result(pr, (unsigned long) data);
+               if (rc)
+                       goto err;
+               count++;
+       }
+
+       if (count)
+               return 0;
+nothing:
+       return 1;
+err:
+       return -1;
+}
+
+const struct blkid_idinfo ioctl_tp_idinfo =
+{
+       .name           = "ioctl",
+       .probefunc      = probe_ioctl_tp,
+       .magics         = BLKID_NONE_MAGIC
+};
+
index 072261f395cb301632ccfcfa16d8fda490ee460d..32d800f4458cd5ce6182d181c3843a25484034a9 100644 (file)
@@ -59,6 +59,7 @@ struct blkid_struct_topology {
  */
 static const struct blkid_idinfo *idinfos[] =
 {
+       &ioctl_tp_idinfo,
        &sysfs_tp_idinfo,
        &md_tp_idinfo,
        &dm_tp_idinfo,
index 98321394e8947b9455ac2c27c972a535b629e06f..fc3fb7340d0b2247750d53e57928098d5ebd6197 100644 (file)
@@ -10,6 +10,7 @@ extern int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val)
 /*
  * topology probers
  */
+extern const struct blkid_idinfo ioctl_tp_idinfo;
 extern const struct blkid_idinfo sysfs_tp_idinfo;
 extern const struct blkid_idinfo md_tp_idinfo;
 extern const struct blkid_idinfo dm_tp_idinfo;