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*b205dceaSmckusick * @(#)mount.h 8.19 (Berkeley) 05/10/95 837e65185Smckusick */ 937e65185Smckusick 109578c90fSmckusick #ifndef KERNEL 119578c90fSmckusick #include <sys/ucred.h> 129578c90fSmckusick #endif 13134356a5Smckusick #include <sys/queue.h> 1416fba789Smckusick #include <net/radix.h> 1516fba789Smckusick #include <sys/socket.h> /* XXX for AF_MAX */ 169578c90fSmckusick 17f43778eaScgd typedef struct { int32_t val[2]; } fsid_t; /* file system id type */ 1837e65185Smckusick 1937e65185Smckusick /* 2037e65185Smckusick * File identifier. 2137e65185Smckusick * These are unique per filesystem on a single machine. 2237e65185Smckusick */ 2337e65185Smckusick #define MAXFIDSZ 16 2437e65185Smckusick 2537e65185Smckusick struct fid { 2637e65185Smckusick u_short fid_len; /* length of data in bytes */ 27a504fefbSmckusick u_short fid_reserved; /* force longword alignment */ 2837e65185Smckusick char fid_data[MAXFIDSZ]; /* data (variable length) */ 2937e65185Smckusick }; 3037e65185Smckusick 3137e65185Smckusick /* 327321ffb6Smckusick * file system statistics 337321ffb6Smckusick */ 347321ffb6Smckusick 3516fba789Smckusick #define MFSNAMELEN 16 /* length of fs type name, including null */ 367321ffb6Smckusick #define MNAMELEN 90 /* length of buffer for returned name */ 377321ffb6Smckusick 387321ffb6Smckusick struct statfs { 3916fba789Smckusick short f_type; /* filesystem type number */ 407321ffb6Smckusick short f_flags; /* copy of mount flags */ 41f6f794dcSmckusick long f_bsize; /* fundamental file system block size */ 42f6f794dcSmckusick long f_iosize; /* optimal transfer block size */ 437321ffb6Smckusick long f_blocks; /* total data blocks in file system */ 447321ffb6Smckusick long f_bfree; /* free blocks in fs */ 457321ffb6Smckusick long f_bavail; /* free blocks avail to non-superuser */ 467321ffb6Smckusick long f_files; /* total file nodes in file system */ 477321ffb6Smckusick long f_ffree; /* free file nodes in fs */ 487321ffb6Smckusick fsid_t f_fsid; /* file system id */ 499a537971Smckusick uid_t f_owner; /* user that mounted the filesystem */ 5016fba789Smckusick long f_spare[4]; /* spare for later */ 5116fba789Smckusick char f_fstypename[MFSNAMELEN]; /* fs type name */ 527321ffb6Smckusick char f_mntonname[MNAMELEN]; /* directory on which mounted */ 537321ffb6Smckusick char f_mntfromname[MNAMELEN];/* mounted filesystem */ 547321ffb6Smckusick }; 5508be226dSkarels 567321ffb6Smckusick /* 573cad2a65Sbostic * Structure per mounted file system. Each mounted file system has an 583cad2a65Sbostic * array of operations and an instance record. The file systems are 593cad2a65Sbostic * put on a doubly linked list. 6037e65185Smckusick */ 61134356a5Smckusick LIST_HEAD(vnodelst, vnode); 62134356a5Smckusick 6337e65185Smckusick struct mount { 6420924bcbSmckusick CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */ 6542bc6a02Smckusick struct vfsops *mnt_op; /* operations on fs */ 6616fba789Smckusick struct vfsconf *mnt_vfc; /* configuration info */ 6742bc6a02Smckusick struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 68134356a5Smckusick struct vnodelst mnt_vnodelist; /* list of vnodes this mount */ 6942bc6a02Smckusick int mnt_flag; /* flags */ 7002cb89ebSmckusick int mnt_maxsymlinklen; /* max size of short symlink */ 7142bc6a02Smckusick struct statfs mnt_stat; /* cache of filesystem stats */ 7242bc6a02Smckusick qaddr_t mnt_data; /* private data */ 7337e65185Smckusick }; 7437e65185Smckusick 7537e65185Smckusick /* 76cc73f08eSmckusick * Mount flags. 770ad268d3Smckusick * 780ad268d3Smckusick * Unmount uses MNT_FORCE flag. 7937e65185Smckusick */ 8042bc6a02Smckusick #define MNT_RDONLY 0x00000001 /* read only filesystem */ 8142bc6a02Smckusick #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 8242bc6a02Smckusick #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 8342bc6a02Smckusick #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 8442bc6a02Smckusick #define MNT_NODEV 0x00000010 /* don't interpret special files */ 85b262b538Spendry #define MNT_UNION 0x00000020 /* union with underlying filesystem */ 8696aa0fb0Smckusick #define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 8708be226dSkarels 8837e65185Smckusick /* 8937e65185Smckusick * exported mount flags. 9037e65185Smckusick */ 91d5bca046Smckusick #define MNT_EXRDONLY 0x00000080 /* exported read only */ 9242bc6a02Smckusick #define MNT_EXPORTED 0x00000100 /* file system is exported */ 93d5bca046Smckusick #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ 94d5bca046Smckusick #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ 95d5bca046Smckusick #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ 9608be226dSkarels 9729abdb40Smckusick /* 9829abdb40Smckusick * Flags set by internal operations. 9929abdb40Smckusick */ 10042bc6a02Smckusick #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 10142bc6a02Smckusick #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 102134356a5Smckusick #define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 10308be226dSkarels 1046c77ce8eSmckusick /* 1056c77ce8eSmckusick * Mask of flags that are visible to statfs() 1066c77ce8eSmckusick */ 10742bc6a02Smckusick #define MNT_VISFLAGMASK 0x0000ffff 10808be226dSkarels 10937e65185Smckusick /* 110cc73f08eSmckusick * filesystem control flags. 111cc73f08eSmckusick * 11242bc6a02Smckusick * MNT_MLOCK lock the mount entry so that name lookup cannot proceed 113cc73f08eSmckusick * past the mount point. This keeps the subtree stable during mounts 114cc73f08eSmckusick * and unmounts. 11537e65185Smckusick */ 11642bc6a02Smckusick #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 117d5bca046Smckusick #define MNT_DELEXPORT 0x00020000 /* delete export host lists */ 1180ad268d3Smckusick #define MNT_RELOAD 0x00040000 /* reload filesystem data */ 1190ad268d3Smckusick #define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 12042bc6a02Smckusick #define MNT_MLOCK 0x00100000 /* lock so that subtree is stable */ 12142bc6a02Smckusick #define MNT_MWAIT 0x00200000 /* someone is waiting for lock */ 12242bc6a02Smckusick #define MNT_MPBUSY 0x00400000 /* scan of mount point in progress */ 12342bc6a02Smckusick #define MNT_MPWANT 0x00800000 /* waiting for mount point */ 12442bc6a02Smckusick #define MNT_UNMOUNT 0x01000000 /* unmount in progress */ 1250ad268d3Smckusick #define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */ 12637e65185Smckusick 12737e65185Smckusick /* 12816fba789Smckusick * Sysctl CTL_VFS definitions. 12916fba789Smckusick * 13016fba789Smckusick * Second level identifier specifies which filesystem. Second level 13116fba789Smckusick * identifier VFS_GENERIC returns information about all filesystems. 13216fba789Smckusick */ 13316fba789Smckusick #define VFS_GENERIC 0 /* generic filesystem information */ 13416fba789Smckusick /* 13516fba789Smckusick * Third level identifiers for VFS_GENERIC are given below; third 13616fba789Smckusick * level identifiers for specific filesystems are given in their 13716fba789Smckusick * mount specific header files. 13816fba789Smckusick */ 13916fba789Smckusick #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 14016fba789Smckusick #define VFS_CONF 2 /* struct: vfsconf for filesystem given 14116fba789Smckusick as next argument */ 14216fba789Smckusick 14316fba789Smckusick /* 14416fba789Smckusick * Flags for various system call interfaces. 14516fba789Smckusick * 14616fba789Smckusick * waitfor flags to vfs_sync() and getfsstat() 14716fba789Smckusick */ 14816fba789Smckusick #define MNT_WAIT 1 14916fba789Smckusick #define MNT_NOWAIT 2 15016fba789Smckusick 15116fba789Smckusick /* 15216fba789Smckusick * Generic file handle 15316fba789Smckusick */ 15416fba789Smckusick struct fhandle { 15516fba789Smckusick fsid_t fh_fsid; /* File system id of mount point */ 15616fba789Smckusick struct fid fh_fid; /* File sys specific id */ 15716fba789Smckusick }; 15816fba789Smckusick typedef struct fhandle fhandle_t; 15916fba789Smckusick 16016fba789Smckusick /* 16116fba789Smckusick * Export arguments for local filesystem mount calls. 16216fba789Smckusick */ 16316fba789Smckusick struct export_args { 16416fba789Smckusick int ex_flags; /* export related flags */ 16516fba789Smckusick uid_t ex_root; /* mapping for root uid */ 16616fba789Smckusick struct ucred ex_anon; /* mapping for anonymous user */ 16716fba789Smckusick struct sockaddr *ex_addr; /* net address to which exported */ 16816fba789Smckusick int ex_addrlen; /* and the net address length */ 16916fba789Smckusick struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 17016fba789Smckusick int ex_masklen; /* and the smask length */ 17116fba789Smckusick }; 17216fba789Smckusick 17316fba789Smckusick /* 17416fba789Smckusick * Filesystem configuration information. One of these exists for each 17516fba789Smckusick * type of filesystem supported by the kernel. These are searched at 17616fba789Smckusick * mount time to identify the requested filesystem. 17716fba789Smckusick */ 17816fba789Smckusick struct vfsconf { 17916fba789Smckusick struct vfsops *vfc_vfsops; /* filesystem operations vector */ 18016fba789Smckusick char vfc_name[MFSNAMELEN]; /* filesystem type name */ 18116fba789Smckusick int vfc_typenum; /* historic filesystem type number */ 18216fba789Smckusick int vfc_refcount; /* number mounted of this type */ 18316fba789Smckusick int vfc_flags; /* permanent flags */ 184*b205dceaSmckusick int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */ 18516fba789Smckusick struct vfsconf *vfc_next; /* next in list */ 18616fba789Smckusick }; 18716fba789Smckusick 18816fba789Smckusick #ifdef KERNEL 18916fba789Smckusick 19016fba789Smckusick extern int maxvfsconf; /* highest defined filesystem type */ 19116fba789Smckusick extern struct vfsconf *vfsconf; /* head of list of filesystem types */ 19216fba789Smckusick 19316fba789Smckusick /* 19437e65185Smckusick * Operations supported on mounted file system. 19537e65185Smckusick */ 19608be226dSkarels #ifdef __STDC__ 1973d6b36cdSmckusick struct nameidata; 198f59765e9Smckusick struct mbuf; 19908be226dSkarels #endif 20008be226dSkarels 20137e65185Smckusick struct vfsops { 20208be226dSkarels int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data, 20308be226dSkarels struct nameidata *ndp, struct proc *p)); 20408be226dSkarels int (*vfs_start) __P((struct mount *mp, int flags, 2053d6b36cdSmckusick struct proc *p)); 20608be226dSkarels int (*vfs_unmount) __P((struct mount *mp, int mntflags, 2073d6b36cdSmckusick struct proc *p)); 20808be226dSkarels int (*vfs_root) __P((struct mount *mp, struct vnode **vpp)); 209d0174f3dSmckusick int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid, 21008be226dSkarels caddr_t arg, struct proc *p)); 21108be226dSkarels int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp, 2123d6b36cdSmckusick struct proc *p)); 213d0174f3dSmckusick int (*vfs_sync) __P((struct mount *mp, int waitfor, 214d0174f3dSmckusick struct ucred *cred, struct proc *p)); 215388852a9Smckusick int (*vfs_vget) __P((struct mount *mp, ino_t ino, 216388852a9Smckusick struct vnode **vpp)); 21708be226dSkarels int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp, 218f59765e9Smckusick struct mbuf *nam, struct vnode **vpp, 219f59765e9Smckusick int *exflagsp, struct ucred **credanonp)); 22008be226dSkarels int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp)); 22116fba789Smckusick int (*vfs_init) __P((struct vfsconf *)); 22216fba789Smckusick int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *, 22316fba789Smckusick size_t, struct proc *)); 22437e65185Smckusick }; 22537e65185Smckusick 2263d6b36cdSmckusick #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ 2273d6b36cdSmckusick (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) 2283d6b36cdSmckusick #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) 2293d6b36cdSmckusick #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) 23042bc6a02Smckusick #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) 2313d6b36cdSmckusick #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) 2323d6b36cdSmckusick #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) 233d0174f3dSmckusick #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) 234388852a9Smckusick #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 235f59765e9Smckusick #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \ 236f59765e9Smckusick (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED) 23742bc6a02Smckusick #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) 2389578c90fSmckusick 2399578c90fSmckusick /* 240a04da360Smckusick * Network address lookup element 2419578c90fSmckusick */ 242a04da360Smckusick struct netcred { 243a04da360Smckusick struct radix_node netc_rnodes[2]; 244a04da360Smckusick int netc_exflags; 245a04da360Smckusick struct ucred netc_anon; 246a04da360Smckusick }; 24751d4aa02Shibler 24851d4aa02Shibler /* 24951d4aa02Shibler * Network export information 25051d4aa02Shibler */ 25151d4aa02Shibler struct netexport { 25251d4aa02Shibler struct netcred ne_defexported; /* Default export */ 25351d4aa02Shibler struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ 25451d4aa02Shibler }; 2559578c90fSmckusick 2569578c90fSmckusick /* 25737e65185Smckusick * exported vnode operations 25837e65185Smckusick */ 25951d4aa02Shibler int vfs_export /* process mount export info */ 26051d4aa02Shibler __P((struct mount *, struct netexport *, struct export_args *)); 26116fba789Smckusick struct mount *vfs_getvfs __P((fsid_t *)); /* return vfs given fsid */ 26251d4aa02Shibler struct netcred *vfs_export_lookup /* lookup host in fs export list */ 26351d4aa02Shibler __P((struct mount *, struct netexport *, struct mbuf *)); 26451d4aa02Shibler int vfs_lock __P((struct mount *)); /* lock a vfs */ 26551d4aa02Shibler int vfs_mountedon __P((struct vnode *));/* is a vfs mounted on vp */ 26616fba789Smckusick void vfs_getnewfsid __P((struct mount *)); /* create a unique fsid */ 26751d4aa02Shibler void vfs_unlock __P((struct mount *)); /* unlock a vfs */ 26820924bcbSmckusick void vfs_unmountall __P((void)); /* unmount all filesystems */ 26920924bcbSmckusick extern CIRCLEQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 27008be226dSkarels 27116fba789Smckusick #else /* !KERNEL */ 272bda92a63Sdonn 273bda92a63Sdonn #include <sys/cdefs.h> 274bda92a63Sdonn 275bda92a63Sdonn __BEGIN_DECLS 276bda92a63Sdonn int fstatfs __P((int, struct statfs *)); 277e4746589Sdonn int getfh __P((const char *, fhandle_t *)); 278e4746589Sdonn int getfsstat __P((struct statfs *, long, int)); 279bda92a63Sdonn int getmntinfo __P((struct statfs **, int)); 28016fba789Smckusick int mount __P((const char *, const char *, int, void *)); 281bda92a63Sdonn int statfs __P((const char *, struct statfs *)); 282bda92a63Sdonn int unmount __P((const char *, int)); 283bda92a63Sdonn __END_DECLS 284bda92a63Sdonn 28508be226dSkarels #endif /* KERNEL */ 286