Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Sep 1996 01:10:48 -0700 (PDT)
From:      Dmitry Kohmanyuk <dk@dog.farm.org>
To:        pius@iago.ienet.com (Pius Fischer)
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: How to safely remove a hard link to a directory?
Message-ID:  <199609140810.BAA09747@dog.farm.org>

next in thread | raw e-mail | index | archive | help
In article <199609140352.UAA01022@iago.ienet.com> you wrote:

> 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:

> 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

mv(1) or cp(1)  all the files from testdir elsewhere to save them.
(oh, you already emptied it. fine.)

do ls -i <yourdir> and note the inode number.
do df <yourdir> and note the special device name (/dev/xxxx).

then, reboot single-user.  (or just unmount the filesystem in question).

# clri /dev/<yourdevice> <your-damaged-inode>

# fsck /dev/<yourdevice>

you should get a couple of errors (probably 
link count or wrong inode). Answer yes and fix them.

mount your device again, or just reboot multi-user.

> 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 ...

follow the steps above, and remember never do it again ;-)

--
Real programmers don't just die, they produce core dumps.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609140810.BAA09747>