Improve get_free_diskspace to be able to handle huge disks (#9158) master
authorAdrian Müller <adrian.mueller@intra2net.com>
Fri, 23 Jan 2026 11:12:18 +0000 (12:12 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 23 Jan 2026 13:41:28 +0000 (14:41 +0100)
A machine with a 20TB HDD failed the statvfs() call on /datastore
due to an overflow in the statvfs call (verified via strace).
We now use the 64 bit version "statvfs64" to fix the issue.

The returned "long long" of I2n::get_free_diskspace() is already 64 bit,
so it can handle sizes up to ~ 8.39 million TiB.

src/filefunc.cpp

index 49358ff..7dca442 100644 (file)
@@ -994,11 +994,11 @@ bool remove_unlisted_files(const std::string &directory,
  **/
 long long get_free_diskspace(const std::string& path)
 {
-    struct statvfs sf;
+    struct statvfs64 sf;
 
     int looplimit=10000;
     int ret;
-    while ( ((ret=statvfs(path.c_str(),&sf)) == -1) && (errno==EINTR) && looplimit > 0)
+    while ( ((ret=statvfs64(path.c_str(),&sf)) == -1) && (errno==EINTR) && looplimit > 0)
         looplimit--;
 
     if (ret==-1)