]>
Commit | Line | Data |
---|---|---|
d9a0b2a5 MK |
1 | .\" Copyright (c) 2007 Silicon Graphics, Inc. All Rights Reserved |
2 | .\" Written by Dave Chinner <dgc@sgi.com> | |
2297bf0e | 3 | .\" |
c4a99c30 | 4 | .\" %%%LICENSE_START(GPLv2_ONELINE) |
d9a0b2a5 | 5 | .\" May be distributed as per GNU General Public License version 2. |
8ff7380d | 6 | .\" %%%LICENSE_END |
d9a0b2a5 | 7 | .\" |
f52e0be8 MK |
8 | .\" 2011-09-19: Added FALLOC_FL_PUNCH_HOLE |
9 | .\" 2011-09-19: Substantial restructuring of the page | |
10 | .\" | |
5722c835 | 11 | .TH FALLOCATE 2 2015-07-23 "Linux" "Linux Programmer's Manual" |
d9a0b2a5 MK |
12 | .SH NAME |
13 | fallocate \- manipulate file space | |
14 | .SH SYNOPSIS | |
15 | .nf | |
86b91fdf | 16 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
ff6db399 | 17 | .B #include <fcntl.h> |
c8250206 | 18 | |
ff6db399 MK |
19 | .BI "int fallocate(int " fd ", int " mode ", off_t " offset \ |
20 | ", off_t " len "); | |
c8250206 | 21 | .fi |
d9a0b2a5 | 22 | .SH DESCRIPTION |
d603cc27 | 23 | This is a nonportable, Linux-specific system call. |
01b7704f MK |
24 | For the portable, POSIX.1-specified method of ensuring that space |
25 | is allocated for a file, see | |
8c56fcec | 26 | .BR posix_fallocate (3). |
01b7704f | 27 | |
d9a0b2a5 MK |
28 | .BR fallocate () |
29 | allows the caller to directly manipulate the allocated disk space | |
30 | for the file referred to by | |
31 | .I fd | |
32 | for the byte range starting at | |
33 | .I offset | |
34 | and continuing for | |
35 | .I len | |
36 | bytes. | |
37 | ||
38 | The | |
39 | .I mode | |
40 | argument determines the operation to be performed on the given range. | |
f52e0be8 MK |
41 | Details of the supported operations are given in the subsections below. |
42 | .SS Allocating disk space | |
43 | The default operation (i.e., | |
44 | .I mode | |
45 | is zero) of | |
46 | .BR fallocate () | |
c166fac5 | 47 | allocates the disk space within the range specified by |
d9a0b2a5 MK |
48 | .I offset |
49 | and | |
50 | .IR len . | |
f52e0be8 MK |
51 | The file size (as reported by |
52 | .BR stat (2)) | |
53 | will be changed if | |
381ee84e | 54 | .IR offset + len |
f52e0be8 | 55 | is greater than the file size. |
4d4cecd6 | 56 | Any subregion within the range specified by |
c166fac5 CH |
57 | .I offset |
58 | and | |
ddacd026 | 59 | .IR len |
c166fac5 | 60 | that did not contain data before the call will be initialized to zero. |
f52e0be8 MK |
61 | This default behavior closely resembles the behavior of the |
62 | .BR posix_fallocate (3) | |
63 | library function, | |
64 | and is intended as a method of optimally implementing that function. | |
65 | ||
66 | After a successful call, subsequent writes into the range specified by | |
67 | .IR offset | |
68 | and | |
69 | .IR len | |
d9a0b2a5 | 70 | are guaranteed not to fail because of lack of disk space. |
f52e0be8 MK |
71 | |
72 | If the | |
73 | .B FALLOC_FL_KEEP_SIZE | |
74 | flag is specified in | |
75 | .IR mode , | |
76 | the behavior of the call is similar, | |
77 | but the file size will not be changed even if | |
381ee84e | 78 | .IR offset + len |
f52e0be8 MK |
79 | is greater than the file size. |
80 | Preallocating zeroed blocks beyond the end of the file in this manner | |
d9a0b2a5 | 81 | is useful for optimizing append workloads. |
d9a0b2a5 | 82 | .PP |
f52e0be8 MK |
83 | Because allocation is done in block size chunks, |
84 | .BR fallocate () | |
85 | may allocate a larger range of disk space than was specified. | |
86 | .SS Deallocating file space | |
87 | Specifying the | |
88 | .BR FALLOC_FL_PUNCH_HOLE | |
89 | flag (available since Linux 2.6.38) in | |
90 | .I mode | |
91 | deallocates space (i.e., creates a hole) | |
96575bbc | 92 | in the byte range starting at |
1c7857e9 LAG |
93 | .I offset |
94 | and continuing for | |
95 | .I len | |
f52e0be8 | 96 | bytes. |
9ee4a2b6 MK |
97 | Within the specified range, partial filesystem blocks are zeroed, |
98 | and whole filesystem blocks are removed from the file. | |
96575bbc MK |
99 | After a successful call, |
100 | subsequent reads from this range will return zeroes. | |
f52e0be8 | 101 | |
96575bbc | 102 | The |
1c7857e9 | 103 | .BR FALLOC_FL_PUNCH_HOLE |
96575bbc | 104 | flag must be ORed with |
1c7857e9 | 105 | .BR FALLOC_FL_KEEP_SIZE |
f52e0be8 MK |
106 | in |
107 | .IR mode ; | |
96575bbc MK |
108 | in other words, even when punching off the end of the file, the file size |
109 | (as reported by | |
1c7857e9 | 110 | .BR stat (2)) |
96575bbc | 111 | does not change. |
f52e0be8 | 112 | |
9ee4a2b6 | 113 | Not all filesystems support |
f52e0be8 | 114 | .BR FALLOC_FL_PUNCH_HOLE ; |
9ee4a2b6 | 115 | if a filesystem doesn't support the operation, an error is returned. |
ce430f41 | 116 | The operation is supported on at least the following filesystems: |
49995543 MK |
117 | .IP * 3 |
118 | XFS (since Linux 2.6.38) | |
119 | .IP * | |
120 | ext4 (since Linux 3.0) | |
121 | .\" commit a4bb6b64e39abc0e41ca077725f2a72c868e7622 | |
122 | .IP * | |
123 | Btrfs (since Linux 3.7) | |
124 | .IP * | |
125 | tmpfs (since Linux 3.5) | |
126 | .\" commit 83e4fa9c16e4af7122e31be3eca5d57881d236fe | |
ea56dddf | 127 | .SS Collapsing file space |
1ecfa5b3 | 128 | .\" commit 00f5e61998dd17f5375d9dfc01331f104b83f841 |
f78da076 | 129 | Specifying the |
ea56dddf | 130 | .BR FALLOC_FL_COLLAPSE_RANGE |
1ecfa5b3 | 131 | flag (available since Linux 3.15) in |
ea56dddf | 132 | .I mode |
1ecfa5b3 MK |
133 | removes a byte range from a file, without leaving a hole. |
134 | The byte range to be collapsed starts at | |
ea56dddf | 135 | .I offset |
1ecfa5b3 | 136 | and continues for |
ea56dddf | 137 | .I len |
f78da076 | 138 | bytes. |
1ecfa5b3 MK |
139 | At the completion of the operation, |
140 | the contents of the file starting at the location | |
141 | .I offset+len | |
142 | will be appended at the location | |
143 | .IR offset , | |
144 | and the file will be | |
145 | .I len | |
146 | bytes smaller. | |
ea56dddf | 147 | |
1ecfa5b3 MK |
148 | A filesystem may place limitations on the granularity of the operation, |
149 | in order to ensure efficient implementation. | |
150 | Typically, | |
151 | .I offset | |
152 | and | |
153 | .I len | |
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, | |
157 | .BR fallocate () | |
158 | will fail with the error | |
159 | .BR EINVAL | |
160 | if this requirement is violated. | |
ea56dddf | 161 | |
1ecfa5b3 MK |
162 | If the region specified by |
163 | .I offset | |
164 | plus | |
165 | .I len | |
166 | reaches or passes the end of file, an error is returned; | |
167 | instead, use | |
168 | .BR ftruncate (2) | |
169 | to truncate a file. | |
170 | ||
171 | No other flags may be specified in | |
172 | .IR mode | |
173 | in conjunction with | |
174 | .BR FALLOC_FL_COLLAPSE_RANGE . | |
ea56dddf | 175 | |
1ecfa5b3 MK |
176 | As at Linux 3.15, |
177 | .B FALLOC_FL_COLLAPSE_RANGE | |
178 | is supported by | |
179 | ext4 (only for extent-based files) | |
180 | .\" commit 9eb79482a97152930b113b51dff530aba9e28c8e | |
181 | and XFS. | |
182 | .\" commit e1d8fb88a64c1f8094b9f6c3b6d2d9e6719c970d | |
7dc489e3 | 183 | .SS Zeroing file space |
44e4132a | 184 | Specifying the |
7dc489e3 | 185 | .BR FALLOC_FL_ZERO_RANGE |
4a401602 | 186 | flag (available since Linux 3.15) |
44e4132a MK |
187 | .\" commit 409332b65d3ed8cfa7a8030f1e9d52f372219642 |
188 | in | |
7dc489e3 LC |
189 | .I mode |
190 | zeroes space in the byte range starting at | |
191 | .I offset | |
192 | and continuing for | |
193 | .I len | |
194 | bytes. | |
195 | Within the specified range, blocks are preallocated for the regions | |
44e4132a MK |
196 | that span the holes in the file. |
197 | After a successful call, subsequent | |
7dc489e3 LC |
198 | reads from this range will return zeroes. |
199 | ||
7c7960f8 MK |
200 | Zeroing is done within the filesystem preferably by converting the range into |
201 | unwritten extents. | |
202 | This approach means that the specified range will not be physically zeroed | |
4cb27742 | 203 | out on the device (except for partial blocks at the either end of the range), |
b9ddebe2 | 204 | and I/O is (otherwise) required only to update metadata. |
7dc489e3 LC |
205 | |
206 | If the | |
207 | .B FALLOC_FL_KEEP_SIZE | |
7c7960f8 | 208 | flag is additionally specified in |
7dc489e3 LC |
209 | .IR mode , |
210 | the behavior of the call is similar, | |
211 | but the file size will not be changed even if | |
212 | .IR offset + len | |
44e4132a | 213 | is greater than the file size. |
a1fa36af | 214 | This behavior is the same as when preallocating space with |
7dc489e3 LC |
215 | .B FALLOC_FL_KEEP_SIZE |
216 | specified. | |
217 | ||
218 | Not all filesystems support | |
219 | .BR FALLOC_FL_ZERO_RANGE ; | |
220 | if a filesystem doesn't support the operation, an error is returned. | |
44e4132a | 221 | The operation is supported on at least the following filesystems: |
7dc489e3 | 222 | .IP * 3 |
4a401602 | 223 | XFS (since Linux 3.15) |
7dc489e3 LC |
224 | .\" commit 376ba313147b4172f3e8cf620b9fb591f3e8cdfa |
225 | .IP * | |
4a401602 | 226 | ext4, for extent-based files (since Linux 3.15) |
7dc489e3 | 227 | .\" commit b8a8684502a0fc852afa0056c6bb2a9273f6fcc0 |
adf507a3 MK |
228 | .IP * |
229 | SMB3 (since Linux 3.17) | |
230 | .\" commit 30175628bf7f521e9ee31ac98fa6d6fe7441a556 | |
7da70a01 | 231 | .SS Increasing file space |
7da70a01 NJ |
232 | Specifying the |
233 | .BR FALLOC_FL_INSERT_RANGE | |
ec9a2be0 MK |
234 | flag |
235 | (available since Linux 4.1) | |
236 | .\" commit dd46c787788d5bf5b974729d43e4c405814a4c7d | |
237 | in | |
7da70a01 | 238 | .I mode |
ec9a2be0 | 239 | increases the file space by inserting a hole within the file size without |
7da70a01 NJ |
240 | overwriting any existing data. |
241 | The hole will start at | |
242 | .I offset | |
243 | and continue for | |
244 | .I len | |
245 | bytes. | |
ec9a2be0 | 246 | When inserting the hole inside file, the contents of the file starting at |
7da70a01 | 247 | .I offset |
ec9a2be0 | 248 | will be shifted upward (i.e., to a higher file offset) by |
7da70a01 NJ |
249 | .I len |
250 | bytes. | |
ec9a2be0 | 251 | Inserting a hole inside a file increases the file size by |
7da70a01 NJ |
252 | .I len |
253 | bytes. | |
254 | ||
ec9a2be0 | 255 | This mode has the same limitations as |
7da70a01 | 256 | .BR FALLOC_FL_COLLAPSE_RANGE |
ec9a2be0 | 257 | regarding the granularity of the operation. |
7da70a01 NJ |
258 | If the granularity requirements are not met, |
259 | .BR fallocate () | |
260 | will fail with the error | |
261 | .BR EINVAL. | |
262 | If the | |
263 | .I offset | |
ec9a2be0 MK |
264 | is equal to or greater than the end of file, an error is returned. |
265 | For such operations (i.e., inserting a hole at the end of file), | |
266 | .BR ftruncate (2) | |
7da70a01 | 267 | should be used. |
7da70a01 NJ |
268 | |
269 | No other flags may be specified in | |
270 | .IR mode | |
271 | in conjunction with | |
272 | .BR FALLOC_FL_INSERT_RANGE . | |
273 | ||
7da70a01 | 274 | .B FALLOC_FL_INSERT_RANGE |
bb2f7580 MK |
275 | requires filesystem support. |
276 | Filesystems that support this operation include | |
277 | XFS (since Linux 4.1) | |
7da70a01 | 278 | .\" commit a904b1ca5751faf5ece8600e18cd3b674afcca1b |
bb2f7580 MK |
279 | and ext4 (since Linux 4.2). |
280 | .\" commit 331573febb6a224bc50322e3670da326cb7f4cfc | |
281 | .\" f2fs also has support since Linux 4.2 | |
282 | .\" commit f62185d0e283e9d311e3ac1020f159d95f0aab39 | |
d9a0b2a5 | 283 | .SH RETURN VALUE |
276939a6 | 284 | On success, |
d9a0b2a5 | 285 | .BR fallocate () |
47a97908 MK |
286 | returns zero. |
287 | On error, \-1 is returned and | |
288 | .I errno | |
289 | is set to indicate the error. | |
d9a0b2a5 MK |
290 | .SH ERRORS |
291 | .TP | |
292 | .B EBADF | |
293 | .I fd | |
294 | is not a valid file descriptor, or is not opened for writing. | |
295 | .TP | |
296 | .B EFBIG | |
297 | .IR offset + len | |
298 | exceeds the maximum file size. | |
299 | .TP | |
7da70a01 NJ |
300 | .B EFBIG |
301 | .I mode | |
302 | is | |
303 | .BR FALLOC_FL_INSERT_RANGE , | |
ec9a2be0 | 304 | and the current file size+\fIlen\fP exceeds the maximum file size. |
7da70a01 | 305 | .TP |
d9a0b2a5 MK |
306 | .B EINTR |
307 | A signal was caught during execution. | |
308 | .TP | |
309 | .B EINVAL | |
310 | .I offset | |
311 | was less than 0, or | |
312 | .I len | |
bea08fec | 313 | .\" FIXME . (raise a kernel bug) Probably the len==0 case should be |
c0c3d019 MK |
314 | .\" a no-op, rather than an error. That would be consistent with |
315 | .\" similar APIs for the len==0 case. | |
316 | .\" See "Re: [PATCH] fallocate.2: add FALLOC_FL_PUNCH_HOLE flag definition" | |
317 | .\" 21 Sep 2012 | |
318 | .\" http://thread.gmane.org/gmane.linux.file-systems/48331/focus=1193526 | |
d9a0b2a5 MK |
319 | was less than or equal to 0. |
320 | .TP | |
1ecfa5b3 MK |
321 | .B EINVAL |
322 | .I mode | |
323 | is | |
324 | .BR FALLOC_FL_COLLAPSE_RANGE | |
325 | and the range specified by | |
326 | .I offset | |
327 | plus | |
328 | .I len | |
329 | reaches or passes the end of the file. | |
330 | .TP | |
331 | .B EINVAL | |
332 | .I mode | |
333 | is | |
7da70a01 NJ |
334 | .BR FALLOC_FL_INSERT_RANGE |
335 | and the range specified by | |
336 | .I offset | |
337 | reaches or passes the end of the file. | |
338 | .TP | |
339 | .B EINVAL | |
340 | .I mode | |
341 | is | |
342 | .BR FALLOC_FL_COLLAPSE_RANGE | |
343 | or | |
344 | .BR FALLOC_FL_INSERT_RANGE , | |
1ecfa5b3 MK |
345 | but either |
346 | .I offset | |
347 | or | |
348 | .I len | |
349 | is not a multiple of the filesystem block size. | |
350 | .TP | |
351 | .B EINVAL | |
718778ad | 352 | .I mode |
ec9a2be0 | 353 | contains one of |
1ecfa5b3 | 354 | .B FALLOC_FL_COLLAPSE_RANGE |
7da70a01 NJ |
355 | or |
356 | .B FALLOC_FL_INSERT_RANGE | |
ec9a2be0 | 357 | and also other flags; |
1ecfa5b3 | 358 | no other flags are permitted with |
7da70a01 NJ |
359 | .BR FALLOC_FL_COLLAPSE_RANGE |
360 | or | |
361 | .BR FALLOC_FL_INSERT_RANGE . | |
718778ad SP |
362 | .TP |
363 | .B EINVAL | |
2af4d967 MK |
364 | .I mode |
365 | is | |
7dc489e3 LC |
366 | .BR FALLOC_FL_COLLAPSE_RANGE |
367 | or | |
7da70a01 NJ |
368 | .BR FALLOC_FL_ZERO_RANGE |
369 | or | |
370 | .BR FALLOC_FL_INSERT_RANGE , | |
2af4d967 MK |
371 | but the file referred to by |
372 | .I fd | |
373 | is not a regular file. | |
374 | .\" There was a inconsistency in 3.15-rc1, that should be resolved so that all | |
375 | .\" filesystems use this error for this case. (Tytso says ex4 will change.) | |
376 | .\" http://thread.gmane.org/gmane.comp.file-systems.xfs.general/60485/focus=5521 | |
377 | .\" From: Michael Kerrisk (man-pages <mtk.manpages@...> | |
378 | .\" Subject: Re: [PATCH v5 10/10] manpage: update FALLOC_FL_COLLAPSE_RANGE flag in fallocate | |
379 | .\" Newsgroups: gmane.linux.man, gmane.linux.file-systems | |
380 | .\" Date: 2014-04-17 13:40:05 GMT | |
1ecfa5b3 | 381 | .TP |
d9a0b2a5 | 382 | .B EIO |
9ee4a2b6 | 383 | An I/O error occurred while reading from or writing to a filesystem. |
d9a0b2a5 MK |
384 | .TP |
385 | .B ENODEV | |
386 | .I fd | |
387 | does not refer to a regular file or a directory. | |
388 | (If | |
389 | .I fd | |
390 | is a pipe or FIFO, a different error results.) | |
391 | .TP | |
392 | .B ENOSPC | |
393 | There is not enough space left on the device containing the file | |
394 | referred to by | |
395 | .IR fd . | |
396 | .TP | |
397 | .B ENOSYS | |
7cb4d005 MK |
398 | This kernel does not implement |
399 | .BR fallocate (). | |
d9a0b2a5 MK |
400 | .TP |
401 | .B EOPNOTSUPP | |
9ee4a2b6 | 402 | The filesystem containing the file referred to by |
7cb4d005 MK |
403 | .I fd |
404 | does not support this operation; | |
405 | or the | |
d9a0b2a5 | 406 | .I mode |
9ee4a2b6 | 407 | is not supported by the filesystem containing the file referred to by |
d9a0b2a5 | 408 | .IR fd . |
45eb0d22 MK |
409 | .TP |
410 | .B EPERM | |
411 | The file referred to by | |
928b1970 | 412 | .I fd |
45eb0d22 | 413 | is marked immutable (see |
7eb92881 | 414 | .BR chattr (1)). |
95dcbfb5 MK |
415 | .TP |
416 | .B EPERM | |
54d25eca MK |
417 | .I mode |
418 | specifies | |
419 | .BR FALLOC_FL_PUNCH_HOLE | |
1ecfa5b3 MK |
420 | or |
421 | .BR FALLOC_FL_COLLAPSE_RANGE | |
7da70a01 NJ |
422 | or |
423 | .BR FALLOC_FL_INSERT_RANGE | |
54d25eca MK |
424 | and |
425 | the file referred to by | |
426 | .I fd | |
427 | is marked append-only | |
428 | (see | |
928b1970 | 429 | .BR chattr (1)). |
45eb0d22 | 430 | .TP |
fbab10e5 MK |
431 | .B EPERM |
432 | The operation was prevented by a file seal; see | |
433 | .BR fcntl (2). | |
434 | .TP | |
45eb0d22 MK |
435 | .B ESPIPE |
436 | .I fd | |
928b1970 | 437 | refers to a pipe or FIFO. |
1ecfa5b3 MK |
438 | .TP |
439 | .B ETXTBSY | |
440 | .I mode | |
441 | specifies | |
7da70a01 NJ |
442 | .BR FALLOC_FL_COLLAPSE_RANGE |
443 | or | |
444 | .BR FALLOC_FL_INSERT_RANGE , | |
1ecfa5b3 MK |
445 | but the file referred to by |
446 | .IR fd | |
447 | is currently being executed. | |
d9a0b2a5 MK |
448 | .SH VERSIONS |
449 | .BR fallocate () | |
d9a0b2a5 | 450 | is available on Linux since kernel 2.6.23. |
ff6db399 | 451 | Support is provided by glibc since version 2.10. |
7f26805b MK |
452 | The |
453 | .BR FALLOC_FL_* | |
454 | flags are defined in glibc headers only since version 2.18. | |
455 | .\" See http://sourceware.org/bugzilla/show_bug.cgi?id=14964 | |
90e261f2 | 456 | .SH CONFORMING TO |
d9a0b2a5 | 457 | .BR fallocate () |
8382f16d | 458 | is Linux-specific. |
d9a0b2a5 | 459 | .SH SEE ALSO |
1b946741 | 460 | .BR fallocate (1), |
d9a0b2a5 | 461 | .BR ftruncate (2), |
f0c34053 MK |
462 | .BR posix_fadvise (3), |
463 | .BR posix_fallocate (3) |