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