Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

File System Implementation File-System Structure

File System Structure File structure


File System Implementation Logical storage unit


Collection of related information




Directory Implementation
Allocation Methods File system resides on secondary storage (disks).
Free-Space Management File system organized into layers.
Efficiency and Performance File control block – storage structure consisting of
information about a file.

Layered File System in OS A Typical File Control Block (FCB)


Logical file system


Provides users the view of a contiguous sequence of words,




All file operations are done on an Open


bytes stored somewhere.


Uses a directory structure, symbolic name


File Table (OFT)


Provides protection and security




Contains information about all the




OS/user interface open files


E.g., to create a new file the API provides a call that calls


Some OS can have multiple such


the logical file system
tables, e.g., one for each process
The file organization module


Knows about files and their logical blocks (say 1,..N)


and one system-wide table


Files are organized in blocks of 32 bytes to 4K bytes




After opening a file the OS updates




Translates logical blocks into physical this OFT table and returns an index
Knows location of file, file allocation type to the raw in the table


Includes a free space manages that tracks unallocated blocks




All future references to the file are




Basic file system




done through the index and not the


Issues commands to the device driver (layer of software that


directly controls disk hardware) to read and write physical symbolic file name
blocks on the disk, 

Index is called FCB, file descriptor


Each physical block identified by a disk address (e.g., drive 2,


(Unix) or file handle (NT)


cylinder 34, track 2, sector 11)


IO control


FCB effectively is another table




The lowest level in the file system containing info about a file for the OS
Consists of device drivers and interrupt handlers to transfer FCB (is an index into a row in OFT) Directory info generally is copied into


information between the memory and the disk


FCB after file opening (compare this
A device driver translates commands such as “get me block


111” into hardware specific ISA used by hardware controller. with the PCB)
This is accomplished by writing specific bits into IO registers

Virtual File Systems Schematic View of Virtual File System

VFS allows the same system call interface (the API) to be


used for different types of file systems.

The API is to the VFS interface, rather than any specific


type of file system.

1
Directory Implementation Allocation Methods

Has a large effect on the file system performance Many files are stored on the same disk;
A) Linear list of file names with pointer to the data blocks. 

one main problem is to allocate space on disk to the files


simplest to program


An allocation method refers to how disk blocks are




time-consuming to execute as require a linear search allocated for files


E.g., to create a new file name we must search the directory to


make sure that no such file exist Three major techniques


When we open the file we must search the linear structure


Many OS implement a software cache for the most 1) Contiguous allocation




frequently/recently accessed directory information


Allocation for a file is contiguous on disk


2) Linked allocation


B) Hash Table – linear list with hash data structure.


Blocks are linked together on disk so can be anywhere


decreases directory search time greatly


3) Indexed allocation


collisions – situations where two file names hash to the same




location Blocks are mapped with a table that contains pointers to




Major difficulty is its fixed size and dependence of hash function on disk blocks (similar to page table)


the size of the table




Typical solution is to make each hash entry a linked list

Contiguous Allocation Contiguous Allocation of Disk Space

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


External fragmentation


First fit and best fit strategies to allocate

Files cannot grow.

Extent-Based Systems Linked Allocation

Many newer file systems (e.g. Veritas File System) use a Each file is a linked list of disk blocks: blocks may be
modified contiguous allocation scheme. scattered anywhere on the disk.

Extent-based file systems allocate disk blocks in extents.




block = pointer

An extent is a contiguous block of disks. Extents are




allocated for file allocation. A file consists of one or more


extents.

2
Linked Allocation (Cont.) Linked Allocation

Simple – need only starting address


Free-space management system – no waste of space
No random access

File-Allocation Table (FAT) Indexed Allocation

File-allocation table (FAT) – Linked allocation solves external fragmentation but cannot
support direct access (FAT helps in that)
disk-space allocation used by
Indexed allocation solves the direct access problem by
MS-DOS and OS/2. FAT table
Bringing all pointers together into the index block.


on each partition contains map 

Index block is an array of block addresses


of linked list 

To read the k-th block we first find its address in the index block by
looking the k-th pointer
Logical view.

index table

Example of Indexed Allocation Indexed Allocation – Mapping (Cont.)

outer-index

index table file

3
Combined Scheme: UNIX inode (4K bytes per
Free-Space Management
block)
Space represented with Bit vector (n blocks)

0 1 2 n-1

0 block[i] free
bit[i] =
1 block[i] occupied

Block number calculation


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

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

Bit map requires extra space. Example:


block size = 212 bytes (4 kbytes) Need to protect:
disk size = 230 bytes (1 gigabyte) Pointer to free list


Bit map


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


Must be kept on disk


Easy to get contiguous files




Copy in memory and disk may differ (coherence issue).




Linked list (free list of blocks is linked together)


Cannot allow for block[i] to have a situation where bit[i] =


Cannot get contiguous space easily




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


No waste of space


Solution:


Set bit[i] = 1 in disk.




Allocate block[i]


Set bit[i] = 1 in memory




File system Efficiency and


Linked Free Space List on Disk
Performance

Efficiency dependent on:


disk allocation and directory algorithms


Performance
Disk/buffer cache – separate section of main memory for


frequently used file blocks (regular IO)


Page cache – caches pages rather than blocks with VM


techniques (memory-mapped IO)


Dedicating section of memory as virtual disk, or RAM disk.


4
Various Disk-Caching Locations Page Cache

A page cache caches pages rather than disk blocks


using virtual memory techniques.

Memory-mapped I/O uses a page cache.

Routine I/O through the file system uses the buffer (disk)
cache.

This leads to the following figure.

I/O Without a Unified Buffer Cache

You might also like