1*ab413307Schristos /* $NetBSD: mount.h,v 1.16 2024/01/19 18:39:15 christos Exp $ */
2063b880cSchristos
3063b880cSchristos /*
4063b880cSchristos * Copyright (c) 1989, 1991, 1993
5063b880cSchristos * The Regents of the University of California. All rights reserved.
6063b880cSchristos *
7063b880cSchristos * Redistribution and use in source and binary forms, with or without
8063b880cSchristos * modification, are permitted provided that the following conditions
9063b880cSchristos * are met:
10063b880cSchristos * 1. Redistributions of source code must retain the above copyright
11063b880cSchristos * notice, this list of conditions and the following disclaimer.
12063b880cSchristos * 2. Redistributions in binary form must reproduce the above copyright
13063b880cSchristos * notice, this list of conditions and the following disclaimer in the
14063b880cSchristos * documentation and/or other materials provided with the distribution.
15063b880cSchristos * 3. Neither the name of the University nor the names of its contributors
16063b880cSchristos * may be used to endorse or promote products derived from this software
17063b880cSchristos * without specific prior written permission.
18063b880cSchristos *
19063b880cSchristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20063b880cSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21063b880cSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22063b880cSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23063b880cSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24063b880cSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25063b880cSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26063b880cSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27063b880cSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28063b880cSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29063b880cSchristos * SUCH DAMAGE.
30063b880cSchristos *
31063b880cSchristos * @(#)mount.h 8.21 (Berkeley) 5/20/95
32063b880cSchristos */
33063b880cSchristos
34063b880cSchristos #ifndef _COMPAT_SYS_MOUNT_H_
35063b880cSchristos #define _COMPAT_SYS_MOUNT_H_
36063b880cSchristos
37063b880cSchristos #ifdef _KERNEL_OPT
38063b880cSchristos #include "opt_compat_43.h"
39063b880cSchristos #endif
40063b880cSchristos
41515c2436Schristos #define MFSNAMELEN 16
42063b880cSchristos
43063b880cSchristos struct statfs12 {
44063b880cSchristos short f_type; /* type of file system */
45063b880cSchristos u_short f_oflags; /* deprecated copy of mount flags */
46063b880cSchristos long f_bsize; /* fundamental file system block size */
47063b880cSchristos long f_iosize; /* optimal transfer block size */
48063b880cSchristos long f_blocks; /* total data blocks in file system */
49063b880cSchristos long f_bfree; /* free blocks in fs */
50063b880cSchristos long f_bavail; /* free blocks avail to non-superuser */
51063b880cSchristos long f_files; /* total file nodes in file system */
52063b880cSchristos long f_ffree; /* free file nodes in fs */
53063b880cSchristos fsid_t f_fsid; /* file system id */
54063b880cSchristos uid_t f_owner; /* user that mounted the file system */
55063b880cSchristos long f_flags; /* copy of mount flags */
56063b880cSchristos long f_syncwrites; /* count of sync writes since mount */
57063b880cSchristos long f_asyncwrites; /* count of async writes since mount */
58063b880cSchristos long f_spare[1]; /* spare for later */
59063b880cSchristos char f_fstypename[MFSNAMELEN]; /* fs type name */
60063b880cSchristos char f_mntonname[MNAMELEN]; /* directory on which mounted */
61063b880cSchristos char f_mntfromname[MNAMELEN]; /* mounted file system */
62063b880cSchristos };
63063b880cSchristos
64c8863f45Schristos #ifndef _KERNEL
65c8863f45Schristos #include <string.h>
66c8863f45Schristos #endif
67c8863f45Schristos
68063b880cSchristos /*
69063b880cSchristos * Operations supported on mounted file system.
70063b880cSchristos */
71c8863f45Schristos /*
72c8863f45Schristos * Convert from a new statvfs to an old statfs structure.
73c8863f45Schristos */
74c8863f45Schristos
75c8863f45Schristos #define MOUNTNO_NONE 0
76c8863f45Schristos #define MOUNTNO_UFS 1 /* UNIX "Fast" Filesystem */
77c8863f45Schristos #define MOUNTNO_NFS 2 /* Network Filesystem */
78c8863f45Schristos #define MOUNTNO_MFS 3 /* Memory Filesystem */
79c8863f45Schristos #define MOUNTNO_MSDOS 4 /* MSDOS Filesystem */
80c8863f45Schristos #define MOUNTNO_CD9660 5 /* iso9660 cdrom */
81c8863f45Schristos #define MOUNTNO_FDESC 6 /* /dev/fd filesystem */
82c8863f45Schristos #define MOUNTNO_KERNFS 7 /* kernel variable filesystem */
83c8863f45Schristos #define MOUNTNO_DEVFS 8 /* device node filesystem */
84c8863f45Schristos #define MOUNTNO_AFS 9 /* AFS 3.x */
85c8863f45Schristos
86c8863f45Schristos static const struct {
87c8863f45Schristos const char *name;
88c8863f45Schristos const int value;
89c8863f45Schristos } __nv[] = {
90c8863f45Schristos { MOUNT_UFS, MOUNTNO_UFS },
91c8863f45Schristos { MOUNT_NFS, MOUNTNO_NFS },
92c8863f45Schristos { MOUNT_MFS, MOUNTNO_MFS },
93c8863f45Schristos { MOUNT_MSDOS, MOUNTNO_MSDOS },
94c8863f45Schristos { MOUNT_CD9660, MOUNTNO_CD9660 },
95c8863f45Schristos { MOUNT_FDESC, MOUNTNO_FDESC },
96c8863f45Schristos { MOUNT_KERNFS, MOUNTNO_KERNFS },
97c8863f45Schristos { MOUNT_AFS, MOUNTNO_AFS },
98c8863f45Schristos };
99c8863f45Schristos
100c8863f45Schristos static __inline void
statvfs_to_statfs12(const struct statvfs * fs,struct statfs12 * s12)101c8863f45Schristos statvfs_to_statfs12(const struct statvfs *fs, struct statfs12 *s12)
102c8863f45Schristos {
103c8863f45Schristos size_t i = 0;
104702ca037Sriastradh
105702ca037Sriastradh memset(s12, 0, sizeof(*s12));
106702ca037Sriastradh
107c8863f45Schristos s12->f_type = 0;
108c8863f45Schristos s12->f_oflags = (short)fs->f_flag;
109c8863f45Schristos
110c8863f45Schristos for (i = 0; i < sizeof(__nv) / sizeof(__nv[0]); i++) {
111c8863f45Schristos if (strcmp(__nv[i].name, fs->f_fstypename) == 0) {
112c8863f45Schristos s12->f_type = __nv[i].value;
113c8863f45Schristos break;
114c8863f45Schristos }
115c8863f45Schristos }
116c8863f45Schristos #define __STATFSCLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
117c8863f45Schristos s12->f_bsize = __STATFSCLAMP(fs->f_frsize);
118c8863f45Schristos s12->f_iosize = __STATFSCLAMP(fs->f_iosize);
119c8863f45Schristos s12->f_blocks = __STATFSCLAMP(fs->f_blocks);
120c8863f45Schristos s12->f_bfree = __STATFSCLAMP(fs->f_bfree);
121c8863f45Schristos if (fs->f_bfree > fs->f_bresvd)
122c8863f45Schristos s12->f_bavail = __STATFSCLAMP(fs->f_bfree - fs->f_bresvd);
123c8863f45Schristos else
124c8863f45Schristos s12->f_bavail = -__STATFSCLAMP(fs->f_bresvd - fs->f_bfree);
125c8863f45Schristos s12->f_files = __STATFSCLAMP(fs->f_files);
126c8863f45Schristos s12->f_ffree = __STATFSCLAMP(fs->f_ffree);
127c8863f45Schristos s12->f_fsid = fs->f_fsidx;
128c8863f45Schristos s12->f_owner = fs->f_owner;
129c8863f45Schristos s12->f_flags = (long)fs->f_flag;
130c8863f45Schristos s12->f_syncwrites = __STATFSCLAMP(fs->f_syncwrites);
131c8863f45Schristos s12->f_asyncwrites = __STATFSCLAMP(fs->f_asyncwrites);
132c8863f45Schristos memcpy(s12->f_fstypename, fs->f_fstypename, sizeof(s12->f_fstypename));
133c8863f45Schristos memcpy(s12->f_mntonname, fs->f_mntonname, sizeof(s12->f_mntonname));
134c8863f45Schristos memcpy(s12->f_mntfromname, fs->f_mntfromname,
135c8863f45Schristos sizeof(s12->f_mntfromname));
136c8863f45Schristos }
137c8863f45Schristos
138063b880cSchristos #ifdef _KERNEL
139c8863f45Schristos static __inline int
statvfs_to_statfs12_copy(const void * vs,void * vs12,size_t l)140c8863f45Schristos statvfs_to_statfs12_copy(const void *vs, void *vs12, size_t l)
141c8863f45Schristos {
1426471d774Sjdolecek struct statfs12 *s12 = kmem_zalloc(sizeof(*s12), KM_SLEEP);
143c8863f45Schristos int error;
144c8863f45Schristos
145f2af77cbSmaxv statvfs_to_statfs12(vs, s12);
14628e771c9Schristos error = copyout(s12, vs12, sizeof(*s12));
1476471d774Sjdolecek kmem_free(s12, sizeof(*s12));
148c8863f45Schristos
149c8863f45Schristos return error;
150c8863f45Schristos }
151063b880cSchristos
152063b880cSchristos /*
153063b880cSchristos * Filesystem configuration information. Not used by NetBSD, but
154063b880cSchristos * defined here to provide a compatible sysctl interface to Lite2.
155063b880cSchristos */
156063b880cSchristos struct vfsconf {
157063b880cSchristos struct vfsops *vfc_vfsops; /* filesystem operations vector */
158063b880cSchristos char vfc_name[MFSNAMELEN]; /* filesystem type name */
159063b880cSchristos int vfc_typenum; /* historic filesystem type number */
160063b880cSchristos int vfc_refcount; /* number mounted of this type */
161063b880cSchristos int vfc_flags; /* permanent flags */
162063b880cSchristos int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
163063b880cSchristos struct vfsconf *vfc_next; /* next in list */
164063b880cSchristos };
165063b880cSchristos
166a3b5baedSmartin /* Old, fixed size filehandle structures (used upto (including) 3.x) */
167a3b5baedSmartin struct compat_30_fid {
168a3b5baedSmartin unsigned short fid_len;
169a3b5baedSmartin unsigned short fid_reserved;
170a3b5baedSmartin char fid_data[16];
171a3b5baedSmartin };
172a3b5baedSmartin struct compat_30_fhandle {
173a3b5baedSmartin fsid_t fh_fsid;
174a3b5baedSmartin struct compat_30_fid fh_fid;
175a3b5baedSmartin };
176a3b5baedSmartin
177063b880cSchristos #else
178063b880cSchristos
179063b880cSchristos __BEGIN_DECLS
180fda5f877Schristos int __compat_fstatfs(int, struct statfs12 *) __dso_hidden;
181fda5f877Schristos int __compat_getfsstat(struct statfs12 *, long, int) __dso_hidden;
182fda5f877Schristos int __compat_statfs(const char *, struct statfs12 *) __dso_hidden;
183fda5f877Schristos int __compat_getmntinfo(struct statfs12 **, int) __dso_hidden;
184063b880cSchristos #if defined(_NETBSD_SOURCE)
185b4cb63a6Smartin struct compat_30_fhandle;
186fda5f877Schristos int __compat_fhstatfs(const struct compat_30_fhandle *, struct statfs12 *)
187ca2d95d1Schristos __dso_hidden;
188bc364eb4Schristos struct stat13;
189fda5f877Schristos int __compat_fhstat(const struct compat_30_fhandle *, struct stat13 *)
190ca2d95d1Schristos __dso_hidden;
191461a86f9Schristos struct stat30;
192fda5f877Schristos int __compat___fhstat30(const struct compat_30_fhandle *, struct stat30 *)
193ca2d95d1Schristos __dso_hidden;
194fda5f877Schristos int __compat___fhstat40(const void *, size_t, struct stat30 *) __dso_hidden;
195bc364eb4Schristos struct stat;
196461a86f9Schristos int __fhstat50(const void *, size_t, struct stat *);
197*ab413307Schristos int __fhopen40(const void *, size_t, int);
198*ab413307Schristos int fhopen(const struct compat_30_fhandle *, int);
199*ab413307Schristos int __getfh30(const char *, void*, size_t *);
200*ab413307Schristos int getfh(const char *path, struct compat_30_fhandle *fhp);
201*ab413307Schristos int mount(const char *, const char *, int, void *);
202*ab413307Schristos int __mount50(const char *, const char *, int, void *, size_t);
203063b880cSchristos #endif /* _NETBSD_SOURCE */
204063b880cSchristos __END_DECLS
205063b880cSchristos
206063b880cSchristos #endif /* _KERNEL */
207063b880cSchristos
208063b880cSchristos #endif /* !_COMPAT_SYS_MOUNT_H_ */
209