9

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.

2
  • There is no single way how Unix stores files. Similar to there is no single way to how windows stores files. In both cases it depends on the filesystem used. (FAT, NTFS, ext2, UFS, ...)
    – Hennes
    Commented Dec 16, 2012 at 16:45
  • For filesystems the directory structure on disk is defined in dirent.h, and you are supposed to use the libcalls opendir/readdir/closedir etc to access the content.
    – ott--
    Commented Dec 16, 2012 at 17:05

1 Answer 1

14

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.

3
  • 2
    "A directory is a specially formatted file. As with all ordinary files, it has data blocks." So are directories stored their filename-inode pairs (leftmost table on the 1st picture, or the row in the 2nd picture) in their data blocks?
    – Oka
    Commented Dec 17, 2012 at 0:49
  • 1
    @Oka: That is correct. Commented Dec 17, 2012 at 10:42
  • So, to be clear, the directory is a file, so it is stored in a data block. Each directory in ext4 filesystem for example (what is represented by ext4_dir_entry_2 is 263 bytes long) a single 4KB block could store about 15 directory entries? Commented Apr 27, 2018 at 2:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .