Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk...

17
3/21/16 1 CSE 30341 Opera,ng System Principles File Systems CSE 30341 – Opera,ng System Principles 2 Files & File Systems File Concept Access Methods Directory Structure File-System Moun,ng File Sharing Protec,on

Transcript of Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk...

Page 1: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

1

CSE30341Opera,ngSystemPrinciples

FileSystems

CSE30341–Opera,ngSystemPrinciples 2

Files&FileSystems

•  FileConcept•  AccessMethods•  DirectoryStructure•  File-SystemMoun,ng•  FileSharing•  Protec,on

Page 2: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

2

CSE30341–Opera,ngSystemPrinciples 3

FileConcept

•  Con,guouslogicaladdressspace•  File=collec,onofrelatedinforma,onrecordedonsecondarystorage

•  Types:– Data

•  Numeric(text,ASCII;“LINE_MAX”bytes)•  Character(text,ASCII;“LINE_MAX”bytes)•  Binary(executable,readablebycomputer)

–  Program

File“interpreta,on”isuptouser/program

CSE30341–Opera,ngSystemPrinciples 4

FileStructure•  None-sequenceofwords,bytes•  Simplerecordstructure–  Lines–  Fixedlength–  Variablelength

•  ComplexStructures–  Forma\eddocument

•  Whodecides:– Opera,ngsystem–  Program

Page 3: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

3

CSE30341–Opera,ngSystemPrinciples 5

ExampleStructures

CSV

Poellabauer,Chris,an,5,3.45Doe,Jane,6,3.98Bowyer,Kevin,4,4.25

XML

<Par,cipantFN=“Chris,an”LN=“Poellabauer”><Publica,onYear=“2008”/><Publica,onYear=“2009”/></Par,cipant>

Structured

Poellabauer

Bualuan

Thain

Chris,an

Ramzi

Doug

cpoellab

rbualuan

dthain

structProfInfo{charszLast[41];charszFirst[31];charszNetID[11];};

CSE30341–Opera,ngSystemPrinciples 6

FileA\ributes•  Name–onlyinforma,onkeptinhuman-readableform•  Iden=fier–uniquetag(number)iden,fiesfilewithinfile

system•  Type–neededforsystemsthatsupportdifferenttypes•  Loca=on–pointertofileloca,onondevice•  Size–currentfilesize•  Protec=on(ACL)–controlswhocandoreading,wri,ng,

execu,ng•  Time,date,anduseriden=fica=on–dataforprotec,on,

security,andusagemonitoring•  Informa,onaboutfilesarekeptinthedirectorystructure,

whichismaintainedonthedisk

Page 4: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

4

CSE30341–Opera,ngSystemPrinciples 7

FileOpera,ons•  Fileisanabstractdatatype•  Basicopera=onsonfiles:

–  Create–  Write–  Read–  Reposi=onwithinfile–  Delete–  Truncate

•  Open(Fi)–searchthedirectorystructureondiskforentryFi,andmovethecontentofentrytomemory

•  Close(Fi)–movethecontentofentryFiinmemorybacktodirectorystructureondisk

•  Openingfiles:“remember”usedfiles;efficiency;convenience

CSE30341–Opera,ngSystemPrinciples 8

OpenFiles

•  Severalpiecesofdataareneededtomanageopenfiles:–  Filepointer:pointertolastread/writeloca,on,perprocessthathasthefileopen

–  File-opencount:counterofnumberof,mesafileisopen–toallowremovalofdatafromopen-filetablewhenlastprocessesclosesit

– Diskloca=onofthefile:cacheofdataaccessinforma,on

– Accessrights:per-processaccessmodeinforma,on

Page 5: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

5

CSE30341–Opera,ngSystemPrinciples 9

OpenFileLocking

•  Providedbysomeopera,ngsystemsandfilesystems(flockandfcntlsystemcalls)

•  Mediatesaccesstoafile

•  Mandatoryoradvisory:– Mandatory–accessisdenieddependingonlocksheldandrequested

– Advisory–processescanfindstatusoflocksanddecidewhattodo

CSE30341–Opera,ngSystemPrinciples 10

FileTypes–Name,Extension

Page 6: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

6

CSE30341–Opera,ngSystemPrinciples 11

AccessMethods•  Sequen=alAccess

readnext writenext reset skipforward

•  DirectAccess readn writen posi,onton readnext writenext rewritenn=rela,veblocknumber

CSE30341–Opera,ngSystemPrinciples 12

Sequen,al-AccessFile

Page 7: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

7

CSE30341–Opera,ngSystemPrinciples 13

Simula,onofSequen,alAccessonDirect-AccessFile

CSE30341–Opera,ngSystemPrinciples 14

DirectoryStructure

•  Acollec,onofnodescontaininginforma,onaboutallfiles

F 1 F 2 F 3F 4

F n

Directory

Files

Both the directory structure and the files reside on diskBackups of these two structures are kept on tapes

Page 8: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

8

CSE30341–Opera,ngSystemPrinciples 15

DiskStructure•  Diskcanbesubdividedintopar==ons•  Disksorpar,,onscanbeRAIDprotectedagainstfailure•  Diskorpar,,oncanbeusedraw–withoutafilesystem,or

formaVedwithafilesystem•  Par,,onsalsoknownasminidisks,slices•  En,tycontainingfilesystemknownasavolume•  Eachvolumecontainingfilesystemalsotracksthatfile

system’sinfoindevicedirectoryorvolumetableofcontents

•  Inaddi,ontogeneral-purposefilesystems,therecanbemanyspecial-purposefilesystems

CSE30341–Opera,ngSystemPrinciples 16

ATypicalFile-systemOrganiza,on

Page 9: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

9

CSE30341–Opera,ngSystemPrinciples 17

Opera,onsPerformedonDirectory

•  Searchforafile•  Createafile

•  Deleteafile

•  Listadirectory•  Renameafile

•  Traversethefilesystem

CSE30341–Opera,ngSystemPrinciples 18

OrganizetheDirectory(Logically)toObtain

•  Efficiency–loca,ngafilequickly

•  Naming–convenienttousers– Twouserscanhavesamenamefordifferentfiles– Thesamefilecanhaveseveraldifferentnames

•  Grouping–logicalgroupingoffilesbyproper,es

Page 10: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

10

CSE30341–Opera,ngSystemPrinciples 19

Single-LevelDirectory

•  Asingledirectoryforallusers

Naming problem

Grouping problem

CSE30341–Opera,ngSystemPrinciples 20

Two-LevelDirectory

•  Separatedirectoryforeachuser

■  Path name■  Can have the same file name for different user■  Efficient searching■  No grouping capability

Page 11: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

11

CSE30341–Opera,ngSystemPrinciples 21

Tree-StructuredDirectories

CSE30341–Opera,ngSystemPrinciples 22

Tree-StructuredDirectories(Cont.)

•  Efficientsearching

•  GroupingCapability

•  Currentdirectory(“workingdirectory”)– cd/spell/mail/prog– cd~– cd.– cd..

Page 12: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

12

CSE30341–Opera,ngSystemPrinciples 23

Tree-StructuredDirectories(Cont)

•  Absoluteorrela=vepathname•  Crea,nganewfileisdoneincurrentdirectory•  Deleteafile rm<file-name>•  Crea,nganewsubdirectoryisdoneincurrentdirectory mkdir<dir-name>

Example:ifincurrentdirectory/mail mkdircount

Deleting “mail” ⇒ deleting the entire subtree rooted by “mail”

CSE30341–Opera,ngSystemPrinciples 24

Acyclic-GraphDirectories

SymboliclinksinUNIX

Page 13: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

13

CSE30341–Opera,ngSystemPrinciples 25

Acyclic-GraphDirectories

CSE30341–Opera,ngSystemPrinciples 26

GeneralGraphDirectory(Cont.)

•  Howdoweguaranteenocycles?– Allowonlylinkstofiles,notsubdirectories– Every,meanewlinkisaddeduseacycledetec,onalgorithmtodeterminewhetheritisOK

–  Ignorelinksforac,vi,essuchasrecursivesearch/delete/etc.

Page 14: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

14

CSE30341–Opera,ngSystemPrinciples 27

FileSystemMoun,ng

•  Afilesystemmustbemountedbeforeitcanbeaccessed

•  Aunmountedfilesystemismountedatamountpoint

CSE30341–Opera,ngSystemPrinciples 28

(a)Exis,ng(b)UnmountedPar,,on

Page 15: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

15

CSE30341–Opera,ngSystemPrinciples 29

MountPoint

CSE30341–Opera,ngSystemPrinciples 30

FileSharing

•  Sharingoffilesonmul,-usersystemsisdesirable

•  Sharingmaybedonethroughaprotec=onscheme

•  Ondistributedsystems,filesmaybesharedacrossanetwork

•  NetworkFileSystem(NFS)isacommondistributedfile-sharingmethod

Page 16: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

16

CSE30341–Opera,ngSystemPrinciples 31

FileSharing–Mul,pleUsers

•  UserIDsiden,fyusers,allowingpermissionsandprotec,onstobeper-user

•  GroupIDsallowuserstobeingroups,permiynggroupaccessrights

CSE30341–Opera,ngSystemPrinciples 32

Protec,on•  Fileowner/creatorshouldbeabletocontrol:– whatcanbedone–  bywhom

•  Typesofaccess–  Read– Write–  Execute– Append– Delete–  List

Page 17: Lecture11-FileSystems · 2016. 3. 22. · 3/21/16 8 CSE 30341 – Operang System Principles 15 Disk Structure • Disk can be subdivided into par==ons • Disks or par,,ons can be

3/21/16

17

CSE30341–Opera,ngSystemPrinciples 33

AccessListsandGroups

•  Modeofaccess:read,write,execute•  Threeclassesofusers

RWX a)owneraccess 7 ⇒ 111

RWX b)groupaccess 6 ⇒ 110 RWX c)publicaccess 1 ⇒ 001

CSE30341–Opera,ngSystemPrinciples 34

ASampleUNIXDirectoryLis,ng