×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Available free space on HD

Available free space on HD

Available free space on HD

(OP)
Hello guys, I have a doubt.

I need write a FTP like program (client and server) and I need to write a function that tells me the amount of free space on HD (to know if there is enough space to transfer the file).

So I informed myself and discovered that the "statvfs" function would resolve my problems. (I'm only using C language exclusively)

With "statvfs" you get the number of free blocks and the size (in bytes) of a block, so I think that the free space on disk (in bytes) is the following multiplication => "free blocks" x "size of a block"

Doing that I got "955344498688 bytes" ( I have an 1 TB HD), that's about 889.73 GB.

When I execute the "df -h" command on the terminal, it gives me this :

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 915G 26G 844G 3% /

When I run "nautilus" (I'm on linux, of course), it says I have 905.4 GB of free space on the file system.

Can anyone explain me why do I have THREE different values for the free space on disk?? Which one should I believe?

Thank you all.

RE: Available free space on HD

1) Is there a recycle bin and is it empty?
One system may be counting the free space including an empty recycle bin while the others exclude the recycle bin.  Do you have 10G of stuff in your recycle bin?

2) Do you have any zombies?  I haven't seen this one for ages.  Basically you have a program which has crashed and you've deleted it so it no longer shows in your file system.  Since it crashed but hasn't terminated, the executable is still on disk even though it doesn't show up anywhere.  The zombie has to be killed off before the disk space is released.  We had one system where the disk showed 90% empty but nobody could write anything to it because of the number of zombies running.

3) Discrepency in block size assumptions.  A 1 byte file takes 1K.  A 1023 byte file takes 1K.  If I add up the 2 file sizes, I could get either 1K or 2K depending on whether I sum file sizes or disk blocks.  On a 4K file system, do I have 2K or 3K free?  It is 2K if you assume 1 block per file under 1024 bytes.  It is 3K if you just add up file sizes and subtract it from the disk size.

Those are the ones I know of.  There may be others.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close