1 .\" $NetBSD: vfsops.9,v 1.41 2009/03/17 00:10:37 joerg Exp $
3 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Gregory McGarry.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
47 .Nd kernel file system interface
54 .Fa "struct mount *mp" "const char *path" "void *data" "size_t *dlen"
57 .Fn VFS_START "struct mount *mp" "int flags"
59 .Fn VFS_UNMOUNT "struct mount *mp" "int mntflags"
61 .Fn VFS_ROOT "struct mount *mp" "struct vnode **vpp"
63 .Fn VFS_QUOTACTL "struct mount *mp" "int cmds" "uid_t uid" "void *arg"
65 .Fn VFS_STATVFS "struct mount *mp" "struct statvfs *sbp"
67 .Fn VFS_SYNC "struct mount *mp" "int waitfor" "kauth_cred_t cred"
69 .Fn VFS_VGET "struct mount *mp" "ino_t ino" "struct vnode **vpp"
71 .Fn VFS_FHTOVP "struct mount *mp" "struct fid *fhp" "struct vnode **vpp"
73 .Fn VFS_VPTOFH "struct vnode *vp" "struct fid *fhp" "size_t *fh_size"
75 .Fn VFS_SNAPSHOT "struct mount *mp" "struct vnode *vp" "struct timespec *ts"
77 .Fn VFS_SUSPENDCTL "struct mount *mp" "int cmd"
79 In a similar fashion to the
81 interface, all operations that are done on a file system are conducted
82 through a single interface that allows the system to carry out
83 operations on a file system without knowing its construction or type.
85 All supported file systems in the kernel have an entry in the
88 This table is generated by
91 .Dv NULL Ns No -terminated
95 The vfsops structure describes the operations that can be done to a
96 specific file system type.
97 The following table lists the elements of the vfsops vector, the
98 corresponding invocation macro, and a description of the element.
100 .Bl -column "int (*vfs_suspendctl)()" "VFS_SUSPENDCTL" -compact
101 .It Sy Vector element Ta Sy Macro Ta Sy Description
103 .It int (*vfs_mount)() \
105 Ta Mount a file system
107 .It int (*vfs_start)() \
111 .It int (*vfs_unmount)() \
113 Ta Unmount a file system
115 .It int (*vfs_root)() \
117 Ta Get the file system root vnode
119 .It int (*vfs_quotactl)() \
121 Ta Query/modify space quotas
123 .It int (*vfs_statvfs)() \
125 Ta Get file system statistics
127 .It int (*vfs_sync)() \
129 Ta Flush file system buffers
131 .It int (*vfs_vget)() \
133 Ta Get vnode from file id
135 .It int (*vfs_fhtovp)() \
137 Ta NFS file handle to vnode lookup
139 .It int (*vfs_vptofh)() \
141 Ta Vnode to NFS file handle lookup
143 .It void (*vfs_init)() \
145 Ta Initialize file system
147 .It void (*vfs_reinit)() \
149 Ta Reinitialize file system
151 .It void (*vfs_done)() \
153 Ta Cleanup unmounted file system
155 .It int (*vfs_mountroot)() \
157 Ta Mount the root file system
159 .It int (*vfs_snapshot)() \
163 .It int (*vfs_suspendctl)() \
164 Ta Dv VFS_SUSPENDCTL \
168 Some additional non-function members of the vfsops structure are the
171 and a reference count
173 It is not mandatory for a file system type to support a particular
174 operation, but it must assign each member function pointer to a
175 suitable function to do the minimum required of it.
176 In most cases, such functions either do nothing or return an error
177 value to the effect that it is not supported.
187 At system boot, each file system with an entry in
189 is established and initialized.
190 Each initialized file system is recorded by the kernel in the list
192 and the file system specific initialization function
194 in its vfsops vector is invoked.
195 When the file system is no longer needed
197 is invoked to run file system specific cleanups and the file system is
198 removed from the kernel list.
200 At system boot, the root file system is mounted by invoking the file
203 function in the vfsops vector.
204 All file systems that can be mounted as a root file system must define
206 It is responsible for initializing to list of mount structures for
207 all future mounted file systems.
209 Kernel state which affects a specific file system type can be
210 queried and modified using the
214 .Bl -tag -width compact
215 .It Fn VFS_MOUNT "mp" "path" "data" "dlen"
216 Mount a file system specified by the mount structure
218 on the mount point described by
222 contains file system type specific data, while the argument
224 points to a location specifying the length of the data.
227 initializes the mount structure for the mounted file system.
228 This structure records mount-specific information for the file system and
229 records the list of vnodes associated with the file system.
230 This function is invoked both to mount new file systems and to change the
231 attributes of an existing file system.
235 .Va mp-\*[Gt]mnt_flag ,
236 the file system should update its state.
237 This can be used, for instance, to convert a read-only file system to
239 The current attributes for a mounted file system can be fetched by
246 are specified, a new file system will attempted to be mounted.
247 .It Fn VFS_START "mp" "flags"
248 Make the file system specified by the mount structure
253 is a set of flags for controlling the operation of
255 This function is invoked after
257 and before the first access to the file system.
258 .It Fn VFS_UNMOUNT "mp" "mntflags"
259 Unmount a file system specified by the mount structure
262 performs any file system type specific operations required before the
263 file system is unmounted, such are flushing buffers.
266 is specified in the flags
268 then open files are forcibly closed.
269 The function also deallocates space associated with data structure
270 that were allocated for the file system when it was mounted.
271 .It Fn VFS_ROOT "mp" "vpp"
272 Get the root vnode of the file system specified by the mount
275 The vnode is returned in the address given by
277 This function is used by the pathname translation algorithms when a
278 vnode that has been covered by a mounted file system is encountered.
279 While resolving the pathname, the pathname translation algorithm will
280 have to go through the directory tree in the file system associated
281 with that mount point and therefore requires the root vnode of the
283 .It Fn VFS_QUOTACTL "mp" "cmds" "uid" "arg"
284 Query/modify user space quotas for the file system specified by the
287 The argument specifies the control command to perform.
288 The userid is specified in
292 allows command-specific data to be returned to the system call
295 is the file system type specific implementation of the
298 .It Fn VFS_STATVFS "mp" "sbp"
299 Get file system statistics for the file system specified by the mount
302 A statvfs structure filled with the statistics is returned in
305 is the file system type specific implementation of the
310 .It Fn VFS_SYNC "mp" "waitfor" "cred"
311 Flush file system I/O buffers for the file system specified by the mount
316 argument indicates whether a partial flush or complete flush should be
320 specifies the calling credentials.
322 does not provide any return value since the operation can never fail.
323 .It Fn VFS_VGET "mp" "ino" "vpp"
324 Get vnode for a file system type specific file id
326 for the file system specified by the mount structure
328 The vnode is returned in the address specified
330 The function is optional for file systems which have a unique id
331 number for every file in the file system.
332 It is used internally by the UFS file system and also by the NFSv3
333 server to implement the READDIRPLUS NFS call.
334 If the file system does not support this function, it should return
336 .It Fn VFS_FHTOVP "mp" "fhp" "vpp"
337 Get the vnode for the file handle
339 in the file system specified by the mount structure
341 The locked vnode is returned in
344 When exporting, the call to
346 should follow a call to
347 .Fn netexport_check ,
348 which checks if the file is accessible to the client.
350 If file handles are not supported by the file system, this function
353 .It Fn VFS_VPTOFH "vp" "fhp" "fh_size"
354 Get a file handle for the vnode specified by
356 The file handle is returned in
358 The contents of the file handle are defined by the file system and are
359 not examined by any other subsystems.
360 It should contain enough information to uniquely identify a file within
361 the file system as well as noticing when a file has been removed and
362 the file system resources have been recycled for a new file.
366 points to the container size for the file handle.
367 This parameter should be updated to the size of the finished file handle.
368 Note that it is legal to call this function with
377 indicates a storage space too small, the storage space required for
378 the file handle corresponding to
380 should be filled in and
384 If file handles are not supported by the file system, this function
387 .It Fn VFS_SNAPSHOT "mp" "vp" "ts"
388 Take a snapshot of the file system specified by the mount structure
390 and make it accessible through the locked vnode
396 it will receive the time this snapshot was taken.
397 If the file system does not support this function, it should return
399 .It Fn VFS_SUSPENDCTL "mp" "cmd"
400 Suspend or resume all operations on this file system.
406 to resume operations.
407 If the file system does not support this function, it should return
411 This section describes places within the
413 source tree where actual code implementing or using the vfs
414 operations can be found.
415 All pathnames are relative to
418 The vfs operations are implemented within the files
419 .Pa sys/kern/vfs_subr.c
421 .Pa sys/kern/vfs_init.c .
430 The vfs operations vector, its functions and the corresponding macros