xref: /illumos-gate/usr/src/uts/common/sys/fs/ufs_quota.h (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
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 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * Lock order for the quota sub-system:
49  *
50  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > dq_freelock
51  *  vfs_dqrwlock > ip.i_contents > dq_cachelock >                 dq_freelock
52  *  vfs_dqrwlock > ip.i_contents >                dquot.dq_lock > dq_freelock
53  *  vfs_dqrwlock > ip.i_contents >                                dq_freelock
54  *  vfs_dqrwlock > ip.i_contents > dq_cachelock > dquot.dq_lock > qip.i_contents
55  */
56 
57 /*
58  * The following constants define the default amount of time given a user
59  * before the soft limits are treated as hard limits (usually resulting
60  * in an allocation failure). These may be  modified by the quotactl
61  * system call with the Q_SETQLIM or Q_SETQUOTA commands.
62  */
63 
64 #define	DQ_FTIMELIMIT	(7 * 24*60*60)		/* 1 week */
65 #define	DQ_BTIMELIMIT	(7 * 24*60*60)		/* 1 week */
66 
67 /*
68  * The dqblk structure defines the format of the disk quota file
69  * (as it appears on disk) - the file is an array of these structures
70  * indexed by user number.  The setquota sys call establishes the inode
71  * for each quota file (a pointer is retained in the mount structure).
72  */
73 
74 struct dqblk {
75 	uint32_t  dqb_bhardlimit; /* absolute limit on disk blks alloc */
76 	uint32_t  dqb_bsoftlimit; /* preferred limit on disk blks */
77 	uint32_t  dqb_curblocks;  /* current block count */
78 	uint32_t  dqb_fhardlimit; /* maximum # allocated files + 1 */
79 	uint32_t  dqb_fsoftlimit; /* preferred file limit */
80 	uint32_t  dqb_curfiles;   /* current # allocated files */
81 	uint32_t  dqb_btimelimit; /* time limit for excessive disk use */
82 	uint32_t  dqb_ftimelimit; /* time limit for excessive files */
83 };
84 
85 #define	dqoff(UID)	(((offset_t)(UID) * sizeof (struct dqblk)))
86 
87 /*
88  * The dquot structure records disk usage for a user on a filesystem.
89  * There is one allocated for each quota that exists on any filesystem
90  * for the current user. A cache is kept of recently used entries.
91  * Active inodes have a pointer to the dquot associated with them.
92  */
93 struct  dquot {
94 	struct dquot *dq_forw, *dq_back; /* hash list, MUST be first entry */
95 	struct dquot *dq_freef, *dq_freeb; /* free list */
96 	short	dq_flags;
97 #define	DQ_ERROR	0x01		/* An error occurred reading dq */
98 #define	DQ_MOD		0x04		/* this quota modified since read */
99 #define	DQ_BLKS		0x10		/* has been warned about blk limit */
100 #define	DQ_FILES	0x20		/* has been warned about file limit */
101 #define	DQ_TRANS	0x40		/* logging ufs operation started */
102 	ulong_t	dq_cnt;			/* count of active references */
103 	uid_t	dq_uid;			/* user this applies to */
104 	struct ufsvfs *dq_ufsvfsp;	/* filesystem this relates to */
105 	offset_t dq_mof;		/* master disk offset of quota record */
106 	struct dqblk dq_dqb;		/* actual usage & quotas */
107 #ifdef _KERNEL
108 	kmutex_t	dq_lock;	/* per dq structure lock */
109 #endif /* _KERNEL */
110 };
111 
112 #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit
113 #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit
114 #define	dq_curblocks	dq_dqb.dqb_curblocks
115 #define	dq_fhardlimit	dq_dqb.dqb_fhardlimit
116 #define	dq_fsoftlimit	dq_dqb.dqb_fsoftlimit
117 #define	dq_curfiles	dq_dqb.dqb_curfiles
118 #define	dq_btimelimit	dq_dqb.dqb_btimelimit
119 #define	dq_ftimelimit	dq_dqb.dqb_ftimelimit
120 
121 /*
122  * flags for vfs_qflags in ufsvfs struct
123  */
124 #define	MQ_ENABLED	0x01		/* quotas are enabled */
125 
126 #if defined(_KERNEL)
127 
128 /*
129  * dquot chach hash chain headers
130  */
131 #define	NDQHASH		64			/* smallish power of two */
132 #define	DQHASH(uid, mp) \
133 	(((uintptr_t)(mp) + (unsigned)(uid)) & (NDQHASH-1))
134 
135 struct	dqhead {
136 	struct	dquot	*dqh_forw;	/* MUST be first */
137 	struct	dquot	*dqh_back;	/* MUST be second */
138 };
139 
140 extern struct dqhead dqhead[NDQHASH];
141 
142 extern struct dquot *dquot, *dquotNDQUOT;
143 extern int ndquot;
144 extern krwlock_t dq_rwlock;		/* quota sub-system init lock */
145 extern int quotas_initialized;		/* quota sub-system init flag */
146 
147 extern void qtinit();
148 extern void qtinit2();
149 extern struct dquot *getinoquota(struct inode *);
150 extern int chkdq(struct inode *ip, long, int, struct cred *, char **errp,
151 		size_t *lenp);
152 extern int chkiq(struct ufsvfs *, int, struct inode *, uid_t, int,
153 		struct cred *, char **errp, size_t *lenp);
154 extern void dqrele(struct dquot *);
155 extern int closedq(struct ufsvfs *, struct cred *);
156 extern int qsync(struct ufsvfs *);
157 
158 extern int getdiskquota(uid_t, struct ufsvfs *, int, struct dquot **);
159 extern void dqput(struct dquot *);
160 extern void dqupdate(struct dquot *);
161 extern void dqinval(struct dquot *);
162 extern void invalidatedq(struct ufsvfs *);
163 
164 extern int quotactl(struct vnode *, intptr_t, int flag, struct cred *);
165 
166 #endif	/* _KERNEL */
167 
168 /*
169  * Definitions for the 'quotactl' system call.
170  */
171 #define	Q_QUOTAON	1	/* turn quotas on */
172 #define	Q_QUOTAOFF	2	/* turn quotas off */
173 #define	Q_SETQUOTA	3	/* set disk limits & usage */
174 #define	Q_GETQUOTA	4	/* get disk limits & usage */
175 #define	Q_SETQLIM	5	/* set disk limits only */
176 #define	Q_SYNC		6	/* update disk copy of quota usages */
177 #define	Q_ALLSYNC	7	/* update disk copy of quota usages for all */
178 
179 #ifdef _SYSCALL32
180 /* ILP32 compatible structure for LP64 kernel. */
181 struct quotctl32 {
182 	int		op;
183 	uid_t		uid;
184 	uint32_t	addr;
185 };
186 #endif /* SYSCALL32 */
187 
188 struct quotctl {
189 	int	op;
190 	uid_t	uid;
191 	caddr_t	addr;
192 };
193 
194 #define	Q_QUOTACTL	0x00030189	/* ioctl command for quotactl */
195 
196 #ifdef	__cplusplus
197 }
198 #endif
199 
200 #endif	/* _SYS_FS_UFS_QUOTA_H */
201