statvfs problem...

Hi,

I’m having a problem getting the number of free blocks using statvfs() on
QNX RTP 6.00
The program below seems to get the total amount of blocks, but the number of
free blocks available
is always 0.

i.e.

#df /dev/hd0t79
/dev/hd0t79 3951360 824819 3126541 21% /

but

#./statvfs /dev/hd0t79
total blocks 3951360
free blocks 0
avail blocks 0

The system I am running on is x86, the size of fsblkcnt_t is reported as 4,
so I assume it’s a u32_t

Any help appreciated

Regards
akeane@quadrics.com

/* cc -o statvfs statvfs.c */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#include <sys/types.h>
#include <sys/statvfs.h>


int main(int argc, char *argv[])
{
struct statvfs fs;

if ( statvfs(argv[1], &fs) == -1)
{
perror(“statvfs”);
return -1;
}

printf(“total blocks %d\n”, fs.f_blocks);
printf(“free blocks %d\n”, fs.f_bfree);
printf(“avail blocks %d\n”, fs.f_bavail);

return 0;
}

akeane <akeane@quadrics.com> wrote:
: The program below seems to get the total amount of blocks, but the number of
: free blocks available is always 0.

: #df /dev/hd0t79
: /dev/hd0t79 3951360 824819 3126541 21% /
: but
: #./statvfs /dev/hd0t79
: total blocks 3951360
: free blocks 0
: avail blocks 0

This is correct. A raw device (a disk or disk partition) doesn’t have
the concept of “free blocks”, they’re all “in-use” by the device. So,
there is no problem with statvfs() and your program is also correct
(just targetted at the wrong mountpoint). “df” has extra logic to
see that “/dev/hd0t79” is actually hosting a filesystem (at “/”) and
internally re-issues the statvfs() at that logical filesystem mountpoint
(probably fs-qnx4 or fs-dos) which does have the concept of logically
allocated/free blocks, to display those numbers.

The DCMD_FSYS_MOUNTED_* devctl()s can be used to nagivate the filesystem
mount hierarchy, but some extra trickery is also required to discriminate
between union mounts (at “/” in this example, which is no doubt shared
by a couple of other IO managers).

If you were to instead mount your “/dev/hd0t79” partition at (for example)
“/filesystem” then your given program would do what you thought with
“./statvfs /filesystem” …

John,

Thanks for explanation, I had tried statvfs / but had gotten
total blocks 1
free blocks 0
avail blocks 0

on my dev machine - presumably this is related to the union mounts trickery,
oh well doesn’t matter the thing works
OK on the production machine!

Regards
Alan Keane
akeane@quadrics.com

“John Garvey” <jgarvey@qnx.com> wrote in message
news:9efl2v$50c$2@nntp.qnx.com

akeane <> akeane@quadrics.com> > wrote:
: The program below seems to get the total amount of blocks, but the
number of
: free blocks available is always 0.

: #df /dev/hd0t79
: /dev/hd0t79 3951360 824819 3126541 21% /
: but
: #./statvfs /dev/hd0t79
: total blocks 3951360
: free blocks 0
: avail blocks 0

This is correct. A raw device (a disk or disk partition) doesn’t have
the concept of “free blocks”, they’re all “in-use” by the device. So,
there is no problem with statvfs() and your program is also correct
(just targetted at the wrong mountpoint). “df” has extra logic to
see that “/dev/hd0t79” is actually hosting a filesystem (at “/”) and
internally re-issues the statvfs() at that logical filesystem mountpoint
(probably fs-qnx4 or fs-dos) which does have the concept of logically
allocated/free blocks, to display those numbers.

The DCMD_FSYS_MOUNTED_* devctl()s can be used to nagivate the filesystem
mount hierarchy, but some extra trickery is also required to discriminate
between union mounts (at “/” in this example, which is no doubt shared
by a couple of other IO managers).

If you were to instead mount your “/dev/hd0t79” partition at (for example)
“/filesystem” then your given program would do what you thought with
“./statvfs /filesystem” …