OSDN Git Service

libparted: gpt: a smaller device need not render both headers invalid
[android-x86/external-parted.git] / tests / t0203-gpt-shortened-device-primary-valid.sh
1 #!/bin/sh
2 # Demonstrate that placing a valid gpt-labeled image on a shorter device
3 # does not invalidate the primary GPT header.
4
5 # Copyright (C) 2012 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
21 ss=$sector_size_
22
23 dev=dev-file
24 dd if=/dev/null of=$dev bs=$ss seek=100 || fail=1
25 parted -s -- $dev mklabel gpt || fail=1
26
27 # Chop off the last two sectors.
28 dd if=/dev/null of=$dev bs=$ss seek=98 || fail=1
29 printf 'ignore\nok\n' > in
30 parted -m ---pretend-input-tty $dev u s p < in > out 2> err || fail=1
31
32 # Remove abs name of $dev_file.
33 sed "s, [^ ]*/$dev, $dev," err > k && mv k err || fail=1
34 # Compare only the last line, to avoid control chars of interactive mode.
35 tail -1 out > k && mv k out || fail=1
36 sed "s,.*/$dev:,$dev:," out > k && mv k out || fail=1
37
38 emit_superuser_warning > err.exp || fail=1
39 cat <<EOF >> err.exp || fail=1
40 Error: end of file while reading $dev
41 Error: The backup GPT table is corrupt, but the primary appears OK, so that will be used.
42 EOF
43
44 echo "$dev:98s:file:$ss:$ss:gpt:;" > out.exp || fail=1
45
46 compare err.exp err || fail=1
47 compare out.exp out || fail=1
48
49 Exit $fail