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>
57 #include <arch_linux/linux.h>
58 #include <arch_linux/linux_proto.h>
59 #include "linux_util.h"
62 sys_linux_creat(struct linux_creat_args
*args
)
64 struct nlookupdata nd
;
68 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_CREATE
);
73 kprintf(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_iresult
);
80 linux_free_path(&path
);
85 sys_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 kprintf(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_iresult
);
141 if (error
== 0 && !(flags
& O_NOCTTY
) &&
142 SESS_LEADER(p
) && !(p
->p_flag
& P_CONTROLT
)) {
145 fp
= holdfp(p
->p_fd
, args
->sysmsg_iresult
, -1);
147 if (fp
->f_type
== DTYPE_VNODE
)
148 fo_ioctl(fp
, TIOCSCTTY
, NULL
, p
->p_ucred
, NULL
);
154 kprintf(LMSG("open returns error %d"), error
);
156 linux_free_path(&path
);
161 sys_linux_lseek(struct linux_lseek_args
*args
)
167 kprintf(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 sys_linux_llseek(struct linux_llseek_args
*args
)
184 kprintf(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 sys_linux_readdir(struct linux_readdir_args
*args
)
199 struct linux_getdents_args lda
;
203 lda
.dent
= args
->dent
;
205 lda
.sysmsg_iresult
= 0;
206 error
= sys_linux_getdents(&lda
);
207 args
->sysmsg_iresult
= lda
.sysmsg_iresult
;
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 reclen
; /* BSD-format */
250 caddr_t outp
; /* Linux-format */
251 int linuxreclen
= 0; /* Linux-format */
258 struct l_dirent linux_dirent
;
259 struct l_dirent64 linux_dirent64
;
260 int error
, eofflag
, justone
;
261 size_t buflen
, nbytes
;
262 off_t
*cookies
= NULL
, *cookiep
;
267 if ((error
= holdvnode(p
->p_fd
, args
->fd
, &fp
)) != 0)
270 if ((fp
->f_flag
& FREAD
) == 0) {
275 vp
= (struct vnode
*) fp
->f_data
;
276 if (vp
->v_type
!= VDIR
) {
281 if ((error
= VOP_GETATTR(vp
, &va
)) != 0)
284 nbytes
= args
->count
;
285 if (nbytes
== (size_t)-1) {
286 /* readdir(2) case. Always struct dirent. */
291 nbytes
= sizeof(linux_dirent
);
296 if ((size_t)nbytes
< 0)
301 buflen
= max(LINUX_DIRBLKSIZ
, nbytes
);
302 buflen
= min(buflen
, MAXBSIZE
);
303 buf
= kmalloc(buflen
, M_TEMP
, M_WAITOK
);
307 aiov
.iov_len
= buflen
;
308 auio
.uio_iov
= &aiov
;
310 auio
.uio_rw
= UIO_READ
;
311 auio
.uio_segflg
= UIO_SYSSPACE
;
313 auio
.uio_resid
= buflen
;
314 auio
.uio_offset
= off
;
317 kfree(cookies
, M_TEMP
);
323 if ((error
= VOP_READDIR(vp
, &auio
, fp
->f_cred
, &eofflag
, &ncookies
,
328 outp
= (caddr_t
)args
->dirent
;
330 if (auio
.uio_resid
>= buflen
)
332 len
= buflen
- auio
.uio_resid
;
337 * When using cookies, the vfs has the option of reading from
338 * a different offset than that supplied (UFS truncates the
339 * offset to a block boundary to make sure that it never reads
340 * partway through a directory entry, even if the directory
341 * has been compacted).
343 while (len
> 0 && ncookies
> 0 && *cookiep
< off
) {
344 bdp
= (struct dirent
*) inp
;
345 len
-= _DIRENT_DIRSIZ(bdp
);
346 inp
+= _DIRENT_DIRSIZ(bdp
);
353 if (cookiep
&& ncookies
== 0)
355 bdp
= (struct dirent
*) inp
;
356 reclen
= _DIRENT_DIRSIZ(bdp
);
362 if (bdp
->d_ino
== 0) {
375 linuxreclen
= (is64bit
)
376 ? LINUX_RECLEN(&linux_dirent64
, bdp
->d_namlen
)
377 : LINUX_RECLEN(&linux_dirent
, bdp
->d_namlen
);
379 if (reclen
> len
|| resid
< linuxreclen
) {
384 bzero(&linux_dirent
, sizeof(linux_dirent
));
385 bzero(&linux_dirent64
, sizeof(linux_dirent64
));
387 /* readdir(2) case. */
388 linux_dirent
.d_ino
= (l_long
)INO64TO32(bdp
->d_ino
);
389 linux_dirent
.d_off
= (l_off_t
)linuxreclen
;
390 linux_dirent
.d_reclen
= (l_ushort
)bdp
->d_namlen
;
391 strcpy(linux_dirent
.d_name
, bdp
->d_name
);
392 error
= copyout(&linux_dirent
, outp
, linuxreclen
);
395 linux_dirent64
.d_ino
= bdp
->d_ino
;
396 linux_dirent64
.d_off
= (cookiep
)
398 : (l_off_t
)(off
+ reclen
);
399 linux_dirent64
.d_reclen
=
400 (l_ushort
)linuxreclen
;
401 linux_dirent64
.d_type
= bdp
->d_type
;
402 strcpy(linux_dirent64
.d_name
, bdp
->d_name
);
403 error
= copyout(&linux_dirent64
, outp
,
406 linux_dirent
.d_ino
= INO64TO32(bdp
->d_ino
);
407 linux_dirent
.d_off
= (cookiep
)
409 : (l_off_t
)(off
+ reclen
);
410 linux_dirent
.d_reclen
= (l_ushort
)linuxreclen
;
411 strcpy(linux_dirent
.d_name
, bdp
->d_name
);
412 error
= copyout(&linux_dirent
, outp
,
429 resid
-= linuxreclen
;
435 if (outp
== (caddr_t
)args
->dirent
&& eofflag
== 0)
440 nbytes
= resid
+ linuxreclen
;
443 args
->sysmsg_iresult
= (int)(nbytes
- resid
);
447 kfree(cookies
, M_TEMP
);
456 sys_linux_getdents(struct linux_getdents_args
*args
)
459 if (ldebug(getdents
))
460 kprintf(ARGS(getdents
, "%d, *, %d"), args
->fd
, args
->count
);
462 return (getdents_common((struct linux_getdents64_args
*)args
, 0));
466 sys_linux_getdents64(struct linux_getdents64_args
*args
)
469 if (ldebug(getdents64
))
470 kprintf(ARGS(getdents64
, "%d, *, %d"), args
->fd
, args
->count
);
472 return (getdents_common(args
, 1));
476 * These exist mainly for hooks for doing /compat/linux translation.
480 sys_linux_access(struct linux_access_args
*args
)
482 struct nlookupdata nd
;
486 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
491 kprintf(ARGS(access
, "%s, %d"), path
, args
->flags
);
493 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
495 error
= kern_access(&nd
, args
->flags
, 0);
497 linux_free_path(&path
);
502 sys_linux_unlink(struct linux_unlink_args
*args
)
504 struct nlookupdata nd
;
508 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
513 kprintf(ARGS(unlink
, "%s"), path
);
515 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
517 error
= kern_unlink(&nd
);
519 linux_free_path(&path
);
524 sys_linux_chdir(struct linux_chdir_args
*args
)
526 struct nlookupdata nd
;
530 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
535 kprintf(ARGS(chdir
, "%s"), path
);
537 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
539 error
= kern_chdir(&nd
);
542 linux_free_path(&path
);
547 sys_linux_chmod(struct linux_chmod_args
*args
)
549 struct nlookupdata nd
;
553 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
558 kprintf(ARGS(chmod
, "%s, %d"), path
, args
->mode
);
560 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
562 error
= kern_chmod(&nd
, args
->mode
);
564 linux_free_path(&path
);
569 sys_linux_mkdir(struct linux_mkdir_args
*args
)
571 struct nlookupdata nd
;
575 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_CREATE
);
580 kprintf(ARGS(mkdir
, "%s, %d"), path
, args
->mode
);
582 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
584 error
= kern_mkdir(&nd
, args
->mode
);
587 linux_free_path(&path
);
592 sys_linux_rmdir(struct linux_rmdir_args
*args
)
594 struct nlookupdata nd
;
598 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
603 kprintf(ARGS(rmdir
, "%s"), path
);
605 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
607 error
= kern_rmdir(&nd
);
609 linux_free_path(&path
);
614 sys_linux_rename(struct linux_rename_args
*args
)
616 struct nlookupdata fromnd
, tond
;
620 error
= linux_copyin_path(args
->from
, &from
, LINUX_PATH_EXISTS
);
623 error
= linux_copyin_path(args
->to
, &to
, LINUX_PATH_CREATE
);
625 linux_free_path(&from
);
630 kprintf(ARGS(rename
, "%s, %s"), from
, to
);
632 error
= nlookup_init(&fromnd
, from
, UIO_SYSSPACE
, 0);
634 error
= nlookup_init(&tond
, to
, UIO_SYSSPACE
, 0);
636 error
= kern_rename(&fromnd
, &tond
);
639 nlookup_done(&fromnd
);
640 linux_free_path(&from
);
641 linux_free_path(&to
);
646 sys_linux_symlink(struct linux_symlink_args
*args
)
648 struct thread
*td
= curthread
;
649 struct nlookupdata nd
;
654 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
657 error
= linux_copyin_path(args
->to
, &link
, LINUX_PATH_CREATE
);
659 linux_free_path(&path
);
664 kprintf(ARGS(symlink
, "%s, %s"), path
, link
);
666 error
= nlookup_init(&nd
, link
, UIO_SYSSPACE
, 0);
668 mode
= ACCESSPERMS
& ~td
->td_proc
->p_fd
->fd_cmask
;
669 error
= kern_symlink(&nd
, path
, mode
);
672 linux_free_path(&path
);
673 linux_free_path(&link
);
678 sys_linux_readlink(struct linux_readlink_args
*args
)
680 struct nlookupdata nd
;
684 error
= linux_copyin_path(args
->name
, &path
, LINUX_PATH_EXISTS
);
688 if (ldebug(readlink
))
689 kprintf(ARGS(readlink
, "%s, %p, %d"), path
, (void *)args
->buf
,
692 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
694 error
= kern_readlink(&nd
, args
->buf
, args
->count
,
695 &args
->sysmsg_iresult
);
698 linux_free_path(&path
);
703 sys_linux_truncate(struct linux_truncate_args
*args
)
705 struct nlookupdata nd
;
709 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
713 if (ldebug(truncate
))
714 kprintf(ARGS(truncate
, "%s, %ld"), path
,
717 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
719 error
= kern_truncate(&nd
, args
->length
);
721 linux_free_path(&path
);
726 sys_linux_truncate64(struct linux_truncate64_args
*args
)
728 struct nlookupdata nd
;
732 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
736 if (ldebug(truncate64
))
737 kprintf(ARGS(truncate64
, "%s, %lld"), path
,
738 (off_t
)args
->length
);
740 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
742 error
= kern_truncate(&nd
, args
->length
);
744 linux_free_path(&path
);
749 sys_linux_ftruncate(struct linux_ftruncate_args
*args
)
754 if (ldebug(ftruncate
))
755 kprintf(ARGS(ftruncate
, "%d, %ld"), args
->fd
,
758 error
= kern_ftruncate(args
->fd
, args
->length
);
764 sys_linux_ftruncate64(struct linux_ftruncate64_args
*args
)
769 if (ldebug(ftruncate
))
770 kprintf(ARGS(ftruncate64
, "%d, %lld"), args
->fd
,
771 (off_t
)args
->length
);
773 error
= kern_ftruncate(args
->fd
, args
->length
);
779 sys_linux_link(struct linux_link_args
*args
)
781 struct nlookupdata nd
, linknd
;
785 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
788 error
= linux_copyin_path(args
->to
, &link
, LINUX_PATH_CREATE
);
790 linux_free_path(&path
);
795 kprintf(ARGS(link
, "%s, %s"), path
, link
);
797 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
799 error
= nlookup_init(&linknd
, link
, UIO_SYSSPACE
, 0);
801 error
= kern_link(&nd
, &linknd
);
802 nlookup_done(&linknd
);
805 linux_free_path(&path
);
806 linux_free_path(&link
);
811 sys_linux_fdatasync(struct linux_fdatasync_args
*uap
)
813 struct fsync_args bsd
;
817 bsd
.sysmsg_iresult
= 0;
819 error
= sys_fsync(&bsd
);
820 uap
->sysmsg_iresult
= bsd
.sysmsg_iresult
;
825 sys_linux_pread(struct linux_pread_args
*uap
)
827 struct thread
*td
= curthread
;
832 aiov
.iov_base
= uap
->buf
;
833 aiov
.iov_len
= uap
->nbyte
;
834 auio
.uio_iov
= &aiov
;
836 auio
.uio_offset
= uap
->offset
;
837 auio
.uio_resid
= uap
->nbyte
;
838 auio
.uio_rw
= UIO_READ
;
839 auio
.uio_segflg
= UIO_USERSPACE
;
842 if ((ssize_t
)auio
.uio_resid
< 0) {
845 error
= kern_preadv(uap
->fd
, &auio
, O_FOFFSET
,
846 &uap
->sysmsg_szresult
);
852 sys_linux_pwrite(struct linux_pwrite_args
*uap
)
854 struct thread
*td
= curthread
;
859 aiov
.iov_base
= uap
->buf
;
860 aiov
.iov_len
= uap
->nbyte
;
861 auio
.uio_iov
= &aiov
;
863 auio
.uio_offset
= uap
->offset
;
864 auio
.uio_resid
= uap
->nbyte
;
865 auio
.uio_rw
= UIO_WRITE
;
866 auio
.uio_segflg
= UIO_USERSPACE
;
869 if ((ssize_t
)auio
.uio_resid
< 0) {
872 error
= kern_pwritev(uap
->fd
, &auio
, O_FOFFSET
,
873 &uap
->sysmsg_szresult
);
879 sys_linux_oldumount(struct linux_oldumount_args
*args
)
881 struct linux_umount_args args2
;
884 args2
.path
= args
->path
;
886 args2
.sysmsg_iresult
= 0;
887 error
= sys_linux_umount(&args2
);
888 args
->sysmsg_iresult
= args2
.sysmsg_iresult
;
893 sys_linux_umount(struct linux_umount_args
*args
)
895 struct unmount_args bsd
;
898 bsd
.path
= args
->path
;
899 bsd
.flags
= args
->flags
; /* XXX correct? */
900 bsd
.sysmsg_iresult
= 0;
902 error
= sys_unmount(&bsd
);
903 args
->sysmsg_iresult
= bsd
.sysmsg_iresult
;
908 * fcntl family of syscalls
920 linux_to_bsd_flock(struct l_flock
*linux_flock
, struct flock
*bsd_flock
)
922 switch (linux_flock
->l_type
) {
924 bsd_flock
->l_type
= F_RDLCK
;
927 bsd_flock
->l_type
= F_WRLCK
;
930 bsd_flock
->l_type
= F_UNLCK
;
933 bsd_flock
->l_type
= -1;
936 bsd_flock
->l_whence
= linux_flock
->l_whence
;
937 bsd_flock
->l_start
= (off_t
)linux_flock
->l_start
;
938 bsd_flock
->l_len
= (off_t
)linux_flock
->l_len
;
939 bsd_flock
->l_pid
= (pid_t
)linux_flock
->l_pid
;
943 bsd_to_linux_flock(struct flock
*bsd_flock
, struct l_flock
*linux_flock
)
945 switch (bsd_flock
->l_type
) {
947 linux_flock
->l_type
= LINUX_F_RDLCK
;
950 linux_flock
->l_type
= LINUX_F_WRLCK
;
953 linux_flock
->l_type
= LINUX_F_UNLCK
;
956 linux_flock
->l_whence
= bsd_flock
->l_whence
;
957 linux_flock
->l_start
= (l_off_t
)bsd_flock
->l_start
;
958 linux_flock
->l_len
= (l_off_t
)bsd_flock
->l_len
;
959 linux_flock
->l_pid
= (l_pid_t
)bsd_flock
->l_pid
;
962 #if defined(__i386__)
972 linux_to_bsd_flock64(struct l_flock64
*linux_flock
, struct flock
*bsd_flock
)
974 switch (linux_flock
->l_type
) {
976 bsd_flock
->l_type
= F_RDLCK
;
979 bsd_flock
->l_type
= F_WRLCK
;
982 bsd_flock
->l_type
= F_UNLCK
;
985 bsd_flock
->l_type
= -1;
988 bsd_flock
->l_whence
= linux_flock
->l_whence
;
989 bsd_flock
->l_start
= (off_t
)linux_flock
->l_start
;
990 bsd_flock
->l_len
= (off_t
)linux_flock
->l_len
;
991 bsd_flock
->l_pid
= (pid_t
)linux_flock
->l_pid
;
995 bsd_to_linux_flock64(struct flock
*bsd_flock
, struct l_flock64
*linux_flock
)
997 switch (bsd_flock
->l_type
) {
999 linux_flock
->l_type
= LINUX_F_RDLCK
;
1002 linux_flock
->l_type
= LINUX_F_WRLCK
;
1005 linux_flock
->l_type
= LINUX_F_UNLCK
;
1008 linux_flock
->l_whence
= bsd_flock
->l_whence
;
1009 linux_flock
->l_start
= (l_loff_t
)bsd_flock
->l_start
;
1010 linux_flock
->l_len
= (l_loff_t
)bsd_flock
->l_len
;
1011 linux_flock
->l_pid
= (l_pid_t
)bsd_flock
->l_pid
;
1013 #endif /* __i386__ */
1016 linux_fcntl_common(struct linux_fcntl64_args
*args
)
1018 struct proc
*p
= curproc
;
1019 struct l_flock linux_flock
;
1021 union fcntl_dat dat
;
1024 switch (args
->cmd
) {
1027 dat
.fc_fd
= args
->arg
;
1034 dat
.fc_cloexec
= args
->arg
;
1042 if (args
->arg
& LINUX_O_NDELAY
)
1043 dat
.fc_flags
|= O_NONBLOCK
;
1044 if (args
->arg
& LINUX_O_APPEND
)
1045 dat
.fc_flags
|= O_APPEND
;
1046 if (args
->arg
& LINUX_O_SYNC
)
1047 dat
.fc_flags
|= O_FSYNC
;
1048 if (args
->arg
& LINUX_FASYNC
)
1049 dat
.fc_flags
|= O_ASYNC
;
1053 case LINUX_F_SETLKW
:
1055 error
= copyin((caddr_t
)args
->arg
, &linux_flock
,
1056 sizeof(linux_flock
));
1059 linux_to_bsd_flock(&linux_flock
, &dat
.fc_flock
);
1061 case LINUX_F_GETOWN
:
1064 case LINUX_F_SETOWN
:
1066 * XXX some Linux applications depend on F_SETOWN having no
1067 * significant effect for pipes (SIGIO is not delivered for
1068 * pipes under Linux-2.2.35 at least).
1070 fp
= holdfp(p
->p_fd
, args
->fd
, -1);
1073 if (fp
->f_type
== DTYPE_PIPE
) {
1079 dat
.fc_owner
= args
->arg
;
1085 error
= kern_fcntl(args
->fd
, cmd
, &dat
, p
->p_ucred
);
1088 switch (args
->cmd
) {
1090 args
->sysmsg_iresult
= dat
.fc_fd
;
1093 args
->sysmsg_iresult
= dat
.fc_cloexec
;
1098 args
->sysmsg_iresult
= 0;
1099 if (dat
.fc_flags
& O_RDONLY
)
1100 args
->sysmsg_iresult
|= LINUX_O_RDONLY
;
1101 if (dat
.fc_flags
& O_WRONLY
)
1102 args
->sysmsg_iresult
|= LINUX_O_WRONLY
;
1103 if (dat
.fc_flags
& O_RDWR
)
1104 args
->sysmsg_iresult
|= LINUX_O_RDWR
;
1105 if (dat
.fc_flags
& O_NDELAY
)
1106 args
->sysmsg_iresult
|= LINUX_O_NONBLOCK
;
1107 if (dat
.fc_flags
& O_APPEND
)
1108 args
->sysmsg_iresult
|= LINUX_O_APPEND
;
1109 if (dat
.fc_flags
& O_FSYNC
)
1110 args
->sysmsg_iresult
|= LINUX_O_SYNC
;
1111 if (dat
.fc_flags
& O_ASYNC
)
1112 args
->sysmsg_iresult
|= LINUX_FASYNC
;
1115 bsd_to_linux_flock(&dat
.fc_flock
, &linux_flock
);
1116 error
= copyout(&linux_flock
, (caddr_t
)args
->arg
,
1117 sizeof(linux_flock
));
1120 case LINUX_F_SETLKW
:
1122 case LINUX_F_GETOWN
:
1123 args
->sysmsg_iresult
= dat
.fc_owner
;
1125 case LINUX_F_SETOWN
:
1134 sys_linux_fcntl(struct linux_fcntl_args
*args
)
1136 struct linux_fcntl64_args args64
;
1141 kprintf(ARGS(fcntl
, "%d, %08x, *"), args
->fd
, args
->cmd
);
1144 args64
.fd
= args
->fd
;
1145 args64
.cmd
= args
->cmd
;
1146 args64
.arg
= args
->arg
;
1147 args64
.sysmsg_iresult
= 0;
1148 error
= linux_fcntl_common(&args64
);
1149 args
->sysmsg_iresult
= args64
.sysmsg_iresult
;
1153 #if defined(__i386__)
1155 sys_linux_fcntl64(struct linux_fcntl64_args
*args
)
1157 struct l_flock64 linux_flock
;
1158 union fcntl_dat dat
;
1162 if (ldebug(fcntl64
))
1163 kprintf(ARGS(fcntl64
, "%d, %08x, *"), args
->fd
, args
->cmd
);
1165 if (args
->cmd
== LINUX_F_GETLK64
|| args
->cmd
== LINUX_F_SETLK64
||
1166 args
->cmd
== LINUX_F_SETLKW64
) {
1167 switch (args
->cmd
) {
1168 case LINUX_F_GETLK64
:
1171 case LINUX_F_SETLK64
:
1174 case LINUX_F_SETLKW64
:
1179 error
= copyin((caddr_t
)args
->arg
, &linux_flock
,
1180 sizeof(linux_flock
));
1183 linux_to_bsd_flock64(&linux_flock
, &dat
.fc_flock
);
1185 error
= kern_fcntl(args
->fd
, cmd
, &dat
, curproc
->p_ucred
);
1187 if (error
== 0 && args
->cmd
== LINUX_F_GETLK64
) {
1188 bsd_to_linux_flock64(&dat
.fc_flock
, &linux_flock
);
1189 error
= copyout(&linux_flock
, (caddr_t
)args
->arg
,
1190 sizeof(linux_flock
));
1193 error
= linux_fcntl_common(args
);
1198 #endif /* __i386__ */
1201 sys_linux_chown(struct linux_chown_args
*args
)
1203 struct nlookupdata nd
;
1207 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
1212 kprintf(ARGS(chown
, "%s, %d, %d"), path
, args
->uid
, args
->gid
);
1214 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
1216 error
= kern_chown(&nd
, args
->uid
, args
->gid
);
1218 linux_free_path(&path
);
1223 sys_linux_lchown(struct linux_lchown_args
*args
)
1225 struct nlookupdata nd
;
1229 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
1234 kprintf(ARGS(lchown
, "%s, %d, %d"), path
, args
->uid
, args
->gid
);
1236 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
1238 error
= kern_chown(&nd
, args
->uid
, args
->gid
);
1240 linux_free_path(&path
);