1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#!/usr/bin/env bash
# nbdkit
# Copyright Red Hat
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Red Hat nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
source ./functions.sh
set -e
set -x
#set -u
requires_run
requires sfdisk --help
requires test -r /dev/urandom
requires_nbdcopy
# RHEL 7 sfdisk didn't have the -X option, so skip the tests here.
if LANG=C sfdisk -X |& grep -sq "invalid option"; then
echo "$0: skipping test because no sfdisk -X option"
exit 77
fi
d="partition1.d"
rm -rf $d
cleanup_fn rm -rf $d
mkdir $d
do_test ()
{
label=$1
nrparts=$2
ignored=$3
rm -f $d/disk
truncate -s 1G $d/disk
sfdisk -X $label $d/disk
# The smallest partition in any test is 1023 sectors. However
# to make things quicker only write a sector of random data.
dd if=/dev/urandom of=$d/rand bs=512 count=1
# Run nbdkit on each partition, copying data in and out.
for ((part=1; part <= $nrparts; ++part)); do
if [ "$part" != "$ignored" ]; then
nbdkit -f -v \
--filter=partition file $d/disk partition=$part \
--run "nbdcopy -C 1 $d/rand \$uri && nbdcopy -C 1 \$uri $d/out"
truncate -s 512 $d/out
cmp $d/rand $d/out
fi
done
}
# Regular MBR with 1-4 primary partitions.
do_test dos 1 <<'EOF'
2048 1023 L -
EOF
do_test dos 2 <<'EOF'
2048 1023 L -
4096 4095 L -
EOF
do_test dos 3 <<'EOF'
2048 1023 L -
4096 4095 L -
8192 8191 L -
EOF
do_test dos 4 <<'EOF'
2048 1023 L -
4096 4095 L -
8192 8191 L -
16384 16383 L -
EOF
# MBR with 3 primary partitions and 2 logical partitions.
# Ignore partition 4 which is the extended partition.
do_test dos 6 4 <<'EOF'
2048 2047 L -
4096 4095 L -
8192 8191 L -
16384 16383 E -
17000 999 L -
18000 999 L -
EOF
# As above but the extended partition is 1.
do_test dos 6 1 <<'EOF'
16384 16383 E -
2048 2047 L -
4096 4095 L -
8192 8191 L -
17000 999 L -
18000 999 L -
EOF
# MBR also allows missing partitions. This disk has only partition 2.
# (Partition 1 must be ignored since it is missing.)
do_test dos 2 1 <<'EOF'
disk2: start=1024 size=1023 type=83
EOF
# Regular GPT with 1-6 partitions.
do_test gpt 1 <<'EOF'
2048 1023 L -
EOF
do_test gpt 2 <<'EOF'
2048 1023 L -
4096 4095 L -
EOF
do_test gpt 3 <<'EOF'
2048 1023 L -
4096 4095 L -
8192 8191 L -
EOF
do_test gpt 4 <<'EOF'
2048 1023 L -
4096 4095 L -
8192 8191 L -
16384 16383 L -
EOF
do_test gpt 5 <<'EOF'
2048 2047 L -
4096 4095 L -
8192 8191 L -
16384 16383 L -
32768 32767 L -
EOF
do_test gpt 6 <<'EOF'
2048 2047 L -
4096 4095 L -
8192 8191 L -
16384 16383 L -
32768 32767 L -
65536 65535 L -
EOF
|