#include <sys/param.h>
#include <sys/systm.h>
#include <sys/syslimits.h>
#include <sys/time.h>
#include <sys/namei.h>
#include <sys/vm.h>
#include <sys/vnode_internal.h>
#include <sys/mount_internal.h>
#include <sys/errno.h>
#include <sys/malloc.h>
#include <sys/filedesc.h>
#include <sys/proc_internal.h>
#include <sys/kdebug.h>
#include <sys/unistd.h>
#include <sys/uio_internal.h>
#include <sys/kauth.h>
#include <bsm/audit_kernel.h>
#if CONFIG_MACF
#include <security/mac_framework.h>
#endif
#if NAMEDRSRCFORK
#include <sys/xattr.h>
#endif
#define VOLFS_MIN_PATH_LEN 9
static void kdebug_lookup(struct vnode *dp, struct componentname *cnp);
#if CONFIG_VOLFS
static int vfs_getrealpath(const char * path, char * realpath, size_t bufsize, vfs_context_t ctx);
#endif
int
namei(struct nameidata *ndp)
{
struct filedesc *fdp;
char *cp;
struct vnode *dp;
uio_t auio;
int error;
struct componentname *cnp = &ndp->ni_cnd;
vfs_context_t ctx = cnp->cn_context;
proc_t p = vfs_context_proc(ctx);
uthread_t ut = (struct uthread *)get_bsdthread_info(current_thread());
char *tmppn;
char uio_buf[ UIO_SIZEOF(1) ];
#if DIAGNOSTIC
if (!vfs_context_ucred(ctx) || !p)
panic ("namei: bad cred/proc");
if (cnp->cn_nameiop & (~OPMASK))
panic ("namei: nameiop contaminated with flags");
if (cnp->cn_flags & OPMASK)
panic ("namei: flags contaminated with nameiops");
#endif
fdp = p->p_fd;
if ((cnp->cn_flags & HASBUF) == 0) {
cnp->cn_pnbuf = ndp->ni_pathbuf;
cnp->cn_pnlen = PATHBUFLEN;
}
#if LP64_DEBUG
if (IS_VALID_UIO_SEGFLG(ndp->ni_segflg) == 0) {
panic("%s :%d - invalid ni_segflg\n", __FILE__, __LINE__);
}
#endif
retry_copy:
if (UIO_SEG_IS_USER_SPACE(ndp->ni_segflg)) {
error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf,
cnp->cn_pnlen, (size_t *)&ndp->ni_pathlen);
} else {
error = copystr(CAST_DOWN(void *, ndp->ni_dirp), cnp->cn_pnbuf,
cnp->cn_pnlen, (size_t *)&ndp->ni_pathlen);
}
if (error == ENAMETOOLONG && !(cnp->cn_flags & HASBUF)) {
MALLOC_ZONE(cnp->cn_pnbuf, caddr_t, MAXPATHLEN, M_NAMEI, M_WAITOK);
if (cnp->cn_pnbuf == NULL) {
error = ENOMEM;
goto error_out;
}
cnp->cn_flags |= HASBUF;
cnp->cn_pnlen = MAXPATHLEN;
goto retry_copy;
}
if (error)
goto error_out;
#if CONFIG_VOLFS
if (ndp->ni_pathlen >= VOLFS_MIN_PATH_LEN &&
cnp->cn_pnbuf[0] == '/' &&
cnp->cn_pnbuf[1] == '.' &&
cnp->cn_pnbuf[2] == 'v' &&
cnp->cn_pnbuf[3] == 'o' &&
cnp->cn_pnbuf[4] == 'l' &&
cnp->cn_pnbuf[5] == '/' ) {
char * realpath;
int realpath_err;
MALLOC_ZONE(realpath, caddr_t, MAXPATHLEN, M_NAMEI, M_WAITOK);
if (realpath) {
if ((realpath_err= vfs_getrealpath(&cnp->cn_pnbuf[6], realpath, MAXPATHLEN, ctx))) {
FREE_ZONE(realpath, MAXPATHLEN, M_NAMEI);
if (realpath_err == ENOSPC){
error = ENAMETOOLONG;
goto error_out;
}
} else {
if (cnp->cn_flags & HASBUF) {
FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
}
cnp->cn_pnbuf = realpath;
cnp->cn_pnlen = MAXPATHLEN;
ndp->ni_pathlen = strlen(realpath) + 1;
cnp->cn_flags |= HASBUF | CN_VOLFSPATH;
}
}
}
#endif
if (cnp->cn_flags & AUDITVNPATH1)
AUDIT_ARG(upath, ut->uu_cdir, cnp->cn_pnbuf, ARG_UPATH1);
if (cnp->cn_flags & AUDITVNPATH2)
AUDIT_ARG(upath, ut->uu_cdir, cnp->cn_pnbuf, ARG_UPATH2);
if (*cnp->cn_pnbuf == '\0') {
error = ENOENT;
goto error_out;
}
ndp->ni_loopcnt = 0;
if ((ndp->ni_rootdir = fdp->fd_rdir) == NULLVP) {
if ( !(fdp->fd_flags & FD_CHROOT))
ndp->ni_rootdir = rootvnode;
}
cnp->cn_nameptr = cnp->cn_pnbuf;
ndp->ni_usedvp = NULLVP;
if (*(cnp->cn_nameptr) == '/') {
while (*(cnp->cn_nameptr) == '/') {
cnp->cn_nameptr++;
ndp->ni_pathlen--;
}
dp = ndp->ni_rootdir;
} else if (cnp->cn_flags & USEDVP) {
dp = ndp->ni_dvp;
ndp->ni_usedvp = dp;
} else
dp = vfs_context_cwd(ctx);
if (dp == NULLVP || (dp->v_lflag & VL_DEAD)) {
error = ENOENT;
goto error_out;
}
ndp->ni_dvp = NULLVP;
ndp->ni_vp = NULLVP;
for (;;) {
int need_newpathbuf;
int linklen;
ndp->ni_startdir = dp;
if ( (error = lookup(ndp)) ) {
goto error_out;
}
if ((cnp->cn_flags & ISSYMLINK) == 0) {
return (0);
}
if ((cnp->cn_flags & FSNODELOCKHELD)) {
cnp->cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(ndp->ni_dvp, NULL);
}
if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
error = ELOOP;
break;
}
#if CONFIG_MACF
if ((error = mac_vnode_check_readlink(ctx, ndp->ni_vp)) != 0)
break;
#endif
if (ndp->ni_pathlen > 1 || !(cnp->cn_flags & HASBUF))
need_newpathbuf = 1;
else
need_newpathbuf = 0;
if (need_newpathbuf) {
MALLOC_ZONE(cp, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
if (cp == NULL) {
error = ENOMEM;
break;
}
} else {
cp = cnp->cn_pnbuf;
}
auio = uio_createwithbuffer(1, 0, UIO_SYSSPACE, UIO_READ, &uio_buf[0], sizeof(uio_buf));
uio_addiov(auio, CAST_USER_ADDR_T(cp), MAXPATHLEN);
error = VNOP_READLINK(ndp->ni_vp, auio, ctx);
if (error) {
if (need_newpathbuf)
FREE_ZONE(cp, MAXPATHLEN, M_NAMEI);
break;
}
linklen = MAXPATHLEN - uio_resid(auio);
if (linklen + ndp->ni_pathlen > MAXPATHLEN) {
if (need_newpathbuf)
FREE_ZONE(cp, MAXPATHLEN, M_NAMEI);
error = ENAMETOOLONG;
break;
}
if (need_newpathbuf) {
long len = cnp->cn_pnlen;
tmppn = cnp->cn_pnbuf;
bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
cnp->cn_pnbuf = cp;
cnp->cn_pnlen = MAXPATHLEN;
if ( (cnp->cn_flags & HASBUF) )
FREE_ZONE(tmppn, len, M_NAMEI);
else
cnp->cn_flags |= HASBUF;
} else
cnp->cn_pnbuf[linklen] = '\0';
ndp->ni_pathlen += linklen;
cnp->cn_nameptr = cnp->cn_pnbuf;
dp = ndp->ni_dvp;
vnode_put(ndp->ni_vp);
vnode_put(ndp->ni_dvp);
ndp->ni_vp = NULLVP;
ndp->ni_dvp = NULLVP;
if (*(cnp->cn_nameptr) == '/') {
while (*(cnp->cn_nameptr) == '/') {
cnp->cn_nameptr++;
ndp->ni_pathlen--;
}
if ((dp = ndp->ni_rootdir) == NULLVP) {
error = ENOENT;
goto error_out;
}
}
}
if (ndp->ni_dvp)
vnode_put(ndp->ni_dvp);
if (ndp->ni_vp)
vnode_put(ndp->ni_vp);
error_out:
if ( (cnp->cn_flags & HASBUF) ) {
cnp->cn_flags &= ~HASBUF;
FREE_ZONE(cnp->cn_pnbuf, cnp->cn_pnlen, M_NAMEI);
}
cnp->cn_pnbuf = NULL;
ndp->ni_vp = NULLVP;
return (error);
}
int
lookup(struct nameidata *ndp)
{
char *cp;
vnode_t tdp;
vnode_t dp;
mount_t mp;
int docache = 1;
int wantparent;
int rdonly;
int trailing_slash = 0;
int dp_authorized = 0;
int error = 0;
struct componentname *cnp = &ndp->ni_cnd;
vfs_context_t ctx = cnp->cn_context;
int mounted_on_depth = 0;
int dont_cache_mp = 0;
vnode_t mounted_on_dp = NULLVP;
int current_mount_generation = 0;
int vbusyflags = 0;
int nc_generation = 0;
if (cnp->cn_flags & (NOCACHE | DOWHITEOUT)) {
if ((cnp->cn_flags & NOCACHE) || (cnp->cn_nameiop == DELETE))
docache = 0;
}
wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT);
rdonly = cnp->cn_flags & RDONLY;
cnp->cn_flags &= ~ISSYMLINK;
cnp->cn_consume = 0;
dp = ndp->ni_startdir;
ndp->ni_startdir = NULLVP;
if ((cnp->cn_flags & CN_NBMOUNTLOOK) != 0)
vbusyflags = LK_NOWAIT;
cp = cnp->cn_nameptr;
if (*cp == '\0') {
if ( (vnode_getwithref(dp)) ) {
dp = NULLVP;
error = ENOENT;
goto bad;
}
goto emptyname;
}
dirloop:
ndp->ni_vp = NULLVP;
if ( (error = cache_lookup_path(ndp, cnp, dp, ctx, &trailing_slash, &dp_authorized)) ) {
dp = NULLVP;
goto bad;
}
if ((cnp->cn_flags & ISLASTCN)) {
if (docache)
cnp->cn_flags |= MAKEENTRY;
} else
cnp->cn_flags |= MAKEENTRY;
dp = ndp->ni_dvp;
if (ndp->ni_vp != NULLVP) {
if (dp != NULLVP)
nc_generation = dp->v_nc_generation - 1;
goto returned_from_lookup_path;
}
if ( (cnp->cn_flags & ISDOTDOT) ) {
for (;;) {
if (dp == ndp->ni_rootdir || dp == rootvnode) {
ndp->ni_dvp = dp;
ndp->ni_vp = dp;
if ( (vnode_get(dp)) ) {
error = ENOENT;
goto bad;
}
goto nextname;
}
if ((dp->v_flag & VROOT) == 0 ||
(cnp->cn_flags & NOCROSSMOUNT))
break;
if (dp->v_mount == NULL) {
error = EBADF;
goto bad;
}
tdp = dp;
dp = tdp->v_mount->mnt_vnodecovered;
vnode_put(tdp);
if ( (vnode_getwithref(dp)) ) {
dp = NULLVP;
error = ENOENT;
goto bad;
}
ndp->ni_dvp = dp;
dp_authorized = 0;
}
}
unionlookup:
ndp->ni_vp = NULLVP;
if (dp->v_type != VDIR) {
error = ENOTDIR;
goto lookup_error;
}
if ( (cnp->cn_flags & DONOTAUTH) != DONOTAUTH ) {
if (!dp_authorized) {
error = vnode_authorize(dp, NULL, KAUTH_VNODE_SEARCH, ctx);
if (error)
goto lookup_error;
}
#if CONFIG_MACF
error = mac_vnode_check_lookup(ctx, dp, cnp);
if (error)
goto lookup_error;
#endif
}
nc_generation = dp->v_nc_generation;
if ( (error = VNOP_LOOKUP(dp, &ndp->ni_vp, cnp, ctx)) ) {
lookup_error:
if ((error == ENOENT) &&
(dp->v_flag & VROOT) && (dp->v_mount != NULL) &&
(dp->v_mount->mnt_flag & MNT_UNION)) {
if ((cnp->cn_flags & FSNODELOCKHELD)) {
cnp->cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(dp, NULL);
}
tdp = dp;
dp = tdp->v_mount->mnt_vnodecovered;
vnode_put(tdp);
if ( (vnode_getwithref(dp)) ) {
dp = NULLVP;
error = ENOENT;
goto bad;
}
ndp->ni_dvp = dp;
dp_authorized = 0;
goto unionlookup;
}
if (error != EJUSTRETURN)
goto bad;
if (ndp->ni_vp != NULLVP)
panic("leaf should be empty");
if (rdonly) {
error = EROFS;
goto bad;
}
if ((cnp->cn_flags & ISLASTCN) && trailing_slash && !(cnp->cn_flags & WILLBEDIR)) {
error = ENOENT;
goto bad;
}
if (cnp->cn_flags & SAVESTART) {
if ( (vnode_get(ndp->ni_dvp)) ) {
error = ENOENT;
goto bad;
}
ndp->ni_startdir = ndp->ni_dvp;
}
if (!wantparent)
vnode_put(ndp->ni_dvp);
if (kdebug_enable)
kdebug_lookup(ndp->ni_dvp, cnp);
return (0);
}
returned_from_lookup_path:
dp = ndp->ni_vp;
if (cnp->cn_consume > 0) {
cnp->cn_nameptr += cnp->cn_consume;
ndp->ni_next += cnp->cn_consume;
ndp->ni_pathlen -= cnp->cn_consume;
cnp->cn_consume = 0;
} else {
if (dp->v_name == NULL || dp->v_parent == NULLVP) {
int isdot_or_dotdot;
int update_flags = 0;
isdot_or_dotdot = (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') || (cnp->cn_flags & ISDOTDOT);
if (isdot_or_dotdot == 0) {
if (dp->v_name == NULL)
update_flags |= VNODE_UPDATE_NAME;
if (ndp->ni_dvp != NULLVP && dp->v_parent == NULLVP)
update_flags |= VNODE_UPDATE_PARENT;
if (update_flags)
vnode_update_identity(dp, ndp->ni_dvp, cnp->cn_nameptr, cnp->cn_namelen, cnp->cn_hash, update_flags);
}
}
if ( (cnp->cn_flags & MAKEENTRY) && (dp->v_flag & VNCACHEABLE) && LIST_FIRST(&dp->v_nclinks) == NULL) {
if (ndp->ni_dvp != NULLVP && (nc_generation == ndp->ni_dvp->v_nc_generation))
cache_enter_with_gen(ndp->ni_dvp, dp, cnp, nc_generation);
}
}
mounted_on_dp = dp;
mounted_on_depth = 0;
dont_cache_mp = 0;
current_mount_generation = mount_generation;
check_mounted_on:
if ((dp->v_type == VDIR) && dp->v_mountedhere &&
((cnp->cn_flags & NOCROSSMOUNT) == 0)) {
vnode_lock(dp);
if ((dp->v_type == VDIR) && (mp = dp->v_mountedhere)) {
struct uthread *uth = (struct uthread *)get_bsdthread_info(current_thread());
mp->mnt_crossref++;
vnode_unlock(dp);
if (vfs_busy(mp, vbusyflags)) {
mount_dropcrossref(mp, dp, 0);
if (vbusyflags == LK_NOWAIT) {
error = ENOENT;
goto bad2;
}
goto check_mounted_on;
}
if ((cnp->cn_flags & ISLASTCN) &&
(cnp->cn_nameiop != LOOKUP ||
(cnp->cn_flags & NOTRIGGER))) {
uth->uu_notrigger = 1;
dont_cache_mp = 1;
}
error = VFS_ROOT(mp, &tdp, ctx);
uth->uu_notrigger = 0;
mount_dropcrossref(mp, dp, 1);
dp = NULL;
vfs_unbusy(mp);
if (error) {
goto bad2;
}
ndp->ni_vp = dp = tdp;
mounted_on_depth++;
goto check_mounted_on;
}
vnode_unlock(dp);
}
#if CONFIG_MACF
if (vfs_flags(vnode_mount(dp)) & MNT_MULTILABEL) {
error = vnode_label(vnode_mount(dp), NULL, dp, NULL,
VNODE_LABEL_NEEDREF, ctx);
if (error)
goto bad2;
}
#endif
if (mounted_on_depth && !dont_cache_mp) {
mp = mounted_on_dp->v_mountedhere;
if (mp) {
mount_lock(mp);
mp->mnt_realrootvp_vid = dp->v_id;
mp->mnt_realrootvp = dp;
mp->mnt_generation = current_mount_generation;
mount_unlock(mp);
}
}
if ((dp->v_type == VLNK) &&
((cnp->cn_flags & FOLLOW) || trailing_slash || *ndp->ni_next == '/')) {
cnp->cn_flags |= ISSYMLINK;
return (0);
}
if (trailing_slash) {
if (dp->v_type != VDIR) {
error = ENOTDIR;
goto bad2;
}
trailing_slash = 0;
}
nextname:
if (*ndp->ni_next == '/') {
cnp->cn_nameptr = ndp->ni_next + 1;
ndp->ni_pathlen--;
while (*cnp->cn_nameptr == '/') {
cnp->cn_nameptr++;
ndp->ni_pathlen--;
}
vnode_put(ndp->ni_dvp);
cp = cnp->cn_nameptr;
if (*cp == '\0')
goto emptyname;
vnode_put(dp);
goto dirloop;
}
if (rdonly &&
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
error = EROFS;
goto bad2;
}
if (cnp->cn_flags & SAVESTART) {
if ( (vnode_get(ndp->ni_dvp)) ) {
error = ENOENT;
goto bad2;
}
ndp->ni_startdir = ndp->ni_dvp;
}
if (!wantparent && ndp->ni_dvp) {
vnode_put(ndp->ni_dvp);
ndp->ni_dvp = NULLVP;
}
if (cnp->cn_flags & AUDITVNPATH1)
AUDIT_ARG(vnpath, dp, ARG_VNODE1);
else if (cnp->cn_flags & AUDITVNPATH2)
AUDIT_ARG(vnpath, dp, ARG_VNODE2);
#if NAMEDRSRCFORK
if ((cnp->cn_flags & CN_WANTSRSRCFORK) && (dp != NULLVP)) {
vnode_t svp = NULLVP;
enum nsoperation nsop;
if (dp->v_type != VREG) {
error = ENOENT;
goto bad2;
}
switch (cnp->cn_nameiop) {
case DELETE:
nsop = NS_DELETE;
break;
case CREATE:
nsop = NS_CREATE;
break;
case LOOKUP:
if (cnp->cn_flags & CN_ALLOWRSRCFORK) {
nsop = NS_OPEN;
} else {
error = EPERM;
goto bad2;
}
break;
default:
error = EPERM;
goto bad2;
}
error = vnode_getnamedstream(dp, &svp, XATTR_RESOURCEFORK_NAME, nsop, 0, ctx);
if (error == ENOATTR || error == ENOENT) {
error = (nsop == NS_CREATE) ? 0 : ENOENT;
}
if (error) {
goto bad2;
}
if (wantparent) {
if (ndp->ni_dvp) {
if (ndp->ni_cnd.cn_flags & FSNODELOCKHELD) {
ndp->ni_cnd.cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(ndp->ni_dvp, NULL);
}
vnode_put(ndp->ni_dvp);
}
ndp->ni_dvp = dp;
} else {
vnode_put(dp);
}
ndp->ni_vp = dp = svp;
if (ndp->ni_pathlen == 1 && ndp->ni_next[0] == '\0') {
ndp->ni_next[0] = '/';
}
cnp->cn_flags &= ~MAKEENTRY;
}
#endif
if (kdebug_enable)
kdebug_lookup(dp, cnp);
return (0);
emptyname:
cnp->cn_namelen = 0;
if (dp->v_type != VDIR) {
error = ENOTDIR;
goto bad;
}
if (cnp->cn_nameiop != LOOKUP) {
error = EISDIR;
goto bad;
}
if (wantparent) {
if ( (vnode_get(dp)) ) {
error = ENOENT;
goto bad;
}
ndp->ni_dvp = dp;
}
cnp->cn_flags &= ~ISDOTDOT;
cnp->cn_flags |= ISLASTCN;
ndp->ni_next = cp;
ndp->ni_vp = dp;
if (cnp->cn_flags & AUDITVNPATH1)
AUDIT_ARG(vnpath, dp, ARG_VNODE1);
else if (cnp->cn_flags & AUDITVNPATH2)
AUDIT_ARG(vnpath, dp, ARG_VNODE2);
if (cnp->cn_flags & SAVESTART)
panic("lookup: SAVESTART");
return (0);
bad2:
if ((cnp->cn_flags & FSNODELOCKHELD)) {
cnp->cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(ndp->ni_dvp, NULL);
}
if (ndp->ni_dvp)
vnode_put(ndp->ni_dvp);
if (dp)
vnode_put(dp);
ndp->ni_vp = NULLVP;
if (kdebug_enable)
kdebug_lookup(dp, cnp);
return (error);
bad:
if ((cnp->cn_flags & FSNODELOCKHELD)) {
cnp->cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(ndp->ni_dvp, NULL);
}
if (dp)
vnode_put(dp);
ndp->ni_vp = NULLVP;
if (kdebug_enable)
kdebug_lookup(dp, cnp);
return (error);
}
int
relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
{
struct vnode *dp = NULL;
int wantparent;
int rdonly;
int error = 0;
#ifdef NAMEI_DIAGNOSTIC
int i, newhash;
char *cp;
#endif
vfs_context_t ctx = cnp->cn_context;;
wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT);
rdonly = cnp->cn_flags & RDONLY;
cnp->cn_flags &= ~ISSYMLINK;
if (cnp->cn_flags & NOCACHE)
cnp->cn_flags &= ~MAKEENTRY;
else
cnp->cn_flags |= MAKEENTRY;
dp = dvp;
if (cnp->cn_nameptr[0] == '\0') {
if (cnp->cn_nameiop != LOOKUP || wantparent) {
error = EISDIR;
goto bad;
}
if (dp->v_type != VDIR) {
error = ENOTDIR;
goto bad;
}
if ( (vnode_get(dp)) ) {
error = ENOENT;
goto bad;
}
*vpp = dp;
if (cnp->cn_flags & SAVESTART)
panic("lookup: SAVESTART");
return (0);
}
if ( (error = VNOP_LOOKUP(dp, vpp, cnp, ctx)) ) {
if (error != EJUSTRETURN)
goto bad;
#if DIAGNOSTIC
if (*vpp != NULL)
panic("leaf should be empty");
#endif
if (rdonly) {
error = EROFS;
goto bad;
}
return (0);
}
dp = *vpp;
#if DIAGNOSTIC
if (dp->v_type == VLNK && (cnp->cn_flags & FOLLOW))
panic ("relookup: symlink found.\n");
#endif
if (rdonly &&
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
error = EROFS;
goto bad2;
}
return (0);
bad2:
vnode_put(dp);
bad:
*vpp = NULL;
return (error);
}
void
nameidone(struct nameidata *ndp)
{
if ((ndp->ni_cnd.cn_flags & FSNODELOCKHELD)) {
ndp->ni_cnd.cn_flags &= ~FSNODELOCKHELD;
unlock_fsnode(ndp->ni_dvp, NULL);
}
if (ndp->ni_cnd.cn_flags & HASBUF) {
char *tmp = ndp->ni_cnd.cn_pnbuf;
ndp->ni_cnd.cn_pnbuf = NULL;
ndp->ni_cnd.cn_flags &= ~HASBUF;
FREE_ZONE(tmp, ndp->ni_cnd.cn_pnlen, M_NAMEI);
}
}
#define NUMPARMS 23
static void
kdebug_lookup(struct vnode *dp, struct componentname *cnp)
{
unsigned int i;
int code;
int dbg_namelen;
char *dbg_nameptr;
long dbg_parms[NUMPARMS];
dbg_namelen = (cnp->cn_nameptr - cnp->cn_pnbuf) + cnp->cn_namelen;
dbg_nameptr = cnp->cn_nameptr + cnp->cn_namelen;
if (dbg_namelen > (int)sizeof(dbg_parms))
dbg_namelen = sizeof(dbg_parms);
dbg_nameptr -= dbg_namelen;
memcpy(dbg_parms, dbg_nameptr, dbg_namelen);
if (dbg_namelen < (int)sizeof(dbg_parms)) {
memset((char *)dbg_parms + dbg_namelen,
*(cnp->cn_nameptr + cnp->cn_namelen) ? '>' : 0,
sizeof(dbg_parms) - dbg_namelen);
}
code = (FSDBG_CODE(DBG_FSRW,36)) | DBG_FUNC_START;
if (dbg_namelen <= 12)
code |= DBG_FUNC_END;
KERNEL_DEBUG_CONSTANT(code, (unsigned int)dp, dbg_parms[0], dbg_parms[1], dbg_parms[2], 0);
code &= ~DBG_FUNC_START;
for (i=3, dbg_namelen -= 12; dbg_namelen > 0; i+=4, dbg_namelen -= 16) {
if (dbg_namelen <= 16)
code |= DBG_FUNC_END;
KERNEL_DEBUG_CONSTANT(code, dbg_parms[i], dbg_parms[i+1], dbg_parms[i+2], dbg_parms[i+3], 0);
}
}
#if CONFIG_VOLFS
static int
vfs_getrealpath(const char * path, char * realpath, size_t bufsize, vfs_context_t ctx)
{
vnode_t vp;
struct mount *mp = NULL;
char *str;
char ch;
unsigned long id;
ino64_t ino;
int error;
int length;
id = strtoul(path, &str, 10);
if (id == 0 || str[0] != '/') {
return (EINVAL);
}
while (*str == '/') {
str++;
}
ch = *str;
mp = mount_lookupby_volfsid(id, 1);
if (mp == NULL) {
return (EINVAL);
}
if (ch == '@' && str[1] == '\0') {
ino = 2;
str++;
} else {
ino = strtouq(str, &str, 10);
}
if (ino == 2) {
error = VFS_ROOT(mp, &vp, ctx);
} else {
error = VFS_VGET(mp, ino, &vp, ctx);
}
vfs_unbusy(mp);
if (error) {
goto out;
}
realpath[0] = '\0';
error = build_path(vp, realpath, bufsize, &length, 0, ctx);
vnode_put(vp);
if (error == 0 && *str != '\0') {
int attempt = strlcat(realpath, str, MAXPATHLEN);
if (attempt > MAXPATHLEN){
error = ENAMETOOLONG;
}
}
out:
return (error);
}
#endif