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.39 2008/09/28 05:08:16 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>
56 #include <sys/mplock2.h>
58 #include <arch_linux/linux.h>
59 #include <arch_linux/linux_proto.h>
60 #include "linux_util.h"
66 sys_linux_creat(struct linux_creat_args *args)
68 struct nlookupdata nd;
72 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
77 kprintf(ARGS(creat, "%s, %d"), path, args->mode);
80 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
82 error = kern_open(&nd, O_WRONLY | O_CREAT | O_TRUNC,
83 args->mode, &args->sysmsg_iresult);
86 linux_free_path(&path);
94 sys_linux_open(struct linux_open_args *args)
96 struct thread *td = curthread;
97 struct proc *p = td->td_proc;
98 struct nlookupdata nd;
102 if (args->flags & LINUX_O_CREAT) {
103 error = linux_copyin_path(args->path, &path,
106 error = linux_copyin_path(args->path, &path,
114 kprintf(ARGS(open, "%s, 0x%x, 0x%x"), path, args->flags,
118 if (args->flags & LINUX_O_RDONLY)
120 if (args->flags & LINUX_O_WRONLY)
122 if (args->flags & LINUX_O_RDWR)
124 if (args->flags & LINUX_O_NDELAY)
126 if (args->flags & LINUX_O_APPEND)
128 if (args->flags & LINUX_O_SYNC)
130 if (args->flags & LINUX_O_NONBLOCK)
132 if (args->flags & LINUX_FASYNC)
134 if (args->flags & LINUX_O_CREAT)
136 if (args->flags & LINUX_O_TRUNC)
138 if (args->flags & LINUX_O_EXCL)
140 if (args->flags & LINUX_O_NOCTTY)
143 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
145 error = kern_open(&nd, flags,
146 args->mode, &args->sysmsg_iresult);
149 if (error == 0 && !(flags & O_NOCTTY) &&
150 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
153 fp = holdfp(p->p_fd, args->sysmsg_iresult, -1);
155 if (fp->f_type == DTYPE_VNODE) {
156 fo_ioctl(fp, TIOCSCTTY, NULL,
165 kprintf(LMSG("open returns error %d"), error);
167 linux_free_path(&path);
175 sys_linux_lseek(struct linux_lseek_args *args)
181 kprintf(ARGS(lseek, "%d, %ld, %d"),
182 args->fdes, (long)args->off, args->whence);
184 error = kern_lseek(args->fdes, args->off, args->whence,
185 &args->sysmsg_offset);
194 sys_linux_llseek(struct linux_llseek_args *args)
201 kprintf(ARGS(llseek, "%d, %d:%d, %d"),
202 args->fd, args->ohigh, args->olow, args->whence);
204 off = (args->olow) | (((off_t) args->ohigh) << 32);
206 error = kern_lseek(args->fd, off, args->whence, &res);
209 error = copyout(&res, args->res, sizeof(res));
217 sys_linux_readdir(struct linux_readdir_args *args)
219 struct linux_getdents_args lda;
223 lda.dent = args->dent;
225 lda.sysmsg_iresult = 0;
226 error = sys_linux_getdents(&lda);
227 args->sysmsg_iresult = lda.sysmsg_iresult;
232 * Note that linux_getdents(2) and linux_getdents64(2) have the same
233 * arguments. They only differ in the definition of struct dirent they
234 * operate on. We use this to common the code, with the exception of
235 * accessing struct dirent. Note that linux_readdir(2) is implemented
236 * by means of linux_getdents(2). In this case we never operate on
237 * struct dirent64 and thus don't need to handle it...
244 char d_name[LINUX_NAME_MAX + 1];
252 char d_name[LINUX_NAME_MAX + 1];
255 #define LINUX_RECLEN(de,namlen) \
256 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
258 #define LINUX_DIRBLKSIZ 512
264 getdents_common(struct linux_getdents64_args *args, int is64bit)
266 struct thread *td = curthread;
267 struct proc *p = td->td_proc;
270 caddr_t inp, buf; /* BSD-format */
271 int reclen; /* BSD-format */
273 caddr_t outp; /* Linux-format */
274 int linuxreclen = 0; /* Linux-format */
281 struct l_dirent linux_dirent;
282 struct l_dirent64 linux_dirent64;
283 int error, eofflag, justone;
284 size_t buflen, nbytes;
285 off_t *cookies = NULL, *cookiep;
288 if ((error = holdvnode(p->p_fd, args->fd, &fp)) != 0)
292 if ((fp->f_flag & FREAD) == 0) {
297 vp = (struct vnode *) fp->f_data;
298 if (vp->v_type != VDIR) {
303 if ((error = VOP_GETATTR(vp, &va)) != 0)
306 nbytes = args->count;
307 if (nbytes == (size_t)-1) {
308 /* readdir(2) case. Always struct dirent. */
313 nbytes = sizeof(linux_dirent);
318 if ((size_t)nbytes < 0)
323 buflen = max(LINUX_DIRBLKSIZ, nbytes);
324 buflen = min(buflen, MAXBSIZE);
325 buf = kmalloc(buflen, M_TEMP, M_WAITOK);
329 aiov.iov_len = buflen;
330 auio.uio_iov = &aiov;
332 auio.uio_rw = UIO_READ;
333 auio.uio_segflg = UIO_SYSSPACE;
335 auio.uio_resid = buflen;
336 auio.uio_offset = off;
339 kfree(cookies, M_TEMP);
345 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
350 outp = (caddr_t)args->dirent;
352 if (auio.uio_resid >= buflen)
354 len = buflen - auio.uio_resid;
359 * When using cookies, the vfs has the option of reading from
360 * a different offset than that supplied (UFS truncates the
361 * offset to a block boundary to make sure that it never reads
362 * partway through a directory entry, even if the directory
363 * has been compacted).
365 while (len > 0 && ncookies > 0 && *cookiep < off) {
366 bdp = (struct dirent *) inp;
367 len -= _DIRENT_DIRSIZ(bdp);
368 inp += _DIRENT_DIRSIZ(bdp);
375 if (cookiep && ncookies == 0)
377 bdp = (struct dirent *) inp;
378 reclen = _DIRENT_DIRSIZ(bdp);
384 if (bdp->d_ino == 0) {
397 linuxreclen = (is64bit)
398 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
399 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
401 if (reclen > len || resid < linuxreclen) {
406 bzero(&linux_dirent, sizeof(linux_dirent));
407 bzero(&linux_dirent64, sizeof(linux_dirent64));
409 /* readdir(2) case. */
410 linux_dirent.d_ino = (l_long)INO64TO32(bdp->d_ino);
411 linux_dirent.d_off = (l_off_t)linuxreclen;
412 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
413 strcpy(linux_dirent.d_name, bdp->d_name);
414 error = copyout(&linux_dirent, outp, linuxreclen);
417 linux_dirent64.d_ino = bdp->d_ino;
418 linux_dirent64.d_off = (cookiep)
420 : (l_off_t)(off + reclen);
421 linux_dirent64.d_reclen =
422 (l_ushort)linuxreclen;
423 linux_dirent64.d_type = bdp->d_type;
424 strcpy(linux_dirent64.d_name, bdp->d_name);
425 error = copyout(&linux_dirent64, outp,
428 linux_dirent.d_ino = INO64TO32(bdp->d_ino);
429 linux_dirent.d_off = (cookiep)
431 : (l_off_t)(off + reclen);
432 linux_dirent.d_reclen = (l_ushort)linuxreclen;
433 strcpy(linux_dirent.d_name, bdp->d_name);
434 error = copyout(&linux_dirent, outp,
451 resid -= linuxreclen;
457 if (outp == (caddr_t)args->dirent && eofflag == 0)
462 nbytes = resid + linuxreclen;
465 args->sysmsg_iresult = (int)(nbytes - resid);
469 kfree(cookies, M_TEMP);
482 sys_linux_getdents(struct linux_getdents_args *args)
485 if (ldebug(getdents))
486 kprintf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
488 return (getdents_common((struct linux_getdents64_args*)args, 0));
495 sys_linux_getdents64(struct linux_getdents64_args *args)
498 if (ldebug(getdents64))
499 kprintf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
501 return (getdents_common(args, 1));
505 * These exist mainly for hooks for doing /compat/linux translation.
510 sys_linux_access(struct linux_access_args *args)
512 struct nlookupdata nd;
516 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
521 kprintf(ARGS(access, "%s, %d"), path, args->flags);
524 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
526 error = kern_access(&nd, args->flags, 0);
529 linux_free_path(&path);
537 sys_linux_unlink(struct linux_unlink_args *args)
539 struct nlookupdata nd;
543 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
548 kprintf(ARGS(unlink, "%s"), path);
551 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
553 error = kern_unlink(&nd);
556 linux_free_path(&path);
564 sys_linux_chdir(struct linux_chdir_args *args)
566 struct nlookupdata nd;
570 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
575 kprintf(ARGS(chdir, "%s"), path);
578 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
580 error = kern_chdir(&nd);
584 linux_free_path(&path);
592 sys_linux_chmod(struct linux_chmod_args *args)
594 struct nlookupdata nd;
598 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
603 kprintf(ARGS(chmod, "%s, %d"), path, args->mode);
606 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
608 error = kern_chmod(&nd, args->mode);
611 linux_free_path(&path);
619 sys_linux_mkdir(struct linux_mkdir_args *args)
621 struct nlookupdata nd;
625 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
630 kprintf(ARGS(mkdir, "%s, %d"), path, args->mode);
633 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
635 error = kern_mkdir(&nd, args->mode);
639 linux_free_path(&path);
647 sys_linux_rmdir(struct linux_rmdir_args *args)
649 struct nlookupdata nd;
653 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
658 kprintf(ARGS(rmdir, "%s"), path);
661 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
663 error = kern_rmdir(&nd);
666 linux_free_path(&path);
674 sys_linux_rename(struct linux_rename_args *args)
676 struct nlookupdata fromnd, tond;
680 error = linux_copyin_path(args->from, &from, LINUX_PATH_EXISTS);
683 error = linux_copyin_path(args->to, &to, LINUX_PATH_CREATE);
685 linux_free_path(&from);
690 kprintf(ARGS(rename, "%s, %s"), from, to);
693 error = nlookup_init(&fromnd, from, UIO_SYSSPACE, 0);
695 error = nlookup_init(&tond, to, UIO_SYSSPACE, 0);
697 error = kern_rename(&fromnd, &tond);
700 nlookup_done(&fromnd);
702 linux_free_path(&from);
703 linux_free_path(&to);
711 sys_linux_symlink(struct linux_symlink_args *args)
713 struct thread *td = curthread;
714 struct nlookupdata nd;
719 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
722 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
724 linux_free_path(&path);
729 kprintf(ARGS(symlink, "%s, %s"), path, link);
732 error = nlookup_init(&nd, link, UIO_SYSSPACE, 0);
734 mode = ACCESSPERMS & ~td->td_proc->p_fd->fd_cmask;
735 error = kern_symlink(&nd, path, mode);
739 linux_free_path(&path);
740 linux_free_path(&link);
748 sys_linux_readlink(struct linux_readlink_args *args)
750 struct nlookupdata nd;
754 error = linux_copyin_path(args->name, &path, LINUX_PATH_EXISTS);
758 if (ldebug(readlink))
759 kprintf(ARGS(readlink, "%s, %p, %d"), path, (void *)args->buf,
763 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
765 error = kern_readlink(&nd, args->buf, args->count,
766 &args->sysmsg_iresult);
770 linux_free_path(&path);
778 sys_linux_truncate(struct linux_truncate_args *args)
780 struct nlookupdata nd;
784 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
788 if (ldebug(truncate))
789 kprintf(ARGS(truncate, "%s, %ld"), path,
793 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
795 error = kern_truncate(&nd, args->length);
798 linux_free_path(&path);
806 sys_linux_truncate64(struct linux_truncate64_args *args)
808 struct nlookupdata nd;
812 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
816 if (ldebug(truncate64))
817 kprintf(ARGS(truncate64, "%s, %lld"), path,
818 (off_t)args->length);
821 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
823 error = kern_truncate(&nd, args->length);
826 linux_free_path(&path);
834 sys_linux_ftruncate(struct linux_ftruncate_args *args)
839 if (ldebug(ftruncate))
840 kprintf(ARGS(ftruncate, "%d, %ld"), args->fd,
844 error = kern_ftruncate(args->fd, args->length);
854 sys_linux_ftruncate64(struct linux_ftruncate64_args *args)
859 if (ldebug(ftruncate))
860 kprintf(ARGS(ftruncate64, "%d, %lld"), args->fd,
861 (off_t)args->length);
864 error = kern_ftruncate(args->fd, args->length);
874 sys_linux_link(struct linux_link_args *args)
876 struct nlookupdata nd, linknd;
880 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
883 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
885 linux_free_path(&path);
890 kprintf(ARGS(link, "%s, %s"), path, link);
893 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
895 error = nlookup_init(&linknd, link, UIO_SYSSPACE, 0);
897 error = kern_link(&nd, &linknd);
898 nlookup_done(&linknd);
902 linux_free_path(&path);
903 linux_free_path(&link);
911 sys_linux_fdatasync(struct linux_fdatasync_args *uap)
913 struct fsync_args bsd;
917 bsd.sysmsg_iresult = 0;
919 error = sys_fsync(&bsd);
920 uap->sysmsg_iresult = bsd.sysmsg_iresult;
928 sys_linux_pread(struct linux_pread_args *uap)
930 struct thread *td = curthread;
935 aiov.iov_base = uap->buf;
936 aiov.iov_len = uap->nbyte;
937 auio.uio_iov = &aiov;
939 auio.uio_offset = uap->offset;
940 auio.uio_resid = uap->nbyte;
941 auio.uio_rw = UIO_READ;
942 auio.uio_segflg = UIO_USERSPACE;
945 if ((ssize_t)auio.uio_resid < 0) {
948 error = kern_preadv(uap->fd, &auio, O_FOFFSET,
949 &uap->sysmsg_szresult);
958 sys_linux_pwrite(struct linux_pwrite_args *uap)
960 struct thread *td = curthread;
965 aiov.iov_base = uap->buf;
966 aiov.iov_len = uap->nbyte;
967 auio.uio_iov = &aiov;
969 auio.uio_offset = uap->offset;
970 auio.uio_resid = uap->nbyte;
971 auio.uio_rw = UIO_WRITE;
972 auio.uio_segflg = UIO_USERSPACE;
975 if ((ssize_t)auio.uio_resid < 0) {
978 error = kern_pwritev(uap->fd, &auio, O_FOFFSET,
979 &uap->sysmsg_szresult);
988 sys_linux_oldumount(struct linux_oldumount_args *args)
990 struct linux_umount_args args2;
993 args2.path = args->path;
995 args2.sysmsg_iresult = 0;
996 error = sys_linux_umount(&args2);
997 args->sysmsg_iresult = args2.sysmsg_iresult;
1005 sys_linux_umount(struct linux_umount_args *args)
1007 struct unmount_args bsd;
1010 bsd.path = args->path;
1011 bsd.flags = args->flags; /* XXX correct? */
1012 bsd.sysmsg_iresult = 0;
1014 error = sys_unmount(&bsd);
1015 args->sysmsg_iresult = bsd.sysmsg_iresult;
1020 * fcntl family of syscalls
1034 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
1036 switch (linux_flock->l_type) {
1038 bsd_flock->l_type = F_RDLCK;
1041 bsd_flock->l_type = F_WRLCK;
1044 bsd_flock->l_type = F_UNLCK;
1047 bsd_flock->l_type = -1;
1050 bsd_flock->l_whence = linux_flock->l_whence;
1051 bsd_flock->l_start = (off_t)linux_flock->l_start;
1052 bsd_flock->l_len = (off_t)linux_flock->l_len;
1053 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
1060 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
1062 switch (bsd_flock->l_type) {
1064 linux_flock->l_type = LINUX_F_RDLCK;
1067 linux_flock->l_type = LINUX_F_WRLCK;
1070 linux_flock->l_type = LINUX_F_UNLCK;
1073 linux_flock->l_whence = bsd_flock->l_whence;
1074 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
1075 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
1076 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
1079 #if defined(__i386__)
1092 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
1094 switch (linux_flock->l_type) {
1096 bsd_flock->l_type = F_RDLCK;
1099 bsd_flock->l_type = F_WRLCK;
1102 bsd_flock->l_type = F_UNLCK;
1105 bsd_flock->l_type = -1;
1108 bsd_flock->l_whence = linux_flock->l_whence;
1109 bsd_flock->l_start = (off_t)linux_flock->l_start;
1110 bsd_flock->l_len = (off_t)linux_flock->l_len;
1111 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
1118 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
1120 switch (bsd_flock->l_type) {
1122 linux_flock->l_type = LINUX_F_RDLCK;
1125 linux_flock->l_type = LINUX_F_WRLCK;
1128 linux_flock->l_type = LINUX_F_UNLCK;
1131 linux_flock->l_whence = bsd_flock->l_whence;
1132 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
1133 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
1134 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
1136 #endif /* __i386__ */
1142 linux_fcntl_common(struct linux_fcntl64_args *args)
1144 struct thread *td = curthread;
1145 struct l_flock linux_flock;
1147 union fcntl_dat dat;
1150 switch (args->cmd) {
1153 dat.fc_fd = args->arg;
1160 dat.fc_cloexec = args->arg;
1168 if (args->arg & LINUX_O_NDELAY)
1169 dat.fc_flags |= O_NONBLOCK;
1170 if (args->arg & LINUX_O_APPEND)
1171 dat.fc_flags |= O_APPEND;
1172 if (args->arg & LINUX_O_SYNC)
1173 dat.fc_flags |= O_FSYNC;
1174 if (args->arg & LINUX_FASYNC)
1175 dat.fc_flags |= O_ASYNC;
1179 case LINUX_F_SETLKW:
1181 error = copyin((caddr_t)args->arg, &linux_flock,
1182 sizeof(linux_flock));
1185 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
1187 case LINUX_F_GETOWN:
1190 case LINUX_F_SETOWN:
1192 * XXX some Linux applications depend on F_SETOWN having no
1193 * significant effect for pipes (SIGIO is not delivered for
1194 * pipes under Linux-2.2.35 at least).
1196 fp = holdfp(td->td_proc->p_fd, args->fd, -1);
1199 if (fp->f_type == DTYPE_PIPE) {
1205 dat.fc_owner = args->arg;
1212 error = kern_fcntl(args->fd, cmd, &dat, td->td_ucred);
1215 switch (args->cmd) {
1217 args->sysmsg_iresult = dat.fc_fd;
1220 args->sysmsg_iresult = dat.fc_cloexec;
1225 args->sysmsg_iresult = 0;
1226 if (dat.fc_flags & O_RDONLY)
1227 args->sysmsg_iresult |= LINUX_O_RDONLY;
1228 if (dat.fc_flags & O_WRONLY)
1229 args->sysmsg_iresult |= LINUX_O_WRONLY;
1230 if (dat.fc_flags & O_RDWR)
1231 args->sysmsg_iresult |= LINUX_O_RDWR;
1232 if (dat.fc_flags & O_NDELAY)
1233 args->sysmsg_iresult |= LINUX_O_NONBLOCK;
1234 if (dat.fc_flags & O_APPEND)
1235 args->sysmsg_iresult |= LINUX_O_APPEND;
1236 if (dat.fc_flags & O_FSYNC)
1237 args->sysmsg_iresult |= LINUX_O_SYNC;
1238 if (dat.fc_flags & O_ASYNC)
1239 args->sysmsg_iresult |= LINUX_FASYNC;
1242 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1243 error = copyout(&linux_flock, (caddr_t)args->arg,
1244 sizeof(linux_flock));
1247 case LINUX_F_SETLKW:
1249 case LINUX_F_GETOWN:
1250 args->sysmsg_iresult = dat.fc_owner;
1252 case LINUX_F_SETOWN:
1264 sys_linux_fcntl(struct linux_fcntl_args *args)
1266 struct linux_fcntl64_args args64;
1271 kprintf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1274 args64.fd = args->fd;
1275 args64.cmd = args->cmd;
1276 args64.arg = args->arg;
1277 args64.sysmsg_iresult = 0;
1278 error = linux_fcntl_common(&args64);
1279 args->sysmsg_iresult = args64.sysmsg_iresult;
1283 #if defined(__i386__)
1288 sys_linux_fcntl64(struct linux_fcntl64_args *args)
1290 struct thread *td = curthread;
1291 struct l_flock64 linux_flock;
1292 union fcntl_dat dat;
1296 if (ldebug(fcntl64))
1297 kprintf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1299 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1300 args->cmd == LINUX_F_SETLKW64) {
1301 switch (args->cmd) {
1302 case LINUX_F_GETLK64:
1305 case LINUX_F_SETLK64:
1308 case LINUX_F_SETLKW64:
1313 error = copyin((caddr_t)args->arg, &linux_flock,
1314 sizeof(linux_flock));
1317 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1320 error = kern_fcntl(args->fd, cmd, &dat, td->td_ucred);
1322 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1323 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1324 error = copyout(&linux_flock, (caddr_t)args->arg,
1325 sizeof(linux_flock));
1328 error = linux_fcntl_common(args);
1333 #endif /* __i386__ */
1339 sys_linux_chown(struct linux_chown_args *args)
1341 struct nlookupdata nd;
1345 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1350 kprintf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1353 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
1355 error = kern_chown(&nd, args->uid, args->gid);
1358 linux_free_path(&path);
1366 sys_linux_lchown(struct linux_lchown_args *args)
1368 struct nlookupdata nd;
1372 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1377 kprintf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1380 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
1382 error = kern_chown(&nd, args->uid, args->gid);
1385 linux_free_path(&path);