p l -tag -offset indent -width LK_EXCLUSIVE -compact t LK_SHARED shared lock t LK_EXCLUSIVE exclusive lock t LK_NOWAIT do not sleep to await lock t LK_RETRY allow lock operation on dead vnode .El
p If the operation is successful zero is returned, otherwise an appropriate error code is returned.
p .Fn vn_lock must not be called when the vnode's reference count is zero. t Fn vn_markexec "vp" Common code to mark the vnode .Fa vp as containing executable code of a running process. t Fn vn_marktext "vp" Common code to mark the vnode .Fa vp as being the text of a running process. t Fn vn_open "at_dvp" "pb" "nmode" "fmode" "cmode" "ret_vp" "ret_domove" "ret_fd" Common code for vnode open operations. The .Fa at_dvp argument, if not NULL, provides the directory relative paths start from, as per .Xr openat 2 . The .Fa pb argument gives the pathname. The arguments .Fa nmode , .Fa fmode and .Fa cmode specify additional .Xr namei 9 flags, the .Xr open 2 flags (converted to .Dv F* from .Dv O_* form) and the access mode (permissions) for creation, respectively. The .Fa nmode argument is restricted to one or perhaps both of the flags .Dv TRYEMULROOT and .Dv NOCHROOT . Other .Xr name 9 modes should be selected via .Fn fmode . The .Fa ret_vp , .Fa ret_domove , and .Fa ret_fd arguments encode the possible return values. When called, .Fn vn_open checks permissions and invokes the .Xr VOP_OPEN 9 or .Xr VOP_CREATE 9 vnode operations. If the operation is unsuccessful an appropriate error code is returned. Otherwise, zero is returned. If a vnode is produced, it is returned locked via .Fa ret_vp . If a file descriptor number is produced instead, the pointer passed via .Fa ret_vp is NULL, the file descriptor is returned via .Fa ret_fd , and the .Fa ret_domove returns a value that is true if the file descriptor should be moved rather than copied. These cases correspond to the internal errors .Dv EMOVEFD and .Dv EDUPFD respectively. See .Xr errno 9 for further information. Callers unprepared to handle file descriptors can set .Fa ret_fd and .Fa ret_domove to NULL, in which case an operation that would produce a file descriptor will instead fail with .Dv EOPNOTSUPP . t Fn vn_bdev_open "dev" "vpp" "l" Opens a block device by its device number for reading and writing, and stores the vnode pointer into .Fa *vpp . The argument .Fa l is the calling process. The vnode can be closed and freed with .Fa vn_close . t Fn vn_bdev_openpath "pb" "vpp" "l" Works like .Fn vn_bdev_open but looks up a file system path .Fa pb to determine the device ID. t Fn vn_rdwr "rw" "vp" "base" "len" "offset" "segflg" "ioflg" "cred" "aresid" "l" Common code to package up an I/O request on a vnode into a uio and then perform the I/O. The argument .Fa rw specifies whether the I/O is a read .Dv ( UIO_READ ) or write .Dv ( UIO_WRITE ) operation. The vnode is specified by .Fa vp . The arguments .Fa l and .Fa cred are the calling lwp and its credentials. If .Fa ioflg contains .Dv IO_NODELOCKED , it is expected that the vnode is locked. .Fa ioflg will be passed to .Fn VOP_READ Ns No / Ns Fn VOP_WRITE . The remaining arguments specify the uio parameters. For further information on these parameters see .Xr uiomove 9 . t Fn vn_readdir "fp" "buf" "segflg" "count" "done" "l" "cookies" "ncookies" Common code for reading the contents of a directory. The argument .Fa fp is the file structure, .Fa buf is the buffer for placing the struct dirent structures. The arguments .Fa cookies and .Fa ncookies specify the addresses for the list and number of directory seek cookies generated for NFS. Both .Fa cookies and .Fa ncookies should be .Dv NULL if they aren't required to be returned by .Fn vn_readdir . If the operation is successful zero is returned, otherwise an appropriate error code is returned. t Fn vn_stat "vp" "sb" Common code for a vnode stat operation. The vnode is specified by the argument .Fa vp , and .Fa sb is the buffer to return the stat information. .Fn vn_stat basically calls the vnode operation .Xr VOP_GETATTR 9 and transfers 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. t Fn vn_writechk "vp" Common code to check for write permission on the vnode .Fa 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. .El .Sh ERRORS l -tag -width Er t Bq Er EBUSY The LK_NOWAIT flag was set and .Fn vn_lock would have slept. t Bq Er ENOENT The vnode has been reclaimed and is dead. This error is only returned if the LK_RETRY flag is not passed to .Fn vn_lock . t Bq Er ETXTBSY Cannot write to a vnode since is a process's text image. .El .Sh CODE REFERENCES The high-level convenience functions are implemented within the files
a sys/kern/vfs_vnops.c and
a sys/sys/vnode.h . .Sh SEE ALSO .Xr file 9 , .Xr intro 9 , .Xr lock 9 , .Xr namei 9 , .Xr vattr 9 , .Xr vfs 9 , .Xr vnode 9 , .Xr vnodeops 9