For academic purposes im trying to demonstrate internal fragmentation of a file. As i understand it, internal fragmentation can be shown as a difference between the size of file and the size of all blocks contatining the file. Finding out the number of block was easy enough. My problem is finding the size of blocks. Is this the number returned by stat -c %o? (4096) or stat -c %B (512).

What is the difference between these two? I've been trying to find answers online, however I'm only getting more confused. Other commands like blockdev --getbsz /dev/sda2 show my filesystem blocksize as 4096. However after doing caculations is seems that 512 is more fitting to be the asnwer im looking for (size of the file i was testing is 44933 and number of blocks is 88. Multiplying it by 4096 leaves us with 360448 which is more that 8 times size of the file).


From the manual for stat(1) one might find (this is from the Centos7 flavour of stat(1); other sources may vary)

   %b     number of blocks allocated (see %B)
   %B     the size in bytes of each block reported by %b

   %o     optimal I/O transfer size hint

which indicates that the first is about blocks allocated on the file system, while the second is the value related to I/O on said file. Noun (blocks allocated) versus verb (transfer of said blocks) more or less.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.