1 /* $NetBSD: mount.h,v 1.15 2021/08/30 08:40:00 riastradh 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
statvfs_to_statfs12(const struct statvfs * fs,struct statfs12 * s12)101 statvfs_to_statfs12(const struct statvfs *fs, struct statfs12 *s12)
102 {
103 size_t i = 0;
104
105 memset(s12, 0, sizeof(*s12));
106
107 s12->f_type = 0;
108 s12->f_oflags = (short)fs->f_flag;
109
110 for (i = 0; i < sizeof(__nv) / sizeof(__nv[0]); i++) {
111 if (strcmp(__nv[i].name, fs->f_fstypename) == 0) {
112 s12->f_type = __nv[i].value;
113 break;
114 }
115 }
116 #define __STATFSCLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
117 s12->f_bsize = __STATFSCLAMP(fs->f_frsize);
118 s12->f_iosize = __STATFSCLAMP(fs->f_iosize);
119 s12->f_blocks = __STATFSCLAMP(fs->f_blocks);
120 s12->f_bfree = __STATFSCLAMP(fs->f_bfree);
121 if (fs->f_bfree > fs->f_bresvd)
122 s12->f_bavail = __STATFSCLAMP(fs->f_bfree - fs->f_bresvd);
123 else
124 s12->f_bavail = -__STATFSCLAMP(fs->f_bresvd - fs->f_bfree);
125 s12->f_files = __STATFSCLAMP(fs->f_files);
126 s12->f_ffree = __STATFSCLAMP(fs->f_ffree);
127 s12->f_fsid = fs->f_fsidx;
128 s12->f_owner = fs->f_owner;
129 s12->f_flags = (long)fs->f_flag;
130 s12->f_syncwrites = __STATFSCLAMP(fs->f_syncwrites);
131 s12->f_asyncwrites = __STATFSCLAMP(fs->f_asyncwrites);
132 memcpy(s12->f_fstypename, fs->f_fstypename, sizeof(s12->f_fstypename));
133 memcpy(s12->f_mntonname, fs->f_mntonname, sizeof(s12->f_mntonname));
134 memcpy(s12->f_mntfromname, fs->f_mntfromname,
135 sizeof(s12->f_mntfromname));
136 }
137
138 #ifdef _KERNEL
139 static __inline int
statvfs_to_statfs12_copy(const void * vs,void * vs12,size_t l)140 statvfs_to_statfs12_copy(const void *vs, void *vs12, size_t l)
141 {
142 struct statfs12 *s12 = kmem_zalloc(sizeof(*s12), KM_SLEEP);
143 int error;
144
145 statvfs_to_statfs12(vs, s12);
146 error = copyout(s12, vs12, sizeof(*s12));
147 kmem_free(s12, sizeof(*s12));
148
149 return error;
150 }
151
152 /*
153 * Filesystem configuration information. Not used by NetBSD, but
154 * defined here to provide a compatible sysctl interface to Lite2.
155 */
156 struct vfsconf {
157 struct vfsops *vfc_vfsops; /* filesystem operations vector */
158 char vfc_name[MFSNAMELEN]; /* filesystem type name */
159 int vfc_typenum; /* historic filesystem type number */
160 int vfc_refcount; /* number mounted of this type */
161 int vfc_flags; /* permanent flags */
162 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
163 struct vfsconf *vfc_next; /* next in list */
164 };
165
166 /* Old, fixed size filehandle structures (used upto (including) 3.x) */
167 struct compat_30_fid {
168 unsigned short fid_len;
169 unsigned short fid_reserved;
170 char fid_data[16];
171 };
172 struct compat_30_fhandle {
173 fsid_t fh_fsid;
174 struct compat_30_fid fh_fid;
175 };
176
177 #else
178
179 __BEGIN_DECLS
180 int __compat_fstatfs(int, struct statfs12 *) __dso_hidden;
181 int __compat_getfsstat(struct statfs12 *, long, int) __dso_hidden;
182 int __compat_statfs(const char *, struct statfs12 *) __dso_hidden;
183 int __compat_getmntinfo(struct statfs12 **, int) __dso_hidden;
184 #if defined(_NETBSD_SOURCE)
185 struct compat_30_fhandle;
186 int __compat_fhstatfs(const struct compat_30_fhandle *, struct statfs12 *)
187 __dso_hidden;
188 struct stat13;
189 int __compat_fhstat(const struct compat_30_fhandle *, struct stat13 *)
190 __dso_hidden;
191 struct stat30;
192 int __compat___fhstat30(const struct compat_30_fhandle *, struct stat30 *)
193 __dso_hidden;
194 int __compat___fhstat40(const void *, size_t, struct stat30 *) __dso_hidden;
195 struct stat;
196 int __fhstat50(const void *, size_t, struct stat *);
197 #endif /* _NETBSD_SOURCE */
198 __END_DECLS
199
200 #endif /* _KERNEL */
201
202 #endif /* !_COMPAT_SYS_MOUNT_H_ */
203