diff options
Diffstat (limited to '')
-rw-r--r-- | win32/mntent.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/win32/mntent.c b/win32/mntent.c new file mode 100644 index 000000000..7f142b485 --- /dev/null +++ b/win32/mntent.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * A simple WIN32 implementation of mntent routines. It only handles | ||
3 | * logical drives. | ||
4 | */ | ||
5 | #define MNTENT_PRIVATE | ||
6 | #include "libbb.h" | ||
7 | |||
8 | struct mntstate { | ||
9 | DWORD drives; | ||
10 | int index; | ||
11 | }; | ||
12 | |||
13 | int fill_mntdata(struct mntdata *data, int index) | ||
14 | { | ||
15 | UINT drive_type; | ||
16 | char buf[PATH_MAX]; | ||
17 | |||
18 | // initialise pointers and scalar data | ||
19 | data->me.mnt_fsname = data->mnt_fsname; | ||
20 | data->me.mnt_dir = data->mnt_dir; | ||
21 | data->me.mnt_type = data->mnt_type; | ||
22 | data->me.mnt_opts = data->mnt_opts; | ||
23 | data->me.mnt_freq = 0; | ||
24 | data->me.mnt_passno = 0; | ||
25 | |||
26 | // initialise strings | ||
27 | data->mnt_fsname[0] = 'A' + index; | ||
28 | data->mnt_fsname[1] = ':'; | ||
29 | data->mnt_fsname[2] = '\0'; | ||
30 | data->mnt_dir[0] = 'A' + index; | ||
31 | data->mnt_dir[1] = ':'; | ||
32 | data->mnt_dir[2] = '/'; | ||
33 | data->mnt_dir[3] = '\0'; | ||
34 | data->mnt_type[0] = '\0'; | ||
35 | data->mnt_opts[0] = '\0'; | ||
36 | |||
37 | drive_type = GetDriveType(data->mnt_dir); | ||
38 | if (drive_type == DRIVE_FIXED || drive_type == DRIVE_CDROM || | ||
39 | drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_REMOTE) { | ||
40 | if (!GetVolumeInformation(data->mnt_dir, NULL, 0, NULL, NULL, | ||
41 | NULL, data->mnt_type, 100)) { | ||
42 | return FALSE; | ||
43 | } | ||
44 | |||
45 | if (realpath(data->mnt_dir, buf) != NULL) { | ||
46 | if (isalpha(buf[0]) && strcmp(buf+1, ":/") == 0) | ||
47 | buf[2] = '\0'; | ||
48 | strcpy(data->mnt_fsname, buf); | ||
49 | } | ||
50 | return TRUE; | ||
51 | } | ||
52 | return FALSE; | ||
53 | } | ||
54 | |||
55 | FILE *mingw_setmntent(void) | ||
56 | { | ||
57 | struct mntstate *state; | ||
58 | |||
59 | if ( (state=malloc(sizeof(struct mntstate))) == NULL ) { | ||
60 | return NULL; | ||
61 | } | ||
62 | |||
63 | state->drives = GetLogicalDrives(); | ||
64 | state->index = -1; | ||
65 | |||
66 | return (FILE *)state; | ||
67 | } | ||
68 | |||
69 | struct mntent *getmntent(FILE *stream) | ||
70 | { | ||
71 | struct mntstate *state = (struct mntstate *)stream; | ||
72 | static struct mntdata *data = NULL; | ||
73 | struct mntent *entry = NULL; | ||
74 | |||
75 | while (++state->index < 26) { | ||
76 | if ((state->drives & 1 << state->index) != 0) { | ||
77 | if (data == NULL) | ||
78 | data = xmalloc(sizeof(*data)); | ||
79 | |||
80 | if (fill_mntdata(data, state->index)) { | ||
81 | entry = &data->me; | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | return entry; | ||
88 | } | ||
89 | |||
90 | int endmntent(FILE *stream) | ||
91 | { | ||
92 | free(stream); | ||
93 | return 0; | ||
94 | } | ||