summaryrefslogtreecommitdiff
path: root/tests/t0283-overlap-partitions.sh
blob: faa7eb8752819c9631de21dbfa880a48e2ec14bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
# ensure parted can ignore partitions that overlap or are
# longer than the disk and remove them

# Copyright (C) 2009-2012, 2014, 2019-2022 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_512_byte_sector_size_
dev=loop-file

truncate -s 10m $dev || framework_failure
parted -s $dev mklabel msdos || framework_failure
msdos-overlap $dev || framework_failure

# print the empty table
parted ---pretend-input-tty $dev <<EOF > out 2>&1 || fail=1
print
ignore
rm
2
EOF

# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
# normalize the actual output
mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s,
   *
,,g;s, $,," \
                      -e "s,^.*/lt-parted: ,parted: ," -e "s/^GNU Parted .*$/GNU Parted VERSION/" o2 > out

# check for expected output
emit_superuser_warning > exp || fail=1
cat <<EOF >> exp || fail=1
GNU Parted VERSION
Using DEVICE
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: Can't have overlapping partitions.
Ignore/Cancel? ignore
Model:  (file)
Disk DEVICE: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  5243kB  4194kB  primary
 2      5242kB  8000kB  2758kB  primary

(parted) rm
Partition number? 2
(parted)
EOF
compare exp out || fail=1

truncate -s 3m $dev || fail=1

# print the table, verify error, ignore it, and remove the partition
parted ---pretend-input-tty $dev <<EOF > out 2>&1 || fail=1
print
ignore
rm
1
EOF

# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
# normalize the actual output
mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s,
   *
,,g;s, $,," \
                      -e "s,^.*/lt-parted: ,parted: ," -e "s/^GNU Parted .*$/GNU Parted VERSION/" o2 > out

# check for expected output
emit_superuser_warning > exp || fail=1
cat <<EOF >> exp || fail=1
GNU Parted VERSION
Using DEVICE
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: Can't have a partition outside the disk!
Ignore/Cancel? ignore
Model:  (file)
Disk DEVICE: 3146kB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  5243kB  4194kB  primary

(parted) rm
Partition number? 1
(parted)
EOF
compare exp out || fail=1

Exit $fail