[PATCH parted 4/5] Take alignment offset into account in ped_device_get_constraint()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ped_device_get_constraint() was trying to do aligment based on physical
sector / logical sector differences, but this does not take
alignment offset into account. So use ped_device_get_minimal_aligment()
instead.

Note this may seem a regression for arch's which don't implement
ped_device_get_minimal_aligment(), but it is not as those arch's do
not differ between physical and logical sector size to begin with.
---
 libparted/device.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/libparted/device.c b/libparted/device.c
index 6a41512..a26c56a 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -427,20 +427,33 @@ ped_device_sync_fast (PedDevice* dev)
 PedConstraint*
 ped_device_get_constraint (PedDevice* dev)
 {
-        int multiplier = dev->phys_sector_size / dev->sector_size;
-
-        PedAlignment* start_align = ped_alignment_new (multiplier, multiplier);
+        const PedAlignment* start_align;
+        const PedAlignment* end_align;
+
+        start_align = ped_device_get_minimal_aligment(dev);
+        if (start_align) {
+                end_align = ped_alignment_new(start_align->offset - 1,
+                                                start_align->grain_size);
+                if (!end_align) {
+                        free ((void *)start_align);
+                        return NULL;
+                }
+        } else
+                start_align = end_align = ped_alignment_any;
 
         PedGeometry *s, *e;
         PedConstraint* c = ped_constraint_new (
-                                start_align, ped_alignment_any,
+                                start_align, end_align,
                                 s = ped_geometry_new (dev, 0, dev->length),
                                 e = ped_geometry_new (dev, 0, dev->length),
                                 1, dev->length);
 
         free (s);
         free (e);
-        free (start_align);
+        if (start_align != ped_alignment_any) {
+                free ((void *)start_align);
+                free ((void *)end_align);
+        }
         return c;
 }
 
-- 
1.6.5.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux