1/* $NetBSD: ufs_quota.h,v 1.22 2014/06/28 22:27:51 dholland Exp $ */
2
3/*
4 * Copyright (c) 1982, 1986, 1990, 1993, 1995
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Robert Elz at The University of Melbourne.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
35 */
36#include <ufs/ufs/quota1.h>
37#include <ufs/ufs/quota2.h>
38
39struct quotakcursor; /* from <sys/quotactl.h> */
40
41
42/* link to this quota in the quota inode (for QUOTA2) */
43struct dq2_desc {
44 uint64_t dq2_lblkno; /* logical disk block holding this quota */
45 u_int dq2_blkoff; /* offset in disk block holding this quota */
46};
47
48/*
49 * The following structure records disk usage for a user or group on a
50 * filesystem. There is one allocated for each quota that exists on any
51 * filesystem for the current user or group. A cache is kept of recently
52 * used entries.
53 * Field markings and the corresponding locks:
54 * h: dqlock
55 * d: dq_interlock
56 *
57 * Lock order is: dq_interlock -> dqlock
58 * dq_interlock -> dqvp
59 */
60struct dquot {
61 LIST_ENTRY(dquot) dq_hash; /* h: hash list */
62 u_int16_t dq_flags; /* d: flags, see below */
63 u_int16_t dq_type; /* d: quota type of this dquot */
64 u_int32_t dq_cnt; /* h: count of active references */
65 u_int32_t dq_id; /* d: identifier this applies to */
66 struct ufsmount *dq_ump; /* d: filesystem this is taken from */
67 kmutex_t dq_interlock; /* d: lock this dquot */
68 union {
69 struct dqblk dq1_dqb; /* d: actual usage & quotas */
70 struct dq2_desc dq2_desc; /* d: pointer to quota data */
71 } dq_un;
72};
73
74/*
75 * Flag values.
76 */
77#define DQ_MOD 0x04 /* this quota modified since read */
78#define DQ_FAKE 0x08 /* no limits here, just usage */
79#define DQ_WARN(ltype) (0x10 << ltype) /* has been warned about "type" limit */
80/*
81 * Shorthand notation.
82 */
83#define dq_bhardlimit dq_un.dq1_dqb.dqb_bhardlimit
84#define dq_bsoftlimit dq_un.dq1_dqb.dqb_bsoftlimit
85#define dq_curblocks dq_un.dq1_dqb.dqb_curblocks
86#define dq_ihardlimit dq_un.dq1_dqb.dqb_ihardlimit
87#define dq_isoftlimit dq_un.dq1_dqb.dqb_isoftlimit
88#define dq_curinodes dq_un.dq1_dqb.dqb_curinodes
89#define dq_btime dq_un.dq1_dqb.dqb_btime
90#define dq_itime dq_un.dq1_dqb.dqb_itime
91
92#define dq2_lblkno dq_un.dq2_desc.dq2_lblkno
93#define dq2_blkoff dq_un.dq2_desc.dq2_blkoff
94/*
95 * If the system has never checked for a quota for this file, then it is
96 * set to NODQUOT. Once a write attempt is made the inode pointer is set
97 * to reference a dquot structure.
98 */
99#define NODQUOT NULL
100
101extern kmutex_t dqlock;
102extern kcondvar_t dqcv;
103/*
104 * Quota name to error message mapping.
105 */
106extern const char *quotatypes[MAXQUOTAS];
107
108int getinoquota(struct inode *);
109int dqget(struct vnode *, u_long, struct ufsmount *, int, struct dquot **);
110void dqref(struct dquot *);
111void dqrele(struct vnode *, struct dquot *);
112void dqflush(struct vnode *);
113
114int chkdq1(struct inode *, int64_t, kauth_cred_t, int);
115int chkiq1(struct inode *, int32_t, kauth_cred_t, int);
116int q1sync(struct mount *);
117int dq1get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
118int dq1sync(struct vnode *, struct dquot *);
119int quota1_handle_cmd_get(struct ufsmount *, const struct quotakey *,
120 struct quotaval *);
121int quota1_handle_cmd_put(struct ufsmount *, const struct quotakey *,
122 const struct quotaval *);
123int quota1_handle_cmd_quotaon(struct lwp *, struct ufsmount *, int,
124 const char *);
125int quota1_handle_cmd_quotaoff(struct lwp *, struct ufsmount *, int);
126
127int chkdq2(struct inode *, int64_t, kauth_cred_t, int);
128int chkiq2(struct inode *, int32_t, kauth_cred_t, int);
129int quota2_handle_cmd_get(struct ufsmount *, const struct quotakey *,
130 struct quotaval *);
131int quota2_handle_cmd_put(struct ufsmount *, const struct quotakey *,
132 const struct quotaval *);
133int quota2_handle_cmd_del(struct ufsmount *, const struct quotakey *);
134int quota2_handle_cmd_cursorget(struct ufsmount *, struct quotakcursor *,
135 struct quotakey *, struct quotaval *, unsigned, unsigned *);
136int quota2_handle_cmd_cursoropen(struct ufsmount *, struct quotakcursor *);
137int quota2_handle_cmd_cursorclose(struct ufsmount *, struct quotakcursor *);
138int quota2_handle_cmd_cursorskipidtype(struct ufsmount *, struct quotakcursor *,
139 int);
140int quota2_handle_cmd_cursoratend(struct ufsmount *, struct quotakcursor *,
141 int *);
142int quota2_handle_cmd_cursorrewind(struct ufsmount *, struct quotakcursor *);
143int q2sync(struct mount *);
144int dq2get(struct vnode *, u_long, struct ufsmount *, int, struct dquot *);
145int dq2sync(struct vnode *, struct dquot *);
146