2
* sysfs based topology -- gathers topology information from Linux sysfs
4
* Copyright (C) 2009 Karel Zak <kzak@redhat.com>
6
* This file may be redistributed under the terms of the
7
* GNU Lesser General Public License.
9
* For more information see Linux kernel Documentation/ABI/testing/sysfs-block.
15
#include <sys/types.h>
23
* Sysfs topology values (since 2.6.31, May 2009).
25
static struct topology_val {
27
/* /sys/dev/block/<maj>:<min>/<ATTR> */
30
/* functions to set probing resut */
31
int (*set_ulong)(blkid_probe, unsigned long);
32
int (*set_int)(blkid_probe, int);
35
{ "alignment_offset", NULL, blkid_topology_set_alignment_offset },
36
{ "queue/minimum_io_size", blkid_topology_set_minimum_io_size },
37
{ "queue/optimal_io_size", blkid_topology_set_optimal_io_size },
38
{ "queue/physical_block_size", blkid_topology_set_physical_sector_size },
41
static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag)
43
dev_t dev, pri_dev = 0;
46
dev = blkid_probe_get_devno(pr);
48
goto nothing; /* probably not a block device */
50
for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
51
struct topology_val *val = &topology_vals[i];
55
if (!blkid_devno_has_attribute(dev, val->attr)) {
56
/* get attribute from partition's primary device */
58
blkid_devno_to_wholedisk(dev, NULL, 0, &pri_dev))
66
if (blkid_devno_get_u64_attribute(attr_dev,
69
rc = val->set_ulong(pr, (unsigned long) data);
71
} else if (val->set_int) {
74
if (blkid_devno_get_s64_attribute(attr_dev,
77
rc = val->set_int(pr, (int) data);
93
const struct blkid_idinfo sysfs_tp_idinfo =
96
.probefunc = probe_sysfs_tp,
97
.magics = BLKID_NONE_MAGIC