linux_file.c revision 1.37.2.8 1 1.37.2.8 nathanw /* $NetBSD: linux_file.c,v 1.37.2.8 2002/04/01 07:44:25 nathanw Exp $ */
2 1.23 erh
3 1.23 erh /*-
4 1.25 fvdl * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5 1.23 erh * All rights reserved.
6 1.23 erh *
7 1.23 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.25 fvdl * by Frank van der Linden and Eric Haszlakiewicz.
9 1.23 erh *
10 1.23 erh * Redistribution and use in source and binary forms, with or without
11 1.23 erh * modification, are permitted provided that the following conditions
12 1.23 erh * are met:
13 1.23 erh * 1. Redistributions of source code must retain the above copyright
14 1.23 erh * notice, this list of conditions and the following disclaimer.
15 1.23 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.23 erh * notice, this list of conditions and the following disclaimer in the
17 1.23 erh * documentation and/or other materials provided with the distribution.
18 1.23 erh * 3. All advertising materials mentioning features or use of this software
19 1.23 erh * must display the following acknowledgement:
20 1.23 erh * This product includes software developed by the NetBSD
21 1.23 erh * Foundation, Inc. and its contributors.
22 1.23 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.23 erh * contributors may be used to endorse or promote products derived
24 1.23 erh * from this software without specific prior written permission.
25 1.23 erh *
26 1.23 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.23 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.23 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.23 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.23 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.23 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.23 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.23 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.23 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.23 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.23 erh * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fvdl */
38 1.1 fvdl
39 1.23 erh /*
40 1.23 erh * Functions in multiarch:
41 1.23 erh * linux_sys_llseek : linux_llseek.c
42 1.23 erh */
43 1.37.2.6 nathanw
44 1.37.2.6 nathanw #include <sys/cdefs.h>
45 1.37.2.8 nathanw __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.37.2.8 2002/04/01 07:44:25 nathanw Exp $");
46 1.23 erh
47 1.1 fvdl #include <sys/param.h>
48 1.1 fvdl #include <sys/systm.h>
49 1.1 fvdl #include <sys/namei.h>
50 1.1 fvdl #include <sys/proc.h>
51 1.1 fvdl #include <sys/file.h>
52 1.1 fvdl #include <sys/stat.h>
53 1.1 fvdl #include <sys/filedesc.h>
54 1.1 fvdl #include <sys/ioctl.h>
55 1.1 fvdl #include <sys/kernel.h>
56 1.1 fvdl #include <sys/mount.h>
57 1.1 fvdl #include <sys/malloc.h>
58 1.13 fvdl #include <sys/vnode.h>
59 1.13 fvdl #include <sys/tty.h>
60 1.37.2.2 nathanw #include <sys/socketvar.h>
61 1.13 fvdl #include <sys/conf.h>
62 1.37.2.4 nathanw #include <sys/pipe.h>
63 1.1 fvdl
64 1.1 fvdl #include <sys/syscallargs.h>
65 1.1 fvdl
66 1.24 christos #include <compat/linux/common/linux_types.h>
67 1.24 christos #include <compat/linux/common/linux_signal.h>
68 1.24 christos #include <compat/linux/common/linux_fcntl.h>
69 1.24 christos #include <compat/linux/common/linux_util.h>
70 1.24 christos #include <compat/linux/common/linux_machdep.h>
71 1.24 christos
72 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
73 1.14 christos
74 1.14 christos static int linux_to_bsd_ioflags __P((int));
75 1.14 christos static int bsd_to_linux_ioflags __P((int));
76 1.14 christos static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
77 1.14 christos static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
78 1.14 christos static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
79 1.37.2.1 nathanw static int linux_stat1 __P((struct lwp *, void *, register_t *, int));
80 1.14 christos
81 1.1 fvdl /*
82 1.1 fvdl * Some file-related calls are handled here. The usual flag conversion
83 1.1 fvdl * an structure conversion is done, and alternate emul path searching.
84 1.1 fvdl */
85 1.1 fvdl
86 1.1 fvdl /*
87 1.1 fvdl * The next two functions convert between the Linux and NetBSD values
88 1.1 fvdl * of the flags used in open(2) and fcntl(2).
89 1.1 fvdl */
90 1.1 fvdl static int
91 1.14 christos linux_to_bsd_ioflags(lflags)
92 1.14 christos int lflags;
93 1.1 fvdl {
94 1.1 fvdl int res = 0;
95 1.1 fvdl
96 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
97 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
98 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
99 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
100 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
101 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
102 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
103 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
104 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
105 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
106 1.1 fvdl res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
107 1.1 fvdl
108 1.1 fvdl return res;
109 1.1 fvdl }
110 1.1 fvdl
111 1.1 fvdl static int
112 1.14 christos bsd_to_linux_ioflags(bflags)
113 1.14 christos int bflags;
114 1.1 fvdl {
115 1.1 fvdl int res = 0;
116 1.1 fvdl
117 1.1 fvdl res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
118 1.1 fvdl res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
119 1.1 fvdl res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
120 1.1 fvdl res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
121 1.1 fvdl res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
122 1.1 fvdl res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
123 1.1 fvdl res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
124 1.1 fvdl res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
125 1.1 fvdl res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
126 1.1 fvdl res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
127 1.1 fvdl res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
128 1.1 fvdl
129 1.1 fvdl return res;
130 1.1 fvdl }
131 1.1 fvdl
132 1.1 fvdl /*
133 1.1 fvdl * creat(2) is an obsolete function, but it's present as a Linux
134 1.1 fvdl * system call, so let's deal with it.
135 1.1 fvdl *
136 1.23 erh * Note: On the Alpha this doesn't really exist in Linux, but it's defined
137 1.23 erh * in syscalls.master anyway so this doesn't have to be special cased.
138 1.23 erh *
139 1.1 fvdl * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
140 1.1 fvdl */
141 1.1 fvdl int
142 1.37.2.1 nathanw linux_sys_creat(l, v, retval)
143 1.37.2.1 nathanw struct lwp *l;
144 1.11 thorpej void *v;
145 1.11 thorpej register_t *retval;
146 1.11 thorpej {
147 1.12 mycroft struct linux_sys_creat_args /* {
148 1.27 christos syscallarg(const char *) path;
149 1.1 fvdl syscallarg(int) mode;
150 1.11 thorpej } */ *uap = v;
151 1.37.2.1 nathanw struct proc *p = l->l_proc;
152 1.12 mycroft struct sys_open_args oa;
153 1.1 fvdl caddr_t sg;
154 1.1 fvdl
155 1.37.2.8 nathanw sg = stackgap_init(p, 0);
156 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
157 1.1 fvdl
158 1.1 fvdl SCARG(&oa, path) = SCARG(uap, path);
159 1.1 fvdl SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
160 1.1 fvdl SCARG(&oa, mode) = SCARG(uap, mode);
161 1.12 mycroft
162 1.37.2.1 nathanw return sys_open(l, &oa, retval);
163 1.1 fvdl }
164 1.1 fvdl
165 1.1 fvdl /*
166 1.1 fvdl * open(2). Take care of the different flag values, and let the
167 1.1 fvdl * NetBSD syscall do the real work. See if this operation
168 1.1 fvdl * gives the current process a controlling terminal.
169 1.1 fvdl * (XXX is this necessary?)
170 1.1 fvdl */
171 1.1 fvdl int
172 1.37.2.1 nathanw linux_sys_open(l, v, retval)
173 1.37.2.1 nathanw struct lwp *l;
174 1.11 thorpej void *v;
175 1.11 thorpej register_t *retval;
176 1.11 thorpej {
177 1.12 mycroft struct linux_sys_open_args /* {
178 1.27 christos syscallarg(const char *) path;
179 1.1 fvdl syscallarg(int) flags;
180 1.1 fvdl syscallarg(int) mode;
181 1.11 thorpej } */ *uap = v;
182 1.37.2.1 nathanw struct proc *p = l->l_proc;
183 1.1 fvdl int error, fl;
184 1.12 mycroft struct sys_open_args boa;
185 1.1 fvdl caddr_t sg;
186 1.1 fvdl
187 1.37.2.8 nathanw sg = stackgap_init(p, 0);
188 1.1 fvdl
189 1.2 fvdl fl = linux_to_bsd_ioflags(SCARG(uap, flags));
190 1.1 fvdl
191 1.2 fvdl if (fl & O_CREAT)
192 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
193 1.2 fvdl else
194 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
195 1.1 fvdl
196 1.1 fvdl SCARG(&boa, path) = SCARG(uap, path);
197 1.1 fvdl SCARG(&boa, flags) = fl;
198 1.1 fvdl SCARG(&boa, mode) = SCARG(uap, mode);
199 1.2 fvdl
200 1.37.2.1 nathanw if ((error = sys_open(l, &boa, retval)))
201 1.1 fvdl return error;
202 1.1 fvdl
203 1.1 fvdl /*
204 1.1 fvdl * this bit from sunos_misc.c (and svr4_fcntl.c).
205 1.1 fvdl * If we are a session leader, and we don't have a controlling
206 1.1 fvdl * terminal yet, and the O_NOCTTY flag is not set, try to make
207 1.1 fvdl * this the controlling terminal.
208 1.1 fvdl */
209 1.1 fvdl if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
210 1.1 fvdl struct filedesc *fdp = p->p_fd;
211 1.37.2.2 nathanw struct file *fp;
212 1.37.2.2 nathanw
213 1.37.2.2 nathanw fp = fd_getfile(fdp, *retval);
214 1.1 fvdl
215 1.1 fvdl /* ignore any error, just give it a try */
216 1.37.2.2 nathanw if (fp != NULL && fp->f_type == DTYPE_VNODE)
217 1.1 fvdl (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
218 1.1 fvdl }
219 1.1 fvdl return 0;
220 1.1 fvdl }
221 1.1 fvdl
222 1.1 fvdl /*
223 1.1 fvdl * The next two functions take care of converting the flock
224 1.1 fvdl * structure back and forth between Linux and NetBSD format.
225 1.1 fvdl * The only difference in the structures is the order of
226 1.1 fvdl * the fields, and the 'whence' value.
227 1.1 fvdl */
228 1.1 fvdl static void
229 1.1 fvdl bsd_to_linux_flock(bfp, lfp)
230 1.1 fvdl struct flock *bfp;
231 1.1 fvdl struct linux_flock *lfp;
232 1.1 fvdl {
233 1.12 mycroft
234 1.1 fvdl lfp->l_start = bfp->l_start;
235 1.1 fvdl lfp->l_len = bfp->l_len;
236 1.1 fvdl lfp->l_pid = bfp->l_pid;
237 1.3 mycroft lfp->l_whence = bfp->l_whence;
238 1.3 mycroft switch (bfp->l_type) {
239 1.1 fvdl case F_RDLCK:
240 1.3 mycroft lfp->l_type = LINUX_F_RDLCK;
241 1.1 fvdl break;
242 1.1 fvdl case F_UNLCK:
243 1.3 mycroft lfp->l_type = LINUX_F_UNLCK;
244 1.1 fvdl break;
245 1.1 fvdl case F_WRLCK:
246 1.3 mycroft lfp->l_type = LINUX_F_WRLCK;
247 1.1 fvdl break;
248 1.1 fvdl }
249 1.1 fvdl }
250 1.1 fvdl
251 1.1 fvdl static void
252 1.1 fvdl linux_to_bsd_flock(lfp, bfp)
253 1.1 fvdl struct linux_flock *lfp;
254 1.1 fvdl struct flock *bfp;
255 1.1 fvdl {
256 1.12 mycroft
257 1.1 fvdl bfp->l_start = lfp->l_start;
258 1.1 fvdl bfp->l_len = lfp->l_len;
259 1.1 fvdl bfp->l_pid = lfp->l_pid;
260 1.3 mycroft bfp->l_whence = lfp->l_whence;
261 1.3 mycroft switch (lfp->l_type) {
262 1.1 fvdl case LINUX_F_RDLCK:
263 1.3 mycroft bfp->l_type = F_RDLCK;
264 1.1 fvdl break;
265 1.1 fvdl case LINUX_F_UNLCK:
266 1.3 mycroft bfp->l_type = F_UNLCK;
267 1.1 fvdl break;
268 1.1 fvdl case LINUX_F_WRLCK:
269 1.3 mycroft bfp->l_type = F_WRLCK;
270 1.1 fvdl break;
271 1.1 fvdl }
272 1.1 fvdl }
273 1.1 fvdl
274 1.1 fvdl /*
275 1.1 fvdl * Most actions in the fcntl() call are straightforward; simply
276 1.1 fvdl * pass control to the NetBSD system call. A few commands need
277 1.1 fvdl * conversions after the actual system call has done its work,
278 1.1 fvdl * because the flag values and lock structure are different.
279 1.1 fvdl */
280 1.1 fvdl int
281 1.37.2.1 nathanw linux_sys_fcntl(l, v, retval)
282 1.37.2.1 nathanw struct lwp *l;
283 1.11 thorpej void *v;
284 1.11 thorpej register_t *retval;
285 1.11 thorpej {
286 1.12 mycroft struct linux_sys_fcntl_args /* {
287 1.1 fvdl syscallarg(int) fd;
288 1.1 fvdl syscallarg(int) cmd;
289 1.1 fvdl syscallarg(void *) arg;
290 1.11 thorpej } */ *uap = v;
291 1.37.2.1 nathanw struct proc *p = l->l_proc;
292 1.23 erh int fd, cmd, error;
293 1.23 erh u_long val;
294 1.1 fvdl caddr_t arg, sg;
295 1.1 fvdl struct linux_flock lfl;
296 1.1 fvdl struct flock *bfp, bfl;
297 1.12 mycroft struct sys_fcntl_args fca;
298 1.13 fvdl struct filedesc *fdp;
299 1.13 fvdl struct file *fp;
300 1.13 fvdl struct vnode *vp;
301 1.13 fvdl struct vattr va;
302 1.13 fvdl long pgid;
303 1.13 fvdl struct pgrp *pgrp;
304 1.13 fvdl struct tty *tp, *(*d_tty) __P((dev_t));
305 1.1 fvdl
306 1.1 fvdl fd = SCARG(uap, fd);
307 1.1 fvdl cmd = SCARG(uap, cmd);
308 1.1 fvdl arg = (caddr_t) SCARG(uap, arg);
309 1.1 fvdl
310 1.1 fvdl switch (cmd) {
311 1.1 fvdl case LINUX_F_DUPFD:
312 1.1 fvdl cmd = F_DUPFD;
313 1.1 fvdl break;
314 1.1 fvdl case LINUX_F_GETFD:
315 1.1 fvdl cmd = F_GETFD;
316 1.1 fvdl break;
317 1.1 fvdl case LINUX_F_SETFD:
318 1.1 fvdl cmd = F_SETFD;
319 1.1 fvdl break;
320 1.1 fvdl case LINUX_F_GETFL:
321 1.1 fvdl SCARG(&fca, fd) = fd;
322 1.1 fvdl SCARG(&fca, cmd) = F_GETFL;
323 1.1 fvdl SCARG(&fca, arg) = arg;
324 1.37.2.1 nathanw if ((error = sys_fcntl(l, &fca, retval)))
325 1.1 fvdl return error;
326 1.1 fvdl retval[0] = bsd_to_linux_ioflags(retval[0]);
327 1.1 fvdl return 0;
328 1.37.2.4 nathanw case LINUX_F_SETFL: {
329 1.37.2.4 nathanw struct file *fp = NULL;
330 1.37.2.4 nathanw
331 1.23 erh val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
332 1.37.2.2 nathanw /*
333 1.37.2.4 nathanw * Linux seems to have same semantics for sending SIGIO to the
334 1.37.2.4 nathanw * read side of socket, but slighly different semantics
335 1.37.2.4 nathanw * for SIGIO to the write side. Rather than sending the SIGIO
336 1.37.2.4 nathanw * every time it's possible to write (directly) more data, it
337 1.37.2.4 nathanw * only sends SIGIO if last write(2) failed due to insufficient
338 1.37.2.4 nathanw * memory to hold the data. This is compatible enough
339 1.37.2.4 nathanw * with NetBSD semantics to not do anything about the
340 1.37.2.4 nathanw * difference.
341 1.37.2.2 nathanw *
342 1.37.2.4 nathanw * Linux does NOT send SIGIO for pipes. Deal with socketpair
343 1.37.2.4 nathanw * ones and DTYPE_PIPE ones. For these, we don't set
344 1.37.2.4 nathanw * the underlying flags (we don't pass O_ASYNC flag down
345 1.37.2.4 nathanw * to sys_fcntl()), but set the FASYNC flag for file descriptor,
346 1.37.2.4 nathanw * so that F_GETFL would report the ASYNC i/o is on.
347 1.37.2.2 nathanw */
348 1.37.2.4 nathanw if (val & O_ASYNC) {
349 1.37.2.4 nathanw if (((fp = fd_getfile(p->p_fd, fd)) == NULL))
350 1.37.2.2 nathanw return (EBADF);
351 1.37.2.2 nathanw
352 1.37.2.2 nathanw FILE_USE(fp);
353 1.37.2.2 nathanw
354 1.37.2.4 nathanw if (((fp->f_type == DTYPE_SOCKET) && fp->f_data
355 1.37.2.4 nathanw && ((struct socket *)fp->f_data)->so_state & SS_ISAPIPE)
356 1.37.2.4 nathanw || (fp->f_type == DTYPE_PIPE))
357 1.37.2.4 nathanw val &= ~O_ASYNC;
358 1.37.2.4 nathanw else {
359 1.37.2.4 nathanw /* not a pipe, do not modify anything */
360 1.37.2.4 nathanw FILE_UNUSE(fp, p);
361 1.37.2.4 nathanw fp = NULL;
362 1.37.2.2 nathanw }
363 1.37.2.4 nathanw }
364 1.37.2.2 nathanw
365 1.37.2.4 nathanw SCARG(&fca, fd) = fd;
366 1.37.2.4 nathanw SCARG(&fca, cmd) = F_SETFL;
367 1.37.2.4 nathanw SCARG(&fca, arg) = (caddr_t) val;
368 1.37.2.4 nathanw
369 1.37.2.4 nathanw error = sys_fcntl(l, &fca, retval);
370 1.37.2.4 nathanw
371 1.37.2.4 nathanw /* Now set the FASYNC flag for pipes */
372 1.37.2.4 nathanw if (fp) {
373 1.37.2.4 nathanw if (!error)
374 1.37.2.4 nathanw fp->f_flag |= FASYNC;
375 1.37.2.2 nathanw FILE_UNUSE(fp, p);
376 1.37.2.2 nathanw }
377 1.37.2.4 nathanw
378 1.37.2.4 nathanw return (error);
379 1.37.2.4 nathanw }
380 1.1 fvdl case LINUX_F_GETLK:
381 1.37.2.8 nathanw sg = stackgap_init(p, 0);
382 1.37.2.8 nathanw bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
383 1.18 kleink if ((error = copyin(arg, &lfl, sizeof lfl)))
384 1.18 kleink return error;
385 1.18 kleink linux_to_bsd_flock(&lfl, &bfl);
386 1.18 kleink if ((error = copyout(&bfl, bfp, sizeof bfl)))
387 1.18 kleink return error;
388 1.1 fvdl SCARG(&fca, fd) = fd;
389 1.1 fvdl SCARG(&fca, cmd) = F_GETLK;
390 1.1 fvdl SCARG(&fca, arg) = bfp;
391 1.37.2.1 nathanw if ((error = sys_fcntl(l, &fca, retval)))
392 1.1 fvdl return error;
393 1.1 fvdl if ((error = copyin(bfp, &bfl, sizeof bfl)))
394 1.1 fvdl return error;
395 1.1 fvdl bsd_to_linux_flock(&bfl, &lfl);
396 1.1 fvdl return copyout(&lfl, arg, sizeof lfl);
397 1.1 fvdl break;
398 1.37.2.8 nathanw
399 1.1 fvdl case LINUX_F_SETLK:
400 1.1 fvdl case LINUX_F_SETLKW:
401 1.1 fvdl cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
402 1.1 fvdl if ((error = copyin(arg, &lfl, sizeof lfl)))
403 1.1 fvdl return error;
404 1.1 fvdl linux_to_bsd_flock(&lfl, &bfl);
405 1.37.2.8 nathanw sg = stackgap_init(p, 0);
406 1.37.2.8 nathanw bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
407 1.1 fvdl if ((error = copyout(&bfl, bfp, sizeof bfl)))
408 1.1 fvdl return error;
409 1.1 fvdl SCARG(&fca, fd) = fd;
410 1.1 fvdl SCARG(&fca, cmd) = cmd;
411 1.1 fvdl SCARG(&fca, arg) = bfp;
412 1.37.2.1 nathanw return sys_fcntl(l, &fca, retval);
413 1.1 fvdl break;
414 1.37.2.8 nathanw
415 1.1 fvdl case LINUX_F_SETOWN:
416 1.13 fvdl case LINUX_F_GETOWN:
417 1.13 fvdl /*
418 1.37.2.8 nathanw * We need to route fcntl() for tty descriptors around normal
419 1.37.2.8 nathanw * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
420 1.37.2.8 nathanw * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
421 1.37.2.8 nathanw * this is not a problem.
422 1.13 fvdl */
423 1.13 fvdl fdp = p->p_fd;
424 1.37.2.2 nathanw if ((fp = fd_getfile(fdp, fd)) == NULL)
425 1.13 fvdl return EBADF;
426 1.37.2.8 nathanw /* FILE_USE() not needed here */
427 1.37.2.8 nathanw if (fp->f_type != DTYPE_VNODE) {
428 1.37.2.8 nathanw notty:
429 1.37.2.8 nathanw /* Not a tty, proceed with common fcntl() */
430 1.13 fvdl cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
431 1.13 fvdl break;
432 1.13 fvdl }
433 1.37.2.8 nathanw
434 1.37.2.8 nathanw /* check that the vnode is a tty */
435 1.13 fvdl vp = (struct vnode *)fp->f_data;
436 1.13 fvdl if (vp->v_type != VCHR)
437 1.37.2.8 nathanw goto notty;
438 1.13 fvdl if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
439 1.13 fvdl return error;
440 1.13 fvdl d_tty = cdevsw[major(va.va_rdev)].d_tty;
441 1.13 fvdl if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
442 1.37.2.8 nathanw goto notty;
443 1.37.2.8 nathanw
444 1.37.2.8 nathanw /* set tty pg_id appropriately */
445 1.13 fvdl if (cmd == LINUX_F_GETOWN) {
446 1.13 fvdl retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
447 1.13 fvdl return 0;
448 1.13 fvdl }
449 1.13 fvdl if ((long)arg <= 0) {
450 1.13 fvdl pgid = -(long)arg;
451 1.13 fvdl } else {
452 1.13 fvdl struct proc *p1 = pfind((long)arg);
453 1.37.2.8 nathanw if (p1 == NULL)
454 1.13 fvdl return (ESRCH);
455 1.13 fvdl pgid = (long)p1->p_pgrp->pg_id;
456 1.13 fvdl }
457 1.13 fvdl pgrp = pgfind(pgid);
458 1.13 fvdl if (pgrp == NULL || pgrp->pg_session != p->p_session)
459 1.13 fvdl return EPERM;
460 1.13 fvdl tp->t_pgrp = pgrp;
461 1.13 fvdl return 0;
462 1.37.2.8 nathanw
463 1.1 fvdl default:
464 1.1 fvdl return EOPNOTSUPP;
465 1.1 fvdl }
466 1.1 fvdl
467 1.1 fvdl SCARG(&fca, fd) = fd;
468 1.1 fvdl SCARG(&fca, cmd) = cmd;
469 1.1 fvdl SCARG(&fca, arg) = arg;
470 1.12 mycroft
471 1.37.2.1 nathanw return sys_fcntl(l, &fca, retval);
472 1.1 fvdl }
473 1.1 fvdl
474 1.1 fvdl /*
475 1.1 fvdl * Convert a NetBSD stat structure to a Linux stat structure.
476 1.1 fvdl * Only the order of the fields and the padding in the structure
477 1.9 fvdl * is different. linux_fakedev is a machine-dependent function
478 1.9 fvdl * which optionally converts device driver major/minor numbers
479 1.9 fvdl * (XXX horrible, but what can you do against code that compares
480 1.9 fvdl * things against constant major device numbers? sigh)
481 1.1 fvdl */
482 1.1 fvdl static void
483 1.1 fvdl bsd_to_linux_stat(bsp, lsp)
484 1.1 fvdl struct stat *bsp;
485 1.1 fvdl struct linux_stat *lsp;
486 1.1 fvdl {
487 1.12 mycroft
488 1.37.2.7 nathanw lsp->lst_dev = linux_fakedev(bsp->st_dev, 0);
489 1.1 fvdl lsp->lst_ino = bsp->st_ino;
490 1.19 christos lsp->lst_mode = (linux_mode_t)bsp->st_mode;
491 1.19 christos if (bsp->st_nlink >= (1 << 15))
492 1.19 christos lsp->lst_nlink = (1 << 15) - 1;
493 1.19 christos else
494 1.19 christos lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
495 1.1 fvdl lsp->lst_uid = bsp->st_uid;
496 1.1 fvdl lsp->lst_gid = bsp->st_gid;
497 1.37.2.7 nathanw lsp->lst_rdev = linux_fakedev(bsp->st_rdev, 1);
498 1.1 fvdl lsp->lst_size = bsp->st_size;
499 1.1 fvdl lsp->lst_blksize = bsp->st_blksize;
500 1.1 fvdl lsp->lst_blocks = bsp->st_blocks;
501 1.1 fvdl lsp->lst_atime = bsp->st_atime;
502 1.1 fvdl lsp->lst_mtime = bsp->st_mtime;
503 1.1 fvdl lsp->lst_ctime = bsp->st_ctime;
504 1.1 fvdl }
505 1.1 fvdl
506 1.1 fvdl /*
507 1.1 fvdl * The stat functions below are plain sailing. stat and lstat are handled
508 1.1 fvdl * by one function to avoid code duplication.
509 1.1 fvdl */
510 1.1 fvdl int
511 1.37.2.1 nathanw linux_sys_fstat(l, v, retval)
512 1.37.2.1 nathanw struct lwp *l;
513 1.11 thorpej void *v;
514 1.11 thorpej register_t *retval;
515 1.11 thorpej {
516 1.12 mycroft struct linux_sys_fstat_args /* {
517 1.1 fvdl syscallarg(int) fd;
518 1.1 fvdl syscallarg(linux_stat *) sp;
519 1.11 thorpej } */ *uap = v;
520 1.37.2.1 nathanw struct proc *p = l->l_proc;
521 1.21 thorpej struct sys___fstat13_args fsa;
522 1.1 fvdl struct linux_stat tmplst;
523 1.1 fvdl struct stat *st,tmpst;
524 1.1 fvdl caddr_t sg;
525 1.1 fvdl int error;
526 1.1 fvdl
527 1.37.2.8 nathanw sg = stackgap_init(p, 0);
528 1.1 fvdl
529 1.37.2.8 nathanw st = stackgap_alloc(p, &sg, sizeof (struct stat));
530 1.1 fvdl
531 1.1 fvdl SCARG(&fsa, fd) = SCARG(uap, fd);
532 1.1 fvdl SCARG(&fsa, sb) = st;
533 1.1 fvdl
534 1.37.2.1 nathanw if ((error = sys___fstat13(l, &fsa, retval)))
535 1.1 fvdl return error;
536 1.1 fvdl
537 1.1 fvdl if ((error = copyin(st, &tmpst, sizeof tmpst)))
538 1.1 fvdl return error;
539 1.1 fvdl
540 1.1 fvdl bsd_to_linux_stat(&tmpst, &tmplst);
541 1.1 fvdl
542 1.1 fvdl if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
543 1.1 fvdl return error;
544 1.1 fvdl
545 1.1 fvdl return 0;
546 1.1 fvdl }
547 1.1 fvdl
548 1.1 fvdl static int
549 1.37.2.1 nathanw linux_stat1(l, v, retval, dolstat)
550 1.37.2.1 nathanw struct lwp *l;
551 1.14 christos void *v;
552 1.1 fvdl register_t *retval;
553 1.1 fvdl int dolstat;
554 1.1 fvdl {
555 1.21 thorpej struct sys___stat13_args sa;
556 1.1 fvdl struct linux_stat tmplst;
557 1.1 fvdl struct stat *st, tmpst;
558 1.37.2.1 nathanw struct proc *p = l->l_proc;
559 1.1 fvdl caddr_t sg;
560 1.1 fvdl int error;
561 1.14 christos struct linux_sys_stat_args *uap = v;
562 1.1 fvdl
563 1.37.2.8 nathanw sg = stackgap_init(p, 0);
564 1.37.2.8 nathanw st = stackgap_alloc(p, &sg, sizeof (struct stat));
565 1.37 jdolecek if (dolstat)
566 1.37 jdolecek CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
567 1.37 jdolecek else
568 1.37 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
569 1.1 fvdl
570 1.1 fvdl SCARG(&sa, ub) = st;
571 1.1 fvdl SCARG(&sa, path) = SCARG(uap, path);
572 1.1 fvdl
573 1.37.2.1 nathanw if ((error = (dolstat ? sys___lstat13(l, &sa, retval) :
574 1.37.2.1 nathanw sys___stat13(l, &sa, retval))))
575 1.1 fvdl return error;
576 1.1 fvdl
577 1.1 fvdl if ((error = copyin(st, &tmpst, sizeof tmpst)))
578 1.1 fvdl return error;
579 1.1 fvdl
580 1.1 fvdl bsd_to_linux_stat(&tmpst, &tmplst);
581 1.1 fvdl
582 1.1 fvdl if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
583 1.1 fvdl return error;
584 1.1 fvdl
585 1.1 fvdl return 0;
586 1.1 fvdl }
587 1.1 fvdl
588 1.1 fvdl int
589 1.37.2.1 nathanw linux_sys_stat(l, v, retval)
590 1.37.2.1 nathanw struct lwp *l;
591 1.11 thorpej void *v;
592 1.11 thorpej register_t *retval;
593 1.11 thorpej {
594 1.12 mycroft struct linux_sys_stat_args /* {
595 1.27 christos syscallarg(const char *) path;
596 1.1 fvdl syscallarg(struct linux_stat *) sp;
597 1.11 thorpej } */ *uap = v;
598 1.11 thorpej
599 1.37.2.1 nathanw return linux_stat1(l, uap, retval, 0);
600 1.1 fvdl }
601 1.1 fvdl
602 1.23 erh /* Note: this is "newlstat" in the Linux sources */
603 1.23 erh /* (we don't bother with the old lstat currently) */
604 1.1 fvdl int
605 1.37.2.1 nathanw linux_sys_lstat(l, v, retval)
606 1.37.2.1 nathanw struct lwp *l;
607 1.11 thorpej void *v;
608 1.11 thorpej register_t *retval;
609 1.11 thorpej {
610 1.12 mycroft struct linux_sys_lstat_args /* {
611 1.27 christos syscallarg(const char *) path;
612 1.1 fvdl syscallarg(struct linux_stat *) sp;
613 1.11 thorpej } */ *uap = v;
614 1.11 thorpej
615 1.37.2.1 nathanw return linux_stat1(l, uap, retval, 1);
616 1.1 fvdl }
617 1.1 fvdl
618 1.1 fvdl /*
619 1.10 fvdl * The following syscalls are mostly here because of the alternate path check.
620 1.1 fvdl */
621 1.1 fvdl int
622 1.37.2.1 nathanw linux_sys_access(l, v, retval)
623 1.37.2.1 nathanw struct lwp *l;
624 1.11 thorpej void *v;
625 1.11 thorpej register_t *retval;
626 1.11 thorpej {
627 1.12 mycroft struct linux_sys_access_args /* {
628 1.27 christos syscallarg(const char *) path;
629 1.1 fvdl syscallarg(int) flags;
630 1.11 thorpej } */ *uap = v;
631 1.37.2.1 nathanw struct proc *p = l->l_proc;
632 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
633 1.1 fvdl
634 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
635 1.1 fvdl
636 1.37.2.1 nathanw return sys_access(l, uap, retval);
637 1.2 fvdl }
638 1.2 fvdl
639 1.2 fvdl int
640 1.37.2.1 nathanw linux_sys_unlink(l, v, retval)
641 1.37.2.1 nathanw struct lwp *l;
642 1.11 thorpej void *v;
643 1.2 fvdl register_t *retval;
644 1.2 fvdl
645 1.2 fvdl {
646 1.12 mycroft struct linux_sys_unlink_args /* {
647 1.27 christos syscallarg(const char *) path;
648 1.11 thorpej } */ *uap = v;
649 1.37.2.1 nathanw struct proc *p = l->l_proc;
650 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
651 1.2 fvdl
652 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
653 1.2 fvdl
654 1.37.2.1 nathanw return sys_unlink(l, uap, retval);
655 1.2 fvdl }
656 1.2 fvdl
657 1.10 fvdl int
658 1.37.2.1 nathanw linux_sys_chdir(l, v, retval)
659 1.37.2.1 nathanw struct lwp *l;
660 1.11 thorpej void *v;
661 1.11 thorpej register_t *retval;
662 1.11 thorpej {
663 1.12 mycroft struct linux_sys_chdir_args /* {
664 1.27 christos syscallarg(const char *) path;
665 1.11 thorpej } */ *uap = v;
666 1.37.2.1 nathanw struct proc *p = l->l_proc;
667 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
668 1.2 fvdl
669 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
670 1.2 fvdl
671 1.37.2.1 nathanw return sys_chdir(l, uap, retval);
672 1.2 fvdl }
673 1.2 fvdl
674 1.2 fvdl int
675 1.37.2.1 nathanw linux_sys_mknod(l, v, retval)
676 1.37.2.1 nathanw struct lwp *l;
677 1.11 thorpej void *v;
678 1.11 thorpej register_t *retval;
679 1.11 thorpej {
680 1.12 mycroft struct linux_sys_mknod_args /* {
681 1.27 christos syscallarg(const char *) path;
682 1.2 fvdl syscallarg(int) mode;
683 1.2 fvdl syscallarg(int) dev;
684 1.11 thorpej } */ *uap = v;
685 1.37.2.1 nathanw struct proc *p = l->l_proc;
686 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
687 1.21 thorpej struct sys_mkfifo_args bma;
688 1.2 fvdl
689 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
690 1.2 fvdl
691 1.10 fvdl /*
692 1.37.2.3 nathanw * BSD handles FIFOs separately
693 1.10 fvdl */
694 1.21 thorpej if (SCARG(uap, mode) & S_IFIFO) {
695 1.21 thorpej SCARG(&bma, path) = SCARG(uap, path);
696 1.21 thorpej SCARG(&bma, mode) = SCARG(uap, mode);
697 1.37.2.1 nathanw return sys_mkfifo(l, uap, retval);
698 1.21 thorpej } else
699 1.37.2.1 nathanw return sys_mknod(l, uap, retval);
700 1.2 fvdl }
701 1.2 fvdl
702 1.2 fvdl int
703 1.37.2.1 nathanw linux_sys_chmod(l, v, retval)
704 1.37.2.1 nathanw struct lwp *l;
705 1.11 thorpej void *v;
706 1.11 thorpej register_t *retval;
707 1.11 thorpej {
708 1.12 mycroft struct linux_sys_chmod_args /* {
709 1.27 christos syscallarg(const char *) path;
710 1.2 fvdl syscallarg(int) mode;
711 1.11 thorpej } */ *uap = v;
712 1.37.2.1 nathanw struct proc *p = l->l_proc;
713 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
714 1.2 fvdl
715 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
716 1.2 fvdl
717 1.37.2.1 nathanw return sys_chmod(l, uap, retval);
718 1.2 fvdl }
719 1.2 fvdl
720 1.37.2.7 nathanw #if defined(__i386__) || defined(__m68k__) || defined(__arm__)
721 1.2 fvdl int
722 1.37.2.1 nathanw linux_sys_chown16(l, v, retval)
723 1.37.2.1 nathanw struct lwp *l;
724 1.11 thorpej void *v;
725 1.11 thorpej register_t *retval;
726 1.11 thorpej {
727 1.31 fvdl struct linux_sys_chown16_args /* {
728 1.27 christos syscallarg(const char *) path;
729 1.2 fvdl syscallarg(int) uid;
730 1.2 fvdl syscallarg(int) gid;
731 1.11 thorpej } */ *uap = v;
732 1.37.2.1 nathanw struct proc *p = l->l_proc;
733 1.22 kleink struct sys___posix_chown_args bca;
734 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
735 1.2 fvdl
736 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
737 1.2 fvdl
738 1.10 fvdl SCARG(&bca, path) = SCARG(uap, path);
739 1.10 fvdl SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
740 1.10 fvdl (uid_t)-1 : SCARG(uap, uid);
741 1.10 fvdl SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
742 1.10 fvdl (gid_t)-1 : SCARG(uap, gid);
743 1.10 fvdl
744 1.37.2.1 nathanw return sys___posix_chown(l, &bca, retval);
745 1.10 fvdl }
746 1.10 fvdl
747 1.10 fvdl int
748 1.37.2.1 nathanw linux_sys_fchown16(l, v, retval)
749 1.37.2.1 nathanw struct lwp *l;
750 1.11 thorpej void *v;
751 1.11 thorpej register_t *retval;
752 1.11 thorpej {
753 1.31 fvdl struct linux_sys_fchown16_args /* {
754 1.10 fvdl syscallarg(int) fd;
755 1.10 fvdl syscallarg(int) uid;
756 1.10 fvdl syscallarg(int) gid;
757 1.11 thorpej } */ *uap = v;
758 1.22 kleink struct sys___posix_fchown_args bfa;
759 1.10 fvdl
760 1.10 fvdl SCARG(&bfa, fd) = SCARG(uap, fd);
761 1.10 fvdl SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
762 1.10 fvdl (uid_t)-1 : SCARG(uap, uid);
763 1.10 fvdl SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
764 1.10 fvdl (gid_t)-1 : SCARG(uap, gid);
765 1.10 fvdl
766 1.37.2.1 nathanw return sys___posix_fchown(l, &bfa, retval);
767 1.2 fvdl }
768 1.2 fvdl
769 1.2 fvdl int
770 1.37.2.1 nathanw linux_sys_lchown16(l, v, retval)
771 1.37.2.1 nathanw struct lwp *l;
772 1.23 erh void *v;
773 1.23 erh register_t *retval;
774 1.23 erh {
775 1.31 fvdl struct linux_sys_lchown16_args /* {
776 1.23 erh syscallarg(char *) path;
777 1.23 erh syscallarg(int) uid;
778 1.23 erh syscallarg(int) gid;
779 1.23 erh } */ *uap = v;
780 1.37.2.1 nathanw struct proc *p = l->l_proc;
781 1.23 erh struct sys___posix_lchown_args bla;
782 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
783 1.33 fvdl
784 1.36 jdolecek CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
785 1.23 erh
786 1.23 erh SCARG(&bla, path) = SCARG(uap, path);
787 1.23 erh SCARG(&bla, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
788 1.23 erh (uid_t)-1 : SCARG(uap, uid);
789 1.23 erh SCARG(&bla, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
790 1.23 erh (gid_t)-1 : SCARG(uap, gid);
791 1.23 erh
792 1.37.2.1 nathanw return sys___posix_lchown(l, &bla, retval);
793 1.33 fvdl }
794 1.37.2.7 nathanw #endif /* __i386__ || __m68k__ || __arm__ */
795 1.37.2.5 nathanw #if defined (__i386__) || defined (__m68k__) || \
796 1.37.2.7 nathanw defined (__powerpc__) || defined (__mips__) || defined(__arm__)
797 1.33 fvdl int
798 1.37.2.1 nathanw linux_sys_chown(l, v, retval)
799 1.37.2.1 nathanw struct lwp *l;
800 1.33 fvdl void *v;
801 1.33 fvdl register_t *retval;
802 1.33 fvdl {
803 1.33 fvdl struct linux_sys_chown_args /* {
804 1.33 fvdl syscallarg(char *) path;
805 1.33 fvdl syscallarg(int) uid;
806 1.33 fvdl syscallarg(int) gid;
807 1.33 fvdl } */ *uap = v;
808 1.37.2.1 nathanw struct proc *p = l->l_proc;
809 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
810 1.33 fvdl
811 1.33 fvdl CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
812 1.33 fvdl
813 1.37.2.1 nathanw return sys___posix_chown(l, uap, retval);
814 1.33 fvdl }
815 1.33 fvdl
816 1.33 fvdl int
817 1.37.2.1 nathanw linux_sys_lchown(l, v, retval)
818 1.37.2.1 nathanw struct lwp *l;
819 1.33 fvdl void *v;
820 1.33 fvdl register_t *retval;
821 1.33 fvdl {
822 1.33 fvdl struct linux_sys_lchown_args /* {
823 1.33 fvdl syscallarg(char *) path;
824 1.33 fvdl syscallarg(int) uid;
825 1.33 fvdl syscallarg(int) gid;
826 1.33 fvdl } */ *uap = v;
827 1.37.2.1 nathanw struct proc *p = l->l_proc;
828 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
829 1.33 fvdl
830 1.36 jdolecek CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
831 1.33 fvdl
832 1.37.2.1 nathanw return sys___posix_lchown(l, uap, retval);
833 1.23 erh }
834 1.37.2.7 nathanw #endif /* __i386__ || __m68k__ || __powerpc__ || __mips__ || __arm__ */
835 1.32 thorpej
836 1.23 erh int
837 1.37.2.1 nathanw linux_sys_rename(l, v, retval)
838 1.37.2.1 nathanw struct lwp *l;
839 1.11 thorpej void *v;
840 1.11 thorpej register_t *retval;
841 1.11 thorpej {
842 1.12 mycroft struct linux_sys_rename_args /* {
843 1.27 christos syscallarg(const char *) from;
844 1.27 christos syscallarg(const char *) to;
845 1.11 thorpej } */ *uap = v;
846 1.37.2.1 nathanw struct proc *p = l->l_proc;
847 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
848 1.2 fvdl
849 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
850 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
851 1.2 fvdl
852 1.37.2.1 nathanw return sys___posix_rename(l, uap, retval);
853 1.2 fvdl }
854 1.2 fvdl
855 1.2 fvdl int
856 1.37.2.1 nathanw linux_sys_mkdir(l, v, retval)
857 1.37.2.1 nathanw struct lwp *l;
858 1.11 thorpej void *v;
859 1.11 thorpej register_t *retval;
860 1.11 thorpej {
861 1.12 mycroft struct linux_sys_mkdir_args /* {
862 1.27 christos syscallarg(const char *) path;
863 1.7 fvdl syscallarg(int) mode;
864 1.11 thorpej } */ *uap = v;
865 1.37.2.1 nathanw struct proc *p = l->l_proc;
866 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
867 1.2 fvdl
868 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
869 1.12 mycroft
870 1.37.2.1 nathanw return sys_mkdir(l, uap, retval);
871 1.2 fvdl }
872 1.2 fvdl
873 1.2 fvdl int
874 1.37.2.1 nathanw linux_sys_rmdir(l, v, retval)
875 1.37.2.1 nathanw struct lwp *l;
876 1.11 thorpej void *v;
877 1.11 thorpej register_t *retval;
878 1.11 thorpej {
879 1.12 mycroft struct linux_sys_rmdir_args /* {
880 1.27 christos syscallarg(const char *) path;
881 1.11 thorpej } */ *uap = v;
882 1.37.2.1 nathanw struct proc *p = l->l_proc;
883 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
884 1.2 fvdl
885 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
886 1.12 mycroft
887 1.37.2.1 nathanw return sys_rmdir(l, uap, retval);
888 1.2 fvdl }
889 1.2 fvdl
890 1.2 fvdl int
891 1.37.2.1 nathanw linux_sys_symlink(l, v, retval)
892 1.37.2.1 nathanw struct lwp *l;
893 1.11 thorpej void *v;
894 1.11 thorpej register_t *retval;
895 1.11 thorpej {
896 1.12 mycroft struct linux_sys_symlink_args /* {
897 1.27 christos syscallarg(const char *) path;
898 1.27 christos syscallarg(const char *) to;
899 1.11 thorpej } */ *uap = v;
900 1.37.2.1 nathanw struct proc *p = l->l_proc;
901 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
902 1.2 fvdl
903 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
904 1.30 jdolecek CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
905 1.2 fvdl
906 1.37.2.1 nathanw return sys_symlink(l, uap, retval);
907 1.34 fvdl }
908 1.34 fvdl
909 1.34 fvdl int
910 1.37.2.1 nathanw linux_sys_link(l, v, retval)
911 1.37.2.1 nathanw struct lwp *l;
912 1.34 fvdl void *v;
913 1.34 fvdl register_t *retval;
914 1.34 fvdl {
915 1.34 fvdl struct linux_sys_link_args /* {
916 1.34 fvdl syscallarg(const char *) path;
917 1.34 fvdl syscallarg(const char *) link;
918 1.34 fvdl } */ *uap = v;
919 1.37.2.1 nathanw struct proc *p = l->l_proc;
920 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
921 1.34 fvdl
922 1.34 fvdl CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
923 1.34 fvdl CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
924 1.34 fvdl
925 1.37.2.1 nathanw return sys_link(l, uap, retval);
926 1.2 fvdl }
927 1.2 fvdl
928 1.2 fvdl int
929 1.37.2.1 nathanw linux_sys_readlink(l, v, retval)
930 1.37.2.1 nathanw struct lwp *l;
931 1.11 thorpej void *v;
932 1.11 thorpej register_t *retval;
933 1.11 thorpej {
934 1.12 mycroft struct linux_sys_readlink_args /* {
935 1.27 christos syscallarg(const char *) name;
936 1.2 fvdl syscallarg(char *) buf;
937 1.2 fvdl syscallarg(int) count;
938 1.11 thorpej } */ *uap = v;
939 1.37.2.1 nathanw struct proc *p = l->l_proc;
940 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
941 1.2 fvdl
942 1.36 jdolecek CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, name));
943 1.12 mycroft
944 1.37.2.1 nathanw return sys_readlink(l, uap, retval);
945 1.2 fvdl }
946 1.2 fvdl
947 1.2 fvdl int
948 1.37.2.1 nathanw linux_sys_truncate(l, v, retval)
949 1.37.2.1 nathanw struct lwp *l;
950 1.11 thorpej void *v;
951 1.11 thorpej register_t *retval;
952 1.11 thorpej {
953 1.12 mycroft struct linux_sys_truncate_args /* {
954 1.27 christos syscallarg(const char *) path;
955 1.2 fvdl syscallarg(long) length;
956 1.11 thorpej } */ *uap = v;
957 1.37.2.1 nathanw struct proc *p = l->l_proc;
958 1.37.2.8 nathanw caddr_t sg = stackgap_init(p, 0);
959 1.2 fvdl
960 1.30 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
961 1.12 mycroft
962 1.37.2.1 nathanw return compat_43_sys_truncate(l, uap, retval);
963 1.15 fvdl }
964 1.15 fvdl
965 1.15 fvdl /*
966 1.15 fvdl * This is just fsync() for now (just as it is in the Linux kernel)
967 1.23 erh * Note: this is not implemented under Linux on Alpha and Arm
968 1.23 erh * but should still be defined in our syscalls.master.
969 1.23 erh * (syscall #148 on the arm)
970 1.15 fvdl */
971 1.15 fvdl int
972 1.37.2.1 nathanw linux_sys_fdatasync(l, v, retval)
973 1.37.2.1 nathanw struct lwp *l;
974 1.15 fvdl void *v;
975 1.15 fvdl register_t *retval;
976 1.15 fvdl {
977 1.16 christos #ifdef notdef
978 1.15 fvdl struct linux_sys_fdatasync_args /* {
979 1.15 fvdl syscallarg(int) fd;
980 1.15 fvdl } */ *uap = v;
981 1.16 christos #endif
982 1.37.2.1 nathanw return sys_fsync(l, v, retval);
983 1.28 tron }
984 1.28 tron
985 1.28 tron /*
986 1.28 tron * pread(2).
987 1.28 tron */
988 1.28 tron int
989 1.37.2.1 nathanw linux_sys_pread(l, v, retval)
990 1.37.2.1 nathanw struct lwp *l;
991 1.28 tron void *v;
992 1.28 tron register_t *retval;
993 1.28 tron {
994 1.28 tron struct linux_sys_pread_args /* {
995 1.28 tron syscallarg(int) fd;
996 1.28 tron syscallarg(void *) buf;
997 1.28 tron syscallarg(size_t) nbyte;
998 1.28 tron syscallarg(linux_off_t) offset;
999 1.28 tron } */ *uap = v;
1000 1.28 tron struct sys_pread_args pra;
1001 1.28 tron
1002 1.28 tron SCARG(&pra, fd) = SCARG(uap, fd);
1003 1.28 tron SCARG(&pra, buf) = SCARG(uap, buf);
1004 1.28 tron SCARG(&pra, nbyte) = SCARG(uap, nbyte);
1005 1.28 tron SCARG(&pra, offset) = SCARG(uap, offset);
1006 1.28 tron
1007 1.37.2.1 nathanw return sys_read(l, &pra, retval);
1008 1.28 tron }
1009 1.28 tron
1010 1.28 tron /*
1011 1.28 tron * pwrite(2).
1012 1.28 tron */
1013 1.28 tron int
1014 1.37.2.1 nathanw linux_sys_pwrite(l, v, retval)
1015 1.37.2.1 nathanw struct lwp *l;
1016 1.28 tron void *v;
1017 1.28 tron register_t *retval;
1018 1.28 tron {
1019 1.28 tron struct linux_sys_pwrite_args /* {
1020 1.28 tron syscallarg(int) fd;
1021 1.28 tron syscallarg(void *) buf;
1022 1.28 tron syscallarg(size_t) nbyte;
1023 1.28 tron syscallarg(linux_off_t) offset;
1024 1.28 tron } */ *uap = v;
1025 1.28 tron struct sys_pwrite_args pra;
1026 1.28 tron
1027 1.28 tron SCARG(&pra, fd) = SCARG(uap, fd);
1028 1.28 tron SCARG(&pra, buf) = SCARG(uap, buf);
1029 1.28 tron SCARG(&pra, nbyte) = SCARG(uap, nbyte);
1030 1.28 tron SCARG(&pra, offset) = SCARG(uap, offset);
1031 1.28 tron
1032 1.37.2.1 nathanw return sys_write(l, &pra, retval);
1033 1.1 fvdl }
1034