File System Management

19
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis File System Management Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis Directory Implementation Before accessing a file, the file must first be opened by the operating system. For that, the OS uses the path name supplied by the user to locate the directory entry. A directory entry provides the name of the file, the information needed to find the blocks of the file, and information about the file‘s attributes.

description

File System Management

Transcript of File System Management

Page 1: File System Management

1

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System ManagementStorage Media

Magnetic Disks

Files and Directories

File Implementation

Directory ImplementationFree Block Management

File System Layout

Disk Performance

Floppy Disks

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory ImplementationBefore accessing a file, the file must

first be opened by the operating

system. For that, the OS uses the

path name supplied by the user to

locate the directory entry.

A directory entry provides

• the name of the file,

• the information needed to find the blocks of the file,

• and information about the file‘s attributes.

Page 2: File System Management

2

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory EntryAttribute placement

The attributes may be stored

a) together with the file name in the directory entry (MS-DOS, VMS)

b) or off the directory entry (Unix)Figure from [Ta01 p.406]

Directory Implementation

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory EntryMS-DOS directory entry

Directory entry size: 32 byte

File attributes stored in entry.

First block number points to first file block, respectively to the corresponding entry in the FAT (DOS uses chained pointers).

Figure from [Ta01 p.440]

Directory Implementation

Page 3: File System Management

3

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

attributes

Directory EntryUnix directory entry (Unix V7)

Entry size: 16 byte.Modern Unix versions allow for longer file names.

File attributes are stored in the inode.

The rest of the inode points to the file blocks

Directory Implementation

directory entry

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory EntryMS-DOS file attributes

A : Archive flag

D: Directory flag

V: Volume label flag

Figure from [Ta01 p.440]

Directory Implementation

A D V S H R

S : System file flag

H: Hidden flag

R: Read-only flag

of file creation

Page 4: File System Management

4

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory ImplementationAn MS-DOS directory (not the entry) itself is a file (a binary file)with the file type attribute set to directory.

The disk blocks pointed to contain other directory entries (eachagain of 32 byte size) which either depict files or subsequent directories (sub directories).

Upon installing an MS-DOS file system, there is automatically created a root directory.

Similar applies to Unix. When the file type attribute is set to directory, the file blocks contain directory entries.

Windows 2000 and descendants (NTFS) treat directories asentities different from files.

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Implementation

directory entry

directory entry

directory entry

directory entry

directory entry

directory entry

directory entry

directory entry

disk block

...

pointing to disk blocks containing directory entries

pointing to disk blocks containing file data

= Directory attribute set

= Directory attribute not set. Regular file.

Legend:

MS-DOS directory

Page 5: File System Management

5

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File LookupHow to find a file name in a directory

• Linear SearchEach directory entry has to be compared against the searchname (string compare). Slow for large directories.

• Binary SearchNeeds a sorted directory (by name). Entering and deleting files requires moving directory entries around in order to keep them sorted (Insertion Sort).

• Hash TableIn addition to each file name, an hash value (a number) is created andstored. Search is then done on the hash value, not on the name.

• B-treeFile names are nodes and leafs in a balanced tree. NTFS.

Directory Implementation

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File Lookup

The steps in looking up the file /usr/ast/mbox in classical Unix

Directory ImplementationFigure from [Ta01 p.447]

Page 6: File System Management

6

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System ManagementStorage Media

Magnetic Disks

Files and Directories

File Implementation

Directory Implementation

Free Block ManagementFile System Layout

Disk Performance

Floppy Disks

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block ManagementTo keep track of the blocks available for allocation (freeblocks), the operating system must somehow maintaina free block pool.

When a file is created, the pool is searched for free blocks. When a file is deleted, the freed blocks are added to the pool.

File systems using a FAT do not need a separate free block pool.Free blocks are simply marked in the table by a 0.

• Linked List• Free List• Bit Map

Free Block Pool Implementations:

Page 7: File System Management

7

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block ManagementLinked ListThe free blocksform a linked list where each block pointsto the next one (chained blocks).

• Simple ImplementationOnly first block number needed.

• Quick AccessNew blocks are prepended (LIFO principle)

• Disk I/OUpdating the pointers involves I/O.

• Block ModificationModified content hinders ‘undelete’ of the block.

Figure from [Sil00 p.388]

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

17 18 0

Free Block ManagementFree List

The free block numbers are listed in a table. The table is stored in disk blocks.The table blocks may belinked together.

• SpaceEach free block requires 4 byte in table

• ManagementAdding and deleting block numbers needs time, in particular when a table blockis almost full (additional disk I/O required).

Figu

re fr

om [T

a01

p.41

3]

Page 8: File System Management

8

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block Management

To each existing block on disk a bit is assigned. Whena block is free, the bit is set. When the block is occupied, the bit is reset (or vice versa). All bits form a bit map.

Bit Map

• CompactEach block represented by a single bit. Fixed size.

• Logical orderNeighboring bits represent neighboring blocks (logical order).Quite easy to find contiguous blocks, or blocks located close together.

• Conversion block number ↔ bit positionFrom the block number the corresponding bit position must becalculated and vice versa.

Figure from [Ta01 p.413]

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System ManagementStorage Media

Magnetic Disks

Files and Directories

File Implementation

Directory Implementation

Free Block Management

File System LayoutDisk Performance

Floppy Disks

Page 9: File System Management

9

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Layout

File system

Figure from [Ta01 p.400], modified

Each Partition starts with a boot block (first block) which is followedby the file system. The boot block may be modified by the file system.

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

FAT copy Files and directoriesFAT Root dir

Layout of FAT file system

File System Layout

Information about the filesystem location is stored in the boot block.

Number of entries in root directory is limited,except for FAT-32 where it is a cluster chain.

A copy of the FAT for reliability reasons

http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspxMicrosoft FAT-32 specification at

Page 10: File System Management

10

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System LayoutPossible file system layouts for a UNIX file system

Super block Inodes Root dir Files and directories

Super block Inodes Root dir Files and directoriesFree block pool

The inode for the root directory is located at a fixed place.

Information about filesystem (block size, volume label,size of inode list, next free inode, next free block, ...)

Bit map free block management

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File areaMFT System files

Layout of NTFS file system

File System Layout

Files for storing metadata about the file system.Actually, the MFT itself is a system file.

Master File Table. Linear sequence of 1kB records. Each record describes one file or directory. MFT is a file, may be located anywhere on disk.

More about NTFS: http://www.ntfs.com/ntfs_basics.htm

Information about the filesystem location is stored in the boot block.

Page 11: File System Management

11

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System ManagementStorage Media

Magnetic Disks

Files and Directories

File Implementation

Directory Implementation

Free Block Management

File System Layout

Disk PerformanceFloppy Disks

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Cylinder Skew

Cylinder skew example

Assumption: Reading frominner tracks towards outertracks.

Here: skew = 3 sectors.

After head has moved tonext track, sector 0 arrives just in time. Reading can continue right away.

Performance improvementwhen reading multiple tracks.

Physical disk geometry, figure from [Ta01 p.316]

Disk Performance

Page 12: File System Management

12

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk SchedulingModern disk drives are addressed as large one-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. The array of logical blocks is mapped into the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the outermost cylinder. Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.

However, it is difficult to convert a logical block into CHS:

• The disk may have defective sectors which are replaced by spare sectors from elsewhere on the disk.

• Owing to zone bit recording the number of sectors per track is not the same for all cylinders. After [Sil00 p.436]

Disk Performance

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk Scheduling• Fast access desired (high disk bandwidth)

Disk bandwidth is the total number of bytes transferred, divided by the total timefrom the first request for service until completion of the last transfer.

• Bandwidth depends on– Seek time, the time for the disk to move the heads to the

cylinder containing the desired sector.

– Rotational latency, the additional time waiting for the disk torotate the desired sector to the disk head.

• Seek time ≈ seek distance.

• Scheduling goal: minimizing seek timeScheduling in earlier days done by OS, nowadays by either OS (then guessing the physical disk geometry) or by the integrated disk drive controller.

Disk Performance

Page 13: File System Management

13

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk Scheduling

• First-Come First-Served (FCFS)

• Shortest Seek Time First (STTF)

• SCAN

• C-SCAN

• C-LOOK

Scheduling Algorithms

For the following examples: Assumption that there are 200 tracks ona single sided disk. Read requests are queued in some queue.The queue is currently holding the requests for tracks 98, 183, 37, 122, 14, 124, 65 and 67. The head is at track 53.

Disk Performance

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

FCFSDisk Scheduling

The requests are serviced in the order of their entry (first entry is served first).

Figure from [Sil00 p.437]

time

track

Page 14: File System Management

14

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

SSTFDisk Scheduling

The next request served is the one that is closest to current position (shortest seek time).

Figure from [Sil00 p.438]

time

track

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

SCANDisk Scheduling

Disk arm starts at one end of the disk and sweeps over to the other end, thereby servicing the requests.

At the other end the head reverses direction and servicing continues on the return trip.

Figure from [Sil00 p.439]

time

track

Page 15: File System Management

15

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

C-SCANDisk Scheduling

Disk arm starts at one end of the disk and sweeps over to the other end, thereby servicing the requests. At the other end the head returns to the beginning of

the disk without servicing on the return trip.

Figure from [Sil00 p.440]

time

track

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

C-LOOK

Like SCAN or C-SCAN, but the head moves only as far as the final request in each direction.

Figure from [Sil00 p.441]

time

track

Disk Scheduling

Page 16: File System Management

16

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

• SSTF is common and has a natural appeal

• SCAN and C-SCAN perform better for systemsthat place a heavy load on the disk.

• Performance depends on the number and typesof requests.

• Requests for disk service are influenced by thefile allocation method.

• Either SSTF or LOOK is a reasonable choice as default algorithm.

Disk SchedulingDisk Performance

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System ManagementStorage Media

Magnetic Disks

Files and Directories

File Implementation

Directory Implementation

Free Block Management

File System Layout

Disk Performance

Floppy Disks

Page 17: File System Management

17

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks

Figure from www.computermuseum.li

• Portable storage media• 8“ floppy in 1969• 5.25“ floppy in 1978• 3.5“ floppy in 1987

720K, 1.44 MB360k ... 1.2M80K ... 1.2MCapacity:

3.5“ disk5.25“ disk8“ disk

Floppy disks almost displaced by Flash Memory (e.g. USB Stick) now, except for the purpose of booting computers (bootable floppies).

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks

Two sided floppy disk

1

2

3

4

5

7

89

19

20

21

2223

25

2627

37

38

39

4041

43

4445

Drehrichtung

Spurnummer

Seite 1(Rückseite)

Seite 0

BIOS 0,0,1

Beginn der Spuren

Sektorerkennung BDOS: 42BIOS: 0,2,6 (Seite, Spur, Sektor)

03 2 1

62442Page 1 (Back)

Track start Rotation direction

Page 0 (Front)

Sector number

Track index (0, 1, 2, ... )

BIOS: 2,0,6 (CHS)BDOS: 42

Page 18: File System Management

18

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks

1

2

3

4

5

7

89

19

20

21

2223

25

2627

37

38

39

4041

43

4445

Drehrichtung

Spurnummer

Seite 1(Rückseite)

Seite 0

BIOS 0,0,1

Beginn der Spuren

Sektorerkennung BDOS: 42BIOS: 0,2,6 (Seite, Spur, Sektor)

03 2 1

62442Page 1 (Back)

Track start Rotation direction

Page 0 (Front)

Sector number

Track index (0, 1, 2, ... )

BIOS: 2,0,6 (CHS)BDOS: 42

BIOS = Basic Input Output SystemStored in (EP)ROM

Sector access through invoking a software-interrupt and addressinga sector by means of CHS.

BDOS = Basic Disk Operating SystemOriginates from CP/M operating system. Higher abstraction level than BIOS.

Sector access through invoking a software-interrupt and addressing a sector by means of a logical consecutive sector number (1, 2, ...).

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy DisksSector Structure

1 2 3 4 5 6 7 8 9

Sync IAM trackindex

headindex

sectorindex

sectorlength CRC DAM 128-1024

data bytesCRC/ ECC

Inter-RecordGap

Address field Data field

CRC: Cyclic Redundancy CheckECC: Error Checking/CorrectionIAM: Index Address MarkDAM: Data Address Mark

sectors

Page 19: File System Management

19

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks

342011211.44 M

30169211.2 M

158521720 K

136421360 K

DataRoot dirFAT 2FAT 1Boot sectorDisk

Starting sector numbers for system and data areas (FAT file system). All numbers are in decimal notation.

Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks

Data(5)

Data(4)

Data(3)

Data(2)

Data(1)

Data(6)

10

11

12

1314

15

16

17

18

Spur 0, Seite 1

Data(1)Data

(2)

Data(3)

Data(4)

Data(5)

Data(6) Dir.

(5)

Dir.(6)

Dir.(7)

Track 0, Page 1Track 0, Page 0

Bootstraploader

1

2

3

45

6

7

8

9

BootstrapLoader

FAT(1)

FAT(2)

FAT(3)FAT

(4)

Dir.(1)

Dir.(2)

Dir.(3)

Dir.(4)

Dir. = allocated space for root directory Track 0 of a 360 kB floppy disk