aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2013-04-03 12:09:21 +0100
committerRon Yorston <rmy@pobox.com>2013-04-03 12:09:21 +0100
commit8782950636f76faa8db0ed8c5d698ab0bd1fbf45 (patch)
tree05f57d81916e41f7ca802ff7eb1934c4d72518a1 /win32
parente4f28beec255ea2e233e0f016d4795d13a24bfae (diff)
downloadbusybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.tar.gz
busybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.tar.bz2
busybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.zip
df: limited implementation for WIN32
Diffstat (limited to 'win32')
-rw-r--r--win32/Kbuild2
-rw-r--r--win32/mntent.c59
-rw-r--r--win32/mntent.h19
-rw-r--r--win32/statfs.c50
-rw-r--r--win32/sys/vfs.h17
5 files changed, 147 insertions, 0 deletions
diff --git a/win32/Kbuild b/win32/Kbuild
index 109b70e7b..564498c78 100644
--- a/win32/Kbuild
+++ b/win32/Kbuild
@@ -13,6 +13,8 @@ lib-$(CONFIG_PLATFORM_MINGW32) += regex.o
13lib-$(CONFIG_WIN32_NET) += net.o 13lib-$(CONFIG_WIN32_NET) += net.o
14lib-$(CONFIG_PLATFORM_MINGW32) += poll.o 14lib-$(CONFIG_PLATFORM_MINGW32) += poll.o
15lib-$(CONFIG_PLATFORM_MINGW32) += popen.o 15lib-$(CONFIG_PLATFORM_MINGW32) += popen.o
16lib-$(CONFIG_PLATFORM_MINGW32) += statfs.o
17lib-$(CONFIG_PLATFORM_MINGW32) += mntent.o
16lib-$(CONFIG_PLATFORM_MINGW32) += system.o 18lib-$(CONFIG_PLATFORM_MINGW32) += system.o
17lib-$(CONFIG_PLATFORM_MINGW32) += termios.o 19lib-$(CONFIG_PLATFORM_MINGW32) += termios.o
18lib-$(CONFIG_PLATFORM_MINGW32) += uname.o 20lib-$(CONFIG_PLATFORM_MINGW32) += uname.o
diff --git a/win32/mntent.c b/win32/mntent.c
new file mode 100644
index 000000000..22efbf1b7
--- /dev/null
+++ b/win32/mntent.c
@@ -0,0 +1,59 @@
1/*
2 * A simple WIN32 implementation of mntent routines. It only handles
3 * fixed logical drives.
4 */
5#include "libbb.h"
6
7struct mntdata {
8 DWORD flags;
9 int index;
10};
11
12FILE *setmntent(const char *file, const char *mode)
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
26struct 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 = { mnt_fsname, mnt_dir, "", 0, 0 };
32 static struct mntent *entry;
33
34 entry = NULL;
35 while ( ++data->index < 26 ) {
36 if ( (data->flags & 1<<data->index) != 0 ) {
37 mnt_fsname[0] = 'A' + data->index;
38 mnt_fsname[1] = ':';
39 mnt_fsname[2] = '\0';
40 mnt_dir[0] = 'A' + data->index;
41 mnt_dir[1] = ':';
42 mnt_dir[2] = '\\';
43 mnt_dir[3] = '\0';
44
45 if ( GetDriveType(mnt_dir) == DRIVE_FIXED ) {
46 entry = &my_mount_entry;
47 break;
48 }
49 }
50 }
51
52 return entry;
53}
54
55int endmntent(FILE *stream)
56{
57 free(stream);
58 return 0;
59}
diff --git a/win32/mntent.h b/win32/mntent.h
new file mode 100644
index 000000000..b035bfa9c
--- /dev/null
+++ b/win32/mntent.h
@@ -0,0 +1,19 @@
1#ifndef MNTENT_H
2#define MNTENT_H
3
4#include <stdio.h>
5
6struct mntent {
7 char *mnt_fsname; /* Device or server for filesystem. */
8 char *mnt_dir; /* Directory mounted on. */
9 char *mnt_type; /* Type of filesystem: ufs, nfs, etc. */
10 char *mnt_opts; /* Comma-separated options for fs. */
11 int mnt_freq; /* Dump frequency (in days). */
12 int mnt_passno; /* Pass number for `fsck'. */
13};
14
15extern FILE *setmntent(const char *file, const char *mode);
16extern struct mntent *getmntent(FILE *stream);
17extern int endmntent(FILE *stream);
18
19#endif
diff --git a/win32/statfs.c b/win32/statfs.c
new file mode 100644
index 000000000..8424d58fa
--- /dev/null
+++ b/win32/statfs.c
@@ -0,0 +1,50 @@
1#include <sys/vfs.h>
2#include "libbb.h"
3
4/*
5 * Code from libguestfs
6 */
7int statfs(const char *file, struct statfs *buf)
8{
9 ULONGLONG free_bytes_available; /* for user - similar to bavail */
10 ULONGLONG total_number_of_bytes;
11 ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */
12
13 if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available,
14 (PULARGE_INTEGER) &total_number_of_bytes,
15 (PULARGE_INTEGER) &total_number_of_free_bytes) ) {
16 return -1;
17 }
18
19 /* XXX I couldn't determine how to get block size. MSDN has a
20 * unhelpful hard-coded list here:
21 * http://support.microsoft.com/kb/140365
22 * but this depends on the filesystem type, the size of the disk and
23 * the version of Windows. So this code assumes the disk is NTFS
24 * and the version of Windows is >= Win2K.
25 */
26 if (total_number_of_bytes < UINT64_C(16) * 1024 * 1024 * 1024 * 1024)
27 buf->f_bsize = 4096;
28 else if (total_number_of_bytes < UINT64_C(32) * 1024 * 1024 * 1024 * 1024)
29 buf->f_bsize = 8192;
30 else if (total_number_of_bytes < UINT64_C(64) * 1024 * 1024 * 1024 * 1024)
31 buf->f_bsize = 16384;
32 else if (total_number_of_bytes < UINT64_C(128) * 1024 * 1024 * 1024 * 1024)
33 buf->f_bsize = 32768;
34 else
35 buf->f_bsize = 65536;
36
37 /* As with stat, -1 indicates a field is not known. */
38 buf->f_frsize = buf->f_bsize;
39 buf->f_blocks = total_number_of_bytes / buf->f_bsize;
40 buf->f_bfree = total_number_of_free_bytes / buf->f_bsize;
41 buf->f_bavail = free_bytes_available / buf->f_bsize;
42 buf->f_files = -1;
43 buf->f_ffree = -1;
44 buf->f_favail = -1;
45 buf->f_fsid = -1;
46 buf->f_flag = -1;
47 buf->f_namemax = FILENAME_MAX;
48
49 return 0;
50}
diff --git a/win32/sys/vfs.h b/win32/sys/vfs.h
new file mode 100644
index 000000000..cb7bda9af
--- /dev/null
+++ b/win32/sys/vfs.h
@@ -0,0 +1,17 @@
1#include <stdint.h>
2
3struct statfs {
4 uint64_t f_bsize;
5 uint64_t f_frsize;
6 uint64_t f_blocks;
7 uint64_t f_bfree;
8 uint64_t f_bavail;
9 uint64_t f_files;
10 uint64_t f_ffree;
11 uint64_t f_favail;
12 uint64_t f_fsid;
13 uint64_t f_flag;
14 uint64_t f_namemax;
15};
16
17extern int statfs(const char *file, struct statfs *buf);