+ double const scale = statfsbuf.f_bsize / 4096.0;
+
+ /* See if this filesystem is read-only */
+ struct statvfs statvfsbuf;
+ statvfs (i->path.c_str(), &statvfsbuf);
+
+ /* f_bavail can be 0 if it is undefined for whatever
+ filesystem we are looking at; Samba shares mounted
+ via GVFS are an example of this.
+ */
+ if (statfsbuf.f_bavail == 0) {
+ /* block count unknown */
+ i->blocks = 0;
+ i->blocks_unknown = true;
+ } else if (statvfsbuf.f_flag & ST_RDONLY) {
+ /* read-only filesystem */
+ i->blocks = 0;
+ i->blocks_unknown = false;
+ } else {
+ /* read/write filesystem with known space */
+ i->blocks = (uint32_t) floor (statfsbuf.f_bavail * scale);
+ i->blocks_unknown = false;
+ }