xref: /original-bsd/sys/ufs/ufs/quota.h (revision 51e389b0)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * 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	7.9 (Berkeley) 02/22/91
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
21  * before the soft limits are treated as hard limits (usually resulting
22  * in an allocation failure). The timer is started when the user crosses
23  * their soft limit, it is reset when they go below their soft limit.
24  */
25 #define	MAX_IQ_TIME	(7*24*60*60)	/* 1 week */
26 #define	MAX_DQ_TIME	(7*24*60*60)	/* 1 week */
27 
28 /*
29  * The following constants define the usage of the quota file array
30  * in the ufsmount structure and dquot array in the inode structure.
31  * The semantics of the elements of these arrays are defined in the
32  * routine getinoquota; the remainder of the quota code treats them
33  * generically and need not be inspected when changing the size of
34  * the array.
35  */
36 #define	MAXQUOTAS	2
37 #define	USRQUOTA	0	/* element used for user quotas */
38 #define	GRPQUOTA	1	/* element used for group quotas */
39 
40 /*
41  * Definitions for the default names of the quotas files.
42  */
43 #define INITQFNAMES { \
44 	"user",		/* USRQUOTA */ \
45 	"group",	/* GRPQUOTA */ \
46 	"undefined", \
47 };
48 #define QUOTAFILENAME "quota"
49 #define QUOTAGROUP "operator"
50 
51 /*
52  * Command definitions for the 'quotactl' system call.
53  * The commands are broken into a main command defined below
54  * and a subcommand that is used to convey the type of
55  * quota that is being manipulated (see above).
56  */
57 #define SUBCMDMASK	0x00ff
58 #define SUBCMDSHIFT	8
59 #define	QCMD(cmd, type)	(((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
60 
61 #define	Q_QUOTAON	0x0100	/* enable quotas */
62 #define	Q_QUOTAOFF	0x0200	/* disable quotas */
63 #define	Q_GETQUOTA	0x0300	/* get limits and usage */
64 #define	Q_SETQUOTA	0x0400	/* set limits and usage */
65 #define	Q_SETUSE	0x0500	/* set usage */
66 #define	Q_SYNC		0x0600	/* sync disk copy of a filesystems quotas */
67 
68 /*
69  * The following structure defines the format of the disk quota file
70  * (as it appears on disk) - the file is an array of these structures
71  * indexed by user or group number.  The setquota system call establishes
72  * the vnode for each quota file (a pointer is retained in the ufsmount
73  * structure).
74  */
75 struct	dqblk {
76 	u_long	dqb_bhardlimit;	/* absolute limit on disk blks alloc */
77 	u_long	dqb_bsoftlimit;	/* preferred limit on disk blks */
78 	u_long	dqb_curblocks;	/* current block count */
79 	u_long	dqb_ihardlimit;	/* maximum # allocated inodes + 1 */
80 	u_long	dqb_isoftlimit;	/* preferred inode limit */
81 	u_long	dqb_curinodes;	/* current # allocated inodes */
82 	time_t	dqb_btime;	/* time limit for excessive disk use */
83 	time_t	dqb_itime;	/* time limit for excessive files */
84 };
85 
86 #ifdef KERNEL
87 /*
88  * The following structure records disk usage for a user or group on a
89  * filesystem. There is one allocated for each quota that exists on any
90  * filesystem for the current user or group. A cache is kept of recently
91  * used entries.
92  */
93 struct	dquot {
94 	struct	dquot *dq_forw, *dq_back;/* MUST be first entry */
95 	struct	dquot *dq_freef, **dq_freeb; /* free list */
96 	short	dq_flags;		/* flags, see below */
97 	short	dq_cnt;			/* count of active references */
98 	short	dq_spare;		/* unused spare padding */
99 	short	dq_type;		/* quota type of this dquot */
100 	u_long	dq_id;			/* identifier this applies to */
101 	struct	ufsmount *dq_ump;	/* filesystem that this is taken from */
102 	struct	dqblk dq_dqb;		/* actual usage & quotas */
103 };
104 /*
105  * Flag values.
106  */
107 #define	DQ_LOCK		0x01		/* this quota locked (no MODS) */
108 #define	DQ_WANT		0x02		/* wakeup on unlock */
109 #define	DQ_MOD		0x04		/* this quota modified since read */
110 #define	DQ_FAKE		0x08		/* no limits here, just usage */
111 #define	DQ_BLKS		0x10		/* has been warned about blk limit */
112 #define	DQ_INODS	0x20		/* has been warned about inode limit */
113 /*
114  * Shorthand notation.
115  */
116 #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit
117 #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit
118 #define	dq_curblocks	dq_dqb.dqb_curblocks
119 #define	dq_ihardlimit	dq_dqb.dqb_ihardlimit
120 #define	dq_isoftlimit	dq_dqb.dqb_isoftlimit
121 #define	dq_curinodes	dq_dqb.dqb_curinodes
122 #define	dq_btime	dq_dqb.dqb_btime
123 #define	dq_itime	dq_dqb.dqb_itime
124 
125 /*
126  * If the system has never checked for a quota for this file,
127  * then it is set to NODQUOT. Once a write attempt is made
128  * the inode pointer is set to reference a dquot structure.
129  */
130 #define	NODQUOT		((struct dquot *) 0)
131 
132 /*
133  * Flags to chkdq() and chkiq()
134  */
135 #define	FORCE	0x01	/* force usage changes independent of limits */
136 #define	CHOWN	0x02	/* (advisory) change initiated by chown */
137 
138 /*
139  * Macros to avoid subroutine calls to trivial functions.
140  */
141 #ifndef DIAGNOSTIC
142 #define	DQREF(dq)	(dq)->dq_cnt++
143 #else
144 #define	DQREF(dq)	dqref(dq)
145 #endif /* DIAGNOSTIC */
146 
147 #else
148 
149 #include <sys/cdefs.h>
150 
151 __BEGIN_DECLS
152 int	quotactl __P((const char *, int, int, void *));
153 __END_DECLS
154 
155 #endif /* KERNEL */
156 #endif /* _QUOTA_ */
157