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