1 .\" Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved
2 .\" Written by Dave Chinner <dgc@sgi.com>
3 .\" May be distributed as per GNU General Public License version 2.
5 .\" 2011-09-19: Added FALLOC_FL_PUNCH_HOLE
6 .\" 2011-09-19: Substantial restructuring of the page
8 .TH FALLOCATE 2 2011-09-19 "Linux" "Linux Programmer's Manual"
10 fallocate \- manipulate file space
13 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .BI "int fallocate(int " fd ", int " mode ", off_t " offset \
20 This is a nonportable, Linux-specific system call.
21 For the portable, POSIX.1-specified method of ensuring that space
22 is allocated for a file, see
23 .BR posix_fallocate (3).
26 allows the caller to directly manipulate the allocated disk space
27 for the file referred to by
29 for the byte range starting at
37 argument determines the operation to be performed on the given range.
38 Details of the supported operations are given in the subsections below.
39 .SS Allocating disk space
40 The default operation (i.e.,
44 allocates and initializes to zero the disk space
45 within the range specified by
49 The file size (as reported by
53 is greater than the file size.
54 This default behavior closely resembles the behavior of the
55 .BR posix_fallocate (3)
57 and is intended as a method of optimally implementing that function.
59 After a successful call, subsequent writes into the range specified by
63 are guaranteed not to fail because of lack of disk space.
66 .B FALLOC_FL_KEEP_SIZE
69 the behavior of the call is similar,
70 but the file size will not be changed even if
72 is greater than the file size.
73 Preallocating zeroed blocks beyond the end of the file in this manner
74 is useful for optimizing append workloads.
76 Because allocation is done in block size chunks,
78 may allocate a larger range of disk space than was specified.
79 .SS Deallocating file space
81 .BR FALLOC_FL_PUNCH_HOLE
82 flag (available since Linux 2.6.38) in
84 deallocates space (i.e., creates a hole)
85 in the byte range starting at
90 Within the specified range, partial file system blocks are zeroed,
91 and whole file system blocks are removed from the file.
92 After a successful call,
93 subsequent reads from this range will return zeroes.
96 .BR FALLOC_FL_PUNCH_HOLE
97 flag must be ORed with
98 .BR FALLOC_FL_KEEP_SIZE
101 in other words, even when punching off the end of the file, the file size
106 Not all file systems support
107 .BR FALLOC_FL_PUNCH_HOLE ;
108 if a file system doesn't support the operation, an error is returned.
111 returns zero on success, and \-1 on failure.
116 is not a valid file descriptor, or is not opened for writing.
120 exceeds the maximum file size.
123 A signal was caught during execution.
129 .\" FIXME (raise a kernel bug) Probably the len==0 case should be
130 .\" a no-op, rather than an error. That would be consistent with
131 .\" similar APIs for the len==0 case.
132 .\" See "Re: [PATCH] fallocate.2: add FALLOC_FL_PUNCH_HOLE flag definition"
134 .\" http://thread.gmane.org/gmane.linux.file-systems/48331/focus=1193526
135 was less than or equal to 0.
138 An I/O error occurred while reading from or writing to a file system.
142 does not refer to a regular file or a directory.
145 is a pipe or FIFO, a different error results.)
148 There is not enough space left on the device containing the file
153 The file system containing the file referred to by
155 does not support this operation.
160 is not supported by the file system containing the file referred to by
164 The file referred to by
166 is marked immutable (see
171 .BR FALLOC_FL_PUNCH_HOLE
173 the file referred to by
175 is marked append-only
181 refers to a pipe or FIFO.
184 is available on Linux since kernel 2.6.23.
185 Support is provided by glibc since version 2.10.
191 .BR posix_fadvise (3),
192 .BR posix_fallocate (3)