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