diff options
-rw-r--r-- | libbb/find_mount_point.c | 23 | ||||
-rw-r--r-- | win32/mntent.c | 106 | ||||
-rw-r--r-- | win32/mntent.h | 12 |
3 files changed, 77 insertions, 64 deletions
diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c index edf734614..2464357c1 100644 --- a/libbb/find_mount_point.c +++ b/libbb/find_mount_point.c | |||
@@ -6,6 +6,9 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | #if ENABLE_PLATFORM_MINGW32 | ||
10 | # define MNTENT_PRIVATE | ||
11 | #endif | ||
9 | #include "libbb.h" | 12 | #include "libbb.h" |
10 | #include <mntent.h> | 13 | #include <mntent.h> |
11 | 14 | ||
@@ -25,13 +28,7 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) | |||
25 | dev_t devno_of_name; | 28 | dev_t devno_of_name; |
26 | bool block_dev; | 29 | bool block_dev; |
27 | #else | 30 | #else |
28 | static char mnt_fsname[4]; | 31 | static struct mntdata *data = NULL; |
29 | static char mnt_dir[4]; | ||
30 | static char mnt_type[1]; | ||
31 | static char mnt_opts[1]; | ||
32 | static struct mntent my_mount_entry = { | ||
33 | mnt_fsname, mnt_dir, mnt_type, mnt_opts, 0, 0 | ||
34 | }; | ||
35 | char *current; | 32 | char *current; |
36 | const char *path; | 33 | const char *path; |
37 | DWORD len; | 34 | DWORD len; |
@@ -105,15 +102,11 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) | |||
105 | } | 102 | } |
106 | 103 | ||
107 | if ( path && isalpha(path[0]) && path[1] == ':' ) { | 104 | if ( path && isalpha(path[0]) && path[1] == ':' ) { |
108 | mnt_fsname[0] = path[0]; | 105 | if (data == NULL) |
109 | mnt_fsname[1] = path[1]; | 106 | data = xmalloc(sizeof(*data)); |
110 | mnt_fsname[2] = '\0'; | ||
111 | mnt_dir[0] = path[0]; | ||
112 | mnt_dir[1] = path[1]; | ||
113 | mnt_dir[2] = '\\'; | ||
114 | mnt_dir[3] = '\0'; | ||
115 | 107 | ||
116 | mountEntry = &my_mount_entry; | 108 | fill_mntdata(data, toupper(path[0]) - 'A'); |
109 | mountEntry = &data->me; | ||
117 | } | 110 | } |
118 | free(current); | 111 | free(current); |
119 | #endif | 112 | #endif |
diff --git a/win32/mntent.c b/win32/mntent.c index 7ab51239d..7f142b485 100644 --- a/win32/mntent.c +++ b/win32/mntent.c | |||
@@ -2,39 +2,20 @@ | |||
2 | * A simple WIN32 implementation of mntent routines. It only handles | 2 | * A simple WIN32 implementation of mntent routines. It only handles |
3 | * logical drives. | 3 | * logical drives. |
4 | */ | 4 | */ |
5 | #define MNTENT_PRIVATE | ||
5 | #include "libbb.h" | 6 | #include "libbb.h" |
6 | 7 | ||
7 | struct mntdata { | 8 | struct mntstate { |
8 | DWORD flags; | 9 | DWORD drives; |
9 | int index; | 10 | int index; |
10 | struct mntent me; | ||
11 | char mnt_fsname[PATH_MAX]; | ||
12 | char mnt_dir[4]; | ||
13 | char mnt_type[100]; | ||
14 | char mnt_opts[4]; | ||
15 | }; | 11 | }; |
16 | 12 | ||
17 | FILE *mingw_setmntent(void) | 13 | int fill_mntdata(struct mntdata *data, int index) |
18 | { | ||
19 | struct mntdata *data; | ||
20 | |||
21 | if ( (data=malloc(sizeof(struct mntdata))) == NULL ) { | ||
22 | return NULL; | ||
23 | } | ||
24 | |||
25 | data->flags = GetLogicalDrives(); | ||
26 | data->index = -1; | ||
27 | |||
28 | return (FILE *)data; | ||
29 | } | ||
30 | |||
31 | struct mntent *getmntent(FILE *stream) | ||
32 | { | 14 | { |
33 | struct mntdata *data = (struct mntdata *)stream; | ||
34 | struct mntent *entry; | ||
35 | UINT drive_type; | 15 | UINT drive_type; |
36 | char buf[PATH_MAX]; | 16 | char buf[PATH_MAX]; |
37 | 17 | ||
18 | // initialise pointers and scalar data | ||
38 | data->me.mnt_fsname = data->mnt_fsname; | 19 | data->me.mnt_fsname = data->mnt_fsname; |
39 | data->me.mnt_dir = data->mnt_dir; | 20 | data->me.mnt_dir = data->mnt_dir; |
40 | data->me.mnt_type = data->mnt_type; | 21 | data->me.mnt_type = data->mnt_type; |
@@ -42,34 +23,61 @@ struct mntent *getmntent(FILE *stream) | |||
42 | data->me.mnt_freq = 0; | 23 | data->me.mnt_freq = 0; |
43 | data->me.mnt_passno = 0; | 24 | data->me.mnt_passno = 0; |
44 | 25 | ||
45 | entry = NULL; | 26 | // initialise strings |
46 | while ( ++data->index < 26 ) { | 27 | data->mnt_fsname[0] = 'A' + index; |
47 | if ( (data->flags & 1<<data->index) != 0 ) { | 28 | data->mnt_fsname[1] = ':'; |
48 | data->mnt_fsname[0] = 'A' + data->index; | 29 | data->mnt_fsname[2] = '\0'; |
49 | data->mnt_fsname[1] = ':'; | 30 | data->mnt_dir[0] = 'A' + index; |
50 | data->mnt_fsname[2] = '\0'; | 31 | data->mnt_dir[1] = ':'; |
51 | data->mnt_dir[0] = 'A' + data->index; | 32 | data->mnt_dir[2] = '/'; |
52 | data->mnt_dir[1] = ':'; | 33 | data->mnt_dir[3] = '\0'; |
53 | data->mnt_dir[2] = '/'; | 34 | data->mnt_type[0] = '\0'; |
54 | data->mnt_dir[3] = '\0'; | 35 | data->mnt_opts[0] = '\0'; |
55 | data->mnt_type[0] = '\0'; | ||
56 | data->mnt_opts[0] = '\0'; | ||
57 | 36 | ||
58 | drive_type = GetDriveType(data->mnt_dir); | 37 | drive_type = GetDriveType(data->mnt_dir); |
59 | if ( drive_type == DRIVE_FIXED || drive_type == DRIVE_CDROM || | 38 | if (drive_type == DRIVE_FIXED || drive_type == DRIVE_CDROM || |
60 | drive_type == DRIVE_REMOVABLE || | 39 | drive_type == DRIVE_REMOVABLE || drive_type == DRIVE_REMOTE) { |
61 | drive_type == DRIVE_REMOTE ) { | 40 | if (!GetVolumeInformation(data->mnt_dir, NULL, 0, NULL, NULL, |
62 | if ( !GetVolumeInformation(data->mnt_dir, NULL, 0, NULL, NULL, | 41 | NULL, data->mnt_type, 100)) { |
63 | NULL, data->mnt_type, 100) ) { | 42 | return FALSE; |
64 | continue; | 43 | } |
65 | } | 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; | ||
66 | 74 | ||
67 | if (realpath(data->mnt_dir, buf) != NULL) { | 75 | while (++state->index < 26) { |
68 | if (isalpha(buf[0]) && strcmp(buf+1, ":/") == 0) | 76 | if ((state->drives & 1 << state->index) != 0) { |
69 | buf[2] = '\0'; | 77 | if (data == NULL) |
70 | strcpy(data->mnt_fsname, buf); | 78 | data = xmalloc(sizeof(*data)); |
71 | } | ||
72 | 79 | ||
80 | if (fill_mntdata(data, state->index)) { | ||
73 | entry = &data->me; | 81 | entry = &data->me; |
74 | break; | 82 | break; |
75 | } | 83 | } |
diff --git a/win32/mntent.h b/win32/mntent.h index 8bdf3d45e..029f18b96 100644 --- a/win32/mntent.h +++ b/win32/mntent.h | |||
@@ -16,6 +16,18 @@ extern FILE *mingw_setmntent(void); | |||
16 | extern struct mntent *getmntent(FILE *stream); | 16 | extern struct mntent *getmntent(FILE *stream); |
17 | extern int endmntent(FILE *stream); | 17 | extern int endmntent(FILE *stream); |
18 | 18 | ||
19 | # if defined(MNTENT_PRIVATE) | ||
20 | struct mntdata { | ||
21 | struct mntent me; | ||
22 | char mnt_fsname[PATH_MAX]; | ||
23 | char mnt_dir[4]; | ||
24 | char mnt_type[100]; | ||
25 | char mnt_opts[4]; | ||
26 | }; | ||
27 | |||
28 | extern int fill_mntdata(struct mntdata *data, int index); | ||
29 | # endif | ||
30 | |||
19 | #define setmntent(f, m) mingw_setmntent() | 31 | #define setmntent(f, m) mingw_setmntent() |
20 | 32 | ||
21 | #endif | 33 | #endif |