aboutsummaryrefslogtreecommitdiff
path: root/win32/mntent.c
blob: 9b04a9c5e376bc3b9449b77df25cbbef0991b643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * A simple WIN32 implementation of mntent routines.  It only handles
 * fixed logical drives.
 */
#include "libbb.h"

struct mntdata {
	DWORD flags;
	int index;
};

FILE *setmntent(const char *file UNUSED_PARAM, const char *mode UNUSED_PARAM)
{
	struct mntdata *data;

	if ( (data=malloc(sizeof(struct mntdata))) == NULL ) {
		return NULL;
	}

	data->flags = GetLogicalDrives();
	data->index = -1;

	return (FILE *)data;
}

struct mntent *getmntent(FILE *stream)
{
	struct mntdata *data = (struct mntdata *)stream;
	static char mnt_fsname[4];
	static char mnt_dir[4];
	static char mnt_type[100];
	static char mnt_opts[4];
	static struct mntent my_mount_entry =
					{ mnt_fsname, mnt_dir, mnt_type, mnt_opts, 0, 0 };
	struct mntent *entry;

	entry = NULL;
	while ( ++data->index < 26 ) {
		if ( (data->flags & 1<<data->index) != 0 ) {
			mnt_fsname[0] = 'A' + data->index;
			mnt_fsname[1] = ':';
			mnt_fsname[2] = '\0';
			mnt_dir[0] = 'A' + data->index;
			mnt_dir[1] = ':';
			mnt_dir[2] = '\\';
			mnt_dir[3] = '\0';
			mnt_type[0] = '\0';
			mnt_opts[0] = '\0';

			if ( GetDriveType(mnt_dir) == DRIVE_FIXED ) {
				if ( !GetVolumeInformation(mnt_dir, NULL, 0, NULL, NULL,
								NULL, mnt_type, 100) ) {
					mnt_type[0] = '\0';
				}

				entry = &my_mount_entry;
				break;
			}
		}
	}

	return entry;
}

int endmntent(FILE *stream)
{
	free(stream);
	return 0;
}