From e6265280520fd21e650aa2634b0a650f8ae3e805 Mon Sep 17 00:00:00 2001 From: Xu Wang <59418106+xwang1498@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:11:10 -0500 Subject: [PATCH 1/3] support free disk size on Windows --- disk-filltest.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/disk-filltest.c b/disk-filltest.c index 56c1c8c..f7954df 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,7 +271,14 @@ 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) { @@ -280,7 +288,7 @@ void write_randfiles(void) 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; From 32abff070f818a4ce020e48805202f3e0eb980d1 Mon Sep 17 00:00:00 2001 From: Xu Wang <59418106+xwang1498@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:34:51 -0500 Subject: [PATCH 2/3] use f_frsize instead of f_bsize for correct free space on macOS --- disk-filltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disk-filltest.c b/disk-filltest.c index f7954df..1d44f51 100644 --- a/disk-filltest.c +++ b/disk-filltest.c @@ -283,7 +283,7 @@ void write_randfiles(void) if (statvfs(".", &buf) == 0) { uint64_t free_size = - (uint64_t)(buf.f_blocks) * (uint64_t)(buf.f_bsize); + (uint64_t)(buf.f_blocks) * (uint64_t)(buf.f_frsize); expected_file_limit = (free_size + gopt_file_size - 1) / (1024 * 1024) / gopt_file_size; From f2d3783f389fed4d65ef3d0f18c814931f39d775 Mon Sep 17 00:00:00 2001 From: Xu Wang <59418106+xwang1498@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:08:03 -0500 Subject: [PATCH 3/3] use f_bfree & f_bavail for correct number of free blocks on linux --- disk-filltest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/disk-filltest.c b/disk-filltest.c index 1d44f51..f558432 100644 --- a/disk-filltest.c +++ b/disk-filltest.c @@ -282,8 +282,13 @@ void write_randfiles(void) struct statvfs buf; if (statvfs(".", &buf) == 0) { - uint64_t free_size = - (uint64_t)(buf.f_blocks) * (uint64_t)(buf.f_frsize); + 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;