The topology information returned by libblkid is not always complete (as the kernel does not always have complete information). This patch makes the linux_get_*_alignment() alignment functions handle this. The algorithm used for linux_get_optimum_alignment is: 1) Always use the reported aligment offset as offset 2a)If optimal io size is present in the topology info use that as grain 2b)If optimal io size is not present in topology info and aligment offset is 0 and minimum io size is a power of 2, use the device.c default optimal alignment (grain 1MiB). 2c)If not 2a and 2b, use the minimum io size, or if that is not defined the physical sector size as grain (iow the minimum alignment). The algorithm used for linux_get_minimum_alignment is: 1) Always use the reported aligment offset as offset 2) Use the minimum io size, or if that is not defined the physical sector size as grain. * libparted/arch/linux.c (linux_get_*_alignment): handle incomplete topology information. --- libparted/arch/linux.c | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 4b7b9f5..a083028 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -2564,9 +2564,14 @@ PedAlignment* linux_get_minimum_alignment(const PedDevice *dev) { blkid_topology tp = LINUX_SPECIFIC(dev)->topology; + if (!tp) + return NULL; - if (!tp || blkid_topology_get_minimum_io_size(tp) == 0) - return NULL; /* ped_alignment_none */ + if (blkid_topology_get_minimum_io_size(tp) == 0) + return ped_alignment_new( + blkid_topology_get_alignment_offset(tp) / + dev->sector_size, + dev->phys_sector_size / dev->sector_size); return ped_alignment_new( blkid_topology_get_alignment_offset(tp) / dev->sector_size, @@ -2577,9 +2582,21 @@ PedAlignment* linux_get_optimum_alignment(const PedDevice *dev) { blkid_topology tp = LINUX_SPECIFIC(dev)->topology; + if (!tp) + return NULL; + + /* If optimal_io_size is 0 _and_ alignment_offset is 0 _and_ + minimum_io_size is a power of 2 then go with the device.c default */ + unsigned long minimum_io_size = blkid_topology_get_minimum_io_size(tp); + if (blkid_topology_get_optimal_io_size(tp) == 0 && + blkid_topology_get_alignment_offset(tp) == 0 && + (minimum_io_size & (minimum_io_size - 1)) == 0) + return NULL; - if (!tp || blkid_topology_get_optimal_io_size(tp) == 0) - return NULL; /* ped_alignment_none */ + /* If optimal_io_size is 0 and we don't meet the other criteria + for using the device.c default, return the minimum alignment. */ + if (blkid_topology_get_optimal_io_size(tp) == 0) + return linux_get_minimum_alignment(dev); return ped_alignment_new( blkid_topology_get_alignment_offset(tp) / dev->sector_size, -- 1.6.6 _______________________________________________ bug-parted mailing list bug-parted@gnu.org http://lists.gnu.org/mailman/listinfo/bug-parted