2 # test diagnostics are printed when seeking too far in seekable files.
4 # Copyright (C) 2008-2024 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 <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
21 require_sparse_support_
# for 'truncate --size=$OFF_T_MAX'
22 eval $
(getlimits
) # for OFF_T limits
25 printf "1234" > file || framework_failure_
28 dd: 'standard input': cannot skip to specified offset
30 0+0 records out" > skip_err || framework_failure_
32 # skipping beyond number of blocks in file should issue a warning
33 dd bs
=1 skip
=5 count
=0 status
=noxfer
< file 2> err || fail
=1
34 compare skip_err err || fail
=1
36 # skipping beyond number of bytes in file should issue a warning
37 dd bs
=3 skip
=2 count
=0 status
=noxfer
< file 2> err || fail
=1
38 compare skip_err err || fail
=1
40 # skipping beyond number of blocks in pipe should issue a warning
41 cat file |
dd bs
=1 skip
=5 count
=0 status
=noxfer
2> err || fail
=1
42 compare skip_err err || fail
=1
44 # skipping beyond number of bytes in pipe should issue a warning
45 cat file |
dd bs
=3 skip
=2 count
=0 status
=noxfer
2> err || fail
=1
46 compare skip_err err || fail
=1
48 # Check seeking beyond file already offset into
49 # skipping beyond number of blocks in file should issue a warning
50 (dd bs
=1 skip
=1 count
=0 2>/dev
/null
&&
51 dd bs
=1 skip
=4 status
=noxfer
2> err
) < file || fail
=1
52 compare skip_err err || fail
=1
54 # Check seeking beyond file already offset into
55 # skipping beyond number of bytes in file should issue a warning
56 (dd bs
=1 skip
=1 count
=0 2>/dev
/null
&&
57 dd bs
=2 skip
=2 status
=noxfer
2> err
) < file || fail
=1
58 compare skip_err err || fail
=1
60 # seeking beyond end of file is OK
61 dd bs
=1 seek
=5 count
=0 status
=noxfer
> file 2> err || fail
=1
63 0+0 records out" > err_ok || framework_failure_
64 compare err_ok err || fail
=1
66 # skipping > OFF_T_MAX should fail immediately
67 dd bs
=1 skip
=$OFF_T_OFLOW count
=0 status
=noxfer
< file 2> err
&& fail
=1
68 # error message should be "... invalid number: strerror(EOVERFLOW)"
69 grep "invalid number:" err
>/dev
/null || fail
=1
70 dd bs
=1 skip
=${OFF_T_OFLOW}x
$OFF_T_OFLOW count
=0 status
=noxfer
< file 2> err
&&
72 grep "invalid number:" err
>/dev
/null || fail
=1
74 # skipping > max file size should fail immediately
75 if ! truncate
--size=$OFF_T_MAX in 2>/dev
/null
; then
76 # truncate is to ensure file system doesn't actually support OFF_T_MAX files
77 dd bs
=1 skip
=$OFF_T_MAX count
=0 status
=noxfer
< file 2> err \
81 if test $lseek_ok = yes; then
82 # On Solaris 10 at least, lseek(>max file size) succeeds,
83 # so just check for the skip warning.
84 compare skip_err err || fail
=1
86 # On Linux kernels at least, lseek(>max file size) fails.
87 # error message should be "... cannot skip: strerror(EINVAL)"
88 grep "cannot skip:" err
>/dev
/null || fail
=1