1 /* 2 * Copyright (c) 1989, 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)mount.h 7.38 (Berkeley) 07/18/92 8 */ 9 10 #ifndef KERNEL 11 #include <sys/ucred.h> 12 #endif 13 14 typedef struct { long val[2]; } fsid_t; /* file system id type */ 15 16 /* 17 * File identifier. 18 * These are unique per filesystem on a single machine. 19 */ 20 #define MAXFIDSZ 16 21 22 struct fid { 23 u_short fid_len; /* length of data in bytes */ 24 u_short fid_reserved; /* force longword alignment */ 25 char fid_data[MAXFIDSZ]; /* data (variable length) */ 26 }; 27 28 /* 29 * file system statistics 30 */ 31 32 #define MNAMELEN 90 /* length of buffer for returned name */ 33 34 struct statfs { 35 short f_type; /* type of filesystem (see below) */ 36 short f_flags; /* copy of mount flags */ 37 long f_bsize; /* fundamental file system block size */ 38 long f_iosize; /* optimal transfer block size */ 39 long f_blocks; /* total data blocks in file system */ 40 long f_bfree; /* free blocks in fs */ 41 long f_bavail; /* free blocks avail to non-superuser */ 42 long f_files; /* total file nodes in file system */ 43 long f_ffree; /* free file nodes in fs */ 44 fsid_t f_fsid; /* file system id */ 45 long f_spare[9]; /* spare for later */ 46 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 47 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 48 }; 49 50 /* 51 * File system types. 52 */ 53 #define MOUNT_NONE 0 54 #define MOUNT_UFS 1 55 #define MOUNT_NFS 2 56 #define MOUNT_MFS 3 57 #define MOUNT_PC 4 58 #define MOUNT_LFS 5 59 #define MOUNT_LOFS 6 60 #define MOUNT_FDESC 7 61 #define MOUNT_PORTAL 8 62 #define MOUNT_NULL 9 63 #define MOUNT_UMAP 10 64 #define MOUNT_KERNFS 11 65 #define MOUNT_MAXTYPE 11 66 67 #define INITMOUNTNAMES { \ 68 "none", /* 0 MOUNT_NONE */ \ 69 "ufs", /* 1 MOUNT_UFS */ \ 70 "nfs", /* 2 MOUNT_NFS */ \ 71 "mfs", /* 3 MOUNT_MFS */ \ 72 "pc", /* 4 MOUNT_PC */ \ 73 "lfs", /* 5 MOUNT_LFS */ \ 74 "lofs", /* 6 MOUNT_LOFS */ \ 75 "fdesc", /* 7 MOUNT_FDESC */ \ 76 "portal", /* 8 MOUNT_PORTAL */ \ 77 "null", /* 9 MOUNT_NULL */ \ 78 "umap", /* 10 MOUNT_UMAP */ \ 79 "kernfs", /* 11 MOUNT_KERNFS */ \ 80 0, /* 12 MOUNT_SPARE */ \ 81 } 82 83 /* 84 * Structure per mounted file system. Each mounted file system has an 85 * array of operations and an instance record. The file systems are 86 * put on a doubly linked list. 87 */ 88 struct mount { 89 struct mount *mnt_next; /* next in mount list */ 90 struct mount *mnt_prev; /* prev in mount list */ 91 struct vfsops *mnt_op; /* operations on fs */ 92 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 93 struct vnode *mnt_mounth; /* list of vnodes this mount */ 94 int mnt_flag; /* flags */ 95 int mnt_maxsymlinklen; /* max size of short symlink */ 96 struct statfs mnt_stat; /* cache of filesystem stats */ 97 qaddr_t mnt_data; /* private data */ 98 }; 99 100 /* 101 * Mount flags. 102 */ 103 #define MNT_RDONLY 0x00000001 /* read only filesystem */ 104 #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 105 #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 106 #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 107 #define MNT_NODEV 0x00000010 /* don't interpret special files */ 108 109 /* 110 * exported mount flags. 111 */ 112 #define MNT_EXRDONLY 0x00000080 /* exported read only */ 113 #define MNT_EXPORTED 0x00000100 /* file system is exported */ 114 #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 115 #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 116 #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 117 118 /* 119 * Flags set by internal operations. 120 */ 121 #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 122 #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 123 124 /* 125 * Mask of flags that are visible to statfs() 126 */ 127 #define MNT_VISFLAGMASK 0x0000ffff 128 129 /* 130 * filesystem control flags. 131 * 132 * MNT_MLOCK lock the mount entry so that name lookup cannot proceed 133 * past the mount point. This keeps the subtree stable during mounts 134 * and unmounts. 135 */ 136 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 137 #define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 138 #define MNT_MLOCK 0x00100000 /* lock so that subtree is stable */ 139 #define MNT_MWAIT 0x00200000 /* someone is waiting for lock */ 140 #define MNT_MPBUSY 0x00400000 /* scan of mount point in progress */ 141 #define MNT_MPWANT 0x00800000 /* waiting for mount point */ 142 #define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 143 144 /* 145 * Operations supported on mounted file system. 146 */ 147 #ifdef KERNEL 148 #ifdef __STDC__ 149 struct nameidata; 150 struct mbuf; 151 #endif 152 153 struct vfsops { 154 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 155 struct nameidata *ndp, struct proc *p)); 156 int (*vfs_start) __P((struct mount *mp, int flags, 157 struct proc *p)); 158 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 159 struct proc *p)); 160 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 161 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 162 caddr_t arg, struct proc *p)); 163 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 164 struct proc *p)); 165 int (*vfs_sync) __P((struct mount *mp, int waitfor, 166 struct ucred *cred, struct proc *p)); 167 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 168 struct vnode **vpp)); 169 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 170 struct mbuf *nam, struct vnode **vpp, 171 int *exflagsp, struct ucred **credanonp)); 172 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 173 int (*vfs_init) __P((void)); 174 }; 175 176 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 177 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 178 #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 179 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 180 #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 181 #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 182 #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 183 #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 184 #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 185 #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 186 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 187 #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 188 #endif /* KERNEL */ 189 190 /* 191 * Flags for various system call interfaces. 192 * 193 * forcibly flags for vfs_umount(). 194 * waitfor flags to vfs_sync() and getfsstat() 195 */ 196 #define MNT_FORCE 1 197 #define MNT_NOFORCE 2 198 #define MNT_WAIT 1 199 #define MNT_NOWAIT 2 200 201 /* 202 * Generic file handle 203 */ 204 struct fhandle { 205 fsid_t fh_fsid; /* File system id of mount point */ 206 struct fid fh_fid; /* File sys specific id */ 207 }; 208 typedef struct fhandle fhandle_t; 209 210 /* 211 * Network address hash list element 212 */ 213 union nethostaddr { 214 u_long had_inetaddr; 215 struct mbuf *had_nam; 216 }; 217 218 struct netaddrhash { 219 struct netaddrhash *neth_next; 220 struct ucred neth_anon; 221 u_short neth_family; 222 union nethostaddr neth_haddr; 223 union nethostaddr neth_hmask; 224 int neth_exflags; 225 }; 226 #define neth_inetaddr neth_haddr.had_inetaddr 227 #define neth_inetmask neth_hmask.had_inetaddr 228 #define neth_nam neth_haddr.had_nam 229 #define neth_msk neth_hmask.had_nam 230 231 /* 232 * Network address hashing defs. 233 */ 234 #define NETHASHSZ 8 /* Must be a power of 2 <= 256 */ 235 #define NETMASK_HASH NETHASHSZ /* Last hash table element is for networks */ 236 #define NETADDRHASH(a) \ 237 (((a)->sa_family == AF_INET) ? ((a)->sa_data[5] & (NETHASHSZ - 1)) : \ 238 (((a)->sa_family == AF_ISO) ? iso_addrhash(a) : 0)) 239 240 /* 241 * Arguments to mount UFS-based filesystems 242 */ 243 struct ufs_args { 244 char *fspec; /* block special device to mount */ 245 int exflags; /* export related flags */ 246 uid_t exroot; /* mapping for root uid */ 247 struct ucred anon; /* mapping for anonymous user */ 248 struct sockaddr *saddr;/* net address to which exported */ 249 int slen; /* and the net address length */ 250 struct sockaddr *smask;/* mask of valid bits in saddr */ 251 int msklen; /* and the smask length */ 252 }; 253 254 #ifdef MFS 255 /* 256 * Arguments to mount MFS 257 */ 258 struct mfs_args { 259 char *name; /* name to export for statfs */ 260 caddr_t base; /* base address of file system in memory */ 261 u_long size; /* size of file system */ 262 }; 263 #endif /* MFS */ 264 265 #ifdef NFS 266 /* 267 * File Handle (32 bytes for version 2), variable up to 1024 for version 3 268 */ 269 union nfsv2fh { 270 fhandle_t fh_generic; 271 u_char fh_bytes[32]; 272 }; 273 typedef union nfsv2fh nfsv2fh_t; 274 275 /* 276 * Arguments to mount NFS 277 */ 278 struct nfs_args { 279 struct sockaddr *addr; /* file server address */ 280 int addrlen; /* length of address */ 281 int sotype; /* Socket type */ 282 int proto; /* and Protocol */ 283 nfsv2fh_t *fh; /* File handle to be mounted */ 284 int flags; /* flags */ 285 int wsize; /* write size in bytes */ 286 int rsize; /* read size in bytes */ 287 int timeo; /* initial timeout in .1 secs */ 288 int retrans; /* times to retry send */ 289 int maxgrouplist; /* Max. size of group list */ 290 int readahead; /* # of blocks to readahead */ 291 int leaseterm; /* Term (sec) of lease */ 292 int deadthresh; /* Retrans threshold */ 293 char *hostname; /* server's name */ 294 }; 295 296 297 /* 298 * NFS mount option flags 299 */ 300 #define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */ 301 #define NFSMNT_WSIZE 0x00000002 /* set write size */ 302 #define NFSMNT_RSIZE 0x00000004 /* set read size */ 303 #define NFSMNT_TIMEO 0x00000008 /* set initial timeout */ 304 #define NFSMNT_RETRANS 0x00000010 /* set number of request retrys */ 305 #define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */ 306 #define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */ 307 #define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */ 308 #define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */ 309 #define NFSMNT_MYWRITE 0x00000200 /* Assume writes were mine */ 310 #define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */ 311 #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ 312 #define NFSMNT_RDIRALOOK 0x00001000 /* Do lookup with readdir (nqnfs) */ 313 #define NFSMNT_LEASETERM 0x00002000 /* set lease term (nqnfs) */ 314 #define NFSMNT_READAHEAD 0x00004000 /* set read ahead */ 315 #define NFSMNT_DEADTHRESH 0x00008000 /* set dead server retry thresh */ 316 #define NFSMNT_NQLOOKLEASE 0x00010000 /* Get lease for lookup */ 317 #define NFSMNT_RESVPORT 0x00020000 /* Allocate a reserved port */ 318 #define NFSMNT_INTERNAL 0xffe00000 /* Bits set internally */ 319 #define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */ 320 #define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */ 321 #define NFSMNT_DISMNT 0x00800000 /* Dismounted */ 322 #define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */ 323 #define NFSMNT_WANTSND 0x02000000 /* Want above */ 324 #define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */ 325 #define NFSMNT_WANTRCV 0x08000000 /* Want above */ 326 #define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */ 327 #define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */ 328 #define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */ 329 #define NFSMNT_AUTHERR 0x80000000 /* Authentication error */ 330 #endif /* NFS */ 331 332 #ifdef KERNEL 333 /* 334 * exported vnode operations 335 */ 336 void vfs_remove __P((struct mount *mp)); /* remove a vfs from mount list */ 337 int vfs_lock __P((struct mount *mp)); /* lock a vfs */ 338 void vfs_unlock __P((struct mount *mp)); /* unlock a vfs */ 339 struct mount *getvfs __P((fsid_t *fsid)); /* return vfs given fsid */ 340 extern struct mount *rootfs; /* ptr to root mount structure */ 341 extern struct vfsops *vfssw[]; /* mount filesystem type table */ 342 343 #else /* KERNEL */ 344 345 #include <sys/cdefs.h> 346 347 __BEGIN_DECLS 348 int fstatfs __P((int, struct statfs *)); 349 int getfh __P((const char *, fhandle_t *)); 350 int getfsstat __P((struct statfs *, long, int)); 351 int getmntinfo __P((struct statfs **, int)); 352 int mount __P((int, const char *, int, void *)); 353 int statfs __P((const char *, struct statfs *)); 354 int unmount __P((const char *, int)); 355 __END_DECLS 356 357 #endif /* KERNEL */ 358