VOP_LOOKUP(9) | Kernel Developer's Manual | VOP_LOOKUP(9) |
VOP_LOOKUP
,
VOP_ABORTOP
, VOP_ACCESS
,
VOP_ADVLOCK
, VOP_BMAP
,
VOP_BWRITE
, VOP_CLOSE
,
VOP_CREATE
, VOP_FSYNC
,
VOP_GETATTR
, VOP_INACTIVE
,
VOP_IOCTL
, VOP_ISLOCKED
,
VOP_KQFILTER
, VOP_LINK
,
VOP_LOCK
, VOP_MKDIR
,
VOP_MKNOD
, VOP_OPEN
,
VOP_PATHCONF
, VOP_POLL
,
VOP_PRINT
, VOP_READ
,
VOP_READDIR
, VOP_READLINK
,
VOP_RECLAIM
, VOP_REMOVE
,
VOP_RENAME
, VOP_REVOKE
,
VOP_RMDIR
, VOP_SETATTR
,
VOP_STRATEGY
, VOP_SYMLINK
,
VOP_UNLOCK
, VOP_WRITE
— vnode operations
#include
<sys/vnode.h>
int
VOP_ABORTOP
(struct vnode *dvp,
struct componentname *cnp);
int
VOP_ACCESS
(struct vnode *vp,
int mode, struct ucred *cred,
struct proc *p);
int
VOP_ADVLOCK
(struct vnode *vp,
void *id, int op,
struct flock *fl, int
flags);
int
VOP_BMAP
(struct vnode *vp,
daddr_t bn, struct vnode **vpp,
daddr_t *bnp, int *runp);
int
VOP_BWRITE
(struct buf *bp);
int
VOP_CLOSE
(struct vnode *vp,
int fflag, struct ucred *cred,
struct proc *p);
int
VOP_CREATE
(struct vnode *dvp,
struct vnode **vpp, struct
componentname *cnp, struct vattr *vap);
int
VOP_FSYNC
(struct vnode *vp,
struct ucred *cred, int waitfor,
struct proc *p);
int
VOP_GETATTR
(struct vnode *vp,
struct vattr *vap, struct ucred
*cred, struct proc *p);
int
VOP_INACTIVE
(struct vnode *vp,
struct proc *p);
int
VOP_IOCTL
(struct vnode *vp,
u_long command, void *data,
int fflag, struct ucred *cred,
struct proc *p);
int
VOP_ISLOCKED
(struct vnode
*vp);
int
VOP_KQFILTER
(struct vnode *vp,
struct knote *kn);
int
VOP_LINK
(struct vnode *dvp,
struct vnode *vp, struct componentname
*cnp);
int
VOP_LOCK
(struct vnode *vp,
int flags);
int
VOP_LOOKUP
(struct vnode *dvp,
struct vnode **vpp, struct
componentname *cnp);
int
VOP_MKDIR
(struct vnode *dvp,
struct vnode **vpp, struct
componentname *cnp, struct vattr *vap);
int
VOP_MKNOD
(struct vnode *dvp,
struct vnode **vpp, struct
componentname *cnp, struct vattr *vap);
int
VOP_OPEN
(struct vnode *vp,
int mode, struct ucred *cred,
struct proc *p);
int
VOP_PATHCONF
(struct vnode *vp,
int name, register_t
*retval);
int
VOP_POLL
(struct vnode *vp,
int fflag, int events,
struct proc *p);
int
VOP_PRINT
(struct vnode *vp);
int
VOP_READ
(struct vnode *vp,
struct uio *uio, int ioflag,
struct ucred *cred);
int
VOP_READDIR
(struct vnode *vp,
struct uio *uio, struct ucred
*cred, int *eofflag);
int
VOP_READLINK
(struct vnode *vp,
struct uio *uio, struct ucred
*cred);
int
VOP_RECLAIM
(struct vnode *vp,
struct proc *p);
int
VOP_REMOVE
(struct vnode *dvp,
struct vnode *vp, struct componentname
*cnp);
int
VOP_RENAME
(struct vnode *fdvp,
struct vnode *fvp, struct
componentname *fcnp, struct vnode *tdvp,
struct vnode *tvp, struct
componentname *tcnp);
int
VOP_REVOKE
(struct vnode *vp,
int flags);
int
VOP_RMDIR
(struct vnode *dvp,
struct vnode *vp, struct componentname
*cnp);
int
VOP_SETATTR
(struct vnode *vp,
struct vattr *vap, struct ucred
*cred, struct proc *p);
int
VOP_STRATEGY
(struct buf
*bp);
int
VOP_SYMLINK
(struct vnode *dvp,
struct vnode **vpp, struct
componentname *cnp, struct vattr *vap,
char *target);
int
VOP_UNLOCK
(struct vnode
*vp);
int
VOP_WRITE
(struct vnode *vp,
struct uio *uio, int ioflag,
struct ucred *cred);
The VOP
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
system calls map directly to a specific VOP function.
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. 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.
The vattr structure used by
VOP_CREATE
(),
VOP_GETATTR
(), VOP_MKDIR
(),
VOP_MKNOD
(), VOP_SETATTR
(),
and VOP_SYMLINK
() is:
struct vattr { enum vtype va_type; /* vnode type */ mode_t va_mode; /* files access mode and type */ nlink_t va_nlink; /* number of references */ uid_t va_uid; /* owner user id */ gid_t va_gid; /* owner group id */ long va_fsid; /* file system id */ u_quad_t va_fileid; /* file id */ u_quad_t va_size; /* file size in bytes */ long va_blocksize; /* blocksize preferred for i/o */ struct timespec va_atime; /* time of last access */ struct timespec va_mtime; /* time of last modification */ struct timespec va_ctime; /* time file changed */ u_long va_gen; /* generation number of file */ u_long va_flags; /* flags defined for file */ dev_t va_rdev; /* device the vnode represents */ u_quad_t va_bytes; /* bytes of held disk space */ u_quad_t va_filerev; /* file modification number */ u_int va_vaflags; /* operations flags */ long va_spare; /* remain quad aligned */ };
The following sections comment on the VOP functions from the consumer's perspective.
VOP_ABORTOP
(dvp,
cnp)VOP_ACCESS
(vp,
mode, cred,
p)mode may contain any of the following values:
If the access check succeeds, zero is returned; otherwise, an appropriate error code is returned.
VOP_ADVLOCK
(vp,
id, op,
fl, flags)op may be one of the following operations:
flags may contain the following flags:
Upon success, zero is returned; otherwise, an appropriate error code is returned.
VOP_BMAP
(vp,
bn, vpp,
bnp, runp)NULL
, will be updated
to point to the vnode of the block device of which
vp is associated. runp, if
non-NULL
, will be updated
to the number of contiguous disk blocks following
*bnp. Upon success, zero is returned; otherwise, an
appropriate error code is returned.
VOP_BWRITE
(bp)VOP_CLOSE
(vp,
fflag, cred,
p)VOP_CREATE
(dvp,
vpp, cnp,
vap)VOP_FSYNC
(vp,
cred, waitfor,
p)MNT_WAIT
to indicate that
VOP_FSYNC
() should not return until all data is
written.
VOP_GETATTR
(vp,
vap, cred,
p)VOP_SETATTR
(vp,
vap, cred,
p)VOP_SETATTR
() requires that
vp be locked. A field value for any member of
vap of VNOVAL
represents
that the information could not be obtained by
VOP_GETATTR
() or should not be changed by
VOP_SETATTR
(). Upon success of obtaining or
changing the attributes, zero is returned; otherwise, an appropriate error
code is returned. All attributes are held in the
vattr structure shown above.
VOP_INACTIVE
(vp,
p)Typically, the underlying file system will write any buffers associated with vp to disk or delete the file entry, if need be. The underlying file system may not necessarily release any buffers associated with vp so that it can be immediately reactivated in case the file is used again. Upon success, zero is returned; otherwise, an appropriate error code is returned.
VOP_IOCTL
(vp,
command, data,
fflag, cred,
p)VOP_ISLOCKED
(vp)VOP_LOCK
(vp,
flags)VOP_UNLOCK
(vp)VOP_LOCK
() is used internally by
vn_lock(9) to lock a vnode. It should
not be used by other file system code.
VOP_UNLOCK
() unlocks a vnode. Note the asymmetry
between vn_lock(9) and
VOP_UNLOCK
().
flags may contain the following flags:
LK_EXCLUSIVE
LK_SHARED
LK_NOWAIT
LK_RECURSEFAIL
LK_DRAIN
VOP_ISLOCKED
()
returns one of the following values:
LK_EXCLUSIVE
LK_EXCLOTHER
LK_SHARED
VOP_ISLOCKED
()
should be used cautiously, as not all file systems implement locks
effectively.
VOP_KQFILTER
(vp,
kn)EVFILT_READ
, EVFILT_WRITE
,
and EVFILT_VNODE
will invoke this operation. Upon
success, zero is returned; otherwise, a non-zero value is returned.
VOP_LINK
(dvp,
vp, cnp)VOP_LOOKUP
(dvp,
vpp, cnp)NULL
and
cnp->cn_flags will be set to
PDIRUNLOCK
if dvp has been
unlocked.
VOP_MKDIR
(dvp,
vpp, cnp,
vap)VOP_MKNOD
(dvp,
vpp, cnp,
vap)NULL
. Upon
success, zero is returned; otherwise, an appropriate error code is
returned.
VOP_OPEN
(vp,
mode, cred,
p)For some underlying file systems, access permissions for the file by the process are checked; for others, this is a no-op. In any case, this must be called before a process can access the file. Upon success, zero is returned; otherwise, an appropriate error code is returned.
VOP_PATHCONF
(vp,
name, retval)VOP_POLL
(vp,
fflag, events,
p)selrecord
()
routine may be used to detect selection collisions for multiple processes
sleeping on the same file, waiting for I/O to become possible, although
all file systems currently assume that I/O is always possible. The return
value specifies which operations from events were
found to be ready, which may be performed without the need for blocking.
VOP_PRINT
(vp)VOP_READ
(vp,
uio, ioflag,
cred)ioflag may contain the following flags:
Upon success, zero is returned; otherwise, an appropriate error code is returned.
VOP_READDIR
(vp,
uio, cred,
eofflag)VOP_READ
(),
and convert its file-system-specific format to that expected by the
getdents(2) system call, storing the
result into the buffers specified by uio.
cred specifies the credentials of the calling
process. *eofflag is set to a non-zero value on
return once successful end-of-file for the directory contents has been
reached.
Upon success, zero is returned; otherwise, an appropriate error code is returned.
VOP_READLINK
(vp,
uio, cred)VOP_RECLAIM
(vp,
p)VOP_RECLAIM
() should
not be used by generic code.
VOP_REMOVE
(dvp,
vp, cnp)VOP_REMOVE
() does not delete the file from disk
unless its link count becomes zero (for file systems which support
multiple links).
VOP_RENAME
(fdvp,
fvp, fcnp,
tdvp, tvp,
tcnp)NULL
) will be released (see
vrele(9)) and tdvp
will have its reference count decremented (see
vput(9)) on return. If not
NULL
, tvp will be unlocked
on return (see vput(9)). Upon success,
zero is returned; otherwise, an appropriate error code is returned.
VOP_REVOKE
(vp,
flags)VOP_RMDIR
(dvp,
vp, cnp)VOP_STRATEGY
(bp)VOP_SYMLINK
(dvp,
vpp, cnp,
vap, target)VOP_SYMLINK
() does not lock or reference
vpp.
VOP_WRITE
(vp,
uio, ioflag,
cred)ioflag may contain the following flags:
Upon success, zero is returned; otherwise, an appropriate error code is returned.
The VOP
functions return 0 to indicate
success and a non-zero error code to indicate failure.
This man page was written by Ted Unangst for OpenBSD.
The locking discipline is too complex. Refer to vn_lock(9).
October 6, 2018 | OpenBSD-current |