From: Karel Zak Date: Fri, 30 Oct 2009 11:08:01 +0000 (+0100) Subject: libblkid: topology - add logical and physical sector size X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c3ceac607b3c7c2acef596fa0ffcaaa64bc6d0e;p=util-linux libblkid: topology - add logical and physical sector size Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/docs/libblkid-sections.txt b/shlibs/blkid/docs/libblkid-sections.txt index 8f643d8b..c8b0045d 100644 --- a/shlibs/blkid/docs/libblkid-sections.txt +++ b/shlibs/blkid/docs/libblkid-sections.txt @@ -117,8 +117,10 @@ blkid_probe_enable_topology blkid_probe_get_topology blkid_topology_get_alignment_offset +blkid_topology_get_logical_sector_size blkid_topology_get_minimum_io_size blkid_topology_get_optimal_io_size +blkid_topology_get_physical_sector_size
diff --git a/shlibs/blkid/samples/topology.c b/shlibs/blkid/samples/topology.c index 4adaa31a..e73cd9e4 100644 --- a/shlibs/blkid/samples/topology.c +++ b/shlibs/blkid/samples/topology.c @@ -42,12 +42,16 @@ int main(int argc, char *argv[]) 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)); } /* diff --git a/shlibs/blkid/src/blkid.sym b/shlibs/blkid/src/blkid.sym index 992d4e9f..97255526 100644 --- a/shlibs/blkid/src/blkid.sym +++ b/shlibs/blkid/src/blkid.sym @@ -109,6 +109,8 @@ global: blkid_probe_set_partitions_flags; blkid_probe_set_superblocks_flags; blkid_topology_get_alignment_offset; + blkid_topology_get_logical_sector_size; blkid_topology_get_minimum_io_size; blkid_topology_get_optimal_io_size; + blkid_topology_get_physical_sector_size; } BLKID_2.15; diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index 0cad69c0..6e9c21e8 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -116,7 +116,7 @@ struct blkid_chaindrv { #define BLKID_PROBVAL_BUFSIZ 64 #define BLKID_NVALS_SUBLKS 14 -#define BLKID_NVALS_TOPLGY 3 +#define BLKID_NVALS_TOPLGY 5 #define BLKID_NVALS_PARTS 1 /* Max number of all values in probing result */ diff --git a/shlibs/blkid/src/topology/ioctl.c b/shlibs/blkid/src/topology/ioctl.c index 962b58ac..709b2f45 100644 --- a/shlibs/blkid/src/topology/ioctl.c +++ b/shlibs/blkid/src/topology/ioctl.c @@ -33,6 +33,8 @@ static struct topology_val { { BLKALIGNOFF, blkid_topology_set_alignment_offset }, { BLKIOMIN, blkid_topology_set_minimum_io_size }, { BLKIOOPT, blkid_topology_set_optimal_io_size }, + { BLKPBSZGET, blkid_topology_set_physical_sector_size } + /* we read BLKSSZGET in topology.c */ }; static int probe_ioctl_tp(blkid_probe pr, const struct blkid_idmag *mag) diff --git a/shlibs/blkid/src/topology/sysfs.c b/shlibs/blkid/src/topology/sysfs.c index 1fb825e4..20c507f1 100644 --- a/shlibs/blkid/src/topology/sysfs.c +++ b/shlibs/blkid/src/topology/sysfs.c @@ -6,6 +6,7 @@ * 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 #include @@ -78,7 +79,7 @@ err: } /* - * Sysfs topology values + * Sysfs topology values (since 2.6.31, May 2009). */ static struct topology_val { @@ -92,6 +93,7 @@ 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) diff --git a/shlibs/blkid/src/topology/topology.c b/shlibs/blkid/src/topology/topology.c index d1fb86f5..db97c5fb 100644 --- a/shlibs/blkid/src/topology/topology.c +++ b/shlibs/blkid/src/topology/topology.c @@ -27,6 +27,13 @@ * 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. * @@ -44,6 +51,8 @@ */ 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 @@ -52,6 +61,8 @@ struct blkid_struct_topology { unsigned long alignment_offset; unsigned long minimum_io_size; unsigned long optimal_io_size; + unsigned long logical_sector_size; + unsigned long physical_sector_size; }; /* @@ -173,6 +184,12 @@ static int topology_probe(blkid_probe pr, struct blkid_chain *chn) 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)); @@ -207,6 +224,24 @@ static int topology_set_value(blkid_probe pr, const char *name, 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, @@ -231,6 +266,30 @@ int blkid_topology_set_optimal_io_size(blkid_probe pr, unsigned long val) 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 @@ -264,3 +323,25 @@ unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp) 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; +} + diff --git a/shlibs/blkid/src/topology/topology.h b/shlibs/blkid/src/topology/topology.h index fc3fb734..d4879204 100644 --- a/shlibs/blkid/src/topology/topology.h +++ b/shlibs/blkid/src/topology/topology.h @@ -6,6 +6,7 @@ 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); +extern int blkid_topology_set_physical_sector_size(blkid_probe pr, unsigned long val); /* * topology probers