OSDN Git Service

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