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.19 2004/11/12 00:09: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>
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"
63 linux_creat(struct linux_creat_args *args)
65 struct nlookupdata nd;
69 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
74 printf(ARGS(creat, "%s, %d"), path, args->mode);
76 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
78 error = kern_open(&nd, O_WRONLY | O_CREAT | O_TRUNC,
79 args->mode, &args->sysmsg_result);
81 linux_free_path(&path);
87 linux_open(struct linux_open_args *args)
89 struct thread *td = curthread;
90 struct proc *p = td->td_proc;
91 struct nlookupdata nd;
97 if (args->flags & LINUX_O_CREAT) {
98 error = linux_copyin_path(args->path, &path,
101 error = linux_copyin_path(args->path, &path,
109 printf(ARGS(open, "%s, 0x%x, 0x%x"), path, args->flags,
113 if (args->flags & LINUX_O_RDONLY)
115 if (args->flags & LINUX_O_WRONLY)
117 if (args->flags & LINUX_O_RDWR)
119 if (args->flags & LINUX_O_NDELAY)
121 if (args->flags & LINUX_O_APPEND)
123 if (args->flags & LINUX_O_SYNC)
125 if (args->flags & LINUX_O_NONBLOCK)
127 if (args->flags & LINUX_FASYNC)
129 if (args->flags & LINUX_O_CREAT)
131 if (args->flags & LINUX_O_TRUNC)
133 if (args->flags & LINUX_O_EXCL)
135 if (args->flags & LINUX_O_NOCTTY)
137 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
139 error = kern_open(&nd, flags,
140 args->mode, &args->sysmsg_result);
143 if (error == 0 && !(flags & O_NOCTTY) &&
144 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
145 struct filedesc *fdp = p->p_fd;
146 struct file *fp = fdp->fd_ofiles[args->sysmsg_result];
148 if (fp->f_type == DTYPE_VNODE)
149 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td);
153 printf(LMSG("open returns error %d"), error);
155 linux_free_path(&path);
160 linux_lseek(struct linux_lseek_args *args)
166 printf(ARGS(lseek, "%d, %ld, %d"),
167 args->fdes, (long)args->off, args->whence);
169 error = kern_lseek(args->fdes, args->off, args->whence,
170 &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));
195 #endif /*!__alpha__*/
199 linux_readdir(struct linux_readdir_args *args)
201 struct linux_getdents_args lda;
205 lda.dent = args->dent;
207 lda.sysmsg_result = 0;
208 error = linux_getdents(&lda);
209 args->sysmsg_result = lda.sysmsg_result;
212 #endif /*!__alpha__*/
215 * Note that linux_getdents(2) and linux_getdents64(2) have the same
216 * arguments. They only differ in the definition of struct dirent they
217 * operate on. We use this to common the code, with the exception of
218 * accessing struct dirent. Note that linux_readdir(2) is implemented
219 * by means of linux_getdents(2). In this case we never operate on
220 * struct dirent64 and thus don't need to handle it...
227 char d_name[LINUX_NAME_MAX + 1];
235 char d_name[LINUX_NAME_MAX + 1];
238 #define LINUX_RECLEN(de,namlen) \
239 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
241 #define LINUX_DIRBLKSIZ 512
244 getdents_common(struct linux_getdents64_args *args, int is64bit)
246 struct thread *td = curthread;
247 struct proc *p = td->td_proc;
250 caddr_t inp, buf; /* BSD-format */
251 int len, reclen; /* BSD-format */
252 caddr_t outp; /* Linux-format */
253 int resid, linuxreclen=0; /* Linux-format */
259 struct l_dirent linux_dirent;
260 struct l_dirent64 linux_dirent64;
261 int buflen, error, eofflag, nbytes, justone;
262 u_long *cookies = NULL, *cookiep;
267 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0)
270 if ((fp->f_flag & FREAD) == 0)
273 vp = (struct vnode *) fp->f_data;
274 if (vp->v_type != VDIR)
277 if ((error = VOP_GETATTR(vp, &va, td)))
280 nbytes = args->count;
282 /* readdir(2) case. Always struct dirent. */
285 nbytes = sizeof(linux_dirent);
292 buflen = max(LINUX_DIRBLKSIZ, nbytes);
293 buflen = min(buflen, MAXBSIZE);
294 buf = malloc(buflen, M_TEMP, M_WAITOK);
295 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
299 aiov.iov_len = buflen;
300 auio.uio_iov = &aiov;
302 auio.uio_rw = UIO_READ;
303 auio.uio_segflg = UIO_SYSSPACE;
305 auio.uio_resid = buflen;
306 auio.uio_offset = off;
309 free(cookies, M_TEMP);
313 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
318 outp = (caddr_t)args->dirent;
320 if ((len = buflen - auio.uio_resid) <= 0)
327 * When using cookies, the vfs has the option of reading from
328 * a different offset than that supplied (UFS truncates the
329 * offset to a block boundary to make sure that it never reads
330 * partway through a directory entry, even if the directory
331 * has been compacted).
333 while (len > 0 && ncookies > 0 && *cookiep <= off) {
334 bdp = (struct dirent *) inp;
335 len -= bdp->d_reclen;
336 inp += bdp->d_reclen;
343 if (cookiep && ncookies == 0)
345 bdp = (struct dirent *) inp;
346 reclen = bdp->d_reclen;
352 if (bdp->d_fileno == 0) {
364 linuxreclen = (is64bit)
365 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
366 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
368 if (reclen > len || resid < linuxreclen) {
374 /* readdir(2) case. */
375 linux_dirent.d_ino = (l_long)bdp->d_fileno;
376 linux_dirent.d_off = (l_off_t)linuxreclen;
377 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
378 strcpy(linux_dirent.d_name, bdp->d_name);
379 error = copyout(&linux_dirent, outp, linuxreclen);
382 linux_dirent64.d_ino = bdp->d_fileno;
383 linux_dirent64.d_off = (cookiep)
385 : (l_off_t)(off + reclen);
386 linux_dirent64.d_reclen =
387 (l_ushort)linuxreclen;
388 linux_dirent64.d_type = bdp->d_type;
389 strcpy(linux_dirent64.d_name, bdp->d_name);
390 error = copyout(&linux_dirent64, outp,
393 linux_dirent.d_ino = bdp->d_fileno;
394 linux_dirent.d_off = (cookiep)
396 : (l_off_t)(off + reclen);
397 linux_dirent.d_reclen = (l_ushort)linuxreclen;
398 strcpy(linux_dirent.d_name, bdp->d_name);
399 error = copyout(&linux_dirent, outp,
414 resid -= linuxreclen;
420 if (outp == (caddr_t)args->dirent)
425 nbytes = resid + linuxreclen;
428 args->sysmsg_result = nbytes - resid;
432 free(cookies, M_TEMP);
434 VOP_UNLOCK(vp, 0, td);
440 linux_getdents(struct linux_getdents_args *args)
443 if (ldebug(getdents))
444 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
446 return (getdents_common((struct linux_getdents64_args*)args, 0));
450 linux_getdents64(struct linux_getdents64_args *args)
453 if (ldebug(getdents64))
454 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
456 return (getdents_common(args, 1));
460 * These exist mainly for hooks for doing /compat/linux translation.
464 linux_access(struct linux_access_args *args)
466 struct nlookupdata nd;
470 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
475 printf(ARGS(access, "%s, %d"), path, args->flags);
477 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
479 error = kern_access(&nd, args->flags);
481 linux_free_path(&path);
486 linux_unlink(struct linux_unlink_args *args)
488 struct nlookupdata nd;
492 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
497 printf(ARGS(unlink, "%s"), path);
499 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
501 error = kern_unlink(&nd);
503 linux_free_path(&path);
508 linux_chdir(struct linux_chdir_args *args)
510 struct nlookupdata nd;
514 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
519 printf(ARGS(chdir, "%s"), path);
521 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
523 error = kern_chdir(&nd);
526 linux_free_path(&path);
531 linux_chmod(struct linux_chmod_args *args)
533 struct nlookupdata nd;
537 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
542 printf(ARGS(chmod, "%s, %d"), path, args->mode);
544 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
546 error = kern_chmod(&nd, args->mode);
548 linux_free_path(&path);
553 linux_mkdir(struct linux_mkdir_args *args)
555 struct nlookupdata nd;
559 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
564 printf(ARGS(mkdir, "%s, %d"), path, args->mode);
566 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
568 error = kern_mkdir(&nd, args->mode);
571 linux_free_path(&path);
576 linux_rmdir(struct linux_rmdir_args *args)
578 struct nlookupdata nd;
582 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
587 printf(ARGS(rmdir, "%s"), path);
589 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
591 error = kern_rmdir(&nd);
593 linux_free_path(&path);
598 linux_rename(struct linux_rename_args *args)
600 struct nlookupdata fromnd, tond;
604 error = linux_copyin_path(args->from, &from, LINUX_PATH_EXISTS);
607 error = linux_copyin_path(args->to, &to, LINUX_PATH_CREATE);
609 linux_free_path(&from);
614 printf(ARGS(rename, "%s, %s"), from, to);
616 error = nlookup_init(&fromnd, from, UIO_SYSSPACE, 0);
618 error = nlookup_init(&tond, to, UIO_SYSSPACE, 0);
620 error = kern_rename(&fromnd, &tond);
623 nlookup_done(&fromnd);
624 linux_free_path(&from);
625 linux_free_path(&to);
630 linux_symlink(struct linux_symlink_args *args)
632 struct thread *td = curthread;
633 struct nlookupdata nd;
638 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
641 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
643 linux_free_path(&path);
648 printf(ARGS(symlink, "%s, %s"), path, link);
650 error = nlookup_init(&nd, link, UIO_SYSSPACE, 0);
652 mode = ACCESSPERMS & ~td->td_proc->p_fd->fd_cmask;
653 error = kern_symlink(&nd, path, mode);
656 linux_free_path(&path);
657 linux_free_path(&link);
662 linux_readlink(struct linux_readlink_args *args)
664 struct nlookupdata nd;
668 error = linux_copyin_path(args->name, &path, LINUX_PATH_EXISTS);
672 if (ldebug(readlink))
673 printf(ARGS(readlink, "%s, %p, %d"), path, (void *)args->buf,
676 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
678 error = kern_readlink(&nd, args->buf, args->count,
679 &args->sysmsg_result);
682 linux_free_path(&path);
687 linux_truncate(struct linux_truncate_args *args)
689 struct nlookupdata nd;
693 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
697 if (ldebug(truncate))
698 printf(ARGS(truncate, "%s, %ld"), path,
701 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
703 error = kern_truncate(&nd, args->length);
705 linux_free_path(&path);
710 linux_truncate64(struct linux_truncate64_args *args)
712 struct nlookupdata nd;
716 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
720 if (ldebug(truncate64))
721 printf(ARGS(truncate64, "%s, %lld"), path,
722 (off_t)args->length);
724 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
726 error = kern_truncate(&nd, args->length);
728 linux_free_path(&path);
733 linux_ftruncate(struct linux_ftruncate_args *args)
738 if (ldebug(ftruncate))
739 printf(ARGS(ftruncate, "%d, %ld"), args->fd,
742 error = kern_ftruncate(args->fd, args->length);
748 linux_ftruncate64(struct linux_ftruncate64_args *args)
753 if (ldebug(ftruncate))
754 printf(ARGS(ftruncate64, "%d, %lld"), args->fd,
755 (off_t)args->length);
757 error = kern_ftruncate(args->fd, args->length);
763 linux_link(struct linux_link_args *args)
765 struct nlookupdata nd, linknd;
769 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
772 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
774 linux_free_path(&path);
779 printf(ARGS(link, "%s, %s"), path, link);
781 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
783 error = nlookup_init(&linknd, link, UIO_SYSSPACE, 0);
785 error = kern_link(&nd, &linknd);
786 nlookup_done(&linknd);
789 linux_free_path(&path);
790 linux_free_path(&link);
796 linux_fdatasync(struct linux_fdatasync_args *uap)
798 struct fsync_args bsd;
802 bsd.sysmsg_result = 0;
805 uap->sysmsg_result = bsd.sysmsg_result;
808 #endif /*!__alpha__*/
811 linux_pread(struct linux_pread_args *uap)
813 struct thread *td = curthread;
818 aiov.iov_base = uap->buf;
819 aiov.iov_len = uap->nbyte;
820 auio.uio_iov = &aiov;
822 auio.uio_offset = uap->offset;
823 auio.uio_resid = uap->nbyte;
824 auio.uio_rw = UIO_READ;
825 auio.uio_segflg = UIO_USERSPACE;
828 error = kern_readv(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
834 linux_pwrite(struct linux_pwrite_args *uap)
836 struct thread *td = curthread;
841 aiov.iov_base = uap->buf;
842 aiov.iov_len = uap->nbyte;
843 auio.uio_iov = &aiov;
845 auio.uio_offset = uap->offset;
846 auio.uio_resid = uap->nbyte;
847 auio.uio_rw = UIO_WRITE;
848 auio.uio_segflg = UIO_USERSPACE;
851 error = kern_writev(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
857 linux_oldumount(struct linux_oldumount_args *args)
859 struct linux_umount_args args2;
862 args2.path = args->path;
864 args2.sysmsg_result = 0;
865 error = linux_umount(&args2);
866 args->sysmsg_result = args2.sysmsg_result;
871 linux_umount(struct linux_umount_args *args)
873 struct unmount_args bsd;
876 bsd.path = args->path;
877 bsd.flags = args->flags; /* XXX correct? */
878 bsd.sysmsg_result = 0;
880 error = unmount(&bsd);
881 args->sysmsg_result = bsd.sysmsg_result;
886 * fcntl family of syscalls
898 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
900 switch (linux_flock->l_type) {
902 bsd_flock->l_type = F_RDLCK;
905 bsd_flock->l_type = F_WRLCK;
908 bsd_flock->l_type = F_UNLCK;
911 bsd_flock->l_type = -1;
914 bsd_flock->l_whence = linux_flock->l_whence;
915 bsd_flock->l_start = (off_t)linux_flock->l_start;
916 bsd_flock->l_len = (off_t)linux_flock->l_len;
917 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
921 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
923 switch (bsd_flock->l_type) {
925 linux_flock->l_type = LINUX_F_RDLCK;
928 linux_flock->l_type = LINUX_F_WRLCK;
931 linux_flock->l_type = LINUX_F_UNLCK;
934 linux_flock->l_whence = bsd_flock->l_whence;
935 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
936 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
937 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
940 #if defined(__i386__)
950 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
952 switch (linux_flock->l_type) {
954 bsd_flock->l_type = F_RDLCK;
957 bsd_flock->l_type = F_WRLCK;
960 bsd_flock->l_type = F_UNLCK;
963 bsd_flock->l_type = -1;
966 bsd_flock->l_whence = linux_flock->l_whence;
967 bsd_flock->l_start = (off_t)linux_flock->l_start;
968 bsd_flock->l_len = (off_t)linux_flock->l_len;
969 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
973 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
975 switch (bsd_flock->l_type) {
977 linux_flock->l_type = LINUX_F_RDLCK;
980 linux_flock->l_type = LINUX_F_WRLCK;
983 linux_flock->l_type = LINUX_F_UNLCK;
986 linux_flock->l_whence = bsd_flock->l_whence;
987 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
988 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
989 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
991 #endif /* __i386__ */
993 #if defined(__alpha__)
994 #define linux_fcntl64_args linux_fcntl_args
998 linux_fcntl_common(struct linux_fcntl64_args *args)
1000 struct proc *p = curproc;
1001 struct l_flock linux_flock;
1002 struct filedesc *fdp;
1004 union fcntl_dat dat;
1007 switch (args->cmd) {
1010 dat.fc_fd = args->arg;
1017 dat.fc_cloexec = args->arg;
1025 if (args->arg & LINUX_O_NDELAY)
1026 dat.fc_flags |= O_NONBLOCK;
1027 if (args->arg & LINUX_O_APPEND)
1028 dat.fc_flags |= O_APPEND;
1029 if (args->arg & LINUX_O_SYNC)
1030 dat.fc_flags |= O_FSYNC;
1031 if (args->arg & LINUX_FASYNC)
1032 dat.fc_flags |= O_ASYNC;
1036 case LINUX_F_SETLKW:
1038 error = copyin((caddr_t)args->arg, &linux_flock,
1039 sizeof(linux_flock));
1042 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
1044 case LINUX_F_GETOWN:
1047 case LINUX_F_SETOWN:
1049 * XXX some Linux applications depend on F_SETOWN having no
1050 * significant effect for pipes (SIGIO is not delivered for
1051 * pipes under Linux-2.2.35 at least).
1054 if ((u_int)args->fd >= fdp->fd_nfiles ||
1055 (fp = fdp->fd_ofiles[args->fd]) == NULL)
1057 if (fp->f_type == DTYPE_PIPE)
1060 dat.fc_owner = args->arg;
1066 error = kern_fcntl(args->fd, cmd, &dat);
1069 switch (args->cmd) {
1071 args->sysmsg_result = dat.fc_fd;
1074 args->sysmsg_result = dat.fc_cloexec;
1079 args->sysmsg_result = 0;
1080 if (dat.fc_flags & O_RDONLY)
1081 args->sysmsg_result |= LINUX_O_RDONLY;
1082 if (dat.fc_flags & O_WRONLY)
1083 args->sysmsg_result |= LINUX_O_WRONLY;
1084 if (dat.fc_flags & O_RDWR)
1085 args->sysmsg_result |= LINUX_O_RDWR;
1086 if (dat.fc_flags & O_NDELAY)
1087 args->sysmsg_result |= LINUX_O_NONBLOCK;
1088 if (dat.fc_flags & O_APPEND)
1089 args->sysmsg_result |= LINUX_O_APPEND;
1090 if (dat.fc_flags & O_FSYNC)
1091 args->sysmsg_result |= LINUX_O_SYNC;
1092 if (dat.fc_flags & O_ASYNC)
1093 args->sysmsg_result |= LINUX_FASYNC;
1096 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1097 error = copyout(&linux_flock, (caddr_t)args->arg,
1098 sizeof(linux_flock));
1101 case LINUX_F_SETLKW:
1103 case LINUX_F_GETOWN:
1104 args->sysmsg_result = dat.fc_owner;
1106 case LINUX_F_SETOWN:
1115 linux_fcntl(struct linux_fcntl_args *args)
1117 struct linux_fcntl64_args args64;
1122 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1125 args64.fd = args->fd;
1126 args64.cmd = args->cmd;
1127 args64.arg = args->arg;
1128 args64.sysmsg_result = 0;
1129 error = linux_fcntl_common(&args64);
1130 args->sysmsg_result = args64.sysmsg_result;
1134 #if defined(__i386__)
1136 linux_fcntl64(struct linux_fcntl64_args *args)
1138 struct l_flock64 linux_flock;
1139 union fcntl_dat dat;
1143 if (ldebug(fcntl64))
1144 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1146 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1147 args->cmd == LINUX_F_SETLKW64) {
1148 switch (args->cmd) {
1149 case LINUX_F_GETLK64:
1152 case LINUX_F_SETLK64:
1155 case LINUX_F_SETLKW64:
1160 error = copyin((caddr_t)args->arg, &linux_flock,
1161 sizeof(linux_flock));
1164 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1166 error = kern_fcntl(args->fd, cmd, &dat);
1168 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1169 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1170 error = copyout(&linux_flock, (caddr_t)args->arg,
1171 sizeof(linux_flock));
1174 error = linux_fcntl_common(args);
1179 #endif /* __i386__ */
1182 linux_chown(struct linux_chown_args *args)
1184 struct nlookupdata nd;
1188 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1193 printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1195 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
1197 error = kern_chown(&nd, args->uid, args->gid);
1199 linux_free_path(&path);
1204 linux_lchown(struct linux_lchown_args *args)
1206 struct nlookupdata nd;
1210 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1215 printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1217 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
1219 error = kern_chown(&nd, args->uid, args->gid);
1221 linux_free_path(&path);