#inode-vs-path
What is an inode? How does a file name differ from the file itself?
Что отвечать
An inode is the kernel's metadata structure for a file: owner, permissions, size, timestamps, and pointers to the data blocks. A file name is a directory entry that links a name string to an inode number. The file is the inode plus its data; the name is only a label. One inode can have several names (a hard link); a file with an open fd stays alive until that fd is closed, even after `rm`.
Что хотят услышать
A candidate should: - tell apart the three things: the inode (holds metadata), the data blocks (hold the contents), and the directory entry (links a name to an inode) - explain why `rm` does not free space right away when an fd is still open: the kernel decrements the link count, but while `i_count > 0` the physical free is deferred until the fd closes - name `ls -i` and `stat` as the tools to see the inode number - explain why the inode table is fixed at `mkfs` time, which is why `df -i` matters on a file system with millions of small files
Подводные камни
- ✗ Saying 'a file equals its name'. No, the name is only a reference to an inode.
- ✗ Not knowing about `df -i`, a classic cause of 'there is space, but the file will not create'.
- ✗ Assuming `rm` frees space instantly. It does not, if someone holds an fd.
Follow-up
- ? What does `lsof | grep deleted` do, and when do you need it?
- ? Can you create a file when all inodes are used up but disk space is free?
- ? How does the ext4 inode layout differ from XFS?
Глубина в базе знаний