2
# Ensure that parted knows when N'th (N>=16) partition is mounted
4
# Copyright (C) 2010-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
22
require_scsi_debug_module_
24
grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
25
skip_ 'this system lacks a new-enough libblkid'
28
partition_sectors=256 # sectors per partition
29
n_partitions=17 # how many partitions to create
30
start=2048 # start sector for the first partition
31
gpt_slop=34 # sectors at end of disk reserved for GPT
33
n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
35
sectors_per_MiB=$((1024 * 1024 / ss))
36
n_MiB=$(((n_sectors + sectors_per_MiB - 1) / sectors_per_MiB))
37
# create memory-backed device
38
scsi_debug_setup_ sector_size=$ss dev_size_mb=$n_MiB > dev-name ||
39
skip_ 'failed to create scsi_debug device'
40
scsi_dev=$(cat dev-name)
42
n=$((n_MiB * sectors_per_MiB))
43
printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug:;\n" \
46
parted -s $scsi_dev mklabel gpt || fail=1
47
parted -s $scsi_dev u s p || fail=1
52
end=$((start + partition_sectors - 1))
53
parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
54
printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
55
test $i = $n_partitions && break
56
start=$((start + partition_sectors))
59
t_final=$(date +%s.%N)
61
# Fail the test if it takes too long.
62
# On Fedora 13, it takes about 15 seconds.
63
# With older kernels, it typically takes more than 150 seconds.
64
$AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
65
' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
68
parted -m -s $scsi_dev u s p > out || fail=1
69
compare exp out || fail=1
71
wait_for_dev_to_appear_ ${scsi_dev}16 || fail_ ${scsi_dev}16 did not appear
73
partitions="${scsi_dev}14 ${scsi_dev}15 ${scsi_dev}16"
74
for i in $partitions; do
75
mkfs.ext3 $i || skip_ mkfs.ext3 $i failed
78
# be sure to unmount upon interrupt, failure, etc.
79
cleanup_fn_() { for i in $partitions; do umount "$i" > /dev/null 2>&1; done; }
81
for part_dev in $partitions; do
82
n=${part_dev#$scsi_dev}
83
mount_point=$(pwd)/m-$n
84
mkdir $mount_point || fail=1
85
mount "$part_dev" "$mount_point" || fail=1
87
# Removal of mounted partition must fail.
88
parted -s $scsi_dev rm $n > out 2>&1 && fail=1
90
echo "Error: Partition $part_dev is being used." \
91
'You must unmount it before you modify it with Parted.' \
92
> exp-error || framework_failure_
95
compare exp-error out || fail=1