aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-05-27 15:23:31 +0100
committerRon Yorston <rmy@pobox.com>2015-05-27 15:30:36 +0100
commit316ecf214a051121516730f794721f5e7b3036ac (patch)
tree3002051097aebc579cfe3a2e008ff43fe100c1c9
parent8a61b67d502ed4fbd5f480ca9458884b55ce7a95 (diff)
downloadbusybox-w32-316ecf214a051121516730f794721f5e7b3036ac.tar.gz
busybox-w32-316ecf214a051121516730f794721f5e7b3036ac.tar.bz2
busybox-w32-316ecf214a051121516730f794721f5e7b3036ac.zip
Enable seamless compression for WIN32
In the archival code we pretend that WIN32 is a no-MMU platform and use the new mingw_popen_fd routine to pipe data to/from commands to compress/decompress. The pretence is maintained by redefining MMU macros in bb_archive.h. This is mostly used in the archival code but there are a handful of places where it's used to access public interfaces. The symbol BB_ARCHIVE_PUBLIC is defined in these places. With these changes: tar supports seamless compression/decompression rpm2cpio and dpkg-deb can be enabled
-rw-r--r--README.md1
-rw-r--r--archival/cpio.c4
-rw-r--r--archival/libarchive/init_handle.c5
-rw-r--r--archival/libarchive/open_transformer.c20
-rw-r--r--archival/rpm2cpio.c2
-rw-r--r--archival/tar.c31
-rw-r--r--configs/mingw32_defconfig18
-rw-r--r--include/bb_archive.h10
-rw-r--r--libbb/appletlib.c1
-rw-r--r--miscutils/bbconfig.c1
-rw-r--r--procps/smemcap.c1
11 files changed, 82 insertions, 12 deletions
diff --git a/README.md b/README.md
index d4140487c..90a89521a 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,5 @@ Then just `make`.
16 16
17 - Use forward slashes in paths: Windows doesn't mind and the shell will be happier. 17 - Use forward slashes in paths: Windows doesn't mind and the shell will be happier.
18 - Don't do wild things with Windows drive or UNC notation. 18 - Don't do wild things with Windows drive or UNC notation.
19 - tar doesn't support seamless compression/decompression: use a pipeline to a compressor/decompressor.
20 - Wildcard expansion is disabled by default, though it can be turned on at compile time. This only affects command line arguments to the binary: the BusyBox shell has full support for wildcards. 19 - Wildcard expansion is disabled by default, though it can be turned on at compile time. This only affects command line arguments to the binary: the BusyBox shell has full support for wildcards.
21 - Handling of users, groups and permissions is totally bogus. The system only admits to knowing about the current user and always returns the same hardcoded uid, gid and permission values. 20 - Handling of users, groups and permissions is totally bogus. The system only admits to knowing about the current user and always returns the same hardcoded uid, gid and permission values.
diff --git a/archival/cpio.c b/archival/cpio.c
index 454648d68..3cb7fdb35 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -374,6 +374,10 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
374 argv += optind; 374 argv += optind;
375 if (opt & OPT_FILE) { /* -F */ 375 if (opt & OPT_FILE) { /* -F */
376 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); 376 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
377#if ENABLE_PLATFORM_MINGW32
378 /* default is seek_by_read but seek_by_jump is OK for file */
379 archive_handle->seek = seek_by_jump;
380#endif
377 } 381 }
378#else 382#else
379 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); 383 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
diff --git a/archival/libarchive/init_handle.c b/archival/libarchive/init_handle.c
index cbae06ac3..b1166d577 100644
--- a/archival/libarchive/init_handle.c
+++ b/archival/libarchive/init_handle.c
@@ -16,7 +16,12 @@ archive_handle_t* FAST_FUNC init_handle(void)
16 archive_handle->action_header = header_skip; 16 archive_handle->action_header = header_skip;
17 archive_handle->action_data = data_skip; 17 archive_handle->action_data = data_skip;
18 archive_handle->filter = filter_accept_all; 18 archive_handle->filter = filter_accept_all;
19#if !ENABLE_PLATFORM_MINGW32
19 archive_handle->seek = seek_by_jump; 20 archive_handle->seek = seek_by_jump;
21#else
22 /* can't reliably detect pipes on WIN32: default to seek_by_read */
23 archive_handle->seek = seek_by_read;
24#endif
20 25
21 return archive_handle; 26 return archive_handle;
22} 27}
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 1c5c185d0..24524f6ee 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -69,6 +69,7 @@ ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *bu
69} 69}
70 70
71#if SEAMLESS_COMPRESSION 71#if SEAMLESS_COMPRESSION
72#if !ENABLE_PLATFORM_MINGW32
72void check_errors_in_children(int signo) 73void check_errors_in_children(int signo)
73{ 74{
74 int status; 75 int status;
@@ -155,6 +156,25 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
155 close(fd_pipe.wr); /* don't want to write to the child */ 156 close(fd_pipe.wr); /* don't want to write to the child */
156 xmove_fd(fd_pipe.rd, fd); 157 xmove_fd(fd_pipe.rd, fd);
157} 158}
159#else
160void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
161{
162 char *cmd;
163 int fd1;
164
165 if (find_applet_by_name(transform_prog) >= 0) {
166 cmd = xasprintf("%s %s -cf -", bb_busybox_exec_path, transform_prog);
167 }
168 else {
169 cmd = xasprintf("%s -cf -", transform_prog);
170 }
171 if ( (fd1=mingw_popen_fd(cmd, "r", fd, NULL)) == -1 ) {
172 bb_perror_msg_and_die("can't execute '%s'", transform_prog);
173 }
174 free(cmd);
175 xmove_fd(fd1, fd);
176}
177#endif
158 178
159/* Used by e.g. rpm which gives us a fd without filename, 179/* Used by e.g. rpm which gives us a fd without filename,
160 * thus we can't guess the format from filename's extension. 180 * thus we can't guess the format from filename's extension.
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 7057570f5..7703629cb 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -88,7 +88,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
88 close(rpm_fd); 88 close(rpm_fd);
89 } 89 }
90 90
91 if (SEAMLESS_COMPRESSION) { 91 if (SEAMLESS_COMPRESSION && !ENABLE_PLATFORM_MINGW32) {
92 check_errors_in_children(0); 92 check_errors_in_children(0);
93 return bb_got_signal; 93 return bb_got_signal;
94 } 94 }
diff --git a/archival/tar.c b/archival/tar.c
index 85551684b..1f9dd23d2 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -617,6 +617,7 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
617} 617}
618 618
619#if SEAMLESS_COMPRESSION 619#if SEAMLESS_COMPRESSION
620#if !ENABLE_PLATFORM_MINGW32
620/* Don't inline: vfork scares gcc and pessimizes code */ 621/* Don't inline: vfork scares gcc and pessimizes code */
621static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) 622static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
622{ 623{
@@ -676,6 +677,27 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
676 bb_perror_msg_and_die("can't execute '%s'", gzip); 677 bb_perror_msg_and_die("can't execute '%s'", gzip);
677 } 678 }
678} 679}
680#else
681static pid_t vfork_compressor(int tar_fd, const char *gzip)
682{
683 char *cmd;
684 int fd1;
685 pid_t pid;
686
687 if (find_applet_by_name(gzip) >= 0) {
688 cmd = xasprintf("%s %s -cf -", bb_busybox_exec_path, gzip);
689 }
690 else {
691 cmd = xasprintf("%s -cf -", gzip);
692 }
693 if ( (fd1=mingw_popen_fd(cmd, "w", tar_fd, &pid)) == -1 ) {
694 bb_perror_msg_and_die("can't execute '%s'", gzip);
695 }
696 free(cmd);
697 xmove_fd(fd1, tar_fd);
698 return pid;
699}
700#endif /* ENABLE_PLATFORM_MINGW32 */
679#endif /* SEAMLESS_COMPRESSION */ 701#endif /* SEAMLESS_COMPRESSION */
680 702
681 703
@@ -691,6 +713,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
691{ 713{
692 int errorFlag = FALSE; 714 int errorFlag = FALSE;
693 struct TarBallInfo tbInfo; 715 struct TarBallInfo tbInfo;
716 IF_PLATFORM_MINGW32(pid_t pid = 0;)
694 717
695 tbInfo.hlInfoHead = NULL; 718 tbInfo.hlInfoHead = NULL;
696 tbInfo.tarFd = tar_fd; 719 tbInfo.tarFd = tar_fd;
@@ -702,7 +725,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
702 725
703#if SEAMLESS_COMPRESSION 726#if SEAMLESS_COMPRESSION
704 if (gzip) 727 if (gzip)
705 vfork_compressor(tbInfo.tarFd, gzip); 728 IF_PLATFORM_MINGW32(pid = )vfork_compressor(tbInfo.tarFd, gzip);
706#endif 729#endif
707 730
708 tbInfo.excludeList = exclude; 731 tbInfo.excludeList = exclude;
@@ -738,7 +761,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
738#if SEAMLESS_COMPRESSION 761#if SEAMLESS_COMPRESSION
739 if (gzip) { 762 if (gzip) {
740 int status; 763 int status;
764#if !ENABLE_PLATFORM_MINGW32
741 if (safe_waitpid(-1, &status, 0) == -1) 765 if (safe_waitpid(-1, &status, 0) == -1)
766#else
767 if (safe_waitpid(pid, &status, 0) == -1)
768#endif
742 bb_perror_msg("waitpid"); 769 bb_perror_msg("waitpid");
743 else if (!WIFEXITED(status) || WEXITSTATUS(status)) 770 else if (!WIFEXITED(status) || WEXITSTATUS(status))
744 /* gzip was killed or has exited with nonzero! */ 771 /* gzip was killed or has exited with nonzero! */
@@ -1208,10 +1235,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1208 if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */) 1235 if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */)
1209 close(tar_handle->src_fd); 1236 close(tar_handle->src_fd);
1210 1237
1238#if !ENABLE_PLATFORM_MINGW32
1211 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { 1239 if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
1212 /* Set bb_got_signal to 1 if a child died with !0 exitcode */ 1240 /* Set bb_got_signal to 1 if a child died with !0 exitcode */
1213 check_errors_in_children(0); 1241 check_errors_in_children(0);
1214 } 1242 }
1243#endif
1215 1244
1216 return bb_got_signal; 1245 return bb_got_signal;
1217} 1246}
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig
index 6804752f2..71ed1c11c 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.24.0.git 3# Busybox version: 1.24.0.git
4# Mon May 18 14:31:53 2015 4# Wed May 27 14:28:56 2015
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
@@ -133,11 +133,11 @@ CONFIG_IOCTL_HEX2STR_ERROR=y
133# 133#
134# Archival Utilities 134# Archival Utilities
135# 135#
136# CONFIG_FEATURE_SEAMLESS_XZ is not set 136CONFIG_FEATURE_SEAMLESS_XZ=y
137# CONFIG_FEATURE_SEAMLESS_LZMA is not set 137CONFIG_FEATURE_SEAMLESS_LZMA=y
138# CONFIG_FEATURE_SEAMLESS_BZ2 is not set 138CONFIG_FEATURE_SEAMLESS_BZ2=y
139# CONFIG_FEATURE_SEAMLESS_GZ is not set 139CONFIG_FEATURE_SEAMLESS_GZ=y
140# CONFIG_FEATURE_SEAMLESS_Z is not set 140CONFIG_FEATURE_SEAMLESS_Z=y
141CONFIG_AR=y 141CONFIG_AR=y
142CONFIG_FEATURE_AR_LONG_FILENAMES=y 142CONFIG_FEATURE_AR_LONG_FILENAMES=y
143CONFIG_FEATURE_AR_CREATE=y 143CONFIG_FEATURE_AR_CREATE=y
@@ -154,7 +154,7 @@ CONFIG_CPIO=y
154CONFIG_FEATURE_CPIO_O=y 154CONFIG_FEATURE_CPIO_O=y
155CONFIG_FEATURE_CPIO_P=y 155CONFIG_FEATURE_CPIO_P=y
156# CONFIG_DPKG is not set 156# CONFIG_DPKG is not set
157# CONFIG_DPKG_DEB is not set 157CONFIG_DPKG_DEB=y
158# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set 158# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
159CONFIG_GZIP=y 159CONFIG_GZIP=y
160CONFIG_FEATURE_GZIP_LONG_OPTIONS=y 160CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
@@ -162,11 +162,11 @@ CONFIG_GZIP_FAST=2
162CONFIG_FEATURE_GZIP_LEVELS=y 162CONFIG_FEATURE_GZIP_LEVELS=y
163CONFIG_LZOP=y 163CONFIG_LZOP=y
164# CONFIG_LZOP_COMPR_HIGH is not set 164# CONFIG_LZOP_COMPR_HIGH is not set
165# CONFIG_RPM2CPIO is not set 165CONFIG_RPM2CPIO=y
166# CONFIG_RPM is not set 166# CONFIG_RPM is not set
167CONFIG_TAR=y 167CONFIG_TAR=y
168CONFIG_FEATURE_TAR_CREATE=y 168CONFIG_FEATURE_TAR_CREATE=y
169# CONFIG_FEATURE_TAR_AUTODETECT is not set 169CONFIG_FEATURE_TAR_AUTODETECT=y
170CONFIG_FEATURE_TAR_FROM=y 170CONFIG_FEATURE_TAR_FROM=y
171CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y 171CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
172# CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set 172# CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
diff --git a/include/bb_archive.h b/include/bb_archive.h
index 5d9e24c17..d94169627 100644
--- a/include/bb_archive.h
+++ b/include/bb_archive.h
@@ -2,6 +2,16 @@
2#ifndef UNARCHIVE_H 2#ifndef UNARCHIVE_H
3#define UNARCHIVE_H 1 3#define UNARCHIVE_H 1
4 4
5#if !defined(BB_ARCHIVE_PUBLIC) && ENABLE_PLATFORM_MINGW32
6/* treat mingw as a non-MMU platform */
7#undef BB_MMU
8#undef USE_FOR_NOMMU
9#undef USE_FOR_MMU
10#define BB_MMU 0
11#define USE_FOR_NOMMU(...) __VA_ARGS__
12#define USE_FOR_MMU(...)
13#endif
14
5PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 15PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
6 16
7enum { 17enum {
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 683d10b20..841494a70 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -62,6 +62,7 @@ static const char usage_messages[] ALIGN1 = UNPACKED_USAGE;
62#if ENABLE_FEATURE_COMPRESS_USAGE 62#if ENABLE_FEATURE_COMPRESS_USAGE
63 63
64static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; 64static const char packed_usage[] ALIGN1 = { PACKED_USAGE };
65#define BB_ARCHIVE_PUBLIC
65# include "bb_archive.h" 66# include "bb_archive.h"
66static const char *unpack_usage_messages(void) 67static const char *unpack_usage_messages(void)
67{ 68{
diff --git a/miscutils/bbconfig.c b/miscutils/bbconfig.c
index e5f4eb379..b252779f5 100644
--- a/miscutils/bbconfig.c
+++ b/miscutils/bbconfig.c
@@ -10,6 +10,7 @@
10#include "libbb.h" 10#include "libbb.h"
11#include "bbconfigopts.h" 11#include "bbconfigopts.h"
12#if ENABLE_FEATURE_COMPRESS_BBCONFIG 12#if ENABLE_FEATURE_COMPRESS_BBCONFIG
13#define BB_ARCHIVE_PUBLIC
13# include "bb_archive.h" 14# include "bb_archive.h"
14# include "bbconfigopts_bz2.h" 15# include "bbconfigopts_bz2.h"
15#endif 16#endif
diff --git a/procps/smemcap.c b/procps/smemcap.c
index 9d1126a49..b2b32198f 100644
--- a/procps/smemcap.c
+++ b/procps/smemcap.c
@@ -20,6 +20,7 @@
20//config: a memory usage statistic tool. 20//config: a memory usage statistic tool.
21 21
22#include "libbb.h" 22#include "libbb.h"
23#define BB_ARCHIVE_PUBLIC
23#include "bb_archive.h" 24#include "bb_archive.h"
24 25
25struct fileblock { 26struct fileblock {