Thanks in advance,
Nancee
My first idea would be to use popen() to run the 'df' utility and analyse
the output, but probably there are more clever ways which, without doubt,
someone else will point out ;-)
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Jens.T...@physik.fu-berlin.de
_ | | | | | | AG Moebius, Institut fuer Molekuelphysik
| |_| | | | | | Fachbereich Physik, Freie Universitaet Berlin
\___/ens|_|homs|_|oerring Tel: ++49 (0)30 838 - 53394 / FAX: - 56046
> Can anyone tell me how to determined free space on a disk within a C
> program?
"man statfs" might help.
Regards,
Stephan
NAME
statfs, fstatfs - get file system statistics
SYNOPSIS
#include <sys/vfs.h>
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
See `man 2 statfs` for details.
--
Bob Nichols rnic...@interaccess.com
download and read the source to df, maybe ?
--
Dave Blake
dbl...@phy.ucsf.edu
Thanks for your input and the input from all the others that have responded.
Now I need help reconciling the info I get from statfs() with that from df.
Test program:
#include <stdio.h>
#include <sys/vfs.h>
int main (int argc, char *argv[])
{
struct statfs sStats;
if( statfs( "/home", &sStats ) == -1 )
printf( "statfs() failed\n" );
else
{
printf( "file system type: %x\n", sStats.f_type );
printf( "optimal transfer block size: %ld\n", sStats.f_bsize );
printf( "total data blocks in file system: %ld\n", sStats.f_blocks );
printf( "free blocks avail to non-superuser: %ld\n", sStats.f_bavail );
printf( "total file nodes in file system: %ld\n", sStats.f_files );
printf( "free file nodes in file system: %ld\n", sStats.f_ffree );
printf( "maximum length of filenames: %ld\n", sStats.f_namelen );
}
return 0;
}
Program output:
file system type: ef53
optimal transfer block size: 4096
total data blocks in file system: 2166335
free blocks avail to non-superuser: 1950418
total file nodes in file system: 1101056
free file nodes in file system: 1094495
maximum length of filenames: 255
df output:
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sdb6 8665340 423524 7801640 6% /home
How does the 'Available' amount from df relate to the members of struct statfs?
Thanks,
Nancee
use statfs (2);
For example:
#include <sys/vfs.h>
#include <stdio.h>
#include <stdlib.h>
#define FSPATH "/dev/hda1"
int
main ()
{
struct statfs info;
statfs (FSPATH, &info);
fprintf (stdout, "block size :%ld,"
" total data blocks :%ld,"
" free blocks for root: %ld,"
" free blocks for user: %ld\n ",
info.f_bsize, info.f_blocks, info.f_bfree, info.f_bavail);
exit (EXIT_SUCCESS);
}
---
Roberto Diaz <rdiaz...@vivaldi.dhis.org>
..For a Brave GNU World..
Concerto Grosso Op. 3/8 A minor
Antonio Vivaldi (so... do you need beautiful words?)
-----
In bytes?
It is the block size multiplied by f_bavail member..
>How does the 'Available' amount from df relate to the members of struct statfs?
i think that you have cheat yourself here ;)
the theory says:
if one block has 1024 bytes, block size in your system
is 4096, then you need to multiply an output of your
program by 4.
output from your program:
>free blocks avail to non-superuser: 1950418
output from your df command:
>/dev/sdb6 8665340 423524 7801640 6% /home
now 1950418*4 should be 7801672, but here it is 7801640.
why ?
i think something was copied/created on your /home
partition between running df and your program commands.
if you can - check it again.
HTH.
--
[ Wojtek gminick Walczak ][ http://hacker.pl/gminick/ ]
[ gminick (at) hacker.pl ][ ]gminick (at) interia.pl[ ]