Copyright ©1993-1998 by Axel T. Schreiner.  All Rights Reserved.



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
{}



Example: host command device

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
{}



Namespace

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.



Devices

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:

perky$ ls -q '#/' root, inplicitly bound to /
80000004.00000000 #/chan
80000001.00000000 #/dev
80000003.00000000 #/net
80000005.00000000 #/nvfs
80000002.00000000 #/prog
perky$ ls -q '#A' audio, sound input and output
00000001.00000000 #A/audio bound to /dev
00000002.00000000 #A/audioctl
perky$ ls -q '#C/cmd' host commands
80000004.00000000 #C/cmd/0 bound to /
00000003.00000000 #C/cmd/clone
perky$ ls -q '#D' SSL, filter for sockets
00000002.00000000 #D/clone bound to /0/ssl etc.
perky$ ls -q '#I' '#I/tcp' '#I/udp' IP, internet connections
80010002.00000000 #I/tcp bound to /net
80000002.00000000 #I/udp
00010003.00000000 #I/tcp/clone
00000003.00000000 #I/udp/clone
perky$ ls -dq '#U' host file system
81000002.336c9483 #U bound to /
perky$ ls -q '#c' console etc., bound to /dev
00000001.00000000 #c/cons console, input and output
00000002.00000000 #c/consctl console, state
00000003.00000000 #c/keyboard keyboard, uninterpreted
00000004.00000000 #c/memory memory allocation state
00000005.00000000 #c/null the void
00000006.00000000 #c/pin PIN, can be written once
00000007.00000000 #c/pointer mouse, position and buttons
00000008.00000000 #c/random random characters
00000009.00000000 #c/sysname host name (shell prompt)
0000000b.00000000 #c/time microseconds since the epoch
0000000a.00000000 #c/user user's name


perky$ # ls '#d' draw device
bound to /dev
perky$ ls -q '#p' '#p/3' processes, bound to /prog
80000010.00000001 #p/1 directory per process id
80000030.00000003 #p/3
00000030.00000003 #p/3/ctl kill, killgrp terminate process
00000031.00000003 #p/3/dbgctl for debugger, controls Dis
0000003a.00000003 #p/3/fd shows file connections
00000032.00000003 #p/3/heap for debugger, look at things
00000033.00000003 #p/3/ns list of all bind/mount operations
00000034.00000003 #p/3/nsgrp PID of namespace group
00000035.00000003 #p/3/pgrp PID or process group
00000036.00000003 #p/3/stack for debugger, shows active modules
00000037.00000003 #p/3/status for ps, process state
00000038.00000003 #p/3/text [not implemented]
00000039.00000003 #p/3/wait blocks until descendant is terminated
perky$ # ls '#s' file2chan() , not bound?



Typical namespace

/appl/ sources
cmd/ commands in /dis
lib/ modules in /dis/lib
math/ commands in /dis/math
wm/ commands in /dis/wm
work/ some unfinished commands?
/chan/ pipes as channels
/demo/dsp/ distributed sports demonstration
/dev/ devices
/dis/ commands and modules
lib/ server, modules
math/ mathematics: fourier analysis, graphics
mux/ set-top-box demonstration
svc/ server, web? httpd webget
wm/ 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
cs/ connection server
db database
namespace namespace for server
namespace.init namespace for wm
/tmp/ temporary files
/usr/ users
inferno/ typical user
keyring/ authentification certificates, privately owned
namespace namespace
wmsetup menu for window system


/Hp/ HP-UX system
/Irix/ Irix (MIPS) system
/Linux/ Linux system
386/ architecture
bin/ external commands: emu limbo mk
include/ C includes
lib/
/Nt/ Windows/NT and Windows 95 system
/Solaris/
386/ Solaris/386 system
sparc/ Solaris/Sparc system

15/Mar/1998