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