1 /* $NetBSD: statvfs.h,v 1.3 2020/07/03 19:00:01 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 2019 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Christos Zoulas. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _COMPAT_SYS_STATVFS_H_ 33 #define _COMPAT_SYS_STATVFS_H_ 34 35 #include <sys/statvfs.h> 36 37 struct statvfs90 { 38 unsigned long f_flag; /* copy of mount exported flags */ 39 unsigned long f_bsize; /* file system block size */ 40 unsigned long f_frsize; /* fundamental file system block size */ 41 unsigned long f_iosize; /* optimal file system block size */ 42 43 /* The following are in units of f_frsize */ 44 fsblkcnt_t f_blocks; /* number of blocks in file system, */ 45 fsblkcnt_t f_bfree; /* free blocks avail in file system */ 46 fsblkcnt_t f_bavail; /* free blocks avail to non-root */ 47 fsblkcnt_t f_bresvd; /* blocks reserved for root */ 48 49 fsfilcnt_t f_files; /* total file nodes in file system */ 50 fsfilcnt_t f_ffree; /* free file nodes in file system */ 51 fsfilcnt_t f_favail; /* free file nodes avail to non-root */ 52 fsfilcnt_t f_fresvd; /* file nodes reserved for root */ 53 54 uint64_t f_syncreads; /* count of sync reads since mount */ 55 uint64_t f_syncwrites; /* count of sync writes since mount */ 56 57 uint64_t f_asyncreads; /* count of async reads since mount */ 58 uint64_t f_asyncwrites; /* count of async writes since mount */ 59 60 fsid_t f_fsidx; /* NetBSD compatible fsid */ 61 unsigned long f_fsid; /* Posix compatible fsid */ 62 unsigned long f_namemax; /* maximum filename length */ 63 uid_t f_owner; /* user that mounted the file system */ 64 65 uint32_t f_spare[4]; /* spare space */ 66 67 char f_fstypename[_VFS_NAMELEN]; /* fs type name */ 68 char f_mntonname[_VFS_MNAMELEN]; /* directory on which mounted */ 69 char f_mntfromname[_VFS_MNAMELEN]; /* mounted file system */ 70 }; 71 72 __BEGIN_DECLS 73 #ifndef _KERNEL 74 #include <string.h> 75 #endif 76 77 static __inline void 78 statvfs_to_statvfs90(const struct statvfs *s, struct statvfs90 *s90) 79 { 80 s90->f_flag = s->f_flag; 81 s90->f_bsize = s->f_bsize; 82 s90->f_frsize = s->f_frsize; 83 s90->f_iosize = s->f_iosize; 84 85 s90->f_blocks = s->f_blocks; 86 s90->f_bfree = s->f_bfree; 87 s90->f_bavail = s->f_bavail; 88 s90->f_bresvd = s->f_bresvd; 89 90 s90->f_files = s->f_files; 91 s90->f_ffree = s->f_ffree; 92 s90->f_favail = s->f_favail; 93 s90->f_fresvd = s->f_fresvd; 94 95 s90->f_syncreads = s->f_syncreads; 96 s90->f_syncwrites = s->f_syncwrites; 97 98 s90->f_asyncreads = s->f_asyncreads; 99 s90->f_asyncwrites = s->f_asyncwrites; 100 101 s90->f_fsidx = s->f_fsidx; 102 s90->f_fsid = s->f_fsid; 103 s90->f_namemax = s->f_namemax; 104 s90->f_owner = s->f_owner; 105 106 memcpy(s90->f_fstypename, s->f_fstypename, sizeof(s90->f_fstypename)); 107 memcpy(s90->f_mntonname, s->f_mntonname, sizeof(s90->f_mntonname)); 108 memcpy(s90->f_mntfromname, s->f_mntfromname, sizeof(s90->f_mntfromname)); 109 } 110 111 #ifdef _KERNEL 112 static __inline int 113 statvfs_to_statvfs90_copy(const void *vs, void *vs90, size_t l) 114 { 115 struct statvfs90 *s90 = kmem_zalloc(sizeof(*s90), KM_SLEEP); 116 int error; 117 118 statvfs_to_statvfs90(vs, s90); 119 error = copyout(s90, vs90, sizeof(*s90)); 120 kmem_free(s90, sizeof(*s90)); 121 122 return error; 123 } 124 #else 125 126 #ifdef __LIBC12_SOURCE__ 127 128 int __compat_statvfs(const char *__restrict, struct statvfs90 *__restrict); 129 int __compat_statvfs1(const char *__restrict, struct statvfs90 *__restrict, 130 int); 131 132 int __compat_fstatvfs(int, struct statvfs90 *); 133 int __compat_fstatvfs1(int, struct statvfs90 *, int); 134 135 int __compat___getmntinfo13(struct statvfs90 **, int); 136 137 int __compat___fhstatvfs40(const void *, size_t, struct statvfs90 *); 138 int __compat___fhstatvfs140(const void *, size_t, struct statvfs90 *, int); 139 140 int __compat_getvfsstat(struct statvfs90 *, size_t, int); 141 142 int __statvfs90(const char *__restrict, struct statvfs *__restrict); 143 int __statvfs190(const char *__restrict, struct statvfs *__restrict, int); 144 145 int __fstatvfs90(int, struct statvfs *); 146 int __fstatvfs190(int, struct statvfs *, int); 147 148 int __fhstatvfs90(const void *, size_t, struct statvfs *); 149 int __fhstatvfs190(const void *, size_t, struct statvfs *, int); 150 151 int __getvfsstat90(struct statvfs *, size_t, int); 152 153 int __getmntinfo90(struct statvfs **, int); 154 155 #endif /* __LIBC12_SOURCE__ */ 156 157 #endif /* _KERNEL */ 158 159 __END_DECLS 160 161 #endif /* !_COMPAT_SYS_STATVFS_H_ */ 162