xref: /linux/fs/xfs/xfs_itable.h (revision d0efc9e4276cda07c2f76652d240b165c30b05b8)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4  */
5 #ifndef __XFS_ITABLE_H__
6 #define	__XFS_ITABLE_H__
7 
8 /* In-memory representation of a userspace request for batch inode data. */
9 struct xfs_ibulk {
10 	struct xfs_mount	*mp;
11 	struct mnt_idmap	*idmap;
12 	void __user		*ubuffer; /* user output buffer */
13 	xfs_ino_t		startino; /* start with this inode */
14 	unsigned int		icount;   /* number of elements in ubuffer */
15 	unsigned int		ocount;   /* number of records returned */
16 	unsigned int		flags;    /* XFS_IBULK_FLAG_* */
17 	unsigned int		iwalk_flags; /* XFS_IWALK_FLAG_* */
18 };
19 
20 /* Fill out the bs_extents64 field if set. */
21 #define XFS_IBULK_NREXT64	(1U << 0)
22 
23 /* Signal that we can return metadata directories. */
24 #define XFS_IBULK_METADIR	(1U << 1)
25 
26 /*
27  * Advance the user buffer pointer by one record of the given size.  If the
28  * buffer is now full, return the appropriate error code.
29  */
30 static inline int
xfs_ibulk_advance(struct xfs_ibulk * breq,size_t bytes)31 xfs_ibulk_advance(
32 	struct xfs_ibulk	*breq,
33 	size_t			bytes)
34 {
35 	char __user		*b = breq->ubuffer;
36 
37 	breq->ubuffer = b + bytes;
38 	breq->ocount++;
39 	return breq->ocount == breq->icount ? -ECANCELED : 0;
40 }
41 
42 /*
43  * Return stat information in bulk (by-inode) for the filesystem.
44  */
45 
46 /*
47  * Return codes for the formatter function are 0 to continue iterating, and
48  * non-zero to stop iterating.  Any non-zero value will be passed up to the
49  * bulkstat/inumbers caller.  The special value -ECANCELED can be used to stop
50  * iteration, as neither bulkstat nor inumbers will ever generate that error
51  * code on their own.
52  */
53 
54 typedef int (*bulkstat_one_fmt_pf)(struct xfs_ibulk *breq,
55 		const struct xfs_bulkstat *bstat);
56 
57 int xfs_bulkstat_one(struct xfs_ibulk *breq, bulkstat_one_fmt_pf formatter);
58 int xfs_bulkstat(struct xfs_ibulk *breq, bulkstat_one_fmt_pf formatter);
59 void xfs_bulkstat_to_bstat(struct xfs_mount *mp, struct xfs_bstat *bs1,
60 		const struct xfs_bulkstat *bstat);
61 
62 typedef int (*inumbers_fmt_pf)(struct xfs_ibulk *breq,
63 		const struct xfs_inumbers *igrp);
64 
65 int xfs_inumbers(struct xfs_ibulk *breq, inumbers_fmt_pf formatter);
66 void xfs_inumbers_to_inogrp(struct xfs_inogrp *ig1,
67 		const struct xfs_inumbers *ig);
68 
69 #endif	/* __XFS_ITABLE_H__ */
70