OSDN Git Service

tests: convert t4100-dvh-partition-limits.sh to use init.sh
[android-x86/external-parted.git] / tests / t4100-dvh-partition-limits.sh
1 #!/bin/sh
2 # enforce limits on partition start sector and length
3
4 # Copyright (C) 2008-2010 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
20 require_root_
21 require_xfs_
22 ss=$sector_size_
23
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'
29 fi
30
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.
35 fs=fs_file
36 mp=`pwd`/mount-point
37 n=4096
38
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
42 mkdir "$mp" || fail=1
43
44 # Unmount upon interrupt, failure, etc., as well as upon normal completion.
45 cleanup_() { cd "$test_dir_" && umount "$mp" > /dev/null 2>&1; }
46
47 # mount it
48 mount -o loop $fs "$mp" || fail=1
49 cd "$mp" || fail=1
50
51 dev=loop-file
52
53 do_mkpart()
54 {
55   set +x # Turn off tracing; otherwise, we pollute stderr.
56   start_sector=$1
57   end_sector=$2
58   # echo '********' $(echo $end_sector - $start_sector + 1 |bc)
59   dd if=/dev/zero of=$dev bs=$ss count=2k seek=$end_sector 2> /dev/null &&
60   parted -s $dev mklabel $table_type &&
61   parted -s $dev mkpart p xfs ${start_sector}s ${end_sector}s
62 }
63
64 # Specify the starting sector number and length in sectors,
65 # rather than start and end.
66 do_mkpart_start_and_len()
67 {
68   set +x # Turn off tracing; otherwise, we pollute stderr.
69   start_sector=$1
70   len=$2
71   end_sector=$(echo $start_sector + $len - 1|bc)
72   do_mkpart $start_sector $end_sector
73 }
74
75 for table_type in dvh; do
76
77 # a partition length of 2^32-1 works.
78 end=$(echo $n+2^32-2|bc) || fail=1
79 do_mkpart $n $end || fail=1
80
81 # print the result
82 parted -s $dev unit s p > out 2>&1 || fail=1
83 sed -n "/^  *1  *$n/s/  */ /gp" out|sed "s/  *\$//" > k && mv k out || fail=1
84 echo " 1 ${n}s ${end}s 4294967295s primary" > exp || fail=1
85 compare out exp || fail=1
86
87 # a partition length of exactly 2^32 sectors provokes failure.
88 do_mkpart $n $(echo $n+2^32-1|bc) > err 2>&1
89 test $? = 1 || fail=1
90
91 bad_part_length()
92 { echo "Error: partition length of $1 sectors exceeds the"\
93   "$table_type-partition-table-imposed maximum of 4294967295"; }
94
95 # check for new diagnostic
96 bad_part_length 4294967296 > exp || fail=1
97 compare err exp || fail=1
98
99 # FIXME: investigate this.
100 # Unexpectedly to me, both of these failed with this same diagnostic:
101 #
102 #   Error: partition length of 4294967296 sectors exceeds the \
103 #   DOS-partition-table-imposed maximum of 2^32-1" > exp &&
104 #
105 # I expected the one below to fail with a length of _4294967297_.
106 # Debugging, I see that _check_partition *does* detect this,
107 # but the diagnostic doesn't get displayed because of the wonders
108 # of parted's exception mechanism.
109
110 # a partition length of 2^32+1 sectors must provoke failure.
111 do_mkpart $n $(echo $n+2^32|bc) > err 2>&1
112 test $? = 1 || fail=1
113
114 # check for new diagnostic
115 bad_part_length 4294967297 > exp || fail=1
116 compare err exp || fail=1
117
118 # =========================================================
119 # Now consider partition starting sector numbers.
120 bad_start_sector()
121 { echo "Error: starting sector number, $1 exceeds the"\
122   "$table_type-partition-table-imposed maximum of 4294967295"; }
123
124 # a partition start sector number of 2^32-1 works.
125 do_mkpart_start_and_len $(echo 2^32-1|bc) 1000 || fail=1
126
127 # FIXME: this partition number 9 (not requested!) looks totally bogus
128 # FIXME: For now, we just expect what the code produces.
129 # FIXME: In the long run, figure out if it's sensible.
130 cat > exp <<EOF
131 Model:  (file)
132 Disk: 4294970342s
133 Sector size (logical/physical): ${ss}B/${ss}B
134 Partition Table: $table_type
135
136 Number  Start        End          Size   Type      File system  Name  Flags
137  9      0s           4095s        4096s  extended
138  1      4294967295s  4294968294s  1000s  primary
139
140 EOF
141
142 # print the result
143 parted -s $dev unit s p > out 2>&1 || fail=1
144 sed "s/Disk .*:/Disk:/;s/ *$//" out > k && mv k out || fail=1
145 compare out exp || fail=1
146
147 # a partition start sector number of 2^32 must fail
148 do_mkpart_start_and_len $(echo 2^32|bc) 1000 > err 2>&1
149 test $? = 1 || fail=1
150
151 # check for new diagnostic
152 bad_start_sector 4294967296 > exp || fail=1
153 compare err exp || fail=1
154
155 # a partition start sector number of 2^32+1 must fail, too.
156 do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1
157 test $? = 1 || fail=1
158
159 # check for new diagnostic
160 bad_start_sector 4294967297 > exp || fail=1
161 compare err exp || fail=1
162
163 done
164
165 Exit $fail