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