⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 implement

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 3 页
字号:
Directories are simply files thatusers cannot write.For a further discussionof the external view of files and directories,see Ref.\0.[ritchie thompson unix bstj 1978%Q This issue.]..PPThe.UXfile system is a disk data structureaccessed completely throughthe block I/O system.As stated before,the canonical view of a ``disk'' isa randomly addressable array of512-byte blocks.A file system breaks the disk intofour self-identifying regions.The first block (address 0)is unused by the file system.It is left aside for booting procedures.The second block (address 1)contains the so-called ``super-block.''This block,among other things,contains the size of the disk andthe boundaries of the other regions.Next comes the i-list,a list of file definitions.Each file definition isa 64-byte structure, called an i-node.The offset of a particular i-nodewithin the i-list is called its i-number.The combination of device name(major and minor numbers) and i-numberserves to uniquely name a particular file.After the i-list,and to the end of the disk,come free storage blocks thatare available for the contents of files..PPThe free space on a disk is maintainedby a linked list of available disk blocks.Every block in this chain contains a disk addressof the next block in the chain.The remaining space contains the address of up to50 disk blocks that are also free.Thus with one I/O operation,the system obtains 50 free blocks and apointer where to find more.The disk allocation algorithms arevery straightforward.Since all allocation is in fixed-sizeblocks and there is strict accounting ofspace,there is no need to compact or garbage collect.However,as disk space becomes dispersed,latency gradually increases.Some installations choose to occasionally compactdisk space to reduce latency..PPAn i-node contains 13 disk addresses.The first 10 of these addresses point directly atthe first 10 blocks of a file.If a file is larger than 10 blocks (5,120 bytes),then the eleventh address points at a blockthat contains the addresses of the next 128 blocks of the file.If the file is still larger than this(70,656 bytes),then the twelfth block points at up to 128 blocks,each pointing to 128 blocks of the file.Files yet larger(8,459,264 bytes)use the thirteenth address for a ``triple indirect'' address.The algorithm ends here with the maximum file sizeof 1,082,201,087 bytes..PPA logical directory hierarchy is addedto this flat physical structure simplyby adding a new type of file, the directory.A directory is accessed exactly as an ordinary file.It contains 16-byte entries consisting ofa 14-byte name and an i-number.The root of the hierarchy is at a known i-number(\fIviz.,\fR 2).The file system structure allows an arbitrary, directed graphof directories with regular files linked inat arbitrary places in this graph.In fact,very early.UXsystems used such a structure.Administration of such a structure became sochaotic that later systems were restrictedto a directory tree.Even now,with regular files linked multiplyinto arbitrary places in the tree,accounting for space has become a problem.It may become necessary to restrict the entirestructure to a tree,and allow a new form of linking thatis subservient to the tree structure..PPThe file system allowseasy creation,easy removal,easy random accessing,and very easy space allocation.With most physical addresses confinedto a small contiguous section of disk,it is also easy to dump, restore, andcheck the consistency of the file system.Large files suffer from indirect addressing,but the cache prevents most of the implied physical I/Owithout adding much execution.The space overhead properties of this scheme are quite good.For example,on one particular file system,there are 25,000 files containing 130M bytes of data-file content.The overhead (i-node, indirect blocks, and last block breakage)is about 11.5M bytes.The directory structure to support these fileshas about 1,500 directories containing 0.6M bytes of directory contentand about 0.5M bytes of overhead in accessing the directories.Added up any way,this comes out to less than a 10 percent overhead for actualstored data.Most systems have this much overhead inpadded trailing blanks alone..NH 2File system implementation.PPBecause the i-node defines a file,the implementation of the file system centersaround access to the i-node.The system maintains a table of all activei-nodes.As a new file is accessed,the system locates the corresponding i-node,allocates an i-node table entry, and readsthe i-node into primary memory.As in the buffer cache,the table entry is considered to be the currentversion of the i-node.Modifications to the i-node are made tothe table entry.When the last access to the i-node goesaway,the table entry is copied back to thesecondary store i-list and the table entry is freed..PPAll I/O operations on files are carried outwith the aid of the corresponding i-node table entry.The accessing of a file is a straightforwardimplementation of the algorithms mentioned previously.The user is not aware of i-nodes and i-numbers.References to the file system are made in terms ofpath names of the directory tree.Converting a path name into an i-node table entryis also straightforward.Starting at some known i-node(the root or the current directory of some process),the next component of the path name issearched by reading the directory.This gives an i-number and an implied device(that of the directory).Thus the next i-node table entry can be accessed.If that was the last component of the path name,then this i-node is the result.If not,this i-node is the directory needed to look upthe next component of the path name, and thealgorithm is repeated..PPThe user process accesses the file system withcertain primitives.The most common of these are.UL open ,.UL create ,.UL read ,.UL write ,.UL seek ,and.UL close .The data structures maintained are shown in Fig. 2..KS.sp 22P.ceFig. 2\(emFile system data structure..KEIn the system data segment associated with a user,there is room for some (usually between 10 and 50) open files.This open file table consists of pointers that can be used to accesscorresponding i-node table entries.Associated with each of these open files isa current I/O pointer.This is a byte offset ofthe next read/write operation on the file.The system treats each read/write requestas random with an implied seek to theI/O pointer.The user usually thinks of the file assequential with the I/O pointerautomatically counting the number of bytesthat have been read/written from the file.The user may,of course,perform random I/O by setting the I/O pointerbefore reads/writes..PPWith file sharing,it is necessary to allow relatedprocesses to share a common I/O pointerand yet have separate I/O pointersfor independent processesthat access the same file.With these two conditions,the I/O pointer cannot residein the i-node table nor canit reside in the list ofopen files for the process.A new table(the open file table)was invented for the sole purposeof holding the I/O pointer.Processes that share the same openfile(the result of.UL fork s)share a common open file table entry.A separate open of the same file willonly share the i-node table entry,but will have distinct open file table entries..PPThe main file system primitives are implemented as follows..UL \&openconverts a file system path name into an i-nodetable entry.A pointer to the i-node table entry is placed in anewly created open file table entry.A pointer to the file table entry is placed in thesystem data segment for the process..UL \&createfirst creates a new i-node entry,writes the i-number into a directory, andthen builds the same structure as for an.UL open ..UL \&readand.UL writejust access the i-node entry as described above..UL \&seeksimply manipulates the I/O pointer.No physical seeking is done..UL \&closejust frees the structures built by.UL openand.UL create .Reference counts are kept on the open file table entries andthe i-node table entries to free these structures afterthe last reference goes away..UL \&unlinksimply decrements the count of thenumber of directories pointing at the given i-node.When the last reference to an i-node table entrygoes away,if the i-node has no directories pointing to it,then the file is removed and the i-node is freed.This delayed removal of files preventsproblems arising from removing active files.A file may be removed while still open.The resulting unnamed file vanisheswhen the file is closed.This is a method of obtaining temporary files..PPThere is a type of unnamed.UC  FIFOfile called a.UL pipe.Implementation of.UL pipe sconsists of implied.UL seek sbefore each.UL reador.UL writein order to implementfirst-in-first-out.There are also checks and synchronizationto prevent thewriter from grossly outproducing thereader and to prevent the reader fromovertaking the writer..NH 2Mounted file systems.PPThe file system of a.UXsystemstarts with some designated block deviceformatted as described above to containa hierarchy.The root of this structure is the root ofthe.UXfile system.A second formatted block device may bemountedat any leaf ofthe current hierarchy.This logically extends the current hierarchy.The implementation ofmountingis trivial.A mount table is maintained containingpairs of designated leaf i-nodes andblock devices.When converting a path name into an i-node,a check is made to see if the new i-node is adesignated leaf.If it is,the i-node of the rootof the block device replaces it..PPAllocation of space for a file is takenfrom the free pool on the device on which thefile lives.Thus a file system consisting of manymounted devices does not have a common pool offree secondary storage space.This separation of space on differentdevices is necessary to allow easyunmountingof a device..NH 2Other system functions.PPThere are some other things that the systemdoes for the user\-alittle accounting,a little tracing/debugging,and a little access protection.Most of these things are not verywell developedbecause our use of the system in computing science researchdoes not need them.There are some features that are missed in someapplications, for example, better inter-process communication..PPThe.UXkernel is an I/O multiplexer more thana complete operating system.This is as it should be.Because of this outlook,many features arefound in mostother operating systems that are missing from the.UXkernel.For example,the.UXkernel does not supportfile access methods,file disposition,file formats,file maximum size,spooling,command language,logical records,physical records,assignment of logical file names,logical file names,more than one character set,an operator's console,an operator,log-in,or log-out.Many of these things are symptoms rather than features.Many of these things are implementedin user softwareusing the kernel as a tool.A good example of this is the command language..[bourne shell 1978 bstj%Q This issue.]Each user may have his own command language.Maintenance of such code is as easy asmaintaining user code.The idea of implementing ``system'' code with generaluser primitivescomes directly from.UC  MULTICS ..[organick multics 1972.].LP.[$LIST$.]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -