Home | History | Annotate | Line # | Download | only in udf
udf_rename.c revision 1.4
      1 /* $NetBSD: udf_rename.c,v 1.4 2013/07/11 19:41:19 reinoud Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2013 Reinoud Zandijk
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  *
     27  * Comments and trivial code from the reference implementation in tmpfs.
     28  */
     29 
     30 #include <sys/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: udf_rename.c,v 1.4 2013/07/11 19:41:19 reinoud Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/errno.h>
     35 #include <sys/kauth.h>
     36 #include <sys/mount.h>
     37 #include <sys/namei.h>
     38 #include <sys/stat.h>
     39 #include <sys/malloc.h>
     40 #include <sys/dirent.h>
     41 #include <sys/vnode.h>
     42 #include <sys/vnode_if.h>
     43 
     44 #include <miscfs/genfs/genfs.h>
     45 
     46 #include <fs/udf/ecma167-udf.h>
     47 #include <fs/udf/udf_mount.h>
     48 #include <sys/dirhash.h>
     49 
     50 #include "udf.h"
     51 #include "udf_subr.h"
     52 #include "udf_bswap.h"
     53 
     54 
     55 /* forwards */
     56 static int udf_sane_rename( struct vnode *, struct componentname *,
     57     struct vnode *, struct componentname *,
     58     kauth_cred_t, bool);
     59 static bool udf_rmdired_p(struct vnode *);
     60 static int udf_gro_lock_directory(struct mount *, struct vnode *);
     61 
     62 static const struct genfs_rename_ops udf_genfs_rename_ops;
     63 
     64 
     65 #define VTOI(vnode) ((struct udf_node *) (vnode)->v_data)
     66 
     67 
     68 /*
     69  * udf_sane_rename: The hairiest vop, with the saner API.
     70  *
     71  * Arguments:
     72  *
     73  * . fdvp (from directory vnode),
     74  * . fcnp (from component name),
     75  * . tdvp (to directory vnode),
     76  * . tcnp (to component name),
     77  * . cred (credentials structure), and
     78  * . posixly_correct (flag for behaviour if target & source link same file).
     79  *
     80  * fdvp and tdvp may be the same, and must be referenced and unlocked.
     81  */
     82 static int
     83 udf_sane_rename( struct vnode *fdvp, struct componentname *fcnp,
     84     struct vnode *tdvp, struct componentname *tcnp,
     85     kauth_cred_t cred, bool posixly_correct)
     86 {
     87 	DPRINTF(CALL, ("udf_sane_rename '%s' -> '%s'\n",
     88 		fcnp->cn_nameptr, tcnp->cn_nameptr));
     89 	return genfs_sane_rename(&udf_genfs_rename_ops,
     90 	    fdvp, fcnp, NULL, tdvp, tcnp, NULL,
     91 	    cred, posixly_correct);
     92 }
     93 
     94 
     95 /*
     96  * udf_rename: the hairiest vop, with the insanest API. Pass to
     97  * genfs_insane_rename immediately.
     98  */
     99 int
    100 udf_rename(void *v)
    101 {
    102 	struct vop_rename_args /* {
    103 		struct vnode *a_fdvp;
    104 		struct vnode *a_fvp;
    105 		struct componentname *a_fcnp;
    106 		struct vnode *a_tdvp;
    107 		struct vnode *a_tvp;
    108 		struct componentname *a_tcnp;
    109 	} */ *ap = v;
    110 	DPRINTF(CALL, ("udf_rename called\n"));
    111 	return genfs_insane_rename(ap, &udf_sane_rename);
    112 }
    113 
    114 
    115 /*
    116  * udf_gro_directory_empty_p: return true if the directory vp is empty. dvp is
    117  * its parent.
    118  *
    119  * vp and dvp must be locked and referenced.
    120  */
    121 static bool
    122 udf_gro_directory_empty_p(struct mount *mp, kauth_cred_t cred,
    123     struct vnode *vp, struct vnode *dvp)
    124 {
    125 	struct udf_node *udf_node = VTOI(vp);
    126 	int error, isempty;
    127 
    128 	KASSERT(mp != NULL);
    129 	KASSERT(vp != NULL);
    130 	KASSERT(dvp != NULL);
    131 	KASSERT(vp != dvp);
    132 	KASSERT(vp->v_mount == mp);
    133 	KASSERT(dvp->v_mount == mp);
    134 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    135 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    136 
    137 	DPRINTF(CALL, ("udf_gro_directory_empty_p called\n"));
    138 	/* make sure our `leaf' node's hash is populated */
    139 	dirhash_get(&udf_node->dir_hash);
    140 	error = udf_dirhash_fill(udf_node);
    141 	if (error) {
    142 		dirhash_put(udf_node->dir_hash);
    143 		return error;
    144 	}
    145 
    146 	/* check to see if the directory is empty */
    147 	isempty = dirhash_dir_isempty(udf_node->dir_hash);
    148 	dirhash_put(udf_node->dir_hash);
    149 
    150 	return isempty;
    151 }
    152 
    153 
    154 /*
    155  * udf_gro_rename_check_possible: check whether a rename is possible
    156  * independent of credentials.
    157  */
    158 static int
    159 udf_gro_rename_check_possible(struct mount *mp,
    160     struct vnode *fdvp, struct vnode *fvp,
    161     struct vnode *tdvp, struct vnode *tvp)
    162 {
    163 	(void)mp;
    164 	KASSERT(mp != NULL);
    165 	KASSERT(fdvp != NULL);
    166 	KASSERT(fvp != NULL);
    167 	KASSERT(tdvp != NULL);
    168 	KASSERT(fdvp != fvp);
    169 	KASSERT(fdvp != tvp);
    170 	KASSERT(tdvp != fvp);
    171 	KASSERT(tdvp != tvp);
    172 	KASSERT(fvp != tvp);
    173 	KASSERT(fdvp->v_type == VDIR);
    174 	KASSERT(tdvp->v_type == VDIR);
    175 	KASSERT(fdvp->v_mount == mp);
    176 	KASSERT(fvp->v_mount == mp);
    177 	KASSERT(tdvp->v_mount == mp);
    178 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    179 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    180 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    181 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    182 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    183 
    184 	DPRINTF(CALL, ("udf_gro_rename_check_possible called\n"));
    185 
    186 	/* flags not implemented since they are not defined (yet) in UDF */
    187 	return 0;
    188 }
    189 
    190 
    191 /*
    192  * udf_gro_rename_check_permitted: check whether a rename is permitted given
    193  * our credentials.
    194  */
    195 static int
    196 udf_gro_rename_check_permitted(struct mount *mp, kauth_cred_t cred,
    197     struct vnode *fdvp, struct vnode *fvp,
    198     struct vnode *tdvp, struct vnode *tvp)
    199 {
    200 	struct udf_node *fdir_node = VTOI(fdvp);
    201 	struct udf_node *tdir_node = VTOI(tdvp);
    202 	struct udf_node *f_node = VTOI(fvp);
    203 	struct udf_node *t_node = (tvp? VTOI(tvp): NULL);
    204 	mode_t fdmode, tdmode;
    205 	uid_t fduid, tduid, fuid, tuid;
    206 	gid_t gdummy;
    207 
    208 	(void)mp;
    209 	KASSERT(mp != NULL);
    210 	KASSERT(fdvp != NULL);
    211 	KASSERT(fvp != NULL);
    212 	KASSERT(tdvp != NULL);
    213 	KASSERT(fdvp != fvp);
    214 	KASSERT(fdvp != tvp);
    215 	KASSERT(tdvp != fvp);
    216 	KASSERT(tdvp != tvp);
    217 	KASSERT(fvp != tvp);
    218 	KASSERT(fdvp->v_type == VDIR);
    219 	KASSERT(tdvp->v_type == VDIR);
    220 	KASSERT(fdvp->v_mount == mp);
    221 	KASSERT(fvp->v_mount == mp);
    222 	KASSERT(tdvp->v_mount == mp);
    223 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    224 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    225 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    226 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    227 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    228 
    229 	DPRINTF(CALL, ("udf_gro_rename_check_permitted called\n"));
    230 	fdmode = udf_getaccessmode(fdir_node);
    231 	tdmode = udf_getaccessmode(tdir_node);
    232 
    233 	udf_getownership(fdir_node, &fduid, &gdummy);
    234 	udf_getownership(tdir_node, &tduid, &gdummy);
    235 	udf_getownership(f_node,    &fuid, &gdummy);
    236 
    237 	tuid = 0;
    238 	if (t_node)
    239 		udf_getownership(t_node, &tuid, &gdummy);
    240 
    241 	return genfs_ufslike_rename_check_permitted(cred,
    242 	    fdvp, fdmode, fduid,
    243 	    fvp,  fuid,
    244 	    tdvp, tdmode, tduid,
    245 	    tvp,  tuid);
    246 }
    247 
    248 
    249 /*
    250  * udf_gro_remove_check_possible: check whether a remove is possible
    251  * independent of credentials.
    252  *
    253  * XXX could check for special attributes?
    254  */
    255 static int
    256 udf_gro_remove_check_possible(struct mount *mp,
    257     struct vnode *dvp, struct vnode *vp)
    258 {
    259 	(void)mp;
    260 	KASSERT(mp != NULL);
    261 	KASSERT(dvp != NULL);
    262 	KASSERT(vp != NULL);
    263 	KASSERT(dvp != vp);
    264 	KASSERT(dvp->v_type == VDIR);
    265 	KASSERT(vp->v_type != VDIR);
    266 	KASSERT(dvp->v_mount == mp);
    267 	KASSERT(vp->v_mount == mp);
    268 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    269 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    270 
    271 	DPRINTF(CALL, ("udf_gro_remove_check_possible called\n"));
    272 
    273 	/* flags not implemented since they are not defined (yet) in UDF */
    274 	return 0;
    275 }
    276 
    277 
    278 /*
    279  * udf_gro_remove_check_permitted: check whether a remove is permitted given
    280  * our credentials.
    281  */
    282 static int
    283 udf_gro_remove_check_permitted(struct mount *mp, kauth_cred_t cred,
    284     struct vnode *dvp, struct vnode *vp)
    285 {
    286 	struct udf_node *dir_node = VTOI(dvp);
    287 	struct udf_node *udf_node = VTOI(vp);
    288 	mode_t dmode;
    289 	uid_t duid, uid;
    290 	gid_t gdummy;
    291 
    292 	(void)mp;
    293 	KASSERT(mp != NULL);
    294 	KASSERT(dvp != NULL);
    295 	KASSERT(vp != NULL);
    296 	KASSERT(dvp != vp);
    297 	KASSERT(dvp->v_type == VDIR);
    298 	KASSERT(vp->v_type != VDIR);
    299 	KASSERT(dvp->v_mount == mp);
    300 	KASSERT(vp->v_mount == mp);
    301 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    302 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    303 
    304 	DPRINTF(CALL, ("udf_gro_remove_check_permitted called\n"));
    305 	dmode = udf_getaccessmode(dir_node);
    306 
    307 	udf_getownership(dir_node, &duid, &gdummy);
    308 	udf_getownership(udf_node, &uid,  &gdummy);
    309 
    310 	return genfs_ufslike_remove_check_permitted(cred,
    311 	    dvp, dmode, duid,
    312 	    vp, uid);
    313 }
    314 
    315 
    316 /*
    317  * udf_gro_rename: actually perform the rename operation.
    318  */
    319 static int
    320 udf_gro_rename(struct mount *mp, kauth_cred_t cred,
    321     struct vnode *fdvp, struct componentname *fcnp,
    322     void *fde, struct vnode *fvp,
    323     struct vnode *tdvp, struct componentname *tcnp,
    324     void *tde, struct vnode *tvp)
    325 {
    326 	struct udf_node *fnode, *fdnode, *tnode, *tdnode;
    327 	struct vattr fvap;
    328 	int error;
    329 
    330 	(void)cred;
    331 	KASSERT(mp != NULL);
    332 	KASSERT(fdvp != NULL);
    333 	KASSERT(fcnp != NULL);
    334 	KASSERT(fvp != NULL);
    335 	KASSERT(tdvp != NULL);
    336 	KASSERT(tcnp != NULL);
    337 	KASSERT(fdvp != fvp);
    338 	KASSERT(fdvp != tvp);
    339 	KASSERT(tdvp != fvp);
    340 	KASSERT(tdvp != tvp);
    341 	KASSERT(fvp != tvp);
    342 	KASSERT(fdvp->v_mount == mp);
    343 	KASSERT(fvp->v_mount == mp);
    344 	KASSERT(tdvp->v_mount == mp);
    345 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    346 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    347 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    348 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    349 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    350 
    351 	DPRINTF(CALL, ("udf_gro_rename called\n"));
    352 	DPRINTF(NODE, ("udf_gro_rename called : %s -> %s\n",
    353 		fcnp->cn_nameptr, tcnp->cn_nameptr));
    354 
    355 	fnode  = VTOI(fvp);
    356 	fdnode = VTOI(fdvp);
    357 	tnode  = (tvp == NULL) ? NULL : VTOI(tvp);
    358 	tdnode = VTOI(tdvp);
    359 
    360 	/* get attribute information */
    361 	error = VOP_GETATTR(fvp, &fvap, NULL);
    362 	if (error)
    363 		return error;
    364 
    365 	/* remove existing entry if present */
    366 	if (tvp)
    367 		udf_dir_detach(tdnode->ump, tdnode, tnode, tcnp);
    368 
    369 	/* create new directory entry for the node */
    370 	error = udf_dir_attach(tdnode->ump, tdnode, fnode, &fvap, tcnp);
    371 	if (error)
    372 		return error;
    373 
    374 	/* unlink old directory entry for the node, if failing, unattach new */
    375 	error = udf_dir_detach(tdnode->ump, fdnode, fnode, fcnp);
    376 	if (error) {
    377 		udf_dir_detach(tdnode->ump, tdnode, fnode, tcnp);
    378 	} else if ((fdnode != tdnode) && (fvp->v_type == VDIR)) {
    379 		/* update fnode's '..' entry */
    380 		error = udf_dir_update_rootentry(fnode->ump, fnode, tdnode);
    381 		if (error) {
    382 			/* 'try' to recover from this situation */
    383 			udf_dir_attach(tdnode->ump, fdnode, fnode, &fvap, fcnp);
    384 			udf_dir_detach(tdnode->ump, tdnode, fnode, tcnp);
    385 		}
    386 	}
    387 
    388 	if (!error) {
    389 		VN_KNOTE(fvp, NOTE_RENAME);
    390 		genfs_rename_cache_purge(fdvp, fvp, tdvp, tvp);
    391 	}
    392 
    393 	return error;
    394 }
    395 
    396 
    397 /*
    398  * udf_gro_remove: rename an object over another link to itself, effectively
    399  * removing just the original link.
    400  */
    401 static int
    402 udf_gro_remove(struct mount *mp, kauth_cred_t cred,
    403     struct vnode *dvp, struct componentname *cnp, void *de, struct vnode *vp)
    404 {
    405 	struct udf_node *dir_node, *udf_node;
    406 
    407 	(void)vp;
    408 	KASSERT(mp != NULL);
    409 	KASSERT(dvp != NULL);
    410 	KASSERT(cnp != NULL);
    411 	KASSERT(vp != NULL);
    412 	KASSERT(dvp != vp);
    413 	KASSERT(dvp->v_mount == mp);
    414 	KASSERT(vp->v_mount == mp);
    415 	KASSERT(dvp->v_type == VDIR);
    416 	KASSERT(vp->v_type != VDIR);
    417 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    418 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    419 
    420 	DPRINTF(CALL, ("udf_gro_remove called\n"));
    421 
    422 	dir_node = VTOI(dvp);
    423 	udf_node = VTOI(vp);
    424 	udf_dir_detach(dir_node->ump, dir_node, udf_node, cnp);
    425 
    426 	return 0;
    427 }
    428 
    429 
    430 /*
    431  * udf_gro_lookup: look up and save the lookup results.
    432  */
    433 static int
    434 udf_gro_lookup(struct mount *mp, struct vnode *dvp,
    435     struct componentname *cnp, void *de_ret, struct vnode **vp_ret)
    436 {
    437 	struct udf_node *dir_node, *res_node;
    438 	struct long_ad   icb_loc;
    439 	const char *name;
    440 	int namelen, error;
    441 	int found;
    442 
    443 	(void)mp;
    444 	KASSERT(mp != NULL);
    445 	KASSERT(dvp != NULL);
    446 	KASSERT(cnp != NULL);
    447 	KASSERT(vp_ret != NULL);
    448 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    449 
    450 	dir_node = VTOI(dvp);
    451 
    452 	DPRINTF(CALL, ("udf_gro_lookup called\n"));
    453 
    454 	/* lookup filename in the directory; location icb_loc */
    455 	name    = cnp->cn_nameptr;
    456 	namelen = cnp->cn_namelen;
    457 	error = udf_lookup_name_in_dir(dvp, name, namelen,
    458 			&icb_loc, &found);
    459 	if (error)
    460 		return error;
    461 	if (!found)
    462 		return ENOENT;
    463 
    464 	DPRINTF(LOOKUP, ("udf_gro_lookup found '%s'\n", name));
    465 	error = udf_get_node(dir_node->ump, &icb_loc, &res_node);
    466 	if (error)
    467 		return error;
    468 	*vp_ret = res_node->vnode;
    469 	VOP_UNLOCK(res_node->vnode);
    470 
    471 	return 0;
    472 }
    473 
    474 
    475 /*
    476  * udf_rmdired_p: check whether the directory vp has been rmdired.
    477  *
    478  * vp must be locked and referenced.
    479  */
    480 static bool
    481 udf_rmdired_p(struct vnode *vp)
    482 {
    483 	DPRINTF(CALL, ("udf_rmdired_p called\n"));
    484 
    485 	KASSERT(vp != NULL);
    486 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    487 	KASSERT(vp->v_type == VDIR);
    488 
    489 	return (VTOI(vp)->i_flags & IN_DELETED);
    490 }
    491 
    492 
    493 /*
    494  * udf_gro_genealogy: analyze the genealogy of the source and target
    495  * directories.
    496  */
    497 static int
    498 udf_gro_genealogy(struct mount *mp, kauth_cred_t cred,
    499     struct vnode *fdvp, struct vnode *tdvp,
    500     struct vnode **intermediate_node_ret)
    501 {
    502 	struct udf_mount *ump;
    503 	struct udf_node *source, *target, *parent_node, *child_node;
    504 	struct long_ad parent_loc;
    505 	const char *name;
    506 	int namelen;
    507 	int error, found;
    508 
    509 	(void)cred;
    510 	KASSERT(mp != NULL);
    511 	KASSERT(fdvp != NULL);
    512 	KASSERT(tdvp != NULL);
    513 	KASSERT(fdvp != tdvp);
    514 	KASSERT(intermediate_node_ret != NULL);
    515 	KASSERT(fdvp->v_mount == mp);
    516 	KASSERT(tdvp->v_mount == mp);
    517 	KASSERT(fdvp->v_type == VDIR);
    518 	KASSERT(tdvp->v_type == VDIR);
    519 
    520 	DPRINTF(CALL, ("udf_gro_genealogy called\n"));
    521 
    522 	/*
    523 	 * We need to provisionally lock tdvp to keep rmdir from deleting it
    524 	 * -- or any ancestor -- at an inopportune moment.
    525 	 *
    526 	 * XXX WHY is this not in genfs's rename? XXX
    527 	 */
    528 	error = udf_gro_lock_directory(mp, tdvp);
    529 	if (error)
    530 		return error;
    531 
    532 	source = VTOI(fdvp);
    533 	target = VTOI(tdvp);
    534 
    535 	name     = "..";
    536 	namelen  = 2;
    537 	error    = 0;
    538 
    539 	ump = target->ump;
    540 
    541 	/* if nodes are equal, it is no use looking */
    542 	if (udf_compare_icb(&source->loc, &target->loc) == 0)
    543 		return EEXIST;
    544 
    545 	child_node = target;
    546 	vref(child_node->vnode);
    547 
    548 	for (;;) {
    549 		DPRINTF(NODE, ("udf_gro_genealogy : "
    550 			"source vp %p, looking at vp %p\n",
    551 			source->vnode, child_node->vnode));
    552 
    553 		/* sanity check */
    554 		if (child_node->vnode->v_type != VDIR) {
    555 			vput(child_node->vnode);
    556 			return ENOTDIR;
    557 		}
    558 
    559 		/* go down one level */
    560 		error = udf_lookup_name_in_dir(child_node->vnode, name, namelen,
    561 			&parent_loc, &found);
    562 		DPRINTF(NODE, ("\tlookup of parent '..' resulted in error %d, "
    563 			"found %d\n", error, found));
    564 		if (!found)
    565 			error = ENOENT;
    566 		if (error) {
    567 			vput(child_node->vnode);
    568 			return error;
    569 		}
    570 
    571 		/* did we encounter the root node? i.e. loop back */
    572 		if (udf_compare_icb(&parent_loc, &child_node->loc) == 0) {
    573 			DPRINTF(NODE, ("ROOT found!\n"));
    574 			vput(child_node->vnode);
    575 			*intermediate_node_ret = NULL;
    576 			return 0;
    577 		}
    578 
    579 		/* did we encounter source node? */
    580 		if (udf_compare_icb(&parent_loc, &source->loc) == 0) {
    581 			DPRINTF(NODE, ("SOURCE NODE FOUND\n"));
    582 			*intermediate_node_ret = child_node->vnode;
    583 			VOP_UNLOCK(child_node->vnode);
    584 			return 0;
    585 		}
    586 
    587 		DPRINTF(NODE, ("\tgetting the parent node\n"));
    588 		error = udf_get_node(ump, &parent_loc, &parent_node);
    589 		if (error) {
    590 			vput(child_node->vnode);
    591 			return error;
    592 		}
    593 
    594 		if (udf_rmdired_p(parent_node->vnode)) {
    595 			vput(child_node->vnode);
    596 			vput(parent_node->vnode);
    597 			return ENOENT;
    598 		}
    599 
    600 		/*
    601 		 * Push our intermediate node, we're done with it, but do
    602 		 * remember our parent location
    603 		 */
    604 		vput(child_node->vnode);
    605 		child_node = parent_node;
    606 	}
    607 }
    608 
    609 
    610 /*
    611  * udf_gro_lock_directory: lock the directory vp, but fail if it has been
    612  * rmdir'd.
    613  */
    614 static int
    615 udf_gro_lock_directory(struct mount *mp, struct vnode *vp)
    616 {
    617 
    618 	(void)mp;
    619 	KASSERT(mp != NULL);
    620 	KASSERT(vp != NULL);
    621 	KASSERT(vp->v_mount == mp);
    622 
    623 	DPRINTF(CALL, ("udf_gro_lock_directory called\n"));
    624 	DPRINTF(LOCKING, ("udf_gro_lock_directory called\n"));
    625 
    626 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    627 
    628 	if (udf_rmdired_p(vp)) {
    629 		VOP_UNLOCK(vp);
    630 		return ENOENT;
    631 	}
    632 
    633 	return 0;
    634 }
    635 
    636 
    637 static const struct genfs_rename_ops udf_genfs_rename_ops = {
    638 	.gro_directory_empty_p		= udf_gro_directory_empty_p,
    639 	.gro_rename_check_possible	= udf_gro_rename_check_possible,
    640 	.gro_rename_check_permitted	= udf_gro_rename_check_permitted,
    641 	.gro_remove_check_possible	= udf_gro_remove_check_possible,
    642 	.gro_remove_check_permitted	= udf_gro_remove_check_permitted,
    643 	.gro_rename			= udf_gro_rename,
    644 	.gro_remove			= udf_gro_remove,
    645 	.gro_lookup			= udf_gro_lookup,
    646 	.gro_genealogy			= udf_gro_genealogy,
    647 	.gro_lock_directory		= udf_gro_lock_directory,
    648 };
    649