bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possibly Broken GPT from Solaris


From: Jim Meyering
Subject: Re: Possibly Broken GPT from Solaris
Date: Sun, 22 Jan 2012 23:12:22 +0100

Jim Meyering wrote:
> Jim Meyering wrote:
...
>> Thanks for the report.
>> I fixed parted to handle precisely the case of zfs-related GPT tables.
>> Here's the NEWS entry for that change:
>>
>>     libparted can now read partition tables with a number of partition
>>     array entries that is different from the default of 128.  Before,
>>     it would fail to recognize them and could even read beyond the end
>>     of a heap-allocated buffer.
>>
>> Here's the commit:
>>
>>     gpt: don't misbehave with e.g., a 9-entry partition array
>>     http://git.sv.gnu.org/cgit/parted.git/commit/?id=ce85c5145ed5e267e
>>
>> There hasn't been a release since that change, so if you want to
>> try it before parted-3.1, you'll have to build from git.
>>
>> Using the latest built from git against your image, I get this:
>>
>>   $ ./parted -s /t/solaris-data.img u s p
>>   Error: 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)?
>>   Warning: Not all of the space available to /t/solaris-data.img appears to 
>> be used, you can fix the GPT to use all of the space (an extra 176 blocks) 
>> or continue with the current setting?
>>   Model:  (file)
>>   Disk /t/solaris-data.img: 204800s
>>   Sector size (logical/physical): 512B/512B
>>   Partition Table: gpt
>>
>>   Number  Start    End      Size     File system  Name  Flags
>>    1      256s     188206s  187951s               zfs
>>    9      188207s  204590s  16384s
>>
>> If you rerun it without -s, you can actually respond to those prompts.
>> Hmm... I have just done that, answered "f" (fix) to the two prompts,
>> and it seemed to succeed (exit 0), yet rerunning that same command,
>> I see something is not quite right:
>>
>>   $ ./parted /t/solaris-data.img u s p
>>   WARNING: You are not superuser.  Watch out for permissions.
>>   Error: Both the primary and backup GPT tables are corrupt.  Try making a 
>> fresh
>>   table, and using Parted's rescue feature to recover partitions.
>>   Model:  (file)
>>   Disk /t/solaris-data.img: 204800s
>>   Sector size (logical/physical): 512B/512B
>>   Partition Table: unknown
>>
>> I'm debugging that right now...
>
> Notice that while the problem you reported was fixed some time ago,
> my little demonstration above exposed a different bug.
>
> I've just diagnosed and fixed that other bug with these two patches, and
> will push them as soon as I've written a test to exercise the affected code.

I've amended that fix with a NEWS update:

  libparted: given a GPT table with a partition table array of length, say 9,
  (usually, there are at least 128 entries) and when run in interactive mode
  with the backup header not at the end of the device where it belongs, parted
  would offer to fix it by moving the backup header to the end.  If you
  accepted, parted could corrupt both headers, truncating their on-disk
  PTE arrays.  Now, parted handles this case.

added this test, and pushed:

>From 552995beccf1c7543b37584bb037e6a1f508c8a4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 22 Jan 2012 14:56:47 +0100
Subject: [PATCH] tests: test for yesterday's bug fix

* tests/Makefile.am (TESTS): Add it.
* tests/t0211-gpt-rewrite-header.sh: New test.
---
 tests/Makefile.am                 |    1 +
 tests/t0211-gpt-rewrite-header.sh |   79 +++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)
 create mode 100644 tests/t0211-gpt-rewrite-header.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 77a1cae..88efbdd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,6 +21,7 @@ TESTS = \
   t0207-IEC-binary-notation.sh \
   t0208-mkpart-end-in-IEC.sh \
   t0210-gpt-resized-partition-entry-array.sh \
+  t0211-gpt-rewrite-header.sh \
   t0220-gpt-msftres.sh \
   t0250-gpt.sh \
   t0280-gpt-corrupt.sh \
diff --git a/tests/t0211-gpt-rewrite-header.sh 
b/tests/t0211-gpt-rewrite-header.sh
new file mode 100644
index 0000000..475c3db
--- /dev/null
+++ b/tests/t0211-gpt-rewrite-header.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+# exercise parted's gpt-rewriting code
+# When it encounters a GPT device with backup not at the end,
+# parted (without -s) offers to correct that by moving the backup
+# header to the end of the device.  Before parted-3.1, when it attempted
+# to do that, starting with a 9-PTE array, it would render the result invalid.
+
+# 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 $srcdir
+require_perl_digest_crc_
+
+ss=$sector_size_
+
+ns=100         # Initial number of sectors.
+ns2=$((ns+64)) # Some larger number of sectors.
+dev=loop-file
+# create a file large enough to hold a GPT partition table
+dd if=/dev/null of=$dev bs=$ss seek=$ns || framework_failure
+
+# create a GPT partition table with 9 PTEs.
+parted -a min -s $dev mklabel gpt \
+    mkpart p1 34s 34s \
+    mkpart p2 35s 35s \
+    mkpart p3 36s 36s \
+    mkpart p4 37s 37s \
+    mkpart p5 38s 38s \
+    mkpart p6 39s 39s \
+    mkpart p7 40s 40s \
+    mkpart p8 41s 41s \
+    mkpart p9 42s 42s \
+  > out 2>&1 || fail=1
+# expect no output
+compare /dev/null out || fail=1
+
+# Adjust the GPT table to have only 9 PTEs.
+gpt-header-munge --sector-size=$ss --n=9 $dev || fail=1
+
+# Extend size of the device.
+dd if=/dev/null of=$dev bs=$ss seek=$ns2 || fail=1
+
+printf '%s\n' f f > in || fail=1
+
+# This would always succeed, even before.
+parted ---pretend-input-tty $dev u s p < in || fail=1
+
+printf '%s\n' \
+    'BYT;' \
+    "...:${ns2}s:file:$ss:$ss:gpt:;" \
+    '1:34s:34s:1s::p1:;' \
+    '2:35s:35s:1s::p2:;' \
+    '3:36s:36s:1s::p3:;' \
+    '4:37s:37s:1s::p4:;' \
+    '5:38s:38s:1s::p5:;' \
+    '6:39s:39s:1s::p6:;' \
+    '7:40s:40s:1s::p7:;' \
+    '8:41s:41s:1s::p8:;' \
+    '9:42s:42s:1s::p9:;' \
+  > exp || fail=1
+
+# Before parted-3.1, this would fail, reporting that both tables are corrupt.
+parted -m -s $dev u s p > out 2>&1 || fail=1
+sed '2s/^[^:]*:/...:/' out > k && mv k out
+compare exp out || fail=1
+
+Exit $fail
--
1.7.9.rc2.2.g183d6



reply via email to

[Prev in Thread] Current Thread [Next in Thread]