5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
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
37 # Test does not run on Windows because we must mark the test file
38 # specially so that Windows recognizes it as sparse. We do not have
39 # the tools available usually to do this (plus I also suspect that
40 # Wine does not emulate this properly).
42 echo "$0: this test needs to be revised to work on Windows"
49 requires
test -r /dev
/urandom
51 requires
$CUT --version
54 requires nbdsh
--version
55 requires
$STAT --version
57 requires
$TRUNCATE --version
59 if ! nbdinfo
--help |
grep -- --map ; then
60 echo "$0: nbdinfo --map option required to run this test"
64 base
=cow-extents1-base.img
67 sock
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
68 files
="$base $pid $out $sock"
70 cleanup_fn
rm -f $files
72 # Create a base file which is half allocated, half sparse.
73 dd if=/dev
/urandom of
=$base count
=128 bs
=1K
75 lastmod
="$($STAT -c "%y
" $base)"
77 # Run nbdkit with a COW overlay.
78 start_nbdkit
-P $pid -U $sock --filter=cow
file $base
79 uri
="nbd+unix:///?socket=$sock"
81 # The map should reflect the base image.
82 nbdinfo
--map "$uri" > $out
84 if [ "$(tr -s ' ' < $out | $CUT -d' ' -f 1-4)" != " 0 131072 0
85 131072 4063232 3" ]; then
86 echo "$0: unexpected initial file map"
94 -c 'h.trim(bs+2, 4*bs-1)' \
95 -c 'h.pwrite(b"1"*bs, 16*bs)' \
96 -c 'h.trim(2*bs, 32*bs)' \
97 -c 'h.pwrite(b"2"*(2*bs), 48*bs)'
99 # The extents map should be fully allocated.
100 nbdinfo
--map "$uri" > $out
102 if [ "$(tr -s ' ' < $out | $CUT -d' ' -f 1-4)" != " 0 65536 0
111 3276800 917504 3" ]; then
112 echo "$0: unexpected trimmed file map"
116 # The original file must not be modified.
117 currmod
="$($STAT -c "%y
" $base)"
118 if [ "$lastmod" != "$currmod" ]; then
119 echo "$0: FAILED last modified time of base file changed"