From d1c13779bb4606cdb6d80a6e1dfd2cdb11478199 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 22 Jan 2014 22:19:52 -0400 Subject: add getDiskSize Couldn't find anything that exposed this for Windows. --- Utility/libdiskfree.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'Utility/libdiskfree.c') diff --git a/Utility/libdiskfree.c b/Utility/libdiskfree.c index d2843ed20..8c9ab6145 100644 --- a/Utility/libdiskfree.c +++ b/Utility/libdiskfree.c @@ -1,6 +1,6 @@ /* disk free space checking, C mini-library * - * Copyright 2012 Joey Hess + * Copyright 2012, 2014 Joey Hess * * Licensed under the GNU GPL version 3 or higher. */ @@ -43,16 +43,12 @@ #include #include -/* Checks the amount of disk that is available to regular (non-root) users. - * (If there's an error, or this is not supported, - * returns 0 and sets errno to nonzero.) - */ -unsigned long long int diskfree(const char *path) { +unsigned long long int get(const char *path, int req) { #ifdef UNKNOWN errno = 1; return 0; #else - unsigned long long int available, blocksize; + unsigned long long int v, blocksize; struct STATSTRUCT buf; if (STATCALL(path, &buf) != 0) @@ -60,12 +56,35 @@ unsigned long long int diskfree(const char *path) { else errno = 0; - available = buf.f_bavail; + switch (req) { + case 0: + v = buf.f_blocks; + break; + case 1: + v = buf.f_bavail; + break; + default: + v = 0; + } + blocksize = buf.f_bsize; - return available * blocksize; + return v * blocksize; #endif } +/* Checks the amount of disk that is available to regular (non-root) users. + * (If there's an error, or this is not supported, + * returns 0 and sets errno to nonzero.) + */ +unsigned long long int diskfree(const char *path) { + return get(path, 1); +} + +/* Gets the total size of the disk. */ +unsigned long long int disksize(const char *path) { + return get(path, 0); +} + /* main () { printf("%lli\n", diskfree(".")); -- cgit v1.2.3