Home | History | Annotate | Line # | Download | only in common
linux32_misc.c revision 1.4.4.1
      1 /*	$NetBSD: linux32_misc.c,v 1.4.4.1 2007/04/15 16:03:15 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
      9  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center;
     10  * by Edgar Fu\ss, Mathematisches Institut der Uni Bonn.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the NetBSD
     23  *	Foundation, Inc. and its contributors.
     24  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25  *    contributors may be used to endorse or promote products derived
     26  *    from this software without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  * POSSIBILITY OF SUCH DAMAGE.
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: linux32_misc.c,v 1.4.4.1 2007/04/15 16:03:15 yamt Exp $");
     43 
     44 #include <sys/param.h>
     45 #include <sys/proc.h>
     46 #include <sys/time.h>
     47 #include <sys/types.h>
     48 #include <sys/malloc.h>
     49 
     50 #include <compat/netbsd32/netbsd32.h>
     51 #include <compat/netbsd32/netbsd32_syscallargs.h>
     52 
     53 #include <compat/linux32/common/linux32_types.h>
     54 #include <compat/linux32/common/linux32_signal.h>
     55 #include <compat/linux32/linux32_syscallargs.h>
     56 
     57 #include <compat/linux/common/linux_types.h>
     58 #include <compat/linux/common/linux_signal.h>
     59 #include <compat/linux/common/linux_misc.h>
     60 #include <compat/linux/common/linux_statfs.h>
     61 #include <compat/linux/linux_syscallargs.h>
     62 
     63 extern const struct linux_mnttypes linux_fstypes[];
     64 extern const int linux_fstypes_cnt;
     65 
     66 
     67 /*
     68  * Implement the fs stat functions. Straightforward.
     69  */
     70 int
     71 linux32_sys_statfs(l, v, retval)
     72 	struct lwp *l;
     73 	void *v;
     74 	register_t *retval;
     75 {
     76 	struct linux32_sys_statfs_args /* {
     77 		syscallarg(const netbsd32_charp char) path;
     78 		syscallarg(linux32_statfsp) sp;
     79 	} */ *uap = v;
     80 	struct proc *p = l->l_proc;
     81 	struct statvfs *btmp, *bsp;
     82 	struct linux_statfs ltmp;
     83 	struct sys_statvfs1_args bsa;
     84 	void *sg;
     85 	int error;
     86 
     87 	sg = stackgap_init(p, 0);
     88 	bsp = stackgap_alloc(p, &sg, sizeof (struct statvfs));
     89 
     90 	NETBSD32TOP(uap, &bsa, path, const char);
     91 	CHECK_ALT_EXIST(l, &sg, SCARG(&bsa, path));
     92 
     93 	SCARG(&bsa, buf) = bsp;
     94 	SCARG(&bsa, flags) = ST_WAIT;
     95 
     96 	if ((error = sys_statvfs1(l, &bsa, retval)))
     97 		return error;
     98 
     99 	btmp = STATVFSBUF_GET();
    100 	error = copyin(bsp, btmp, sizeof(*btmp));
    101 	if (error) {
    102 		goto out;
    103 	}
    104 	bsd_to_linux_statfs(btmp, &ltmp);
    105 	error = copyout(&ltmp, SCARG_P32(uap, sp), sizeof ltmp);
    106 out:
    107 	STATVFSBUF_PUT(btmp);
    108 	return error;
    109 }
    110