Skip to content

Commit

Permalink
Port Facebook PR8370 to Stardog: GetFreeSpace wrong if not root (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvon authored Jun 10, 2021
1 parent 54a9cb4 commit d924a50
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,17 @@ class PosixFileSystem : public FileSystem {
return IOError("While doing statvfs", fname, errno);
}

*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
// sbuf.bfree is total free space available to root
// sbuf.bavail is total free space available to unprivileged user
// sbuf.bavail <= sbuf.bfree ... pick correct based upon effective user id
if (geteuid()) {
// non-zero user is unprivileged, or -1 if error. take more conservative
// size
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bavail);
} else {
// root user can access all disk space
*free_space = ((uint64_t)sbuf.f_bsize * sbuf.f_bfree);
}
return IOStatus::OK();
}

Expand Down

0 comments on commit d924a50

Please sign in to comment.