[Parted-commits] GNU Parted Official Repository: Changes to 'next'

Jim Meyering meyering at alioth.debian.org
Wed Aug 26 14:28:15 UTC 2009


 libparted/labels/dos.c                     |   33 +++++++++++++++--------------
 tests/t0202-gpt-pmbr.sh                    |   16 ++++++++------
 tests/t2300-dos-label-extended-bootcode.sh |   12 +++++-----
 3 files changed, 34 insertions(+), 27 deletions(-)

New commits:
commit c3d0c29999af4f3a08e9f5cc7f950f3fd4d2fb53
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Wed Aug 26 12:29:46 2009 +0200

    dos: adjust variable declarations
    
    * libparted/labels/dos.c (write_ext_table): Move declaration of S down
    to just before its first use.
    Fix alignment of lba_offset declaration.

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 648c79c..a3487a0 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1030,8 +1030,7 @@ write_ext_table (const PedDisk* disk,
                  PedSector sector, const PedPartition* logical)
 {
 	PedPartition*		part;
-	PedSector			lba_offset;
-	void*				s;
+	PedSector		lba_offset;
 
 	PED_ASSERT (disk != NULL, return 0);
 	PED_ASSERT (ped_disk_extended_partition (disk) != NULL, return 0);
@@ -1039,6 +1038,7 @@ write_ext_table (const PedDisk* disk,
 
 	lba_offset = ped_disk_extended_partition (disk)->geom.start;
 
+	void* s;
 	if (!ptt_read_sector (disk->dev, sector, &s))
 		return 0;
 

commit ca4f538076fdf39dc2c95f471edaf8dfd20f3973
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Wed Aug 26 12:29:26 2009 +0200

    dos: factor out and define DOS_N_PRI_PARTITIONS
    
    * dos.c (DOS_N_PRI_PARTITIONS): Define.

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index f67a872..648c79c 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -55,6 +55,9 @@ static const char MBR_BOOT_CODE[] = {
 #define MSDOS_MAGIC		0xAA55
 #define PARTITION_MAGIC_MAGIC	0xf6f6
 
+/* The maximum number of DOS primary partitions.  */
+#define DOS_N_PRI_PARTITIONS	4
+
 #define PARTITION_EMPTY		0x00
 #define PARTITION_FAT12		0x01
 #define PARTITION_FAT16_SM	0x04
@@ -126,7 +129,7 @@ struct _DosRawTable {
 	char			boot_code [440];
 	uint32_t                mbr_signature;	/* really a unique ID */
 	uint16_t                Unknown;
-	DosRawPartition		partitions [4];
+	DosRawPartition		partitions [DOS_N_PRI_PARTITIONS];
 	uint16_t		magic;
 } __attribute__((packed));
 
@@ -181,14 +184,14 @@ msdos_probe (const PedDevice *dev)
 	 * and ensure that each partition has a boot indicator that is
 	 * either 0 or 0x80.
 	 */
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
 		if (part_table->partitions[i].boot_ind != 0
 		    && part_table->partitions[i].boot_ind != 0x80)
 			goto probe_fail;
 	}
 
 	/* If this is a GPT disk, fail here */
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
 		if (part_table->partitions[i].type == PARTITION_GPT)
 			goto probe_fail;
 	}
@@ -849,7 +852,7 @@ read_table (PedDisk* disk, PedSector sector, int is_extended_table)
 #endif
 
 	/* parse the partitions from this table */
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
 		raw_part = &table->partitions [i];
 		if (raw_part->type == PARTITION_EMPTY || !raw_part->length)
 			continue;
@@ -903,7 +906,7 @@ read_table (PedDisk* disk, PedSector sector, int is_extended_table)
 
 	if (is_extended_table) {
 		/* process the nested extended partitions */
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < DOS_N_PRI_PARTITIONS; i++) {
 			PedSector part_start;
 
 			raw_part = &table->partitions [i];
@@ -1145,7 +1148,7 @@ msdos_write (const PedDisk* disk)
 	memset (table->partitions, 0, sizeof (table->partitions));
 	table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
-	for (i=1; i<=4; i++) {
+	for (i=1; i<=DOS_N_PRI_PARTITIONS; i++) {
 		part = ped_disk_get_partition (disk, i);
 		if (!part)
 			continue;
@@ -2223,7 +2226,7 @@ static int
 next_primary (const PedDisk* disk)
 {
 	int	i;
-	for (i=1; i<=4; i++) {
+	for (i=1; i<=DOS_N_PRI_PARTITIONS; i++) {
 		if (!ped_disk_get_partition (disk, i))
 			return i;
 	}
@@ -2247,7 +2250,7 @@ msdos_partition_enumerate (PedPartition* part)
 	PED_ASSERT (part->disk != NULL, return 0);
 
 	/* don't re-number a primary partition */
-	if (part->num != -1 && part->num <= 4)
+	if (part->num != -1 && part->num <= DOS_N_PRI_PARTITIONS)
 		return 1;
 
 	part->num = -1;
@@ -2263,7 +2266,7 @@ msdos_partition_enumerate (PedPartition* part)
 static int
 msdos_get_max_primary_partition_count (const PedDisk* disk)
 {
-	return 4;
+	return DOS_N_PRI_PARTITIONS;
 }
 
 static bool

commit 99a8c948542a9c69e91b33253f98dd47905f0c71
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Wed Aug 26 12:28:41 2009 +0200

    dos: use sizeof(variable) instead of sizeof(type)
    
    * libparted/labels/dos.c (write_ext_table): Use sizeof(variable)
    instead of sizeof(type)
    (write_empty_table, msdos_write): Likewise.

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 2b1aaca..f67a872 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1040,7 +1040,7 @@ write_ext_table (const PedDisk* disk,
 		return 0;
 
 	DosRawTable *table = s;
-	memset(&(table->partitions), 0, 4 * sizeof(DosRawPartition));
+	memset(&(table->partitions), 0, sizeof (table->partitions));
 	table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
 	int ok = 0;
@@ -1080,10 +1080,10 @@ write_empty_table (const PedDisk* disk, PedSector sector)
 	PED_ASSERT (disk != NULL, return 0);
 
 	if (ptt_read_sector (disk->dev, sector, &table_sector)) {
-		memcpy (&table, table_sector, sizeof(DosRawTable));
+		memcpy (&table, table_sector, sizeof (table));
 		free(table_sector);
 	}
-	memset (&(table.partitions), 0, 4 * sizeof(DosRawPartition));
+	memset (&(table.partitions), 0, sizeof (table.partitions));
 	table.magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
 	return ped_device_write (disk->dev, (void*) &table, sector, 1);
@@ -1142,7 +1142,7 @@ msdos_write (const PedDisk* disk)
 	if (!table->mbr_signature)
 		table->mbr_signature = generate_random_id();
 
-	memset (table->partitions, 0, sizeof (DosRawPartition) * 4);
+	memset (table->partitions, 0, sizeof (table->partitions));
 	table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
 	for (i=1; i<=4; i++) {

commit 4a4ad385f402caa86a302b00ad6eebf26998f167
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Wed Aug 26 15:10:49 2009 +0200

    tests: t0202-gpt-pmbr.sh: various fixes
    
    * tests/t0202-gpt-pmbr.sh: use $bootcode_size variable instead
    of plain 446.  Do not use /dev/urandom since it might not exist.

diff --git a/tests/t0202-gpt-pmbr.sh b/tests/t0202-gpt-pmbr.sh
index 2c365c2..996cfe9 100755
--- a/tests/t0202-gpt-pmbr.sh
+++ b/tests/t0202-gpt-pmbr.sh
@@ -21,14 +21,18 @@ test_description='Preserve first 446B of the Protected MBR for gpt partitions.'
 . $srcdir/test-lib.sh
 
 dev=loop-file
+bootcode_size=446
+
 test_expect_success \
     'Create a 100k test file with random content' \
-    'dd if=/dev/urandom of=$dev bs=1c count=446 &&
-     dd if=/dev/zero of=$dev bs=1c seek=446 count=101954 > /dev/null 2>&1'
+    'printf %0${bootcode_size}d 0 > in &&
+     dd if=in of=$dev bs=1c count=$bootcode_size &&
+     dd if=/dev/zero of=$dev bs=1c seek=$bootcode_size \
+	    count=101954 > /dev/null 2>&1'
 
 test_expect_success \
-    'Extract the first 446 Bytes before GPT creation' \
-    'dd if=$dev of=before bs=1c count=446 > /dev/null 2>&1'
+    'Extract the first $bootcode_size Bytes before GPT creation' \
+    'dd if=$dev of=before bs=1c count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
     'create a GPT partition table' \
@@ -36,8 +40,8 @@ test_expect_success \
 test_expect_success 'expect no output' 'compare out /dev/null'
 
 test_expect_success \
-    'Extract the first 446 Bytes after GPT creation' \
-    'dd if=$dev of=after bs=1c count=446 > /dev/null 2>&1'
+    'Extract the first $bootcode_size Bytes after GPT creation' \
+    'dd if=$dev of=after bs=1c count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
     'Compare the before and after' \

commit d5d8f07c62639689a949b9c233b2a01f935d447c
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Wed Aug 26 15:10:31 2009 +0200

    tests: t2300-dos-label-extended-bootcode.sh: various fixes
    
    * tests/t2300-dos-label-extended-bootcode.sh:
    - fix typo where only first 400B of fake bootcode was installed
    - use bootcode_size variable and increase its value from 440 to 446
    - do not use /dev/urandom since it might not exist

diff --git a/tests/t2300-dos-label-extended-bootcode.sh b/tests/t2300-dos-label-extended-bootcode.sh
index f2f3a83..a0dd2e9 100755
--- a/tests/t2300-dos-label-extended-bootcode.sh
+++ b/tests/t2300-dos-label-extended-bootcode.sh
@@ -22,9 +22,8 @@ test_description='Ensure parted preserves bootcode in extended partition.'
 
 require_512_byte_sector_size_
 
-# Note: the bootcode size is 440B
-
 dev=loop-file
+bootcode_size=446
 
 test_expect_success \
   'Create the test file' \
@@ -47,12 +46,13 @@ test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Install fake bootcode' \
-  'dd if=/dev/urandom of=$dev bs=1c seek=16384 count=400 \
-    conv=notrunc > /dev/null 2>&1'
+  'printf %0${bootcode_size}d 0 > in &&
+   dd if=in of=$dev bs=1c seek=16384 count=$bootcode_size \
+      conv=notrunc > /dev/null 2>&1'
 
 test_expect_success \
   'Save fake bootcode for later comparison' \
-  'dd if=$dev of=before bs=1 skip=16384 count=440 > /dev/null 2>&1'
+  'dd if=$dev of=before bs=1 skip=16384 count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
   'Do something to the label' \
@@ -61,7 +61,7 @@ test_expect_success 'Expect no output' 'compare out /dev/null'
 
 test_expect_success \
   'Extract the bootcode for comparison' \
-  'dd if=$dev of=after bs=1 skip=16384 count=440 > /dev/null 2>&1'
+  'dd if=$dev of=after bs=1 skip=16384 count=$bootcode_size > /dev/null 2>&1'
 
 test_expect_success \
   'Expect bootcode has not changed' \



More information about the Parted-commits mailing list