[comp.unix.questions] /-happy

merritt@iris613.gsfc.nasa.gov (John H Merritt) (08/17/90)

Explain why '/////' is valid in the following statement:

cd /./../tmp/////../././bin

It is interesting that any permutation of '.', '..', '/' and directory
names can be used with, at least, csh, sh, and tcsh to yield a valid
path name.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
John H. Merritt                   #  Yesterday I knew nothing,
Applied Research Corporation      #  Today I know that.
merritt@iris613.gsfc.nasa.gov     #

merlyn@iwarp.intel.com (Randal Schwartz) (08/17/90)

In article <3139@dftsrv.gsfc.nasa.gov>, merritt@iris613 (John H Merritt) writes:
| Explain why '/////' is valid in the following statement:
| 
| cd /./../tmp/////../././bin
| 
| It is interesting that any permutation of '.', '..', '/' and directory
| names can be used with, at least, csh, sh, and tcsh to yield a valid
| path name.

The null pathname (look carefully between the consecutive "/"-s, and
you'll see them there) is a valid synonym for the "current directory".

So aaa////bbb is the same as aaa/././././bbb, except that you don't
have to stat "." four additional times (it'd be fast, but it still
takes time).

Just another Unix hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

tchrist@convex.COM (Tom Christiansen) (08/17/90)

In article <1990Aug16.215045.21300@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes:
>| Explain why '/////' is valid in the following statement:
>| cd /./../tmp/////../././bin
>
>The null pathname (look carefully between the consecutive "/"-s, and
>you'll see them there) is a valid synonym for the "current directory".

Well, only until POSIX, after which a null pathname "" is considered an
error and NOT to be a valid synonym for ".".  However, this case continues
to work because adjacent /'s are to be collapsed in the kernel's path-to-
inode routine (possibly lookuppn() or namei() depending on UNIX flavor).

--tom
--
  "UNIX was never designed to keep people from doing stupid things, because 
   that policy would also keep them from doing clever things." [Doug Gwyn]

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/18/90)

In article <3139@dftsrv.gsfc.nasa.gov> merritt@iris613.gsfc.nasa.gov (John H Merritt) writes:
>Explain why '/////' is valid in the following statement:
>cd /./../tmp/////../././bin
>It is interesting that any permutation of '.', '..', '/' and directory
>names can be used with, at least, csh, sh, and tcsh to yield a valid
>path name.

You're overgeneralizing.
Shells, which must necessarily implement "cd" as a built-in instead of
invoking a subprocess to do the chdir, sometimes are implemented to keep
track internally of the current working directory, especially if they
offer a shell variable that expands to the CWD string.  As a side-effect
of an internal canonicalization of the CWD string, such shells may
themselves try to remove . .. and null pathname components.  It is not
true that the kernel would necessarily accept such a noncanonicalized
string as a valid argument to the chdir() system call.
All the pathname canonicalization algorithms I've encountered so far
have had some undesirable features, such as you mention.  I've been
working on an improved algorithm, but it's not available yet.  Note that
there is no way to handle "whatever/foo/.." where "foo" does not exist
or is not a directory, without consulting the kernel about it, which is
contrary to the whole notion of using pathname canonicalization.

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/18/90)

In article <1990Aug16.215045.21300@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes:
>The null pathname (look carefully between the consecutive "/"-s, and
>you'll see them there) is a valid synonym for the "current directory".

No, it isn't, at least for modern UNIX implementations.

jeff@onion.pdx.com (Jeff Beadles) (08/21/90)

merlyn@iwarp.intel.com (Randal Schwartz) writes:
|>
|>The null pathname (look carefully between the consecutive "/"-s, and
|>you'll see them there) is a valid synonym for the "current directory".
|>
|>So aaa////bbb is the same as aaa/././././bbb, except that you don't
|>have to stat "." four additional times (it'd be fast, but it still
|>takes time).
|>
|>Just another Unix hacker,
|>--
|>/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
|>| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
|>| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
|>\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/


Not true.  (At least in 4.2BSD, and I'm too lazy to check SysV 3.2... :-)
Here's a small snippit of code from sys/ufs_nami.c

        ...
        if (*cp == '/') {
                while (*cp == '/')
                        cp++;
        ...


Thus, the multiple '/' 's are just ignored.

        -Jeff
--
Jeff Beadles  jeff@onion.pdx.com  jeff@quark.wv.tek.com