1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef _LINUX_QUOTA_
34#define _LINUX_QUOTA_
35
36#include <linux/errno.h>
37#include <linux/types.h>
38
39#define __DQUOT_VERSION__ "dquot_6.5.2"
40
41#define MAXQUOTAS 2
42#define USRQUOTA 0
43#define GRPQUOTA 1
44
45
46
47
48#define INITQFNAMES { \
49 "user", \
50 "group", \
51 "undefined", \
52};
53
54
55
56
57
58
59
60#define SUBCMDMASK 0x00ff
61#define SUBCMDSHIFT 8
62#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
63
64#define Q_SYNC 0x800001
65#define Q_QUOTAON 0x800002
66#define Q_QUOTAOFF 0x800003
67#define Q_GETFMT 0x800004
68#define Q_GETINFO 0x800005
69#define Q_SETINFO 0x800006
70#define Q_GETQUOTA 0x800007
71#define Q_SETQUOTA 0x800008
72
73
74#define QFMT_VFS_OLD 1
75#define QFMT_VFS_V0 2
76
77
78
79#define QIF_DQBLKSIZE_BITS 10
80#define QIF_DQBLKSIZE (1 << QIF_DQBLKSIZE_BITS)
81
82
83
84
85
86enum {
87 QIF_BLIMITS_B = 0,
88 QIF_SPACE_B,
89 QIF_ILIMITS_B,
90 QIF_INODES_B,
91 QIF_BTIME_B,
92 QIF_ITIME_B,
93};
94
95#define QIF_BLIMITS (1 << QIF_BLIMITS_B)
96#define QIF_SPACE (1 << QIF_SPACE_B)
97#define QIF_ILIMITS (1 << QIF_ILIMITS_B)
98#define QIF_INODES (1 << QIF_INODES_B)
99#define QIF_BTIME (1 << QIF_BTIME_B)
100#define QIF_ITIME (1 << QIF_ITIME_B)
101#define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
102#define QIF_USAGE (QIF_SPACE | QIF_INODES)
103#define QIF_TIMES (QIF_BTIME | QIF_ITIME)
104#define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
105
106struct if_dqblk {
107 __u64 dqb_bhardlimit;
108 __u64 dqb_bsoftlimit;
109 __u64 dqb_curspace;
110 __u64 dqb_ihardlimit;
111 __u64 dqb_isoftlimit;
112 __u64 dqb_curinodes;
113 __u64 dqb_btime;
114 __u64 dqb_itime;
115 __u32 dqb_valid;
116};
117
118
119
120
121
122#define IIF_BGRACE 1
123#define IIF_IGRACE 2
124#define IIF_FLAGS 4
125#define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
126
127struct if_dqinfo {
128 __u64 dqi_bgrace;
129 __u64 dqi_igrace;
130 __u32 dqi_flags;
131 __u32 dqi_valid;
132};
133
134
135
136
137#define QUOTA_NL_NOWARN 0
138#define QUOTA_NL_IHARDWARN 1
139#define QUOTA_NL_ISOFTLONGWARN 2
140#define QUOTA_NL_ISOFTWARN 3
141#define QUOTA_NL_BHARDWARN 4
142#define QUOTA_NL_BSOFTLONGWARN 5
143#define QUOTA_NL_BSOFTWARN 6
144#define QUOTA_NL_IHARDBELOW 7
145#define QUOTA_NL_ISOFTBELOW 8
146#define QUOTA_NL_BHARDBELOW 9
147#define QUOTA_NL_BSOFTBELOW 10
148
149enum {
150 QUOTA_NL_C_UNSPEC,
151 QUOTA_NL_C_WARNING,
152 __QUOTA_NL_C_MAX,
153};
154#define QUOTA_NL_C_MAX (__QUOTA_NL_C_MAX - 1)
155
156enum {
157 QUOTA_NL_A_UNSPEC,
158 QUOTA_NL_A_QTYPE,
159 QUOTA_NL_A_EXCESS_ID,
160 QUOTA_NL_A_WARNING,
161 QUOTA_NL_A_DEV_MAJOR,
162 QUOTA_NL_A_DEV_MINOR,
163 QUOTA_NL_A_CAUSED_ID,
164 __QUOTA_NL_A_MAX,
165};
166#define QUOTA_NL_A_MAX (__QUOTA_NL_A_MAX - 1)
167
168
169#ifdef __KERNEL__
170#include <linux/list.h>
171#include <linux/mutex.h>
172#include <linux/rwsem.h>
173#include <linux/spinlock.h>
174#include <linux/wait.h>
175
176#include <linux/dqblk_xfs.h>
177#include <linux/dqblk_v1.h>
178#include <linux/dqblk_v2.h>
179
180#include <asm/atomic.h>
181
182typedef __kernel_uid32_t qid_t;
183typedef long long qsize_t;
184
185extern spinlock_t dq_data_lock;
186
187
188
189#define DQUOT_INIT_ALLOC max(V1_INIT_ALLOC, V2_INIT_ALLOC)
190#define DQUOT_INIT_REWRITE max(V1_INIT_REWRITE, V2_INIT_REWRITE)
191#define DQUOT_DEL_ALLOC max(V1_DEL_ALLOC, V2_DEL_ALLOC)
192#define DQUOT_DEL_REWRITE max(V1_DEL_REWRITE, V2_DEL_REWRITE)
193
194
195
196
197struct mem_dqblk {
198 qsize_t dqb_bhardlimit;
199 qsize_t dqb_bsoftlimit;
200 qsize_t dqb_curspace;
201 qsize_t dqb_rsvspace;
202 qsize_t dqb_ihardlimit;
203 qsize_t dqb_isoftlimit;
204 qsize_t dqb_curinodes;
205 time_t dqb_btime;
206 time_t dqb_itime;
207};
208
209
210
211
212struct quota_format_type;
213
214struct mem_dqinfo {
215 struct quota_format_type *dqi_format;
216 int dqi_fmt_id;
217
218 struct list_head dqi_dirty_list;
219 unsigned long dqi_flags;
220 unsigned int dqi_bgrace;
221 unsigned int dqi_igrace;
222 qsize_t dqi_maxblimit;
223 qsize_t dqi_maxilimit;
224 void *dqi_priv;
225};
226
227struct super_block;
228
229#define DQF_MASK 0xffff
230#define DQF_INFO_DIRTY_B 16
231#define DQF_INFO_DIRTY (1 << DQF_INFO_DIRTY_B)
232
233extern void mark_info_dirty(struct super_block *sb, int type);
234static inline int info_dirty(struct mem_dqinfo *info)
235{
236 return test_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
237}
238
239struct dqstats {
240 int lookups;
241 int drops;
242 int reads;
243 int writes;
244 int cache_hits;
245 int allocated_dquots;
246 int free_dquots;
247 int syncs;
248};
249
250extern struct dqstats dqstats;
251
252#define DQ_MOD_B 0
253#define DQ_BLKS_B 1
254#define DQ_INODES_B 2
255#define DQ_FAKE_B 3
256#define DQ_READ_B 4
257#define DQ_ACTIVE_B 5
258#define DQ_LASTSET_B 6
259
260
261
262
263
264struct dquot {
265 struct hlist_node dq_hash;
266 struct list_head dq_inuse;
267 struct list_head dq_free;
268 struct list_head dq_dirty;
269 struct mutex dq_lock;
270 atomic_t dq_count;
271 wait_queue_head_t dq_wait_unused;
272 struct super_block *dq_sb;
273 unsigned int dq_id;
274 loff_t dq_off;
275 unsigned long dq_flags;
276 short dq_type;
277 struct mem_dqblk dq_dqb;
278};
279
280#define QUOTA_OK 0
281#define NO_QUOTA 1
282
283
284struct quota_format_ops {
285 int (*check_quota_file)(struct super_block *sb, int type);
286 int (*read_file_info)(struct super_block *sb, int type);
287 int (*write_file_info)(struct super_block *sb, int type);
288 int (*free_file_info)(struct super_block *sb, int type);
289 int (*read_dqblk)(struct dquot *dquot);
290 int (*commit_dqblk)(struct dquot *dquot);
291 int (*release_dqblk)(struct dquot *dquot);
292};
293
294
295struct dquot_operations {
296 int (*initialize) (struct inode *, int);
297 int (*drop) (struct inode *);
298 int (*alloc_space) (struct inode *, qsize_t, int);
299 int (*alloc_inode) (const struct inode *, qsize_t);
300 int (*free_space) (struct inode *, qsize_t);
301 int (*free_inode) (const struct inode *, qsize_t);
302 int (*transfer) (struct inode *, struct iattr *);
303 int (*write_dquot) (struct dquot *);
304 struct dquot *(*alloc_dquot)(struct super_block *, int);
305 void (*destroy_dquot)(struct dquot *);
306 int (*acquire_dquot) (struct dquot *);
307 int (*release_dquot) (struct dquot *);
308 int (*mark_dirty) (struct dquot *);
309 int (*write_info) (struct super_block *, int);
310
311 int (*reserve_space) (struct inode *, qsize_t, int);
312
313 int (*claim_space) (struct inode *, qsize_t);
314
315 void (*release_rsv) (struct inode *, qsize_t);
316
317 qsize_t (*get_reserved_space) (struct inode *);
318};
319
320
321struct quotactl_ops {
322 int (*quota_on)(struct super_block *, int, int, char *, int);
323 int (*quota_off)(struct super_block *, int, int);
324 int (*quota_sync)(struct super_block *, int);
325 int (*get_info)(struct super_block *, int, struct if_dqinfo *);
326 int (*set_info)(struct super_block *, int, struct if_dqinfo *);
327 int (*get_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
328 int (*set_dqblk)(struct super_block *, int, qid_t, struct if_dqblk *);
329 int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
330 int (*set_xstate)(struct super_block *, unsigned int, int);
331 int (*get_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
332 int (*set_xquota)(struct super_block *, int, qid_t, struct fs_disk_quota *);
333};
334
335struct quota_format_type {
336 int qf_fmt_id;
337 struct quota_format_ops *qf_ops;
338 struct module *qf_owner;
339 struct quota_format_type *qf_next;
340};
341
342
343enum {
344 _DQUOT_USAGE_ENABLED = 0,
345 _DQUOT_LIMITS_ENABLED,
346 _DQUOT_SUSPENDED,
347
348
349 _DQUOT_STATE_FLAGS
350};
351#define DQUOT_USAGE_ENABLED (1 << _DQUOT_USAGE_ENABLED)
352#define DQUOT_LIMITS_ENABLED (1 << _DQUOT_LIMITS_ENABLED)
353#define DQUOT_SUSPENDED (1 << _DQUOT_SUSPENDED)
354#define DQUOT_STATE_FLAGS (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED | \
355 DQUOT_SUSPENDED)
356
357#define DQUOT_QUOTA_SYS_FILE (1 << 6)
358
359
360
361
362
363#define DQUOT_NEGATIVE_USAGE (1 << 7)
364
365static inline unsigned int dquot_state_flag(unsigned int flags, int type)
366{
367 if (type == USRQUOTA)
368 return flags;
369 return flags << _DQUOT_STATE_FLAGS;
370}
371
372static inline unsigned int dquot_generic_flag(unsigned int flags, int type)
373{
374 if (type == USRQUOTA)
375 return flags;
376 return flags >> _DQUOT_STATE_FLAGS;
377}
378
379struct quota_info {
380 unsigned int flags;
381 struct mutex dqio_mutex;
382 struct mutex dqonoff_mutex;
383 struct rw_semaphore dqptr_sem;
384 struct inode *files[MAXQUOTAS];
385 struct mem_dqinfo info[MAXQUOTAS];
386 struct quota_format_ops *ops[MAXQUOTAS];
387};
388
389int register_quota_format(struct quota_format_type *fmt);
390void unregister_quota_format(struct quota_format_type *fmt);
391
392struct quota_module_name {
393 int qm_fmt_id;
394 char *qm_mod_name;
395};
396
397#define INIT_QUOTA_MODULE_NAMES {\
398 {QFMT_VFS_OLD, "quota_v1"},\
399 {QFMT_VFS_V0, "quota_v2"},\
400 {0, NULL}}
401
402#else
403
404# include <sys/cdefs.h>
405
406__BEGIN_DECLS
407long quotactl __P ((unsigned int, const char *, int, caddr_t));
408__END_DECLS
409
410#endif
411#endif
412