Home | History | Annotate | Line # | Download | only in common
linux_statfs.h revision 1.5
      1  1.5     chs /*	$NetBSD: linux_statfs.h,v 1.5 2010/11/02 18:14:05 chs Exp $	*/
      2  1.1   njoly 
      3  1.1   njoly /*-
      4  1.1   njoly  * Copyright (c) 1995, 1998, 1999 The NetBSD Foundation, Inc.
      5  1.1   njoly  * All rights reserved.
      6  1.1   njoly  *
      7  1.1   njoly  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1   njoly  * by Frank van der Linden and Eric Haszlakiewicz; by Jason R. Thorpe
      9  1.1   njoly  * of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
     10  1.1   njoly  *
     11  1.1   njoly  * Redistribution and use in source and binary forms, with or without
     12  1.1   njoly  * modification, are permitted provided that the following conditions
     13  1.1   njoly  * are met:
     14  1.1   njoly  * 1. Redistributions of source code must retain the above copyright
     15  1.1   njoly  *    notice, this list of conditions and the following disclaimer.
     16  1.1   njoly  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1   njoly  *    notice, this list of conditions and the following disclaimer in the
     18  1.1   njoly  *    documentation and/or other materials provided with the distribution.
     19  1.1   njoly  *
     20  1.1   njoly  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1   njoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1   njoly  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1   njoly  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1   njoly  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1   njoly  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1   njoly  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1   njoly  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1   njoly  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1   njoly  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1   njoly  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1   njoly  */
     32  1.1   njoly 
     33  1.1   njoly #ifndef _LINUX_STATFS_H
     34  1.1   njoly #define _LINUX_STATFS_H
     35  1.1   njoly 
     36  1.5     chs static void __unused bsd_to_linux_statfs(const struct statvfs *,
     37  1.2     dsl     struct linux_statfs *);
     38  1.5     chs static void __unused bsd_to_linux_statfs64(const struct statvfs *,
     39  1.5     chs     struct linux_statfs64 *);
     40  1.1   njoly 
     41  1.1   njoly /*
     42  1.1   njoly  * Convert NetBSD statvfs structure to Linux statfs structure.
     43  1.1   njoly  * Linux doesn't have f_flag, and we can't set f_frsize due
     44  1.1   njoly  * to glibc statvfs() bug (see below).
     45  1.1   njoly  */
     46  1.5     chs static void __unused
     47  1.4  cegger bsd_to_linux_statfs(const struct statvfs *bsp, struct linux_statfs *lsp)
     48  1.1   njoly {
     49  1.1   njoly 	int i;
     50  1.1   njoly 
     51  1.1   njoly 	for (i = 0; i < linux_fstypes_cnt; i++) {
     52  1.1   njoly 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
     53  1.1   njoly 			lsp->l_ftype = linux_fstypes[i].linux;
     54  1.1   njoly 			break;
     55  1.1   njoly 		}
     56  1.1   njoly 	}
     57  1.1   njoly 
     58  1.1   njoly 	if (i == linux_fstypes_cnt) {
     59  1.1   njoly 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
     60  1.1   njoly 	}
     61  1.1   njoly 
     62  1.1   njoly 	/*
     63  1.1   njoly 	 * The sizes are expressed in number of blocks. The block
     64  1.1   njoly 	 * size used for the size is f_frsize for POSIX-compliant
     65  1.1   njoly 	 * statvfs. Linux statfs uses f_bsize as the block size
     66  1.1   njoly 	 * (f_frsize used to not be available in Linux struct statfs).
     67  1.1   njoly 	 * However, glibc 2.3.3 statvfs() wrapper fails to adjust the block
     68  1.1   njoly 	 * counts for different f_frsize if f_frsize is provided by the kernel.
     69  1.1   njoly 	 * POSIX conforming apps thus get wrong size if f_frsize
     70  1.1   njoly 	 * is different to f_bsize. Thus, we just pretend we don't
     71  1.1   njoly 	 * support f_frsize.
     72  1.1   njoly 	 */
     73  1.1   njoly 
     74  1.1   njoly 	lsp->l_fbsize = bsp->f_frsize;
     75  1.1   njoly 	lsp->l_ffrsize = 0;			/* compat */
     76  1.1   njoly 	lsp->l_fblocks = bsp->f_blocks;
     77  1.1   njoly 	lsp->l_fbfree = bsp->f_bfree;
     78  1.1   njoly 	lsp->l_fbavail = bsp->f_bavail;
     79  1.1   njoly 	lsp->l_ffiles = bsp->f_files;
     80  1.1   njoly 	lsp->l_fffree = bsp->f_ffree;
     81  1.1   njoly 	/* Linux sets the fsid to 0..., we don't */
     82  1.1   njoly 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
     83  1.1   njoly 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
     84  1.1   njoly 	lsp->l_fnamelen = bsp->f_namemax;
     85  1.1   njoly 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
     86  1.1   njoly }
     87  1.1   njoly 
     88  1.5     chs /*
     89  1.5     chs  * Convert NetBSD statvfs structure to Linux statfs64 structure.
     90  1.5     chs  * See comments in bsd_to_linux_statfs() for further background.
     91  1.5     chs  * We can safely pass correct bsize and frsize here, since Linux glibc
     92  1.5     chs  * statvfs() doesn't use statfs64().
     93  1.5     chs  */
     94  1.5     chs static void __unused
     95  1.5     chs bsd_to_linux_statfs64(const struct statvfs *bsp, struct linux_statfs64 *lsp)
     96  1.5     chs {
     97  1.5     chs 	int i, div;
     98  1.5     chs 
     99  1.5     chs 	for (i = 0; i < linux_fstypes_cnt; i++) {
    100  1.5     chs 		if (strcmp(bsp->f_fstypename, linux_fstypes[i].bsd) == 0) {
    101  1.5     chs 			lsp->l_ftype = linux_fstypes[i].linux;
    102  1.5     chs 			break;
    103  1.5     chs 		}
    104  1.5     chs 	}
    105  1.5     chs 
    106  1.5     chs 	if (i == linux_fstypes_cnt) {
    107  1.5     chs 		lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC;
    108  1.5     chs 	}
    109  1.5     chs 
    110  1.5     chs 	div = bsp->f_frsize ? (bsp->f_bsize / bsp->f_frsize) : 1;
    111  1.5     chs 	if (div == 0)
    112  1.5     chs 		div = 1;
    113  1.5     chs 	lsp->l_fbsize = bsp->f_bsize;
    114  1.5     chs 	lsp->l_ffrsize = bsp->f_frsize;
    115  1.5     chs 	lsp->l_fblocks = bsp->f_blocks / div;
    116  1.5     chs 	lsp->l_fbfree = bsp->f_bfree / div;
    117  1.5     chs 	lsp->l_fbavail = bsp->f_bavail / div;
    118  1.5     chs 	lsp->l_ffiles = bsp->f_files;
    119  1.5     chs 	lsp->l_fffree = bsp->f_ffree / div;
    120  1.5     chs 	/* Linux sets the fsid to 0..., we don't */
    121  1.5     chs 	lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0];
    122  1.5     chs 	lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1];
    123  1.5     chs 	lsp->l_fnamelen = bsp->f_namemax;
    124  1.5     chs 	(void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare));
    125  1.5     chs }
    126  1.5     chs 
    127  1.1   njoly #endif /* !_LINUX_STATFS_H */
    128