mount.h revision 30354
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 * $Id: mount.h,v 1.47 1997/09/27 13:39:49 kato 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#include <sys/lock.h> 45#include <net/radix.h> 46#include <sys/socket.h> /* XXX for AF_MAX */ 47 48typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ 49 50/* 51 * File identifier. 52 * These are unique per filesystem on a single machine. 53 */ 54#define MAXFIDSZ 16 55 56struct fid { 57 u_short fid_len; /* length of data in bytes */ 58 u_short fid_reserved; /* force longword alignment */ 59 char fid_data[MAXFIDSZ]; /* data (variable length) */ 60}; 61 62/* 63 * file system statistics 64 */ 65 66#define MFSNAMELEN 16 /* length of fs type name, including null */ 67#define MNAMELEN 90 /* length of buffer for returned name */ 68 69struct statfs { 70 long f_spare2; /* placeholder */ 71 long f_bsize; /* fundamental file system block size */ 72 long f_iosize; /* optimal transfer block size */ 73 long f_blocks; /* total data blocks in file system */ 74 long f_bfree; /* free blocks in fs */ 75 long f_bavail; /* free blocks avail to non-superuser */ 76 long f_files; /* total file nodes in file system */ 77 long f_ffree; /* free file nodes in fs */ 78 fsid_t f_fsid; /* file system id */ 79 uid_t f_owner; /* user that mounted the filesystem */ 80 int f_type; /* type of filesystem (see below) */ 81 int f_flags; /* copy of mount flags */ 82 long f_spare[2]; /* spare for later */ 83 char f_fstypename[MFSNAMELEN]; /* fs type name */ 84 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 85 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 86}; 87 88/* 89 * File system types (for backwards compat with 4.4Lite.) 90 */ 91#define MOUNT_NONE 0 92#define MOUNT_UFS 1 /* Fast Filesystem */ 93#define MOUNT_NFS 2 /* Sun-compatible Network Filesystem */ 94#define MOUNT_MFS 3 /* Memory-based Filesystem */ 95#define MOUNT_MSDOS 4 /* MS/DOS Filesystem */ 96#define MOUNT_LFS 5 /* Log-based Filesystem */ 97#define MOUNT_LOFS 6 /* Loopback Filesystem */ 98#define MOUNT_FDESC 7 /* File Descriptor Filesystem */ 99#define MOUNT_PORTAL 8 /* Portal Filesystem */ 100#define MOUNT_NULL 9 /* Minimal Filesystem Layer */ 101#define MOUNT_UMAP 10 /* User/Group Identifier Remapping Filesystem */ 102#define MOUNT_KERNFS 11 /* Kernel Information Filesystem */ 103#define MOUNT_PROCFS 12 /* /proc Filesystem */ 104#define MOUNT_AFS 13 /* Andrew Filesystem */ 105#define MOUNT_CD9660 14 /* ISO9660 (aka CDROM) Filesystem */ 106#define MOUNT_UNION 15 /* Union (translucent) Filesystem */ 107#define MOUNT_DEVFS 16 /* existing device Filesystem */ 108#define MOUNT_EXT2FS 17 /* Linux EXT2FS */ 109#define MOUNT_TFS 18 /* Netcon Novell filesystem */ 110#define MOUNT_MAXTYPE 18 111 112#define INITMOUNTNAMES { \ 113 "none", /* 0 MOUNT_NONE */ \ 114 "ufs", /* 1 MOUNT_UFS */ \ 115 "nfs", /* 2 MOUNT_NFS */ \ 116 "mfs", /* 3 MOUNT_MFS */ \ 117 "msdos", /* 4 MOUNT_MSDOS */ \ 118 "lfs", /* 5 MOUNT_LFS */ \ 119 "lofs", /* 6 MOUNT_LOFS */ \ 120 "fdesc", /* 7 MOUNT_FDESC */ \ 121 "portal", /* 8 MOUNT_PORTAL */ \ 122 "null", /* 9 MOUNT_NULL */ \ 123 "umap", /* 10 MOUNT_UMAP */ \ 124 "kernfs", /* 11 MOUNT_KERNFS */ \ 125 "procfs", /* 12 MOUNT_PROCFS */ \ 126 "afs", /* 13 MOUNT_AFS */ \ 127 "cd9660", /* 14 MOUNT_CD9660 */ \ 128 "union", /* 15 MOUNT_UNION */ \ 129 "devfs", /* 16 MOUNT_DEVFS */ \ 130 "ext2fs", /* 17 MOUNT_EXT2FS */ \ 131 "tfs", /* 18 MOUNT_TFS */ \ 132 0, /* 18 MOUNT_SPARE */ \ 133} 134 135/* 136 * Structure per mounted file system. Each mounted file system has an 137 * array of operations and an instance record. The file systems are 138 * put on a doubly linked list. 139 */ 140LIST_HEAD(vnodelst, vnode); 141 142struct mount { 143 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */ 144 struct vfsops *mnt_op; /* operations on fs */ 145 struct vfsconf *mnt_vfc; /* configuration info */ 146 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 147 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 148 struct lock mnt_lock; /* mount structure lock */ 149 int mnt_flag; /* flags */ 150 int mnt_maxsymlinklen; /* max size of short symlink */ 151 struct statfs mnt_stat; /* cache of filesystem stats */ 152 qaddr_t mnt_data; /* private data */ 153 time_t mnt_time; /* last time written*/ 154}; 155 156/* 157 * Mount flags. 158 * 159 * Unmount uses MNT_FORCE flag. 160 */ 161#define MNT_RDONLY 0x00000001 /* read only filesystem */ 162#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 163#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 164#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 165#define MNT_NODEV 0x00000010 /* don't interpret special files */ 166#define MNT_UNION 0x00000020 /* union with underlying filesystem */ 167#define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 168#define MNT_NOATIME 0x10000000 /* Disable update of file access times */ 169#define MNT_NOCLUSTERR 0x40000000 /* Disable cluster read */ 170#define MNT_NOCLUSTERW 0x80000000 /* Disable cluster read */ 171 172/* 173 * exported mount flags. 174 */ 175#define MNT_EXRDONLY 0x00000080 /* exported read only */ 176#define MNT_EXPORTED 0x00000100 /* file system is exported */ 177#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 178#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 179#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 180#define MNT_EXPUBLIC 0x20000000 /* public export (WebNFS) */ 181 182/* 183 * Flags set by internal operations. 184 */ 185#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 186#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 187#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 188#define MNT_USER 0x00008000 /* mounted by a user */ 189 190/* 191 * Mask of flags that are visible to statfs() 192 */ 193#define MNT_VISFLAGMASK (MNT_RDONLY|MNT_SYNCHRONOUS|MNT_NOEXEC|MNT_NOSUID| \ 194 MNT_NODEV|MNT_UNION|MNT_ASYNC|MNT_EXRDONLY| \ 195 MNT_EXPORTED|MNT_DEFEXPORTED|MNT_EXPORTANON| \ 196 MNT_EXKERB|MNT_LOCAL|MNT_USER|MNT_QUOTA|MNT_ROOTFS| \ 197 MNT_NOATIME|MNT_NOCLUSTERR|MNT_NOCLUSTERW) 198 199/* 200 * External filesystem control flags. 201 */ 202#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 203#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 204#define MNT_RELOAD 0x00040000 /* reload filesystem data */ 205#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 206/* 207 * Internal filesystem control flags. 208 * 209 * MNT_UNMOUNT locks the mount entry so that name lookup cannot proceed 210 * past the mount point. This keeps the subtree stable during mounts 211 * and unmounts. 212 */ 213#define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 214#define MNT_MWAIT 0x02000000 /* waiting for unmount to finish */ 215#define MNT_WANTRDWR 0x04000000 /* upgrade to read/write requested */ 216 217/* 218 * Sysctl CTL_VFS definitions. 219 * 220 * Second level identifier specifies which filesystem. Second level 221 * identifier VFS_VFSCONF returns information about all filesystems. 222 * Second level identifier VFS_GENERIC is non-terminal. 223 */ 224#define VFS_VFSCONF 0 /* get configured filesystems */ 225#define VFS_GENERIC 0 /* generic filesystem information */ 226/* 227 * Third level identifiers for VFS_GENERIC are given below; third 228 * level identifiers for specific filesystems are given in their 229 * mount specific header files. 230 */ 231#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 232#define VFS_CONF 2 /* struct: vfsconf for filesystem given 233 as next argument */ 234 235/* 236 * Flags for various system call interfaces. 237 * 238 * waitfor flags to vfs_sync() and getfsstat() 239 */ 240#define MNT_WAIT 1 241#define MNT_NOWAIT 2 242 243/* 244 * Generic file handle 245 */ 246struct fhandle { 247 fsid_t fh_fsid; /* File system id of mount point */ 248 struct fid fh_fid; /* File sys specific id */ 249}; 250typedef struct fhandle fhandle_t; 251 252/* 253 * Export arguments for local filesystem mount calls. 254 */ 255struct export_args { 256 int ex_flags; /* export related flags */ 257 uid_t ex_root; /* mapping for root uid */ 258 struct ucred ex_anon; /* mapping for anonymous user */ 259 struct sockaddr *ex_addr; /* net address to which exported */ 260 int ex_addrlen; /* and the net address length */ 261 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 262 int ex_masklen; /* and the smask length */ 263 char *ex_indexfile; /* index file for WebNFS URLs */ 264}; 265 266/* 267 * Structure holding information for a publicly exported filesystem 268 * (WebNFS). Currently the specs allow just for one such filesystem. 269 */ 270struct nfs_public { 271 int np_valid; /* Do we hold valid information */ 272 fhandle_t np_handle; /* Filehandle for pub fs (internal) */ 273 struct mount *np_mount; /* Mountpoint of exported fs */ 274 char *np_index; /* Index file */ 275}; 276 277/* 278 * Filesystem configuration information. One of these exists for each 279 * type of filesystem supported by the kernel. These are searched at 280 * mount time to identify the requested filesystem. 281 */ 282struct vfsconf { 283 struct vfsops *vfc_vfsops; /* filesystem operations vector */ 284 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 285 int vfc_typenum; /* historic filesystem type number */ 286 int vfc_refcount; /* number mounted of this type */ 287 int vfc_flags; /* permanent flags */ 288 struct vfsconf *vfc_next; /* next in list */ 289}; 290 291struct ovfsconf { 292 void *vfc_vfsops; 293 char vfc_name[32]; 294 int vfc_index; 295 int vfc_refcount; 296 int vfc_flags; 297}; 298 299/* 300 * NB: these flags refer to IMPLEMENTATION properties, not properties of 301 * any actual mounts; i.e., it does not make sense to change the flags. 302 */ 303#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */ 304#define VFCF_NETWORK 0x00020000 /* may get data over the network */ 305#define VFCF_READONLY 0x00040000 /* writes are not implemented */ 306#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */ 307#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */ 308#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode*/ 309 310#ifdef KERNEL 311 312#ifdef MALLOC_DECLARE 313MALLOC_DECLARE(M_MOUNT); 314#endif 315extern int maxvfsconf; /* highest defined filesystem type */ 316extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 317 318/* 319 * Operations supported on mounted file system. 320 */ 321#ifdef __STDC__ 322struct nameidata; 323struct mbuf; 324#endif 325 326struct vfsops { 327 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 328 struct nameidata *ndp, struct proc *p)); 329 int (*vfs_start) __P((struct mount *mp, int flags, 330 struct proc *p)); 331 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 332 struct proc *p)); 333 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 334 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 335 caddr_t arg, struct proc *p)); 336 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 337 struct proc *p)); 338 int (*vfs_sync) __P((struct mount *mp, int waitfor, 339 struct ucred *cred, struct proc *p)); 340 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 341 struct vnode **vpp)); 342 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 343 struct sockaddr *nam, struct vnode **vpp, 344 int *exflagsp, struct ucred **credanonp)); 345 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 346 int (*vfs_init) __P((struct vfsconf *)); 347}; 348 349#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 350 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 351#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 352#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 353#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 354#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 355#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 356#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 357#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 358#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 359 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 360#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 361 362#ifdef VFS_LKM 363#include <sys/conf.h> 364#include <sys/exec.h> 365#include <sys/sysent.h> 366#include <sys/lkm.h> 367 368#define VFS_SET(vfsops, fsname, index, flags) \ 369 static struct vfsconf _fs_vfsconf = { \ 370 &vfsops, \ 371 #fsname, \ 372 index, \ 373 0, \ 374 flags, \ 375 }; \ 376 extern struct linker_set MODVNOPS; \ 377 MOD_VFS(fsname,&MODVNOPS,&_fs_vfsconf); \ 378 extern int \ 379 fsname ## _mod __P((struct lkm_table *, int, int)); \ 380 int \ 381 fsname ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \ 382 MOD_DISPATCH(fsname, \ 383 lkmtp, cmd, ver, lkm_nullcmd, lkm_nullcmd, lkm_nullcmd); } 384#else 385 386#define VFS_SET(vfsops, fsname, index, flags) \ 387 static struct vfsconf _fs_vfsconf = { \ 388 &vfsops, \ 389 #fsname, \ 390 index, \ 391 0, \ 392 flags | VFCF_STATIC, \ 393 }; \ 394 DATA_SET(vfs_set,_fs_vfsconf) 395#endif /* VFS_LKM */ 396 397#endif /* KERNEL */ 398 399#ifdef KERNEL 400#include <net/radix.h> 401#include <sys/socket.h> /* XXX for AF_MAX */ 402 403/* 404 * Network address lookup element 405 */ 406struct netcred { 407 struct radix_node netc_rnodes[2]; 408 int netc_exflags; 409 struct ucred netc_anon; 410}; 411 412/* 413 * Network export information 414 */ 415struct netexport { 416 struct netcred ne_defexported; /* Default export */ 417 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 418}; 419 420extern char *mountrootfsname; 421 422/* 423 * exported vnode operations 424 */ 425int dounmount __P((struct mount *, int, struct proc *)); 426int vfs_setpublicfs /* set publicly exported fs */ 427 __P((struct mount *, struct netexport *, struct export_args *)); 428int vfs_lock __P((struct mount *)); /* lock a vfs */ 429void vfs_msync __P((struct mount *, int)); 430void vfs_unlock __P((struct mount *)); /* unlock a vfs */ 431int vfs_busy __P((struct mount *, int, struct simplelock *, struct proc *)); 432int vfs_export /* process mount export info */ 433 __P((struct mount *, struct netexport *, struct export_args *)); 434struct netcred *vfs_export_lookup /* lookup host in fs export list */ 435 __P((struct mount *, struct netexport *, struct sockaddr *)); 436void vfs_getnewfsid __P((struct mount *)); 437struct mount *vfs_getvfs __P((fsid_t *)); /* return vfs given fsid */ 438int vfs_mountedon __P((struct vnode *)); /* is a vfs mounted on vp */ 439int vfs_mountrootfs __P((char *)); 440int vfs_rootmountalloc __P((char *, char *, struct mount **)); 441void vfs_unbusy __P((struct mount *, struct proc *)); 442void vfs_unmountall __P((void)); 443extern CIRCLEQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 444extern struct simplelock mountlist_slock; 445extern struct nfs_public nfs_pub; 446 447#else /* !KERNEL */ 448 449#include <sys/cdefs.h> 450 451__BEGIN_DECLS 452int fstatfs __P((int, struct statfs *)); 453int getfh __P((const char *, fhandle_t *)); 454int getfsstat __P((struct statfs *, long, int)); 455int getmntinfo __P((struct statfs **, int)); 456int mount __P((const char *, const char *, int, void *)); 457int statfs __P((const char *, struct statfs *)); 458int unmount __P((const char *, int)); 459 460/* C library stuff */ 461#ifdef _NEW_VFSCONF 462#define getvfsbyname new_getvfsbyname 463int new_getvfsbyname __P((const char *, struct vfsconf *)); 464#else 465#define vfsconf ovfsconf 466struct ovfsconf *getvfsbyname __P((const char *)); 467struct ovfsconf *getvfsbytype __P((int)); 468struct ovfsconf *getvfsent __P((void)); 469#endif 470void setvfsent __P((int)); 471void endvfsent __P((void)); 472int vfsisloadable __P((const char *)); 473int vfsload __P((const char *)); 474__END_DECLS 475 476#endif /* KERNEL */ 477 478#endif /* !_SYS_MOUNT_H_ */ 479