chapter 11: file system implementation hung q. ngo kyunghee university spring 2009

24
Chapter 11: File System Chapter 11: File System Implementation Implementation Hung Q. Ngo KyungHee University Spring 2009 http://uclab.khu.ac.kr/lectures/2009-1-os.html

Upload: benjamin-jordan

Post on 28-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Chapter 11: File System Chapter 11: File System ImplementationImplementation

Hung Q. Ngo

KyungHee University

Spring 2009

http://uclab.khu.ac.kr/lectures/2009-1-os.html

11.2 Hung Q. Ngo Spring 2009Operating System

Chapter 11: File System ImplementationChapter 11: File System Implementation

File-System Structure

Allocation Methods

Free-Space Management

Note: Some slides and/or pictures in the following areadapted from slides ©2005 Silberschatz, Galvin, and Gagne. Many slides generated from my lecture notes by Kubiatowicz.

11.3 Hung Q. Ngo Spring 2009Operating System

ObjectivesObjectives

To describe the details of implementing local file systems and directory structures

To discuss block allocation and free-block algorithms and trade-offs

11.4 Hung Q. Ngo Spring 2009Operating System

File-System StructureFile-System Structure

File structure

Logical storage unit

Collection of related information

File system resides on secondary storage (disks)

File system organized into layers

File control block – storage structure consisting of information about a file

11.5 Hung Q. Ngo Spring 2009Operating System

Layered File SystemLayered File System

Basic file system: each physical block is identified by its numeric disk address, e.g. drive 1, cylinder 73, track 2, sector 10

File-organization module: translation between logical blocks and physical blocks. Free space management

Logical file system: manages directory structure, maintains file structure via file-control blocks (FCB), responsible for protection and security

11.6 Hung Q. Ngo Spring 2009Operating System

File-System ImplementationFile-System Implementation

11.7 Hung Q. Ngo Spring 2009Operating System

On-Disk File System StructureOn-Disk File System Structure

11.8 Hung Q. Ngo Spring 2009Operating System

In-Memory File System StructureIn-Memory File System Structure

11.9 Hung Q. Ngo Spring 2009Operating System

Opening & Reading a FileOpening & Reading a File

Per process: store current file pointer, access rights, accounting info, etc.

system-wide: location of file on disk, access dates, file size...

11.10 Hung Q. Ngo Spring 2009Operating System

Allocation MethodsAllocation Methods

An allocation method refers to how disk blocks are allocated for files:

Contiguous allocation

Linked allocation

Indexed allocation

11.11 Hung Q. Ngo Spring 2009Operating System

Contiguous AllocationContiguous Allocation

Each file occupies a set of contiguous blocks on the disk

Simple – only starting location (block #) and length (number of blocks) are required

Random access

Wasteful of space (dynamic storage-allocation problem)

Files cannot grow

11.12 Hung Q. Ngo Spring 2009Operating System

Linked AllocationLinked Allocation

Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.

Directory table stores pointers to the start and end blocks

Each block stores pointer to next block (usually first/last 4bytes) and block data

pointer

Data

block =

11.13 Hung Q. Ngo Spring 2009Operating System

Linked Allocation (Cont.)Linked Allocation (Cont.)

Simple – need only starting address

Free-space management system – no waste of space

No random access

File-allocation table (FAT) – disk-space allocation used by MS-DOS and OS/2.

11.14 Hung Q. Ngo Spring 2009Operating System

File-Allocation TableFile-Allocation Table

EOF

0300

11.15 Hung Q. Ngo Spring 2009Operating System

Indexed AllocationIndexed Allocation

Brings all pointers together into the index blocks.

Logical view.

Random access Dynamic access without external fragmentation, but have overhead of index block.

index table

11.16 Hung Q. Ngo Spring 2009Operating System

Example of Indexed AllocationExample of Indexed Allocation

11.17 Hung Q. Ngo Spring 2009Operating System

Quiz on Indexed AllocationQuiz on Indexed Allocation

HDD = 32GB

Block size = 512Bytes

Maximum file size =256KB

How many blocks used to store the index tables?

5 10 10 25 26 2632 2 2 2 2 2 2 block numbers

needs at least 26bits to encode each entry in the index table=4bytes

File size max = 256KB = 512 blocks entry table must store 512 entries

512 4 4

GB KB KB blocks

bytes

blocks

11.18 Hung Q. Ngo Spring 2009Operating System

Combined Scheme: UNIX iNode Table Combined Scheme: UNIX iNode Table (4K bytes per block)(4K bytes per block)

(12)

11.19 Hung Q. Ngo Spring 2009Operating System

Memory Management Using iNodesMemory Management Using iNodes

11.20 Hung Q. Ngo Spring 2009Operating System

Free-Space ManagementFree-Space Management

Free-space linked list

Bitmap

11.21 Hung Q. Ngo Spring 2009Operating System

Linked Free Space List on DiskLinked Free Space List on Disk

Block #2 Block #3

Quiz:

HDD = 20MB

Block size = 1KB

If disk is totally empty, how many blocks to store the free space linked list?

15 15

15

1515

20 2 2

2 block numbers need 2bytes to save the block numbers

1 block = 1024 bytes save up to 511 free blocks

22 free blocks 40511

MB KB blocks

blocks

Next block in the linked list

11.22 Hung Q. Ngo Spring 2009Operating System

Free-Space ManagementFree-Space Management

Bit vector (n blocks)

0 1 2 n-1

bit[i] = 1 block[i] free

0 block[i] occupied

First free block number calculation:

(number of bits per word) *(number of 0-value words) +offset of first 1 bit

11.23 Hung Q. Ngo Spring 2009Operating System

Free-Space Management (Cont.)Free-Space Management (Cont.)

Bit map requires extra space

Example:

block size = 212 bytes

disk size = 230 bytes (1 gigabyte)

n = 230/212 = 218 bits (or 32K bytes)

Easy to get contiguous files

Linked list (free list)

Cannot get contiguous space easily

End of Chapter 11End of Chapter 11