162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc. 462306a36Sopenharmony_ci * All Rights Reserved. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __XFS_QUOTA_DEFS_H__ 762306a36Sopenharmony_ci#define __XFS_QUOTA_DEFS_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* 1062306a36Sopenharmony_ci * Quota definitions shared between user and kernel source trees. 1162306a36Sopenharmony_ci */ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* 1462306a36Sopenharmony_ci * Even though users may not have quota limits occupying all 64-bits, 1562306a36Sopenharmony_ci * they may need 64-bit accounting. Hence, 64-bit quota-counters, 1662306a36Sopenharmony_ci * and quota-limits. This is a waste in the common case, but hey ... 1762306a36Sopenharmony_ci */ 1862306a36Sopenharmony_citypedef uint64_t xfs_qcnt_t; 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_citypedef uint8_t xfs_dqtype_t; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#define XFS_DQTYPE_STRINGS \ 2362306a36Sopenharmony_ci { XFS_DQTYPE_USER, "USER" }, \ 2462306a36Sopenharmony_ci { XFS_DQTYPE_PROJ, "PROJ" }, \ 2562306a36Sopenharmony_ci { XFS_DQTYPE_GROUP, "GROUP" }, \ 2662306a36Sopenharmony_ci { XFS_DQTYPE_BIGTIME, "BIGTIME" } 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* 2962306a36Sopenharmony_ci * flags for q_flags field in the dquot. 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_ci#define XFS_DQFLAG_DIRTY (1u << 0) /* dquot is dirty */ 3262306a36Sopenharmony_ci#define XFS_DQFLAG_FREEING (1u << 1) /* dquot is being torn down */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define XFS_DQFLAG_STRINGS \ 3562306a36Sopenharmony_ci { XFS_DQFLAG_DIRTY, "DIRTY" }, \ 3662306a36Sopenharmony_ci { XFS_DQFLAG_FREEING, "FREEING" } 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * We have the possibility of all three quota types being active at once, and 4062306a36Sopenharmony_ci * hence free space modification requires modification of all three current 4162306a36Sopenharmony_ci * dquots in a single transaction. For this case we need to have a reservation 4262306a36Sopenharmony_ci * of at least 3 dquots. 4362306a36Sopenharmony_ci * 4462306a36Sopenharmony_ci * However, a chmod operation can change both UID and GID in a single 4562306a36Sopenharmony_ci * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be 4662306a36Sopenharmony_ci * modified. Hence for this case we need to reserve space for at least 4 dquots. 4762306a36Sopenharmony_ci * 4862306a36Sopenharmony_ci * And in the worst case, there's a rename operation that can be modifying up to 4962306a36Sopenharmony_ci * 4 inodes with dquots attached to them. In reality, the only inodes that can 5062306a36Sopenharmony_ci * have their dquots modified are the source and destination directory inodes 5162306a36Sopenharmony_ci * due to directory name creation and removal. That can require space allocation 5262306a36Sopenharmony_ci * and/or freeing on both directory inodes, and hence all three dquots on each 5362306a36Sopenharmony_ci * inode can be modified. And if the directories are world writeable, all the 5462306a36Sopenharmony_ci * dquots can be unique and so 6 dquots can be modified.... 5562306a36Sopenharmony_ci * 5662306a36Sopenharmony_ci * And, of course, we also need to take into account the dquot log format item 5762306a36Sopenharmony_ci * used to describe each dquot. 5862306a36Sopenharmony_ci */ 5962306a36Sopenharmony_ci#define XFS_DQUOT_LOGRES(mp) \ 6062306a36Sopenharmony_ci ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT) 6362306a36Sopenharmony_ci#define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT) 6462306a36Sopenharmony_ci#define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT) 6562306a36Sopenharmony_ci#define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT) 6662306a36Sopenharmony_ci#define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD) 6762306a36Sopenharmony_ci#define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD) 6862306a36Sopenharmony_ci#define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD) 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* 7162306a36Sopenharmony_ci * Flags to tell various functions what to do. Not all of these are meaningful 7262306a36Sopenharmony_ci * to a single function. None of these XFS_QMOPT_* flags are meant to have 7362306a36Sopenharmony_ci * persistent values (ie. their values can and will change between versions) 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci#define XFS_QMOPT_UQUOTA (1u << 0) /* user dquot requested */ 7662306a36Sopenharmony_ci#define XFS_QMOPT_GQUOTA (1u << 1) /* group dquot requested */ 7762306a36Sopenharmony_ci#define XFS_QMOPT_PQUOTA (1u << 2) /* project dquot requested */ 7862306a36Sopenharmony_ci#define XFS_QMOPT_FORCE_RES (1u << 3) /* ignore quota limits */ 7962306a36Sopenharmony_ci#define XFS_QMOPT_SBVERSION (1u << 4) /* change superblock version num */ 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* 8262306a36Sopenharmony_ci * flags to xfs_trans_mod_dquot to indicate which field needs to be 8362306a36Sopenharmony_ci * modified. 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define XFS_QMOPT_RES_REGBLKS (1u << 7) 8662306a36Sopenharmony_ci#define XFS_QMOPT_RES_RTBLKS (1u << 8) 8762306a36Sopenharmony_ci#define XFS_QMOPT_BCOUNT (1u << 9) 8862306a36Sopenharmony_ci#define XFS_QMOPT_ICOUNT (1u << 10) 8962306a36Sopenharmony_ci#define XFS_QMOPT_RTBCOUNT (1u << 11) 9062306a36Sopenharmony_ci#define XFS_QMOPT_DELBCOUNT (1u << 12) 9162306a36Sopenharmony_ci#define XFS_QMOPT_DELRTBCOUNT (1u << 13) 9262306a36Sopenharmony_ci#define XFS_QMOPT_RES_INOS (1u << 14) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* 9562306a36Sopenharmony_ci * flags for dqalloc. 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci#define XFS_QMOPT_INHERIT (1u << 31) 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define XFS_QMOPT_FLAGS \ 10062306a36Sopenharmony_ci { XFS_QMOPT_UQUOTA, "UQUOTA" }, \ 10162306a36Sopenharmony_ci { XFS_QMOPT_PQUOTA, "PQUOTA" }, \ 10262306a36Sopenharmony_ci { XFS_QMOPT_FORCE_RES, "FORCE_RES" }, \ 10362306a36Sopenharmony_ci { XFS_QMOPT_SBVERSION, "SBVERSION" }, \ 10462306a36Sopenharmony_ci { XFS_QMOPT_GQUOTA, "GQUOTA" }, \ 10562306a36Sopenharmony_ci { XFS_QMOPT_INHERIT, "INHERIT" }, \ 10662306a36Sopenharmony_ci { XFS_QMOPT_RES_REGBLKS, "RES_REGBLKS" }, \ 10762306a36Sopenharmony_ci { XFS_QMOPT_RES_RTBLKS, "RES_RTBLKS" }, \ 10862306a36Sopenharmony_ci { XFS_QMOPT_BCOUNT, "BCOUNT" }, \ 10962306a36Sopenharmony_ci { XFS_QMOPT_ICOUNT, "ICOUNT" }, \ 11062306a36Sopenharmony_ci { XFS_QMOPT_RTBCOUNT, "RTBCOUNT" }, \ 11162306a36Sopenharmony_ci { XFS_QMOPT_DELBCOUNT, "DELBCOUNT" }, \ 11262306a36Sopenharmony_ci { XFS_QMOPT_DELRTBCOUNT, "DELRTBCOUNT" }, \ 11362306a36Sopenharmony_ci { XFS_QMOPT_RES_INOS, "RES_INOS" } 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/* 11662306a36Sopenharmony_ci * flags to xfs_trans_mod_dquot. 11762306a36Sopenharmony_ci */ 11862306a36Sopenharmony_ci#define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS 11962306a36Sopenharmony_ci#define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS 12062306a36Sopenharmony_ci#define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS 12162306a36Sopenharmony_ci#define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT 12262306a36Sopenharmony_ci#define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT 12362306a36Sopenharmony_ci#define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT 12462306a36Sopenharmony_ci#define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT 12562306a36Sopenharmony_ci#define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#define XFS_QMOPT_QUOTALL \ 12962306a36Sopenharmony_ci (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA) 13062306a36Sopenharmony_ci#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS) 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciextern xfs_failaddr_t xfs_dquot_verify(struct xfs_mount *mp, 13462306a36Sopenharmony_ci struct xfs_disk_dquot *ddq, xfs_dqid_t id); 13562306a36Sopenharmony_ciextern xfs_failaddr_t xfs_dqblk_verify(struct xfs_mount *mp, 13662306a36Sopenharmony_ci struct xfs_dqblk *dqb, xfs_dqid_t id); 13762306a36Sopenharmony_ciextern int xfs_calc_dquots_per_chunk(unsigned int nbblks); 13862306a36Sopenharmony_ciextern void xfs_dqblk_repair(struct xfs_mount *mp, struct xfs_dqblk *dqb, 13962306a36Sopenharmony_ci xfs_dqid_t id, xfs_dqtype_t type); 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_cistruct xfs_dquot; 14262306a36Sopenharmony_citime64_t xfs_dquot_from_disk_ts(struct xfs_disk_dquot *ddq, 14362306a36Sopenharmony_ci __be32 dtimer); 14462306a36Sopenharmony_ci__be32 xfs_dquot_to_disk_ts(struct xfs_dquot *ddq, time64_t timer); 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci#endif /* __XFS_QUOTA_H__ */ 147