]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/fallocate.2
grfix
[thirdparty/man-pages.git] / man2 / fallocate.2
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.
4 .\"
5 .TH FALLOCATE 2 2007-07-20 "Linux" "Linux Programmer's Manual"
6 .SH NAME
7 fallocate \- manipulate file space
8 .SH SYNOPSIS
9 .nf
10 .\" FIXME . eventually this #include will probably be something
11 .\" different when support is added in glibc.
12 .B #include <linux/falloc.h>
13
14 .BI "long fallocate(int " fd ", int " mode ", loff_t " offset \
15 ", loff_t " len ");
16 .fi
17 .\" FIXME . check later what feature text macros are required in glibc
18 .SH DESCRIPTION
19 .BR fallocate ()
20 allows the caller to directly manipulate the allocated disk space
21 for the file referred to by
22 .I fd
23 for the byte range starting at
24 .I offset
25 and continuing for
26 .I len
27 bytes.
28
29 The
30 .I mode
31 argument determines the operation to be performed on the given range.
32 Currently only one flag is supported for
33 .IR mode :
34 .TP
35 .B FALLOC_FL_KEEP_SIZE
36 This flag allocates and initializes to zero the disk space
37 within the range specified by
38 .I offset
39 and
40 .IR len .
41 After a successful call, subsequent writes into this range
42 are guaranteed not to fail because of lack of disk space.
43 Preallocating zeroed blocks beyond the end of the file
44 is useful for optimizing append workloads.
45 Preallocating blocks does not change
46 the file size (as reported by
47 .BR stat (2))
48 even if it is less than
49 .IR offset + len .
50 .\"
51 .\" Note from Amit Arora:
52 .\" There were few more flags which were discussed, but none of
53 .\" them have been finalized upon. Here are these flags:
54 .\" FA_FL_DEALLOC, FA_FL_DEL_DATA, FA_FL_ERR_FREE, FA_FL_NO_MTIME,
55 .\" FA_FL_NO_CTIME
56 .\" All of the above flags were debated upon and we can not say
57 .\" if any/which one of these flags will make it to the later kernels.
58 .PP
59 If
60 .B FALLOC_FL_KEEP_SIZE
61 flag is not specified in
62 .IR mode ,
63 the default behavior is almost same as when this flag is specified.
64 The only difference is that on success,
65 the file size will be changed if
66 .I "offset + len"
67 is greater than the file size.
68 This default behavior closely resembles the behavior of the
69 .BR posix_fallocate (3)
70 library function,
71 and is intended as a method of optimally implementing that function.
72 .PP
73 Because allocation is done in block size chunks,
74 .BR fallocate ()
75 may allocate a larger range than that which was specified.
76 .SH RETURN VALUE
77 .BR fallocate ()
78 returns zero on success, or an error number on failure.
79 Note that
80 .\" FIXME . the library wrapper function will do the right
81 .\" thing, returning -1 on error and setting errno.
82 .I errno
83 is not set.
84 .SH ERRORS
85 .TP
86 .B EBADF
87 .I fd
88 is not a valid file descriptor, or is not opened for writing.
89 .TP
90 .B EFBIG
91 .IR offset + len
92 exceeds the maximum file size.
93 .TP
94 .B EINTR
95 A signal was caught during execution.
96 .TP
97 .B EINVAL
98 .I offset
99 was less than 0, or
100 .I len
101 was less than or equal to 0.
102 .TP
103 .B EIO
104 An I/O error occurred while reading from or writing to a file system.
105 .TP
106 .B ENODEV
107 .I fd
108 does not refer to a regular file or a directory.
109 (If
110 .I fd
111 is a pipe or FIFO, a different error results.)
112 .TP
113 .B ENOSPC
114 There is not enough space left on the device containing the file
115 referred to by
116 .IR fd .
117 .TP
118 .B ENOSYS
119 The file system containing the file referred to by
120 .I fd
121 does not support this operation.
122 .TP
123 .B EOPNOTSUPP
124 The
125 .I mode
126 is not supported by the file system containing the file referred to by
127 .IR fd .
128 .SH VERSIONS
129 .BR fallocate ()
130 is available on Linux since kernel 2.6.23.
131 .SH CONFORMING TO
132 .BR fallocate ()
133 is Linux-specific.
134 .SH SEE ALSO
135 .BR ftruncate (2),
136 .BR posix_fallocate (3),
137 .BR posix_fadvise (3)