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 20 typedef uint8_t xfs_dqtype_t; 21 22 #define XFS_DQTYPE_STRINGS \ 23 { XFS_DQTYPE_USER, "USER" }, \ 24 { XFS_DQTYPE_PROJ, "PROJ" }, \ 25 { XFS_DQTYPE_GROUP, "GROUP" }, \ 26 { XFS_DQTYPE_BIGTIME, "BIGTIME" } 27 28 /* 29 * flags for q_flags field in the dquot. 30 */ 31 #define XFS_DQFLAG_DIRTY (1u << 0) /* dquot is dirty */ 32 33 #define XFS_DQFLAG_STRINGS \ 34 { XFS_DQFLAG_DIRTY, "DIRTY" } 35 36 /* 37 * We have the possibility of all three quota types being active at once, and 38 * hence free space modification requires modification of all three current 39 * dquots in a single transaction. For this case we need to have a reservation 40 * of at least 3 dquots. 41 * 42 * However, a chmod operation can change both UID and GID in a single 43 * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be 44 * modified. Hence for this case we need to reserve space for at least 4 dquots. 45 * 46 * And in the worst case, there's a rename operation that can be modifying up to 47 * 4 inodes with dquots attached to them. In reality, the only inodes that can 48 * have their dquots modified are the source and destination directory inodes 49 * due to directory name creation and removal. That can require space allocation 50 * and/or freeing on both directory inodes, and hence all three dquots on each 51 * inode can be modified. And if the directories are world writeable, all the 52 * dquots can be unique and so 6 dquots can be modified.... 53 * 54 * And, of course, we also need to take into account the dquot log format item 55 * used to describe each dquot. 56 */ 57 #define XFS_DQUOT_LOGRES \ 58 ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6) 59 60 #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT) 61 #define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT) 62 #define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT) 63 #define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT) 64 #define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD) 65 #define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD) 66 #define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD) 67 68 /* 69 * Flags to tell various functions what to do. Not all of these are meaningful 70 * to a single function. None of these XFS_QMOPT_* flags are meant to have 71 * persistent values (ie. their values can and will change between versions) 72 */ 73 #define XFS_QMOPT_UQUOTA (1u << 0) /* user dquot requested */ 74 #define XFS_QMOPT_GQUOTA (1u << 1) /* group dquot requested */ 75 #define XFS_QMOPT_PQUOTA (1u << 2) /* project dquot requested */ 76 #define XFS_QMOPT_FORCE_RES (1u << 3) /* ignore quota limits */ 77 #define XFS_QMOPT_SBVERSION (1u << 4) /* change superblock version num */ 78 79 /* 80 * flags to xfs_trans_mod_dquot to indicate which field needs to be 81 * modified. 82 */ 83 #define XFS_QMOPT_RES_REGBLKS (1u << 7) 84 #define XFS_QMOPT_RES_RTBLKS (1u << 8) 85 #define XFS_QMOPT_BCOUNT (1u << 9) 86 #define XFS_QMOPT_ICOUNT (1u << 10) 87 #define XFS_QMOPT_RTBCOUNT (1u << 11) 88 #define XFS_QMOPT_DELBCOUNT (1u << 12) 89 #define XFS_QMOPT_DELRTBCOUNT (1u << 13) 90 #define XFS_QMOPT_RES_INOS (1u << 14) 91 92 /* 93 * flags for dqalloc. 94 */ 95 #define XFS_QMOPT_INHERIT (1u << 31) 96 97 #define XFS_QMOPT_FLAGS \ 98 { XFS_QMOPT_UQUOTA, "UQUOTA" }, \ 99 { XFS_QMOPT_PQUOTA, "PQUOTA" }, \ 100 { XFS_QMOPT_FORCE_RES, "FORCE_RES" }, \ 101 { XFS_QMOPT_SBVERSION, "SBVERSION" }, \ 102 { XFS_QMOPT_GQUOTA, "GQUOTA" }, \ 103 { XFS_QMOPT_INHERIT, "INHERIT" }, \ 104 { XFS_QMOPT_RES_REGBLKS, "RES_REGBLKS" }, \ 105 { XFS_QMOPT_RES_RTBLKS, "RES_RTBLKS" }, \ 106 { XFS_QMOPT_BCOUNT, "BCOUNT" }, \ 107 { XFS_QMOPT_ICOUNT, "ICOUNT" }, \ 108 { XFS_QMOPT_RTBCOUNT, "RTBCOUNT" }, \ 109 { XFS_QMOPT_DELBCOUNT, "DELBCOUNT" }, \ 110 { XFS_QMOPT_DELRTBCOUNT, "DELRTBCOUNT" }, \ 111 { XFS_QMOPT_RES_INOS, "RES_INOS" } 112 113 /* 114 * flags to xfs_trans_mod_dquot. 115 */ 116 #define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS 117 #define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS 118 #define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS 119 #define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT 120 #define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT 121 #define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT 122 #define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT 123 #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT 124 125 126 #define XFS_QMOPT_QUOTALL \ 127 (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA) 128 #define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS) 129 130 131 extern xfs_failaddr_t xfs_dquot_verify(struct xfs_mount *mp, 132 struct xfs_disk_dquot *ddq, xfs_dqid_t id); 133 extern xfs_failaddr_t xfs_dqblk_verify(struct xfs_mount *mp, 134 struct xfs_dqblk *dqb, xfs_dqid_t id); 135 extern int xfs_calc_dquots_per_chunk(unsigned int nbblks); 136 extern void xfs_dqblk_repair(struct xfs_mount *mp, struct xfs_dqblk *dqb, 137 xfs_dqid_t id, xfs_dqtype_t type); 138 139 struct xfs_dquot; 140 time64_t xfs_dquot_from_disk_ts(struct xfs_disk_dquot *ddq, 141 __be32 dtimer); 142 __be32 xfs_dquot_to_disk_ts(struct xfs_dquot *ddq, time64_t timer); 143 144 static inline const char * 145 xfs_dqinode_path(xfs_dqtype_t type) 146 { 147 switch (type) { 148 case XFS_DQTYPE_USER: 149 return "user"; 150 case XFS_DQTYPE_GROUP: 151 return "group"; 152 case XFS_DQTYPE_PROJ: 153 return "project"; 154 } 155 156 ASSERT(0); 157 return NULL; 158 } 159 160 static inline enum xfs_metafile_type 161 xfs_dqinode_metafile_type(xfs_dqtype_t type) 162 { 163 switch (type) { 164 case XFS_DQTYPE_USER: 165 return XFS_METAFILE_USRQUOTA; 166 case XFS_DQTYPE_GROUP: 167 return XFS_METAFILE_GRPQUOTA; 168 case XFS_DQTYPE_PROJ: 169 return XFS_METAFILE_PRJQUOTA; 170 } 171 172 ASSERT(0); 173 return XFS_METAFILE_UNKNOWN; 174 } 175 176 unsigned int xfs_dqinode_sick_mask(xfs_dqtype_t type); 177 178 int xfs_dqinode_load(struct xfs_trans *tp, struct xfs_inode *dp, 179 xfs_dqtype_t type, struct xfs_inode **ipp); 180 int xfs_dqinode_metadir_create(struct xfs_inode *dp, xfs_dqtype_t type, 181 struct xfs_inode **ipp); 182 int xfs_dqinode_metadir_link(struct xfs_inode *dp, xfs_dqtype_t type, 183 struct xfs_inode *ip); 184 int xfs_dqinode_mkdir_parent(struct xfs_mount *mp, struct xfs_inode **dpp); 185 int xfs_dqinode_load_parent(struct xfs_trans *tp, struct xfs_inode **dpp); 186 187 #endif /* __XFS_QUOTA_H__ */ 188