[Top][All Lists]
[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: |
Wed, 10 Feb 2010 14:12:56 +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 c031018..fb55932 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
gpt: read-only operation could clobber MBR part of hybrid GPT+MBR table
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
- [PATCH parted 1/7] linux: Fixup phys_sector_size setting, Hans de Goede, 2010/02/10
- [PATCH parted 3/7] linux: handle incomplete topology information, Hans de Goede, 2010/02/10
- [PATCH parted 6/7] parted: Change default alignment to optimal, Hans de Goede, 2010/02/10
- [PATCH parted 4/7] parted: Honor --align option also in mkpartfs, resize and print cmds, Hans de Goede, 2010/02/10
- [PATCH parted 7/7] dasd: Fix NULL pointer dereference in dasd_read, Hans de Goede, 2010/02/10
- [PATCH parted 5/7] parted: change warnings when initial constrained mkpart fails, Hans de Goede, 2010/02/10
- [PATCH parted 2/7] libparted: Give device_get_*_alignment sane defaults,
Hans de Goede <=
- Re: [PATCH parted 1/7] linux: Fixup phys_sector_size setting, Jim Meyering, 2010/02/10