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