output from statvfs different than df
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > output from statvfs different than df




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    output from statvfs different than df  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 12:21 AM

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??






[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 12:21 AM

Small correction to sample code:

long long  Avail_Space  = svfs.f_bavail

Same strange results though.






[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
Eric Sosman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 12:21 AM

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





[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 12:21 AM

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






[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
Eric Sosman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 06:25 AM

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





[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 12:27 PM

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.






[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
Eric Sosman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 06:18 PM

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.
[vbcol=seagreen]
> 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





[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
kenkahn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-21-07 06:18 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..







[ Post a follow-up to this message ]



    Re: output from statvfs different than df  
Eric Sosman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-22-07 12:17 AM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:49 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register