Reputation: 107
i create a file using dd command like this:
dd if=/dev/zero of=1g.dd bs=1M count=512 seek=512
when i run command ls 1g.dd
, its size is 1G, run du 1g.dd
, it's 512M.
there is a struct stat
in c library to read file size, but it can only read out that 1G size, now how can i get that 512M size which is the real size of that file?
now the only way i know is to parse shell command du
's output. can i read out the size from the file directly?
Upvotes: 1
Views: 531
Reputation: 206659
You can use the st_blocks
member of struct stat
for that, it tells you how many 512 byte blocks (this is valid on Linux, could be different on other OSes, and could depend on the filesystem) have been allocated to the file.
Upvotes: 1