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.11 2003/10/17 05:25:45 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>
46 #include <sys/sysproto.h>
48 #include <sys/vnode.h>
50 #include <vfs/ufs/quota.h>
51 #include <vfs/ufs/ufsmount.h>
53 #include <sys/file2.h>
55 #include <arch_linux/linux.h>
56 #include <arch_linux/linux_proto.h>
57 #include "linux_util.h"
61 linux_creat(struct linux_creat_args *args)
63 struct open_args bsd_open_args;
68 CHECKALTCREAT(&sg, args->path);
72 printf(ARGS(creat, "%s, %d"), args->path, args->mode);
74 bsd_open_args.sysmsg_result = 0;
75 bsd_open_args.path = args->path;
76 bsd_open_args.mode = args->mode;
77 bsd_open_args.flags = O_WRONLY | O_CREAT | O_TRUNC;
78 error = open(&bsd_open_args);
79 args->sysmsg_result = bsd_open_args.sysmsg_result;
85 linux_open(struct linux_open_args *args)
87 struct open_args bsd_open_args;
90 struct thread *td = curthread;
91 struct proc *p = td->td_proc;
97 if (args->flags & LINUX_O_CREAT)
98 CHECKALTCREAT(&sg, args->path);
100 CHECKALTEXIST(&sg, args->path);
104 printf(ARGS(open, "%s, 0x%x, 0x%x"),
105 args->path, args->flags, args->mode);
107 bsd_open_args.flags = 0;
108 if (args->flags & LINUX_O_RDONLY)
109 bsd_open_args.flags |= O_RDONLY;
110 if (args->flags & LINUX_O_WRONLY)
111 bsd_open_args.flags |= O_WRONLY;
112 if (args->flags & LINUX_O_RDWR)
113 bsd_open_args.flags |= O_RDWR;
114 if (args->flags & LINUX_O_NDELAY)
115 bsd_open_args.flags |= O_NONBLOCK;
116 if (args->flags & LINUX_O_APPEND)
117 bsd_open_args.flags |= O_APPEND;
118 if (args->flags & LINUX_O_SYNC)
119 bsd_open_args.flags |= O_FSYNC;
120 if (args->flags & LINUX_O_NONBLOCK)
121 bsd_open_args.flags |= O_NONBLOCK;
122 if (args->flags & LINUX_FASYNC)
123 bsd_open_args.flags |= O_ASYNC;
124 if (args->flags & LINUX_O_CREAT)
125 bsd_open_args.flags |= O_CREAT;
126 if (args->flags & LINUX_O_TRUNC)
127 bsd_open_args.flags |= O_TRUNC;
128 if (args->flags & LINUX_O_EXCL)
129 bsd_open_args.flags |= O_EXCL;
130 if (args->flags & LINUX_O_NOCTTY)
131 bsd_open_args.flags |= O_NOCTTY;
132 bsd_open_args.path = args->path;
133 bsd_open_args.mode = args->mode;
134 bsd_open_args.sysmsg_result = 0;
135 error = open(&bsd_open_args);
136 args->sysmsg_result = bsd_open_args.sysmsg_result;
138 if (!error && !(bsd_open_args.flags & O_NOCTTY) &&
139 SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
140 struct filedesc *fdp = p->p_fd;
141 struct file *fp = fdp->fd_ofiles[bsd_open_args.sysmsg_result];
143 if (fp->f_type == DTYPE_VNODE)
144 fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td);
148 printf(LMSG("open returns error %d"), error);
154 linux_lseek(struct linux_lseek_args *args)
156 struct lseek_args tmp_args;
161 printf(ARGS(lseek, "%d, %ld, %d"),
162 args->fdes, (long)args->off, args->whence);
164 tmp_args.fd = args->fdes;
165 tmp_args.offset = (off_t)args->off;
166 tmp_args.whence = args->whence;
167 tmp_args.sysmsg_result = 0;
168 error = lseek(&tmp_args);
169 args->sysmsg_result = tmp_args.sysmsg_result;
175 linux_llseek(struct linux_llseek_args *args)
177 struct lseek_args bsd_args;
183 printf(ARGS(llseek, "%d, %d:%d, %d"),
184 args->fd, args->ohigh, args->olow, args->whence);
186 off = (args->olow) | (((off_t) args->ohigh) << 32);
188 bsd_args.fd = args->fd;
189 bsd_args.offset = off;
190 bsd_args.whence = args->whence;
191 bsd_args.sysmsg_result = 0;
193 if ((error = lseek(&bsd_args)))
196 if ((error = copyout(&bsd_args.sysmsg_offset, (caddr_t)args->res, sizeof (off_t)))) {
199 args->sysmsg_result = 0;
202 #endif /*!__alpha__*/
206 linux_readdir(struct linux_readdir_args *args)
208 struct linux_getdents_args lda;
212 lda.dent = args->dent;
214 lda.sysmsg_result = 0;
215 error = linux_getdents(&lda);
216 args->sysmsg_result = lda.sysmsg_result;
219 #endif /*!__alpha__*/
222 * Note that linux_getdents(2) and linux_getdents64(2) have the same
223 * arguments. They only differ in the definition of struct dirent they
224 * operate on. We use this to common the code, with the exception of
225 * accessing struct dirent. Note that linux_readdir(2) is implemented
226 * by means of linux_getdents(2). In this case we never operate on
227 * struct dirent64 and thus don't need to handle it...
234 char d_name[LINUX_NAME_MAX + 1];
242 char d_name[LINUX_NAME_MAX + 1];
245 #define LINUX_RECLEN(de,namlen) \
246 ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1))
248 #define LINUX_DIRBLKSIZ 512
251 getdents_common(struct linux_getdents64_args *args, int is64bit)
253 struct thread *td = curthread;
254 struct proc *p = td->td_proc;
257 caddr_t inp, buf; /* BSD-format */
258 int len, reclen; /* BSD-format */
259 caddr_t outp; /* Linux-format */
260 int resid, linuxreclen=0; /* Linux-format */
266 struct l_dirent linux_dirent;
267 struct l_dirent64 linux_dirent64;
268 int buflen, error, eofflag, nbytes, justone;
269 u_long *cookies = NULL, *cookiep;
274 if ((error = getvnode(p->p_fd, args->fd, &fp)) != 0)
277 if ((fp->f_flag & FREAD) == 0)
280 vp = (struct vnode *) fp->f_data;
281 if (vp->v_type != VDIR)
284 if ((error = VOP_GETATTR(vp, &va, td)))
287 nbytes = args->count;
289 /* readdir(2) case. Always struct dirent. */
292 nbytes = sizeof(linux_dirent);
299 buflen = max(LINUX_DIRBLKSIZ, nbytes);
300 buflen = min(buflen, MAXBSIZE);
301 buf = malloc(buflen, M_TEMP, M_WAITOK);
302 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
306 aiov.iov_len = buflen;
307 auio.uio_iov = &aiov;
309 auio.uio_rw = UIO_READ;
310 auio.uio_segflg = UIO_SYSSPACE;
312 auio.uio_resid = buflen;
313 auio.uio_offset = off;
316 free(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 -= bdp->d_reclen;
343 inp += bdp->d_reclen;
350 if (cookiep && ncookies == 0)
352 bdp = (struct dirent *) inp;
353 reclen = bdp->d_reclen;
359 if (bdp->d_fileno == 0) {
371 linuxreclen = (is64bit)
372 ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen)
373 : LINUX_RECLEN(&linux_dirent, bdp->d_namlen);
375 if (reclen > len || resid < linuxreclen) {
381 /* readdir(2) case. */
382 linux_dirent.d_ino = (l_long)bdp->d_fileno;
383 linux_dirent.d_off = (l_off_t)linuxreclen;
384 linux_dirent.d_reclen = (l_ushort)bdp->d_namlen;
385 strcpy(linux_dirent.d_name, bdp->d_name);
386 error = copyout(&linux_dirent, outp, linuxreclen);
389 linux_dirent64.d_ino = bdp->d_fileno;
390 linux_dirent64.d_off = (cookiep)
392 : (l_off_t)(off + reclen);
393 linux_dirent64.d_reclen =
394 (l_ushort)linuxreclen;
395 linux_dirent64.d_type = bdp->d_type;
396 strcpy(linux_dirent64.d_name, bdp->d_name);
397 error = copyout(&linux_dirent64, outp,
400 linux_dirent.d_ino = bdp->d_fileno;
401 linux_dirent.d_off = (cookiep)
403 : (l_off_t)(off + reclen);
404 linux_dirent.d_reclen = (l_ushort)linuxreclen;
405 strcpy(linux_dirent.d_name, bdp->d_name);
406 error = copyout(&linux_dirent, outp,
421 resid -= linuxreclen;
427 if (outp == (caddr_t)args->dirent)
432 nbytes = resid + linuxreclen;
435 args->sysmsg_result = nbytes - resid;
439 free(cookies, M_TEMP);
441 VOP_UNLOCK(vp, 0, td);
447 linux_getdents(struct linux_getdents_args *args)
450 if (ldebug(getdents))
451 printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count);
453 return (getdents_common((struct linux_getdents64_args*)args, 0));
457 linux_getdents64(struct linux_getdents64_args *args)
460 if (ldebug(getdents64))
461 printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count);
463 return (getdents_common(args, 1));
467 * These exist mainly for hooks for doing /compat/linux translation.
471 linux_access(struct linux_access_args *args)
473 struct access_args bsd;
477 sg = stackgap_init();
478 CHECKALTEXIST(&sg, args->path);
482 printf(ARGS(access, "%s, %d"), args->path, args->flags);
484 bsd.path = args->path;
485 bsd.flags = args->flags;
486 bsd.sysmsg_result = 0;
488 error = access(&bsd);
489 args->sysmsg_result = bsd.sysmsg_result;
494 linux_unlink(struct linux_unlink_args *args)
496 struct unlink_args bsd;
500 sg = stackgap_init();
501 CHECKALTEXIST(&sg, args->path);
505 printf(ARGS(unlink, "%s"), args->path);
507 bsd.path = args->path;
508 bsd.sysmsg_result = 0;
510 error = unlink(&bsd);
511 args->sysmsg_result = bsd.sysmsg_result;
516 linux_chdir(struct linux_chdir_args *args)
518 struct chdir_args bsd;
522 sg = stackgap_init();
523 CHECKALTEXIST(&sg, args->path);
527 printf(ARGS(chdir, "%s"), args->path);
529 bsd.path = args->path;
530 bsd.sysmsg_result = 0;
533 args->sysmsg_result = bsd.sysmsg_result;
538 linux_chmod(struct linux_chmod_args *args)
540 struct chmod_args bsd;
544 sg = stackgap_init();
545 CHECKALTEXIST(&sg, args->path);
549 printf(ARGS(chmod, "%s, %d"), args->path, args->mode);
551 bsd.path = args->path;
552 bsd.mode = args->mode;
553 bsd.sysmsg_result = 0;
556 args->sysmsg_result = bsd.sysmsg_result;
561 linux_mkdir(struct linux_mkdir_args *args)
563 struct mkdir_args bsd;
567 sg = stackgap_init();
568 CHECKALTCREAT(&sg, args->path);
572 printf(ARGS(mkdir, "%s, %d"), args->path, args->mode);
574 bsd.path = args->path;
575 bsd.mode = args->mode;
576 bsd.sysmsg_result = 0;
579 args->sysmsg_result = bsd.sysmsg_result;
584 linux_rmdir(struct linux_rmdir_args *args)
586 struct rmdir_args bsd;
590 sg = stackgap_init();
591 CHECKALTEXIST(&sg, args->path);
595 printf(ARGS(rmdir, "%s"), args->path);
597 bsd.path = args->path;
598 bsd.sysmsg_result = 0;
601 args->sysmsg_result = bsd.sysmsg_result;
606 linux_rename(struct linux_rename_args *args)
608 struct rename_args bsd;
612 sg = stackgap_init();
613 CHECKALTEXIST(&sg, args->from);
614 CHECKALTCREAT(&sg, args->to);
618 printf(ARGS(rename, "%s, %s"), args->from, args->to);
620 bsd.from = args->from;
622 bsd.sysmsg_result = 0;
624 error = rename(&bsd);
625 args->sysmsg_result = bsd.sysmsg_result;
630 linux_symlink(struct linux_symlink_args *args)
632 struct symlink_args bsd;
636 sg = stackgap_init();
637 CHECKALTEXIST(&sg, args->path);
638 CHECKALTCREAT(&sg, args->to);
642 printf(ARGS(symlink, "%s, %s"), args->path, args->to);
644 bsd.path = args->path;
646 bsd.sysmsg_result = 0;
648 error = symlink(&bsd);
649 args->sysmsg_result = bsd.sysmsg_result;
654 linux_readlink(struct linux_readlink_args *args)
656 struct readlink_args bsd;
660 sg = stackgap_init();
661 CHECKALTEXIST(&sg, args->name);
664 if (ldebug(readlink))
665 printf(ARGS(readlink, "%s, %p, %d"),
666 args->name, (void *)args->buf, args->count);
668 bsd.path = args->name;
670 bsd.count = args->count;
671 bsd.sysmsg_result = 0;
673 error = readlink(&bsd);
674 args->sysmsg_result = bsd.sysmsg_result;
679 linux_truncate(struct linux_truncate_args *args)
681 struct truncate_args bsd;
685 sg = stackgap_init();
686 CHECKALTEXIST(&sg, args->path);
689 if (ldebug(truncate))
690 printf(ARGS(truncate, "%s, %ld"), args->path,
693 bsd.path = args->path;
694 bsd.length = args->length;
695 bsd.sysmsg_result = 0;
697 error = truncate(&bsd);
698 args->sysmsg_result = bsd.sysmsg_result;
703 linux_link(struct linux_link_args *args)
705 struct link_args bsd;
709 sg = stackgap_init();
710 CHECKALTEXIST(&sg, args->path);
711 CHECKALTCREAT(&sg, args->to);
715 printf(ARGS(link, "%s, %s"), args->path, args->to);
718 bsd.path = args->path;
720 bsd.sysmsg_result = 0;
723 args->sysmsg_result = bsd.sysmsg_result;
729 linux_fdatasync(struct linux_fdatasync_args *uap)
731 struct fsync_args bsd;
735 bsd.sysmsg_result = 0;
738 uap->sysmsg_result = bsd.sysmsg_result;
741 #endif /*!__alpha__*/
744 linux_pread(struct linux_pread_args *uap)
746 struct thread *td = curthread;
751 aiov.iov_base = uap->buf;
752 aiov.iov_len = uap->nbyte;
753 auio.uio_iov = &aiov;
755 auio.uio_offset = uap->offset;
756 auio.uio_resid = uap->nbyte;
757 auio.uio_rw = UIO_READ;
758 auio.uio_segflg = UIO_USERSPACE;
761 error = kern_readv(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
767 linux_pwrite(struct linux_pwrite_args *uap)
769 struct thread *td = curthread;
774 aiov.iov_base = uap->buf;
775 aiov.iov_len = uap->nbyte;
776 auio.uio_iov = &aiov;
778 auio.uio_offset = uap->offset;
779 auio.uio_resid = uap->nbyte;
780 auio.uio_rw = UIO_WRITE;
781 auio.uio_segflg = UIO_USERSPACE;
784 error = kern_writev(uap->fd, &auio, FOF_OFFSET, &uap->sysmsg_result);
790 linux_oldumount(struct linux_oldumount_args *args)
792 struct linux_umount_args args2;
795 args2.path = args->path;
797 args2.sysmsg_result = 0;
798 error = linux_umount(&args2);
799 args->sysmsg_result = args2.sysmsg_result;
804 linux_umount(struct linux_umount_args *args)
806 struct unmount_args bsd;
809 bsd.path = args->path;
810 bsd.flags = args->flags; /* XXX correct? */
811 bsd.sysmsg_result = 0;
813 error = unmount(&bsd);
814 args->sysmsg_result = bsd.sysmsg_result;
819 * fcntl family of syscalls
831 linux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock)
833 switch (linux_flock->l_type) {
835 bsd_flock->l_type = F_RDLCK;
838 bsd_flock->l_type = F_WRLCK;
841 bsd_flock->l_type = F_UNLCK;
844 bsd_flock->l_type = -1;
847 bsd_flock->l_whence = linux_flock->l_whence;
848 bsd_flock->l_start = (off_t)linux_flock->l_start;
849 bsd_flock->l_len = (off_t)linux_flock->l_len;
850 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
854 bsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock)
856 switch (bsd_flock->l_type) {
858 linux_flock->l_type = LINUX_F_RDLCK;
861 linux_flock->l_type = LINUX_F_WRLCK;
864 linux_flock->l_type = LINUX_F_UNLCK;
867 linux_flock->l_whence = bsd_flock->l_whence;
868 linux_flock->l_start = (l_off_t)bsd_flock->l_start;
869 linux_flock->l_len = (l_off_t)bsd_flock->l_len;
870 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
873 #if defined(__i386__)
883 linux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock)
885 switch (linux_flock->l_type) {
887 bsd_flock->l_type = F_RDLCK;
890 bsd_flock->l_type = F_WRLCK;
893 bsd_flock->l_type = F_UNLCK;
896 bsd_flock->l_type = -1;
899 bsd_flock->l_whence = linux_flock->l_whence;
900 bsd_flock->l_start = (off_t)linux_flock->l_start;
901 bsd_flock->l_len = (off_t)linux_flock->l_len;
902 bsd_flock->l_pid = (pid_t)linux_flock->l_pid;
906 bsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock)
908 switch (bsd_flock->l_type) {
910 linux_flock->l_type = LINUX_F_RDLCK;
913 linux_flock->l_type = LINUX_F_WRLCK;
916 linux_flock->l_type = LINUX_F_UNLCK;
919 linux_flock->l_whence = bsd_flock->l_whence;
920 linux_flock->l_start = (l_loff_t)bsd_flock->l_start;
921 linux_flock->l_len = (l_loff_t)bsd_flock->l_len;
922 linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid;
924 #endif /* __i386__ */
926 #if defined(__alpha__)
927 #define linux_fcntl64_args linux_fcntl_args
931 linux_fcntl_common(struct linux_fcntl64_args *args)
933 struct proc *p = curproc;
934 struct l_flock linux_flock;
935 struct filedesc *fdp;
943 dat.fc_fd = args->arg;
950 dat.fc_cloexec = args->arg;
958 if (args->arg & LINUX_O_NDELAY)
959 dat.fc_flags |= O_NONBLOCK;
960 if (args->arg & LINUX_O_APPEND)
961 dat.fc_flags |= O_APPEND;
962 if (args->arg & LINUX_O_SYNC)
963 dat.fc_flags |= O_FSYNC;
964 if (args->arg & LINUX_FASYNC)
965 dat.fc_flags |= O_ASYNC;
971 error = copyin((caddr_t)args->arg, &linux_flock,
972 sizeof(linux_flock));
975 linux_to_bsd_flock(&linux_flock, &dat.fc_flock);
982 * XXX some Linux applications depend on F_SETOWN having no
983 * significant effect for pipes (SIGIO is not delivered for
984 * pipes under Linux-2.2.35 at least).
987 if ((u_int)args->fd >= fdp->fd_nfiles ||
988 (fp = fdp->fd_ofiles[args->fd]) == NULL)
990 if (fp->f_type == DTYPE_PIPE)
993 dat.fc_owner = args->arg;
999 error = kern_fcntl(args->fd, cmd, &dat);
1002 switch (args->cmd) {
1004 args->sysmsg_result = dat.fc_fd;
1007 args->sysmsg_result = dat.fc_cloexec;
1012 args->sysmsg_result = 0;
1013 if (dat.fc_flags & O_RDONLY)
1014 args->sysmsg_result |= LINUX_O_RDONLY;
1015 if (dat.fc_flags & O_WRONLY)
1016 args->sysmsg_result |= LINUX_O_WRONLY;
1017 if (dat.fc_flags & O_RDWR)
1018 args->sysmsg_result |= LINUX_O_RDWR;
1019 if (dat.fc_flags & O_NDELAY)
1020 args->sysmsg_result |= LINUX_O_NONBLOCK;
1021 if (dat.fc_flags & O_APPEND)
1022 args->sysmsg_result |= LINUX_O_APPEND;
1023 if (dat.fc_flags & O_FSYNC)
1024 args->sysmsg_result |= LINUX_O_SYNC;
1025 if (dat.fc_flags & O_ASYNC)
1026 args->sysmsg_result |= LINUX_FASYNC;
1029 bsd_to_linux_flock(&dat.fc_flock, &linux_flock);
1030 error = copyout(&linux_flock, (caddr_t)args->arg,
1031 sizeof(linux_flock));
1034 case LINUX_F_SETLKW:
1036 case LINUX_F_GETOWN:
1037 args->sysmsg_result = dat.fc_owner;
1039 case LINUX_F_SETOWN:
1048 linux_fcntl(struct linux_fcntl_args *args)
1050 struct linux_fcntl64_args args64;
1055 printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd);
1058 args64.fd = args->fd;
1059 args64.cmd = args->cmd;
1060 args64.arg = args->arg;
1061 args64.sysmsg_result = 0;
1062 error = linux_fcntl_common(&args64);
1063 args->sysmsg_result = args64.sysmsg_result;
1067 #if defined(__i386__)
1069 linux_fcntl64(struct linux_fcntl64_args *args)
1071 struct l_flock64 linux_flock;
1072 union fcntl_dat dat;
1076 if (ldebug(fcntl64))
1077 printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd);
1079 if (args->cmd == LINUX_F_GETLK64 || args->cmd == LINUX_F_SETLK64 ||
1080 args->cmd == LINUX_F_SETLKW64) {
1081 switch (args->cmd) {
1082 case LINUX_F_GETLK64:
1085 case LINUX_F_SETLK64:
1088 case LINUX_F_SETLKW64:
1093 error = copyin((caddr_t)args->arg, &linux_flock,
1094 sizeof(linux_flock));
1097 linux_to_bsd_flock64(&linux_flock, &dat.fc_flock);
1099 error = kern_fcntl(args->fd, cmd, &dat);
1101 if (error == 0 && args->cmd == LINUX_F_GETLK64) {
1102 bsd_to_linux_flock64(&dat.fc_flock, &linux_flock);
1103 error = copyout(&linux_flock, (caddr_t)args->arg,
1104 sizeof(linux_flock));
1107 error = linux_fcntl_common(args);
1112 #endif /* __i386__ */
1115 linux_chown(struct linux_chown_args *args)
1117 struct chown_args bsd;
1121 sg = stackgap_init();
1122 CHECKALTEXIST(&sg, args->path);
1126 printf(ARGS(chown, "%s, %d, %d"), args->path, args->uid,
1130 bsd.path = args->path;
1131 bsd.uid = args->uid;
1132 bsd.gid = args->gid;
1133 bsd.sysmsg_result = 0;
1134 error = chown(&bsd);
1135 args->sysmsg_result = bsd.sysmsg_result;
1140 linux_lchown(struct linux_lchown_args *args)
1142 struct lchown_args bsd;
1146 sg = stackgap_init();
1147 CHECKALTEXIST(&sg, args->path);
1151 printf(ARGS(lchown, "%s, %d, %d"), args->path, args->uid,
1155 bsd.path = args->path;
1156 bsd.uid = args->uid;
1157 bsd.gid = args->gid;
1158 bsd.sysmsg_result = 0;
1160 error = lchown(&bsd);
1161 args->sysmsg_result = bsd.sysmsg_result;