FreeBSD/Linux Kernel Cross Reference
sys/bsd/sys/quota.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1982, 1986, 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * This code is derived from software contributed to Berkeley by
30 * Robert Elz at The University of Melbourne.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)quota.h
61 * derived from @(#)ufs/ufs/quota.h 8.3 (Berkeley) 8/19/94
62 */
63
64 #ifndef _SYS_QUOTA_H
65 #define _SYS_QUOTA_H
66
67 #include <sys/appleapiopts.h>
68
69 #ifdef __APPLE_API_UNSTABLE
70 /*
71 * Definitions for disk quotas imposed on the average user
72 * (big brother finally hits UNIX).
73 *
74 * The following constants define the amount of time given a user before the
75 * soft limits are treated as hard limits (usually resulting in an allocation
76 * failure). The timer is started when the user crosses their soft limit, it
77 * is reset when they go below their soft limit.
78 */
79 #define MAX_IQ_TIME (7*24*60*60) /* seconds in 1 week */
80 #define MAX_DQ_TIME (7*24*60*60) /* seconds in 1 week */
81
82 /*
83 * The following constants define the usage of the quota file array in the
84 * file system mount structure and dquot array in the inode structure. The semantics
85 * of the elements of these arrays are defined in the routine getinoquota;
86 * the remainder of the quota code treats them generically and need not be
87 * inspected when changing the size of the array.
88 */
89 #define MAXQUOTAS 2
90 #define USRQUOTA 0 /* element used for user quotas */
91 #define GRPQUOTA 1 /* element used for group quotas */
92
93 /*
94 * Definitions for the default names of the quotas files.
95 */
96 #define INITQFNAMES { \
97 "user", /* USRQUOTA */ \
98 "group", /* GRPQUOTA */ \
99 "undefined", \
100 };
101 #define QUOTAFILENAME ".quota"
102 #define QUOTAOPSNAME ".quota.ops"
103 #define QUOTAGROUP "operator"
104
105 /*
106 * Command definitions for the 'quotactl' system call. The commands are
107 * broken into a main command defined below and a subcommand that is used
108 * to convey the type of quota that is being manipulated (see above).
109 */
110 #define SUBCMDMASK 0x00ff
111 #define SUBCMDSHIFT 8
112 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
113
114 #define Q_QUOTAON 0x0100 /* enable quotas */
115 #define Q_QUOTAOFF 0x0200 /* disable quotas */
116 #define Q_GETQUOTA 0x0300 /* get limits and usage */
117 #define Q_SETQUOTA 0x0400 /* set limits and usage */
118 #define Q_SETUSE 0x0500 /* set usage */
119 #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
120 #define Q_QUOTASTAT 0x0700 /* get quota on/off status */
121
122 /*
123 * The following two structures define the format of the disk
124 * quota file (as it appears on disk) - the file contains a
125 * header followed by a hash table of dqblk entries. To find
126 * a particular entry, the user or group number (id) is first
127 * converted to an index into this table by means of the hash
128 * function dqhash1. If there is a collision at that index
129 * location then a second hash value is computed which using
130 * dqhash2. This second hash value is then used as an offset
131 * to the next location to probe. ID = 0 is used to indicate
132 * an empty (unused) entry. So there can never be an entry in
133 * the quota file for user 0 or group 0 (which is OK since disk
134 * quotas are never enforced for user 0).
135 *
136 * The setquota system call establishes the vnode for each quota
137 * file (a pointer is retained in the filesystem mount structure).
138 */
139 struct dqfilehdr {
140 u_int32_t dqh_magic;
141 u_int32_t dqh_version; /* == QF_VERSION */
142 u_int32_t dqh_maxentries; /* must be a power of 2 */
143 u_int32_t dqh_entrycnt; /* count of active entries */
144 u_int32_t dqh_flags; /* reserved for now (0) */
145 time_t dqh_chktime; /* time of last quota check */
146 time_t dqh_btime; /* time limit for excessive disk use */
147 time_t dqh_itime; /* time limit for excessive files */
148 char dqh_string[16]; /* tag string */
149 u_int32_t dqh_spare[4]; /* pad struct to power of 2 */
150 };
151
152 struct dqblk {
153 u_int64_t dqb_bhardlimit; /* absolute limit on disk bytes alloc */
154 u_int64_t dqb_bsoftlimit; /* preferred limit on disk bytes */
155 u_int64_t dqb_curbytes; /* current byte count */
156 u_int32_t dqb_ihardlimit; /* maximum # allocated inodes + 1 */
157 u_int32_t dqb_isoftlimit; /* preferred inode limit */
158 u_int32_t dqb_curinodes; /* current # allocated inodes */
159 time_t dqb_btime; /* time limit for excessive disk use */
160 time_t dqb_itime; /* time limit for excessive files */
161 u_int32_t dqb_id; /* identifier (0 for empty entries) */
162 u_int32_t dqb_spare[4]; /* pad struct to power of 2 */
163 };
164
165
166 #define INITQMAGICS { \
167 0xff31ff35, /* USRQUOTA */ \
168 0xff31ff27, /* GRPQUOTA */ \
169 };
170
171 #define QF_VERSION 1
172 #define QF_STRING_TAG "QUOTA HASH FILE"
173
174 #define QF_USERS_PER_GB 256
175 #define QF_MIN_USERS 2048
176 #define QF_MAX_USERS (2048*1024)
177
178 #define QF_GROUPS_PER_GB 32
179 #define QF_MIN_GROUPS 2048
180 #define QF_MAX_GROUPS (256*1024)
181
182
183 /*
184 * The primary and secondary multiplicative hash functions are
185 * derived from Knuth (vol. 3). They use a prime that is in
186 * golden ratio to the machine's word size.
187 */
188 #define dqhash1(id, shift, mask) \
189 ((((id) * 2654435761UL) >> (shift)) & (mask))
190
191 #define dqhash2(id, mask) \
192 (dqhash1((id), 11, (mask)>>1) | 1)
193
194 /*
195 * Compute a disk offset into a quota file.
196 */
197 #define dqoffset(index) \
198 (sizeof (struct dqfilehdr) + ((index) * sizeof (struct dqblk)))
199 /*
200 * Compute the hash shift value.
201 * It is the word size, in bits, minus the hash table size, in bits.
202 */
203 static __inline int dqhashshift(u_long);
204
205 static __inline int
206 dqhashshift(u_long size)
207 {
208 int shift;
209
210 for (shift = 32; size > 1; size >>= 1, --shift)
211 continue;
212 return (shift);
213 }
214
215
216 #ifndef KERNEL
217
218 #include <sys/cdefs.h>
219
220 __BEGIN_DECLS
221 int quotactl __P((char *, int, int, caddr_t));
222 __END_DECLS
223 #endif /* !KERNEL */
224
225 #ifdef KERNEL
226 #include <sys/queue.h>
227
228 /*
229 * Macros to avoid subroutine calls to trivial functions.
230 */
231 #if DIAGNOSTIC
232 #define DQREF(dq) dqref(dq)
233 #else
234 #define DQREF(dq) (dq)->dq_cnt++
235 #endif
236
237
238 /* Quota file info
239 */
240 struct quotafile {
241 struct vnode *qf_vp; /* quota file vnode */
242 struct ucred *qf_cred; /* quota file access cred */
243 int qf_shift; /* primary hash shift */
244 int qf_maxentries; /* size of hash table (power of 2) */
245 int qf_entrycnt; /* count of active entries */
246 time_t qf_btime; /* block quota time limit */
247 time_t qf_itime; /* inode quota time limit */
248 char qf_qflags; /* quota specific flags */
249 };
250
251 /*
252 * Flags describing the runtime state of quotas.
253 * (in qf_qflags)
254 */
255 #define QTF_OPENING 0x01 /* Q_QUOTAON in progress */
256 #define QTF_CLOSING 0x02 /* Q_QUOTAOFF in progress */
257
258
259 /*
260 * The following structure records disk usage for a user or group on a
261 * filesystem. There is one allocated for each quota that exists on any
262 * filesystem for the current user or group. A cache is kept of recently
263 * used entries.
264 */
265 struct dquot {
266 LIST_ENTRY(dquot) dq_hash; /* hash list */
267 TAILQ_ENTRY(dquot) dq_freelist; /* free list */
268 u_int16_t dq_flags; /* flags, see below */
269 u_int16_t dq_cnt; /* count of active references */
270 u_int16_t dq_spare; /* unused spare padding */
271 u_int16_t dq_type; /* quota type of this dquot */
272 u_int32_t dq_id; /* identifier this applies to */
273 u_int32_t dq_index; /* index into quota file */
274 struct quotafile *dq_qfile; /* quota file that this is taken from */
275 struct dqblk dq_dqb; /* actual usage & quotas */
276 };
277 /*
278 * Flag values.
279 */
280 #define DQ_LOCK 0x01 /* this quota locked (no MODS) */
281 #define DQ_WANT 0x02 /* wakeup on unlock */
282 #define DQ_MOD 0x04 /* this quota modified since read */
283 #define DQ_FAKE 0x08 /* no limits here, just usage */
284 #define DQ_BLKS 0x10 /* has been warned about blk limit */
285 #define DQ_INODS 0x20 /* has been warned about inode limit */
286 /*
287 * Shorthand notation.
288 */
289 #define dq_bhardlimit dq_dqb.dqb_bhardlimit
290 #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit
291 #define dq_curbytes dq_dqb.dqb_curbytes
292 #define dq_ihardlimit dq_dqb.dqb_ihardlimit
293 #define dq_isoftlimit dq_dqb.dqb_isoftlimit
294 #define dq_curinodes dq_dqb.dqb_curinodes
295 #define dq_btime dq_dqb.dqb_btime
296 #define dq_itime dq_dqb.dqb_itime
297
298 /*
299 * If the system has never checked for a quota for this file, then it is
300 * set to NODQUOT. Once a write attempt is made the inode pointer is set
301 * to reference a dquot structure.
302 */
303 #define NODQUOT NULL
304
305 /*
306 * Flags to chkdq() and chkiq()
307 */
308 #define FORCE 0x01 /* force usage changes independent of limits */
309 #define CHOWN 0x02 /* (advisory) change initiated by chown */
310
311
312 /*
313 * Functions that manage the in-core dquot and the
314 * on-disk dqblk data structures.
315 */
316 __BEGIN_DECLS
317 int dqfileopen(struct quotafile *, int);
318 void dqfileclose(struct quotafile *, int);
319 void dqflush(struct vnode *);
320 int dqget(struct vnode *, u_long, struct quotafile *, int, struct dquot **);
321 void dqinit(void);
322 void dqref(struct dquot *);
323 void dqrele(struct vnode *, struct dquot *);
324 void dqreclaim(struct vnode *, struct dquot *);
325 int dqsync(struct vnode *, struct dquot *);
326 void dqsync_orphans(struct quotafile *);
327 __END_DECLS
328
329 #endif /* KERNEL */
330
331 #endif /* __APPLE_API_UNSTABLE */
332
333 #endif /* !_SYS_QUOTA_H_ */
Cache object: b399f012a15b4b143ba68ccf7d8c4f34
|