#include <string.h>
#include <stdlib.h>
#include <stdint.h>
-#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
* 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;
if (!data)
continue;
- rc = set_value(pr, chn, val, data);
+ rc = val->set_result(pr, data);
if (rc)
goto err;
count++;
#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
*/
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
#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