mount.h revision 24674
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.41 1997/03/03 11:55:47 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#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 170/* 171 * exported mount flags. 172 */ 173#define MNT_EXRDONLY 0x00000080 /* exported read only */ 174#define MNT_EXPORTED 0x00000100 /* file system is exported */ 175#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 176#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 177#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 178 179/* 180 * Flags set by internal operations. 181 */ 182#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 183#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 184#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 185#define MNT_USER 0x00008000 /* mounted by a user */ 186 187/* 188 * Mask of flags that are visible to statfs() 189 */ 190#define MNT_VISFLAGMASK (MNT_RDONLY|MNT_SYNCHRONOUS|MNT_NOEXEC|MNT_NOSUID| \ 191 MNT_NODEV|MNT_UNION|MNT_ASYNC|MNT_EXRDONLY|MNT_EXPORTED| \ 192 MNT_DEFEXPORTED|MNT_EXPORTANON|MNT_EXKERB|MNT_LOCAL| \ 193 MNT_USER|MNT_QUOTA|MNT_ROOTFS|MNT_NOATIME) 194 195/* 196 * External filesystem control flags. 197 */ 198#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 199#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 200#define MNT_RELOAD 0x00040000 /* reload filesystem data */ 201#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 202/* 203 * Internal filesystem control flags. 204 * 205 * MNT_UNMOUNT locks the mount entry so that name lookup cannot proceed 206 * past the mount point. This keeps the subtree stable during mounts 207 * and unmounts. 208 */ 209#define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 210#define MNT_MWAIT 0x02000000 /* waiting for unmount to finish */ 211#define MNT_WANTRDWR 0x04000000 /* upgrade to read/write requested */ 212 213/* 214 * Sysctl CTL_VFS definitions. 215 * 216 * Second level identifier specifies which filesystem. Second level 217 * identifier VFS_VFSCONF returns information about all filesystems. 218 * Second level identifier VFS_GENERIC is non-terminal. 219 */ 220#define VFS_VFSCONF 0 /* get configured filesystems */ 221#define VFS_GENERIC 0 /* generic filesystem information */ 222/* 223 * Third level identifiers for VFS_GENERIC are given below; third 224 * level identifiers for specific filesystems are given in their 225 * mount specific header files. 226 */ 227#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 228#define VFS_CONF 2 /* struct: vfsconf for filesystem given 229 as next argument */ 230 231/* 232 * Flags for various system call interfaces. 233 * 234 * waitfor flags to vfs_sync() and getfsstat() 235 */ 236#define MNT_WAIT 1 237#define MNT_NOWAIT 2 238 239/* 240 * Generic file handle 241 */ 242struct fhandle { 243 fsid_t fh_fsid; /* File system id of mount point */ 244 struct fid fh_fid; /* File sys specific id */ 245}; 246typedef struct fhandle fhandle_t; 247 248/* 249 * Export arguments for local filesystem mount calls. 250 */ 251struct export_args { 252 int ex_flags; /* export related flags */ 253 uid_t ex_root; /* mapping for root uid */ 254 struct ucred ex_anon; /* mapping for anonymous user */ 255 struct sockaddr *ex_addr; /* net address to which exported */ 256 int ex_addrlen; /* and the net address length */ 257 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 258 int ex_masklen; /* and the smask length */ 259}; 260 261/* 262 * Filesystem configuration information. One of these exists for each 263 * type of filesystem supported by the kernel. These are searched at 264 * mount time to identify the requested filesystem. 265 */ 266struct vfsconf { 267 struct vfsops *vfc_vfsops; /* filesystem operations vector */ 268 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 269 int vfc_typenum; /* historic filesystem type number */ 270 int vfc_refcount; /* number mounted of this type */ 271 int vfc_flags; /* permanent flags */ 272 struct vfsconf *vfc_next; /* next in list */ 273}; 274 275struct ovfsconf { 276 void *vfc_vfsops; 277 char vfc_name[32]; 278 int vfc_index; 279 int vfc_refcount; 280 int vfc_flags; 281}; 282 283/* 284 * NB: these flags refer to IMPLEMENTATION properties, not properties of 285 * any actual mounts; i.e., it does not make sense to change the flags. 286 */ 287#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */ 288#define VFCF_NETWORK 0x00020000 /* may get data over the network */ 289#define VFCF_READONLY 0x00040000 /* writes are not implemented */ 290#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */ 291#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */ 292#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode*/ 293 294#ifdef KERNEL 295 296extern int maxvfsconf; /* highest defined filesystem type */ 297extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 298 299/* 300 * Operations supported on mounted file system. 301 */ 302#ifdef __STDC__ 303struct nameidata; 304struct mbuf; 305#endif 306 307struct vfsops { 308 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 309 struct nameidata *ndp, struct proc *p)); 310 int (*vfs_start) __P((struct mount *mp, int flags, 311 struct proc *p)); 312 int (*vfs_unmount) __P((struct mount *mp, int mntflags, 313 struct proc *p)); 314 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 315 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 316 caddr_t arg, struct proc *p)); 317 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 318 struct proc *p)); 319 int (*vfs_sync) __P((struct mount *mp, int waitfor, 320 struct ucred *cred, struct proc *p)); 321 int (*vfs_vget) __P((struct mount *mp, ino_t ino, 322 struct vnode **vpp)); 323 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 324 struct mbuf *nam, struct vnode **vpp, 325 int *exflagsp, struct ucred **credanonp)); 326 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 327 int (*vfs_init) __P((struct vfsconf *)); 328}; 329 330#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 331 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 332#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 333#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 334#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 335#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 336#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 337#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 338#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 339#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 340 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 341#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 342 343#ifdef VFS_LKM 344#include <sys/conf.h> 345#include <sys/exec.h> 346#include <sys/sysent.h> 347#include <sys/lkm.h> 348 349#define VFS_SET(vfsops, fsname, index, flags) \ 350 static struct vfsconf _fs_vfsconf = { \ 351 &vfsops, \ 352 #fsname, \ 353 index, \ 354 0, \ 355 flags, \ 356 }; \ 357 extern struct linker_set MODVNOPS; \ 358 MOD_VFS(fsname,&MODVNOPS,&_fs_vfsconf); \ 359 extern int \ 360 fsname ## _mod __P((struct lkm_table *, int, int)); \ 361 int \ 362 fsname ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \ 363 MOD_DISPATCH(fsname, \ 364 lkmtp, cmd, ver, lkm_nullcmd, lkm_nullcmd, lkm_nullcmd); } 365#else 366 367#define VFS_SET(vfsops, fsname, index, flags) \ 368 static struct vfsconf _fs_vfsconf = { \ 369 &vfsops, \ 370 #fsname, \ 371 index, \ 372 0, \ 373 flags | VFCF_STATIC, \ 374 }; \ 375 DATA_SET(vfs_set,_fs_vfsconf) 376#endif /* VFS_LKM */ 377 378#endif /* KERNEL */ 379 380#ifdef KERNEL 381#include <net/radix.h> 382#include <sys/socket.h> /* XXX for AF_MAX */ 383 384/* 385 * Network address lookup element 386 */ 387struct netcred { 388 struct radix_node netc_rnodes[2]; 389 int netc_exflags; 390 struct ucred netc_anon; 391}; 392 393/* 394 * Network export information 395 */ 396struct netexport { 397 struct netcred ne_defexported; /* Default export */ 398 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 399}; 400 401extern char *mountrootfsname; 402 403/* 404 * exported vnode operations 405 */ 406int dounmount __P((struct mount *, int, struct proc *)); 407int vfs_lock __P((struct mount *)); /* lock a vfs */ 408void vfs_msync __P((struct mount *, int)); 409void vfs_unlock __P((struct mount *)); /* unlock a vfs */ 410int vfs_busy __P((struct mount *, int, struct simplelock *, struct proc *)); 411int vfs_export /* process mount export info */ 412 __P((struct mount *, struct netexport *, struct export_args *)); 413struct netcred *vfs_export_lookup /* lookup host in fs export list */ 414 __P((struct mount *, struct netexport *, struct mbuf *)); 415void vfs_getnewfsid __P((struct mount *)); 416struct mount *vfs_getvfs __P((fsid_t *)); /* return vfs given fsid */ 417int vfs_mountedon __P((struct vnode *)); /* is a vfs mounted on vp */ 418int vfs_mountrootfs __P((char *)); 419int vfs_rootmountalloc __P((char *, char *, struct mount **)); 420void vfs_unbusy __P((struct mount *, struct proc *)); 421void vfs_unmountall __P((void)); 422extern CIRCLEQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 423extern struct simplelock mountlist_slock; 424 425#else /* !KERNEL */ 426 427#include <sys/cdefs.h> 428 429__BEGIN_DECLS 430int fstatfs __P((int, struct statfs *)); 431int getfh __P((const char *, fhandle_t *)); 432int getfsstat __P((struct statfs *, long, int)); 433int getmntinfo __P((struct statfs **, int)); 434#ifdef _NEW_VFSCONF 435int mount __P((const char *, const char *, int, void *)); 436#else 437int mount __P((int, const char *, int, void *)); 438#endif 439int statfs __P((const char *, struct statfs *)); 440int unmount __P((const char *, int)); 441 442/* C library stuff */ 443#ifdef _NEW_VFSCONF 444#define getvfsbyname new_getvfsbyname 445int new_getvfsbyname __P((const char *, struct vfsconf *)); 446#else 447#define vfsconf ovfsconf 448struct ovfsconf *getvfsbyname __P((const char *)); 449struct ovfsconf *getvfsbytype __P((int)); 450struct ovfsconf *getvfsent __P((void)); 451#endif 452void setvfsent __P((int)); 453void endvfsent __P((void)); 454int vfsisloadable __P((const char *)); 455int vfsload __P((const char *)); 456__END_DECLS 457 458#endif /* KERNEL */ 459 460#endif /* !_SYS_MOUNT_H_ */ 461