1 .\" Copyright (c) 2006, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH posix_fallocate 3 (date) "Linux man-pages (unreleased)"
7 posix_fallocate \- allocate file space
10 .RI ( libc ", " \-lc )
15 .BI "int posix_fallocate(int " fd ", off_t " offset ", off_t " len );
20 Feature Test Macro Requirements for glibc (see
21 .BR feature_test_macros (7)):
24 .BR posix_fallocate ():
26 _POSIX_C_SOURCE >= 200112L
30 .BR posix_fallocate ()
31 ensures that disk space is allocated for the file referred to by the
34 for the bytes in the range starting at
39 After a successful call to
40 .BR posix_fallocate (),
41 subsequent writes to bytes in the specified range are
42 guaranteed not to fail because of lack of disk space.
44 If the size of the file is less than
46 then the file is increased to this size;
47 otherwise the file size is left unchanged.
49 .BR posix_fallocate ()
50 returns zero on success, or an error number on failure.
58 is not a valid file descriptor, or is not opened for writing.
62 exceeds the maximum file size.
65 A signal was caught during execution.
71 was less than or equal to 0, or the underlying filesystem does not
72 support the operation.
76 does not refer to a regular file.
79 There is not enough space left on the device containing the file
84 The filesystem containing the file referred to by
86 does not support this operation.
87 This error code can be returned by C libraries that don't perform the
88 emulation shown in NOTES, such as musl libc.
94 .BR posix_fallocate ()
95 is available since glibc 2.1.94.
97 For an explanation of the terms used in this section, see
105 Interface Attribute Value
107 .BR posix_fallocate ()
109 MT-Safe (but see NOTES)
118 POSIX.1-2008 says that an implementation
127 POSIX.1-2001 says that an implementation
141 In the glibc implementation,
142 .BR posix_fallocate ()
143 is implemented using the
145 system call, which is MT-safe.
146 If the underlying filesystem does not support
148 then the operation is emulated with the following caveats:
150 The emulation is inefficient.
152 There is a race condition where concurrent writes from another thread or
153 process could be overwritten with null bytes.
155 There is a race condition where concurrent file size increases by
156 another thread or process could result in a file whose size is smaller
161 has been opened with the
165 flags, the function fails with the error
168 In general, the emulation is not MT-safe.
169 On Linux, applications may use
171 if they cannot tolerate the emulation caveats.
173 only recommended if the application plans to terminate the operation if
175 is returned, otherwise the application itself will need to implement a
176 fallback with all the same problems as the emulation provided by glibc.
181 .BR posix_fadvise (2)