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