VNODEOPS(9) | Kernel Developer's Manual | VNODEOPS(9) |
int
VOP_LOOKUP(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp);
int
VOP_CREATE(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, kauth_cred_t cred);
int
VOP_CLOSE(struct vnode *vp, int fflag, kauth_cred_t cred);
int
VOP_ACCESS(struct vnode *vp, int mode, kauth_cred_t cred);
int
VOP_GETATTR(struct vnode *vp, struct vattr *vap, kauth_cred_t cred);
int
VOP_SETATTR(struct vnode *vp, struct vattr *vap, kauth_cred_t cred);
int
VOP_READ(struct vnode *vp, struct uio *uio, int ioflag, kauth_cred_t cred);
int
VOP_WRITE(struct vnode *vp, struct uio *uio, int ioflag, kauth_cred_t cred);
int
VOP_IOCTL(struct vnode *vp, u_long command, void *data, int fflag, kauth_cred_t cred);
int
VOP_FCNTL(struct vnode *vp, u_int command, void *data, int fflag, kauth_cred_t cred);
int
VOP_POLL(struct vnode *vp, int events);
int
VOP_KQFILTER(struct vnode *vp, struct knote *kn);
int
VOP_REVOKE(struct vnode *vp, int flags);
int
VOP_MMAP(struct vnode *vp, vm_prot_t prot, kauth_cred_t cred);
int
VOP_FSYNC(struct vnode *vp, kauth_cred_t cred, int flags, off_t offlo, off_t offhi);
int
VOP_SEEK(struct vnode *vp, off_t oldoff, off_t newoff, kauth_cred_t cred);
int
VOP_REMOVE(struct vnode *vp, struct vnode *vp, struct componentname *cnp);
int
VOP_LINK(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_MKDIR(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct vattr *vap);
int
VOP_RMDIR(struct vnode *dvp, struct vnode *vp, struct componentname *cnp);
int
VOP_SYMLINK(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct vattr *vap, char *target);
int
VOP_READDIR(struct vnode *vp, struct uio *uio, kauth_cred_t cred, int *eofflag, off_t **cookies, int *ncookies);
int
VOP_READLINK(struct vnode *vp, struct uio *uio, kauth_cred_t cred);
int
VOP_ABORTOP(struct vnode *dvp, struct componentname *cnp);
int
VOP_INACTIVE(struct vnode *vp);
int
VOP_RECLAIM(struct vnode *vp);
int
VOP_LOCK(struct vnode *vp, int flags);
int
VOP_UNLOCK(struct vnode *vp);
int
VOP_ISLOCKED(struct vnode *vp);
int
VOP_BMAP(struct vnode *vp, daddr_t bn, struct vnode **vpp, daddr_t *bnp, int *runp);
int
VOP_PRINT(struct vnode *vp);
int
VOP_PATHCONF(struct vnode *vp, int name, register_t *retval);
int
VOP_ADVLOCK(struct vnode *vp, void *id, int op, struct flock *fl, int flags);
int
VOP_WHITEOUT(struct vnode *dvp, struct componentname *cnp, int flags);
int
VOP_GETPAGES(struct vnode *vp, voff_t offset, struct vm_page **m, int *count, int centeridx, vm_prot_t access_type, int advice, int flags);
int
VOP_PUTPAGES(struct vnode *vp, voff_t offlo, voff_t offhi, int flags);
int
VOP_STRATEGY(struct vnode *vp, struct buf *bp);
int
VOP_BWRITE(struct vnode *vp, struct buf *bp);
int
VOP_GETEXTATTR(struct vnode *vp, int attrnamespace, const char *name, struct uio *uio, size_t *size, kauth_cred_t cred);
int
VOP_SETEXTATTR(struct vnode *vp, int attrnamespace, const char *name, struct uio *uio, kauth_cred_t cred);
int
VOP_LISTEXTATTR(struct vnode *vp, int attrnamespace, struct uio *uio, size_t *size, kauth_cred_t cred);
int
VOP_DELETEEXTATTR(struct vnode *vp, int attrnamespace, const char *name, kauth_cred_t cred);
Not all header files are required for each function.
Functions in the vnode operations vector are invoked using specialized macros. The following table gives a summary of the operations.
Macro | Description |
VOP_LOOKUP | Lookup file name in name cache |
VOP_CREATE | Create a new file |
VOP_MKNOD | Make a new device |
VOP_OPEN | Open a file |
VOP_CLOSE | Close a file |
VOP_ACCESS | Determine file accessibility |
VOP_GETATTR | Get file attributes |
VOP_SETATTR | Set file attributes |
VOP_READ | Read from a file |
VOP_WRITE | Write to a file |
VOP_IOCTL | Perform device-specific I/O |
VOP_FCNTL | Perform file control |
VOP_POLL | Test if poll event has occurred |
VOP_KQFILTER | Register a knote |
VOP_REVOKE | Eliminate vode activity |
VOP_MMAP | Map file into user address space |
VOP_FSYNC | Flush pending data to disk |
VOP_SEEK | Test if file is seekable |
VOP_REMOVE | Remove a file |
VOP_LINK | Link a file |
VOP_RENAME | Rename a file |
VOP_MKDIR | Make a new directory |
VOP_RMDIR | Remove a directory |
VOP_SYMLINK | Create a symbolic link |
VOP_READDIR | Read directory entry |
VOP_READLINK | Read contents of a symlink |
VOP_ABORTOP | Abort pending operation |
VOP_INACTIVE | Release the inactive vnode |
VOP_RECLAIM | Reclaim vnode for another file |
VOP_LOCK | Sleep until vnode lock is free |
VOP_UNLOCK | Wake up process sleeping on lock |
VOP_ISLOCKED | Test if vnode is locked |
VOP_BMAP | Logical block number conversion |
VOP_PRINT | Print debugging information |
VOP_PATHCONF | Return POSIX pathconf data |
VOP_ADVLOCK | Advisory record locking |
VOP_WHITEOUT | Whiteout vnode |
VOP_GETPAGES | Read VM pages from file |
VOP_PUTPAGES | Write VM pages to file |
VOP_STRATEGY | Read/write a file system buffer |
VOP_BWRITE | Write a file system buffer |
VOP_GETEXTATTR | Get extended attribute |
VOP_SETEXTATTR | Set extended attribute |
VOP_LISTEXTATTR | List extended attributes |
VOP_DELETEEXTATTR | Remove extended attribute |
The implementation details of the vnode operations vector are not quite what is described here.
If the file system type does not support a specific operation, it must nevertheless assign an appropriate stub in the vnode operations vector to do the minimum required of it. In most cases, such functions either do nothing or return an error value to the effect that it is not supported.
Many of the functions in the vnode operations vector take a componentname structure. It is used to encapsulate many parameters into a single function argument. It has the following structure:
struct componentname { /* * Arguments to lookup. */ uint32_t cn_nameiop; /* namei operation */ uint32_t cn_flags; /* flags to namei */ kauth_cred_t cn_cred; /* credentials */ /* * Shared between lookup and commit routines. */ char *cn_pnbuf; /* pathname buffer */ const char *cn_nameptr; /* pointer to looked up name */ size_t cn_namelen; /* length of looked up component */ u_long cn_hash; /* hash value of looked up name */ size_t cn_consume; /* chars to consume in lookup() */ };
The top half of the structure is used exclusively for the pathname lookups using VOP_LOOKUP() and is initialized by the caller. The semantics of the lookup are affected by the lookup operation specified in cn_nameiop and the flags specified in cn_flags. Valid operations are:
Valid values for cn->cn_flags are:
No vnode operations may be called from interrupt context. Most operations also require the vnode to be locked on entry. To prevent deadlocks, when acquiring locks on multiple vnodes, the lock of parent directory must be acquired before the lock on the child directory.
Vnode operations for a file system type generally should not be called directly from the kernel, but accessed indirectly through the high-level convenience functions discussed in vnsubr(9).
There are three types of lookups: ".", ".." (ISDOTDOT), and regular. If the pathname component being searched for is ".", then dvp has an extra reference added to it and it is returned in *vpp. If the pathname component being search for is ".." (ISDOTDOT), dvp is unlocked, the ".." node is locked and then dvp is relocked. This process preserves the protocol of always locking nodes from root downward and prevents deadlock. For other pathname components, VOP_LOOKUP() checks the accessibility of the directory and searches the name cache for the pathname component. See namecache(9). If the pathname is not found in the name cache, the directory is searched for the pathname. The resulting locked vnode is returned in vpp. dvp is always returned locked.
On failure *vpp is NULL, and *dvp is left locked. If the operation is successful *vpp is locked and zero is returned. Typically, if *vpp and dvp are the same vnode the caller will need to release twice (decrement the reference count) and unlock once.
This function is called after VOP_LOOKUP() when a file is being created. Normally, VOP_LOOKUP() will have set the SAVENAME flag in cnp->cn_flags to keep the memory pointed to by cnp->cn_pnbuf valid. If an error is detected when creating the file, this memory is released. If the file is created successfully it will be released unless the SAVESTART flags in specified in cnp->cn_flags.
This function is called after VOP_LOOKUP() when a device-special file is being created. Normally, VOP_LOOKUP() will have set the SAVENAME flag in cnp->cn_flags to keep the memory pointed to by cnp->cn_pnbuf valid. If an error is detected when creating the device-special file, this memory is released. If the device-special file is created successfully it will be released unless the SAVESTART flags in specified in cnp->cn_flags.
VOP_OPEN() expects the vnode vp to be locked on entry and will leave it locked on return. If the operation is successful zero is returned, otherwise an appropriate error code is returned.
The vnode vp will be locked on entry and should remain locked on return.
The vnode vp will be locked on entry and should remain locked on return.
For more information on vnode attributes see vattr(9).
The vnode vp will be locked on entry and should remain locked on return.
For more information on vnode attributes see vattr(9).
The ioflag argument is used to give directives and hints to the file system. When attempting a read, the high 16 bits are used to provide a read-ahead hint (in unit of file system blocks) that the file system should attempt. The low 16 bits are a bit mask which can contain the following flags:
Zero is returned on success, otherwise an error is returned. The vnode should be locked on entry and remains locked on exit.
The ioflag argument is used to give directives and hints to the file system. The low 16 bits are a bit mask which can contain the same flags as VOP_READ().
Zero is returned on success, otherwise an error is returned. The vnode should be locked on entry and remains locked on exit.
Most file systems do not supply a function for VOP_IOCTL(). This function implements the ioctl(2) system call.
The vnode vp remains unlocked throughout the whole operation.
The vnode vp remains unlocked throughout the whole operation.
The vnode vp remains unlocked throughout the whole operation.
Most file systems do not supply a function for VOP_MMAP() and use genfs_mmap() to default for success. Only file systems which do not integrate with the page cache at all typically want to disallow memory mapping.
This function implements the sync(2) and fsync(2) system calls.
The source directory and file vnodes should be unlocked and their reference counts should be incremented before entry. The target directory and file vnodes should both be locked on entry. VOP_RENAME() updates the reference counts prior to returning.
This function is called after VOP_LOOKUP() when a directory is being created. Normally, VOP_LOOKUP() will have set the SAVENAME flag in cnp->cn_flags to keep the memory pointed to by cnp->cn_pnbuf valid. If an error is detected when creating the directory, this memory is released. If the directory is created successfully it will be released unless the SAVESTART flags in specified in cnp->cn_flags.
This function is called after VOP_LOOKUP() when a symbolic link is being created. Normally, VOP_LOOKUP() will have set the SAVENAME flag in cnp->cn_flags to keep the memory pointed to by cnp->cn_pnbuf valid. If an error is detected when creating the symbolic link, this memory is released. If the symbolic link is created successfully it will be released unless the SAVESTART flags in specified in cnp->cn_flags.
The directory should be locked on entry and will remain locked on return.
In case ncookies and cookies are supplied, one cookie should be returned per directory entry. The value of the cookie for each directory entry should be the offset within the directory where the on-disk version of the following directory entry starts. That is, for each directory entry i, the corresponding cookie should refer to the offset of directory entry i + 1.
Note that the cookies array must be allocated by the callee using the M_TEMP malloc type as callers of VOP_READDIR() must be able to free the allocation.
The vnode should be locked on entry and will remain locked on return.
This operation is rarely implemented in file systems and genfs_abortop() is typically used instead.
This function must never be used to make locking decisions at run time: it is provided only for diagnostic purposes.
If vpp is not NULL, the vnode of the device vnode for the file system is returned in the address specified by vpp. If runp is not NULL, the number of contiguous blocks starting from the next block after the queried block will be returned in runp.
If name is recognized, *retval is set to the specified value and zero is returned, otherwise an appropriate error is returned.
The argument fl is a description of the lock. In the case of SEEK_CUR, The caller should add the current file offset to fl->l_start beforehand. VOP_ADVLOCK() treats SEEK_CUR as SEEK_SET.
The argument flags is the set of flags. Valid values are:
If the operation is successful zero is returned, otherwise an appropriate error is returned.
The vnode dvp should be locked on entry and will remain locked on return.
This function is primarily used by the page-fault handing mechanism.
The function is primarily used by the pageout handling mechanism and is commonly implemented indirectly by genfs_putpages() with the help of VOP_STRATEGY() and VOP_BMAP().
The vnode vp should be locked on entry and will remain locked on return.
February 13, 2012 | NetBSD 6.1 |