2 * Copyright (c) 1994-1995 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/compat/linux/linux_file.c,v 1.41.2.6 2003/01/06 09:19:43 fjoe Exp $
29 * $DragonFly: src/sys/emulation/linux/linux_file.c,v 1.8 2003/08/07 21:17:18 dillon Exp $
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/dirent.h>
38 #include <sys/fcntl.h>
40 #include <sys/filedesc.h>
42 #include <sys/malloc.h>
43 #include <sys/mount.h>
45 #include <sys/sysproto.h>
47 #include <sys/vnode.h>
49 #include <vfs/ufs/quota.h>
50 #include <vfs/ufs/ufsmount.h>
52 #include <sys/file2.h>
54 #include <emulation/linux/machine/linux.h>
55 #include <emulation/linux/machine/linux_proto.h>
56 #include "linux_util.h"
60 linux_creat(struct linux_creat_args *args)
62 struct open_args bsd_open_args;
67 CHECKALTCREAT(&sg, args->path);
71 printf(ARGS(creat, "%s, %d"), args->path, args->mode);
73 bsd_open_args.sysmsg_result = 0;
74 bsd_open_args.path = args->path;
75 bsd_open_args.mode = args->mode;
76 bsd_open_args.flags = O_WRONLY | O_CREAT | O_TRUNC;
77 error = open(&bsd_open_args);
78 args->sysmsg_result = bsd_open_args.sysmsg_result;
84 linux_open(struct linux_open_args *args)
86 struct open_args bsd_open_args;
89 struct thread *td = curthread;
90 struct proc *p = td->td_proc;
96 if (args->flags & LINUX_O_CREAT)
97 CHECKALTCREAT(&sg, args->path);
99 CHECKALTEXIST(&sg, args->path);
103 printf(ARGS(open, "%s, 0x%x, 0x%x"),
104 args->path, args->flags, args->mode);
106 bsd_open_args.flags = 0;
107 if (args->flags & LINUX_O_RDONLY)
108 bsd_open_args.flags |= O_RDONLY;
109 if (args->flags & LINUX_O_WRONLY)
110 bsd_open_args.flags |= O_WRONLY;
111 if (args->flags & LINUX_O_RDWR)
112 bsd_open_args.flags |= O_RDWR;
113 if (args->flags & LINUX_O_NDELAY)
114 bsd_open_args.flags |= O_NONBLOCK;
115 if (args->flags & LINUX_O_APPEND)
116 bsd_open_args.flags |= O_APPEND;
117 if (args->flags & LINUX_O_SYNC)
118 bsd_open_args.flags |= O_FSYNC;
119 if (args->flags & LINUX_O_NONBLOCK)
120 bsd_open_args.flags |= O_NONBLOCK;
121 if (args->flags & LINUX_FASYNC)
122 bsd_open_args.flags |= O_ASYNC;
123 if (args->flags & LINUX_O_CREAT)
124 bsd_open_args.flags |= O_CREAT;
125 if (args->flags & LINUX_O_TRUNC)
126 bsd_open_args.flags |= O_TRUNC;
127 if (args->flags & LINUX_O_EXCL)
128 bsd_open_args.flags |= O_EXCL;
129 if (args->flags & LINUX_O_NOCTTY)
130 bsd_open_args.flags |= O_NOCTTY;
131 bsd_open_args.path = args->path;
132 bsd_open_args.mode = args->mode;
133 bsd_open_args.sysmsg_result = 0;
134 error = open(&bsd_open_args);
135 args->sysmsg_result = bsd_open_args.sysmsg_result;
137 if (!error && !(bsd_open_args.flags & O_NOCTTY) &&
138 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
139 struct filedesc *fdp = p->p_fd;
140 struct file *fp = fdp->fd_ofiles[bsd_open_args.sysmsg_result];
142 if (fp->f_type == DTYPE_VNODE)
143 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td);
147 printf(LMSG("open returns error %d"), error);
153 linux_lseek(struct linux_lseek_args *args)
155 struct lseek_args tmp_args;
160 printf(ARGS(lseek, "%d, %ld, %d"),
161 args->fdes, (long)args->off, args->whence);
163 tmp_args.fd = args->fdes;
164 tmp_args.offset = (off_t)args->off;
165 tmp_args.whence = args->whence;
166 tmp_args.sysmsg_result = 0;
167 error = lseek(&tmp_args);
168 args->sysmsg_result = tmp_args.sysmsg_result;
174 linux_llseek(struct linux_llseek_args *args)
176 struct lseek_args bsd_args;
182 printf(ARGS(llseek, "%d, %d:%d, %d"),
183 args->fd, args->ohigh, args->olow, args->whence);
185 off = (args->olow) | (((off_t) args->ohigh) << 32);
187 bsd_args.fd = args->fd;
188 bsd_args.offset = off;
189 bsd_args.whence = args->whence;
190 bsd_args.sysmsg_result = 0;
192 if ((error = lseek(&bsd_args)))
195 if ((error = copyout(&bsd_args.sysmsg_offset, (caddr_t)args->res, sizeof (off_t)))) {
198 args->sysmsg_result = 0;
201 #endif /*!__alpha__*/
205 linux_readdir(struct linux_readdir_args *args)
207 struct linux_getdents_args lda;
211 lda.dent = args->dent;
213 lda.sysmsg_result = 0;
214 error = linux_getdents(&lda);
215 args->sysmsg_result = lda.sysmsg_result;
218 #endif /*!__alpha__*/
221 * Note that linux_getdents(2) and linux_getdents64(2) have the same
222 * arguments. They only differ in the definition of struct dirent they
223 * operate on. We use this to common the code, with the exception of
224 * accessing struct dirent. Note that linux_readdir(2) is implemented
225 * by means of linux_getdents(2). In this case we never operate on
226 * struct dirent64 and thus don't need to handle it...
233 char d_name[LINUX_NAME_MAX + 1];
241 char d_name[LINUX_NAME_MAX + 1];
244 #define LINUX_RECLEN(de,namlen) \
245 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
247 #define LINUX_DIRBLKSIZ 512
250 getdents_common(struct linux_getdents64_args *args, int is64bit)
252 struct thread *td = curthread;
253 struct proc *p = td->td_proc;
256 caddr_t inp, buf; /* BSD-format */
257 int len, reclen; /* BSD-format */
258 caddr_t outp; /* Linux-format */
259 int resid, linuxreclen=0; /* Linux-format */
265 struct l_dirent linux_dirent;
266 struct l_dirent64 linux_dirent64;
267 int buflen, error, eofflag, nbytes, justone;
268 u_long *cookies = NULL, *cookiep;
273 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0)
276 if ((fp->f_flag & FREAD) == 0)
279 vp = (struct vnode *) fp->f_data;
280 if (vp->v_type != VDIR)
283 if ((error = VOP_GETATTR(vp, &va, td)))
286 nbytes = args->count;
288 /* readdir(2) case. Always struct dirent. */
291 nbytes = sizeof(linux_dirent);
298 buflen = max(LINUX_DIRBLKSIZ, nbytes);
299 buflen = min(buflen, MAXBSIZE);
300 buf = malloc(buflen, M_TEMP, M_WAITOK);
301 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
305 aiov.iov_len = buflen;
306 auio.uio_iov = &aiov;
308 auio.uio_rw = UIO_READ;
309 auio.uio_segflg = UIO_SYSSPACE;
311 auio.uio_resid = buflen;
312 auio.uio_offset = off;
315 free(cookies, M_TEMP);
319 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
324 outp = (caddr_t)args->dirent;
326 if ((len = buflen - auio.uio_resid) <= 0)
333 * When using cookies, the vfs has the option of reading from
334 * a different offset than that supplied (UFS truncates the
335 * offset to a block boundary to make sure that it never reads
336 * partway through a directory entry, even if the directory
337 * has been compacted).
339 while (len > 0 && ncookies > 0 && *cookiep <= off) {
340 bdp = (struct dirent *) inp;
341 len -= bdp->d_reclen;
342 inp += bdp->d_reclen;
349 if (cookiep && ncookies == 0)
351 bdp = (struct dirent *) inp;
352 reclen = bdp->d_reclen;
358 if (bdp->d_fileno == 0) {
370 linuxreclen = (is64bit)
371 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
372 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
374 if (reclen > len || resid < linuxreclen) {
380 /* readdir(2) case. */
381 linux_dirent.d_ino = (l_long)bdp->d_fileno;
382 linux_dirent.d_off = (l_off_t)linuxreclen;
383 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
384 strcpy(linux_dirent.d_name, bdp->d_name);
385 error = copyout(&linux_dirent, outp, linuxreclen);
388 linux_dirent64.d_ino = bdp->d_fileno;
389 linux_dirent64.d_off = (cookiep)
391 : (l_off_t)(off + reclen);
392 linux_dirent64.d_reclen =
393 (l_ushort)linuxreclen;
394 linux_dirent64.d_type = bdp->d_type;
395 strcpy(linux_dirent64.d_name, bdp->d_name);
396 error = copyout(&linux_dirent64, outp,
399 linux_dirent.d_ino = bdp->d_fileno;
400 linux_dirent.d_off = (cookiep)
402 : (l_off_t)(off + reclen);
403 linux_dirent.d_reclen = (l_ushort)linuxreclen;
404 strcpy(linux_dirent.d_name, bdp->d_name);
405 error = copyout(&linux_dirent, outp,
420 resid -= linuxreclen;
426 if (outp == (caddr_t)args->dirent)
431 nbytes = resid + linuxreclen;
434 args->sysmsg_result = nbytes - resid;
438 free(cookies, M_TEMP);
440 VOP_UNLOCK(vp, 0, td);
446 linux_getdents(struct linux_getdents_args *args)
449 if (ldebug(getdents))
450 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
452 return (getdents_common((struct linux_getdents64_args*)args, 0));
456 linux_getdents64(struct linux_getdents64_args *args)
459 if (ldebug(getdents64))
460 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
462 return (getdents_common(args, 1));
466 * These exist mainly for hooks for doing /compat/linux translation.
470 linux_access(struct linux_access_args *args)
472 struct access_args bsd;
476 sg = stackgap_init();
477 CHECKALTEXIST(&sg, args->path);
481 printf(ARGS(access, "%s, %d"), args->path, args->flags);
483 bsd.path = args->path;
484 bsd.flags = args->flags;
485 bsd.sysmsg_result = 0;
487 error = access(&bsd);
488 args->sysmsg_result = bsd.sysmsg_result;
493 linux_unlink(struct linux_unlink_args *args)
495 struct unlink_args bsd;
499 sg = stackgap_init();
500 CHECKALTEXIST(&sg, args->path);
504 printf(ARGS(unlink, "%s"), args->path);
506 bsd.path = args->path;
507 bsd.sysmsg_result = 0;
509 error = unlink(&bsd);
510 args->sysmsg_result = bsd.sysmsg_result;
515 linux_chdir(struct linux_chdir_args *args)
517 struct chdir_args bsd;
521 sg = stackgap_init();
522 CHECKALTEXIST(&sg, args->path);
526 printf(ARGS(chdir, "%s"), args->path);
528 bsd.path = args->path;
529 bsd.sysmsg_result = 0;
532 args->sysmsg_result = bsd.sysmsg_result;
537 linux_chmod(struct linux_chmod_args *args)
539 struct chmod_args bsd;
543 sg = stackgap_init();
544 CHECKALTEXIST(&sg, args->path);
548 printf(ARGS(chmod, "%s, %d"), args->path, args->mode);
550 bsd.path = args->path;
551 bsd.mode = args->mode;
552 bsd.sysmsg_result = 0;
555 args->sysmsg_result = bsd.sysmsg_result;
560 linux_mkdir(struct linux_mkdir_args *args)
562 struct mkdir_args bsd;
566 sg = stackgap_init();
567 CHECKALTCREAT(&sg, args->path);
571 printf(ARGS(mkdir, "%s, %d"), args->path, args->mode);
573 bsd.path = args->path;
574 bsd.mode = args->mode;
575 bsd.sysmsg_result = 0;
578 args->sysmsg_result = bsd.sysmsg_result;
583 linux_rmdir(struct linux_rmdir_args *args)
585 struct rmdir_args bsd;
589 sg = stackgap_init();
590 CHECKALTEXIST(&sg, args->path);
594 printf(ARGS(rmdir, "%s"), args->path);
596 bsd.path = args->path;
597 bsd.sysmsg_result = 0;
600 args->sysmsg_result = bsd.sysmsg_result;
605 linux_rename(struct linux_rename_args *args)
607 struct rename_args bsd;
611 sg = stackgap_init();
612 CHECKALTEXIST(&sg, args->from);
613 CHECKALTCREAT(&sg, args->to);
617 printf(ARGS(rename, "%s, %s"), args->from, args->to);
619 bsd.from = args->from;
621 bsd.sysmsg_result = 0;
623 error = rename(&bsd);
624 args->sysmsg_result = bsd.sysmsg_result;
629 linux_symlink(struct linux_symlink_args *args)
631 struct symlink_args bsd;
635 sg = stackgap_init();
636 CHECKALTEXIST(&sg, args->path);
637 CHECKALTCREAT(&sg, args->to);
641 printf(ARGS(symlink, "%s, %s"), args->path, args->to);
643 bsd.path = args->path;
645 bsd.sysmsg_result = 0;
647 error = symlink(&bsd);
648 args->sysmsg_result = bsd.sysmsg_result;
653 linux_readlink(struct linux_readlink_args *args)
655 struct readlink_args bsd;
659 sg = stackgap_init();
660 CHECKALTEXIST(&sg, args->name);
663 if (ldebug(readlink))
664 printf(ARGS(readlink, "%s, %p, %d"),
665 args->name, (void *)args->buf, args->count);
667 bsd.path = args->name;
669 bsd.count = args->count;
670 bsd.sysmsg_result = 0;
672 error = readlink(&bsd);
673 args->sysmsg_result = bsd.sysmsg_result;
678 linux_truncate(struct linux_truncate_args *args)
680 struct truncate_args bsd;
684 sg = stackgap_init();
685 CHECKALTEXIST(&sg, args->path);
688 if (ldebug(truncate))
689 printf(ARGS(truncate, "%s, %ld"), args->path,
692 bsd.path = args->path;
693 bsd.length = args->length;
694 bsd.sysmsg_result = 0;
696 error = truncate(&bsd);
697 args->sysmsg_result = bsd.sysmsg_result;
702 linux_link(struct linux_link_args *args)
704 struct link_args bsd;
708 sg = stackgap_init();
709 CHECKALTEXIST(&sg, args->path);
710 CHECKALTCREAT(&sg, args->to);
714 printf(ARGS(link, "%s, %s"), args->path, args->to);
717 bsd.path = args->path;
719 bsd.sysmsg_result = 0;
722 args->sysmsg_result = bsd.sysmsg_result;
728 linux_fdatasync(struct linux_fdatasync_args *uap)
730 struct fsync_args bsd;
734 bsd.sysmsg_result = 0;
737 uap->sysmsg_result = bsd.sysmsg_result;
740 #endif /*!__alpha__*/
743 linux_pread(struct linux_pread_args *uap)
745 struct pread_args bsd;
750 bsd.nbyte = uap->nbyte;
751 bsd.offset = uap->offset;
752 bsd.sysmsg_result = 0;
755 uap->sysmsg_result = bsd.sysmsg_result;
760 linux_pwrite(struct linux_pwrite_args *uap)
762 struct pwrite_args bsd;
767 bsd.nbyte = uap->nbyte;
768 bsd.offset = uap->offset;
769 bsd.sysmsg_result = 0;
771 error = pwrite(&bsd);
772 uap->sysmsg_result = bsd.sysmsg_result;
777 linux_oldumount(struct linux_oldumount_args *args)
779 struct linux_umount_args args2;
782 args2.path = args->path;
784 args2.sysmsg_result = 0;
785 error = linux_umount(&args2);
786 args->sysmsg_result = args2.sysmsg_result;
791 linux_umount(struct linux_umount_args *args)
793 struct unmount_args bsd;
796 bsd.path = args->path;
797 bsd.flags = args->flags; /* XXX correct? */
798 bsd.sysmsg_result = 0;
800 error = unmount(&bsd);
801 args->sysmsg_result = bsd.sysmsg_result;
806 * fcntl family of syscalls
818 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
820 switch (linux_flock->l_type) {
822 bsd_flock->l_type = F_RDLCK;
825 bsd_flock->l_type = F_WRLCK;
828 bsd_flock->l_type = F_UNLCK;
831 bsd_flock->l_type = -1;
834 bsd_flock->l_whence = linux_flock->l_whence;
835 bsd_flock->l_start = (off_t)linux_flock->l_start;
836 bsd_flock->l_len = (off_t)linux_flock->l_len;
837 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
841 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
843 switch (bsd_flock->l_type) {
845 linux_flock->l_type = LINUX_F_RDLCK;
848 linux_flock->l_type = LINUX_F_WRLCK;
851 linux_flock->l_type = LINUX_F_UNLCK;
854 linux_flock->l_whence = bsd_flock->l_whence;
855 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
856 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
857 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
860 #if defined(__i386__)
870 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
872 switch (linux_flock->l_type) {
874 bsd_flock->l_type = F_RDLCK;
877 bsd_flock->l_type = F_WRLCK;
880 bsd_flock->l_type = F_UNLCK;
883 bsd_flock->l_type = -1;
886 bsd_flock->l_whence = linux_flock->l_whence;
887 bsd_flock->l_start = (off_t)linux_flock->l_start;
888 bsd_flock->l_len = (off_t)linux_flock->l_len;
889 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
893 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
895 switch (bsd_flock->l_type) {
897 linux_flock->l_type = LINUX_F_RDLCK;
900 linux_flock->l_type = LINUX_F_WRLCK;
903 linux_flock->l_type = LINUX_F_UNLCK;
906 linux_flock->l_whence = bsd_flock->l_whence;
907 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
908 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
909 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
911 #endif /* __i386__ */
913 #if defined(__alpha__)
914 #define linux_fcntl64_args linux_fcntl_args
918 fcntl_common(struct linux_fcntl64_args *args)
920 struct proc *p = curproc;
921 struct l_flock linux_flock;
922 struct flock *bsd_flock;
923 struct fcntl_args fcntl_args;
924 struct filedesc *fdp;
929 sg = stackgap_init();
930 bsd_flock = (struct flock *)stackgap_alloc(&sg, sizeof(bsd_flock));
932 fcntl_args.fd = args->fd;
933 fcntl_args.sysmsg_result = 0;
937 fcntl_args.cmd = F_DUPFD;
938 fcntl_args.arg = args->arg;
941 fcntl_args.cmd = F_GETFD;
944 fcntl_args.cmd = F_SETFD;
945 fcntl_args.arg = args->arg;
948 fcntl_args.cmd = F_GETFL;
949 error = fcntl(&fcntl_args);
950 result = fcntl_args.sysmsg_result;
951 args->sysmsg_result = 0;
952 if (result & O_RDONLY)
953 args->sysmsg_result |= LINUX_O_RDONLY;
954 if (result & O_WRONLY)
955 args->sysmsg_result |= LINUX_O_WRONLY;
957 args->sysmsg_result |= LINUX_O_RDWR;
958 if (result & O_NDELAY)
959 args->sysmsg_result |= LINUX_O_NONBLOCK;
960 if (result & O_APPEND)
961 args->sysmsg_result |= LINUX_O_APPEND;
962 if (result & O_FSYNC)
963 args->sysmsg_result |= LINUX_O_SYNC;
964 if (result & O_ASYNC)
965 args->sysmsg_result |= LINUX_FASYNC;
970 if (args->arg & LINUX_O_NDELAY)
971 fcntl_args.arg |= O_NONBLOCK;
972 if (args->arg & LINUX_O_APPEND)
973 fcntl_args.arg |= O_APPEND;
974 if (args->arg & LINUX_O_SYNC)
975 fcntl_args.arg |= O_FSYNC;
976 if (args->arg & LINUX_FASYNC)
977 fcntl_args.arg |= O_ASYNC;
978 fcntl_args.cmd = F_SETFL;
982 error = copyin((caddr_t)args->arg, &linux_flock,
983 sizeof(linux_flock));
986 linux_to_bsd_flock(&linux_flock, bsd_flock);
987 fcntl_args.fd = args->fd;
988 fcntl_args.cmd = F_GETLK;
989 fcntl_args.arg = (long)bsd_flock;
990 error = fcntl(&fcntl_args);
991 args->sysmsg_result = fcntl_args.sysmsg_result;
994 bsd_to_linux_flock(bsd_flock, &linux_flock);
995 return (copyout(&linux_flock, (caddr_t)args->arg,
996 sizeof(linux_flock)));
999 error = copyin((caddr_t)args->arg, &linux_flock,
1000 sizeof(linux_flock));
1003 linux_to_bsd_flock(&linux_flock, bsd_flock);
1004 fcntl_args.fd = args->fd;
1005 fcntl_args.cmd = F_SETLK;
1006 fcntl_args.arg = (long)bsd_flock;
1008 case LINUX_F_SETLKW:
1009 error = copyin((caddr_t)args->arg, &linux_flock,
1010 sizeof(linux_flock));
1013 linux_to_bsd_flock(&linux_flock, bsd_flock);
1014 fcntl_args.fd = args->fd;
1015 fcntl_args.cmd = F_SETLKW;
1016 fcntl_args.arg = (long)bsd_flock;
1018 case LINUX_F_GETOWN:
1019 fcntl_args.cmd = F_GETOWN;
1021 case LINUX_F_SETOWN:
1023 * XXX some Linux applications depend on F_SETOWN having no
1024 * significant effect for pipes (SIGIO is not delivered for
1025 * pipes under Linux-2.2.35 at least).
1028 if ((u_int)args->fd >= fdp->fd_nfiles ||
1029 (fp = fdp->fd_ofiles[args->fd]) == NULL)
1031 if (fp->f_type == DTYPE_PIPE)
1033 fcntl_args.cmd = F_SETOWN;
1034 fcntl_args.arg = args->arg;
1039 error = fcntl(&fcntl_args);
1040 args->sysmsg_result = fcntl_args.sysmsg_result;
1045 linux_fcntl(struct linux_fcntl_args *args)
1047 struct linux_fcntl64_args args64;
1052 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1055 args64.fd = args->fd;
1056 args64.cmd = args->cmd;
1057 args64.arg = args->arg;
1058 args64.sysmsg_result = 0;
1059 error = fcntl_common(&args64);
1060 args->sysmsg_result = args64.sysmsg_result;
1064 #if defined(__i386__)
1066 linux_fcntl64(struct linux_fcntl64_args *args)
1068 struct fcntl_args fcntl_args;
1069 struct l_flock64 linux_flock;
1070 struct flock *bsd_flock;
1074 sg = stackgap_init();
1075 bsd_flock = (struct flock *)stackgap_alloc(&sg, sizeof(bsd_flock));
1078 if (ldebug(fcntl64))
1079 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1081 fcntl_args.sysmsg_result = 0;
1083 switch (args->cmd) {
1084 case LINUX_F_GETLK64:
1085 error = copyin((caddr_t)args->arg, &linux_flock,
1086 sizeof(linux_flock));
1089 linux_to_bsd_flock64(&linux_flock, bsd_flock);
1090 fcntl_args.fd = args->fd;
1091 fcntl_args.cmd = F_GETLK;
1092 fcntl_args.arg = (long)bsd_flock;
1093 error = fcntl(&fcntl_args);
1094 args->sysmsg_result = fcntl_args.sysmsg_result;
1097 bsd_to_linux_flock64(bsd_flock, &linux_flock);
1098 return (copyout(&linux_flock, (caddr_t)args->arg,
1099 sizeof(linux_flock)));
1101 case LINUX_F_SETLK64:
1102 error = copyin((caddr_t)args->arg, &linux_flock,
1103 sizeof(linux_flock));
1106 linux_to_bsd_flock64(&linux_flock, bsd_flock);
1107 fcntl_args.fd = args->fd;
1108 fcntl_args.cmd = F_SETLK;
1109 fcntl_args.arg = (long)bsd_flock;
1110 error = fcntl(&fcntl_args);
1111 args->sysmsg_result = fcntl_args.sysmsg_result;
1114 case LINUX_F_SETLKW64:
1115 error = copyin((caddr_t)args->arg, &linux_flock,
1116 sizeof(linux_flock));
1119 linux_to_bsd_flock64(&linux_flock, bsd_flock);
1120 fcntl_args.fd = args->fd;
1121 fcntl_args.cmd = F_SETLKW;
1122 fcntl_args.arg = (long)bsd_flock;
1123 error = fcntl(&fcntl_args);
1124 args->sysmsg_result = fcntl_args.sysmsg_result;
1128 return (fcntl_common(args));
1130 #endif /* __i386__ */
1133 linux_chown(struct linux_chown_args *args)
1135 struct chown_args bsd;
1139 sg = stackgap_init();
1140 CHECKALTEXIST(&sg, args->path);
1144 printf(ARGS(chown, "%s, %d, %d"), args->path, args->uid,
1148 bsd.path = args->path;
1149 bsd.uid = args->uid;
1150 bsd.gid = args->gid;
1151 bsd.sysmsg_result = 0;
1152 error = chown(&bsd);
1153 args->sysmsg_result = bsd.sysmsg_result;
1158 linux_lchown(struct linux_lchown_args *args)
1160 struct lchown_args bsd;
1164 sg = stackgap_init();
1165 CHECKALTEXIST(&sg, args->path);
1169 printf(ARGS(lchown, "%s, %d, %d"), args->path, args->uid,
1173 bsd.path = args->path;
1174 bsd.uid = args->uid;
1175 bsd.gid = args->gid;
1176 bsd.sysmsg_result = 0;
1178 error = lchown(&bsd);
1179 args->sysmsg_result = bsd.sysmsg_result;