xref: /linux-6.15/include/uapi/linux/falloc.h (revision 57413d8e)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI_FALLOC_H_
3607ca46eSDavid Howells #define _UAPI_FALLOC_H_
4607ca46eSDavid Howells 
5*57413d8eSChristoph Hellwig #define FALLOC_FL_ALLOCATE_RANGE 0x00 /* allocate range */
6607ca46eSDavid Howells #define FALLOC_FL_KEEP_SIZE	0x01 /* default is extend size */
7607ca46eSDavid Howells #define FALLOC_FL_PUNCH_HOLE	0x02 /* de-allocates range */
8607ca46eSDavid Howells #define FALLOC_FL_NO_HIDE_STALE	0x04 /* reserved codepoint */
9607ca46eSDavid Howells 
1000f5e619SNamjae Jeon /*
1100f5e619SNamjae Jeon  * FALLOC_FL_COLLAPSE_RANGE is used to remove a range of a file
1200f5e619SNamjae Jeon  * without leaving a hole in the file. The contents of the file beyond
1300f5e619SNamjae Jeon  * the range being removed is appended to the start offset of the range
1400f5e619SNamjae Jeon  * being removed (i.e. the hole that was punched is "collapsed"),
1500f5e619SNamjae Jeon  * resulting in a file layout that looks like the range that was
1600f5e619SNamjae Jeon  * removed never existed. As such collapsing a range of a file changes
1700f5e619SNamjae Jeon  * the size of the file, reducing it by the same length of the range
1800f5e619SNamjae Jeon  * that has been removed by the operation.
1900f5e619SNamjae Jeon  *
2000f5e619SNamjae Jeon  * Different filesystems may implement different limitations on the
2100f5e619SNamjae Jeon  * granularity of the operation. Most will limit operations to
2200f5e619SNamjae Jeon  * filesystem block size boundaries, but this boundary may be larger or
2300f5e619SNamjae Jeon  * smaller depending on the filesystem and/or the configuration of the
2400f5e619SNamjae Jeon  * filesystem or file.
2500f5e619SNamjae Jeon  *
2600f5e619SNamjae Jeon  * Attempting to collapse a range that crosses the end of the file is
2700f5e619SNamjae Jeon  * considered an illegal operation - just use ftruncate(2) if you need
2800f5e619SNamjae Jeon  * to collapse a range that crosses EOF.
2900f5e619SNamjae Jeon  */
3000f5e619SNamjae Jeon #define FALLOC_FL_COLLAPSE_RANGE	0x08
31607ca46eSDavid Howells 
32409332b6SLukas Czerner /*
33409332b6SLukas Czerner  * FALLOC_FL_ZERO_RANGE is used to convert a range of file to zeros preferably
34409332b6SLukas Czerner  * without issuing data IO. Blocks should be preallocated for the regions that
35409332b6SLukas Czerner  * span holes in the file, and the entire range is preferable converted to
36409332b6SLukas Czerner  * unwritten extents - even though file system may choose to zero out the
37409332b6SLukas Czerner  * extent or do whatever which will result in reading zeros from the range
38409332b6SLukas Czerner  * while the range remains allocated for the file.
39409332b6SLukas Czerner  *
40409332b6SLukas Czerner  * This can be also used to preallocate blocks past EOF in the same way as
41409332b6SLukas Czerner  * with fallocate. Flag FALLOC_FL_KEEP_SIZE should cause the inode
42409332b6SLukas Czerner  * size to remain the same.
43409332b6SLukas Czerner  */
44409332b6SLukas Czerner #define FALLOC_FL_ZERO_RANGE		0x10
45409332b6SLukas Czerner 
46dd46c787SNamjae Jeon /*
47dd46c787SNamjae Jeon  * FALLOC_FL_INSERT_RANGE is use to insert space within the file size without
48dd46c787SNamjae Jeon  * overwriting any existing data. The contents of the file beyond offset are
49dd46c787SNamjae Jeon  * shifted towards right by len bytes to create a hole.  As such, this
50dd46c787SNamjae Jeon  * operation will increase the size of the file by len bytes.
51dd46c787SNamjae Jeon  *
52dd46c787SNamjae Jeon  * Different filesystems may implement different limitations on the granularity
53dd46c787SNamjae Jeon  * of the operation. Most will limit operations to filesystem block size
54dd46c787SNamjae Jeon  * boundaries, but this boundary may be larger or smaller depending on
55dd46c787SNamjae Jeon  * the filesystem and/or the configuration of the filesystem or file.
56dd46c787SNamjae Jeon  *
57dd46c787SNamjae Jeon  * Attempting to insert space using this flag at OR beyond the end of
58dd46c787SNamjae Jeon  * the file is considered an illegal operation - just use ftruncate(2) or
59dd46c787SNamjae Jeon  * fallocate(2) with mode 0 for such type of operations.
60dd46c787SNamjae Jeon  */
61dd46c787SNamjae Jeon #define FALLOC_FL_INSERT_RANGE		0x20
62dd46c787SNamjae Jeon 
6371be6b49SDarrick J. Wong /*
6471be6b49SDarrick J. Wong  * FALLOC_FL_UNSHARE_RANGE is used to unshare shared blocks within the
6571be6b49SDarrick J. Wong  * file size without overwriting any existing data. The purpose of this
6671be6b49SDarrick J. Wong  * call is to preemptively reallocate any blocks that are subject to
6771be6b49SDarrick J. Wong  * copy-on-write.
6871be6b49SDarrick J. Wong  *
6971be6b49SDarrick J. Wong  * Different filesystems may implement different limitations on the
7071be6b49SDarrick J. Wong  * granularity of the operation. Most will limit operations to filesystem
7171be6b49SDarrick J. Wong  * block size boundaries, but this boundary may be larger or smaller
7271be6b49SDarrick J. Wong  * depending on the filesystem and/or the configuration of the filesystem
7371be6b49SDarrick J. Wong  * or file.
7471be6b49SDarrick J. Wong  *
7571be6b49SDarrick J. Wong  * This flag can only be used with allocate-mode fallocate, which is
7671be6b49SDarrick J. Wong  * to say that it cannot be used with the punch, zero, collapse, or
7771be6b49SDarrick J. Wong  * insert range modes.
7871be6b49SDarrick J. Wong  */
7971be6b49SDarrick J. Wong #define FALLOC_FL_UNSHARE_RANGE		0x40
8071be6b49SDarrick J. Wong 
81607ca46eSDavid Howells #endif /* _UAPI_FALLOC_H_ */
82