1*2166d7a6Sriastradh /* $NetBSD: mount.h,v 1.15 2021/08/30 08:40:00 riastradh 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
645d25767aSchristos #ifndef _KERNEL
655d25767aSchristos #include <string.h>
665d25767aSchristos #endif
675d25767aSchristos
68063b880cSchristos /*
69063b880cSchristos * Operations supported on mounted file system.
70063b880cSchristos */
715d25767aSchristos /*
725d25767aSchristos * Convert from a new statvfs to an old statfs structure.
735d25767aSchristos */
745d25767aSchristos
755d25767aSchristos #define MOUNTNO_NONE 0
765d25767aSchristos #define MOUNTNO_UFS 1 /* UNIX "Fast" Filesystem */
775d25767aSchristos #define MOUNTNO_NFS 2 /* Network Filesystem */
785d25767aSchristos #define MOUNTNO_MFS 3 /* Memory Filesystem */
795d25767aSchristos #define MOUNTNO_MSDOS 4 /* MSDOS Filesystem */
805d25767aSchristos #define MOUNTNO_CD9660 5 /* iso9660 cdrom */
815d25767aSchristos #define MOUNTNO_FDESC 6 /* /dev/fd filesystem */
825d25767aSchristos #define MOUNTNO_KERNFS 7 /* kernel variable filesystem */
835d25767aSchristos #define MOUNTNO_DEVFS 8 /* device node filesystem */
845d25767aSchristos #define MOUNTNO_AFS 9 /* AFS 3.x */
855d25767aSchristos
865d25767aSchristos static const struct {
875d25767aSchristos const char *name;
885d25767aSchristos const int value;
895d25767aSchristos } __nv[] = {
905d25767aSchristos { MOUNT_UFS, MOUNTNO_UFS },
915d25767aSchristos { MOUNT_NFS, MOUNTNO_NFS },
925d25767aSchristos { MOUNT_MFS, MOUNTNO_MFS },
935d25767aSchristos { MOUNT_MSDOS, MOUNTNO_MSDOS },
945d25767aSchristos { MOUNT_CD9660, MOUNTNO_CD9660 },
955d25767aSchristos { MOUNT_FDESC, MOUNTNO_FDESC },
965d25767aSchristos { MOUNT_KERNFS, MOUNTNO_KERNFS },
975d25767aSchristos { MOUNT_AFS, MOUNTNO_AFS },
985d25767aSchristos };
995d25767aSchristos
1005d25767aSchristos static __inline void
statvfs_to_statfs12(const struct statvfs * fs,struct statfs12 * s12)1015d25767aSchristos statvfs_to_statfs12(const struct statvfs *fs, struct statfs12 *s12)
1025d25767aSchristos {
1035d25767aSchristos size_t i = 0;
104*2166d7a6Sriastradh
105*2166d7a6Sriastradh memset(s12, 0, sizeof(*s12));
106*2166d7a6Sriastradh
1075d25767aSchristos s12->f_type = 0;
1085d25767aSchristos s12->f_oflags = (short)fs->f_flag;
1095d25767aSchristos
1105d25767aSchristos for (i = 0; i < sizeof(__nv) / sizeof(__nv[0]); i++) {
1115d25767aSchristos if (strcmp(__nv[i].name, fs->f_fstypename) == 0) {
1125d25767aSchristos s12->f_type = __nv[i].value;
1135d25767aSchristos break;
1145d25767aSchristos }
1155d25767aSchristos }
1165d25767aSchristos #define __STATFSCLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
1175d25767aSchristos s12->f_bsize = __STATFSCLAMP(fs->f_frsize);
1185d25767aSchristos s12->f_iosize = __STATFSCLAMP(fs->f_iosize);
1195d25767aSchristos s12->f_blocks = __STATFSCLAMP(fs->f_blocks);
1205d25767aSchristos s12->f_bfree = __STATFSCLAMP(fs->f_bfree);
1215d25767aSchristos if (fs->f_bfree > fs->f_bresvd)
1225d25767aSchristos s12->f_bavail = __STATFSCLAMP(fs->f_bfree - fs->f_bresvd);
1235d25767aSchristos else
1245d25767aSchristos s12->f_bavail = -__STATFSCLAMP(fs->f_bresvd - fs->f_bfree);
1255d25767aSchristos s12->f_files = __STATFSCLAMP(fs->f_files);
1265d25767aSchristos s12->f_ffree = __STATFSCLAMP(fs->f_ffree);
1275d25767aSchristos s12->f_fsid = fs->f_fsidx;
1285d25767aSchristos s12->f_owner = fs->f_owner;
1295d25767aSchristos s12->f_flags = (long)fs->f_flag;
1305d25767aSchristos s12->f_syncwrites = __STATFSCLAMP(fs->f_syncwrites);
1315d25767aSchristos s12->f_asyncwrites = __STATFSCLAMP(fs->f_asyncwrites);
1325d25767aSchristos memcpy(s12->f_fstypename, fs->f_fstypename, sizeof(s12->f_fstypename));
1335d25767aSchristos memcpy(s12->f_mntonname, fs->f_mntonname, sizeof(s12->f_mntonname));
1345d25767aSchristos memcpy(s12->f_mntfromname, fs->f_mntfromname,
1355d25767aSchristos sizeof(s12->f_mntfromname));
1365d25767aSchristos }
1375d25767aSchristos
138063b880cSchristos #ifdef _KERNEL
1395d25767aSchristos static __inline int
statvfs_to_statfs12_copy(const void * vs,void * vs12,size_t l)1405d25767aSchristos statvfs_to_statfs12_copy(const void *vs, void *vs12, size_t l)
1415d25767aSchristos {
1420be8f39aSjdolecek struct statfs12 *s12 = kmem_zalloc(sizeof(*s12), KM_SLEEP);
1435d25767aSchristos int error;
1445d25767aSchristos
1458d25bda6Smaxv statvfs_to_statfs12(vs, s12);
1461eaeaab0Schristos error = copyout(s12, vs12, sizeof(*s12));
1470be8f39aSjdolecek kmem_free(s12, sizeof(*s12));
1485d25767aSchristos
1495d25767aSchristos return error;
1505d25767aSchristos }
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
180a949d096Schristos int __compat_fstatfs(int, struct statfs12 *) __dso_hidden;
181a949d096Schristos int __compat_getfsstat(struct statfs12 *, long, int) __dso_hidden;
182a949d096Schristos int __compat_statfs(const char *, struct statfs12 *) __dso_hidden;
183a949d096Schristos int __compat_getmntinfo(struct statfs12 **, int) __dso_hidden;
184063b880cSchristos #if defined(_NETBSD_SOURCE)
185b4cb63a6Smartin struct compat_30_fhandle;
186a949d096Schristos int __compat_fhstatfs(const struct compat_30_fhandle *, struct statfs12 *)
187fafcda42Schristos __dso_hidden;
188bc364eb4Schristos struct stat13;
189a949d096Schristos int __compat_fhstat(const struct compat_30_fhandle *, struct stat13 *)
190fafcda42Schristos __dso_hidden;
191461a86f9Schristos struct stat30;
192a949d096Schristos int __compat___fhstat30(const struct compat_30_fhandle *, struct stat30 *)
193fafcda42Schristos __dso_hidden;
194a949d096Schristos int __compat___fhstat40(const void *, size_t, struct stat30 *) __dso_hidden;
195bc364eb4Schristos struct stat;
196461a86f9Schristos int __fhstat50(const void *, size_t, struct stat *);
197063b880cSchristos #endif /* _NETBSD_SOURCE */
198063b880cSchristos __END_DECLS
199063b880cSchristos
200063b880cSchristos #endif /* _KERNEL */
201063b880cSchristos
202063b880cSchristos #endif /* !_COMPAT_SYS_MOUNT_H_ */
203