| 1 | /* $NetBSD: linux_statfs.h,v 1.6 2012/09/13 13:59:33 pooka 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 __unused bsd_to_linux_statfs(const struct statvfs *, |
| 37 | struct linux_statfs *); |
| 38 | static void __unused bsd_to_linux_statfs64(const struct statvfs *, |
| 39 | struct linux_statfs64 *); |
| 40 | |
| 41 | /* |
| 42 | * Convert NetBSD statvfs structure to Linux statfs structure. |
| 43 | * Linux doesn't have f_flag, and we can't set f_frsize due |
| 44 | * to glibc statvfs() bug (see below). |
| 45 | */ |
| 46 | static void __unused |
| 47 | bsd_to_linux_statfs(const struct statvfs *bsp, 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].mty_bsd) == 0) { |
| 53 | lsp->l_ftype = linux_fstypes[i].mty_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 | /* |
| 89 | * Convert NetBSD statvfs structure to Linux statfs64 structure. |
| 90 | * See comments in bsd_to_linux_statfs() for further background. |
| 91 | * We can safely pass correct bsize and frsize here, since Linux glibc |
| 92 | * statvfs() doesn't use statfs64(). |
| 93 | */ |
| 94 | static void __unused |
| 95 | bsd_to_linux_statfs64(const struct statvfs *bsp, struct linux_statfs64 *lsp) |
| 96 | { |
| 97 | int i, div; |
| 98 | |
| 99 | for (i = 0; i < linux_fstypes_cnt; i++) { |
| 100 | if (strcmp(bsp->f_fstypename, linux_fstypes[i].mty_bsd) == 0) { |
| 101 | lsp->l_ftype = linux_fstypes[i].mty_linux; |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (i == linux_fstypes_cnt) { |
| 107 | lsp->l_ftype = LINUX_DEFAULT_SUPER_MAGIC; |
| 108 | } |
| 109 | |
| 110 | div = bsp->f_frsize ? (bsp->f_bsize / bsp->f_frsize) : 1; |
| 111 | if (div == 0) |
| 112 | div = 1; |
| 113 | lsp->l_fbsize = bsp->f_bsize; |
| 114 | lsp->l_ffrsize = bsp->f_frsize; |
| 115 | lsp->l_fblocks = bsp->f_blocks / div; |
| 116 | lsp->l_fbfree = bsp->f_bfree / div; |
| 117 | lsp->l_fbavail = bsp->f_bavail / div; |
| 118 | lsp->l_ffiles = bsp->f_files; |
| 119 | lsp->l_fffree = bsp->f_ffree / div; |
| 120 | /* Linux sets the fsid to 0..., we don't */ |
| 121 | lsp->l_ffsid.val[0] = bsp->f_fsidx.__fsid_val[0]; |
| 122 | lsp->l_ffsid.val[1] = bsp->f_fsidx.__fsid_val[1]; |
| 123 | lsp->l_fnamelen = bsp->f_namemax; |
| 124 | (void)memset(lsp->l_fspare, 0, sizeof(lsp->l_fspare)); |
| 125 | } |
| 126 | |
| 127 | #endif /* !_LINUX_STATFS_H */ |
| 128 | |