オリジナルは http://www.debian.org/ports/hurd/hurd-doc-translator です.

レビュー用に原文との対訳形式にしてあります.

文責:伊藤雅典 (marchan@computer.org)
協力:明嵐さん
$Id: hurd-doc-translator.wml.html,v 1.2 2000-10-24 02:22:13+09 marc Exp marc $


#use wml::debian::template title="Debian GNU/Hurd --- Documentation" NOHEADER="yes" [ Ports ] [ Debian GNU/Hurd ] [ News ] [ Installation ] [ Documentation ] [ Development ] [ Links ] [ Contact ]

Debian GNU/Hurd

トランスレータ

コンセプト

Before we take a closer look at translators, let us consider regular filesystems. A filesystem is store for a hierarchical tree of directories and files. You access directories and files by a special character string, the path. Furthermore, there are symbolic links to refer to one file at several places in the tree, there are hard links to give one and the same file several names. There are also special device files for communication with the hardware device drivers of the kernel, and there are mount points to include other stores in the directory tree. Then there are obscure objects like fifos and hard links.

トランスレータの詳細に入る前に,普通のファイルシステムについて考えてみよう. ファイルシステムとは,ディレクトリとファイルの階層的なツリーの記憶領域である. ディレクトリやファイルにアクセスする時は,パスという特別な文字列を用いる. さらに,シンボリックリンクというものがあって, このツリーの中のどこかにあるファイルを参照することができるし,ハードリンク というものもあって,1つのファイルに複数の名前をつけることができる. また,カーネル内にある,ハードウェアのデバイスドライバとの通信のための 特殊デバイスファイルというものもあるし, ディレクトリツリーに他の記憶領域を含めるために マウントポイントというものもある. それから,fifo やハードリンクのようなわかりにくいオブジェクトもある.

Although these objects are very different, they share some common properties, for example, they have all an owner and a group associated with them as well as access rights (permissions). This information is written in inodes. This is a actually a further commonality: Every object has exactly one inode associated with it (hard links are somewhat special as they share one and the same inode). Sometimes, the inode has further information stored in it. For example, the inode can contain the target of a symbolic link.

これらのオブジェクトは大きく異なるものではあるが, いくつか共通の属性を持っている. 例えば,所有者やグループ,そしてアクセス権(パーミッション)である. この情報は inode に書かれている. 実は,このこと自体,もう一つの共通した属性である. すべてのオブジェクトには,それに対応したただ1つの inode があり, ハードリンクは,1つのまったく同一の inode を共有するので, いくぶん特殊なものである. inode はもっと情報を持っていることがある. 例えば,inode はシンボリックリンク先の情報を持つことができる.

However, these commonalities are usually not exploited in the implementations, despite the common programming interface to them. All inodes can be accessed through the standard POSIX calls, for example read() and write(). For example, to add a new object type (for example a new link type) to a common monolithic unix kernel, you would need to modify the code for each filesystem seperately.

しかしながら,通常こうした共通性は,プログラミング上, 同一のインタフェースを持っているものの,実装上は利用されていない. すべての inode は,例えば read()write() といった 標準 POSIX コールを通してアクセスできる. 例えば,普通のモノリシックな UNIX カーネルに,新規のリンク型のような 新しいオブジェクト型を追加するためには, それぞれのファイルシステムのコードに別々に修正を加えなければならないだろう.

In the Hurd, things work differently. Although in the Hurd a special filesystem server can exploit special properties of standard object types like links (in the ext2 filesystem with fast links, for example), it has a general interface to add such features without modifying existing code.

Hurd では,事情はことなる. Hurd の場合,特別なファイルシステムサーバはリンクのような, 標準的なオブジェクト型の,特別な性質 (例えば,ext2 ファイルシステムにおける高速リンク(fast link)) を利用することができるが, Hurd は既存のコードの修正なしに,このような機能を追加するための一般的な インタフェースを持っている.

The trick is to allow a program to be inserted between the actual content of a file and the user accessing this file. Such a program is called a translator, because it is able to process the incoming requests in many different ways. In other words, a translator is a Hurd server which provides the basic filesystem interface.

そのしかけとは,あるファイルの実際の内容と,このファイルに対する 実際のユーザアクセスの途中に,別のプログラムを挿入するものである. こうしたプログラムはトランスレータと呼ばれ, さまざまな異なった方法によってやってくる要求を処理することができる. 言い替えれば,トランスレータとは,基本的なファイルシステムインタフェースを 提供する Hurd のサーバである.

Translators have very interesting properties. From the kernels point of view, they are just another user process. This means, translators can be run by any user. You don't need root priviligies to install or modify a translator, you only need the access rights for the underlying inode the translator is attached to. Many translators don't require an actual file to operate, they can provide information by their own means. This is why the information about translators is stored in the inode.

トランスレータはとても興味深い特徴を持っている. カーネルの視点からは,単なるユーザプロセスである. これは,トランスレータは任意のユーザによって実行できることを意味している. トランスレータをインストールしたり修正するのにルート権限は必要なく, そのトランスレータが結びつけられた(背景にある) inode に対するアクセス権さえ あればよい. 多くのトランスレータは,自前で情報を吐き出すもので, 実際には層さの対象となるべきファイルを持たない. これは,トランスレータに関する情報が inode に格納されているからである.

Translators are responsible to serve all file system operations that involve the inode they are attached to. Because they are not restricted to the usual set of objects (device file, link etc), they are free to return anything that makes sense to the programmer. One could imagine a translator that behaves like a directory when accessed by cd or ls and at the same time behaves like a file when accessed by cat.

トランスレータは,それが結びつけられている inode に対するファイルシステム操作 のすべてを提供する責任を負う, トランスレータの対象は通常(デバイスファイルやリンクなど)のオブジェクトに限定 されていないので,何でも自由にプログラマに意味のある結果を返すことができる. トランスレータとは,cdls で アクセスされた時にはディレクトリのようにふるまい, cat でアクセスされた時には同時にファイルとして ふるまうようなものとイメージすることができるかもしれない.

マウントポイント

A mount point can be seen as an inode that has a special translator attached to it. Its purpose would be to translate filesystem operations on the mount point in filesystem operations on another store, let's say, another partition.

マウントポイントは,特殊なトランスレータが結びつけられた inode とみなす ことができる. このトランスレータの目的は,マウントポイントに対するファイルシステム操作を, 別の記憶領域(別のパーティションと呼ぼう)へのファイルシステム操作に 変換することである.

Indeed, this is how filesystems are implemented under the Hurd. A filesystem is a translator. This translator takes a store as its argument, and is able to serve all filesystem operations transparently.

まさに,これが Hurd におけるファイルシステムの実装方式である. 1つのファイルシステムは1つのトランスレータである. このトランスレータは記憶領域を引数にとり,すべてのファイルシステム操作を 透過的に提供することができる.

デバイスファイル

There are many different device files, and in systems with a monolithical kernel, they are all provided by the kernel itself. In the Hurd, all device files are provided by translators. One translator can provide support for many similar device files, for example all hard disk partitions. This way, the number of actual translators needed is quite small. However, note that for each device file accessed, a seperate translator task is started. Because the Hurd is heavily multi threaded, this is very cheap.

デバイスファイルには多くの種類があり,モノリシックカーネルによる システムにおいては,これらはすべてカーネル自身によって提供される. Hurd では,すべてのデバイスファイルはトランスレータによって提供される. 1つのトランスレータは,例えばすべてのハードディスクのパーティションのように, 多くの似通ったデバイスファイルに対するサポートを提供することができる. このように,実際に必要とされるトランスレータの数は非常に少ない. しかしながら,アクセス対象のデバイスそれぞれに対して,別々のトランスレータ のタスク(訳注:process相当)が起動されることに注意しなければならない. Hurd は高度にマルチスレッド化されているので,このコストは安い. (FIXME-J: ほんまかいな? TASK 生成のコストって高いと思うんだが…)

When hardware is involved, a translator usually starts to communicate with the kernel to get the data from the hardware. However, if no hardware access is necessary, the kernel does not need to be involved. For example, /dev/zero does not require hardware access, and can therefore be implemented completely in user space.

トランスレータは,普通,ハードウェアが必要とされた時, ハードウェアからデータを得るためにカーネルと通信しはじめる. しかし,ハードウェアにアクセス不要であれば,カーネルは必要とされない. 例えば,/dev/zero はハードウェアアクセスを必要としないので, 完全にユーザ空間で実装可能である.

シンボリックリンク

A symbolic link can be seen as a translator. Accesing the symbolic link would start up the translator, which would forward the request to the filesystem that contains the file the link points to.

シンボリックリンクはトランスレータとみなすことができる. シンボリックリンクに対するアクセスは, トランスレータを起動することになるだろう. アクセス要求は,そのリンクが示すファイルを含むファイルシステムへ転送される.

However, for better performance, filesystems that have native support for symbolic links can take advantage of this feature and implement symbolic links differently. Internally, accessing a symbolic link would not start a new translator process. However, to the user, it would still look as if a passive translator is involved (see below for an explanation what a passsive translator is).

しかし,より良い性能のためには, シンボリックリンクをネイティブサポートしているファイルシステムは この機能を活かし,違うやり方で実装することができるだろう. 内部的には,シンボリックリンクに対するアクセスが新しいトランスレータの プロセスを起動することはないが,ユーザにとっては, パッシブ・トランスレータが関与しているように見えることは変わりない. (パッシブ・トランスレータが何かについては以下の説明を参照のこと)

Because the Hurd ships with a symlink translator, any filesystem server that provides support for translators automatically has support for symlinks (and firmlinks, and device files etc)! This means, you can get a working filesystem very fast, and add native support for symlinks and other features later.

Hurd は symlink トランスレータを提供しているので, トランスレータをサポートするファイルシステムサーバは自動的に symlink (と firmlink と デバイスファイルなど)をサポートする. これは,使い物になる(working)ファイルシステムを とても早く手にすることができるし, symlink や他の機能のネイティブサポートを後から追加できる ということを意味する.

パッシブ・トランスレータ,アクティブ・トランスレータ

There are two types of translators, passive and active. They are really completely different things, so don't mix them up, but they have a close relation to each other.

トランスレータには2つの種類がある.パッシブとアクティブである. これらはまったく異なったものなので,混同しないように. しかし,お互いに密接な関係がある.

アクティブ・トランスレータ

An active translator is a running translator process, as introduced above. You can set and remove active translators using the settrans -a command. The -a option is necessary to tell settrans that you want to modify the active translator.

アクティブ・トランスレータは,上で紹介したように実行中のトランスレータ・ プロセスである. settrans -a コマンドによってアクティブ・トランスレータを セットしたり削除したりできる-a オプションは settrans にアクティブ・トランスレータを操作したいと 教えるのに必要である.

The settrans command takes three kind of arguments. First, you can set options for the settrans command itself, like -a to modify the active translator. Then you set the inode you want to modify. Remember that a translator is always associated with an inode in the directory hierarchy. You can only modify one inode at a time. If you do not specify any more arguments, settrans will try to remove an existing translator. How hard it tries depends on the force options you specify (if the translator is in use by any process, you will get "device or resource busy" error message unless you force it to go away).

settrans コマンドは3種類の引数をとる. 1つめは,アクティブトランスレータに対する操作を示す -a のように,settrans コマンドそのものに 対するオプションである. 次に,変更したい inode を指定する. トランスレータはいつもディレクトリ階層の中の inode に関連づけられいている ことを思い出そう.1回に1つの inode だけ操作することができる. もし,他に何も引数を指定なければ,settrans は 既に動いているトランスレータを削除しようとする. この操作の影響力(FIXME-J: 訳語は?)は,force オプションの指定に依存する. (もし,そのトランスレータが他のプロセスから使用中であれば, そのまま進むよう強制しない限り,"device or resourcebusy" という エラーメッセージが出るだろう.)

But if you specify further arguments, it will be interpreted as a command line to run the translator. This means, the next argument is the filename of the translator executable. Further arguments are options to the translator, and not to the settrans command.

しかし,さらにつけ加えて引数を指定すれば,そのトランスレータを実行するための コマンドライン引数として解釈される. これは,次の引数はトランスレータの実行ファイルのファイル名であることを 意味する. それ以降の引数は, settrans コマンドそのトランスレータに対する引数である.

For example, to mount an ext2fs partition, you can run settrans -a -c /mnt /hurd/ext2fs /dev/hd2s5. The -c option will create the mount point for you if it doesn't exist already. This does not need to be a directory, by the way. To unmount, you would try settrans -a /mnt.

例えば,ext2fs パーティションをマウントするには, settrans -a -c /mnt /hurd/ext2fs /dev/hd2s5 と実行すればよい. -c オプションは,マウントポイントが存在しなければ 作成することを意味する. なお,これ(マウントポイント)はディレクトリである必要はない. マウント解除するには,settrans -a /mnt を実行すればよい.

パッシブ・トランスレータ

A passive translator is set and modified with the same syntax as the active translator (just leave away the -a, so everything said above is true for passive translators, too. However, there is a difference: passive translators are not yet started.

パッシブ・トランスレータは,アクティブ・トランスレータとまったく同じ 文法によって,設定したり削除される. (-a 以外,上述したすべてのことはパッシブ・トランスレータにも あてはまる.) ただし,違いが1つある.パッシブトランスレータはまだ起動されていないのである.

This makes sense, because this is what you usually want. You don't want the partition mounted unless you really access files on this partition. You don't want to bring up the network unless there is some traffic and so on.

これは,普通に要望されることだから意味がある. あるパーティションは,あなたが実際にその上のファイルにアクセスするまで マウントしたくないだろう.また,なんらかのトラフィックが生じるまでネットワーク を起動したくないだろう.

Instead, the first time the passive translator is accessed, it is automatically read out of the inode and an active translator is started on top of it using the command line that was stored in the inode. This is similar to the Linux automounter functionality. However, it does not come as an additional bonus that you have to set up manually, but an integral part of the system. So, setting passive translators defers starting the translator task until you really need it. By the way, if the active translator dies for some reason, the next time the inode is accessed the translator is restarted.

そのかわりに,パッシブ・トランスレータが初めてアクセスされた時に, 自動的に inode を読みだして,その inode に記録されていたコマンドライン オプションを使ってアクティブ・トランスレータが起動される. これは,Linux の automounter と似た機能である. ただし,これはあなたが手動で設定をしたことによる追加のボーナスではなく, システムの肝要な部分の1つである. したがって,パッシブ・トランスレータを設定することは, 必要になった時にトランスレータを起動することとは違う. なお,何らかの理由でアクティブ・トランスレータが死んだ場合, 次にその inode がアクセスされた時にそのトランスレータは再起動される. (FIXME-J: 原文だとこうだが,これってパッシブ・トランスレータのことじゃないの?)

There is a further difference: active translators can die or get lost. As soon as the active translator process is killed (for example, because you reboot the machine) it is lost forever. Passive translators are not transient and stay in the inode during reboots until you modify them with the settrans program or delete the inodes they are attached to. This means, you don't need to maintain a configuration file with your mount points.

この2つには,もっと違いがある. アクティブ・トランスレータは死んだり失われたりする. アクティブ・トランスレータのプロセスが kill されると (たとえば,マシンを reboot した場合), すぐに,その状態は永遠に失われる. パッシブ・トランスレータは settrans プログラムで変更するか, それが結びつけられたinode が削除されない限り, reboot の間もinode の中に存在して一過性のものではない. これは,マウントポイントの設定ファイルを維持する必要がないことを意味する.

One last point: Even if you have set a passive translator, you can still set a different active translator. Only if the translator is automatically started because there was no active translator the time the inode was accessed the passive translator is considered.

最後の1点. パッシブ・トランスレータを設定したとしても, 他の違うアクティブ・トランスレータを設定できる. ある inode がアクセスされる時, 他にアクティブ・トランスレータがいないので自動的にトランスレータが起動される 場合のみ,パッシブトランスレータが対象となる.

トランスレータの管理

As mentioned above, you can use settrans to set and alter passive and active translators. There are a lot of options to change the behaviour of settrans in case something goes wrong, and to conditionalize its action. Here are some common usages:

上で述べたように,パッシブまたはアクティブ・トランスレータを設定したり 変更したりするのには settrans コマンドを使えばよい. 何かうまくいかないときに settrans のふるまいを変えたり, 動きに条件をつけるためのオプションはたくさんある. ここでは一般的な使い方を示す.

You can use the showtrans command to see if a translator is attached to an inode. This will only show you the passive translator though.

あるトランスレータが inode に結びつけられているかどうかを見るには, showtransコマンドを使えばよい. ただし,これはパッシブ・トランスレータのみを表示する.

You can change the options of an active (filesystem) translator with fsysopts without actually restarting it. This is very convenient. For example, you can do what is called "remounting a partition read-only" under Linux simply by running fsysopts /mntpoint --readonly. The running active translator will change its behaviour according to your request if possible. fsysopts /mntpoint without a parameter shows you the current settings.

fsysopts によって,(ファイルシステムの) アクティブ・トランスレータのオプションを, 再起動することなしに変更することが可能である.これはとても便利である. 例えば,Linux で "remounting a partition read-only" と呼ばれていることを, 単にfsysopts /mntpoint --readonly を実行するだけでできる. 実行中のアクティブ・トランスレータは,可能であれば,要求にしたがって 動きを変えるだろう. パラメタなしの fsysopts /mntpoint によって,現在の設定が 表示される.

I recommend that you start by reading the /bin/mount command, it is only a small script. Because setting filesystem translators is similar to mounting partitions, you can easily grasp the concept this way. Make a file system image with dd if=/dev/zero of=dummy.fs bs=1024k count=8; mke2fs dummy.fs and "mount" it with settrans -c dummy /hurd/ext2fs `pwd`/dummy.fs. Note that the translator is not started yet, no new ext2fs process is running (verify with ps Aux). Check that everything is correct using showtrans

/bin/mountコマンド(これは小さなスクリプトである)を読むことから始めるのを推奨する. ファイルシステムのトランスレータを設定するのはパーティションのマウントとよく 似ているので,このやり方で容易にコンセプトを理解できるだろう. ファイルシステムイメージを dd if=/dev/zero of=dummy.fs bs=1024k count=8; mke2fs dummy.fs で作り, settrans -c dummy /hurd/ext2fs `pwd`/dummy.fs "マウント" してみる. このトランスレータはまだ起動されておらず, 新しい ext2fs プロセスが実行されていないこと に注意しよう.(ps Aux によって検証できる). 全てが正しいことを showtrans で確認すること.

Now type ls dummy and you will notice the short delay that occurs while the translator is started. After that, there will be no more delays accessing dummy. Under Linux, one would say that you automounted a loop file system. Check with ps Aux that there is an ext2fs dummy process up and running now. Now put some files into the new directory. Try to make the filesystem read-only with fsysopts. Note how further write attempts fail now. Try to kill the active translator with settrans -g.

さて,ls dummy と入力してみよう. あなたはトランスレータが起動される間,ちょっと待たされるのに気付くだろう. この後,dummy にアクセスするのに待たされることはないだろう. Linux では,あなたは loop ファイルシステムを automount したのだと 言う人がいるかもしれない. ps Aux で,ext2fs dummy プロセスが起動されて 実行中であることを確認しよう. ここで,新しいディレクトリになにかファイルを作成してみよう. fsysopts によって,ファイルシステムを read-only にしてみよう. すると,これ以上の write は失敗することに注意しよう. アクティブ・トランスレータを kill するのに,settrans -g を 試してみよう.

You should have some understanding of what is going on now. Now remember that this was only one special server, the Hurd ext2fs server. There are many more server in the directory. Some of them are for filesystems. Some are needed for file system features like links. Some are needed for device files. Some are useful for networking. Imagine "mounting" an FTP Server with settrans and downloading files simply with the standard cp command. Or editing your web sites with emacs /ftp/homepage.my.server.org/index.html!

今,何が起こっているのか,いくらか理解できただろう. ここで,これはたった一つの特別なサーバ,Hurd の ext2fs サーバ であることを思いおこそう. hurd ディレクトリには,もっとたくさんのサーバがある. その中のいくつかはファイルシステムである. リンクのようなファイルシステムの機能を実現するために必要なものもあるし, デバイスファイルのために必要なものもある. ネットワークのために有用なものもある. FTPサーバを settrans で "マウント" して, 単純に標準的な cp コマンドでファイルをダウンロードすることを想像 してみよう. または,あなたのウェブサイトを emacs /ftp/homepage.my.server.org/index.html という風に編集することを!