[comp.unix.questions] Cyclic directories

dold@mitisft.Convergent.COM (Clarence Dold) (11/10/89)

in article <1021@icus.islp.ny.us>, lenny@icus.islp.ny.us (Lenny Tropiano) says:

> It was fsck'ing "/" root like it should have, and it said something about
> a directory link was wrong, adjust.  I did.  Then it said something
> about an unreferenced directory, should it reconnect.  I said yes again.

> # ls -liF /lost+found
> total 1
>  3388 drwxr-xr-x  3 lenny   icus         48 Nov  5 01:27 003388/

> # cd /lost+found/003388
> # ls -liF 
> total 1
>  3388 drwxr-xr-x  3 lenny   icus         48 Nov  5 01:27 icus/

> Now I thought that was strange, the i-nodes were the same.  Of course
> it pointed around in circles!

Because there was discussion of 'cc -o *.c' on the net recently, I am 
making the assumption that you toyed around with the possibilities.
If the super-user does 'cc -o junk junk.c', where junk happened to
be a directory, you will arrive at the above mentioned situation.
A normal user can't unlink a directory, but the super can, which is
exactly what ld does.
fsck can't figure out what to do, as you've noticed.
-- 
---
Clarence A Dold - dold@tsmiti.Convergent.COM		(408) 434-5293
		...pyramid!ctnews!tsmiti!dold
		P.O.Box 6685, San Jose, CA 95150-6685	MS#10-007

jbm@uncle.UUCP (John B. Milton) (11/11/89)

In article <1285@mitisft.Convergent.COM> dold@mitisft.Convergent.COM (Clarence Dold) writes:
>in article <1021@icus.islp.ny.us>, lenny@icus.islp.ny.us (Lenny Tropiano) says:
[found cyclic dir in lost+found, etc]
[dirs can be unlinked by root]

All this brings up a whole set of nasty things in UNIX. The fact that
directories can be linked is why . and .. work. The fact that mkdir and rmdir
use simple mknod/link/link and unlink/unlink/unlink (at least on our flavor of
UNIX) means that crashes during incomplete updates of either of these can leave
weird things. Since root can do link and unlink on directories, then root CAN
"corrupt" the disk:

{
  system("mkdir a"); /* we now have a, a/. and a/.. */
  unlink("a"); /* now a/. is floating and a/.. has a bad link count */
}

This kind of corruption is not harmful, but does give fsck some work to do.

As far as using linked directories, there are some interesting applications.
The down side is that the UNIX utilities were not designed to deal with the
problems, like cpio making two copies and du showing too much. Another
problem with linked directories comes when they are dismantled. If rmdir
is used, then the . and .. entries are lost.

The fact that fsck doesn't do anything about strange directory links is
probably weak support for the feature, since it can't be used if fsck keeps
undoing it. This is like linking on DOS, where it can be done, but chkdsk
does not like it.

John
-- 
John Bly Milton IV, jbm@uncle.UUCP, n8emr!uncle!jbm@osu-cis.cis.ohio-state.edu
(614) h:252-8544, w:785-1110; N8KSN, AMPR: 44.70.0.52; Don't FLAME, inform!