0

I am learning about *nix file systems. In particular, I've been following this tutorial https://www.grymoire.com/Unix/Inodes.html interspersed with some Googling & whatnot. Is the true form of a Unix directory essentially just a file that consists of (column 1) inode numbers and (column 2) a string indicating the name of the file/directory corresponding to that inode number? And then, what we see as "The files/other directories that are contained in this directory" is really just the fact that the OS prints out the list of items in the table, when you do $ ls (or otherwise browse a particular directory)?

So for example is this the true format of a directory file...

enter image description here

if this were done in C, a file with a int inode column and a char * filename column.

2

1 Answer 1

2

Is the true form of a Unix directory essentially just a file that consists of (column 1) inode numbers and (column 2) a string indicating the name of the file/directory corresponding to that inode number?

At least conceptually, yes. The actual on-disk format might be different, however.

Though AFAIK many filesystems (like ext4), treat directories as files in the way that their storage area is reserved in the same way. (Except that ext4 directories can't reduce in size.) A directory also needs to have an inode of its own to store modification dates and permissions etc. But what is inside the data area of a directory is different. The "classic" format is just a list of {name, inode} entries (with some minor bookkeeping like the length of space reserved for the name), but more advanced data structures (trees) are also used. For ext4, see: https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Directory_Entries

Note also that depending on the filesystem, a directory entry can also contain the type of the pointed-to inode. That can be useful as an optimization, if you only need the type, there's no need to make a separate system call to stat() the entry. Also, the inode type doesn't change during the lifetime of the inode, so there's no issues from having to keep multiple directory entries in sync, like there would be if mutable inode data was shunted to the direntry.

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