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