《《文件系统结构》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《文件系统结构》PPT课件.ppt(54页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、 2009Operating SystemsChapter 11:File-System Implementation11.2 2009Operating Systems Chapter 11 File System Implementationn n11.1 11.1 File-System StructureFile-System Structure 文件系统结构文件系统结构文件系统结构文件系统结构n n11.2 11.2 File-System Implementation File-System Implementation 文件系统实现文件系统实现文件系统实现文件系统实现n n11.
2、3 11.3 Directory ImplementationDirectory Implementation 目录实现目录实现目录实现目录实现n n11.4 11.4 Allocation MethodsAllocation Methods 分配方法分配方法分配方法分配方法n n11.5 11.5 Free-Space Management Free-Space Management 空闲空间管理空闲空间管理空闲空间管理空闲空间管理nExercises11.3 2009Operating Systems11.1 File-System Structure文件系统结构文件系统结构nI/Otra
3、nsfersbetweenmemoryanddiskareperformedinunitsofblocks.内存与磁盘间的内存与磁盘间的I/O传输以块为单位传输以块为单位lEachblockisoneormoresectors(扇区).nFilestructurelLogicalstorageunitlCollectionofrelatedinformationnFilesystemresidesonsecondarystorage(disks).nFilesystemorganizedintolayers.n nFile control block File control block(FC
4、BFCB)文件控制块文件控制块lstoragestructureconsistingofinformationaboutafile.11.4 2009Operating SystemsLayered File SystemCommands(such as“retrieve block 123”)hardware-specific instructions(controller)(controller)device driversdevice driversandinterrupt handlersinterrupt handlerstotransferinformationbetweenthe
5、mainmemoryandthedisksystem.Issuegenericcommandstotheappropriatedevicedriver1.Translatelogicalblockaddresstophysicalblockaddress;2.freespacemanager.Managesmetadatainformation.1.managesthedirectorystructure;2.maintainsfilestructureviafile control blockfile control block(FCBFCB);3.protectionandsecurity
6、.11.5 2009Operating Systems11.2 File-System Implementation文件系统实现文件系统实现Inthissection,wedelveintothestructuresandoperationsusedtoimplementfile-systemoperations.n n1.Overview1.Overviewn n2.Partitions and Mounting 2.Partitions and Mounting 分区及安装分区及安装分区及安装分区及安装n n3.Virtual File Systems 3.Virtual File Sys
7、tems 虚拟文件系统虚拟文件系统虚拟文件系统虚拟文件系统11.6 2009Operating Systems1.Overviewn nOn-disk and in-memory structures used to implement a file On-disk and in-memory structures used to implement a file system:system:lThe on-disk structures:4Aboot control blockboot control block:引导控制块containsinformationneededbythesyst
8、emtobootanoperatingsystemfromthatpartition.4Apartition control blockpartition control block:分区控制块containspartitiondetails(suchas:thenumberofblocksinthepartition,sizeoftheblocks,free-blockcountandfree-blockpointers,andfreeFCBcountandFCBpointers).44Directory structure Directory structure 目录结构44FCBFCB文
9、件控制块11.7 2009Operating SystemslThe in-memory structures:4Anin-memory partition table in-memory partition table 内存内存内存内存 分区表分区表分区表分区表containinginformationabouteachmountedpartition.4Anin-memory directory structure in-memory directory structure 内存内存内存内存 目录结构目录结构目录结构目录结构thatholdsthedirectoryinformationo
10、frecentlyaccesseddirectories.4Thesystem-wide open-file table system-wide open-file table 系统系统系统系统 打开文件表打开文件表打开文件表打开文件表containsacopyoftheFCBofeachopenfile,aswellasotherinformation.4Theper-process open-file table per-process open-file table 进程进程进程进程 打开文件表打开文件表打开文件表打开文件表containsapointertotheappropriate
11、entryinthesystem-wideopen-filetable,aswellasotherinformation.11.8 2009Operating SystemsA typical file control block11.9 2009Operating Systemsn nCreate a new file Create a new file 创建新文件创建新文件创建新文件创建新文件l lThe process:The process:4Anapplication programapplication programcallsthelogical file systemlogic
12、al file system.44Logical file systemLogical file systemallocatesanewFCBFCB,.4Readtheappropriatedirectoryintomemory,updatesitwiththenewfilenameandFCB,andwritesitbacktothedisk.l lAbout directoryAbout directory4Someoperatingsystems(includingUNIX)treatadirectoryasafile.4Someoperatingsystems(includingWin
13、dowsNT)treatadirectoriesasentitiesseparatefromfiles.(separatesystemcallsforfilesanddirectories.)11.10 2009Operating Systemsn nOpen a file Open a file 打开文件打开文件打开文件打开文件lThe process:4Thedirectory structures is searcheddirectory structures is searchedforthegivenfilename.(Partsofthedirectorystructureareu
14、suallycachedinmemorytospeeddirectoryoperations.)4The FCBFCBiscopiedintoasystem-wide open-file tablesystem-wide open-file tableinmemory.4Anentryentryismadeintheper-process open-file tableper-process open-file table.(withapointertotheentryinthesystem-wideopen-filetable,apointertothecurrentlocationinth
15、efile,theaccessmodeinwhichthefileisopen,)4Theopencallreturnsa pointer pointer totheappropriateentryintheper-process per-process open-file tableopen-file table.Allfileoperationsarethenperformedviathispointer.lAbout the pointer returned by the open call4Unixsystemsrefertoitasafile descriptorfile descr
16、iptor.4Windows2000referstoitasafile handlefile handle.11.11 2009Operating Systemsn nClose a file Close a file 关闭文件关闭文件关闭文件关闭文件lThe process:4Theper-process table entryper-process table entry isremoved,andthesystem-wideentrysopencountisdecremented.4Whenallusersthathaveopenedthefilecloseit,theupdatedfi
17、leinformationiscopiedbacktothedisk-based directorydisk-based directory structurestructureandthesystem-wide open-file table entrysystem-wide open-file table entryisremoved.11.12 2009Operating SystemsIn-Memory file-system structures.(a)File open.(b)File read.11.13 2009Operating Systems2.Partitions and
18、 Mounting分区及安装分区及安装n nThe layout of disk can have many variations,depending on the The layout of disk can have many variations,depending on the operating system.operating system.lAdiskcanbeslicedintomultiplepartitions,orapartitioncanspanmultipledisks(-aformofRAID).n nEach partition can be:Each parti
19、tion can be:l“rawraw”:生分区生分区4containing no file system44Raw diskRaw diskisusedwherenofilesystemisappropriate.4Examples:UNIXswapspace,somedatabases.l“cookedcooked”:熟分区熟分区4containing a file system11.14 2009Operating Systemsn nBoot information Boot information 引导信息引导信息lcanbestoredinaseparatepartition.l
20、ithasitsownformat4becauseatboottimethesystemdoesnothavefile-systemdevicedriversloadedandthereforecannotinterpretthefile-systemformat.4itisusuallyasequentialseriesofblocks,loadedasanimageintomemory.Executionoftheimagestartsatapredefinedlocation,suchasthefirstbyte.11.15 2009Operating Systemsn nroot pa
21、rtition root partition 根分区根分区lwhichcontainstheoperating-systemkernelandpotentiallyothersystemfiles,ismountedatboottime.4Otherpartitionscanbeautomaticallymountedatbootormanuallymountedlater,dependingontheoperatingsystem.lAspartofasuccessfulmountoperation,theoperatingsystemverifiesthatthedevicecontain
22、savalidfilesystem.4Itdoessobyaskingthedevicedrivertoreadthedevicedirectoryandverifyingthatthedirectoryhastheexpectedformat.Iftheformatisinvalid,thepartitionmusthaveitsconsistencycheckedandpossiblycorrect,eitherwithorwithoutuserintervention.lFinally,theoperatingsystemnotesinitsin-memorymount tablemou
23、nt tablestructurethatafilesystemismounted,andthetypeofthefilesystem.11.16 2009Operating Systems3.Virtual File Systems虚拟文件系统虚拟文件系统 Howdoesanoperatingsystemallowmultipletypesoffilesystemstobeintegratedintoadirectorystructure?Howcanusersseamlesslymovebetweenfile-systemtypesastheynavigatethefile-systems
24、pace?n nVirtual File Systems Virtual File Systems(VFSVFS)lprovideanobject-orientedwayofimplementingfilesystems.lVFSallowsthesamesystemcallinterface(theAPI)tobeusedfordifferenttypesoffilesystems.lTheAPIistotheVFSinterface,ratherthananyspecifictypeoffilesystem.11.17 2009Operating SystemsSchematic View
25、 of Virtual File System11.18 2009Operating Systems11.3 Directory Implementation目录实现目录实现n n1.1.Linear listLinear list线性表线性表线性表线性表lLinearlistoffilenameswithpointertothedatablocks.lsimpletoprogramltime-consumingtoexecuten n2.2.Hash Table Hash Table 哈希表哈希表哈希表哈希表llinearlistwithhashdatastructure.ldecrease
26、sdirectorysearchtimelcollisionssituationswheretwofilenameshashtothesamelocationlfixedsize11.19 2009Operating Systems11.4 Allocation Methods分配方法分配方法nAnallocation methodallocation methodreferstohowdiskblocksareallocatedforfiles.n nGoalGoalldiskspaceisutilizedeffectivelyandfilecanbeaccessedquickly.n nT
27、hree major methods:Three major methods:lContiguousallocation连续分配连续分配连续分配连续分配lLinkedallocation链接分配链接分配链接分配链接分配lIndexedallocation索引分配索引分配索引分配索引分配11.20 2009Operating SystemsContiguous Allocation of Disk SpacenEachfileoccupiesasetofcontiguousblocksonthedisk.nThedirectoryentryforeachfileindicatestheaddre
28、ssofthestartingblock(block#)andthelengthoftheareaallocatedforthisfile(numberofblocks).1.Contiguous Allocation 连续分配连续分配11.21 2009Operating SystemsAdvantagesnTheleastnumberofdiskseek.(foronlyoneaccessjob)nAccessingafileiseasy.(forbothsequentialanddirectaccess)DrawbacksnDifficultyforfindingspaceforanew
29、file.nWastefulofspace:externalfragmentation.(dynamicstorage-allocationproblem)nSize-declarationproblem:filescannotgrow.11.22 2009Operating Systemsn nExtent-Based Systems Extent-Based Systems 基于扩展的系统基于扩展的系统基于扩展的系统基于扩展的系统lManynewerfilesystems(I.e.VeritasFileSystem)useamodifiedcontiguousallocationschem
30、e.lExtent-basedfilesystemsallocatediskblocksinextents.lAnextentisacontiguousblockofdisks.4Extentsareallocatedforfileallocation.4Afileconsistsofoneormoreextents.11.23 2009Operating Systems2.Linked Allocation 链接分配链接分配nEachfileisalinkedlistofdiskblocks:blocksmaybescatteredanywhereonthedisk.pointerblock
31、=Linked Allocation11.24 2009Operating SystemsAdvantagesnSimpleneedonlystartingaddressnFree-spacemanagementsystemnowasteofspaceDisadvantagesnNorandomaccessnWastefulofspace:thespacerequiredforthepointers.lSolution:collectblocksintomultiples-clustersnReliability.lPartialsolution:usedoublelinkedlistsort
32、ostorethefilenameandrelativeblocknumberineachblock.(however,theseschemesrequireevenmoreoverheadforeachfile.)11.25 2009Operating SystemsFAT Allocation 文件分配表文件分配表n nFile-allocation tableFile-allocation table(FATFAT)ldisk-spaceallocationusedbyMS-DOSandOS/2.lAsectionofdiskatthebeginningofeachpartitionis
33、setasidetocontaintheFAT.lFAThasoneentryforeachdiskblock,andisindexedbyblock#.4Eachentrycontainstheblock#ofthenextblockinthefile.4Unusedblocksareindicatedbya0tablevalue.lThedirectoryentrycontainstheblock#ofthefirstblockofthefile.11.26 2009Operating SystemsFile-Allocation Table11.27 2009Operating Syst
34、emsnTheFATallocationschemecanresultinasignificantnumberofdiskheadseeks,unlesstheFATiscached.nAbenefitisthatrandomaccesstimeisimproved11.28 2009Operating Systems3.Indexed Allocation 索引分配索引分配nBringsallpointerstogetherintotheindex blockindex block.nLogicalview.indextablenEachfilehasitsownindexblock.lTh
35、eithentryintheindexblockpointstotheithblockofthefile.nThedirectorycontainstheaddressoftheindexblock.11.29 2009Operating SystemsExample of Indexed Allocation11.30 2009Operating Systemsn nAdvantagesAdvantageslIndexallocationsupportsrandom accesslDynamicaccesswithoutexternalfragmentationn nDisadvantage
36、sDisadvantageslWastefulofspace:4thepointeroverheadoftheindexblockisgenerallygreaterthanthepointeroverheadoflinkedallocation.lDynamicaccesswithoutexternalfragmentationn nProblem:Problem:How large the index block should be?How large the index block should be?l lLinked schemeLinked scheme:linktogethers
37、everalindexblocks.l lMultilevel indexMultilevel indexl lCombined schemeCombined scheme11.31 2009Operating SystemsLinked schemenMapping from logical to physicalinafileofmaximumsizeof256Kwordsandblocksizeof512words.Weneedonly1blockforindextable.LA/512QRQ=displacementintoindextableR=displacementintoblo
38、ck11.32 2009Operating SystemsnMappingfromlogicaltophysicalinafileofunboundedlength(blocksizeof512words).nLinkedschemeLinkblocksofindextable(nolimitonsize).LA/(512x511)Q1R1Q1=blockofindextableR1 isusedasfollows:R1/512Q2R2Q2=displacementintoblockofindextableR2displacementintoblockoffile:11.33 2009Oper
39、ating SystemsnTwo-levelindex(maximumfilesizeis5123)LA/(512x512)Q1R1Q1=displacementintoouter-indexR1isusedasfollows:R1/512Q2R2Q2=displacementintoblockofindextableR2displacementintoblockoffile:Multilevel index11.34 2009Operating SystemsMultilevelindexouter-indexindextablefile11.35 2009Operating System
40、sCombined Scheme:UNIX(4K bytes per block)The UNIX i inode.11.36 2009Operating Systems11.5 Free-Space Management闲空间管理闲空间管理n1.Bit vector(bit map)位向量(位映象)位向量(位映象)0 12n-1biti=1blockifree0blockioccupiedBlocknumbercalculationThe block#of the first free block=The block#of the first free block=(number of bi
41、ts per word)*(number of 0-value words)+offset of first 1 bitnumber of bits per word)*(number of 0-value words)+offset of first 1 bit首个空闲块块号首个空闲块块号每个字的位数*0值字数首个“1”位的偏移量11.37 2009Operating SystemsnBitmaprequiresextraspace.位映象需要额外的空间Example:blocksize=212bytesdisksize=230bytes(1gigabyte)n=230/212=218bit
42、s(or32Kbytes)nEasytogetcontiguousfiles易得到连续的文件11.38 2009Operating Systems2.Linked list(free list)链接列表(空闲列表)链接列表(空闲列表)nLinktogetherallthefreediskblocks,keepingapointertothefirstfreeblockinaspeciallocationonthediskandcachingitinmemory.所有的空闲盘块链接到一起,将首个空闲块的指针保存在磁盘特定的位置,并把他缓存(cache)到内存。nThisschemeisnotef
43、ficient:totraversethelist,wemustreadeachblock,whichrequiressubstantialI/Otime.该方案效率不高:遍历列表需要读取每个盘块,这需要相当多的I/O时间。nTheFATmethodincorporatesfree-blockaccountingintotheallocationdatastructure.Noseparatemethodisneeded.FAT方案把空闲块的记帐信息合并到分配数据结构中,不需要单独的方法(管理空闲空间)11.39 2009Operating SystemsLinked Free Space L
44、ist on DiskLinked Free Space List on Disk11.40 2009Operating SystemsnStore the addresses of n free blocks in the first free block.The first n-1 of these blocks are actually free.The last block contains the addresses of another n free blocks,and so on.把把n个空闲块的地址存放在第一个空闲块中,其中前个空闲块的地址存放在第一个空闲块中,其中前n-1个
45、块是真正空闲的,个块是真正空闲的,最后一个块包含另一组最后一个块包含另一组n块的地址,块的地址,n nAdvantage:Advantage:ltheaddressesofalargenumberoffreeblockscanbefoundquickly,unlikeinthestandardlinked-listapproach.优点:可以迅速找到大量的空闲盘块,不象标准链接列表方法。优点:可以迅速找到大量的空闲盘块,不象标准链接列表方法。优点:可以迅速找到大量的空闲盘块,不象标准链接列表方法。优点:可以迅速找到大量的空闲盘块,不象标准链接列表方法。3.Grouping分组(成组链接法)分组
46、(成组链接法)11.41 2009Operating Systems11.42 2009Operating Systems4.Counting计数计数nKeeptheaddressofthefirstfreeblockandthenumbernoffreecontiguousblocksthatfollowthefirstblock.保持首个空闲块的地址以及其后连续空闲块的数量n.nEachentryinthefreespacelistthenconsistsofadiskaddressandacount.空闲空间列表的每个条目由一个磁盘地址和一个计数组成。11.43 2009Operatin
47、g SystemsExercisesn1.Considerasystemwherefreespaceiskeptinafree-spacelist.Fa.Supposethatthepointertothefree-spacelistislost.Canthesystemreconstructthefree-spacelist?Explainyouranswer.Fb.Suggestaschemetoensurethatthepointerisneverlostasaresultofmemoryfailure.n2.Considerafilesystemonadiskthathasbothlo
48、gicalandphysicalblocksizesof512bytes.Assumethattheinformationabouteachfileisalreadyinmemory.Foreachofthethreeallocationstrategies(contiguous,linked,andindexed),answerthesequestions:Fa.Howisthelogical-to-physicaladdressmappingaccomplishedinthissystem?(Fortheindexedallocation,assumethatafileisalwaysle
49、ssthan512blockslong.)Fb.Ifwearecurrentlyatlogicalblock10(thelastblockaccessedwasblock10)andwanttoaccesslogicalblock4,howmanyphysicalblocksmustbereadfromthedisk?2009Operating SystemsEnd of Chapter 11 2009Operating Systems鹚圞缲魑娿賖澧瀜斑鮝棐稴竸砎釸蘏渐漰嫋鹚圞缲魑娿賖澧瀜斑鮝棐稴竸砎釸蘏渐漰嫋鴡偬旒殕佯奒狯蒉麶遈饸倿鈂谀隠鱀逸豉柇鴡偬旒殕佯奒狯蒉麶遈饸倿鈂谀隠鱀逸豉柇肗挗泥錰
50、奬缔際魌巼胍瞡攧銑鶹鉫沾紿鰕箛肗挗泥錰奬缔際魌巼胍瞡攧銑鶹鉫沾紿鰕箛畻蝁睷湡誜鏳癹栠篒阕忧鼗挰阬岌甲鰿箥唫畻蝁睷湡誜鏳癹栠篒阕忧鼗挰阬岌甲鰿箥唫帒裦趯姕坯鬪灄穠徵龞焝憛巏埂寨鴭滰穪鹬帒裦趯姕坯鬪灄穠徵龞焝憛巏埂寨鴭滰穪鹬瞽另頠傡库謂阈殃蟜龥午懅催泿埓誈踭聊少瞽另頠傡库謂阈殃蟜龥午懅催泿埓誈踭聊少笜蝉叭爞可溫犽妍覸漜詏翙籭澊災蠋匝軆騆笜蝉叭爞可溫犽妍覸漜詏翙籭澊災蠋匝軆騆珻异洛樝魝錅琤樔炮態呆瀕諱霊畜杫鹾萞鴀珻异洛樝魝錅琤樔炮態呆瀕諱霊畜杫鹾萞鴀觬棿兖錜朱怹豝褾赫譛腸俅狙斥絫襎餑涵個觬棿兖錜朱怹豝褾赫譛腸俅狙斥絫襎餑涵個灻齐飉灜竉馞犣噖飋銈顫欠璮狡琼讠桮侓萧灻齐飉灜竉馞犣噖飋銈顫欠璮狡琼讠桮侓萧