[PATCH] use 1MB partition alignment with GPT and disks with !512b sector sizes
Matt Domsch
Matt_Domsch at dell.com
Wed Jan 28 01:48:37 UTC 2009
---
include/parted/constraint.h | 3 +++
include/parted/natmath.h | 1 +
libparted/cs/constraint.c | 16 ++++++++++++++++
libparted/cs/natmath.c | 6 ++++++
libparted/labels/gpt.c | 7 ++++++-
5 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/include/parted/constraint.h b/include/parted/constraint.h
index 6496926..f2ffb0e 100644
--- a/include/parted/constraint.h
+++ b/include/parted/constraint.h
@@ -65,6 +65,9 @@ extern PedConstraint*
ped_constraint_new_from_max (const PedGeometry* max);
extern PedConstraint*
+ped_constraint_new_from_max_1MB_aligned (const PedGeometry* max);
+
+extern PedConstraint*
ped_constraint_duplicate (const PedConstraint* constraint);
extern void
diff --git a/include/parted/natmath.h b/include/parted/natmath.h
index 596d98a..0bbd507 100644
--- a/include/parted/natmath.h
+++ b/include/parted/natmath.h
@@ -86,6 +86,7 @@ ped_alignment_is_aligned (const PedAlignment* align, const PedGeometry* geom,
extern const PedAlignment* ped_alignment_any;
extern const PedAlignment* ped_alignment_none;
+extern const PedAlignment* ped_alignment_1MB;
static inline PedSector
ped_div_round_up (PedSector numerator, PedSector divisor)
diff --git a/libparted/cs/constraint.c b/libparted/cs/constraint.c
index e094e5b..fd18fef 100644
--- a/libparted/cs/constraint.c
+++ b/libparted/cs/constraint.c
@@ -173,6 +173,22 @@ ped_constraint_new_from_max (const PedGeometry* max)
}
/**
+ * Return a constraint that requires a region to be entirely contained inside
+ * \p max, starting on a 1MB boundary and ending wherever.
+ *
+ * \return \c NULL on failure.
+ */
+PedConstraint*
+ped_constraint_new_from_max_1MB_aligned (const PedGeometry* max)
+{
+ PED_ASSERT (max != NULL, return NULL);
+
+ return ped_constraint_new (
+ ped_alignment_1MB, ped_alignment_any,
+ max, max, 1, max->length);
+}
+
+/**
* Duplicate a constraint.
*
* \return \c NULL on failure.
diff --git a/libparted/cs/natmath.c b/libparted/cs/natmath.c
index 7511fbd..aff0e67 100644
--- a/libparted/cs/natmath.c
+++ b/libparted/cs/natmath.c
@@ -48,8 +48,14 @@ static const PedAlignment _any = {
grain_size: 1
};
+static const PedAlignment _1MB = {
+ offset: 0,
+ grain_size: 2048,
+};
+
const PedAlignment* ped_alignment_any = &_any;
const PedAlignment* ped_alignment_none = NULL;
+const PedAlignment* ped_alignment_1MB = &_1MB;
/* This function returns "a mod b", the way C should have done it!
* Mathematicians prefer -3 mod 4 to be 3. Reason: division by N
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index abfb242..9d3df10 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1485,7 +1485,12 @@ _non_metadata_constraint (const PedDisk* disk)
{
GPTDiskData* gpt_disk_data = disk->disk_specific;
- return ped_constraint_new_from_max (&gpt_disk_data->data_area);
+ /* Vista now does this for all disks, not just those with >512b sectors */
+ if (disk->dev->sector_size > PED_SECTOR_SIZE_DEFAULT)
+ return ped_constraint_new_from_max_1MB_aligned (&gpt_disk_data->data_area);
+ else
+ return ped_constraint_new_from_max (&gpt_disk_data->data_area);
+
}
static int
--
1.6.0.5
--
Matt Domsch
Linux Technology Strategist, Dell Office of the CTO
linux.dell.com & www.dell.com/linux
More information about the parted-devel
mailing list