现代操作系统 Chapter 4.ppt
《现代操作系统 Chapter 4.ppt》由会员分享,可在线阅读,更多相关《现代操作系统 Chapter 4.ppt(70页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Chapter 4 File systemsContents4.1 Files4.2 Directories4.3 File System Implementation4.4 File System Management and Optimization4.5 Example File Systems 2File SystemsvEssential requirements for long-term information storage:It must be possible to store a very large amount of information.The informati
2、on must survive the termination of the process using it.Multiple processes must be able to access the information concurrently.3File SystemsvFiles are logical units of information created by processes.vThat part of the OS dealing with files is known as the file system.44.1 Files4.1.1 File namingvWhe
3、n a process creates a file,it gives the file a name.When the process terminates,the file continues to exist and can be accessed by other processes using its name.vThe rules of file naming(文件命名规则文件命名规则)vFile extension(文件扩展名文件扩展名)5Figure 4-2.Three kinds of files.(a)Byte sequence.(b)Record sequence.(c)
4、Tree.4.1.2 File structure64.1.3 File TypesvRegular file(普通文件普通文件)ASCII filesBinary filesvSpecial file(特殊文件特殊文件)Character special file:are related to input/output and used to model serial I/O devicesBlock special file:are used to model disks74.1.4 File accessvSequential access(顺序存取顺序存取)A process coul
5、d read all the bytes or records in a file in order,starting at the beginning,but could not skip around and read them out of order.vRandom access(随机存取随机存取)The bytes or records in these files can be read in any order.84.1.5 File attributesFigure 4-4.Some possible file attributes.94.1.6 File Operations
6、vCreatevDeletevOpenvClosevReadvWritevAppendvSeekvGet attributesvSet attributesvRename 104.1.7 An example program using file system calls(1)11An example program using file system calls(2)124.2 Directories1.Single-level Directory systemsvAdvantages:SimplicityThe ability to locate file quickly13Directo
7、ries2.Hierarchical(层次层次)directory systemsAdvantages:can group files in natural ways14Directories3.Path namesvAbsolute path name(绝对路径绝对路径):consisting of the path from the root directory to the file.It always start at the root directory and are unique.vRelative path name(相对路径相对路径):it is used in conjun
8、ction with the concept of the working directory.15Directories4.Directory OperationsCreateDeleteOpendirClosedirReaddirRenameLinkUnlink 164.3 File System Implementation4.3.1 File System Layout4.3.2 Implementing Files4.3.3 Implementing directories4.3.4 Shared files4.3.5 Journaling File Systems(JFS)4.3.
9、6 Virtual File Systems(VFS)174.3.1 File System Layout(布局布局)Sector 0 of the disk is called the MBR(Master Boot Record,主引导记录主引导记录)and is used to boot the computer.The end of the MBR contains the partition table.184.3.2 Implementing FilesThe most important issue in implementing file storage is keeping
10、track of which disk blocks go with which file.vContiguous allocation(连续分配连续分配)vLinked list allocation(链表分配链表分配)vLinked list allocation using a table in memoryvi-nodes 191.Contiguous allocation The simplest allocation scheme is to store each file as a contiguous run of disk blocks.20Contiguous alloca
11、tionFigure 4-10.(a)Contiguous allocation of disk space for 7 files.(b)The state of the disk after files D and F have been removed.21Contiguous allocationvAdvantages:It is simple to implement.The read performance is excellent.vDisadvantage:Over the course of time,the disk becomes fragmented.vAn examp
12、le of contiguous allocation:CD-ROM222.Linked list allocation Linked list allocation:The first word of each block is used as a pointer to the next one.The rest of the block is for data.23Linked list allocationFigure 4-11.Storing a file as a linked list of disk blocks.24Linked list allocationvAdvantag
13、e:every disk block can be used.No space is lost to disk fragmentation(except for internal fragmentation in the last block).vDisadvantage:random access is extremely slowThe amount of data storage in a block is no longer a power of two because the pointer takes up a few bytes.253.Linked list allocatio
14、n using a table in memoryBoth disadvantages of the linked list allocation can be eliminated by taking the pointer word from each disk block and putting it in a table in memory.Such a table in main memory is called a FAT(File Allocation Table,文件分配表文件分配表).26Linked list allocation using a table in memo
15、ry Figure 4-12.Linked list allocation using a file allocation table in main memory.Disadvantage:the entire table must be in memory all the time to make it work.The FAT idea doesnt scale well to large disks.274.i-nodesFigure 4-13.An example i-node.vAssociate with each file a data structure called an
16、i-node,which lists the attributes and disk addresses of the files blocks.vAdvantage:the i-node need only be in memory when the corresponding file is open.284.3.3 Implementing directoriesvWhen a file is opened,the OS uses the path name supplied by the user to locate the directory entry.The directory
17、entry provides the information needed to find the disk blocks.vThe main function of the directory system is to map the ASCII name of the file onto the information needed to locate the data.29Implementing directoriesvWhere should the attributes be stored?1.One obvious possibility is to store them dir
18、ectly in the directory entry.30Implementing directories2.For systems that use i-nodes,another possibility for storing the attributes is in the i-nodes,rather than in the directory entries.31Implementing directoriesvSo far we have made the assumption that files have short,fixed-length names.However,n
19、early all modern OS support longer,variable-length file names.How can these be implemented?vMethod 1:to set a limit on file name length,typically 255 characters,and then use one of the designs of Fig 4-14.This approach wastes a great deal of directory space,since few files have such long names.32vMe
20、thod 2:each directory entry contains a fixed portion,typically starting with the length of the entry,and then followed by data with a fixed format,usually including the file attributes.This fixed-length header is followed by the actual file name.Implementing directories33Implementing directoriesvMet
21、hod 3:make the directory entries themselves all fixed length and keep the file names together in a heap(堆堆)at the end of the directory.344.3.4 Shared filesvWhen several users are working together on a project,they often need to share files.35Shared filesvSolution 1:disk blocks are not listed in dire
22、ctories,but in i-node.This is the approach used in UNIX.Hard link(硬链接硬链接)vSolution 2:B links to one of Cs files by having the system create a new file,of type LINK.The new file contains just the path name of the file to which it is linked.Symbolic link(符号链接符号链接)36Disadvantages of the two solutions?v
23、Hard link:vSymbolic link:require extra overhead374.3.5 Journaling File Systems(JFS)vThe basic idea is to keep a log of what the file system is going to do before it does it,so that if the system crashes before it can do its planned work,upon rebooting the system can look in the log to see what was g
24、oing on at the time of the crash and finish the job.Journaling file systems(日志文件系统日志文件系统)vMicrosofts NTFS systemvThe Linux ext3 file system38An examplevOperations required to remove a file in UNIX:Remove the file from its directory.Release the i-node to the pool of free i-nodes.Return all the disk b
25、locks to the pool of free disk blocks.vWhat the JFS does is first write a log entry listing the three actions to be completed.The log entry is then written to disk.Only after the log entry has been written,do the various operations begin.After the operations complete successfully,the log is erased.3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 现代操作系统 Chapter 现代 操作系统
限制150内