[Tutor] Mount size

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Oct 28 20:52:40 CEST 2004



On Thu, 28 Oct 2004, Faulconer, Steven M. wrote:


> Thanks for the response. Since the calls are not reliable for NFS
> mounts,


Hi Steven,


I'd better clarify this.  That is not what I wrote.  I quoted from the man
page that:

> BUGS
>      The values returned for f_files, f_ffree, and  f_favail  may
>      not be valid for NFS mounted file systems.


What this is saying is that certain portions of the statvfs() return value
might be buggy.  But it does not say that the whole thing is broken.
*grin*

I assume that the rest of it --- including f_frsize and f_bavail --- is
ok. If we look at the C source code for GNU df, we can see that it does
use statvfs, f_frsize, f_bsize, and b_avail.


/*** a fragment in coreutils-5.0/lib/fsutils.c   ***/
  struct statvfs fsd;

  if (statvfs (path, &fsd) < 0)
    return -1;

  /* f_frsize isn't guaranteed to be supported.  */
  fsp->fsu_blocksize = (fsd.f_frsize
                        ? PROPAGATE_ALL_ONES (fsd.f_frsize)
                        : PROPAGATE_ALL_ONES (fsd.f_bsize));
/******/


According to this code, GNU df prefers to use f_frsize if it's there.  If
f_frsize isn't there, then GNU df will fall back on f_bsize.  But its
first choice is to use f_frsize, which is the second component of the
statvfs() return value.


So you just have to be careful to discriminate which portions of
os.statvfs() to use.  I'm getting good results with:

###
import os

def getFreeBytes(mountpoint):
    """Returns the number of free bytes available off a mount point."""
    data = os.statvfs(mountpoint)
    frsize = data[1]
    bavail = data[4]
    return frsize * bavail
###



For example, let's say that we're on a Solaris 8 system with a NFS mount:

###
-bash-2.05b$ /usr/pubsw/bin/df -H /sybase-log
Filesystem             Size   Used  Avail Use% Mounted on
tair5:/export/sybase-log
                       5.3G   441M   4.8G   9% /sybase-log
###


I'm getting very good agreement with that getFreeBytes() function:

###
>>> getFreeBytes("/sybase-log")
4797079552L
###


Anyway, I hope this helps!



More information about the Tutor mailing list