X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fstatfs.c;h=9e1d3cd1932cd190f5a3bc766093c558a9745f83;hb=refs%2Ftags%2Fupstream%2F2.5.1;hp=5f5270feebd28e7340b045e09c95603c34d9b661;hpb=94c03cae686e4196a345d72452fda2a5203768ce;p=debian%2Famanda diff --git a/common-src/statfs.c b/common-src/statfs.c index 5f5270f..9e1d3cd 100644 --- a/common-src/statfs.c +++ b/common-src/statfs.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: statfs.c,v 1.13 2005/09/30 19:13:27 martinea Exp $ + * $Id: statfs.c,v 1.16 2006/08/24 17:05:35 martinea Exp $ * * a generic statfs-like routine */ @@ -98,7 +98,7 @@ # define STATFS_FAVAIL(buf) (buf).f_ffree # define STATFS_FFREE(buf) (buf).f_ffree # define STATFS_SCALE(buf) (buf).f_bsize -# define STATFS(path, buffer) statfs(path, &buffer, sizeof(STATFS_STRUCT), 0) +# define STATFS(path, buffer) statfs(path, &buffer, SIZEOF(STATFS_STRUCT), 0) # else # if HAVE_SYS_MOUNT_H /* @@ -119,7 +119,7 @@ # define STATFS_SCALE(buf) (buf).f_bsize # define STATFS(path, buffer) statfs(path, &buffer) # ifdef STATFS_OSF1 -# define STATFS(path, buffer) statfs(path, &buffer, sizeof(STATFS_STRUCT)) +# define STATFS(path, buffer) statfs(path, &buffer, SIZEOF(STATFS_STRUCT)) # endif # endif # endif @@ -127,11 +127,23 @@ # endif #endif -#define scale(r,s) ( (r) == -1? -1 : (int)((r)*(double)(s)/1024.0) ) -int get_fs_stats(dir, sp) -char *dir; -generic_fs_stats_t *sp; +off_t scale(off_t r, off_t s); + +off_t +scale( + off_t r, + off_t s) +{ + if (r == (off_t)-1) + return (off_t)-1; + return r*(s/(off_t)1024); +} + +int +get_fs_stats( + char * dir, + generic_fs_stats_t *sp) { STATFS_STRUCT statbuf; @@ -140,15 +152,18 @@ generic_fs_stats_t *sp; /* total, avail, free: converted to kbytes, rounded down */ - sp->total = scale(STATFS_TOTAL(statbuf), STATFS_SCALE(statbuf)); - sp->avail = scale(STATFS_AVAIL(statbuf), STATFS_SCALE(statbuf)); - sp->free = scale(STATFS_FREE(statbuf), STATFS_SCALE(statbuf)); + sp->total = scale((off_t)STATFS_TOTAL(statbuf), + (off_t)STATFS_SCALE(statbuf)); + sp->avail = scale((off_t)STATFS_AVAIL(statbuf), + (off_t)STATFS_SCALE(statbuf)); + sp->free = scale((off_t)STATFS_FREE(statbuf), + (off_t)STATFS_SCALE(statbuf)); /* inode stats */ - sp->files = STATFS_FILES(statbuf); - sp->favail = STATFS_FAVAIL(statbuf); - sp->ffree = STATFS_FFREE(statbuf); + sp->files = (off_t)STATFS_FILES(statbuf); + sp->favail = (off_t)STATFS_FAVAIL(statbuf); + sp->ffree = (off_t)STATFS_FFREE(statbuf); return 0; } @@ -156,9 +171,10 @@ generic_fs_stats_t *sp; #ifdef TEST /* ----- test scaffolding ----- */ -int main(argc, argv) -int argc; -char **argv; +int +main( + int argc, + char ** argv) { generic_fs_stats_t statbuf; @@ -166,6 +182,8 @@ char **argv; set_pname(argv[0]); + dbopen(NULL); + if(argc < 2) { fprintf(stderr, "Usage: %s files ...\n", get_pname()); return 1;