On 4/17/07, Debarshi 'Rishi' Ray <[EMAIL PROTECTED]> wrote:
> Therefore I suggest the following changes in

Could you prepare a patch against our current GIT code?

I had hoped to avoid being drawn into that, but it turned out to be
painless.  :-)  Patch attached.

In addition to the changes I listed before, this also fixes what
appear to be byte order errors.  (The contents of the gpt structure
should be in LE byte order, not CPU byte order, it seems.)  Let me
know if I'm wrong about this.

> How to reproduce: If you have a spare disk, download the Nexenta alpha
> 6 install CD [6].  When it boots, press F2 to get a shell.  Use
> "format -e" to determine the OpenSolaris name for your disk, and then
> create a ZFS pool on it (e.g., "zpool create foo c2d0").  Then type
> "halt" to reboot, and go run Parted from Linux.

Parted has been ported to Nexenta as well. You could try to see
whether it takes care of the issues that you have raised.

Unfortunately that would require actually *installing* Nexenta instead
of just booting the install CD and using a shell, so I am reluctant to
do that again.  The source package is not available from the Nexenta
website, alpha 6 does not have a live CD yet, and the install CD does
not provide network access.  But I doubt the Parted on Nexenta fixed
this problem; most Solaris installations don't use EFI disk labels
yet, as I understand it.

There is
also something called solaris-parted
(http://code.google.com/p/solaris-parted/), but I think this one is
different than the one found in Nexenta's repositories, because last
time I tried Nexenta (a month back) it had a patched Parted 1.6.x  in
its repository.

That is still true.  (Nexenta hasn't changed often.)  And the version
of gpt.c in solaris-parted does not have any significant changes from
the current version of gpt.c.


Matthew
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index f03c8e5..5b3721c 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -390,7 +390,7 @@ pth_crc32(const PedDevice* dev, const GuidPartitionTableHeader_t* pth)
         PED_ASSERT (dev != NULL, return 0);
         PED_ASSERT (pth != NULL, return 0);
        
-        crc32 = efi_crc32 (pth_raw, pth_get_size_static (dev));
+        crc32 = efi_crc32 (pth_raw, PED_LE32_TO_CPU (pth->HeaderSize));
 
         ped_free (pth_raw);
       
@@ -590,8 +590,13 @@ _header_is_valid (const PedDevice* dev, GuidPartitionTableHeader_t* gpt)
 
 	if (PED_LE64_TO_CPU (gpt->Signature) != GPT_HEADER_SIGNATURE)
 		return 0;
-	if (PED_LE32_TO_CPU (gpt->HeaderSize)
-			> pth_get_size_static (dev))
+	/*
+	 * "While the GUID Partition Table Header's size may increase
+	 * in the future it cannot span more than one block on the
+	 * device."  EFI Specification, version 1.10, 11.2.2.1
+	 */
+	if (PED_LE32_TO_CPU (gpt->HeaderSize) < pth_get_size_static (dev)
+	    || PED_LE32_TO_CPU (gpt->HeaderSize) > dev->sector_size)
 		return 0;
 
 	origcrc = gpt->HeaderCRC32;
@@ -639,23 +644,21 @@ _parse_header (PedDisk* disk, GuidPartitionTableHeader_t* gpt,
 	PED_ASSERT (_header_is_valid (disk->dev, gpt), return 0);
 
 #ifndef DISCOVER_ONLY
-	if (PED_CPU_TO_LE32 (gpt->Revision) > GPT_HEADER_REVISION_V1_02
-	    || PED_CPU_TO_LE32 (gpt->HeaderSize) != pth_get_size_static (
-                                                        disk->dev)) {
+	if (PED_LE32_TO_CPU (gpt->Revision) > GPT_HEADER_REVISION_V1_02) {
 		if (ped_exception_throw (
 			PED_EXCEPTION_WARNING,
 			PED_EXCEPTION_IGNORE_CANCEL,
 			_("The format of the GPT partition table is version "
 			  "%x, which is newer than what Parted can "
 			  "recognise.  Please tell us!  [EMAIL PROTECTED]"),
-			PED_CPU_TO_LE32 (gpt->Revision))
+			PED_LE32_TO_CPU (gpt->Revision))
 				!= PED_EXCEPTION_IGNORE)
 			return 0;
 	}
 #endif
 
-	first_usable = PED_CPU_TO_LE64 (gpt->FirstUsableLBA);
-	last_usable = PED_CPU_TO_LE64 (gpt->LastUsableLBA);
+	first_usable = PED_LE64_TO_CPU (gpt->FirstUsableLBA);
+	last_usable = PED_LE64_TO_CPU (gpt->LastUsableLBA);
 
 
 /*
@@ -670,8 +673,8 @@ _parse_header (PedDisk* disk, GuidPartitionTableHeader_t* gpt,
    
 	last_usable_if_grown 
 		= PED_CPU_TO_LE64 (disk->dev->length - 2 - 
-		((PedSector)(PED_CPU_TO_LE32(gpt->NumberOfPartitionEntries)) * 
-		(PedSector)(PED_CPU_TO_LE32(gpt->SizeOfPartitionEntry)) / 
+		((PedSector)(PED_LE32_TO_CPU(gpt->NumberOfPartitionEntries)) * 
+		(PedSector)(PED_LE32_TO_CPU(gpt->SizeOfPartitionEntry)) / 
 		disk->dev->sector_size));
 
 	last_usable_min_default = disk->dev->length - 2 - 
@@ -719,7 +722,7 @@ _parse_header (PedDisk* disk, GuidPartitionTableHeader_t* gpt,
 
 
 	gpt_disk_data->entry_count
-		= PED_CPU_TO_LE32 (gpt->NumberOfPartitionEntries);
+		= PED_LE32_TO_CPU (gpt->NumberOfPartitionEntries);
 	PED_ASSERT (gpt_disk_data->entry_count > 0, return 0);
 	PED_ASSERT (gpt_disk_data->entry_count <= 8192, return 0);
 
_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to