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