4 # Test 'offset' and 'size' options of the raw driver. Make sure we can't
5 # (or can) read and write outside of the image size.
7 # Copyright (C) 2016 Red Hat, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 owner
=tgolembi@redhat.com
27 echo "QA output created by $seq"
29 status
=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
42 _supported_proto
file fuse
46 # Create JSON with options
48 printf %s
'json:{"driver":"raw", '
49 printf %s
"\"offset\":\"$img_offset\", "
50 if [ "$img_size" -ne -1 ] ; then
51 printf %s
"\"size\":\"$img_size\", "
54 printf %s
'"driver":"file", '
55 printf %s
"\"filename\":\"$TEST_IMG\" "
60 if [ "$img_size" -ge 0 ] ; then
63 test_size
=$
((size-img_offset
))
68 $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
72 $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
75 echo "check that offset is respected"
76 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
79 echo "write before image boundary"
80 $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
83 echo "write across image boundary"
84 $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
87 echo "write at image boundary"
88 $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io
91 echo "write after image boundary"
92 $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
95 echo "writev before/after image boundary"
96 $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
99 echo "read before image boundary"
100 $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
103 echo "read across image boundary"
104 $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
107 echo "read at image boundary"
108 $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io
111 echo "read after image boundary"
112 $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
115 echo "readv before/after image boundary"
116 $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
119 echo "fill image with pattern"
120 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
123 echo "write zeroes and check"
124 $QEMU_IO -c "write -z 0 512" "$(img_json)" | _filter_qemu_io
125 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
128 echo "write zeroes across image boundary"
129 $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
132 echo "write zeroes at image boundary and check"
133 $QEMU_IO -c "write -z $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
134 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
135 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
138 echo "fill image with pattern"
139 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
142 echo "discard and check"
143 $QEMU_IO -c "discard 0 512" "$(img_json)" | _filter_qemu_io
144 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
147 echo "discard across image boundary"
148 $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
151 echo "discard at image boundary and check"
152 $QEMU_IO -c "discard $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
153 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
154 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
158 echo "== test 'offset' option =="
167 echo "== test 'offset' and 'size' options =="
176 echo "== test misaligned 'offset' =="
185 echo "== test reopen =="
191 $QEMU_IO "$(img_json)" <<EOT
195 reopen -o driver=raw,offset=1536,size=1024
201 echo "checking boundaries"
202 $QEMU_IO -c "read -v 510 4" $TEST_IMG | _filter_qemu_io
203 $QEMU_IO -c "read -v 1022 4" $TEST_IMG | _filter_qemu_io
204 $QEMU_IO -c "read -v 1534 4" $TEST_IMG | _filter_qemu_io
205 $QEMU_IO -c "read -v 2558 4" $TEST_IMG | _filter_qemu_io