18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_QUOTA_DEFS_H__ 78c2ecf20Sopenharmony_ci#define __XFS_QUOTA_DEFS_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Quota definitions shared between user and kernel source trees. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 148c2ecf20Sopenharmony_ci * Even though users may not have quota limits occupying all 64-bits, 158c2ecf20Sopenharmony_ci * they may need 64-bit accounting. Hence, 64-bit quota-counters, 168c2ecf20Sopenharmony_ci * and quota-limits. This is a waste in the common case, but hey ... 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_citypedef uint64_t xfs_qcnt_t; 198c2ecf20Sopenharmony_citypedef uint16_t xfs_qwarncnt_t; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_citypedef uint8_t xfs_dqtype_t; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define XFS_DQTYPE_STRINGS \ 248c2ecf20Sopenharmony_ci { XFS_DQTYPE_USER, "USER" }, \ 258c2ecf20Sopenharmony_ci { XFS_DQTYPE_PROJ, "PROJ" }, \ 268c2ecf20Sopenharmony_ci { XFS_DQTYPE_GROUP, "GROUP" }, \ 278c2ecf20Sopenharmony_ci { XFS_DQTYPE_BIGTIME, "BIGTIME" } 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * flags for q_flags field in the dquot. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define XFS_DQFLAG_DIRTY (1 << 0) /* dquot is dirty */ 338c2ecf20Sopenharmony_ci#define XFS_DQFLAG_FREEING (1 << 1) /* dquot is being torn down */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define XFS_DQFLAG_STRINGS \ 368c2ecf20Sopenharmony_ci { XFS_DQFLAG_DIRTY, "DIRTY" }, \ 378c2ecf20Sopenharmony_ci { XFS_DQFLAG_FREEING, "FREEING" } 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * We have the possibility of all three quota types being active at once, and 418c2ecf20Sopenharmony_ci * hence free space modification requires modification of all three current 428c2ecf20Sopenharmony_ci * dquots in a single transaction. For this case we need to have a reservation 438c2ecf20Sopenharmony_ci * of at least 3 dquots. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * However, a chmod operation can change both UID and GID in a single 468c2ecf20Sopenharmony_ci * transaction, resulting in requiring {old, new} x {uid, gid} dquots to be 478c2ecf20Sopenharmony_ci * modified. Hence for this case we need to reserve space for at least 4 dquots. 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * And in the worst case, there's a rename operation that can be modifying up to 508c2ecf20Sopenharmony_ci * 4 inodes with dquots attached to them. In reality, the only inodes that can 518c2ecf20Sopenharmony_ci * have their dquots modified are the source and destination directory inodes 528c2ecf20Sopenharmony_ci * due to directory name creation and removal. That can require space allocation 538c2ecf20Sopenharmony_ci * and/or freeing on both directory inodes, and hence all three dquots on each 548c2ecf20Sopenharmony_ci * inode can be modified. And if the directories are world writeable, all the 558c2ecf20Sopenharmony_ci * dquots can be unique and so 6 dquots can be modified.... 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * And, of course, we also need to take into account the dquot log format item 588c2ecf20Sopenharmony_ci * used to describe each dquot. 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_ci#define XFS_DQUOT_LOGRES(mp) \ 618c2ecf20Sopenharmony_ci ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define XFS_IS_QUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT) 648c2ecf20Sopenharmony_ci#define XFS_IS_UQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_UQUOTA_ACCT) 658c2ecf20Sopenharmony_ci#define XFS_IS_PQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_PQUOTA_ACCT) 668c2ecf20Sopenharmony_ci#define XFS_IS_GQUOTA_RUNNING(mp) ((mp)->m_qflags & XFS_GQUOTA_ACCT) 678c2ecf20Sopenharmony_ci#define XFS_IS_UQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_UQUOTA_ENFD) 688c2ecf20Sopenharmony_ci#define XFS_IS_GQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_GQUOTA_ENFD) 698c2ecf20Sopenharmony_ci#define XFS_IS_PQUOTA_ENFORCED(mp) ((mp)->m_qflags & XFS_PQUOTA_ENFD) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* 728c2ecf20Sopenharmony_ci * Incore only flags for quotaoff - these bits get cleared when quota(s) 738c2ecf20Sopenharmony_ci * are in the process of getting turned off. These flags are in m_qflags but 748c2ecf20Sopenharmony_ci * never in sb_qflags. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_ci#define XFS_UQUOTA_ACTIVE 0x1000 /* uquotas are being turned off */ 778c2ecf20Sopenharmony_ci#define XFS_GQUOTA_ACTIVE 0x2000 /* gquotas are being turned off */ 788c2ecf20Sopenharmony_ci#define XFS_PQUOTA_ACTIVE 0x4000 /* pquotas are being turned off */ 798c2ecf20Sopenharmony_ci#define XFS_ALL_QUOTA_ACTIVE \ 808c2ecf20Sopenharmony_ci (XFS_UQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE) 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* 838c2ecf20Sopenharmony_ci * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees 848c2ecf20Sopenharmony_ci * quota will be not be switched off as long as that inode lock is held. 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_ci#define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \ 878c2ecf20Sopenharmony_ci XFS_GQUOTA_ACTIVE | \ 888c2ecf20Sopenharmony_ci XFS_PQUOTA_ACTIVE)) 898c2ecf20Sopenharmony_ci#define XFS_IS_UQUOTA_ON(mp) ((mp)->m_qflags & XFS_UQUOTA_ACTIVE) 908c2ecf20Sopenharmony_ci#define XFS_IS_GQUOTA_ON(mp) ((mp)->m_qflags & XFS_GQUOTA_ACTIVE) 918c2ecf20Sopenharmony_ci#define XFS_IS_PQUOTA_ON(mp) ((mp)->m_qflags & XFS_PQUOTA_ACTIVE) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * Flags to tell various functions what to do. Not all of these are meaningful 958c2ecf20Sopenharmony_ci * to a single function. None of these XFS_QMOPT_* flags are meant to have 968c2ecf20Sopenharmony_ci * persistent values (ie. their values can and will change between versions) 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci#define XFS_QMOPT_UQUOTA 0x0000004 /* user dquot requested */ 998c2ecf20Sopenharmony_ci#define XFS_QMOPT_PQUOTA 0x0000008 /* project dquot requested */ 1008c2ecf20Sopenharmony_ci#define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */ 1018c2ecf20Sopenharmony_ci#define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */ 1028c2ecf20Sopenharmony_ci#define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */ 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* 1058c2ecf20Sopenharmony_ci * flags to xfs_trans_mod_dquot to indicate which field needs to be 1068c2ecf20Sopenharmony_ci * modified. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci#define XFS_QMOPT_RES_REGBLKS 0x0010000 1098c2ecf20Sopenharmony_ci#define XFS_QMOPT_RES_RTBLKS 0x0020000 1108c2ecf20Sopenharmony_ci#define XFS_QMOPT_BCOUNT 0x0040000 1118c2ecf20Sopenharmony_ci#define XFS_QMOPT_ICOUNT 0x0080000 1128c2ecf20Sopenharmony_ci#define XFS_QMOPT_RTBCOUNT 0x0100000 1138c2ecf20Sopenharmony_ci#define XFS_QMOPT_DELBCOUNT 0x0200000 1148c2ecf20Sopenharmony_ci#define XFS_QMOPT_DELRTBCOUNT 0x0400000 1158c2ecf20Sopenharmony_ci#define XFS_QMOPT_RES_INOS 0x0800000 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* 1188c2ecf20Sopenharmony_ci * flags for dqalloc. 1198c2ecf20Sopenharmony_ci */ 1208c2ecf20Sopenharmony_ci#define XFS_QMOPT_INHERIT 0x1000000 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* 1238c2ecf20Sopenharmony_ci * flags to xfs_trans_mod_dquot. 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_RES_BLKS XFS_QMOPT_RES_REGBLKS 1268c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_RES_RTBLKS XFS_QMOPT_RES_RTBLKS 1278c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_RES_INOS XFS_QMOPT_RES_INOS 1288c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_BCOUNT XFS_QMOPT_BCOUNT 1298c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_DELBCOUNT XFS_QMOPT_DELBCOUNT 1308c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_ICOUNT XFS_QMOPT_ICOUNT 1318c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_RTBCOUNT XFS_QMOPT_RTBCOUNT 1328c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define XFS_QMOPT_QUOTALL \ 1368c2ecf20Sopenharmony_ci (XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA) 1378c2ecf20Sopenharmony_ci#define XFS_QMOPT_RESBLK_MASK (XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ciextern xfs_failaddr_t xfs_dquot_verify(struct xfs_mount *mp, 1408c2ecf20Sopenharmony_ci struct xfs_disk_dquot *ddq, xfs_dqid_t id); 1418c2ecf20Sopenharmony_ciextern xfs_failaddr_t xfs_dqblk_verify(struct xfs_mount *mp, 1428c2ecf20Sopenharmony_ci struct xfs_dqblk *dqb, xfs_dqid_t id); 1438c2ecf20Sopenharmony_ciextern int xfs_calc_dquots_per_chunk(unsigned int nbblks); 1448c2ecf20Sopenharmony_ciextern void xfs_dqblk_repair(struct xfs_mount *mp, struct xfs_dqblk *dqb, 1458c2ecf20Sopenharmony_ci xfs_dqid_t id, xfs_dqtype_t type); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistruct xfs_dquot; 1488c2ecf20Sopenharmony_citime64_t xfs_dquot_from_disk_ts(struct xfs_disk_dquot *ddq, 1498c2ecf20Sopenharmony_ci __be32 dtimer); 1508c2ecf20Sopenharmony_ci__be32 xfs_dquot_to_disk_ts(struct xfs_dquot *ddq, time64_t timer); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#endif /* __XFS_QUOTA_H__ */ 153