Commit | Line | Data |
---|---|---|
aae599ba JA |
1 | #include <stdio.h> |
2 | #include <string.h> | |
aae599ba JA |
3 | |
4 | #ifdef CONFIG_GETMNTENT | |
4ab72793 | 5 | #include <mntent.h> |
aae599ba | 6 | |
a89ba4b1 JA |
7 | #include "lib/mountcheck.h" |
8 | ||
aae599ba JA |
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 | ||
e7e136da TK |
34 | #elif defined(CONFIG_GETMNTINFO) |
35 | /* for BSDs */ | |
36 | #include <sys/param.h> | |
37 | #include <sys/mount.h> | |
aae599ba JA |
38 | |
39 | int 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 | ||
4f76cfe4 TK |
56 | #else |
57 | /* others */ | |
58 | ||
59 | int device_is_mounted(const char *dev) | |
60 | { | |
61 | return 0; | |
62 | } | |
63 | ||
aae599ba | 64 | #endif |