tp = blkid_probe_get_topology(pr);
if (tp) {
printf("----- binary interface:\n");
- printf("\talignment offset : %lu\n",
+ printf("\talignment offset : %lu\n",
blkid_topology_get_alignment_offset(tp));
- printf("\tminimum io size : %lu\n",
+ printf("\tminimum io size : %lu\n",
blkid_topology_get_minimum_io_size(tp));
- printf("\toptimal io size : %lu\n",
+ printf("\toptimal io size : %lu\n",
blkid_topology_get_optimal_io_size(tp));
+ printf("\tlogical sector size : %lu\n",
+ blkid_topology_get_logical_sector_size(tp));
+ printf("\tphysical sector size : %lu\n",
+ blkid_topology_get_physical_sector_size(tp));
}
/*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License.
*
+ * For more information see Linux kernel Documentation/ABI/testing/sysfs-block.
*/
#include <stdio.h>
#include <string.h>
}
/*
- * Sysfs topology values
+ * Sysfs topology values (since 2.6.31, May 2009).
*/
static struct topology_val {
{ "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 },
+ { "queue/physical_block_size", blkid_topology_set_physical_sector_size },
};
static int probe_sysfs_tp(blkid_probe pr, const struct blkid_idmag *mag)
* NAME=value (tags) interface is enabled by blkid_probe_enable_topology(),
* and provides:
*
+ * @LOGICAL_SECTOR_SIZE: this is the smallest unit the storage device can
+ * address. It is typically 512 bytes.
+ *
+ * @PHYSICAL_SECTOR_SIZE: this is the smallest unit a physical storage device
+ * can write atomically. It is usually the same as the
+ * logical sector size but may be bigger.
+ *
* @MINIMUM_IO_SIZE: minimum size which is the device's preferred unit of I/O.
* For RAID arrays it is often the stripe chunk size.
*
*/
static int topology_probe(blkid_probe pr, struct blkid_chain *chn);
static void topology_free(blkid_probe pr, void *data);
+static int topology_is_complete(blkid_probe pr);
+static int topology_set_logical_sector_size(blkid_probe pr);
/*
* Binary interface
unsigned long alignment_offset;
unsigned long minimum_io_size;
unsigned long optimal_io_size;
+ unsigned long logical_sector_size;
+ unsigned long physical_sector_size;
};
/*
continue;
}
+ if (!topology_is_complete(pr))
+ continue;
+
+ /* generic for all probing drivers */
+ topology_set_logical_sector_size(pr);
+
DBG(DEBUG_LOWPROBE,
printf("<-- leaving probing loop (type=%s) [TOPOLOGY idx=%d]\n",
id->name, chn->idx));
return blkid_probe_sprintf_value(pr, name, "%llu", data);
}
+/* the topology info is complete when we have at least "minimum_io_size" which
+ * is provides by all blkid topology drivers */
+static int topology_is_complete(blkid_probe pr)
+{
+ struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+ if (!chn)
+ return FALSE;
+
+ if (chn->binary && chn->data) {
+ blkid_topology tp = (blkid_topology) chn->data;
+ if (tp->minimum_io_size)
+ return TRUE;
+ }
+
+ return __blkid_probe_lookup_value(pr, "MINIMUM_IO_SIZE") ? TRUE : FALSE;
+}
+
int blkid_topology_set_alignment_offset(blkid_probe pr, unsigned long val)
{
return topology_set_value(pr,
val);
}
+/* BLKSSZGET is provided on all systems since 2.3.3 -- so we don't have to
+ * waste time with sysfs or or.
+ */
+static int topology_set_logical_sector_size(blkid_probe pr)
+{
+ unsigned long val = blkid_probe_get_sectorsize(pr);
+
+ if (!val)
+ return -1;
+
+ return topology_set_value(pr,
+ "LOGICAL_SECTOR_SIZE",
+ offsetof(struct blkid_struct_topology, logical_sector_size),
+ val);
+}
+
+int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val)
+{
+ return topology_set_value(pr,
+ "PHYSICAL_SECTOR_SIZE",
+ offsetof(struct blkid_struct_topology, physical_sector_size),
+ val);
+}
+
/**
* blkid_topology_get_alignment_offset:
* @tp: topology
return tp ? tp->optimal_io_size : 0;
}
+/**
+ * blkid_topology_get_logical_sector_size
+ * @tp: topology
+ *
+ * Returns: logical sector size (BLKSSZGET ioctl) in bytes or 0.
+ */
+unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
+{
+ return tp ? tp->logical_sector_size : 0;
+}
+
+/**
+ * blkid_topology_get_physical_sector_size
+ * @tp: topology
+ *
+ * Returns: logical sector size (BLKSSZGET ioctl) in bytes or 0.
+ */
+unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
+{
+ return tp ? tp->physical_sector_size : 0;
+}
+