1.\" $NetBSD: vfsops.9,v 1.15 2003/12/04 23:57:44 wiz Exp $ 2.\" 3.\" Copyright (c) 2001 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd December 5, 2003 38.Dt VFSOPS 9 39.Os 40.Sh NAME 41.Nm vfsops , 42.Nm VFS_MOUNT , 43.Nm VFS_START , 44.Nm VFS_UNMOUNT , 45.Nm VFS_ROOT , 46.Nm VFS_QUOTACTL , 47.Nm VFS_STATFS , 48.Nm VFS_STATFS , 49.Nm VFS_SYNC , 50.Nm VFS_VGET , 51.Nm VFS_FHTOVP , 52.Nm VFS_VPTOFH , 53.Nm VFS_CHECKEXP 54.Nd kernel file system interface 55.Sh SYNOPSIS 56.In sys/param.h 57.In sys/mount.h 58.In sys/vnode.h 59.Ft int 60.Fn VFS_MOUNT "struct mount *mp" "const char *path" "void *data" \ 61"struct nameidata *ndp" "struct proc *p" 62.Ft int 63.Fn VFS_START "struct mount *mp" "int flags" "struct proc *p" 64.Ft int 65.Fn VFS_UNMOUNT "struct mount *mp" "int mntflags" "struct proc *p" 66.Ft int 67.Fn VFS_ROOT "struct mount *mp" "struct vnode **vpp" 68.Ft int 69.Fn VFS_QUOTACTL "struct mount *mp" "int cmds" "uid_t uid" \ 70"caddr_t arg" "struct proc *p" 71.Ft int 72.Fn VFS_STATFS "struct mount *mp" "struct statfs *sbp" "struct proc *p" 73.Ft int 74.Fn VFS_SYNC "struct mount *mp" "int waitfor" "struct ucred *cred" \ 75"struct proc *p" 76.Ft int 77.Fn VFS_VGET "struct mount *mp" "ino_t ino" "struct vnode **vpp" 78.Ft int 79.Fn VFS_FHTOVP "struct mount *mp" "struct fid *fhp" "struct vnode **vpp" 80.Ft int 81.Fn VFS_VPTOFH "struct vnode *vp" "struct fid *fhp" 82.Ft int 83.Fn VFS_CHECKEXP "struct mount *mp" "struct mbuf *nam" \ 84"int *extflagsp" "struct ucred **credanonp" 85.Sh DESCRIPTION 86In a similar fashion to the 87.Xr vnode 9 88interface, all operations that are done on a file system are conducted 89through a single interface that allows the system to carry out 90operations on a file system without knowing its construction or type. 91.Pp 92All supported file systems in the kernel have an entry in the 93.Va vfs_list_initial 94table. 95This table is generated by 96.Xr config 8 97and is a 98.Dv NULL Ns No -terminated 99list of 100.Em vfsops 101structures. 102The vfsops structure describes the operations that can be done to a 103specific file system type. 104The following table list the elements of the vfsops vector, the 105corresponding invocation macro, and a description of the element. 106.Pp 107.nf 108.ta \w'int (*vfs_mountroot)()'u+2n +\w'VFS_QUOTACTL'u+2n +\w'Get the file system root vnode'u 109\fIVector element\fP \fIMacro\fP \fIDescription\fP 110.ta \w'int (*vfs_mountroot)()'u+2n +\w'VFS_QUOTACTL'u+2n +\w'Get the file system root vnode'u+6nC 111.sp 5p 112int (*vfs_mount)() VFS_MOUNT Mount a file system 113int (*vfs_start)() VFS_START Make operational 114int (*vfs_unmount)() VFS_UMOUNT Unmount a file system 115int (*vfs_root)() VFS_ROOT Get the file system root vnode 116int (*vfs_quotactl)() VFS_QUOTACTL Query/modify space quotas 117int (*vfs_statfs)() VFS_STATFS Get file system statistics 118int (*vfs_sync)() VFS_SYNC Flush file system buffers 119int (*vfs_vget)() VFS_VGET Get vnode from file id 120int (*vfs_fhtovp)() VFS_FHTOVP NFS file handle to vnode lookup 121int (*vfs_vptofh)() VFS_VPTOFH Vnode to NFS file handle lookup 122void (*vfs_init)() - Initialise file system 123void (*vfs_reinit)() - Reinitialise file system 124void (*vfs_done)() - Cleanup unmounted file system 125int (*vfs_mountroot)() - Mount the root file system 126int (*vfs_checkexp)() VFS_CHECKEXP Check if file system is exported 127.fi 128.Pp 129Some additional non-function members of the vfsops structure are the 130file system name 131.Ns Em vfs_name 132and a reference count 133.Ns Em vfs_refcount . 134It is not mandatory for a file system type to support a particular 135operation, but it must assign each member function pointer to a 136suitable function to do the minimum required of it. 137In most cases, such functions either do nothing or return an error 138value to the effect that it is not supported. 139.Em vfs_reinit 140and 141.Em vfs_mountroot 142may 143be 144.Dv NULL . 145.Pp 146At system boot, each file system with an entry in 147.Va vfs_list_initial 148is established and initialised. 149Each initialised file system is recorded by the kernel in the list 150.Va vfs_list 151and the file system specific initialisation function 152.Em vfs_init 153in its vfsops vector is invoked. 154When the file system is not longer needed 155.Em vfs_done 156is invoked to run file system specific cleanups and the file system is 157removed from the kernel list. 158.Pp 159At system boot, the root filesystem is mounted by invoking the file 160system type specific 161.Em vfs_mountroot 162function in the vfsops vector. 163All filesystems that can be mounted as a root file system must define 164this function. 165It is responsible for initialising to list of mount structures for 166all future mounted file systems. 167.Pp 168Kernel state which affects a specific file system type can be 169queried and modified using the 170.Xr sysctl 8 171interface. 172.Sh FUNCTIONS 173.Bl -tag -width compact 174.It Fn VFS_MOUNT "mp" "path" "data" "ndp" "p" 175Mount a file system specified by the mount structure 176.Fa mp 177on the mount point described by 178.Fa path . 179The argument 180.Fa data 181contains file system type specific data and is read into the kernel 182using 183.Xr copyin 9 . 184The argument 185.Fa ndp 186contains the result of a 187.Xr namei 9 188call on the pathname of the mount point and 189.Fa p 190is the calling process. 191.Fn VFS_MOUNT 192initialises the mount structure for the mounted file system. 193This structure records mount-specific information for the file system and 194records the list of vnodes associated with the file system. 195This function is invoked both to mount new file systems and to change the 196attributes of an existing file system. 197If the MNT_UPDATE flag is set in 198.Em mp-\*[Gt]mnt_flag 199then the filesystem should update its internal state from the value of 200.Em mp-\*[Gt]mnt_flag . 201This can be used, for instance, to convert a read-only filesystem to 202read-write. 203If the MNT_UPDATE flag is not specified, then this is a newly 204mounted filesystem. 205.It Fn VFS_START "mp" "flags" "p" 206Make the file system specified by the mount structure 207.Fa mp 208operational. 209The argument 210.Fa p 211is the calling process. 212The argument 213.Fa flags 214is a set of flags for controlling the operation of 215.Fn VOP_START . 216This function is invoked after 217.Fn VFS_MOUNT 218and before the first access to the file system. 219.It Fn VFS_UNMOUNT "mp" "mntflags" "p" 220Unmount a file system specified by the mount structure 221.Fa mp . 222The argument 223.Fa p 224is the calling process. 225.Fn VFS_UNMOUNT 226performs any file system type specific operations required before the 227file system is unmounted, such are flushing buffers. 228If MNT_FORCE is specified in the flags 229.Fa mntflags 230then open files are forcibly closed. 231The function also deallocates space associated with data structure 232that were allocated for the file system when it was mounted. 233.It Fn VFS_ROOT "mp" "vpp" 234Get the root vnode of the file system specified by the mount 235structure 236.Fa mp . 237The vnode is returned in the address given by 238.Fa vpp . 239This function is used by the pathname translation algorithms when a 240vnode that has been covered by a mounted file system is encountered. 241While resolving the pathname, the pathname translation algorithm will 242have to go through the directory tree in the file system associated 243with that mount point and therefore requires the root vnode of the 244file system. 245.It Fn VFS_QUOTACTL "mp" "cmds" "uid" "arg" "p" 246Query/modify user space quotas for the file system specified by the 247mount structure 248.Fa mp . 249The argument specifies the control command to perform. 250The userid is specified in 251.Fa id , 252the calling process is 253.Fa p 254and 255.Fa arg 256allows command-specific data to be returned to the system call 257interface. 258.Fn VFS_QUOTACTL 259is the file system type specific implementation of the 260.Xr quotactl 2 261system call. 262.It Fn VFS_STATFS "mp" "sbp" "p" 263Get file system statistics for the file system specified by the mount 264structure 265.Fa mp . 266The argument 267.Fa p 268is the calling process. 269A statfs structure filled with the statistics is returned in 270.Fa sbp . 271.Fn VFS_STATFS 272is the file system type specific implementation of the 273.Xr statfs 2 274and 275.Xr fstatfs 2 276system calls. 277.It Fn VFS_SYNC "mp" "waitfor" "cred" "p" 278Flush file system I/O buffers for the file system specified by the mount 279structure 280.Fa mp . 281The 282.Fa waitfor 283argument indicates whether a partial flush or complete flush should be 284performed. 285The arguments 286.Fa p 287and 288.Fa cred 289specific the calling process and its credentials respectively. 290.Fn VFS_SYNC 291does not provide any return value since the operation can never fail. 292.It Fn VFS_VGET "mp" "ino" "vpp" 293Get vnode for a file system type specific file id 294.Fa ino 295for the file system specified by the mount structure 296.Fa mp . 297The vnode is returned in the address specified 298.Fa vpp . 299The function is optional for file systems which have a unique id 300number for every file in the file system. 301It is used internally by the UFS file system and also by the NFSv3 302server to implement the READDIRPLUS nfs call. 303If the file system does not support this function, it should return 304.Er EOPNOTSUPP . 305.It Fn VFS_FHTOVP "mp" "fhp" "vpp" 306Get the vnode for the NFS file specified by the file handle 307.Fa fhp 308in the file system specified by the mount structure 309.Fa mp . 310The locked vnode is returned in 311.Fa vpp . 312.Pp 313A call to 314.Fn VFS_FHTOVP 315should generally be followed by a call to 316.Fn VFS_CHECKEXP 317to check if the file is accessable to the client. 318.It Fn VFS_VPTOFH "vp" "fhp" 319Get a unique NFS file handle for the file specified by the vnode 320.Fa vp . 321The file handle is returned in 322.Fa fhp . 323The contents of the file handle are defined by the file system and are 324not examined by any other subsystems. 325It should contain enough information to uniquely identify a file within 326the file system as well as noticing when a file has been removed and 327the file system resources have been recycled for a new file. 328.It Fn VFS_CHECKEXP "mp" "nam" "extflagsp" "credanonp" 329Check if the file system specified by the mount structure 330.Fa mp 331is exported to a client with anonymous credentials 332.Fa credanonp . 333The argument 334.Fa nam 335is an mbuf containing the network address of the client. 336The return parameters for the export flags for the client are returned 337in the address specified by 338.Fa exflagsp . 339This function is used by the NFS server. 340It is generally invoked before 341.Fn VFS_FHTOVP 342to validate that client has access to the file system. 343The file system should call 344.Fn vfs_export_lookup 345with the address of an appropriate netexport structure and the address 346of the client to verify that the client can access this file system. 347.El 348.Sh CODE REFERENCES 349This section describes places within the 350.Nx 351source tree where actual code implementing or using the vfs 352operations can be found. 353All pathnames are relative to 354.Pa /usr/src . 355.Pp 356The vfs operations are implemented within the files 357.Pa sys/kern/vfs_subr.c 358and 359.Pa sys/kern/vfs_init.c . 360.Sh SEE ALSO 361.Xr intro 9 , 362.Xr namei 9 , 363.Xr vfs 9 , 364.Xr vfssubr 9 , 365.Xr vnode 9 , 366.Xr vnodeops 9 367.Sh HISTORY 368The vfs operations vector, its functions and the corresponding macros 369appeared in 370.Bx 4.3 . 371