Home | History | Annotate | Line # | Download | only in common
linux_llseek.c revision 1.3
      1  1.3  mycroft /*	$NetBSD: linux_llseek.c,v 1.3 1995/04/04 04:21:30 mycroft Exp $	*/
      2  1.1     fvdl 
      3  1.1     fvdl /*
      4  1.1     fvdl  * Copyright (c) 1995 Frank van der Linden
      5  1.1     fvdl  * All rights reserved.
      6  1.1     fvdl  *
      7  1.1     fvdl  * Redistribution and use in source and binary forms, with or without
      8  1.1     fvdl  * modification, are permitted provided that the following conditions
      9  1.1     fvdl  * are met:
     10  1.1     fvdl  * 1. Redistributions of source code must retain the above copyright
     11  1.1     fvdl  *    notice, this list of conditions and the following disclaimer.
     12  1.1     fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1     fvdl  *    notice, this list of conditions and the following disclaimer in the
     14  1.1     fvdl  *    documentation and/or other materials provided with the distribution.
     15  1.1     fvdl  * 3. All advertising materials mentioning features or use of this software
     16  1.1     fvdl  *    must display the following acknowledgement:
     17  1.1     fvdl  *      This product includes software developed for the NetBSD Project
     18  1.1     fvdl  *      by Frank van der Linden
     19  1.1     fvdl  * 4. The name of the author may not be used to endorse or promote products
     20  1.1     fvdl  *    derived from this software without specific prior written permission
     21  1.1     fvdl  *
     22  1.1     fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1     fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1     fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1     fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1     fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1     fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1     fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1     fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1     fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1     fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1     fvdl  */
     33  1.1     fvdl 
     34  1.1     fvdl #include <sys/param.h>
     35  1.1     fvdl #include <sys/systm.h>
     36  1.1     fvdl #include <sys/namei.h>
     37  1.1     fvdl #include <sys/proc.h>
     38  1.1     fvdl #include <sys/file.h>
     39  1.1     fvdl #include <sys/stat.h>
     40  1.1     fvdl #include <sys/filedesc.h>
     41  1.1     fvdl #include <sys/ioctl.h>
     42  1.1     fvdl #include <sys/kernel.h>
     43  1.1     fvdl #include <sys/mount.h>
     44  1.1     fvdl #include <sys/malloc.h>
     45  1.1     fvdl 
     46  1.1     fvdl #include <sys/syscallargs.h>
     47  1.1     fvdl 
     48  1.1     fvdl #include <compat/linux/linux_types.h>
     49  1.1     fvdl #include <compat/linux/linux_syscallargs.h>
     50  1.1     fvdl #include <compat/linux/linux_fcntl.h>
     51  1.1     fvdl #include <compat/linux/linux_util.h>
     52  1.1     fvdl 
     53  1.1     fvdl /*
     54  1.1     fvdl  * Some file-related calls are handled here. The usual flag conversion
     55  1.1     fvdl  * an structure conversion is done, and alternate emul path searching.
     56  1.1     fvdl  */
     57  1.1     fvdl 
     58  1.1     fvdl /*
     59  1.1     fvdl  * The next two functions convert between the Linux and NetBSD values
     60  1.1     fvdl  * of the flags used in open(2) and fcntl(2).
     61  1.1     fvdl  */
     62  1.1     fvdl static int
     63  1.1     fvdl linux_to_bsd_ioflags(int lflags)
     64  1.1     fvdl {
     65  1.1     fvdl 	int res = 0;
     66  1.1     fvdl 
     67  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
     68  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
     69  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
     70  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
     71  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
     72  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
     73  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
     74  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
     75  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
     76  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
     77  1.1     fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
     78  1.1     fvdl 
     79  1.1     fvdl 	return res;
     80  1.1     fvdl }
     81  1.1     fvdl 
     82  1.1     fvdl static int
     83  1.1     fvdl bsd_to_linux_ioflags(int bflags)
     84  1.1     fvdl {
     85  1.1     fvdl 	int res = 0;
     86  1.1     fvdl 
     87  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
     88  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
     89  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
     90  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
     91  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
     92  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
     93  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
     94  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
     95  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
     96  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
     97  1.1     fvdl 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
     98  1.1     fvdl 
     99  1.1     fvdl 	return res;
    100  1.1     fvdl }
    101  1.1     fvdl 
    102  1.1     fvdl /*
    103  1.1     fvdl  * creat(2) is an obsolete function, but it's present as a Linux
    104  1.1     fvdl  * system call, so let's deal with it.
    105  1.1     fvdl  *
    106  1.1     fvdl  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    107  1.1     fvdl  */
    108  1.1     fvdl int
    109  1.1     fvdl linux_creat(p, uap, retval)
    110  1.1     fvdl 	struct proc *p;
    111  1.1     fvdl 	struct linux_creat_args /* {
    112  1.1     fvdl 		syscallarg(char *) path;
    113  1.1     fvdl 		syscallarg(int) mode;
    114  1.1     fvdl 	} */ *uap;
    115  1.1     fvdl 	register_t *retval;
    116  1.1     fvdl {
    117  1.1     fvdl 	struct open_args oa;
    118  1.1     fvdl 	caddr_t sg;
    119  1.1     fvdl 
    120  1.1     fvdl 	sg = stackgap_init();
    121  1.2     fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    122  1.1     fvdl 
    123  1.1     fvdl 	SCARG(&oa, path) = SCARG(uap, path);
    124  1.1     fvdl 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    125  1.1     fvdl 	SCARG(&oa, mode) = SCARG(uap, mode);
    126  1.1     fvdl 	return open(p, &oa, retval);
    127  1.1     fvdl }
    128  1.1     fvdl 
    129  1.1     fvdl /*
    130  1.1     fvdl  * open(2). Take care of the different flag values, and let the
    131  1.1     fvdl  * NetBSD syscall do the real work. See if this operation
    132  1.1     fvdl  * gives the current process a controlling terminal.
    133  1.1     fvdl  * (XXX is this necessary?)
    134  1.1     fvdl  */
    135  1.1     fvdl int
    136  1.1     fvdl linux_open(p, uap, retval)
    137  1.1     fvdl 	struct proc *p;
    138  1.1     fvdl 	struct linux_open_args /* {
    139  1.1     fvdl 		syscallarg(char *) path;
    140  1.1     fvdl 		syscallarg(int) flags;
    141  1.1     fvdl 		syscallarg(int) mode;
    142  1.1     fvdl 	} */ *uap;
    143  1.1     fvdl 	register_t *retval;
    144  1.1     fvdl {
    145  1.1     fvdl 	int error, fl;
    146  1.1     fvdl 	struct open_args boa;
    147  1.1     fvdl 	caddr_t sg;
    148  1.1     fvdl 
    149  1.1     fvdl 	sg = stackgap_init();
    150  1.1     fvdl 
    151  1.2     fvdl 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    152  1.1     fvdl 
    153  1.2     fvdl 	if (fl & O_CREAT)
    154  1.2     fvdl 		CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    155  1.2     fvdl 	else
    156  1.2     fvdl 		CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    157  1.1     fvdl 
    158  1.1     fvdl 	SCARG(&boa, path) = SCARG(uap, path);
    159  1.1     fvdl 	SCARG(&boa, flags) = fl;
    160  1.1     fvdl 	SCARG(&boa, mode) = SCARG(uap, mode);
    161  1.2     fvdl 
    162  1.1     fvdl 	if ((error = open(p, &boa, retval)))
    163  1.1     fvdl 		return error;
    164  1.1     fvdl 
    165  1.1     fvdl 	/*
    166  1.1     fvdl 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    167  1.1     fvdl 	 * If we are a session leader, and we don't have a controlling
    168  1.1     fvdl 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    169  1.1     fvdl 	 * this the controlling terminal.
    170  1.1     fvdl 	 */
    171  1.1     fvdl         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
    172  1.1     fvdl                 struct filedesc *fdp = p->p_fd;
    173  1.1     fvdl                 struct file     *fp = fdp->fd_ofiles[*retval];
    174  1.1     fvdl 
    175  1.1     fvdl                 /* ignore any error, just give it a try */
    176  1.1     fvdl                 if (fp->f_type == DTYPE_VNODE)
    177  1.1     fvdl                         (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
    178  1.1     fvdl         }
    179  1.1     fvdl 	return 0;
    180  1.1     fvdl }
    181  1.1     fvdl 
    182  1.1     fvdl /*
    183  1.2     fvdl  * This appears to be part of a Linux attempt to switch to 64 bits file sizes.
    184  1.2     fvdl  */
    185  1.2     fvdl int
    186  1.2     fvdl linux_llseek(p, uap, retval)
    187  1.2     fvdl 	struct proc *p;
    188  1.2     fvdl 	struct linux_llseek_args /* {
    189  1.2     fvdl 		syscallarg(int) fd;
    190  1.2     fvdl 		syscallarg(uint32_t) ohigh;
    191  1.2     fvdl 		syscallarg(uint32_t) olow;
    192  1.2     fvdl 		syscallarg(caddr_t) res;
    193  1.2     fvdl 		syscallarg(int) whence;
    194  1.2     fvdl 	} */ *uap;
    195  1.2     fvdl 	register_t *retval;
    196  1.2     fvdl {
    197  1.2     fvdl 	struct lseek_args bla;
    198  1.2     fvdl 	int error;
    199  1.2     fvdl 	off_t off;
    200  1.2     fvdl 
    201  1.2     fvdl 	off = SCARG(uap, olow) | (((off_t) SCARG(uap, ohigh)) << 32);
    202  1.2     fvdl 
    203  1.2     fvdl 	SCARG(&bla, fd) = SCARG(uap, fd);
    204  1.2     fvdl 	SCARG(&bla, offset) = off;
    205  1.2     fvdl 	SCARG(&bla, whence) = SCARG(uap, whence);
    206  1.2     fvdl 
    207  1.2     fvdl 	if ((error = lseek(p, &bla, retval)))
    208  1.2     fvdl 		return error;
    209  1.2     fvdl 
    210  1.2     fvdl 	if ((error = copyout(retval, SCARG(uap, res), sizeof (off_t))))
    211  1.2     fvdl 		return error;
    212  1.2     fvdl 
    213  1.2     fvdl 	retval[0] = 0;
    214  1.2     fvdl 	return 0;
    215  1.2     fvdl }
    216  1.2     fvdl 
    217  1.2     fvdl /*
    218  1.1     fvdl  * The next two functions take care of converting the flock
    219  1.1     fvdl  * structure back and forth between Linux and NetBSD format.
    220  1.1     fvdl  * The only difference in the structures is the order of
    221  1.1     fvdl  * the fields, and the 'whence' value.
    222  1.1     fvdl  */
    223  1.1     fvdl static void
    224  1.1     fvdl bsd_to_linux_flock(bfp, lfp)
    225  1.1     fvdl 	struct flock *bfp;
    226  1.1     fvdl 	struct linux_flock *lfp;
    227  1.1     fvdl {
    228  1.1     fvdl 	lfp->l_start = bfp->l_start;
    229  1.1     fvdl 	lfp->l_len = bfp->l_len;
    230  1.1     fvdl 	lfp->l_pid = bfp->l_pid;
    231  1.3  mycroft 	lfp->l_whence = bfp->l_whence;
    232  1.3  mycroft 	switch (bfp->l_type) {
    233  1.1     fvdl 	case F_RDLCK:
    234  1.3  mycroft 		lfp->l_type = LINUX_F_RDLCK;
    235  1.1     fvdl 		break;
    236  1.1     fvdl 	case F_UNLCK:
    237  1.3  mycroft 		lfp->l_type = LINUX_F_UNLCK;
    238  1.1     fvdl 		break;
    239  1.1     fvdl 	case F_WRLCK:
    240  1.3  mycroft 		lfp->l_type = LINUX_F_WRLCK;
    241  1.1     fvdl 		break;
    242  1.1     fvdl 	}
    243  1.1     fvdl }
    244  1.1     fvdl 
    245  1.1     fvdl static void
    246  1.1     fvdl linux_to_bsd_flock(lfp, bfp)
    247  1.1     fvdl 	struct linux_flock *lfp;
    248  1.1     fvdl 	struct flock *bfp;
    249  1.1     fvdl {
    250  1.1     fvdl 	bfp->l_start = lfp->l_start;
    251  1.1     fvdl 	bfp->l_len = lfp->l_len;
    252  1.1     fvdl 	bfp->l_pid = lfp->l_pid;
    253  1.3  mycroft 	bfp->l_whence = lfp->l_whence;
    254  1.3  mycroft 	switch (lfp->l_type) {
    255  1.1     fvdl 	case LINUX_F_RDLCK:
    256  1.3  mycroft 		bfp->l_type = F_RDLCK;
    257  1.1     fvdl 		break;
    258  1.1     fvdl 	case LINUX_F_UNLCK:
    259  1.3  mycroft 		bfp->l_type = F_UNLCK;
    260  1.1     fvdl 		break;
    261  1.1     fvdl 	case LINUX_F_WRLCK:
    262  1.3  mycroft 		bfp->l_type = F_WRLCK;
    263  1.1     fvdl 		break;
    264  1.1     fvdl 	}
    265  1.1     fvdl }
    266  1.1     fvdl 
    267  1.1     fvdl /*
    268  1.1     fvdl  * Most actions in the fcntl() call are straightforward; simply
    269  1.1     fvdl  * pass control to the NetBSD system call. A few commands need
    270  1.1     fvdl  * conversions after the actual system call has done its work,
    271  1.1     fvdl  * because the flag values and lock structure are different.
    272  1.1     fvdl  */
    273  1.1     fvdl int
    274  1.1     fvdl linux_fcntl(p, uap, retval)
    275  1.1     fvdl 	struct proc *p;
    276  1.1     fvdl 	struct linux_fcntl_args /* {
    277  1.1     fvdl 		syscallarg(int) fd;
    278  1.1     fvdl 		syscallarg(int) cmd;
    279  1.1     fvdl 		syscallarg(void *) arg;
    280  1.1     fvdl 	} */ *uap;
    281  1.1     fvdl 	register_t *retval;
    282  1.1     fvdl {
    283  1.1     fvdl 	int fd, cmd, error, *tval,val;
    284  1.1     fvdl 	caddr_t arg, sg;
    285  1.1     fvdl 	struct linux_flock lfl;
    286  1.1     fvdl 	struct flock *bfp, bfl;
    287  1.1     fvdl 	struct fcntl_args fca;
    288  1.1     fvdl 
    289  1.1     fvdl 	fd = SCARG(uap, fd);
    290  1.1     fvdl 	cmd = SCARG(uap, cmd);
    291  1.1     fvdl 	arg = (caddr_t) SCARG(uap, arg);
    292  1.1     fvdl 
    293  1.1     fvdl 	switch (cmd) {
    294  1.1     fvdl 	case LINUX_F_DUPFD:
    295  1.1     fvdl 		cmd = F_DUPFD;
    296  1.1     fvdl 		break;
    297  1.1     fvdl 	case LINUX_F_GETFD:
    298  1.1     fvdl 		cmd = F_GETFD;
    299  1.1     fvdl 		break;
    300  1.1     fvdl 	case LINUX_F_SETFD:
    301  1.1     fvdl 		cmd = F_SETFD;
    302  1.1     fvdl 		break;
    303  1.1     fvdl 	case LINUX_F_GETFL:
    304  1.1     fvdl 		SCARG(&fca, fd) = fd;
    305  1.1     fvdl 		SCARG(&fca, cmd) = F_GETFL;
    306  1.1     fvdl 		SCARG(&fca, arg) = arg;
    307  1.1     fvdl 		if ((error = fcntl(p, &fca, retval)))
    308  1.1     fvdl 			return error;
    309  1.1     fvdl 		retval[0] = bsd_to_linux_ioflags(retval[0]);
    310  1.1     fvdl 		return 0;
    311  1.1     fvdl 	case LINUX_F_SETFL:
    312  1.1     fvdl 		if ((error = copyin(SCARG(uap, arg), &val, sizeof (int))))
    313  1.1     fvdl 			return error;
    314  1.1     fvdl 		val = linux_to_bsd_ioflags(val);
    315  1.1     fvdl 		sg = stackgap_init();
    316  1.1     fvdl 		tval = (int *) stackgap_alloc(&sg, sizeof (int));
    317  1.1     fvdl 		if ((error = copyout(&val, tval, sizeof (int))))
    318  1.1     fvdl 			return error;
    319  1.1     fvdl 		SCARG(&fca, fd) = fd;
    320  1.1     fvdl 		SCARG(&fca, cmd) = F_SETFL;
    321  1.1     fvdl 		SCARG(&fca, arg) = tval;
    322  1.1     fvdl 		return fcntl(p, &fca, retval);
    323  1.1     fvdl 	case LINUX_F_GETLK:
    324  1.1     fvdl 		sg = stackgap_init();
    325  1.1     fvdl 		bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
    326  1.1     fvdl 		SCARG(&fca, fd) = fd;
    327  1.1     fvdl 		SCARG(&fca, cmd) = F_GETLK;
    328  1.1     fvdl 		SCARG(&fca, arg) = bfp;
    329  1.1     fvdl 		if ((error = fcntl(p, &fca, retval)))
    330  1.1     fvdl 			return error;
    331  1.1     fvdl 		if ((error = copyin(bfp, &bfl, sizeof bfl)))
    332  1.1     fvdl 			return error;
    333  1.1     fvdl 		bsd_to_linux_flock(&bfl, &lfl);
    334  1.1     fvdl 		return copyout(&lfl, arg, sizeof lfl);
    335  1.1     fvdl 		break;
    336  1.1     fvdl 	case LINUX_F_SETLK:
    337  1.1     fvdl 	case LINUX_F_SETLKW:
    338  1.1     fvdl 		cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
    339  1.1     fvdl 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    340  1.1     fvdl 			return error;
    341  1.1     fvdl 		linux_to_bsd_flock(&lfl, &bfl);
    342  1.1     fvdl 		sg = stackgap_init();
    343  1.1     fvdl 		bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
    344  1.1     fvdl 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    345  1.1     fvdl 			return error;
    346  1.1     fvdl 		SCARG(&fca, fd) = fd;
    347  1.1     fvdl 		SCARG(&fca, cmd) = cmd;
    348  1.1     fvdl 		SCARG(&fca, arg) = bfp;
    349  1.1     fvdl 		return fcntl(p, &fca, retval);
    350  1.1     fvdl 		break;
    351  1.1     fvdl 	case LINUX_F_SETOWN:
    352  1.1     fvdl 		cmd = F_SETOWN;
    353  1.1     fvdl 		break;
    354  1.1     fvdl 	case LINUX_F_GETOWN:
    355  1.1     fvdl 		cmd = F_GETOWN;
    356  1.1     fvdl 		break;
    357  1.1     fvdl 	default:
    358  1.1     fvdl 		return EOPNOTSUPP;
    359  1.1     fvdl 	}
    360  1.1     fvdl 
    361  1.1     fvdl 	SCARG(&fca, fd) = fd;
    362  1.1     fvdl 	SCARG(&fca, cmd) = cmd;
    363  1.1     fvdl 	SCARG(&fca, arg) = arg;
    364  1.1     fvdl 	return fcntl(p, uap, retval);
    365  1.1     fvdl }
    366  1.1     fvdl 
    367  1.1     fvdl /*
    368  1.1     fvdl  * Convert a NetBSD stat structure to a Linux stat structure.
    369  1.1     fvdl  * Only the order of the fields and the padding in the structure
    370  1.1     fvdl  * is different.
    371  1.1     fvdl  */
    372  1.1     fvdl static void
    373  1.1     fvdl bsd_to_linux_stat(bsp, lsp)
    374  1.1     fvdl 	struct stat *bsp;
    375  1.1     fvdl 	struct linux_stat *lsp;
    376  1.1     fvdl {
    377  1.1     fvdl 	lsp->lst_dev     = bsp->st_dev;
    378  1.1     fvdl 	lsp->lst_ino     = bsp->st_ino;
    379  1.1     fvdl 	lsp->lst_mode    = bsp->st_mode;
    380  1.1     fvdl 	lsp->lst_nlink   = bsp->st_nlink;
    381  1.1     fvdl 	lsp->lst_uid     = bsp->st_uid;
    382  1.1     fvdl 	lsp->lst_gid     = bsp->st_gid;
    383  1.1     fvdl 	lsp->lst_rdev    = bsp->st_rdev;
    384  1.1     fvdl 	lsp->lst_size    = bsp->st_size;
    385  1.1     fvdl 	lsp->lst_blksize = bsp->st_blksize;
    386  1.1     fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    387  1.1     fvdl 	lsp->lst_atime   = bsp->st_atime;
    388  1.1     fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    389  1.1     fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    390  1.1     fvdl }
    391  1.1     fvdl 
    392  1.1     fvdl /*
    393  1.1     fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    394  1.1     fvdl  * by one function to avoid code duplication.
    395  1.1     fvdl  */
    396  1.1     fvdl int
    397  1.1     fvdl linux_fstat(p, uap, retval)
    398  1.1     fvdl 	struct proc *p;
    399  1.1     fvdl 	struct linux_fstat_args /* {
    400  1.1     fvdl 		syscallarg(int) fd;
    401  1.1     fvdl 		syscallarg(linux_stat *) sp;
    402  1.1     fvdl 	} */ *uap;
    403  1.1     fvdl 	register_t *retval;
    404  1.1     fvdl {
    405  1.1     fvdl 	struct fstat_args fsa;
    406  1.1     fvdl 	struct linux_stat tmplst;
    407  1.1     fvdl 	struct stat *st,tmpst;
    408  1.1     fvdl 	caddr_t sg;
    409  1.1     fvdl 	int error;
    410  1.1     fvdl 
    411  1.1     fvdl 	sg = stackgap_init();
    412  1.1     fvdl 
    413  1.1     fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    414  1.1     fvdl 
    415  1.1     fvdl 	SCARG(&fsa, fd) = SCARG(uap, fd);
    416  1.1     fvdl 	SCARG(&fsa, sb) = st;
    417  1.1     fvdl 
    418  1.1     fvdl 	if ((error = fstat(p, &fsa, retval)))
    419  1.1     fvdl 		return error;
    420  1.1     fvdl 
    421  1.1     fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    422  1.1     fvdl 		return error;
    423  1.1     fvdl 
    424  1.1     fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    425  1.1     fvdl 
    426  1.1     fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    427  1.1     fvdl 		return error;
    428  1.1     fvdl 
    429  1.1     fvdl 	return 0;
    430  1.1     fvdl }
    431  1.1     fvdl 
    432  1.1     fvdl static int
    433  1.1     fvdl linux_stat1(p, uap, retval, dolstat)
    434  1.1     fvdl 	struct proc *p;
    435  1.1     fvdl 	struct linux_stat_args *uap;
    436  1.1     fvdl 	register_t *retval;
    437  1.1     fvdl 	int dolstat;
    438  1.1     fvdl {
    439  1.1     fvdl 	struct stat_args sa;
    440  1.1     fvdl 	struct linux_stat tmplst;
    441  1.1     fvdl 	struct stat *st, tmpst;
    442  1.1     fvdl 	caddr_t sg;
    443  1.1     fvdl 	int error;
    444  1.1     fvdl 
    445  1.1     fvdl 	sg = stackgap_init();
    446  1.1     fvdl 
    447  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    448  1.1     fvdl 
    449  1.1     fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    450  1.1     fvdl 	SCARG(&sa, ub) = st;
    451  1.1     fvdl 	SCARG(&sa, path) = SCARG(uap, path);
    452  1.1     fvdl 
    453  1.1     fvdl 	if ((error = (dolstat ? lstat(p, &sa, retval) : stat(p, &sa, retval))))
    454  1.1     fvdl 		return error;
    455  1.1     fvdl 
    456  1.1     fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    457  1.1     fvdl 		return error;
    458  1.1     fvdl 
    459  1.1     fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    460  1.1     fvdl 
    461  1.1     fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    462  1.1     fvdl 		return error;
    463  1.1     fvdl 
    464  1.1     fvdl 	return 0;
    465  1.1     fvdl }
    466  1.1     fvdl 
    467  1.1     fvdl int
    468  1.1     fvdl linux_stat(p, uap, retval)
    469  1.1     fvdl 	struct proc *p;
    470  1.1     fvdl 	struct linux_stat_args /* {
    471  1.1     fvdl 		syscallarg(char *) path;
    472  1.1     fvdl 		syscallarg(struct linux_stat *) sp;
    473  1.1     fvdl 	} */ *uap;
    474  1.1     fvdl 	register_t *retval;
    475  1.1     fvdl {
    476  1.1     fvdl 	return linux_stat1(p, uap, retval, 0);
    477  1.1     fvdl }
    478  1.1     fvdl 
    479  1.1     fvdl int
    480  1.1     fvdl linux_lstat(p, uap, retval)
    481  1.1     fvdl 	struct proc *p;
    482  1.1     fvdl 	struct linux_lstat_args /* {
    483  1.1     fvdl 		syscallarg(char *) path;
    484  1.1     fvdl 		syscallarg(struct linux_stat *) sp;
    485  1.1     fvdl 	} */ *uap;
    486  1.1     fvdl 	register_t *retval;
    487  1.1     fvdl {
    488  1.1     fvdl 	return linux_stat1(p, uap, retval, 1);
    489  1.1     fvdl }
    490  1.1     fvdl 
    491  1.1     fvdl /*
    492  1.2     fvdl  * The following syscalls are only here because of the alternate path check.
    493  1.1     fvdl  */
    494  1.1     fvdl int
    495  1.1     fvdl linux_access(p, uap, retval)
    496  1.1     fvdl 	struct proc *p;
    497  1.1     fvdl 	struct linux_access_args /* {
    498  1.1     fvdl 		syscallarg(char *) path;
    499  1.1     fvdl 		syscallarg(int) flags;
    500  1.1     fvdl 	} */ *uap;
    501  1.1     fvdl 	register_t *retval;
    502  1.1     fvdl {
    503  1.1     fvdl 	caddr_t sg = stackgap_init();
    504  1.1     fvdl 
    505  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    506  1.1     fvdl 
    507  1.1     fvdl 	return access(p, uap, retval);
    508  1.2     fvdl }
    509  1.2     fvdl 
    510  1.2     fvdl int
    511  1.2     fvdl linux_unlink(p, uap, retval)
    512  1.2     fvdl 	struct proc *p;
    513  1.2     fvdl 	struct linux_unlink_args /* {
    514  1.2     fvdl 		syscallarg(char *) path;
    515  1.2     fvdl 	} */ *uap;
    516  1.2     fvdl 	register_t *retval;
    517  1.2     fvdl 
    518  1.2     fvdl {
    519  1.2     fvdl 	caddr_t sg = stackgap_init();
    520  1.2     fvdl 
    521  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    522  1.2     fvdl 
    523  1.2     fvdl 	return unlink(p, uap, retval);
    524  1.2     fvdl }
    525  1.2     fvdl 
    526  1.2     fvdl int linux_chdir(p, uap, retval)
    527  1.2     fvdl 	struct proc *p;
    528  1.2     fvdl 	struct linux_chdir_args /* {
    529  1.2     fvdl 		syscallarg(char *) path;
    530  1.2     fvdl 	} */ *uap;
    531  1.2     fvdl 	register_t *retval;
    532  1.2     fvdl {
    533  1.2     fvdl 	caddr_t sg = stackgap_init();
    534  1.2     fvdl 
    535  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    536  1.2     fvdl 
    537  1.2     fvdl 	return chdir(p, uap, retval);
    538  1.2     fvdl }
    539  1.2     fvdl 
    540  1.2     fvdl int
    541  1.2     fvdl linux_mknod(p, uap, retval)
    542  1.2     fvdl 	struct proc *p;
    543  1.2     fvdl 	struct linux_mknod_args /* {
    544  1.2     fvdl 		syscallarg(char *) path;
    545  1.2     fvdl 		syscallarg(int) mode;
    546  1.2     fvdl 		syscallarg(int) dev;
    547  1.2     fvdl 	} */ *uap;
    548  1.2     fvdl 	register_t *retval;
    549  1.2     fvdl {
    550  1.2     fvdl 	caddr_t sg = stackgap_init();
    551  1.2     fvdl 
    552  1.2     fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    553  1.2     fvdl 
    554  1.2     fvdl 	return mknod(p, uap, retval);
    555  1.2     fvdl }
    556  1.2     fvdl 
    557  1.2     fvdl int
    558  1.2     fvdl linux_chmod(p, uap, retval)
    559  1.2     fvdl 	struct proc *p;
    560  1.2     fvdl 	struct linux_chmod_args /* {
    561  1.2     fvdl 		syscallarg(char *) path;
    562  1.2     fvdl 		syscallarg(int) mode;
    563  1.2     fvdl 	} */ *uap;
    564  1.2     fvdl 	register_t *retval;
    565  1.2     fvdl {
    566  1.2     fvdl 	caddr_t sg = stackgap_init();
    567  1.2     fvdl 
    568  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    569  1.2     fvdl 
    570  1.2     fvdl 	return chmod(p, uap, retval);
    571  1.2     fvdl }
    572  1.2     fvdl 
    573  1.2     fvdl int
    574  1.2     fvdl linux_chown(p, uap, retval)
    575  1.2     fvdl 	struct proc *p;
    576  1.2     fvdl 	struct linux_chown_args /* {
    577  1.2     fvdl 		syscallarg(char *) path;
    578  1.2     fvdl 		syscallarg(int) uid;
    579  1.2     fvdl 		syscallarg(int) gid;
    580  1.2     fvdl 	} */ *uap;
    581  1.2     fvdl 	register_t *retval;
    582  1.2     fvdl {
    583  1.2     fvdl 	caddr_t sg = stackgap_init();
    584  1.2     fvdl 
    585  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    586  1.2     fvdl 
    587  1.2     fvdl 	return chmod(p, uap, retval);
    588  1.2     fvdl }
    589  1.2     fvdl 
    590  1.2     fvdl int
    591  1.2     fvdl linux_rename(p, uap, retval)
    592  1.2     fvdl 	struct proc *p;
    593  1.2     fvdl 	struct linux_rename_args /* {
    594  1.2     fvdl 		syscallarg(char *) from;
    595  1.2     fvdl 		syscallarg(char *) to;
    596  1.2     fvdl 	} */ *uap;
    597  1.2     fvdl 	register_t *retval;
    598  1.2     fvdl {
    599  1.2     fvdl 	caddr_t sg = stackgap_init();
    600  1.2     fvdl 
    601  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
    602  1.2     fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    603  1.2     fvdl 
    604  1.2     fvdl 	return rename(p, uap, retval);
    605  1.2     fvdl }
    606  1.2     fvdl 
    607  1.2     fvdl int
    608  1.2     fvdl linux_mkdir(p, uap, retval)
    609  1.2     fvdl 	struct proc *p;
    610  1.2     fvdl 	struct linux_mkdir_args /* {
    611  1.2     fvdl 		syscallarg(char *) path;
    612  1.2     fvdl 	} */ *uap;
    613  1.2     fvdl 	register_t *retval;
    614  1.2     fvdl {
    615  1.2     fvdl 	caddr_t sg = stackgap_init();
    616  1.2     fvdl 
    617  1.2     fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    618  1.2     fvdl 	return mkdir(p, uap, retval);
    619  1.2     fvdl }
    620  1.2     fvdl 
    621  1.2     fvdl int
    622  1.2     fvdl linux_rmdir(p, uap, retval)
    623  1.2     fvdl 	struct proc *p;
    624  1.2     fvdl 	struct linux_rmdir_args /* {
    625  1.2     fvdl 		syscallarg(char *) path;
    626  1.2     fvdl 	} */ *uap;
    627  1.2     fvdl 	register_t *retval;
    628  1.2     fvdl {
    629  1.2     fvdl 	caddr_t sg = stackgap_init();
    630  1.2     fvdl 
    631  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    632  1.2     fvdl 	return rmdir(p, uap, retval);
    633  1.2     fvdl }
    634  1.2     fvdl 
    635  1.2     fvdl int
    636  1.2     fvdl linux_symlink(p, uap, retval)
    637  1.2     fvdl 	struct proc *p;
    638  1.2     fvdl 	struct linux_symlink_args /* {
    639  1.2     fvdl 		syscallarg(char *) path;
    640  1.2     fvdl 		syscallarg(char *) to;
    641  1.2     fvdl 	} */ *uap;
    642  1.2     fvdl 	register_t *retval;
    643  1.2     fvdl {
    644  1.2     fvdl 	caddr_t sg = stackgap_init();
    645  1.2     fvdl 
    646  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    647  1.2     fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    648  1.2     fvdl 
    649  1.2     fvdl 	return symlink(p, uap, retval);
    650  1.2     fvdl }
    651  1.2     fvdl 
    652  1.2     fvdl int
    653  1.2     fvdl linux_readlink(p, uap, retval)
    654  1.2     fvdl 	struct proc *p;
    655  1.2     fvdl 	struct linux_readlink_args /* {
    656  1.2     fvdl 		syscallarg(char *) name;
    657  1.2     fvdl 		syscallarg(char *) buf;
    658  1.2     fvdl 		syscallarg(int) count;
    659  1.2     fvdl 	} */ *uap;
    660  1.2     fvdl {
    661  1.2     fvdl 	caddr_t sg = stackgap_init();
    662  1.2     fvdl 
    663  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, name));
    664  1.2     fvdl 	return readlink(p, uap, retval);
    665  1.2     fvdl }
    666  1.2     fvdl 
    667  1.2     fvdl int
    668  1.2     fvdl linux_truncate(p, uap, retval)
    669  1.2     fvdl 	struct proc *p;
    670  1.2     fvdl 	struct linux_truncate_args /* {
    671  1.2     fvdl 		syscallarg(char *) path;
    672  1.2     fvdl 		syscallarg(long) length;
    673  1.2     fvdl 	} */ *uap;
    674  1.2     fvdl {
    675  1.2     fvdl 	caddr_t sg = stackgap_init();
    676  1.2     fvdl 
    677  1.2     fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    678  1.2     fvdl 	return compat_43_truncate(p, uap, retval);
    679  1.1     fvdl }
    680