September 28, 2003

Plan 9 簡介

http://plan9.bell-labs.com/magic/man2html/1/0intro
這是 Plan9 Manual Vol.1 裡的 0 introduction

總論
Plan 9 是由各自獨立的終端機、運算伺服器(CPU Server)、檔案伺服器組合而成的
分散式運算環境。使用者在有圖型視窗界面的終端機上工作。有些視窗會連接到運算
伺服器上,目的要讓大量複雜的運算工作可由強力的伺服器完成,但又同時可由終端機
完成。獨立的檔案伺服器提供終端機與運算伺服器儲存檔案的空間。

命名空間(Name Spaces)

在 Plan 9 的世界中,幾乎所有的物件都被視為檔案。 經由指定名稱所存取到的物件
是由稱之為「命名空間(Name space)」的轉換表而來的。 簡要的說明請查手冊中的
namespace(4)。 所有 Plan 9 執行中的程式都屬於一個執行程序群組 (請參照 fork(2)
中的 rfock),且每個群組的 name space 都可獨立自訂。

Namespace 是階層式的結構。完整的檔名(或稱完整路徑)看起來像 /e1/e2/.../en
,與 UNIX 的檔名型式非常接近。

Plan 9 的服務有很多種,每種都提供了樹狀的檔案結構。Namespace 是由繫結(Bind)
服務(或服務的子樹)到對應的名稱位置所完成的。一般而言,使用者的主要檔案伺服器
是 bind 到 name space 的起點 (root),其它服務則 bind 到對應的子目錄中。

Plan 9 有「聯合目錄(Union directories)」: 由多個目錄共同做成的目錄同時 bind
到同樣的地方。 構成聯合目錄的目錄們會照順序被列出來。當建立 binding 時 (見
bind(1)),可由旗標指定新加入的成員要到序列開頭、結尾,或取代序列。在此聯合
目錄中尋找名稱時,所有成員目錄會照序列的列表順序依次搜尋直到找到對應名稱。
另外還有旗標可指定是否可在成員目錄中建立檔案:新建的檔案會依順序被放到第一
個可供寫入的目錄中。

把 Plan 9 的一切組合在一起朳是稱之為 9P 的網路通訊協定,在手冊中的第五節。
所有的Plan 9 伺服器都會接受與回應 9P 的要求以瀏覽整個檔案樹與執行要求的動作
如讀取或寫入檔案。

啟動
開啟終端機的電源或 reset 時,要指定用來開機的檔案伺服器的名稱、用來開機的
kernel 、還有要使用的使用者名稱與密碼。實際的執行過程隨環境與機器而不同。
開機成功後,終端機會載入一個 Plan 9 kernel 以設定環境變數 (env(3)) 與建立
啟始的 namespace (namespace(4), boot(8), init(8))。其中有些重要的地方是:

* The environment variable $cputype is set to the name of the kernel's CPU's architecture: one of alpha, mips, sparc, power (Power PC), 386 (386, 486, Pentium, ...) etc. The environment variable $objtype is initially the same as $cputype.
* The environment variable $terminal is set to a description of the machine running the kernel, such as generic pc. Sometimes the middle word of $terminal encodes the file from which the kernel is booted; e.g. alpha apc axp is bootstrapped from /alpha/bapc.
* The environment variable $service is set to terminal. (Other ways of accessing Plan 9 may set $service to one of cpu, con, or rx.)
* The environment variable $user is set to the name of the user who booted the terminal. The environment variable $home is set to that user's home directory.
* /$cputype/bin 與 /rc/bin 會被結合到聯合目錄 /bin.

開機後終端機會使用命令解譯器(command interpreter, rc(1))執行 profile:
/usr/$user/lib/profile,然後切到使用者的家目錄。

下列為典型的 profile:

bind -a $home/bin/rc /bin
bind -a $home/bin/$cputype /bin
bind -c $home/tmp /tmp
font = /lib/font/bit/pelm/euro.9.font
upas/fs
switch($service){
case terminal
plumber
prompt=('term% ' ' ')
exec rio -f $font
case cpu
bind /mnt/term/dev/cons /dev/cons
bind /mnt/term/dev/consctl /dev/consctl
bind -a /mnt/term/mnt/wsys /dev
prompt=('cpu% ' ' ')
news
case con
prompt=('cpu% ' ' ')
news
}

The first three lines replace /tmp with a tmp in the user's home directory and union personal bin directories with /bin, to be searched after the standard bin directories. The next starts the mail file system; see mail(1). Then different things happen, depending on the $service environment variable, such as running the window system rio(1) on a terminal.

To do heavy work such as compiling, the cpu(1) command connects a window to a CPU server; the same environment variables are set (to different values) and the same profile is run. The initial directory is the current directory in the terminal window where cpu was typed. The value of $service will be cpu, so the second arm of the profile switch is executed. The root of the terminal's name space is accessible through /mnt/term, so the bind is a way of making the window system's graphics interface (see draw(3)) available to programs running on the CPU server. The news(1) command reports current Plan 9 affairs.

The third possible service type, con, is set when the CPU server is called from a non-Plan-9 machine, such as through telnet (see con(1)).

Using Plan 9
The user commands of Plan 9 are reminiscent of those in Research Unix, version 10. There are a number of differences, however.

The standard shell is rc(1), not the Bourne shell. The most noticeable differences appear only when programming and macro processing.

The character-delete character is backspace, and the line-kill character is control-U; these cannot be changed.

DEL is the interrupt character: typing it sends an interrupt to processes running in that window. See keyboard(6) for instructions on typing characters like DEL on the various keyboards.

If a program dies with something like an address error, it enters a `Broken' state. It lingers, available for debugging with db(1) or acid(1). Broke (see kill(1)) cleans up broken processes.

The standard editor is one of acme(1) or sam(1). There is a variant of sam that permits running the file-manipulating part of sam on a non-Plan-9 system:

sam -r tcp!kremvax

For historical reasons, sam uses a tab stop setting of 8 spaces, while the other editors and window systems use 4 spaces. These defaults can be overridden by setting the value of the environment variable $tabstop to the desired number of spaces per tab.

Machine names may be prefixed by the network name, here tcp; il for the Plan 9 Internet protocol and net for the system default.

Login connections and remote execution on non-Plan-9 machines are usually done by saying, for example,

con kremvax

rx deepthought chess

(see con(1)).

9fs connects to file systems of remote systems (see srv(4)). For example,

9fs kremvax

sets things up so that the root of kremvax's file tree is visible locally in /n/kremvax.

Faces(1) gives graphical notification of arriving mail.

The Plan 9 file server has an integrated backup facility. The command

9fs dump

binds to /n/dump a tree containing the daily backups on the file server. The dump tree has years as top level file names, and month-day as next level file names. For example, /n/dump/2000/0120 is the root of the file system as it appeared at dump time on January 20, 2000. If more than one dump is taken on the same day, dumps after the first have an extra digit. To recover the version of this file as it was on June 15, 1999,

cp /n/dump/1999/0615/sys/man/1/0intro .

or use yesterday(1).

相關資訊
This section for general publicly accessible commands.
手冊第 2 節:程式庫函式,包含系統呼叫。
手冊第 3 節:核心裝置(kernel device, 由 bind(1) 存取)
手冊第 4 節:檔案服務(由 mount 存取)
手冊第 5 節:Plan 9 檔案通訊協定
手冊第 6 節:檔案格式
手冊第 7 節:資料庫與資料庫存取程式
手冊第 8 節:與管理 Plan 9 有關的資訊
/sys/doc 有此手冊參考到的 paper 的複本。

錯誤檢查
每個程式時都會傳回稱之為結束狀態的字串。它是由 exits(2) 呼叫或經由寫入
至 /proc/pid/note 檔案 (參照 proc(3)) 的方式造成非正常結束所產生的。空字串
通常表示正常結束,而非空字串則表示失敗的原因。

Posted by piaip at September 28, 2003 08:09 PM | TrackBack