OSDN Git Service

libparted: Give device_get_*_alignment sane defaults
authorHans de Goede <hdegoede@redhat.com>
Sat, 30 Jan 2010 16:53:48 +0000 (17:53 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 10 Feb 2010 13:28:49 +0000 (14:28 +0100)
When the topology info is incomplete or non existent, return something
more sensible than 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 (New features): Mention it.

NEWS
libparted/device.c

diff --git a/NEWS b/NEWS
index dcbc817..f13eba5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU parted NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+  The ped_device_get_*_alignment() functions now return a sane default
+  value instead of NULL when 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
 
   Parted no longer uses a physical sector size of 0 or of any other
index dda8d74..0f36a03 100644 (file)
@@ -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;
 }
 
 /** @} */