Download Introduction to Operating Systems Abstractions Using Plan 9 from

Transcript
- 159 -
7.5. Name spaces
In Plan 9, we use file names like /usr/nemo. A name is just a string. It is a sequence of characters. However, because it is a file name, we give some meaning to the string. For example, the
name /usr/nemo means:
1
Start at the file named /, which is also known as the root directory.
2
Walk down the file tree to the file with name usr,
3
Walk down again to the file named nemo. You have arrived.
This name specifies a path to walk through the tree of files to reach a particular file of interest, as
shown in figure 7.1. What is a file? Something that you can open, read, write, etc. As long
as the file implements these operations, both you and Plan 9 are happy with it.
/
386
arm
usr
n
tmp
nemo glenda mero
Figure 7.1: A file name is a path to walk in the tree of files.
But how can /, which is just a name, refer to a file? Where does it come from? And why
can a name like /dev/cons refer to different files at different windows? The answers come
from the abstraction used to provide names for files, the name space. In this case, names are for
files, and we will not be saying this explicitly. It should be clear by the context.
A name space is just a set of names that you can use (all the file paths that you might ever
use in your file tree). Somewhat confusingly, the abstraction that provides a name space is also
called a name space. To add more confusion, this is also called a name service.
The name space takes a name, i.e., a string, and translates this name into something that can
be used as a file in Plan 9. This translation is called resolving a name. It takes a name and yields
a Chan, the data structure used to represent a file within the Plan 9 kernel. Thus, you might say
that resolving a name takes a string and yields a file. The translation is done by walking through
the file tree as shown above.
Because Plan 9 is a distributed system, your kernel does not have any data structure to
implement files. This may be a surprise, because in Plan 9 everything is a file, or at least looks
like a file. But Plan 9 does not provide the files itself. Files are provided by other programs that
may be running far away in the network, at different machines. These programs are called file
servers.
File servers implement and maintain file trees, and you may talk to them across the network
to walk their trees and use their files. But you cannot even touch nor see the files, they are kept
inside a file server program, far away. What you can do is to talk to the file server program to ask
it to do whatever you may want to do to the files it keeps. The protocol used to talk (i.e., the language spoken) is called 9P. The section 5 of the system manual documents this protocol. Any
program speaking 9P can be used as a file server for Plan 9.
The conversation between Plan 9 and a file server is made through a network connection. If