diff options
Diffstat (limited to 'win32/mntent.c')
-rw-r--r-- | win32/mntent.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/win32/mntent.c b/win32/mntent.c new file mode 100644 index 000000000..d39ceb4a6 --- /dev/null +++ b/win32/mntent.c | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * A simple WIN32 implementation of mntent routines. It only handles | ||
3 | * fixed logical drives. | ||
4 | */ | ||
5 | #include "libbb.h" | ||
6 | |||
7 | struct mntdata { | ||
8 | DWORD flags; | ||
9 | int index; | ||
10 | }; | ||
11 | |||
12 | FILE *setmntent(const char *file UNUSED_PARAM, const char *mode UNUSED_PARAM) | ||
13 | { | ||
14 | struct mntdata *data; | ||
15 | |||
16 | if ( (data=malloc(sizeof(struct mntdata))) == NULL ) { | ||
17 | return NULL; | ||
18 | } | ||
19 | |||
20 | data->flags = GetLogicalDrives(); | ||
21 | data->index = -1; | ||
22 | |||
23 | return (FILE *)data; | ||
24 | } | ||
25 | |||
26 | struct mntent *getmntent(FILE *stream) | ||
27 | { | ||
28 | struct mntdata *data = (struct mntdata *)stream; | ||
29 | static char mnt_fsname[4]; | ||
30 | static char mnt_dir[4]; | ||
31 | static struct mntent my_mount_entry = | ||
32 | { mnt_fsname, mnt_dir, (char *)"", (char *)"", 0, 0 }; | ||
33 | struct mntent *entry; | ||
34 | static char fsname[100]; | ||
35 | |||
36 | entry = NULL; | ||
37 | while ( ++data->index < 26 ) { | ||
38 | if ( (data->flags & 1<<data->index) != 0 ) { | ||
39 | mnt_fsname[0] = 'A' + data->index; | ||
40 | mnt_fsname[1] = ':'; | ||
41 | mnt_fsname[2] = '\0'; | ||
42 | mnt_dir[0] = 'A' + data->index; | ||
43 | mnt_dir[1] = ':'; | ||
44 | mnt_dir[2] = '\\'; | ||
45 | mnt_dir[3] = '\0'; | ||
46 | |||
47 | if ( GetDriveType(mnt_dir) == DRIVE_FIXED ) { | ||
48 | my_mount_entry.mnt_type = ""; | ||
49 | if ( GetVolumeInformation(mnt_dir, NULL, 0, NULL, NULL, | ||
50 | NULL, fsname, 100) ) { | ||
51 | my_mount_entry.mnt_type = fsname; | ||
52 | } | ||
53 | |||
54 | entry = &my_mount_entry; | ||
55 | break; | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return entry; | ||
61 | } | ||
62 | |||
63 | int endmntent(FILE *stream) | ||
64 | { | ||
65 | free(stream); | ||
66 | return 0; | ||
67 | } | ||