weird behavior with stat and file sizes



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?

.



Relevant Pages

  • Function to get partition list
    ... partition statistics using statvfs(). ... But to get partition info, ...
    (comp.unix.solaris)
  • Setting up a file server for a diskless X-Terminal
    ... I want to set up a series of subdirectories on my main machine with the root file system, ... Is there a way to unpack the F7 rpms into these subdirectories? ... I don't want to set up an entire partition for this, and go through the entire partitioning and install procedure. ... I have a vague memory that you could do this with slackware, is there a way to do this with Fedora? ...
    (Fedora)
  • Re: How to improve the performance
    ... Here's a link to a chapter from the SQL Server 2000 Resource Kit ... > However, when the number of records get bigger and bigger, the performance ... > Actually, my table have already an index on the rowID, the result of query ... >>> I think my issue can be fixed by using partition view, ...
    (microsoft.public.sqlserver.programming)
  • Re: Setting up a file server for a diskless X-Terminal
    ... What is the best way to set up the root file system? ... series of subdirectories on my main machine with the root file system, ... set up an entire partition for this, ... I have a vague memory that you could do ...
    (Fedora)
  • Re: Help! - Need Partitioning Advice
    ... Windows XP, Program Files ... Your "backup" partition should not be bigger than 2X the active data partition ... Give yourself more room on your primary data partition. ...
    (microsoft.public.windowsxp.help_and_support)