summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.1
blob: fe5072ae86814d9410faa7b41e983d55fad9829a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
.TH FALLOCATE 1 "April 2014" "util-linux" "User Commands"
.SH NAME
fallocate \- preallocate or deallocate space to a file
.SH SYNOPSIS
.B fallocate
.RB [ \-c | \-p | \-z ]
.RB [ \-o
.IR offset ]
.B \-l
.I length
.RB [ \-n ]
.I filename
.PP
.B fallocate \-d
.RB [ \-o
.IR offset ]
.RB [ \-l
.IR length ]
.I filename
.PP
.B fallocate \-x
.RB [ \-o
.IR offset ]
.B \-l
.I length
.I filename
.SH DESCRIPTION
.B fallocate
is used to manipulate the allocated disk space for a file,
either to deallocate or preallocate it.
For filesystems which support the fallocate system call,
preallocation is done quickly by allocating blocks and marking them as
uninitialized, requiring no IO to the data blocks.
This is much faster than creating a file by filling it with zeroes.
.PP
The exit code returned by
.B fallocate
is 0 on success and 1 on failure.
.SH OPTIONS
The
.I length
and
.I offset
arguments may be followed by the multiplicative suffixes KiB (=1024),
MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB, and YiB (the "iB" is
optional, e.g., "K" has the same meaning as "KiB") or the suffixes
KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB, and YB.
.PP
The options
.BR \-\-collapse\-range ", " \-\-dig\-holes ", " \-\-punch\-hole ,
and
.B \-\-zero\-range
are mutually exclusive.
.TP
.BR \-c ", " \-\-collapse\-range
Removes a byte range from a file, without leaving a hole.
The byte range to be collapsed starts at
.I offset
and continues for
.I length
bytes.
At the completion of the operation,
the contents of the file starting at the location
.IR offset + length
will be appended at the location
.IR offset ,
and the file will be
.I length
bytes smaller.
The option
.B \-\-keep\-size
may not be specified for the collapse-range operation.
.sp
Available since Linux 3.15 for ext4 (only for extent-based files) and XFS.
.sp
A filesystem may place limitations on the granularity of the operation, in
order to ensure efficient implementation.  Typically, offset and len must be a
multiple of the filesystem logical block size, which varies according to the
filesystem type and configuration.  If a filesystem has such a requirement,
the operation will fail with the error EINVAL if this requirement is violated.
.TP
.BR \-d ", " \-\-dig\-holes
Detect and dig holes.
This makes the file sparse in-place, without using extra disk space.
The minimum size of the hole depends on filesystem I/O block size
(usually 4096 bytes).
Also, when using this option,
.B \-\-keep\-size
is implied.  If no range is specified by
.B \-\-offset
and
.BR \-\-length ,
then the entire file is analyzed for holes.
.sp
You can think of this option as doing a
.RB """" "cp \-\-sparse" """"
and then renaming the destination file to the original,
without the need for extra disk space.
.sp
See \fB\-\-punch\-hole\fP for a list of supported filesystems.
.TP
.BR \-i ", " \-\-insert\-range
Insert a hole of
.I length
bytes from
.IR offset ,
shifting existing data.
.TP
.BR \-l ", " "\-\-length " \fIlength
Specifies the length of the range, in bytes.
.TP
.BR \-n ", " \-\-keep\-size
Do not modify the apparent length of the file.  This may effectively allocate
blocks past EOF, which can be removed with a truncate.
.TP
.BR \-o ", " "\-\-offset " \fIoffset
Specifies the beginning offset of the range, in bytes.
.TP
.BR \-p ", " \-\-punch\-hole
Deallocates space (i.e., creates a hole) in the byte range starting at
.I offset
and continuing for
.I length
bytes.
Within the specified range, partial filesystem blocks are zeroed,
and whole filesystem blocks are removed from the file.
After a successful call,
subsequent reads from this range will return zeroes.
This option may not be specified at the same time as the
.B \-\-zero\-range
option.
Also, when using this option,
.B \-\-keep\-size
is implied.
.sp
Supported for XFS (since Linux 2.6.38), ext4 (since Linux 3.0),
Btrfs (since Linux 3.7) and tmpfs (since Linux 3.5).
.TP
.BR \-v ", " \-\-verbose
Enable verbose mode.
.TP
.BR \-x ", " \-\-posix
Enable POSIX operation mode.
In that mode allocation operation always completes,
but it may take longer time when fast allocation is not supported by
the underlying filesystem.
.TP
.BR \-z ", " \-\-zero\-range
Zeroes space in the byte range starting at
.I offset
and continuing for
.I length
bytes.
Within the specified range, blocks are preallocated for the regions
that span the holes in the file.
After a successful call,
subsequent reads from this range will return zeroes.
.sp
Zeroing is done within the filesystem preferably by converting the
range into unwritten extents.  This approach means that the specified
range will not be physically zeroed out on the device (except for
partial blocks at the either end of the range), and I/O is
(otherwise) required only to update metadata.
.sp
Option \fB\-\-keep\-size\fP can be specified to prevent file length
modification.
.sp
Available since Linux 3.14 for ext4 (only for extent-based files) and XFS.
.TP
.BR \-V ", " \-\-version
Display version information and exit.
.TP
.BR \-h ", " \-\-help
Display help text and exit.
.SH AUTHORS
.MT sandeen@redhat.com
Eric Sandeen
.ME
.br
.MT kzak@redhat.com
Karel Zak
.ME
.SH SEE ALSO
.BR truncate (1),
.BR fallocate (2),
.BR posix_fallocate (3)
.SH AVAILABILITY
The fallocate command is part of the util-linux package and is available from
.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
Linux Kernel Archive
.UE .