title: statvfs() not working correctly C++ linux
body: <p>I am trying to get the available disk space. However, the size I am getting back does not change when I write more files to disk. What am I doing wrong?</p>
  
  <p>I confirmed that I am writing to <code>/dev/sda1</code> by running <code>df -h</code> and seeing that available space is indeed going down as I write files to disk.</p>
  
  <pre><code>double size; //size of aval disk space
  struct statvfs buf;
  
  if((statvfs("/dev/sda1", &amp;buf)) &lt; 0)
  {
     printf("Failed to get statvfs\n");
  }
  else
  {
      size = (((double)buf.f_bavail * buf.f_bsize) / 1048576);
      printf("You have: %.0f MB free\n", size);
  }
  </code></pre>