1 .\" $NetBSD: vnsubr.9,v 1.37 2009/05/28 09:32:17 wiz Exp $
3 .\" Copyright (c) 2001, 2005, 2006 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.
37 .Nm vn_default_error ,
43 .Nm vn_restorerecurse ,
48 .Nd high-level convenience functions for vnode operations
54 .Fn vn_bwrite "void *ap"
56 .Fn vn_close "struct vnode *vp" "int flags" "kauth_cred_t cred"
58 .Fn vn_default_error "void *v"
60 .Fn vn_isunder "struct vnode *dvp" "struct vnode *rvp" "struct lwp *l"
62 .Fn vn_lock "struct vnode *vp" "int flags"
64 .Fn vn_markexec "struct vnode *vp"
66 .Fn vn_marktext "struct vnode *vp"
68 .Fn vn_setrecurse "struct vnode *vp"
70 .Fn vn_restorerecurse "struct vnode *vp" "u_int flags"
72 .Fn vn_open "struct nameidata *ndp" "int fmode" "int cmode"
75 .Fa "enum uio_rw rw" "struct vnode *vp" "void *base"
76 .Fa "int len" "off_t offset" "enum uio_seg segflg" "int ioflg"
77 .Fa "kauth_cred_t cred" "size_t *aresid" "struct lwp *l"
80 .Fn vn_readdir "file_t *fp" "char *buf" "int segflg" "u_int count" "int *done" "struct lwp *l" "off_t **cookies" "int *ncookies"
82 .Fn vn_stat "struct vnode *vp" "struct stat *sb"
84 .Fn vn_writechk "struct vnode *vp"
86 The high-level functions described in this page are convenience
87 functions for simplified access to the vnode operations described in
90 .Bl -tag -width compact
92 Common code for block write operations.
93 .It Fn vn_close "vp" "flags" "cred"
94 Common code for a vnode close.
97 is the unlocked vnode of the vnode to close.
99 simply locks the vnode, invokes the vnode operation
103 to return the vnode to the freelist or holdlist.
106 expects an unlocked, referenced vnode and will dereference the vnode
108 If the operation is successful zero is returned,
109 otherwise an appropriate error is returned.
110 .It Fn vn_default_error "v"
111 A generic "default" routine that just returns error.
112 It is used by a file system to specify unsupported operations in
113 the vnode operations vector.
114 .It Fn vn_isunder "dvp" "rvp" "l"
115 Common code to check if one directory specified by the vnode
117 can be found inside the directory specified by the vnode
121 is the calling process.
123 is intended to be used in
129 actually means something.
130 If the operation is successful zero is returned, otherwise 1 is returned.
131 .It Fn vn_lock "vp" "flags"
132 Common code to acquire the lock for vnode
138 flags used to lock the vnode.
139 If the operation is successful zero is returned, otherwise an
140 appropriate error code is returned.
143 is released on return.
146 must not be called when the vnode's reference count is zero.
150 .It Fn vn_markexec "vp"
151 Common code to mark the vnode
153 as containing executable code of a running process.
154 .It Fn vn_marktext "vp"
155 Common code to mark the vnode
157 as being the text of a running process.
158 .It Fn vn_setrecurse "vp"
159 Common code to enable
161 on the vnode lock for vnode
166 flags after the update.
167 .It Fn vn_restorerecurse "vp" "flags"
168 Common code to restore the vnode lock flags for the vnode
170 It is called when done with
172 .It Fn vn_open "ndp" "fmode" "cmode"
173 Common code for vnode open operations.
174 The pathname is described in the nameidata pointer (see
182 file mode and the access permissions for creation.
184 checks permissions and invokes the
189 If the operation is successful zero is returned and the vnode is locked,
190 otherwise an appropriate error code is returned.
191 .It Fn vn_rdwr "rw" "vp" "base" "len" "offset" "segflg" "ioflg" "cred" "aresid" "l"
192 Common code to package up an I/O request on a vnode into a uio and
193 then perform the I/O.
196 specifies whether the I/O is a read
201 The vnode is specified by
207 are the calling lwp and its credentials.
212 it is expected that the vnode is locked.
215 .Fn VOP_READ Ns No / Ns Fn VOP_WRITE .
216 The remaining arguments specify the uio parameters.
217 For further information on these parameters see
219 .It Fn vn_readdir "fp" "buf" "segflg" "count" "done" "l" "cookies" "ncookies"
220 Common code for reading the contents of a directory.
223 is the file structure,
225 is the buffer for placing the struct dirent structures.
230 specify the addresses for the list and number of directory seek
231 cookies generated for NFS.
238 if they aren't required to be returned by
240 If the operation is successful zero is returned, otherwise an
241 appropriate error code is returned.
242 .It Fn vn_stat "vp" "sb"
243 Common code for a vnode stat operation.
244 The vnode is specified by the argument
248 is the buffer to return the stat information.
250 basically calls the vnode operation
252 and transfers the contents of a vattr structure into a struct stat.
253 If the operation is successful zero is returned, otherwise an
254 appropriate error code is returned.
255 .It Fn vn_writechk "vp"
256 Common code to check for write permission on the vnode
258 A vnode is read-only if it is in use as a process's text image.
259 If the vnode is read-only ETEXTBSY is returned, otherwise zero is
260 returned to indicate that the vnode can be written to.
265 The LK_NOWAIT flag was set and
269 The vnode has been reclaimed and is dead.
270 This error is only returned if the LK_RETRY flag is not passed to
273 Cannot write to a vnode since is a process's text image.
276 This section describes places within the
278 source tree where actual code implementing or using the vnode
279 framework can be found.
280 All pathnames are relative to
283 The high-level convenience functions are implemented within the files
284 .Pa sys/kern/vfs_vnops.c
286 .Pa sys/sys/vnode.h .