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 without 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.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_compat.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/dirent.h>
39 #include <sys/fcntl.h>
41 #include <sys/filedesc.h>
44 #include <sys/malloc.h>
45 #include <sys/mount.h>
46 #include <sys/mutex.h>
49 #include <sys/syscallsubr.h>
50 #include <sys/sysproto.h>
51 #include <sys/unistd.h>
53 #include <sys/vnode.h>
55 #include <ufs/ufs/extattr.h>
56 #include <ufs/ufs/quota.h>
57 #include <ufs/ufs/ufsmount.h>
59 #include "opt_compat.h"
62 #include <machine/../linux32/linux.h>
63 #include <machine/../linux32/linux32_proto.h>
65 #include <machine/../linux/linux.h>
66 #include <machine/../linux/linux_proto.h>
68 #include <compat/linux/linux_util.h>
72 linux_creat(struct thread *td, struct linux_creat_args *args)
77 LCONVPATHEXIST(td, args->path, &path);
81 printf(ARGS(creat, "%s, %d"), path, args->mode);
83 error = kern_open(td, path, UIO_SYSSPACE, O_WRONLY | O_CREAT | O_TRUNC,
91 linux_open(struct thread *td, struct linux_open_args *args)
93 struct proc *p = td->td_proc;
97 if (args->flags & LINUX_O_CREAT)
98 LCONVPATHCREAT(td, args->path, &path);
100 LCONVPATHEXIST(td, args->path, &path);
104 printf(ARGS(open, "%s, 0x%x, 0x%x"),
105 path, args->flags, args->mode);
108 if (args->flags & LINUX_O_RDONLY)
109 bsd_flags |= O_RDONLY;
110 if (args->flags & LINUX_O_WRONLY)
111 bsd_flags |= O_WRONLY;
112 if (args->flags & LINUX_O_RDWR)
114 if (args->flags & LINUX_O_NDELAY)
115 bsd_flags |= O_NONBLOCK;
116 if (args->flags & LINUX_O_APPEND)
117 bsd_flags |= O_APPEND;
118 if (args->flags & LINUX_O_SYNC)
119 bsd_flags |= O_FSYNC;
120 if (args->flags & LINUX_O_NONBLOCK)
121 bsd_flags |= O_NONBLOCK;
122 if (args->flags & LINUX_FASYNC)
123 bsd_flags |= O_ASYNC;
124 if (args->flags & LINUX_O_CREAT)
125 bsd_flags |= O_CREAT;
126 if (args->flags & LINUX_O_TRUNC)
127 bsd_flags |= O_TRUNC;
128 if (args->flags & LINUX_O_EXCL)
130 if (args->flags & LINUX_O_NOCTTY)
131 bsd_flags |= O_NOCTTY;
133 error = kern_open(td, path, UIO_SYSSPACE, bsd_flags, args->mode);
135 if (!error && !(bsd_flags & O_NOCTTY) &&
136 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
140 error = fget(td, td->td_retval[0], &fp);
142 if (fp->f_type == DTYPE_VNODE)
143 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td->td_ucred,
151 printf(LMSG("open returns error %d"), error);
159 linux_lseek(struct thread *td, struct linux_lseek_args *args)
162 struct lseek_args /* {
172 printf(ARGS(lseek, "%d, %ld, %d"),
173 args->fdes, (long)args->off, args->whence);
175 tmp_args.fd = args->fdes;
176 tmp_args.offset = (off_t)args->off;
177 tmp_args.whence = args->whence;
178 error = lseek(td, &tmp_args);
184 linux_llseek(struct thread *td, struct linux_llseek_args *args)
186 struct lseek_args bsd_args;
192 printf(ARGS(llseek, "%d, %d:%d, %d"),
193 args->fd, args->ohigh, args->olow, args->whence);
195 off = (args->olow) | (((off_t) args->ohigh) << 32);
197 bsd_args.fd = args->fd;
198 bsd_args.offset = off;
199 bsd_args.whence = args->whence;
201 if ((error = lseek(td, &bsd_args)))
204 if ((error = copyout(td->td_retval, args->res, sizeof (off_t))))
207 td->td_retval[0] = 0;
210 #endif /*!__alpha__*/
214 linux_readdir(struct thread *td, struct linux_readdir_args *args)
216 struct linux_getdents_args lda;
219 lda.dent = args->dent;
221 return linux_getdents(td, &lda);
223 #endif /*!__alpha__*/
226 * Note that linux_getdents(2) and linux_getdents64(2) have the same
227 * arguments. They only differ in the definition of struct dirent they
228 * operate on. We use this to common the code, with the exception of
229 * accessing struct dirent. Note that linux_readdir(2) is implemented
230 * by means of linux_getdents(2). In this case we never operate on
231 * struct dirent64 and thus don't need to handle it...
238 char d_name[LINUX_NAME_MAX + 1];
246 char d_name[LINUX_NAME_MAX + 1];
249 #define LINUX_RECLEN(de,namlen) \
250 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
252 #define LINUX_DIRBLKSIZ 512
255 getdents_common(struct thread *td, struct linux_getdents64_args *args,
260 caddr_t inp, buf; /* BSD-format */
261 int len, reclen; /* BSD-format */
262 caddr_t outp; /* Linux-format */
263 int resid, linuxreclen=0; /* Linux-format */
268 struct l_dirent linux_dirent;
269 struct l_dirent64 linux_dirent64;
270 int buflen, error, eofflag, nbytes, justone;
271 u_long *cookies = NULL, *cookiep;
272 int ncookies, vfslocked;
274 nbytes = args->count;
276 /* readdir(2) case. Always struct dirent. */
279 nbytes = sizeof(linux_dirent);
284 if ((error = getvnode(td->td_proc->p_fd, args->fd, &fp)) != 0)
287 if ((fp->f_flag & FREAD) == 0) {
293 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
294 if (vp->v_type != VDIR) {
295 VFS_UNLOCK_GIANT(vfslocked);
302 buflen = max(LINUX_DIRBLKSIZ, nbytes);
303 buflen = min(buflen, MAXBSIZE);
304 buf = malloc(buflen, M_TEMP, M_WAITOK);
305 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
309 aiov.iov_len = buflen;
310 auio.uio_iov = &aiov;
312 auio.uio_rw = UIO_READ;
313 auio.uio_segflg = UIO_SYSSPACE;
315 auio.uio_resid = buflen;
316 auio.uio_offset = off;
319 free(cookies, M_TEMP);
325 * Do directory search MAC check using non-cached credentials.
327 if ((error = mac_check_vnode_readdir(td->td_ucred, vp)))
330 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
335 outp = (caddr_t)args->dirent;
337 if ((len = buflen - auio.uio_resid) <= 0)
344 * When using cookies, the vfs has the option of reading from
345 * a different offset than that supplied (UFS truncates the
346 * offset to a block boundary to make sure that it never reads
347 * partway through a directory entry, even if the directory
348 * has been compacted).
350 while (len > 0 && ncookies > 0 && *cookiep <= off) {
351 bdp = (struct dirent *) inp;
352 len -= bdp->d_reclen;
353 inp += bdp->d_reclen;
360 if (cookiep && ncookies == 0)
362 bdp = (struct dirent *) inp;
363 reclen = bdp->d_reclen;
369 if (bdp->d_fileno == 0) {
381 linuxreclen = (is64bit)
382 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
383 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
385 if (reclen > len || resid < linuxreclen) {
391 /* readdir(2) case. */
392 linux_dirent.d_ino = (l_long)bdp->d_fileno;
393 linux_dirent.d_off = (l_off_t)linuxreclen;
394 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
395 strcpy(linux_dirent.d_name, bdp->d_name);
396 error = copyout(&linux_dirent, outp, linuxreclen);
399 linux_dirent64.d_ino = bdp->d_fileno;
400 linux_dirent64.d_off = (cookiep)
402 : (l_off_t)(off + reclen);
403 linux_dirent64.d_reclen =
404 (l_ushort)linuxreclen;
405 linux_dirent64.d_type = bdp->d_type;
406 strcpy(linux_dirent64.d_name, bdp->d_name);
407 error = copyout(&linux_dirent64, outp,
410 linux_dirent.d_ino = bdp->d_fileno;
411 linux_dirent.d_off = (cookiep)
413 : (l_off_t)(off + reclen);
414 linux_dirent.d_reclen = (l_ushort)linuxreclen;
415 strcpy(linux_dirent.d_name, bdp->d_name);
416 error = copyout(&linux_dirent, outp,
431 resid -= linuxreclen;
437 if (outp == (caddr_t)args->dirent)
442 nbytes = resid + linuxreclen;
445 td->td_retval[0] = nbytes - resid;
449 free(cookies, M_TEMP);
451 VOP_UNLOCK(vp, 0, td);
452 VFS_UNLOCK_GIANT(vfslocked);
459 linux_getdents(struct thread *td, struct linux_getdents_args *args)
463 if (ldebug(getdents))
464 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
467 return (getdents_common(td, (struct linux_getdents64_args*)args, 0));
471 linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
475 if (ldebug(getdents64))
476 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
479 return (getdents_common(td, args, 1));
483 * These exist mainly for hooks for doing /compat/linux translation.
487 linux_access(struct thread *td, struct linux_access_args *args)
492 /* linux convention */
493 if (args->flags & ~(F_OK | X_OK | W_OK | R_OK))
496 LCONVPATHEXIST(td, args->path, &path);
500 printf(ARGS(access, "%s, %d"), path, args->flags);
502 error = kern_access(td, path, UIO_SYSSPACE, args->flags);
509 linux_unlink(struct thread *td, struct linux_unlink_args *args)
515 LCONVPATHEXIST(td, args->path, &path);
519 printf(ARGS(unlink, "%s"), path);
522 error = kern_unlink(td, path, UIO_SYSSPACE);
524 /* Introduce POSIX noncompliant behaviour of Linux */
525 if (kern_stat(td, path, UIO_SYSSPACE, &st) == 0)
526 if (S_ISDIR(st.st_mode))
533 linux_chdir(struct thread *td, struct linux_chdir_args *args)
538 LCONVPATHEXIST(td, args->path, &path);
542 printf(ARGS(chdir, "%s"), path);
544 error = kern_chdir(td, path, UIO_SYSSPACE);
550 linux_chmod(struct thread *td, struct linux_chmod_args *args)
555 LCONVPATHEXIST(td, args->path, &path);
559 printf(ARGS(chmod, "%s, %d"), path, args->mode);
561 error = kern_chmod(td, path, UIO_SYSSPACE, args->mode);
567 linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
572 LCONVPATHCREAT(td, args->path, &path);
576 printf(ARGS(mkdir, "%s, %d"), path, args->mode);
578 error = kern_mkdir(td, path, UIO_SYSSPACE, args->mode);
584 linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
589 LCONVPATHEXIST(td, args->path, &path);
593 printf(ARGS(rmdir, "%s"), path);
595 error = kern_rmdir(td, path, UIO_SYSSPACE);
601 linux_rename(struct thread *td, struct linux_rename_args *args)
606 LCONVPATHEXIST(td, args->from, &from);
607 /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
608 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
616 printf(ARGS(rename, "%s, %s"), from, to);
618 error = kern_rename(td, from, to, UIO_SYSSPACE);
625 linux_symlink(struct thread *td, struct linux_symlink_args *args)
630 LCONVPATHEXIST(td, args->path, &path);
631 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
632 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
640 printf(ARGS(symlink, "%s, %s"), path, to);
642 error = kern_symlink(td, path, to, UIO_SYSSPACE);
649 linux_readlink(struct thread *td, struct linux_readlink_args *args)
654 LCONVPATHEXIST(td, args->name, &name);
657 if (ldebug(readlink))
658 printf(ARGS(readlink, "%s, %p, %d"), name, (void *)args->buf,
661 error = kern_readlink(td, name, UIO_SYSSPACE, args->buf, UIO_USERSPACE,
668 linux_truncate(struct thread *td, struct linux_truncate_args *args)
673 LCONVPATHEXIST(td, args->path, &path);
676 if (ldebug(truncate))
677 printf(ARGS(truncate, "%s, %ld"), path, (long)args->length);
680 error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
686 linux_ftruncate(struct thread *td, struct linux_ftruncate_args *args)
688 struct ftruncate_args /* {
696 nuap.length = args->length;
697 return (ftruncate(td, &nuap));
701 linux_link(struct thread *td, struct linux_link_args *args)
706 LCONVPATHEXIST(td, args->path, &path);
707 /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
708 error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1);
716 printf(ARGS(link, "%s, %s"), path, to);
718 error = kern_link(td, path, to, UIO_SYSSPACE);
726 linux_fdatasync(td, uap)
728 struct linux_fdatasync_args *uap;
730 struct fsync_args bsd;
733 return fsync(td, &bsd);
735 #endif /*!__alpha__*/
740 struct linux_pread_args *uap;
742 struct pread_args bsd;
748 bsd.nbyte = uap->nbyte;
749 bsd.offset = uap->offset;
751 error = pread(td, &bsd);
754 /* This seems to violate POSIX but linux does it */
755 if ((error = fgetvp(td, uap->fd, &vp)) != 0)
757 if (vp->v_type == VDIR) {
768 linux_pwrite(td, uap)
770 struct linux_pwrite_args *uap;
772 struct pwrite_args bsd;
776 bsd.nbyte = uap->nbyte;
777 bsd.offset = uap->offset;
778 return pwrite(td, &bsd);
782 linux_mount(struct thread *td, struct linux_mount_args *args)
785 char fstypename[MFSNAMELEN];
786 char mntonname[MNAMELEN], mntfromname[MNAMELEN];
791 error = copyinstr(args->filesystemtype, fstypename, MFSNAMELEN - 1,
795 error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL);
798 error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL);
804 printf(ARGS(mount, "%s, %s, %s"),
805 fstypename, mntfromname, mntonname);
808 if (strcmp(fstypename, "ext2") == 0) {
809 strcpy(fstypename, "ext2fs");
811 ufs.fspec = mntfromname;
812 #define DEFAULT_ROOTID -2
813 ufs.export.ex_root = DEFAULT_ROOTID;
814 ufs.export.ex_flags =
815 args->rwflag & LINUX_MS_RDONLY ? MNT_EXRDONLY : 0;
816 } else if (strcmp(fstypename, "proc") == 0) {
817 strcpy(fstypename, "linprocfs");
825 if ((args->rwflag & 0xffff0000) == 0xc0ed0000) {
827 * Linux SYNC flag is not included; the closest equivalent
828 * FreeBSD has is !ASYNC, which is our default.
830 if (args->rwflag & LINUX_MS_RDONLY)
831 fsflags |= MNT_RDONLY;
832 if (args->rwflag & LINUX_MS_NOSUID)
833 fsflags |= MNT_NOSUID;
834 if (args->rwflag & LINUX_MS_NOEXEC)
835 fsflags |= MNT_NOEXEC;
836 if (args->rwflag & LINUX_MS_REMOUNT)
837 fsflags |= MNT_UPDATE;
840 if (strcmp(fstypename, "linprocfs") == 0) {
841 error = kernel_vmount(fsflags,
842 "fstype", fstypename,
851 linux_oldumount(struct thread *td, struct linux_oldumount_args *args)
853 struct linux_umount_args args2;
855 args2.path = args->path;
857 return (linux_umount(td, &args2));
861 linux_umount(struct thread *td, struct linux_umount_args *args)
863 struct unmount_args bsd;
865 bsd.path = args->path;
866 bsd.flags = args->flags; /* XXX correct? */
867 return (unmount(td, &bsd));
871 * fcntl family of syscalls
881 #if defined(__amd64__) && defined(COMPAT_LINUX32)
887 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
889 switch (linux_flock->l_type) {
891 bsd_flock->l_type = F_RDLCK;
894 bsd_flock->l_type = F_WRLCK;
897 bsd_flock->l_type = F_UNLCK;
900 bsd_flock->l_type = -1;
903 bsd_flock->l_whence = linux_flock->l_whence;
904 bsd_flock->l_start = (off_t)linux_flock->l_start;
905 bsd_flock->l_len = (off_t)linux_flock->l_len;
906 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
910 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
912 switch (bsd_flock->l_type) {
914 linux_flock->l_type = LINUX_F_RDLCK;
917 linux_flock->l_type = LINUX_F_WRLCK;
920 linux_flock->l_type = LINUX_F_UNLCK;
923 linux_flock->l_whence = bsd_flock->l_whence;
924 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
925 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
926 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
929 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
937 #if defined(__amd64__) && defined(COMPAT_LINUX32)
943 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
945 switch (linux_flock->l_type) {
947 bsd_flock->l_type = F_RDLCK;
950 bsd_flock->l_type = F_WRLCK;
953 bsd_flock->l_type = F_UNLCK;
956 bsd_flock->l_type = -1;
959 bsd_flock->l_whence = linux_flock->l_whence;
960 bsd_flock->l_start = (off_t)linux_flock->l_start;
961 bsd_flock->l_len = (off_t)linux_flock->l_len;
962 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
963 bsd_flock->l_sysid = 0;
967 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
969 switch (bsd_flock->l_type) {
971 linux_flock->l_type = LINUX_F_RDLCK;
974 linux_flock->l_type = LINUX_F_WRLCK;
977 linux_flock->l_type = LINUX_F_UNLCK;
980 linux_flock->l_whence = bsd_flock->l_whence;
981 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
982 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
983 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
985 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
987 #if defined(__alpha__)
988 #define linux_fcntl64_args linux_fcntl_args
992 fcntl_common(struct thread *td, struct linux_fcntl64_args *args)
994 struct l_flock linux_flock;
995 struct flock bsd_flock;
1000 switch (args->cmd) {
1002 return (kern_fcntl(td, args->fd, F_DUPFD, args->arg));
1005 return (kern_fcntl(td, args->fd, F_GETFD, 0));
1008 return (kern_fcntl(td, args->fd, F_SETFD, args->arg));
1011 error = kern_fcntl(td, args->fd, F_GETFL, 0);
1012 result = td->td_retval[0];
1013 td->td_retval[0] = 0;
1014 if (result & O_RDONLY)
1015 td->td_retval[0] |= LINUX_O_RDONLY;
1016 if (result & O_WRONLY)
1017 td->td_retval[0] |= LINUX_O_WRONLY;
1018 if (result & O_RDWR)
1019 td->td_retval[0] |= LINUX_O_RDWR;
1020 if (result & O_NDELAY)
1021 td->td_retval[0] |= LINUX_O_NONBLOCK;
1022 if (result & O_APPEND)
1023 td->td_retval[0] |= LINUX_O_APPEND;
1024 if (result & O_FSYNC)
1025 td->td_retval[0] |= LINUX_O_SYNC;
1026 if (result & O_ASYNC)
1027 td->td_retval[0] |= LINUX_FASYNC;
1028 #ifdef LINUX_O_NOFOLLOW
1029 if (result & O_NOFOLLOW)
1030 td->td_retval[0] |= LINUX_O_NOFOLLOW;
1032 #ifdef LINUX_O_DIRECT
1033 if (result & O_DIRECT)
1034 td->td_retval[0] |= LINUX_O_DIRECT;
1040 if (args->arg & LINUX_O_NDELAY)
1042 if (args->arg & LINUX_O_APPEND)
1044 if (args->arg & LINUX_O_SYNC)
1046 if (args->arg & LINUX_FASYNC)
1048 #ifdef LINUX_O_NOFOLLOW
1049 if (args->arg & LINUX_O_NOFOLLOW)
1052 #ifdef LINUX_O_DIRECT
1053 if (args->arg & LINUX_O_DIRECT)
1056 return (kern_fcntl(td, args->fd, F_SETFL, arg));
1059 error = copyin((void *)args->arg, &linux_flock,
1060 sizeof(linux_flock));
1063 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1064 error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
1067 bsd_to_linux_flock(&bsd_flock, &linux_flock);
1068 return (copyout(&linux_flock, (void *)args->arg,
1069 sizeof(linux_flock)));
1072 error = copyin((void *)args->arg, &linux_flock,
1073 sizeof(linux_flock));
1076 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1077 return (kern_fcntl(td, args->fd, F_SETLK,
1078 (intptr_t)&bsd_flock));
1080 case LINUX_F_SETLKW:
1081 error = copyin((void *)args->arg, &linux_flock,
1082 sizeof(linux_flock));
1085 linux_to_bsd_flock(&linux_flock, &bsd_flock);
1086 return (kern_fcntl(td, args->fd, F_SETLKW,
1087 (intptr_t)&bsd_flock));
1089 case LINUX_F_GETOWN:
1090 return (kern_fcntl(td, args->fd, F_GETOWN, 0));
1092 case LINUX_F_SETOWN:
1094 * XXX some Linux applications depend on F_SETOWN having no
1095 * significant effect for pipes (SIGIO is not delivered for
1096 * pipes under Linux-2.2.35 at least).
1098 error = fget(td, args->fd, &fp);
1101 if (fp->f_type == DTYPE_PIPE) {
1107 return (kern_fcntl(td, args->fd, F_SETOWN, args->arg));
1114 linux_fcntl(struct thread *td, struct linux_fcntl_args *args)
1116 struct linux_fcntl64_args args64;
1120 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1123 args64.fd = args->fd;
1124 args64.cmd = args->cmd;
1125 args64.arg = args->arg;
1126 return (fcntl_common(td, &args64));
1129 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
1131 linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
1133 struct l_flock64 linux_flock;
1134 struct flock bsd_flock;
1138 if (ldebug(fcntl64))
1139 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1142 switch (args->cmd) {
1143 case LINUX_F_GETLK64:
1144 error = copyin((void *)args->arg, &linux_flock,
1145 sizeof(linux_flock));
1148 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1149 error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock);
1152 bsd_to_linux_flock64(&bsd_flock, &linux_flock);
1153 return (copyout(&linux_flock, (void *)args->arg,
1154 sizeof(linux_flock)));
1156 case LINUX_F_SETLK64:
1157 error = copyin((void *)args->arg, &linux_flock,
1158 sizeof(linux_flock));
1161 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1162 return (kern_fcntl(td, args->fd, F_SETLK,
1163 (intptr_t)&bsd_flock));
1165 case LINUX_F_SETLKW64:
1166 error = copyin((void *)args->arg, &linux_flock,
1167 sizeof(linux_flock));
1170 linux_to_bsd_flock64(&linux_flock, &bsd_flock);
1171 return (kern_fcntl(td, args->fd, F_SETLKW,
1172 (intptr_t)&bsd_flock));
1175 return (fcntl_common(td, args));
1177 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
1180 linux_chown(struct thread *td, struct linux_chown_args *args)
1185 LCONVPATHEXIST(td, args->path, &path);
1189 printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1191 error = kern_chown(td, path, UIO_SYSSPACE, args->uid, args->gid);
1197 linux_lchown(struct thread *td, struct linux_lchown_args *args)
1202 LCONVPATHEXIST(td, args->path, &path);
1206 printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1208 error = kern_lchown(td, path, UIO_SYSSPACE, args->uid, args->gid);