xref: /openbmc/linux/fs/xfs/libxfs/xfs_quota_defs.h (revision 2bdd5238)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_QUOTA_DEFS_H__
7 #define __XFS_QUOTA_DEFS_H__
8 
9 /*
10  * Quota definitions shared between user and kernel source trees.
11  */
12 
13 /*
14  * Even though users may not have quota limits occupying all 64-bits,
15  * they may need 64-bit accounting. Hence, 64-bit quota-counters,
16  * and quota-limits. This is a waste in the common case, but hey ...
17  */
18 typedef uint64_t	xfs_qcnt_t;
19 typedef uint16_t	xfs_qwarncnt_t;
20 
21 typedef uint8_t		xfs_dqtype_t;
22 
23 #define XFS_DQTYPE_STRINGS \
24 	{ XFS_DQTYPE_USER,	"USER" }, \
25 	{ XFS_DQTYPE_PROJ,	"PROJ" }, \
26 	{ XFS_DQTYPE_GROUP,	"GROUP" }, \
27 	{ XFS_DQTYPE_BIGTIME,	"BIGTIME" }
28 
29 /*
30  * flags for q_flags field in the dquot.
31  */
32 #define XFS_DQFLAG_DIRTY	(1 << 0)	/* dquot is dirty */
33 #define XFS_DQFLAG_FREEING	(1 << 1)	/* dquot is being torn down */
34 
35 #define XFS_DQFLAG_STRINGS \
36 	{ XFS_DQFLAG_DIRTY,	"DIRTY" }, \
37 	{ XFS_DQFLAG_FREEING,	"FREEING" }
38 
39 /*
40  * We have the possibility of all three quota types being active at once, and
41  * hence free space modification requires modification of all three current
42  * dquots in a single transaction. For this case we need to have a reservation
43  * of at least 3 dquots.
44  *
45  * However, a chmod operation can change both UID and GID in a single
46  * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be
47  * modified. Hence for this case we need to reserve space for at least 4 dquots.
48  *
49  * And in the worst case, there's a rename operation that can be modifying up to
50  * 4 inodes with dquots attached to them. In reality, the only inodes that can
51  * have their dquots modified are the source and destination directory inodes
52  * due to directory name creation and removal. That can require space allocation
53  * and/or freeing on both directory inodes, and hence all three dquots on each
54  * inode can be modified. And if the directories are world writeable, all the
55  * dquots can be unique and so 6 dquots can be modified....
56  *
57  * And, of course, we also need to take into account the dquot log format item
58  * used to describe each dquot.
59  */
60 #define XFS_DQUOT_LOGRES(mp)	\
61 	((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6)
62 
63 #define XFS_IS_QUOTA_ON(mp)		((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
64 #define XFS_IS_UQUOTA_ON(mp)		((mp)->m_qflags & XFS_UQUOTA_ACCT)
65 #define XFS_IS_PQUOTA_ON(mp)		((mp)->m_qflags & XFS_PQUOTA_ACCT)
66 #define XFS_IS_GQUOTA_ON(mp)		((mp)->m_qflags & XFS_GQUOTA_ACCT)
67 #define XFS_IS_UQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_UQUOTA_ENFD)
68 #define XFS_IS_GQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_GQUOTA_ENFD)
69 #define XFS_IS_PQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_PQUOTA_ENFD)
70 
71 /*
72  * Flags to tell various functions what to do. Not all of these are meaningful
73  * to a single function. None of these XFS_QMOPT_* flags are meant to have
74  * persistent values (ie. their values can and will change between versions)
75  */
76 #define XFS_QMOPT_UQUOTA	0x0000004 /* user dquot requested */
77 #define XFS_QMOPT_PQUOTA	0x0000008 /* project dquot requested */
78 #define XFS_QMOPT_FORCE_RES	0x0000010 /* ignore quota limits */
79 #define XFS_QMOPT_SBVERSION	0x0000040 /* change superblock version num */
80 #define XFS_QMOPT_GQUOTA	0x0002000 /* group dquot requested */
81 
82 /*
83  * flags to xfs_trans_mod_dquot to indicate which field needs to be
84  * modified.
85  */
86 #define XFS_QMOPT_RES_REGBLKS	0x0010000
87 #define XFS_QMOPT_RES_RTBLKS	0x0020000
88 #define XFS_QMOPT_BCOUNT	0x0040000
89 #define XFS_QMOPT_ICOUNT	0x0080000
90 #define XFS_QMOPT_RTBCOUNT	0x0100000
91 #define XFS_QMOPT_DELBCOUNT	0x0200000
92 #define XFS_QMOPT_DELRTBCOUNT	0x0400000
93 #define XFS_QMOPT_RES_INOS	0x0800000
94 
95 /*
96  * flags for dqalloc.
97  */
98 #define XFS_QMOPT_INHERIT	0x1000000
99 
100 /*
101  * flags to xfs_trans_mod_dquot.
102  */
103 #define XFS_TRANS_DQ_RES_BLKS	XFS_QMOPT_RES_REGBLKS
104 #define XFS_TRANS_DQ_RES_RTBLKS	XFS_QMOPT_RES_RTBLKS
105 #define XFS_TRANS_DQ_RES_INOS	XFS_QMOPT_RES_INOS
106 #define XFS_TRANS_DQ_BCOUNT	XFS_QMOPT_BCOUNT
107 #define XFS_TRANS_DQ_DELBCOUNT	XFS_QMOPT_DELBCOUNT
108 #define XFS_TRANS_DQ_ICOUNT	XFS_QMOPT_ICOUNT
109 #define XFS_TRANS_DQ_RTBCOUNT	XFS_QMOPT_RTBCOUNT
110 #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT
111 
112 
113 #define XFS_QMOPT_QUOTALL	\
114 		(XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
115 #define XFS_QMOPT_RESBLK_MASK	(XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
116 
117 extern xfs_failaddr_t xfs_dquot_verify(struct xfs_mount *mp,
118 		struct xfs_disk_dquot *ddq, xfs_dqid_t id);
119 extern xfs_failaddr_t xfs_dqblk_verify(struct xfs_mount *mp,
120 		struct xfs_dqblk *dqb, xfs_dqid_t id);
121 extern int xfs_calc_dquots_per_chunk(unsigned int nbblks);
122 extern void xfs_dqblk_repair(struct xfs_mount *mp, struct xfs_dqblk *dqb,
123 		xfs_dqid_t id, xfs_dqtype_t type);
124 
125 struct xfs_dquot;
126 time64_t xfs_dquot_from_disk_ts(struct xfs_disk_dquot *ddq,
127 		__be32 dtimer);
128 __be32 xfs_dquot_to_disk_ts(struct xfs_dquot *ddq, time64_t timer);
129 
130 #endif	/* __XFS_QUOTA_H__ */
131