~ubuntu-branches/ubuntu/precise/parted/precise

« back to all changes in this revision

Viewing changes to tests/t4100-msdos-partition-limits.sh

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-02-06 16:39:19 UTC
  • mfrom: (1.1.5 upstream)
  • mto: (7.3.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 48.
  • Revision ID: james.westby@ubuntu.com-20100206163919-nsxr2vtchk0ecabf
Tags: upstream-2.1
ImportĀ upstreamĀ versionĀ 2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 3 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
test_description='enforce limits on partition start sector and length'
 
19
 
 
20
# Need root privileges to use mount.
 
21
privileges_required_=1
 
22
 
 
23
: ${srcdir=.}
 
24
. $srcdir/test-lib.sh
 
25
require_xfs_
 
26
ss=$sector_size_
 
27
 
 
28
####################################################
 
29
# Create and mount a file system capable of dealing with >=2TB files.
 
30
# We must be able to create a file with an apparent length of 2TB or larger.
 
31
# It needn't be a large file system.
 
32
fs=fs_file
 
33
mp=`pwd`/mount-point
 
34
n=4096
 
35
 
 
36
test_expect_success \
 
37
    'create an XFS file system' \
 
38
    '
 
39
    dd if=/dev/zero of=$fs bs=1MB count=2 seek=20 &&
 
40
    mkfs.xfs -q $fs &&
 
41
    mkdir "$mp"
 
42
 
 
43
    '
 
44
 
 
45
# Unmount upon interrupt, failure, etc., as well as upon normal completion.
 
46
cleanup_() { cd "$test_dir_" && umount "$mp" > /dev/null 2>&1; }
 
47
 
 
48
test_expect_success \
 
49
    'mount it' \
 
50
    '
 
51
    mount -o loop $fs "$mp" &&
 
52
    cd "$mp"
 
53
 
 
54
    '
 
55
dev=loop-file
 
56
 
 
57
do_mkpart()
 
58
{
 
59
  start_sector=$1
 
60
  end_sector=$2
 
61
  # echo '********' $(echo $end_sector - $start_sector + 1 |bc)
 
62
  dd if=/dev/zero of=$dev bs=$ss count=2k seek=$end_sector 2> /dev/null &&
 
63
  parted -s $dev mklabel $table_type &&
 
64
  parted -s $dev mkpart p xfs ${start_sector}s ${end_sector}s
 
65
}
 
66
 
 
67
# Specify the starting sector number and length in sectors,
 
68
# rather than start and end.
 
69
do_mkpart_start_and_len()
 
70
{
 
71
  start_sector=$1
 
72
  len=$2
 
73
  end_sector=$(echo $start_sector + $len - 1|bc)
 
74
  do_mkpart $start_sector $end_sector
 
75
}
 
76
 
 
77
for table_type in msdos; do
 
78
 
 
79
test_expect_success \
 
80
    "$table_type: a partition length of 2^32-1 works." \
 
81
    '
 
82
    end=$(echo $n+2^32-2|bc) &&
 
83
    do_mkpart $n $end
 
84
    '
 
85
 
 
86
test_expect_success \
 
87
    'print the result' \
 
88
    'parted -s $dev unit s p > out 2>&1 &&
 
89
     sed -n "/^  *1  *$n/s/  */ /gp" out|sed "s/  *\$//" > k && mv k out &&
 
90
     echo " 1 ${n}s ${end}s 4294967295s primary" > exp &&
 
91
     diff -u out exp
 
92
    '
 
93
 
 
94
test_expect_failure \
 
95
    "$table_type: a partition length of exactly 2^32 sectors provokes failure." \
 
96
    'do_mkpart $n $(echo $n+2^32-1|bc) > err 2>&1'
 
97
 
 
98
bad_part_length()
 
99
{ echo "Error: partition length of $1 sectors exceeds the"\
 
100
  "$table_type-partition-table-imposed maximum of 4294967295"; }
 
101
test_expect_success \
 
102
    'check for new diagnostic' \
 
103
    'bad_part_length 4294967296 > exp && diff -u err exp'
 
104
 
 
105
# FIXME: investigate this.
 
106
# Unexpectedly to me, both of these failed with this same diagnostic:
 
107
#
 
108
#   Error: partition length of 4294967296 sectors exceeds the \
 
109
#   DOS-partition-table-imposed maximum of 2^32-1" > exp &&
 
110
#
 
111
# I expected the one below to fail with a length of _4294967297_.
 
112
# Debugging, I see that _check_partition *does* detect this,
 
113
# but the diagnostic doesn't get displayed because of the wonders
 
114
# of parted's exception mechanism.
 
115
 
 
116
test_expect_failure \
 
117
    "$table_type: a partition length of 2^32+1 sectors provokes failure." \
 
118
    'do_mkpart $n $(echo $n+2^32|bc) > err 2>&1'
 
119
 
 
120
# FIXME: odd that we asked for 2^32+1, yet the diagnostic says 2^32
 
121
# FIXME: Probably due to constraints.
 
122
# FIXME: For now, just accept the current output.
 
123
test_expect_success \
 
124
    'check for new diagnostic' \
 
125
    'bad_part_length 4294967296 > exp && diff -u err exp'
 
126
 
 
127
# =========================================================
 
128
# Now consider partition starting sector numbers.
 
129
bad_start_sector()
 
130
{ echo "Error: starting sector number, $1 exceeds the"\
 
131
  "$table_type-partition-table-imposed maximum of 4294967295"; }
 
132
 
 
133
test_expect_success \
 
134
    "$table_type: a partition start sector number of 2^32-1 works." \
 
135
    'do_mkpart_start_and_len $(echo 2^32-1|bc) 1000'
 
136
 
 
137
cat > exp <<EOF
 
138
Model:  (file)
 
139
Disk: 4294970342s
 
140
Sector size (logical/physical): ${ss}B/${ss}B
 
141
Partition Table: $table_type
 
142
 
 
143
Number  Start        End          Size   Type     File system  Flags
 
144
 1      4294967295s  4294968294s  1000s  primary
 
145
 
 
146
EOF
 
147
 
 
148
test_expect_success \
 
149
    'print the result' \
 
150
    'parted -s $dev unit s p > out 2>&1 &&
 
151
     sed "s/Disk .*:/Disk:/;s/ *$//" out > k && mv k out &&
 
152
     diff -u out exp
 
153
    '
 
154
 
 
155
test_expect_failure \
 
156
    "$table_type: a partition start sector number of 2^32 must fail." \
 
157
    'do_mkpart_start_and_len $(echo 2^32|bc) 1000 > err 2>&1'
 
158
test_expect_success \
 
159
    'check for new diagnostic' \
 
160
    'bad_start_sector 4294967296 > exp && diff -u err exp'
 
161
 
 
162
test_expect_failure \
 
163
    "$table_type: a partition start sector number of 2^32+1 must fail, too." \
 
164
    'do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1'
 
165
test_expect_success \
 
166
    'check for new diagnostic' \
 
167
    'bad_start_sector 4294967296 > exp && diff -u err exp'
 
168
 
 
169
done
 
170
 
 
171
test_done