+ if (((vp->v_parent != NULLVP) && !fixhardlink) ||
+ (flags & BUILDPATH_NO_FS_ENTER)) {
+
+ /*
+ * In this if () block we are not allowed to enter the filesystem
+ * to conclusively get the most accurate parent identifier.
+ * As a result, if 'vp' does not identify '/' and it
+ * does not have a valid v_parent, then error out
+ * and disallow further path construction
+ */
+ if ((vp->v_parent == NULLVP) && (rootvnode != vp)) {
+ /*
+ * Only '/' is allowed to have a NULL parent
+ * pointer. Upper level callers should ideally
+ * re-drive name lookup on receiving a ENOENT.
+ */
+ ret = ENOENT;
+
+ /* The code below will exit early if 'tvp = vp' == NULL */
+ }
+ vp = vp->v_parent;
+
+ /*
+ * if the vnode we have in hand isn't a directory and it
+ * has a v_parent, then we started with the resource fork
+ * so skip up to avoid getting a duplicate copy of the
+ * file name in the path.
+ */
+ if (vp && !vnode_isdir(vp) && vp->v_parent) {
+ vp = vp->v_parent;
+ }
+ } else {
+ /*
+ * No parent, go get it if supported.
+ */
+ struct vnode_attr va;
+ vnode_t dvp;
+
+ /*
+ * Make sure file system supports obtaining a path from id.
+ */
+ if (!(vp->v_mount->mnt_kern_flag & MNTK_PATH_FROM_ID)) {
+ ret = ENOENT;
+ goto out_unlock;
+ }
+ vid = vp->v_id;
+
+ NAME_CACHE_UNLOCK();
+
+ if (vp != first_vp && vp != vp_with_iocount) {
+ if (vp_with_iocount) {
+ vnode_put(vp_with_iocount);
+ vp_with_iocount = NULLVP;
+ }
+ if (vnode_getwithvid(vp, vid))
+ goto again;
+ vp_with_iocount = vp;
+ }
+ VATTR_INIT(&va);
+ VATTR_WANTED(&va, va_parentid);
+
+ if (fixhardlink) {
+ VATTR_WANTED(&va, va_name);
+ MALLOC_ZONE(va.va_name, caddr_t, MAXPATHLEN, M_NAMEI, M_WAITOK);
+ } else {
+ va.va_name = NULL;
+ }
+ /*
+ * Ask the file system for its parent id and for its name (optional).
+ */
+ ret = vnode_getattr(vp, &va, ctx);
+
+ if (fixhardlink) {
+ if ((ret == 0) && (VATTR_IS_SUPPORTED(&va, va_name))) {
+ str = va.va_name;
+ vnode_update_identity(vp, NULL, str, strlen(str), 0, VNODE_UPDATE_NAME);
+ } else if (vp->v_name) {
+ str = vp->v_name;
+ ret = 0;
+ } else {
+ ret = ENOENT;
+ goto bad_news;
+ }
+ len = strlen(str);