Home > Archive > Unix Programming > July 2007 > output from statvfs different than df
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
output from statvfs different than df
|
|
| kenkahn 2007-07-20, 7:10 pm |
| Given the following code
struct statvfs svfs;
statvfs(Path,&svfs);
long long Total_Space = svfs.f_blocks;
Total_Space *= svfs.f_frsize;
Total_Space /= 1024;
long long Avail_Space = svfs.f_bfree;
Avail_Space *= svfs.f_frsize;
Avail_Space /= 1024;
printf("total=%uKb favail=%uKB\n",
Total_Space,Avail_Space);
If I run this on a Solaris 5.10 system against my home directory, and
then run 'df -k' against the same directory I get
Total Available
code 586702560 41429828
df 586702612 41409928
Not quite the same, but close enough (I guess). If I now run the same
test on /etc I get
Total Available
code 586702564 41397932
df 219429321 177958127
This is not even close. I'm obviously either doing something
incorrect in my code, or just not understanding something.
Any help??
| |
| kenkahn 2007-07-20, 7:10 pm |
| Small correction to sample code:
long long Avail_Space = svfs.f_bavail
Same strange results though.
| |
| Eric Sosman 2007-07-20, 7:10 pm |
| kenkahn wrote On 07/20/07 14:56,:
> Given the following code
> [...]
> long long Total_Space = svfs.f_blocks;
> [...]
> long long Avail_Space = svfs.f_bfree;
> [...]
> printf("total=%uKb favail=%uKB\n",
> Total_Space,Avail_Space);
Try "%lld" instead of "%u" ...
--
Eric.Sosman@sun.com
| |
| kenkahn 2007-07-20, 7:10 pm |
| I changed the printf to
printf("total=%llu avail=%llu\n",Total_Space,Avail_Space);
but still got these results
Total Available
code 586718280 69401748
df 219429321 177958111
| |
| Eric Sosman 2007-07-20, 10:06 pm |
| kenkahn wrote:
> I changed the printf to
>
> printf("total=%llu avail=%llu\n",Total_Space,Avail_Space);
>
> but still got these results
>
> Total Available
> code 586718280 69401748
> df 219429321 177958111
All right: enough of guesswork. Please give us the
*complete* program, the *exact* command lines you used to
run it and to run df, and the *exact* output of both. I'm
tired to death of filling in the gaps in loose approximations.
--
Eric Sosman
esosman@ieee-dot-org.invalid
| |
| kenkahn 2007-07-21, 8:05 am |
| On Jul 20, 9:27 pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> All right: enough of guesswork. Please give us the
> *complete* program, the *exact* command lines you used to
> run it and to run df, and the *exact* output of both.
The code in my original post is the exact code. Just stick it in a
main, replace Path with ArgV[1], and do a simple gcc (v3.2.3) compile
gcc -o freespace freespace.c
I ran both this and 'df -k' directly from a ksh command line under a
Solaris 5.10 sparc system.
> freespace /etc
> df -k /etc
The output results from both are exactly as listed on the table in the
original post, I just extracted out the relevant values.
| |
| Eric Sosman 2007-07-21, 8:05 am |
| kenkahn wrote:
> On Jul 20, 9:27 pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>
> The code in my original post is the exact code. Just stick it in a
> main, replace Path with ArgV[1], and do a simple gcc (v3.2.3) compile
>
> gcc -o freespace freespace.c
I'm not at a Solaris system at the moment, but I can
predict what the compiler will say about "the exact code"
from your first message: It will spew a bunch of error
messages and refuse to compile. There are no #include
lines to get definitions of things like struct statvfs,
there is no main() function, there are no functions at
all, there are executable statements just floating around
in the ether outside of blocks ... And on top of this,
you want me to "replace Path with ArgV[1]" -- explain to
me again, please, just how "exact" is the code we've seen
thus far?
> I ran both this and 'df -k' directly from a ksh command line under a
> Solaris 5.10 sparc system.
>
This is good: You've given the exact command lines,
as requested.
[color=darkred]
> The output results from both are exactly as listed on the table in the
> original post, I just extracted out the relevant values.
That is, you did not post the exact output; you chose
to censor it first. Has it occurred to you that some of
the other things df prints might have a bearing on the issue?
I'm not saying they definitely do, but they certainly could --
if only we could see them.
Please try again: *exact* code, *exact* command lines
(they're short; it won't hurt to repeat them so we can have
everything conveniently in one message), *exact* outputs.
Then, perhaps, we can make some progress.
--
Eric Sosman
esosman@ieee-dot-org.invalid
| |
| kenkahn 2007-07-21, 7:06 pm |
| Eric, your post forced me to revisit my original code and, I admit, I
did find a coding error (it was always setting the value for Path to
the current directory). I fixed this and the call to statvfs does
indeed jive with df.
Thanks..
| |
| Eric Sosman 2007-07-21, 7:06 pm |
| kenkahn wrote:
> Eric, your post forced me to revisit my original code and, I admit, I
> did find a coding error (it was always setting the value for Path to
> the current directory). I fixed this and the call to statvfs does
> indeed jive with df.
Glad things worked out. It's not easy to describe a problem
well: One is torn between the desire to suppress irrelevant
detail and the fear of omitting something important. Leave out
something vital, and you'll never find the problem in what
remains -- but keep everything including the kitchen sink, and
you'll never be able to focus.
It's an essential skill for a programmer, though, since it's
fundamental to the process of debugging. Keep at it!
--
Eric Sosman
esosman@ieee-dot-org.invalid
|
|
|
|
|