1 /* 2 * Copyright (c) 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)mount.h 8.21 (Berkeley) 05/20/95 8 */ 9 10 #ifndef KERNEL 11 #include <sys/ucred.h> 12 #endif 13 #include <sys/queue.h> 14 #include <sys/lock.h> 15 #include <net/radix.h> 16 #include <sys/socket.h> /* XXX for AF_MAX */ 17 18 typedef struct { int32_t val[2]; } fsid_t; /* file system id type */ 19 20 /* 21 * File identifier. 22 * These are unique per filesystem on a single machine. 23 */ 24 #define MAXFIDSZ 16 25 26 struct fid { 27 u_short fid_len; /* length of data in bytes */ 28 u_short fid_reserved; /* force longword alignment */ 29 char fid_data[MAXFIDSZ]; /* data (variable length) */ 30 }; 31 32 /* 33 * file system statistics 34 */ 35 36 #define MFSNAMELEN 16 /* length of fs type name, including null */ 37 #define MNAMELEN 90 /* length of buffer for returned name */ 38 39 struct statfs { 40 short f_type; /* filesystem type number */ 41 short f_flags; /* copy of mount flags */ 42 long f_bsize; /* fundamental file system block size */ 43 long f_iosize; /* optimal transfer block size */ 44 long f_blocks; /* total data blocks in file system */ 45 long f_bfree; /* free blocks in fs */ 46 long f_bavail; /* free blocks avail to non-superuser */ 47 long f_files; /* total file nodes in file system */ 48 long f_ffree; /* free file nodes in fs */ 49 fsid_t f_fsid; /* file system id */ 50 uid_t f_owner; /* user that mounted the filesystem */ 51 long f_spare[4]; /* spare for later */ 52 char f_fstypename[MFSNAMELEN]; /* fs type name */ 53 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 54 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 55 }; 56 57 /* 58 * Structure per mounted file system. Each mounted file system has an 59 * array of operations and an instance record. The file systems are 60 * put on a doubly linked list. 61 */ 62 LIST_HEAD(vnodelst, vnode); 63 64 struct mount { 65 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */ 66 struct vfsops *mnt_op; /* operations on fs */ 67 struct vfsconf *mnt_vfc; /* configuration info */ 68 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 69 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 70 struct lock mnt_lock; /* mount structure lock */ 71 int mnt_flag; /* flags */ 72 int mnt_maxsymlinklen; /* max size of short symlink */ 73 struct statfs mnt_stat; /* cache of filesystem stats */ 74 qaddr_t mnt_data; /* private data */ 75 }; 76 77 /* 78 * Mount flags. 79 * 80 * Unmount uses MNT_FORCE flag. 81 */ 82 #define MNT_RDONLY 0x00000001 /* read only filesystem */ 83 #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 84 #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 85 #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 86 #define MNT_NODEV 0x00000010 /* don't interpret special files */ 87 #define MNT_UNION 0x00000020 /* union with underlying filesystem */ 88 #define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 89 90 /* 91 * exported mount flags. 92 */ 93 #define MNT_EXRDONLY 0x00000080 /* exported read only */ 94 #define MNT_EXPORTED 0x00000100 /* file system is exported */ 95 #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 96 #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 97 #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 98 99 /* 100 * Flags set by internal operations. 101 */ 102 #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 103 #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 104 #define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 105 106 /* 107 * Mask of flags that are visible to statfs() 108 */ 109 #define MNT_VISFLAGMASK 0x0000ffff 110 111 /* 112 * External filesystem control flags. 113 */ 114 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 115 #define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 116 #define MNT_RELOAD 0x00040000 /* reload filesystem data */ 117 #define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 118 /* 119 * Internal filesystem control flags. 120 * 121 * MNT_UNMOUNT locks the mount entry so that name lookup cannot proceed 122 * past the mount point. This keeps the subtree stable during mounts 123 * and unmounts. 124 */ 125 #define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 126 #define MNT_MWAIT 0x02000000 /* waiting for unmount to finish */ 127 #define MNT_WANTRDWR 0x04000000 /* upgrade to read/write requested */ 128 129 /* 130 * Sysctl CTL_VFS definitions. 131 * 132 * Second level identifier specifies which filesystem. Second level 133 * identifier VFS_GENERIC returns information about all filesystems. 134 */ 135 #define VFS_GENERIC 0 /* generic filesystem information */ 136 /* 137 * Third level identifiers for VFS_GENERIC are given below; third 138 * level identifiers for specific filesystems are given in their 139 * mount specific header files. 140 */ 141 #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 142 #define VFS_CONF 2 /* struct: vfsconf for filesystem given 143 as next argument */ 144 145 /* 146 * Flags for various system call interfaces. 147 * 148 * waitfor flags to vfs_sync() and getfsstat() 149 */ 150 #define MNT_WAIT 1 151 #define MNT_NOWAIT 2 152 153 /* 154 * Generic file handle 155 */ 156 struct fhandle { 157 fsid_t fh_fsid; /* File system id of mount point */ 158 struct fid fh_fid; /* File sys specific id */ 159 }; 160 typedef struct fhandle fhandle_t; 161 162 /* 163 * Export arguments for local filesystem mount calls. 164 */ 165 struct export_args { 166 int ex_flags; /* export related flags */ 167 uid_t ex_root; /* mapping for root uid */ 168 struct ucred ex_anon; /* mapping for anonymous user */ 169 struct sockaddr *ex_addr; /* net address to which exported */ 170 int ex_addrlen; /* and the net address length */ 171 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 172 int ex_masklen; /* and the smask length */ 173 }; 174 175 /* 176 * Filesystem configuration information. One of these exists for each 177 * type of filesystem supported by the kernel. These are searched at 178 * mount time to identify the requested filesystem. 179 */ 180 struct vfsconf { 181 struct vfsops *vfc_vfsops; /* filesystem operations vector */ 182 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 183 int vfc_typenum; /* historic filesystem type number */ 184 int vfc_refcount; /* number mounted of this type */ 185 int vfc_flags; /* permanent flags */ 186 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */ 187 struct vfsconf *vfc_next; /* next in list */ 188 }; 189 190 #ifdef KERNEL 191 192 extern int maxvfsconf; /* highest defined filesystem type */ 193 extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 194 195 /* 196 * Operations supported on mounted file system. 197 */ 198 #ifdef __STDC__ 199 struct nameidata; 200 struct mbuf; 201 #endif 202 203 struct vfsops { 204 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 205 struct nameidata *ndp, struct proc *p)); 206 int (*vfs_start) __P((struct mount *mp, int flags, 207 struct proc *p)); 208 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 209 struct proc *p)); 210 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 211 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 212 caddr_t arg, struct proc *p)); 213 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 214 struct proc *p)); 215 int (*vfs_sync) __P((struct mount *mp, int waitfor, 216 struct ucred *cred, struct proc *p)); 217 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 218 struct vnode **vpp)); 219 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 220 struct mbuf *nam, struct vnode **vpp, 221 int *exflagsp, struct ucred **credanonp)); 222 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 223 int (*vfs_init) __P((struct vfsconf *)); 224 int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *, 225 size_t, struct proc *)); 226 }; 227 228 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 229 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 230 #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 231 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 232 #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 233 #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 234 #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 235 #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 236 #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 237 #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 238 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 239 #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 240 241 /* 242 * Network address lookup element 243 */ 244 struct netcred { 245 struct radix_node netc_rnodes[2]; 246 int netc_exflags; 247 struct ucred netc_anon; 248 }; 249 250 /* 251 * Network export information 252 */ 253 struct netexport { 254 struct netcred ne_defexported; /* Default export */ 255 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 256 }; 257 258 /* 259 * exported vnode operations 260 */ 261 int vfs_busy __P((struct mount *, int, struct simplelock *, struct proc *)); 262 int vfs_export __P((struct mount *, struct netexport *, 263 struct export_args *)); 264 struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *, 265 struct mbuf *)); 266 void vfs_getnewfsid __P((struct mount *)); 267 struct mount *vfs_getvfs __P((fsid_t *)); 268 int vfs_mountedon __P((struct vnode *)); 269 int vfs_mountroot __P((void)); 270 int vfs_rootmountalloc __P((char *, char *, struct mount **)); 271 void vfs_unbusy __P((struct mount *, struct proc *)); 272 void vfs_unmountall __P((void)); 273 extern CIRCLEQ_HEAD(mntlist, mount) mountlist; 274 extern struct simplelock mountlist_slock; 275 276 #else /* !KERNEL */ 277 278 #include <sys/cdefs.h> 279 280 __BEGIN_DECLS 281 int fstatfs __P((int, struct statfs *)); 282 int getfh __P((const char *, fhandle_t *)); 283 int getfsstat __P((struct statfs *, long, int)); 284 int getmntinfo __P((struct statfs **, int)); 285 int mount __P((const char *, const char *, int, void *)); 286 int statfs __P((const char *, struct statfs *)); 287 int unmount __P((const char *, int)); 288 __END_DECLS 289 290 #endif /* KERNEL */ 291