Question

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?

Was it helpful?

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.

OTHER TIPS

In most Linux file systems, files can have holes in them - areas filled with zeroes that aren't mapped to any disk block. Hence, the file size and the block size can be different.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top