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_result
);
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_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 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_result
= 0;
206 error
= sys_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 off_t
*cookies
= NULL
, *cookiep
;
264 if ((error
= holdvnode(p
->p_fd
, args
->fd
, &fp
)) != 0)
267 if ((fp
->f_flag
& FREAD
) == 0) {
272 vp
= (struct vnode
*) fp
->f_data
;
273 if (vp
->v_type
!= VDIR
) {
278 if ((error
= VOP_GETATTR(vp
, &va
)) != 0)
281 nbytes
= args
->count
;
283 /* readdir(2) case. Always struct dirent. */
288 nbytes
= sizeof(linux_dirent
);
298 buflen
= max(LINUX_DIRBLKSIZ
, nbytes
);
299 buflen
= min(buflen
, MAXBSIZE
);
300 buf
= kmalloc(buflen
, M_TEMP
, M_WAITOK
);
304 aiov
.iov_len
= buflen
;
305 auio
.uio_iov
= &aiov
;
307 auio
.uio_rw
= UIO_READ
;
308 auio
.uio_segflg
= UIO_SYSSPACE
;
310 auio
.uio_resid
= buflen
;
311 auio
.uio_offset
= off
;
314 kfree(cookies
, M_TEMP
);
320 if ((error
= VOP_READDIR(vp
, &auio
, fp
->f_cred
, &eofflag
, &ncookies
,
325 outp
= (caddr_t
)args
->dirent
;
327 if ((len
= buflen
- auio
.uio_resid
) <= 0)
334 * When using cookies, the vfs has the option of reading from
335 * a different offset than that supplied (UFS truncates the
336 * offset to a block boundary to make sure that it never reads
337 * partway through a directory entry, even if the directory
338 * has been compacted).
340 while (len
> 0 && ncookies
> 0 && *cookiep
< off
) {
341 bdp
= (struct dirent
*) inp
;
342 len
-= _DIRENT_DIRSIZ(bdp
);
343 inp
+= _DIRENT_DIRSIZ(bdp
);
350 if (cookiep
&& ncookies
== 0)
352 bdp
= (struct dirent
*) inp
;
353 reclen
= _DIRENT_DIRSIZ(bdp
);
359 if (bdp
->d_ino
== 0) {
372 linuxreclen
= (is64bit
)
373 ? LINUX_RECLEN(&linux_dirent64
, bdp
->d_namlen
)
374 : LINUX_RECLEN(&linux_dirent
, bdp
->d_namlen
);
376 if (reclen
> len
|| resid
< linuxreclen
) {
381 bzero(&linux_dirent
, sizeof(linux_dirent
));
382 bzero(&linux_dirent64
, sizeof(linux_dirent64
));
384 /* readdir(2) case. */
385 linux_dirent
.d_ino
= (l_long
)INO64TO32(bdp
->d_ino
);
386 linux_dirent
.d_off
= (l_off_t
)linuxreclen
;
387 linux_dirent
.d_reclen
= (l_ushort
)bdp
->d_namlen
;
388 strcpy(linux_dirent
.d_name
, bdp
->d_name
);
389 error
= copyout(&linux_dirent
, outp
, linuxreclen
);
392 linux_dirent64
.d_ino
= bdp
->d_ino
;
393 linux_dirent64
.d_off
= (cookiep
)
395 : (l_off_t
)(off
+ reclen
);
396 linux_dirent64
.d_reclen
=
397 (l_ushort
)linuxreclen
;
398 linux_dirent64
.d_type
= bdp
->d_type
;
399 strcpy(linux_dirent64
.d_name
, bdp
->d_name
);
400 error
= copyout(&linux_dirent64
, outp
,
403 linux_dirent
.d_ino
= INO64TO32(bdp
->d_ino
);
404 linux_dirent
.d_off
= (cookiep
)
406 : (l_off_t
)(off
+ reclen
);
407 linux_dirent
.d_reclen
= (l_ushort
)linuxreclen
;
408 strcpy(linux_dirent
.d_name
, bdp
->d_name
);
409 error
= copyout(&linux_dirent
, outp
,
426 resid
-= linuxreclen
;
432 if (outp
== (caddr_t
)args
->dirent
&& eofflag
== 0)
437 nbytes
= resid
+ linuxreclen
;
440 args
->sysmsg_result
= nbytes
- resid
;
444 kfree(cookies
, M_TEMP
);
453 sys_linux_getdents(struct linux_getdents_args
*args
)
456 if (ldebug(getdents
))
457 kprintf(ARGS(getdents
, "%d, *, %d"), args
->fd
, args
->count
);
459 return (getdents_common((struct linux_getdents64_args
*)args
, 0));
463 sys_linux_getdents64(struct linux_getdents64_args
*args
)
466 if (ldebug(getdents64
))
467 kprintf(ARGS(getdents64
, "%d, *, %d"), args
->fd
, args
->count
);
469 return (getdents_common(args
, 1));
473 * These exist mainly for hooks for doing /compat/linux translation.
477 sys_linux_access(struct linux_access_args
*args
)
479 struct nlookupdata nd
;
483 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
488 kprintf(ARGS(access
, "%s, %d"), path
, args
->flags
);
490 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
492 error
= kern_access(&nd
, args
->flags
);
494 linux_free_path(&path
);
499 sys_linux_unlink(struct linux_unlink_args
*args
)
501 struct nlookupdata nd
;
505 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
510 kprintf(ARGS(unlink
, "%s"), path
);
512 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
514 error
= kern_unlink(&nd
);
516 linux_free_path(&path
);
521 sys_linux_chdir(struct linux_chdir_args
*args
)
523 struct nlookupdata nd
;
527 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
532 kprintf(ARGS(chdir
, "%s"), path
);
534 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
536 error
= kern_chdir(&nd
);
539 linux_free_path(&path
);
544 sys_linux_chmod(struct linux_chmod_args
*args
)
546 struct nlookupdata nd
;
550 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
555 kprintf(ARGS(chmod
, "%s, %d"), path
, args
->mode
);
557 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
559 error
= kern_chmod(&nd
, args
->mode
);
561 linux_free_path(&path
);
566 sys_linux_mkdir(struct linux_mkdir_args
*args
)
568 struct nlookupdata nd
;
572 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_CREATE
);
577 kprintf(ARGS(mkdir
, "%s, %d"), path
, args
->mode
);
579 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
581 error
= kern_mkdir(&nd
, args
->mode
);
584 linux_free_path(&path
);
589 sys_linux_rmdir(struct linux_rmdir_args
*args
)
591 struct nlookupdata nd
;
595 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
600 kprintf(ARGS(rmdir
, "%s"), path
);
602 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
604 error
= kern_rmdir(&nd
);
606 linux_free_path(&path
);
611 sys_linux_rename(struct linux_rename_args
*args
)
613 struct nlookupdata fromnd
, tond
;
617 error
= linux_copyin_path(args
->from
, &from
, LINUX_PATH_EXISTS
);
620 error
= linux_copyin_path(args
->to
, &to
, LINUX_PATH_CREATE
);
622 linux_free_path(&from
);
627 kprintf(ARGS(rename
, "%s, %s"), from
, to
);
629 error
= nlookup_init(&fromnd
, from
, UIO_SYSSPACE
, 0);
631 error
= nlookup_init(&tond
, to
, UIO_SYSSPACE
, 0);
633 error
= kern_rename(&fromnd
, &tond
);
636 nlookup_done(&fromnd
);
637 linux_free_path(&from
);
638 linux_free_path(&to
);
643 sys_linux_symlink(struct linux_symlink_args
*args
)
645 struct thread
*td
= curthread
;
646 struct nlookupdata nd
;
651 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
654 error
= linux_copyin_path(args
->to
, &link
, LINUX_PATH_CREATE
);
656 linux_free_path(&path
);
661 kprintf(ARGS(symlink
, "%s, %s"), path
, link
);
663 error
= nlookup_init(&nd
, link
, UIO_SYSSPACE
, 0);
665 mode
= ACCESSPERMS
& ~td
->td_proc
->p_fd
->fd_cmask
;
666 error
= kern_symlink(&nd
, path
, mode
);
669 linux_free_path(&path
);
670 linux_free_path(&link
);
675 sys_linux_readlink(struct linux_readlink_args
*args
)
677 struct nlookupdata nd
;
681 error
= linux_copyin_path(args
->name
, &path
, LINUX_PATH_EXISTS
);
685 if (ldebug(readlink
))
686 kprintf(ARGS(readlink
, "%s, %p, %d"), path
, (void *)args
->buf
,
689 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
691 error
= kern_readlink(&nd
, args
->buf
, args
->count
,
692 &args
->sysmsg_result
);
695 linux_free_path(&path
);
700 sys_linux_truncate(struct linux_truncate_args
*args
)
702 struct nlookupdata nd
;
706 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
710 if (ldebug(truncate
))
711 kprintf(ARGS(truncate
, "%s, %ld"), path
,
714 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
716 error
= kern_truncate(&nd
, args
->length
);
718 linux_free_path(&path
);
723 sys_linux_truncate64(struct linux_truncate64_args
*args
)
725 struct nlookupdata nd
;
729 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
733 if (ldebug(truncate64
))
734 kprintf(ARGS(truncate64
, "%s, %lld"), path
,
735 (off_t
)args
->length
);
737 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
739 error
= kern_truncate(&nd
, args
->length
);
741 linux_free_path(&path
);
746 sys_linux_ftruncate(struct linux_ftruncate_args
*args
)
751 if (ldebug(ftruncate
))
752 kprintf(ARGS(ftruncate
, "%d, %ld"), args
->fd
,
755 error
= kern_ftruncate(args
->fd
, args
->length
);
761 sys_linux_ftruncate64(struct linux_ftruncate64_args
*args
)
766 if (ldebug(ftruncate
))
767 kprintf(ARGS(ftruncate64
, "%d, %lld"), args
->fd
,
768 (off_t
)args
->length
);
770 error
= kern_ftruncate(args
->fd
, args
->length
);
776 sys_linux_link(struct linux_link_args
*args
)
778 struct nlookupdata nd
, linknd
;
782 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
785 error
= linux_copyin_path(args
->to
, &link
, LINUX_PATH_CREATE
);
787 linux_free_path(&path
);
792 kprintf(ARGS(link
, "%s, %s"), path
, link
);
794 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
796 error
= nlookup_init(&linknd
, link
, UIO_SYSSPACE
, 0);
798 error
= kern_link(&nd
, &linknd
);
799 nlookup_done(&linknd
);
802 linux_free_path(&path
);
803 linux_free_path(&link
);
808 sys_linux_fdatasync(struct linux_fdatasync_args
*uap
)
810 struct fsync_args bsd
;
814 bsd
.sysmsg_result
= 0;
816 error
= sys_fsync(&bsd
);
817 uap
->sysmsg_result
= bsd
.sysmsg_result
;
822 sys_linux_pread(struct linux_pread_args
*uap
)
824 struct thread
*td
= curthread
;
829 aiov
.iov_base
= uap
->buf
;
830 aiov
.iov_len
= uap
->nbyte
;
831 auio
.uio_iov
= &aiov
;
833 auio
.uio_offset
= uap
->offset
;
834 auio
.uio_resid
= uap
->nbyte
;
835 auio
.uio_rw
= UIO_READ
;
836 auio
.uio_segflg
= UIO_USERSPACE
;
839 if (auio
.uio_resid
< 0)
842 error
= kern_preadv(uap
->fd
, &auio
, O_FOFFSET
, &uap
->sysmsg_result
);
847 sys_linux_pwrite(struct linux_pwrite_args
*uap
)
849 struct thread
*td
= curthread
;
854 aiov
.iov_base
= uap
->buf
;
855 aiov
.iov_len
= uap
->nbyte
;
856 auio
.uio_iov
= &aiov
;
858 auio
.uio_offset
= uap
->offset
;
859 auio
.uio_resid
= uap
->nbyte
;
860 auio
.uio_rw
= UIO_WRITE
;
861 auio
.uio_segflg
= UIO_USERSPACE
;
864 if (auio
.uio_resid
< 0)
867 error
= kern_pwritev(uap
->fd
, &auio
, O_FOFFSET
, &uap
->sysmsg_result
);
873 sys_linux_oldumount(struct linux_oldumount_args
*args
)
875 struct linux_umount_args args2
;
878 args2
.path
= args
->path
;
880 args2
.sysmsg_result
= 0;
881 error
= sys_linux_umount(&args2
);
882 args
->sysmsg_result
= args2
.sysmsg_result
;
887 sys_linux_umount(struct linux_umount_args
*args
)
889 struct unmount_args bsd
;
892 bsd
.path
= args
->path
;
893 bsd
.flags
= args
->flags
; /* XXX correct? */
894 bsd
.sysmsg_result
= 0;
896 error
= sys_unmount(&bsd
);
897 args
->sysmsg_result
= bsd
.sysmsg_result
;
902 * fcntl family of syscalls
914 linux_to_bsd_flock(struct l_flock
*linux_flock
, struct flock
*bsd_flock
)
916 switch (linux_flock
->l_type
) {
918 bsd_flock
->l_type
= F_RDLCK
;
921 bsd_flock
->l_type
= F_WRLCK
;
924 bsd_flock
->l_type
= F_UNLCK
;
927 bsd_flock
->l_type
= -1;
930 bsd_flock
->l_whence
= linux_flock
->l_whence
;
931 bsd_flock
->l_start
= (off_t
)linux_flock
->l_start
;
932 bsd_flock
->l_len
= (off_t
)linux_flock
->l_len
;
933 bsd_flock
->l_pid
= (pid_t
)linux_flock
->l_pid
;
937 bsd_to_linux_flock(struct flock
*bsd_flock
, struct l_flock
*linux_flock
)
939 switch (bsd_flock
->l_type
) {
941 linux_flock
->l_type
= LINUX_F_RDLCK
;
944 linux_flock
->l_type
= LINUX_F_WRLCK
;
947 linux_flock
->l_type
= LINUX_F_UNLCK
;
950 linux_flock
->l_whence
= bsd_flock
->l_whence
;
951 linux_flock
->l_start
= (l_off_t
)bsd_flock
->l_start
;
952 linux_flock
->l_len
= (l_off_t
)bsd_flock
->l_len
;
953 linux_flock
->l_pid
= (l_pid_t
)bsd_flock
->l_pid
;
956 #if defined(__i386__)
966 linux_to_bsd_flock64(struct l_flock64
*linux_flock
, struct flock
*bsd_flock
)
968 switch (linux_flock
->l_type
) {
970 bsd_flock
->l_type
= F_RDLCK
;
973 bsd_flock
->l_type
= F_WRLCK
;
976 bsd_flock
->l_type
= F_UNLCK
;
979 bsd_flock
->l_type
= -1;
982 bsd_flock
->l_whence
= linux_flock
->l_whence
;
983 bsd_flock
->l_start
= (off_t
)linux_flock
->l_start
;
984 bsd_flock
->l_len
= (off_t
)linux_flock
->l_len
;
985 bsd_flock
->l_pid
= (pid_t
)linux_flock
->l_pid
;
989 bsd_to_linux_flock64(struct flock
*bsd_flock
, struct l_flock64
*linux_flock
)
991 switch (bsd_flock
->l_type
) {
993 linux_flock
->l_type
= LINUX_F_RDLCK
;
996 linux_flock
->l_type
= LINUX_F_WRLCK
;
999 linux_flock
->l_type
= LINUX_F_UNLCK
;
1002 linux_flock
->l_whence
= bsd_flock
->l_whence
;
1003 linux_flock
->l_start
= (l_loff_t
)bsd_flock
->l_start
;
1004 linux_flock
->l_len
= (l_loff_t
)bsd_flock
->l_len
;
1005 linux_flock
->l_pid
= (l_pid_t
)bsd_flock
->l_pid
;
1007 #endif /* __i386__ */
1010 linux_fcntl_common(struct linux_fcntl64_args
*args
)
1012 struct proc
*p
= curproc
;
1013 struct l_flock linux_flock
;
1015 union fcntl_dat dat
;
1018 switch (args
->cmd
) {
1021 dat
.fc_fd
= args
->arg
;
1028 dat
.fc_cloexec
= args
->arg
;
1036 if (args
->arg
& LINUX_O_NDELAY
)
1037 dat
.fc_flags
|= O_NONBLOCK
;
1038 if (args
->arg
& LINUX_O_APPEND
)
1039 dat
.fc_flags
|= O_APPEND
;
1040 if (args
->arg
& LINUX_O_SYNC
)
1041 dat
.fc_flags
|= O_FSYNC
;
1042 if (args
->arg
& LINUX_FASYNC
)
1043 dat
.fc_flags
|= O_ASYNC
;
1047 case LINUX_F_SETLKW
:
1049 error
= copyin((caddr_t
)args
->arg
, &linux_flock
,
1050 sizeof(linux_flock
));
1053 linux_to_bsd_flock(&linux_flock
, &dat
.fc_flock
);
1055 case LINUX_F_GETOWN
:
1058 case LINUX_F_SETOWN
:
1060 * XXX some Linux applications depend on F_SETOWN having no
1061 * significant effect for pipes (SIGIO is not delivered for
1062 * pipes under Linux-2.2.35 at least).
1064 fp
= holdfp(p
->p_fd
, args
->fd
, -1);
1067 if (fp
->f_type
== DTYPE_PIPE
) {
1073 dat
.fc_owner
= args
->arg
;
1079 error
= kern_fcntl(args
->fd
, cmd
, &dat
, p
->p_ucred
);
1082 switch (args
->cmd
) {
1084 args
->sysmsg_result
= dat
.fc_fd
;
1087 args
->sysmsg_result
= dat
.fc_cloexec
;
1092 args
->sysmsg_result
= 0;
1093 if (dat
.fc_flags
& O_RDONLY
)
1094 args
->sysmsg_result
|= LINUX_O_RDONLY
;
1095 if (dat
.fc_flags
& O_WRONLY
)
1096 args
->sysmsg_result
|= LINUX_O_WRONLY
;
1097 if (dat
.fc_flags
& O_RDWR
)
1098 args
->sysmsg_result
|= LINUX_O_RDWR
;
1099 if (dat
.fc_flags
& O_NDELAY
)
1100 args
->sysmsg_result
|= LINUX_O_NONBLOCK
;
1101 if (dat
.fc_flags
& O_APPEND
)
1102 args
->sysmsg_result
|= LINUX_O_APPEND
;
1103 if (dat
.fc_flags
& O_FSYNC
)
1104 args
->sysmsg_result
|= LINUX_O_SYNC
;
1105 if (dat
.fc_flags
& O_ASYNC
)
1106 args
->sysmsg_result
|= LINUX_FASYNC
;
1109 bsd_to_linux_flock(&dat
.fc_flock
, &linux_flock
);
1110 error
= copyout(&linux_flock
, (caddr_t
)args
->arg
,
1111 sizeof(linux_flock
));
1114 case LINUX_F_SETLKW
:
1116 case LINUX_F_GETOWN
:
1117 args
->sysmsg_result
= dat
.fc_owner
;
1119 case LINUX_F_SETOWN
:
1128 sys_linux_fcntl(struct linux_fcntl_args
*args
)
1130 struct linux_fcntl64_args args64
;
1135 kprintf(ARGS(fcntl
, "%d, %08x, *"), args
->fd
, args
->cmd
);
1138 args64
.fd
= args
->fd
;
1139 args64
.cmd
= args
->cmd
;
1140 args64
.arg
= args
->arg
;
1141 args64
.sysmsg_result
= 0;
1142 error
= linux_fcntl_common(&args64
);
1143 args
->sysmsg_result
= args64
.sysmsg_result
;
1147 #if defined(__i386__)
1149 sys_linux_fcntl64(struct linux_fcntl64_args
*args
)
1151 struct l_flock64 linux_flock
;
1152 union fcntl_dat dat
;
1156 if (ldebug(fcntl64
))
1157 kprintf(ARGS(fcntl64
, "%d, %08x, *"), args
->fd
, args
->cmd
);
1159 if (args
->cmd
== LINUX_F_GETLK64
|| args
->cmd
== LINUX_F_SETLK64
||
1160 args
->cmd
== LINUX_F_SETLKW64
) {
1161 switch (args
->cmd
) {
1162 case LINUX_F_GETLK64
:
1165 case LINUX_F_SETLK64
:
1168 case LINUX_F_SETLKW64
:
1173 error
= copyin((caddr_t
)args
->arg
, &linux_flock
,
1174 sizeof(linux_flock
));
1177 linux_to_bsd_flock64(&linux_flock
, &dat
.fc_flock
);
1179 error
= kern_fcntl(args
->fd
, cmd
, &dat
, curproc
->p_ucred
);
1181 if (error
== 0 && args
->cmd
== LINUX_F_GETLK64
) {
1182 bsd_to_linux_flock64(&dat
.fc_flock
, &linux_flock
);
1183 error
= copyout(&linux_flock
, (caddr_t
)args
->arg
,
1184 sizeof(linux_flock
));
1187 error
= linux_fcntl_common(args
);
1192 #endif /* __i386__ */
1195 sys_linux_chown(struct linux_chown_args
*args
)
1197 struct nlookupdata nd
;
1201 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
1206 kprintf(ARGS(chown
, "%s, %d, %d"), path
, args
->uid
, args
->gid
);
1208 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, NLC_FOLLOW
);
1210 error
= kern_chown(&nd
, args
->uid
, args
->gid
);
1212 linux_free_path(&path
);
1217 sys_linux_lchown(struct linux_lchown_args
*args
)
1219 struct nlookupdata nd
;
1223 error
= linux_copyin_path(args
->path
, &path
, LINUX_PATH_EXISTS
);
1228 kprintf(ARGS(lchown
, "%s, %d, %d"), path
, args
->uid
, args
->gid
);
1230 error
= nlookup_init(&nd
, path
, UIO_SYSSPACE
, 0);
1232 error
= kern_chown(&nd
, args
->uid
, args
->gid
);
1234 linux_free_path(&path
);