xref: /titanic_52/usr/src/uts/common/sys/fs/ufs_quota.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_UFS_QUOTA_H
41*7c478bd9Sstevel@tonic-gate #define	_SYS_FS_UFS_QUOTA_H
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
46*7c478bd9Sstevel@tonic-gate extern "C" {
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * Lock order for the quota sub-system:
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > dq_freelock
53*7c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock >                 dq_freelock
54*7c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents >                dquot.dq_lock > dq_freelock
55*7c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents >                                dq_freelock
56*7c478bd9Sstevel@tonic-gate  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > qip.i_contents
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * The following constants define the default amount of time given a user
61*7c478bd9Sstevel@tonic-gate  * before the soft limits are treated as hard limits (usually resulting
62*7c478bd9Sstevel@tonic-gate  * in an allocation failure). These may be  modified by the quotactl
63*7c478bd9Sstevel@tonic-gate  * system call with the Q_SETQLIM or Q_SETQUOTA commands.
64*7c478bd9Sstevel@tonic-gate  */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #define	DQ_FTIMELIMIT	(7 * 24*60*60)		/* 1 week */
67*7c478bd9Sstevel@tonic-gate #define	DQ_BTIMELIMIT	(7 * 24*60*60)		/* 1 week */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate /*
70*7c478bd9Sstevel@tonic-gate  * The dqblk structure defines the format of the disk quota file
71*7c478bd9Sstevel@tonic-gate  * (as it appears on disk) - the file is an array of these structures
72*7c478bd9Sstevel@tonic-gate  * indexed by user number.  The setquota sys call establishes the inode
73*7c478bd9Sstevel@tonic-gate  * for each quota file (a pointer is retained in the mount structure).
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate struct dqblk {
77*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_bhardlimit; /* absolute limit on disk blks alloc */
78*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_bsoftlimit; /* preferred limit on disk blks */
79*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_curblocks;  /* current block count */
80*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_fhardlimit; /* maximum # allocated files + 1 */
81*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_fsoftlimit; /* preferred file limit */
82*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_curfiles;   /* current # allocated files */
83*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_btimelimit; /* time limit for excessive disk use */
84*7c478bd9Sstevel@tonic-gate 	uint32_t  dqb_ftimelimit; /* time limit for excessive files */
85*7c478bd9Sstevel@tonic-gate };
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #define	dqoff(UID)	(((offset_t)(UID) * sizeof (struct dqblk)))
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * The dquot structure records disk usage for a user on a filesystem.
91*7c478bd9Sstevel@tonic-gate  * There is one allocated for each quota that exists on any filesystem
92*7c478bd9Sstevel@tonic-gate  * for the current user. A cache is kept of recently used entries.
93*7c478bd9Sstevel@tonic-gate  * Active inodes have a pointer to the dquot associated with them.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate struct  dquot {
96*7c478bd9Sstevel@tonic-gate 	struct dquot *dq_forw, *dq_back; /* hash list, MUST be first entry */
97*7c478bd9Sstevel@tonic-gate 	struct dquot *dq_freef, *dq_freeb; /* free list */
98*7c478bd9Sstevel@tonic-gate 	short	dq_flags;
99*7c478bd9Sstevel@tonic-gate #define	DQ_ERROR	0x01		/* An error occurred reading dq */
100*7c478bd9Sstevel@tonic-gate #define	DQ_MOD		0x04		/* this quota modified since read */
101*7c478bd9Sstevel@tonic-gate #define	DQ_BLKS		0x10		/* has been warned about blk limit */
102*7c478bd9Sstevel@tonic-gate #define	DQ_FILES	0x20		/* has been warned about file limit */
103*7c478bd9Sstevel@tonic-gate #define	DQ_TRANS	0x40		/* logging ufs operation started */
104*7c478bd9Sstevel@tonic-gate 	ulong_t	dq_cnt;			/* count of active references */
105*7c478bd9Sstevel@tonic-gate 	uid_t	dq_uid;			/* user this applies to */
106*7c478bd9Sstevel@tonic-gate 	struct ufsvfs *dq_ufsvfsp;	/* filesystem this relates to */
107*7c478bd9Sstevel@tonic-gate 	offset_t dq_mof;		/* master disk offset of quota record */
108*7c478bd9Sstevel@tonic-gate 	struct dqblk dq_dqb;		/* actual usage & quotas */
109*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
110*7c478bd9Sstevel@tonic-gate 	kmutex_t	dq_lock;	/* per dq structure lock */
111*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
112*7c478bd9Sstevel@tonic-gate };
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit
115*7c478bd9Sstevel@tonic-gate #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit
116*7c478bd9Sstevel@tonic-gate #define	dq_curblocks	dq_dqb.dqb_curblocks
117*7c478bd9Sstevel@tonic-gate #define	dq_fhardlimit	dq_dqb.dqb_fhardlimit
118*7c478bd9Sstevel@tonic-gate #define	dq_fsoftlimit	dq_dqb.dqb_fsoftlimit
119*7c478bd9Sstevel@tonic-gate #define	dq_curfiles	dq_dqb.dqb_curfiles
120*7c478bd9Sstevel@tonic-gate #define	dq_btimelimit	dq_dqb.dqb_btimelimit
121*7c478bd9Sstevel@tonic-gate #define	dq_ftimelimit	dq_dqb.dqb_ftimelimit
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate /*
124*7c478bd9Sstevel@tonic-gate  * flags for vfs_qflags in ufsvfs struct
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate #define	MQ_ENABLED	0x01		/* quotas are enabled */
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /*
131*7c478bd9Sstevel@tonic-gate  * dquot chach hash chain headers
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate #define	NDQHASH		64			/* smallish power of two */
134*7c478bd9Sstevel@tonic-gate #define	DQHASH(uid, mp) \
135*7c478bd9Sstevel@tonic-gate 	(((uintptr_t)(mp) + (unsigned)(uid)) & (NDQHASH-1))
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate struct	dqhead {
138*7c478bd9Sstevel@tonic-gate 	struct	dquot	*dqh_forw;	/* MUST be first */
139*7c478bd9Sstevel@tonic-gate 	struct	dquot	*dqh_back;	/* MUST be second */
140*7c478bd9Sstevel@tonic-gate };
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate extern struct dqhead dqhead[NDQHASH];
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate extern struct dquot *dquot, *dquotNDQUOT;
145*7c478bd9Sstevel@tonic-gate extern int ndquot;
146*7c478bd9Sstevel@tonic-gate extern krwlock_t dq_rwlock;		/* quota sub-system init lock */
147*7c478bd9Sstevel@tonic-gate extern int quotas_initialized;		/* quota sub-system init flag */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate extern void qtinit();
150*7c478bd9Sstevel@tonic-gate extern void qtinit2();
151*7c478bd9Sstevel@tonic-gate extern struct dquot *getinoquota(struct inode *);
152*7c478bd9Sstevel@tonic-gate extern int chkdq(struct inode *ip, long, int, struct cred *, char **errp,
153*7c478bd9Sstevel@tonic-gate 		size_t *lenp);
154*7c478bd9Sstevel@tonic-gate extern int chkiq(struct ufsvfs *, int, struct inode *, uid_t, int,
155*7c478bd9Sstevel@tonic-gate 		struct cred *, char **errp, size_t *lenp);
156*7c478bd9Sstevel@tonic-gate extern void dqrele(struct dquot *);
157*7c478bd9Sstevel@tonic-gate extern int closedq(struct ufsvfs *, struct cred *);
158*7c478bd9Sstevel@tonic-gate extern int qsync(struct ufsvfs *);
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate extern int getdiskquota(uid_t, struct ufsvfs *, int, struct dquot **);
161*7c478bd9Sstevel@tonic-gate extern void dqput(struct dquot *);
162*7c478bd9Sstevel@tonic-gate extern void dqupdate(struct dquot *);
163*7c478bd9Sstevel@tonic-gate extern void dqinval(struct dquot *);
164*7c478bd9Sstevel@tonic-gate extern void invalidatedq(struct ufsvfs *);
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate extern int quotactl(struct vnode *, intptr_t, int flag, struct cred *);
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * Definitions for the 'quotactl' system call.
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate #define	Q_QUOTAON	1	/* turn quotas on */
174*7c478bd9Sstevel@tonic-gate #define	Q_QUOTAOFF	2	/* turn quotas off */
175*7c478bd9Sstevel@tonic-gate #define	Q_SETQUOTA	3	/* set disk limits & usage */
176*7c478bd9Sstevel@tonic-gate #define	Q_GETQUOTA	4	/* get disk limits & usage */
177*7c478bd9Sstevel@tonic-gate #define	Q_SETQLIM	5	/* set disk limits only */
178*7c478bd9Sstevel@tonic-gate #define	Q_SYNC		6	/* update disk copy of quota usages */
179*7c478bd9Sstevel@tonic-gate #define	Q_ALLSYNC	7	/* update disk copy of quota usages for all */
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
182*7c478bd9Sstevel@tonic-gate /* ILP32 compatible structure for LP64 kernel. */
183*7c478bd9Sstevel@tonic-gate struct quotctl32 {
184*7c478bd9Sstevel@tonic-gate 	int		op;
185*7c478bd9Sstevel@tonic-gate 	uid_t		uid;
186*7c478bd9Sstevel@tonic-gate 	uint32_t	addr;
187*7c478bd9Sstevel@tonic-gate };
188*7c478bd9Sstevel@tonic-gate #endif /* SYSCALL32 */
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate struct quotctl {
191*7c478bd9Sstevel@tonic-gate 	int	op;
192*7c478bd9Sstevel@tonic-gate 	uid_t	uid;
193*7c478bd9Sstevel@tonic-gate 	caddr_t	addr;
194*7c478bd9Sstevel@tonic-gate };
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate #define	Q_QUOTACTL	0x00030189	/* ioctl command for quotactl */
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate #endif
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_UFS_QUOTA_H */
203