log: remember to free output buffer when done
[fio.git] / lib / mountcheck.c
index bb01f69f46b1ed579fbd36bb6d4a4cf6f8f4f374..2fb6fe742faa3e3348c994e9e75a8167b633013b 100644 (file)
@@ -4,6 +4,8 @@
 #ifdef CONFIG_GETMNTENT
 #include <mntent.h>
 
+#include "mountcheck.h"
+
 #define MTAB   "/etc/mtab"
 
 int device_is_mounted(const char *dev)
@@ -29,7 +31,51 @@ int device_is_mounted(const char *dev)
        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
+/* others */
 
 int device_is_mounted(const char *dev)
 {