mount.h revision 51068
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.21 (Berkeley) 5/20/95 34 * $FreeBSD: head/sys/sys/mount.h 51068 1999-09-07 22:42:38Z alfred $ 35 */ 36 37#ifndef _SYS_MOUNT_H_ 38#define _SYS_MOUNT_H_ 39 40#include <sys/ucred.h> 41#include <sys/queue.h> 42#include <sys/lock.h> 43 44typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ 45 46/* 47 * File identifier. 48 * These are unique per filesystem on a single machine. 49 */ 50#define MAXFIDSZ 16 51 52struct fid { 53 u_short fid_len; /* length of data in bytes */ 54 u_short fid_reserved; /* force longword alignment */ 55 char fid_data[MAXFIDSZ]; /* data (variable length) */ 56}; 57 58/* 59 * file system statistics 60 */ 61 62#define MFSNAMELEN 16 /* length of fs type name, including null */ 63#define MNAMELEN 90 /* length of buffer for returned name */ 64 65struct statfs { 66 long f_spare2; /* placeholder */ 67 long f_bsize; /* fundamental file system block size */ 68 long f_iosize; /* optimal transfer block size */ 69 long f_blocks; /* total data blocks in file system */ 70 long f_bfree; /* free blocks in fs */ 71 long f_bavail; /* free blocks avail to non-superuser */ 72 long f_files; /* total file nodes in file system */ 73 long f_ffree; /* free file nodes in fs */ 74 fsid_t f_fsid; /* file system id */ 75 uid_t f_owner; /* user that mounted the filesystem */ 76 int f_type; /* type of filesystem */ 77 int f_flags; /* copy of mount exported flags */ 78 long f_syncwrites; /* count of sync writes since mount */ 79 long f_asyncwrites; /* count of async writes since mount */ 80 char f_fstypename[MFSNAMELEN]; /* fs type name */ 81 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 82 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 83}; 84 85/* 86 * Structure per mounted file system. Each mounted file system has an 87 * array of operations and an instance record. The file systems are 88 * put on a doubly linked list. 89 */ 90LIST_HEAD(vnodelst, vnode); 91 92struct mount { 93 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */ 94 struct vfsops *mnt_op; /* operations on fs */ 95 struct vfsconf *mnt_vfc; /* configuration info */ 96 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 97 struct vnode *mnt_syncer; /* syncer vnode */ 98 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 99 struct lock mnt_lock; /* mount structure lock */ 100 int mnt_flag; /* flags shared with user */ 101 int mnt_kern_flag; /* kernel only flags */ 102 int mnt_maxsymlinklen; /* max size of short symlink */ 103 struct statfs mnt_stat; /* cache of filesystem stats */ 104 qaddr_t mnt_data; /* private data */ 105 time_t mnt_time; /* last time written*/ 106}; 107 108/* 109 * User specifiable flags. 110 */ 111#define MNT_RDONLY 0x00000001 /* read only filesystem */ 112#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 113#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 114#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 115#define MNT_NODEV 0x00000010 /* don't interpret special files */ 116#define MNT_UNION 0x00000020 /* union with underlying filesystem */ 117#define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 118#define MNT_SUIDDIR 0x00100000 /* special handling of SUID on dirs */ 119#define MNT_SOFTDEP 0x00200000 /* soft updates being done */ 120#define MNT_NOSYMFOLLOW 0x00400000 /* do not follow symlinks */ 121#define MNT_NOATIME 0x10000000 /* disable update of file access time */ 122#define MNT_NOCLUSTERR 0x40000000 /* disable cluster read */ 123#define MNT_NOCLUSTERW 0x80000000 /* disable cluster write */ 124 125/* 126 * NFS export related mount flags. 127 */ 128#define MNT_EXRDONLY 0x00000080 /* exported read only */ 129#define MNT_EXPORTED 0x00000100 /* file system is exported */ 130#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 131#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 132#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 133#define MNT_EXPUBLIC 0x20000000 /* public export (WebNFS) */ 134 135/* 136 * Flags set by internal operations, 137 * but visible to the user. 138 * XXX some of these are not quite right.. (I've never seen the root flag set) 139 */ 140#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 141#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 142#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 143#define MNT_USER 0x00008000 /* mounted by a user */ 144 145/* 146 * Mask of flags that are visible to statfs() 147 * XXX I think that this could now become (~(MNT_CMDFLAGS)) 148 * but the 'mount' program may need changing to handle this. 149 * XXX MNT_EXPUBLIC is presently left out. I don't know why. 150 */ 151#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \ 152 MNT_NOSUID | MNT_NODEV | MNT_UNION | \ 153 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \ 154 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \ 155 MNT_LOCAL | MNT_USER | MNT_QUOTA | \ 156 MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \ 157 MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP \ 158 /* | MNT_EXPUBLIC */) 159/* 160 * External filesystem command modifier flags. 161 * Unmount can use the MNT_FORCE flag. 162 * XXX These are not STATES and really should be somewhere else. 163 */ 164#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 165#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 166#define MNT_RELOAD 0x00040000 /* reload filesystem data */ 167#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 168#define MNT_CMDFLAGS (MNT_UPDATE|MNT_DELEXPORT|MNT_RELOAD|MNT_FORCE) 169/* 170 * Internal filesystem control flags stored in mnt_kern_flag. 171 * 172 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed 173 * past the mount point. This keeps the subtree stable during mounts 174 * and unmounts. 175 */ 176#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */ 177#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */ 178#define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */ 179 180/* 181 * Sysctl CTL_VFS definitions. 182 * 183 * Second level identifier specifies which filesystem. Second level 184 * identifier VFS_VFSCONF returns information about all filesystems. 185 * Second level identifier VFS_GENERIC is non-terminal. 186 */ 187#define VFS_VFSCONF 0 /* get configured filesystems */ 188#define VFS_GENERIC 0 /* generic filesystem information */ 189/* 190 * Third level identifiers for VFS_GENERIC are given below; third 191 * level identifiers for specific filesystems are given in their 192 * mount specific header files. 193 */ 194#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 195#define VFS_CONF 2 /* struct: vfsconf for filesystem given 196 as next argument */ 197 198/* 199 * Flags for various system call interfaces. 200 * 201 * waitfor flags to vfs_sync() and getfsstat() 202 */ 203#define MNT_WAIT 1 /* synchronously wait for I/O to complete */ 204#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ 205#define MNT_LAZY 3 /* push data not written by filesystem syncer */ 206 207/* 208 * Generic file handle 209 */ 210struct fhandle { 211 fsid_t fh_fsid; /* File system id of mount point */ 212 struct fid fh_fid; /* File sys specific id */ 213}; 214typedef struct fhandle fhandle_t; 215 216/* 217 * Export arguments for local filesystem mount calls. 218 */ 219struct export_args { 220 int ex_flags; /* export related flags */ 221 uid_t ex_root; /* mapping for root uid */ 222 struct ucred ex_anon; /* mapping for anonymous user */ 223 struct sockaddr *ex_addr; /* net address to which exported */ 224 int ex_addrlen; /* and the net address length */ 225 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 226 int ex_masklen; /* and the smask length */ 227 char *ex_indexfile; /* index file for WebNFS URLs */ 228}; 229 230/* 231 * Structure holding information for a publicly exported filesystem 232 * (WebNFS). Currently the specs allow just for one such filesystem. 233 */ 234struct nfs_public { 235 int np_valid; /* Do we hold valid information */ 236 fhandle_t np_handle; /* Filehandle for pub fs (internal) */ 237 struct mount *np_mount; /* Mountpoint of exported fs */ 238 char *np_index; /* Index file */ 239}; 240 241/* 242 * Filesystem configuration information. One of these exists for each 243 * type of filesystem supported by the kernel. These are searched at 244 * mount time to identify the requested filesystem. 245 */ 246struct vfsconf { 247 struct vfsops *vfc_vfsops; /* filesystem operations vector */ 248 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 249 int vfc_typenum; /* historic filesystem type number */ 250 int vfc_refcount; /* number mounted of this type */ 251 int vfc_flags; /* permanent flags */ 252 struct vfsconf *vfc_next; /* next in list */ 253}; 254 255struct ovfsconf { 256 void *vfc_vfsops; 257 char vfc_name[32]; 258 int vfc_index; 259 int vfc_refcount; 260 int vfc_flags; 261}; 262 263/* 264 * NB: these flags refer to IMPLEMENTATION properties, not properties of 265 * any actual mounts; i.e., it does not make sense to change the flags. 266 */ 267#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */ 268#define VFCF_NETWORK 0x00020000 /* may get data over the network */ 269#define VFCF_READONLY 0x00040000 /* writes are not implemented */ 270#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */ 271#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */ 272#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode*/ 273 274#ifdef KERNEL 275 276#ifdef MALLOC_DECLARE 277MALLOC_DECLARE(M_MOUNT); 278#endif 279extern int maxvfsconf; /* highest defined filesystem type */ 280extern int nfs_mount_type; /* vfc_typenum for nfs, or -1 */ 281extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 282 283/* 284 * Operations supported on mounted file system. 285 */ 286#ifdef __STDC__ 287struct nameidata; 288struct mbuf; 289#endif 290 291struct vfsops { 292 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 293 struct nameidata *ndp, struct proc *p)); 294 int (*vfs_start) __P((struct mount *mp, int flags, 295 struct proc *p)); 296 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 297 struct proc *p)); 298 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 299 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 300 caddr_t arg, struct proc *p)); 301 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 302 struct proc *p)); 303 int (*vfs_sync) __P((struct mount *mp, int waitfor, 304 struct ucred *cred, struct proc *p)); 305 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 306 struct vnode **vpp)); 307 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 308 struct sockaddr *nam, struct vnode **vpp, 309 int *exflagsp, struct ucred **credanonp)); 310 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 311 int (*vfs_init) __P((struct vfsconf *)); 312 int (*vfs_uninit) __P((struct vfsconf *)); 313}; 314 315#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 316 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 317#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 318#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 319#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 320#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 321#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 322#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 323#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 324#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 325 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 326#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 327 328#include <sys/module.h> 329 330#define VFS_SET(vfsops, fsname, flags) \ 331 static struct vfsconf fsname ## _vfsconf = { \ 332 &vfsops, \ 333 #fsname, \ 334 -1, \ 335 0, \ 336 flags \ 337 }; \ 338 static moduledata_t fsname ## _mod = { \ 339 #fsname, \ 340 vfs_modevent, \ 341 & fsname ## _vfsconf \ 342 }; \ 343 DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE) 344 345#include <net/radix.h> 346 347#define AF_MAX 31 /* XXX */ 348 349/* 350 * Network address lookup element 351 */ 352struct netcred { 353 struct radix_node netc_rnodes[2]; 354 int netc_exflags; 355 struct ucred netc_anon; 356}; 357 358/* 359 * Network export information 360 */ 361struct netexport { 362 struct netcred ne_defexported; /* Default export */ 363 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 364}; 365 366extern char *mountrootfsname; 367 368/* 369 * exported vnode operations 370 */ 371int dounmount __P((struct mount *, int, struct proc *)); 372int vfs_setpublicfs /* set publicly exported fs */ 373 __P((struct mount *, struct netexport *, struct export_args *)); 374int vfs_lock __P((struct mount *)); /* lock a vfs */ 375void vfs_msync __P((struct mount *, int)); 376void vfs_unlock __P((struct mount *)); /* unlock a vfs */ 377int vfs_busy __P((struct mount *, int, struct simplelock *, struct proc *)); 378int vfs_export /* process mount export info */ 379 __P((struct mount *, struct netexport *, struct export_args *)); 380struct netcred *vfs_export_lookup /* lookup host in fs export list */ 381 __P((struct mount *, struct netexport *, struct sockaddr *)); 382int vfs_allocate_syncvnode __P((struct mount *)); 383void vfs_getnewfsid __P((struct mount *)); 384struct mount *vfs_getvfs __P((fsid_t *)); /* return vfs given fsid */ 385int vfs_modevent __P((module_t, int, void *)); 386int vfs_mountedon __P((struct vnode *)); /* is a vfs mounted on vp */ 387int vfs_rootmountalloc __P((char *, char *, struct mount **)); 388void vfs_unbusy __P((struct mount *, struct proc *)); 389void vfs_unmountall __P((void)); 390int vfs_register __P((struct vfsconf *)); 391int vfs_unregister __P((struct vfsconf *)); 392extern CIRCLEQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 393extern struct simplelock mountlist_slock; 394extern struct nfs_public nfs_pub; 395 396/* 397 * Declarations for these vfs default operations are located in 398 * kern/vfs_default.c, they should be used instead of making "dummy" 399 * functions or casting entries in the VFS op table to "enopnotsupp()". 400 */ 401int vfs_stdmount __P((struct mount *mp, char *path, caddr_t data, 402 struct nameidata *ndp, struct proc *p)); 403int vfs_stdstart __P((struct mount *mp, int flags, struct proc *p)); 404int vfs_stdunmount __P((struct mount *mp, int mntflags, struct proc *p)); 405int vfs_stdroot __P((struct mount *mp, struct vnode **vpp)); 406int vfs_stdquotactl __P((struct mount *mp, int cmds, uid_t uid, 407 caddr_t arg, struct proc *p)); 408int vfs_stdstatfs __P((struct mount *mp, struct statfs *sbp, struct proc *p)); 409int vfs_stdsync __P((struct mount *mp, int waitfor, struct ucred *cred, 410 struct proc *p)); 411int vfs_stdvget __P((struct mount *mp, ino_t ino, struct vnode **vpp)); 412int vfs_stdfhtovp __P((struct mount *mp, struct fid *fhp, struct sockaddr *nam, 413 struct vnode **vpp, int *exflagsp, struct ucred **credanonp)); 414int vfs_stdvptofh __P((struct vnode *vp, struct fid *fhp)); 415int vfs_stdinit __P((struct vfsconf *)); 416int vfs_stduninit __P((struct vfsconf *)); 417 418#else /* !KERNEL */ 419 420#include <sys/cdefs.h> 421 422__BEGIN_DECLS 423int fstatfs __P((int, struct statfs *)); 424int getfh __P((const char *, fhandle_t *)); 425int getfsstat __P((struct statfs *, long, int)); 426int getmntinfo __P((struct statfs **, int)); 427int mount __P((const char *, const char *, int, void *)); 428int statfs __P((const char *, struct statfs *)); 429int unmount __P((const char *, int)); 430 431/* C library stuff */ 432void endvfsent __P((void)); 433struct ovfsconf *getvfsbyname __P((const char *)); 434struct ovfsconf *getvfsbytype __P((int)); 435struct ovfsconf *getvfsent __P((void)); 436#define getvfsbyname new_getvfsbyname 437int new_getvfsbyname __P((const char *, struct vfsconf *)); 438void setvfsent __P((int)); 439int vfsisloadable __P((const char *)); 440int vfsload __P((const char *)); 441__END_DECLS 442 443#endif /* KERNEL */ 444 445#endif /* !_SYS_MOUNT_H_ */ 446