title: Remaining disk space in linux and the limits of long
body: <p>I understand that the disk space in linux could be programmatically retrieved using:</p>
  <pre><code>// header for statvfs
  #include &lt;sys/statvfs.h&gt;
  
  long GetAvailableSpace(const char* path)
  {
    struct statvfs stat;
  
    if (statvfs(path, &amp;stat) != 0) {
      // error happens, just quits here
      return -1;
    }
  
    // the available size is f_bsize * f_bavail
    return stat.f_bsize * stat.f_bavail;
  }
  
  int main(int argc, const char *argv[])
  {
     // assuming input is the directory which one is interested
     printf(&quot; The remaining size is %ld \n&quot;, GetAvailableSpace(argv[1]));
  }
  </code></pre>
  <p>However on checking the file structure for <strong>struct statvfs</strong>, they are</p>
  <pre><code>struct statvfs {
      unsigned long  f_bsize;    /* filesystem block size */
      unsigned long  f_frsize;   /* fragment size */
      fsblkcnt_t     f_blocks;   /* size of fs in f_frsize units */
      fsblkcnt_t     f_bfree;    /* # free blocks */
      fsblkcnt_t     f_bavail;   /* # free blocks for unprivileged users */
      fsfilcnt_t     f_files;    /* # inodes */
      fsfilcnt_t     f_ffree;    /* # free inodes */
      fsfilcnt_t     f_favail;   /* # free inodes for unprivileged users */
      unsigned long  f_fsid;     /* filesystem ID */
      unsigned long  f_flag;     /* mount flags */
      unsigned long  f_namemax;  /* maximum filename length */
  };
  </code></pre>
  <p>Theoretically the size of <code>stat.f_bavail</code>, could be also an unsigned long (I suspect). Wouldn't the multiplication of two unsigned long be much more than a long return type would hold?</p>