vfs_syscalls_50.c revision 1.1.6.1 1 1.1.6.1 yamt /* $NetBSD: vfs_syscalls_50.c,v 1.1.6.1 2009/05/04 08:12:18 yamt Exp $ */
2 1.1.6.1 yamt
3 1.1.6.1 yamt /*-
4 1.1.6.1 yamt * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1.6.1 yamt * All rights reserved.
6 1.1.6.1 yamt *
7 1.1.6.1 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.6.1 yamt * by Christos Zoulas.
9 1.1.6.1 yamt *
10 1.1.6.1 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.6.1 yamt * modification, are permitted provided that the following conditions
12 1.1.6.1 yamt * are met:
13 1.1.6.1 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.6.1 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.6.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.6.1 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.6.1 yamt * documentation and/or other materials provided with the distribution.
18 1.1.6.1 yamt * 3. All advertising materials mentioning features or use of this software
19 1.1.6.1 yamt * must display the following acknowledgement:
20 1.1.6.1 yamt * This product includes software developed by the NetBSD
21 1.1.6.1 yamt * Foundation, Inc. and its contributors.
22 1.1.6.1 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.6.1 yamt * contributors may be used to endorse or promote products derived
24 1.1.6.1 yamt * from this software without specific prior written permission.
25 1.1.6.1 yamt *
26 1.1.6.1 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.6.1 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.6.1 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.6.1 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.6.1 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.6.1 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.6.1 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.6.1 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.6.1 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.6.1 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.6.1 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.1.6.1 yamt */
38 1.1.6.1 yamt #include <sys/cdefs.h>
39 1.1.6.1 yamt __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_50.c,v 1.1.6.1 2009/05/04 08:12:18 yamt Exp $");
40 1.1.6.1 yamt
41 1.1.6.1 yamt #include <sys/param.h>
42 1.1.6.1 yamt #include <sys/systm.h>
43 1.1.6.1 yamt #include <sys/namei.h>
44 1.1.6.1 yamt #include <sys/filedesc.h>
45 1.1.6.1 yamt #include <sys/kernel.h>
46 1.1.6.1 yamt #include <sys/file.h>
47 1.1.6.1 yamt #include <sys/stat.h>
48 1.1.6.1 yamt #include <sys/socketvar.h>
49 1.1.6.1 yamt #include <sys/vnode.h>
50 1.1.6.1 yamt #include <sys/mount.h>
51 1.1.6.1 yamt #include <sys/proc.h>
52 1.1.6.1 yamt #include <sys/uio.h>
53 1.1.6.1 yamt #include <sys/dirent.h>
54 1.1.6.1 yamt #include <sys/malloc.h>
55 1.1.6.1 yamt #include <sys/kauth.h>
56 1.1.6.1 yamt #include <sys/time.h>
57 1.1.6.1 yamt #include <sys/vfs_syscalls.h>
58 1.1.6.1 yamt #ifndef LFS
59 1.1.6.1 yamt #define LFS
60 1.1.6.1 yamt #endif
61 1.1.6.1 yamt #include <sys/syscallargs.h>
62 1.1.6.1 yamt
63 1.1.6.1 yamt #include <ufs/lfs/lfs_extern.h>
64 1.1.6.1 yamt
65 1.1.6.1 yamt #include <compat/common/compat_util.h>
66 1.1.6.1 yamt #include <compat/sys/time.h>
67 1.1.6.1 yamt #include <compat/sys/stat.h>
68 1.1.6.1 yamt #include <compat/sys/dirent.h>
69 1.1.6.1 yamt #include <compat/sys/mount.h>
70 1.1.6.1 yamt
71 1.1.6.1 yamt static void cvtstat(struct stat30 *, const struct stat *);
72 1.1.6.1 yamt
73 1.1.6.1 yamt /*
74 1.1.6.1 yamt * Convert from a new to an old stat structure.
75 1.1.6.1 yamt */
76 1.1.6.1 yamt static void
77 1.1.6.1 yamt cvtstat(struct stat30 *ost, const struct stat *st)
78 1.1.6.1 yamt {
79 1.1.6.1 yamt
80 1.1.6.1 yamt ost->st_dev = st->st_dev;
81 1.1.6.1 yamt ost->st_ino = st->st_ino;
82 1.1.6.1 yamt ost->st_mode = st->st_mode;
83 1.1.6.1 yamt ost->st_nlink = st->st_nlink;
84 1.1.6.1 yamt ost->st_uid = st->st_uid;
85 1.1.6.1 yamt ost->st_gid = st->st_gid;
86 1.1.6.1 yamt ost->st_rdev = st->st_rdev;
87 1.1.6.1 yamt timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
88 1.1.6.1 yamt timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
89 1.1.6.1 yamt timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
90 1.1.6.1 yamt timespec_to_timespec50(&st->st_birthtimespec, &ost->st_birthtimespec);
91 1.1.6.1 yamt ost->st_size = st->st_size;
92 1.1.6.1 yamt ost->st_blocks = st->st_blocks;
93 1.1.6.1 yamt ost->st_blksize = st->st_blksize;
94 1.1.6.1 yamt ost->st_flags = st->st_flags;
95 1.1.6.1 yamt ost->st_gen = st->st_gen;
96 1.1.6.1 yamt }
97 1.1.6.1 yamt
98 1.1.6.1 yamt /*
99 1.1.6.1 yamt * Get file status; this version follows links.
100 1.1.6.1 yamt */
101 1.1.6.1 yamt /* ARGSUSED */
102 1.1.6.1 yamt int
103 1.1.6.1 yamt compat_50_sys___stat30(struct lwp *l, const struct compat_50_sys___stat30_args *uap, register_t *retval)
104 1.1.6.1 yamt {
105 1.1.6.1 yamt /* {
106 1.1.6.1 yamt syscallarg(const char *) path;
107 1.1.6.1 yamt syscallarg(struct stat30 *) ub;
108 1.1.6.1 yamt } */
109 1.1.6.1 yamt struct stat sb;
110 1.1.6.1 yamt struct stat30 osb;
111 1.1.6.1 yamt int error;
112 1.1.6.1 yamt
113 1.1.6.1 yamt error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
114 1.1.6.1 yamt if (error)
115 1.1.6.1 yamt return error;
116 1.1.6.1 yamt cvtstat(&osb, &sb);
117 1.1.6.1 yamt error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
118 1.1.6.1 yamt return error;
119 1.1.6.1 yamt }
120 1.1.6.1 yamt
121 1.1.6.1 yamt
122 1.1.6.1 yamt /*
123 1.1.6.1 yamt * Get file status; this version does not follow links.
124 1.1.6.1 yamt */
125 1.1.6.1 yamt /* ARGSUSED */
126 1.1.6.1 yamt int
127 1.1.6.1 yamt compat_50_sys___lstat30(struct lwp *l, const struct compat_50_sys___lstat30_args *uap, register_t *retval)
128 1.1.6.1 yamt {
129 1.1.6.1 yamt /* {
130 1.1.6.1 yamt syscallarg(const char *) path;
131 1.1.6.1 yamt syscallarg(struct stat30 *) ub;
132 1.1.6.1 yamt } */
133 1.1.6.1 yamt struct stat sb;
134 1.1.6.1 yamt struct stat30 osb;
135 1.1.6.1 yamt int error;
136 1.1.6.1 yamt
137 1.1.6.1 yamt error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
138 1.1.6.1 yamt if (error)
139 1.1.6.1 yamt return error;
140 1.1.6.1 yamt cvtstat(&osb, &sb);
141 1.1.6.1 yamt error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
142 1.1.6.1 yamt return error;
143 1.1.6.1 yamt }
144 1.1.6.1 yamt
145 1.1.6.1 yamt /*
146 1.1.6.1 yamt * Return status information about a file descriptor.
147 1.1.6.1 yamt */
148 1.1.6.1 yamt /* ARGSUSED */
149 1.1.6.1 yamt int
150 1.1.6.1 yamt compat_50_sys___fstat30(struct lwp *l, const struct compat_50_sys___fstat30_args *uap, register_t *retval)
151 1.1.6.1 yamt {
152 1.1.6.1 yamt /* {
153 1.1.6.1 yamt syscallarg(int) fd;
154 1.1.6.1 yamt syscallarg(struct stat30 *) sb;
155 1.1.6.1 yamt } */
156 1.1.6.1 yamt struct stat sb;
157 1.1.6.1 yamt struct stat30 osb;
158 1.1.6.1 yamt int error;
159 1.1.6.1 yamt
160 1.1.6.1 yamt error = do_sys_fstat(SCARG(uap, fd), &sb);
161 1.1.6.1 yamt if (error)
162 1.1.6.1 yamt return error;
163 1.1.6.1 yamt cvtstat(&osb, &sb);
164 1.1.6.1 yamt error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
165 1.1.6.1 yamt return error;
166 1.1.6.1 yamt }
167 1.1.6.1 yamt
168 1.1.6.1 yamt /* ARGSUSED */
169 1.1.6.1 yamt int
170 1.1.6.1 yamt compat_50_sys___fhstat40(struct lwp *l, const struct compat_50_sys___fhstat40_args *uap, register_t *retval)
171 1.1.6.1 yamt {
172 1.1.6.1 yamt /* {
173 1.1.6.1 yamt syscallarg(const void *) fhp;
174 1.1.6.1 yamt syscallarg(size_t) fh_size;
175 1.1.6.1 yamt syscallarg(struct stat30 *) sb;
176 1.1.6.1 yamt } */
177 1.1.6.1 yamt struct stat sb;
178 1.1.6.1 yamt struct stat30 osb;
179 1.1.6.1 yamt int error;
180 1.1.6.1 yamt
181 1.1.6.1 yamt error = do_fhstat(l, SCARG(uap, fhp), SCARG(uap, fh_size), &sb);
182 1.1.6.1 yamt if (error)
183 1.1.6.1 yamt return error;
184 1.1.6.1 yamt cvtstat(&osb, &sb);
185 1.1.6.1 yamt error = copyout(&osb, SCARG(uap, sb), sizeof (osb));
186 1.1.6.1 yamt return error;
187 1.1.6.1 yamt }
188 1.1.6.1 yamt
189 1.1.6.1 yamt static int
190 1.1.6.1 yamt compat_50_do_sys_utimes(struct lwp *l, struct vnode *vp, const char *path,
191 1.1.6.1 yamt int flag, const struct timeval50 *tptr)
192 1.1.6.1 yamt {
193 1.1.6.1 yamt struct timeval tv[2], *tvp;
194 1.1.6.1 yamt struct timeval50 tv50[2];
195 1.1.6.1 yamt if (tptr) {
196 1.1.6.1 yamt int error = copyin(tptr, tv50, sizeof(tv50));
197 1.1.6.1 yamt if (error)
198 1.1.6.1 yamt return error;
199 1.1.6.1 yamt timeval50_to_timeval(&tv50[0], &tv[0]);
200 1.1.6.1 yamt timeval50_to_timeval(&tv50[1], &tv[1]);
201 1.1.6.1 yamt tvp = tv;
202 1.1.6.1 yamt } else
203 1.1.6.1 yamt tvp = NULL;
204 1.1.6.1 yamt return do_sys_utimes(l, vp, path, flag, tvp, UIO_SYSSPACE);
205 1.1.6.1 yamt }
206 1.1.6.1 yamt
207 1.1.6.1 yamt /*
208 1.1.6.1 yamt * Set the access and modification times given a path name; this
209 1.1.6.1 yamt * version follows links.
210 1.1.6.1 yamt */
211 1.1.6.1 yamt /* ARGSUSED */
212 1.1.6.1 yamt int
213 1.1.6.1 yamt compat_50_sys_utimes(struct lwp *l, const struct compat_50_sys_utimes_args *uap,
214 1.1.6.1 yamt register_t *retval)
215 1.1.6.1 yamt {
216 1.1.6.1 yamt /* {
217 1.1.6.1 yamt syscallarg(const char *) path;
218 1.1.6.1 yamt syscallarg(const struct timeval50 *) tptr;
219 1.1.6.1 yamt } */
220 1.1.6.1 yamt
221 1.1.6.1 yamt return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
222 1.1.6.1 yamt SCARG(uap, tptr));
223 1.1.6.1 yamt }
224 1.1.6.1 yamt
225 1.1.6.1 yamt /*
226 1.1.6.1 yamt * Set the access and modification times given a file descriptor.
227 1.1.6.1 yamt */
228 1.1.6.1 yamt /* ARGSUSED */
229 1.1.6.1 yamt int
230 1.1.6.1 yamt compat_50_sys_futimes(struct lwp *l,
231 1.1.6.1 yamt const struct compat_50_sys_futimes_args *uap, register_t *retval)
232 1.1.6.1 yamt {
233 1.1.6.1 yamt /* {
234 1.1.6.1 yamt syscallarg(int) fd;
235 1.1.6.1 yamt syscallarg(const struct timeval50 *) tptr;
236 1.1.6.1 yamt } */
237 1.1.6.1 yamt int error;
238 1.1.6.1 yamt struct file *fp;
239 1.1.6.1 yamt
240 1.1.6.1 yamt /* fd_getvnode() will use the descriptor for us */
241 1.1.6.1 yamt if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
242 1.1.6.1 yamt return error;
243 1.1.6.1 yamt error = compat_50_do_sys_utimes(l, fp->f_data, NULL, 0,
244 1.1.6.1 yamt SCARG(uap, tptr));
245 1.1.6.1 yamt fd_putfile(SCARG(uap, fd));
246 1.1.6.1 yamt return error;
247 1.1.6.1 yamt }
248 1.1.6.1 yamt
249 1.1.6.1 yamt /*
250 1.1.6.1 yamt * Set the access and modification times given a path name; this
251 1.1.6.1 yamt * version does not follow links.
252 1.1.6.1 yamt */
253 1.1.6.1 yamt int
254 1.1.6.1 yamt compat_50_sys_lutimes(struct lwp *l,
255 1.1.6.1 yamt const struct compat_50_sys_lutimes_args *uap, register_t *retval)
256 1.1.6.1 yamt {
257 1.1.6.1 yamt /* {
258 1.1.6.1 yamt syscallarg(const char *) path;
259 1.1.6.1 yamt syscallarg(const struct timeval50 *) tptr;
260 1.1.6.1 yamt } */
261 1.1.6.1 yamt
262 1.1.6.1 yamt return compat_50_do_sys_utimes(l, NULL, SCARG(uap, path), NOFOLLOW,
263 1.1.6.1 yamt SCARG(uap, tptr));
264 1.1.6.1 yamt }
265 1.1.6.1 yamt
266 1.1.6.1 yamt int
267 1.1.6.1 yamt compat_50_sys_lfs_segwait(struct lwp *l,
268 1.1.6.1 yamt const struct compat_50_sys_lfs_segwait_args *uap, register_t *retval)
269 1.1.6.1 yamt {
270 1.1.6.1 yamt /* {
271 1.1.6.1 yamt syscallarg(fsid_t *) fsidp;
272 1.1.6.1 yamt syscallarg(struct timeval50 *) tv;
273 1.1.6.1 yamt } */
274 1.1.6.1 yamt #ifdef notyet
275 1.1.6.1 yamt struct timeval atv;
276 1.1.6.1 yamt struct timeval50 atv50;
277 1.1.6.1 yamt fsid_t fsid;
278 1.1.6.1 yamt int error;
279 1.1.6.1 yamt
280 1.1.6.1 yamt /* XXX need we be su to segwait? */
281 1.1.6.1 yamt if ((error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
282 1.1.6.1 yamt NULL)) != 0)
283 1.1.6.1 yamt return (error);
284 1.1.6.1 yamt if ((error = copyin(SCARG(uap, fsidp), &fsid, sizeof(fsid_t))) != 0)
285 1.1.6.1 yamt return (error);
286 1.1.6.1 yamt
287 1.1.6.1 yamt if (SCARG(uap, tv)) {
288 1.1.6.1 yamt error = copyin(SCARG(uap, tv), &atv50, sizeof(atv50));
289 1.1.6.1 yamt if (error)
290 1.1.6.1 yamt return (error);
291 1.1.6.1 yamt timeval50_to_timeval(&atv50, &atv);
292 1.1.6.1 yamt if (itimerfix(&atv))
293 1.1.6.1 yamt return (EINVAL);
294 1.1.6.1 yamt } else /* NULL or invalid */
295 1.1.6.1 yamt atv.tv_sec = atv.tv_usec = 0;
296 1.1.6.1 yamt return lfs_segwait(&fsid, &atv);
297 1.1.6.1 yamt #else
298 1.1.6.1 yamt return ENOSYS;
299 1.1.6.1 yamt #endif
300 1.1.6.1 yamt }
301 1.1.6.1 yamt
302 1.1.6.1 yamt int
303 1.1.6.1 yamt compat_50_sys_mknod(struct lwp *l,
304 1.1.6.1 yamt const struct compat_50_sys_mknod_args *uap, register_t *retval)
305 1.1.6.1 yamt {
306 1.1.6.1 yamt /* {
307 1.1.6.1 yamt syscallarg(const char *) path;
308 1.1.6.1 yamt syscallarg(mode_t) mode;
309 1.1.6.1 yamt syscallarg(uint32_t) dev;
310 1.1.6.1 yamt } */
311 1.1.6.1 yamt return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
312 1.1.6.1 yamt SCARG(uap, dev), retval);
313 1.1.6.1 yamt }
314