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.31 2006/06/03 08:06:31 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>
41 #include <sys/filedesc.h>
42 #include <sys/kern_syscall.h>
44 #include <sys/malloc.h>
45 #include <sys/mount.h>
46 #include <sys/nlookup.h>
48 #include <sys/sysproto.h>
50 #include <sys/vnode.h>
52 #include <vfs/ufs/quota.h>
53 #include <vfs/ufs/ufsmount.h>
55 #include <sys/file2.h>
57 #include <arch_linux/linux.h>
58 #include <arch_linux/linux_proto.h>
59 #include "linux_util.h"
62 linux_creat(struct linux_creat_args *args)
64 struct nlookupdata nd;
68 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
73 printf(ARGS(creat, "%s, %d"), path, args->mode);
75 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
77 error = kern_open(&nd, O_WRONLY | O_CREAT | O_TRUNC,
78 args->mode, &args->sysmsg_result);
80 linux_free_path(&path);
85 linux_open(struct linux_open_args *args)
87 struct thread *td = curthread;
88 struct proc *p = td->td_proc;
89 struct nlookupdata nd;
95 if (args->flags & LINUX_O_CREAT) {
96 error = linux_copyin_path(args->path, &path,
99 error = linux_copyin_path(args->path, &path,
107 printf(ARGS(open, "%s, 0x%x, 0x%x"), path, args->flags,
111 if (args->flags & LINUX_O_RDONLY)
113 if (args->flags & LINUX_O_WRONLY)
115 if (args->flags & LINUX_O_RDWR)
117 if (args->flags & LINUX_O_NDELAY)
119 if (args->flags & LINUX_O_APPEND)
121 if (args->flags & LINUX_O_SYNC)
123 if (args->flags & LINUX_O_NONBLOCK)
125 if (args->flags & LINUX_FASYNC)
127 if (args->flags & LINUX_O_CREAT)
129 if (args->flags & LINUX_O_TRUNC)
131 if (args->flags & LINUX_O_EXCL)
133 if (args->flags & LINUX_O_NOCTTY)
135 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
137 error = kern_open(&nd, flags,
138 args->mode, &args->sysmsg_result);
141 if (error == 0 && !(flags & O_NOCTTY) &&
142 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
145 fp = holdfp(p->p_fd, args->sysmsg_result, -1);
147 if (fp->f_type == DTYPE_VNODE)
148 fo_ioctl(fp, TIOCSCTTY, NULL, p->p_ucred);
154 printf(LMSG("open returns error %d"), error);
156 linux_free_path(&path);
161 linux_lseek(struct linux_lseek_args *args)
167 printf(ARGS(lseek, "%d, %ld, %d"),
168 args->fdes, (long)args->off, args->whence);
170 error = kern_lseek(args->fdes, args->off, args->whence,
171 &args->sysmsg_offset);
177 linux_llseek(struct linux_llseek_args *args)
184 printf(ARGS(llseek, "%d, %d:%d, %d"),
185 args->fd, args->ohigh, args->olow, args->whence);
187 off = (args->olow) | (((off_t) args->ohigh) << 32);
189 error = kern_lseek(args->fd, off, args->whence, &res);
192 error = copyout(&res, args->res, sizeof(res));
197 linux_readdir(struct linux_readdir_args *args)
199 struct linux_getdents_args lda;
203 lda.dent = args->dent;
205 lda.sysmsg_result = 0;
206 error = linux_getdents(&lda);
207 args->sysmsg_result = lda.sysmsg_result;
212 * Note that linux_getdents(2) and linux_getdents64(2) have the same
213 * arguments. They only differ in the definition of struct dirent they
214 * operate on. We use this to common the code, with the exception of
215 * accessing struct dirent. Note that linux_readdir(2) is implemented
216 * by means of linux_getdents(2). In this case we never operate on
217 * struct dirent64 and thus don't need to handle it...
224 char d_name[LINUX_NAME_MAX + 1];
232 char d_name[LINUX_NAME_MAX + 1];
235 #define LINUX_RECLEN(de,namlen) \
236 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
238 #define LINUX_DIRBLKSIZ 512
241 getdents_common(struct linux_getdents64_args *args, int is64bit)
243 struct thread *td = curthread;
244 struct proc *p = td->td_proc;
247 caddr_t inp, buf; /* BSD-format */
248 int len, reclen; /* BSD-format */
249 caddr_t outp; /* Linux-format */
250 int resid, linuxreclen=0; /* Linux-format */
256 struct l_dirent linux_dirent;
257 struct l_dirent64 linux_dirent64;
258 int buflen, error, eofflag, nbytes, justone;
259 u_long *cookies = NULL, *cookiep;
264 if ((error = holdvnode(p->p_fd, args->fd, &fp)) != 0)
267 if ((fp->f_flag & FREAD) == 0) {
272 vp = (struct vnode *) fp->f_data;
273 if (vp->v_type != VDIR) {
278 if ((error = VOP_GETATTR(vp, &va)) != 0)
281 nbytes = args->count;
283 /* readdir(2) case. Always struct dirent. */
288 nbytes = sizeof(linux_dirent);
296 buflen = max(LINUX_DIRBLKSIZ, nbytes);
297 buflen = min(buflen, MAXBSIZE);
298 buf = malloc(buflen, M_TEMP, M_WAITOK);
299 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
303 aiov.iov_len = buflen;
304 auio.uio_iov = &aiov;
306 auio.uio_rw = UIO_READ;
307 auio.uio_segflg = UIO_SYSSPACE;
309 auio.uio_resid = buflen;
310 auio.uio_offset = off;
313 free(cookies, M_TEMP);
317 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
322 outp = (caddr_t)args->dirent;
324 if ((len = buflen - auio.uio_resid) <= 0)
331 * When using cookies, the vfs has the option of reading from
332 * a different offset than that supplied (UFS truncates the
333 * offset to a block boundary to make sure that it never reads
334 * partway through a directory entry, even if the directory
335 * has been compacted).
337 while (len > 0 && ncookies > 0 && *cookiep <= off) {
338 bdp = (struct dirent *) inp;
339 len -= _DIRENT_DIRSIZ(bdp);
340 inp += _DIRENT_DIRSIZ(bdp);
347 if (cookiep && ncookies == 0)
349 bdp = (struct dirent *) inp;
350 reclen = _DIRENT_DIRSIZ(bdp);
356 if (bdp->d_ino == 0) {
368 linuxreclen = (is64bit)
369 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
370 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
372 if (reclen > len || resid < linuxreclen) {
378 /* readdir(2) case. */
379 linux_dirent.d_ino = (l_long)bdp->d_ino;
380 linux_dirent.d_off = (l_off_t)linuxreclen;
381 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
382 strcpy(linux_dirent.d_name, bdp->d_name);
383 error = copyout(&linux_dirent, outp, linuxreclen);
386 linux_dirent64.d_ino = bdp->d_ino;
387 linux_dirent64.d_off = (cookiep)
389 : (l_off_t)(off + reclen);
390 linux_dirent64.d_reclen =
391 (l_ushort)linuxreclen;
392 linux_dirent64.d_type = bdp->d_type;
393 strcpy(linux_dirent64.d_name, bdp->d_name);
394 error = copyout(&linux_dirent64, outp,
397 linux_dirent.d_ino = bdp->d_ino;
398 linux_dirent.d_off = (cookiep)
400 : (l_off_t)(off + reclen);
401 linux_dirent.d_reclen = (l_ushort)linuxreclen;
402 strcpy(linux_dirent.d_name, bdp->d_name);
403 error = copyout(&linux_dirent, outp,
418 resid -= linuxreclen;
424 if (outp == (caddr_t)args->dirent && eofflag == 0)
429 nbytes = resid + linuxreclen;
432 args->sysmsg_result = nbytes - resid;
436 free(cookies, M_TEMP);
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 nlookupdata nd;
476 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
481 printf(ARGS(access, "%s, %d"), path, args->flags);
483 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
485 error = kern_access(&nd, args->flags);
487 linux_free_path(&path);
492 linux_unlink(struct linux_unlink_args *args)
494 struct nlookupdata nd;
498 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
503 printf(ARGS(unlink, "%s"), path);
505 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
507 error = kern_unlink(&nd);
509 linux_free_path(&path);
514 linux_chdir(struct linux_chdir_args *args)
516 struct nlookupdata nd;
520 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
525 printf(ARGS(chdir, "%s"), path);
527 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
529 error = kern_chdir(&nd);
532 linux_free_path(&path);
537 linux_chmod(struct linux_chmod_args *args)
539 struct nlookupdata nd;
543 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
548 printf(ARGS(chmod, "%s, %d"), path, args->mode);
550 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
552 error = kern_chmod(&nd, args->mode);
554 linux_free_path(&path);
559 linux_mkdir(struct linux_mkdir_args *args)
561 struct nlookupdata nd;
565 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
570 printf(ARGS(mkdir, "%s, %d"), path, args->mode);
572 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
574 error = kern_mkdir(&nd, args->mode);
577 linux_free_path(&path);
582 linux_rmdir(struct linux_rmdir_args *args)
584 struct nlookupdata nd;
588 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
593 printf(ARGS(rmdir, "%s"), path);
595 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
597 error = kern_rmdir(&nd);
599 linux_free_path(&path);
604 linux_rename(struct linux_rename_args *args)
606 struct nlookupdata fromnd, tond;
610 error = linux_copyin_path(args->from, &from, LINUX_PATH_EXISTS);
613 error = linux_copyin_path(args->to, &to, LINUX_PATH_CREATE);
615 linux_free_path(&from);
620 printf(ARGS(rename, "%s, %s"), from, to);
622 error = nlookup_init(&fromnd, from, UIO_SYSSPACE, 0);
624 error = nlookup_init(&tond, to, UIO_SYSSPACE, 0);
626 error = kern_rename(&fromnd, &tond);
629 nlookup_done(&fromnd);
630 linux_free_path(&from);
631 linux_free_path(&to);
636 linux_symlink(struct linux_symlink_args *args)
638 struct thread *td = curthread;
639 struct nlookupdata nd;
644 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
647 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
649 linux_free_path(&path);
654 printf(ARGS(symlink, "%s, %s"), path, link);
656 error = nlookup_init(&nd, link, UIO_SYSSPACE, 0);
658 mode = ACCESSPERMS & ~td->td_proc->p_fd->fd_cmask;
659 error = kern_symlink(&nd, path, mode);
662 linux_free_path(&path);
663 linux_free_path(&link);
668 linux_readlink(struct linux_readlink_args *args)
670 struct nlookupdata nd;
674 error = linux_copyin_path(args->name, &path, LINUX_PATH_EXISTS);
678 if (ldebug(readlink))
679 printf(ARGS(readlink, "%s, %p, %d"), path, (void *)args->buf,
682 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
684 error = kern_readlink(&nd, args->buf, args->count,
685 &args->sysmsg_result);
688 linux_free_path(&path);
693 linux_truncate(struct linux_truncate_args *args)
695 struct nlookupdata nd;
699 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
703 if (ldebug(truncate))
704 printf(ARGS(truncate, "%s, %ld"), path,
707 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
709 error = kern_truncate(&nd, args->length);
711 linux_free_path(&path);
716 linux_truncate64(struct linux_truncate64_args *args)
718 struct nlookupdata nd;
722 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
726 if (ldebug(truncate64))
727 printf(ARGS(truncate64, "%s, %lld"), path,
728 (off_t)args->length);
730 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
732 error = kern_truncate(&nd, args->length);
734 linux_free_path(&path);
739 linux_ftruncate(struct linux_ftruncate_args *args)
744 if (ldebug(ftruncate))
745 printf(ARGS(ftruncate, "%d, %ld"), args->fd,
748 error = kern_ftruncate(args->fd, args->length);
754 linux_ftruncate64(struct linux_ftruncate64_args *args)
759 if (ldebug(ftruncate))
760 printf(ARGS(ftruncate64, "%d, %lld"), args->fd,
761 (off_t)args->length);
763 error = kern_ftruncate(args->fd, args->length);
769 linux_link(struct linux_link_args *args)
771 struct nlookupdata nd, linknd;
775 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
778 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
780 linux_free_path(&path);
785 printf(ARGS(link, "%s, %s"), path, link);
787 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
789 error = nlookup_init(&linknd, link, UIO_SYSSPACE, 0);
791 error = kern_link(&nd, &linknd);
792 nlookup_done(&linknd);
795 linux_free_path(&path);
796 linux_free_path(&link);
801 linux_fdatasync(struct linux_fdatasync_args *uap)
803 struct fsync_args bsd;
807 bsd.sysmsg_result = 0;
810 uap->sysmsg_result = bsd.sysmsg_result;
815 linux_pread(struct linux_pread_args *uap)
817 struct thread *td = curthread;
822 aiov.iov_base = uap->buf;
823 aiov.iov_len = uap->nbyte;
824 auio.uio_iov = &aiov;
826 auio.uio_offset = uap->offset;
827 auio.uio_resid = uap->nbyte;
828 auio.uio_rw = UIO_READ;
829 auio.uio_segflg = UIO_USERSPACE;
832 if (auio.uio_resid < 0)
835 error = kern_preadv(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
840 linux_pwrite(struct linux_pwrite_args *uap)
842 struct thread *td = curthread;
847 aiov.iov_base = uap->buf;
848 aiov.iov_len = uap->nbyte;
849 auio.uio_iov = &aiov;
851 auio.uio_offset = uap->offset;
852 auio.uio_resid = uap->nbyte;
853 auio.uio_rw = UIO_WRITE;
854 auio.uio_segflg = UIO_USERSPACE;
857 if (auio.uio_resid < 0)
860 error = kern_pwritev(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
866 linux_oldumount(struct linux_oldumount_args *args)
868 struct linux_umount_args args2;
871 args2.path = args->path;
873 args2.sysmsg_result = 0;
874 error = linux_umount(&args2);
875 args->sysmsg_result = args2.sysmsg_result;
880 linux_umount(struct linux_umount_args *args)
882 struct unmount_args bsd;
885 bsd.path = args->path;
886 bsd.flags = args->flags; /* XXX correct? */
887 bsd.sysmsg_result = 0;
889 error = unmount(&bsd);
890 args->sysmsg_result = bsd.sysmsg_result;
895 * fcntl family of syscalls
907 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
909 switch (linux_flock->l_type) {
911 bsd_flock->l_type = F_RDLCK;
914 bsd_flock->l_type = F_WRLCK;
917 bsd_flock->l_type = F_UNLCK;
920 bsd_flock->l_type = -1;
923 bsd_flock->l_whence = linux_flock->l_whence;
924 bsd_flock->l_start = (off_t)linux_flock->l_start;
925 bsd_flock->l_len = (off_t)linux_flock->l_len;
926 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
930 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
932 switch (bsd_flock->l_type) {
934 linux_flock->l_type = LINUX_F_RDLCK;
937 linux_flock->l_type = LINUX_F_WRLCK;
940 linux_flock->l_type = LINUX_F_UNLCK;
943 linux_flock->l_whence = bsd_flock->l_whence;
944 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
945 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
946 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
949 #if defined(__i386__)
959 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
961 switch (linux_flock->l_type) {
963 bsd_flock->l_type = F_RDLCK;
966 bsd_flock->l_type = F_WRLCK;
969 bsd_flock->l_type = F_UNLCK;
972 bsd_flock->l_type = -1;
975 bsd_flock->l_whence = linux_flock->l_whence;
976 bsd_flock->l_start = (off_t)linux_flock->l_start;
977 bsd_flock->l_len = (off_t)linux_flock->l_len;
978 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
982 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
984 switch (bsd_flock->l_type) {
986 linux_flock->l_type = LINUX_F_RDLCK;
989 linux_flock->l_type = LINUX_F_WRLCK;
992 linux_flock->l_type = LINUX_F_UNLCK;
995 linux_flock->l_whence = bsd_flock->l_whence;
996 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
997 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
998 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
1000 #endif /* __i386__ */
1003 linux_fcntl_common(struct linux_fcntl64_args *args)
1005 struct proc *p = curproc;
1006 struct l_flock linux_flock;
1008 union fcntl_dat dat;
1011 switch (args->cmd) {
1014 dat.fc_fd = args->arg;
1021 dat.fc_cloexec = args->arg;
1029 if (args->arg & LINUX_O_NDELAY)
1030 dat.fc_flags |= O_NONBLOCK;
1031 if (args->arg & LINUX_O_APPEND)
1032 dat.fc_flags |= O_APPEND;
1033 if (args->arg & LINUX_O_SYNC)
1034 dat.fc_flags |= O_FSYNC;
1035 if (args->arg & LINUX_FASYNC)
1036 dat.fc_flags |= O_ASYNC;
1040 case LINUX_F_SETLKW:
1042 error = copyin((caddr_t)args->arg, &linux_flock,
1043 sizeof(linux_flock));
1046 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
1048 case LINUX_F_GETOWN:
1051 case LINUX_F_SETOWN:
1053 * XXX some Linux applications depend on F_SETOWN having no
1054 * significant effect for pipes (SIGIO is not delivered for
1055 * pipes under Linux-2.2.35 at least).
1057 fp = holdfp(p->p_fd, args->fd, -1);
1060 if (fp->f_type == DTYPE_PIPE) {
1066 dat.fc_owner = args->arg;
1072 error = kern_fcntl(args->fd, cmd, &dat, p->p_ucred);
1075 switch (args->cmd) {
1077 args->sysmsg_result = dat.fc_fd;
1080 args->sysmsg_result = dat.fc_cloexec;
1085 args->sysmsg_result = 0;
1086 if (dat.fc_flags & O_RDONLY)
1087 args->sysmsg_result |= LINUX_O_RDONLY;
1088 if (dat.fc_flags & O_WRONLY)
1089 args->sysmsg_result |= LINUX_O_WRONLY;
1090 if (dat.fc_flags & O_RDWR)
1091 args->sysmsg_result |= LINUX_O_RDWR;
1092 if (dat.fc_flags & O_NDELAY)
1093 args->sysmsg_result |= LINUX_O_NONBLOCK;
1094 if (dat.fc_flags & O_APPEND)
1095 args->sysmsg_result |= LINUX_O_APPEND;
1096 if (dat.fc_flags & O_FSYNC)
1097 args->sysmsg_result |= LINUX_O_SYNC;
1098 if (dat.fc_flags & O_ASYNC)
1099 args->sysmsg_result |= LINUX_FASYNC;
1102 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1103 error = copyout(&linux_flock, (caddr_t)args->arg,
1104 sizeof(linux_flock));
1107 case LINUX_F_SETLKW:
1109 case LINUX_F_GETOWN:
1110 args->sysmsg_result = dat.fc_owner;
1112 case LINUX_F_SETOWN:
1121 linux_fcntl(struct linux_fcntl_args *args)
1123 struct linux_fcntl64_args args64;
1128 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1131 args64.fd = args->fd;
1132 args64.cmd = args->cmd;
1133 args64.arg = args->arg;
1134 args64.sysmsg_result = 0;
1135 error = linux_fcntl_common(&args64);
1136 args->sysmsg_result = args64.sysmsg_result;
1140 #if defined(__i386__)
1142 linux_fcntl64(struct linux_fcntl64_args *args)
1144 struct l_flock64 linux_flock;
1145 union fcntl_dat dat;
1149 if (ldebug(fcntl64))
1150 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1152 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1153 args->cmd == LINUX_F_SETLKW64) {
1154 switch (args->cmd) {
1155 case LINUX_F_GETLK64:
1158 case LINUX_F_SETLK64:
1161 case LINUX_F_SETLKW64:
1166 error = copyin((caddr_t)args->arg, &linux_flock,
1167 sizeof(linux_flock));
1170 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1172 error = kern_fcntl(args->fd, cmd, &dat, curproc->p_ucred);
1174 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1175 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1176 error = copyout(&linux_flock, (caddr_t)args->arg,
1177 sizeof(linux_flock));
1180 error = linux_fcntl_common(args);
1185 #endif /* __i386__ */
1188 linux_chown(struct linux_chown_args *args)
1190 struct nlookupdata nd;
1194 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1199 printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1201 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
1203 error = kern_chown(&nd, args->uid, args->gid);
1205 linux_free_path(&path);
1210 linux_lchown(struct linux_lchown_args *args)
1212 struct nlookupdata nd;
1216 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1221 printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1223 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
1225 error = kern_chown(&nd, args->uid, args->gid);
1227 linux_free_path(&path);