2 # enforce limits on partition start sector and length
4 # Copyright (C) 2008-2012 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
24 # On a 32-bit system, we must skip this test when $ss >= 4096.
25 # Otherwise, due to an inherent 32-bit-XFS limit, dd would fail to
26 # create the file of size > 16TiB
27 if test $(uname -m) != x86_64; then
28 test $ss -le 2048 || skip_ 'this test works only on a 64-bit system'
31 ####################################################
32 # Create and mount a file system capable of dealing with >=2TB files.
33 # We must be able to create a file with an apparent length of 2TB or larger.
34 # It needn't be a large file system.
39 # create an XFS file system
40 dd if=/dev/zero of=$fs bs=1MB count=2 seek=20 || fail=1
41 mkfs.xfs -f -q $fs || fail=1
44 # Unmount upon interrupt, failure, etc., as well as upon normal completion.
45 cleanup_fn_() { cd "$test_dir_" && umount "$mp" > /dev/null 2>&1; }
48 mount -o loop $fs "$mp" || fail=1
55 set +x # Turn off tracing; otherwise, we pollute stderr.
58 # echo '********' $(echo $end_sector - $start_sector + 1 |bc)
59 dd if=/dev/zero of=$dev bs=$ss count=2k seek=$end_sector 2> dd-err ||
60 { cat dd-err 1>&2; return 1; }
61 parted -s $dev mklabel $table_type &&
62 parted -s $dev mkpart p xfs ${start_sector}s ${end_sector}s
65 # Specify the starting sector number and length in sectors,
66 # rather than start and end.
67 do_mkpart_start_and_len()
69 set +x # Turn off tracing; otherwise, we pollute stderr.
72 end_sector=$(echo $start_sector + $len - 1|bc)
73 do_mkpart $start_sector $end_sector
76 for table_type in msdos; do
78 # a partition length of 2^32-1 works.
79 end=$(echo $n+2^32-2|bc) || fail=1
80 do_mkpart $n $end || fail=1
83 parted -s $dev unit s p > out 2>&1 || fail=1
84 sed -n "/^ *1 *$n/s/ */ /gp" out|sed "s/ *\$//" > k && mv k out || fail=1
85 echo " 1 ${n}s ${end}s 4294967295s primary" > exp || fail=1
86 compare exp out || fail=1
88 # a partition length of exactly 2^32 sectors provokes failure.
89 do_mkpart $n $(echo $n+2^32-1|bc) > err 2>&1
93 { echo "Error: partition length of $1 sectors exceeds the"\
94 "$table_type-partition-table-imposed maximum of 4294967295"; }
96 # check for new diagnostic
97 bad_part_length 4294967296 > exp || fail=1
98 compare exp err || fail=1
100 # a partition length of 2^32+1 sectors must provoke failure.
101 do_mkpart $n $(echo $n+2^32|bc) > err 2>&1
102 test $? = 1 || fail=1
104 # check for new diagnostic
105 bad_part_length 4294967297 > exp || fail=1
106 compare exp err || fail=1
108 # =========================================================
109 # Now consider partition starting sector numbers.
111 { echo "Error: starting sector number, $1 exceeds the"\
112 "$table_type-partition-table-imposed maximum of 4294967295"; }
114 # a partition start sector number of 2^32-1 works.
115 do_mkpart_start_and_len $(echo 2^32-1|bc) 1000 || fail=1
119 Disk $dev: 4294970342s
120 Sector size (logical/physical): ${ss}B/${ss}B
121 Partition Table: $table_type
124 Number Start End Size Type File system Flags
125 1 4294967295s 4294968294s 1000s primary
130 parted -s $dev unit s p > out 2>&1 || fail=1
131 sed "s/^Disk .*\($dev: [0-9][0-9]*s\)$/Disk \1/;s/ *$//" out > k \
132 && mv k out || fail=1
133 compare exp out || fail=1
135 # a partition start sector number of 2^32 must fail
136 do_mkpart_start_and_len $(echo 2^32|bc) 1000 > err 2>&1
137 test $? = 1 || fail=1
139 # check for new diagnostic
140 bad_start_sector 4294967296 > exp || fail=1
141 compare exp err || fail=1
143 # a partition start sector number of 2^32+1 must fail, too.
144 do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1
145 test $? = 1 || fail=1
147 # check for new diagnostic
148 bad_start_sector 4294967297 > exp || fail=1
149 compare exp err || fail=1