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