weird behavior with stat and file sizes
- From: "maria" <marialgullickson@xxxxxxxxx>
- Date: 21 Mar 2006 10:02:54 -0800
I have a program that iterates through all the files in a partition by
doing readdir() on the mount point and recursively going through all
the subdirectories. While doing this, I sum up the sizes of all the
regular files (DT_REG == pDirEnt->d_type). I am getting size by
calling lstat() and grabbing st_size out of the result.
I am also getting the total amount of used space in the partition, with
this:
struct statvfs dirStat;
statvfs(_dir.c_str(), &dirStat);
unsigned long bytesUsed = (dirStat.f_blocks - dirStat.f_bfree) *
dirStat.f_frsize;
The result I get from statvfs agrees with what running 'df' on the
command-line tells me, so that's good.
The weird this is that the value I get from summing up filesizes is
sometimes *bigger* than what I get from statvfs() or df. I could
understand if it's smaller (I'm not counting the size of directories or
symlinks), but I can't figure out why it's bigger.
In one example, on an NTFS partition, df reports 1.91GB, while the
files add up to 2.26GB. I've already verified that this isn't due to
something like mixing up 1024 vs. 1000 B per KB.
Any ideas?
.
- Follow-Ups:
- Re: weird behavior with stat and file sizes
- From: Roger Leigh
- Re: weird behavior with stat and file sizes
- From: Michael Kerrisk
- Re: weird behavior with stat and file sizes
- Prev by Date: Re: Is stork a troll? (was Re: Trolltech QT license question)
- Next by Date: Re: weird behavior with stat and file sizes
- Previous by thread: GTK code problem ?
- Next by thread: Re: weird behavior with stat and file sizes
- Index(es):
Relevant Pages
|