xref: /original-bsd/sys/ufs/ufs/quota.h (revision 27393bdf)
1 /*
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Robert Elz at The University of Melbourne.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)quota.h	8.3 (Berkeley) 08/19/94
11  */
12 
13 #ifndef _QUOTA_
14 #define _QUOTA_
15 
16 /*
17  * Definitions for disk quotas imposed on the average user
18  * (big brother finally hits UNIX).
19  *
20  * The following constants define the amount of time given a user before the
21  * soft limits are treated as hard limits (usually resulting in an allocation
22  * failure). The timer is started when the user crosses their soft limit, it
23  * is reset when they go below their soft limit.
24  */
25 #define	MAX_IQ_TIME	(7*24*60*60)	/* seconds in 1 week */
26 #define	MAX_DQ_TIME	(7*24*60*60)	/* seconds in 1 week */
27 
28 /*
29  * The following constants define the usage of the quota file array in the
30  * ufsmount structure and dquot array in the inode structure.  The semantics
31  * of the elements of these arrays are defined in the routine getinoquota;
32  * the remainder of the quota code treats them generically and need not be
33  * inspected when changing the size of the array.
34  */
35 #define	MAXQUOTAS	2
36 #define	USRQUOTA	0	/* element used for user quotas */
37 #define	GRPQUOTA	1	/* element used for group quotas */
38 
39 /*
40  * Definitions for the default names of the quotas files.
41  */
42 #define INITQFNAMES { \
43 	"user",		/* USRQUOTA */ \
44 	"group",	/* GRPQUOTA */ \
45 	"undefined", \
46 };
47 #define	QUOTAFILENAME	"quota"
48 #define	QUOTAGROUP	"operator"
49 
50 /*
51  * Command definitions for the 'quotactl' system call.  The commands are
52  * broken into a main command defined below and a subcommand that is used
53  * to convey the type of quota that is being manipulated (see above).
54  */
55 #define SUBCMDMASK	0x00ff
56 #define SUBCMDSHIFT	8
57 #define	QCMD(cmd, type)	(((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
58 
59 #define	Q_QUOTAON	0x0100	/* enable quotas */
60 #define	Q_QUOTAOFF	0x0200	/* disable quotas */
61 #define	Q_GETQUOTA	0x0300	/* get limits and usage */
62 #define	Q_SETQUOTA	0x0400	/* set limits and usage */
63 #define	Q_SETUSE	0x0500	/* set usage */
64 #define	Q_SYNC		0x0600	/* sync disk copy of a filesystems quotas */
65 
66 /*
67  * The following structure defines the format of the disk quota file
68  * (as it appears on disk) - the file is an array of these structures
69  * indexed by user or group number.  The setquota system call establishes
70  * the vnode for each quota file (a pointer is retained in the ufsmount
71  * structure).
72  */
73 struct dqblk {
74 	u_int32_t dqb_bhardlimit;	/* absolute limit on disk blks alloc */
75 	u_int32_t dqb_bsoftlimit;	/* preferred limit on disk blks */
76 	u_int32_t dqb_curblocks;	/* current block count */
77 	u_int32_t dqb_ihardlimit;	/* maximum # allocated inodes + 1 */
78 	u_int32_t dqb_isoftlimit;	/* preferred inode limit */
79 	u_int32_t dqb_curinodes;	/* current # allocated inodes */
80 	time_t	  dqb_btime;		/* time limit for excessive disk use */
81 	time_t	  dqb_itime;		/* time limit for excessive files */
82 };
83 
84 /*
85  * The following structure records disk usage for a user or group on a
86  * filesystem. There is one allocated for each quota that exists on any
87  * filesystem for the current user or group. A cache is kept of recently
88  * used entries.
89  */
90 struct dquot {
91 	LIST_ENTRY(dquot) dq_hash;	/* hash list */
92 	TAILQ_ENTRY(dquot) dq_freelist;	/* free list */
93 	u_int16_t dq_flags;		/* flags, see below */
94 	u_int16_t dq_cnt;		/* count of active references */
95 	u_int16_t dq_spare;		/* unused spare padding */
96 	u_int16_t dq_type;		/* quota type of this dquot */
97 	u_int32_t dq_id;		/* identifier this applies to */
98 	struct	ufsmount *dq_ump;	/* filesystem that this is taken from */
99 	struct	dqblk dq_dqb;		/* actual usage & quotas */
100 };
101 /*
102  * Flag values.
103  */
104 #define	DQ_LOCK		0x01		/* this quota locked (no MODS) */
105 #define	DQ_WANT		0x02		/* wakeup on unlock */
106 #define	DQ_MOD		0x04		/* this quota modified since read */
107 #define	DQ_FAKE		0x08		/* no limits here, just usage */
108 #define	DQ_BLKS		0x10		/* has been warned about blk limit */
109 #define	DQ_INODS	0x20		/* has been warned about inode limit */
110 /*
111  * Shorthand notation.
112  */
113 #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit
114 #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit
115 #define	dq_curblocks	dq_dqb.dqb_curblocks
116 #define	dq_ihardlimit	dq_dqb.dqb_ihardlimit
117 #define	dq_isoftlimit	dq_dqb.dqb_isoftlimit
118 #define	dq_curinodes	dq_dqb.dqb_curinodes
119 #define	dq_btime	dq_dqb.dqb_btime
120 #define	dq_itime	dq_dqb.dqb_itime
121 
122 /*
123  * If the system has never checked for a quota for this file, then it is
124  * set to NODQUOT.  Once a write attempt is made the inode pointer is set
125  * to reference a dquot structure.
126  */
127 #define	NODQUOT		NULL
128 
129 /*
130  * Flags to chkdq() and chkiq()
131  */
132 #define	FORCE	0x01	/* force usage changes independent of limits */
133 #define	CHOWN	0x02	/* (advisory) change initiated by chown */
134 
135 /*
136  * Macros to avoid subroutine calls to trivial functions.
137  */
138 #ifdef DIAGNOSTIC
139 #define	DQREF(dq)	dqref(dq)
140 #else
141 #define	DQREF(dq)	(dq)->dq_cnt++
142 #endif
143 
144 #include <sys/cdefs.h>
145 
146 struct dquot;
147 struct inode;
148 struct mount;
149 struct proc;
150 struct ucred;
151 struct ufsmount;
152 struct vnode;
153 __BEGIN_DECLS
154 int	chkdq __P((struct inode *, long, struct ucred *, int));
155 int	chkdqchg __P((struct inode *, long, struct ucred *, int));
156 int	chkiq __P((struct inode *, long, struct ucred *, int));
157 int	chkiqchg __P((struct inode *, long, struct ucred *, int));
158 void	dqflush __P((struct vnode *));
159 int	dqget __P((struct vnode *,
160 	    u_long, struct ufsmount *, int, struct dquot **));
161 void	dqinit __P((void));
162 void	dqref __P((struct dquot *));
163 void	dqrele __P((struct vnode *, struct dquot *));
164 int	dqsync __P((struct vnode *, struct dquot *));
165 int	getinoquota __P((struct inode *));
166 int	getquota __P((struct mount *, u_long, int, caddr_t));
167 int	qsync __P((struct mount *mp));
168 int	quotaoff __P((struct proc *, struct mount *, int));
169 int	quotaon __P((struct proc *, struct mount *, int, caddr_t));
170 int	setquota __P((struct mount *, u_long, int, caddr_t));
171 int	setuse __P((struct mount *, u_long, int, caddr_t));
172 int	ufs_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *));
173 __END_DECLS
174 
175 #ifdef DIAGNOSTIC
176 __BEGIN_DECLS
177 void	chkdquot __P((struct inode *));
178 __END_DECLS
179 #endif
180 
181 #endif /* _QUOTA_ */
182