I'm implementing du -a in C and I'm using the stat function for this. The problem is that what I get from using st_blocks is 2× what I get when I use the command itself, does this make any sense? or am I doing something wrong?

  • Please add more details, such as a copy of the code you're writing, the output it gives, and the output you're expecting. – jayhendren Nov 16 '16 at 19:09

stat counts 512-byte blocks in st_blocks, whereas du counts 1024-byte blocks by default (in most Linux distributions) — so it's perfectly normal to get twice the number of blocks from stat.

(POSIX du counts 512-byte blocks too; GNU du follows that standard if you set POSIXLY_CORRECT.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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