1 /* 2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. 3 * All Rights Reserved. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it would be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 #ifndef __XFS_QUOTA_DEFS_H__ 19 #define __XFS_QUOTA_DEFS_H__ 20 21 /* 22 * Quota definitions shared between user and kernel source trees. 23 */ 24 25 /* 26 * Even though users may not have quota limits occupying all 64-bits, 27 * they may need 64-bit accounting. Hence, 64-bit quota-counters, 28 * and quota-limits. This is a waste in the common case, but hey ... 29 */ 30 typedef __uint64_t xfs_qcnt_t; 31 typedef __uint16_t xfs_qwarncnt_t; 32 33 /* 34 * flags for q_flags field in the dquot. 35 */ 36 #define XFS_DQ_USER 0x0001 /* a user quota */ 37 #define XFS_DQ_PROJ 0x0002 /* project quota */ 38 #define XFS_DQ_GROUP 0x0004 /* a group quota */ 39 #define XFS_DQ_DIRTY 0x0008 /* dquot is dirty */ 40 #define XFS_DQ_FREEING 0x0010 /* dquot is being torn down */ 41 42 #define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP) 43 44 #define XFS_DQ_FLAGS \ 45 { XFS_DQ_USER, "USER" }, \ 46 { XFS_DQ_PROJ, "PROJ" }, \ 47 { XFS_DQ_GROUP, "GROUP" }, \ 48 { XFS_DQ_DIRTY, "DIRTY" }, \ 49 { XFS_DQ_FREEING, "FREEING" } 50 51 /* 52 * We have the possibility of all three quota types being active at once, and 53 * hence free space modification requires modification of all three current 54 * dquots in a single transaction. For this case we need to have a reservation 55 * of at least 3 dquots. 56 * 57 * However, a chmod operation can change both UID and GID in a single 58 * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be 59 * modified. Hence for this case we need to reserve space for at least 4 dquots. 60 * 61 * And in the worst case, there's a rename operation that can be modifying up to 62 * 4 inodes with dquots attached to them. In reality, the only inodes that can 63 * have their dquots modified are the source and destination directory inodes 64 * due to directory name creation and removal. That can require space allocation 65 * and/or freeing on both directory inodes, and hence all three dquots on each 66 * inode can be modified. And if the directories are world writeable, all the 67 * dquots can be unique and so 6 dquots can be modified.... 68 * 69 * And, of course, we also need to take into account the dquot log format item 70 * used to describe each dquot. 71 */ 72 #define XFS_DQUOT_LOGRES(mp) \ 73 ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6) 74 75 #define XFS_IS_QUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT) 76 #define XFS_IS_UQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT) 77 #define XFS_IS_PQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT) 78 #define XFS_IS_GQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT) 79 #define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD) 80 #define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD) 81 #define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD) 82 83 /* 84 * Incore only flags for quotaoff - these bits get cleared when quota(s) 85 * are in the process of getting turned off. These flags are in m_qflags but 86 * never in sb_qflags. 87 */ 88 #define XFS_UQUOTA_ACTIVE 0x1000 /* uquotas are being turned off */ 89 #define XFS_GQUOTA_ACTIVE 0x2000 /* gquotas are being turned off */ 90 #define XFS_PQUOTA_ACTIVE 0x4000 /* pquotas are being turned off */ 91 #define XFS_ALL_QUOTA_ACTIVE \ 92 (XFS_UQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE) 93 94 /* 95 * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees 96 * quota will be not be switched off as long as that inode lock is held. 97 */ 98 #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \ 99 XFS_GQUOTA_ACTIVE | \ 100 XFS_PQUOTA_ACTIVE)) 101 #define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE) 102 #define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE) 103 #define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACTIVE) 104 105 /* 106 * Flags to tell various functions what to do. Not all of these are meaningful 107 * to a single function. None of these XFS_QMOPT_* flags are meant to have 108 * persistent values (ie. their values can and will change between versions) 109 */ 110 #define XFS_QMOPT_DQALLOC 0x0000002 /* alloc dquot ondisk if needed */ 111 #define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */ 112 #define XFS_QMOPT_PQUOTA 0x0000008 /* project dquot requested */ 113 #define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */ 114 #define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */ 115 #define XFS_QMOPT_DOWARN 0x0000400 /* increase warning cnt if needed */ 116 #define XFS_QMOPT_DQREPAIR 0x0001000 /* repair dquot if damaged */ 117 #define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */ 118 #define XFS_QMOPT_ENOSPC 0x0004000 /* enospc instead of edquot (prj) */ 119 #define XFS_QMOPT_DQNEXT 0x0008000 /* return next dquot >= this ID */ 120 121 /* 122 * flags to xfs_trans_mod_dquot to indicate which field needs to be 123 * modified. 124 */ 125 #define XFS_QMOPT_RES_REGBLKS 0x0010000 126 #define XFS_QMOPT_RES_RTBLKS 0x0020000 127 #define XFS_QMOPT_BCOUNT 0x0040000 128 #define XFS_QMOPT_ICOUNT 0x0080000 129 #define XFS_QMOPT_RTBCOUNT 0x0100000 130 #define XFS_QMOPT_DELBCOUNT 0x0200000 131 #define XFS_QMOPT_DELRTBCOUNT 0x0400000 132 #define XFS_QMOPT_RES_INOS 0x0800000 133 134 /* 135 * flags for dqalloc. 136 */ 137 #define XFS_QMOPT_INHERIT 0x1000000 138 139 /* 140 * flags to xfs_trans_mod_dquot. 141 */ 142 #define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS 143 #define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS 144 #define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS 145 #define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT 146 #define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT 147 #define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT 148 #define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT 149 #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT 150 151 152 #define XFS_QMOPT_QUOTALL \ 153 (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA) 154 #define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS) 155 156 extern int xfs_dqcheck(struct xfs_mount *mp, xfs_disk_dquot_t *ddq, 157 xfs_dqid_t id, uint type, uint flags, const char *str); 158 extern int xfs_calc_dquots_per_chunk(unsigned int nbblks); 159 160 #endif /* __XFS_QUOTA_H__ */ 161