/* * Copyright (c) 1982, 1986 Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Robert Elz at The University of Melbourne. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _LINUX_QUOTA_ #define _LINUX_QUOTA_ #include <linux/list.h> #include <linux/mutex.h> #include <linux/rwsem.h> #include <linux/spinlock.h> #include <linux/wait.h> #include <linux/percpu_counter.h> #include <linux/dqblk_xfs.h> #include <linux/dqblk_v1.h> #include <linux/dqblk_v2.h> #include <linux/atomic.h> #include <linux/uidgid.h> #include <linux/projid.h> #include <uapi/linux/quota.h> #undef USRQUOTA #undef GRPQUOTA #undef PRJQUOTA enum quota_type { … }; /* Masks for quota types when used as a bitmask */ #define QTYPE_MASK_USR … #define QTYPE_MASK_GRP … #define QTYPE_MASK_PRJ … qid_t; /* Type in which we store ids in memory */ qsize_t; /* Type in which we store sizes */ struct kqid { … }; extern bool qid_eq(struct kqid left, struct kqid right); extern bool qid_lt(struct kqid left, struct kqid right); extern qid_t from_kqid(struct user_namespace *to, struct kqid qid); extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid); extern bool qid_valid(struct kqid qid); /** * make_kqid - Map a user-namespace, type, qid tuple into a kqid. * @from: User namespace that the qid is in * @type: The type of quota * @qid: Quota identifier * * Maps a user-namespace, type qid tuple into a kernel internal * kqid, and returns that kqid. * * When there is no mapping defined for the user-namespace, type, * qid tuple an invalid kqid is returned. Callers are expected to * test for and handle invalid kqids being returned. * Invalid kqids may be tested for using qid_valid(). */ static inline struct kqid make_kqid(struct user_namespace *from, enum quota_type type, qid_t qid) { … } /** * make_kqid_invalid - Explicitly make an invalid kqid * @type: The type of quota identifier * * Returns an invalid kqid with the specified type. */ static inline struct kqid make_kqid_invalid(enum quota_type type) { … } /** * make_kqid_uid - Make a kqid from a kuid * @uid: The kuid to make the quota identifier from */ static inline struct kqid make_kqid_uid(kuid_t uid) { … } /** * make_kqid_gid - Make a kqid from a kgid * @gid: The kgid to make the quota identifier from */ static inline struct kqid make_kqid_gid(kgid_t gid) { … } /** * make_kqid_projid - Make a kqid from a projid * @projid: The kprojid to make the quota identifier from */ static inline struct kqid make_kqid_projid(kprojid_t projid) { … } /** * qid_has_mapping - Report if a qid maps into a user namespace. * @ns: The user namespace to see if a value maps into. * @qid: The kernel internal quota identifier to test. */ static inline bool qid_has_mapping(struct user_namespace *ns, struct kqid qid) { … } extern spinlock_t dq_data_lock; /* Maximal numbers of writes for quota operation (insert/delete/update) * (over VFS all formats) */ #define DQUOT_INIT_ALLOC … #define DQUOT_INIT_REWRITE … #define DQUOT_DEL_ALLOC … #define DQUOT_DEL_REWRITE … /* * Data for one user/group kept in memory */ struct mem_dqblk { … }; /* * Data for one quotafile kept in memory */ struct quota_format_type; struct mem_dqinfo { … }; struct super_block; /* Mask for flags passed to userspace */ #define DQF_GETINFO_MASK … /* Mask for flags modifiable from userspace */ #define DQF_SETINFO_MASK … enum { … }; #define DQF_INFO_DIRTY … extern void mark_info_dirty(struct super_block *sb, int type); static inline int info_dirty(struct mem_dqinfo *info) { … } enum { … }; struct dqstats { … }; extern struct dqstats dqstats; static inline void dqstats_inc(unsigned int type) { … } static inline void dqstats_dec(unsigned int type) { … } #define DQ_MOD_B … #define DQ_BLKS_B … #define DQ_INODES_B … #define DQ_FAKE_B … #define DQ_READ_B … #define DQ_ACTIVE_B … #define DQ_RELEASING_B … #define DQ_LASTSET_B … struct dquot { … }; /* Operations which must be implemented by each quota format */ struct quota_format_ops { … }; /* Operations working with dquots */ struct dquot_operations { … }; struct path; /* Structure for communicating via ->get_dqblk() & ->set_dqblk() */ struct qc_dqblk { … }; /* * Field specifiers for ->set_dqblk() in struct qc_dqblk and also for * ->set_info() in struct qc_info */ #define QC_INO_SOFT … #define QC_INO_HARD … #define QC_SPC_SOFT … #define QC_SPC_HARD … #define QC_RT_SPC_SOFT … #define QC_RT_SPC_HARD … #define QC_LIMIT_MASK … #define QC_SPC_TIMER … #define QC_INO_TIMER … #define QC_RT_SPC_TIMER … #define QC_TIMER_MASK … #define QC_SPC_WARNS … #define QC_INO_WARNS … #define QC_RT_SPC_WARNS … #define QC_WARNS_MASK … #define QC_SPACE … #define QC_INO_COUNT … #define QC_RT_SPACE … #define QC_ACCT_MASK … #define QC_FLAGS … #define QCI_SYSFILE … #define QCI_ROOT_SQUASH … #define QCI_ACCT_ENABLED … #define QCI_LIMITS_ENFORCED … /* Structures for communicating via ->get_state */ struct qc_type_state { … }; struct qc_state { … }; /* Structure for communicating via ->set_info */ struct qc_info { … }; /* Operations handling requests from userspace */ struct quotactl_ops { … }; struct quota_format_type { … }; /** * Quota state flags - they come in three flavors - for users, groups and projects. * * Actual typed flags layout: * USRQUOTA GRPQUOTA PRJQUOTA * DQUOT_USAGE_ENABLED 0x0001 0x0002 0x0004 * DQUOT_LIMITS_ENABLED 0x0008 0x0010 0x0020 * DQUOT_SUSPENDED 0x0040 0x0080 0x0100 * * Following bits are used for non-typed flags: * DQUOT_QUOTA_SYS_FILE 0x0200 * DQUOT_NEGATIVE_USAGE 0x0400 * DQUOT_NOLIST_DIRTY 0x0800 */ enum { … }; #define DQUOT_USAGE_ENABLED … #define DQUOT_LIMITS_ENABLED … #define DQUOT_SUSPENDED … #define DQUOT_STATE_FLAGS … /* Other quota flags */ #define DQUOT_STATE_LAST … #define DQUOT_QUOTA_SYS_FILE … /* Quota file is a special * system file and user cannot * touch it. Filesystem is * responsible for setting * S_NOQUOTA, S_NOATIME flags */ #define DQUOT_NEGATIVE_USAGE … /* Allow negative quota usage */ /* Do not track dirty dquots in a list */ #define DQUOT_NOLIST_DIRTY … static inline unsigned int dquot_state_flag(unsigned int flags, int type) { … } static inline unsigned int dquot_generic_flag(unsigned int flags, int type) { … } /* Bitmap of quota types where flag is set in flags */ static __always_inline unsigned dquot_state_types(unsigned flags, unsigned flag) { … } #ifdef CONFIG_QUOTA_NETLINK_INTERFACE extern void quota_send_warning(struct kqid qid, dev_t dev, const char warntype); #else static inline void quota_send_warning(struct kqid qid, dev_t dev, const char warntype) { return; } #endif /* CONFIG_QUOTA_NETLINK_INTERFACE */ struct quota_info { … }; int register_quota_format(struct quota_format_type *fmt); void unregister_quota_format(struct quota_format_type *fmt); struct quota_module_name { … }; #define INIT_QUOTA_MODULE_NAMES … #endif /* _QUOTA_ */