Title: RE: Anybody else having a problem with statvfs on Solaris (or other p latforms)?

How do I get the size prorammatically of an unmounted partition?

-----Original Message-----
From: Andrew Hood [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 24, 2004 4:20 PM
To: Bruce Shaw
Cc: Net-Snmp-Coders (E-mail)
Subject: Re: Anybody else having a problem with statvfs on Solaris (or
other p latforms)?


Bruce Shaw wrote:

>         if (statvfs("/dev/dsk/c0t0d0s7",&vfs) == -1)

The first arg to statvfs is a directory or file, not a device.

>              printf("size = %d, blocks = %d free = %d\n",
 >                    vfs.f_frsize, vfs.f_blocks, vfs.f_bfree, mt[n]);

gcc should complain about %d They should be %ld

This works for me:

==========================================================
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/statvfs.h>
char *mt[] = { "/", "/home", "/opt", "/usr", "/usr/OV", "/usr/src",
     "/usr/src/gnu", "/usr/src/misc", "/var", "/var/cdtemp", "/vmdisks",
     "/tmp", "/old", "/d", "/c", "/e", NULL
};
int main(int argc, char *argv[])
{
     int n;
     struct statvfs vfs;

     for (n = 0; mt[n]; n++) {
        if (statvfs(mt[n], &vfs) == -1)
            printf("partition lookup  failed%s\n", mt[n]);
        else {
            printf("size = %5ld, blocks = %7ld free = %7ld %s\n",
                   vfs.f_frsize, vfs.f_blocks, vfs.f_bfree, mt[n]);
        }                       /*end if */
     }                          /* end for */
     return 0;
}                               /* end vfs.c */
==========================================================

size =  1024, blocks =  508020 free =  191144 /
size =  4096, blocks =  714596 free =  286144 /home
size =  4096, blocks =  500932 free =  226343 /opt
size =  4096, blocks =  878968 free =  118357 /usr
size =  4096, blocks =  258022 free =  101117 /usr/OV
size =  4096, blocks =  476735 free =  350052 /usr/src
size =  4096, blocks =  516052 free =   35234 /usr/src/gnu
size =  4096, blocks =  516052 free =   35985 /usr/src/misc
size =  4096, blocks =  249958 free =  173429 /var
size =  4096, blocks =  516052 free =  279473 /var/cdtemp
size =  4096, blocks = 1332460 free =  281919 /vmdisks
size =  4096, blocks =  761796 free =  252723 /tmp
size =  4096, blocks = 2031782 free =  141666 /old
size =  4096, blocks =  654640 free =   69039 /d
size =  4096, blocks =  526128 free =   66424 /c
size = 32768, blocks =   32877 free =   22850 /e


--
There's no point in being grown up if you can't be childish sometimes.
                 -- Dr. Who

This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal and or privileged information. Please contact us immediately if you are not the intended recipient of this communication, and do not copy, distribute, or take action relying on it. Any communication received in error, or subsequent reply, should be deleted or destroyed.

Reply via email to