Home | History | Annotate | Line # | Download | only in common
linux_statfs.h revision 1.1.16.1
      1 /*	$NetBSD: linux_statfs.h,v 1.1.16.1 2007/12/09 19:37:06 jmcneill 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  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #ifndef _LINUX_STATFS_H
     41 #define _LINUX_STATFS_H
     42 
     43 static void bsd_to_linux_statfs(const struct statvfs *,
     44     struct linux_statfs *);
     45 
     46 /*
     47  * Convert NetBSD statvfs structure to Linux statfs structure.
     48  * Linux doesn't have f_flag, and we can't set f_frsize due
     49  * to glibc statvfs() bug (see below).
     50  */
     51 static void
     52 bsd_to_linux_statfs(bsp, lsp)
     53 	const struct statvfs *bsp;
     54 	struct linux_statfs *lsp;
     55 {
     56 	int i;
     57 
     58 	for (i = 0; i < linux_fstypes_cnt; i++) {
     59 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
     60 			lsp->l_ftype = linux_fstypes[i].linux;
     61 			break;
     62 		}
     63 	}
     64 
     65 	if (i == linux_fstypes_cnt) {
     66 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
     67 	}
     68 
     69 	/*
     70 	 * The sizes are expressed in number of blocks. The block
     71 	 * size used for the size is f_frsize for POSIX-compliant
     72 	 * statvfs. Linux statfs uses f_bsize as the block size
     73 	 * (f_frsize used to not be available in Linux struct statfs).
     74 	 * However, glibc 2.3.3 statvfs() wrapper fails to adjust the block
     75 	 * counts for different f_frsize if f_frsize is provided by the kernel.
     76 	 * POSIX conforming apps thus get wrong size if f_frsize
     77 	 * is different to f_bsize. Thus, we just pretend we don't
     78 	 * support f_frsize.
     79 	 */
     80 
     81 	lsp->l_fbsize = bsp->f_frsize;
     82 	lsp->l_ffrsize = 0;			/* compat */
     83 	lsp->l_fblocks = bsp->f_blocks;
     84 	lsp->l_fbfree = bsp->f_bfree;
     85 	lsp->l_fbavail = bsp->f_bavail;
     86 	lsp->l_ffiles = bsp->f_files;
     87 	lsp->l_fffree = bsp->f_ffree;
     88 	/* Linux sets the fsid to 0..., we don't */
     89 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
     90 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
     91 	lsp->l_fnamelen = bsp->f_namemax;
     92 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
     93 }
     94 
     95 #endif /* !_LINUX_STATFS_H */
     96