man-pages/man3/posix_fallocate.3.html
2021-03-31 01:06:50 +01:00

284 lines
5.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of POSIX_FALLOCATE</TITLE>
</HEAD><BODY>
<H1>POSIX_FALLOCATE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
posix_fallocate - allocate file space
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>&gt;</B>
<B>int posix_fallocate(int </B><I>fd</I><B>, off_t </B><I>offset</I><B>, off_t </B><I>len</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>posix_fallocate</B>():
<DL COMPACT><DT id="1"><DD>
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The function
<B>posix_fallocate</B>()
ensures that disk space is allocated for the file referred to by the
file descriptor
<I>fd</I>
for the bytes in the range starting at
<I>offset</I>
and continuing for
<I>len</I>
bytes.
After a successful call to
<B>posix_fallocate</B>(),
subsequent writes to bytes in the specified range are
guaranteed not to fail because of lack of disk space.
<P>
If the size of the file is less than
<I>offset</I>+<I>len</I>,
then the file is increased to this size;
otherwise the file size is left unchanged.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>posix_fallocate</B>()
returns zero on success, or an error number on failure.
Note that
<I>errno</I>
is not set.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>EBADF</B>
<DD>
<I>fd</I>
is not a valid file descriptor, or is not opened for writing.
<DT id="3"><B>EFBIG</B>
<DD>
<I>offset+len</I>
exceeds the maximum file size.
<DT id="4"><B>EINTR</B>
<DD>
A signal was caught during execution.
<DT id="5"><B>EINVAL</B>
<DD>
<I>offset</I>
was less than 0, or
<I>len</I>
was less than or equal to 0, or the underlying filesystem does not
support the operation.
<DT id="6"><B>ENODEV</B>
<DD>
<I>fd</I>
does not refer to a regular file.
<DT id="7"><B>ENOSPC</B>
<DD>
There is not enough space left on the device containing the file
referred to by
<I>fd</I>.
<DT id="8"><B>ESPIPE</B>
<DD>
<I>fd</I>
refers to a pipe.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
<B>posix_fallocate</B>()
is available since glibc 2.1.94.
<A NAME="lbAH">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>posix_fallocate</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe (but see NOTES)<BR></TD></TR>
</TABLE>
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001.
<P>
POSIX.1-2008 says that an implementation
<I>shall</I>
give the
<B>EINVAL</B>
error if
<I>len</I>
was 0, or
<I>offset</I>
was less than 0.
POSIX.1-2001 says that an implementation
<I>shall</I>
give the
<B>EINVAL</B>
error if
<I>len</I>
is less than 0, or
<I>offset</I>
was less than 0, and
<I>may</I>
give the error if
<I>len</I>
equals zero.
<A NAME="lbAJ">&nbsp;</A>
<H2>NOTES</H2>
In the glibc implementation,
<B>posix_fallocate</B>()
is implemented using the
<B><A HREF="/cgi-bin/man/man2html?2+fallocate">fallocate</A></B>(2)
system call, which is MT-safe.
If the underlying filesystem does not support
<B><A HREF="/cgi-bin/man/man2html?2+fallocate">fallocate</A></B>(2),
then the operation is emulated with the following caveats:
<DL COMPACT>
<DT id="9">*<DD>
The emulation is inefficient.
<DT id="10">*<DD>
There is a race condition where concurrent writes from another thread or
process could be overwritten with null bytes.
<DT id="11">*<DD>
There is a race condition where concurrent file size increases by
another thread or process could result in a file whose size is smaller
than expected.
<DT id="12">*<DD>
If
<I>fd</I>
has been opened with the
<B>O_APPEND</B>
or
<B>O_WRONLY</B>
flags, the function fails with the error
<B>EBADF</B>.
</DL>
<P>
In general, the emulation is not MT-safe.
On Linux, applications may use
<B><A HREF="/cgi-bin/man/man2html?2+fallocate">fallocate</A></B>(2)
if they cannot tolerate the emulation caveats.
In general, this is
only recommended if the application plans to terminate the operation if
<B>EOPNOTSUPP</B>
is returned, otherwise the application itself will need to implement a
fallback with all the same problems as the emulation provided by glibc.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+fallocate">fallocate</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+fallocate">fallocate</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+posix_fadvise">posix_fadvise</A></B>(2)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="13"><A HREF="#lbAB">NAME</A><DD>
<DT id="14"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="15"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="16"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="17"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="18"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="19"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="20"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="21"><A HREF="#lbAJ">NOTES</A><DD>
<DT id="22"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="23"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:52 GMT, March 31, 2021
</BODY>
</HTML>