1POSIX_FALLOCATE(3) Linux Programmer's Manual POSIX_FALLOCATE(3)
2
3
4
6 posix_fallocate - allocate file space
7
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
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
27 increased to this size; otherwise the file size is left unchanged.
28
30 posix_fallocate() returns zero on success, or an error number on fail‐
31 ure. Note that errno is not set.
32
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 ESPIPE fd refers to a pipe.
49
51 posix_fallocate() is available since glibc 2.1.94.
52
54 For an explanation of the terms used in this section, see
55 attributes(7).
56
57 ┌──────────────────┬───────────────┬─────────────────────────┐
58 │Interface │ Attribute │ Value │
59 ├──────────────────┼───────────────┼─────────────────────────┤
60 │posix_fallocate() │ Thread safety │ MT-Safe (but see NOTES) │
61 └──────────────────┴───────────────┴─────────────────────────┘
63 POSIX.1-2001.
64
65 POSIX.1-2008 says that an implementation shall give the EINVAL error if
66 len was 0, or offset was less than 0. POSIX.1-2001 says that an imple‐
67 mentation shall give the EINVAL error if len is less than 0, or offset
68 was less than 0, and may give the error if len equals zero.
69
71 In the glibc implementation, posix_fallocate() is implemented using the
72 fallocate(2) system call, which is MT-safe. If the underlying filesys‐
73 tem does not support fallocate(2), then the operation is emulated with
74 the following caveats:
75
76 * The emulation is inefficient.
77
78 * There is a race condition where concurrent writes from another thread
79 or process could be overwritten with null bytes.
80
81 * There is a race condition where concurrent file size increases by
82 another thread or process could result in a file whose size is
83 smaller than expected.
84
85 * If fd has been opened with the O_APPEND or O_WRONLY flags, the func‐
86 tion fails with the error EBADF.
87
88 In general, the emulation is not MT-safe. On Linux, applications may
89 use fallocate(2) if they cannot tolerate the emulation caveats. In
90 general, this is only recommended if the application plans to terminate
91 the operation if EOPNOTSUPP is returned, otherwise the application
92 itself will need to implement a fallback with all the same problems as
93 the emulation provided by glibc.
94
96 fallocate(1), fallocate(2), lseek(2), posix_fadvise(2)
97
99 This page is part of release 5.04 of the Linux man-pages project. A
100 description of the project, information about reporting bugs, and the
101 latest version of this page, can be found at
102 https://www.kernel.org/doc/man-pages/.
103
104
105
106GNU 2017-09-15 POSIX_FALLOCATE(3)