1FALLOCATE(2)               Linux Programmer's Manual              FALLOCATE(2)
2
3
4

NAME

6       fallocate - manipulate file space
7

SYNOPSIS

9       #define _GNU_SOURCE             /* See feature_test_macros(7) */
10       #include <fcntl.h>
11
12       int fallocate(int fd, int mode, off_t offset, off_t len);
13

DESCRIPTION

15       This  is  a nonportable, Linux-specific system call.  For the portable,
16       POSIX.1-specified method of ensuring that  space  is  allocated  for  a
17       file, see posix_fallocate(3).
18
19       fallocate() allows the caller to directly manipulate the allocated disk
20       space for the file referred to by fd for the  byte  range  starting  at
21       offset and continuing for len bytes.
22
23       The mode argument determines the operation to be performed on the given
24       range.  Details of the supported operations are given  in  the  subsec‐
25       tions below.
26
27   Allocating disk space
28       The default operation (i.e., mode is zero) of fallocate() allocates and
29       initializes to zero the disk space within the range specified by offset
30       and  len.   The  file  size (as reported by stat(2)) will be changed if
31       offset+len is greater  than  the  file  size.   This  default  behavior
32       closely  resembles the behavior of the posix_fallocate(3) library func‐
33       tion, and is intended as a method of optimally implementing that  func‐
34       tion.
35
36       After  a successful call, subsequent writes into the range specified by
37       offset and len are guaranteed not to  fail  because  of  lack  of  disk
38       space.
39
40       If  the  FALLOC_FL_KEEP_SIZE flag is specified in mode, the behavior of
41       the call is similar, but the file size will not be changed even if off‐
42       set+len  is  greater  than  the file size.  Preallocating zeroed blocks
43       beyond the end of the file in this  manner  is  useful  for  optimizing
44       append workloads.
45
46       Because  allocation is done in block size chunks, fallocate() may allo‐
47       cate a larger range of disk space than was specified.
48
49   Deallocating file space
50       Specifying the FALLOC_FL_PUNCH_HOLE flag (available since Linux 2.6.38)
51       in  mode  deallocates  space  (i.e.,  creates a hole) in the byte range
52       starting at offset and continuing for len bytes.  Within the  specified
53       range,  partial  file  system  blocks are zeroed, and whole file system
54       blocks are removed from the file.  After a successful call,  subsequent
55       reads from this range will return zeroes.
56
57       The  FALLOC_FL_PUNCH_HOLE flag must be ORed with FALLOC_FL_KEEP_SIZE in
58       mode; in other words, even when punching off the end of the  file,  the
59       file size (as reported by stat(2)) does not change.
60
61       Not  all  file  systems  support FALLOC_FL_PUNCH_HOLE; if a file system
62       doesn't support the operation, an error is returned.
63

RETURN VALUE

65       On success, fallocate() returns zero.  On error,  -1  is  returned  and
66       errno is set to indicate the error.
67

ERRORS

69       EBADF  fd is not a valid file descriptor, or is not opened for writing.
70
71       EFBIG  offset+len exceeds the maximum file size.
72
73       EINTR  A signal was caught during execution.
74
75       EINVAL offset was less than 0, or len was less than or equal to 0.
76
77       EIO    An  I/O  error  occurred while reading from or writing to a file
78              system.
79
80       ENODEV fd does not refer to a regular file or a directory.  (If fd is a
81              pipe or FIFO, a different error results.)
82
83       ENOSPC There is not enough space left on the device containing the file
84              referred to by fd.
85
86       ENOSYS This kernel does not implement fallocate().
87
88       EOPNOTSUPP
89              The file system containing the file referred to by fd  does  not
90              support this operation; or the mode is not supported by the file
91              system containing the file referred to by fd.
92
93       EPERM  The file referred to by fd is marked immutable (see  chattr(1)).
94              Or: mode specifies FALLOC_FL_PUNCH_HOLE and the file referred to
95              by fd is marked append-only (see chattr(1)).
96
97       ESPIPE fd refers to a pipe or FIFO.
98

VERSIONS

100       fallocate() is available on Linux since kernel 2.6.23.  Support is pro‐
101       vided  by  glibc since version 2.10.  The FALLOC_FL_* flags are defined
102       in glibc headers only since version 2.18.
103

CONFORMING TO

105       fallocate() is Linux-specific.
106

SEE ALSO

108       fallocate(1), ftruncate(2), posix_fadvise(3), posix_fallocate(3)
109

COLOPHON

111       This page is part of release 3.53 of the Linux  man-pages  project.   A
112       description  of  the project, and information about reporting bugs, can
113       be found at http://www.kernel.org/doc/man-pages/.
114
115
116
117Linux                             2013-06-10                      FALLOCATE(2)
Impressum