From: Karel Zak Date: Fri, 18 Sep 2009 11:07:52 +0000 (+0200) Subject: libblkid: add private blkid_topology_set_*() functions X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4747be18976da4f7c5bd17fe478d87fc02b4e6c3;p=util-linux libblkid: add private blkid_topology_set_*() functions Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/topology/sysfs.c b/shlibs/blkid/src/topology/sysfs.c index f4e63a2c..1fb825e4 100644 --- a/shlibs/blkid/src/topology/sysfs.c +++ b/shlibs/blkid/src/topology/sysfs.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -82,45 +81,28 @@ err: * Sysfs topology values */ static struct topology_val { - const char *val_name; /* NAME=value */ - const char *sysfs_name; /* /sys/dev/block/:/NAME */ - const size_t bin_offset; /* blkid_struct_topology member */ -} topology_vals[] = { - { "ALIGNMENT_OFFSET", "alignment_offset", - offsetof(struct blkid_struct_topology, alignment_offset) }, - { "MINIMUM_IO_SIZE", "queue/minimum_io_size", - offsetof(struct blkid_struct_topology, minimum_io_size) }, - {"OPTIMAL_IO_SIZE", "queue/optimal_io_size", - offsetof(struct blkid_struct_topology, optimal_io_size) } -}; -static int set_value(blkid_probe pr, struct blkid_chain *chn, - struct topology_val *val, unsigned long data) -{ - if (chn->binary) { - unsigned long *v = - (unsigned long *) (chn->data + val->bin_offset); - *v = data; - return 0; - } - return blkid_probe_sprintf_value(pr, val->val_name, "%llu", data); -} + /* /sys/dev/block/:/NAME */ + const char *sysfs_name; + /* function to set probing resut */ + int (*set_result)(blkid_probe, unsigned long); + +} topology_vals[] = { + { "alignment_offset", blkid_topology_set_alignment_offset }, + { "queue/minimum_io_size", blkid_topology_set_minimum_io_size }, + { "queue/optimal_io_size", blkid_topology_set_optimal_io_size }, +}; static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag) { dev_t dev, pri_dev = 0; int i, rc = 0, count = 0; - struct blkid_chain *chn; dev = blkid_probe_get_devno(pr); if (!dev) goto nothing; /* probably not a block device */ - chn = blkid_probe_get_chain(pr); - if (!chn) - goto err; - for (i = 0; i < ARRAY_SIZE(topology_vals); i++) { struct topology_val *val = &topology_vals[i]; unsigned long data; @@ -133,7 +115,7 @@ static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag) if (!data) continue; - rc = set_value(pr, chn, val, data); + rc = val->set_result(pr, data); if (rc) goto err; count++; diff --git a/shlibs/blkid/src/topology/topology.c b/shlibs/blkid/src/topology/topology.c index 26930cfa..3a636f55 100644 --- a/shlibs/blkid/src/topology/topology.c +++ b/shlibs/blkid/src/topology/topology.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "topology.h" @@ -42,6 +43,15 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn); static void topology_free(blkid_probe pr, void *data); +/* + * Binary interface + */ +struct blkid_struct_topology { + unsigned long alignment_offset; + unsigned long minimum_io_size; + unsigned long optimal_io_size; +}; + /* * Topology chain probing functions */ @@ -164,6 +174,47 @@ static void topology_free(blkid_probe pr, void *data) free(data); } +static int topology_set_value(blkid_probe pr, const char *name, + size_t structoff, unsigned long data) +{ + struct blkid_chain *chn = blkid_probe_get_chain(pr); + + if (!chn) + return -1; + + if (chn->binary) { + unsigned long *v = + (unsigned long *) (chn->data + structoff); + *v = data; + return 0; + } + return blkid_probe_sprintf_value(pr, name, "%llu", data); +} + +int blkid_topology_set_alignment_offset(blkid_probe pr, unsigned long val) +{ + return topology_set_value(pr, + "ALIGNMENT_OFFSET", + offsetof(struct blkid_struct_topology, alignment_offset), + val); +} + +int blkid_topology_set_minimum_io_size(blkid_probe pr, unsigned long val) +{ + return topology_set_value(pr, + "MINIMUM_IO_SIZE", + offsetof(struct blkid_struct_topology, minimum_io_size), + val); +} + +int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val) +{ + return topology_set_value(pr, + "OPTIMAL_IO_SIZE", + offsetof(struct blkid_struct_topology, optimal_io_size), + val); +} + /** * blkid_topology_get_alignment_offset: * @tp: topology diff --git a/shlibs/blkid/src/topology/topology.h b/shlibs/blkid/src/topology/topology.h index ecb28454..876ae653 100644 --- a/shlibs/blkid/src/topology/topology.h +++ b/shlibs/blkid/src/topology/topology.h @@ -3,14 +3,9 @@ #include "blkidP.h" -/* - * Binary interface - */ -struct blkid_struct_topology { - unsigned long alignment_offset; - unsigned long minimum_io_size; - unsigned long optimal_io_size; -}; +extern int blkid_topology_set_alignment_offset(blkid_probe pr, unsigned long val); +extern int blkid_topology_set_minimum_io_size(blkid_probe pr, unsigned long val); +extern int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val); /* * topology probers