diff options
author | Karel Zak <kzak@redhat.com> | 2009-10-19 15:33:00 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2009-10-19 15:33:00 +0200 |
commit | 58cde6ce4143d1852696e96e588079b700b557e0 (patch) | |
tree | 8fe135d59b64c56c862abc13db4de649d0bdde77 | |
parent | 5e51568e144746ab5821b43d9991c208189fbbb8 (diff) | |
download | util-linux-old-58cde6ce4143d1852696e96e588079b700b557e0.tar.gz |
libblkid: add support for topology ioctls
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | shlibs/blkid/src/topology/Makefile.am | 1 | ||||
-rw-r--r-- | shlibs/blkid/src/topology/ioctl.c | 70 | ||||
-rw-r--r-- | shlibs/blkid/src/topology/topology.c | 1 | ||||
-rw-r--r-- | shlibs/blkid/src/topology/topology.h | 1 |
4 files changed, 73 insertions, 0 deletions
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 <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 +}; + 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; |