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.14 2003/11/13 04:04:42 daver 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>
41 #include <sys/kern_syscall.h>
43 #include <sys/malloc.h>
44 #include <sys/mount.h>
45 #include <sys/namei.h>
47 #include <sys/sysproto.h>
49 #include <sys/vnode.h>
51 #include <vfs/ufs/quota.h>
52 #include <vfs/ufs/ufsmount.h>
54 #include <sys/file2.h>
56 #include <arch_linux/linux.h>
57 #include <arch_linux/linux_proto.h>
58 #include "linux_util.h"
62 linux_creat(struct linux_creat_args *args)
64 struct thread *td = curthread;
69 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
74 printf(ARGS(creat, "%s, %d"), path, args->mode);
76 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td);
78 error = kern_open(&nd, O_WRONLY | O_CREAT | O_TRUNC, args->mode,
79 &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;
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 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td);
139 error = kern_open(&nd, flags, args->mode, &args->sysmsg_result);
141 if (error == 0 && !(flags & O_NOCTTY) &&
142 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
143 struct filedesc *fdp = p->p_fd;
144 struct file *fp = fdp->fd_ofiles[args->sysmsg_result];
146 if (fp->f_type == DTYPE_VNODE)
147 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td);
151 printf(LMSG("open returns error %d"), error);
153 linux_free_path(&path);
158 linux_lseek(struct linux_lseek_args *args)
164 printf(ARGS(lseek, "%d, %ld, %d"),
165 args->fdes, (long)args->off, args->whence);
167 error = kern_lseek(args->fdes, args->off, args->whence,
168 &args->sysmsg_offset);
175 linux_llseek(struct linux_llseek_args *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 error = kern_lseek(args->fd, off, args->whence, &res);
190 error = copyout(&res, args->res, sizeof(res));
193 #endif /*!__alpha__*/
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;
210 #endif /*!__alpha__*/
213 * Note that linux_getdents(2) and linux_getdents64(2) have the same
214 * arguments. They only differ in the definition of struct dirent they
215 * operate on. We use this to common the code, with the exception of
216 * accessing struct dirent. Note that linux_readdir(2) is implemented
217 * by means of linux_getdents(2). In this case we never operate on
218 * struct dirent64 and thus don't need to handle it...
225 char d_name[LINUX_NAME_MAX + 1];
233 char d_name[LINUX_NAME_MAX + 1];
236 #define LINUX_RECLEN(de,namlen) \
237 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
239 #define LINUX_DIRBLKSIZ 512
242 getdents_common(struct linux_getdents64_args *args, int is64bit)
244 struct thread *td = curthread;
245 struct proc *p = td->td_proc;
248 caddr_t inp, buf; /* BSD-format */
249 int len, reclen; /* BSD-format */
250 caddr_t outp; /* Linux-format */
251 int resid, linuxreclen=0; /* Linux-format */
257 struct l_dirent linux_dirent;
258 struct l_dirent64 linux_dirent64;
259 int buflen, error, eofflag, nbytes, justone;
260 u_long *cookies = NULL, *cookiep;
265 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0)
268 if ((fp->f_flag & FREAD) == 0)
271 vp = (struct vnode *) fp->f_data;
272 if (vp->v_type != VDIR)
275 if ((error = VOP_GETATTR(vp, &va, td)))
278 nbytes = args->count;
280 /* readdir(2) case. Always struct dirent. */
283 nbytes = sizeof(linux_dirent);
290 buflen = max(LINUX_DIRBLKSIZ, nbytes);
291 buflen = min(buflen, MAXBSIZE);
292 buf = malloc(buflen, M_TEMP, M_WAITOK);
293 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
297 aiov.iov_len = buflen;
298 auio.uio_iov = &aiov;
300 auio.uio_rw = UIO_READ;
301 auio.uio_segflg = UIO_SYSSPACE;
303 auio.uio_resid = buflen;
304 auio.uio_offset = off;
307 free(cookies, M_TEMP);
311 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
316 outp = (caddr_t)args->dirent;
318 if ((len = buflen - auio.uio_resid) <= 0)
325 * When using cookies, the vfs has the option of reading from
326 * a different offset than that supplied (UFS truncates the
327 * offset to a block boundary to make sure that it never reads
328 * partway through a directory entry, even if the directory
329 * has been compacted).
331 while (len > 0 && ncookies > 0 && *cookiep <= off) {
332 bdp = (struct dirent *) inp;
333 len -= bdp->d_reclen;
334 inp += bdp->d_reclen;
341 if (cookiep && ncookies == 0)
343 bdp = (struct dirent *) inp;
344 reclen = bdp->d_reclen;
350 if (bdp->d_fileno == 0) {
362 linuxreclen = (is64bit)
363 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
364 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
366 if (reclen > len || resid < linuxreclen) {
372 /* readdir(2) case. */
373 linux_dirent.d_ino = (l_long)bdp->d_fileno;
374 linux_dirent.d_off = (l_off_t)linuxreclen;
375 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
376 strcpy(linux_dirent.d_name, bdp->d_name);
377 error = copyout(&linux_dirent, outp, linuxreclen);
380 linux_dirent64.d_ino = bdp->d_fileno;
381 linux_dirent64.d_off = (cookiep)
383 : (l_off_t)(off + reclen);
384 linux_dirent64.d_reclen =
385 (l_ushort)linuxreclen;
386 linux_dirent64.d_type = bdp->d_type;
387 strcpy(linux_dirent64.d_name, bdp->d_name);
388 error = copyout(&linux_dirent64, outp,
391 linux_dirent.d_ino = bdp->d_fileno;
392 linux_dirent.d_off = (cookiep)
394 : (l_off_t)(off + reclen);
395 linux_dirent.d_reclen = (l_ushort)linuxreclen;
396 strcpy(linux_dirent.d_name, bdp->d_name);
397 error = copyout(&linux_dirent, outp,
412 resid -= linuxreclen;
418 if (outp == (caddr_t)args->dirent)
423 nbytes = resid + linuxreclen;
426 args->sysmsg_result = nbytes - resid;
430 free(cookies, M_TEMP);
432 VOP_UNLOCK(vp, 0, td);
438 linux_getdents(struct linux_getdents_args *args)
441 if (ldebug(getdents))
442 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
444 return (getdents_common((struct linux_getdents64_args*)args, 0));
448 linux_getdents64(struct linux_getdents64_args *args)
451 if (ldebug(getdents64))
452 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
454 return (getdents_common(args, 1));
458 * These exist mainly for hooks for doing /compat/linux translation.
462 linux_access(struct linux_access_args *args)
464 struct thread *td = curthread;
469 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
474 printf(ARGS(access, "%s, %d"), path, args->flags);
476 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW | CNP_LOCKLEAF | CNP_NOOBJ,
477 UIO_SYSSPACE, path, td);
479 error = kern_access(&nd, args->flags);
481 linux_free_path(&path);
486 linux_unlink(struct linux_unlink_args *args)
488 struct thread *td = curthread;
493 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
498 printf(ARGS(unlink, "%s"), path);
500 NDINIT(&nd, NAMEI_DELETE, CNP_LOCKPARENT, UIO_SYSSPACE, path, td);
502 error = kern_unlink(&nd);
504 linux_free_path(&path);
509 linux_chdir(struct linux_chdir_args *args)
511 struct thread *td = curthread;
516 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
521 printf(ARGS(chdir, "%s"), path);
523 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW | CNP_LOCKLEAF, UIO_SYSSPACE,
526 error = kern_chdir(&nd);
528 linux_free_path(&path);
533 linux_chmod(struct linux_chmod_args *args)
535 struct thread *td = curthread;
540 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
545 printf(ARGS(chmod, "%s, %d"), path, args->mode);
547 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td);
549 error = kern_chmod(&nd, args->mode);
551 linux_free_path(&path);
556 linux_mkdir(struct linux_mkdir_args *args)
558 struct thread *td = curthread;
563 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
568 printf(ARGS(mkdir, "%s, %d"), path, args->mode);
570 NDINIT(&nd, NAMEI_CREATE, CNP_LOCKPARENT, UIO_SYSSPACE, path, td);
572 error = kern_mkdir(&nd, args->mode);
574 linux_free_path(&path);
579 linux_rmdir(struct linux_rmdir_args *args)
581 struct thread *td = curthread;
586 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
591 printf(ARGS(rmdir, "%s"), path);
593 NDINIT(&nd, NAMEI_DELETE, CNP_LOCKPARENT | CNP_LOCKLEAF,
594 UIO_SYSSPACE, path, td);
596 error = kern_rmdir(&nd);
598 linux_free_path(&path);
603 linux_rename(struct linux_rename_args *args)
605 struct thread *td = curthread;
606 struct nameidata 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"), args->from, args->to);
622 NDINIT(&fromnd, NAMEI_DELETE, CNP_WANTPARENT | CNP_SAVESTART,
623 UIO_SYSSPACE, from, td);
624 NDINIT(&tond, NAMEI_RENAME,
625 CNP_LOCKPARENT | CNP_LOCKLEAF | CNP_NOCACHE |
626 CNP_SAVESTART | CNP_NOOBJ,
627 UIO_SYSSPACE, to, td);
629 error = kern_rename(&fromnd, &tond);
631 linux_free_path(&from);
632 linux_free_path(&to);
637 linux_symlink(struct linux_symlink_args *args)
639 struct thread *td = curthread;
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 NDINIT(&nd, NAMEI_CREATE, CNP_LOCKPARENT | CNP_NOOBJ, UIO_SYSSPACE,
659 error = kern_symlink(path, &nd);
661 linux_free_path(&path);
662 linux_free_path(&link);
667 linux_readlink(struct linux_readlink_args *args)
669 struct thread *td = curthread;
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 NDINIT(&nd, NAMEI_LOOKUP, CNP_LOCKLEAF | CNP_NOOBJ, UIO_SYSSPACE,
685 error = kern_readlink(&nd, args->buf, args->count,
686 &args->sysmsg_result);
688 linux_free_path(&path);
693 linux_truncate(struct linux_truncate_args *args)
695 struct thread *td = curthread;
700 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
704 if (ldebug(truncate))
705 printf(ARGS(truncate, "%s, %ld"), args->path,
708 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td);
710 error = kern_truncate(&nd, args->length);
712 linux_free_path(&path);
717 linux_ftruncate(struct linux_ftruncate_args *args)
722 if (ldebug(ftruncate))
723 printf(ARGS(ftruncate, "%d, %ld"), args->fd,
726 error = kern_ftruncate(args->fd, args->length);
732 linux_link(struct linux_link_args *args)
734 struct thread *td = curthread;
735 struct nameidata nd, linknd;
739 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
742 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
744 linux_free_path(&path);
749 printf(ARGS(link, "%s, %s"), path, link);
751 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW | CNP_NOOBJ, UIO_SYSSPACE,
753 NDINIT(&linknd, NAMEI_CREATE, CNP_LOCKPARENT | CNP_NOOBJ,
754 UIO_SYSSPACE, link, td);
756 error = kern_link(&nd, &linknd);
758 linux_free_path(&path);
759 linux_free_path(&link);
765 linux_fdatasync(struct linux_fdatasync_args *uap)
767 struct fsync_args bsd;
771 bsd.sysmsg_result = 0;
774 uap->sysmsg_result = bsd.sysmsg_result;
777 #endif /*!__alpha__*/
780 linux_pread(struct linux_pread_args *uap)
782 struct thread *td = curthread;
787 aiov.iov_base = uap->buf;
788 aiov.iov_len = uap->nbyte;
789 auio.uio_iov = &aiov;
791 auio.uio_offset = uap->offset;
792 auio.uio_resid = uap->nbyte;
793 auio.uio_rw = UIO_READ;
794 auio.uio_segflg = UIO_USERSPACE;
797 error = kern_readv(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
803 linux_pwrite(struct linux_pwrite_args *uap)
805 struct thread *td = curthread;
810 aiov.iov_base = uap->buf;
811 aiov.iov_len = uap->nbyte;
812 auio.uio_iov = &aiov;
814 auio.uio_offset = uap->offset;
815 auio.uio_resid = uap->nbyte;
816 auio.uio_rw = UIO_WRITE;
817 auio.uio_segflg = UIO_USERSPACE;
820 error = kern_writev(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
826 linux_oldumount(struct linux_oldumount_args *args)
828 struct linux_umount_args args2;
831 args2.path = args->path;
833 args2.sysmsg_result = 0;
834 error = linux_umount(&args2);
835 args->sysmsg_result = args2.sysmsg_result;
840 linux_umount(struct linux_umount_args *args)
842 struct unmount_args bsd;
845 bsd.path = args->path;
846 bsd.flags = args->flags; /* XXX correct? */
847 bsd.sysmsg_result = 0;
849 error = unmount(&bsd);
850 args->sysmsg_result = bsd.sysmsg_result;
855 * fcntl family of syscalls
867 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
869 switch (linux_flock->l_type) {
871 bsd_flock->l_type = F_RDLCK;
874 bsd_flock->l_type = F_WRLCK;
877 bsd_flock->l_type = F_UNLCK;
880 bsd_flock->l_type = -1;
883 bsd_flock->l_whence = linux_flock->l_whence;
884 bsd_flock->l_start = (off_t)linux_flock->l_start;
885 bsd_flock->l_len = (off_t)linux_flock->l_len;
886 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
890 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
892 switch (bsd_flock->l_type) {
894 linux_flock->l_type = LINUX_F_RDLCK;
897 linux_flock->l_type = LINUX_F_WRLCK;
900 linux_flock->l_type = LINUX_F_UNLCK;
903 linux_flock->l_whence = bsd_flock->l_whence;
904 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
905 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
906 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
909 #if defined(__i386__)
919 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
921 switch (linux_flock->l_type) {
923 bsd_flock->l_type = F_RDLCK;
926 bsd_flock->l_type = F_WRLCK;
929 bsd_flock->l_type = F_UNLCK;
932 bsd_flock->l_type = -1;
935 bsd_flock->l_whence = linux_flock->l_whence;
936 bsd_flock->l_start = (off_t)linux_flock->l_start;
937 bsd_flock->l_len = (off_t)linux_flock->l_len;
938 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
942 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
944 switch (bsd_flock->l_type) {
946 linux_flock->l_type = LINUX_F_RDLCK;
949 linux_flock->l_type = LINUX_F_WRLCK;
952 linux_flock->l_type = LINUX_F_UNLCK;
955 linux_flock->l_whence = bsd_flock->l_whence;
956 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
957 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
958 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
960 #endif /* __i386__ */
962 #if defined(__alpha__)
963 #define linux_fcntl64_args linux_fcntl_args
967 linux_fcntl_common(struct linux_fcntl64_args *args)
969 struct proc *p = curproc;
970 struct l_flock linux_flock;
971 struct filedesc *fdp;
979 dat.fc_fd = args->arg;
986 dat.fc_cloexec = args->arg;
994 if (args->arg & LINUX_O_NDELAY)
995 dat.fc_flags |= O_NONBLOCK;
996 if (args->arg & LINUX_O_APPEND)
997 dat.fc_flags |= O_APPEND;
998 if (args->arg & LINUX_O_SYNC)
999 dat.fc_flags |= O_FSYNC;
1000 if (args->arg & LINUX_FASYNC)
1001 dat.fc_flags |= O_ASYNC;
1005 case LINUX_F_SETLKW:
1007 error = copyin((caddr_t)args->arg, &linux_flock,
1008 sizeof(linux_flock));
1011 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
1013 case LINUX_F_GETOWN:
1016 case LINUX_F_SETOWN:
1018 * XXX some Linux applications depend on F_SETOWN having no
1019 * significant effect for pipes (SIGIO is not delivered for
1020 * pipes under Linux-2.2.35 at least).
1023 if ((u_int)args->fd >= fdp->fd_nfiles ||
1024 (fp = fdp->fd_ofiles[args->fd]) == NULL)
1026 if (fp->f_type == DTYPE_PIPE)
1029 dat.fc_owner = args->arg;
1035 error = kern_fcntl(args->fd, cmd, &dat);
1038 switch (args->cmd) {
1040 args->sysmsg_result = dat.fc_fd;
1043 args->sysmsg_result = dat.fc_cloexec;
1048 args->sysmsg_result = 0;
1049 if (dat.fc_flags & O_RDONLY)
1050 args->sysmsg_result |= LINUX_O_RDONLY;
1051 if (dat.fc_flags & O_WRONLY)
1052 args->sysmsg_result |= LINUX_O_WRONLY;
1053 if (dat.fc_flags & O_RDWR)
1054 args->sysmsg_result |= LINUX_O_RDWR;
1055 if (dat.fc_flags & O_NDELAY)
1056 args->sysmsg_result |= LINUX_O_NONBLOCK;
1057 if (dat.fc_flags & O_APPEND)
1058 args->sysmsg_result |= LINUX_O_APPEND;
1059 if (dat.fc_flags & O_FSYNC)
1060 args->sysmsg_result |= LINUX_O_SYNC;
1061 if (dat.fc_flags & O_ASYNC)
1062 args->sysmsg_result |= LINUX_FASYNC;
1065 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1066 error = copyout(&linux_flock, (caddr_t)args->arg,
1067 sizeof(linux_flock));
1070 case LINUX_F_SETLKW:
1072 case LINUX_F_GETOWN:
1073 args->sysmsg_result = dat.fc_owner;
1075 case LINUX_F_SETOWN:
1084 linux_fcntl(struct linux_fcntl_args *args)
1086 struct linux_fcntl64_args args64;
1091 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1094 args64.fd = args->fd;
1095 args64.cmd = args->cmd;
1096 args64.arg = args->arg;
1097 args64.sysmsg_result = 0;
1098 error = linux_fcntl_common(&args64);
1099 args->sysmsg_result = args64.sysmsg_result;
1103 #if defined(__i386__)
1105 linux_fcntl64(struct linux_fcntl64_args *args)
1107 struct l_flock64 linux_flock;
1108 union fcntl_dat dat;
1112 if (ldebug(fcntl64))
1113 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1115 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1116 args->cmd == LINUX_F_SETLKW64) {
1117 switch (args->cmd) {
1118 case LINUX_F_GETLK64:
1121 case LINUX_F_SETLK64:
1124 case LINUX_F_SETLKW64:
1129 error = copyin((caddr_t)args->arg, &linux_flock,
1130 sizeof(linux_flock));
1133 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1135 error = kern_fcntl(args->fd, cmd, &dat);
1137 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1138 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1139 error = copyout(&linux_flock, (caddr_t)args->arg,
1140 sizeof(linux_flock));
1143 error = linux_fcntl_common(args);
1148 #endif /* __i386__ */
1151 linux_chown(struct linux_chown_args *args)
1153 struct thread *td = curthread;
1154 struct nameidata nd;
1158 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1163 printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1165 NDINIT(&nd, NAMEI_LOOKUP, CNP_FOLLOW, UIO_SYSSPACE, path, td);
1167 error = kern_chown(&nd, args->uid, args->gid);
1169 linux_free_path(&path);
1174 linux_lchown(struct linux_lchown_args *args)
1176 struct thread *td = curthread;
1177 struct nameidata nd;
1181 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1186 printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1188 NDINIT(&nd, NAMEI_LOOKUP, 0, UIO_SYSSPACE, path, td);
1190 error = kern_chown(&nd, args->uid, args->gid);
1192 linux_free_path(&path);