Date: Fri, 13 Sep 1996 20:52:18 -0700 From: Pius Fischer <pius@iago.ienet.com> To: freebsd-hackers@FreeBSD.ORG Subject: How to safely remove a hard link to a directory? Message-ID: <199609140352.UAA01022@iago.ienet.com>
next in thread | raw e-mail | index | archive | help
Oops, I know, I know, I shouldn't have done this, but maybe it's not too late. I think I need some help or advice on what to do now before I do anything that could really screw up the filesystem. On a pre-2.1.5 version of FreeBSD-stable, I wrote a little C program that just passes its first two command line arguments to link(2). That way, when I'm superuser, I can create a hard link to a directory (I won't get into why I wanted to do this). The program is called 'lndir' and here's basically what I did: /home/pius/web>mkdir testdir /home/pius/web>touch testdir/testfile Then I become superuser and do this: /home/pius/web>./lndir testdir testdir2 Now I want to remove both directories: /home/pius/web>rm testdir/testfile /home/pius/web>rm testdir2/testfile rm: testdir2/testfile: No such file or directory /home/pius/web>rmdir testdir2 rmdir: testdir2: Directory not empty /home/pius/web>rmdir testdir rmdir: testdir: Directory not empty /home/pius/web>ls -al testdir2 total 8 drwx------ 3 pius web 512 Sep 13 19:52 . drwx--x--- 6 pius web 512 Sep 13 19:57 .. /home/pius/web>ls -al testdir total 8 drwx------ 3 pius web 512 Sep 13 19:52 . drwx--x--- 6 pius web 512 Sep 13 19:57 .. /home/pius/web> Uh, so now I can't remove either directory and I'm a little afraid of doing an rm -rf or writing a C program that calls unlink(2) before I really know what is going to happen. Of course only after creating this hard link do I read the man page for link(2) on my FreeBSD 2.2-960612-SNAP system and the last couple lines are a little scary ("The link system call traditionally allows the super-user to link directories which corrupts the filesystem coherency."). The man page on the older system had no such warning. I was aware of what Richard Stevens says on p. 101 in his _Advanced Programming in the UNIX environment_ (again, the footnote is kind of scary and so I tried to be careful), but I figured he corrupted his filesystem because he created a hard link to the parent directory, creating a loop, and then tried to unlink the hard link. So, anyways, how can I safely remove these two directories? Maybe I'm a little too paranoid right now, but I'm going to go ahead and backup the important data from this filesystem onto another machine ... Thanks very much for any help, Pius
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609140352.UAA01022>