1 /* $NetBSD: ffs_quota2.c,v 1.5 2015/02/22 14:12:48 maxv 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.5 2015/02/22 14:12:48 maxv Exp $");
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/systm.h>
34 #include <sys/namei.h>
36 #include <sys/vnode.h>
37 #include <sys/mount.h>
38 #include <sys/kauth.h>
40 #include <ufs/ufs/quota2.h>
41 #include <ufs/ufs/inode.h>
42 #include <ufs/ufs/ufsmount.h>
43 #include <ufs/ffs/ffs_extern.h>
44 #include <ufs/ffs/fs.h>
47 ffs_quota2_mount(struct mount
*mp
)
49 struct ufsmount
*ump
= VFSTOUFS(mp
);
50 struct fs
*fs
= ump
->um_fs
;
53 struct lwp
*l
= curlwp
;
55 if ((fs
->fs_flags
& FS_DOQUOTA2
) == 0)
58 ump
->um_flags
|= UFS_QUOTA2
;
59 ump
->umq2_bsize
= fs
->fs_bsize
;
60 ump
->umq2_bmask
= fs
->fs_qbmask
;
61 if (fs
->fs_quota_magic
!= Q2_HEAD_MAGIC
) {
62 printf("%s: invalid quota magic number\n",
63 mp
->mnt_stat
.f_mntonname
);
66 if ((fs
->fs_quota_flags
& FS_Q2_DO_TYPE(USRQUOTA
)) &&
67 fs
->fs_quotafile
[USRQUOTA
] == 0) {
68 printf("%s: no user quota inode\n",
69 mp
->mnt_stat
.f_mntonname
);
72 if ((fs
->fs_quota_flags
& FS_Q2_DO_TYPE(GRPQUOTA
)) &&
73 fs
->fs_quotafile
[GRPQUOTA
] == 0) {
74 printf("%s: no group quota inode\n",
75 mp
->mnt_stat
.f_mntonname
);
79 if (fs
->fs_quota_flags
& FS_Q2_DO_TYPE(USRQUOTA
) &&
80 ump
->um_quotas
[USRQUOTA
] == NULLVP
) {
81 error
= VFS_VGET(mp
, fs
->fs_quotafile
[USRQUOTA
], &vp
);
83 printf("%s: can't vget() user quota inode: %d\n",
84 mp
->mnt_stat
.f_mntonname
, error
);
87 ump
->um_quotas
[USRQUOTA
] = vp
;
88 ump
->um_cred
[USRQUOTA
] = l
->l_cred
;
89 mutex_enter(vp
->v_interlock
);
91 mutex_exit(vp
->v_interlock
);
94 if (fs
->fs_quota_flags
& FS_Q2_DO_TYPE(GRPQUOTA
) &&
95 ump
->um_quotas
[GRPQUOTA
] == NULLVP
) {
96 error
= VFS_VGET(mp
, fs
->fs_quotafile
[GRPQUOTA
], &vp
);
98 vn_close(ump
->um_quotas
[USRQUOTA
],
99 FREAD
|FWRITE
, l
->l_cred
);
100 printf("%s: can't vget() group quota inode: %d\n",
101 mp
->mnt_stat
.f_mntonname
, error
);
104 ump
->um_quotas
[GRPQUOTA
] = vp
;
105 ump
->um_cred
[GRPQUOTA
] = l
->l_cred
;
106 mutex_enter(vp
->v_interlock
);
107 vp
->v_vflag
|= VV_SYSTEM
;
109 mutex_exit(vp
->v_interlock
);
113 mp
->mnt_flag
|= MNT_QUOTA
;