oses: 10. filesys intf. 1 operating systems v objectives –describe the user interface to the file...

40
es: 10. FileSys Intf. Operating Systems Operating Systems Objectives Objectives describe the user interface to describe the user interface to the file system (files, the file system (files, directories, access) directories, access) Certificate Program in Software D evelopment CSE-TC and CSIM, AIT September -- November, 2003 10. File System Interface (Ch. 10 S&G)

Upload: kerrie-johns

Post on 01-Jan-2016

219 views

Category:

Documents


1 download

TRANSCRIPT

OSes: 10. FileSys Intf. 1

Operating SystemsOperating Systems

ObjectivesObjectives– describe the user interface to the file describe the user interface to the file

system (files, directories, access)system (files, directories, access)

Certificate Program in Software DevelopmentCSE-TC and CSIM, AITSeptember -- November, 2003

10. File System Interface(Ch. 10 S&G)

OSes: 10. FileSys Intf. 2

ContentsContents

1.1. The File ConceptThe File Concept

2.2. Access MethodsAccess Methods

3.3. Directory StructureDirectory Structure

4.4. ProtectionProtection

5.5. Consistency SemanticsConsistency Semantics

OSes: 10. FileSys Intf. 3

1. The File Concept1. The File Concept

The file system provides a uniform logical The file system provides a uniform logical view of physical storage.view of physical storage.

Smallest logical storage unit is the Smallest logical storage unit is the filefile– usually mapped to storage on a nonvolatile usually mapped to storage on a nonvolatile

physical devicephysical device

OSes: 10. FileSys Intf. 4

1.1. File Attributes1.1. File Attributes

NameName TypeType LocationLocation SizeSize ProtectionProtection

– access controls for who can read, access controls for who can read, write, execute the filewrite, execute the file

Time(s)Time(s)

OSes: 10. FileSys Intf. 5

1.2. File Operations1.2. File Operations

View a file as an abstract data typeView a file as an abstract data type– data as bits/bytes/lines/recordsdata as bits/bytes/lines/records– operationsoperations

Six basic operations:Six basic operations:– create, write, read, seek in a file, delete, create, write, read, seek in a file, delete,

truncatetruncate

continued

OSes: 10. FileSys Intf. 6

Requires read and write pointers, or a Requires read and write pointers, or a current-file-position pointer.current-file-position pointer.

Other possible operations:Other possible operations:– append, copy, renameappend, copy, rename– get/set file attributesget/set file attributes– etc.etc.

OSes: 10. FileSys Intf. 7

1.3. Opening a File1.3. Opening a File

open()open() finds the file and stores a pointer to finds the file and stores a pointer to it in an it in an open file tableopen file table (OFT). (OFT).

I/O operations use the pointer rather than I/O operations use the pointer rather than the file name so there is no need to search the file name so there is no need to search for the file each time.for the file each time.

OSes: 10. FileSys Intf. 8

Multi-user VariationMulti-user Variation Several users may have the same file open Several users may have the same file open

at the same time.at the same time.

Use two levels of internal tables:Use two levels of internal tables:– an OFT per process storing details on the an OFT per process storing details on the

open files of the processopen files of the process e.g. file pointers, access rightse.g. file pointers, access rights

– a system-wide OFT storing a system-wide OFT storing process-independent details on the filesprocess-independent details on the files

location on disk, size, open count, lock(s)location on disk, size, open count, lock(s)

OSes: 10. FileSys Intf. 9

Two-level File TablesTwo-level File Tables

system OFT

process P1

OFT

process P2

VUW CS 305

OFT

OSes: 10. FileSys Intf. 10

1.4. File Types1.4. File Types

Useful so the OS can automatically modify Useful so the OS can automatically modify its processing behaviourits processing behaviour– e.g. differentiate between source code (open e.g. differentiate between source code (open

with an editor) and object code (execute)with an editor) and object code (execute)

– know that files are ‘related’know that files are ‘related’e.g. e.g. example.cexample.c and and example.oexample.o

continued

OSes: 10. FileSys Intf. 11

Approaches:Approaches:– file name extensions (e.g. Windows)file name extensions (e.g. Windows)– creator attributes (e.g. Mac)creator attributes (e.g. Mac)– magic numbers (e.g. UNIX)magic numbers (e.g. UNIX)

OSes: 10. FileSys Intf. 12

1.5. File Structures1.5. File Structures

Most modern OSes support a minimal Most modern OSes support a minimal number of file structures directlynumber of file structures directly– e.g. UNIX sees every file as a sequence of e.g. UNIX sees every file as a sequence of

8-bit bytes8-bit bytes

Benefits:Benefits:– applications have more flexibilityapplications have more flexibility– simplifies the OSsimplifies the OS

OSes: 10. FileSys Intf. 13

Internal File StructuresInternal File Structures

PackingPacking is required to convert between is required to convert between logical records and physical blockslogical records and physical blocks– internal fragmentationinternal fragmentation will occur will occur

Physical blocks

Logical records

OSes: 10. FileSys Intf. 14

2. Access Methods2. Access Methods

2.1. Sequential Access2.1. Sequential Access Fig. 10.3, p.347

beginningcurrentposition end

rewindread or write

OSes: 10. FileSys Intf. 15

2.2. Direct Access2.2. Direct Access

A file is made up of fixed length logical A file is made up of fixed length logical records (a disk model).records (a disk model).

Can move quickly to any record location by Can move quickly to any record location by supplying a relative record numbersupplying a relative record number– relative to the current record positionrelative to the current record position– e.g.e.g. seek(20);seek(20); // move to rec. 20// move to rec. 20

seek(-1);seek(-1); // move to rec. // move to rec. 1919

read();read();

OSes: 10. FileSys Intf. 16

2.3. Indexed Access2.3. Indexed Access

Make an index file for the file, which Make an index file for the file, which contains pointers to various recordscontains pointers to various records– improves search timeimproves search time

Fig. 10.5, p.349

AdamsArthurAsher

Smith

::

indexfile Smith, John 007 23

direct access file

OSes: 10. FileSys Intf. 17

2.4. Memory Mapping2.4. Memory Mapping

Map sections of a file into virtual memory.Map sections of a file into virtual memory.

Reads and writes to the mapped region act Reads and writes to the mapped region act as reads and writes to the file.as reads and writes to the file.

Useful way of sharing a fileUseful way of sharing a file– but requires a mutual exclusion mechanismbut requires a mutual exclusion mechanism

continued

OSes: 10. FileSys Intf. 18

file region

Process Bvirtual memory

Memory Mapping DiagramMemory Mapping Diagram

region

Process Avirtual memory

physical memory

OSes: 10. FileSys Intf. 19

3. Directory Structure3. Directory Structure

PartitionsPartitions (mini-disks, volumes) (mini-disks, volumes)– provide separate logical spaces on one diskprovide separate logical spaces on one disk– group several disks into a single logical spacegroup several disks into a single logical space

Device directoryDevice directory– holds file information (e.g. name, location, size, holds file information (e.g. name, location, size,

type) for all files in that partitiontype) for all files in that partition

OSes: 10. FileSys Intf. 20

Typical Directory OperationsTypical Directory Operations

SearchSearch Create a fileCreate a file Delete a fileDelete a file List a directoryList a directory Remove a fileRemove a file Traverse all the filesTraverse all the files

– e.g. for making backupse.g. for making backups

OSes: 10. FileSys Intf. 21

Types of Directory StructureTypes of Directory Structure

3.1. Single-level Directory3.1. Single-level Directory

3.2. Two-level Directory3.2. Two-level Directory

3.3. Tree-structured Directory3.3. Tree-structured Directory

3.4. Acyclic Graph Directory3.4. Acyclic Graph Directory

3.5. General Graph Directory3.5. General Graph Directory

OSes: 10. FileSys Intf. 22

3.1. Single-level Directory3.1. Single-level Directory

Easy to support and understand.Easy to support and understand. Problems start when there are large Problems start when there are large

numbers of files and/or users.numbers of files and/or users.

Fig. 10.7, p.351

log foo recs1 test data mail recs2

OSes: 10. FileSys Intf. 23

3.2. Two-level Directory3.2. Two-level DirectoryFig. 10.8, p.352

log foo recs1 test data mail recs2

user1 user2 user3

User FileDirectory (UFD)

Master File Directory (MFD)

continued

OSes: 10. FileSys Intf. 24

Some IssuesSome Issues

How isolated are users?How isolated are users?

How is a path defined?How is a path defined?– e.g. e.g. /user1/foo/user1/foo

How do users access system files?How do users access system files?– copyingcopying– (extendible) search paths(extendible) search paths

OSes: 10. FileSys Intf. 25

3.3. Tree-structured Directory3.3. Tree-structured DirectoryFig. 10.9, p.354

list all count

list rade

count list

dict spell

words

w7

w

root

continued

OSes: 10. FileSys Intf. 26

Treat a subdirectory like another fileTreat a subdirectory like another file– use a special bit in the directory entry to use a special bit in the directory entry to

distinguish a file (0) from a subdirectory (1)distinguish a file (0) from a subdirectory (1)

Absolute vs. relative path names?Absolute vs. relative path names?– e.g.e.g. /spell/words/rade/spell/words/rade

../spell/words/rade../spell/words/rade

How is a non-empty subdirectory deleted?How is a non-empty subdirectory deleted?

OSes: 10. FileSys Intf. 27

3.4. Acyclic Graph Directory3.4. Acyclic Graph DirectoryFig. 10.10, p.357

list all count

list rade

count list

dict spell

words

w7

w

root

continued

OSes: 10. FileSys Intf. 28

A natural generalisation of a tree-structured A natural generalisation of a tree-structured directory schemedirectory scheme– allows files/subdirectories to be sharedallows files/subdirectories to be shared

How are cycles avoided?How are cycles avoided?

A file/subdirectory may have multiple A file/subdirectory may have multiple absolute path namesabsolute path names– complicates traversalcomplicates traversal

continued

OSes: 10. FileSys Intf. 29

How are shared files/subdirectories deleted?How are shared files/subdirectories deleted?– leave ‘dangling pointers’ (cheap)leave ‘dangling pointers’ (cheap)

– use an access list (expensive)use an access list (expensive)

– use a reference countuse a reference count

OSes: 10. FileSys Intf. 30

Sharing in UNIXSharing in UNIX

Symbolic linksSymbolic links– a pointer to another file/subdirectorya pointer to another file/subdirectory– easily identified by a bit set in the file entryeasily identified by a bit set in the file entry– deletion leaves links ‘dangling’deletion leaves links ‘dangling’

Hard linksHard links– keep a reference count for hard links to a filekeep a reference count for hard links to a file– cannot link to a subdirectorycannot link to a subdirectory

avoids cyclic graphsavoids cyclic graphs

OSes: 10. FileSys Intf. 31

3.5. General Graph Directory3.5. General Graph DirectoryFig. 10.10, p.357

text mail book

avi count

book mail

avi jim

count

root

continued

OSes: 10. FileSys Intf. 32

Traversal could go into an infinite loopTraversal could go into an infinite loop– use a bounded searchuse a bounded search

A subdirectory that refers to itself will A subdirectory that refers to itself will never have a reference count of 0never have a reference count of 0– not possible to delete itnot possible to delete it

Garbage collectionGarbage collection is required to reclaim is required to reclaim inaccessible files/subdirectoriesinaccessible files/subdirectories– very expensivevery expensive

OSes: 10. FileSys Intf. 33

4. Protection4. Protection

Protection mechanisms control/limit file Protection mechanisms control/limit file and directory access operations, such as:and directory access operations, such as:– reading, writing, execution,reading, writing, execution,

appending, deletion, listingappending, deletion, listing

Protection levels and types depend on the Protection levels and types depend on the systemsystem– PC --> corporate installationPC --> corporate installation

OSes: 10. FileSys Intf. 34

4.1. Access Lists & Fields4.1. Access Lists & Fields

Access ListAccess List– specify access rights for every user of every filespecify access rights for every user of every file– tedious; leads to very large liststedious; leads to very large lists

FieldsFields (Groups) (Groups)– owner/group/worldowner/group/world– each field in UNIX has 3 bits for read, write, each field in UNIX has 3 bits for read, write,

and execute permissionsand execute permissions

OSes: 10. FileSys Intf. 35

UNIX ExampleUNIX Example

bazooka<ad>47: ls -lbazooka<ad>47: ls -ltotal 62total 62drwxr-xr-x 2 ad 512 Nov 4 1998 Figures/drwxr-xr-x 2 ad 512 Nov 4 1998 Figures/-rw-r--r-- 1 ad 14109 Nov 12 1998 Listings-rw-r--r-- 1 ad 14109 Nov 12 1998 Listings-rw-r--r-- 1 ad 1878 Nov 4 1998 abstract.tex-rw-r--r-- 1 ad 1878 Nov 4 1998 abstract.tex-rw-r--r-- 1 ad 782 Nov 4 1998 cover-note-rw-r--r-- 1 ad 782 Nov 4 1998 cover-notedrwxr-xr-x 2 ad 512 Feb 16 08:59 old_code/drwxr-xr-x 2 ad 512 Feb 16 08:59 old_code/-rw-r--r-- 1 ad 24450 Nov 4 1998 progHTTP.txt-rw-r--r-- 1 ad 24450 Nov 4 1998 progHTTP.txtdrwxr-xr-x 2 ad 512 Nov 12 1998 revisted/drwxr-xr-x 2 ad 512 Nov 12 1998 revisted/-rwxr-xr-x 1 ad 11676 Feb 16 08:52 sock_brow*-rwxr-xr-x 1 ad 11676 Feb 16 08:52 sock_brow*-rw-r--r-- 1 ad 4150 Dec 22 17:07 sock_brow.c-rw-r--r-- 1 ad 4150 Dec 22 17:07 sock_brow.c-rw-r--r-- 1 ad 887 Nov 4 1998 web-tech-addr-rw-r--r-- 1 ad 887 Nov 4 1998 web-tech-addr

Fig. 10.12, p.364

OSes: 10. FileSys Intf. 36

4.2. Passwords4.2. Passwords

A password per fileA password per file– too hard to remembertoo hard to remember

A password per subdirectoryA password per subdirectory– too course-grainedtoo course-grained

OSes: 10. FileSys Intf. 37

5. Consistency Semantics5. Consistency Semantics

Consistency semanticsConsistency semantics is how an OS deals is how an OS deals with modifications to a shared file by with modifications to a shared file by multiple users who are accessing the file at multiple users who are accessing the file at the same time.the same time.

OSes: 10. FileSys Intf. 38

Consistency Sems for UNIXConsistency Sems for UNIX

A write is A write is immediately visibleimmediately visible to every to every shared users.shared users.

Processes may share the current position Processes may share the current position pointer of the file.pointer of the file.

Users see a shared file as representing a Users see a shared file as representing a single physical entity.single physical entity.

OSes: 10. FileSys Intf. 39

Consistency Sems for Andrew FSConsistency Sems for Andrew FS A distributed file system from CMU.A distributed file system from CMU.

A write is A write is notnot immediately visibleimmediately visible.. A change becomes visible to subsequent A change becomes visible to subsequent

opens after the file has been closed.opens after the file has been closed.

Users see a shared file as representing Users see a shared file as representing several temporary (possibly different) several temporary (possibly different) images of the single physical entity.images of the single physical entity.

OSes: 10. FileSys Intf. 40

Immutable Shared FilesImmutable Shared Files

A type of file which cannot be modified if A type of file which cannot be modified if it is declared as shareable by its creator.it is declared as shareable by its creator.

Greatly simplifies sharing in a distributed Greatly simplifies sharing in a distributed file system.file system.