posix_fallocate Subroutine

Purpose

Reserve storage space for a given file descriptor.

Syntax

 #include <fcntl.h>
int posix_fallocate (int fd, off_t offset, size_t len);

Description

This function reserves adequate space on the file system for the file data range beginning at the value specified by the offset parameter and continuing for the number of bytes specified by the len parameter. Upon successful return, subsequent writes to this file data range will not fail due to lack of free space on the file system media. Space allocated by the posix_fallocate subroutine can be freed by a successful call to the creat subroutine or open subroutine, or by the ftruncate subroutine, which truncates the file size to a size smaller than the sum of the offset parameter and the len parameter.

Parameters

Item Description
fd File descriptor of the file toreserve
offset Represents the beginning of the address range
len Determines the length of the address range

Return Values

Upon successful completion, the posix_fallocate 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
EBADF The fd parameter references a file that was opened without write permission.
EFBIG The value of the offset parameter plus the len parameter is greater than the maximum file size
EINTR A signal was caught during execution
EIO An I/O error occurred while reading from or writing to a file system
ENODEV The fd parameter does not refer to a regular file.
EINVAL The value of the advice parameter is invalid.
ENOSPC There is insufficient free space remaining on the file system storage media
ESPIPE The fd parameter is associated with a pipe of FIFO
ENOTSUP The underlying file system is not supported