Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions disk-filltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
#include <unistd.h>

#if defined(_MSC_VER) || defined(__MINGW32__)
/* no <sys/statvfs.h> */
#include <fileapi.h>
#define HAVE_FILEAPI 1
#else
#include <sys/statvfs.h>
#define HAVE_STATVFS 1
Expand Down Expand Up @@ -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;
Expand Down