From 58cde6ce4143d1852696e96e588079b700b557e0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 19 Oct 2009 15:33:00 +0200 Subject: [PATCH] libblkid: add support for topology ioctls Signed-off-by: Karel Zak --- shlibs/blkid/src/topology/Makefile.am | 1 + shlibs/blkid/src/topology/ioctl.c | 70 +++++++++++++++++++++++++++ shlibs/blkid/src/topology/topology.c | 1 + shlibs/blkid/src/topology/topology.h | 1 + 4 files changed, 73 insertions(+) create mode 100644 shlibs/blkid/src/topology/ioctl.c diff --git a/shlibs/blkid/src/topology/Makefile.am b/shlibs/blkid/src/topology/Makefile.am index 05a8ac9f..c0c3a9f6 100644 --- a/shlibs/blkid/src/topology/Makefile.am +++ b/shlibs/blkid/src/topology/Makefile.am @@ -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 index 00000000..962b58ac --- /dev/null +++ b/shlibs/blkid/src/topology/ioctl.c @@ -0,0 +1,70 @@ +/* + * ioctl based topology -- gathers topology information + * + * 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 + +#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 +}; + diff --git a/shlibs/blkid/src/topology/topology.c b/shlibs/blkid/src/topology/topology.c index 072261f3..32d800f4 100644 --- a/shlibs/blkid/src/topology/topology.c +++ b/shlibs/blkid/src/topology/topology.c @@ -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, diff --git a/shlibs/blkid/src/topology/topology.h b/shlibs/blkid/src/topology/topology.h index 98321394..fc3fb734 100644 --- a/shlibs/blkid/src/topology/topology.h +++ b/shlibs/blkid/src/topology/topology.h @@ -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; -- 2.39.5