~ubuntu-branches/ubuntu/vivid/parted/vivid

« back to all changes in this revision

Viewing changes to tests/t9042-dos-partition-limit.sh

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-07-21 10:23:16 UTC
  • mfrom: (7.2.32 sid)
  • Revision ID: package-import@ubuntu.com-20140721102316-jsyv3yzmbo8vlde5
Tags: 3.1-3
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Ensure that parted enforces msdos partition limit
 
3
 
 
4
# Copyright (C) 2010-2012 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
 
 
21
require_root_
 
22
require_scsi_debug_module_
 
23
 
 
24
grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
 
25
  skip_ 'this system lacks a new-enough libblkid'
 
26
 
 
27
ss=$sector_size_
 
28
partition_sectors=256  # sectors per partition
 
29
n_partitions=61        # how many partitions to create
 
30
start=2048             # start sector for the first partition
 
31
 
 
32
n_sectors=$(($start + n_partitions * partition_sectors))
 
33
 
 
34
sectors_per_MiB=$((1024 * 1024 / ss))
 
35
n_MiB=$(((n_sectors + sectors_per_MiB - 1) / sectors_per_MiB))
 
36
# create memory-backed device
 
37
scsi_debug_setup_ sector_size=$ss dev_size_mb=$n_MiB > dev-name ||
 
38
  skip_ 'failed to create scsi_debug device'
 
39
scsi_dev=$(cat dev-name)
 
40
 
 
41
n=$((n_MiB * sectors_per_MiB))
 
42
printf '%s\n' "BYT;" \
 
43
    "$scsi_dev:${n}s:scsi:$ss:$ss:msdos:Linux scsi_debug:;" \
 
44
    "1:$((start-2))s:$((n-1))s:$((n-start+2))s:::lba;" \
 
45
  > exp || fail=1
 
46
 
 
47
parted -s $scsi_dev mklabel msdos || fail=1
 
48
parted -s -a min $scsi_dev mkpart extended $((start-2))s 100% || fail=1
 
49
 
 
50
i=1
 
51
while :; do
 
52
    end=$((start + partition_sectors - 2))
 
53
    parted -s -a min $scsi_dev mkpart logical ${start}s ${end}s || fail=1
 
54
    printf "$((i+4)):${start}s:${end}s:$((end-start+1))s:::;\n" >> exp
 
55
    test $i = $((n_partitions - 1)) && break
 
56
    start=$((start + partition_sectors))
 
57
    i=$((i+1))
 
58
done
 
59
 
 
60
parted -m -s $scsi_dev u s p > out || fail=1
 
61
compare exp out || fail=1
 
62
 
 
63
start=$((start + partition_sectors))
 
64
end=$((start + partition_sectors - 2))
 
65
 
 
66
#try one more partition than allowed, make sure it fails
 
67
 
 
68
parted -s -a min $scsi_dev mkpart logical ${start}s ${end}s > out 2>&1
 
69
cat <<EOF > exp
 
70
Error: cannot create any more partitions
 
71
EOF
 
72
compare exp out || fail=1
 
73
 
 
74
Exit $fail