1 /* $NetBSD: mount.h,v 1.11 2019/10/04 01:28:02 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1989, 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * @(#)mount.h 8.21 (Berkeley) 5/20/95 32 */ 33 34 #ifndef _COMPAT_SYS_MOUNT_H_ 35 #define _COMPAT_SYS_MOUNT_H_ 36 37 #ifdef _KERNEL_OPT 38 #include "opt_compat_43.h" 39 #endif 40 41 #define MFSNAMELEN 16 42 43 struct statfs12 { 44 short f_type; /* type of file system */ 45 u_short f_oflags; /* deprecated copy of mount flags */ 46 long f_bsize; /* fundamental file system block size */ 47 long f_iosize; /* optimal transfer block size */ 48 long f_blocks; /* total data blocks in file system */ 49 long f_bfree; /* free blocks in fs */ 50 long f_bavail; /* free blocks avail to non-superuser */ 51 long f_files; /* total file nodes in file system */ 52 long f_ffree; /* free file nodes in fs */ 53 fsid_t f_fsid; /* file system id */ 54 uid_t f_owner; /* user that mounted the file system */ 55 long f_flags; /* copy of mount flags */ 56 long f_syncwrites; /* count of sync writes since mount */ 57 long f_asyncwrites; /* count of async writes since mount */ 58 long f_spare[1]; /* spare for later */ 59 char f_fstypename[MFSNAMELEN]; /* fs type name */ 60 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 61 char f_mntfromname[MNAMELEN]; /* mounted file system */ 62 }; 63 64 #ifndef _KERNEL 65 #include <string.h> 66 #endif 67 68 /* 69 * Operations supported on mounted file system. 70 */ 71 /* 72 * Convert from a new statvfs to an old statfs structure. 73 */ 74 75 #define MOUNTNO_NONE 0 76 #define MOUNTNO_UFS 1 /* UNIX "Fast" Filesystem */ 77 #define MOUNTNO_NFS 2 /* Network Filesystem */ 78 #define MOUNTNO_MFS 3 /* Memory Filesystem */ 79 #define MOUNTNO_MSDOS 4 /* MSDOS Filesystem */ 80 #define MOUNTNO_CD9660 5 /* iso9660 cdrom */ 81 #define MOUNTNO_FDESC 6 /* /dev/fd filesystem */ 82 #define MOUNTNO_KERNFS 7 /* kernel variable filesystem */ 83 #define MOUNTNO_DEVFS 8 /* device node filesystem */ 84 #define MOUNTNO_AFS 9 /* AFS 3.x */ 85 86 static const struct { 87 const char *name; 88 const int value; 89 } __nv[] = { 90 { MOUNT_UFS, MOUNTNO_UFS }, 91 { MOUNT_NFS, MOUNTNO_NFS }, 92 { MOUNT_MFS, MOUNTNO_MFS }, 93 { MOUNT_MSDOS, MOUNTNO_MSDOS }, 94 { MOUNT_CD9660, MOUNTNO_CD9660 }, 95 { MOUNT_FDESC, MOUNTNO_FDESC }, 96 { MOUNT_KERNFS, MOUNTNO_KERNFS }, 97 { MOUNT_AFS, MOUNTNO_AFS }, 98 }; 99 100 static __inline void 101 statvfs_to_statfs12(const struct statvfs *fs, struct statfs12 *s12) 102 { 103 size_t i = 0; 104 s12->f_type = 0; 105 s12->f_oflags = (short)fs->f_flag; 106 107 memset(s12, 0, sizeof(*s12)); 108 for (i = 0; i < sizeof(__nv) / sizeof(__nv[0]); i++) { 109 if (strcmp(__nv[i].name, fs->f_fstypename) == 0) { 110 s12->f_type = __nv[i].value; 111 break; 112 } 113 } 114 #define __STATFSCLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a)) 115 s12->f_bsize = __STATFSCLAMP(fs->f_frsize); 116 s12->f_iosize = __STATFSCLAMP(fs->f_iosize); 117 s12->f_blocks = __STATFSCLAMP(fs->f_blocks); 118 s12->f_bfree = __STATFSCLAMP(fs->f_bfree); 119 if (fs->f_bfree > fs->f_bresvd) 120 s12->f_bavail = __STATFSCLAMP(fs->f_bfree - fs->f_bresvd); 121 else 122 s12->f_bavail = -__STATFSCLAMP(fs->f_bresvd - fs->f_bfree); 123 s12->f_files = __STATFSCLAMP(fs->f_files); 124 s12->f_ffree = __STATFSCLAMP(fs->f_ffree); 125 s12->f_fsid = fs->f_fsidx; 126 s12->f_owner = fs->f_owner; 127 s12->f_flags = (long)fs->f_flag; 128 s12->f_syncwrites = __STATFSCLAMP(fs->f_syncwrites); 129 s12->f_asyncwrites = __STATFSCLAMP(fs->f_asyncwrites); 130 memcpy(s12->f_fstypename, fs->f_fstypename, sizeof(s12->f_fstypename)); 131 memcpy(s12->f_mntonname, fs->f_mntonname, sizeof(s12->f_mntonname)); 132 memcpy(s12->f_mntfromname, fs->f_mntfromname, 133 sizeof(s12->f_mntfromname)); 134 } 135 136 #ifdef _KERNEL 137 static __inline int 138 statvfs_to_statfs12_copy(const void *vs, void *vs12, size_t l) 139 { 140 struct statfs12 *s12 = STATVFSBUF_GET(); 141 int error; 142 143 statvfs_to_statfs12(vs, vs12); 144 error = copyout(s12, vs12, l); 145 STATVFSBUF_PUT(s12); 146 147 return error; 148 } 149 150 /* 151 * Filesystem configuration information. Not used by NetBSD, but 152 * defined here to provide a compatible sysctl interface to Lite2. 153 */ 154 struct vfsconf { 155 struct vfsops *vfc_vfsops; /* filesystem operations vector */ 156 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 157 int vfc_typenum; /* historic filesystem type number */ 158 int vfc_refcount; /* number mounted of this type */ 159 int vfc_flags; /* permanent flags */ 160 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */ 161 struct vfsconf *vfc_next; /* next in list */ 162 }; 163 164 /* Old, fixed size filehandle structures (used upto (including) 3.x) */ 165 struct compat_30_fid { 166 unsigned short fid_len; 167 unsigned short fid_reserved; 168 char fid_data[16]; 169 }; 170 struct compat_30_fhandle { 171 fsid_t fh_fsid; 172 struct compat_30_fid fh_fid; 173 }; 174 175 #else 176 177 __BEGIN_DECLS 178 int __compat_fstatfs(int, struct statfs12 *) __dso_hidden; 179 int __compat_getfsstat(struct statfs12 *, long, int) __dso_hidden; 180 int __compat_statfs(const char *, struct statfs12 *) __dso_hidden; 181 int __compat_getmntinfo(struct statfs12 **, int) __dso_hidden; 182 #if defined(_NETBSD_SOURCE) 183 struct compat_30_fhandle; 184 int __compat_fhstatfs(const struct compat_30_fhandle *, struct statfs12 *) 185 __dso_hidden; 186 struct stat13; 187 int __compat_fhstat(const struct compat_30_fhandle *, struct stat13 *) 188 __dso_hidden; 189 struct stat30; 190 int __compat___fhstat30(const struct compat_30_fhandle *, struct stat30 *) 191 __dso_hidden; 192 int __compat___fhstat40(const void *, size_t, struct stat30 *) __dso_hidden; 193 struct stat; 194 int __fhstat50(const void *, size_t, struct stat *); 195 #endif /* _NETBSD_SOURCE */ 196 __END_DECLS 197 198 #endif /* _KERNEL */ 199 200 #endif /* !_COMPAT_SYS_MOUNT_H_ */ 201