Unit 4 File Management System.ppt (File Services)

AnilkumarBrahmane2 13 views 57 slides May 17, 2024
Slide 1
Slide 1 of 57
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57

About This Presentation

This is for learning purpose.


Slide Content

Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Prof. A. V. Brahmane
Assistant Professor
E-mail : [email protected]
Contact No: 91301 91301 Ext :145, 9922827812
Subject-Operating System and Administration (CO2013)
Unit IV-Introduction to the File System

Content
•Internal representation of the files,
•i-node,
•structure of regular files,
•directories,
•conversion of pathnames to i-node, Superblock,
•i-node assignments to new files,
•Allocation of disk blocks
•Pathnames,
•File system,
•Mounting and unmounting,
•The organization of the File Tree, File Types, File Attributes, Access Control lists.
•Case Study –Open Source Automation Red Hat Ansible, Introduction, Overview and setup, How
Ansible works, Playbooks, Variables, Advanced execution.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Internal Representation of Files
•EveryfileaUNIXsystemhasauniqueinode.Processesinteractwithfilesusing
welldefinedsystemcalls.Theusersspecifyafilewithacharacterstringwhichis
thefile'spathandthenthesystemgettheinodewhichismappedtothefile
whichcorrespondstothepath.
•Thealgorithmsdescribedbelowareabovethelayerofbuffercache.
Diagrammatically,itcanbeshownlikethis:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

File system Algorithms
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Inodes
•Inodes exist in a static form on the disk. The kernel reads them into
in-core inodes and modifies them.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Disk inodes consists of the following fields:
•Ownerinformation:ownershipisdividedintoauserandagroupofusers.Root
userhasaccesstoallthefiles.
•Filetype:itstateswhetherafileisanormalfile,adirectory,ablockorcharacter
specialfile,oradevicefile.
•Fileaccesspermissions:thereare3typesofaccesspermissions:owner,group
andothers.Thereareseparatepermissionsforreading,writingandexecuting.
Sinceexecutepermissionisnotapplicabletoadirectory,executepermissionfora
directorygivestherighttosearchinsidethedirectory.
•Accesstimes:thetimesatwhichthefilewaslastaccessedandlastmodified,and
thetimeatwhichtheinodeswaslastmodified
•Numberoflinks:numberofplacesfromwhichthefileisbeingreferred.
•.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Arrayofdiskblocks:eveniftheusersgetalogicallysequentialrepresentationof
datainfiles,theactualdataisscatteredacrossthedisk.Thisarraykeepsthe
addressesofthediskblocksonwhichthedataisscattered.
•Filesize:theaddressingofthefilebeginsfromlocation0fromrelativetothe
startinglocationandthesizeofthefileisthemaximumoffsetofthefile+1.For
example,ifausercreatesafileandwritesabyteatoffset999,thesizeofthefile
is1000
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Sample Disk Inode
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

The in-core inodes
•Thein-coreinodescontainthefollowingfieldsinadditionaltothefieldsofthe
diskinode:
•Statusoftheinode
•Locked.
•Aprocessis(ormanyprocessesare)waitingforittobeunlocked.
•Thedataintheinodediffersfromthediskinodeduetochangeintheinode
data.
•Thedataintheinodediffersfromthediskinodeduetochangeinthefile
data.
•Thefileisamountpoint(discussedlater).
•Thedevicenumberofthelogicaldeviceofthefilesystemonwhichthefile
resides.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Inodenumber:thediskinodesareplacedinanarray.Sothenumberoftheinode
isnothingbuttheindexoftheinodeinthearray.Thatiswhythediskcopydoes
notneedtostoretheinodenumber.
•Pointstoinodes:justlikethebuffercache,thein-coreinodesarenothingbuta
cachefordiskinodes(butwithsomeextrainformationwhichisdeterministic).In-
coreinodesalsohavehashqueuesandafreelistandthelistsbehaveinavery
similarwaytothebufferlists.Theinodehasnextandpreviouspointerstothe
inodesinthehashqueueandfreelists.Thehashqueueshaveahashfunction
basedonthedevicenumberandinodenumber.
•Referencecount:itgivesthenumberofinstancesoffilesthatareactivecurrently.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Accessing Inodes
•Thealgorithmigetallocatesanin-corecopyofaninode.
•Iftheinodeisnotfoundonahashqueue,itallocatesaninodefromthefreelist
andreadsthediskcopyintothein-coreinode.
•Italreadyknowstheinodenumberanddevicenumber.
•Itcalculatesthelogicalblocknumberonwhichthediskinoderesidesaccording
tohowmanyinodesfitintoonediskblock.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Important Calculation
•Theformulaforcalculatingthelogicalblocknumberis:
•blocknumber=((inodenumber-1)/numberofinodesperblock)+startblockof
inodelist
•wherethedivisionoperationreturnstheintegerpartofthequotient.
•Tofindthebyteoffsetoftheinodeinthatblock,thisfollowingformulaisused:
•byteoffset=((inodenumber-1)%numberofinodesperblock)*sizeofdisk
inode
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithm for allocation of incore inode -iget
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Releasing Inodes –iput
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Structure of a Regular File
•InUNIX,thedatainfilesisnotstoredsequentiallyondisk.
•Ifitwastobestoredsequentially,thefilesizewouldnotbeflexiblewithoutlarge
fragmentation.
•Incaseofsequentialstorage,theinodewouldonlyneedtostorethestarting
addressandsize.
•Instead,theinodestoresthediskblocknumbersonwhichthedataispresent.
•Butforsuchstrategy,ifafilehaddataacross1000blocks,theinodewouldneed
tostorethenumbersof1000blocksandthesizeoftheinodewoulddiffer
accordingtothesizeofthefile.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Direct and Indirect Blocks in Inode
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Tobeabletohaveconstantsizeandyetallowlargefiles,indirectaddressingisused.
•Theinodeshavearrayofsize13whichforstoringtheblocknumbers,although,the
numberofelementsinarrayisindependentofthestoragestrategy.
•Thefirst10membersofthearrayare"directaddresses",meaningthattheystorethe
blocknumbersofactualdata.
•The11thmemberis"singleindirect",itstorestheblocknumberoftheblockwhichhas
"directaddresses".
•The12thmemberis"doubleindirect",itstoresblocknumberofa"singleindirect"block.
•Andthe13thmemberis"tripleindirect",itstoresblocknumberofa"doubleindirect"
block.
•Thisstrategycanbeextendedto"quadruple"or"quintuple"indirectaddressing.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Ifalogicalblockonthefilesystemholds1Kbytesandthatablocknumberis
addressablebya32bitinteger,thenablockcanholdupto256blocknumbers.
Themaximumfilesizewith13memberdataarrayis:
•10directblockswith1Kbyteseach = 10Kbytes
•1indirectblockwith256directblocks = 256Kbytes
•1doubleindirectblockwith256indirectblocks = 64Mbytes
•1tripleindirectblockwith256doubleindirectblocks= 16Gbytes
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Toaccessbyteoffset9000:Thefirst10blockscontain10Kbytes.So9000shouldbein
thefirst10block.9000/1024=8soitisinthe8thblock(startingfrom0).And9000%
1024=808sothebyteoffsetintothe8thblockis808bytes(startingfrom0).(Block367
inthefigure.)
•Toaccessbyteoffset350000:Thefirst10blockscontain10Kbytes(350000-10240=
339760).Asingleindirectblockcontains256Kbytes.(339760-(256*1024)=77616).So
adoubleindirectblock(block9156inthefigure)mustbeused.Everysingleindirect
blockinthedoubleindirectblockcontains256K,sodatamustbeinthe0thsingle
indirectblock(block331inthefigure).Everydirectblockinthesingleindirectblock
addresses10Kbytes(77616/10240=7).Sothedatamustbein7th(startingfrom0)
directblock(blocknumber3333inthefigure).Andthebyteoffsetwillbe77616%1024
=816.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

bmap Algorithm
•The algorithmbmapis used to convert logical byte offset of a file to a physical
disk block:
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithm -bmap
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Directories
•Directoryfileshaveentriesofsubdirectoriesandfilesthatresideinsidethem.
•Directoryfileshavethemappingofafilenameanditsinodenumber.
•Onedirectoryentrytakes16bytes.
•14bytesaregivenforthenameofthefileand2bytesforinodenumber.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Directory layout for /etc
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Theentry.hastheinodenumberofthethedirectoryfileitself.
•And..hastheinodenumberoftheparentdirectory..and..fortherootdirectory
arenothingbutinodenumbersoftherootdirectoryitself.
•Entriesthathavetheinodenumber0areempty(i.e.deletedfiles).
•Thekernelhasexclusivewritestowritetoadirectory.
•Theaccesspermissionfordirectoriesmeandifferentthings.
•Readpermissionisforreadingthecontentsofthedirectory,writepermission
giventhepermissiontocreatefilesanddirectoriesinthatdirectory,andthe
executepermissiongivestherighttosearchinthatdirectory.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Conversion of Path Name to an Inode
•Algorithmnamei(nametoinode)isusedforconvertingapathtoaninode
number.
•Thekernelparsesthepathbyaccessingeachinodeinthepathandfinally
returningtheinodeoftherequiredfile.
•Everyprocesshasacurrentdirectory.Thecurrentdirectoryofprocess0isthe
rootdirectory.
•Foreveryotherprocess,itisthecurrentdirectoryofitsparentprocess.Laterthe
processcanchangethecurrentdirectorywiththesystemcallchdir.
•Theinodeofthecurrentdirectoryisstoredintheu-area.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Searchesstartwithrespecttothecurrentdirectoryunlessthepathbeginswith
the/component,statingthatthesearchshouldstartwiththerootdirectory.
•Inodenumberoftherootispresentastheglobalvariable.Evenifthecurrent
rootischangedbyusingchroot(moreonthislater),thecurrentrootinode
numberisstoredintheu-area.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithmnamei
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Superblock
•Thecontentsofthesuperblockare:
•sizeofthefilesystem.
•numberoffreeblocksinthefilesystem.
•listoffreeblocksinthefilesystem.
•pointertothenextfreeblockinthefreeblockslist
•sizeoftheinodeslist.
•numberoffreeinodesinthefilesystem.
•listoffreeinodesinthefilesystem.
•pointertothenextfreeinodeinthefreeinodeslist.
•lockfieldsforthefreeblocksandfreeinodeslist.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Superblock cont….
•afieldindicatingwhetherthesuperblockhaschanged.
•Thekernelperiodicallywritesthesuperblocktothediskifithadbeenmodified
sothatitisconsistentwiththedataonthedisk.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Inode Assignment to a New File
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

ialloc
•Ifthelistofinodesnumbersinthesuperblockisnotempty,thekernelassigns
thenextinodenumber,allocatesafreein-coreinodeforthenewlyassigneddisk
inodeusingalgorithmiget,copiesthediskinodetothein-corecopy,initializes
thefieldsintheinodeandreturnsthelockedinode.Itupdatestheinodeondisk
toindicatethattheinodeisinuse.
•Ifthesuperblocklistoffreeinodesisempty,thekernelsearchesthediskand
placesasmanyfreeinodenumbersaspossibleintothesuperblock.Thekernel
readstheinodelistondisk,blockbyblock,andfillsthesuperblocklistofinode
numberstocapacity,rememberingthehighest-numberedinodethatitfinds
("remembered"inode).Itisthelastonesavedinthesuperblock.Thenexttime
thekernelsearchesthediskforfreeinodes,itusestherememberedinodeasits
startingpoint,therebyassuringthatitwastesnotimereadingdiskblockswhere
nofreeinodesshouldexist.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Two Arrays of Free Inode Numbers
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithm for freeing inodes (ifree)
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Ifthesuperblockislocked,thealgorithmreturns,theinodenumberisnot
updatedinthefreelistofinodenumbers.
•Buttheinodecanbefoundwhensearchingthediskblocks.Ifthediskblockslist
isfullandtheinodenumberislessthantherememberedinodenumber,the
replacetherememberedinodenumberwiththeinputinodenumber,sothatthe
searchwillstartfromthatinode.
•Ideally,thereshouldneverbefreeinodeswhoseinodenumberislessthanthe
rememberedinodenumber,butexceptionsarepossible.
•Ifaninodeisbeingfreedandthesuperblockislocked,insuchsituation,theitis
possibletohaveaninodenumberthatisfreeandislessthantheremembered
inodenumber.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Placing Free Inode Numbers into Super Block
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Allocation of Disk Blocks
•Whendataiswrittenonafile,thekernelmustallocatediskblocksfromthefile
system(fordirectdatablocksorsometimes,indirectdatablocks).
•Thefilesystemsuperblockcontainsanarraythatisusedtocachethenumbersof
freediskblocksinthefilesystem.
•Theutilityprogrammkfs(makefilesystem)organizesthedatablocksofafile
systeminalinkedlist,suchthateachlinkofthelistisadiskblockthatcontainsan
arrayoffreediskblocknumbers,andonearrayentryisthenumberofthenext
blockofthelinkedlist.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Linked List of Free Disk Block Numbers
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Algorithm for allocation of disk blocks (alloc)
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Theprogrammkfstriestoorganizetheoriginallinkedlistoffreeblocknumberssothat
blocknumbersdispensedtoafileareneareachother.
•Thishelpsperformance,becauseitreducesdiskseektimeandlatencywhenaprocess
readsafilesequentially.
•Thekernelmakesnoattempttosortblocknumbersonthefreelist.
•Thealgorithmfreeforfreeingablockisthereverseoftheoneforallocatingablock.
•Ifthesuperblocklistisnotfull,theblocknumberofthenewlyfreedblockisplacedon
thesuperblocklist.
•If,however,thesuperblocklistisfull,thenewlyfreedblockbecomesalinkblock;the
kernelwritesthesuperblocklistintotheblockandwritestheblocktodisk.
•Itthenplacestheblocknumberofthenewlyfreedblockinthesuperblocklist:That
blocknumberistheonlymemberofthelist.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

An example of how the super block free data blocks list works
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thereisadifferenceishowfreeinodenumbersaremanagedandhowfreedisk
blocknumbersaremanaged.
•Allthefreediskblocknumbersarestoredasalinkedlistofarraysbutincaseof
freeinodenumbers,allthefreeinodenumbersarenotstored.
•Afterthecapacityofthefreeinodenumbersexceeds,theotherfreeinode
numbersarenotstoredanywhere.
•Thereare3reasonsforthisdifferenttreatment:
•Thekernelcandeterminewhetheraninodeisfreebyinspectingitsfiletype.However,thereisno
waytoknowwhetheradiskblockisfreebylookingatthedatainit.
•Diskblocklendthemselvestotheuseoflinkedlist:adiskblockeasilyholdslargelistsoffree
blocknumbers.Butinodeshavenoconvenientplaceforbulkstorageoflargelistoffreeinode
numbers.
•Userstendtousefreediskblocksmorethanfreeinodes,sotheperformancelaginsearching
wouldbemorenoticeableincaseofdiskblocksthaninodes.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

Other File Types
•TheUNIXsystemsupportstwootherfiletypes:pipesandspecialfiles.Apipe,
sometimescalledafifo(first-in-first-out),differsfromaregularfileinthatitsdata
istransient;oncedataisreadfromapipe,itcannotbereadagain.Also,thedata
isreadintheorderthatitwaswrittentothepipe,andthesystemallowsno
deviationfromthatorder.Thekernelstoresdatainapipethesamewayitstores
datainanordinaryfile,exceptthatitusesonlythedirectblocks,nottheindirect
blocks.Pipesaredescribedlater.
•OthertypesinUNIXsystemarespecialfiles,includingblockdevicespecialfiles
andcharacterdevicespecialfiles.Bothtypesspecifydevices,andthereforethe
fileinodesdonotreferenceanydata.Instead,theinodecontainstwonumbers
knownasthemajorandminordevicenumbers.Themajornumberindicatesa
devicetypesuchasterminalordisk,andtheminornumberindicatestheunit
numberofthedevice

DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

•Thank you …..
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Tags