bloom: allow to pass in whether to set bits for strings
[fio.git] / lib / mountcheck.c
1 #include <stdio.h>
2 #include <string.h>
3
4 #ifdef CONFIG_GETMNTENT
5 #include <mntent.h>
6
7 #include "lib/mountcheck.h"
8
9 #define MTAB    "/etc/mtab"
10
11 int device_is_mounted(const char *dev)
12 {
13         FILE *mtab;
14         struct mntent *mnt;
15         int ret = 0;
16
17         mtab = setmntent(MTAB, "r");
18         if (!mtab)
19                 return 0;
20
21         while ((mnt = getmntent(mtab)) != NULL) {
22                 if (!mnt->mnt_fsname)
23                         continue;
24                 if (!strcmp(mnt->mnt_fsname, dev)) {
25                         ret = 1;
26                         break;
27                 }
28         }
29
30         endmntent(mtab);
31         return ret;
32 }
33
34 #elif defined(CONFIG_GETMNTINFO)
35 /* for BSDs */
36 #include <sys/param.h>
37 #include <sys/mount.h>
38
39 int device_is_mounted(const char *dev)
40 {
41         struct statfs *st;
42         int i, ret;
43
44         ret = getmntinfo(&st, MNT_NOWAIT);
45         if (ret <= 0)
46                 return 0;
47
48         for (i = 0; i < ret; i++) {
49                 if (!strcmp(st[i].f_mntfromname, dev))
50                         return 1;
51         }
52
53         return 0;
54 }
55
56 #else
57 /* others */
58
59 int device_is_mounted(const char *dev)
60 {
61         return 0;
62 }
63
64 #endif