VOP_LOOKUP(9) | Kernel Developer's Manual | VOP_LOOKUP(9) |
VOP_LOOKUP
—
lookup a component of a pathname
#include
<sys/param.h>
#include <sys/vnode.h>
#include <sys/namei.h>
int
VOP_LOOKUP
(struct
vnode *dvp, struct vnode
**vpp, struct
componentname *cnp);
This entry point looks up a single pathname component in a given directory.
Its arguments are:
struct componentname { /* * Arguments to lookup. */ u_long cn_nameiop; /* namei operation */ u_long cn_flags; /* flags to namei */ struct thread *cn_thread; /* thread requesting lookup */ struct ucred *cn_cred; /* credentials */ int cn_lkflags; /* Lock flags LK_EXCLUSIVE or LK_SHARED */ /* * Shared between lookup and commit routines. */ char *cn_pnbuf; /* pathname buffer */ char *cn_nameptr; /* pointer to looked up name */ long cn_namelen; /* length of looked up component */ };
Convert a component of a pathname into a pointer to a locked vnode. This is a very central and rather complicated routine. If the file system is not maintained in a strict tree hierarchy, this can result in a deadlock situation.
The cnp->cn_nameiop argument is
LOOKUP
, CREATE
,
RENAME
, or DELETE
depending on the intended use of the object. When
CREATE
, RENAME
, or
DELETE
is specified, information usable in
creating, renaming, or deleting a directory entry may be calculated.
Overall outline of VOP_LOOKUP:
notfound:
EJUSTRETURN
, leaving info on available
slots else return ENOENT
.found:
The directory dvp should be locked on entry and exit, regardless of error condition. If an entry is found in the directory, it will be returned locked.
Zero is returned with *vpp set to the locked vnode of the file if the component is found. If the component being searched for is ".", then the vnode just has an extra reference added to it with vref(9). The caller must take care to release the locks appropriately in this case.
If the component is not found and the operation is
CREATE
or RENAME
, the flag
ISLASTCN
is specified and the operation would
succeed, the special return value EJUSTRETURN
is
returned. Otherwise, an appropriate error code is returned.
ENOTDIR
]ENOENT
]EACCES
]EJUSTRETURN
]CREATE
or RENAME
operation would be successful.vnode(9), VOP_ACCESS(9), VOP_CREATE(9), VOP_MKDIR(9), VOP_MKNOD(9), VOP_RENAME(9), VOP_SYMLINK(9)
The function VOP_LOOKUP
appeared in
4.3BSD.
This manual page was written by Doug Rabson, with some text from comments in ufs_lookup.c.
August 8, 2018 | Debian |