137e65185Smckusick /* 283adbb3cSbostic * Copyright (c) 1989, 1991, 1993 383adbb3cSbostic * The Regents of the University of California. All rights reserved. 437e65185Smckusick * 598799fb9Sbostic * %sccs.include.redist.c% 637e65185Smckusick * 7*83e1a490Smckusick * @(#)mount.h 8.21 (Berkeley) 05/20/95 837e65185Smckusick */ 937e65185Smckusick 109578c90fSmckusick #ifndef KERNEL 119578c90fSmckusick #include <sys/ucred.h> 129578c90fSmckusick #endif 13134356a5Smckusick #include <sys/queue.h> 14*83e1a490Smckusick #include <sys/lock.h> 1516fba789Smckusick #include <net/radix.h> 1616fba789Smckusick #include <sys/socket.h> /* XXX for AF_MAX */ 179578c90fSmckusick 18f43778eaScgd typedef struct { int32_t val[2]; } fsid_t; /* file system id type */ 1937e65185Smckusick 2037e65185Smckusick /* 2137e65185Smckusick * File identifier. 2237e65185Smckusick * These are unique per filesystem on a single machine. 2337e65185Smckusick */ 2437e65185Smckusick #define MAXFIDSZ 16 2537e65185Smckusick 2637e65185Smckusick struct fid { 2737e65185Smckusick u_short fid_len; /* length of data in bytes */ 28a504fefbSmckusick u_short fid_reserved; /* force longword alignment */ 2937e65185Smckusick char fid_data[MAXFIDSZ]; /* data (variable length) */ 3037e65185Smckusick }; 3137e65185Smckusick 3237e65185Smckusick /* 337321ffb6Smckusick * file system statistics 347321ffb6Smckusick */ 357321ffb6Smckusick 3616fba789Smckusick #define MFSNAMELEN 16 /* length of fs type name, including null */ 377321ffb6Smckusick #define MNAMELEN 90 /* length of buffer for returned name */ 387321ffb6Smckusick 397321ffb6Smckusick struct statfs { 4016fba789Smckusick short f_type; /* filesystem type number */ 417321ffb6Smckusick short f_flags; /* copy of mount flags */ 42f6f794dcSmckusick long f_bsize; /* fundamental file system block size */ 43f6f794dcSmckusick long f_iosize; /* optimal transfer block size */ 447321ffb6Smckusick long f_blocks; /* total data blocks in file system */ 457321ffb6Smckusick long f_bfree; /* free blocks in fs */ 467321ffb6Smckusick long f_bavail; /* free blocks avail to non-superuser */ 477321ffb6Smckusick long f_files; /* total file nodes in file system */ 487321ffb6Smckusick long f_ffree; /* free file nodes in fs */ 497321ffb6Smckusick fsid_t f_fsid; /* file system id */ 509a537971Smckusick uid_t f_owner; /* user that mounted the filesystem */ 5116fba789Smckusick long f_spare[4]; /* spare for later */ 5216fba789Smckusick char f_fstypename[MFSNAMELEN]; /* fs type name */ 537321ffb6Smckusick char f_mntonname[MNAMELEN]; /* directory on which mounted */ 547321ffb6Smckusick char f_mntfromname[MNAMELEN];/* mounted filesystem */ 557321ffb6Smckusick }; 5608be226dSkarels 577321ffb6Smckusick /* 583cad2a65Sbostic * Structure per mounted file system. Each mounted file system has an 593cad2a65Sbostic * array of operations and an instance record. The file systems are 603cad2a65Sbostic * put on a doubly linked list. 6137e65185Smckusick */ 62134356a5Smckusick LIST_HEAD(vnodelst, vnode); 63134356a5Smckusick 6437e65185Smckusick struct mount { 6520924bcbSmckusick CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */ 6642bc6a02Smckusick struct vfsops *mnt_op; /* operations on fs */ 6716fba789Smckusick struct vfsconf *mnt_vfc; /* configuration info */ 6842bc6a02Smckusick struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 69134356a5Smckusick struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 70*83e1a490Smckusick struct lock mnt_lock; /* mount structure lock */ 7142bc6a02Smckusick int mnt_flag; /* flags */ 7202cb89ebSmckusick int mnt_maxsymlinklen; /* max size of short symlink */ 7342bc6a02Smckusick struct statfs mnt_stat; /* cache of filesystem stats */ 7442bc6a02Smckusick qaddr_t mnt_data; /* private data */ 7537e65185Smckusick }; 7637e65185Smckusick 7737e65185Smckusick /* 78cc73f08eSmckusick * Mount flags. 790ad268d3Smckusick * 800ad268d3Smckusick * Unmount uses MNT_FORCE flag. 8137e65185Smckusick */ 8242bc6a02Smckusick #define MNT_RDONLY 0x00000001 /* read only filesystem */ 8342bc6a02Smckusick #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 8442bc6a02Smckusick #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 8542bc6a02Smckusick #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 8642bc6a02Smckusick #define MNT_NODEV 0x00000010 /* don't interpret special files */ 87b262b538Spendry #define MNT_UNION 0x00000020 /* union with underlying filesystem */ 8896aa0fb0Smckusick #define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 8908be226dSkarels 9037e65185Smckusick /* 9137e65185Smckusick * exported mount flags. 9237e65185Smckusick */ 93d5bca046Smckusick #define MNT_EXRDONLY 0x00000080 /* exported read only */ 9442bc6a02Smckusick #define MNT_EXPORTED 0x00000100 /* file system is exported */ 95d5bca046Smckusick #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 96d5bca046Smckusick #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 97d5bca046Smckusick #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 9808be226dSkarels 9929abdb40Smckusick /* 10029abdb40Smckusick * Flags set by internal operations. 10129abdb40Smckusick */ 10242bc6a02Smckusick #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 10342bc6a02Smckusick #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 104134356a5Smckusick #define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 10508be226dSkarels 1066c77ce8eSmckusick /* 1076c77ce8eSmckusick * Mask of flags that are visible to statfs() 1086c77ce8eSmckusick */ 10942bc6a02Smckusick #define MNT_VISFLAGMASK 0x0000ffff 11008be226dSkarels 11137e65185Smckusick /* 112*83e1a490Smckusick * External filesystem control flags. 11337e65185Smckusick */ 11442bc6a02Smckusick #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 115d5bca046Smckusick #define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 1160ad268d3Smckusick #define MNT_RELOAD 0x00040000 /* reload filesystem data */ 1170ad268d3Smckusick #define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 118*83e1a490Smckusick /* 119*83e1a490Smckusick * Internal filesystem control flags. 120*83e1a490Smckusick * 121*83e1a490Smckusick * MNT_UNMOUNT locks the mount entry so that name lookup cannot proceed 122*83e1a490Smckusick * past the mount point. This keeps the subtree stable during mounts 123*83e1a490Smckusick * and unmounts. 124*83e1a490Smckusick */ 12542bc6a02Smckusick #define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 126*83e1a490Smckusick #define MNT_MWAIT 0x02000000 /* waiting for unmount to finish */ 127*83e1a490Smckusick #define MNT_WANTRDWR 0x04000000 /* upgrade to read/write requested */ 12837e65185Smckusick 12937e65185Smckusick /* 13016fba789Smckusick * Sysctl CTL_VFS definitions. 13116fba789Smckusick * 13216fba789Smckusick * Second level identifier specifies which filesystem. Second level 13316fba789Smckusick * identifier VFS_GENERIC returns information about all filesystems. 13416fba789Smckusick */ 13516fba789Smckusick #define VFS_GENERIC 0 /* generic filesystem information */ 13616fba789Smckusick /* 13716fba789Smckusick * Third level identifiers for VFS_GENERIC are given below; third 13816fba789Smckusick * level identifiers for specific filesystems are given in their 13916fba789Smckusick * mount specific header files. 14016fba789Smckusick */ 14116fba789Smckusick #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 14216fba789Smckusick #define VFS_CONF 2 /* struct: vfsconf for filesystem given 14316fba789Smckusick as next argument */ 14416fba789Smckusick 14516fba789Smckusick /* 14616fba789Smckusick * Flags for various system call interfaces. 14716fba789Smckusick * 14816fba789Smckusick * waitfor flags to vfs_sync() and getfsstat() 14916fba789Smckusick */ 15016fba789Smckusick #define MNT_WAIT 1 15116fba789Smckusick #define MNT_NOWAIT 2 15216fba789Smckusick 15316fba789Smckusick /* 15416fba789Smckusick * Generic file handle 15516fba789Smckusick */ 15616fba789Smckusick struct fhandle { 15716fba789Smckusick fsid_t fh_fsid; /* File system id of mount point */ 15816fba789Smckusick struct fid fh_fid; /* File sys specific id */ 15916fba789Smckusick }; 16016fba789Smckusick typedef struct fhandle fhandle_t; 16116fba789Smckusick 16216fba789Smckusick /* 16316fba789Smckusick * Export arguments for local filesystem mount calls. 16416fba789Smckusick */ 16516fba789Smckusick struct export_args { 16616fba789Smckusick int ex_flags; /* export related flags */ 16716fba789Smckusick uid_t ex_root; /* mapping for root uid */ 16816fba789Smckusick struct ucred ex_anon; /* mapping for anonymous user */ 16916fba789Smckusick struct sockaddr *ex_addr; /* net address to which exported */ 17016fba789Smckusick int ex_addrlen; /* and the net address length */ 17116fba789Smckusick struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 17216fba789Smckusick int ex_masklen; /* and the smask length */ 17316fba789Smckusick }; 17416fba789Smckusick 17516fba789Smckusick /* 17616fba789Smckusick * Filesystem configuration information. One of these exists for each 17716fba789Smckusick * type of filesystem supported by the kernel. These are searched at 17816fba789Smckusick * mount time to identify the requested filesystem. 17916fba789Smckusick */ 18016fba789Smckusick struct vfsconf { 18116fba789Smckusick struct vfsops *vfc_vfsops; /* filesystem operations vector */ 18216fba789Smckusick char vfc_name[MFSNAMELEN]; /* filesystem type name */ 18316fba789Smckusick int vfc_typenum; /* historic filesystem type number */ 18416fba789Smckusick int vfc_refcount; /* number mounted of this type */ 18516fba789Smckusick int vfc_flags; /* permanent flags */ 186b205dceaSmckusick int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */ 18716fba789Smckusick struct vfsconf *vfc_next; /* next in list */ 18816fba789Smckusick }; 18916fba789Smckusick 19016fba789Smckusick #ifdef KERNEL 19116fba789Smckusick 19216fba789Smckusick extern int maxvfsconf; /* highest defined filesystem type */ 19316fba789Smckusick extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 19416fba789Smckusick 19516fba789Smckusick /* 19637e65185Smckusick * Operations supported on mounted file system. 19737e65185Smckusick */ 19808be226dSkarels #ifdef __STDC__ 1993d6b36cdSmckusick struct nameidata; 200f59765e9Smckusick struct mbuf; 20108be226dSkarels #endif 20208be226dSkarels 20337e65185Smckusick struct vfsops { 20408be226dSkarels int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 20508be226dSkarels struct nameidata *ndp, struct proc *p)); 20608be226dSkarels int (*vfs_start) __P((struct mount *mp, int flags, 2073d6b36cdSmckusick struct proc *p)); 20808be226dSkarels int (*vfs_unmount) __P((struct mount *mp, int mntflags, 2093d6b36cdSmckusick struct proc *p)); 21008be226dSkarels int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 211d0174f3dSmckusick int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 21208be226dSkarels caddr_t arg, struct proc *p)); 21308be226dSkarels int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 2143d6b36cdSmckusick struct proc *p)); 215d0174f3dSmckusick int (*vfs_sync) __P((struct mount *mp, int waitfor, 216d0174f3dSmckusick struct ucred *cred, struct proc *p)); 217388852a9Smckusick int (*vfs_vget) __P((struct mount *mp, ino_t ino, 218388852a9Smckusick struct vnode **vpp)); 21908be226dSkarels int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 220f59765e9Smckusick struct mbuf *nam, struct vnode **vpp, 221f59765e9Smckusick int *exflagsp, struct ucred **credanonp)); 22208be226dSkarels int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 22316fba789Smckusick int (*vfs_init) __P((struct vfsconf *)); 22416fba789Smckusick int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *, 22516fba789Smckusick size_t, struct proc *)); 22637e65185Smckusick }; 22737e65185Smckusick 2283d6b36cdSmckusick #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 2293d6b36cdSmckusick (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 2303d6b36cdSmckusick #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 2313d6b36cdSmckusick #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 23242bc6a02Smckusick #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 2333d6b36cdSmckusick #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 2343d6b36cdSmckusick #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 235d0174f3dSmckusick #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 236388852a9Smckusick #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 237f59765e9Smckusick #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 238f59765e9Smckusick (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 23942bc6a02Smckusick #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 2409578c90fSmckusick 2419578c90fSmckusick /* 242a04da360Smckusick * Network address lookup element 2439578c90fSmckusick */ 244a04da360Smckusick struct netcred { 245a04da360Smckusick struct radix_node netc_rnodes[2]; 246a04da360Smckusick int netc_exflags; 247a04da360Smckusick struct ucred netc_anon; 248a04da360Smckusick }; 24951d4aa02Shibler 25051d4aa02Shibler /* 25151d4aa02Shibler * Network export information 25251d4aa02Shibler */ 25351d4aa02Shibler struct netexport { 25451d4aa02Shibler struct netcred ne_defexported; /* Default export */ 25551d4aa02Shibler struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 25651d4aa02Shibler }; 2579578c90fSmckusick 2589578c90fSmckusick /* 25937e65185Smckusick * exported vnode operations 26037e65185Smckusick */ 261*83e1a490Smckusick int vfs_busy __P((struct mount *, int, struct simplelock *, struct proc *)); 262*83e1a490Smckusick int vfs_export __P((struct mount *, struct netexport *, 263*83e1a490Smckusick struct export_args *)); 264*83e1a490Smckusick struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *, 265*83e1a490Smckusick struct mbuf *)); 266*83e1a490Smckusick void vfs_getnewfsid __P((struct mount *)); 267*83e1a490Smckusick struct mount *vfs_getvfs __P((fsid_t *)); 268*83e1a490Smckusick int vfs_mountedon __P((struct vnode *)); 269*83e1a490Smckusick int vfs_mountroot __P((void)); 270*83e1a490Smckusick int vfs_rootmountalloc __P((char *, char *, struct mount **)); 271*83e1a490Smckusick void vfs_unbusy __P((struct mount *, struct proc *)); 272*83e1a490Smckusick void vfs_unmountall __P((void)); 273*83e1a490Smckusick extern CIRCLEQ_HEAD(mntlist, mount) mountlist; 274*83e1a490Smckusick extern struct simplelock mountlist_slock; 27508be226dSkarels 27616fba789Smckusick #else /* !KERNEL */ 277bda92a63Sdonn 278bda92a63Sdonn #include <sys/cdefs.h> 279bda92a63Sdonn 280bda92a63Sdonn __BEGIN_DECLS 281bda92a63Sdonn int fstatfs __P((int, struct statfs *)); 282e4746589Sdonn int getfh __P((const char *, fhandle_t *)); 283e4746589Sdonn int getfsstat __P((struct statfs *, long, int)); 284bda92a63Sdonn int getmntinfo __P((struct statfs **, int)); 28516fba789Smckusick int mount __P((const char *, const char *, int, void *)); 286bda92a63Sdonn int statfs __P((const char *, struct statfs *)); 287bda92a63Sdonn int unmount __P((const char *, int)); 288bda92a63Sdonn __END_DECLS 289bda92a63Sdonn 29008be226dSkarels #endif /* KERNEL */ 291