Top Banner
File 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.
26

File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

File 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.

Page 2: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

File System Mounting

A file system must be mounted before it is available to use. The OS is given the name of the device and the

location within the file structure at which to attach the file system.

The OS verifies that the device contains a valid file system.

The OS notes in its directory structure that a file system is mounted at the specified mount point.

Page 3: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Allocation Methods

Three major methods of allocating disk space are in wide use: Contiguous Linked Indexed

Page 4: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Contiguous AllocationEach file occupies a set of contiguous blocks on the

disk.Simple – only the starting location (block #) and its

length (number of blocks) are required.Random access is fairly easy.Wasteful of space (dynamic storage allocation

problem).

Page 5: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Contiguous Allocation (cont)

Files cannot grow.Mapping from logical to physical.

Block to be accessed = Q + starting address Displacement into block = R

LA/512Q

R

Page 6: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Linked Allocation

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

pointerblock =

Page 7: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Linked Allocation (cont)

Allocate as needed, link together; e.g., file starts at block 9

Page 8: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Linked Allocation (cont)

Simple – needs only a starting address.Free space management system – no waste of space.No random access.

Page 9: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Linked Allocation (cont)

Mapping

Block to be accessed is the Qth block in the linked list of blocks representing the file.

Displacement into block = R + 1

File allocation table (FAT) – disk space allocation used by MSDOS and OS/2 Contains one entry for each disk block. Use much like the linked list; contains pointers.

LA/511Q

R

Page 10: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation

Brings all pointers together into the index block.Logical view.

index table

Page 11: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Example of Indexed Allocation

Page 12: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation (cont)

Need index table.Random access is possible.Dynamic access without external

fragmentation, but have overhead of index block.

Page 13: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation (cont)

Mapping from logical to physical in a file of maximum size of 256K words and block size of 512 words. We need only 1 block for index table.

Q = displacement into index table R = displacement into block

LA/512Q

R

Page 14: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation – Mapping Mapping from logical to physical in a file of unbounded length

(block size of 512 words).Linked scheme – Link blocks of index table (no limit on size).

Page 15: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation – Mapping (cont)

Q1 = block of index table R1 is used as follows:

Q2 = displacement into block of index table R2 = displacement into block of file

LA / (512 x 511)Q1

R1

R1 / 512Q2

R2

Page 16: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation – Mapping (cont)

Two-level index (maximum file size is 512 3)

Q1 = displacement into outer index R1 is used as follows:

Q2 = displacement into block of index table R2 = displacement into block of file

LA / (512 x 512)Q1

R1

R1 / 512Q2

R2

Page 17: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Indexed Allocation – Mapping (cont)

outer-index

index table file

Page 18: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Combined Scheme: UNIX (4K bytes per block)

Page 19: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Free Space ManagementBit vector (n blocks)

Block number calculation

0 1 2 n-1

bit[i] =0 block[i] free

1 block[i] occupied

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

Page 20: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

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

Page 21: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Free Space Management (cont)

Linked list (free list) Cannot get contiguous space easily. No waste of space.

Grouping Store the addresses of n free blocks into the first free

block.

Counting Maintain address of block and the number of

contiguous blocks that are free.

Page 22: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Free Space Management (cont)

Need to protect: Pointer to free list Bit map

• Must be kept on disk• Copy in memory and disk may differ.• Cannot allow for block[i] to have a situation where

bit[i] = 1 in memory and bit[i] = 0 on disk. Solution:

• Set bit[i] = 1 in disk.• Allocate block[i]• Set bit[i] = 1 in memory

Page 23: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Directory ImplementationLinear list of file names with pointer to the data

blocks. Simple to program. Time-consuming to execute.

Hash Table – linear list with hash data structure. Decreases directory search time. Collisions – situations where two file names hash to

the same location. Fixed size of hash table is a problem.

Page 24: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Efficiency and PerformanceEfficiency dependent on:

Disk allocation and directory algorithms. Types of data kept in file’s directory entry.

Performance Disk cache – separate section of main memory for

frequently used blocks. Free-behind and read-ahead – techniques to optimize

sequential access. Improve PC performance by dedicating section of

memory as virtual disk, or RAM disk.

Page 25: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Various Disk-Caching Locations

Page 26: File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Recovery

Consistency checker – compares data in directory structure with data blocks on disk and tries to fix inconsistencies.

Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape).

Recover lost file or disk by restoring data from backup.