Disk Free Space


#1

Hi,

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

Mickael.


#2

for linux, it is the command df
no idea about easy ways to do that on windows - but there sure is some
api-call for that too…
2006/1/24, Mickael Faivre-Macon removed_email_address@domain.invalid:


#3

This is highly OS-specific so I sincerely doubt there is a general
method. Different OSes treat disks entirely differently. To demonstrate
the complexity, simply ask yourself these questions: Is a network share
a disk? A folder on a remote FTP server? A loop device mounting a file
on a remote SMB server accessed via a VPN? The file itself?

Try either using a system-specific call for each platform you may be
operating on or simply try to write your stuff to the disk, catching
the appropriate error if it fails.


#4

Mickael Faivre-Macon wrote:

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

On {U,Li}n[iu]x, df.
On Windows, dir. It’s the last line of output.


#5

Jeffrey S. wrote:

Mickael Faivre-Macon wrote:

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

On {U,Li}n[iu]x, df.
On Windows, dir. It’s the last line of output.

You can install the GnuWin32 tools on windows to get df working there,
IIRC.


#6

Mickael Faivre-Macon wrote:

Hi,

Is a way to know free disk space left other that using Win32 API or a
system call on linux ?

Mickael.

A way to directly make the correct system call from ruby:
size = 64
unpack_fmt = ‘iiiiiiiiiiiiiiii’
foo = ’ ’ * size
syscall(99, “/mountpoint”, foo)
type, @bsize, @blocks, @bfree, @bavail, @files, @ffree, tmp,tmp,@namelen
= foo.unpack(unpack_fmt)
usage=100*(@blocks-@bfree)/@blocks

(Copied from someone who wrote a ruby script that did the same thing as
df.)

Edwin


#7

I thought there would be a portable library to manage disk in general.
But thank you all for your replies.
Mickael.