File: /usr/include/linux/quota.h
1 /*
2 * Copyright (c) 1982, 1986 Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * Version: $Id: quota.h,v 2.0 1996/11/17 16:48:14 mvw Exp mvw $
37 */
38
39 #ifndef _LINUX_QUOTA_
40 #define _LINUX_QUOTA_
41
42 #include <linux/errno.h>
43 #include <linux/types.h>
44
45 typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
46 typedef __u64 qsize_t; /* Type in which we store size limitations */
47
48 #define MAXQUOTAS 2
49 #define USRQUOTA 0 /* element used for user quotas */
50 #define GRPQUOTA 1 /* element used for group quotas */
51
52 /*
53 * Definitions for the default names of the quotas files.
54 */
55 #define INITQFNAMES { \
56 "user", /* USRQUOTA */ \
57 "group", /* GRPQUOTA */ \
58 "undefined", \
59 }
60
61 /*
62 * Definitions of magics and versions of current quota files
63 */
64 #define INITQMAGICS {\
65 0xd9c01f11, /* USRQUOTA */\
66 0xd9c01927 /* GRPQUOTA */\
67 }
68
69 #define INITQVERSIONS {\
70 0, /* USRQUOTA */\
71 0 /* GRPQUOTA */\
72 }
73
74 #define QUOTAFILENAME "aquota"
75 #define QUOTAGROUP "staff"
76
77 /* Size of blocks in which are counted size limits */
78 #define QUOTABLOCK_BITS 10
79 #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
80
81 /* Conversion routines from and to quota blocks */
82 #define qb2kb(x) ((x) << (QUOTABLOCK_BITS-10))
83 #define kb2qb(x) ((x) >> (QUOTABLOCK_BITS-10))
84 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
85
86 /*
87 * Command definitions for the 'quotactl' system call.
88 * The commands are broken into a main command defined below
89 * and a subcommand that is used to convey the type of
90 * quota that is being manipulated (see above).
91 */
92 #define SUBCMDMASK 0x00ff
93 #define SUBCMDSHIFT 8
94 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
95
96 #define Q_QUOTAON 0x0100 /* enable quotas */
97 #define Q_QUOTAOFF 0x0200 /* disable quotas */
98 /* GETQUOTA, SETQUOTA and SETUSE which were at 0x0300-0x0500 has now other parameteres */
99 #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
100 #define Q_SETQLIM 0x0700 /* set limits */
101 #define Q_GETSTATS 0x0800 /* get collected stats */
102 #define Q_GETINFO 0x0900 /* get info about quotas - graces, flags... */
103 #define Q_SETINFO 0x0A00 /* set info about quotas */
104 #define Q_SETGRACE 0x0B00 /* set inode and block grace */
105 #define Q_SETFLAGS 0x0C00 /* set flags for quota */
106 #define Q_GETQUOTA 0x0D00 /* get limits and usage */
107 #define Q_SETQUOTA 0x0E00 /* set limits and usage */
108 #define Q_SETUSE 0x0F00 /* set usage */
109 /* 0x1000 used by old RSQUASH */
110
111 /*
112 * The following structure defines the format of the disk quota file
113 * (as it appears on disk) - the file is a hash table whose entries points
114 * to blocks of these structures.
115 */
116 struct disk_dqblk {
117 __u32 dqb_id; /* id this quota applies to */
118 __u32 dqb_ihardlimit; /* absolute limit on allocated inodes */
119 __u32 dqb_isoftlimit; /* preferred inode limit */
120 __u32 dqb_curinodes; /* current # allocated inodes */
121 __u32 dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
122 __u32 dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
123 __u64 dqb_curspace; /* current space occupied (in bytes) */
124 __u64 dqb_btime; /* time limit for excessive disk use */
125 __u64 dqb_itime; /* time limit for excessive inode use */
126 };
127
128 /* This is in-memory copy of quota block. See meaning of entries above */
129 struct mem_dqblk {
130 unsigned int dqb_ihardlimit;
131 unsigned int dqb_isoftlimit;
132 unsigned int dqb_curinodes;
133 unsigned int dqb_bhardlimit;
134 unsigned int dqb_bsoftlimit;
135 qsize_t dqb_curspace;
136 __kernel_time_t dqb_btime;
137 __kernel_time_t dqb_itime;
138 };
139
140 /*
141 * Here are header structures as written on disk and their in-memory copies
142 */
143 /* First generic header */
144 struct disk_dqheader {
145 __u32 dqh_magic; /* Magic number identifying file */
146 __u32 dqh_version; /* File version */
147 };
148
149 /* Header with type and version specific information */
150 struct disk_dqinfo {
151 __u32 dqi_bgrace; /* Time before block soft limit becomes hard limit */
152 __u32 dqi_igrace; /* Time before inode soft limit becomes hard limit */
153 __u32 dqi_flags; /* Flags for quotafile (DQF_*) */
154 __u32 dqi_blocks; /* Number of blocks in file */
155 __u32 dqi_free_blk; /* Number of first free block in the list */
156 __u32 dqi_free_entry; /* Number of block with at least one free entry */
157 };
158
159 /* Inmemory copy of version specific information */
160 struct mem_dqinfo {
161 unsigned int dqi_bgrace;
162 unsigned int dqi_igrace;
163 unsigned int dqi_flags;
164 unsigned int dqi_blocks;
165 unsigned int dqi_free_blk;
166 unsigned int dqi_free_entry;
167 };
168
169 /* Flags for version specific files */
170 #define DQF_MASK 0x0000 /* Mask for all valid ondisk flags */
171
172 #ifdef __KERNEL__
173 #define DQF_DIRTY 0x0010 /* Is info dirty? */
174 extern inline void mark_info_dirty(struct mem_dqinfo *info)
175 {
176 info->dqi_flags |= DQF_DIRTY;
177 }
178 #define info_dirty(info) ((info)->dqi_flags & DQF_DIRTY)
179 #endif
180 /*
181 * Structure of header of block with quota structures. It is padded to 16 bytes so
182 * there will be space for exactly 18 quota-entries in a block
183 */
184 struct disk_dqdbheader {
185 __u32 dqdh_next_free; /* Number of next block with free entry */
186 __u32 dqdh_prev_free; /* Number of previous block with free entry */
187 __u16 dqdh_entries; /* Number of valid entries in block */
188 __u16 dqdh_pad1;
189 __u32 dqdh_pad2;
190 };
191
192 #define DQINFOOFF sizeof(struct disk_dqheader) /* Offset of info header in file */
193 #define DQBLKSIZE_BITS 10
194 #define DQBLKSIZE (1 << DQBLKSIZE_BITS) /* Size of block with quota structures */
195 #define DQTREEOFF 1 /* Offset of tree in file in blocks */
196 #define DQTREEDEPTH 4 /* Depth of quota tree */
197 #define DQSTRINBLK ((DQBLKSIZE - sizeof(struct disk_dqdbheader)) / sizeof(struct disk_dqblk)) /* Number of entries in one blocks */
198
199 struct dqstats {
200 __u32 lookups;
201 __u32 drops;
202 __u32 reads;
203 __u32 writes;
204 __u32 cache_hits;
205 __u32 allocated_dquots;
206 __u32 free_dquots;
207 __u32 syncs;
208 };
209
210 #ifdef __KERNEL__
211
212 extern int nr_dquots, nr_free_dquots;
213
214 #define NR_DQHASH 43 /* Just an arbitrary number */
215
216 #define DQ_LOCKED 0x01 /* dquot under IO */
217 #define DQ_MOD 0x02 /* dquot modified since read */
218 #define DQ_BLKS 0x10 /* uid/gid has been warned about blk limit */
219 #define DQ_INODES 0x20 /* uid/gid has been warned about inode limit */
220 #define DQ_FAKE 0x40 /* no limits only usage */
221
222 struct dquot {
223 struct list_head dq_hash; /* Hash list in memory */
224 struct list_head dq_inuse; /* List of all quotas */
225 struct list_head dq_free; /* Free list element */
226 wait_queue_head_t dq_wait_lock; /* Pointer to waitqueue on dquot lock */
227 wait_queue_head_t dq_wait_free; /* Pointer to waitqueue for quota to be unused */
228 int dq_count; /* Reference count */
229
230 /* fields after this point are cleared when invalidating */
231 struct super_block *dq_sb; /* superblock this applies to */
232 qid_t dq_id; /* ID this applies to (uid, gid) */
233 kdev_t dq_dev; /* Device this applies to */
234 short dq_type; /* Type of quota */
235 short dq_flags; /* See DQ_* */
236 loff_t dq_off; /* Offset of structure in file (0 for not allocated) */
237 unsigned long dq_referenced; /* Number of times this dquot was
238 referenced during its lifetime */
239 struct mem_dqblk dq_dqb; /* Diskquota usage */
240 };
241
242 #define NODQUOT (struct dquot *)NULL
243
244 #define dq_curspace dq_dqb.dqb_curspace
245 #define dq_curinodes dq_dqb.dqb_curinodes
246 #define dq_isoftlimit dq_dqb.dqb_isoftlimit
247 #define dq_ihardlimit dq_dqb.dqb_ihardlimit
248 #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit
249 #define dq_bhardlimit dq_dqb.dqb_bhardlimit
250 #define dq_itime dq_dqb.dqb_itime
251 #define dq_btime dq_dqb.dqb_btime
252
253 /*
254 * Flags used for set_dqblk.
255 */
256 #define SET_QUOTA 0x01
257 #define SET_USE 0x02
258 #define SET_QLIMIT 0x04
259
260 /*
261 * Flags used for set_info
262 */
263 #define ISET_GRACE 0x01
264 #define ISET_FLAGS 0x02
265 #define ISET_ALL 0x03
266
267 #define QUOTA_OK 0
268 #define NO_QUOTA 1
269
270 typedef char *dqbuf_t;
271
272 #else
273
274 # /* nodep */ include <sys/cdefs.h>
275
276 __BEGIN_DECLS
277 long quotactl __P ((int, const char *, qid_t, __kernel_caddr_t));
278 __END_DECLS
279
280 #endif /* __KERNEL__ */
281 #endif /* _QUOTA_ */
282