[parted-devel] [PATCH 2/2] tests: add t0301-overwrite-gpt-pmbr.sh
Jim Meyering
jim at meyering.net
Sat Mar 24 09:07:49 UTC 2012
Brian C. Lane wrote:
> From: "Brian C. Lane" <bcl at redhat.com>
>
> Make sure parted checks the PMBR before the GPT partition table.
>
> * NEWS: Update with new GPT behavior
> * tests/Makefile.am: Add new test
> * tests/overwrite-gpt-pmbr.sh: new test
> ---
...
> diff --git a/tests/t0301-overwrite-gpt-pmbr.sh b/tests/t0301-overwrite-gpt-pmbr.sh
...
> +PARTED_SECTOR_SIZE=4096
> +export PARTED_SECTOR_SIZE
I suppose the above two lines were just for testing?
Their presence would serve solely to disable tests with a
smaller simulated sector size. I've removed them.
> +dev=loop-file
> +# create a backing file large enough for a GPT partition table
> +dd if=/dev/null of=$dev seek=4001 2> /dev/null || framework_failure
> +
> +# create a GPT partition table
> +parted -s $dev mklabel gpt > out 2>&1 || fail=1
> +# expect no output
> +compare /dev/null out || fail=1
> +
> +# create a DOS partition table
> +fdisk $dev > out 2>&1 <<EOF
> +o
> +w
> +EOF
This would be our first use of fdisk.
Technically, we'd have to skip the test when fdisk is not available.
Instead, I've adjusted the test not to require that: instead, create
an MSDOS table in a separate file and transplant it into the GPT-labeled one.
I've also adjusted the NEWS entry.
I'll wait for your ACK before pushing this.
>From 5021bbdc6ee892890c2c6fede806b9ad6a6a9378 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl at redhat.com>
Date: Tue, 20 Mar 2012 17:25:23 -0700
Subject: [PATCH] tests: add t0301-overwrite-gpt-pmbr.sh
Make sure parted checks the PMBR before the GPT partition table.
* NEWS: Update with new GPT behavior.
* tests/overwrite-gpt-pmbr.sh: New test.
* tests/Makefile.am (TESTS): Add it.
---
NEWS | 5 +++++
tests/Makefile.am | 1 +
tests/t0301-overwrite-gpt-pmbr.sh | 44 +++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100755 tests/t0301-overwrite-gpt-pmbr.sh
diff --git a/NEWS b/NEWS
index 3bef20e..3969c44 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU parted NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug Fixes
+
+ libparted: treat a disk with no pMBR as an msdos-labeled disk
+ even when it has valid GPT headers.
+
* Noteworthy changes in release 3.1 (2012-03-02) [stable]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1b37fd9..1264812 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,7 @@ TESTS = \
t0250-gpt.sh \
t0280-gpt-corrupt.sh \
t0300-dos-on-gpt.sh \
+ t0301-overwrite-gpt-pmbr.sh \
t0400-loop-clobber-infloop.sh \
t0500-dup-clobber.sh \
t0501-duplicate.sh \
diff --git a/tests/t0301-overwrite-gpt-pmbr.sh b/tests/t0301-overwrite-gpt-pmbr.sh
new file mode 100755
index 0000000..e7edb66
--- /dev/null
+++ b/tests/t0301-overwrite-gpt-pmbr.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Test creating a msdos partition over a GPT partition with
+# fdisk which doesn't remove the GPT partitions, only the PMBR
+
+# Copyright (C) 2009-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=loop-file
+
+# Create a GPT partition table.
+dd if=/dev/null of=$dev bs=$ss seek=80 2> /dev/null || framework_failure
+parted -s $dev mklabel gpt > out 2>&1 || framework_failure_
+compare /dev/null out || framework_failure_
+
+# Create an MSDOS partition table in another file.
+dd if=/dev/null of=m bs=$ss seek=80 2> /dev/null || framework_failure
+parted -s m mklabel msdos > out 2>&1 || framework_failure_
+compare /dev/null out || framework_failure_
+
+# Transplant the MSDOS MBR into the GPT-formatted image.
+dd if=m of=$dev bs=$ss count=1 conv=notrunc || framework_failure_
+
+# Now, try to create a GPT partition table in $dev.
+# Before, parted would prompt, asking about the apparent inconsistency.
+parted -s $dev mklabel gpt > out 2>&1 || fail=1
+# expect no output
+compare /dev/null out || fail=1
+
+Exit $fail
--
1.7.10.rc1.23.g16a10
More information about the parted-devel
mailing list