diff --git a/disk-filltest.c b/disk-filltest.c index 56c1c8c..f558432 100644 --- a/disk-filltest.c +++ b/disk-filltest.c @@ -42,7 +42,8 @@ #include #if defined(_MSC_VER) || defined(__MINGW32__) - /* no */ + #include + #define HAVE_FILEAPI 1 #else #include #define HAVE_STATVFS 1 @@ -270,17 +271,29 @@ void write_randfiles(void) unsigned int expected_file_limit = UINT_MAX; if (gopt_file_limit == UINT_MAX) { -#if HAVE_STATVFS +#if HAVE_FILEAPI + ULARGE_INTEGER free_size; + + if (GetDiskFreeSpaceEx(NULL, &free_size, NULL, NULL)) { + expected_file_limit = (free_size.QuadPart + gopt_file_size - 1) + / (1024 * 1024) / gopt_file_size; + } +#elif HAVE_STATVFS struct statvfs buf; if (statvfs(".", &buf) == 0) { - uint64_t free_size = - (uint64_t)(buf.f_blocks) * (uint64_t)(buf.f_bsize); + uint64_t free_blocks; + if (geteuid() == 0) + free_blocks = (uint64_t)(buf.f_bfree); + else + free_blocks = (uint64_t)(buf.f_bavail); + + uint64_t free_size = free_blocks * (uint64_t)(buf.f_frsize); expected_file_limit = (free_size + gopt_file_size - 1) / (1024 * 1024) / gopt_file_size; } -#endif /* HAVE_STATVFS */ +#endif } else { expected_file_limit = gopt_file_limit;