A File System for the 21st Century Previewing the Windows NT 50 File System.docx

上传人:b****5 文档编号:8202781 上传时间:2023-01-29 格式:DOCX 页数:13 大小:71.79KB
下载 相关 举报
A File System for the 21st Century Previewing the Windows NT 50 File System.docx_第1页
第1页 / 共13页
A File System for the 21st Century Previewing the Windows NT 50 File System.docx_第2页
第2页 / 共13页
A File System for the 21st Century Previewing the Windows NT 50 File System.docx_第3页
第3页 / 共13页
A File System for the 21st Century Previewing the Windows NT 50 File System.docx_第4页
第4页 / 共13页
A File System for the 21st Century Previewing the Windows NT 50 File System.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

A File System for the 21st Century Previewing the Windows NT 50 File System.docx

《A File System for the 21st Century Previewing the Windows NT 50 File System.docx》由会员分享,可在线阅读,更多相关《A File System for the 21st Century Previewing the Windows NT 50 File System.docx(13页珍藏版)》请在冰豆网上搜索。

A File System for the 21st Century Previewing the Windows NT 50 File System.docx

AFileSystemforthe21stCenturyPreviewingtheWindowsNT50FileSystem

AFileSystemforthe21stCentury:

PreviewingtheWindowsNT5.0FileSystem

JeffreyRichterandLuisFelipeCabrera

BecauseofthewayNTFSstoresattributes,itispossibleforalloftheattributesofasinglefile,includingitsDataattribute,toberesident.Thisimprovesperformancewhenaccessingsmallfiles.NTFSalsostoresthemostcommonattributesofafileinthefile’sdirectoryentry.

Thisarticleassumesyou’refamiliarwithC++andWin32

Codeforthisarticle:

Nov98NTFS.exe(5KB)

JeffreyRichterwroteAdvancedWindows,ThirdEdition(MicrosoftPress,1997)andWindows95:

ADeveloper’sGuide(M&TBooks,1995).Jeffcanbereachedatwww.JeffreyR.

LuisFelipeCabreraisanarchitectintheWindowsNTBaseDevelopmentgroupatMicrosoft.HisresponsibilitiesareinWindowsNT5.0storagemanagement.

ManyofyourprogrammingtaskswillbesimplifiedwhenyoutakeadvantageofthenewinnovationsintheWindowsNT®5.0filesystem(NTFS).Let'sgoonawhirlwindtourofthesenewfeatures.Remember,wearediscussingsoftwarethatisinbeta,soeverythingissubjecttochange.PleasecheckMicrosoft'smostrecentdocumentationbeforewritinganycodebasedonthisinformation.

Let'sbeginwithanoverviewoftheNTFSfilesystemlayoutondisk.Whilethisinformationisprogrammaticallyoff-limitstotheapplicationdeveloper,ahigh-levelexplanationwillmakeitmucheasierforyoutounderstandmanyofthenewNTFSfeatures.

AttheheartoftheNTFSfilesystemisaspecialfilecalledthemasterfiletable(MFT).ThisfileiscreatedwhenyouformatavolumeforNTFS.TheMFTconsistsofanarrayof1KBentries;eachentryidentifiesasinglefileonthevolume.Whenyoucreateafile,NTFSmustfirstlocateanemptyentrywithintheMFTarray(growingthearrayifnecessary);thenitfillsthe1KBentrywithinformationaboutthefile.Afile'sinformationconsistsofacollectionofattributes.Figure1showsalistofstandardattributesthatcanbeassociatedwithasinglefile(ordirectory).

Whenafileiscreated,thesystemcreatesthesetofattributesfortheMFT'sfileentryandattemptstoplacetheminsidethe1KBblock.Buttherearetwoproblems:

mostattributesarevariablelength,andmanyattributes(likeName,Data,andNamedData)canbemuchlargerthan1KB.SoNTFScan'tjustsimplythrowalltheattributesinsideanMFTentry.Instead,NTFSmustexaminetheattributes;ifthelengthofanattribute'svalueissmall,theattribute'svalueisplacedinsidetheMFTentry.Thisiscalledaresidentattribute.Iftheattribute'svalueislarge,thenthesystemplacestheattributevalueinanotherlocationonthedisk(makingthisanonresidentattribute),andsimplyplacesapointertotheattribute'svalueinsidetheMFTentry.

Today,everybodyhaslotsandlotsofsmallfilesstoredthroughouttheirharddrives.Weallhavelotsofshortcut(.LNK)filesandprobablylotsofDESKTOP.INIfilessprinkledaround.BecauseofthewaythatNTFSstoresattributesinanMFTentry,itispossibleforalloftheattributesofasinglefile,includingitsDataattribute,toberesident.Thisgreatlyimprovesperformancewhenaccessingsmallfiles.Inaddition,NTFSalsostoresthemostcommonattributesofafileinthedirectoryentrythatrepresentsthefile.ThismeansthatwhenthesystemdoesaFindFirstFile/FindNextFileoperationtoretrieveafile'snameorbasicattributes,thedatafortheseattributesisfoundinthedirectoryentry,sonootherdiskaccessisneeded.

PriortoWindowsNT4.0,anMFTentryinNTFSwas4KBinsize.This,ofcourse,allowedfileswithslightlymoredatatohavetheirdataresident.InWindowsNT4.0,MicrosoftparedthesizeofanMFTentryto1KB.MicrosoftstudiedthenumberoffilesandtheirsizesonmanytypicalsystemsandsawthatNTFSwaswastingalotofspaceinMFTentriesandthatitwouldbemoreefficienttomaketheMFTentry1KB.

Nowlet'sgooversomeofthefeaturesofferedbyNTFSthatsoftwaredeveloperscan(andshould)takeadvantageof.

Streams

It'slittleknownthatNTFSallowsasinglefiletohavemultipledatastreams.ThisfeaturehasactuallybeeninNTFSsinceitsveryfirstversion(inWindowsNT3.1)buthasbeendownplayedbyMicrosoft.Thisisunfortunatebecausestreamscanbeincrediblyusefulinmanysituations.

Forinstance,let'ssaythatyouaredevelopingabitmap-editorapplication.Whentheusersavestheirdata,youcreateaBMPfileontheharddisk.You'dalsoliketostoreathumbnailversionoftheimageaswell.Thumbnailsaretypicallystoredattheendofafile,afterthemainbitmapimage.Toshowthethumbnailimage,youmustopenthefile,parsetheheaderinformation,seektothebytesfollowingthemainimage'sdata,readinthethumbnailimage'sdata,andthendisplaythethumbnail.Youcouldstorethethumbnaildatainaseparatefile,butit'snotagoodideabecauseit'stooeasyforthemainimagefileandthethumbnailfiletogetseparated.

AnNTFSnamedstreamoffersthebestofbothworlds.Whenyourapplicationcreatesitsfile,youcanwritethemainimage'sdatatothedefault(unnamed)streamandthencreateanother(named)datastreaminsidethesamefileforthethumbnailimage'sdata.Youhaveonlyonefile,butitcontainstwodatastreams.

Tounderstandhowthisworks,let'sperformanexperiment.OnaWindowsNT-basedmachine(anyversion)openacommandshell.ThenchangetoanNTFSpartitionandenterthefollowing:

C:

\>ECHO"HiReader">XX.TXT:

MyStream

Whenyouexecutethiscommand,thesystemcreatesafilecalledXX.TXT.Thisfilecontainstwostreams:

anunnamedstreamthatcontains0bytesandanamedstream(calledMyStream)thatcontainsthetext"HiReader".Ifyouhaven'tguessedbynow,youaccessafile'snamedstreambyplacingacolonafterthefilenamefollowedbythenameofthestream.Aswithfilenames,Win32®functionstreatstreamnamesascase-preservedandsearchesarecase-insensitive.

Unfortunately,thetoolssuppliedwiththesystemtreatstreamsassecondclasscitizensatbest.Forexample,executethefollowingcommand:

C:

\>DIRXX.TXT

VolumeindriveCisWizard

VolumeSerialNumberis40E5-92D4

DirectoryofC:

\

03/18/9808:

36a0XX.TXT

1File(s)0bytes

0Dir(s)3,399,192,576bytesfree

Asyoucansee,DIRreportsthatthefilesizeis0bytes,butthisisnottrue.TheDIRcommandonlyreportstotheuserthesizeofafile'sunnamedstream;thesizesofnamedstreamswithinthefilearenotshowntotheuser.Bytheway,Exploreralsoreportsafilesizeof0bytes.Thisallowsforsomegeekypartygameswhereyoucanallocatealargestreaminafileonafriend'sdisk.Thefriendwon'tbeabletodiscoverwhereallthediskspacehasgonebecauseallofthetoolsreportthatthefileoccupiesonly0bytes!

Whenworkingwithstreams,rememberthatit'sonlythetoolsthatdon'ttreatstreamswiththerespectthattheydeserve;NTFShasfullsupportforstreams(theyevencountagainstyourstoragequota).

Now,toseethecontentsofthestream,executethiscommand:

C:

\>MORE

MyStream

"HiReader"

Here'sanotherwaytousestreams.Saythatyouarewritingaword-processingapplication.Whentheuseropensupanexistingdocument,youwillprobablycreateatemporaryfilethatholdsalloftheuser'schanges.Then,whentheuserdecidestosavethechanges,youwillwritealloftheupdatedinformationtothetemporaryfile,deletetheoriginalfile,andfinallymovethetemporaryfilebacktotheoriginalfile'slocationwhilerenamingthefile.

Thissoundsfairlysimpleandstraightforward,butyou'reprobablyforgettingafewthings.Thefinalfileshouldhavethesamecreationtimestampastheoriginal,soyou'llhavetofixthat.Thefinalfileshouldalsohavethesamefileattributesandsecurityinformationastheoriginal.Itisveryeasytomissproperlyupdatingsomeoftheseattributesduringthisfile-saveoperation.

Ifyouusestreams,alloftheseproblemsgoaway.Allstreamswithinasinglefilesharethefile'sattributes(timestamp,security,andsoon).Youshouldreviseyourapplicationsothattheuser'stemporaryinformationiswrittentoanamedstreamwithinthefile.Then,whentheusersavesthedata,renamethetemporarynameddatastreamtotheunnameddatastream,andNTFSwilldeletetheoldunnameddatastreamanddotherenameinanall-or-nothingmanner.Youwon'thavetodoanythingtothefile'sattributesatall;they'llalljustbethesame.

Beforeweleavestreams,letusjustpointoutafewmorethings.First,ifyoucopyafilecontainingstreamstoafilesystemthatdoesn'tsupportstreams(liketheFATfilesystemusedonfloppydisks),onlythedataintheunnamedstreamiscopiedover;thedatainanynamedstreamsdoesnotgetcopied.

Second,nameddatastreamscanalsobeassociatedwithadirectory.Directoriesneverhaveanunnameddatastreamassociatedwiththembuttheycertainlycanhavenamedstreams.SomeofyoumaybefamiliarwiththeDESKTOP.INIfileusedbytheExplorer.IftheExplorerseesthisfileinadirectory,itknowstoloadashellnamespaceextensionandallowstheshellnamespaceextensiontoparsethecontentsofthedirectory.ThesystemusesthisforfolderssuchasMyDocuments,Fonts,InternetChannels,andmanymore.SincetheDESKTOP.INIfiledescribeshowtheExplorershoulddisplaythecontentsofadirectory,wouldn'titmakemoresenseforMicrosofttoplacetheDESKTOP.INIdataintoanamedstreamwithinadirectory?

ThereasonMicrosoftdoesn'tdothisisbackwardcompatibility.StreamsareimplementedonlyonNTFSdrives;theydonotexistonFATfilesystemsoronCD-ROMdrives.For

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1