11 - File System Implementations

Data structures Summary

File block allocation Free space management Directory structure
Contiguous Disk block bitmap Linear list
Linked List Disk block linked list Hash table
FAT    
Indexed allocation    

Disk organization

OS Boot Block Partition Details Directory Structure File Info File Data
         

General Disk Structure: 1D Logical Block array

Logical block: Smallest accessible unit (~512B to 4KB), mapped into disk sectors (layout id disk sectors hardware dependent, dictated by drivers).

File info and data

File: Collection of logical blocks. When file size $\neq$​ multiple of logical blocks: internal fragmentation.

Data Allocation on disk

Contiguous allocation

Linked list allocation

File Allocation Table

Indexed Allocation

Free space management

2 operations: Allocate (file creation/expansion) and free (deletion/truncation)

Bitmap

Block bitmap

Block linked list

Directory structure

Track files + file information in a directory, then maps file name to file info.

Given a full path name, recursive search of directories necessary to arrive at file info.

Linear list

Hash Table

File Information

Case studies

Microsoft FAT File System

FAT entry: FREE / Block num / EOF / BAD. To find a file, you need to have the index of the first block of the file.

Directory: Special type of file. (Root directory is in a special location. Other directories are in data blocks.) Every file/subdirectory = directory entry.

Order Directory entry item Bytes
1 File name 8
2 File ext. 3
3 Attributes 1
4 Reserved 10
5 Creation date 2
6 Creation time 2
7 First disk block (FAT16) 2
8 File size 4
TOTAL   32

FAT16 can only have $2^{16}$​​​ block indices, and thus blocks, with 16 bits.

To access a file we start from the initial block and access the initial block’s next block, and so on.

Path of access

To search for an empty block, you have to do a linear pass through the whole FAT to find FREE blocks.

Boot FAT FAT dup. Root dir. Data blocks
OS boot block Partition details + File info - Dir. structure Dir. structure + File data

Extended File System 2

ext2 block group

Order Block Group Item Info
1 Superblock Total I-node #, I-nodes per group, total disk blocks, disk blocks per group
2 Group descriptors Number of free disk blocks, free I-nodes, location of bitmaps
3 Block bitmap One bit per block in BG. (0/1)
4 I-node bitmap One bit per I-node in BG. (0/1)
5 I-node table Array of indexed I-nodes of this BG.
6 Data blocks  

[1, 2] are duplicated in every block group.

Order I-node details Bytes
1 Mode 2
2 Owner info 4
3 File size 4 or 8
4 Timestamps $3 \times 4$
5 Data block pointers $15 \times 4$
6 Reference count [e.g. # hard links] 2
etc…
TOTAL   128

Note that file name is not in the I-node, i.e. it is contained in the data blocks the I-node points to.

These are the data blocks that constitute the file data. Indirect blocks do not contain file data itself.

I-node tree

How much space? (4B block address, 1KiB disk block)

\[\begin{aligned} n &= 2^{10} / 4 \quad \text{block addresses per disk block} \\ \text{blocks} &= 12 + n + n^2 + n^3 \\ \text{size} &= \# \text{blocks} \times 2^{10} \approx 16 \text{GB} \end{aligned}\]

Directory: Contains a linked list of directory entries = files/sub-directories’ info within this directory. (Root directory is at I-node 2.)

Directory entry item (in data block)
I-node number
Size of entry
(to locate next entry via moving pointer by offset)
Length of file/subdirectory name
Type (is file/subdirectory?)
File/subdirectory name

To access a file: /sub/file

  1. [I-node Table] / at I-node 2
  2. [I-node 2] File metadata for sub at disk-block 15
  3. [Disk block 15] sub at I-node 8
  4. [I-node 8] File metadata for file at disk-block 28
  5. [Disk block 28] file at I-node 4
  6. [I-node 4] actual file at disk-block 13.

To delete a file:

  1. Remove directory entry from parent (by removing from file-metadata linked list)
  2. Update I-node bitmap: mark as 0
  3. Update block bitmap: mark as 0

Directory entry

Hard Links:

Hard link

Soft/Symbolic link:

Symbolic link