Subject: rename of one linked file onto its brother removes the target!
To: None <gnats-bugs@NetBSD.ORG, current-users@NetBSD.ORG>
From: John Kohl <jtk@kolvir.blrc.ma.us>
List: current-users
Date: 11/10/1994 23:38:58
>Submitter-Id:	net
>Originator:	John Kohl
>Organization:
>Confidential:	no
>Synopsis:	rename of one linked file onto its brother removes the target
>Severity:	serious
>Priority:	medium
>Category:	kern
>Class:		sw-bug
>Release:	1.0
>Environment:
System: NetBSD kolvir 1.0 NetBSD 1.0 (KOLVIR) #0: Thu Nov 10 20:10:51 EST 1994 jtk@kolvir:/u1/NetBSD-1.0/src/sys/arch/i386/compile/KOLVIR i386

>Description:
If you link two files, and do a rename("a", "b"), "a" is retained while
"b" is unlinked.  Whoops!

>How-To-Repeat:
% cd /tmp
% mkdir bar
% cd bar
% cp /etc/motd .
% ln motd xxx
% ls -lai
total 4
7 drwxr-xr-x  2 jtk   wheel  512 Nov 10 23:34 .
2 drwxrwxrwt  4 root  wheel  512 Nov 10 23:34 ..
8 -rw-r--r--  2 jtk   wheel   54 Nov 10 23:34 motd
8 -rw-r--r--  2 jtk   wheel   54 Nov 10 23:34 xxx
% mv motd xxx
% ls -lai
total 3
7 drwxr-xr-x  2 jtk   wheel  512 Nov 10 23:34 .
2 drwxrwxrwt  4 root  wheel  512 Nov 10 23:34 ..
8 -rw-r--r--  1 jtk   wheel   54 Nov 10 23:34 motd

>Fix:
	The short-circuit code in ufs_vnops.c:ufs_rename() which calls
to VOP_REMOVE() is short-circuiting the wrong entry.  A quick look
convinced me that I need to think carefully about locking/flags/etc
before touching this code.