]> err.no Git - util-linux/commitdiff
libblkid: add private blkid_topology_set_*() functions
authorKarel Zak <kzak@redhat.com>
Fri, 18 Sep 2009 11:07:52 +0000 (13:07 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 18 Sep 2009 11:07:52 +0000 (13:07 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/topology/sysfs.c
shlibs/blkid/src/topology/topology.c
shlibs/blkid/src/topology/topology.h

index f4e63a2cb0b446146a0d58468865fcbbf98e6b2a..1fb825e4fcc11be2013ff0d4c6d0e0dc4dc108c8 100644 (file)
@@ -11,7 +11,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <stddef.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -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/<maj>:<min>/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/<maj>:<min>/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++;
index 26930cfa0774d02b856ef98420d8239fed1ce63d..3a636f558324689176c14b6cf0572d1cac4595de 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stddef.h>
 
 #include "topology.h"
 
 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
index ecb28454d090e0bd5a3375c24776047c0f995836..876ae653d3d901ccc1fba89a86dbb20ea0afe62f 100644 (file)
@@ -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