NAMEI(9) | Kernel Developer's Manual | NAMEI(9) |
int
namei(struct nameidata *ndp);
int
lookup_for_nfsd(struct nameidata *ndp, struct vnode *startdir, int neverfollow);
int
lookup_for_nfsd_index(struct nameidata *ndp);
int
relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp);
void
NDINIT(struct nameidata *ndp, u_long op, u_long flags, struct pathbuf *pathbuf);
int
namei_simple_kernel(const char *path, namei_simple_flags_t sflags, struct vnode **ret);
int
namei_simple_user(const char *path, namei_simple_flags_t sflags, struct vnode **ret);
Except for the simple forms, the arguments passed to the functions are encapsulated in the nameidata structure. It has the following structure:
struct nameidata { /* * Arguments to namei/lookup. */ const char *ni_dirp; /* pathname pointer */ enum uio_seg ni_segflg; /* location of pathname */ /* * Arguments to lookup. */ struct vnode *ni_startdir; /* starting directory */ struct vnode *ni_rootdir; /* logical root directory */ /* * Results: returned from/manipulated by lookup */ struct vnode *ni_vp; /* vnode of result */ struct vnode *ni_dvp; /* vnode of intermediate dir */ /* * Shared between namei and lookup/commit routines. */ size_t ni_pathlen; /* remaining chars in path */ const char *ni_next; /* next location in pathname */ u_long ni_loopcnt; /* count of symlinks encountered */ /* * Lookup parameters */ struct componentname { /* * Arguments to lookup. */ u_long cn_nameiop; /* namei operation */ u_long 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 */ long cn_namelen; /* length of looked up component */ u_long cn_hash; /* hash value of looked up name */ long cn_consume; /* chars to consume in lookup() */ } ni_cnd; };
The namei interface accesses vnode operations by passing arguments in the partially initialised componentname structure ni_cnd. This structure describes the subset of information from the nameidata structure that is passed through to the vnode operations. See vnodeops(9) for more information. The details of the componentname structure are not absolutely necessary since the members are initialised by the helper macro NDINIT(). It is useful to know the operations and flags as specified in vnodeops(9).
The namei interface overloads ni_cnd.cn_flags with some additional flags. These flags should be specific to the namei interface and ignored by vnode operations. However, due to the historic close relationship between the namei interface and the vnode operations, these flags are sometimes used (and set) by vnode operations, particularly VOP_LOOKUP(). The additional flags are:
If the caller of namei() sets the SAVENAME flag, then it must free the buffer. If VOP_LOOKUP() sets the flag, then the buffer must be freed by either the commit routine or the VOP_ABORT() routine. The SAVESTART flag is set only by the callers of namei(). It implies SAVENAME plus the addition of saving the parent directory that contains the name in ni_startdir. It allows repeated calls to lookup() for the name being sought. The caller is responsible for releasing the buffer and for invoking vrele() on ni_startdir.
All access to the namei interface must be in process context. Pathname lookups cannot be done in interrupt context.
The vnode for the pathname is returned in ndp->ni_vp. The parent directory is returned locked in ndp->ni_dvp iff LOCKPARENT is specified.
If ndp->ni_cnd.cn_flags has the FOLLOW flag set then symbolic links are followed when they occur at the end of the name translation process. Symbolic links are always followed for all other pathname components other than the last.
Historically namei had a sub-function called lookup(). This function processed a pathname until either running out of material or encountering a symbolic link. namei worked by first setting up the start directory ndp->ni_startdir and then calling lookup() repeatedly.
The semantics of namei are altered by the operation specified by ndp->ni_cnd.cn_nameiop. When CREATE, RENAME, or DELETE is specified, information usable in creating, renaming, or deleting a directory entry may be calculated.
If the target of the pathname exists and LOCKLEAF is set, the target is returned locked in ndp->ni_vp, otherwise it is returned unlocked.
As of this writing the internal function do_lookup() is comparable to the historic lookup() but this code is slated for refactoring.
This routine stores the credentials of the calling thread (curlwp) in ndp. In the rare case that another set of credentials is required for the namei operation, ndp->ni_cnd.cn_cred must be set manually.
November 16, 2010 | NetBSD 6.1 |