]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blame - parted/patches/parted-2.1-gpt-clobber-pmbr-rh563211.patch
Move all packages to root.
[people/amarx/ipfire-3.x.git] / parted / patches / parted-2.1-gpt-clobber-pmbr-rh563211.patch
CommitLineData
a7d4b011
SS
1From 28be933ce317f954be1e39a50d8f42197d6e3c15 Mon Sep 17 00:00:00 2001
2From: Jim Meyering <meyering@redhat.com>
3Date: Sun, 7 Feb 2010 20:31:11 +0100
4Subject: [PATCH parted 01/10] gpt: read-only operation could clobber MBR part of hybrid GPT+MBR table
5
6* libparted/labels/gpt.c (gpt_read): Fix a bug introduced by me in
7commit 7f753b1b, "gpt: rewrite GPT header-reading code".
8Set write_back=0 in one more code path.
9* tests/Makefile.am (TESTS): Add t0205-gpt-list-clobbers-pmbr.sh.
10* tests/t0205-gpt-list-clobbers-pmbr.sh: New test.
11Reported by aix27249 in
12http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/250
13---
14 libparted/labels/gpt.c | 10 ++++--
15 tests/Makefile.am | 1 +
16 tests/t0205-gpt-list-clobbers-pmbr.sh | 59 +++++++++++++++++++++++++++++++++
17 4 files changed, 72 insertions(+), 3 deletions(-)
18 create mode 100644 tests/t0205-gpt-list-clobbers-pmbr.sh
19
20diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
21index 9d9876c..ea96a3b 100644
22--- a/libparted/labels/gpt.c
23+++ b/libparted/labels/gpt.c
24@@ -4,7 +4,7 @@
25 original version by Matt Domsch <Matt_Domsch@dell.com>
26 Disclaimed into the Public Domain
27
28- Portions Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
29+ Portions Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
30
31 EFI GUID Partition Table handling
32 Per Intel EFI Specification v1.02
33@@ -932,9 +932,9 @@ gpt_read (PedDisk *disk)
34 if (primary_gpt && backup_gpt)
35 {
36 /* Both are valid. */
37+#ifndef DISCOVER_ONLY
38 if (PED_LE64_TO_CPU (primary_gpt->AlternateLBA) < disk->dev->length - 1)
39 {
40-#ifndef DISCOVER_ONLY
41 switch (ped_exception_throw
42 (PED_EXCEPTION_ERROR,
43 (PED_EXCEPTION_FIX | PED_EXCEPTION_CANCEL
44@@ -954,8 +954,12 @@ gpt_read (PedDisk *disk)
45 write_back = 0;
46 break;
47 }
48-#endif /* !DISCOVER_ONLY */
49 }
50+ else
51+ {
52+ write_back = 0;
53+ }
54+#endif /* !DISCOVER_ONLY */
55 gpt = primary_gpt;
56 pth_free (backup_gpt);
57 }
58diff --git a/tests/Makefile.am b/tests/Makefile.am
59index 7bfb22e..38922f6 100644
60--- a/tests/Makefile.in
61+++ b/tests/Makefile.in
62@@ -9,6 +9,7 @@ TESTS = \
63 t0200-gpt.sh \
64 t0201-gpt.sh \
65 t0202-gpt-pmbr.sh \
66+ t0205-gpt-list-clobbers-pmbr.sh \
67 t0220-gpt-msftres.sh \
68 t0250-gpt.sh \
69 t0280-gpt-corrupt.sh \
70@@ -1261,6 +1261,8 @@ t0201-gpt.sh.log: t0201-gpt.sh
71 @p='t0201-gpt.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
72 t0202-gpt-pmbr.sh.log: t0202-gpt-pmbr.sh
73 @p='t0202-gpt-pmbr.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
74+t0205-gpt-list-clobbers-pmbr.sh.log: t0205-gpt-list-clobbers-pmbr.sh
75+ @p='t0205-gpt-list-clobbers-pmbr.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
76 t0220-gpt-msftres.sh.log: t0220-gpt-msftres.sh
77 @p='t0220-gpt-msftres.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
78 t0250-gpt.sh.log: t0250-gpt.sh
79diff --git a/tests/t0205-gpt-list-clobbers-pmbr.sh b/tests/t0205-gpt-list-clobbers-pmbr.sh
80new file mode 100644
81index 0000000..979a15e
82--- /dev/null
83+++ b/tests/t0205-gpt-list-clobbers-pmbr.sh
84@@ -0,0 +1,59 @@
85+#!/bin/sh
86+# Ensure that printing a GPT partition table does not modify the pMBR.
87+# Due to a bug in parted-2.1, "parted /dev/... print" would do just that.
88+# Not a problem for most, but if you have a hybrid, e.g., gptsync'd
89+# GPT/MBR table, merely listing the table with Parted-2.1 would clobber
90+# the MBR part.
91+
92+# Copyright (C) 2010 Free Software Foundation, Inc.
93+
94+# This program is free software; you can redistribute it and/or modify
95+# it under the terms of the GNU General Public License as published by
96+# the Free Software Foundation; either version 3 of the License, or
97+# (at your option) any later version.
98+
99+# This program is distributed in the hope that it will be useful,
100+# but WITHOUT ANY WARRANTY; without even the implied warranty of
101+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102+# GNU General Public License for more details.
103+
104+# You should have received a copy of the GNU General Public License
105+# along with this program. If not, see <http://www.gnu.org/licenses/>.
106+
107+if test "$VERBOSE" = yes; then
108+ set -x
109+ parted --version
110+fi
111+
112+: ${srcdir=.}
113+. $srcdir/t-lib.sh
114+
115+fail=0
116+
117+ss=$sector_size_
118+n_sectors=400
119+dev=dev-file
120+
121+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
122+parted -s $dev mklabel gpt || fail=1
123+parted -s $dev mkpart p1 101s 150s || fail=1
124+parted -s $dev mkpart p2 151s 200s || fail=1
125+parted -s $dev mkpart p3 201s 250s || fail=1
126+
127+parted -m -s $dev u s p || fail=1
128+
129+# Write non-NUL bytes all over the MBR, so we're likely to see any change.
130+# However, be careful to leave the type of the first partition, 0xEE,
131+# as well as the final two magic bytes.
132+printf '%0450d\xee%059d\x55\xaa' 0 0 | dd of=$dev count=1 conv=notrunc || fail=1
133+
134+dd if=$dev of=before count=1 || fail=1
135+
136+chmod a-w $dev
137+parted -m -s $dev u s p || fail=1
138+
139+dd if=$dev of=after count=1 || fail=1
140+
141+cmp before after || fail=1
142+
143+Exit $fail
144--
1451.6.6
146