linux_file.c revision 127057
19313Ssos/*- 29313Ssos * Copyright (c) 1994-1995 S�ren Schmidt 39313Ssos * All rights reserved. 49313Ssos * 59313Ssos * Redistribution and use in source and binary forms, with or without 69313Ssos * modification, are permitted provided that the following conditions 79313Ssos * are met: 89313Ssos * 1. Redistributions of source code must retain the above copyright 9111798Sdes * notice, this list of conditions and the following disclaimer 109313Ssos * in this position and unchanged. 119313Ssos * 2. Redistributions in binary form must reproduce the above copyright 129313Ssos * notice, this list of conditions and the following disclaimer in the 139313Ssos * documentation and/or other materials provided with the distribution. 149313Ssos * 3. The name of the author may not be used to endorse or promote products 1597748Sschweikh * derived from this software without specific prior written permission 169313Ssos * 179313Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 189313Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 199313Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 209313Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 219313Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 229313Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239313Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249313Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259313Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 269313Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279313Ssos */ 289313Ssos 29116173Sobrien#include <sys/cdefs.h> 30116173Sobrien__FBSDID("$FreeBSD: head/sys/compat/linux/linux_file.c 127057 2004-03-16 08:37:19Z tjr $"); 31116173Sobrien 3231784Seivind#include "opt_compat.h" 33101189Srwatson#include "opt_mac.h" 3431784Seivind 359313Ssos#include <sys/param.h> 369313Ssos#include <sys/systm.h> 3776166Smarkm#include <sys/conf.h> 3876166Smarkm#include <sys/dirent.h> 399313Ssos#include <sys/fcntl.h> 409313Ssos#include <sys/file.h> 419313Ssos#include <sys/filedesc.h> 4231561Sbde#include <sys/lock.h> 43101189Srwatson#include <sys/mac.h> 449313Ssos#include <sys/malloc.h> 4572538Sjlemon#include <sys/mount.h> 4676166Smarkm#include <sys/mutex.h> 4776166Smarkm#include <sys/proc.h> 48102814Siedowse#include <sys/syscallsubr.h> 4976166Smarkm#include <sys/sysproto.h> 5014331Speter#include <sys/tty.h> 5176166Smarkm#include <sys/vnode.h> 5212458Sbde 5372538Sjlemon#include <ufs/ufs/extattr.h> 5472538Sjlemon#include <ufs/ufs/quota.h> 5572538Sjlemon#include <ufs/ufs/ufsmount.h> 5672538Sjlemon 5764905Smarcel#include <machine/../linux/linux.h> 5868583Smarcel#include <machine/../linux/linux_proto.h> 5964905Smarcel#include <compat/linux/linux_util.h> 609313Ssos 6168201Sobrien#ifndef __alpha__ 629313Ssosint 6383366Sjulianlinux_creat(struct thread *td, struct linux_creat_args *args) 649313Ssos{ 65102814Siedowse char *path; 66102814Siedowse int error; 679313Ssos 68102814Siedowse LCONVPATHEXIST(td, args->path, &path); 6914331Speter 709313Ssos#ifdef DEBUG 7172543Sjlemon if (ldebug(creat)) 72102814Siedowse printf(ARGS(creat, "%s, %d"), path, args->mode); 739313Ssos#endif 74102814Siedowse error = kern_open(td, path, UIO_SYSSPACE, O_WRONLY | O_CREAT | O_TRUNC, 75102814Siedowse args->mode); 76102814Siedowse LFREEPATH(path); 77102814Siedowse return (error); 789313Ssos} 7968201Sobrien#endif /*!__alpha__*/ 809313Ssos 819313Ssosint 8283366Sjulianlinux_open(struct thread *td, struct linux_open_args *args) 839313Ssos{ 8483382Sjhb struct proc *p = td->td_proc; 85102814Siedowse char *path; 86102814Siedowse int bsd_flags, error; 8714331Speter 8814331Speter if (args->flags & LINUX_O_CREAT) 89102814Siedowse LCONVPATHCREAT(td, args->path, &path); 9014331Speter else 91102814Siedowse LCONVPATHEXIST(td, args->path, &path); 9214331Speter 939313Ssos#ifdef DEBUG 9472543Sjlemon if (ldebug(open)) 9572543Sjlemon printf(ARGS(open, "%s, 0x%x, 0x%x"), 96102814Siedowse path, args->flags, args->mode); 979313Ssos#endif 98102814Siedowse bsd_flags = 0; 999313Ssos if (args->flags & LINUX_O_RDONLY) 100102814Siedowse bsd_flags |= O_RDONLY; 101111798Sdes if (args->flags & LINUX_O_WRONLY) 102102814Siedowse bsd_flags |= O_WRONLY; 1039313Ssos if (args->flags & LINUX_O_RDWR) 104102814Siedowse bsd_flags |= O_RDWR; 1059313Ssos if (args->flags & LINUX_O_NDELAY) 106102814Siedowse bsd_flags |= O_NONBLOCK; 1079313Ssos if (args->flags & LINUX_O_APPEND) 108102814Siedowse bsd_flags |= O_APPEND; 1099313Ssos if (args->flags & LINUX_O_SYNC) 110102814Siedowse bsd_flags |= O_FSYNC; 1119313Ssos if (args->flags & LINUX_O_NONBLOCK) 112102814Siedowse bsd_flags |= O_NONBLOCK; 1139313Ssos if (args->flags & LINUX_FASYNC) 114102814Siedowse bsd_flags |= O_ASYNC; 1159313Ssos if (args->flags & LINUX_O_CREAT) 116102814Siedowse bsd_flags |= O_CREAT; 1179313Ssos if (args->flags & LINUX_O_TRUNC) 118102814Siedowse bsd_flags |= O_TRUNC; 1199313Ssos if (args->flags & LINUX_O_EXCL) 120102814Siedowse bsd_flags |= O_EXCL; 1219313Ssos if (args->flags & LINUX_O_NOCTTY) 122102814Siedowse bsd_flags |= O_NOCTTY; 1239313Ssos 124102814Siedowse error = kern_open(td, path, UIO_SYSSPACE, bsd_flags, args->mode); 12570061Sjhb PROC_LOCK(p); 126102814Siedowse if (!error && !(bsd_flags & O_NOCTTY) && 1279313Ssos SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { 12889306Salfred struct file *fp; 1299313Ssos 130113917Sjhb PROC_UNLOCK(p); 13189319Salfred error = fget(td, td->td_retval[0], &fp); 13289319Salfred if (!error) { 13389319Salfred if (fp->f_type == DTYPE_VNODE) 134102003Srwatson fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, td->td_ucred, 135102003Srwatson td); 13689319Salfred fdrop(fp, td); 13789319Salfred } 13891140Stanimura } else { 13970061Sjhb PROC_UNLOCK(p); 14014331Speter#ifdef DEBUG 14172543Sjlemon if (ldebug(open)) 14272543Sjlemon printf(LMSG("open returns error %d"), error); 14314331Speter#endif 14491140Stanimura } 145102814Siedowse LFREEPATH(path); 1469313Ssos return error; 1479313Ssos} 1489313Ssos 1499313Ssosint 15083366Sjulianlinux_lseek(struct thread *td, struct linux_lseek_args *args) 1519313Ssos{ 1529313Ssos 15312858Speter struct lseek_args /* { 15412858Speter int fd; 1559313Ssos int pad; 15612858Speter off_t offset; 1579313Ssos int whence; 15812858Speter } */ tmp_args; 1599313Ssos int error; 1609313Ssos 1619313Ssos#ifdef DEBUG 16272543Sjlemon if (ldebug(lseek)) 16372543Sjlemon printf(ARGS(lseek, "%d, %ld, %d"), 16483221Smarcel args->fdes, (long)args->off, args->whence); 1659313Ssos#endif 16612858Speter tmp_args.fd = args->fdes; 16712858Speter tmp_args.offset = (off_t)args->off; 1689313Ssos tmp_args.whence = args->whence; 16983366Sjulian error = lseek(td, &tmp_args); 1709313Ssos return error; 1719313Ssos} 1729313Ssos 17368201Sobrien#ifndef __alpha__ 17414331Speterint 17583366Sjulianlinux_llseek(struct thread *td, struct linux_llseek_args *args) 17614331Speter{ 17714331Speter struct lseek_args bsd_args; 17814331Speter int error; 17914331Speter off_t off; 18014331Speter 18114331Speter#ifdef DEBUG 18272543Sjlemon if (ldebug(llseek)) 18372543Sjlemon printf(ARGS(llseek, "%d, %d:%d, %d"), 18472543Sjlemon args->fd, args->ohigh, args->olow, args->whence); 18514331Speter#endif 18614331Speter off = (args->olow) | (((off_t) args->ohigh) << 32); 18714331Speter 18814331Speter bsd_args.fd = args->fd; 18914331Speter bsd_args.offset = off; 19014331Speter bsd_args.whence = args->whence; 19114331Speter 19283366Sjulian if ((error = lseek(td, &bsd_args))) 19314331Speter return error; 19414331Speter 195111797Sdes if ((error = copyout(td->td_retval, args->res, sizeof (off_t)))) 19614331Speter return error; 19714331Speter 19883366Sjulian td->td_retval[0] = 0; 19914331Speter return 0; 20014331Speter} 20168201Sobrien#endif /*!__alpha__*/ 20214331Speter 20368201Sobrien#ifndef __alpha__ 2049313Ssosint 20583366Sjulianlinux_readdir(struct thread *td, struct linux_readdir_args *args) 2069313Ssos{ 20714331Speter struct linux_getdents_args lda; 20814331Speter 20914331Speter lda.fd = args->fd; 21014331Speter lda.dent = args->dent; 21114331Speter lda.count = 1; 21283366Sjulian return linux_getdents(td, &lda); 21314331Speter} 21468201Sobrien#endif /*!__alpha__*/ 21514331Speter 21683221Smarcel/* 21783221Smarcel * Note that linux_getdents(2) and linux_getdents64(2) have the same 21883221Smarcel * arguments. They only differ in the definition of struct dirent they 21983221Smarcel * operate on. We use this to common the code, with the exception of 22083221Smarcel * accessing struct dirent. Note that linux_readdir(2) is implemented 22183221Smarcel * by means of linux_getdents(2). In this case we never operate on 22283221Smarcel * struct dirent64 and thus don't need to handle it... 22383221Smarcel */ 22483221Smarcel 22583221Smarcelstruct l_dirent { 22683221Smarcel l_long d_ino; 22783221Smarcel l_off_t d_off; 22883221Smarcel l_ushort d_reclen; 22983221Smarcel char d_name[LINUX_NAME_MAX + 1]; 23083221Smarcel}; 23183221Smarcel 23283221Smarcelstruct l_dirent64 { 23383221Smarcel uint64_t d_ino; 23483221Smarcel int64_t d_off; 23583221Smarcel l_ushort d_reclen; 23683221Smarcel u_char d_type; 23783221Smarcel char d_name[LINUX_NAME_MAX + 1]; 23883221Smarcel}; 23983221Smarcel 24083221Smarcel#define LINUX_RECLEN(de,namlen) \ 24183221Smarcel ALIGN((((char *)&(de)->d_name - (char *)de) + (namlen) + 1)) 24283221Smarcel 24383221Smarcel#define LINUX_DIRBLKSIZ 512 24483221Smarcel 24583221Smarcelstatic int 24683366Sjuliangetdents_common(struct thread *td, struct linux_getdents64_args *args, 24783221Smarcel int is64bit) 24814331Speter{ 249111798Sdes struct dirent *bdp; 25083221Smarcel struct vnode *vp; 25183221Smarcel caddr_t inp, buf; /* BSD-format */ 25283221Smarcel int len, reclen; /* BSD-format */ 25383221Smarcel caddr_t outp; /* Linux-format */ 25483221Smarcel int resid, linuxreclen=0; /* Linux-format */ 25583221Smarcel struct file *fp; 25683221Smarcel struct uio auio; 25783221Smarcel struct iovec aiov; 25883221Smarcel off_t off; 25983221Smarcel struct l_dirent linux_dirent; 26083221Smarcel struct l_dirent64 linux_dirent64; 26183221Smarcel int buflen, error, eofflag, nbytes, justone; 26283221Smarcel u_long *cookies = NULL, *cookiep; 26383221Smarcel int ncookies; 2649313Ssos 26583366Sjulian if ((error = getvnode(td->td_proc->p_fd, args->fd, &fp)) != 0) 26683221Smarcel return (error); 2679313Ssos 26889306Salfred if ((fp->f_flag & FREAD) == 0) { 26989306Salfred fdrop(fp, td); 27083221Smarcel return (EBADF); 27189306Salfred } 2729313Ssos 273116678Sphk vp = fp->f_vnode; 27489306Salfred if (vp->v_type != VDIR) { 27589306Salfred fdrop(fp, td); 27683221Smarcel return (EINVAL); 27789306Salfred } 2789313Ssos 27983221Smarcel nbytes = args->count; 28083221Smarcel if (nbytes == 1) { 28183221Smarcel /* readdir(2) case. Always struct dirent. */ 28289306Salfred if (is64bit) { 28389306Salfred fdrop(fp, td); 28483221Smarcel return (EINVAL); 28589306Salfred } 28683221Smarcel nbytes = sizeof(linux_dirent); 28783221Smarcel justone = 1; 28883221Smarcel } else 28983221Smarcel justone = 0; 2909313Ssos 29183221Smarcel off = fp->f_offset; 2929313Ssos 29383221Smarcel buflen = max(LINUX_DIRBLKSIZ, nbytes); 29483221Smarcel buflen = min(buflen, MAXBSIZE); 295111119Simp buf = malloc(buflen, M_TEMP, M_WAITOK); 29683366Sjulian vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 29783221Smarcel 2989313Ssosagain: 29983221Smarcel aiov.iov_base = buf; 30083221Smarcel aiov.iov_len = buflen; 30183221Smarcel auio.uio_iov = &aiov; 30283221Smarcel auio.uio_iovcnt = 1; 30383221Smarcel auio.uio_rw = UIO_READ; 30483221Smarcel auio.uio_segflg = UIO_SYSSPACE; 30583366Sjulian auio.uio_td = td; 30683221Smarcel auio.uio_resid = buflen; 30783221Smarcel auio.uio_offset = off; 3089313Ssos 30983221Smarcel if (cookies) { 31083221Smarcel free(cookies, M_TEMP); 31183221Smarcel cookies = NULL; 31283221Smarcel } 31324654Sdfr 314101189Srwatson#ifdef MAC 315101189Srwatson /* 316101189Srwatson * Do directory search MAC check using non-cached credentials. 317101189Srwatson */ 318112451Sjhb if ((error = mac_check_vnode_readdir(td->td_ucred, vp))) 319101189Srwatson goto out; 320101189Srwatson#endif /* MAC */ 32183221Smarcel if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, 32283221Smarcel &cookies))) 32383221Smarcel goto out; 3249313Ssos 32583221Smarcel inp = buf; 32683221Smarcel outp = (caddr_t)args->dirent; 32783221Smarcel resid = nbytes; 32883221Smarcel if ((len = buflen - auio.uio_resid) <= 0) 32983221Smarcel goto eof; 3309313Ssos 33183221Smarcel cookiep = cookies; 33224654Sdfr 33383221Smarcel if (cookies) { 33483221Smarcel /* 33583221Smarcel * When using cookies, the vfs has the option of reading from 33683221Smarcel * a different offset than that supplied (UFS truncates the 33783221Smarcel * offset to a block boundary to make sure that it never reads 33883221Smarcel * partway through a directory entry, even if the directory 33983221Smarcel * has been compacted). 34083221Smarcel */ 34183221Smarcel while (len > 0 && ncookies > 0 && *cookiep <= off) { 34283221Smarcel bdp = (struct dirent *) inp; 34383221Smarcel len -= bdp->d_reclen; 34483221Smarcel inp += bdp->d_reclen; 34583221Smarcel cookiep++; 34683221Smarcel ncookies--; 34783221Smarcel } 34824654Sdfr } 34924654Sdfr 35083221Smarcel while (len > 0) { 35183221Smarcel if (cookiep && ncookies == 0) 35283221Smarcel break; 35383221Smarcel bdp = (struct dirent *) inp; 35483221Smarcel reclen = bdp->d_reclen; 35583221Smarcel if (reclen & 3) { 35683221Smarcel error = EFAULT; 35783221Smarcel goto out; 35883221Smarcel } 35983221Smarcel 36083221Smarcel if (bdp->d_fileno == 0) { 36183221Smarcel inp += reclen; 36283221Smarcel if (cookiep) { 36383221Smarcel off = *cookiep++; 36483221Smarcel ncookies--; 36583221Smarcel } else 36683221Smarcel off += reclen; 36783221Smarcel 36883221Smarcel len -= reclen; 36983221Smarcel continue; 37083221Smarcel } 37183221Smarcel 37283221Smarcel linuxreclen = (is64bit) 37383221Smarcel ? LINUX_RECLEN(&linux_dirent64, bdp->d_namlen) 37483221Smarcel : LINUX_RECLEN(&linux_dirent, bdp->d_namlen); 37583221Smarcel 37683221Smarcel if (reclen > len || resid < linuxreclen) { 37783221Smarcel outp++; 37883221Smarcel break; 37983221Smarcel } 38083221Smarcel 38183221Smarcel if (justone) { 38283221Smarcel /* readdir(2) case. */ 38383221Smarcel linux_dirent.d_ino = (l_long)bdp->d_fileno; 38483221Smarcel linux_dirent.d_off = (l_off_t)linuxreclen; 38583221Smarcel linux_dirent.d_reclen = (l_ushort)bdp->d_namlen; 38683221Smarcel strcpy(linux_dirent.d_name, bdp->d_name); 38783221Smarcel error = copyout(&linux_dirent, outp, linuxreclen); 38883221Smarcel } else { 38983221Smarcel if (is64bit) { 39083221Smarcel linux_dirent64.d_ino = bdp->d_fileno; 39183221Smarcel linux_dirent64.d_off = (cookiep) 39283221Smarcel ? (l_off_t)*cookiep 39383221Smarcel : (l_off_t)(off + reclen); 39483221Smarcel linux_dirent64.d_reclen = 39583221Smarcel (l_ushort)linuxreclen; 39683221Smarcel linux_dirent64.d_type = bdp->d_type; 39783221Smarcel strcpy(linux_dirent64.d_name, bdp->d_name); 39883221Smarcel error = copyout(&linux_dirent64, outp, 39983221Smarcel linuxreclen); 40083221Smarcel } else { 40183221Smarcel linux_dirent.d_ino = bdp->d_fileno; 40283221Smarcel linux_dirent.d_off = (cookiep) 40383221Smarcel ? (l_off_t)*cookiep 40483221Smarcel : (l_off_t)(off + reclen); 40583221Smarcel linux_dirent.d_reclen = (l_ushort)linuxreclen; 40683221Smarcel strcpy(linux_dirent.d_name, bdp->d_name); 40783221Smarcel error = copyout(&linux_dirent, outp, 40883221Smarcel linuxreclen); 40983221Smarcel } 41083221Smarcel } 41183221Smarcel if (error) 41283221Smarcel goto out; 41383221Smarcel 41483221Smarcel inp += reclen; 41583221Smarcel if (cookiep) { 41683221Smarcel off = *cookiep++; 41783221Smarcel ncookies--; 41883221Smarcel } else 41983221Smarcel off += reclen; 42083221Smarcel 42183221Smarcel outp += linuxreclen; 42283221Smarcel resid -= linuxreclen; 42383221Smarcel len -= reclen; 42483221Smarcel if (justone) 42583221Smarcel break; 42610355Sswallace } 4279313Ssos 42883221Smarcel if (outp == (caddr_t)args->dirent) 42983221Smarcel goto again; 4309313Ssos 43183221Smarcel fp->f_offset = off; 43283221Smarcel if (justone) 43383221Smarcel nbytes = resid + linuxreclen; 43410355Sswallace 4359313Ssoseof: 43683366Sjulian td->td_retval[0] = nbytes - resid; 43783221Smarcel 4389313Ssosout: 43983221Smarcel if (cookies) 44083221Smarcel free(cookies, M_TEMP); 44183221Smarcel 44283366Sjulian VOP_UNLOCK(vp, 0, td); 44389306Salfred fdrop(fp, td); 44483221Smarcel free(buf, M_TEMP); 44583221Smarcel return (error); 4469313Ssos} 44714331Speter 44883221Smarcelint 44983366Sjulianlinux_getdents(struct thread *td, struct linux_getdents_args *args) 45083221Smarcel{ 45183221Smarcel 45283221Smarcel#ifdef DEBUG 45383221Smarcel if (ldebug(getdents)) 45483221Smarcel printf(ARGS(getdents, "%d, *, %d"), args->fd, args->count); 45583221Smarcel#endif 45683221Smarcel 45783366Sjulian return (getdents_common(td, (struct linux_getdents64_args*)args, 0)); 45883221Smarcel} 45983221Smarcel 46083221Smarcelint 46183366Sjulianlinux_getdents64(struct thread *td, struct linux_getdents64_args *args) 46283221Smarcel{ 46383221Smarcel 46483221Smarcel#ifdef DEBUG 46583221Smarcel if (ldebug(getdents64)) 46683221Smarcel printf(ARGS(getdents64, "%d, *, %d"), args->fd, args->count); 46783221Smarcel#endif 46883221Smarcel 46983366Sjulian return (getdents_common(td, args, 1)); 47083221Smarcel} 47183221Smarcel 47214331Speter/* 47314331Speter * These exist mainly for hooks for doing /compat/linux translation. 47414331Speter */ 47514331Speter 47614331Speterint 47783366Sjulianlinux_access(struct thread *td, struct linux_access_args *args) 47814331Speter{ 479102814Siedowse char *path; 480102814Siedowse int error; 48114331Speter 482102814Siedowse LCONVPATHEXIST(td, args->path, &path); 48314331Speter 48414331Speter#ifdef DEBUG 48572543Sjlemon if (ldebug(access)) 486102814Siedowse printf(ARGS(access, "%s, %d"), path, args->flags); 48714331Speter#endif 488102814Siedowse error = kern_access(td, path, UIO_SYSSPACE, args->flags); 489102814Siedowse LFREEPATH(path); 490102814Siedowse return (error); 49114331Speter} 49214331Speter 49314331Speterint 49483366Sjulianlinux_unlink(struct thread *td, struct linux_unlink_args *args) 49514331Speter{ 496102814Siedowse char *path; 497102814Siedowse int error; 49814331Speter 499102814Siedowse LCONVPATHEXIST(td, args->path, &path); 50014331Speter 50114331Speter#ifdef DEBUG 50272543Sjlemon if (ldebug(unlink)) 503102814Siedowse printf(ARGS(unlink, "%s"), path); 50414331Speter#endif 50514331Speter 506102814Siedowse error = kern_unlink(td, path, UIO_SYSSPACE); 507102814Siedowse LFREEPATH(path); 508102814Siedowse return (error); 50914331Speter} 51014331Speter 51114331Speterint 51283366Sjulianlinux_chdir(struct thread *td, struct linux_chdir_args *args) 51314331Speter{ 514102814Siedowse char *path; 515102814Siedowse int error; 51614331Speter 517102814Siedowse LCONVPATHEXIST(td, args->path, &path); 51814331Speter 51914331Speter#ifdef DEBUG 52072543Sjlemon if (ldebug(chdir)) 521102814Siedowse printf(ARGS(chdir, "%s"), path); 52214331Speter#endif 523102814Siedowse error = kern_chdir(td, path, UIO_SYSSPACE); 524102814Siedowse LFREEPATH(path); 525102814Siedowse return (error); 52614331Speter} 52714331Speter 52814331Speterint 52983366Sjulianlinux_chmod(struct thread *td, struct linux_chmod_args *args) 53014331Speter{ 531102814Siedowse char *path; 532102814Siedowse int error; 53314331Speter 534102814Siedowse LCONVPATHEXIST(td, args->path, &path); 53514331Speter 53614331Speter#ifdef DEBUG 53772543Sjlemon if (ldebug(chmod)) 538102814Siedowse printf(ARGS(chmod, "%s, %d"), path, args->mode); 53914331Speter#endif 540102814Siedowse error = kern_chmod(td, path, UIO_SYSSPACE, args->mode); 541102814Siedowse LFREEPATH(path); 542102814Siedowse return (error); 54314331Speter} 54414331Speter 54514331Speterint 54683366Sjulianlinux_mkdir(struct thread *td, struct linux_mkdir_args *args) 54714331Speter{ 548102814Siedowse char *path; 549102814Siedowse int error; 55014331Speter 551102814Siedowse LCONVPATHCREAT(td, args->path, &path); 55214331Speter 55314331Speter#ifdef DEBUG 55472543Sjlemon if (ldebug(mkdir)) 555102814Siedowse printf(ARGS(mkdir, "%s, %d"), path, args->mode); 55614331Speter#endif 557102814Siedowse error = kern_mkdir(td, path, UIO_SYSSPACE, args->mode); 558102814Siedowse LFREEPATH(path); 559102814Siedowse return (error); 56014331Speter} 56114331Speter 56214331Speterint 56383366Sjulianlinux_rmdir(struct thread *td, struct linux_rmdir_args *args) 56414331Speter{ 565102814Siedowse char *path; 566102814Siedowse int error; 56714331Speter 568102814Siedowse LCONVPATHEXIST(td, args->path, &path); 56914331Speter 57014331Speter#ifdef DEBUG 57172543Sjlemon if (ldebug(rmdir)) 572102814Siedowse printf(ARGS(rmdir, "%s"), path); 57314331Speter#endif 574102814Siedowse error = kern_rmdir(td, path, UIO_SYSSPACE); 575102814Siedowse LFREEPATH(path); 576102814Siedowse return (error); 57714331Speter} 57814331Speter 57914331Speterint 58083366Sjulianlinux_rename(struct thread *td, struct linux_rename_args *args) 58114331Speter{ 582102814Siedowse char *from, *to; 583102814Siedowse int error; 58414331Speter 585102814Siedowse LCONVPATHEXIST(td, args->from, &from); 586102814Siedowse /* Expand LCONVPATHCREATE so that `from' can be freed on errors */ 587102814Siedowse error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1); 588102814Siedowse if (to == NULL) { 589102814Siedowse LFREEPATH(from); 590102814Siedowse return (error); 591102814Siedowse } 59214331Speter 59314331Speter#ifdef DEBUG 59472543Sjlemon if (ldebug(rename)) 595102814Siedowse printf(ARGS(rename, "%s, %s"), from, to); 59614331Speter#endif 597102814Siedowse error = kern_rename(td, from, to, UIO_SYSSPACE); 598102814Siedowse LFREEPATH(from); 599102814Siedowse LFREEPATH(to); 600102814Siedowse return (error); 60114331Speter} 60214331Speter 60314331Speterint 60483366Sjulianlinux_symlink(struct thread *td, struct linux_symlink_args *args) 60514331Speter{ 606102814Siedowse char *path, *to; 607102814Siedowse int error; 60814331Speter 609102814Siedowse LCONVPATHEXIST(td, args->path, &path); 610102814Siedowse /* Expand LCONVPATHCREATE so that `path' can be freed on errors */ 611102814Siedowse error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1); 612102814Siedowse if (to == NULL) { 613102814Siedowse LFREEPATH(path); 614102814Siedowse return (error); 615102814Siedowse } 61614331Speter 61714331Speter#ifdef DEBUG 61872543Sjlemon if (ldebug(symlink)) 619102814Siedowse printf(ARGS(symlink, "%s, %s"), path, to); 62014331Speter#endif 621102814Siedowse error = kern_symlink(td, path, to, UIO_SYSSPACE); 622102814Siedowse LFREEPATH(path); 623102814Siedowse LFREEPATH(to); 624102814Siedowse return (error); 62514331Speter} 62614331Speter 62714331Speterint 62883366Sjulianlinux_readlink(struct thread *td, struct linux_readlink_args *args) 62914331Speter{ 630102814Siedowse char *name; 631102814Siedowse int error; 63214331Speter 633102814Siedowse LCONVPATHEXIST(td, args->name, &name); 63414331Speter 63514331Speter#ifdef DEBUG 63672543Sjlemon if (ldebug(readlink)) 637102814Siedowse printf(ARGS(readlink, "%s, %p, %d"), name, (void *)args->buf, 638102814Siedowse args->count); 63914331Speter#endif 640102814Siedowse error = kern_readlink(td, name, UIO_SYSSPACE, args->buf, UIO_USERSPACE, 641102814Siedowse args->count); 642102814Siedowse LFREEPATH(name); 643102814Siedowse return (error); 64414331Speter} 64514331Speter 64614331Speterint 64783366Sjulianlinux_truncate(struct thread *td, struct linux_truncate_args *args) 64814331Speter{ 649102814Siedowse char *path; 650102814Siedowse int error; 65114331Speter 652102814Siedowse LCONVPATHEXIST(td, args->path, &path); 65314331Speter 65414331Speter#ifdef DEBUG 65572543Sjlemon if (ldebug(truncate)) 656102814Siedowse printf(ARGS(truncate, "%s, %ld"), path, (long)args->length); 65714331Speter#endif 65814331Speter 659102814Siedowse error = kern_truncate(td, path, UIO_SYSSPACE, args->length); 660102814Siedowse LFREEPATH(path); 661102814Siedowse return (error); 66214331Speter} 66314331Speter 66449662Smarcelint 66583366Sjulianlinux_link(struct thread *td, struct linux_link_args *args) 66649662Smarcel{ 667102814Siedowse char *path, *to; 668102814Siedowse int error; 66949662Smarcel 670102814Siedowse LCONVPATHEXIST(td, args->path, &path); 671102814Siedowse /* Expand LCONVPATHCREATE so that `path' can be freed on errors */ 672102814Siedowse error = linux_emul_convpath(td, args->to, UIO_USERSPACE, &to, 1); 673102814Siedowse if (to == NULL) { 674102814Siedowse LFREEPATH(path); 675102814Siedowse return (error); 676102814Siedowse } 67749662Smarcel 67849662Smarcel#ifdef DEBUG 67972543Sjlemon if (ldebug(link)) 680102814Siedowse printf(ARGS(link, "%s, %s"), path, to); 68149662Smarcel#endif 682102814Siedowse error = kern_link(td, path, to, UIO_SYSSPACE); 683102814Siedowse LFREEPATH(path); 684102814Siedowse LFREEPATH(to); 685102814Siedowse return (error); 68649662Smarcel} 68749788Smarcel 68868201Sobrien#ifndef __alpha__ 68953713Smarcelint 69083366Sjulianlinux_fdatasync(td, uap) 69183366Sjulian struct thread *td; 69253713Smarcel struct linux_fdatasync_args *uap; 69353713Smarcel{ 69453713Smarcel struct fsync_args bsd; 69553713Smarcel 69653713Smarcel bsd.fd = uap->fd; 69783366Sjulian return fsync(td, &bsd); 69853713Smarcel} 69968201Sobrien#endif /*!__alpha__*/ 70063285Smarcel 70163285Smarcelint 70283366Sjulianlinux_pread(td, uap) 70383366Sjulian struct thread *td; 70463285Smarcel struct linux_pread_args *uap; 70563285Smarcel{ 70663285Smarcel struct pread_args bsd; 70763285Smarcel 70863285Smarcel bsd.fd = uap->fd; 70963285Smarcel bsd.buf = uap->buf; 71063285Smarcel bsd.nbyte = uap->nbyte; 71163285Smarcel bsd.offset = uap->offset; 71283366Sjulian return pread(td, &bsd); 71363285Smarcel} 71463285Smarcel 71563285Smarcelint 71683366Sjulianlinux_pwrite(td, uap) 71783366Sjulian struct thread *td; 71863285Smarcel struct linux_pwrite_args *uap; 71963285Smarcel{ 72063285Smarcel struct pwrite_args bsd; 72163285Smarcel 72263285Smarcel bsd.fd = uap->fd; 72363285Smarcel bsd.buf = uap->buf; 72463285Smarcel bsd.nbyte = uap->nbyte; 72563285Smarcel bsd.offset = uap->offset; 72683366Sjulian return pwrite(td, &bsd); 72763285Smarcel} 72872538Sjlemon 72972538Sjlemonint 73083366Sjulianlinux_mount(struct thread *td, struct linux_mount_args *args) 73172538Sjlemon{ 73272538Sjlemon struct ufs_args ufs; 733111798Sdes char fstypename[MFSNAMELEN]; 734111798Sdes char mntonname[MNAMELEN], mntfromname[MNAMELEN]; 73573286Sadrian int error; 73673286Sadrian int fsflags; 73773286Sadrian const char *fstype; 73873286Sadrian void *fsdata; 73972538Sjlemon 740111798Sdes error = copyinstr(args->filesystemtype, fstypename, MFSNAMELEN - 1, 74173286Sadrian NULL); 74272538Sjlemon if (error) 743111798Sdes return (error); 744127057Stjr error = copyinstr(args->specialfile, mntfromname, MNAMELEN - 1, NULL); 74572538Sjlemon if (error) 746111798Sdes return (error); 747127057Stjr error = copyinstr(args->dir, mntonname, MNAMELEN - 1, NULL); 74872538Sjlemon if (error) 749111798Sdes return (error); 75072538Sjlemon 75172538Sjlemon#ifdef DEBUG 75272538Sjlemon if (ldebug(mount)) 75372538Sjlemon printf(ARGS(mount, "%s, %s, %s"), 75472538Sjlemon fstypename, mntfromname, mntonname); 75572538Sjlemon#endif 75672538Sjlemon 75772538Sjlemon if (strcmp(fstypename, "ext2") == 0) { 75873286Sadrian fstype = "ext2fs"; 75973286Sadrian fsdata = &ufs; 76072538Sjlemon ufs.fspec = mntfromname; 76172538Sjlemon#define DEFAULT_ROOTID -2 76272538Sjlemon ufs.export.ex_root = DEFAULT_ROOTID; 76372538Sjlemon ufs.export.ex_flags = 76472538Sjlemon args->rwflag & LINUX_MS_RDONLY ? MNT_EXRDONLY : 0; 76572538Sjlemon } else if (strcmp(fstypename, "proc") == 0) { 76673286Sadrian fstype = "linprocfs"; 76773286Sadrian fsdata = NULL; 76872538Sjlemon } else { 76972538Sjlemon return (ENODEV); 77072538Sjlemon } 77172538Sjlemon 77273286Sadrian fsflags = 0; 77372538Sjlemon 77472538Sjlemon if ((args->rwflag & 0xffff0000) == 0xc0ed0000) { 77572538Sjlemon /* 77672538Sjlemon * Linux SYNC flag is not included; the closest equivalent 77772538Sjlemon * FreeBSD has is !ASYNC, which is our default. 77872538Sjlemon */ 77972538Sjlemon if (args->rwflag & LINUX_MS_RDONLY) 780111798Sdes fsflags |= MNT_RDONLY; 78172538Sjlemon if (args->rwflag & LINUX_MS_NOSUID) 782111798Sdes fsflags |= MNT_NOSUID; 78372538Sjlemon if (args->rwflag & LINUX_MS_NODEV) 784111798Sdes fsflags |= MNT_NODEV; 78572538Sjlemon if (args->rwflag & LINUX_MS_NOEXEC) 786111798Sdes fsflags |= MNT_NOEXEC; 78772538Sjlemon if (args->rwflag & LINUX_MS_REMOUNT) 788111798Sdes fsflags |= MNT_UPDATE; 78972538Sjlemon } 79072538Sjlemon 79183366Sjulian return (vfs_mount(td, fstype, mntonname, fsflags, fsdata)); 79272538Sjlemon} 79372538Sjlemon 79472538Sjlemonint 79583366Sjulianlinux_oldumount(struct thread *td, struct linux_oldumount_args *args) 79672538Sjlemon{ 79783221Smarcel struct linux_umount_args args2; 79872538Sjlemon 79972538Sjlemon args2.path = args->path; 80072538Sjlemon args2.flags = 0; 80183366Sjulian return (linux_umount(td, &args2)); 80272538Sjlemon} 80372538Sjlemon 80472538Sjlemonint 80583366Sjulianlinux_umount(struct thread *td, struct linux_umount_args *args) 80672538Sjlemon{ 80772538Sjlemon struct unmount_args bsd; 80872538Sjlemon 80972538Sjlemon bsd.path = args->path; 81072538Sjlemon bsd.flags = args->flags; /* XXX correct? */ 81183366Sjulian return (unmount(td, &bsd)); 81272538Sjlemon} 81383221Smarcel 81483221Smarcel/* 81583221Smarcel * fcntl family of syscalls 81683221Smarcel */ 81783221Smarcel 81883221Smarcelstruct l_flock { 81983221Smarcel l_short l_type; 82083221Smarcel l_short l_whence; 82183221Smarcel l_off_t l_start; 82283221Smarcel l_off_t l_len; 82383221Smarcel l_pid_t l_pid; 82483221Smarcel}; 82583221Smarcel 82683221Smarcelstatic void 82783221Smarcellinux_to_bsd_flock(struct l_flock *linux_flock, struct flock *bsd_flock) 82883221Smarcel{ 82983221Smarcel switch (linux_flock->l_type) { 83083221Smarcel case LINUX_F_RDLCK: 83183221Smarcel bsd_flock->l_type = F_RDLCK; 83283221Smarcel break; 83383221Smarcel case LINUX_F_WRLCK: 83483221Smarcel bsd_flock->l_type = F_WRLCK; 83583221Smarcel break; 83683221Smarcel case LINUX_F_UNLCK: 83783221Smarcel bsd_flock->l_type = F_UNLCK; 83883221Smarcel break; 83983221Smarcel default: 84083221Smarcel bsd_flock->l_type = -1; 84183221Smarcel break; 84283221Smarcel } 84383221Smarcel bsd_flock->l_whence = linux_flock->l_whence; 84483221Smarcel bsd_flock->l_start = (off_t)linux_flock->l_start; 84583221Smarcel bsd_flock->l_len = (off_t)linux_flock->l_len; 84683221Smarcel bsd_flock->l_pid = (pid_t)linux_flock->l_pid; 84783221Smarcel} 84883221Smarcel 84983221Smarcelstatic void 85083221Smarcelbsd_to_linux_flock(struct flock *bsd_flock, struct l_flock *linux_flock) 85183221Smarcel{ 85283221Smarcel switch (bsd_flock->l_type) { 85383221Smarcel case F_RDLCK: 85483221Smarcel linux_flock->l_type = LINUX_F_RDLCK; 85583221Smarcel break; 85683221Smarcel case F_WRLCK: 85783221Smarcel linux_flock->l_type = LINUX_F_WRLCK; 85883221Smarcel break; 85983221Smarcel case F_UNLCK: 86083221Smarcel linux_flock->l_type = LINUX_F_UNLCK; 86183221Smarcel break; 86283221Smarcel } 86383221Smarcel linux_flock->l_whence = bsd_flock->l_whence; 86483221Smarcel linux_flock->l_start = (l_off_t)bsd_flock->l_start; 86583221Smarcel linux_flock->l_len = (l_off_t)bsd_flock->l_len; 86683221Smarcel linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid; 86783221Smarcel} 86883221Smarcel 86983221Smarcel#if defined(__i386__) 87083221Smarcelstruct l_flock64 { 87183221Smarcel l_short l_type; 87283221Smarcel l_short l_whence; 87383221Smarcel l_loff_t l_start; 87483221Smarcel l_loff_t l_len; 87583221Smarcel l_pid_t l_pid; 87683221Smarcel}; 87783221Smarcel 87883221Smarcelstatic void 87983221Smarcellinux_to_bsd_flock64(struct l_flock64 *linux_flock, struct flock *bsd_flock) 88083221Smarcel{ 88183221Smarcel switch (linux_flock->l_type) { 88283221Smarcel case LINUX_F_RDLCK: 88383221Smarcel bsd_flock->l_type = F_RDLCK; 88483221Smarcel break; 88583221Smarcel case LINUX_F_WRLCK: 88683221Smarcel bsd_flock->l_type = F_WRLCK; 88783221Smarcel break; 88883221Smarcel case LINUX_F_UNLCK: 88983221Smarcel bsd_flock->l_type = F_UNLCK; 89083221Smarcel break; 89183221Smarcel default: 89283221Smarcel bsd_flock->l_type = -1; 89383221Smarcel break; 89483221Smarcel } 89583221Smarcel bsd_flock->l_whence = linux_flock->l_whence; 89683221Smarcel bsd_flock->l_start = (off_t)linux_flock->l_start; 89783221Smarcel bsd_flock->l_len = (off_t)linux_flock->l_len; 89883221Smarcel bsd_flock->l_pid = (pid_t)linux_flock->l_pid; 89983221Smarcel} 90083221Smarcel 90183221Smarcelstatic void 90283221Smarcelbsd_to_linux_flock64(struct flock *bsd_flock, struct l_flock64 *linux_flock) 90383221Smarcel{ 90483221Smarcel switch (bsd_flock->l_type) { 90583221Smarcel case F_RDLCK: 90683221Smarcel linux_flock->l_type = LINUX_F_RDLCK; 90783221Smarcel break; 90883221Smarcel case F_WRLCK: 90983221Smarcel linux_flock->l_type = LINUX_F_WRLCK; 91083221Smarcel break; 91183221Smarcel case F_UNLCK: 91283221Smarcel linux_flock->l_type = LINUX_F_UNLCK; 91383221Smarcel break; 91483221Smarcel } 91583221Smarcel linux_flock->l_whence = bsd_flock->l_whence; 91683221Smarcel linux_flock->l_start = (l_loff_t)bsd_flock->l_start; 91783221Smarcel linux_flock->l_len = (l_loff_t)bsd_flock->l_len; 91883221Smarcel linux_flock->l_pid = (l_pid_t)bsd_flock->l_pid; 91983221Smarcel} 92083221Smarcel#endif /* __i386__ */ 92183221Smarcel 92283221Smarcel#if defined(__alpha__) 92383221Smarcel#define linux_fcntl64_args linux_fcntl_args 92483221Smarcel#endif 92583221Smarcel 92683221Smarcelstatic int 92783366Sjulianfcntl_common(struct thread *td, struct linux_fcntl64_args *args) 92883221Smarcel{ 929107680Siedowse struct l_flock linux_flock; 930107680Siedowse struct flock bsd_flock; 93183221Smarcel struct file *fp; 932102872Siedowse long arg; 93383221Smarcel int error, result; 93483221Smarcel 93583221Smarcel switch (args->cmd) { 93683221Smarcel case LINUX_F_DUPFD: 937102872Siedowse return (kern_fcntl(td, args->fd, F_DUPFD, args->arg)); 93883221Smarcel 93983221Smarcel case LINUX_F_GETFD: 940102872Siedowse return (kern_fcntl(td, args->fd, F_GETFD, 0)); 94183221Smarcel 94283221Smarcel case LINUX_F_SETFD: 943102872Siedowse return (kern_fcntl(td, args->fd, F_SETFD, args->arg)); 94483221Smarcel 94583221Smarcel case LINUX_F_GETFL: 946102872Siedowse error = kern_fcntl(td, args->fd, F_GETFL, 0); 94783366Sjulian result = td->td_retval[0]; 94883366Sjulian td->td_retval[0] = 0; 94983221Smarcel if (result & O_RDONLY) 95083366Sjulian td->td_retval[0] |= LINUX_O_RDONLY; 95183221Smarcel if (result & O_WRONLY) 95283366Sjulian td->td_retval[0] |= LINUX_O_WRONLY; 95383221Smarcel if (result & O_RDWR) 95483366Sjulian td->td_retval[0] |= LINUX_O_RDWR; 95583221Smarcel if (result & O_NDELAY) 95683366Sjulian td->td_retval[0] |= LINUX_O_NONBLOCK; 95783221Smarcel if (result & O_APPEND) 95883366Sjulian td->td_retval[0] |= LINUX_O_APPEND; 95983221Smarcel if (result & O_FSYNC) 96083366Sjulian td->td_retval[0] |= LINUX_O_SYNC; 96183221Smarcel if (result & O_ASYNC) 96283366Sjulian td->td_retval[0] |= LINUX_FASYNC; 96383221Smarcel return (error); 96483221Smarcel 96583221Smarcel case LINUX_F_SETFL: 966102872Siedowse arg = 0; 96783221Smarcel if (args->arg & LINUX_O_NDELAY) 968102872Siedowse arg |= O_NONBLOCK; 96983221Smarcel if (args->arg & LINUX_O_APPEND) 970102872Siedowse arg |= O_APPEND; 97183221Smarcel if (args->arg & LINUX_O_SYNC) 972102872Siedowse arg |= O_FSYNC; 97383221Smarcel if (args->arg & LINUX_FASYNC) 974102872Siedowse arg |= O_ASYNC; 975102872Siedowse return (kern_fcntl(td, args->fd, F_SETFL, arg)); 97683221Smarcel 977107680Siedowse case LINUX_F_GETLK: 978111797Sdes error = copyin((void *)args->arg, &linux_flock, 979107680Siedowse sizeof(linux_flock)); 980107680Siedowse if (error) 981107680Siedowse return (error); 982107680Siedowse linux_to_bsd_flock(&linux_flock, &bsd_flock); 983107680Siedowse error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock); 984107680Siedowse if (error) 985107680Siedowse return (error); 986107680Siedowse bsd_to_linux_flock(&bsd_flock, &linux_flock); 987111797Sdes return (copyout(&linux_flock, (void *)args->arg, 988107680Siedowse sizeof(linux_flock))); 989107680Siedowse 990107680Siedowse case LINUX_F_SETLK: 991111797Sdes error = copyin((void *)args->arg, &linux_flock, 992107680Siedowse sizeof(linux_flock)); 993107680Siedowse if (error) 994107680Siedowse return (error); 995107680Siedowse linux_to_bsd_flock(&linux_flock, &bsd_flock); 996107680Siedowse return (kern_fcntl(td, args->fd, F_SETLK, 997107680Siedowse (intptr_t)&bsd_flock)); 998107680Siedowse 999107680Siedowse case LINUX_F_SETLKW: 1000111797Sdes error = copyin((void *)args->arg, &linux_flock, 1001107680Siedowse sizeof(linux_flock)); 1002107680Siedowse if (error) 1003107680Siedowse return (error); 1004107680Siedowse linux_to_bsd_flock(&linux_flock, &bsd_flock); 1005107680Siedowse return (kern_fcntl(td, args->fd, F_SETLKW, 1006107680Siedowse (intptr_t)&bsd_flock)); 1007107680Siedowse 100883221Smarcel case LINUX_F_GETOWN: 1009102872Siedowse return (kern_fcntl(td, args->fd, F_GETOWN, 0)); 101083221Smarcel 101183221Smarcel case LINUX_F_SETOWN: 101283221Smarcel /* 101383221Smarcel * XXX some Linux applications depend on F_SETOWN having no 101483221Smarcel * significant effect for pipes (SIGIO is not delivered for 101583221Smarcel * pipes under Linux-2.2.35 at least). 101683221Smarcel */ 101789319Salfred error = fget(td, args->fd, &fp); 101889319Salfred if (error) 101989319Salfred return (error); 102089306Salfred if (fp->f_type == DTYPE_PIPE) { 102189306Salfred fdrop(fp, td); 102283221Smarcel return (EINVAL); 102389306Salfred } 102489306Salfred fdrop(fp, td); 102583221Smarcel 1026102872Siedowse return (kern_fcntl(td, args->fd, F_SETOWN, args->arg)); 102783221Smarcel } 102883221Smarcel 102983221Smarcel return (EINVAL); 103083221Smarcel} 103183221Smarcel 103283221Smarcelint 103383366Sjulianlinux_fcntl(struct thread *td, struct linux_fcntl_args *args) 103483221Smarcel{ 103583221Smarcel struct linux_fcntl64_args args64; 103683221Smarcel 103783221Smarcel#ifdef DEBUG 103883221Smarcel if (ldebug(fcntl)) 103983221Smarcel printf(ARGS(fcntl, "%d, %08x, *"), args->fd, args->cmd); 104083221Smarcel#endif 104183221Smarcel 104283221Smarcel args64.fd = args->fd; 104383221Smarcel args64.cmd = args->cmd; 104483221Smarcel args64.arg = args->arg; 104583366Sjulian return (fcntl_common(td, &args64)); 104683221Smarcel} 104783221Smarcel 104883221Smarcel#if defined(__i386__) 104983221Smarcelint 105083366Sjulianlinux_fcntl64(struct thread *td, struct linux_fcntl64_args *args) 105183221Smarcel{ 105283221Smarcel struct l_flock64 linux_flock; 1053102872Siedowse struct flock bsd_flock; 105483221Smarcel int error; 105583221Smarcel 105683221Smarcel#ifdef DEBUG 105783221Smarcel if (ldebug(fcntl64)) 105883221Smarcel printf(ARGS(fcntl64, "%d, %08x, *"), args->fd, args->cmd); 105983221Smarcel#endif 106083221Smarcel 106183221Smarcel switch (args->cmd) { 106299687Srobert case LINUX_F_GETLK64: 1063111797Sdes error = copyin((void *)args->arg, &linux_flock, 106483221Smarcel sizeof(linux_flock)); 106583221Smarcel if (error) 106683221Smarcel return (error); 1067102872Siedowse linux_to_bsd_flock64(&linux_flock, &bsd_flock); 1068102872Siedowse error = kern_fcntl(td, args->fd, F_GETLK, (intptr_t)&bsd_flock); 106983221Smarcel if (error) 107083221Smarcel return (error); 1071102872Siedowse bsd_to_linux_flock64(&bsd_flock, &linux_flock); 1072111797Sdes return (copyout(&linux_flock, (void *)args->arg, 1073111797Sdes sizeof(linux_flock))); 107483221Smarcel 107599687Srobert case LINUX_F_SETLK64: 1076111797Sdes error = copyin((void *)args->arg, &linux_flock, 107783221Smarcel sizeof(linux_flock)); 107883221Smarcel if (error) 107983221Smarcel return (error); 1080102872Siedowse linux_to_bsd_flock64(&linux_flock, &bsd_flock); 1081102872Siedowse return (kern_fcntl(td, args->fd, F_SETLK, 1082102872Siedowse (intptr_t)&bsd_flock)); 108383221Smarcel 108499687Srobert case LINUX_F_SETLKW64: 1085111797Sdes error = copyin((void *)args->arg, &linux_flock, 108683221Smarcel sizeof(linux_flock)); 108783221Smarcel if (error) 108883221Smarcel return (error); 1089102872Siedowse linux_to_bsd_flock64(&linux_flock, &bsd_flock); 1090102872Siedowse return (kern_fcntl(td, args->fd, F_SETLKW, 1091102872Siedowse (intptr_t)&bsd_flock)); 109283221Smarcel } 109383221Smarcel 109483366Sjulian return (fcntl_common(td, args)); 109583221Smarcel} 109683221Smarcel#endif /* __i386__ */ 109785022Smarcel 109885022Smarcelint 109985022Smarcellinux_chown(struct thread *td, struct linux_chown_args *args) 110085022Smarcel{ 1101102814Siedowse char *path; 1102102814Siedowse int error; 110385022Smarcel 1104102814Siedowse LCONVPATHEXIST(td, args->path, &path); 110585022Smarcel 110685022Smarcel#ifdef DEBUG 110785022Smarcel if (ldebug(chown)) 1108102814Siedowse printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid); 110985022Smarcel#endif 1110102814Siedowse error = kern_chown(td, path, UIO_SYSSPACE, args->uid, args->gid); 1111102814Siedowse LFREEPATH(path); 1112102814Siedowse return (error); 111385022Smarcel} 111485022Smarcel 111585022Smarcelint 111685022Smarcellinux_lchown(struct thread *td, struct linux_lchown_args *args) 111785022Smarcel{ 1118102814Siedowse char *path; 1119102814Siedowse int error; 112085022Smarcel 1121102814Siedowse LCONVPATHEXIST(td, args->path, &path); 112285022Smarcel 112385022Smarcel#ifdef DEBUG 112485022Smarcel if (ldebug(lchown)) 1125102814Siedowse printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid); 112685022Smarcel#endif 1127102814Siedowse error = kern_lchown(td, path, UIO_SYSSPACE, args->uid, args->gid); 1128102814Siedowse LFREEPATH(path); 1129102814Siedowse return (error); 113085022Smarcel} 1131