2 # Test cp --sparse=always
4 # Copyright (C) 2006-2016 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=.}/tests/init.sh"; path_prepend_ .
/src
21 require_sparse_support_
23 # Create a sparse file.
24 # It has to be at least 128K in order to be sparse on some systems.
25 # Make its size one larger than 128K, in order to tickle the
26 # bug in coreutils-6.0.
27 size
=$
(expr 128 \
* 1024 + 1)
28 dd bs
=1 seek
=$size of
=sparse
< /dev
/null
2> /dev
/null || framework_failure_
31 cp --sparse=always sparse copy || fail
=1
33 # Ensure that the copy has the same block count as the original.
34 test $
(stat
--printf %b copy
) -le $
(stat
--printf %b sparse
) || fail
=1
36 # Ensure that --sparse={always,never} with --reflink fail.
37 returns_
1 cp --sparse=always
--reflink sparse copy || fail
=1
38 returns_
1 cp --sparse=never
--reflink sparse copy || fail
=1
41 # Ensure we handle sparse/non-sparse transitions correctly
42 maxn
=128 # how many $hole_size chunks per file
43 hole_size
=$
(stat
-c %o copy
)
44 dd if=/dev
/zero bs
=$hole_size count
=$maxn of
=zeros || framework_failure_
45 tr '\0' 'U' < zeros
> nonzero || framework_failure_
47 for pattern
in 1 0; do
48 test "$pattern" = 1 && pattern
="$(printf '%s\n%s' nonzero zeros)"
49 test "$pattern" = 0 && pattern
="$(printf '%s\n%s' zeros nonzero)"
51 for n
in 1 2 4 11 32 $maxn; do
52 parts
=$
(expr $maxn / $n)
56 # Generate non sparse file for copying with alternating
57 # hole/data patterns of size n * $hole_size
58 for i
in $
(yes "$pattern" |
head -n$parts); do
59 dd iflag
=fullblock
if=$i of
=sparse.
in conv
=notrunc oflag
=append \
60 bs
=$hole_size count
=$n status
=none || framework_failure_
63 cp --sparse=always sparse.
in sparse.out || fail
=1 # non sparse input
64 cp --sparse=always sparse.out sparse.out2 || fail
=1 # sparse input
66 cmp sparse.
in sparse.out || fail
=1
67 cmp sparse.
in sparse.out2 || fail
=1