David Scott <djsco@bgs.ac.uk> wrote:
I am currently porting some application software from QNX 4 to 6.2.1. On
QNX 4, part of this software used the disk_space() function to get the
number of blocks and number of free blocks on the disk.
When migrating this, I have tried to use statvfs() to get the same
information, but it doesn’t seem to work very well. It correctly reports
the filesystem blocksize and the total number of blocks, but the number of
free blocks is reported as zero. The fstatvfs() function is even worse,
reporting the blocksize and total number of blocks as 1, and free blocks as
zero. To prove to myself that I wasn’t doing something silly, I tried the
same source code on a solaris platform, where it worked perfectly.
Can anyone explain this and/or suggest a solution? I would like to avoid
execing to a shell to run df, as the use of exec is causing problems in this
application. But the fact that df works means that the information must be
available.
Thanks
David Scott.
Dunno. The following code snippet works for me – we use it as part of
midnight diagnostics to verify basic sanity, in this case, that there is
still at least 1 MB of free disk space…
The key might be which filesystem you are using to verify – it could be
some package-filesystem junk. Try a “real” file – below, we use “/var”…
static int
diags_test_free_disk (void)
{
struct statvfs statbuf;
// free disk test – there must be at least 1 MB of free disk space in “/var”
if (statvfs ("/var", &statbuf) == -1) {
sl_printf (“DIAGS: statvfs (/var) failed, errno %d (%s)\n”, errno, strerror (errno));
return (DIAGS_CANT_STAT_VAR);
}
if (statbuf.f_bfree * statbuf.f_bsize < 1000000) {
sl_printf (“DIAGS: less than 1000000 bytes of disk space free (%d blocks of %ld bytes (total %ld) free)\n”, statbuf.f_bfree, statbuf.f_bsize, statbuf.f_bfree * statbuf.f_bsize);
return (DIAGS_OUT_OF_DISK);
}
return (DIAGS_OK);
}
Cheers,
-RK
[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~museum/