Allocate space for a file on the filesystem
#include <fcntl.h> int posix_fallocate( int fd, off_t offset, off_t len ); int posix_fallocate64( int fd, off64_t offset, off64_t len );
- A file descriptor for the file you want to allocate space for.
- The offset into the file where you want to allocate space.
- The number of bytes to allocate.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The posix_fallocate() and posix_fallocate64() functions ensure that any required storage for regular file data starting at offset and continuing for len bytes is allocated on the filesystem storage media. The posix_fallocate64() function is a large-file version of posix_fallocate().
If posix_fallocate() returns successfully, subsequent writes to the specified file data won't fail due to the lack of free space on the filesystem storage media.
If the offset + len is beyond the current file size, then posix_fallocate() adjusts the file size to be offset + len. Otherwise, the file size isn't changed.
- The fd argument isn't a valid file descriptor.
- The fd argument references a file that was opened without write permission.
- The value of offset + len is greater than the maximum file size.
- A signal was caught during execution.
- The len argument was zero or the offset argument was less than zero.
- An I/O error occurred while reading from or writing to a filesystem.
- The fd argument doesn't refer to a regular file.
- There's insufficient free space remaining on the filesystem storage media.
- The fd argument is associated with a pipe or FIFO.
Last modified: 2014-06-24