Difference between statvfs() and statfs() system calls?

Matt Joiner picture Matt Joiner · Oct 31, 2009 · Viewed 10.9k times · Source

Why do the statfs() and statvfs() calls both exist when they're so similar?

Under what circumstances would I prefer one over the other?

Answer

DigitalRoss picture DigitalRoss · Oct 31, 2009

Err, "historical reasons".

Originally 4.4BSD defined a statfs() call. Linux later implemented a slightly different call with the same name. Posix standardized it between all freenix and Unix versions by defining statvfs().

statfs() is OS-specific

statvfs() is posix-conforming

As they all return slightly different structures, later ones to come along can't replace the first.

In general you should use statvfs(), the Posix one. Be careful about "use Posix" advice, though, as in some cases (pty, for example) the BSD (or whatever) one is more portable in practice.