Petr Uzel <[email protected]> wrote:
> Here is a simple shell script that illustrates the incorrect behavior.
> The patch I've sent before fixes the issue (at least for me ;) ).
>
> ============================
> I'd like to transform it to the form of parted-testsuite, but it will
> take me some time as I'm not familiar much with it - any hints would
> be highly appreciated ;)

Great.
Thanks for the example.
Here's how I'd do it, using only a backing file.
No need for lvm.
First I do it at the shell/command-line level:

  dev=file
  dd if=/dev/null of=$dev bs=1 seek=30M
  ./parted -s $dev mklabel gpt
  dd if=$dev of=before bs=512 count=1 skip=1 2>/dev/null
  ./parted -m -s $dev p

  # make the backing file larger.  one byte is enough
  printf x >> $dev

  ./parted -m -s $dev p
  Error: The backup GPT table is not at the end of the disk, as it should be...
  ...
  dd if=$dev of=after bs=512 count=1 skip=1 2>/dev/null
  cmp before after
  before after differ: byte 17, line 1
  [Exit 1]

Then I made that into a test like any of the others:
[I chose a low numbered name for the new file, because this is a
 very fundamental property of partition tables (no file system
 aspects involved) ]

In the process, I discovered a GPT-related bug that
would provoke a failed assertion.  So I fixed that.  Patch below.
Would you like to write the test case for *it*?
If so, please name it t0201-gpt.sh, since it'll be
very similar to the one below (which has a FIXME
comment I plan to address before pushing).

My plan for tomorrow:

  - apply your patch, and test a little
  - address FIXME comment in the test script below
  - ensure that the test passes
  - push your patch and the test-adding one

If you write the test to exercise my patch,
(or tell me you'd rather not, in which case I'll do it),
I'll push those two change sets, too.

>From efeaceacd3af6a8b1b7dcc006e87f99daf15f997 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Mon, 16 Feb 2009 17:54:57 +0100
Subject: [PATCH 1/2] 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.
---
 tests/Makefile.am  |    1 +
 tests/t0200-gpt.sh |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100755 tests/t0200-gpt.sh

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..013b0a4
--- /dev/null
+++ b/tests/t0200-gpt.sh
@@ -0,0 +1,55 @@
+#!/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='ensure that printing a partition table does 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 p > out 2> err'
+# FIXME compare expected out and err
+
+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
--
1.6.2.rc0.264.g60787


>From 3dd5698e74dcff6b6a6af0f53a02ec880e64701b Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Mon, 16 Feb 2009 19:02:58 +0100
Subject: [PATCH 2/2] avoid failed assertion when creating a GPT partition 
table...

on top of an old one for a larger device

Here's the reproducer:

dev=file
dd if=/dev/null of=$dev bs=1 seek=30M
./parted -s $dev mklabel gpt
dd if=$dev of=prim_gpt_before bs=512 count=1 skip=1 2>/dev/null
./parted -m -s $dev p
truncate -s +10M $dev
./parted -m -s $dev p
dd if=/dev/null of=$dev bs=1 seek=30M
./parted -s $dev mklabel gpt
---
 libparted/labels/gpt.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 13d2e88..62beead 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -4,7 +4,7 @@
     original version by Matt Domsch <[email protected]>
     Disclaimed into the Public Domain

-    Portions Copyright (C) 2001-2003, 2005-2008 Free Software Foundation, Inc.
+    Portions Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.

     EFI GUID Partition Table handling
     Per Intel EFI Specification v1.02
@@ -824,8 +824,13 @@ gpt_read (PedDisk * disk)
                goto error;

        if (_read_header (disk->dev, &gpt, 1)) {
-               PED_ASSERT ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
-                               <= disk->dev->length - 1, goto error_free_gpt);
+               /* There used to be a GPT partition table here, with an
+                  alternate LBA that extended beyond the current
+                  end-of-device.  Treat it as a non-match.   */
+               if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
+                    > disk->dev->length - 1)
+                       goto error_free_gpt;
+
                if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
                                < disk->dev->length - 1) {
                        char* zeros = ped_malloc (pth_get_size (disk->dev));
--
1.6.2.rc0.264.g60787

_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to