include problem
[unix-history] / .ref-BSD-3 / usr / doc / cacm / p1
CommitLineData
8340f87c
BJ
1.ds n \s+2
2.hw above-mentioned
3.ds s \s-2
4.ds m \v'-.3'.\v'.3'
5.TL
6The UNIX
7Time-Sharing System\f1\s10\v'-.2n'*\v'.2n'\s0\fP
8.AU
9D. M. Ritchie and K. Thompson
10.AB
11.FS
12* Copyright 1974,
13Association for Computing Machinery, Inc.,
14reprinted by permission.
15This is a revised version of an article
16that appeared in Communications of the \*sACM\*n,
17.IT 17 ,
18No. 7 (July 1974), pp. 365-375.
19That article was a
20revised version of a paper presented
21at the Fourth \*sACM\*n Symposium on Operating
22Systems Principles,
23\*sIBM\*n Thomas J. Watson Research Center,
24Yorktown Heights,
25New York,
26October 15-17, 1973.
27.FE
28.UX
29is a general-purpose, multi-user, interactive
30operating system for the larger Digital Equipment Corporation
31\*sPDP\*n-11 and
32the Interdata 8/32 computers.
33It offers a number of features
34seldom found even in larger operating
35systems, including
36.IP i
37A hierarchical file system incorporating
38demountable volumes,
39.IP ii
40Compatible file, device, and inter-process I/O,
41.IP iii
42The ability to initiate asynchronous processes,
43.IP iv
44System command language selectable on a per-user basis,
45.IP v
46Over 100 subsystems including a dozen languages,
47.IP vi
48High degree of portability.
49.LP
50This paper discusses the nature
51and implementation of the file system
52and of the user command interface.
53.AE
54.NH
55INTRODUCTION
56.PP
57There have been four versions of
58the
59.UX
60time-sharing system.
61.hy 12
62The earliest (circa 1969-70) ran on
63the Digital Equipment Corporation \*sPDP\*n-7 and -9 computers.
64The second version ran on the unprotected
65\*sPDP\*n-11/20 computer.
66The third incorporated multiprogramming and ran
67on the \*sPDP\*n-11/34, /40, /45, /60, and /70 computers;
68it is the one described in the previously published version
69of this paper, and is also the most widely used today.
70.hy 14
71This paper describes only the
72fourth, current
73system that runs on the \*sPDP\*n-11/70 and the
74Interdata 8/32 computers.
75In fact, the differences among the various systems is
76rather small;
77most of the revisions made to the originally published version of this
78paper,
79aside from those concerned with style,
80had to do with details of the implementation of the file system.
81.PP
82Since
83\*sPDP\*n-11
84.UX
85became operational
86in February, 1971,
87over 600 installations have been put into service.
88Most of them are engaged in applications such as
89computer science education,
90the preparation and formatting of documents
91and other textual material,
92the collection and processing of trouble data
93from various switching machines within the Bell System,
94and recording and checking telephone service
95orders.
96Our own installation is used mainly for research
97in operating systems, languages,
98computer networks,
99and other topics in computer science, and also for
100document preparation.
101.PP
102Perhaps the most important achievement of
103.UX
104is to demonstrate
105that
106a powerful operating system for interactive use
107need not be expensive either in equipment or in human
108effort:
109it
110can run on hardware costing as little as $40,000, and
111less than two man-years were spent on the main system
112software.
113We hope, however, that users find
114that the
115most important characteristics of the system
116are its simplicity, elegance, and ease of use.
117.PP
118Besides the operating system proper, some major programs
119available under
120.UX
121are
122.DS
123.nf
124C compiler
125Text editor based on \*sQED\*n
126.[
127qed lampson
128.]
129Assembler, linking loader, symbolic debugger
130Phototypesetting and equation setting programs
131.[
132cherry kernighan typesetting mathematics cacm
133.]
134.[
135kernighan lesk ossanna document preparation bstj
136%Q This issue
137.]
138.fi
139.in +3n
140.ll -5n
141.ti -3n
142Dozens of languages including
143Fortran 77, Basic, Snobol, \*sAPL\*n, Algol 68, M6, \*sTMG\*n, Pascal
144.in
145.ll
146.DE
147There is a host of maintenance, utility, recreation and novelty programs,
148all written locally.
149The
150.UX
151user community, which numbers in the thousands,
152has contributed many more programs and languages.
153It is worth noting that the system is totally self-supporting.
154All
155.UX
156software is maintained on
157the
158system;
159likewise, this paper and all other
160documents
161in this issue
162were generated and formatted by the
163.UX
164editor and text formatting
165programs.
166.SH
167II. HARDWARE AND SOFTWARE ENVIRONMENT
168.PP
169The \*sPDP\*n-11/70 on which the Research
170.UX
171system is installed is a 16-bit
172word (8-bit byte) computer with 768K bytes of core memory;
173the system kernel
174occupies 90K bytes
175about equally divided between code
176and data tables.
177This system, however, includes a very large number of
178device drivers
179and enjoys a generous allotment
180of space for I/O buffers and system tables;
181a minimal system capable of running the software
182mentioned above can
183require as little as 96K bytes
184of core altogether.
185There are even larger installations;
186see the description of the
187\*sPWB/UNIX\*n systems,
188.[
189dolotta mashey workbench software engineering
190.]
191.[
192dolotta haight mashey workbench bstj
193%Q This issue
194.]
195for example.
196There are also much smaller, though somewhat restricted,
197versions of the system.
198.[
199lycklama microprocessor bstj
200%Q This issue
201.]
202.PP
203Our own \*sPDP\*n-11 has two
204200-Mb moving-head disks
205for file system storage and swapping.
206There are 20 variable-speed
207communications interfaces
208attached to 300- and 1200-baud data sets,
209and an additional 12 communication lines
210hard-wired to 9600-baud terminals and
211satellite computers.
212There are also several 2400- and 4800-baud
213synchronous communication interfaces
214used for machine-to-machine file transfer.
215Finally, there is a variety
216of miscellaneous
217devices including
218nine-track magnetic tape,
219a line printer,
220a voice synthesizer,
221a phototypesetter,
222a digital switching network,
223and a chess machine.
224.PP
225The preponderance of
226.UX
227software is written in the
228abovementioned C language.
229.[
230c programming language kernighan ritchie prentice-hall
231.]
232Early versions of the operating system were written in assembly language,
233but during the summer of 1973, it was rewritten in C.
234The size of the new system was about one-third greater
235than that of the old.
236Since the new system not only became much easier to
237understand and to modify but also
238included
239many functional improvements,
240including multiprogramming and the ability to
241share reentrant code among several user programs,
242we consider this increase in size quite acceptable.
243.SH
244III. THE FILE SYSTEM
245.PP
246The most important role of
247the system
248is to provide
249a file system.
250From the point of view of the user, there
251are three kinds of files: ordinary disk files,
252directories, and special files.
253.SH
2543.1 Ordinary files
255.PP
256A file
257contains whatever information the user places on it,
258for example, symbolic or binary
259(object) programs.
260No particular structuring is expected by the system.
261A file of text consists simply of a string
262of characters, with lines demarcated by the newline character.
263Binary programs are sequences of words as
264they will appear in core memory when the program
265starts executing.
266A few user programs manipulate files with more
267structure;
268for example, the assembler generates, and the loader
269expects, an object file in a particular format.
270However,
271the structure of files is controlled by
272the programs that use them, not by the system.
273.SH
2743.2 Directories
275.PP
276Directories provide
277the mapping between the names of files
278and the files themselves, and thus
279induce a structure on the file system as a whole.
280Each user has a directory of his own files;
281he may also create subdirectories to contain
282groups of files conveniently treated together.
283A directory behaves exactly like an ordinary file except that it
284cannot be written on by unprivileged programs, so that the system
285controls the contents of directories.
286However, anyone with
287appropriate permission may read a directory just like any other file.
288.PP
289The system maintains several directories
290for its own use.
291One of these is the
292.UL root
293directory.
294All files in the system can be found by tracing
295a path through a chain of directories
296until the desired file is reached.
297The starting point for such searches is often the
298.UL root .
299Other system directories contain all the programs provided
300for general use; that is, all the
301.IT commands .
302As will be seen, however, it is by no means necessary
303that a program reside in one of these directories for it
304to be executed.
305.PP
306Files are named by sequences of 14 or
307fewer characters.
308When the name of a file is specified to the
309system, it may be in the form of a
310.IT path
311.IT name ,
312which
313is a sequence of directory names separated by slashes, ``/\^'',
314and ending in a file name.
315If the sequence begins with a slash, the search begins in the
316root directory.
317The name
318.UL /alpha/beta/gamma
319causes the system to search
320the root for directory
321.UL alpha ,
322then to search
323.UL alpha
324for
325.UL beta ,
326finally to find
327.UL gamma
328in
329.UL beta .
330.UL \&gamma
331may be an ordinary file, a directory, or a special
332file.
333As a limiting case, the name ``/\^'' refers to the root itself.
334.PP
335A path name not starting with ``/\^'' causes the system to begin the
336search in the user's current directory.
337Thus, the name
338.UL alpha/beta
339specifies the file named
340.UL beta
341in
342subdirectory
343.UL alpha
344of the current
345directory.
346The simplest kind of name, for example,
347.UL alpha ,
348refers to a file that itself is found in the current
349directory.
350As another limiting case, the null file name refers
351to the current directory.
352.PP
353The same non-directory file may appear in several directories under
354possibly different names.
355This feature is called
356.IT linking ;
357a directory entry for a file is sometimes called a link.
358The
359.UX
360system
361differs from other systems in which linking is permitted
362in that all links to a file have equal status.
363That is, a file does not exist within a particular directory;
364the directory entry for a file consists merely
365of its name and a pointer to the information actually
366describing the file.
367Thus a file exists independently of any
368directory entry, although in practice a file is made to
369disappear along with the last link to it.
370.PP
371Each directory always has at least two entries.
372The name
373``\|\fB.\|\fP'' in each directory refers to the directory itself.
374Thus a program
375may read the current directory under the name ``\fB\|.\|\fP'' without knowing
376its complete path name.
377The name ``\fB\|.\|.\|\fP'' by convention refers to the parent of the
378directory in which it appears, that is, to the directory in which
379it was created.
380.PP
381The directory structure is constrained to have the form
382of a rooted tree.
383Except for the special entries ``\|\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP'', each directory
384must appear as an entry in exactly one other directory, which is its
385parent.
386The reason for this is to simplify the writing of programs
387that visit subtrees of the directory structure, and more
388important, to avoid the separation of portions of the hierarchy.
389If arbitrary links to directories were permitted, it would
390be quite difficult to detect when the last connection from
391the root to a directory was severed.
392.SH
3933.3 Special files
394.PP
395Special files constitute the most unusual feature of the
396.UX
397file system.
398Each supported I/O device
399is associated with at least one such file.
400Special files are read and written just like ordinary
401disk files, but requests to read or write result in activation of the associated
402device.
403An entry for each special file resides in directory
404.UL /dev ,
405although a link may be made to one of these files
406just as it may to an ordinary file.
407Thus, for example,
408to write on a magnetic tape
409one may write on the file
410.UL /dev/mt .
411Special files exist for each communication line, each disk,
412each tape drive,
413and for physical main memory.
414Of course,
415the active disks
416and the memory special file are protected from
417indiscriminate access.
418.PP
419There is a threefold advantage in treating
420I/O devices this way:
421file and device I/O
422are as similar as possible;
423file and device names have the same
424syntax and meaning, so that
425a program expecting a file name
426as a parameter can be passed a device
427name; finally,
428special files are subject to the same
429protection mechanism as regular files.
430.SH
4313.4 Removable file systems
432.PP
433Although the root of the file system is always stored on the same
434device,
435it is not necessary that the entire file system hierarchy
436reside on this device.
437There is a
438.UL mount
439system request with two arguments:
440the name of an existing ordinary file, and the name of a special
441file whose associated
442storage volume (e.g., a disk pack) should have the structure
443of an independent file system
444containing its own directory hierarchy.
445The effect of
446.UL mount
447is to cause
448references to the heretofore ordinary file
449to refer instead to the root directory
450of the file system on the removable volume.
451In effect,
452.UL mount
453replaces a leaf of the hierarchy tree (the ordinary file)
454by a whole new subtree (the hierarchy stored on the
455removable volume).
456After the
457.UL mount ,
458there is virtually no distinction
459between files on the removable volume and those in the
460permanent file system.
461In our installation, for example,
462the root directory resides
463on a small partition of one of
464our disk drives,
465while the other drive,
466which contains the user's files,
467is mounted by the system initialization
468sequence.
469A mountable file system is generated by
470writing on its corresponding special file.
471A utility program is available to create
472an empty file system,
473or one may simply copy an existing file system.
474.PP
475There is only one exception to the rule of identical
476treatment of files on different devices:
477no link may exist between one file system hierarchy and
478another.
479This restriction is enforced so as to avoid
480the elaborate bookkeeping
481that would otherwise be required to assure removal of the links
482whenever the removable volume is dismounted.
483.SH
4843.5 Protection
485.PP
486Although the access control scheme
487is quite simple, it has some unusual features.
488Each user of the system is assigned a unique
489user identification number.
490When a file is created, it is marked with
491the user \*sID\*n of its owner.
492Also given for new files
493is a set of ten protection bits.
494Nine of these specify
495independently read, write, and execute permission
496for the
497owner of the file,
498for other members of his group,
499and for all remaining users.
500.PP
501If the tenth bit is on, the system
502will temporarily change the user identification
503(hereafter, user \*sID\*n)
504of the current user to that of the creator of the file whenever
505the file is executed as a program.
506This change in user \*sID\*n is effective only
507during the execution of the program that calls for it.
508The set-user-\*sID\*n feature provides
509for privileged programs that may use files
510inaccessible to other users.
511For example, a program may keep an accounting file
512that should neither be read nor changed
513except by the program itself.
514If the set-user-\*sID\*n bit is on for the
515program, it may access the file although
516this access might be forbidden to other programs
517invoked by the given program's user.
518Since the actual user \*sID\*n
519of the invoker of any program
520is always available,
521set-user-\*sID\*n programs
522may take any measures desired to satisfy themselves
523as to their invoker's credentials.
524This mechanism is used to allow users to execute
525the carefully written
526commands
527that call privileged system entries.
528For example, there is a system entry
529invokable only by the ``super-user'' (below)
530that creates
531an empty directory.
532As indicated above, directories are expected to
533have entries for ``\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP''.
534The command which creates a directory
535is owned by the super-user
536and has the set-user-\*sID\*n bit set.
537After it checks its invoker's authorization to
538create the specified directory,
539it creates it and makes the entries
540for ``\fB\|.\|\fP'' and ``\fB\|.\|.\|\fP''.
541.PP
542Because anyone may set the set-user-\*sID\*n
543bit on one of his own files,
544this mechanism is generally
545available without administrative intervention.
546For example,
547this protection scheme easily solves the \*sMOO\*n
548accounting problem posed by ``Aleph-null.''
549.[
550aleph null software practice
551.]
552.PP
553The system recognizes one particular user \*sID\*n (that of the ``super-user'') as
554exempt from the usual constraints on file access; thus (for example),
555programs may be written to dump and reload the file
556system without
557unwanted interference from the protection
558system.