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 2013-02-12 "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 and initializes to zero the disk space
48 within the range specified by
52 The file size (as reported by
56 is greater than the file size.
57 This default behavior closely resembles the behavior of the
58 .BR posix_fallocate (3)
60 and is intended as a method of optimally implementing that function.
62 After a successful call, subsequent writes into the range specified by
66 are guaranteed not to fail because of lack of disk space.
69 .B FALLOC_FL_KEEP_SIZE
72 the behavior of the call is similar,
73 but the file size will not be changed even if
75 is greater than the file size.
76 Preallocating zeroed blocks beyond the end of the file in this manner
77 is useful for optimizing append workloads.
79 Because allocation is done in block size chunks,
81 may allocate a larger range of disk space than was specified.
82 .SS Deallocating file space
84 .BR FALLOC_FL_PUNCH_HOLE
85 flag (available since Linux 2.6.38) in
87 deallocates space (i.e., creates a hole)
88 in the byte range starting at
93 Within the specified range, partial file system blocks are zeroed,
94 and whole file system blocks are removed from the file.
95 After a successful call,
96 subsequent reads from this range will return zeroes.
99 .BR FALLOC_FL_PUNCH_HOLE
100 flag must be ORed with
101 .BR FALLOC_FL_KEEP_SIZE
104 in other words, even when punching off the end of the file, the file size
109 Not all file systems support
110 .BR FALLOC_FL_PUNCH_HOLE ;
111 if a file system doesn't support the operation, an error is returned.
114 returns zero on success, and \-1 on failure.
119 is not a valid file descriptor, or is not opened for writing.
123 exceeds the maximum file size.
126 A signal was caught during execution.
132 .\" FIXME (raise a kernel bug) Probably the len==0 case should be
133 .\" a no-op, rather than an error. That would be consistent with
134 .\" similar APIs for the len==0 case.
135 .\" See "Re: [PATCH] fallocate.2: add FALLOC_FL_PUNCH_HOLE flag definition"
137 .\" http://thread.gmane.org/gmane.linux.file-systems/48331/focus=1193526
138 was less than or equal to 0.
141 An I/O error occurred while reading from or writing to a file system.
145 does not refer to a regular file or a directory.
148 is a pipe or FIFO, a different error results.)
151 There is not enough space left on the device containing the file
156 This kernel does not implement
160 The file system containing the file referred to by
162 does not support this operation;
165 is not supported by the file system containing the file referred to by
169 The file referred to by
171 is marked immutable (see
176 .BR FALLOC_FL_PUNCH_HOLE
178 the file referred to by
180 is marked append-only
186 refers to a pipe or FIFO.
189 is available on Linux since kernel 2.6.23.
190 Support is provided by glibc since version 2.10.
193 flags are defined in glibc headers only since version 2.18.
194 .\" See http://sourceware.org/bugzilla/show_bug.cgi?id=14964
201 .BR posix_fadvise (3),
202 .BR posix_fallocate (3)