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.29 2006/05/19 07:33:43 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 = getvnode(p->p_fd, args->fd, &fp)) != 0)
267 if ((fp->f_flag & FREAD) == 0)
270 vp = (struct vnode *) fp->f_data;
271 if (vp->v_type != VDIR)
274 if ((error = VOP_GETATTR(vp, &va)))
277 nbytes = args->count;
279 /* readdir(2) case. Always struct dirent. */
282 nbytes = sizeof(linux_dirent);
289 buflen = max(LINUX_DIRBLKSIZ, nbytes);
290 buflen = min(buflen, MAXBSIZE);
291 buf = malloc(buflen, M_TEMP, M_WAITOK);
292 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
296 aiov.iov_len = buflen;
297 auio.uio_iov = &aiov;
299 auio.uio_rw = UIO_READ;
300 auio.uio_segflg = UIO_SYSSPACE;
302 auio.uio_resid = buflen;
303 auio.uio_offset = off;
306 free(cookies, M_TEMP);
310 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
315 outp = (caddr_t)args->dirent;
317 if ((len = buflen - auio.uio_resid) <= 0)
324 * When using cookies, the vfs has the option of reading from
325 * a different offset than that supplied (UFS truncates the
326 * offset to a block boundary to make sure that it never reads
327 * partway through a directory entry, even if the directory
328 * has been compacted).
330 while (len > 0 && ncookies > 0 && *cookiep <= off) {
331 bdp = (struct dirent *) inp;
332 len -= _DIRENT_DIRSIZ(bdp);
333 inp += _DIRENT_DIRSIZ(bdp);
340 if (cookiep && ncookies == 0)
342 bdp = (struct dirent *) inp;
343 reclen = _DIRENT_DIRSIZ(bdp);
349 if (bdp->d_ino == 0) {
361 linuxreclen = (is64bit)
362 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
363 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
365 if (reclen > len || resid < linuxreclen) {
371 /* readdir(2) case. */
372 linux_dirent.d_ino = (l_long)bdp->d_ino;
373 linux_dirent.d_off = (l_off_t)linuxreclen;
374 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
375 strcpy(linux_dirent.d_name, bdp->d_name);
376 error = copyout(&linux_dirent, outp, linuxreclen);
379 linux_dirent64.d_ino = bdp->d_ino;
380 linux_dirent64.d_off = (cookiep)
382 : (l_off_t)(off + reclen);
383 linux_dirent64.d_reclen =
384 (l_ushort)linuxreclen;
385 linux_dirent64.d_type = bdp->d_type;
386 strcpy(linux_dirent64.d_name, bdp->d_name);
387 error = copyout(&linux_dirent64, outp,
390 linux_dirent.d_ino = bdp->d_ino;
391 linux_dirent.d_off = (cookiep)
393 : (l_off_t)(off + reclen);
394 linux_dirent.d_reclen = (l_ushort)linuxreclen;
395 strcpy(linux_dirent.d_name, bdp->d_name);
396 error = copyout(&linux_dirent, outp,
411 resid -= linuxreclen;
417 if (outp == (caddr_t)args->dirent)
422 nbytes = resid + linuxreclen;
425 args->sysmsg_result = nbytes - resid;
429 free(cookies, M_TEMP);
437 linux_getdents(struct linux_getdents_args *args)
440 if (ldebug(getdents))
441 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
443 return (getdents_common((struct linux_getdents64_args*)args, 0));
447 linux_getdents64(struct linux_getdents64_args *args)
450 if (ldebug(getdents64))
451 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
453 return (getdents_common(args, 1));
457 * These exist mainly for hooks for doing /compat/linux translation.
461 linux_access(struct linux_access_args *args)
463 struct nlookupdata nd;
467 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
472 printf(ARGS(access, "%s, %d"), path, args->flags);
474 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
476 error = kern_access(&nd, args->flags);
478 linux_free_path(&path);
483 linux_unlink(struct linux_unlink_args *args)
485 struct nlookupdata nd;
489 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
494 printf(ARGS(unlink, "%s"), path);
496 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
498 error = kern_unlink(&nd);
500 linux_free_path(&path);
505 linux_chdir(struct linux_chdir_args *args)
507 struct nlookupdata nd;
511 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
516 printf(ARGS(chdir, "%s"), path);
518 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
520 error = kern_chdir(&nd);
523 linux_free_path(&path);
528 linux_chmod(struct linux_chmod_args *args)
530 struct nlookupdata nd;
534 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
539 printf(ARGS(chmod, "%s, %d"), path, args->mode);
541 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
543 error = kern_chmod(&nd, args->mode);
545 linux_free_path(&path);
550 linux_mkdir(struct linux_mkdir_args *args)
552 struct nlookupdata nd;
556 error = linux_copyin_path(args->path, &path, LINUX_PATH_CREATE);
561 printf(ARGS(mkdir, "%s, %d"), path, args->mode);
563 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
565 error = kern_mkdir(&nd, args->mode);
568 linux_free_path(&path);
573 linux_rmdir(struct linux_rmdir_args *args)
575 struct nlookupdata nd;
579 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
584 printf(ARGS(rmdir, "%s"), path);
586 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
588 error = kern_rmdir(&nd);
590 linux_free_path(&path);
595 linux_rename(struct linux_rename_args *args)
597 struct nlookupdata fromnd, tond;
601 error = linux_copyin_path(args->from, &from, LINUX_PATH_EXISTS);
604 error = linux_copyin_path(args->to, &to, LINUX_PATH_CREATE);
606 linux_free_path(&from);
611 printf(ARGS(rename, "%s, %s"), from, to);
613 error = nlookup_init(&fromnd, from, UIO_SYSSPACE, 0);
615 error = nlookup_init(&tond, to, UIO_SYSSPACE, 0);
617 error = kern_rename(&fromnd, &tond);
620 nlookup_done(&fromnd);
621 linux_free_path(&from);
622 linux_free_path(&to);
627 linux_symlink(struct linux_symlink_args *args)
629 struct thread *td = curthread;
630 struct nlookupdata nd;
635 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
638 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
640 linux_free_path(&path);
645 printf(ARGS(symlink, "%s, %s"), path, link);
647 error = nlookup_init(&nd, link, UIO_SYSSPACE, 0);
649 mode = ACCESSPERMS & ~td->td_proc->p_fd->fd_cmask;
650 error = kern_symlink(&nd, path, mode);
653 linux_free_path(&path);
654 linux_free_path(&link);
659 linux_readlink(struct linux_readlink_args *args)
661 struct nlookupdata nd;
665 error = linux_copyin_path(args->name, &path, LINUX_PATH_EXISTS);
669 if (ldebug(readlink))
670 printf(ARGS(readlink, "%s, %p, %d"), path, (void *)args->buf,
673 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
675 error = kern_readlink(&nd, args->buf, args->count,
676 &args->sysmsg_result);
679 linux_free_path(&path);
684 linux_truncate(struct linux_truncate_args *args)
686 struct nlookupdata nd;
690 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
694 if (ldebug(truncate))
695 printf(ARGS(truncate, "%s, %ld"), path,
698 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
700 error = kern_truncate(&nd, args->length);
702 linux_free_path(&path);
707 linux_truncate64(struct linux_truncate64_args *args)
709 struct nlookupdata nd;
713 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
717 if (ldebug(truncate64))
718 printf(ARGS(truncate64, "%s, %lld"), path,
719 (off_t)args->length);
721 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
723 error = kern_truncate(&nd, args->length);
725 linux_free_path(&path);
730 linux_ftruncate(struct linux_ftruncate_args *args)
735 if (ldebug(ftruncate))
736 printf(ARGS(ftruncate, "%d, %ld"), args->fd,
739 error = kern_ftruncate(args->fd, args->length);
745 linux_ftruncate64(struct linux_ftruncate64_args *args)
750 if (ldebug(ftruncate))
751 printf(ARGS(ftruncate64, "%d, %lld"), args->fd,
752 (off_t)args->length);
754 error = kern_ftruncate(args->fd, args->length);
760 linux_link(struct linux_link_args *args)
762 struct nlookupdata nd, linknd;
766 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
769 error = linux_copyin_path(args->to, &link, LINUX_PATH_CREATE);
771 linux_free_path(&path);
776 printf(ARGS(link, "%s, %s"), path, link);
778 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
780 error = nlookup_init(&linknd, link, UIO_SYSSPACE, 0);
782 error = kern_link(&nd, &linknd);
783 nlookup_done(&linknd);
786 linux_free_path(&path);
787 linux_free_path(&link);
792 linux_fdatasync(struct linux_fdatasync_args *uap)
794 struct fsync_args bsd;
798 bsd.sysmsg_result = 0;
801 uap->sysmsg_result = bsd.sysmsg_result;
806 linux_pread(struct linux_pread_args *uap)
808 struct thread *td = curthread;
813 aiov.iov_base = uap->buf;
814 aiov.iov_len = uap->nbyte;
815 auio.uio_iov = &aiov;
817 auio.uio_offset = uap->offset;
818 auio.uio_resid = uap->nbyte;
819 auio.uio_rw = UIO_READ;
820 auio.uio_segflg = UIO_USERSPACE;
823 if (auio.uio_resid < 0)
826 error = kern_preadv(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
831 linux_pwrite(struct linux_pwrite_args *uap)
833 struct thread *td = curthread;
838 aiov.iov_base = uap->buf;
839 aiov.iov_len = uap->nbyte;
840 auio.uio_iov = &aiov;
842 auio.uio_offset = uap->offset;
843 auio.uio_resid = uap->nbyte;
844 auio.uio_rw = UIO_WRITE;
845 auio.uio_segflg = UIO_USERSPACE;
848 if (auio.uio_resid < 0)
851 error = kern_pwritev(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__ */
994 linux_fcntl_common(struct linux_fcntl64_args *args)
996 struct proc *p = curproc;
997 struct l_flock linux_flock;
1002 switch (args->cmd) {
1005 dat.fc_fd = args->arg;
1012 dat.fc_cloexec = args->arg;
1020 if (args->arg & LINUX_O_NDELAY)
1021 dat.fc_flags |= O_NONBLOCK;
1022 if (args->arg & LINUX_O_APPEND)
1023 dat.fc_flags |= O_APPEND;
1024 if (args->arg & LINUX_O_SYNC)
1025 dat.fc_flags |= O_FSYNC;
1026 if (args->arg & LINUX_FASYNC)
1027 dat.fc_flags |= O_ASYNC;
1031 case LINUX_F_SETLKW:
1033 error = copyin((caddr_t)args->arg, &linux_flock,
1034 sizeof(linux_flock));
1037 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
1039 case LINUX_F_GETOWN:
1042 case LINUX_F_SETOWN:
1044 * XXX some Linux applications depend on F_SETOWN having no
1045 * significant effect for pipes (SIGIO is not delivered for
1046 * pipes under Linux-2.2.35 at least).
1048 fp = holdfp(p->p_fd, args->fd, -1);
1051 if (fp->f_type == DTYPE_PIPE) {
1057 dat.fc_owner = args->arg;
1063 error = kern_fcntl(args->fd, cmd, &dat, p->p_ucred);
1066 switch (args->cmd) {
1068 args->sysmsg_result = dat.fc_fd;
1071 args->sysmsg_result = dat.fc_cloexec;
1076 args->sysmsg_result = 0;
1077 if (dat.fc_flags & O_RDONLY)
1078 args->sysmsg_result |= LINUX_O_RDONLY;
1079 if (dat.fc_flags & O_WRONLY)
1080 args->sysmsg_result |= LINUX_O_WRONLY;
1081 if (dat.fc_flags & O_RDWR)
1082 args->sysmsg_result |= LINUX_O_RDWR;
1083 if (dat.fc_flags & O_NDELAY)
1084 args->sysmsg_result |= LINUX_O_NONBLOCK;
1085 if (dat.fc_flags & O_APPEND)
1086 args->sysmsg_result |= LINUX_O_APPEND;
1087 if (dat.fc_flags & O_FSYNC)
1088 args->sysmsg_result |= LINUX_O_SYNC;
1089 if (dat.fc_flags & O_ASYNC)
1090 args->sysmsg_result |= LINUX_FASYNC;
1093 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1094 error = copyout(&linux_flock, (caddr_t)args->arg,
1095 sizeof(linux_flock));
1098 case LINUX_F_SETLKW:
1100 case LINUX_F_GETOWN:
1101 args->sysmsg_result = dat.fc_owner;
1103 case LINUX_F_SETOWN:
1112 linux_fcntl(struct linux_fcntl_args *args)
1114 struct linux_fcntl64_args args64;
1119 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1122 args64.fd = args->fd;
1123 args64.cmd = args->cmd;
1124 args64.arg = args->arg;
1125 args64.sysmsg_result = 0;
1126 error = linux_fcntl_common(&args64);
1127 args->sysmsg_result = args64.sysmsg_result;
1131 #if defined(__i386__)
1133 linux_fcntl64(struct linux_fcntl64_args *args)
1135 struct l_flock64 linux_flock;
1136 union fcntl_dat dat;
1140 if (ldebug(fcntl64))
1141 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1143 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1144 args->cmd == LINUX_F_SETLKW64) {
1145 switch (args->cmd) {
1146 case LINUX_F_GETLK64:
1149 case LINUX_F_SETLK64:
1152 case LINUX_F_SETLKW64:
1157 error = copyin((caddr_t)args->arg, &linux_flock,
1158 sizeof(linux_flock));
1161 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1163 error = kern_fcntl(args->fd, cmd, &dat, curproc->p_ucred);
1165 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1166 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1167 error = copyout(&linux_flock, (caddr_t)args->arg,
1168 sizeof(linux_flock));
1171 error = linux_fcntl_common(args);
1176 #endif /* __i386__ */
1179 linux_chown(struct linux_chown_args *args)
1181 struct nlookupdata nd;
1185 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1190 printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
1192 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW);
1194 error = kern_chown(&nd, args->uid, args->gid);
1196 linux_free_path(&path);
1201 linux_lchown(struct linux_lchown_args *args)
1203 struct nlookupdata nd;
1207 error = linux_copyin_path(args->path, &path, LINUX_PATH_EXISTS);
1212 printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
1214 error = nlookup_init(&nd, path, UIO_SYSSPACE, 0);
1216 error = kern_chown(&nd, args->uid, args->gid);
1218 linux_free_path(&path);