Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

File Systems & Inodes
OS

File Systems & Inodes

How does the OS organize billions of bits on a disk? Explore file allocation, metadata, and the Inode.

A file system controls how data is stored, organized, and retrieved on storage devices. It provides the abstraction of files and directories over raw disk blocks.

File Metadata (Inode in Unix/Linux)

Every file has metadata — data about the file. In Unix, this is stored in the inode (index node):

Inode fieldDescription
File sizeIn bytes
Owner UID/GIDUser and group ownership
Permissionsrwx bits for user/group/others
TimestampsAccess, modify, change times
Link countNumber of directory entries pointing to this inode
Block pointersDirect, indirect, double-indirect pointers to data blocks

Important: The inode does NOT store the filename. Filenames are stored in directory entries (dentries), which map filenames to inode numbers.

File Allocation Methods

MethodHow it worksRandom accessGrowthFragmentation
ContiguousFile occupies consecutive blocksFast — direct calculationDifficult — need to move fileExternal
LinkedEach block points to the nextSlow — must traverse chainEasyNone
IndexedIndex block holds all pointersFast — index blockModerateNone (index overhead)

Extents (Modern approach)

Used by ext4, NTFS. A file is described by a list of extents — contiguous block ranges. Combines contiguous allocation’s speed with indexed allocation’s flexibility.

Directory Structures

  • Single-level: all files in one directory — naming conflicts
  • Two-level: one directory per user
  • Tree-structured: hierarchical directories — most common (Unix, Windows)
  • Acyclic graph: directories can link to subdirectories (hard links)
Hard LinkSoft Link (Symlink)
Points toSame inode numberPath to target file
Survives target deletion?Yes (inode still exists)No (dangling link)
Across filesystems?NoYes
Directory link?Typically noYes

Q: What information is stored in an inode?

A: Size, owner, permissions, timestamps, link count, and pointers to data blocks. The filename is NOT stored in the inode — it’s stored in directory entries.

Q: Compare contiguous, linked, and indexed allocation.

A: Contiguous is fast for sequential access but hard to grow. Linked supports growth but no random access. Indexed supports both random access and growth but has index block overhead. Modern systems use extents (a hybrid approach).

A: A hard link is another directory entry pointing to the same inode — deleting the original doesn’t affect it. A symbolic link is a special file containing the path to the target — if the target is deleted, the link breaks.

Q: How does the OS track free space?

A: Two common methods: (1) Bit vector — a bitmap where each bit represents a block (1 = free). (2) Linked list — each free block points to the next. Bit vectors are more efficient for locating contiguous free space.

My Private Notes

Notes are auto-saved locally to this device.