Tutorials Logic, IN info@tutorialslogic.com

File System in OS Allocation, inode, FAT

File Attributes and Operations

A file is a named collection of related information stored on secondary storage. File attributes include:

File Operations: Create, Read, Write, Seek (reposition), Delete, Truncate, Open, Close, Rename, Copy

  • Name: Human-readable identifier
  • Type: File extension or magic number (text, binary, executable)
  • Size: Current file size in bytes
  • Location: Pointer to file location on disk
  • Permissions: Read, write, execute for owner, group, others
  • Timestamps: Creation time, last modified, last accessed
  • Owner: User/group that owns the file

Directory Structures

  • Single-Level Directory: All files in one directory. Simple but no organization. Name conflicts for multiple users.
  • Two-Level Directory: Separate directory for each user. Solves name conflicts but no grouping within user's files.
  • Tree-Structured Directory: Hierarchical structure with subdirectories. Most common (Unix/Windows). Supports absolute and relative paths.
  • Acyclic Graph Directory: Allows sharing of files/directories (hard links, symbolic links). No cycles allowed.
  • General Graph Directory: Allows cycles. Requires garbage collection to handle cycles.

File Allocation Methods

How files are stored on disk affects performance and space utilization:

Method Description Pros Cons
Contiguous File occupies consecutive disk blocks Fast sequential and random access, simple External fragmentation, file size must be known in advance
Linked Each block contains a pointer to the next block No external fragmentation, easy to grow Slow random access, pointer overhead, reliability (lost pointer)
Indexed Index block contains pointers to all file blocks Fast random access, no external fragmentation Index block overhead, small files waste space

FAT and inode

FAT (File Allocation Table): Used by Windows (FAT12, FAT16, FAT32, exFAT). A table stored at the beginning of the disk where each entry corresponds to a disk cluster. Each entry contains the number of the next cluster in the file chain, or a special value for end-of-file or free cluster.

inode (Index Node): Used by Unix/Linux file systems (ext2, ext3, ext4). Each file has an inode that stores all metadata (permissions, owner, timestamps, size) and pointers to data blocks. The inode does NOT store the filename - that's stored in the directory entry.

  • Direct pointers: Point directly to data blocks (fast for small files)
  • Single indirect: Points to a block of pointers
  • Double indirect: Points to a block of pointers to blocks of pointers
  • Triple indirect: Three levels of indirection (for very large files)

Free Space Management

  • Bitmap (Bit Vector): One bit per disk block. 0 = free, 1 = allocated. Easy to find contiguous free blocks. Requires extra space.
  • Linked List: Free blocks are linked together. No wasted space but slow to find contiguous blocks.
  • Grouping: First free block stores addresses of n free blocks. Last of those stores addresses of next n free blocks.
  • Counting: Store address of first free block and count of consecutive free blocks following it.

Crash Consistency Changes the Order of Safe Writes

Creating or replacing a file may update data blocks, metadata, directory entries, allocation maps, and journal records. A write call returning does not always mean every layer has persisted the data. Applications that require durable replacement write a temporary file, flush the required data, rename atomically within the file system, and account for directory durability according to the platform contract.

Hard links share one file object, while symbolic links store another path. Test deletion, rename, open handles, permission changes, and recovery after interruption so code does not confuse a directory name with the underlying file identity.

File OS state trace

File OS state trace
Event 1: a process requests a resource related to File
Event 2: the kernel checks permissions, availability, and current state
Event 3: the scheduler or manager decides whether to run, wait, block, or fail
Event 4: the process observes the result and continues or handles the error

File small simulation

File small simulation
Input: P1, P2, P3
Resource/state: limited
Rule: apply the File policy step by step
Output: show which process runs, waits, completes, or is denied

Always write the before-state and after-state for each step.
Before you move on

File System in OS Allocation, inode, FAT Mastery Check

4 checks
  • Explain how a directory entry, file identifier, metadata record, and data blocks work together.
  • Compare contiguous, linked, indexed, inode-based, and FAT allocation for access speed and fragmentation.
  • Trace hard links, symbolic links, deletion, and open handles without confusing a name with the file object.
  • Describe how journaling, checksums, free-space tracking, and recovery protect metadata after a crash.

Operating System Questions Learners Ask

A file stores data; a directory maps names to files and other directories.

It affects sequential access, random access, fragmentation, and metadata overhead.

It is a process-local handle for an open file or I/O resource.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.