[comp.bugs.sys5] /etc/link problem via /etc/mvdir

markus@etn-rad.UUCP (Markus Richardson) (05/21/88)

I did something dangerous/stupid but only realized it after the fact.  
(I'm sure I've heard that one before :-)
my . directory looked something like:
	dir1/  dir2/  dir3/  dir4/  dir5/  dir6/  dir7/  dir8/  dir9/

I entered '/etc/mvdir * dir9' thinking (ala /bin/mv) that /etc/mvdir
and /etc/link would be smart enough to catch that I was trying to
link a directory (namely dir9) to itself.  Well, after no error message I 
got alittle panicky and of course did a /bin/ls.  Nothing in the . directory!

Needless to say, I could not locate the directories and associated files
until I did a /etc/fsck.  They all turned out to be UNREFerenced.  What the 
heck happened?   If it matters, I am running SysV.2 on a Plexus.

-- 

        Markus N. Richardson
        Research and Development
        Eaton Corporation IMSD
        31717 La Tienda Drive
        Westlake Village, CA 91359
        
        { voder,ihnp4,trwrb,scgvaxd,jplgodo }!wlbr!etn-rad!markus
          wlbr!etn-rad!markus@etn-wlv.eaton.com

mmengel@cuuxb.ATT.COM (~XT4103000~Marc Mengel~C25~G25~6184~) (05/23/88)

In article <532@etn-rad.UUCP> markus@etn-rad.UUCP (Markus Richardson) writes:
>I did something dangerous/stupid but only realized it after the fact.  
>...
>I entered '/etc/mvdir * dir9' 
>...
>Needless to say, I could not locate the directories and associated files
>until I did a /etc/fsck.  They all turned out to be UNREFerenced.  What the 
>heck happened?   If it matters, I am running SysV.2 on a Plexus.

I assume you moved dir9 into itself, i.e. 

	link("dir9","dir9/dir9");
	link("dir9/dir9/..", "dir9");
	unlink("dir9");

Thereby generating a circular reference (hence the ref count on dir9
was still 1 after the whole proceeding, so no warnings about removing
the last link to a non-empyt directory).

And some people wonder why linking/unlinking directories requires
root permissions under Sys V...
-- 
 Marc Mengel	

 attmail!mmengel
 ...!{moss|lll-crg|mtune|ihnp4}!cuuxb!mmengel

allbery@ncoast.UUCP (Brandon S. Allbery) (06/01/88)

As quoted from <532@etn-rad.UUCP> by markus@etn-rad.UUCP (Markus Richardson):
+---------------
| I did something dangerous/stupid but only realized it after the fact.  
| my . directory looked something like:
| 	dir1/  dir2/  dir3/  dir4/  dir5/  dir6/  dir7/  dir8/  dir9/
| 
| I entered '/etc/mvdir * dir9' thinking (ala /bin/mv) that /etc/mvdir
| and /etc/link would be smart enough to catch that I was trying to
| link a directory (namely dir9) to itself.  Well, after no error message I 
| got alittle panicky and of course did a /bin/ls.  Nothing in the . directory!
+---------------

Check the man pages.  /etc/link is a pure link(2) with NO CHECKING WHATSOEVER
-- it is a tool for repairing a filesystem, NOT intended for general use.

Moral:  be VERY careful when using /etc/mvdir, /etc/link, or /etc/unlink:
these programs deliberately violate the rules which are intended to maintain
the "directed acyclic graph" which is the Unix filesystem, and using them
without caution will cause massive disasters.

(SVR3'ers can ignore the warning about "mvdir", I think:  any system which
implements mkdir(2) and rmdir(2) as primitives should be able to handle
moving directories around a filesystem.  But Plexii run SVR2.)
-- 
	      Brandon S. Allbery, moderator of comp.sources.misc
	{well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery
Delphi: ALLBERY						     MCI Mail: BALLBERY

haugj@pigs.UUCP (John F. Haugh II) (06/06/88)

In article <7850@ncoast.UUCP>, allbery@ncoast.UUCP (Brandon S. Allbery) writes:
> As quoted from <532@etn-rad.UUCP> by markus@etn-rad.UUCP (Markus Richardson):
> +---------------
> | I did something dangerous/stupid but only realized it after the fact.  
> | my . directory looked something like:
> | 	dir1/  dir2/  dir3/  dir4/  dir5/  dir6/  dir7/  dir8/  dir9/
> | 
> | I entered '/etc/mvdir * dir9' thinking (ala /bin/mv) that /etc/mvdir
> | and /etc/link would be smart enough to catch that I was trying to
> | link a directory (namely dir9) to itself.  Well, after no error message I 
> | got alittle panicky and of course did a /bin/ls.  Nothing in the . directory!
> +---------------
> 
> Check the man pages.  /etc/link is a pure link(2) with NO CHECKING WHATSOEVER
> -- it is a tool for repairing a filesystem, NOT intended for general use.
> -- 
> 	      Brandon S. Allbery, moderator of comp.sources.misc

The /etc/mvdir I have does not support multiple arguments so I obviously
don't have the same version as Markus is talking about.

However, the version which I have will not permit a directory to be moved
into another IF the two source is a prefix of the destination.  For example,

	mvdir /etc /etc

fails with the message 'arguments have common path'.  /etc/mvdir is attempting
to move /etc to /etc/etc and finds that /etc is a path prefix of /etc/etc.

The comparision is on a textual basis, so the test fails for any case where
the path contains directories such as `/etc/../etc' or even `/etc/.'.  None
the less, even these cases are detectable and any deviation from `expected'
behavior should be documented, or any paths containing `.' or `..' should
be disallowed.

/etc/mvdir can work without suprizes if properly coded.  In both my case
and Markus', the program is broken.  The user should never be expected to
do with `right' thing without first being warned about what the `wrong'
thing is.

- John.
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!killer!rpp386!jfh                          jfh@rpp386.uucp :SMAILERS

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune