9fans archive / 1995 / 03 / 7 / prev next
From: serge@eul... serge@eul...
Subject: no need for cd
Date: Wed, 8 Mar 1995 16:27:13 -0500
Just for fun (:-), given that
+ current working directory is a (per-)process (file system)
specific information
and
+ Plan9/Brazil/VSTa/(Mach?) have a general mechanism for manipulating
this (i.e. mount)
then
+ it may be possible to eliminate/emulate cd/pwd via mount, e.g.
+ reserve (by convention only, of course :-) a
directory, say "/@" (a fat ".", ala sam :-), or
possibly something else, easier to type, e.g. without
the need for a shift key, say ",")
+ in libc/kernel: chdir(char *dir) { mount(dir, "/@"); }
+ in rc/sh/bin: fn pwd { mount | grep /@ | awk ... }
+ make the kernel prepend the string "/@" if the file
name does not begin with "/" and resolve the pathname again
It may also be possible to eliminate "." and "..", but only if they are
the first (and only, e.g. no "./." or "../..") thing at the front of a
pathname, since then they refer to process specific state (anywhere
else in a pathname they refer to a directory specific state):
+ reserve (by convention again :-) a directory, say /@@
(see above :-)
+ in libc/kernel: chdir(char *dir) {
mount(dir, "/@");
mount(basename(dir), "/@@"); }
+ make the kernel translate leading "./" and "../" to
"/@/" and "/@@/ (for compatibility only, e.g. new
programs don't need that and can use "/@" and "/@@"
directly)
Come to think of it, if the kernel just threw out (ala sed) all
occurrences of "./" and "xxx/../" in pathnames, we wouldn't even need
the above. (Didn't the Plan9 people say that mount entries are hashed,
so that ".." can refer to arbitrary directories, depending on what
you've mounted? E.g. this won't change any semantics.) We might even
be able call use "/." instead of "/@" and "/.." instead of "/@@".
(It's been too quiet here lately :-)