|
Packit |
7cfc04 |
.\" Copyright (c) 2006, Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH POSIX_FALLOCATE 3 2017-09-15 "GNU" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
posix_fallocate \- allocate file space
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
.B #include <fcntl.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "int posix_fallocate(int " fd ", off_t " offset ", off_t " len );
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.ad l
|
|
Packit |
7cfc04 |
.in -4n
|
|
Packit |
7cfc04 |
Feature Test Macro Requirements for glibc (see
|
|
Packit |
7cfc04 |
.BR feature_test_macros (7)):
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BR posix_fallocate ():
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
_POSIX_C_SOURCE\ >=\ 200112L
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.ad
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The function
|
|
Packit |
7cfc04 |
.BR posix_fallocate ()
|
|
Packit |
7cfc04 |
ensures that disk space is allocated for the file referred to by the
|
|
Packit |
7cfc04 |
file descriptor
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
for the bytes in the range starting at
|
|
Packit |
7cfc04 |
.I offset
|
|
Packit |
7cfc04 |
and continuing for
|
|
Packit |
7cfc04 |
.I len
|
|
Packit |
7cfc04 |
bytes.
|
|
Packit |
7cfc04 |
After a successful call to
|
|
Packit |
7cfc04 |
.BR posix_fallocate (),
|
|
Packit |
7cfc04 |
subsequent writes to bytes in the specified range are
|
|
Packit |
7cfc04 |
guaranteed not to fail because of lack of disk space.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If the size of the file is less than
|
|
Packit |
7cfc04 |
.IR offset + len ,
|
|
Packit |
7cfc04 |
then the file is increased to this size;
|
|
Packit |
7cfc04 |
otherwise the file size is left unchanged.
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
.BR posix_fallocate ()
|
|
Packit |
7cfc04 |
returns zero on success, or an error number on failure.
|
|
Packit |
7cfc04 |
Note that
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is not set.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EBADF
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
is not a valid file descriptor, or is not opened for writing.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EFBIG
|
|
Packit |
7cfc04 |
.I offset+len
|
|
Packit |
7cfc04 |
exceeds the maximum file size.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EINTR
|
|
Packit |
7cfc04 |
A signal was caught during execution.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EINVAL
|
|
Packit |
7cfc04 |
.I offset
|
|
Packit |
7cfc04 |
was less than 0, or
|
|
Packit |
7cfc04 |
.I len
|
|
Packit |
7cfc04 |
was less than or equal to 0, or the underlying filesystem does not
|
|
Packit |
7cfc04 |
support the operation.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENODEV
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
does not refer to a regular file.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOSPC
|
|
Packit |
7cfc04 |
There is not enough space left on the device containing the file
|
|
Packit |
7cfc04 |
referred to by
|
|
Packit |
7cfc04 |
.IR fd .
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ESPIPE
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
refers to a pipe.
|
|
Packit |
7cfc04 |
.SH VERSIONS
|
|
Packit |
7cfc04 |
.BR posix_fallocate ()
|
|
Packit |
7cfc04 |
is available since glibc 2.1.94.
|
|
Packit |
7cfc04 |
.SH ATTRIBUTES
|
|
Packit |
7cfc04 |
For an explanation of the terms used in this section, see
|
|
Packit |
7cfc04 |
.BR attributes (7).
|
|
Packit |
7cfc04 |
.TS
|
|
Packit |
7cfc04 |
allbox;
|
|
Packit |
7cfc04 |
lb lb lb
|
|
Packit |
7cfc04 |
l l l.
|
|
Packit |
7cfc04 |
Interface Attribute Value
|
|
Packit |
7cfc04 |
T{
|
|
Packit |
7cfc04 |
.BR posix_fallocate ()
|
|
Packit |
7cfc04 |
T} Thread safety MT-Safe (but see NOTES)
|
|
Packit |
7cfc04 |
.TE
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
POSIX.1-2001.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
POSIX.1-2008 says that an implementation
|
|
Packit |
7cfc04 |
.I shall
|
|
Packit |
7cfc04 |
give the
|
|
Packit |
7cfc04 |
.B EINVAL
|
|
Packit |
7cfc04 |
error if
|
|
Packit |
7cfc04 |
.I len
|
|
Packit |
7cfc04 |
was 0, or
|
|
Packit |
7cfc04 |
.I offset
|
|
Packit |
7cfc04 |
was less than 0.
|
|
Packit |
7cfc04 |
POSIX.1-2001 says that an implementation
|
|
Packit |
7cfc04 |
.I shall
|
|
Packit |
7cfc04 |
give the
|
|
Packit |
7cfc04 |
.B EINVAL
|
|
Packit |
7cfc04 |
error if
|
|
Packit |
7cfc04 |
.I len
|
|
Packit |
7cfc04 |
is less than 0, or
|
|
Packit |
7cfc04 |
.I offset
|
|
Packit |
7cfc04 |
was less than 0, and
|
|
Packit |
7cfc04 |
.I may
|
|
Packit |
7cfc04 |
give the error if
|
|
Packit |
7cfc04 |
.I len
|
|
Packit |
7cfc04 |
equals zero.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
In the glibc implementation,
|
|
Packit |
7cfc04 |
.BR posix_fallocate ()
|
|
Packit |
7cfc04 |
is implemented using the
|
|
Packit |
7cfc04 |
.BR fallocate (2)
|
|
Packit |
7cfc04 |
system call, which is MT-safe.
|
|
Packit |
7cfc04 |
If the underlying filesystem does not support
|
|
Packit |
7cfc04 |
.BR fallocate (2),
|
|
Packit |
7cfc04 |
then the operation is emulated with the following caveats:
|
|
Packit |
7cfc04 |
.IP * 2
|
|
Packit |
7cfc04 |
The emulation is inefficient.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
There is a race condition where concurrent writes from another thread or
|
|
Packit |
7cfc04 |
process could be overwritten with null bytes.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
There is a race condition where concurrent file size increases by
|
|
Packit |
7cfc04 |
another thread or process could result in a file whose size is smaller
|
|
Packit |
7cfc04 |
than expected.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
has been opened with the
|
|
Packit |
7cfc04 |
.B O_APPEND
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.B O_WRONLY
|
|
Packit |
7cfc04 |
flags, the function fails with the error
|
|
Packit |
7cfc04 |
.BR EBADF .
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
In general, the emulation is not MT-safe.
|
|
Packit |
7cfc04 |
On Linux, applications may use
|
|
Packit |
7cfc04 |
.BR fallocate (2)
|
|
Packit |
7cfc04 |
if they cannot tolerate the emulation caveats.
|
|
Packit |
7cfc04 |
In general, this is
|
|
Packit |
7cfc04 |
only recommended if the application plans to terminate the operation if
|
|
Packit |
7cfc04 |
.B EOPNOTSUPP
|
|
Packit |
7cfc04 |
is returned, otherwise the application itself will need to implement a
|
|
Packit |
7cfc04 |
fallback with all the same problems as the emulation provided by glibc.
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR fallocate (1),
|
|
Packit |
7cfc04 |
.BR fallocate (2),
|
|
Packit |
7cfc04 |
.BR lseek (2),
|
|
Packit |
7cfc04 |
.BR posix_fadvise (2)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|