bug-parted
[Top][All Lists]
Advanced

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

[PATCH parted 2/7] libparted: Give device_get_*_alignment sane defaults


From: Hans de Goede
Subject: [PATCH parted 2/7] libparted: Give device_get_*_alignment sane defaults
Date: Sat, 30 Jan 2010 17:53:48 +0100

When the topology info is incomplete or non existent, return something
more sensible then NULL (which ends up being interpreted as
PedAlignmentAny in most cases). The default minimum alignment aligns to
physical sector size, the default optimal alignment is 1 MiB, which is
what vista and windows 7 do.
* libparted/device.c (device_get_*_alignment): Add default aligments.
---
 NEWS               |    7 +++++++
 libparted/device.c |   30 ++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index d94b0db..53477d3 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU parted NEWS                                    -*- outline 
-*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+  The ped_device_get_*_alignment() functions will now return a sane default
+  value instead of NULL if the so called topology information is incomplete.
+  The default minimum alignment aligns to physical sector size, the default
+  optimal alignment is 1MiB, which is what vista and windows 7 do.
+
 ** Bug Fixes
 
  Fix physical sector size being 0 or smaller then the logical sector size.
diff --git a/libparted/device.c b/libparted/device.c
index dda8d74..0f36a03 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -501,10 +501,16 @@ ped_device_get_optimal_aligned_constraint(const PedDevice 
*dev)
 PedAlignment*
 ped_device_get_minimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_minimum_alignment)
-                return ped_architecture->dev_ops->get_minimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_minimum_alignment(dev);
+
+        if (align == NULL)
+                align = ped_alignment_new(0,
+                                dev->phys_sector_size / dev->sector_size);
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /**
@@ -521,10 +527,26 @@ ped_device_get_minimum_alignment(const PedDevice *dev)
 PedAlignment*
 ped_device_get_optimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_optimum_alignment)
-                return ped_architecture->dev_ops->get_optimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_optimum_alignment(dev);
+
+        /* If the arch specific code could not give as an alignment
+           return a default value based on the type of device. */
+        if (align == NULL) {
+                switch (dev->type) {
+                case PED_DEVICE_DASD:
+                        align = ped_device_get_minimum_alignment(dev);
+                        break;
+                default:
+                        /* Align to a grain of 1MiB (like vista / win7) */
+                        align = ped_alignment_new(0,
+                                                  1048576 / dev->sector_size);
+                }
+        }
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /** @} */
-- 
1.6.6





reply via email to

[Prev in Thread] Current Thread [Next in Thread]