Home | History | Annotate | Line # | Download | only in common
linux_file64.c revision 1.2.6.2
      1  1.2.6.2  jdolecek /*	$NetBSD: linux_file64.c,v 1.2.6.2 2002/03/16 16:00:37 jdolecek Exp $	*/
      2      1.1  jdolecek 
      3      1.1  jdolecek /*-
      4      1.1  jdolecek  * Copyright (c) 1995, 1998, 2000 The NetBSD Foundation, Inc.
      5      1.1  jdolecek  * All rights reserved.
      6      1.1  jdolecek  *
      7      1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  jdolecek  * by Frank van der Linden and Eric Haszlakiewicz.
      9      1.1  jdolecek  *
     10      1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11      1.1  jdolecek  * modification, are permitted provided that the following conditions
     12      1.1  jdolecek  * are met:
     13      1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14      1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15      1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18      1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19      1.1  jdolecek  *    must display the following acknowledgement:
     20      1.1  jdolecek  *	This product includes software developed by the NetBSD
     21      1.1  jdolecek  *	Foundation, Inc. and its contributors.
     22      1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     24      1.1  jdolecek  *    from this software without specific prior written permission.
     25      1.1  jdolecek  *
     26      1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  jdolecek  */
     38      1.1  jdolecek 
     39      1.1  jdolecek /*
     40      1.1  jdolecek  * Linux 64bit filesystem calls. Used on 32bit archs, not used on 64bit ones.
     41      1.1  jdolecek  */
     42      1.1  jdolecek 
     43  1.2.6.1   thorpej #include <sys/cdefs.h>
     44  1.2.6.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.2.6.2 2002/03/16 16:00:37 jdolecek Exp $");
     45  1.2.6.1   thorpej 
     46      1.1  jdolecek #include <sys/param.h>
     47      1.1  jdolecek #include <sys/systm.h>
     48      1.1  jdolecek #include <sys/namei.h>
     49      1.1  jdolecek #include <sys/proc.h>
     50      1.1  jdolecek #include <sys/file.h>
     51      1.1  jdolecek #include <sys/stat.h>
     52      1.1  jdolecek #include <sys/filedesc.h>
     53      1.1  jdolecek #include <sys/ioctl.h>
     54      1.1  jdolecek #include <sys/kernel.h>
     55      1.1  jdolecek #include <sys/mount.h>
     56      1.1  jdolecek #include <sys/malloc.h>
     57      1.1  jdolecek #include <sys/vnode.h>
     58      1.1  jdolecek #include <sys/tty.h>
     59      1.1  jdolecek #include <sys/conf.h>
     60      1.1  jdolecek 
     61      1.1  jdolecek #include <sys/syscallargs.h>
     62      1.1  jdolecek 
     63      1.1  jdolecek #include <compat/linux/common/linux_types.h>
     64      1.1  jdolecek #include <compat/linux/common/linux_signal.h>
     65      1.1  jdolecek #include <compat/linux/common/linux_fcntl.h>
     66      1.1  jdolecek #include <compat/linux/common/linux_util.h>
     67      1.1  jdolecek #include <compat/linux/common/linux_machdep.h>
     68      1.1  jdolecek 
     69      1.1  jdolecek #include <compat/linux/linux_syscallargs.h>
     70      1.1  jdolecek 
     71      1.1  jdolecek static void bsd_to_linux_stat __P((struct stat *, struct linux_stat64 *));
     72      1.1  jdolecek static int linux_do_stat64 __P((struct proc *, void *, register_t *, int));
     73      1.1  jdolecek 
     74      1.1  jdolecek /*
     75      1.1  jdolecek  * Convert a NetBSD stat structure to a Linux stat structure.
     76      1.1  jdolecek  * Only the order of the fields and the padding in the structure
     77      1.1  jdolecek  * is different. linux_fakedev is a machine-dependent function
     78      1.1  jdolecek  * which optionally converts device driver major/minor numbers
     79      1.1  jdolecek  * (XXX horrible, but what can you do against code that compares
     80      1.1  jdolecek  * things against constant major device numbers? sigh)
     81      1.1  jdolecek  */
     82      1.1  jdolecek static void
     83      1.1  jdolecek bsd_to_linux_stat(bsp, lsp)
     84      1.1  jdolecek 	struct stat *bsp;
     85      1.1  jdolecek 	struct linux_stat64 *lsp;
     86      1.1  jdolecek {
     87  1.2.6.2  jdolecek 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
     88      1.1  jdolecek 	lsp->lst_ino     = bsp->st_ino;
     89      1.1  jdolecek 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
     90      1.1  jdolecek 	if (bsp->st_nlink >= (1 << 15))
     91      1.1  jdolecek 		lsp->lst_nlink = (1 << 15) - 1;
     92      1.1  jdolecek 	else
     93      1.1  jdolecek 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
     94      1.1  jdolecek 	lsp->lst_uid     = bsp->st_uid;
     95      1.1  jdolecek 	lsp->lst_gid     = bsp->st_gid;
     96  1.2.6.2  jdolecek 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
     97      1.1  jdolecek 	lsp->lst_size    = bsp->st_size;
     98      1.1  jdolecek 	lsp->lst_blksize = bsp->st_blksize;
     99      1.1  jdolecek 	lsp->lst_blocks  = bsp->st_blocks;
    100      1.1  jdolecek 	lsp->lst_atime   = bsp->st_atime;
    101      1.1  jdolecek 	lsp->lst_mtime   = bsp->st_mtime;
    102      1.1  jdolecek 	lsp->lst_ctime   = bsp->st_ctime;
    103  1.2.6.2  jdolecek 	lsp->lst_ino64   = bsp->st_ino;
    104      1.1  jdolecek }
    105      1.1  jdolecek 
    106      1.1  jdolecek /*
    107      1.1  jdolecek  * The stat functions below are plain sailing. stat and lstat are handled
    108      1.1  jdolecek  * by one function to avoid code duplication.
    109      1.1  jdolecek  */
    110      1.1  jdolecek int
    111      1.1  jdolecek linux_sys_fstat64(p, v, retval)
    112      1.1  jdolecek 	struct proc *p;
    113      1.1  jdolecek 	void *v;
    114      1.1  jdolecek 	register_t *retval;
    115      1.1  jdolecek {
    116      1.1  jdolecek 	struct linux_sys_fstat64_args /* {
    117      1.1  jdolecek 		syscallarg(int) fd;
    118  1.2.6.1   thorpej 		syscallarg(struct linux_stat64 *) sp;
    119      1.1  jdolecek 	} */ *uap = v;
    120      1.1  jdolecek 	struct sys___fstat13_args fsa;
    121      1.1  jdolecek 	struct linux_stat64 tmplst;
    122      1.1  jdolecek 	struct stat *st,tmpst;
    123      1.1  jdolecek 	caddr_t sg;
    124      1.1  jdolecek 	int error;
    125      1.1  jdolecek 
    126      1.1  jdolecek 	sg = stackgap_init(p->p_emul);
    127      1.1  jdolecek 
    128      1.1  jdolecek 	st = stackgap_alloc(&sg, sizeof (struct stat));
    129      1.1  jdolecek 
    130      1.1  jdolecek 	SCARG(&fsa, fd) = SCARG(uap, fd);
    131      1.1  jdolecek 	SCARG(&fsa, sb) = st;
    132      1.1  jdolecek 
    133      1.1  jdolecek 	if ((error = sys___fstat13(p, &fsa, retval)))
    134      1.1  jdolecek 		return error;
    135      1.1  jdolecek 
    136      1.1  jdolecek 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    137      1.1  jdolecek 		return error;
    138      1.1  jdolecek 
    139      1.1  jdolecek 	bsd_to_linux_stat(&tmpst, &tmplst);
    140      1.1  jdolecek 
    141      1.1  jdolecek 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    142      1.1  jdolecek 		return error;
    143      1.1  jdolecek 
    144      1.1  jdolecek 	return 0;
    145      1.1  jdolecek }
    146      1.1  jdolecek 
    147      1.1  jdolecek static int
    148      1.1  jdolecek linux_do_stat64(p, v, retval, dolstat)
    149      1.1  jdolecek 	struct proc *p;
    150      1.1  jdolecek 	void *v;
    151      1.1  jdolecek 	register_t *retval;
    152      1.1  jdolecek 	int dolstat;
    153      1.1  jdolecek {
    154      1.1  jdolecek 	struct sys___stat13_args sa;
    155      1.1  jdolecek 	struct linux_stat64 tmplst;
    156      1.1  jdolecek 	struct stat *st, tmpst;
    157      1.1  jdolecek 	caddr_t sg;
    158      1.1  jdolecek 	int error;
    159      1.1  jdolecek 	struct linux_sys_stat64_args *uap = v;
    160      1.1  jdolecek 
    161      1.1  jdolecek 	sg = stackgap_init(p->p_emul);
    162      1.1  jdolecek 	st = stackgap_alloc(&sg, sizeof (struct stat));
    163      1.1  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    164      1.1  jdolecek 
    165      1.1  jdolecek 	SCARG(&sa, ub) = st;
    166      1.1  jdolecek 	SCARG(&sa, path) = SCARG(uap, path);
    167      1.1  jdolecek 
    168      1.1  jdolecek 	if ((error = (dolstat ? sys___lstat13(p, &sa, retval) :
    169      1.1  jdolecek 				sys___stat13(p, &sa, retval))))
    170      1.1  jdolecek 		return error;
    171      1.1  jdolecek 
    172      1.1  jdolecek 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    173      1.1  jdolecek 		return error;
    174      1.1  jdolecek 
    175      1.1  jdolecek 	bsd_to_linux_stat(&tmpst, &tmplst);
    176      1.1  jdolecek 
    177      1.1  jdolecek 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    178      1.1  jdolecek 		return error;
    179      1.1  jdolecek 
    180      1.1  jdolecek 	return 0;
    181      1.1  jdolecek }
    182      1.1  jdolecek 
    183      1.1  jdolecek int
    184      1.1  jdolecek linux_sys_stat64(p, v, retval)
    185      1.1  jdolecek 	struct proc *p;
    186      1.1  jdolecek 	void *v;
    187      1.1  jdolecek 	register_t *retval;
    188      1.1  jdolecek {
    189      1.1  jdolecek 	struct linux_sys_stat64_args /* {
    190      1.1  jdolecek 		syscallarg(const char *) path;
    191      1.1  jdolecek 		syscallarg(struct linux_stat64 *) sp;
    192      1.1  jdolecek 	} */ *uap = v;
    193      1.1  jdolecek 
    194      1.1  jdolecek 	return linux_do_stat64(p, uap, retval, 0);
    195      1.1  jdolecek }
    196      1.1  jdolecek 
    197      1.1  jdolecek int
    198      1.1  jdolecek linux_sys_lstat64(p, v, retval)
    199      1.1  jdolecek 	struct proc *p;
    200      1.1  jdolecek 	void *v;
    201      1.1  jdolecek 	register_t *retval;
    202      1.1  jdolecek {
    203      1.1  jdolecek 	struct linux_sys_lstat64_args /* {
    204      1.1  jdolecek 		syscallarg(const char *) path;
    205      1.1  jdolecek 		syscallarg(struct linux_stat64 *) sp;
    206      1.1  jdolecek 	} */ *uap = v;
    207      1.1  jdolecek 
    208      1.1  jdolecek 	return linux_do_stat64(p, uap, retval, 1);
    209      1.2  jdolecek }
    210      1.2  jdolecek 
    211      1.2  jdolecek int
    212      1.2  jdolecek linux_sys_truncate64(p, v, retval)
    213      1.2  jdolecek 	struct proc *p;
    214      1.2  jdolecek 	void *v;
    215      1.2  jdolecek 	register_t *retval;
    216      1.2  jdolecek {
    217      1.2  jdolecek 	struct linux_sys_truncate64_args /* {
    218      1.2  jdolecek 		syscallarg(const char *) path;
    219      1.2  jdolecek 		syscallarg(off_t) length;
    220      1.2  jdolecek 	} */ *uap = v;
    221      1.2  jdolecek 	caddr_t sg = stackgap_init(p->p_emul);
    222      1.2  jdolecek 
    223      1.2  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    224      1.2  jdolecek 
    225      1.2  jdolecek 	return sys_truncate(p, uap, retval);
    226      1.1  jdolecek }
    227  1.2.6.1   thorpej 
    228  1.2.6.1   thorpej #ifdef __mips__ /* i386 and powerpc could use it too */
    229  1.2.6.1   thorpej int
    230  1.2.6.1   thorpej linux_sys_fcntl64(p, v, retval)
    231  1.2.6.1   thorpej 	struct proc *p;
    232  1.2.6.1   thorpej 	void *v;
    233  1.2.6.1   thorpej 	register_t *retval;
    234  1.2.6.1   thorpej {
    235  1.2.6.1   thorpej 	struct linux_sys_fcntl64_args /* {
    236  1.2.6.1   thorpej 		syscallarg(unsigned int) fd;
    237  1.2.6.1   thorpej 		syscallarg(unsigned int) cmd;
    238  1.2.6.1   thorpej 		syscallarg(unsigned long) arg;
    239  1.2.6.1   thorpej 	} */ *uap = v;
    240  1.2.6.1   thorpej 	unsigned int fd, cmd;
    241  1.2.6.1   thorpej 	unsigned long arg;
    242  1.2.6.1   thorpej 	int error;
    243  1.2.6.1   thorpej 
    244  1.2.6.1   thorpej 	fd = SCARG(uap, fd);
    245  1.2.6.1   thorpej 	cmd = SCARG(uap, cmd);
    246  1.2.6.1   thorpej 	arg = SCARG(uap, arg);
    247  1.2.6.1   thorpej 
    248  1.2.6.1   thorpej 	switch (cmd) {
    249  1.2.6.1   thorpej 		/* XXX implement this later */
    250  1.2.6.1   thorpej 		case LINUX_F_GETLK64:
    251  1.2.6.1   thorpej 			error = 0;
    252  1.2.6.1   thorpej 			break;
    253  1.2.6.1   thorpej 		case LINUX_F_SETLK64:
    254  1.2.6.1   thorpej 			error = 0;
    255  1.2.6.1   thorpej 			break;
    256  1.2.6.1   thorpej 		case LINUX_F_SETLKW64:
    257  1.2.6.1   thorpej 			error = 0;
    258  1.2.6.1   thorpej 			break;
    259  1.2.6.1   thorpej 		default:
    260  1.2.6.1   thorpej 			error = linux_sys_fcntl(p, v, retval);
    261  1.2.6.1   thorpej 			break;
    262  1.2.6.1   thorpej 	}
    263  1.2.6.1   thorpej 
    264  1.2.6.1   thorpej 	return error;
    265  1.2.6.1   thorpej }
    266  1.2.6.1   thorpej #endif /* __mips__ */
    267