1 /* Declare an access pattern hint for files.
2 Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #include <sys/types.h>
21 /* There are a few hints one can provide, which have the
22 following characteristics on Linux 2.6.31 at least.
25 Doubles the size of read ahead done for file
27 _synchronously_ prepopulate the buffer cache with the file
29 Could lower priority of data in buffer caches,
30 but currently does nothing.
32 Drop the file from cache.
33 Note this is automatically done when files are unlinked.
35 We use this enum "type" both to make it explicit that
36 these options are mutually exclusive, and to discourage
37 the passing of the possibly undefined POSIX_FADV_... values.
38 Note we could #undef the POSIX_FADV_ values, but that would
39 preclude using the posix_fadvise() function with its standard
40 constants. Using posix_fadvise() might be required if the return
41 value is needed, but it must be guarded by appropriate #ifdefs. */
43 #if HAVE_POSIX_FADVISE
45 FADVISE_NORMAL
= POSIX_FADV_NORMAL
,
46 FADVISE_SEQUENTIAL
= POSIX_FADV_SEQUENTIAL
,
47 FADVISE_NOREUSE
= POSIX_FADV_NOREUSE
,
48 FADVISE_DONTNEED
= POSIX_FADV_DONTNEED
,
49 FADVISE_WILLNEED
= POSIX_FADV_WILLNEED
,
50 FADVISE_RANDOM
= POSIX_FADV_RANDOM
63 /* We ignore any errors as these hints are only advisory.
64 There is the chance one can pass invalid ADVICE, which will
65 not be indicated, but given the simplicity of the interface
66 this is unlikely. Also not returning errors allows the
67 unconditional passing of descriptors to non standard files,
68 which will just be ignored if unsupported. */
70 void fdadvise (int fd
, off_t offset
, off_t len
, fadvice_t advice
);
71 void fadvise (FILE *fp
, fadvice_t advice
);