[Tutor] Mount size
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Oct 28 00:20:03 CEST 2004
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
non-super-user*/
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:
"""
BUGS
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
drives.
I hope this helps!
More information about the Tutor
mailing list