home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / unix / p1 < prev    next >
Encoding:
Text File  |  1975-06-26  |  16.3 KB  |  516 lines

  1. .wh -1i fo
  2. .sp 1.25i
  3. .wh 0 hd
  4. .ps 16
  5. .ft B
  6. .ce
  7. The U\s14NIX\s16 Time-Sharing System
  8. .ft I
  9. .sp  .3i
  10. .ce 2
  11. \*nDennis M. Ritchie
  12. Ken Thompson
  13.  
  14. .ce 2
  15. Bell Laboratories
  16. Murray Hill, N. J. 07974
  17. .fi
  18. .ft B
  19. .sp .5i
  20. .ce
  21. ABSTRACT
  22. .sp
  23. .ft R
  24. U\*sNIX\*n is a general-purpose, multi-user, interactive
  25. operating system for the Digital Equipment Corporation
  26. \*sPDP\*n-11/40, 11/45 and 11/70 computers.
  27. It offers a number of features
  28. seldom found even in larger operating
  29. systems, including
  30. .br
  31. .tr |
  32. .de dl
  33. .sp .3
  34. .ti -\w'1.|'u
  35. ..
  36. .in .5i
  37. .dl
  38. 1.|A hierarchical file system incorporating
  39. demountable volumes,
  40. .dl
  41. 2.|Compatible file, device, and inter-process I/O,
  42. .dl
  43. 3.|The ability to initiate asynchronous processes,
  44. .dl
  45. 4.|System command language selectable on a per-user basis,
  46. .dl
  47. 5.|Over 100 subsystems including a dozen languages.
  48. .sp .3
  49. .in 0
  50. .tr ||
  51. This paper discusses the nature
  52. and implementation of the file system
  53. and of the user command interface.
  54. .sp 2.0
  55. .ft B
  56. 1. Introduction
  57. .es
  58. There have been three versions of \*sUNIX\*n.
  59. The earliest version (circa 1969-70) ran on
  60. the Digital Equipment Corporation \*sPDP\*n-7 and -9 computers.
  61. The second version ran on the unprotected
  62. \*sPDP\*n-11/20 computer.
  63. This paper describes only the \*sPDP\*n-11/40, /45 and /70\*r system,
  64. since it is more modern and
  65. many of the differences between it and older \*sUNIX\*n systems result from
  66. redesign of features found to be deficient or lacking.
  67. .pg
  68. Since \*sPDP\*n-11 \*sUNIX\*n became operational
  69. in February, 1971,
  70. about 100 installations have been put into service;
  71. they are generally smaller
  72. than the system described here.
  73. Most of them are engaged in applications such as
  74. the preparation and formatting of patent applications
  75. and other textual material,
  76. the collection and processing of trouble data
  77. from various switching machines within the Bell System,
  78. and recording and checking telephone service
  79. orders.
  80. Our own installation is used mainly for research
  81. in operating systems, languages,
  82. computer networks,
  83. and other topics in computer science, and also for
  84. document preparation.
  85. .br
  86. .sp
  87. \l'2i'
  88. .ps 8
  89. .vs 9p
  90. .pg
  91. Copyright \(co 1974,
  92. Association for Computing Machinery, Inc.
  93. General permission to republish,
  94. but not for profit,
  95. all or part of this material
  96. is granted provided that \s7ACM\s8's copyright
  97. notice is given and that reference is made to the publication,
  98. to its date of issue,
  99. and to the fact that reprinting privileges were granted by
  100. permission of the Association for Computing Machinery.
  101. .pg
  102. This is a revised version of an article
  103. appearing in the Communications of the \s7ACM\s8,
  104. Volume 17, Number 7 (July 1974) pp. 365-375.
  105. That article is a
  106. revised version of a paper presented
  107. at the Fourth \s7ACM\s8 Symposium on Operating
  108. Systems Principles,
  109. \s7IBM\s8 Thomas J. Watson Research Center,
  110. Yorktown Heights,
  111. New York,
  112. October 15-17, 1973.
  113. .br
  114. .ps 10
  115. .vs 12p
  116. .bp
  117. .pg
  118. Perhaps the most important achievement of \*sUNIX\*n is to demonstrate
  119. that
  120. a powerful operating system for interactive use
  121. need not be expensive either in equipment or in human
  122. effort:
  123. \*sUNIX\*n can run on hardware costing as little as $40,000, and
  124. less than two man-years were spent on the main system
  125. software.
  126. Yet \*sUNIX\*n contains a number of features
  127. seldom offered even in much larger systems.
  128. Hopefully, however, the users of \*sUNIX\*n will find that the
  129. most important characteristics of the system
  130. are its simplicity, elegance, and ease of use.
  131. .pg
  132. Besides the system proper, the major programs
  133. available under \*sUNIX\*n are
  134. .sp 1.0
  135. .ne 3
  136. .in .75i
  137. .ne 3
  138. .ti .5i
  139. assembler,
  140. .ti .5i
  141. text editor based on \*sQED\*n\*r,
  142. .ti .5i
  143. linking loader,
  144. .ti .5i
  145. symbolic debugger,
  146. .ti .5i
  147. compiler for a language resembling \*sBCPL\*n\*r with types and structures (C),
  148. .ti .5i
  149. interpreter for a dialect of \*sBASIC\*n,
  150. .ti .5i
  151. phototypesetting and equation setting programs
  152. .ti .5i
  153. Fortran compiler,
  154. .ti .5i
  155. Snobol interpreter,
  156. .ti .5i
  157. top-down compiler-compiler (\*sTMG\*n\*r),
  158. .ti .5i
  159. bottom-up compiler-compiler (\*sYACC\*n),
  160. .ti .5i
  161. form letter generator,
  162. .ti .5i
  163. macro processor (M6\*r),
  164. .ti .5i
  165. permuted index program.
  166. .sp .5
  167. .in 0
  168. .fi
  169. There is also a host of maintenance, utility, recreation and novelty programs.
  170. All of these programs were written locally.
  171. It is worth noting that the system is totally self-supporting.
  172. All \*sUNIX\*n software is maintained under \*sUNIX\*n;
  173. likewise, this paper and all other \*sUNIX\*n
  174. documents
  175. were generated and formatted by the \*sUNIX\*n editor and text formatting
  176. program.
  177. .s1
  178. 2. Hardware and software environment
  179. .es
  180. The \*sPDP\*n-11/45 on which our \*sUNIX\*n installation is implemented is a 16-bit
  181. word (8-bit byte) computer with 112K bytes of core memory;
  182. \*sUNIX\*n occupies 53K bytes.
  183. This system, however, includes a very large number of
  184. device drivers
  185. and enjoys a generous allotment
  186. of space for I/O buffers and system tables;
  187. a minimal system capable of running the software
  188. mentioned above can
  189. require as little as 64K bytes
  190. of core altogether.
  191. .pg
  192. Our \*sPDP\*n-11 has a 1M byte fixed-head disk, used
  193. for file system storage and swapping,
  194. four moving-head disk drives which each provide 2.5M bytes
  195. on removable disk cartridges,
  196. and a single moving-head disk drive which
  197. uses removable 40M byte disk packs.
  198. There are also a high-speed paper tape reader-punch,
  199. nine-track magnetic tape,
  200. and \*sDEC\*ntape (a variety
  201. of magnetic tape facility in which individual records
  202. may be addressed and rewritten).
  203. Besides the console typewriter, there are 30 variable-speed
  204. communications interfaces
  205. attached to 100-series datasets
  206. and a 201 dataset interface used
  207. primarily for spooling printout to
  208. a communal line printer.
  209. There are also several one-of-a-kind
  210. devices including a Picturephone\(rg interface,
  211. a voice response unit,
  212. a voice synthesizer,
  213. a phototypesetter,
  214. a digital switching network,
  215. and a satellite \*sPDP\*n-11/20
  216. which generates vectors, curves, and characters on a Tektronix
  217. 611 storage-tube display.
  218. .pg
  219. The greater part of \*sUNIX\*n software is written in the
  220. above-mentioned C language\*r.
  221. Early versions of the operating system were written in assembly language,
  222. but during the summer of 1973, it was rewritten in C.
  223. The size of the new system is about one third greater
  224. than the old.
  225. Since the new system is not only much easier to
  226. understand and to modify but also
  227. includes
  228. many functional improvements,
  229. including multiprogramming and the ability to
  230. share reentrant code among several user programs,
  231. we considered this increase in size quite acceptable.
  232. .s1
  233. 3. The File system
  234. .es
  235. The most important role of \*sUNIX\*n is to provide
  236. a file system.
  237. From the point of view of the user, there
  238. are three kinds of files: ordinary disk files,
  239. directories, and special files.
  240. .s2
  241. 3.1 Ordinary files
  242. .es
  243. A file
  244. contains whatever information the user places on it,
  245. for example symbolic or binary
  246. (object) programs.
  247. No particular structuring is expected by the system.
  248. Files of text consist simply of a string
  249. of characters, with lines demarcated by the new-line character.
  250. Binary programs are sequences of words as
  251. they will appear in core memory when the program
  252. starts executing.
  253. A few user programs manipulate files with more
  254. structure;
  255. for example, the assembler generates, and the loader
  256. expects, an object file in a particular format.
  257. However,
  258. the structure of files is controlled by
  259. the programs which use them, not by the system.
  260. .s2
  261. 3.2 Directories
  262. .es
  263. Directories provide
  264. the mapping between the names of files
  265. and the files themselves, and thus
  266. induce a structure on the file system as a whole.
  267. Each user has a directory of his own files;
  268. he may also create subdirectories to contain
  269. groups of files conveniently treated together.
  270. A directory behaves exactly like an ordinary file except that it
  271. cannot be written on by unprivileged programs, so that the system
  272. controls the contents of directories.
  273. However, anyone with
  274. appropriate permission may read a directory just like any other file.
  275. .pg
  276. The system maintains several directories
  277. for its own use.
  278. One of these is the \fIroot\fR directory.
  279. All files in the system can be found by tracing
  280. a path through a chain of directories
  281. until the desired file is reached.
  282. The starting point for such searches is often the
  283. root.
  284. Another system directory contains all the programs provided
  285. for general use; that is, all the \fIcommands\fR.
  286. As will be seen, however, it is by no means necessary
  287. that a program reside in this directory for it
  288. to be executed.
  289. .pg
  290. Files are named by sequences of 14 or
  291. fewer characters.
  292. When the name of a file is specified to the
  293. system, it may be in the form of a
  294. .ft I
  295. path name,
  296. .ft R
  297. which
  298. is a sequence of directory names separated by slashes ``\|/\|''
  299. and ending in a file name.
  300. If the sequence begins with a slash, the search begins in the
  301. root directory.
  302. The name \fI/\|alpha\|/\|beta\|/\|gamma\fR causes the system to search
  303. the root for directory \fIalpha,\fR
  304. then to search \fIalpha\fR for \fIbeta,\fR
  305. finally to find \fIgamma\fR in \fIbeta\fR.
  306. \fIGamma\fR may be an ordinary file, a directory, or a special
  307. file.
  308. As a limiting case, the name ``/\|'' refers to the root itself.
  309. .pg
  310. A path name not starting with ``/\|'' causes the system to begin the
  311. search in the user's current directory.
  312. Thus, the name \fIalpha\|/\|beta\fR specifies the file named \fIbeta\fR in
  313. subdirectory \fIalpha\fR of the current
  314. directory.
  315. The simplest kind of name, for example \fIalpha\fR,
  316. refers to a file which itself is found in the current
  317. directory.
  318. As another limiting case, the null file name refers
  319. to the current directory.
  320. .pg
  321. The same non-directory file may appear in several directories under
  322. possibly different names.
  323. This feature is called \fIlinking;\fR
  324. a directory entry for a file is sometimes called a link.
  325. \*sUNIX\*n differs from other systems in which linking is permitted
  326. in that all links to a file have equal status.
  327. That is, a file does not exist within a particular directory;
  328. the directory entry for a file consists merely
  329. of its name and a pointer to the information actually
  330. describing the file.
  331. Thus a file exists independently of any
  332. directory entry, although in practice a file is made to
  333. disappear along with the last link to it.
  334. .pg
  335. Each directory always has at least two entries.
  336. The name
  337. ``\|\fB.\|\fR'' in each directory refers to the directory itself.
  338. Thus a program
  339. may read the current directory under the name ``\fB\|.\|\fR'' without knowing
  340. its complete path name.
  341. The name ``\fB\|.\|.\|\fR'' by convention refers to the parent of the
  342. directory in which it appears, that is, to the directory in which
  343. it was created.
  344. .pl +1
  345. .pg
  346. The directory structure is constrained to have the form
  347. of a rooted tree.
  348. Except for the special entries ``\|\fB\|.\|\fR'' and ``\fB\|.\|.\|\fR'', each directory
  349. must appear as an entry in exactly one other, which is its
  350. parent.
  351. The reason for this is to simplify the writing of programs
  352. which visit subtrees of the directory structure, and more
  353. important, to avoid the separation of portions of the hierarchy.
  354. If arbitrary links to directories were permitted, it would
  355. be quite difficult to detect when the last connection from
  356. the root to a directory was severed.
  357. .s2
  358. .pl -1
  359. 3.3 Special files
  360. .es
  361. Special files constitute the most unusual feature of the \*sUNIX\*n
  362. file system.
  363. Each I/O device supported by \*sUNIX\*n
  364. is associated with at least one such file.
  365. Special files are read and written just like ordinary
  366. disk files, but requests to read or write result in activation of the associated
  367. device.
  368. An entry for each special file resides in directory \fI/\|dev,\fR
  369. although a link may be made to one of these files
  370. just like an ordinary file.
  371. Thus, for example,
  372. to punch paper tape,
  373. one may write on the file \fI\|/\|dev\|/\|ppt\fR.
  374. Special files exist for each communication line, each disk,
  375. each tape drive,
  376. and for physical core memory.
  377. Of course,
  378. the active disks
  379. and the core special file are protected from
  380. indiscriminate access.
  381. .pg
  382. There is a threefold advantage in treating
  383. I/O devices this way:
  384. file and device I/O
  385. are as similar as possible;
  386. file and device names have the same
  387. syntax and meaning, so that
  388. a program expecting a file name
  389. as a parameter can be passed a device
  390. name; finally,
  391. special files are subject to the same
  392. protection mechanism as regular files.
  393. .s2
  394. 3.4 Removable file systems
  395. .es
  396. Although the root of the file system is always stored on the same
  397. device,
  398. it is not necessary that the entire file system hierarchy
  399. reside on this device.
  400. There is a \fImount\fR system request which has two arguments:
  401. the name of an existing ordinary file, and the name of a special
  402. file whose associated
  403. storage volume (e. g. disk pack) should have the structure
  404. of an independent file system
  405. containing its own directory hierarchy.
  406. The effect of \fImount\fR is to cause
  407. references to the heretofore ordinary file
  408. to refer instead to the root directory
  409. of the file system on the removable volume.
  410. In effect, \fImount\fR
  411. replaces a leaf of the hierarchy tree (the ordinary file)
  412. by a whole new subtree (the hierarchy stored on the
  413. removable volume).
  414. After the \fImount\fR,
  415. there is virtually no distinction
  416. between files on the removable volume and those in the
  417. permanent file system.
  418. In our installation, for example,
  419. the root directory resides
  420. on the fixed-head disk,
  421. and the large disk drive, which contains user's files,
  422. is mounted by the system initialization
  423. program;
  424. the four smaller disk drives are available
  425. to users for mounting their
  426. own disk packs.
  427. A mountable file system is generated by
  428. writing on its corresponding special file.
  429. A utility program is available to create
  430. an empty file system,
  431. or one may simply copy an existing file system.
  432. .pg
  433. There is only one exception to the rule of identical
  434. treatment of files on different devices:
  435. no link may exist between one file system hierarchy and
  436. another.
  437. This restriction is enforced so as to avoid
  438. the elaborate bookkeeping
  439. which would otherwise be required to assure removal of the links
  440. when the removable volume is finally dismounted.
  441. In particular, in the root directories of
  442. all file systems, removable or not, the
  443. name
  444. ``\fB\|.\|.\|\fR''
  445. refers to the directory itself instead of to its parent.
  446. .s2
  447. 3.5 Protection
  448. .es
  449. Although the access control scheme in \*sUNIX\*n
  450. is quite simple, it has some unusual features.
  451. Each user of the system is assigned a unique
  452. user identification number.
  453. When a file is created, it is marked with
  454. the user \*sID\*n of its owner.
  455. Also given for new files
  456. is a set of seven protection bits.
  457. Six of these specify
  458. independently read, write, and execute permission
  459. for the
  460. owner of the file and for all other users.
  461. .pg
  462. If the seventh bit is on, the system
  463. will temporarily change the user identification
  464. of the current user to that of the creator of the file whenever
  465. the file is executed as a program.
  466. This change in user \*sID\*n is effective only
  467. during the execution of the program which calls for it.
  468. The set-user-\*sID\*n feature provides
  469. for privileged programs which may use files
  470. inaccessible to other users.
  471. For example, a program may keep an accounting file
  472. which should neither be read nor changed
  473. except by the program itself.
  474. If the set-user-identification bit is on for the
  475. program, it may access the file although
  476. this access might be forbidden to other programs
  477. invoked by the given program's user.
  478. Since the actual user \*sID\*n
  479. of the invoker of any program
  480. is always available,
  481. set-user-\*sID\*n programs
  482. may take any measures desired to satisfy themselves
  483. as to their invoker's credentials.
  484. This mechanism is used to allow users to execute
  485. the carefully-written
  486. commands
  487. which call privileged system entries.
  488. For example, there is a system entry
  489. invokable only by the ``super-user'' (below)
  490. which creates
  491. an empty directory.
  492. As indicated above, directories are expected to
  493. have entries for ``\fB\|.\|\fR'' and ``\fB\|.\|.\|\fR''.
  494. The command which creates a directory
  495. is owned by the super-user
  496. and has the set-user-\*sID\*n bit set.
  497. After it checks its invoker's authorization to
  498. create the specified directory,
  499. it creates it and makes the entries
  500. for ``\fB\|.\|\fR'' and ``\fB\|.\|.\|\fR''.
  501. .pg
  502. Since anyone may set the set-user-\*sID\*n
  503. bit on one of his own files,
  504. this mechanism is generally
  505. available without administrative intervention.
  506. For example,
  507. this protection scheme easily solves the \*sMOO\*n
  508. accounting problem posed in [\n+r].
  509. .pg
  510. The system recognizes one particular user \*sID\*n (that of the ``super-user'') as
  511. exempt from the usual constraints on file access; thus (for example)
  512. programs may be written to dump and reload the file
  513. system without
  514. unwanted interference from the protection
  515. system.
  516.