Linux – How are directory structures stored in UNIX filesystem

filesystemslinuxunix

I have read that each directories store their content (files and subdirectories) by using a list of filename and inode pairs. But none of the reference I got said something about how they are stored.

Are they stored on inode of their parent directory, using data blocks like a normal file, or maybe using other ways that I don't aware of?

Thanks for the clarification.

Best Answer

See file system internals which outlines in a rather simple way the internals of a typical Unix filesystem.

enter image description here

Most Unix filesystems contain

  • A boot block
  • A superblock (disk geometry, partition layout, inode count, etc)
  • Inode blocks
  • Data blocks

Modern filesystems contain additional structures.

One of the things in the superblock is the location of the inodes for the root directory.

A directory is a specially formatted file. As with all ordinary files, it has data blocks.

You can see this in The Linux Documentation Project: Filesystem

enter image description here

You can use debugfs to explore these structures.

Related Question