diff options
author | Ron Yorston <rmy@pobox.com> | 2021-06-27 13:40:07 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-06-27 14:05:33 +0100 |
commit | 0fdf99bee07b6c38795eb5415b5e337ab82cfba8 (patch) | |
tree | 09409cdc12b08bd3e37c942738525666ed759a02 /win32/mntent.c | |
parent | 6d6856355aec9ed6c9b8039b9b1ec8f997395c9e (diff) | |
download | busybox-w32-0fdf99bee07b6c38795eb5415b5e337ab82cfba8.tar.gz busybox-w32-0fdf99bee07b6c38795eb5415b5e337ab82cfba8.tar.bz2 busybox-w32-0fdf99bee07b6c38795eb5415b5e337ab82cfba8.zip |
win32: changes to mntent implementation
Make the structure returned by getmntent(3) static so it persists
after endmntent(3) closes the stream. No current caller in the
WIN32 port needs this functionality but it's good to match the
documented behaviour.
Populate more fields of the mntent structure in find_mount_point().
This is required to support the df -t and -T flags recently added
upstream.
The static structures used here are allocated on demand. Separate
static structures are used in each case because df iterates through
mounts calling statfs(2) on each and the WIN32 implementation of
statfs(2) calls find_mount_point().
Diffstat (limited to 'win32/mntent.c')
-rw-r--r-- | win32/mntent.c | 106 |
1 files changed, 57 insertions, 49 deletions
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 | } |