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