Home | History | Annotate | Line # | Download | only in udf
udf_rename.c revision 1.6
      1 /* $NetBSD: udf_rename.c,v 1.6 2013/07/13 19:39:02 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.6 2013/07/13 19:39:02 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 		/* VERY unlikely, answer its not empty */
    144 		return 0;
    145 	}
    146 
    147 	/* check to see if the directory is empty */
    148 	isempty = dirhash_dir_isempty(udf_node->dir_hash);
    149 	dirhash_put(udf_node->dir_hash);
    150 
    151 	return isempty;
    152 }
    153 
    154 
    155 /*
    156  * udf_gro_rename_check_possible: check whether a rename is possible
    157  * independent of credentials.
    158  */
    159 static int
    160 udf_gro_rename_check_possible(struct mount *mp,
    161     struct vnode *fdvp, struct vnode *fvp,
    162     struct vnode *tdvp, struct vnode *tvp)
    163 {
    164 	(void)mp;
    165 	KASSERT(mp != NULL);
    166 	KASSERT(fdvp != NULL);
    167 	KASSERT(fvp != NULL);
    168 	KASSERT(tdvp != NULL);
    169 	KASSERT(fdvp != fvp);
    170 	KASSERT(fdvp != tvp);
    171 	KASSERT(tdvp != fvp);
    172 	KASSERT(tdvp != tvp);
    173 	KASSERT(fvp != tvp);
    174 	KASSERT(fdvp->v_type == VDIR);
    175 	KASSERT(tdvp->v_type == VDIR);
    176 	KASSERT(fdvp->v_mount == mp);
    177 	KASSERT(fvp->v_mount == mp);
    178 	KASSERT(tdvp->v_mount == mp);
    179 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    180 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    181 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    182 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    183 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    184 
    185 	DPRINTF(CALL, ("udf_gro_rename_check_possible called\n"));
    186 
    187 	/* flags not implemented since they are not defined (yet) in UDF */
    188 	return 0;
    189 }
    190 
    191 
    192 /*
    193  * udf_gro_rename_check_permitted: check whether a rename is permitted given
    194  * our credentials.
    195  */
    196 static int
    197 udf_gro_rename_check_permitted(struct mount *mp, kauth_cred_t cred,
    198     struct vnode *fdvp, struct vnode *fvp,
    199     struct vnode *tdvp, struct vnode *tvp)
    200 {
    201 	struct udf_node *fdir_node = VTOI(fdvp);
    202 	struct udf_node *tdir_node = VTOI(tdvp);
    203 	struct udf_node *f_node = VTOI(fvp);
    204 	struct udf_node *t_node = (tvp? VTOI(tvp): NULL);
    205 	mode_t fdmode, tdmode;
    206 	uid_t fduid, tduid, fuid, tuid;
    207 	gid_t gdummy;
    208 
    209 	(void)mp;
    210 	KASSERT(mp != NULL);
    211 	KASSERT(fdvp != NULL);
    212 	KASSERT(fvp != NULL);
    213 	KASSERT(tdvp != NULL);
    214 	KASSERT(fdvp != fvp);
    215 	KASSERT(fdvp != tvp);
    216 	KASSERT(tdvp != fvp);
    217 	KASSERT(tdvp != tvp);
    218 	KASSERT(fvp != tvp);
    219 	KASSERT(fdvp->v_type == VDIR);
    220 	KASSERT(tdvp->v_type == VDIR);
    221 	KASSERT(fdvp->v_mount == mp);
    222 	KASSERT(fvp->v_mount == mp);
    223 	KASSERT(tdvp->v_mount == mp);
    224 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    225 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    226 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    227 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    228 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    229 
    230 	DPRINTF(CALL, ("udf_gro_rename_check_permitted called\n"));
    231 	fdmode = udf_getaccessmode(fdir_node);
    232 	tdmode = udf_getaccessmode(tdir_node);
    233 
    234 	udf_getownership(fdir_node, &fduid, &gdummy);
    235 	udf_getownership(tdir_node, &tduid, &gdummy);
    236 	udf_getownership(f_node,    &fuid, &gdummy);
    237 
    238 	tuid = 0;
    239 	if (t_node)
    240 		udf_getownership(t_node, &tuid, &gdummy);
    241 
    242 	return genfs_ufslike_rename_check_permitted(cred,
    243 	    fdvp, fdmode, fduid,
    244 	    fvp,  fuid,
    245 	    tdvp, tdmode, tduid,
    246 	    tvp,  tuid);
    247 }
    248 
    249 
    250 /*
    251  * udf_gro_remove_check_possible: check whether a remove is possible
    252  * independent of credentials.
    253  *
    254  * XXX could check for special attributes?
    255  */
    256 static int
    257 udf_gro_remove_check_possible(struct mount *mp,
    258     struct vnode *dvp, struct vnode *vp)
    259 {
    260 	(void)mp;
    261 	KASSERT(mp != NULL);
    262 	KASSERT(dvp != NULL);
    263 	KASSERT(vp != NULL);
    264 	KASSERT(dvp != vp);
    265 	KASSERT(dvp->v_type == VDIR);
    266 	KASSERT(vp->v_type != VDIR);
    267 	KASSERT(dvp->v_mount == mp);
    268 	KASSERT(vp->v_mount == mp);
    269 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    270 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    271 
    272 	DPRINTF(CALL, ("udf_gro_remove_check_possible called\n"));
    273 
    274 	/* flags not implemented since they are not defined (yet) in UDF */
    275 	return 0;
    276 }
    277 
    278 
    279 /*
    280  * udf_gro_remove_check_permitted: check whether a remove is permitted given
    281  * our credentials.
    282  */
    283 static int
    284 udf_gro_remove_check_permitted(struct mount *mp, kauth_cred_t cred,
    285     struct vnode *dvp, struct vnode *vp)
    286 {
    287 	struct udf_node *dir_node = VTOI(dvp);
    288 	struct udf_node *udf_node = VTOI(vp);
    289 	mode_t dmode;
    290 	uid_t duid, uid;
    291 	gid_t gdummy;
    292 
    293 	(void)mp;
    294 	KASSERT(mp != NULL);
    295 	KASSERT(dvp != NULL);
    296 	KASSERT(vp != NULL);
    297 	KASSERT(dvp != vp);
    298 	KASSERT(dvp->v_type == VDIR);
    299 	KASSERT(vp->v_type != VDIR);
    300 	KASSERT(dvp->v_mount == mp);
    301 	KASSERT(vp->v_mount == mp);
    302 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    303 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    304 
    305 	DPRINTF(CALL, ("udf_gro_remove_check_permitted called\n"));
    306 	dmode = udf_getaccessmode(dir_node);
    307 
    308 	udf_getownership(dir_node, &duid, &gdummy);
    309 	udf_getownership(udf_node, &uid,  &gdummy);
    310 
    311 	return genfs_ufslike_remove_check_permitted(cred,
    312 	    dvp, dmode, duid,
    313 	    vp, uid);
    314 }
    315 
    316 
    317 /*
    318  * udf_gro_rename: actually perform the rename operation.
    319  */
    320 static int
    321 udf_gro_rename(struct mount *mp, kauth_cred_t cred,
    322     struct vnode *fdvp, struct componentname *fcnp,
    323     void *fde, struct vnode *fvp,
    324     struct vnode *tdvp, struct componentname *tcnp,
    325     void *tde, struct vnode *tvp)
    326 {
    327 	struct udf_node *fnode, *fdnode, *tnode, *tdnode;
    328 	struct vattr fvap;
    329 	int error;
    330 
    331 	(void)cred;
    332 	KASSERT(mp != NULL);
    333 	KASSERT(fdvp != NULL);
    334 	KASSERT(fcnp != NULL);
    335 	KASSERT(fvp != NULL);
    336 	KASSERT(tdvp != NULL);
    337 	KASSERT(tcnp != NULL);
    338 	KASSERT(fdvp != fvp);
    339 	KASSERT(fdvp != tvp);
    340 	KASSERT(tdvp != fvp);
    341 	KASSERT(tdvp != tvp);
    342 	KASSERT(fvp != tvp);
    343 	KASSERT(fdvp->v_mount == mp);
    344 	KASSERT(fvp->v_mount == mp);
    345 	KASSERT(tdvp->v_mount == mp);
    346 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
    347 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
    348 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
    349 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
    350 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
    351 
    352 	DPRINTF(CALL, ("udf_gro_rename called\n"));
    353 	DPRINTF(NODE, ("udf_gro_rename called : %s -> %s\n",
    354 		fcnp->cn_nameptr, tcnp->cn_nameptr));
    355 
    356 	fnode  = VTOI(fvp);
    357 	fdnode = VTOI(fdvp);
    358 	tnode  = (tvp == NULL) ? NULL : VTOI(tvp);
    359 	tdnode = VTOI(tdvp);
    360 
    361 	/* get attribute information */
    362 	error = VOP_GETATTR(fvp, &fvap, NULL);
    363 	if (error)
    364 		return error;
    365 
    366 	/* remove existing entry if present */
    367 	if (tvp)
    368 		udf_dir_detach(tdnode->ump, tdnode, tnode, tcnp);
    369 
    370 	/* create new directory entry for the node */
    371 	error = udf_dir_attach(tdnode->ump, tdnode, fnode, &fvap, tcnp);
    372 	if (error)
    373 		return error;
    374 
    375 	/* unlink old directory entry for the node, if failing, unattach new */
    376 	error = udf_dir_detach(tdnode->ump, fdnode, fnode, fcnp);
    377 	if (error)
    378 		goto rollback_attach;
    379 
    380 	if ((fdnode != tdnode) && (fvp->v_type == VDIR)) {
    381 		/* update fnode's '..' entry */
    382 		error = udf_dir_update_rootentry(fnode->ump, fnode, tdnode);
    383 		if (error)
    384 			goto rollback;
    385 	}
    386 
    387 	VN_KNOTE(fvp, NOTE_RENAME);
    388 	genfs_rename_cache_purge(fdvp, fvp, tdvp, tvp);
    389 	return 0;
    390 
    391 rollback:
    392 	/* 'try' to recover from this situation */
    393 	udf_dir_attach(tdnode->ump, fdnode, fnode, &fvap, fcnp);
    394 rollback_attach:
    395 	udf_dir_detach(tdnode->ump, tdnode, fnode, tcnp);
    396 
    397 	return error;
    398 }
    399 
    400 
    401 /*
    402  * udf_gro_remove: rename an object over another link to itself, effectively
    403  * removing just the original link.
    404  */
    405 static int
    406 udf_gro_remove(struct mount *mp, kauth_cred_t cred,
    407     struct vnode *dvp, struct componentname *cnp, void *de, struct vnode *vp)
    408 {
    409 	struct udf_node *dir_node, *udf_node;
    410 
    411 	(void)vp;
    412 	KASSERT(mp != NULL);
    413 	KASSERT(dvp != NULL);
    414 	KASSERT(cnp != NULL);
    415 	KASSERT(vp != NULL);
    416 	KASSERT(dvp != vp);
    417 	KASSERT(dvp->v_mount == mp);
    418 	KASSERT(vp->v_mount == mp);
    419 	KASSERT(dvp->v_type == VDIR);
    420 	KASSERT(vp->v_type != VDIR);
    421 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    422 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    423 
    424 	DPRINTF(CALL, ("udf_gro_remove called\n"));
    425 
    426 	dir_node = VTOI(dvp);
    427 	udf_node = VTOI(vp);
    428 	udf_dir_detach(dir_node->ump, dir_node, udf_node, cnp);
    429 
    430 	return 0;
    431 }
    432 
    433 
    434 /*
    435  * udf_gro_lookup: look up and save the lookup results.
    436  */
    437 static int
    438 udf_gro_lookup(struct mount *mp, struct vnode *dvp,
    439     struct componentname *cnp, void *de_ret, struct vnode **vp_ret)
    440 {
    441 	struct udf_node *dir_node, *res_node;
    442 	struct long_ad   icb_loc;
    443 	const char *name;
    444 	int namelen, error;
    445 	int found;
    446 
    447 	(void)mp;
    448 	KASSERT(mp != NULL);
    449 	KASSERT(dvp != NULL);
    450 	KASSERT(cnp != NULL);
    451 	KASSERT(vp_ret != NULL);
    452 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
    453 
    454 	dir_node = VTOI(dvp);
    455 
    456 	DPRINTF(CALL, ("udf_gro_lookup called\n"));
    457 
    458 	/* lookup filename in the directory; location icb_loc */
    459 	name    = cnp->cn_nameptr;
    460 	namelen = cnp->cn_namelen;
    461 	error = udf_lookup_name_in_dir(dvp, name, namelen,
    462 			&icb_loc, &found);
    463 	if (error)
    464 		return error;
    465 	if (!found)
    466 		return ENOENT;
    467 
    468 	DPRINTF(LOOKUP, ("udf_gro_lookup found '%s'\n", name));
    469 	error = udf_get_node(dir_node->ump, &icb_loc, &res_node);
    470 	if (error)
    471 		return error;
    472 	*vp_ret = res_node->vnode;
    473 	VOP_UNLOCK(res_node->vnode);
    474 
    475 	return 0;
    476 }
    477 
    478 
    479 /*
    480  * udf_rmdired_p: check whether the directory vp has been rmdired.
    481  *
    482  * vp must be locked and referenced.
    483  */
    484 static bool
    485 udf_rmdired_p(struct vnode *vp)
    486 {
    487 	DPRINTF(CALL, ("udf_rmdired_p called\n"));
    488 
    489 	KASSERT(vp != NULL);
    490 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
    491 	KASSERT(vp->v_type == VDIR);
    492 
    493 	return (VTOI(vp)->i_flags & IN_DELETED);
    494 }
    495 
    496 
    497 /*
    498  * udf_gro_genealogy: analyze the genealogy of the source and target
    499  * directories.
    500  */
    501 static int
    502 udf_gro_genealogy(struct mount *mp, kauth_cred_t cred,
    503     struct vnode *fdvp, struct vnode *tdvp,
    504     struct vnode **intermediate_node_ret)
    505 {
    506 	struct udf_mount *ump;
    507 	struct udf_node *source, *target, *parent_node, *child_node;
    508 	struct long_ad parent_loc;
    509 	const char *name;
    510 	int namelen;
    511 	int error, found;
    512 
    513 	(void)cred;
    514 	KASSERT(mp != NULL);
    515 	KASSERT(fdvp != NULL);
    516 	KASSERT(tdvp != NULL);
    517 	KASSERT(fdvp != tdvp);
    518 	KASSERT(intermediate_node_ret != NULL);
    519 	KASSERT(fdvp->v_mount == mp);
    520 	KASSERT(tdvp->v_mount == mp);
    521 	KASSERT(fdvp->v_type == VDIR);
    522 	KASSERT(tdvp->v_type == VDIR);
    523 
    524 	DPRINTF(CALL, ("udf_gro_genealogy called\n"));
    525 
    526 	/*
    527 	 * We need to provisionally lock tdvp to keep rmdir from deleting it
    528 	 * -- or any ancestor -- at an inopportune moment.
    529 	 *
    530 	 * XXX WHY is this not in genfs's rename? XXX
    531 	 */
    532 	error = udf_gro_lock_directory(mp, tdvp);
    533 	if (error)
    534 		return error;
    535 
    536 	source = VTOI(fdvp);
    537 	target = VTOI(tdvp);
    538 
    539 	name     = "..";
    540 	namelen  = 2;
    541 	error    = 0;
    542 
    543 	ump = target->ump;
    544 
    545 	/* if nodes are equal, it is no use looking */
    546 	if (udf_compare_icb(&source->loc, &target->loc) == 0)
    547 		return EEXIST;
    548 
    549 	child_node = target;
    550 	vref(child_node->vnode);
    551 
    552 	for (;;) {
    553 		DPRINTF(NODE, ("udf_gro_genealogy : "
    554 			"source vp %p, looking at vp %p\n",
    555 			source->vnode, child_node->vnode));
    556 
    557 		/* sanity check */
    558 		if (child_node->vnode->v_type != VDIR) {
    559 			vput(child_node->vnode);
    560 			return ENOTDIR;
    561 		}
    562 
    563 		/* go down one level */
    564 		error = udf_lookup_name_in_dir(child_node->vnode, name, namelen,
    565 			&parent_loc, &found);
    566 		DPRINTF(NODE, ("\tlookup of parent '..' resulted in error %d, "
    567 			"found %d\n", error, found));
    568 		if (!found)
    569 			error = ENOENT;
    570 		if (error) {
    571 			vput(child_node->vnode);
    572 			return error;
    573 		}
    574 
    575 		/* did we encounter the root node? i.e. loop back */
    576 		if (udf_compare_icb(&parent_loc, &child_node->loc) == 0) {
    577 			DPRINTF(NODE, ("ROOT found!\n"));
    578 			vput(child_node->vnode);
    579 			*intermediate_node_ret = NULL;
    580 			return 0;
    581 		}
    582 
    583 		/* did we encounter source node? */
    584 		if (udf_compare_icb(&parent_loc, &source->loc) == 0) {
    585 			DPRINTF(NODE, ("SOURCE NODE FOUND\n"));
    586 			*intermediate_node_ret = child_node->vnode;
    587 			VOP_UNLOCK(child_node->vnode);
    588 			return 0;
    589 		}
    590 
    591 		DPRINTF(NODE, ("\tgetting the parent node\n"));
    592 		error = udf_get_node(ump, &parent_loc, &parent_node);
    593 		if (error) {
    594 			vput(child_node->vnode);
    595 			return error;
    596 		}
    597 
    598 		if (udf_rmdired_p(parent_node->vnode)) {
    599 			vput(child_node->vnode);
    600 			vput(parent_node->vnode);
    601 			return ENOENT;
    602 		}
    603 
    604 		/*
    605 		 * Push our intermediate node, we're done with it, but do
    606 		 * remember our parent location
    607 		 */
    608 		vput(child_node->vnode);
    609 		child_node = parent_node;
    610 	}
    611 }
    612 
    613 
    614 /*
    615  * udf_gro_lock_directory: lock the directory vp, but fail if it has been
    616  * rmdir'd.
    617  */
    618 static int
    619 udf_gro_lock_directory(struct mount *mp, struct vnode *vp)
    620 {
    621 
    622 	(void)mp;
    623 	KASSERT(mp != NULL);
    624 	KASSERT(vp != NULL);
    625 	KASSERT(vp->v_mount == mp);
    626 
    627 	DPRINTF(CALL, ("udf_gro_lock_directory called\n"));
    628 	DPRINTF(LOCKING, ("udf_gro_lock_directory called\n"));
    629 
    630 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    631 
    632 	if (udf_rmdired_p(vp)) {
    633 		VOP_UNLOCK(vp);
    634 		return ENOENT;
    635 	}
    636 
    637 	return 0;
    638 }
    639 
    640 
    641 static const struct genfs_rename_ops udf_genfs_rename_ops = {
    642 	.gro_directory_empty_p		= udf_gro_directory_empty_p,
    643 	.gro_rename_check_possible	= udf_gro_rename_check_possible,
    644 	.gro_rename_check_permitted	= udf_gro_rename_check_permitted,
    645 	.gro_remove_check_possible	= udf_gro_remove_check_possible,
    646 	.gro_remove_check_permitted	= udf_gro_remove_check_permitted,
    647 	.gro_rename			= udf_gro_rename,
    648 	.gro_remove			= udf_gro_remove,
    649 	.gro_lookup			= udf_gro_lookup,
    650 	.gro_genealogy			= udf_gro_genealogy,
    651 	.gro_lock_directory		= udf_gro_lock_directory,
    652 };
    653