add Berkeley specific copyright notice
[unix-history] / usr / src / share / doc / smm / 05.fastfs / 5.t
CommitLineData
9299c540
KB
1.\" Copyright (c) 1986 The Regents of the University of California.
2.\" All rights reserved.
bade79af 3.\"
9299c540
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)5.t 6.2 (Berkeley) %G%
bade79af
KD
17.\"
18.ds RH Functional enhancements
19.NH
20File system functional enhancements
21.PP
c20eb73f
KD
22The performance enhancements to the
23UNIX file system did not require
24any changes to the semantics or
25data structures visible to application programs.
26However, several changes had been generally desired for some
27time but had not been introduced because they would require users to
bade79af
KD
28dump and restore all their file systems.
29Since the new file system already
c20eb73f 30required all existing file systems to
bade79af 31be dumped and restored,
c20eb73f 32these functional enhancements were introduced at this time.
bade79af
KD
33.NH 2
34Long file names
35.PP
36File names can now be of nearly arbitrary length.
c20eb73f
KD
37Only programs that read directories are affected by this change.
38To promote portability to UNIX systems that
bade79af 39are not running the new file system, a set of directory
c20eb73f 40access routines have been introduced to provide a consistent
bade79af
KD
41interface to directories on both old and new systems.
42.PP
c20eb73f 43Directories are allocated in 512 byte units called chunks.
bade79af 44This size is chosen so that each allocation can be transferred
c20eb73f
KD
45to disk in a single operation.
46Chunks are broken up into variable length records termed
47directory entries. A directory entry
48contains the information necessary to map the name of a
49file to its associated inode.
50No directory entry is allowed to span multiple chunks.
51The first three fields of a directory entry are fixed length
52and contain: an inode number, the size of the entry, and the length
53of the file name contained in the entry.
54The remainder of an entry is variable length and contains
55a null terminated file name, padded to a 4 byte boundary.
56The maximum length of a file name in a directory is
57currently 255 characters.
58.PP
59Available space in a directory is recorded by having
60one or more entries accumulate the free space in their
61entry size fields. This results in directory entries
62that are larger than required to hold the
63entry name plus fixed length fields. Space allocated
64to a directory should always be completely accounted for
65by totaling up the sizes of its entries.
66When an entry is deleted from a directory,
67its space is returned to a previous entry
68in the same directory chunk by increasing the size of the
69previous entry by the size of the deleted entry.
70If the first entry of a directory chunk is free, then
71the entry's inode number is set to zero to indicate
72that it is unallocated.
bade79af
KD
73.NH 2
74File locking
75.PP
76The old file system had no provision for locking files.
77Processes that needed to synchronize the updates of a
c20eb73f 78file had to use a separate ``lock'' file.
bade79af 79A process would try to create a ``lock'' file.
c20eb73f
KD
80If the creation succeeded, then the process
81could proceed with its update;
82if the creation failed, then the process would wait and try again.
bade79af 83This mechanism had three drawbacks.
c20eb73f
KD
84Processes consumed CPU time by looping over attempts to create locks.
85Locks left lying around because of system crashes had
86to be manually removed (normally in a system startup command script).
bade79af
KD
87Finally, processes running as system administrator
88are always permitted to create files,
c20eb73f 89so were forced to use a different mechanism.
bade79af 90While it is possible to get around all these problems,
c20eb73f 91the solutions are not straight forward,
bade79af
KD
92so a mechanism for locking files has been added.
93.PP
c20eb73f
KD
94The most general schemes allow multiple processes
95to concurrently update a file.
bade79af 96Several of these techniques are discussed in [Peterson83].
c20eb73f 97A simpler technique is to serialize access to a file with locks.
bade79af
KD
98To attain reasonable efficiency,
99certain applications require the ability to lock pieces of a file.
100Locking down to the byte level has been implemented in the
101Onyx file system by [Bass81].
c20eb73f 102However, for the standard system applications,
bade79af
KD
103a mechanism that locks at the granularity of a file is sufficient.
104.PP
105Locking schemes fall into two classes,
106those using hard locks and those using advisory locks.
107The primary difference between advisory locks and hard locks is the
c20eb73f
KD
108extent of enforcement.
109A hard lock is always enforced when a program tries to
bade79af
KD
110access a file;
111an advisory lock is only applied when it is requested by a program.
112Thus advisory locks are only effective when all programs accessing
113a file use the locking scheme.
c20eb73f
KD
114With hard locks there must be some override
115policy implemented in the kernel.
116With advisory locks the policy is left to the user programs.
bade79af 117In the UNIX system, programs with system administrator
c20eb73f
KD
118privilege are allowed override any protection scheme.
119Because many of the programs that need to use locks must
120also run as the system administrator,
bade79af 121we chose to implement advisory locks rather than
c20eb73f
KD
122create an additional protection scheme that was inconsistent
123with the UNIX philosophy or could
124not be used by system administration programs.
bade79af
KD
125.PP
126The file locking facilities allow cooperating programs to apply
127advisory
128.I shared
129or
130.I exclusive
131locks on files.
c20eb73f 132Only one process may have an exclusive
bade79af
KD
133lock on a file while multiple shared locks may be present.
134Both shared and exclusive locks cannot be present on
135a file at the same time.
136If any lock is requested when
137another process holds an exclusive lock,
138or an exclusive lock is requested when another process holds any lock,
c20eb73f 139the lock request will block until the lock can be obtained.
bade79af
KD
140Because shared and exclusive locks are advisory only,
141even if a process has obtained a lock on a file,
c20eb73f 142another process may access the file.
bade79af 143.PP
c20eb73f
KD
144Locks are applied or removed only on open files.
145This means that locks can be manipulated without
146needing to close and reopen a file.
bade79af 147This is useful, for example, when a process wishes
c20eb73f
KD
148to apply a shared lock, read some information
149and determine whether an update is required, then
150apply an exclusive lock and update the file.
bade79af 151.PP
c20eb73f 152A request for a lock will cause a process to block if the lock
bade79af
KD
153can not be immediately obtained.
154In certain instances this is unsatisfactory.
155For example, a process that
156wants only to check if a lock is present would require a separate
157mechanism to find out this information.
158Consequently, a process may specify that its locking
159request should return with an error if a lock can not be immediately
160obtained.
c20eb73f
KD
161Being able to conditionally request a lock
162is useful to ``daemon'' processes
bade79af
KD
163that wish to service a spooling area.
164If the first instance of the
165daemon locks the directory where spooling takes place,
166later daemon processes can
167easily check to see if an active daemon exists.
c20eb73f
KD
168Since locks exist only while the locking processes exist,
169lock files can never be left active after
170the processes exit or if the system crashes.
bade79af
KD
171.PP
172Almost no deadlock detection is attempted.
c20eb73f
KD
173The only deadlock detection done by the system is that the file
174to which a lock is applied must not already have a
bade79af
KD
175lock of the same type (i.e. the second of two successive calls
176to apply a lock of the same type will fail).
bade79af
KD
177.NH 2
178Symbolic links
179.PP
c20eb73f 180The traditional UNIX file system allows multiple
bade79af 181directory entries in the same file system
c20eb73f
KD
182to reference a single file. Each directory entry
183``links'' a file's name to an inode and its contents.
bade79af 184The link concept is fundamental;
c20eb73f 185inodes do not reside in directories, but exist separately and
bade79af 186are referenced by links.
c20eb73f
KD
187When all the links to an inode are removed,
188the inode is deallocated.
189This style of referencing an inode does
190not allow references across physical file
bade79af
KD
191systems, nor does it support inter-machine linkage.
192To avoid these limitations
193.I "symbolic links"
c20eb73f 194similar to the scheme used by Multics [Feiertag71] have been added.
bade79af
KD
195.PP
196A symbolic link is implemented as a file that contains a pathname.
197When the system encounters a symbolic link while
198interpreting a component of a pathname,
199the contents of the symbolic link is prepended to the rest
200of the pathname, and this name is interpreted to yield the
201resulting pathname.
c20eb73f
KD
202In UNIX, pathnames are specified relative to the root
203of the file system hierarchy, or relative to a process's
204current working directory. Pathnames specified relative
205to the root are called absolute pathnames. Pathnames
206specified relative to the current working directory are
207termed relative pathnames.
208If a symbolic link contains an absolute pathname,
bade79af
KD
209the absolute pathname is used,
210otherwise the contents of the symbolic link is evaluated
211relative to the location of the link in the file hierarchy.
212.PP
213Normally programs do not want to be aware that there is a
214symbolic link in a pathname that they are using.
215However certain system utilities
216must be able to detect and manipulate symbolic links.
217Three new system calls provide the ability to detect, read, and write
c20eb73f
KD
218symbolic links; seven system utilities required changes
219to use these calls.
bade79af 220.PP
c20eb73f
KD
221In future Berkeley software distributions
222it may be possible to reference file systems located on
223remote machines using pathnames. When this occurs,
bade79af
KD
224it will be possible to create symbolic links that span machines.
225.NH 2
226Rename
227.PP
c20eb73f
KD
228Programs that create a new version of an existing
229file typically create the
bade79af 230new version as a temporary file and then rename the temporary file
c20eb73f
KD
231with the name of the target file.
232In the old UNIX file system renaming required three calls to the system.
233If a program were interrupted or the system crashed between these calls,
234the target file could be left with only its temporary name.
235To eliminate this possibility the \fIrename\fP system call
236has been added. The rename call does the rename operation
237in a fashion that guarantees the existence of the target name.
238.PP
239Rename works both on data files and directories.
240When renaming directories,
241the system must do special validation checks to insure
bade79af
KD
242that the directory tree structure is not corrupted by the creation
243of loops or inaccessible directories.
244Such corruption would occur if a parent directory were moved
245into one of its descendants.
c20eb73f 246The validation check requires tracing the descendents of the target
bade79af
KD
247directory to insure that it does not include the directory being moved.
248.NH 2
249Quotas
250.PP
251The UNIX system has traditionally attempted to share all available
252resources to the greatest extent possible.
253Thus any single user can allocate all the available space
254in the file system.
255In certain environments this is unacceptable.
256Consequently, a quota mechanism has been added for restricting the
257amount of file system resources that a user can obtain.
c20eb73f 258The quota mechanism sets limits on both the number of inodes
bade79af
KD
259and the number of disk blocks that a user may allocate.
260A separate quota can be set for each user on each file system.
c20eb73f 261Resources are given both a hard and a soft limit.
bade79af
KD
262When a program exceeds a soft limit,
263a warning is printed on the users terminal;
264the offending program is not terminated
265unless it exceeds its hard limit.
266The idea is that users should stay below their soft limit between
267login sessions,
c20eb73f 268but they may use more resources while they are actively working.
bade79af
KD
269To encourage this behavior,
270users are warned when logging in if they are over
271any of their soft limits.
c20eb73f 272If users fails to correct the problem for too many login sessions,
bade79af
KD
273they are eventually reprimanded by having their soft limit
274enforced as their hard limit.
c20eb73f
KD
275.ds RH Acknowledgements
276.sp 2
277.ne 1i