dea27462e121befd46793c0b057948912bacc36a
[fio.git] / lib / mountcheck.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <mntent.h>
4
5 #ifdef CONFIG_GETMNTENT
6
7 #define MTAB    "/etc/mtab"
8
9 int device_is_mounted(const char *dev)
10 {
11         FILE *mtab;
12         struct mntent *mnt;
13         int ret = 0;
14
15         mtab = setmntent(MTAB, "r");
16         if (!mtab)
17                 return 0;
18
19         while ((mnt = getmntent(mtab)) != NULL) {
20                 if (!mnt->mnt_fsname)
21                         continue;
22                 if (!strcmp(mnt->mnt_fsname, dev)) {
23                         ret = 1;
24                         break;
25                 }
26         }
27
28         endmntent(mtab);
29         return ret;
30 }
31
32 #else
33
34 int device_is_mounted(const char *dev)
35 {
36         return 0;
37 }
38
39 #endif