Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Nov 1995 09:22:05 +0100 (MET)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        freebsd-hackers@freebsd.org (FreeBSD hackers)
Cc:        bob@luke.pmr.com
Subject:   Re: How can I remove hard links between directories?
Message-ID:  <199511270822.JAA03924@uriah.heep.sax.de>
In-Reply-To: <199511270213.VAA23308@skynet.ctr.columbia.edu> from "A boy and his worm gear" at Nov 26, 95 09:13:25 pm

next in thread | previous in thread | raw e-mail | index | archive | help
As A boy and his worm gear wrote:
> 
> > Help!  An apparently buggy version of afio that I was running has
> > created some hard links between a couple of directories on my system

David?  Didn't we nuke the ability to hard-link directories some day
in 1.1.5.1?  Should we nuke this again?

> > (2.1-STABLE) and I need to get rid of them.  Unfortunately rmdir
> > simply complains that the directory is not empty (use counts on
> > these two directries is 4 rather than 2).  Can someone please tell
> > me a way to fix this?

> I can think of one admittedly ugly way to fix this: use clri to zap
> the inode associated with this troublesome directory, then run fsck
> to pick up the pieces afterwards.

It's rather ugly.  Better, use this:

#include <unistd.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
	int status = 0;

	if(argc < 2) {
		fprintf(stderr, "usage: unlink name [...]\n");
		return 1;
	}

	while( ++argv, --argc) {
		if(unlink(*argv) == -1) {
			perror("unlink()");
			status++;
		}
	}
	return status? 1: 0;
}

This used to be availabe as /etc/unlink in ancient systems.  In case
you've botched your system to a degree where you cannot run your C
compiler, here's a binary for it:

begin 755 unlink.gz
M'XL("(9TN3```W5N;&EN:P#M5GUL$V48?Z_MH(RQ+RP,6.1`5!9Q8R88G!D.
M9D64P=:NJ#%XE/6V]NS:IKT;^,'</$>L1TU-T!A#C$3\3Q/_,''$10N;@DK\
M0&(,SF1!C(<C`7%1G"/U>>Z>DVX!_=-_[DG>>][GZ_<^[_-^W0FVMX^5,V8T
MHJ:"OG?+^@V;O8*_?;VO/=`J;-[:O'ZS]ZJ9!=(_J>==V_P9Q95YS)79YE9[
M74PNSFH.]:A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,)MLLLFF_X?PGZ"<9VPE_]^^"7J#=H!O"%H"[OQWH67I4<=W
MHQ4>=!Y_4N`];$(E^&7/3<+O#W#]$O%?@'/`SP!W`#\-W`G\)'`7\,^`%P$_
H"GP6^VY&;B,S9)MLLLDFFVRRR2:;;++))IMLLNG?Z6_T.MT"`"```,^`
`
end
-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



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