mount.h revision 2811
1/* 2 * Copyright (c) 1989, 1991, 1993 3 * The Regents of the University of California. 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 * @(#)mount.h 8.13 (Berkeley) 3/27/94 34 * $Id: mount.h,v 1.5 1994/08/22 14:09:51 bde Exp $ 35 */ 36 37#ifndef _SYS_MOUNT_H_ 38#define _SYS_MOUNT_H_ 39 40#ifndef KERNEL 41#include <sys/ucred.h> 42#endif 43#include <sys/queue.h> 44 45typedef struct { long val[2]; } fsid_t; /* file system id type */ 46 47/* 48 * File identifier. 49 * These are unique per filesystem on a single machine. 50 */ 51#define MAXFIDSZ 16 52 53struct fid { 54 u_short fid_len; /* length of data in bytes */ 55 u_short fid_reserved; /* force longword alignment */ 56 char fid_data[MAXFIDSZ]; /* data (variable length) */ 57}; 58 59/* 60 * file system statistics 61 */ 62 63#define MNAMELEN 90 /* length of buffer for returned name */ 64 65struct statfs { 66 short f_type; /* type of filesystem (see below) */ 67 short f_flags; /* copy of mount flags */ 68 long f_bsize; /* fundamental file system block size */ 69 long f_iosize; /* optimal transfer block size */ 70 long f_blocks; /* total data blocks in file system */ 71 long f_bfree; /* free blocks in fs */ 72 long f_bavail; /* free blocks avail to non-superuser */ 73 long f_files; /* total file nodes in file system */ 74 long f_ffree; /* free file nodes in fs */ 75 fsid_t f_fsid; /* file system id */ 76 long f_spare[9]; /* spare for later */ 77 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 78 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 79}; 80 81/* 82 * File system types. 83 */ 84#define MOUNT_NONE 0 85#define MOUNT_UFS 1 /* Fast Filesystem */ 86#define MOUNT_NFS 2 /* Sun-compatible Network Filesystem */ 87#define MOUNT_MFS 3 /* Memory-based Filesystem */ 88#define MOUNT_MSDOS 4 /* MS/DOS Filesystem */ 89#define MOUNT_LFS 5 /* Log-based Filesystem */ 90#define MOUNT_LOFS 6 /* Loopback Filesystem */ 91#define MOUNT_FDESC 7 /* File Descriptor Filesystem */ 92#define MOUNT_PORTAL 8 /* Portal Filesystem */ 93#define MOUNT_NULL 9 /* Minimal Filesystem Layer */ 94#define MOUNT_UMAP 10 /* User/Group Identifer Remapping Filesystem */ 95#define MOUNT_KERNFS 11 /* Kernel Information Filesystem */ 96#define MOUNT_PROCFS 12 /* /proc Filesystem */ 97#define MOUNT_AFS 13 /* Andrew Filesystem */ 98#define MOUNT_CD9660 14 /* ISO9660 (aka CDROM) Filesystem */ 99#define MOUNT_UNION 15 /* Union (translucent) Filesystem */ 100#define MOUNT_MAXTYPE 15 101 102#define INITMOUNTNAMES { \ 103 "none", /* 0 MOUNT_NONE */ \ 104 "ufs", /* 1 MOUNT_UFS */ \ 105 "nfs", /* 2 MOUNT_NFS */ \ 106 "mfs", /* 3 MOUNT_MFS */ \ 107 "msdos", /* 4 MOUNT_MSDOS */ \ 108 "lfs", /* 5 MOUNT_LFS */ \ 109 "lofs", /* 6 MOUNT_LOFS */ \ 110 "fdesc", /* 7 MOUNT_FDESC */ \ 111 "portal", /* 8 MOUNT_PORTAL */ \ 112 "null", /* 9 MOUNT_NULL */ \ 113 "umap", /* 10 MOUNT_UMAP */ \ 114 "kernfs", /* 11 MOUNT_KERNFS */ \ 115 "procfs", /* 12 MOUNT_PROCFS */ \ 116 "afs", /* 13 MOUNT_AFS */ \ 117 "iso9660fs", /* 14 MOUNT_CD9660 */ \ 118 "union", /* 15 MOUNT_UNION */ \ 119 0, /* 16 MOUNT_SPARE */ \ 120} 121 122/* 123 * Structure per mounted file system. Each mounted file system has an 124 * array of operations and an instance record. The file systems are 125 * put on a doubly linked list. 126 */ 127LIST_HEAD(vnodelst, vnode); 128 129struct mount { 130 TAILQ_ENTRY(mount) mnt_list; /* mount list */ 131 struct vfsops *mnt_op; /* operations on fs */ 132 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 133 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 134 int mnt_flag; /* flags */ 135 int mnt_maxsymlinklen; /* max size of short symlink */ 136 struct statfs mnt_stat; /* cache of filesystem stats */ 137 qaddr_t mnt_data; /* private data */ 138}; 139 140/* 141 * Mount flags. 142 * 143 * Unmount uses MNT_FORCE flag. 144 */ 145#define MNT_RDONLY 0x00000001 /* read only filesystem */ 146#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 147#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 148#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 149#define MNT_NODEV 0x00000010 /* don't interpret special files */ 150#define MNT_UNION 0x00000020 /* union with underlying filesystem */ 151#define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 152 153/* 154 * exported mount flags. 155 */ 156#define MNT_EXRDONLY 0x00000080 /* exported read only */ 157#define MNT_EXPORTED 0x00000100 /* file system is exported */ 158#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 159#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 160#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 161 162/* 163 * Flags set by internal operations. 164 */ 165#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 166#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 167#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 168#define MNT_USER 0x00008000 /* mounted by a user */ 169 170/* 171 * Mask of flags that are visible to statfs() 172 */ 173#define MNT_VISFLAGMASK 0x0000ffff 174 175/* 176 * filesystem control flags. 177 * 178 * MNT_MLOCK lock the mount entry so that name lookup cannot proceed 179 * past the mount point. This keeps the subtree stable during mounts 180 * and unmounts. 181 */ 182#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 183#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 184#define MNT_RELOAD 0x00040000 /* reload filesystem data */ 185#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 186#define MNT_MLOCK 0x00100000 /* lock so that subtree is stable */ 187#define MNT_MWAIT 0x00200000 /* someone is waiting for lock */ 188#define MNT_MPBUSY 0x00400000 /* scan of mount point in progress */ 189#define MNT_MPWANT 0x00800000 /* waiting for mount point */ 190#define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 191#define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */ 192 193/* 194 * Operations supported on mounted file system. 195 */ 196#ifdef KERNEL 197#ifdef __STDC__ 198struct nameidata; 199struct mbuf; 200#endif 201 202struct vfsops { 203 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 204 struct nameidata *ndp, struct proc *p)); 205 int (*vfs_start) __P((struct mount *mp, int flags, 206 struct proc *p)); 207 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 208 struct proc *p)); 209 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 210 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 211 caddr_t arg, struct proc *p)); 212 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 213 struct proc *p)); 214 int (*vfs_sync) __P((struct mount *mp, int waitfor, 215 struct ucred *cred, struct proc *p)); 216 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 217 struct vnode **vpp)); 218 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 219 struct mbuf *nam, struct vnode **vpp, 220 int *exflagsp, struct ucred **credanonp)); 221 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 222 int (*vfs_init) __P((void)); 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#endif /* KERNEL */ 238 239/* 240 * Flags for various system call interfaces. 241 * 242 * waitfor flags to vfs_sync() and getfsstat() 243 */ 244#define MNT_WAIT 1 245#define MNT_NOWAIT 2 246 247/* 248 * Generic file handle 249 */ 250struct fhandle { 251 fsid_t fh_fsid; /* File system id of mount point */ 252 struct fid fh_fid; /* File sys specific id */ 253}; 254typedef struct fhandle fhandle_t; 255 256#ifdef KERNEL 257#include <net/radix.h> 258#include <sys/socket.h> /* XXX for AF_MAX */ 259 260/* 261 * Network address lookup element 262 */ 263struct netcred { 264 struct radix_node netc_rnodes[2]; 265 int netc_exflags; 266 struct ucred netc_anon; 267}; 268 269/* 270 * Network export information 271 */ 272struct netexport { 273 struct netcred ne_defexported; /* Default export */ 274 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 275}; 276#endif /* KERNEL */ 277 278/* 279 * Export arguments for local filesystem mount calls. 280 */ 281struct export_args { 282 int ex_flags; /* export related flags */ 283 uid_t ex_root; /* mapping for root uid */ 284 struct ucred ex_anon; /* mapping for anonymous user */ 285 struct sockaddr *ex_addr; /* net address to which exported */ 286 int ex_addrlen; /* and the net address length */ 287 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 288 int ex_masklen; /* and the smask length */ 289}; 290 291/* 292 * Arguments to mount UFS-based filesystems 293 */ 294struct ufs_args { 295 char *fspec; /* block special device to mount */ 296 struct export_args export; /* network export information */ 297}; 298 299#ifdef MFS 300/* 301 * Arguments to mount MFS 302 */ 303struct mfs_args { 304 char *fspec; /* name to export for statfs */ 305 struct export_args export; /* if exported MFSes are supported */ 306 caddr_t base; /* base of file system in memory */ 307 u_long size; /* size of file system */ 308}; 309#endif /* MFS */ 310 311#ifdef CD9660 312/* 313 * Arguments to mount ISO 9660 filesystems. 314 */ 315struct iso_args { 316 char *fspec; /* block special device to mount */ 317 struct export_args export; /* network export info */ 318 int flags; /* mounting flags, see below */ 319 320}; 321#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/ 322#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */ 323#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attributes */ 324#endif /* CD9660 */ 325 326#ifdef NFS 327/* 328 * File Handle (32 bytes for version 2), variable up to 1024 for version 3 329 */ 330union nfsv2fh { 331 fhandle_t fh_generic; 332 u_char fh_bytes[32]; 333}; 334typedef union nfsv2fh nfsv2fh_t; 335 336/* 337 * Arguments to mount NFS 338 */ 339struct nfs_args { 340 struct sockaddr *addr; /* file server address */ 341 int addrlen; /* length of address */ 342 int sotype; /* Socket type */ 343 int proto; /* and Protocol */ 344 nfsv2fh_t *fh; /* File handle to be mounted */ 345 int flags; /* flags */ 346 int wsize; /* write size in bytes */ 347 int rsize; /* read size in bytes */ 348 int timeo; /* initial timeout in .1 secs */ 349 int retrans; /* times to retry send */ 350 int maxgrouplist; /* Max. size of group list */ 351 int readahead; /* # of blocks to readahead */ 352 int leaseterm; /* Term (sec) of lease */ 353 int deadthresh; /* Retrans threshold */ 354 char *hostname; /* server's name */ 355}; 356 357 358/* 359 * NFS mount option flags 360 */ 361#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */ 362#define NFSMNT_WSIZE 0x00000002 /* set write size */ 363#define NFSMNT_RSIZE 0x00000004 /* set read size */ 364#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */ 365#define NFSMNT_RETRANS 0x00000010 /* set number of request retrys */ 366#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */ 367#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */ 368#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */ 369#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */ 370#define NFSMNT_MYWRITE 0x00000200 /* Assume writes were mine */ 371#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */ 372#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ 373#define NFSMNT_RDIRALOOK 0x00001000 /* Do lookup with readdir (nqnfs) */ 374#define NFSMNT_LEASETERM 0x00002000 /* set lease term (nqnfs) */ 375#define NFSMNT_READAHEAD 0x00004000 /* set read ahead */ 376#define NFSMNT_DEADTHRESH 0x00008000 /* set dead server retry thresh */ 377#define NFSMNT_NQLOOKLEASE 0x00010000 /* Get lease for lookup */ 378#define NFSMNT_RESVPORT 0x00020000 /* Allocate a reserved port */ 379#define NFSMNT_INTERNAL 0xffe00000 /* Bits set internally */ 380#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */ 381#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */ 382#define NFSMNT_DISMNT 0x00800000 /* Dismounted */ 383#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */ 384#define NFSMNT_WANTSND 0x02000000 /* Want above */ 385#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */ 386#define NFSMNT_WANTRCV 0x08000000 /* Want above */ 387#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */ 388#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */ 389#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */ 390#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */ 391#endif /* NFS */ 392 393#ifdef KERNEL 394/* 395 * exported vnode operations 396 */ 397int dounmount __P((struct mount *, int, struct proc *)); 398struct mount *getvfs __P((fsid_t *)); /* return vfs given fsid */ 399int vflush __P((struct mount *mp, struct vnode *skipvp, int flags)); 400int vfs_export /* process mount export info */ 401 __P((struct mount *, struct netexport *, struct export_args *)); 402struct netcred *vfs_export_lookup /* lookup host in fs export list */ 403 __P((struct mount *, struct netexport *, struct mbuf *)); 404int vfs_lock __P((struct mount *)); /* lock a vfs */ 405int vfs_mountedon __P((struct vnode *));/* is a vfs mounted on vp */ 406void vfs_unlock __P((struct mount *)); /* unlock a vfs */ 407extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 408extern struct vfsops *vfssw[]; /* filesystem type table */ 409 410#else /* KERNEL */ 411 412#include <sys/cdefs.h> 413 414__BEGIN_DECLS 415int fstatfs __P((int, struct statfs *)); 416int getfh __P((const char *, fhandle_t *)); 417int getfsstat __P((struct statfs *, long, int)); 418int getmntinfo __P((struct statfs **, int)); 419int mount __P((int, const char *, int, void *)); 420int statfs __P((const char *, struct statfs *)); 421int unmount __P((const char *, int)); 422__END_DECLS 423 424#endif /* KERNEL */ 425 426#endif /* !_SYS_MOUNT_H_ */ 427