When the source and destination objects for VOP_RENAME() are the same,
POSIX advice to just ignore the operation and return 0. We already handle this case in kern_rename(), but don't give bad example - the source is not removed.
This commit is contained in:
parent
479a8f8dd7
commit
162ce1a75f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=163990
@ -104,34 +104,13 @@ vop_rename(struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if just deleting a link name.
|
* POSIX: "If the old argument and the new argument
|
||||||
|
* both refer to links to the same existing file,
|
||||||
|
* the rename() function shall return successfully
|
||||||
|
* and perform no other action."
|
||||||
|
* The upper layers already handle this case.
|
||||||
*/
|
*/
|
||||||
if (fvp == tvp) {
|
KASSERT(fvp != tvp, ("vop_rename: source and destination are the same"));
|
||||||
if (fvp->v_type == VDIR) {
|
|
||||||
error = EINVAL;
|
|
||||||
goto abortit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Release destination.
|
|
||||||
*/
|
|
||||||
vput(tdvp);
|
|
||||||
vput(tvp);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Delete source. Pretty bizarre stuff.
|
|
||||||
*/
|
|
||||||
vrele(fdvp);
|
|
||||||
vrele(fvp);
|
|
||||||
fcnp->cn_flags &= ~MODMASK;
|
|
||||||
fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
|
|
||||||
fcnp->cn_nameiop = DELETE;
|
|
||||||
VREF(fdvp);
|
|
||||||
error = relookup(fdvp, &fvp, fcnp);
|
|
||||||
if (error == 0)
|
|
||||||
vrele(fdvp);
|
|
||||||
return VOP_REMOVE(fdvp, fvp, fcnp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fvp is immutable) {
|
if (fvp is immutable) {
|
||||||
error = EPERM;
|
error = EPERM;
|
||||||
|
Loading…
Reference in New Issue
Block a user