Brain Dump

inode

Tags
comp-arch

Is a file or directory. Technically an inode contains metadata about the file alongside pointers to disk-blocks on the hard-disk that the file can be read or written to.

One thing to note about inodes is that they don't contain file-names. Instead file-names are stored in directories and the file-name entry points back to the inode which will direct the OS to where the data for the file is stored. This facility means that multiple file-names can point to the same files, allowing you to create hard-links within the file-system.

Note: many file-systems place a set limit on the number of inodes that can exist, which also places a limit on the number of files the file-system can support.

Removing a file (using rm or unlink) removes the inode reference from a directory entry but doesn't delete the underlying inode. This is why you can have multiple hard-links to the same inode and removing one link doesn't remove the other. Instead the inode maintains a counter for the number of hard-links to it and an inode is only considered deleted when the number of references to it drops to 0. Note: This feature is extremely valuable for incremental-backups. You can copy a file into an archive to back it up, but if you create a new backup after that and the file hasn't been modified you can simply store a hard-link to its previous backup instead of duplicating it.

Note: You can distinguish the type of a file (file, directory, device, etc.) using the st_mode value in that files inode entry.

Links to this note