0% found this document useful (0 votes)
29 views34 pages

CH 14

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views34 pages

CH 14

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

File System Implementation

Chapter 14

Reading list: Sections 14.1 to 14.5 inclusive

April 30, 2025 OS: FSI 1


Objectives

◼ Describe the details of implementing

◼ local file systems

◼ directory structures

◼ Discuss:

◼ block allocation

◼ free-block algorithms

April 30, 2025 OS: FSI 2


Chapter Outline

◼ File-System Structure

◼ File-System Operations

◼ Directory Implementation

◼ Allocation Methods

◼ Free-space management

April 30, 2025 OS: FSI 3


- File-system Structure

◼ A file
◼ Logical storage unit
◼ Collection of related information
◼ File system
◼ resides on secondary storage (mainly disks). Disk provides in-place rewrite and
random access
◼ Provided user interface to storage, mapping logical to physical
◼ Provides efficient and convenient access to disk by allowing data to be stored,
located retrieved easily
◼ Organized into layers

April 30, 2025 OS: FSI 4


-- Layered File System

Application programs

Logical file system

File-organization module OS

Basic file system

I/O control

Devices

April 30, 2025 OS: FSI 5


-- Layered File System

Application programs
Interface that issues system
calls to the logical file system.

Logical file system

File-organization module

Basic file system

I/O control

Devices

April 30, 2025 OS: FSI 6


-- Layered File System

Application programs
▪ Manages the metadata
information of the files. Ex.
File control block (FCB),
Logical file system directories
▪ Uses a symbolic file name (
usually from the application
File-organization module
program) and searches the
directory to provide the file
organization module with
Basic file system
the information it needs.
▪ Also provides protection
I/O control and security

Devices

April 30, 2025 OS: FSI 7


-- Layered File System

Application programs

Logical file system


▪ Takes care of free-space
management.
File-organization module
▪ Translate logical addresses
to physical addresses:
(drive #, Cylinder #, Track
Basic file system
#, Sector #)

I/O control

Devices

April 30, 2025 OS: FSI 8


-- Layered File System

Application programs

Logical file system

Issues generic commands to


File-organization module the appropriate device driver
to read and write physical
blocks on the disk.
Basic file system
▪ Physical block address is
translated into block
I/O control number and presented to
I/O control layer.

Devices

April 30, 2025 OS: FSI 9


-- Layered File System

Application programs

Logical file system

File-organization module

Basic file system

I/O control Next slide

Devices

April 30, 2025 OS: FSI 10


… -- File-System Layers

▪ I/O control

▪ Controls devices - Consists of device drivers, interrupt handlers:

▪ Input to a device driver is generally a high-level command (e.g., retrieve block


150)

▪ Output of a device driver is low-level, hardware specific instructions used by


hardware controller, which interfaces the I/O device to the rest of the system.

▪ Usually, device driver writes specific bit patterns to special locations in the I/O
controller’s memory (Control register) – These bits tells the controller the
device location and what to do.

April 30, 2025 OS: FSI 11


- File-System Operations

◼ Several structures are used to implement a file system.

◼ These structures vary depending on the operating system and the file system, but
some general principles apply.

◼ These structures can be divided into:

◼ On-disk file-system structures

◼ In memory file-system structures

April 30, 2025 OS: FSI 12


- On-disk File-system Structures

◼ Boot control block: Contains info. needed by the system to boot OS

◼ File control block (FCB)

◼ Volume control block: Contains volume (partition) details. E.g. Number of


blocks per partition, size of blocks, free blocks, etc

◼ Directory structure per file system

April 30, 2025 OS: FSI 13


-- A Typical File Control Block (FCB)

◼ OS maintains FCB per file, which contains many details about the file
◼ Typically, permissions, size, dates, access control list (ACL)
◼ Example:

April 30, 2025 OS: FSI 14


-- In-Memory File System Structures …

◼ Mount table: Contains information about each mounted volume

◼ Directory structure cache: Holds information about recently accessed directories

◼ System-wide open-file table (copy of FCB)

◼ Per-process open-file table: Pointer to FCB and other info.

April 30, 2025 OS: FSI 15


- Directory Implementation

◼ Linear 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

April 30, 2025 OS: FSI 16


- Allocation Methods

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

◼ Contiguous allocation

◼ Linked allocation

◼ Indexed allocation

April 30, 2025 OS: FSI 17


-- Contiguous 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

April 30, 2025 OS: FSI 18


--- Contiguous Allocation of Disk Space

April 30, 2025 OS: FSI 19


-- Extent-Based Systems

◼ Many newer file systems (i.e. Veritas File System) use a modified contiguous
allocation scheme

◼ Extent-based file systems allocate disk blocks in extents

◼ An extent is a contiguous block of disks

◼ Extents are allocated for file allocation

◼ A file consists of one or more extents.

April 30, 2025 OS: FSI 20


-- Linked Allocation

◼ Each file is a linked list of


disk blocks: blocks may be
scattered anywhere on the
disk.

April 30, 2025 OS: FSI 21


--- File-Allocation Table

April 30, 2025 OS: FSI 22


-- Indexed Allocation

◼ Need index table

◼ Random access

◼ Dynamic access without external fragmentation, but have overhead of


index block.

April 30, 2025 OS: FSI 23


--- Example of Indexed Allocation

April 30, 2025 OS: FSI 24


- Free-Space Management

◼ Bit vector

◼ Linked free space list

◼ Grouping

◼ Counting

April 30, 2025 OS: FSI 25


-- Bit Vector …

◼ Bit vector (n blocks)

0 1 2 n-1


0  block[i] free
bit[i] =
1  block[i] occupied

To find the Block number of the first free block

(number of bits per word) *


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

April 30, 2025 OS: FSI 26


… -- Bit vector …

◼ Disadvantage: Bit map requires extra space


◼ Example:
block size = 4k = 212 bytes
disk size = 1 GB = 230 bytes
bit map size = 230/212 = 218 bits (or 32K bytes = 8 disk blocks)

◼ Advantage: Easy to get contiguous files

April 30, 2025 OS: FSI 27


… -- Bit vector

◼ 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[k] to have a situation where bit[k] = 1 in
memory and bit[k] = 0 on disk

◼ Solution:
◼ Set bit[k] = 1 in disk
◼ Allocate block[k]
◼ Set bit[k] = 1 in memory

April 30, 2025 OS: FSI 28


-- Linked Free Space List on Disk

◼ Advantage: No waste of space

◼ Disadvantage: Cannot get


contiguous space easily

April 30, 2025 OS: FSI 29


-- Grouping

◼ Modification of the linked free-list

◼ Stores the address of the n free blocks in the first block.

◼ The first n-1 of these blocks are actually free

◼ The last block contains the address of another n free blocks

April 30, 2025 OS: FSI 30


-- Counting

◼ This approach takes advantage of the fact that contiguous blocks are allocated
and freed simultaneously.

◼ Keeps the address of the first free blocks and the number n of free contiguous
blocks

◼ Particularly good if space is allocated using contiguous allocation.

April 30, 2025 OS: FSI 31


Summary

◼ File-System Layers
◼ Application program
◼ Logical file system
◼ File organization module
◼ Basic file system
◼ I/O control
◼ Devices
◼ File-System Implementation
◼ In Disk file-system structures
◼ In memory file-system structures
◼ Directory implementation
◼ Linear list
◼ Hash Table
◼ Allocation methods
◼ Contiguous
◼ Linked
◼ Indexed
◼ Free Space Management
◼ Bit vector
◼ Linked free space list
◼ Grouping
◼ Counting

April 30, 2025 OS: FSI 32


Disclaimer

◼ Parts of the lecture slides contain original work of Abraham Silberschatz, Peter B.
Galvin, Greg Gagne, Andrew S. Tanenbaum, and Gary Nutt. The slides are intended
for the sole purpose of instruction of Operating Systems course at KFUPM. All
copyrighted materials belong to their original owner(s).

April 30, 2025 OS: FSI 33


April 30, 2025 OS: FSI 34

You might also like