Add device_is_mounted() support for NetBSD
[fio.git] / lib / mountcheck.c
index dea27462e121befd46793c0b057948912bacc36a..0aec7441f91d412a01fc17d1ec083415f3f58e26 100644 (file)
@@ -1,8 +1,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdio.h>
 #include <string.h>
-#include <mntent.h>
 
 #ifdef CONFIG_GETMNTENT
 
 #ifdef CONFIG_GETMNTENT
+#include <mntent.h>
+
+#include "lib/mountcheck.h"
 
 #define MTAB   "/etc/mtab"
 
 
 #define MTAB   "/etc/mtab"
 
@@ -29,7 +31,51 @@ int device_is_mounted(const char *dev)
        return ret;
 }
 
        return ret;
 }
 
+#elif defined(CONFIG_GETMNTINFO)
+/* for most BSDs */
+#include <sys/param.h>
+#include <sys/mount.h>
+
+int device_is_mounted(const char *dev)
+{
+       struct statfs *st;
+       int i, ret;
+
+       ret = getmntinfo(&st, MNT_NOWAIT);
+       if (ret <= 0)
+               return 0;
+
+       for (i = 0; i < ret; i++) {
+               if (!strcmp(st[i].f_mntfromname, dev))
+                       return 1;
+       }
+
+       return 0;
+}
+
+#elif defined(CONFIG_GETMNTINFO_STATVFS)
+/* for NetBSD */
+#include <sys/statvfs.h>
+
+int device_is_mounted(const char *dev)
+{
+       struct statvfs *st;
+       int i, ret;
+
+       ret = getmntinfo(&st, MNT_NOWAIT);
+       if (ret <= 0)
+               return 0;
+
+       for (i = 0; i < ret; i++) {
+               if (!strcmp(st[i].f_mntfromname, dev))
+                       return 1;
+       }
+
+       return 0;
+}
+
 #else
 #else
+/* others */
 
 int device_is_mounted(const char *dev)
 {
 
 int device_is_mounted(const char *dev)
 {