compat_50_quota.c revision 1.3.2.2 1 1.3.2.2 martin /* $NetBSD: compat_50_quota.c,v 1.3.2.2 2020/04/08 14:08:00 martin Exp $ */
2 1.3.2.2 martin
3 1.3.2.2 martin /*-
4 1.3.2.2 martin * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.3.2.2 martin * All rights reserved.
6 1.3.2.2 martin *
7 1.3.2.2 martin * This code is derived from software contributed to The NetBSD Foundation
8 1.3.2.2 martin * by Christos Zoulas.
9 1.3.2.2 martin *
10 1.3.2.2 martin * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 martin * modification, are permitted provided that the following conditions
12 1.3.2.2 martin * are met:
13 1.3.2.2 martin * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 martin * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 martin * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 martin * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 martin * documentation and/or other materials provided with the distribution.
18 1.3.2.2 martin *
19 1.3.2.2 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.3.2.2 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.3.2.2 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3.2.2 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3.2.2 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.3.2.2 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.3.2.2 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.3.2.2 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.3.2.2 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.3.2.2 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.3.2.2 martin * POSSIBILITY OF SUCH DAMAGE.
30 1.3.2.2 martin */
31 1.3.2.2 martin #include <sys/cdefs.h>
32 1.3.2.2 martin __KERNEL_RCSID(0, "$NetBSD: compat_50_quota.c,v 1.3.2.2 2020/04/08 14:08:00 martin Exp $");
33 1.3.2.2 martin
34 1.3.2.2 martin #if defined(_KERNEL_OPT)
35 1.3.2.2 martin #include "opt_compat_netbsd.h"
36 1.3.2.2 martin #endif
37 1.3.2.2 martin
38 1.3.2.2 martin #include <sys/module.h>
39 1.3.2.2 martin #include <sys/namei.h>
40 1.3.2.2 martin #include <sys/param.h>
41 1.3.2.2 martin #include <sys/quota.h>
42 1.3.2.2 martin #include <sys/quotactl.h>
43 1.3.2.2 martin #include <sys/systm.h>
44 1.3.2.2 martin #include <sys/syscall.h>
45 1.3.2.2 martin #include <sys/syscallvar.h>
46 1.3.2.2 martin #include <sys/syscallargs.h>
47 1.3.2.2 martin #include <sys/vfs_syscalls.h>
48 1.3.2.2 martin #include <sys/vnode.h>
49 1.3.2.2 martin
50 1.3.2.2 martin #include <ufs/ufs/quota1.h>
51 1.3.2.2 martin
52 1.3.2.2 martin static const struct syscall_package vfs_syscalls_50_quota_syscalls[] = {
53 1.3.2.2 martin { SYS_compat_50_quotactl, 0, (sy_call_t *)compat_50_sys_quotactl },
54 1.3.2.2 martin { 0, 0, NULL }
55 1.3.2.2 martin };
56 1.3.2.2 martin
57 1.3.2.2 martin /* ARGSUSED */
58 1.3.2.2 martin int
59 1.3.2.2 martin compat_50_sys_quotactl(struct lwp *l, const struct compat_50_sys_quotactl_args *uap, register_t *retval)
60 1.3.2.2 martin {
61 1.3.2.2 martin /* {
62 1.3.2.2 martin syscallarg(const char *) path;
63 1.3.2.2 martin syscallarg(int) cmd;
64 1.3.2.2 martin syscallarg(int) uid;
65 1.3.2.2 martin syscallarg(void *) arg;
66 1.3.2.2 martin } */
67 1.3.2.2 martin struct vnode *vp;
68 1.3.2.2 martin struct mount *mp;
69 1.3.2.2 martin int q1cmd;
70 1.3.2.2 martin int idtype;
71 1.3.2.2 martin char *qfile;
72 1.3.2.2 martin struct dqblk dqblk;
73 1.3.2.2 martin struct quotakey key;
74 1.3.2.2 martin struct quotaval blocks, files;
75 1.3.2.2 martin struct quotastat qstat;
76 1.3.2.2 martin int error;
77 1.3.2.2 martin
78 1.3.2.2 martin error = namei_simple_user(SCARG(uap, path),
79 1.3.2.2 martin NSM_FOLLOW_TRYEMULROOT, &vp);
80 1.3.2.2 martin if (error != 0)
81 1.3.2.2 martin return (error);
82 1.3.2.2 martin
83 1.3.2.2 martin mp = vp->v_mount;
84 1.3.2.2 martin q1cmd = SCARG(uap, cmd);
85 1.3.2.2 martin idtype = quota_idtype_from_ufs(q1cmd & SUBCMDMASK);
86 1.3.2.2 martin
87 1.3.2.2 martin switch ((q1cmd & ~SUBCMDMASK) >> SUBCMDSHIFT) {
88 1.3.2.2 martin case Q_QUOTAON:
89 1.3.2.2 martin qfile = PNBUF_GET();
90 1.3.2.2 martin error = copyinstr(SCARG(uap, arg), qfile, PATH_MAX, NULL);
91 1.3.2.2 martin if (error != 0) {
92 1.3.2.2 martin PNBUF_PUT(qfile);
93 1.3.2.2 martin break;
94 1.3.2.2 martin }
95 1.3.2.2 martin
96 1.3.2.2 martin error = vfs_quotactl_quotaon(mp, idtype, qfile);
97 1.3.2.2 martin
98 1.3.2.2 martin PNBUF_PUT(qfile);
99 1.3.2.2 martin break;
100 1.3.2.2 martin
101 1.3.2.2 martin case Q_QUOTAOFF:
102 1.3.2.2 martin error = vfs_quotactl_quotaoff(mp, idtype);
103 1.3.2.2 martin break;
104 1.3.2.2 martin
105 1.3.2.2 martin case Q_GETQUOTA:
106 1.3.2.2 martin key.qk_idtype = idtype;
107 1.3.2.2 martin key.qk_id = SCARG(uap, uid);
108 1.3.2.2 martin
109 1.3.2.2 martin key.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
110 1.3.2.2 martin error = vfs_quotactl_get(mp, &key, &blocks);
111 1.3.2.2 martin if (error) {
112 1.3.2.2 martin break;
113 1.3.2.2 martin }
114 1.3.2.2 martin
115 1.3.2.2 martin key.qk_objtype = QUOTA_OBJTYPE_FILES;
116 1.3.2.2 martin error = vfs_quotactl_get(mp, &key, &files);
117 1.3.2.2 martin if (error) {
118 1.3.2.2 martin break;
119 1.3.2.2 martin }
120 1.3.2.2 martin
121 1.3.2.2 martin quotavals_to_dqblk(&blocks, &files, &dqblk);
122 1.3.2.2 martin error = copyout(&dqblk, SCARG(uap, arg), sizeof(dqblk));
123 1.3.2.2 martin break;
124 1.3.2.2 martin
125 1.3.2.2 martin case Q_SETQUOTA:
126 1.3.2.2 martin error = copyin(SCARG(uap, arg), &dqblk, sizeof(dqblk));
127 1.3.2.2 martin if (error) {
128 1.3.2.2 martin break;
129 1.3.2.2 martin }
130 1.3.2.2 martin dqblk_to_quotavals(&dqblk, &blocks, &files);
131 1.3.2.2 martin
132 1.3.2.2 martin key.qk_idtype = idtype;
133 1.3.2.2 martin key.qk_id = SCARG(uap, uid);
134 1.3.2.2 martin
135 1.3.2.2 martin key.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
136 1.3.2.2 martin error = vfs_quotactl_put(mp, &key, &blocks);
137 1.3.2.2 martin if (error) {
138 1.3.2.2 martin break;
139 1.3.2.2 martin }
140 1.3.2.2 martin
141 1.3.2.2 martin key.qk_objtype = QUOTA_OBJTYPE_FILES;
142 1.3.2.2 martin error = vfs_quotactl_put(mp, &key, &files);
143 1.3.2.2 martin break;
144 1.3.2.2 martin
145 1.3.2.2 martin case Q_SYNC:
146 1.3.2.2 martin /*
147 1.3.2.2 martin * not supported but used only to see if quota is supported,
148 1.3.2.2 martin * emulate with stat
149 1.3.2.2 martin *
150 1.3.2.2 martin * XXX should probably be supported
151 1.3.2.2 martin */
152 1.3.2.2 martin (void)idtype; /* not used */
153 1.3.2.2 martin
154 1.3.2.2 martin error = vfs_quotactl_stat(mp, &qstat);
155 1.3.2.2 martin break;
156 1.3.2.2 martin
157 1.3.2.2 martin case Q_SETUSE:
158 1.3.2.2 martin default:
159 1.3.2.2 martin error = EOPNOTSUPP;
160 1.3.2.2 martin break;
161 1.3.2.2 martin }
162 1.3.2.2 martin
163 1.3.2.2 martin vrele(vp);
164 1.3.2.2 martin return error;
165 1.3.2.2 martin }
166 1.3.2.2 martin
167 1.3.2.2 martin MODULE(MODULE_CLASS_EXEC, compat_50_quota, "compat_50,ufs");
168 1.3.2.2 martin
169 1.3.2.2 martin static int
170 1.3.2.2 martin compat_50_quota_modcmd(modcmd_t cmd, void *arg)
171 1.3.2.2 martin {
172 1.3.2.2 martin
173 1.3.2.2 martin switch (cmd) {
174 1.3.2.2 martin case MODULE_CMD_INIT:
175 1.3.2.2 martin return syscall_establish(NULL, vfs_syscalls_50_quota_syscalls);
176 1.3.2.2 martin case MODULE_CMD_FINI:
177 1.3.2.2 martin return syscall_disestablish(NULL, vfs_syscalls_50_quota_syscalls);
178 1.3.2.2 martin default:
179 1.3.2.2 martin return ENOTTY;
180 1.3.2.2 martin }
181 1.3.2.2 martin }
182