Skip to contentSkip to conversation

GPT patch for parted 1.4.7

Linux-ia64 [email protected] 1 participant 1 message Mar 6, 2001

lore
Share & tools
lore
#0 lore raw

Attached is a patch against GNU Parted 1.4.7 which adds EFI GPT support. This has not yet been submitted to the GNU Parted team officially, I'm waiting on a kernel IOCTL patch to be included first. A lot of people are interested in this, so I'm making it available for testing. I haven't tested this against newer versions of parted, but expect it to drop in with minimal effort.

Notes:
- This works for all disks with an even number of 512-byte sectors.
- This works for SCSI disks with an odd number of 512-byte sectors by using SCSI Generic (sg) commands to read/write the last odd sector. Odd-sized IDE disks won't work.
- Pending the inclusion of a kernel patch to allow reading/writing the last sector of any disk via a block layer IOCTL, I'll re-write this patch to remove the sg hacks and use that instead.

Assistance:
If anyone wants to help, particularly in adding Unicode support to parted, I'd appreciate it. Please join the bug-parted mailing list. To subscribe or unsubscribe via the World Wide Web, visit
http://mail.gnu.org/mailman/listinfo/bug-parted
or, via email, send a message with subject or body 'help' to
[email protected]

Your feedback is encouraged.

Thanks,
Matt

--
Matt Domsch
Dell Linux Systems Group
Linux OS Development
www.dell.com/linux

include/parted/Makefile.am +2 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/include/parted/Makefile.am parted-1.4.7-gpt/include/parted/Makefile.am
@@ -6,6 +6,7 @@
 			exception.h	\
 			filesys.h	\
 			natmath.h	\
+			crc32.h		\
 			parted.h
 
 noinst_HEADERS	      = disk_bsd.h	\
@@ -13,5 +14,6 @@
 			disk_loop.h	\
 			disk_mac.h	\
 			disk_pc98.h	\
+			disk_gpt.h	\
 			endian.h
 
include/parted/crc32.h +34 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/include/parted/crc32.h parted-1.4.7-gpt/include/parted/crc32.h
@@ -0,0 +1,34 @@
+/*
+    libparted - a library for manipulating disk partitions
+    Copyright (C) 1998-2000 Free Software Foundation, Inc.
+
+    crc32.h
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifndef _CRC32_H
+#define _CRC32_H
+
+#include <linux/types.h>
+
+/*
+ * This computes a 32 bit CRC of the data in the buffer, and returns the CRC.
+ * The polynomial used is 0xedb88320.
+ */
+
+extern __u32 crc32 (const void *buf, unsigned long len, __u32 seed);
+
+#endif /* _CRC32_H */
include/parted/disk_gpt.h +195 -0

195 lines not on this page · raw message

libparted/Makefile.am +12 -1
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/Makefile.am parted-1.4.7-gpt/libparted/Makefile.am
@@ -15,12 +15,23 @@
 			llseek.c		\
 			llseek.h		\
 			natmath.c		\
+			crc32.c			\
 			disk.c			\
 			disk_bsd.c		\
 			disk_dos.c		\
 			disk_loop.c		\
 			disk_mac.c		\
-			disk_pc98.c
+			disk_pc98.c		\
+			disk_gpt.c              \
+			device_scsi.c           \
+			device_scsi.h           \
+			sg_map.c                \
+			sg_map.h                \
+			sg_dd.c                 \
+			sg_dd.h                 \
+			sg_err.c                \
+			sg_err.h             
+
 
 libparted_la_LIBADD   =	fs_ext2/libext2.la		\
 			fs_fat/libfat.la		\
libparted/crc32.c +125 -0

125 lines not on this page · raw message

libparted/device.c +28 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/device.c parted-1.4.7-gpt/libparted/device.c
@@ -41,6 +41,7 @@
 #include <sys/sysmacros.h>
 #include <sys/stat.h>
 #include <scsi/scsi.h>
+#include "device_scsi.h"
 
 #include <parted/parted.h>
 
@@ -828,6 +829,20 @@
 	PED_ASSERT (!dev->external_mode, return 0);
 	PED_ASSERT (buffer != NULL, return 0);
 
+
+	/* Kludge.  This is necessary to read/write the last
+	   block of an odd-sized SCSI disk, until 2.5.x kernel fixes.
+	   This is only used by disk_gpt.c, and only to read/write
+	   one sector, so we don't have to be fancy.
+	*/
+
+	if (dev->type == PED_DEVICE_SCSI &&
+	    (dev->length & 1) &&
+	    (count == 1) &&
+	    start == dev->length - 1) {
+		return ped_device_read_scsi(dev, buffer, start, count);
+	}
+
 	while (1) {
 		if (ped_device_seek (dev, start))
 			break;
@@ -946,6 +961,19 @@
 			return 0;
 		else
 			return 1;
+	}
+
+	/* Kludge.  This is necessary to read/write the last
+	   block of an odd-sized SCSI disk, until 2.5.x kernel fixes.
+	   This is only used by disk_gpt.c, and only to read/write
+	   one sector, so we don't have to be fancy.
+	*/
+
+	if (dev->type == PED_DEVICE_SCSI &&
+	    (dev->length & 1) &&
+	    (count == 1) &&
+	    start == dev->length - 1) {
+		return ped_device_write_scsi(dev, buffer, start, count);
 	}
 
 	while (1) {
libparted/device_scsi.c +102 -0

102 lines not on this page · raw message

libparted/device_scsi.h +28 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/device_scsi.h parted-1.4.7-gpt/libparted/device_scsi.h
@@ -0,0 +1,28 @@
+/*
+    libparted - a library for manipulating disk partitions
+    Copyright (C) 1998-2000 Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "parted/device.h"
+
+int
+ped_device_read_scsi (PedDevice* dev, const void* buffer, PedSector start,
+		      PedSector count);
+int
+ped_device_write_scsi (PedDevice* dev, const void* buffer, PedSector start,
+		       PedSector count);
+
libparted/disk.c +7 -3
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/disk.c parted-1.4.7-gpt/libparted/disk.c
@@ -174,6 +174,7 @@
 	disk->dev = dev;
 	disk->type = disk_type;
 	disk->update_mode = 0;
+	disk->disk_specific = NULL;
 
 	disk->part_list = ped_partition_new (
 		disk, PED_PARTITION_FREESPACE, NULL,
@@ -581,6 +582,7 @@
 	part->type = type;
 	part->part_list = NULL;
 	part->fs_type = fs_type;
+	part->disk_specific = NULL;
 
 	return part;
 
@@ -599,6 +601,8 @@
 	PedPartition*	part;
 
 	PED_ASSERT (disk != NULL, return NULL);
+	PED_ASSERT (disk->type != NULL, return NULL);
+	PED_ASSERT (disk->type->ops != NULL, return NULL);
 	PED_ASSERT (disk->type->ops->partition_new != NULL, return NULL);
 
 	supports_extended = ped_disk_type_check_feature (disk->type,
@@ -1314,10 +1318,10 @@
 	PED_ASSERT (part != NULL, return 0);
 
 #ifdef VERBOSE
-	printf ("ped_disk_add_partition (dev=\"%s\", start=%d, end=%d,"
+	printf ("ped_disk_add_partition (dev=\"%s\", start=%llx, end=%llx,"
 		" type=%x)\n",
-		disk->dev->path, (int) part->geom.start, (int) part->geom.end,
-		(int) part->system);
+		disk->dev->path, part->geom.start, part->geom.end,
+		part->type);
 #endif
 
 	if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED)
libparted/disk_dos.c +6 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/disk_dos.c parted-1.4.7-gpt/libparted/disk_dos.c
@@ -232,6 +232,12 @@
 			return 0;
 	}
 
+	/* If this is a GPT disk, fail here */
+	for (i = 0; i < 4; i++) {
+		if (part_table.partitions[i].type == 0xEE)
+ 			return 0;
+ 	}
+
 	/* HACK: it's impossible to tell PC98 and msdos disk labels apart.
 	 * Someone made the signatures the same (very clever).  Since
 	 * PC98 has some idiosyncracies with it's boot-loader, it's detection
libparted/disk_gpt.c +1738 -0

1,738 lines not on this page · raw message

libparted/fs_ext2/interface.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_ext2/interface.c parted-1.4.7-gpt/libparted/fs_ext2/interface.c
@@ -31,6 +31,7 @@
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
 #include <parted/disk_bsd.h>
+#include <parted/disk_gpt.h>
 #include "ext2.h"
 #include "parted_io.h"
 
@@ -342,6 +343,15 @@
 	if (strcmp (disk_type->name, BSD_NAME) == 0) {
 		BSDPartitionData* bsd_data = part->disk_specific;
 		bsd_data->type = 0x8;
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData *gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);	
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_BASIC_DATA_GUID;
 		return 1;
 	}
 
libparted/fs_fat/fat.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_fat/fat.c parted-1.4.7-gpt/libparted/fs_fat/fat.c
@@ -22,6 +22,7 @@
 #include <parted/disk_loop.h>
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
+#include <parted/disk_gpt.h>
 
 #include "fat.h"
 #include "calc.h"
@@ -751,6 +752,15 @@
 		else
 			strcpy (mac_data->system_name, "FAT");
 		mac_data->status = 0x33;
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData *gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);	
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_BASIC_DATA_GUID;
 		return 1;
 	}
 
libparted/fs_hfs/hfs.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_hfs/hfs.c parted-1.4.7-gpt/libparted/fs_hfs/hfs.c
@@ -25,6 +25,7 @@
 #include <parted/disk_loop.h>
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
+#include <parted/disk_gpt.h>
 
 #include <libintl.h>
 #if ENABLE_NLS
@@ -151,6 +152,15 @@
 			strcpy (mac_data->system_name, "Apple_HFS");
 			mac_data->status |= 0x7f;
 		}
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData *gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);	
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_BASIC_DATA_GUID;
 		return 1;
 	}
 
libparted/fs_linux_swap/linux_swap.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_linux_swap/linux_swap.c parted-1.4.7-gpt/libparted/fs_linux_swap/linux_swap.c
@@ -28,6 +28,7 @@
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
 #include <parted/disk_bsd.h>
+#include <parted/disk_gpt.h>
 
 #include <libintl.h>
 #if ENABLE_NLS
@@ -565,6 +566,15 @@
 	if (strcmp (disk_type->name, BSD_NAME) == 0) {
 		BSDPartitionData* bsd_data = part->disk_specific;
 		bsd_data->type = 0x1;
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData* gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_SWAP_GUID;
 		return 1;
 	}
 
libparted/fs_ntfs/ntfs.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_ntfs/ntfs.c parted-1.4.7-gpt/libparted/fs_ntfs/ntfs.c
@@ -25,6 +25,7 @@
 #include <parted/disk_loop.h>
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
+#include <parted/disk_gpt.h>
 
 #include <libintl.h>
 #if ENABLE_NLS
@@ -147,6 +148,15 @@
 		else
 			strcpy (mac_data->system_name, "Apple_UNIX_SVR2");
 		mac_data->status = 0x33;
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData *gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);	
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_BASIC_DATA_GUID;
 		return 1;
 	}
 
libparted/fs_reiserfs/reiserfs.c +10 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/fs_reiserfs/reiserfs.c parted-1.4.7-gpt/libparted/fs_reiserfs/reiserfs.c
@@ -25,6 +25,7 @@
 #include <parted/disk_loop.h>
 #include <parted/disk_pc98.h>
 #include <parted/disk_mac.h>
+#include <parted/disk_gpt.h>
 
 #include <libintl.h>
 #if ENABLE_NLS
@@ -181,6 +182,15 @@
 		else
 			strcpy (mac_data->system_name, "Apple_UNIX_SVR2");
 		mac_data->status = 0x33;
+		return 1;
+	}
+
+	if (strcmp (disk_type->name, GPT_NAME) == 0) {
+		GPTPartitionData *gpt_part_data = part->disk_specific;
+		PED_ASSERT(gpt_part_data      != NULL, return 0);	
+		PED_ASSERT(gpt_part_data->pte != NULL, return 0);
+		gpt_part_data->pte->PartitionTypeGuid =
+			PARTITION_BASIC_DATA_GUID;
 		return 1;
 	}
 
libparted/libparted.c +2 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/libparted.c parted-1.4.7-gpt/libparted/libparted.c
@@ -65,6 +65,7 @@
 	ped_disk_pc98_init ();
 	ped_disk_mac_init ();
 	ped_disk_bsd_init ();
+	ped_disk_gpt_init ();
 }
 
 static void
@@ -102,6 +103,7 @@
 	ped_disk_loop_done ();
 	ped_disk_mac_done ();
 	ped_disk_bsd_done ();
+	ped_disk_gpt_done ();
 }
 
 static void
libparted/sg_dd.c +781 -0

502 lines not on this page · raw message

libparted/sg_dd.h +23 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/sg_dd.h parted-1.4.7-gpt/libparted/sg_dd.h

Lines of this file are not shown. View the raw message.

libparted/sg_err.c +648 -0

648 lines not on this page · raw message

libparted/sg_err.h +156 -0

156 lines not on this page · raw message

libparted/sg_map.c +422 -0

422 lines not on this page · raw message

libparted/sg_map.h +33 -0
diff -BburN --exclude *.orig --exclude *.spec --exclude=*Makefile.in --exclude=*.po* parted-1.4.7/libparted/sg_map.h parted-1.4.7-gpt/libparted/sg_map.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.