Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Available free space on HD

Status
Not open for further replies.

leowribeiro

Programmer
Feb 16, 2012
1
0
0
BR
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top