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

拥有回忆 提交于 2019-12-08 14:37:57

问题


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

Under what circumstances would I prefer one over the other?


回答1:


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.




回答2:


If you just want file system capacity and usage information, the other answers are correct: prefer statvfs because it is standard POSIX and handles large file sizes better. statfs is BSD- and Linux-specific, with different structures on each. (Linux 2.6 added new statfs64 and fstatfs64 system calls that use an expanded structure to handle larger sizes.) However, statfs is still useful on Linux for determining the file system type (assuming you're okay with writing Linux-specific code).




回答3:


statfs() is deprecated in favor of statvfs(), which deals considerably better with large file support. statfs() is known to do odd things for sizes that exceed the value of an unsigned long.

As far as I can tell (and remember), statvfs() has been around since Redhat 7.3, just after being introduced as a POSIX replacement. You'll likely find it on (most) modern systems.



来源:https://stackoverflow.com/questions/1653163/difference-between-statvfs-and-statfs-system-calls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!