1 .\" Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved
2 .\" Written by Dave Chinner <dgc@sgi.com>
4 .\" %%%LICENSE_START(GPLv2_ONELINE)
5 .\" May be distributed as per GNU General Public License version 2.
8 .\" 2011-09-19: Added FALLOC_FL_PUNCH_HOLE
9 .\" 2011-09-19: Substantial restructuring of the page
11 .TH FALLOCATE 2 2014-05-08 "Linux" "Linux Programmer's Manual"
13 fallocate \- manipulate file space
16 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
19 .BI "int fallocate(int " fd ", int " mode ", off_t " offset \
23 This is a nonportable, Linux-specific system call.
24 For the portable, POSIX.1-specified method of ensuring that space
25 is allocated for a file, see
26 .BR posix_fallocate (3).
29 allows the caller to directly manipulate the allocated disk space
30 for the file referred to by
32 for the byte range starting at
40 argument determines the operation to be performed on the given range.
41 Details of the supported operations are given in the subsections below.
42 .SS Allocating disk space
43 The default operation (i.e.,
47 allocates the disk space within the range specified by
51 The file size (as reported by
55 is greater than the file size.
56 Any subregion within the range specified by
60 that did not contain data before the call will be initialized to zero.
61 This default behavior closely resembles the behavior of the
62 .BR posix_fallocate (3)
64 and is intended as a method of optimally implementing that function.
66 After a successful call, subsequent writes into the range specified by
70 are guaranteed not to fail because of lack of disk space.
73 .B FALLOC_FL_KEEP_SIZE
76 the behavior of the call is similar,
77 but the file size will not be changed even if
79 is greater than the file size.
80 Preallocating zeroed blocks beyond the end of the file in this manner
81 is useful for optimizing append workloads.
83 Because allocation is done in block size chunks,
85 may allocate a larger range of disk space than was specified.
86 .SS Deallocating file space
88 .BR FALLOC_FL_PUNCH_HOLE
89 flag (available since Linux 2.6.38) in
91 deallocates space (i.e., creates a hole)
92 in the byte range starting at
97 Within the specified range, partial filesystem blocks are zeroed,
98 and whole filesystem blocks are removed from the file.
99 After a successful call,
100 subsequent reads from this range will return zeroes.
103 .BR FALLOC_FL_PUNCH_HOLE
104 flag must be ORed with
105 .BR FALLOC_FL_KEEP_SIZE
108 in other words, even when punching off the end of the file, the file size
113 Not all filesystems support
114 .BR FALLOC_FL_PUNCH_HOLE ;
115 if a filesystem doesn't support the operation, an error is returned.
116 The operation is supported on at least the following filesystems:
118 XFS (since Linux 2.6.38)
120 ext4 (since Linux 3.0)
121 .\" commit a4bb6b64e39abc0e41ca077725f2a72c868e7622
123 Btrfs (since Linux 3.7)
125 tmpfs (since Linux 3.5)
126 .\" commit 83e4fa9c16e4af7122e31be3eca5d57881d236fe
127 .SS Collapsing file space
128 .\" commit 00f5e61998dd17f5375d9dfc01331f104b83f841
130 .BR FALLOC_FL_COLLAPSE_RANGE
131 flag (available since Linux 3.15) in
133 removes a byte range from a file, without leaving a hole.
134 The byte range to be collapsed starts at
139 At the completion of the operation,
140 the contents of the file starting at the location
142 will be appended at the location
148 A filesystem may place limitations on the granularity of the operation,
149 in order to ensure efficient implementation.
154 must be a multiple of the filesystem logical block size,
155 which varies according to the filesystem type and configuration.
156 If a filesystem has such a requirement,
158 will fail with the error
160 if this requirement is violated.
162 If the region specified by
166 reaches or passes the end of file, an error is returned;
171 No other flags may be specified in
174 .BR FALLOC_FL_COLLAPSE_RANGE .
177 .B FALLOC_FL_COLLAPSE_RANGE
179 ext4 (only for extent-based files)
180 .\" commit 9eb79482a97152930b113b51dff530aba9e28c8e
182 .\" commit e1d8fb88a64c1f8094b9f6c3b6d2d9e6719c970d
183 .SS Zeroing file space
185 .BR FALLOC_FL_ZERO_RANGE
186 flag (available since Linux 3.14)
187 .\" commit 409332b65d3ed8cfa7a8030f1e9d52f372219642
190 zeroes space in the byte range starting at
195 Within the specified range, blocks are preallocated for the regions
196 that span the holes in the file.
197 After a successful call, subsequent
198 reads from this range will return zeroes.
200 Zeroing is done within the filesystem preferably by converting the range into
202 This approach means that the specified range will not be physically zeroed
203 out on the device (except for partial blocks at the either end of the range),
204 and I/O is (otherwise) required only to update metadata.
207 .B FALLOC_FL_KEEP_SIZE
208 flag is additionally specified in
210 the behavior of the call is similar,
211 but the file size will not be changed even if
213 is greater than the file size.
214 This behaviour is the same as when preallocating space with
215 .B FALLOC_FL_KEEP_SIZE
218 Not all filesystems support
219 .BR FALLOC_FL_ZERO_RANGE ;
220 if a filesystem doesn't support the operation, an error is returned.
221 The operation is supported on at least the following filesystems:
223 XFS (since Linux 3.14)
224 .\" commit 376ba313147b4172f3e8cf620b9fb591f3e8cdfa
226 ext4, for extent-based files (since Linux 3.14)
227 .\" commit b8a8684502a0fc852afa0056c6bb2a9273f6fcc0
232 On error, \-1 is returned and
234 is set to indicate the error.
239 is not a valid file descriptor, or is not opened for writing.
243 exceeds the maximum file size.
246 A signal was caught during execution.
252 .\" FIXME (raise a kernel bug) Probably the len==0 case should be
253 .\" a no-op, rather than an error. That would be consistent with
254 .\" similar APIs for the len==0 case.
255 .\" See "Re: [PATCH] fallocate.2: add FALLOC_FL_PUNCH_HOLE flag definition"
257 .\" http://thread.gmane.org/gmane.linux.file-systems/48331/focus=1193526
258 was less than or equal to 0.
263 .BR FALLOC_FL_COLLAPSE_RANGE
264 and the range specified by
268 reaches or passes the end of the file.
273 .BR FALLOC_FL_COLLAPSE_RANGE ,
278 is not a multiple of the filesystem block size.
283 .B FALLOC_FL_COLLAPSE_RANGE
285 no other flags are permitted with
286 .BR FALLOC_FL_COLLAPSE_RANGE .
291 .BR FALLOC_FL_COLLAPSE_RANGE
293 .BR FALLOC_FL_ZERO_RANGE ,
294 but the file referred to by
296 is not a regular file.
297 .\" There was a inconsistency in 3.15-rc1, that should be resolved so that all
298 .\" filesystems use this error for this case. (Tytso says ex4 will change.)
299 .\" http://thread.gmane.org/gmane.comp.file-systems.xfs.general/60485/focus=5521
300 .\" From: Michael Kerrisk (man-pages <mtk.manpages@...>
301 .\" Subject: Re: [PATCH v5 10/10] manpage: update FALLOC_FL_COLLAPSE_RANGE flag in fallocate
302 .\" Newsgroups: gmane.linux.man, gmane.linux.file-systems
303 .\" Date: 2014-04-17 13:40:05 GMT
306 An I/O error occurred while reading from or writing to a filesystem.
310 does not refer to a regular file or a directory.
313 is a pipe or FIFO, a different error results.)
316 There is not enough space left on the device containing the file
321 This kernel does not implement
325 The filesystem containing the file referred to by
327 does not support this operation;
330 is not supported by the filesystem containing the file referred to by
334 The file referred to by
336 is marked immutable (see
341 .BR FALLOC_FL_PUNCH_HOLE
343 .BR FALLOC_FL_COLLAPSE_RANGE
345 the file referred to by
347 is marked append-only
353 refers to a pipe or FIFO.
358 .BR FALLOC_FL_COLLAPSE_RANGE ,
359 but the file referred to by
361 is currently being executed.
364 is available on Linux since kernel 2.6.23.
365 Support is provided by glibc since version 2.10.
368 flags are defined in glibc headers only since version 2.18.
369 .\" See http://sourceware.org/bugzilla/show_bug.cgi?id=14964
376 .BR posix_fadvise (3),
377 .BR posix_fallocate (3)
379 This page is part of release 3.67 of the Linux
382 A description of the project,
383 information about reporting bugs,
384 and the latest version of this page,
386 \%http://www.kernel.org/doc/man\-pages/.