1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * $Id$ 34 */ 35 36 typedef quad fsid_t; /* file system id type */ 37 38 /* 39 * File identifier. 40 * These are unique per filesystem on a single machine. 41 */ 42 #define MAXFIDSZ 16 43 44 struct fid { 45 u_short fid_len; /* length of data in bytes */ 46 u_short fid_reserved; /* force longword alignment */ 47 char fid_data[MAXFIDSZ]; /* data (variable length) */ 48 }; 49 50 /* 51 * file system statistics 52 */ 53 54 #define MNAMELEN 90 /* length of buffer for returned name */ 55 56 struct statfs { 57 short f_type; /* type of filesystem (see below) */ 58 short f_flags; /* copy of mount flags */ 59 long f_fsize; /* fundamental file system block size */ 60 long f_bsize; /* optimal transfer block size */ 61 long f_blocks; /* total data blocks in file system */ 62 long f_bfree; /* free blocks in fs */ 63 long f_bavail; /* free blocks avail to non-superuser */ 64 long f_files; /* total file nodes in file system */ 65 long f_ffree; /* free file nodes in fs */ 66 fsid_t f_fsid; /* file system id */ 67 long f_spare[9]; /* spare for later */ 68 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 69 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 70 }; 71 72 /* 73 * File system types. 74 */ 75 #define MOUNT_NONE 0 76 #define MOUNT_UFS 1 /* UNIX "Fast" Filesystem */ 77 #define MOUNT_NFS 2 /* Network Filesystem */ 78 #define MOUNT_MFS 3 /* Memory Filesystem */ 79 #define MOUNT_MSDOS 4 /* MSDOS Filesystem */ 80 #define MOUNT_ISOFS 5 /* iso9660 cdrom */ 81 /*#define MOUNT_MAXTYPE 5*/ 82 83 /* 84 * Structure per mounted file system. 85 * Each mounted file system has an array of 86 * operations and an instance record. 87 * The file systems are put on a doubly linked list. 88 */ 89 struct mount { 90 struct mount *mnt_next; /* next in mount list */ 91 struct mount *mnt_prev; /* prev in mount list */ 92 struct vfsops *mnt_op; /* operations on fs */ 93 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 94 struct vnode *mnt_mounth; /* list of vnodes this mount */ 95 int mnt_flag; /* flags */ 96 uid_t mnt_exroot; /* exported mapping for uid 0 */ 97 struct statfs mnt_stat; /* cache of filesystem stats */ 98 qaddr_t mnt_data; /* private data */ 99 }; 100 101 /* 102 * Mount flags. 103 */ 104 #define MNT_RDONLY 0x00000001 /* read only filesystem */ 105 #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 106 #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 107 #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 108 #define MNT_NODEV 0x00000010 /* don't interpret special files */ 109 #define MNT_WCHR 0x00000020 /* use wide characters instead */ 110 111 /* 112 * exported mount flags. 113 */ 114 #define MNT_EXPORTED 0x00000100 /* file system is exported */ 115 #define MNT_EXRDONLY 0x00000200 /* exported read only */ 116 117 /* 118 * Flags set by internal operations. 119 */ 120 #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 121 #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 122 123 /* 124 * Mask of flags that are visible to statfs() 125 */ 126 #define MNT_VISFLAGMASK 0x0000ffff 127 128 /* 129 * filesystem control flags. 130 * 131 * MNT_MLOCK lock the mount entry so that name lookup cannot proceed 132 * past the mount point. This keeps the subtree stable during mounts 133 * and unmounts. 134 */ 135 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 136 #define MNT_MLOCK 0x00100000 /* lock so that subtree is stable */ 137 #define MNT_MWAIT 0x00200000 /* someone is waiting for lock */ 138 #define MNT_MPBUSY 0x00400000 /* scan of mount point in progress */ 139 #define MNT_MPWANT 0x00800000 /* waiting for mount point */ 140 #define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 141 142 /* 143 * Operations supported on mounted file system. 144 */ 145 #ifdef KERNEL 146 #ifdef __STDC__ 147 struct nameidata; 148 #endif 149 150 /* XXX should be struct vfs */ 151 struct vfsops { 152 char *vfs_name; /* virtual filesystem module type name */ 153 int vfs_type; /* virtual filesystem module type */ 154 struct vfsops *vfs_next; /* next filesystem type */ 155 156 int (*vfs_mount)(struct mount *, char *, caddr_t, struct nameidata *, struct proc *); 157 int (*vfs_start)(struct mount *, int, struct proc *); 158 int (*vfs_unmount)(struct mount *, int, struct proc *); 159 int (*vfs_root)(struct mount *, struct vnode **); 160 int (*vfs_quotactl)(struct mount *, int, uid_t, caddr_t, struct proc *); 161 int (*vfs_statfs)(struct mount *, struct statfs *, struct proc *); 162 int (*vfs_sync)(struct mount *, int); 163 int (*vfs_fhtovp)(struct mount *, struct fid *, struct vnode **); 164 int (*vfs_vptofh)(struct vnode *, struct fid *); 165 int (*vfs_init) (void); 166 int (*vfs_mountroot)(void); 167 }; 168 169 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 170 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 171 #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 172 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 173 #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 174 #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 175 #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 176 #define VFS_SYNC(MP, WAITFOR) (*(MP)->mnt_op->vfs_sync)(MP, WAITFOR) 177 #define VFS_FHTOVP(MP, FIDP, VPP) (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP) 178 #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 179 #endif /* KERNEL */ 180 181 /* 182 * Flags for various system call interfaces. 183 * 184 * forcibly flags for vfs_umount(). 185 * waitfor flags to vfs_sync() and getfsstat() 186 */ 187 #define MNT_FORCE 1 188 #define MNT_NOFORCE 2 189 #define MNT_WAIT 1 190 #define MNT_NOWAIT 2 191 192 /* 193 * Generic file handle 194 */ 195 struct fhandle { 196 fsid_t fh_fsid; /* File system id of mount point */ 197 struct fid fh_fid; /* Id of file */ 198 }; 199 typedef struct fhandle fhandle_t; 200 201 /* 202 * Arguments to mount UFS 203 */ 204 struct ufs_args { 205 char *fspec; /* block special device to mount */ 206 int exflags; /* export related flags */ 207 uid_t exroot; /* mapping for root uid */ 208 }; 209 210 #ifdef MFS 211 /* 212 * Arguments to mount MFS 213 */ 214 struct mfs_args { 215 char *name; /* name to export for statfs */ 216 caddr_t base; /* base address of file system in memory */ 217 u_long size; /* size of file system */ 218 }; 219 #endif MFS 220 221 #ifdef NFS 222 /* 223 * File Handle (32 bytes for version 2), variable up to 1024 for version 3 224 */ 225 union nfsv2fh { 226 fhandle_t fh_generic; 227 u_char fh_bytes[32]; 228 }; 229 typedef union nfsv2fh nfsv2fh_t; 230 231 /* 232 * Arguments to mount NFS 233 */ 234 struct nfs_args { 235 struct sockaddr *addr; /* file server address */ 236 int sotype; /* Socket type */ 237 int proto; /* and Protocol */ 238 nfsv2fh_t *fh; /* File handle to be mounted */ 239 int flags; /* flags */ 240 int wsize; /* write size in bytes */ 241 int rsize; /* read size in bytes */ 242 int timeo; /* initial timeout in .1 secs */ 243 int retrans; /* times to retry send */ 244 char *hostname; /* server's name */ 245 }; 246 /* 247 * NFS mount option flags 248 */ 249 #define NFSMNT_SOFT 0x0001 /* soft mount (hard is default) */ 250 #define NFSMNT_WSIZE 0x0002 /* set write size */ 251 #define NFSMNT_RSIZE 0x0004 /* set read size */ 252 #define NFSMNT_TIMEO 0x0008 /* set initial timeout */ 253 #define NFSMNT_RETRANS 0x0010 /* set number of request retrys */ 254 #define NFSMNT_HOSTNAME 0x0020 /* set hostname for error printf */ 255 #define NFSMNT_INT 0x0040 /* allow interrupts on hard mount */ 256 #define NFSMNT_NOCONN 0x0080 /* Don't Connect the socket */ 257 #define NFSMNT_SCKLOCK 0x0100 /* Lock socket against others */ 258 #define NFSMNT_WANTSCK 0x0200 /* Want a socket lock */ 259 #define NFSMNT_SPONGY 0x0400 /* spongy mount (soft for stat and lookup) */ 260 #define NFSMNT_COMPRESS 0x0800 /* Compress nfs rpc xdr */ 261 #define NFSMNT_LOCKBITS (NFSMNT_SCKLOCK | NFSMNT_WANTSCK) 262 #endif NFS 263 264 #ifdef KERNEL 265 /* 266 * exported vnode operations 267 */ 268 void vfs_remove __P((struct mount *mp)); /* remove a vfs from mount list */ 269 270 /* interface symbols */ 271 #define __ISYM_VERSION__ "1" /* XXX RCS major revision number of hdr file */ 272 #include "isym.h" /* this header has interface symbols */ 273 274 /* global variables used in core kernel and other modules */ 275 __ISYM__(struct mount *, rootfs,) /* ptr to root mount structure */ 276 277 /* functions used in modules */ 278 __ISYM__(int, vfs_lock, (struct mount *mp)) /* lock a vfs */ 279 __ISYM__(void, vfs_unlock, (struct mount *mp)) /* unlock a vfs */ 280 __ISYM__(int, vfs_busy, (struct mount *mp)) /* busy a vfs */ 281 __ISYM__(void, vfs_unbusy, (struct mount *mp)) /* unbusy a vfs */ 282 __ISYM__(struct mount *, getvfs, (fsid_t *fsid)) /* return vfs given fsid */ 283 __ISYM__(void, mntflushbuf, (struct mount *mountp, int flags)) 284 __ISYM__(int, mntinvalbuf, (struct mount *mountp)) 285 __ISYM__(int, vflush, (struct mount *mp, struct vnode *skipvp, int flags)) 286 __ISYM__(void, addvfs, (struct vfsops *)) /* insert filesystem into vfslist */ 287 __ISYM__(void, cache_purgevfs, (struct mount *mp)) 288 289 #undef __ISYM__ 290 #undef __ISYM_ALIAS__ 291 #undef __ISYM_VERSION__ 292 293 /* XXX temp vm interface */ 294 void vnode_pager_umount(struct mount *mp); 295 296 /* struct vfsops *vfssw[]; /* mount filesystem type table */ 297 extern struct vfsops *vfs; /* head of vfs list */ 298 struct vfsops *findvfs(int type); /* return vfs associated with type */ 299 /* use another filesystem to complete a different filesystem */ 300 void incoporatefs(struct vfsops *, struct vfsops *); 301 /*int (*mountroot)(); /* perform mount of root filesystem */ 302 303 #else /* KERNEL */ 304 305 #include <sys/cdefs.h> 306 307 __BEGIN_DECLS 308 int fstatfs __P((int, struct statfs *)); 309 int getfh __P((const char *, fhandle_t *)); 310 int getfsstat __P((struct statfs *, long, int)); 311 int getmntinfo __P((struct statfs **, int)); 312 int mount __P((int, const char *, int, void *)); 313 int statfs __P((const char *, struct statfs *)); 314 int unmount __P((const char *, int)); 315 __END_DECLS 316 317 #endif /* KERNEL */ 318