Path: utzoo!mnetor!uunet!mcvax!ukc!cheviot!robert
From: robert@cheviot.newcastle.ac.uk (Robert Stroud)
Newsgroups: comp.unix.wizards
Subject: Re: //host vs "mount point"
Message-ID: <2584@cheviot.newcastle.ac.uk>
Date: 4 Dec 87 16:22:51 GMT
References: <648@tut.cis.ohio-state.edu> <1668@tut.cis.ohio-state.edu> <38c15248.4580@hi-csc.UUCP> <9559@mimsy.UUCP> <411@PT.CS.CMU.EDU> <6769@brl-smoke.ARPA>
Reply-To: robert@cheviot (Robert Stroud)
Organization: Computing Laboratory, U of Newcastle upon Tyne, UK NE17RU
Lines: 62

In article <6769@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes:
>In article <411@PT.CS.CMU.EDU> jgm@K.GP.CS.CMU.EDU (John Myers) writes:
>>Just to add to the confusion, let me put in a plug in for the Carnegie-Mellon
>>University Computer Science Department's syntax:
>>/../host
>
>Stolen from the Newcastle Connection.
>
>>"/.." is known as the "super-root".  It seems logically consistent to me...
>
>So, what is the result of
>	$ cd /..
>	$ pwd

/.. of course!!

If you add directories above root (and remember that with the Newcastle
Connection, /.. was just a directory rather than some mysterious 
"super-root") so that it is possible for your current directory to
be in an uncle or cousin relationship with root (rather than a direct
descendent), then you have to modify the pwd algorithm accordingly.

pwd assumes that if you go up the tree with ".." enough times you will
get to root. If your current directory is in a sideways relationship
to root, this assumption will no longer be valid.

The modified pwd algorithm should work like this:

(1) Go up the tree with .. from your current directory until you
find / or reach the base of the tree (a directory which is its own
parent).

(2) If you didn't reach / in (1), then starting from / go up to
the base of the tree with .. and prefix the appropriate number of
/..'s to the string from (1).

For example, after cd /../../C/D, step (1) will give /C/D and step (2)
will give /../.. so the answer is /../../C/D.

This is relatively straightforward to implement. I've made the necessary
modifications to the System V /bin/pwd and sh (which has a built-in pwd)
for use with a kernel implementation of the Newcastle Connection.

The tricky bit is getting the shortest possible pathname. For example,
if / corresponds to /../../A/B in the global naming tree, then after
cd /../C, the modified pwd algorithm would give /../../A/C which is
correct but redundant. (/../../A is the same as /.. if / is /../../A/B).

This can be fixed if you keep a record of everywhere you visit in (1) and
stop in (2) when you reach somewhere you've visited before, but since in
an infinite naming tree this would require an infinite amount of storage
and isn't very efficient in any case, it is easier to simply implement
the algorithm given (which also requires an infinite amount of storage
in the general case of course!) and ignore this problem.

Robert J Stroud,
Computing Laboratory,
University of Newcastle upon Tyne.

ARPA robert%cheviot.newcastle@nss.cs.ucl.ac.uk
UUCP ...!ukc!cheviot!robert
JANET robert@newcastle.cheviot