From df68ccd8b8354a84e57469a498997ab50aaa5dd3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 6 Jun 2012 11:03:23 +0200 Subject: [PATCH] fdisk: fix io_size usage in new API properly implemented fdisk_dev_has_topology() requires optimal I/O size to detect that the device provides topology. Unfortunately, currently used cxt->io_size maybe overwritten in __discover_topology() to min_io_size. This patch introduces cxt->optimal_io_size and keeps it independent on cxt->io_size. The cxt->io_size is I/O size used by fdisk for alignment calculation. Signed-off-by: Karel Zak --- fdisk/fdisk.h | 9 +++++---- fdisk/utils.c | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index d5d66d3cfc..c645b24d55 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -107,10 +107,11 @@ struct fdisk_context { char *dev_path; /* device path */ /* topology */ - unsigned long io_size; - unsigned long min_io_size; - unsigned long phy_sector_size; /* physical size */ - unsigned long sector_size; /* logical size */ + unsigned long io_size; /* I/O size used by fdisk */ + unsigned long optimal_io_size; /* optional I/O returned by device */ + unsigned long min_io_size; /* minimal I/O size */ + unsigned long phy_sector_size; /* physical size */ + unsigned long sector_size; /* logical size */ unsigned long alignment_offset; /* geometry */ diff --git a/fdisk/utils.c b/fdisk/utils.c index 4d838412c8..352a9346b1 100644 --- a/fdisk/utils.c +++ b/fdisk/utils.c @@ -61,10 +61,12 @@ static int __discover_topology(struct fdisk_context *cxt) if (tp) { cxt->min_io_size = blkid_topology_get_minimum_io_size(tp); - cxt->io_size = blkid_topology_get_optimal_io_size(tp); + cxt->optimal_io_size = blkid_topology_get_optimal_io_size(tp); cxt->phy_sector_size = blkid_topology_get_physical_sector_size(tp); cxt->alignment_offset = blkid_topology_get_alignment_offset(tp); + /* I/O size used by fdisk */ + cxt->io_size = cxt->optimal_io_size; if (!cxt->io_size) /* optimal IO is optional, default to minimum IO */ cxt->io_size = cxt->min_io_size; @@ -110,8 +112,8 @@ int fdisk_dev_has_topology(struct fdisk_context *cxt) * optimal_io_size is set or alignment_offset is set or * minimum_io_size is not power of 2. */ - if (cxt->io_size || cxt->alignment_offset || - (cxt->min_io_size & (cxt->min_io_size - 1))) + if (cxt->optimal_io_size || cxt->alignment_offset || + !is_power_of_2(cxt->min_io_size)) return 1; return 0; } -- 2.47.3