Why is the inode table usually not resizable

filesystemsinode

Unix file systems usually have an inode table, and the number of entries in this table is usually fixed at the time the file system is created. This sometimes leads to people with plenty of disk space getting confusing error messages about no free space, and even after they figure out what the problem is, there is no easy solution for what to do about it.

But it seems (to me) that it would be very desirable to avoid this whole mess by allocating inodes on demand, completely transparently to users and system administrators. If you're into cute hacks, you could even make the inode table itself be a file, and thus reuse the code you already have that finds free space on the disk. If you're lucky, you might even end up with the inodes near the files themselves, without explicitly trying to achieve this result.

But nobody (that I know of) actually does this, so there's probably a catch that I'm missing. Any idea what it might be?

Best Answer

Say you did make the inode table a file; then the next question is... where do you store information about that file? You'd thus need "real" inodes and "extended" inodes, like an MS-DOS partition table. Given, you'd only need one (or maybe a few — e.g., to also have your journal be a file). But you'd actually have special cases, different code. Any corruption to that file would be disastrous, too. And consider that, before journaling, it was common for files that were being written e.g., when the power went out to be heavily damaged. Your file operations would have to be a lot more robust vs. power failure/crash/etc. than they were on, e.g., ext2.

Traditional Unix filesystems found a simpler (and more robust) solution: put an inode block (or group of blocks) every X blocks. Then you find them by simple arithmetic. Of course, then it's not possible to add more (without restructuring the entire filesystem). And even if you lose/corrupt the inode block you were writing to when the power failed, that's only losing a few inodes — far better than a substantial portion of the filesystem.

More modern designs use things like B-tree variants. Modern filesystems like btrfs, XFS, and ZFS do not suffer from inode limits.

Related Question