[Parted-commits] GNU Parted Official Repository: Changes to 'master'
Jim Meyering
meyering at alioth.debian.org
Mon Jan 9 11:03:42 UTC 2012
libparted/labels/gpt.c | 21 +++------
tests/Makefile.am | 1
tests/t0203-gpt-shortened-device-primary-valid.sh | 49 ++++++++++++++++++++++
3 files changed, 58 insertions(+), 13 deletions(-)
New commits:
commit 1159193e4648b9264cbe322c575ae1446be5cf48
Author: Jim Meyering <meyering at redhat.com>
Date: Mon Jan 9 09:21:09 2012 +0100
libparted: gpt: a smaller device need not render both headers invalid
Putting a valid GPT-labeled image on a smaller device, (i.e., one that
truncates the backup GPT header, but that does not impact the primary
one) should not render the primary header invalid.
* libparted/labels/gpt.c (_header_is_valid): Do *not* reject a header
when its last_usable value is larger than the device length.
This reverts part of commit v3.0-10-g99f9c6a, "gpt: don't abort for a
truncated GPT-formatted device". With this change, running parted in
interactive mode with such an image/device combination will recognize
that only the backup header is corrupt, and will offer to correct it.
Before, it would report that both headers were corrupt.
* tests/t0203-gpt-shortened-device-primary-valid.sh: New file.
* tests/Makefile.am (TESTS): Add it.
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index b812c4a..3fdd672 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -4,7 +4,7 @@
original version by Matt Domsch <Matt_Domsch at dell.com>
Disclaimed into the Public Domain
- Portions Copyright (C) 2001-2003, 2005-2011 Free Software Foundation, Inc.
+ Portions Copyright (C) 2001-2003, 2005-2012 Free Software Foundation, Inc.
EFI GUID Partition Table handling
Per Intel EFI Specification v1.02
@@ -670,10 +670,6 @@ _header_is_valid (PedDisk const *disk, GuidPartitionTableHeader_t *gpt,
if (first_usable < 3)
return 0;
- PedSector last_usable = PED_LE64_TO_CPU (gpt->LastUsableLBA);
- if (disk->dev->length < last_usable)
- return 0;
-
origcrc = gpt->HeaderCRC32;
gpt->HeaderCRC32 = 0;
if (pth_crc32 (dev, gpt, &crc) != 0)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 89162ba..f442204 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ TESTS = \
t0201-gpt.sh \
t0202-gpt-pmbr.sh \
t0203-gpt-tiny-device-abort.sh \
+ t0203-gpt-shortened-device-primary-valid.sh \
t0205-gpt-list-clobbers-pmbr.sh \
t0206-gpt-print-with-corrupt-primary-clobbers-pmbr.sh \
t0207-IEC-binary-notation.sh \
diff --git a/tests/t0203-gpt-shortened-device-primary-valid.sh b/tests/t0203-gpt-shortened-device-primary-valid.sh
new file mode 100755
index 0000000..27f2c5f
--- /dev/null
+++ b/tests/t0203-gpt-shortened-device-primary-valid.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Demonstrate that placing a valid gpt-labeled image on a shorter device
+# does not invalidate the primary GPT header.
+
+# Copyright (C) 2012 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/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+ss=$sector_size_
+
+dev=dev-file
+dd if=/dev/null of=$dev bs=$ss seek=100 || fail=1
+parted -s -- $dev mklabel gpt || fail=1
+
+# Chop off the last two sectors.
+dd if=/dev/null of=$dev bs=$ss seek=98 || fail=1
+printf 'ignore\nok\n' > in
+parted -m ---pretend-input-tty $dev u s p < in > out 2> err || fail=1
+
+# Remove abs name of $dev_file.
+sed "s, [^ ]*/$dev, $dev," err > k && mv k err || fail=1
+# Compare only the last line, to avoid control chars of interactive mode.
+tail -1 out > k && mv k out || fail=1
+sed "s,.*/$dev:,$dev:," out > k && mv k out || fail=1
+
+emit_superuser_warning > err.exp || fail=1
+cat <<EOF >> err.exp || fail=1
+Error: end of file while reading $dev
+Error: The backup GPT table is corrupt, but the primary appears OK, so that will be used.
+EOF
+
+echo "$dev:98s:file:$ss:$ss:gpt:;" > out.exp || fail=1
+
+compare err.exp err || fail=1
+compare out.exp out || fail=1
+
+Exit $fail
commit 2f1f6c9a808987c288e83a1e91a23e5d6243066c
Author: Jim Meyering <meyering at redhat.com>
Date: Fri Dec 30 21:03:06 2011 +0100
gpt: eliminate four PED_ASSERT uses
* libparted/labels/gpt.c (_parse_header): Convert a few PED_ASSERT
uses to friendlier 'test-and-return-0's. Reported by Graham Markall
in http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10653
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 9d464c6..b812c4a 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -728,19 +728,18 @@ _parse_header (PedDisk *disk, const GuidPartitionTableHeader_t *gpt,
GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / disk->dev->sector_size;
if (last_usable_if_grown > last_usable_min_default)
- {
- last_usable_if_grown = last_usable_min_default;
- }
+ last_usable_if_grown = last_usable_min_default;
- PED_ASSERT (last_usable > first_usable);
- PED_ASSERT (last_usable <= disk->dev->length);
+ if (last_usable <= first_usable
+ || disk->dev->length < last_usable)
+ return 0;
- PED_ASSERT (last_usable_if_grown > first_usable);
- PED_ASSERT (last_usable_if_grown <= disk->dev->length);
+ if (last_usable_if_grown <= first_usable
+ || disk->dev->length < last_usable_if_grown)
+ return 0;
if (!asked_already && last_usable < last_usable_if_grown)
{
-
PedExceptionOption q;
q = ped_exception_throw
More information about the Parted-commits
mailing list