FreeBSD/sys/fs/pseudofs/pseudofs_vnops.c
/*
 * Convert a vnode to its component name
 */
Convert a vnode to its component name
Convert a vnode to its component name
static int
pfs_vptocnp(struct vop_vptocnp_args *ap)
{
	struct vnode *vp = ap->a_vp;
	struct vnode **dvp = ap->a_vpp;
	struct pfs_vdata *pvd = vp->v_data;
	struct pfs_node *pd = pvd->pvd_pn;
	struct pfs_node *pn;
	struct mount *mp;
	char *buf = ap->a_buf;
	int *buflen = ap->a_buflen;
	char pidbuf[PFS_NAMELEN];
	pid_t pid = pvd->pvd_pid;
	int len, i, error, locked;
	i = *buflen;
	error = 0;
	pfs_lock(pd);
	if (vp->v_type == VDIR && pd->pn_type == pfstype_root) {
		*dvp = vp;
		vhold(*dvp);
		pfs_unlock(pd);
		PFS_RETURN (0);
	} else if (vp->v_type == VDIR && pd->pn_type == pfstype_procdir) {
		len = snprintf(pidbuf, sizeof(pidbuf), "%d", pid);
		i -= len;
		if (i < 0) {
			error = ENOMEM;
			goto failed;
		}
		bcopy(pidbuf, buf + i, len);
	} else {
		len = strlen(pd->pn_name);
		i -= len;
		if (i < 0) {
			error = ENOMEM;
			goto failed;
		}
		bcopy(pd->pn_name, buf + i, len);
	}
	pn = pd->pn_parent;
	pfs_unlock(pd);
	mp = vp->v_mount;
	error = vfs_busy(mp, 0);
	if (error)
		return (error);
	locked = VOP_ISLOCKED(vp);
	VOP_UNLOCK(vp, 0);
	error = pfs_vncache_alloc(mp, dvp, pn, pid);
	if (error) {
		vn_lock(vp, locked | LK_RETRY);
		vfs_unbusy(mp);
		PFS_RETURN(error);
	}
	*buflen = i;
	VOP_UNLOCK(*dvp, 0);
	vn_lock(vp, locked | LK_RETRY);
	vfs_unbusy(mp);
	PFS_RETURN (0);
failed:
	pfs_unlock(pd);
	PFS_RETURN(error);
}
static int pfs_vptocnp ( struct vop_vptocnp_args * ap ) { struct vnode * vp = ap -> a_vp ; struct vnode * * dvp = ap -> a_vpp ; struct pfs_vdata * pvd = vp -> v_data ; struct pfs_node * pd = pvd -> pvd_pn ; struct pfs_node * pn ; struct mount * mp ; char * buf = ap -> a_buf ; int * buflen = ap -> a_buflen ; char pidbuf [ PFS_NAMELEN ] ; pid_t pid = pvd -> pvd_pid ; int len , i , error , locked ; i = * buflen ; error = 0 ; pfs_lock ( pd ) ; if ( vp -> v_type == VDIR && pd -> pn_type == pfstype_root ) { * dvp = vp ; vhold ( * dvp ) ; pfs_unlock ( pd ) ; PFS_RETURN ( 0 ) ; } else if ( vp -> v_type == VDIR && pd -> pn_type == pfstype_procdir ) { len = snprintf ( pidbuf , sizeof ( pidbuf ) , " " , pid ) ; i -= len ; if ( i < 0 ) { error = ENOMEM ; goto failed ; } bcopy ( pidbuf , buf + i , len ) ; } else { len = strlen ( pd -> pn_name ) ; i -= len ; if ( i < 0 ) { error = ENOMEM ; goto failed ; } bcopy ( pd -> pn_name , buf + i , len ) ; } pn = pd -> pn_parent ; pfs_unlock ( pd ) ; mp = vp -> v_mount ; error = vfs_busy ( mp , 0 ) ; if ( error ) return ( error ) ; locked = VOP_ISLOCKED ( vp ) ; VOP_UNLOCK ( vp , 0 ) ; error = pfs_vncache_alloc ( mp , dvp , pn , pid ) ; if ( error ) { vn_lock ( vp , locked | LK_RETRY ) ; vfs_unbusy ( mp ) ; PFS_RETURN ( error ) ; } * buflen = i ; VOP_UNLOCK ( * dvp , 0 ) ; vn_lock ( vp , locked | LK_RETRY ) ; vfs_unbusy ( mp ) ; PFS_RETURN ( 0 ) ; failed : pfs_unlock ( pd ) ; PFS_RETURN ( error ) ; }
Convert a vnode to its component name
Convert a vnode to its component name
/*
	 * vp is held by caller.
	 */