xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/sys/linux/fs.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**
2  * D header file for the linux/fs.h interface.
3  *
4  * This file has definitions for some important file table structures
5  * and constants and structures used by various generic file system
6  * ioctl's.
7  *
8  * Copyright: The D Language Foundation 2021.
9  * License : $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
10  * Authors : Luís Ferreira
11  */
12 module core.sys.linux.fs;
13 
14 version (linux):
15 
16 public import core.sys.posix.sys.ioctl;
17 
18 import core.stdc.config : c_ulong, c_long;
19 
20 extern (C):
21 @system:
22 @nogc:
23 nothrow:
24 
25 enum INR_OPEN_CUR = 1024; /// Initial setting for nfile rlimits
26 enum INR_OPEN_MAX = 4096; /// Hard limit for nfile rlimits
27 
28 enum BLOCK_SIZE_BITS = 10; ///
29 enum BLOCK_SIZE = 1 << BLOCK_SIZE_BITS; ///
30 
31 enum
32 {
33     SEEK_SET = 0, /// seek relative to beginning of file
34     SEEK_CUR = 1, /// seek relative to current file position
35     SEEK_END = 2, /// seek relative to end of file
36     SEEK_DATA = 3, /// seek to the next data
37     SEEK_HOLE = 4, /// seek to the next hole
38     SEEK_MAX = SEEK_HOLE, ///
39 }
40 
41 enum
42 {
43     RENAME_NOREPLACE = 1 << 0, /// Don't overwrite target
44     RENAME_EXCHANGE = 1 << 1, /// Exchange source and dest
45     RENAME_WHITEOUT = 1 << 2, /// Whiteout source
46 }
47 
48 struct file_clone_range
49 {
50     long src_fd;
51     ulong src_offset;
52     ulong src_length;
53     ulong dest_offset;
54 }
55 
56 struct fstrim_range
57 {
58     ulong start;
59     ulong len;
60     ulong minlen;
61 }
62 
63 /**
64  * extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions
65  */
66 enum
67 {
68     FILE_DEDUPE_RANGE_SAME = 0,
69     FILE_DEDUPE_RANGE_DIFFERS = 1,
70 }
71 
72 /**
73  * from struct btrfs_ioctl_file_extent_same_info
74  */
75 struct file_dedupe_range_info
76 {
77     long dest_fd; /// in - destination file
78     ulong dest_offset; /// in - start of extent in destination
79     ulong bytes_deduped; /// out - total # of bytes we were able to dedupe from this file.
80     /** status of this dedupe operation:
81      * < 0 for error
82      * == FILE_DEDUPE_RANGE_SAME if dedupe succeeds
83      * == FILE_DEDUPE_RANGE_DIFFERS if data differs
84      */
85     int status;
86     uint reserved; /// must be zero
87 }
88 
89 /**
90  * from struct btrfs_ioctl_file_extent_same_args
91  */
92 struct file_dedupe_range
93 {
94     ulong src_offset; /// in - start of extent in source
95     ulong src_length; /// in - length of extent
96     ushort dest_count; /// in - total elements in info array
97     ushort reserved1; /// must be zero
98     uint reserved2; /// must be zero
99     file_dedupe_range_info[0] info;
100 }
101 
102 /**
103  * And dynamically-tunable limits and defaults:
104  */
105 struct files_stat_struct
106 {
107     c_ulong nr_files; /// read only
108     c_ulong nr_free_files; /// read only
109     c_ulong max_files; /// tunable
110 }
111 
112 struct inodes_stat_t
113 {
114     c_long nr_inodes;
115     c_long nr_unused;
116     c_long[5] dummy; /// padding for sysctl ABI compatibility
117 }
118 
119 enum NR_FILE = 8192;
120 
121 /**
122  * Structure for FS_IOC_FSGETXATTR[A] and FS_IOC_FSSETXATTR.
123  */
124 struct fsxattr
125 {
126     uint fsx_xflags;
127     uint fsx_extsize;
128     uint fsx_nextents;
129     uint fsx_projid; /// project identifier
130     uint fsx_cowextsize; /// CoW extsize
131     ubyte[8] fsx_pad;
132 }
133 
134 /*
135  * Flags for the fsx_xflags field
136  */
137 enum {
138     S_XFLAG_REALTIME = 0x00000001, /// data in realtime volume
139     S_XFLAG_PREALLOC = 0x00000002, /// preallocated file extents
140     S_XFLAG_IMMUTABLE = 0x00000008, /// file cannot be modified
141     S_XFLAG_APPEND = 0x00000010, /// all writes append
142     S_XFLAG_SYNC = 0x00000020, /// all writes synchronous
143     S_XFLAG_NOATIME = 0x00000040, /// do not update access time
144     S_XFLAG_NODUMP = 0x00000080, /// do not include in backups
145     S_XFLAG_RTINHERIT = 0x00000100, /// create with rt bit set
146     S_XFLAG_PROJINHERIT = 0x00000200, /// create with parents projid
147     S_XFLAG_NOSYMLINKS = 0x00000400, /// disallow symlink creation
148     S_XFLAG_EXTSIZE = 0x00000800, /// extent size allocator hint
149     S_XFLAG_EXTSZINHERIT = 0x00001000, /// inherit inode extent size
150     S_XFLAG_NODEFRAG = 0x00002000, /// do not defragment
151     S_XFLAG_FILESTREAM = 0x00004000, /// use filestream allocator
152     S_XFLAG_DAX = 0x00008000, /// use DAX for IO
153     S_XFLAG_COWEXTSIZE = 0x00010000, /// CoW extent size allocator hint
154     S_XFLAG_HASATTR = 0x80000000, /// no DIFLAG for this
155 }
156 
157 static if (__traits(compiles, _IO(1, 2)))
158 {
159     enum BLKROSET = _IO(0x12, 93); /// set device read-only
160     enum BLKROGET = _IO(0x12, 94); /// get read-only status
161     enum BLKRRPART = _IO(0x12, 95); /// re-read partition table
162     enum BLKGETSIZE = _IO(0x12, 96); /// return device size
163     enum BLKFLSBUF = _IO(0x12, 97); /// flush buffer cache
164     enum BLKRASET = _IO(0x12, 98); /// set read ahead for block device
165     enum BLKRAGET = _IO(0x12, 99); /// get current read ahead setting
166     enum BLKFRASET = _IO(0x12, 100); /// set filesystem
167     enum BLKFRAGET = _IO(0x12, 101); /// get filesystem
168     enum BLKSECTSET = _IO(0x12, 102); /// set max sectors per request
169     enum BLKSECTGET = _IO(0x12, 103); /// get max sectors per request
170     enum BLKSSZGET = _IO(0x12, 104); /// get block device sector size
171 
172 
173     enum BLKBSZGET = _IOR!size_t(0x12, 112);
174     enum BLKBSZSET = _IOW!size_t(0x12, 113);
175     enum BLKGETSIZE64 = _IOR!size_t(0x12, 114);
176     enum BLKTRACESTART = _IO(0x12, 116);
177     enum BLKTRACESTOP = _IO(0x12, 117);
178     enum BLKTRACETEARDOWN = _IO(0x12, 118);
179     enum BLKDISCARD = _IO(0x12, 119);
180     enum BLKIOMIN = _IO(0x12, 120);
181     enum BLKIOOPT = _IO(0x12, 121);
182     enum BLKALIGNOFF = _IO(0x12, 122);
183     enum BLKPBSZGET = _IO(0x12, 123);
184     enum BLKDISCARDZEROES = _IO(0x12, 124);
185     enum BLKSECDISCARD = _IO(0x12, 125);
186     enum BLKROTATIONAL = _IO(0x12, 126);
187     enum BLKZEROOUT = _IO(0x12, 127);
188 
189     enum BMAP_IOCTL = 1; /// obsolete - kept for compatibility
190     enum FIBMAP = _IO(0x00, 1); /// bmap access
191     enum FIGETBSZ = _IO(0x00, 2); /// get the block size used for bmap
192 }
193 
194 enum FSLABEL_MAX = 256; /// Max chars for the interface; each fs may differ
195 
196 /**
197  * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
198  *
199  * Note: for historical reasons, these flags were originally used and
200  * defined for use by ext2/ext3, and then other file systems started
201  * using these flags so they wouldn't need to write their own version
202  * of chattr/lsattr (which was shipped as part of e2fsprogs).  You
203  * should think twice before trying to use these flags in new
204  * contexts, or trying to assign these flags, since they are used both
205  * as the UAPI and the on-disk encoding for ext2/3/4.  Also, we are
206  * almost out of 32-bit flags.  :-)
207  *
208  * We have recently hoisted FS_IOC_FSGETXATTR / FS_IOC_FSSETXATTR from
209  * XFS to the generic FS level interface.  This uses a structure that
210  * has padding and hence has more room to grow, so it may be more
211  * appropriate for many new use cases.
212  */
213 enum {
214     FS_SECRM_FL = 0x00000001, /// Secure deletion
215     FS_UNRM_FL = 0x00000002, /// Undelete
216     FS_COMPR_FL = 0x00000004, /// Compress file
217     FS_SYNC_FL = 0x00000008, /// Synchronous updates
218     FS_IMMUTABLE_FL = 0x00000010, /// Immutable file
219     FS_APPEND_FL = 0x00000020, /// writes to file may only append
220     FS_NODUMP_FL = 0x00000040, /// do not dump file
221     FS_NOATIME_FL = 0x00000080, /// do not update atime
222     FS_DIRTY_FL = 0x00000100, /// Reserved for compression usage
223     FS_COMPRBLK_FL = 0x00000200, /// One or more compressed clusters
224     FS_NOCOMP_FL = 0x00000400, /// Don't compress
225     FS_ENCRYPT_FL = 0x00000800, /// Encrypted file
226     FS_BTREE_FL = 0x00001000, /// btree format dir
227     FS_INDEX_FL = 0x00001000, /// hash-indexed directory
228     FS_IMAGIC_FL = 0x00002000, /// AFS directory
229     FS_JOURNAL_DATA_FL = 0x00004000, /// Reserved for ext3
230     FS_NOTAIL_FL = 0x00008000, /// file tail should not be merged
231     FS_DIRSYNC_FL = 0x00010000, /// dirsync behaviour (directories only)
232     FS_TOPDIR_FL = 0x00020000, /// Top of directory hierarchie
233     FS_HUGE_FILE_FL = 0x00040000, /// Reserved for ext4
234     FS_EXTENT_FL = 0x00080000, /// Extents
235     FS_VERITY_FL = 0x00100000, /// Verity protected inode
236     FS_EA_INODE_FL = 0x00200000, /// Inode used for large EA
237     FS_EOFBLOCKS_FL = 0x00400000, /// Reserved for ext4
238     FS_NOCOW_FL = 0x00800000, /// Do not cow file
239     FS_DAX_FL = 0x02000000, /// Inode is DAX
240     FS_INLINE_DATA_FL = 0x10000000, /// Reserved for ext4
241     FS_PROJINHERIT_FL = 0x20000000, /// Create with parents projid
242     FS_CASEFOLD_FL = 0x40000000, /// Folder is case insensitive
243     FS_RESERVED_FL = 0x80000000, /// reserved for ext2 lib
244 }
245 
246 enum FS_FL_USER_VISIBLE = 0x0003DFFF; /// User visible flags
247 enum FS_FL_USER_MODIFIABLE = 0x000380FF; /// User modifiable flags
248 
249 enum SYNC_FILE_RANGE_WAIT_BEFORE = 1;
250 enum SYNC_FILE_RANGE_WRITE = 2;
251 enum SYNC_FILE_RANGE_WAIT_AFTER = 4;
252 enum SYNC_FILE_RANGE_WRITE_AND_WAIT = SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WAIT_AFTER;
253 
254 alias __kernel_rwf_t = int;
255 
256 /**
257  * Flags for preadv2/pwritev2:
258  */
259 enum : __kernel_rwf_t {
260     RWF_HIPRI = 0x00000001, /// high priority request, poll if possible
261     RWF_DSYNC = 0x00000002, /// per-IO O_DSYNC
262     RWF_SYNC = 0x00000004, /// per-IO O_SYNC
263     RWF_NOWAIT = 0x00000008, /// per-IO, return -EAGAIN if operation would block
264     RWF_APPEND = 0x00000010, /// per-IO O_APPEND
265 }
266 
267 /// mask of flags supported by the kernel
268 enum RWF_SUPPORTED = RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT | RWF_APPEND;
269