1POSIX_FALLOCATE(3)         Linux Programmer's Manual        POSIX_FALLOCATE(3)
2
3
4

NAME

6       posix_fallocate - allocate file space
7

SYNOPSIS

9       #include <fcntl.h>
10
11       int posix_fallocate(int fd, off_t offset, off_t len);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       posix_fallocate():
16           _POSIX_C_SOURCE >= 200112L
17

DESCRIPTION

19       The function posix_fallocate() ensures that disk space is allocated for
20       the file referred to by the file descriptor fd for the bytes in the
21       range starting at offset and continuing for len bytes.  After a suc‐
22       cessful call to posix_fallocate(), subsequent writes to bytes in the
23       specified range are guaranteed not to fail because of lack of disk
24       space.
25
26       If the size of the file is less than offset+len, then the file is in‐
27       creased to this size; otherwise the file size is left unchanged.
28

RETURN VALUE

30       posix_fallocate() returns zero on success, or an error number on fail‐
31       ure.  Note that errno is not set.
32

ERRORS

34       EBADF  fd is not a valid file descriptor, or is not opened for writing.
35
36       EFBIG  offset+len exceeds the maximum file size.
37
38       EINTR  A signal was caught during execution.
39
40       EINVAL offset was less than 0, or len was less than or equal to 0, or
41              the underlying filesystem does not support the operation.
42
43       ENODEV fd does not refer to a regular file.
44
45       ENOSPC There is not enough space left on the device containing the file
46              referred to by fd.
47
48       EOPNOTSUPP
49              The filesystem containing the file referred to by fd does not
50              support this operation.  This error code can be returned by C
51              libraries that don't perform the emulation shown in NOTES, such
52              as musl libc.
53
54       ESPIPE fd refers to a pipe.
55

VERSIONS

57       posix_fallocate() is available since glibc 2.1.94.
58

ATTRIBUTES

60       For an explanation of the terms used in this section, see at‐
61       tributes(7).
62
63       ┌──────────────────┬───────────────┬───────────────────────────────────┐
64Interface         Attribute     Value                             
65       ├──────────────────┼───────────────┼───────────────────────────────────┤
66posix_fallocate() │ Thread safety │ MT-Safe (but see NOTES)           │
67       └──────────────────┴───────────────┴───────────────────────────────────┘
68

CONFORMING TO

70       POSIX.1-2001.
71
72       POSIX.1-2008 says that an implementation shall give the EINVAL error if
73       len was 0, or offset was less than 0.  POSIX.1-2001 says that an imple‐
74       mentation shall give the EINVAL error if len is less than 0, or  offset
75       was less than 0, and may give the error if len equals zero.
76

NOTES

78       In the glibc implementation, posix_fallocate() is implemented using the
79       fallocate(2) system call, which is MT-safe.  If the underlying filesys‐
80       tem  does not support fallocate(2), then the operation is emulated with
81       the following caveats:
82
83       * The emulation is inefficient.
84
85       * There is a race condition where concurrent writes from another thread
86         or process could be overwritten with null bytes.
87
88       * There is a race condition where concurrent file size increases by an‐
89         other thread or process could result in a file whose size is  smaller
90         than expected.
91
92       * If  fd has been opened with the O_APPEND or O_WRONLY flags, the func‐
93         tion fails with the error EBADF.
94
95       In general, the emulation is not MT-safe.  On Linux,  applications  may
96       use  fallocate(2)  if  they  cannot tolerate the emulation caveats.  In
97       general, this is only recommended if the application plans to terminate
98       the  operation if EOPNOTSUPP is returned, otherwise the application it‐
99       self will need to implement a fallback with all the  same  problems  as
100       the emulation provided by glibc.
101

SEE ALSO

103       fallocate(1), fallocate(2), lseek(2), posix_fadvise(2)
104

COLOPHON

106       This  page  is  part of release 5.13 of the Linux man-pages project.  A
107       description of the project, information about reporting bugs,  and  the
108       latest     version     of     this    page,    can    be    found    at
109       https://www.kernel.org/doc/man-pages/.
110
111
112
113GNU                               2021-03-22                POSIX_FALLOCATE(3)
Impressum