Search code examples
linuxoperating-systemfilesystemsinode

why does an inode have two different fields for size and block count?


There are two separate fields in inodes in Linux namely size and blocks. Why do we have to have two fields. If we just have the block count, wouldn't it be enough?

I tried creating a text file, and adding characters to it. The size was changing, but the block count stayed nearly the same. (used "stat filename" command)

Therefore can I assume that "size" field is used to make sure that the OS doesn't read unrelated data stored in the block which does not own to the file?


Solution

  • Yes, the size field is used to read only the bytes that belong to file.

    Actually, a file may occupy more blocks on disks than size / block_size + 1.