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 JA |
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 | ||
e7e136da TK |
32 | #elif defined(CONFIG_GETMNTINFO) |
33 | /* for BSDs */ | |
34 | #include <sys/param.h> | |
35 | #include <sys/mount.h> | |
aae599ba JA |
36 | |
37 | int device_is_mounted(const char *dev) | |
38 | { | |
e7e136da TK |
39 | struct statfs *st; |
40 | int i, ret; | |
41 | ||
42 | ret = getmntinfo(&st, MNT_NOWAIT); | |
43 | if (ret <= 0) | |
44 | return 0; | |
45 | ||
46 | for (i = 0; i < ret; i++) { | |
47 | if (!strcmp(st[i].f_mntfromname, dev)) | |
48 | return 1; | |
49 | } | |
50 | ||
aae599ba JA |
51 | return 0; |
52 | } | |
53 | ||
4f76cfe4 TK |
54 | #else |
55 | /* others */ | |
56 | ||
57 | int device_is_mounted(const char *dev) | |
58 | { | |
59 | return 0; | |
60 | } | |
61 | ||
aae599ba | 62 | #endif |