Add get_fs_size() support for BSDs
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 10 Jun 2015 12:45:00 +0000 (21:45 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 11 Jun 2015 11:08:36 +0000 (20:08 +0900)
commit60f840a8426f8a9c72063929035e8f15100c54cd
tree0c43732e117f05c7e58694715245e9a936fc532d
parent5efb2861b1b8d4620fa83585f0584dea9e9bff21
Add get_fs_size() support for BSDs

Add get_fs_size() for FreeBSD/DragonFlyBSD. The same code may
work on NetBSD/OpenBSD as it uses POSIX statvfs(2).

The following results verify df(1) (which also typically uses
statfs(2) or statvfs(2)) shows the same number given that df(1)
output is correct for the given filesystems.

--
 # uname
 FreeBSD
 # cat ./test2.c
 #include <stdio.h>
 #include "os/os-freebsd.h"
 int main(int argc, char *argv[]) {
         printf("%s %llu\n", argv[1], get_fs_size(argv[1]));
         return 0;
 }
 # clang -Wall -g ./test2.c -o test2
 # ./test2 /
 / 102783143936
 # df -TH /
 Filesystem   Type    Size    Used   Avail Capacity  Mounted on
 /dev/ada0p2  ufs     112G    9.5G     94G     9%    /
                      ^^^^^^^^^^^^     ^^^
                      112G - 9.5G      bfree!=bavail
                      = 102.5G         like it differs on ext[234]
--
 # uname
 DragonFly
 # cat ./test2.c
 #include <stdio.h>
 #include "os/os-dragonfly.h"
 int main(int argc, char *argv[]) {
         printf("%s %llu\n", argv[1], get_fs_size(argv[1]));
         return 0;
 }
 # gcc -Wall -g ./test2.c -o test2
 # ./test2 /
 / 450287370240
 # df -TH /
 Filesystem  Type     Size   Used  Avail Capacity  Mounted on
 ROOT        hammer   480G    30G   450G     6%    /
os/os-dragonfly.h
os/os-freebsd.h