MJHD

エモさ駆動開発

ドットファイルが非表示な理由

A lesson in shortcuts. Long ago, as the design of the Unix file system was…より…

Long ago, as the design of the Unix file system was being worked out, the entries . and .. appeared, to make navigation easier. I'm not sure but I believe .. went in during the Version 2 rewrite, when the file system became hierarchical (it had a very different structure early on). When one typed ls, however, these files appeared, so either Ken or Dennis added a simple test to the program. It was in assembler then, but the code in question was equivalent to something like this:
if (name[0] == '.') continue;
This statement was a little shorter than what it should have been, which is
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue;
but hey, it was easy.

日本語:

昔々,UNIXファイルシステムの構想が現れてきた頃,(ディレクトリ間の)移動を楽にするため,「.」「..」という項目が作られた.
これは,私は詳しくは知らないがおそらく,ファイルシステムが階層構造であるバージョン2に書き直される際のことであったと思う.
そのままでは「ls」と打ち込むと,「.」「..」の項目は表示されてしまっていた.
そこで,KenかDennisのどちらかが,ある簡単な判定式を書いた.
この判定式はアセンブリ言語で書かれたものであったが,だいたい以下のようなものであった
if (name[0] == '.') continue;
この文は,本来はあるべき以下のような判定式より,少しだけ短かったのだ
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue;
そう,その方が簡単だったんだ.

ということで,本来項目名全体を比較するべきところを,一文字目が'.'であるかどうかという判定にしてしまったらしい.まぁでも,アセンブリ言語であれば端折りたくもなるよなぁ.

その後,怠惰な他のプログラマたちがこのバグを利用し,「.」から始まる項目を非表示として扱うようになったらしい.