op sy 03 ch 41

37
1 Chapter 4.1: File System • What is a file system • Objectives and user requirements • Characteristics of files and directories • File system implementation • Directory implementation • Free block management • File system reliability • Increasing file system performance

Upload: google

Post on 15-Jan-2015

394 views

Category:

Education


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Op Sy 03 Ch 41

1

Chapter 4.1: File System• What is a file system• Objectives and user requirements• Characteristics of files and directories• File system implementation• Directory implementation• Free block management• File system reliability• Increasing file system performance

Page 2: Op Sy 03 Ch 41

2

Ceng 334 - Operating Systems 4-2

File System

• The collection of algorithms and data structures which perform the translation from logical file operations (system calls) to actual physical storage of information

File System

Page 3: Op Sy 03 Ch 41

3

Ceng 334 - Operating Systems 4-3

Objectives of a File System

• Provide storage of data and manipulation

• Guarantee consistency of data and minimise errors

• Optimise performance (system and user)

• Eliminate data loss (data destruction)

• Support variety of I/O devices

• Provide a standard user interface

• Support multiple users

Objectives of a File System

Page 4: Op Sy 03 Ch 41

4

Ceng 334 - Operating Systems 4-4

User Requirements

• Access files using a symbolic name

• Capability to create, delete and change files

• Controlled access to system and other users’ files

• Control own access rights

• Capability of restructuring files

• Capability to move data between files

• Backup and recovery of files

User Requirements

Page 5: Op Sy 03 Ch 41

5

Ceng 334 - Operating Systems 4-5

Files

• Naming – Name formation

– Extensions

• Structuring – Byte sequence (as in DOS, Windows & UNIX)

– Record sequence (as in old systems)

– Tree structure (as in some mainframe Oses)

Files

Page 6: Op Sy 03 Ch 41

6

Ceng 334 - Operating Systems 4-6

Files (Cont.)

• File types– Regular (ASCII, binary)

– Directories

– Character special files

– Block special files)

• File access– Sequential access

– Random access

Files

Page 7: Op Sy 03 Ch 41

7

Ceng 334 - Operating Systems 4-7

Files (Cont.)

• File attributes– Read, write, execute, archive, hidden, system

etc.

– Creation, last access, last modification

• File operations– Create, delete, rename, open, close, read, write,

append, seek, get attributes, set attributes

Files

Page 8: Op Sy 03 Ch 41

8

Ceng 334 - Operating Systems 4-8

Directories

• Where to store attributes– In directory entry (DOS, Windows)– In a separate data structure (UNIX)

• Path names– Absolute path name– Relative path name– Working (current) directory

• Operations– Create, delete, rename, open directory, close

directory, read directory, link (mount), unlink

Directories

Page 9: Op Sy 03 Ch 41

9

Ceng 334 - Operating Systems 4-9

Directories & Files (UNIX)

d2

f3f2

f1

/

d1 f4

f5 f7

d3

d4 d5 d6

f6

Disk ADisk B

Root Directory

Linked Branch

Working Directory

• Working directory : d2 • Absolute path to file f2 : /d1/d2/f2• Relative path to file f2 : f2

Unix; Directory and Files

Page 10: Op Sy 03 Ch 41

10

Ceng 334 - Operating Systems 4-10

Physical Disk Space Management

Heads

Cylinder

• Each plate is composed of sectors or physical blocks which are laid along concentric tracks

• Sectors are at least 512 bytes in size• Sectors under the head and accessed without a

head movement form a cylinder

SectorTrack

Physical Disk Space Management

Page 11: Op Sy 03 Ch 41

11

Ceng 334 - Operating Systems 4-11

File System Implementation

• Contiguous allocation

• Linked list allocation

• Linked list allocation using an index (DOS file allocation table - FAT)

• i-nodes (UNIX)

File System Implementation

Page 12: Op Sy 03 Ch 41

12

File System Implementation• A possible file system layout• MBR: Master Boot Records is used to boot computer. The end of

the MBR contains the partition table. (read boot block and execute)

Page 13: Op Sy 03 Ch 41

13

Ceng 334 - Operating Systems 4-12

Contiguous Allocation

• The file is stored as a contiguous block of data allocated at file creation

• FAT (file allocation table) contains file name, start block, length

• Advantages– Simple to implement (start block & length is

enough to define a file)– Fast access as blocks follow each other

• Disadvantages– Fragmentation– Re-allocation (compaction)

Contiguous Allocation

Page 14: Op Sy 03 Ch 41

14

Ceng 334 - Operating Systems 4-13

Linked List Allocation

• The file is stored as a linked list of blocks• Each block contains a pointer to the next

block• FAT (file allocation table) contains file

name, first block address• Advantages

– Fragmentation is eliminated– Block size is not a power of 2 because of

pointer space• Disadvantages

– Random access is very slow as links have to be followed

Linked List Allocation

Page 15: Op Sy 03 Ch 41

15

Ceng 334 - Operating Systems 4-14

Linked list allocation using an index (DOS FAT)

Disk size

EOF

1

Free

5

Free

7

Bad

Free

…..

3 75 1

0

1

2

3

4

5

6

7

FAT (File allocation table)

File blocks

n

First block address is in directory entry

Linked List (DOS FAT)

Page 16: Op Sy 03 Ch 41

16

Ceng 334 - Operating Systems 4-15

Linked list allocation using an index (Cont.)

• The DOS (Windows) FAT is arranged this way

• All block pointers are in FAT so that don’t take up space in actual block

• Random access is faster since FAT is always in memory

• 16-bit DOS FAT length is (65536+2)*2 = 131076 bytes

Linked List Using an Index

Page 17: Op Sy 03 Ch 41

17

Ceng 334 - Operating Systems 4-16

Problem

• 16-bit DOS FAT can only accommodate 65536 pointers (ie., a maximum of 64 MB disk)

• How can we handle large disks such as a 4 GB disk?

Problems

Page 18: Op Sy 03 Ch 41

18

Ceng 334 - Operating Systems 4-17

i (index)-nodes (UNIX)File mode

Number of linksUIDGID

File sizeTime created

Time last accessedTime last modified

10 disk block numbersSingle indirect block

Triple indirect blockDouble indirect block

Indirect blocks Data blocks

Unix; i-nodes

Page 19: Op Sy 03 Ch 41

19

Ceng 334 - Operating Systems 4-18

i-nodes (Cont.)

• Assume each block is 1 KB in size and 32 bits (4 bytes) are used as block numbers

• Each indirect block holds 256 block numbers

• First 10 blocks : file size <= 10 KB

• Single indirect : file size <= 256+10 = 266 KB

• Double indirect : file size <= 256*256 +266 = 65802 KB = 64.26 MB

• Triple indirect : file size <= 256*256*256 + 65802= 16843018 KB = ~16 GB

i-nodes

Page 20: Op Sy 03 Ch 41

20

Ceng 334 - Operating Systems 4-19

Directory Implementation

• DOS (Windows) directory structure

• UNIX directory structure

Directory Implementation

Page 21: Op Sy 03 Ch 41

21

Ceng 334 - Operating Systems 4-20

DOS (Windows) Directory Structure (32 bytes)

File name Ext A Reserved T PD Size

8 bytes 3 1 10 2 2 2 4

Attributes (A,D,V,S,H,R)

Time of creation

Date of creation

Pointer to first data block

DOS; Directory Structure

Page 22: Op Sy 03 Ch 41

22

Windows 98: Directory Structure N.

• DOS directory entry used in Windows 98

Page 23: Op Sy 03 Ch 41

23

Windows 98: Directory Structure Ext.

• An entry for (part of) a long file name in Windows 98.

• If attribute is 0x0F, the MS-DOS ignores the entry as invalid.

Page 24: Op Sy 03 Ch 41

24

• An example of how a long name is stored in Windows 98

• 6 bit are used for the sequence number and 63013 819 character (long file name are possible).

• Because of historic reasons this limited to 260 characters. (last sequence number 68 = 64 + 4 seq. of previous row)

• The quick brown fox jumps over the lazy dog.

Page 25: Op Sy 03 Ch 41

25

Ceng 334 - Operating Systems 4-21

UNIX Directory Structure (16 bytes)

I-node # File name2 bytes 14 bytes

Unix; Directory Structure

Page 26: Op Sy 03 Ch 41

26

Ceng 334 - Operating Systems 4-22

Path Name Lookup : /usr/ast/mbox

245

Root (/) i-node

1 .1 ..4 bin7 dev

14 lib9 etc6 usr

Root directory file block 245

132

i-node 6 of /usr

6 .1 ..

19 prog30 stu51 html26 ast45 genc

/usr directory file block 132

406

i-node 26 of /usr/ast26 .6 ..

60 mbox92 books81 src

/usr/ast directory file block 406

i-node 60 of /usr/ast/mbox

Blocks of file

Path Name Lookup

Page 27: Op Sy 03 Ch 41

27

Ceng 334 - Operating Systems 4-23

Shared Files

• File f2 is shared by two paths (users!) and there is one physical copy.

• The directories d1 & d2 point to the same i-node with link count equal to 2

• Deletion is done by decrementing the link count. When it reaches zero the file is deleted physically

/

d1 d2

f1 f2 f3

Shared Files

Page 28: Op Sy 03 Ch 41

28

Disk Space Management• Dark line (left hand scale) gives data rate of a disk• Dotted line (right hand scale) gives disk space efficiency• All files 2KB

Page 29: Op Sy 03 Ch 41

29

Ceng 334 - Operating Systems 4-24

How to Keep Track of Free Disk Blocks

• Linked list of disk blocks

• Bit maps

• Indexing as used in DOS FAT

Keeping Track of Disk Blocks

Page 30: Op Sy 03 Ch 41

30

Ceng 334 - Operating Systems 4-25

Linked List of Disk Blocks

• A block of size 1 KB can hold 512 block numbers if 16 bits are used for free block addresses

• Allocation is simple. Delete block number from free blocks list

Freedisk

blocknumbers

Freedisk

blocknumbers

Linked List of Disk Blocks

Page 31: Op Sy 03 Ch 41

31

Ceng 334 - Operating Systems 4-26

Bit Maps

• The bit map is implemented by reserving a bit string whose length equals the number of blocks

• A ‘1’ may indicate that the block is used and ‘0’ for free blocks

• If the disk is nearly full then the bit map method may not be as fast as the linked list method

Bit Maps

Page 32: Op Sy 03 Ch 41

32

File System Reliability

• File system states(a) consistent(b) missing block(c) duplicate block in free list(d) duplicate data block

Page 33: Op Sy 03 Ch 41

33

Ceng 334 - Operating Systems 4-27

Increasing File System Performance• Disks (floopies, hard disks, CD ROMS) are

still slow when compared to the memory• Use of a memory cache may speed the disk

transfers between disk and process• Blocks are read into the cache first.

Subsequent accesses are through the cache• Blocks are swapped in & out using

replacement algorithms such as FIFO, LRU• System crashes may cause data loss if

modified blocks are not written back to disk

File System Performance

Page 34: Op Sy 03 Ch 41

34

Ceng 334 - Operating Systems 4-28

Where to Put the Current “File Position” Field

• The file position field is a 16 or 32 bit variable which holds the address of the next byte to be read or written in a file

– Put it in the i-node

– Put it in process table

File Position

Page 35: Op Sy 03 Ch 41

35

Ceng 334 - Operating Systems 4-29

File Position Field in i-node

• If two or more processes share the same field, then they must have a different file position

• Since i-node is unique for a file, the file position can not be put in the i-node

File Position in i-node

Page 36: Op Sy 03 Ch 41

36

File Position in Process Table

Ceng 334 - Operating Systems 4-30

File Position Field in Process Table

• When a process forks, both the parent and the child must have the same file position

• Since the parent and the child have different process tables they can not share the same file position

• So, we can not put in process table

Page 37: Op Sy 03 Ch 41

37

Ceng 334 - Operating Systems 4-31

Solution

• Use an intermediate table for file positions

parent

child

Process tables

position

File positions table

i-nodeof

file

Solution