[Tutor] Mount size

Faulconer, Steven M. STEVEN.M.FAULCONER at saic.com
Thu Oct 28 15:37:18 CEST 2004


Thanks for the response. Since the calls are not reliable for NFS mounts, is
there a pure python way of getting that information? We originally had a
system call that ran a df with some awk's and sed's to get what we need, but
we felt that had to be a way within python to do this. We can go back to
that method, but I'd really like a pure python way of reliably getting
available space on local and NFS mounted volumes.

If you or anyone else has any ideas, I'd love to hear them.


-----Original Message-----
From: Danny Yoo [mailto:dyoo at hkn.eecs.berkeley.edu] 
Sent: Wednesday, October 27, 2004 6:20 PM
To: Faulconer, Steven M.
Cc: tutor at python.org
Subject: Re: [Tutor] Mount size

On Wed, 27 Oct 2004, Faulconer, Steven M. wrote:

> We are having some issues getting reliable information for available 
> disk space within Python programs. We are using os.statvfs to get the 
> blocks free, but the numbers are not consistent between local and NFS 
> mounted drives.

[some text cut]

> Given that f_bavail is the number of blocks available (non-superuser) 
> I would assume that we could multiply that by f_bsize and then divide 
> by 1 million (for megabytes) or 1 billion (gigabytes).

Hi Steven,

You may want to use f_frsize, not f_bsize.  The underlying man page for
statvfs says the following about the tuple that we get back:

     u_long      f_bsize;             /* preferred file system block
                                         size */
     u_long      f_frsize;            /* fundamental filesystem block
                                         (size if supported) */
     fsblkcnt_t  f_blocks;            /* total # of blocks on file system
                                         in units of f_frsize */
     fsblkcnt_t  f_bfree;             /* total # of free blocks */
     fsblkcnt_t  f_bavail;            /* # of free blocks avail to
                                         non-super-user */
     fsfilcnt_t  f_files;             /* total # of file nodes (inodes) */
     fsfilcnt_t  f_ffree;             /* total # of free file nodes */
     fsfilcnt_t  f_favail;            /* # of inodes avail to
     u_long      f_fsid;              /* file system id (dev for now) */
     char        f_basetype[FSTYPSZ]; /* target fs type name,
                                       null-terminated */
     u_long      f_flag;              /* bit mask of flags */
     u_long      f_namemax;           /* maximum file name length */
     char        f_fstr[32];          /* file system specific string */
     u_long      f_filler[16];        /* reserved for future expansion */


(Taken from Solaris 8 man page on statvfs)

The way that the docs make a distinction between the "preferred" and
"fundamental" block sizes is significant.  Use 'f_frsize' instead, and you
should get better results.

There's also a section in the BUGS that says:

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

So be careful not to depends on those particular values on NFS-mounted

I hope this helps!

More information about the Tutor mailing list