Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 4.8: Directory structures, directory implementation and file allocation methods

Organising files into single-level, two-level, tree and graph directories; implementing directories with lists and hash tables; and placing file blocks with contiguous, linked and indexed allocation.

Module 4 1 hour Theory CO4
← Before
4.7 File concepts
Files and access methods
You are here
4.8 Directory structures, directory implementation and file allocation methods
Module 4 · Memory and File Management
Next →
5.1 Disks & RAID
Module 5 begins

Learning objectives

By the end of this session you should be able to:

  • Compare single-level, two-level, tree, acyclic-graph and general-graph directories.
  • Distinguish absolute and relative path names, hard and symbolic links.
  • Compare linear-list and hash-table directory implementations.
  • Explain contiguous, linked (FAT) and indexed allocation with their trade-offs.
  • Compute the maximum file size of a UNIX inode scheme.

Lecture notes

1. Directory structures

A directory is a symbol table that translates file names into file-control-block entries. Operations: search, create, delete, list, rename a file, and traverse the file system. The organisation should be efficient (locate a file quickly), allow convenient naming (same name for different users' files), and support grouping.

All files in one directory. Simple, but names must be unique across all users and there is no grouping.

directory
cat · bo · a · test · data · mail · cont · hex · records

A master file directory (MFD) with one user file directory (UFD) per user. Different users can use the same name; path = user/name. No grouping within a user.

MFD
user1 → cat, bo, test · user2 → a, test · user3 → data

Tree-structured — directories contain files and subdirectories to any depth. Absolute path from the root (/home/ravi/os/lab1.sh) or relative to the current directory (os/lab1.sh). Efficient searching and grouping. Used by every modern OS.

Lets directories share subdirectories or files (a team folder) via links: hard links (another directory entry for the same inode) or symbolic links (a file containing a path). Problems: a file has several names (traversal may count it twice) and deletion — keep a reference count and delete only when it reaches 0.

Allowing links to any directory may create cycles — a search could loop forever and a self-referencing directory may never reach count 0. Solutions: forbid links to directories, use garbage collection, or detect cycles when a link is added.

2. Directory implementation

Linear list

File names with pointers to data blocks. Simple to program; finding a file needs a linear search — slow for large directories (a sorted list or tree helps).

Hash table

A linear list plus a hash table keyed on the file name: lookup in roughly O(1). Must handle collisions (chained overflow) and a fixed table size.

3. Allocation methods — how file blocks are placed on disk

Each file occupies a set of contiguous blocks; the directory stores start and length.

count: 0–1tr: 14–16mail: 19–24

✔ Both sequential and direct access are fast (block b of file = start + b), minimal seeks. ✘ External fragmentation (as in Session 4.2), and the file size must be known in advance — growing a file may require moving it.

Each file is a linked list of blocks scattered anywhere; the directory stores the first and last block; each block holds a pointer to the next.

jeep: 9→16→1→10→25→ −1

✔ No external fragmentation, files grow easily. ✘ Only sequential access is efficient (reaching block i needs i reads); pointers use space; one damaged pointer loses the rest of the file.

FAT (File-Allocation Table), used by MS-DOS and USB drives, keeps all the pointers in one table at the start of the volume — it can be cached in memory, making random access much faster.

All pointers of a file are brought together in an index block; entry i points to the i-th block. The directory stores the index block's address.

jeep → index block 19 → [ 9, 16, 1, 10, 25, −1, … ]

✔ Direct access without external fragmentation. ✘ An index block is wasted for tiny files; large files need several: linked index blocks, a multilevel index, or the combined scheme.

The combined scheme of the UNIX inode: 12 direct pointers (small files need no extra blocks), then a single indirect, a double indirect and a triple indirect pointer.

With 4 KB blocks and 4-byte pointers (1024 pointers per block): direct = 48 KB, single indirect adds 4 MB, double indirect 4 GB, triple indirect 4 TB.

MethodSequential accessDirect accessFragmentationGrowth
ContiguousExcellentExcellentExternalHard
Linked (FAT)GoodPoor (good with cached FAT)NoneEasy
Indexed (inode)GoodGoodNone (index overhead)Easy
Free-space management (briefly)

The file system must also track free blocks: a bit vector (1 bit per block — easy to find contiguous runs), a linked list of free blocks, grouping (first free block stores addresses of n free blocks) or counting (address + run length).

VideoBytes

Directory structures

Video coming soon

Directory structures

Recorded by Dr. Krithika L.B. Slot m4-directories

File allocation methods

Video coming soon

File allocation methods

Recorded by Dr. Krithika L.B. Slot m4-allocation

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
Which directory structure allows two users to have a file named test.c but no subdirectories?

Two-level directory.

Why does linked allocation make direct access slow?

To reach block i you must follow i pointers, each needing a disk read.

A file of 6 blocks uses contiguous allocation starting at block 14. Where is logical block 4?

14 + 4 = block 18.

With 4 KB blocks and 4-byte pointers, how much data can the single-indirect pointer address?

4096 / 4 = 1024 pointers × 4 KB = 4 MB.

How does an acyclic-graph directory decide when to really delete a shared file?

It keeps a reference (link) count and frees the file when the count reaches zero.

Key takeaways

  • Directories: single-level → two-level → tree → acyclic graph (sharing via links) → general graph (cycles).
  • Directory lookup: linear list (simple) or hash table (fast).
  • Allocation: contiguous (fast, fragments), linked/FAT (no fragmentation, slow direct access), indexed/inode (direct access, index overhead).

Where this leads

Files end up as blocks on a disk. How is that disk organised, how are requests to it ordered, and how do we survive a disk failure? Module 5 starts with devices.

Go to Module 5 — Session 5.1: Disk structure and RAID →