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