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

Jim Meyering meyering at alioth.debian.org
Thu Feb 25 17:23:06 UTC 2010


 NEWS                       |    6 ++++
 libparted/labels/sun.c     |   20 +++++++++++++--
 tests/Makefile.am          |    3 +-
 tests/t0500-dup-clobber.sh |   33 ++++++++++++++++++++++++
 tests/t4001-sun-vtoc.sh    |   60 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 119 insertions(+), 3 deletions(-)

New commits:
commit ed21c3e673912a205b295ef442dc5f677bfca1b5
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu Feb 25 18:19:10 2010 +0100

    tests: convert t4001 to use the new framework
    
    * tests/t4001-sun-vtoc.sh: Convert.
    * tests/Makefile.am (TESTS): Add it to the list.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d0d301d..8159a32 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ TESTS = \
   t2300-dos-label-extended-bootcode.sh \
   t3000-resize-fs.sh \
   t4000-sun-raid-type.sh \
+  t4001-sun-vtoc.sh \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
   t4100-msdos-starting-sector.sh \
diff --git a/tests/t4001-sun-vtoc.sh b/tests/t4001-sun-vtoc.sh
index 78c10c6..839d399 100755
--- a/tests/t4001-sun-vtoc.sh
+++ b/tests/t4001-sun-vtoc.sh
@@ -18,37 +18,43 @@
 
 # Written by Karel Zak <kzak at redhat.com>
 
-test_description='test Sun VTOC initialization'
+if test "$VERBOSE" = yes; then
+  set -x
+  parted --version
+fi
 
 : ${srcdir=.}
-. $srcdir/test-lib.sh
+. $srcdir/t-lib.sh
 
 N=2M
 dev=loop-file
-test_expect_success \
-    'create a file to simulate the underlying device' \
-    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
-
-test_expect_success \
-    'label the test disk' \
-    'parted -s $dev mklabel sun > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
-
-test_expect_success \
-    'extract version' \
-    'od -t x1 -An -j128 -N4 $dev > out && echo " 00 00 00 01" > exp'
-test_expect_success 'expect it to be 00 00 00 01, not 00 00 00 00' \
-    'compare out exp'
-
-test_expect_success \
-    'extract nparts' \
-    'od -t x1 -An -j140 -N2 $dev > out && echo " 00 08" > exp'
-test_expect_success 'expect it to be 00 08, not 00 00' 'compare out exp'
-
-test_expect_success \
-    'extract sanity magic' \
-    'od -t x1 -An -j188 -N4 $dev > out && echo " 60 0d de ee" > exp'
-test_expect_success 'expect it to be 60 0d de ee, not 00 00 00 00' \
-    'compare out exp'
-
-test_done
+# create a file to simulate the underlying device
+dd if=/dev/null of=$dev bs=1 seek=$N || framework_failure
+
+fail=0
+
+# label the test disk
+parted -s $dev mklabel sun > out 2>&1 || fail=1
+# expect no output
+compare out /dev/null || fail=1
+
+# extract version
+od -t x1 -An -j128 -N4 $dev > out || fail=1
+echo " 00 00 00 01" > exp || fail=1
+# expect it to be 00 00 00 01, not 00 00 00 00
+compare out exp || fail=1
+
+# extract nparts
+od -t x1 -An -j140 -N2 $dev > out || fail=1
+echo " 00 08" > exp || fail=1
+
+# expect it to be 00 08, not 00 00
+compare out exp || fail=1
+
+# extract sanity magic
+od -t x1 -An -j188 -N4 $dev > out || fail=1
+echo " 60 0d de ee" > exp
+# expect it to be 60 0d de ee, not 00 00 00 00
+compare out exp || fail=1
+
+Exit $fail

commit 0fe636d803496c0fff7ab0944d4d8c3b01c6d929
Author: Karel Zak <kzak at redhat.com>
Date:   Fri Feb 19 16:12:52 2010 +0100

    sun: initialize basic partition table fields
    
    libparted completely ignores basic fields (version, nparts and sanity)
    in the sun VTOC, then for example fdisk prints warnings for such
    partition table:
    
    	# fdisk -lu /dev/sdb
    	Detected sun disklabel with wrong version [0x00000000].
    	Detected sun disklabel with wrong sanity [0x00000000].
    	Detected sun disklabel with wrong num_partitions [0].
    
    It seems that the current libparted sun support follows old Linux
    kernel code, but the code was changed 3 years ago (see kernel commit
    3961bae0ac030a70ae2e0578270203889021f1a1).
    
    Note that the number of partitions (nparts) is optional for Linux
    kernel, but fdisk(8) strictly requires SUN_DISK_MAXPARTITIONS (=8)
    there. This patch sets nparts to SUN_DISK_MAXPARTITIONS rather then
    use a real number of partitions.
    
    * NEWS (Bug fixes): Mention it.
    * libparted/labels/sun.c: Update from kernel.
    * tests/t4001-sun-vtoc.sh: New file.  Test for this.

diff --git a/NEWS b/NEWS
index 30ca181..53f83ce 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,12 @@ GNU parted NEWS                                    -*- outline -*-
   found to be corrupt.
   [bug introduced prior to parted-1.8.0]
 
+  sun: the version, sanity and nparts VTOC fields were ignored by libparted.
+  Those fields are properly initialized now. The nparts (number of partitions)
+  field is initialized to 8 (max. number of sun partitions) rather that to a
+  real number of partitions. This solution is compatible with Linux kernel
+  and Linux fdisk.
+
   "make install" no longer installs tests programs named disk and label
 
   libparted: try harder to inform kernel of partition changes.
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index 9aeddcf..177a47c 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -44,6 +44,9 @@
 #define SUN_DISK_MAGIC		0xDABE	/* Disk magic number */
 #define SUN_DISK_MAXPARTITIONS	8
 
+#define SUN_VTOC_VERSION	1
+#define SUN_VTOC_SANITY		0x600DDEEE
+
 #define WHOLE_DISK_ID		0x05
 #define WHOLE_DISK_PART		2	/* as in 0, 1, 2 (3rd partition) */
 #define LINUX_SWAP_ID		0x82
@@ -68,9 +71,18 @@ struct __attribute__ ((packed)) _SunPartitionInfo {
 
 struct __attribute__ ((packed)) _SunRawLabel {
 	char 		info[128];	/* Informative text string */
-	u_int8_t	spare0[14];
+	u_int32_t	version;	/* Layout version */
+	u_int8_t	volume[8];	/* Volume name */
+	u_int16_t	nparts;		/* Number of partitions */
 	SunPartitionInfo infos[SUN_DISK_MAXPARTITIONS];
-	u_int8_t	spare1[246];	/* Boot information etc. */
+	u_int16_t	padding;	/* Alignment padding */
+	u_int32_t	bootinfo[3];	/* Info needed by mboot */
+	u_int32_t	sanity;		/* To verify vtoc sanity */
+	u_int32_t	reserved[10];	/* Free space */
+	u_int32_t	timestamp[8];	/* Partition timestamp */
+	u_int32_t	write_reinstruct; /* sectors to skip, writes */
+	u_int32_t	read_reinstruct; /* sectors to skip, reads */
+	u_int8_t	spare1[148];	/* Padding */
 	u_int16_t	rspeed;		/* Disk rotational speed */
 	u_int16_t	pcylcount;	/* Physical cylinder count */
 	u_int16_t	sparecyl;	/* extra sects per cylinder */
@@ -195,6 +207,10 @@ sun_alloc (const PedDevice* dev)
 	label->nsect	= PED_CPU_TO_BE16 (bios_geom->sectors);
 	label->ncyl	= PED_CPU_TO_BE16 (dev->length / cyl_size);
 
+	label->sanity   = PED_CPU_TO_BE32 (SUN_VTOC_SANITY);
+	label->version  = PED_CPU_TO_BE32 (SUN_VTOC_VERSION);
+	label->nparts   = PED_CPU_TO_BE16 (SUN_DISK_MAXPARTITIONS);
+
 	/* Add a whole disk partition at a minimum */
 	label->infos[WHOLE_DISK_PART].id = WHOLE_DISK_ID;
 	label->partitions[WHOLE_DISK_PART].start_cylinder = 0;
diff --git a/tests/t4001-sun-vtoc.sh b/tests/t4001-sun-vtoc.sh
new file mode 100755
index 0000000..78c10c6
--- /dev/null
+++ b/tests/t4001-sun-vtoc.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# Ensure that Sun VTOC is properly initialized.
+
+# Copyright (C) 2009-2010 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Written by Karel Zak <kzak at redhat.com>
+
+test_description='test Sun VTOC initialization'
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+N=2M
+dev=loop-file
+test_expect_success \
+    'create a file to simulate the underlying device' \
+    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
+
+test_expect_success \
+    'label the test disk' \
+    'parted -s $dev mklabel sun > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+test_expect_success \
+    'extract version' \
+    'od -t x1 -An -j128 -N4 $dev > out && echo " 00 00 00 01" > exp'
+test_expect_success 'expect it to be 00 00 00 01, not 00 00 00 00' \
+    'compare out exp'
+
+test_expect_success \
+    'extract nparts' \
+    'od -t x1 -An -j140 -N2 $dev > out && echo " 00 08" > exp'
+test_expect_success 'expect it to be 00 08, not 00 00' 'compare out exp'
+
+test_expect_success \
+    'extract sanity magic' \
+    'od -t x1 -An -j188 -N4 $dev > out && echo " 60 0d de ee" > exp'
+test_expect_success 'expect it to be 60 0d de ee, not 00 00 00 00' \
+    'compare out exp'
+
+test_done

commit d462d59f8c290edcc053b6677143d745c4d51d67
Author: Jim Meyering <meyering at redhat.com>
Date:   Thu Feb 25 15:05:46 2010 +0100

    tests: wrap the dup-clobber test in a script, ...
    
    so that its artifacts are created in the usual temporary subdir
    * tests/Makefile.am (TESTS): Remove dup-clobber, and instead...
    Add t0500-dup-clobber.sh.
    * tests/t0500-dup-clobber.sh: New script.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index afe711c..d0d301d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,7 +2,6 @@ XFAIL_TESTS = \
   t3200-type-change.sh
 
 TESTS = \
-  dup-clobber \
   t0000-basic.sh \
   t0001-tiny.sh \
   t0010-script-no-ctrl-chars.sh \
@@ -17,6 +16,7 @@ TESTS = \
   t0280-gpt-corrupt.sh \
   t0300-dos-on-gpt.sh \
   t0400-loop-clobber-infloop.sh \
+  t0500-dup-clobber.sh \
   t1100-busy-label.sh \
   t1700-ext-probe.sh \
   t2100-mkswap.sh \
diff --git a/tests/t0500-dup-clobber.sh b/tests/t0500-dup-clobber.sh
new file mode 100644
index 0000000..d699a4f
--- /dev/null
+++ b/tests/t0500-dup-clobber.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Drive the dup-clobber program.
+
+# Copyright (C) 2009-2010 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 3 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, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  parted --version
+fi
+
+: ${srcdir=.}
+. $srcdir/t-lib.sh
+
+PATH="..:$PATH"
+export PATH
+
+fail=0
+dup-clobber || fail=1
+
+Exit $fail



More information about the Parted-commits mailing list