log: remember to free output buffer when done
[fio.git] / lib / mountcheck.c
CommitLineData
aae599ba
JA
1#include <stdio.h>
2#include <string.h>
aae599ba
JA
3
4#ifdef CONFIG_GETMNTENT
4ab72793 5#include <mntent.h>
aae599ba 6
19192959 7#include "mountcheck.h"
a89ba4b1 8
aae599ba
JA
9#define MTAB "/etc/mtab"
10
11int 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
e7e136da 34#elif defined(CONFIG_GETMNTINFO)
b765bec0 35/* for most BSDs */
e7e136da
TK
36#include <sys/param.h>
37#include <sys/mount.h>
aae599ba
JA
38
39int device_is_mounted(const char *dev)
40{
e7e136da
TK
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
aae599ba
JA
53 return 0;
54}
55
b765bec0
TK
56#elif defined(CONFIG_GETMNTINFO_STATVFS)
57/* for NetBSD */
58#include <sys/statvfs.h>
59
60int device_is_mounted(const char *dev)
61{
62 struct statvfs *st;
63 int i, ret;
64
65 ret = getmntinfo(&st, MNT_NOWAIT);
66 if (ret <= 0)
67 return 0;
68
69 for (i = 0; i < ret; i++) {
70 if (!strcmp(st[i].f_mntfromname, dev))
71 return 1;
72 }
73
74 return 0;
75}
76
4f76cfe4
TK
77#else
78/* others */
79
80int device_is_mounted(const char *dev)
81{
82 return 0;
83}
84
aae599ba 85#endif