How come that inodes of directories store filenames in ext4 filesystem

debugfsdirectoryext4filesystemsinode

A directory inode isn't substantially different from that of a regular file's inode, what I comprehend from Ext4 Disk Layout is that:

Directory Entries:
Therefore, it is more accurate to say that a directory is a series of data blocks and that each block contains a linear array of directory entries.

The directory entry stores the filename together with a pointer to its inode. Hence, if the documentation says each block contains directory entries, why debugfs reports something different that the filenames stored in the directory's inode? This is a debugging session on an ext4 formatted flash drive:

debugfs:  cat /sub
�
 .
  ..�
     spam�spam2�spam3��spam4

I don't think inode_i_block can store those filenames, I've created files with really long filenames, more than 60 bytes in size. Running cat on the inode from debugfs displayed the filenames too, so the long filenames were in the inode again!

The Contents of inode.i_block:

Depending on the type of file an inode describes, the 60 bytes of storage in inode.i_block can be used in different ways. In general, regular files and directories will use it for file block indexing information, and special files will use it for special purposes.

Also, there's no reference to the inode storing the filenames in Hash Tree Directories
section which is the newer implementation. I feel I missed something in that document.

The main question is if a directory's inode contain filenames, what do its data blocks store then?

Best Answer

Directory entries are stored both in inode.i_block and the data blocks. See "Inline Data" and "Inline Directories" in the document you linked to.

Related Question