This creates a new 1MB start alignment constraint, and has GPT use it
when disks have a logical block size != 512 bytes.  This might need to
be extended to do so if the disk has a physical sector size != 512
bytes as well, for the case of 512b logical, 4k physical sectors,
where we really want the partitions on 4k boundaries at least.

Note, Vista uses a 1MB partition alignment always now, where XP and
earlier used the standard cylinder boundary.  We might want to default
parted to using 1MB alignments always, but to not overwrite exising
partition layouts.

Note also, I haven't seen parted code to handle "odd alignment".
http://lists.alioth.debian.org/pipermail/parted-devel/2007-December/002055.html
http://www.idema.org/_smartsite/modules/local/data_file/show_file.php?cmd=download&data_file_id=1719
describes T13 Identify Device command, word 209, which shows how to
get this alignment. It seems future SATA disks will use "odd
alignment" as that's what XP used, but for SCSI that isn't determined
yet.

Fun fun.


>From 99262fdd657138c06733a5ac7f65032ccedd450c Mon Sep 17 00:00:00 2001
From: Matt Domsch <[email protected]>
Date: Tue, 27 Jan 2009 19:48:37 -0600
Subject: [PATCH] use 1MB partition alignment with GPT and disks with !512b 
sector sizes

---
 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

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to