ffs_quota2.c revision 1.4 1 1.4 rmind /* $NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp $ */
2 1.2 bouyer /*-
3 1.2 bouyer * Copyright (c) 2010 Manuel Bouyer
4 1.2 bouyer * All rights reserved.
5 1.2 bouyer *
6 1.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.2 bouyer * modification, are permitted provided that the following conditions
8 1.2 bouyer * are met:
9 1.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.2 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.2 bouyer * documentation and/or other materials provided with the distribution.
14 1.2 bouyer *
15 1.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
26 1.2 bouyer */
27 1.2 bouyer
28 1.2 bouyer #include <sys/cdefs.h>
29 1.4 rmind __KERNEL_RCSID(0, "$NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp $");
30 1.2 bouyer
31 1.2 bouyer #include <sys/param.h>
32 1.2 bouyer #include <sys/kernel.h>
33 1.2 bouyer #include <sys/systm.h>
34 1.2 bouyer #include <sys/namei.h>
35 1.2 bouyer #include <sys/file.h>
36 1.2 bouyer #include <sys/proc.h>
37 1.2 bouyer #include <sys/vnode.h>
38 1.2 bouyer #include <sys/mount.h>
39 1.2 bouyer #include <sys/kauth.h>
40 1.2 bouyer
41 1.2 bouyer #include <ufs/ufs/quota2.h>
42 1.2 bouyer #include <ufs/ufs/inode.h>
43 1.2 bouyer #include <ufs/ufs/ufsmount.h>
44 1.2 bouyer #include <ufs/ffs/ffs_extern.h>
45 1.2 bouyer #include <ufs/ffs/fs.h>
46 1.2 bouyer
47 1.2 bouyer
48 1.2 bouyer int
49 1.2 bouyer ffs_quota2_mount(struct mount *mp)
50 1.2 bouyer {
51 1.2 bouyer struct ufsmount *ump = VFSTOUFS(mp);
52 1.2 bouyer struct fs *fs = ump->um_fs;
53 1.2 bouyer int error = 0;
54 1.2 bouyer struct vnode *vp;
55 1.2 bouyer struct lwp *l = curlwp;
56 1.2 bouyer
57 1.2 bouyer if ((fs->fs_flags & FS_DOQUOTA2) == 0)
58 1.2 bouyer return 0;
59 1.2 bouyer
60 1.2 bouyer ump->um_flags |= UFS_QUOTA2;
61 1.2 bouyer ump->umq2_bsize = fs->fs_bsize;
62 1.2 bouyer ump->umq2_bmask = fs->fs_qbmask;
63 1.2 bouyer if (fs->fs_quota_magic != Q2_HEAD_MAGIC) {
64 1.2 bouyer printf("%s: Invalid quota magic number\n",
65 1.2 bouyer mp->mnt_stat.f_mntonname);
66 1.2 bouyer return EINVAL;
67 1.2 bouyer }
68 1.2 bouyer if ((fs->fs_quota_flags & FS_Q2_DO_TYPE(USRQUOTA)) &&
69 1.2 bouyer fs->fs_quotafile[USRQUOTA] == 0) {
70 1.2 bouyer printf("%s: no user quota inode\n",
71 1.2 bouyer mp->mnt_stat.f_mntonname);
72 1.2 bouyer error = EINVAL;
73 1.2 bouyer }
74 1.2 bouyer if ((fs->fs_quota_flags & FS_Q2_DO_TYPE(GRPQUOTA)) &&
75 1.2 bouyer fs->fs_quotafile[GRPQUOTA] == 0) {
76 1.2 bouyer printf("%s: no group quota inode\n",
77 1.2 bouyer mp->mnt_stat.f_mntonname);
78 1.2 bouyer error = EINVAL;
79 1.2 bouyer }
80 1.2 bouyer if (error)
81 1.2 bouyer return error;
82 1.2 bouyer
83 1.2 bouyer if (fs->fs_quota_flags & FS_Q2_DO_TYPE(USRQUOTA) &&
84 1.2 bouyer ump->um_quotas[USRQUOTA] == NULLVP) {
85 1.2 bouyer error = VFS_VGET(mp, fs->fs_quotafile[USRQUOTA], &vp);
86 1.2 bouyer if (error) {
87 1.2 bouyer printf("%s: can't vget() user quota inode: %d\n",
88 1.2 bouyer mp->mnt_stat.f_mntonname, error);
89 1.2 bouyer return error;
90 1.2 bouyer }
91 1.2 bouyer ump->um_quotas[USRQUOTA] = vp;
92 1.2 bouyer ump->um_cred[USRQUOTA] = l->l_cred;
93 1.4 rmind mutex_enter(vp->v_interlock);
94 1.2 bouyer vp->v_writecount++;
95 1.4 rmind mutex_exit(vp->v_interlock);
96 1.2 bouyer VOP_UNLOCK(vp);
97 1.2 bouyer }
98 1.2 bouyer if (fs->fs_quota_flags & FS_Q2_DO_TYPE(GRPQUOTA) &&
99 1.2 bouyer ump->um_quotas[GRPQUOTA] == NULLVP) {
100 1.2 bouyer error = VFS_VGET(mp, fs->fs_quotafile[GRPQUOTA], &vp);
101 1.2 bouyer if (error) {
102 1.2 bouyer vn_close(ump->um_quotas[USRQUOTA],
103 1.2 bouyer FREAD|FWRITE, l->l_cred);
104 1.2 bouyer printf("%s: can't vget() group quota inode: %d\n",
105 1.2 bouyer mp->mnt_stat.f_mntonname, error);
106 1.2 bouyer return error;
107 1.2 bouyer }
108 1.2 bouyer ump->um_quotas[GRPQUOTA] = vp;
109 1.2 bouyer ump->um_cred[GRPQUOTA] = l->l_cred;
110 1.4 rmind mutex_enter(vp->v_interlock);
111 1.2 bouyer vp->v_vflag |= VV_SYSTEM;
112 1.2 bouyer vp->v_writecount++;
113 1.4 rmind mutex_exit(vp->v_interlock);
114 1.2 bouyer VOP_UNLOCK(vp);
115 1.2 bouyer }
116 1.2 bouyer mp->mnt_flag |= MNT_QUOTA;
117 1.2 bouyer return 0;
118 1.2 bouyer }
119