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