aboutsummaryrefslogtreecommitdiff
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
parente4f28beec255ea2e233e0f016d4795d13a24bfae (diff)
downloadbusybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.tar.gz
busybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.tar.bz2
busybox-w32-8782950636f76faa8db0ed8c5d698ab0bd1fbf45.zip
df: limited implementation for WIN32
-rw-r--r--configs/mingw32_defconfig6
-rw-r--r--include/platform.h1
-rw-r--r--libbb/find_mount_point.c37
-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
8 files changed, 187 insertions, 4 deletions
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig
index 52b6a50cb..1447a00f1 100644
--- a/configs/mingw32_defconfig
+++ b/configs/mingw32_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Busybox version: 1.22.0.git 3# Busybox version: 1.22.0-TIG-1095-ge4f28be
4# Thu Mar 14 10:41:31 2013 4# Wed Apr 3 11:24:01 2013
5# 5#
6CONFIG_HAVE_DOT_CONFIG=y 6CONFIG_HAVE_DOT_CONFIG=y
7# CONFIG_PLATFORM_POSIX is not set 7# CONFIG_PLATFORM_POSIX is not set
@@ -213,7 +213,7 @@ CONFIG_DD=y
213# CONFIG_FEATURE_DD_SIGNAL_HANDLING is not set 213# CONFIG_FEATURE_DD_SIGNAL_HANDLING is not set
214# CONFIG_FEATURE_DD_THIRD_STATUS_LINE is not set 214# CONFIG_FEATURE_DD_THIRD_STATUS_LINE is not set
215CONFIG_FEATURE_DD_IBS_OBS=y 215CONFIG_FEATURE_DD_IBS_OBS=y
216# CONFIG_DF is not set 216CONFIG_DF=y
217# CONFIG_FEATURE_DF_FANCY is not set 217# CONFIG_FEATURE_DF_FANCY is not set
218CONFIG_DIRNAME=y 218CONFIG_DIRNAME=y
219CONFIG_DOS2UNIX=y 219CONFIG_DOS2UNIX=y
diff --git a/include/platform.h b/include/platform.h
index fa4267b4b..432cb9cae 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -420,7 +420,6 @@ typedef unsigned smalluint;
420# undef HAVE_VASPRINTF 420# undef HAVE_VASPRINTF
421# undef HAVE_UNLOCKED_STDIO 421# undef HAVE_UNLOCKED_STDIO
422# undef HAVE_UNLOCKED_LINE_OPS 422# undef HAVE_UNLOCKED_LINE_OPS
423# undef HAVE_MNTENT_H
424# undef HAVE_SYS_STATFS_H 423# undef HAVE_SYS_STATFS_H
425#endif 424#endif
426 425
diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c
index 9676b5f52..b9bc1dd76 100644
--- a/libbb/find_mount_point.c
+++ b/libbb/find_mount_point.c
@@ -24,10 +24,18 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too)
24 struct mntent *mountEntry; 24 struct mntent *mountEntry;
25 dev_t devno_of_name; 25 dev_t devno_of_name;
26 bool block_dev; 26 bool block_dev;
27#if ENABLE_PLATFORM_MINGW32
28 static char mnt_fsname[4];
29 static char mnt_dir[4];
30 struct mntent my_mount_entry = { mnt_fsname, mnt_dir, "", "", 0, 0 };
31 char *current, *path;
32 DWORD len;
33#endif
27 34
28 if (stat(name, &s) != 0) 35 if (stat(name, &s) != 0)
29 return NULL; 36 return NULL;
30 37
38#if !ENABLE_PLATFORM_MINGW32
31 devno_of_name = s.st_dev; 39 devno_of_name = s.st_dev;
32 block_dev = 0; 40 block_dev = 0;
33 /* Why S_ISCHR? - UBI volumes use char devices, not block */ 41 /* Why S_ISCHR? - UBI volumes use char devices, not block */
@@ -64,6 +72,35 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too)
64 break; 72 break;
65 } 73 }
66 endmntent(mtab_fp); 74 endmntent(mtab_fp);
75#else
76 mountEntry = NULL;
77 path = NULL;
78 current = NULL;
79
80 if ( isalpha(name[0]) && name[1] == ':' ) {
81 path = name;
82 }
83 else {
84 if ( (len=GetCurrentDirectory(0, NULL)) > 0 &&
85 (current=malloc(len+1)) != NULL &&
86 GetCurrentDirectory(len, current) ) {
87 path = current;
88 }
89 }
90
91 if ( path && isalpha(path[0]) && path[1] == ':' ) {
92 mnt_fsname[0] = path[0];
93 mnt_fsname[1] = path[1];
94 mnt_fsname[2] = '\0';
95 mnt_dir[0] = path[0];
96 mnt_dir[1] = path[1];
97 mnt_dir[2] = '\\';
98 mnt_dir[3] = '\0';
99
100 mountEntry = &my_mount_entry;
101 }
102 free(current);
103#endif
67 104
68 return mountEntry; 105 return mountEntry;
69} 106}
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);