2 # Ensure dd invalidates to EOF when appropriate
4 # Copyright (C) 2017-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_strace_ fadvise64
,fadvise64_64
23 head -c1234567 /dev
/zero
> in.f || framework_failure_
25 # Check basic operation or skip.
26 # We could check for 'Operation not supported' error here,
27 # but that was seen to be brittle. HPUX returns ENOTTY for example.
28 # So assume that if this basic operation fails, it's due to lack
29 # of support by the system.
30 dd if=in.f iflag
=nocache count
=0 ||
31 skip_
'this file system lacks support for posix_fadvise()'
34 strace
-o dd.strace
-e fadvise64
,fadvise64_64
dd status
=none
"$@" || fail
=1
38 grep -F ' 0, POSIX_FADV_DONTNEED' dd.strace
>/dev
/null
41 # The commented fadvise64 calls are what are expected with
42 # a 4KiB page size and 128KiB IO_BUFSIZE.
44 strace_dd
if=in.f of
=out.f bs
=1M oflag
=nocache
,sync
45 #fadvise64(1, 0, 1048576, POSIX_FADV_DONTNEED) = 0
46 #fadvise64(1, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
47 #fadvise64(1, 1179648, 0, POSIX_FADV_DONTNEED) = 0
48 advised_to_eof || fail
=1
50 strace_dd
if=in.f count
=0 iflag
=nocache
51 #fadvise64(0, 0, 0, POSIX_FADV_DONTNEED) = 0
52 advised_to_eof || fail
=1
54 strace_dd
if=in.f of
=/dev
/null iflag
=nocache skip
=10 count
=300
55 #fadvise64(0, 5120, 131072, POSIX_FADV_DONTNEED) = 0
56 #fadvise64(0, 136192, 22528, POSIX_FADV_DONTNEED) = 0
57 returns_
1 advised_to_eof || fail
=1
59 strace_dd
if=in.f of
=/dev
/null iflag
=nocache bs
=1M count
=3000
60 #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
61 #fadvise64(0, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
62 #fadvise64(0, 1179648, 0, POSIX_FADV_DONTNEED) = 0
63 advised_to_eof || fail
=1
65 strace_dd
if=in.f of
=/dev
/null bs
=1M count
=1 iflag
=nocache
66 #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
67 returns_
1 advised_to_eof || fail
=1
69 strace_dd
if=in.f of
=out.f bs
=1M iflag
=nocache oflag
=nocache
,sync
70 #fadvise64(0, 0, 1048576, POSIX_FADV_DONTNEED) = 0
71 #fadvise64(1, 0, 1048576, POSIX_FADV_DONTNEED) = 0
72 #fadvise64(0, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
73 #fadvise64(1, 1048576, 131072, POSIX_FADV_DONTNEED) = 0
74 #fadvise64(0, 1179648, 0, POSIX_FADV_DONTNEED) = 0
75 #fadvise64(1, 1179648, 0, POSIX_FADV_DONTNEED) = 0
76 advised_to_eof || fail
=1
78 # Ensure sub page size offsets are handled.
79 # I.e., only page aligned offsets are sent to fadvise.
80 if ! strace
-o dd.strace
-e fadvise64
,fadvise64_64
dd status
=none \
81 if=in.f of
=out.f bs
=1M oflag
=direct oseek
=512B
; then
82 warn_
'512 byte aligned O_DIRECT is not supported on this (file) system'
83 # The current file system may not support O_DIRECT,
84 # or older XFS had a page size alignment requirement
86 #The first call is redundant but inconsequential
87 #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
88 #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
89 advised_to_eof || fail
=1
91 strace_dd
if=in.f of
=out.f bs
=1M oflag
=direct
92 #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
93 #fadvise64(1, 1048576, 0, POSIX_FADV_DONTNEED) = 0
94 advised_to_eof || fail
=1