vnsubr, vn_bwrite, vn_close, vn_closefile, vn_default_error, vn_fcntl,
vn_ioctl, vn_isunder, vn_lock, vn_markexec, vn_setrecurse,
vn_restorerecurse, vn_open, vn_read, vn_poll, vn_stat, vn_write,
vn_writechk - high-level convenience functions for vnode operations
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/vnode.h>
int
vn_bwrite(void *ap);
int
vn_close(struct vnode *vp, int flags, struct ucred *cred,
struct proc *p);
int
vn_closefile(struct file *fp, struct proc *p);
int
vn_default_error(void *v);
int
vn_fcntl(struct file *fp, u_int com, caddr_t data, struct proc *p);
int
vn_ioctl(struct file *fp, u_long com, caddr_t data, struct proc *p);
int
vn_isunder(struct vnode *dvp, struct vnode *rvp, struct proc *p);
int
vn_lock(struct vnode *vp, int flags);
void
vn_markexec(struct vnode *vp);
u_int
vn_setrecurse(struct vnode *vp);
void
vn_restorerecurse(struct vnode *vp, u_int flags);
int
vn_open(struct nameidata *ndp, int fmode, int cmode);
int
vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, int len,
off_t offset, enum uio_seg segflg, int ioflg, struct ucred *cred,
size_t *aresid, struct proc *p);
int
vn_read(struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags);
int
vn_readdir(struct file *fp, char *buf, int segflg, u_int count,
int *done, struct proc *p, off_t **cookies, int *ncookies);
int
vn_poll(struct file *fp, int events, struct proc *p);
int
vn_stat(void *fdata, struct stat *sb, struct proc *p);
int
vn_write(struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags);
int
vn_writechk(struct vnode *vp);
The high-level functions described in this page are convenience functions
for simplied access to the vnode operations described in vnodeops(9).
vn_bwrite(ap)
Common code for block write operations.
vn_close(vp, flags, cred, p)
Common code for a vnode close. The argument vp is the locked
vnode of the vnode to close. vn_close() simply locks the vnode,
invokes the vnode operation VOP_CLOSE(9) and calls vput() to
return the vnode to the freelist or holdlist. Note that
vn_close() expects an unlocked, referenced vnode and will dereference
the vnode prior to returning. If the operation is successful
zero is returned, otherwise an appropriate error is
returned.
vn_closefile(fp, p)
Common code for a file table vnode close operation. The file is
described by fp and p is the calling process. vn_closefile()
simply calls vn_close() with the appropriate arguments.
vn_default_error(v)
A generic "default" routine that just returns error. It is used
by a file system to specify unsupported operations in the vnode
operations vector.
vn_fcntl(fp, com, data, p)
Common code for a file table vnode fcntl(2) operation. The file
is specified by fp. The argument p is the calling process.
vn_fcntl() simply locks the vnode and invokes the vnode operation
VOP_FCNTL(9) with the command com and buffer data. The
vnode is unlocked on return. If the operation is successful
zero is returned, otherwise an appropriate error is returned.
vn_ioctl(fp, com, data, p)
Common code for a file table vnode ioctl operation. The file is
specified by fp. The argument p is the calling process.
vn_ioctl() simply locks the vnode and invokes the vnode operation
VOP_IOCTL(9) with the command com and buffer data. The
vnode is unlocked on return. If the operation is successful
zero is returned, otherwise an appropriate error is returned.
vn_isunder(dvp, rvp, p)
Common code to check if one directory specified by the vnode rvp
can be found inside the directory specified by the vnode dvp.
The argument p is the calling process. vn_isunder() is intended
to be used in chroot(2), chdir(2), fchdir(2), etc., to ensure
that chroot(2) actually means something. If the operation is
successful zero is returned, otherwise 1 is returned.
vn_lock(vp, flags)
Common code to acquire the lock for vnode vp. The argument
flags specifies the lockmgr(9) flags used to lock the vnode. If
the operation is successful zero is returned, otherwise an
appropriate error code is returned. The vnode interlock
v_interlock is releases on return.
vn_lock() must not be called when the vnode's reference count is
zero. Instead, vget(9) should be used.
vn_markexec(vp)
Common code to mark the vnode vp as containing executable code
of a running process.
vn_setrecurse(vp)
Common code to enable LK_CANRECURSE on the vnode lock for vnode
vp. vn_setrecurse() returns the new lockmgr(9) flags after the
update.
vn_restorerecurse(vp, flags)
Common code to restore the vnode lock flags for the vnode vp.
It is called when done with vn_setrecurse().
vn_open(ndp, fmode, cmode)
Common code for vnode open operations. The pathname is
described in the nameidata pointer (see namei(9)). The arguments
fmode and cmode specify the open(2) file mode and the
access permissions for creation. vn_open() checks permissions
and invokes the VOP_OPEN(9) or VOP_CREATE(9) vnode operations.
If the operation is successful zero is returned, otherwise an
appropriate error code is returned.
vn_rdwr( Common code to package up an I/O request on a vnode
into a uio and then perform the I/O. The argument rw specifies
whether the I/O is a read (UIO_READ) or write (UIO_WRITE) operation.
The unlocked vnode is specified by vp. The arguments p
and cred are the calling process and its credentials. The
remaining arguments specify the uio parameters. For further
information on these parameters see uiomove(9).
vn_read(fp, offset, uio, cred, flags)
Common code for a file table vnode read. The argument fp is the
file structure, The argument offset is the offset into the
file. The argument uio is the uio structure describing the memory
to read into. The caller's credentials are specified in
cred. The flags argument can define FOF_UPDATE_OFFSET to update
the read position in the file. If the operation is successful
zero is returned, otherwise an appropriate error is returned.
vn_readdir( Common code for reading the contents of a directory.
The argument fp is the file structure, buf is the buffer for
placing the struct dirent structures. The arguments cookies and
ncookies specify the addresses for the list and number of directory
seek cookies generated for NFS. Both cookies and ncookies
should be NULL is they aren't required to be returned by
vn_readdir(). If the operation is successful zero is returned,
otherwise an appropriate error code is returned.
vn_poll(fp, events, p)
Common code for a file table vnode poll operation. vn_poll()
simply calls VOP_POLL(9) with the events events and the calling
process p. If the operation is success zero is returned, otherwise
an appropriate error code is returned.
vn_stat(fdata, sb, p)
Common code for a vnode stat operation. The vnode is specified
by the argument fdata and sb is the buffer to return the stat
information. The argument p is the calling process. vn_stat()
basically calls the vnode operation VOP_GETATTR(9) and transfer
the contents of a vattr structure into a struct stat. If the
operation is successful zero is returned, otherwise an appropriate
error code is returned.
vn_write(fp, offset, uio, cred, flags)
Common code for a file table vnode write. The argument fp is
the file structure, The argument offset is the offset into the
file. The argument uio is the uio structure describing the memory
to read from. The caller's credentials are specified in
cred. The flags argument can define FOF_UPDATE_OFFSET to update
the read position in the file. If the operation is successful
zero is returned, otherwise an appropriate error is returned.
vn_writechk(vp)
Common code to check for write permission on the vnode vp. A
vnode is read-only if it is in use as a process's text image.
If the vnode is read-only ETEXTBSY is returned, otherwise zero
is returned to indicate that the vnode can be written to.
[ETXTBSY] Cannot write to a vnode since is a process's text
image.
[ENOENT] The vnode has been reclaimed and is dead. This error
is only returned if the LK_RETRY flag is not passed to
vn_lock().
[EBUSY] The LK_NOWAIT flag was set and vn_lock() would have
slept.
This section describes places within the NetBSD source tree where actual
code implementing or utilising the vnode framework can be found. All
pathnames are relative to /usr/src.
The high-level convenience functions are implemented within the file
sys/kern/vfs_vnops.c.
intro(9), lock(9), namei(9), vattr(9), vfs(9), vnode(9), vnodeops(9)
BSD October 22, 2001 BSD
[ Back ] |