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

Jim Meyering meyering at alioth.debian.org
Tue Feb 17 11:47:25 UTC 2009


 libparted/labels/gpt.c |   25 +++++++++++++--------
 tests/Makefile.am      |    1 
 tests/t0200-gpt.sh     |   56 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 10 deletions(-)

New commits:
commit 1eef5e4d03df7678ac9b86db1bb8eb5d43cc59be
Author: Jim Meyering <meyering at redhat.com>
Date:   Mon Feb 16 17:54:57 2009 +0100

    gpt: add a test: printing a partition table must not modify it
    
    * tests/t0200-gpt.sh: New file.
    * tests/Makefile.am (TESTS): Add the new test.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1214f9c..14e4862 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,7 @@
 TESTS = \
   t0000-basic.sh \
   t0100-print.sh \
+  t0200-gpt.sh \
   t1000-mkpartfs.sh \
   t1100-busy-label.sh \
   t1500-small-ext2.sh \
diff --git a/tests/t0200-gpt.sh b/tests/t0200-gpt.sh
new file mode 100755
index 0000000..633d580
--- /dev/null
+++ b/tests/t0200-gpt.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Copyright (C) 2009 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/>.
+
+test_description='printing a GPT partition table must not modify it'
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+N=2M
+dev=loop-file
+test_expect_success \
+    'create a file large enough to hold a GPT partition table' \
+    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
+
+test_expect_success \
+    'create a GPT partition table' \
+    'parted -s $dev mklabel gpt > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+test_expect_success \
+    'save a copy of the original primary GPT table' \
+    'dd if=$dev of=before count=1 skip=1'
+
+test_expect_success \
+    'extend the backing file by 1 byte' \
+    'printf x >> $dev'
+
+test_expect_success \
+    'use parted simply to print the partition table' \
+    'parted -m -s $dev u s p > out 2> err'
+# don't bother comparing stdout
+test_expect_success 'expect no stderr' 'compare err /dev/null'
+
+test_expect_success \
+    'extract the primary GPT table again' \
+    'dd if=$dev of=after count=1 skip=1'
+
+test_expect_success \
+    'compare partition tables (they had better be identical)' \
+    'compare before after'
+
+test_done

commit d7d9f2c40c6bb3e83a7e6ea3164b4f4eb7440a47
Author: Petr Uzel <petr.uzel at suse.cz>
Date:   Fri Feb 13 13:27:55 2009 +0100

    gpt: do not automatically "correct" a suspicious GPT partition table
    
    Previously, when parted was invoked on a disk with a GPT partition table
    and the backup GPT was not in the last sector of the disk, and even if
    the requested operation was just to print the partition table, parted
    would "repair" this automatically. This behavior is undesirable in the
    following situation:
    
    dm-raid on top of block device. The dm-raid is partitioned with GPT. If
    the dm-raid starts on the first block of underlying device (AFAIK this is
    the case with FastTrack controllers) and the user runs parted on the
    dm-raid, it will identify the physical device as being partitioned with
    GPT and see the backup GPT table not to be in the last sector of the
    physical device and thus move it to this location (which may lead to
    destruction of dm-raid metadata in case they are located at the end of
    physical device).
    
    This patch modifies parted's behavior to ignore fixing of backup GPT
    position by default.

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 13d2e88..eea562d 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -831,21 +831,26 @@ gpt_read (PedDisk * disk)
 			char* zeros = ped_malloc (pth_get_size (disk->dev));
 
 #ifndef DISCOVER_ONLY
-			if (ped_exception_throw (
+			switch (ped_exception_throw (
 				PED_EXCEPTION_ERROR,
-				PED_EXCEPTION_FIX | PED_EXCEPTION_CANCEL,
+				PED_EXCEPTION_FIX | PED_EXCEPTION_CANCEL | PED_EXCEPTION_IGNORE,
 		_("The backup GPT table is not at the end of the disk, as it "
 		  "should be.  This might mean that another operating system "
 		  "believes the disk is smaller.  Fix, by moving the backup "
-		  "to the end (and removing the old backup)?"))
-					== PED_EXCEPTION_CANCEL)
-				goto error_free_gpt;
+		  "to the end (and removing the old backup)?"))) {
+				case PED_EXCEPTION_CANCEL:
+					goto error_free_gpt;
+				case PED_EXCEPTION_FIX:
+					write_back = 1;
+					memset (zeros, 0, disk->dev->sector_size);
+					ped_device_write (disk->dev, zeros,
+							  PED_LE64_TO_CPU (gpt->AlternateLBA),
+							  1);
+					break;
+				default:
+					break;
+			}
 
-			write_back = 1;
-			memset (zeros, 0, disk->dev->sector_size);
-			ped_device_write (disk->dev, zeros,
-					  PED_LE64_TO_CPU (gpt->AlternateLBA),
-					  1);
 #endif /* !DISCOVER_ONLY */
 		}
 	} else { /* primary GPT *not* ok */



More information about the Parted-commits mailing list