1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
.\" $OpenBSD: VOP_LOOKUP.9,v 1.8 2003/04/30 04:53:18 tedu Exp $
.\"
.\" Copyright (c) 2003 Ted Unangst
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd March 9, 2003
.Dt VOP 9
.Os
.Sh NAME
.Nm VOP functions
.Nd vnode operations
.Sh SYNOPSIS
.Fd #include <sys/vnode.h>
.Ft int
.Fo VOP_CREATE
.Fa "struct vnode *dvp"
.Fa "struct vnode **vpp"
.Fa "struct componentname *cnp"
.Fa "struct vattr *vap"
.Fc
.Ft int
.Fo VOP_FSYNC
.Fa "struct vnode *vp"
.Fa "struct ucred *cred"
.Fa "int waitfor"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_GETEXTATTR
.Fa "struct vnode *vp"
.Fa "int attrnamespace"
.Fa "const char *name"
.Fa "struct uio *uio"
.Fa "size_t *size"
.Fa "struct ucred *cred"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_ISLOCKED
.Fa "struct vnode *"
.Fc
.Ft int
.Fo VOP_LINK
.Fa "struct vnode *dvp"
.Fa "struct vnode *vp"
.Fa "struct componentname *cnp"
.Fc
.Ft int
.Fo VOP_LOCK
.Fa "struct vnode *vp"
.Fa "int flags"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_LOOKUP
.Fa "struct vnode *dvp"
.Fa "struct vnode **vpp"
.Fa "struct componentname *cnp"
.Fc
.Ft int
.Fo VOP_MKDIR
.Fa "struct vnode *dvp"
.Fa "struct vnode **vpp"
.Fa "struct componentname *cnp"
.Fa "struct vattr *vap"
.Fc
.Ft int
.Fo VOP_PRINT
.Fa "struct vnode *vp"
.Fc
.Ft int
.Fo VOP_READLINK
.Fa "struct vnode *vp"
.Fa "struct uio *uio"
.Fa "struct ucred *cred"
.Fc
.Ft int
.Fo VOP_REALLOCBLKS
.Fa "struct vnode *vp"
.Fa "struct cluster_save *buflist"
.Fc
.Ft int
.Fo VOP_RECLAIM
.Fa "struct vnode *vp"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_REMOVE
.Fa "struct vnode *dvp"
.Fa "struct vnode *vp"
.Fa "struct componentname *cnp"
.Fc
.Ft int
.Fo VOP_REVOKE
.Fa "struct vnode *vp"
.Fa "int flags"
.Fc
.Ft int
.Fo VOP_RMDIR
.Fa "struct vnode *dvp"
.Fa "struct vnode *vp"
.Fa "struct componentname *cnp"
.Fc
.Ft int
.Fo VOP_SETEXTATTR
.Fa "struct vnode *vp"
.Fa "int attrnamespace"
.Fa "const char *name"
.Fa "struct uio *uio"
.Fa "struct ucred *cred"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_STRATEGY
.Fa "struct buf *bp"
.Fc
.Ft int
.Fo VOP_SYMLINK
.Fa "struct vnode *dvp"
.Fa "struct vnode *vpp"
.Fa "struct componentname *cnp"
.Fa "struct vattr *vap"
.Fa "char *target"
.Fc
.Ft int
.Fo VOP_UNLOCK
.Fa "struct vnode *vp"
.Fa "int flags"
.Fa "struct proc *p"
.Fc
.Ft int
.Fo VOP_WHITEOUT
.Fa "struct vnode *dvp"
.Fa "struct componentname *cnp"
.Fa "int flags"
.Fc
.\" and many more
.Sh DESCRIPTION
The
.Nm
functions implement a generic way to perform operations on vnodes.
The VOP function called passes the arguments to the correct file system
specific function.
Not all file systems implement all operations, in which case a generic
method will be used.
These functions exist to provide an abstract method to invoke vnode
operations without needing to know anything about the underlying file system.
Many syscalls map directly to a specific VOP function.
.Pp
The arguments for each VOP
function consist of one or more vnode pointers along with other data
needed to perform the operation.
Care must be taken to obey the vnode locking discipline when using
VOP functions.
The locking discipline for all currently defined VOP
functions is described in the file
.Pa sys/kern/vnode_if.src .
Many VOP calls take a struct proc *p argument.
This should be the current process.
VOP calls are not safe to call in an interrupt context.
.Pp
The following sections comment on the VOP functions from the consumer's
perspective.
Some notes for file system implementors follow.
.Sh VOP_CREATE
.Fn VOP_CREATE
creates a new directory entry for a regular file in the directory
.Ar dvp
and returns a locked, referenced vnode in
.Ar vpp .
The file name is in
.Ar cnp
and its permissions will be
.Ar vap .
.Sh VOP_FSYNC
.Fn VOP_FSYNC
flushes any dirty buffers associated with
.Ar vp
to disk.
The vnode is locked on entry and exit.
.Ar waitfor
can be set to MNT_WAIT to indicate VOP_FSYNC should not return
until all data is written.
.Sh VOP_GETEXTATTR
.Fn VOP_GETEXTATTR
and
.Fn VOP_SETEXTATTR
are called to get and set named extended file attributes (see
.Xr extattr 9 ) .
.Ar vp
is the vnode for which to get or set the attribute.
It must be locked.
.Ar attrnamespace
is an integer describing whether the attribute belongs in the
user or system namespace.
.Ar name
is the extended attribute to get or set.
.Ar uio
is a
.Xr uio 9
structure with the userland address containing the userland data.
VOP_GETEXTATTR will return the actual length of the attribute
in
.Ar size
if it is non-NULL.
.Ar cred
is a pointer to the credentials used to access the file.
.Sh VOP_LINK
.Fn VOP_LINK
increases the link count for the vnode
.Ar vp .
A new entry with name
.Ar cnp
should be added to the directory
.Ar dvp .
.Ar dvp
is locked on entry and unlocked on exit.
.Sh VOP_LOOKUP
.Fn VOP_LOOKUP
finds the file corresponding to the name
.Ar cnp
in the directory
.Ar dvp
and returns a vnode in
.Ar vpp .
.Ar dvp
is locked on entry and exit, and
.Ar vpp
is locked upon a successful return.
.Ar vpp
will be NULL on error, and cnp->cn_flags will be set to PDIRUNLOCK
if
.Ar dvp
has been unlocked for an unsuccessful return.
.Sh VOP_MKDIR
.Fn VOP_MKDIR
implements the
.Xr mkdir 2
syscall.
A new directory with name matching that in
.Ar cnp
and with permissions
.Ar vattr
will be created in the directory
.Ar dvp .
On success, the new vnode is returned locked in
.Ar vpp .
.Ar dvp
must be locked on entry and is unlocked on exit.
.Sh VOP_PRINT
.Fn VOP_PRINT
prints information about the vnode to the kernel message buffer.
It is not used normally, but exists only for debugging purposes.
.Sh VOP_READLINK
.Fn VOP_READLINK
reads a symbolic link and returns the target's name in
.Ar uio .
.Ar vp
is locked on entry and exit and must be a symlink.
.Sh VOP_REALLOCBLKS
.Fn VOP_REALLOCBLKS
is called by the vfs write clustering code.
It gives the file system an opporunity to rearrange the on disk blocks
for a file to reduce fragmentation.
.Ar vp
is the locked vnode for the file, and
.Ar buflist
is a cluster of the outstanding buffers about to written.
Currently, only FFS implements this call.
.Sh VOP_RECLAIM
.Fn VOP_RECLAIM
is used by
.Xr vclean 9
so that the file system has an opportunity to free memory
and perform any other cleanup activity related to
.Ar vp .
.Ar vp
is unlocked on entry and exit.
VOP_RECLAIM should not be used by generic code.
.Sh VOP_REMOVE
.Fn VOP_REMOVE
removes the link named
.Ar cnp
from the directory
.Ar dvp .
This file corresponds to the vnode
.Ar vp .
Both dvp and vp are locked on entry and unlocked on exit, and
each has its reference count decremented by one.
VOP_REMOVE does not delete the file from disk unless its link count
becomes zero (for file systems which support multiple links).
.Sh VOP_REVOKE
.Fn VOP_REVOKE
is used by the
.Xr revoke 2
syscall to prevent any further access to a vnode.
The vnode ops will be changed to those of deadfs, which returns only
errors.
.Ar vp
must be unlocked.
.Sh VOP_RMDIR
.Fn VOP_RMDIR
implements the
.Xr rmdir 2
syscall.
The directory
.Ar vp
will be removed from the directory
.Ar dvp .
Both are locked on entry and unlocked on exit.
The name of the directory for removal is additionally contained in
.Ar cnp .
.Sh VOP_STRATEGY
.Fn VOP_STRATEGY
is the only VOP call not taking a vnode argument.
It calls the appropriate strategy function for the device backing the
buffer's vnode.
.Sh VOP_SYMLINK
.Fn VOP_SYMLINK
creates a symbolic link with name
.Ar cnp
in the directory
.Ar dvp
with mode
.Ar vap .
The link will point to
.Ar target
and a vnode for it is returned in
.Ar vpp .
The directory vnode is locked on entry and unlocked on exit.
Note that unlike most VOP calls returning a vnode, VOP_SYMLINK
does not lock or reference
.Ar vpp .
.Sh VOP_LOCK
.Fn VOP_LOCK
is used internally by
.Xr vn_lock 9
to lock a vnode.
It should not be used by other file system code.
.Fn VOP_UNLOCK
unlocks a vnode.
.Ar flags
should be zero in most cases.
.Fn VOP_ISLOCKED
returns 1 if
.Ar vp
is locked and 0 if not.
It should be used cautiously, as not all file systems implement locks
effectively.
Note the asymmetry between vn_lock and VOP_UNLOCK.
.Sh VOP_WHITEOUT
.Fn VOP_WHITEOUT
manipulates whiteout entries in a directory.
.Ar dvp
is the directory containing, or to contain, the whiteout.
It is locked on entry and exit.
.Ar cnp
contains the name of the whiteout.
.Ar flags
is used to indicate the operation.
Whiteouts may be created or deleted.
A whiteout entry is normally used to indicate the absence of a file on a
translucent file system.
.Sh IMPLEMENTATION NOTES
The
.Nm VOP
functions are stubs which redirect their arguments to the
appropriate function for each file system.
In order to allow for layered file systems and generic bypass methods,
all vnode operation implementing functions take only a single void *
pointer as an argument.
This points to a structure containing the real arguments.
Additionally, this structure contains a struct vnodeop_desc *,
or vnodeop description.
The description is typically used by the abstract VOP code, but can
be useful to the lower implementation as well.
Every file system defines an array of struct vnodeopv_entry_desc
that contains one entry for each implemented vnode op.
Unimplemented vnode operations match the default description,
.Em vop_default_desc .
Most non-layer file systems should assign the default error handler,
.Em vn_default_error ,
to the generic description.
.Pp
All lower level implementations should conform to the interfaces described
above.
The rules for locking and referencing vnodes are enforced by each
file system implementation, not the VOP stubs.
.Sh RETURN VALUES
The
.Nm
functions return 0 to indicate success and a non-zero error code
to indicate failure.
.Sh FILES
.Bl -tag -width sys/kern/vnode_if.src -compact
.It Pa sys/kern/vnode_if.src
source file containing
.Nm
definitions
.It Pa sys/kern/vnode_if.c
C file with implementations of each
.Nm
stub call
.El
.Sh SEE ALSO
.Xr errno 2 ,
.Xr vn_lock 9 ,
.Xr vnode 9
.Sh AUTHORS
This man page was written by Ted Unangst for OpenBSD.
.Sh BUGS
The locking discipline is too complex.
Refer to
.Xr vn_lock 9 .
|