Add device_is_mounted() support for BSDs
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Tue, 2 Jun 2015 14:40:44 +0000 (23:40 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 3 Jun 2015 21:49:56 +0000 (06:49 +0900)
commite7e136da9253290a96ccfbfae5cadaf109b59b3c
treef7a83af9a012a26c459e19096a7dea84f8ce2798
parenta53d4f7847273faeef9795ad7a3f5865b0c22840
Add device_is_mounted() support for BSDs

Implement '#elif' part of lib/mountcheck.c using getmntinfo(3).

This should implement device_is_mounted() on most BSDs, and has been
tested on FreeBSD/DragonFlyBSD. NetBSD/OpenBSD do have getmntinfo(3)
but may need to include different headers according to their online
manpages.

--
 # cat ./test1.c
 #include <stdio.h>
 #include "./lib/mountcheck.h"
 int main(int argc, char *argv[]) {
  printf("%s %d\n", argv[1], device_is_mounted(argv[1]));
  return 0;
 }

--
 # uname
 FreeBSD
 # clang -Wall -g ./test1.c ./lib/mountcheck.o -o ./test1
 # ./test1 /dev/ada0p2  /* UFS */
 /dev/ada0p2 1
 # ./test1 zfs  /* ZFS */
 zfs 1
 # ./test1 zfs/test  /* ZFS */
 zfs/test 1
 # ./test1 /dev/da0  /* not mounted device */
 /dev/da0 0
 # ./test1 random  /* irrelevant string */
 random 0

--
 # uname
 DragonFly
 # gcc -Wall -g ./test1.c ./lib/mountcheck.o -o ./test1
 # ./test1 /pfs/@@-1:00005  /* HAMMER */
 /pfs/@@-1:00005 1
 # ./test1 procfs  /* procfs */
 procfs 1
 # ./test1 /dev/da8  /* not mounted device */
 /dev/da8 0
 # ./test1 random  /* irrelevant string */
 random 0
configure
lib/mountcheck.c