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