Home | History | Annotate | Line # | Download | only in common
linux_statfs.h revision 1.2.16.1
      1 /*	$NetBSD: linux_statfs.h,v 1.2.16.1 2008/05/16 02:23:43 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  *
     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  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef _LINUX_STATFS_H
     34 #define _LINUX_STATFS_H
     35 
     36 static void bsd_to_linux_statfs(const struct statvfs *,
     37     struct linux_statfs *);
     38 
     39 /*
     40  * Convert NetBSD statvfs structure to Linux statfs structure.
     41  * Linux doesn't have f_flag, and we can't set f_frsize due
     42  * to glibc statvfs() bug (see below).
     43  */
     44 static void
     45 bsd_to_linux_statfs(bsp, lsp)
     46 	const struct statvfs *bsp;
     47 	struct linux_statfs *lsp;
     48 {
     49 	int i;
     50 
     51 	for (i = 0; i < linux_fstypes_cnt; i++) {
     52 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
     53 			lsp->l_ftype = linux_fstypes[i].linux;
     54 			break;
     55 		}
     56 	}
     57 
     58 	if (i == linux_fstypes_cnt) {
     59 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
     60 	}
     61 
     62 	/*
     63 	 * The sizes are expressed in number of blocks. The block
     64 	 * size used for the size is f_frsize for POSIX-compliant
     65 	 * statvfs. Linux statfs uses f_bsize as the block size
     66 	 * (f_frsize used to not be available in Linux struct statfs).
     67 	 * However, glibc 2.3.3 statvfs() wrapper fails to adjust the block
     68 	 * counts for different f_frsize if f_frsize is provided by the kernel.
     69 	 * POSIX conforming apps thus get wrong size if f_frsize
     70 	 * is different to f_bsize. Thus, we just pretend we don't
     71 	 * support f_frsize.
     72 	 */
     73 
     74 	lsp->l_fbsize = bsp->f_frsize;
     75 	lsp->l_ffrsize = 0;			/* compat */
     76 	lsp->l_fblocks = bsp->f_blocks;
     77 	lsp->l_fbfree = bsp->f_bfree;
     78 	lsp->l_fbavail = bsp->f_bavail;
     79 	lsp->l_ffiles = bsp->f_files;
     80 	lsp->l_fffree = bsp->f_ffree;
     81 	/* Linux sets the fsid to 0..., we don't */
     82 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
     83 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
     84 	lsp->l_fnamelen = bsp->f_namemax;
     85 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
     86 }
     87 
     88 #endif /* !_LINUX_STATFS_H */
     89