bug-parted
[Top][All Lists]
Advanced

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

Re: GPT: don't misbehave with e.g., a 9-entry partition


From: Jim Meyering
Subject: Re: GPT: don't misbehave with e.g., a 9-entry partition
Date: Fri, 04 Nov 2011 09:36:51 +0100

Jim Meyering wrote:
> Just over a year ago, Robert Herndon reported that parted
> would fail to read partition tables with say, 9 partition array
> entries instead of the usual 128:
>
>     http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10173/
>
> His proposed solution used in 1/4 turned out to be the best way
> I could see to solve the problem.  If someone sees a cleaner
> approach, please let me know.  Part of the hold up was that
> I wanted a way to create an offending partition table to be
> used in a test to exercise this fix.  I completed the script
> in 3/4 and used it in 4/4 to ensure at least that
> "parted -s $dev print" can now deal with such partition tables.
>
>   [PATCH 1/4] gpt: prepare for tables with n_partition_array_entries
>   [PATCH 2/4] gpt: don't misbehave with e.g., a 9-entry partition
>   [PATCH 3/4] tests: rewrite/complete GPT-munging perl script
>   [PATCH 4/4] tests: exercise the "GPT vs other-sized partition entry

FYI, the tests weren't quite right.

I'm merging the following changes into 3&4 above:
  - the rewritten script has to be distributed, now that it's used in a test
  - "make check" failed when simulating sector size > 512; addressing the
      FIXME comment in the new script almost made that work
  - there was one remaining hard-coded "512" in the script.  Fixing *that*, and
  - making t0210-*.sh use the script's new --sector-size= option solved
      the problem

>From 35659557391375b29e90cd127d53873b4b356add Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 4 Nov 2011 07:56:23 +0100
Subject: [PATCH 1/4] * tests/Makefile.am (EXTRA_DIST): Add gpt-header-munge.

---
 tests/Makefile.am |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 47fd8b6..71787e5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,7 +63,7 @@ TESTS = \

 EXTRA_DIST = \
   $(TESTS) lvm-utils.sh t-local.sh t-lvm.sh \
-  init.cfg init.sh t-lib-helpers.sh
+  init.cfg init.sh t-lib-helpers.sh gpt-header-munge

 check_PROGRAMS = print-align print-max dup-clobber duplicate
 LDADD = \
--
1.7.8.rc0.35.gee6df


>From 1cef79efc7858e8f500c76b182b8527ad7ea8b96 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 4 Nov 2011 08:13:34 +0100
Subject: [PATCH 2/4] * tests/gpt-header-munge (usage): New option:
 --sector-size=N

---
 tests/gpt-header-munge |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/gpt-header-munge b/tests/gpt-header-munge
index 297e8ae..c97a53d 100755
--- a/tests/gpt-header-munge
+++ b/tests/gpt-header-munge
@@ -30,8 +30,8 @@ my $gpt_header_len = 92;
 # This too is specified in the GPT header, but AFAIK, no one changes it.
 my $pe_size = 128;

-# Sector size; FIXME: make this an option; default to 512.
-my $ss = 512;
+# Sector size.
+my $ss;

 # Sector number of the backup GPT header, to be read from the primary header.
 my $backup_LBA;
@@ -174,6 +174,7 @@ This option must be specified:

 The following are optional:

+   --sector-size=N    assume sector size of N bytes (default: 512)
    --help             display this help and exit
    --version          output version information and exit

@@ -195,6 +196,7 @@ EOF
   GetOptions
     (
      'n-partition-array-entries=i' => \$n_partition_entries,
+     'sector-size=i' => \$ss,

      help => sub { usage 0 },
      version => sub { print "$ME version $VERSION\n"; exit },
@@ -203,6 +205,9 @@ EOF
   defined $n_partition_entries
     or (warn "$ME: --n-partition-array-entries=N not specified\n"), usage 1;

+  defined $ss
+    or $ss = 512;
+
   # Require sensible number:
   # It must either be <= 128, or else a multiple of 4 so that at 128 bytes 
each,
   # this array fully occupies a whole number of 512-byte sectors.
--
1.7.8.rc0.35.gee6df


>From 930f798a0e97f22a0f4b7e417e432d422bb7c558 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 4 Nov 2011 08:26:50 +0100
Subject: [PATCH 3/4] remove a hard-coded 512 (use $ss instead)

---
 tests/gpt-header-munge |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tests/gpt-header-munge b/tests/gpt-header-munge
index c97a53d..9b869dd 100755
--- a/tests/gpt-header-munge
+++ b/tests/gpt-header-munge
@@ -143,7 +143,7 @@ sub set_CRCs ($$$$)
       $off % $ss == 0
        or die "$ME: internal error: starting LBA byte offset($off) is"
          . " not a multiple of $ss\n";
-      my $lba = $off / 512;
+      my $lba = $off / $ss;
       substr ($$buf, 72, 8) = pack ('Q<', $lba);
     }

--
1.7.8.rc0.35.gee6df


>From d0752fff3fda0cdd99ff18440968c00b62740176 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 4 Nov 2011 08:28:24 +0100
Subject: [PATCH 4/4] tests: pass --sector-size=$ss to gpt-header-munge

* tests/t0210-gpt-resized-partition-entry-array.sh (dev): Pass
--sector-size=$ss to gpt-header-munge.
---
 tests/t0210-gpt-resized-partition-entry-array.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tests/t0210-gpt-resized-partition-entry-array.sh 
b/tests/t0210-gpt-resized-partition-entry-array.sh
index 8a3dcea..c3d3ee2 100755
--- a/tests/t0210-gpt-resized-partition-entry-array.sh
+++ b/tests/t0210-gpt-resized-partition-entry-array.sh
@@ -18,6 +18,8 @@

 . "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir

+ss=$sector_size_
+
 N=2M
 dev=loop-file
 # create a file large enough to hold a GPT partition table
@@ -28,7 +30,7 @@ parted -s $dev mklabel gpt > out 2>&1 || fail=1
 # expect no output
 compare out /dev/null || fail=1

-gpt-header-munge --n=9 $dev || fail=1
+gpt-header-munge --sector-size=$ss --n=9 $dev || fail=1

 parted -m -s $dev u s p > out 2>&1 || fail=1
 sed 's/.*:gpt:/:gpt:/' out > k && mv k out
--
1.7.8.rc0.35.gee6df



reply via email to

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