posix_fadvise Subroutine
Purpose
Provides advisory information to the system about the future behavior of the application with respect to a given file.
Syntax
#include <fcntl.h>
int posix_fadvise (int fd, off_t offset, size_t len, int advice);
Description
This
function advises the system on the expected future behavior of the
application with regards to a given file. The system can take this
advice into account when performing operations on file data specified
by this function. The advice is given over the range covered by the offset parameter
and continuing for the number of bytes specified by the len parameter.
If the value of the len parameter is 0
, then
all data following the offset parameter is covered.
To use the posix_fadvise subroutine, you must first open the file, and then call the posix_fadvise subroutine. The advisory information of a file is not reset when the file is closed. The client application must call the posix_fadvise subroutine along with the POSIX_FADV_NORMAL flag to reset all advisory information.
- POSIX_FADV_NORMAL
- Resets all advisory information of a file to its default values.
- POSIX_FADV_SEQUENTIAL
- Valid option, but this value does not perform any action.
- POSIX_FADV_RANDOM
- Valid option, but this value does not perform any action.
- POSIX_FADV_WILLNEED
- Valid option, but this value does not perform any action.
- POSIX_FADV_DONTNEED
- Valid option, but this value does not perform any action.
- POSIX_FADV_NOREUSE
- Valid option, but this value does not perform any action.
- POSIX_FADV_NOWRITEBEHIND
- Instructs a file to ignore the normal write-behind functionality. You can run a system call,
such as the
sync
system call, to explicitly write-back the information present in the file to the disk. This parameter value can be used only for regular files in enhanced Journaled File System (JFS2).
Parameters
Item | Description |
---|---|
fd | File descriptor of the file to be advised. |
offset | Represents the beginning of the address range. |
len | Determines the length of the address range. |
advice | Defines the advice to be provided. |
Return Values
Upon
successful completion, the posix_fadvise subroutine returns 0
.
Otherwise, one of the following error codes will be returned.
Error Codes
Item | Description |
---|---|
EBADF | The fd parameter is not a valid file descriptor. |
EINVAL | The value of the advice parameter is invalid. |
ESPIPE | The fd parameter is associated with a pipe of FIFO. |