Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / i386 / boot / dosboot / quota.h
1 /*\r
2  * Copyright (c) 1982, 1986 Regents of the University of California.\r
3  * All rights reserved.\r
4  *\r
5  * This code is derived from software contributed to Berkeley by\r
6  * Robert Elz at The University of Melbourne.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions\r
10  * are met:\r
11  * 1. Redistributions of source code must retain the above copyright\r
12  *    notice, this list of conditions and the following disclaimer.\r
13  * 2. Redistributions in binary form must reproduce the above copyright\r
14  *    notice, this list of conditions and the following disclaimer in the\r
15  *    documentation and/or other materials provided with the distribution.\r
16  * 3. All advertising materials mentioning features or use of this software\r
17  *    must display the following acknowledgement:\r
18  *      This product includes software developed by the University of\r
19  *      California, Berkeley and its contributors.\r
20  * 4. Neither the name of the University nor the names of its contributors\r
21  *    may be used to endorse or promote products derived from this software\r
22  *    without specific prior written permission.\r
23  *\r
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
34  * SUCH DAMAGE.\r
35  *\r
36  *      from: @(#)quota.h       7.9 (Berkeley) 2/22/91\r
37  * $FreeBSD: src/sys/i386/boot/dosboot/quota.h,v 1.6 1999/12/29 04:32:51 peter Exp $\r
38  */\r
39 \r
40 #ifndef _QUOTA_\r
41 #define _QUOTA_\r
42 \r
43 /*\r
44  * Definitions for disk quotas imposed on the average user\r
45  * (big brother finally hits UNIX).\r
46  *\r
47  * The following constants define the amount of time given a user\r
48  * before the soft limits are treated as hard limits (usually resulting\r
49  * in an allocation failure). The timer is started when the user crosses\r
50  * their soft limit, it is reset when they go below their soft limit.\r
51  */\r
52 #define MAX_IQ_TIME     (7*24*60*60)    /* 1 week */\r
53 #define MAX_DQ_TIME     (7*24*60*60)    /* 1 week */\r
54 \r
55 /*\r
56  * The following constants define the usage of the quota file array\r
57  * in the ufsmount structure and dquot array in the inode structure.\r
58  * The semantics of the elements of these arrays are defined in the\r
59  * routine getinoquota; the remainder of the quota code treats them\r
60  * generically and need not be inspected when changing the size of\r
61  * the array.\r
62  */\r
63 enum quotatype {\r
64         USRQUOTA = 0,   /* element used for user quotas */\r
65         GRPQUOTA = 1,   /* element used for group quotas */\r
66         MAXQUOTAS = 2\r
67 };\r
68 \r
69 /*\r
70  * Definitions for the default names of the quotas files.\r
71  */\r
72 #define INITQFNAMES { \\r
73         "user",         /* USRQUOTA */ \\r
74         "group",        /* GRPQUOTA */ \\r
75         "undefined", \\r
76 };\r
77 #define QUOTAFILENAME "quota"\r
78 #define QUOTAGROUP "operator"\r
79 \r
80 /*\r
81  * Command definitions for the 'quotactl' system call.\r
82  * The commands are broken into a main command defined below\r
83  * and a subcommand that is used to convey the type of\r
84  * quota that is being manipulated (see above).\r
85  */\r
86 #define SUBCMDMASK      0x00ff\r
87 #define SUBCMDSHIFT     8\r
88 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))\r
89 \r
90 #define Q_QUOTAON       0x0100  /* enable quotas */\r
91 #define Q_QUOTAOFF      0x0200  /* disable quotas */\r
92 #define Q_GETQUOTA      0x0300  /* get limits and usage */\r
93 #define Q_SETQUOTA      0x0400  /* set limits and usage */\r
94 #define Q_SETUSE        0x0500  /* set usage */\r
95 #define Q_SYNC          0x0600  /* sync disk copy of a filesystems quotas */\r
96 \r
97 /*\r
98  * The following structure defines the format of the disk quota file\r
99  * (as it appears on disk) - the file is an array of these structures\r
100  * indexed by user or group number.  The setquota system call establishes\r
101  * the vnode for each quota file (a pointer is retained in the ufsmount\r
102  * structure).\r
103  */\r
104 struct  dqblk {\r
105         u_long  dqb_bhardlimit; /* absolute limit on disk blks alloc */\r
106         u_long  dqb_bsoftlimit; /* preferred limit on disk blks */\r
107         u_long  dqb_curblocks;  /* current block count */\r
108         u_long  dqb_ihardlimit; /* maximum # allocated inodes + 1 */\r
109         u_long  dqb_isoftlimit; /* preferred inode limit */\r
110         u_long  dqb_curinodes;  /* current # allocated inodes */\r
111         time_t  dqb_btime;      /* time limit for excessive disk use */\r
112         time_t  dqb_itime;      /* time limit for excessive files */\r
113 };\r
114 \r
115 #ifdef KERNEL\r
116 /*\r
117  * The following structure records disk usage for a user or group on a\r
118  * filesystem. There is one allocated for each quota that exists on any\r
119  * filesystem for the current user or group. A cache is kept of recently\r
120  * used entries.\r
121  */\r
122 struct  dquot {\r
123         struct  dquot *dq_forw, *dq_back;/* MUST be first entry */\r
124         struct  dquot *dq_freef, **dq_freeb; /* free list */\r
125         short   dq_flags;               /* flags, see below */\r
126         short   dq_cnt;                 /* count of active references */\r
127         short   dq_spare;               /* unused spare padding */\r
128         short   dq_type;                /* quota type of this dquot */\r
129         u_long  dq_id;                  /* identifier this applies to */\r
130         struct  ufsmount *dq_ump;       /* filesystem that this is taken from */\r
131         struct  dqblk dq_dqb;           /* actual usage & quotas */\r
132 };\r
133 /*\r
134  * Flag values.\r
135  */\r
136 #define DQ_LOCK         0x01            /* this quota locked (no MODS) */\r
137 #define DQ_WANT         0x02            /* wakeup on unlock */\r
138 #define DQ_MOD          0x04            /* this quota modified since read */\r
139 #define DQ_FAKE         0x08            /* no limits here, just usage */\r
140 #define DQ_BLKS         0x10            /* has been warned about blk limit */\r
141 #define DQ_INODS        0x20            /* has been warned about inode limit */\r
142 /*\r
143  * Shorthand notation.\r
144  */\r
145 #define dq_bhardlimit   dq_dqb.dqb_bhardlimit\r
146 #define dq_bsoftlimit   dq_dqb.dqb_bsoftlimit\r
147 #define dq_curblocks    dq_dqb.dqb_curblocks\r
148 #define dq_ihardlimit   dq_dqb.dqb_ihardlimit\r
149 #define dq_isoftlimit   dq_dqb.dqb_isoftlimit\r
150 #define dq_curinodes    dq_dqb.dqb_curinodes\r
151 #define dq_btime        dq_dqb.dqb_btime\r
152 #define dq_itime        dq_dqb.dqb_itime\r
153 \r
154 /*\r
155  * If the system has never checked for a quota for this file,\r
156  * then it is set to NODQUOT. Once a write attempt is made\r
157  * the inode pointer is set to reference a dquot structure.\r
158  */\r
159 #define NODQUOT         ((struct dquot *) 0)\r
160 \r
161 /*\r
162  * Flags to chkdq() and chkiq()\r
163  */\r
164 #define FORCE   0x01    /* force usage changes independent of limits */\r
165 #define CHOWN   0x02    /* (advisory) change initiated by chown */\r
166 \r
167 /*\r
168  * Macros to avoid subroutine calls to trivial functions.\r
169  */\r
170 #ifndef DIAGNOSTIC\r
171 #define DQREF(dq)       (dq)->dq_cnt++\r
172 #else\r
173 #define DQREF(dq)       dqref(dq)\r
174 #endif /* DIAGNOSTIC */\r
175 \r
176 struct inode; struct ucred; struct mount; struct vnode;\r
177 \r
178 int getinoquota(struct inode *);\r
179 int chkdq(struct inode *, long, struct ucred *, int);\r
180 int chkdqchg(struct inode *, long, struct ucred *, enum quotatype);\r
181 int chkiq(struct inode *, long, struct ucred *, int);\r
182 int chkiqchg(struct inode *, long, struct ucred *, enum quotatype);\r
183 #ifdef DIAGNOSTIC\r
184 void chkdquot(struct inode *);\r
185 #endif\r
186 int quotaon(struct proc *, struct mount *, enum quotatype, caddr_t);\r
187 int quotaoff(struct proc *, struct mount *, enum quotatype);\r
188 int getquota(struct mount *, u_long, enum quotatype, caddr_t);\r
189 int setquota(struct mount *, u_long, enum quotatype, caddr_t);\r
190 int setuse(struct mount *, u_long, enum quotatype, caddr_t);\r
191 int qsync(struct mount *);\r
192 void dqinit(void);\r
193 int dqget(struct vnode *, u_long, struct ufsmount *, enum quotatype, struct dquot **);\r
194 void dqref(struct dquot *);\r
195 void dqrele(struct vnode *, struct dquot *);\r
196 int dqsync(struct vnode *, struct dquot *);\r
197 void dqflush(struct vnode *);\r
198 \r
199 #else\r
200 \r
201 #include "cdefs.h"\r
202 \r
203 __BEGIN_DECLS\r
204 int     quotactl __P((const char *, int, int, void *));\r
205 __END_DECLS\r
206 \r
207 #endif /* _KERNEL */\r
208 #endif /* _QUOTA_ */\r