posix_fallocate(), posix_fallocate64()

Allocate space for a file on the filesystem

Synopsis:

#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 );

Since:

BlackBerry 10.0.0

Arguments:

fd
A file descriptor for the file you want to allocate space for.
offset
The offset into the file where you want to allocate space.
len
The number of bytes to allocate.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

You can free the allocated space by using creat() or open() to truncate the file, or by calling ftruncate() to make the size of the file less than offset + len.

Returns:

EOK
Success.
EBADF
The fd argument isn't a valid file descriptor.
EBADF
The fd argument references a file that was opened without write permission.
EFBIG
The value of offset + len is greater than the maximum file size.
EINTR
A signal was caught during execution.
EINVAL
The len argument was zero or the offset argument was less than zero.
EIO
An I/O error occurred while reading from or writing to a filesystem.
ENODEV
The fd argument doesn't refer to a regular file.
ENOSPC
There's insufficient free space remaining on the filesystem storage media.
ESPIPE
The fd argument is associated with a pipe or FIFO.

Classification:

posix_fallocate() is POSIX 1003.1 ADV; posix_fallocate64() is Large-file support

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus