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