3
File sytems and namespaces
Resources as file systems
Inferno follows Plan 9 in decribing resources as file systems, i.e., that operations like open, read, and write are used to deal with resources such as devices, processes, etc. In particular, a resource can be represented as a dynamic hierarchy of files.
Example: system console device
| perky$ cat < /dev/cons | read from the keyboard | |
| hi | ||
| hi | ||
| control-D | ||
| perky$ echo hello > /dev/cons | write to the screen | |
| hello | ||
| perky$ sh raw >/dev/consctl & cat | raw: no echo, no escapes | |
| abcdefg | input characters not visible | |
| done | for 10 seconds | |
| xyz | ||
| xyz |
A shell script
is used for the demonstration [no initial comment, no arguments]:
{03/raw}
| echo rawon | write turns raw on | |
| sleep 10 | ||
| echo done >/dev/cons |
# to demonstrate 'rawon' for 10 seconds
| # | sh raw >/dev/consctl & cat | close turns raw off |
| perky$ cat '#C/cmd/clone' | get unused (new) directory | |
| 0 |
perky$ sh date >'#C/cmd/0/ctl' <'#C/cmd/0/data'
devcmd: 'date
' pid 235
Wed May 7 13:03:50 MET DST 1997
cat: read error: write to hungup channel
A shell script is used so that both files are open before the command is sent to the host and the answer read back:
{03/date}
echo exec date
cat >/dev/cons
{}
Like Plan 9, Inferno uses a process specific namespace which can be inherited and shared or splitt off or erased with pctl()
.
The shell splits off its own namespace initially, but shares it with spawned commands. Therefore, cd
is a command not built into the shell which, however, cannot affect the original shell when it is used in a shell script.
| perky$ cd /tmp; pwd | expected effect | |
| /tmp | ||
| perky$ echo 'cd /; pwd' > root | ||
| perky$ sh root; pwd | ||
| / | cd applies to script's shell | |
| /tmp | ...but not to toplevel shell |
Similarly, the commands bind, mount and unmount
affect the namespace of the calling shell.
Union directories
bind
rearranges a namespace. Directories or files can be covered (hidden), directories can be joined.
bind source target
| source covers target; a reference to target subsequently finds source. Roughly similar to a symbolic link. |
bind -a source target
| source and target form a union directory; a reference to target subsequently finds both directories, where the content of source appears after that of target. |
bind -b source target
| source and target form a union directory; a reference to target subsequently finds both directories, where the content of source appears before that of target. |
| -c | additionally permits creation of files in the union directory. A new file name is entered |
| into the first directory within a union where creation is possible. |
Because a private directory can be joined to /dis, the shell needs no PATH. Commands are searched in the current directory, and also in /dis unless the command name has ./ at the beginning.
The Inferno kernel recognizes names starting in # followed by one more character. The character selects a device, i.e., a server that is part of the kernel. Devices offer their resources as file systems, i.e., # can be viewed as the root of the kernel's own file system tree that encompasses the devices. The following results were obtained on Linux:
| /appl/ | sources |
| commands in /dis | |
| modules in /dis/lib | |
| commands in /dis/math | |
| commands in /dis/wm | |
| some unfinished commands? | |
| /chan/ | pipes as channels |
| /demo/dsp/ | distributed sports demonstration |
| /dev/ | devices |
| /dis/ | commands and modules |
| server, modules | |
| mathematics: fourier analysis, graphics | |
| set-top-box demonstration | |
| server, web? httpd webget | |
| window system demonstration | |
| /fonts/ | bitmaps for fonts |
| /httpcache/ | |
| /icons/ | |
| /include/ | C includes |
| /keydb/ | CA files |
| /lib/ | data for some programs |
| /licensedb/ | licenses |
| /locale/ | time zones and? |
| /man/ | manual in HTML |
| /module/ | Limbo module imports |
| /movies/ | data for mux |
| /n/ | mount points for network connections |
| /net/ | network connections |
| /nvfs/ | |
| /prog/ | process data |
| /services/ | data for some programs |
| connection server | |
| database | |
| namespace for server | |
| namespace for wm | |
| /tmp/ | temporary files |
| /usr/ | users |
| typical user | |
| authentification certificates, privately owned | |
| namespace | |
| menu for window system |
| /Hp/ | HP-UX system |
| /Irix/ | Irix (MIPS) system |
| /Linux/ | Linux system |
| architecture | |
| external commands: emu limbo mk | |
| C includes | |
| /Nt/ | Windows/NT and Windows 95 system |
| /Solaris/ | |
| Solaris/386 system | |
| Solaris/Sparc system |