xref: /linux/fs/xfs/libxfs/xfs_fs.h (revision 26fbb4c8c7c3ee9a4c3b4de555a8587b5a19154e)
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  * Copyright (c) 1995-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_FS_H__
7 #define __XFS_FS_H__
8 
9 /*
10  * SGI's XFS filesystem's major stuff (constants, structures)
11  */
12 
13 /*
14  * Direct I/O attribute record used with XFS_IOC_DIOINFO
15  * d_miniosz is the min xfer size, xfer size multiple and file seek offset
16  * alignment.
17  */
18 #ifndef HAVE_DIOATTR
19 struct dioattr {
20 	__u32		d_mem;		/* data buffer memory alignment */
21 	__u32		d_miniosz;	/* min xfer size		*/
22 	__u32		d_maxiosz;	/* max xfer size		*/
23 };
24 #endif
25 
26 /*
27  * Structure for XFS_IOC_GETBMAP.
28  * On input, fill in bmv_offset and bmv_length of the first structure
29  * to indicate the area of interest in the file, and bmv_entries with
30  * the number of array elements given back.  The first structure is
31  * updated on return to give the offset and length for the next call.
32  */
33 #ifndef HAVE_GETBMAP
34 struct getbmap {
35 	__s64		bmv_offset;	/* file offset of segment in blocks */
36 	__s64		bmv_block;	/* starting block (64-bit daddr_t)  */
37 	__s64		bmv_length;	/* length of segment, blocks	    */
38 	__s32		bmv_count;	/* # of entries in array incl. 1st  */
39 	__s32		bmv_entries;	/* # of entries filled in (output)  */
40 };
41 #endif
42 
43 /*
44  *	Structure for XFS_IOC_GETBMAPX.	 Fields bmv_offset through bmv_entries
45  *	are used exactly as in the getbmap structure.  The getbmapx structure
46  *	has additional bmv_iflags and bmv_oflags fields. The bmv_iflags field
47  *	is only used for the first structure.  It contains input flags
48  *	specifying XFS_IOC_GETBMAPX actions.  The bmv_oflags field is filled
49  *	in by the XFS_IOC_GETBMAPX command for each returned structure after
50  *	the first.
51  */
52 #ifndef HAVE_GETBMAPX
53 struct getbmapx {
54 	__s64		bmv_offset;	/* file offset of segment in blocks */
55 	__s64		bmv_block;	/* starting block (64-bit daddr_t)  */
56 	__s64		bmv_length;	/* length of segment, blocks	    */
57 	__s32		bmv_count;	/* # of entries in array incl. 1st  */
58 	__s32		bmv_entries;	/* # of entries filled in (output). */
59 	__s32		bmv_iflags;	/* input flags (1st structure)	    */
60 	__s32		bmv_oflags;	/* output flags (after 1st structure)*/
61 	__s32		bmv_unused1;	/* future use			    */
62 	__s32		bmv_unused2;	/* future use			    */
63 };
64 #endif
65 
66 /*	bmv_iflags values - set by XFS_IOC_GETBMAPX caller.	*/
67 #define BMV_IF_ATTRFORK		0x1	/* return attr fork rather than data */
68 #define BMV_IF_NO_DMAPI_READ	0x2	/* Do not generate DMAPI read event  */
69 #define BMV_IF_PREALLOC		0x4	/* rtn status BMV_OF_PREALLOC if req */
70 #define BMV_IF_DELALLOC		0x8	/* rtn status BMV_OF_DELALLOC if req */
71 #define BMV_IF_NO_HOLES		0x10	/* Do not return holes */
72 #define BMV_IF_COWFORK		0x20	/* return CoW fork rather than data */
73 #define BMV_IF_VALID	\
74 	(BMV_IF_ATTRFORK|BMV_IF_NO_DMAPI_READ|BMV_IF_PREALLOC|	\
75 	 BMV_IF_DELALLOC|BMV_IF_NO_HOLES|BMV_IF_COWFORK)
76 
77 /*	bmv_oflags values - returned for each non-header segment */
78 #define BMV_OF_PREALLOC		0x1	/* segment = unwritten pre-allocation */
79 #define BMV_OF_DELALLOC		0x2	/* segment = delayed allocation */
80 #define BMV_OF_LAST		0x4	/* segment is the last in the file */
81 #define BMV_OF_SHARED		0x8	/* segment shared with another file */
82 
83 /*	fmr_owner special values for FS_IOC_GETFSMAP */
84 #define XFS_FMR_OWN_FREE	FMR_OWN_FREE      /* free space */
85 #define XFS_FMR_OWN_UNKNOWN	FMR_OWN_UNKNOWN   /* unknown owner */
86 #define XFS_FMR_OWN_FS		FMR_OWNER('X', 1) /* static fs metadata */
87 #define XFS_FMR_OWN_LOG		FMR_OWNER('X', 2) /* journalling log */
88 #define XFS_FMR_OWN_AG		FMR_OWNER('X', 3) /* per-AG metadata */
89 #define XFS_FMR_OWN_INOBT	FMR_OWNER('X', 4) /* inode btree blocks */
90 #define XFS_FMR_OWN_INODES	FMR_OWNER('X', 5) /* inodes */
91 #define XFS_FMR_OWN_REFC	FMR_OWNER('X', 6) /* refcount tree */
92 #define XFS_FMR_OWN_COW		FMR_OWNER('X', 7) /* cow staging */
93 #define XFS_FMR_OWN_DEFECTIVE	FMR_OWNER('X', 8) /* bad blocks */
94 
95 /*
96  * Structure for XFS_IOC_FSSETDM.
97  * For use by backup and restore programs to set the XFS on-disk inode
98  * fields di_dmevmask and di_dmstate.  These must be set to exactly and
99  * only values previously obtained via xfs_bulkstat!  (Specifically the
100  * struct xfs_bstat fields bs_dmevmask and bs_dmstate.)
101  */
102 #ifndef HAVE_FSDMIDATA
103 struct fsdmidata {
104 	__u32		fsd_dmevmask;	/* corresponds to di_dmevmask */
105 	__u16		fsd_padding;
106 	__u16		fsd_dmstate;	/* corresponds to di_dmstate  */
107 };
108 #endif
109 
110 /*
111  * File segment locking set data type for 64 bit access.
112  * Also used for all the RESV/FREE interfaces.
113  */
114 typedef struct xfs_flock64 {
115 	__s16		l_type;
116 	__s16		l_whence;
117 	__s64		l_start;
118 	__s64		l_len;		/* len == 0 means until end of file */
119 	__s32		l_sysid;
120 	__u32		l_pid;
121 	__s32		l_pad[4];	/* reserve area			    */
122 } xfs_flock64_t;
123 
124 /*
125  * Output for XFS_IOC_FSGEOMETRY_V1
126  */
127 struct xfs_fsop_geom_v1 {
128 	__u32		blocksize;	/* filesystem (data) block size */
129 	__u32		rtextsize;	/* realtime extent size		*/
130 	__u32		agblocks;	/* fsblocks in an AG		*/
131 	__u32		agcount;	/* number of allocation groups	*/
132 	__u32		logblocks;	/* fsblocks in the log		*/
133 	__u32		sectsize;	/* (data) sector size, bytes	*/
134 	__u32		inodesize;	/* inode size in bytes		*/
135 	__u32		imaxpct;	/* max allowed inode space(%)	*/
136 	__u64		datablocks;	/* fsblocks in data subvolume	*/
137 	__u64		rtblocks;	/* fsblocks in realtime subvol	*/
138 	__u64		rtextents;	/* rt extents in realtime subvol*/
139 	__u64		logstart;	/* starting fsblock of the log	*/
140 	unsigned char	uuid[16];	/* unique id of the filesystem	*/
141 	__u32		sunit;		/* stripe unit, fsblocks	*/
142 	__u32		swidth;		/* stripe width, fsblocks	*/
143 	__s32		version;	/* structure version		*/
144 	__u32		flags;		/* superblock version flags	*/
145 	__u32		logsectsize;	/* log sector size, bytes	*/
146 	__u32		rtsectsize;	/* realtime sector size, bytes	*/
147 	__u32		dirblocksize;	/* directory block size, bytes	*/
148 };
149 
150 /*
151  * Output for XFS_IOC_FSGEOMETRY_V4
152  */
153 struct xfs_fsop_geom_v4 {
154 	__u32		blocksize;	/* filesystem (data) block size */
155 	__u32		rtextsize;	/* realtime extent size		*/
156 	__u32		agblocks;	/* fsblocks in an AG		*/
157 	__u32		agcount;	/* number of allocation groups	*/
158 	__u32		logblocks;	/* fsblocks in the log		*/
159 	__u32		sectsize;	/* (data) sector size, bytes	*/
160 	__u32		inodesize;	/* inode size in bytes		*/
161 	__u32		imaxpct;	/* max allowed inode space(%)	*/
162 	__u64		datablocks;	/* fsblocks in data subvolume	*/
163 	__u64		rtblocks;	/* fsblocks in realtime subvol	*/
164 	__u64		rtextents;	/* rt extents in realtime subvol*/
165 	__u64		logstart;	/* starting fsblock of the log	*/
166 	unsigned char	uuid[16];	/* unique id of the filesystem	*/
167 	__u32		sunit;		/* stripe unit, fsblocks	*/
168 	__u32		swidth;		/* stripe width, fsblocks	*/
169 	__s32		version;	/* structure version		*/
170 	__u32		flags;		/* superblock version flags	*/
171 	__u32		logsectsize;	/* log sector size, bytes	*/
172 	__u32		rtsectsize;	/* realtime sector size, bytes	*/
173 	__u32		dirblocksize;	/* directory block size, bytes	*/
174 	__u32		logsunit;	/* log stripe unit, bytes	*/
175 };
176 
177 /*
178  * Output for XFS_IOC_FSGEOMETRY
179  */
180 struct xfs_fsop_geom {
181 	__u32		blocksize;	/* filesystem (data) block size */
182 	__u32		rtextsize;	/* realtime extent size		*/
183 	__u32		agblocks;	/* fsblocks in an AG		*/
184 	__u32		agcount;	/* number of allocation groups	*/
185 	__u32		logblocks;	/* fsblocks in the log		*/
186 	__u32		sectsize;	/* (data) sector size, bytes	*/
187 	__u32		inodesize;	/* inode size in bytes		*/
188 	__u32		imaxpct;	/* max allowed inode space(%)	*/
189 	__u64		datablocks;	/* fsblocks in data subvolume	*/
190 	__u64		rtblocks;	/* fsblocks in realtime subvol	*/
191 	__u64		rtextents;	/* rt extents in realtime subvol*/
192 	__u64		logstart;	/* starting fsblock of the log	*/
193 	unsigned char	uuid[16];	/* unique id of the filesystem	*/
194 	__u32		sunit;		/* stripe unit, fsblocks	*/
195 	__u32		swidth;		/* stripe width, fsblocks	*/
196 	__s32		version;	/* structure version		*/
197 	__u32		flags;		/* superblock version flags	*/
198 	__u32		logsectsize;	/* log sector size, bytes	*/
199 	__u32		rtsectsize;	/* realtime sector size, bytes	*/
200 	__u32		dirblocksize;	/* directory block size, bytes	*/
201 	__u32		logsunit;	/* log stripe unit, bytes	*/
202 	uint32_t	sick;		/* o: unhealthy fs & rt metadata */
203 	uint32_t	checked;	/* o: checked fs & rt metadata	*/
204 	__u64		reserved[17];	/* reserved space		*/
205 };
206 
207 #define XFS_FSOP_GEOM_SICK_COUNTERS	(1 << 0)  /* summary counters */
208 #define XFS_FSOP_GEOM_SICK_UQUOTA	(1 << 1)  /* user quota */
209 #define XFS_FSOP_GEOM_SICK_GQUOTA	(1 << 2)  /* group quota */
210 #define XFS_FSOP_GEOM_SICK_PQUOTA	(1 << 3)  /* project quota */
211 #define XFS_FSOP_GEOM_SICK_RT_BITMAP	(1 << 4)  /* realtime bitmap */
212 #define XFS_FSOP_GEOM_SICK_RT_SUMMARY	(1 << 5)  /* realtime summary */
213 
214 /* Output for XFS_FS_COUNTS */
215 typedef struct xfs_fsop_counts {
216 	__u64	freedata;	/* free data section blocks */
217 	__u64	freertx;	/* free rt extents */
218 	__u64	freeino;	/* free inodes */
219 	__u64	allocino;	/* total allocated inodes */
220 } xfs_fsop_counts_t;
221 
222 /* Input/Output for XFS_GET_RESBLKS and XFS_SET_RESBLKS */
223 typedef struct xfs_fsop_resblks {
224 	__u64  resblks;
225 	__u64  resblks_avail;
226 } xfs_fsop_resblks_t;
227 
228 #define XFS_FSOP_GEOM_VERSION		0
229 #define XFS_FSOP_GEOM_VERSION_V5	5
230 
231 #define XFS_FSOP_GEOM_FLAGS_ATTR	(1 << 0)  /* attributes in use	   */
232 #define XFS_FSOP_GEOM_FLAGS_NLINK	(1 << 1)  /* 32-bit nlink values   */
233 #define XFS_FSOP_GEOM_FLAGS_QUOTA	(1 << 2)  /* quotas enabled	   */
234 #define XFS_FSOP_GEOM_FLAGS_IALIGN	(1 << 3)  /* inode alignment	   */
235 #define XFS_FSOP_GEOM_FLAGS_DALIGN	(1 << 4)  /* large data alignment  */
236 #define XFS_FSOP_GEOM_FLAGS_SHARED	(1 << 5)  /* read-only shared	   */
237 #define XFS_FSOP_GEOM_FLAGS_EXTFLG	(1 << 6)  /* special extent flag   */
238 #define XFS_FSOP_GEOM_FLAGS_DIRV2	(1 << 7)  /* directory version 2   */
239 #define XFS_FSOP_GEOM_FLAGS_LOGV2	(1 << 8)  /* log format version 2  */
240 #define XFS_FSOP_GEOM_FLAGS_SECTOR	(1 << 9)  /* sector sizes >1BB	   */
241 #define XFS_FSOP_GEOM_FLAGS_ATTR2	(1 << 10) /* inline attributes rework */
242 #define XFS_FSOP_GEOM_FLAGS_PROJID32	(1 << 11) /* 32-bit project IDs	   */
243 #define XFS_FSOP_GEOM_FLAGS_DIRV2CI	(1 << 12) /* ASCII only CI names   */
244 	/*  -- Do not use --		(1 << 13)    SGI parent pointers   */
245 #define XFS_FSOP_GEOM_FLAGS_LAZYSB	(1 << 14) /* lazy superblock counters */
246 #define XFS_FSOP_GEOM_FLAGS_V5SB	(1 << 15) /* version 5 superblock  */
247 #define XFS_FSOP_GEOM_FLAGS_FTYPE	(1 << 16) /* inode directory types */
248 #define XFS_FSOP_GEOM_FLAGS_FINOBT	(1 << 17) /* free inode btree	   */
249 #define XFS_FSOP_GEOM_FLAGS_SPINODES	(1 << 18) /* sparse inode chunks   */
250 #define XFS_FSOP_GEOM_FLAGS_RMAPBT	(1 << 19) /* reverse mapping btree */
251 #define XFS_FSOP_GEOM_FLAGS_REFLINK	(1 << 20) /* files can share blocks */
252 #define XFS_FSOP_GEOM_FLAGS_BIGTIME	(1 << 21) /* 64-bit nsec timestamps */
253 
254 /*
255  * Minimum and maximum sizes need for growth checks.
256  *
257  * Block counts are in units of filesystem blocks, not basic blocks.
258  */
259 #define XFS_MIN_AG_BLOCKS	64
260 #define XFS_MIN_LOG_BLOCKS	512ULL
261 #define XFS_MAX_LOG_BLOCKS	(1024 * 1024ULL)
262 #define XFS_MIN_LOG_BYTES	(10 * 1024 * 1024ULL)
263 
264 /*
265  * Limits on sb_agblocks/sb_agblklog -- mkfs won't format AGs smaller than
266  * 16MB or larger than 1TB.
267  */
268 #define XFS_MIN_AG_BYTES	(1ULL << 24)	/* 16 MB */
269 #define XFS_MAX_AG_BYTES	(1ULL << 40)	/* 1 TB */
270 
271 /* keep the maximum size under 2^31 by a small amount */
272 #define XFS_MAX_LOG_BYTES \
273 	((2 * 1024 * 1024 * 1024ULL) - XFS_MIN_LOG_BYTES)
274 
275 /* Used for sanity checks on superblock */
276 #define XFS_MAX_DBLOCKS(s) ((xfs_rfsblock_t)(s)->sb_agcount * (s)->sb_agblocks)
277 #define XFS_MIN_DBLOCKS(s) ((xfs_rfsblock_t)((s)->sb_agcount - 1) *	\
278 			 (s)->sb_agblocks + XFS_MIN_AG_BLOCKS)
279 
280 /*
281  * Output for XFS_IOC_AG_GEOMETRY
282  */
283 struct xfs_ag_geometry {
284 	uint32_t	ag_number;	/* i/o: AG number */
285 	uint32_t	ag_length;	/* o: length in blocks */
286 	uint32_t	ag_freeblks;	/* o: free space */
287 	uint32_t	ag_icount;	/* o: inodes allocated */
288 	uint32_t	ag_ifree;	/* o: inodes free */
289 	uint32_t	ag_sick;	/* o: sick things in ag */
290 	uint32_t	ag_checked;	/* o: checked metadata in ag */
291 	uint32_t	ag_flags;	/* i/o: flags for this ag */
292 	uint64_t	ag_reserved[12];/* o: zero */
293 };
294 #define XFS_AG_GEOM_SICK_SB	(1 << 0)  /* superblock */
295 #define XFS_AG_GEOM_SICK_AGF	(1 << 1)  /* AGF header */
296 #define XFS_AG_GEOM_SICK_AGFL	(1 << 2)  /* AGFL header */
297 #define XFS_AG_GEOM_SICK_AGI	(1 << 3)  /* AGI header */
298 #define XFS_AG_GEOM_SICK_BNOBT	(1 << 4)  /* free space by block */
299 #define XFS_AG_GEOM_SICK_CNTBT	(1 << 5)  /* free space by length */
300 #define XFS_AG_GEOM_SICK_INOBT	(1 << 6)  /* inode index */
301 #define XFS_AG_GEOM_SICK_FINOBT	(1 << 7)  /* free inode index */
302 #define XFS_AG_GEOM_SICK_RMAPBT	(1 << 8)  /* reverse mappings */
303 #define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9)  /* reference counts */
304 
305 /*
306  * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT
307  */
308 typedef struct xfs_growfs_data {
309 	__u64		newblocks;	/* new data subvol size, fsblocks */
310 	__u32		imaxpct;	/* new inode space percentage limit */
311 } xfs_growfs_data_t;
312 
313 typedef struct xfs_growfs_log {
314 	__u32		newblocks;	/* new log size, fsblocks */
315 	__u32		isint;		/* 1 if new log is internal */
316 } xfs_growfs_log_t;
317 
318 typedef struct xfs_growfs_rt {
319 	__u64		newblocks;	/* new realtime size, fsblocks */
320 	__u32		extsize;	/* new realtime extent size, fsblocks */
321 } xfs_growfs_rt_t;
322 
323 
324 /*
325  * Structures returned from ioctl XFS_IOC_FSBULKSTAT & XFS_IOC_FSBULKSTAT_SINGLE
326  */
327 typedef struct xfs_bstime {
328 	__kernel_long_t tv_sec;		/* seconds		*/
329 	__s32		tv_nsec;	/* and nanoseconds	*/
330 } xfs_bstime_t;
331 
332 struct xfs_bstat {
333 	__u64		bs_ino;		/* inode number			*/
334 	__u16		bs_mode;	/* type and mode		*/
335 	__u16		bs_nlink;	/* number of links		*/
336 	__u32		bs_uid;		/* user id			*/
337 	__u32		bs_gid;		/* group id			*/
338 	__u32		bs_rdev;	/* device value			*/
339 	__s32		bs_blksize;	/* block size			*/
340 	__s64		bs_size;	/* file size			*/
341 	xfs_bstime_t	bs_atime;	/* access time			*/
342 	xfs_bstime_t	bs_mtime;	/* modify time			*/
343 	xfs_bstime_t	bs_ctime;	/* inode change time		*/
344 	int64_t		bs_blocks;	/* number of blocks		*/
345 	__u32		bs_xflags;	/* extended flags		*/
346 	__s32		bs_extsize;	/* extent size			*/
347 	__s32		bs_extents;	/* number of extents		*/
348 	__u32		bs_gen;		/* generation count		*/
349 	__u16		bs_projid_lo;	/* lower part of project id	*/
350 #define	bs_projid	bs_projid_lo	/* (previously just bs_projid)	*/
351 	__u16		bs_forkoff;	/* inode fork offset in bytes	*/
352 	__u16		bs_projid_hi;	/* higher part of project id	*/
353 	uint16_t	bs_sick;	/* sick inode metadata		*/
354 	uint16_t	bs_checked;	/* checked inode metadata	*/
355 	unsigned char	bs_pad[2];	/* pad space, unused		*/
356 	__u32		bs_cowextsize;	/* cow extent size		*/
357 	__u32		bs_dmevmask;	/* DMIG event mask		*/
358 	__u16		bs_dmstate;	/* DMIG state info		*/
359 	__u16		bs_aextents;	/* attribute number of extents	*/
360 };
361 
362 /* New bulkstat structure that reports v5 features and fixes padding issues */
363 struct xfs_bulkstat {
364 	uint64_t	bs_ino;		/* inode number			*/
365 	uint64_t	bs_size;	/* file size			*/
366 
367 	uint64_t	bs_blocks;	/* number of blocks		*/
368 	uint64_t	bs_xflags;	/* extended flags		*/
369 
370 	int64_t		bs_atime;	/* access time, seconds		*/
371 	int64_t		bs_mtime;	/* modify time, seconds		*/
372 
373 	int64_t		bs_ctime;	/* inode change time, seconds	*/
374 	int64_t		bs_btime;	/* creation time, seconds	*/
375 
376 	uint32_t	bs_gen;		/* generation count		*/
377 	uint32_t	bs_uid;		/* user id			*/
378 	uint32_t	bs_gid;		/* group id			*/
379 	uint32_t	bs_projectid;	/* project id			*/
380 
381 	uint32_t	bs_atime_nsec;	/* access time, nanoseconds	*/
382 	uint32_t	bs_mtime_nsec;	/* modify time, nanoseconds	*/
383 	uint32_t	bs_ctime_nsec;	/* inode change time, nanoseconds */
384 	uint32_t	bs_btime_nsec;	/* creation time, nanoseconds	*/
385 
386 	uint32_t	bs_blksize;	/* block size			*/
387 	uint32_t	bs_rdev;	/* device value			*/
388 	uint32_t	bs_cowextsize_blks; /* cow extent size hint, blocks */
389 	uint32_t	bs_extsize_blks; /* extent size hint, blocks	*/
390 
391 	uint32_t	bs_nlink;	/* number of links		*/
392 	uint32_t	bs_extents;	/* number of extents		*/
393 	uint32_t	bs_aextents;	/* attribute number of extents	*/
394 	uint16_t	bs_version;	/* structure version		*/
395 	uint16_t	bs_forkoff;	/* inode fork offset in bytes	*/
396 
397 	uint16_t	bs_sick;	/* sick inode metadata		*/
398 	uint16_t	bs_checked;	/* checked inode metadata	*/
399 	uint16_t	bs_mode;	/* type and mode		*/
400 	uint16_t	bs_pad2;	/* zeroed			*/
401 
402 	uint64_t	bs_pad[7];	/* zeroed			*/
403 };
404 
405 #define XFS_BULKSTAT_VERSION_V1	(1)
406 #define XFS_BULKSTAT_VERSION_V5	(5)
407 
408 /* bs_sick flags */
409 #define XFS_BS_SICK_INODE	(1 << 0)  /* inode core */
410 #define XFS_BS_SICK_BMBTD	(1 << 1)  /* data fork */
411 #define XFS_BS_SICK_BMBTA	(1 << 2)  /* attr fork */
412 #define XFS_BS_SICK_BMBTC	(1 << 3)  /* cow fork */
413 #define XFS_BS_SICK_DIR		(1 << 4)  /* directory */
414 #define XFS_BS_SICK_XATTR	(1 << 5)  /* extended attributes */
415 #define XFS_BS_SICK_SYMLINK	(1 << 6)  /* symbolic link remote target */
416 #define XFS_BS_SICK_PARENT	(1 << 7)  /* parent pointers */
417 
418 /*
419  * Project quota id helpers (previously projid was 16bit only
420  * and using two 16bit values to hold new 32bit projid was chosen
421  * to retain compatibility with "old" filesystems).
422  */
423 static inline uint32_t
424 bstat_get_projid(const struct xfs_bstat *bs)
425 {
426 	return (uint32_t)bs->bs_projid_hi << 16 | bs->bs_projid_lo;
427 }
428 
429 /*
430  * The user-level BulkStat Request interface structure.
431  */
432 struct xfs_fsop_bulkreq {
433 	__u64		__user *lastip;	/* last inode # pointer		*/
434 	__s32		icount;		/* count of entries in buffer	*/
435 	void		__user *ubuffer;/* user buffer for inode desc.	*/
436 	__s32		__user *ocount;	/* output count pointer		*/
437 };
438 
439 /*
440  * Structures returned from xfs_inumbers routine (XFS_IOC_FSINUMBERS).
441  */
442 struct xfs_inogrp {
443 	__u64		xi_startino;	/* starting inode number	*/
444 	__s32		xi_alloccount;	/* # bits set in allocmask	*/
445 	__u64		xi_allocmask;	/* mask of allocated inodes	*/
446 };
447 
448 /* New inumbers structure that reports v5 features and fixes padding issues */
449 struct xfs_inumbers {
450 	uint64_t	xi_startino;	/* starting inode number	*/
451 	uint64_t	xi_allocmask;	/* mask of allocated inodes	*/
452 	uint8_t		xi_alloccount;	/* # bits set in allocmask	*/
453 	uint8_t		xi_version;	/* version			*/
454 	uint8_t		xi_padding[6];	/* zero				*/
455 };
456 
457 #define XFS_INUMBERS_VERSION_V1	(1)
458 #define XFS_INUMBERS_VERSION_V5	(5)
459 
460 /* Header for bulk inode requests. */
461 struct xfs_bulk_ireq {
462 	uint64_t	ino;		/* I/O: start with this inode	*/
463 	uint32_t	flags;		/* I/O: operation flags		*/
464 	uint32_t	icount;		/* I: count of entries in buffer */
465 	uint32_t	ocount;		/* O: count of entries filled out */
466 	uint32_t	agno;		/* I: see comment for IREQ_AGNO	*/
467 	uint64_t	reserved[5];	/* must be zero			*/
468 };
469 
470 /*
471  * Only return results from the specified @agno.  If @ino is zero, start
472  * with the first inode of @agno.
473  */
474 #define XFS_BULK_IREQ_AGNO	(1 << 0)
475 
476 /*
477  * Return bulkstat information for a single inode, where @ino value is a
478  * special value, not a literal inode number.  See the XFS_BULK_IREQ_SPECIAL_*
479  * values below.  Not compatible with XFS_BULK_IREQ_AGNO.
480  */
481 #define XFS_BULK_IREQ_SPECIAL	(1 << 1)
482 
483 #define XFS_BULK_IREQ_FLAGS_ALL	(XFS_BULK_IREQ_AGNO | \
484 				 XFS_BULK_IREQ_SPECIAL)
485 
486 /* Operate on the root directory inode. */
487 #define XFS_BULK_IREQ_SPECIAL_ROOT	(1)
488 
489 /*
490  * ioctl structures for v5 bulkstat and inumbers requests
491  */
492 struct xfs_bulkstat_req {
493 	struct xfs_bulk_ireq	hdr;
494 	struct xfs_bulkstat	bulkstat[];
495 };
496 #define XFS_BULKSTAT_REQ_SIZE(nr)	(sizeof(struct xfs_bulkstat_req) + \
497 					 (nr) * sizeof(struct xfs_bulkstat))
498 
499 struct xfs_inumbers_req {
500 	struct xfs_bulk_ireq	hdr;
501 	struct xfs_inumbers	inumbers[];
502 };
503 #define XFS_INUMBERS_REQ_SIZE(nr)	(sizeof(struct xfs_inumbers_req) + \
504 					 (nr) * sizeof(struct xfs_inumbers))
505 
506 /*
507  * Error injection.
508  */
509 typedef struct xfs_error_injection {
510 	__s32		fd;
511 	__s32		errtag;
512 } xfs_error_injection_t;
513 
514 
515 /*
516  * Speculative preallocation trimming.
517  */
518 #define XFS_EOFBLOCKS_VERSION		1
519 struct xfs_fs_eofblocks {
520 	__u32		eof_version;
521 	__u32		eof_flags;
522 	uid_t		eof_uid;
523 	gid_t		eof_gid;
524 	prid_t		eof_prid;
525 	__u32		pad32;
526 	__u64		eof_min_file_size;
527 	__u64		pad64[12];
528 };
529 
530 /* eof_flags values */
531 #define XFS_EOF_FLAGS_SYNC		(1 << 0) /* sync/wait mode scan */
532 #define XFS_EOF_FLAGS_UID		(1 << 1) /* filter by uid */
533 #define XFS_EOF_FLAGS_GID		(1 << 2) /* filter by gid */
534 #define XFS_EOF_FLAGS_PRID		(1 << 3) /* filter by project id */
535 #define XFS_EOF_FLAGS_MINFILESIZE	(1 << 4) /* filter by min file size */
536 #define XFS_EOF_FLAGS_UNION		(1 << 5) /* union filter algorithm;
537 						  * kernel only, not included in
538 						  * valid mask */
539 #define XFS_EOF_FLAGS_VALID	\
540 	(XFS_EOF_FLAGS_SYNC |	\
541 	 XFS_EOF_FLAGS_UID |	\
542 	 XFS_EOF_FLAGS_GID |	\
543 	 XFS_EOF_FLAGS_PRID |	\
544 	 XFS_EOF_FLAGS_MINFILESIZE)
545 
546 
547 /*
548  * The user-level Handle Request interface structure.
549  */
550 typedef struct xfs_fsop_handlereq {
551 	__u32		fd;		/* fd for FD_TO_HANDLE		*/
552 	void		__user *path;	/* user pathname		*/
553 	__u32		oflags;		/* open flags			*/
554 	void		__user *ihandle;/* user supplied handle		*/
555 	__u32		ihandlen;	/* user supplied length		*/
556 	void		__user *ohandle;/* user buffer for handle	*/
557 	__u32		__user *ohandlen;/* user buffer length		*/
558 } xfs_fsop_handlereq_t;
559 
560 /*
561  * Compound structures for passing args through Handle Request interfaces
562  * xfs_fssetdm_by_handle, xfs_attrlist_by_handle, xfs_attrmulti_by_handle
563  * - ioctls: XFS_IOC_FSSETDM_BY_HANDLE, XFS_IOC_ATTRLIST_BY_HANDLE, and
564  *	     XFS_IOC_ATTRMULTI_BY_HANDLE
565  */
566 
567 typedef struct xfs_fsop_setdm_handlereq {
568 	struct xfs_fsop_handlereq	hreq;	/* handle information	*/
569 	struct fsdmidata		__user *data;	/* DMAPI data	*/
570 } xfs_fsop_setdm_handlereq_t;
571 
572 /*
573  * Flags passed in xfs_attr_multiop.am_flags for the attr ioctl interface.
574  *
575  * NOTE: Must match the values declared in libattr without the XFS_IOC_ prefix.
576  */
577 #define XFS_IOC_ATTR_ROOT	0x0002	/* use attrs in root namespace */
578 #define XFS_IOC_ATTR_SECURE	0x0008	/* use attrs in security namespace */
579 #define XFS_IOC_ATTR_CREATE	0x0010	/* fail if attr already exists */
580 #define XFS_IOC_ATTR_REPLACE	0x0020	/* fail if attr does not exist */
581 
582 typedef struct xfs_attrlist_cursor {
583 	__u32		opaque[4];
584 } xfs_attrlist_cursor_t;
585 
586 /*
587  * Define how lists of attribute names are returned to userspace from the
588  * XFS_IOC_ATTRLIST_BY_HANDLE ioctl.  struct xfs_attrlist is the header at the
589  * beginning of the returned buffer, and a each entry in al_offset contains the
590  * relative offset of an xfs_attrlist_ent containing the actual entry.
591  *
592  * NOTE: struct xfs_attrlist must match struct attrlist defined in libattr, and
593  * struct xfs_attrlist_ent must match struct attrlist_ent defined in libattr.
594  */
595 struct xfs_attrlist {
596 	__s32	al_count;	/* number of entries in attrlist */
597 	__s32	al_more;	/* T/F: more attrs (do call again) */
598 	__s32	al_offset[1];	/* byte offsets of attrs [var-sized] */
599 };
600 
601 struct xfs_attrlist_ent {	/* data from attr_list() */
602 	__u32	a_valuelen;	/* number bytes in value of attr */
603 	char	a_name[1];	/* attr name (NULL terminated) */
604 };
605 
606 typedef struct xfs_fsop_attrlist_handlereq {
607 	struct xfs_fsop_handlereq	hreq; /* handle interface structure */
608 	struct xfs_attrlist_cursor	pos; /* opaque cookie, list offset */
609 	__u32				flags;	/* which namespace to use */
610 	__u32				buflen;	/* length of buffer supplied */
611 	void				__user *buffer;	/* returned names */
612 } xfs_fsop_attrlist_handlereq_t;
613 
614 typedef struct xfs_attr_multiop {
615 	__u32		am_opcode;
616 #define ATTR_OP_GET	1	/* return the indicated attr's value */
617 #define ATTR_OP_SET	2	/* set/create the indicated attr/value pair */
618 #define ATTR_OP_REMOVE	3	/* remove the indicated attr */
619 	__s32		am_error;
620 	void		__user *am_attrname;
621 	void		__user *am_attrvalue;
622 	__u32		am_length;
623 	__u32		am_flags; /* XFS_IOC_ATTR_* */
624 } xfs_attr_multiop_t;
625 
626 typedef struct xfs_fsop_attrmulti_handlereq {
627 	struct xfs_fsop_handlereq	hreq; /* handle interface structure */
628 	__u32				opcount;/* count of following multiop */
629 	struct xfs_attr_multiop		__user *ops; /* attr_multi data */
630 } xfs_fsop_attrmulti_handlereq_t;
631 
632 /*
633  * per machine unique filesystem identifier types.
634  */
635 typedef struct { __u32 val[2]; } xfs_fsid_t; /* file system id type */
636 
637 typedef struct xfs_fid {
638 	__u16	fid_len;		/* length of remainder	*/
639 	__u16	fid_pad;
640 	__u32	fid_gen;		/* generation number	*/
641 	__u64	fid_ino;		/* 64 bits inode number */
642 } xfs_fid_t;
643 
644 typedef struct xfs_handle {
645 	union {
646 		__s64	    align;	/* force alignment of ha_fid	 */
647 		xfs_fsid_t  _ha_fsid;	/* unique file system identifier */
648 	} ha_u;
649 	xfs_fid_t	ha_fid;		/* file system specific file ID	 */
650 } xfs_handle_t;
651 #define ha_fsid ha_u._ha_fsid
652 
653 /*
654  * Structure passed to XFS_IOC_SWAPEXT
655  */
656 typedef struct xfs_swapext
657 {
658 	int64_t		sx_version;	/* version */
659 #define XFS_SX_VERSION		0
660 	int64_t		sx_fdtarget;	/* fd of target file */
661 	int64_t		sx_fdtmp;	/* fd of tmp file */
662 	xfs_off_t	sx_offset;	/* offset into file */
663 	xfs_off_t	sx_length;	/* leng from offset */
664 	char		sx_pad[16];	/* pad space, unused */
665 	struct xfs_bstat sx_stat;	/* stat of target b4 copy */
666 } xfs_swapext_t;
667 
668 /*
669  * Flags for going down operation
670  */
671 #define XFS_FSOP_GOING_FLAGS_DEFAULT		0x0	/* going down */
672 #define XFS_FSOP_GOING_FLAGS_LOGFLUSH		0x1	/* flush log but not data */
673 #define XFS_FSOP_GOING_FLAGS_NOLOGFLUSH		0x2	/* don't flush log nor data */
674 
675 /* metadata scrubbing */
676 struct xfs_scrub_metadata {
677 	__u32 sm_type;		/* What to check? */
678 	__u32 sm_flags;		/* flags; see below. */
679 	__u64 sm_ino;		/* inode number. */
680 	__u32 sm_gen;		/* inode generation. */
681 	__u32 sm_agno;		/* ag number. */
682 	__u64 sm_reserved[5];	/* pad to 64 bytes */
683 };
684 
685 /*
686  * Metadata types and flags for scrub operation.
687  */
688 
689 /* Scrub subcommands. */
690 #define XFS_SCRUB_TYPE_PROBE	0	/* presence test ioctl */
691 #define XFS_SCRUB_TYPE_SB	1	/* superblock */
692 #define XFS_SCRUB_TYPE_AGF	2	/* AG free header */
693 #define XFS_SCRUB_TYPE_AGFL	3	/* AG free list */
694 #define XFS_SCRUB_TYPE_AGI	4	/* AG inode header */
695 #define XFS_SCRUB_TYPE_BNOBT	5	/* freesp by block btree */
696 #define XFS_SCRUB_TYPE_CNTBT	6	/* freesp by length btree */
697 #define XFS_SCRUB_TYPE_INOBT	7	/* inode btree */
698 #define XFS_SCRUB_TYPE_FINOBT	8	/* free inode btree */
699 #define XFS_SCRUB_TYPE_RMAPBT	9	/* reverse mapping btree */
700 #define XFS_SCRUB_TYPE_REFCNTBT	10	/* reference count btree */
701 #define XFS_SCRUB_TYPE_INODE	11	/* inode record */
702 #define XFS_SCRUB_TYPE_BMBTD	12	/* data fork block mapping */
703 #define XFS_SCRUB_TYPE_BMBTA	13	/* attr fork block mapping */
704 #define XFS_SCRUB_TYPE_BMBTC	14	/* CoW fork block mapping */
705 #define XFS_SCRUB_TYPE_DIR	15	/* directory */
706 #define XFS_SCRUB_TYPE_XATTR	16	/* extended attribute */
707 #define XFS_SCRUB_TYPE_SYMLINK	17	/* symbolic link */
708 #define XFS_SCRUB_TYPE_PARENT	18	/* parent pointers */
709 #define XFS_SCRUB_TYPE_RTBITMAP	19	/* realtime bitmap */
710 #define XFS_SCRUB_TYPE_RTSUM	20	/* realtime summary */
711 #define XFS_SCRUB_TYPE_UQUOTA	21	/* user quotas */
712 #define XFS_SCRUB_TYPE_GQUOTA	22	/* group quotas */
713 #define XFS_SCRUB_TYPE_PQUOTA	23	/* project quotas */
714 #define XFS_SCRUB_TYPE_FSCOUNTERS 24	/* fs summary counters */
715 
716 /* Number of scrub subcommands. */
717 #define XFS_SCRUB_TYPE_NR	25
718 
719 /* i: Repair this metadata. */
720 #define XFS_SCRUB_IFLAG_REPAIR		(1 << 0)
721 
722 /* o: Metadata object needs repair. */
723 #define XFS_SCRUB_OFLAG_CORRUPT		(1 << 1)
724 
725 /*
726  * o: Metadata object could be optimized.  It's not corrupt, but
727  *    we could improve on it somehow.
728  */
729 #define XFS_SCRUB_OFLAG_PREEN		(1 << 2)
730 
731 /* o: Cross-referencing failed. */
732 #define XFS_SCRUB_OFLAG_XFAIL		(1 << 3)
733 
734 /* o: Metadata object disagrees with cross-referenced metadata. */
735 #define XFS_SCRUB_OFLAG_XCORRUPT	(1 << 4)
736 
737 /* o: Scan was not complete. */
738 #define XFS_SCRUB_OFLAG_INCOMPLETE	(1 << 5)
739 
740 /* o: Metadata object looked funny but isn't corrupt. */
741 #define XFS_SCRUB_OFLAG_WARNING		(1 << 6)
742 
743 /*
744  * o: IFLAG_REPAIR was set but metadata object did not need fixing or
745  *    optimization and has therefore not been altered.
746  */
747 #define XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED (1 << 7)
748 
749 #define XFS_SCRUB_FLAGS_IN	(XFS_SCRUB_IFLAG_REPAIR)
750 #define XFS_SCRUB_FLAGS_OUT	(XFS_SCRUB_OFLAG_CORRUPT | \
751 				 XFS_SCRUB_OFLAG_PREEN | \
752 				 XFS_SCRUB_OFLAG_XFAIL | \
753 				 XFS_SCRUB_OFLAG_XCORRUPT | \
754 				 XFS_SCRUB_OFLAG_INCOMPLETE | \
755 				 XFS_SCRUB_OFLAG_WARNING | \
756 				 XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED)
757 #define XFS_SCRUB_FLAGS_ALL	(XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT)
758 
759 /*
760  * ioctl limits
761  */
762 #ifdef XATTR_LIST_MAX
763 #  define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
764 #else
765 #  define XFS_XATTR_LIST_MAX 65536
766 #endif
767 
768 
769 /*
770  * ioctl commands that are used by Linux filesystems
771  */
772 #define XFS_IOC_GETXFLAGS	FS_IOC_GETFLAGS
773 #define XFS_IOC_SETXFLAGS	FS_IOC_SETFLAGS
774 #define XFS_IOC_GETVERSION	FS_IOC_GETVERSION
775 
776 /*
777  * ioctl commands that replace IRIX fcntl()'s
778  * For 'documentation' purposed more than anything else,
779  * the "cmd #" field reflects the IRIX fcntl number.
780  */
781 #define XFS_IOC_ALLOCSP		_IOW ('X', 10, struct xfs_flock64)
782 #define XFS_IOC_FREESP		_IOW ('X', 11, struct xfs_flock64)
783 #define XFS_IOC_DIOINFO		_IOR ('X', 30, struct dioattr)
784 #define XFS_IOC_FSGETXATTR	FS_IOC_FSGETXATTR
785 #define XFS_IOC_FSSETXATTR	FS_IOC_FSSETXATTR
786 #define XFS_IOC_ALLOCSP64	_IOW ('X', 36, struct xfs_flock64)
787 #define XFS_IOC_FREESP64	_IOW ('X', 37, struct xfs_flock64)
788 #define XFS_IOC_GETBMAP		_IOWR('X', 38, struct getbmap)
789 #define XFS_IOC_FSSETDM		_IOW ('X', 39, struct fsdmidata)
790 #define XFS_IOC_RESVSP		_IOW ('X', 40, struct xfs_flock64)
791 #define XFS_IOC_UNRESVSP	_IOW ('X', 41, struct xfs_flock64)
792 #define XFS_IOC_RESVSP64	_IOW ('X', 42, struct xfs_flock64)
793 #define XFS_IOC_UNRESVSP64	_IOW ('X', 43, struct xfs_flock64)
794 #define XFS_IOC_GETBMAPA	_IOWR('X', 44, struct getbmap)
795 #define XFS_IOC_FSGETXATTRA	_IOR ('X', 45, struct fsxattr)
796 /*	XFS_IOC_SETBIOSIZE ---- deprecated 46	   */
797 /*	XFS_IOC_GETBIOSIZE ---- deprecated 47	   */
798 #define XFS_IOC_GETBMAPX	_IOWR('X', 56, struct getbmap)
799 #define XFS_IOC_ZERO_RANGE	_IOW ('X', 57, struct xfs_flock64)
800 #define XFS_IOC_FREE_EOFBLOCKS	_IOR ('X', 58, struct xfs_fs_eofblocks)
801 /*	XFS_IOC_GETFSMAP ------ hoisted 59         */
802 #define XFS_IOC_SCRUB_METADATA	_IOWR('X', 60, struct xfs_scrub_metadata)
803 #define XFS_IOC_AG_GEOMETRY	_IOWR('X', 61, struct xfs_ag_geometry)
804 
805 /*
806  * ioctl commands that replace IRIX syssgi()'s
807  */
808 #define XFS_IOC_FSGEOMETRY_V1	     _IOR ('X', 100, struct xfs_fsop_geom_v1)
809 #define XFS_IOC_FSBULKSTAT	     _IOWR('X', 101, struct xfs_fsop_bulkreq)
810 #define XFS_IOC_FSBULKSTAT_SINGLE    _IOWR('X', 102, struct xfs_fsop_bulkreq)
811 #define XFS_IOC_FSINUMBERS	     _IOWR('X', 103, struct xfs_fsop_bulkreq)
812 #define XFS_IOC_PATH_TO_FSHANDLE     _IOWR('X', 104, struct xfs_fsop_handlereq)
813 #define XFS_IOC_PATH_TO_HANDLE	     _IOWR('X', 105, struct xfs_fsop_handlereq)
814 #define XFS_IOC_FD_TO_HANDLE	     _IOWR('X', 106, struct xfs_fsop_handlereq)
815 #define XFS_IOC_OPEN_BY_HANDLE	     _IOWR('X', 107, struct xfs_fsop_handlereq)
816 #define XFS_IOC_READLINK_BY_HANDLE   _IOWR('X', 108, struct xfs_fsop_handlereq)
817 #define XFS_IOC_SWAPEXT		     _IOWR('X', 109, struct xfs_swapext)
818 #define XFS_IOC_FSGROWFSDATA	     _IOW ('X', 110, struct xfs_growfs_data)
819 #define XFS_IOC_FSGROWFSLOG	     _IOW ('X', 111, struct xfs_growfs_log)
820 #define XFS_IOC_FSGROWFSRT	     _IOW ('X', 112, struct xfs_growfs_rt)
821 #define XFS_IOC_FSCOUNTS	     _IOR ('X', 113, struct xfs_fsop_counts)
822 #define XFS_IOC_SET_RESBLKS	     _IOWR('X', 114, struct xfs_fsop_resblks)
823 #define XFS_IOC_GET_RESBLKS	     _IOR ('X', 115, struct xfs_fsop_resblks)
824 #define XFS_IOC_ERROR_INJECTION	     _IOW ('X', 116, struct xfs_error_injection)
825 #define XFS_IOC_ERROR_CLEARALL	     _IOW ('X', 117, struct xfs_error_injection)
826 /*	XFS_IOC_ATTRCTL_BY_HANDLE -- deprecated 118	 */
827 
828 #define XFS_IOC_FREEZE		     _IOWR('X', 119, int)	/* aka FIFREEZE */
829 #define XFS_IOC_THAW		     _IOWR('X', 120, int)	/* aka FITHAW */
830 
831 #define XFS_IOC_FSSETDM_BY_HANDLE    _IOW ('X', 121, struct xfs_fsop_setdm_handlereq)
832 #define XFS_IOC_ATTRLIST_BY_HANDLE   _IOW ('X', 122, struct xfs_fsop_attrlist_handlereq)
833 #define XFS_IOC_ATTRMULTI_BY_HANDLE  _IOW ('X', 123, struct xfs_fsop_attrmulti_handlereq)
834 #define XFS_IOC_FSGEOMETRY_V4	     _IOR ('X', 124, struct xfs_fsop_geom_v4)
835 #define XFS_IOC_GOINGDOWN	     _IOR ('X', 125, uint32_t)
836 #define XFS_IOC_FSGEOMETRY	     _IOR ('X', 126, struct xfs_fsop_geom)
837 #define XFS_IOC_BULKSTAT	     _IOR ('X', 127, struct xfs_bulkstat_req)
838 #define XFS_IOC_INUMBERS	     _IOR ('X', 128, struct xfs_inumbers_req)
839 /*	XFS_IOC_GETFSUUID ---------- deprecated 140	 */
840 
841 
842 #ifndef HAVE_BBMACROS
843 /*
844  * Block I/O parameterization.	A basic block (BB) is the lowest size of
845  * filesystem allocation, and must equal 512.  Length units given to bio
846  * routines are in BB's.
847  */
848 #define BBSHIFT		9
849 #define BBSIZE		(1<<BBSHIFT)
850 #define BBMASK		(BBSIZE-1)
851 #define BTOBB(bytes)	(((__u64)(bytes) + BBSIZE - 1) >> BBSHIFT)
852 #define BTOBBT(bytes)	((__u64)(bytes) >> BBSHIFT)
853 #define BBTOB(bbs)	((bbs) << BBSHIFT)
854 #endif
855 
856 #endif	/* __XFS_FS_H__ */
857