Chapter 11:
Implementing File Systems
Chapter 11: Implementing File Systems
File-System Structure
File-System Implementation
Directory Implementation
Allocation Methods
Free-Space Management
Efficiency and Performance
Recovery
Log-Structured File Systems
NFS
Example: WAFL File System
Operating System Principles 11.2 Silberschatz, Galvin and Gagne ©2005
Objectives
To describe the details of implementing local file systems and
directory structures
To describe the implementation of remote file systems
To discuss block allocation and free-block algorithms and trade-offs
Operating System Principles 11.3 Silberschatz, Galvin and Gagne ©2005
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
Operating System Principles 11.4 Silberschatz, Galvin and Gagne ©2005
A Typical File Control Block
Operating System Principles 11.5 Silberschatz, Galvin and Gagne ©2005
In-Memory File System Structures
The following figure illustrates the necessary file system structures
provided by the operating systems.
Figure 12-3(a) refers to opening a file.
Figure 12-3(b) refers to reading a file.
Operating System Principles 11.6 Silberschatz, Galvin and Gagne ©2005
In-Memory File System Structures
Operating System Principles 11.7 Silberschatz, Galvin and Gagne ©2005
Virtual File Systems
Virtual File Systems (VFS) provide an object-oriented way of
implementing file systems.
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.
Operating System Principles 11.8 Silberschatz, Galvin and Gagne ©2005
Schematic View of Virtual File System
Operating System Principles 11.9 Silberschatz, Galvin and Gagne ©2005
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
Operating System Principles 11.10 Silberschatz, Galvin and Gagne ©2005
Allocation Methods
An allocation method refers to how disk blocks are allocated for
files:
Contiguous allocation
Linked allocation
Indexed allocation
Operating System Principles 11.11 Silberschatz, Galvin and Gagne ©2005
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
Operating System Principles 11.12 Silberschatz, Galvin and Gagne ©2005
Contiguous Allocation of Disk Space
Operating System Principles 11.13 Silberschatz, Galvin and Gagne ©2005
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.
Operating System Principles 11.14 Silberschatz, Galvin and Gagne ©2005
Linked Allocation no random access
Operating System Principles 11.15 Silberschatz, Galvin and Gagne ©2005
File-Allocation Table
Operating System Principles 11.16 Silberschatz, Galvin and Gagne ©2005
Indexed Allocation
random access
Brings all pointers together into the index block.
Logical view.
index table
Operating System Principles 11.17 Silberschatz, Galvin and Gagne ©2005
Example of Indexed Allocation
Operating System Principles 11.18 Silberschatz, Galvin and Gagne ©2005
Indexed Allocation – Mapping (Cont.)
outer-index
index table file
Operating System Principles 11.19 Silberschatz, Galvin and Gagne ©2005
Combined Scheme: UNIX (4K bytes per block)
fast for small files that use direct blocks only
else slower random access
can use sharding (actually not faster, because parallel but must still
read very big data) and mem-cache (to reduce I/O on disk)
Operating System Principles 11.20 Silberschatz, Galvin and Gagne ©2005
Free-Space Management
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
Operating System Principles 11.21 Silberschatz, Galvin and Gagne ©2005
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
No waste of space
Grouping
Counting
Operating System Principles 11.22 Silberschatz, Galvin and Gagne ©2005
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
Operating System Principles 11.23 Silberschatz, Galvin and Gagne ©2005
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
Operating System Principles 11.24 Silberschatz, Galvin and Gagne ©2005
Linked Free Space List on Disk
Operating System Principles 11.25 Silberschatz, Galvin and Gagne ©2005
FAT (12, 16, 32) system
File Allocation Table
File allocation File allocation
Boot sector Root directory Other directories and all files
table 1 table 2 (duplicate)
0000
0001
Name Property Start
0002 3 File 1 … 2
0003 4 File 2 … 5
0004 EOF File 3 … 7 2 3 4
0005 6
0006 8 File1 File1 File1
0007 EOF
0008 EOF 5 6 7
0009 0000
… Cluster File2 File2 File3
◼ FAT12: 32MB 8 9 10
◼ FAT16: 4GB File2 empty empty
◼ FAT32: 8TB
26
Operating System Principles 11.26 Silberschatz, Galvin and Gagne ©2005
Boot sector
Operating System Principles 11.27 Silberschatz, Galvin and Gagne ©2005
Operating System Principles 11.28 Silberschatz, Galvin and Gagne ©2005
Long file name
…
Entry 32 bytes
Entry ext N 32 bytes
…
Entry ext 2
Entry ext 1
Entry
Entry
…
29
Operating System Principles 11.29 Silberschatz, Galvin and Gagne ©2005
Entry ext
Offset # byte mean
0 1 Entry order (start at 1)
1 A (10d) 5 Unicode characters –UTF16
B (11d) 1 If entry ext (= 0Fh)
E (14d) C (12d) 6 unicode characters
1C (28d) 4 2 unicode characters
30
Operating System Principles 11.30 Silberschatz, Galvin and Gagne ©2005
NTFS (New Technology File System)
16 exabytes
(16 billion GB)
Standard Security
information Filename descriptor Data 31
Operating System Principles 11.31 Silberschatz, Galvin and Gagne ©2005
Unix /Linux file system
I-node
boot block super block I-node files and directories
◼ Single indirect:
256KB
◼ Double indirect:
256*256 = 65 MB
◼ Triple indirect:
256*256*256 =
16GB
32
Operating System Principles 11.32 Silberschatz, Galvin and Gagne ©2005
UNIX V7 file system
33
Operating System Principles 11.33 Silberschatz, Galvin and Gagne ©2005
End of Chapter 11