tar + gzip/bzip2/etc: support NOMMU machines (by Alex Landau <landau_alex@yahoo.com>)
authorDenis Vlasenko <vda.linux@googlemail.com>
Wed, 5 Sep 2007 11:48:32 +0000 (11:48 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Wed, 5 Sep 2007 11:48:32 +0000 (11:48 -0000)
archival/bbunzip.c
archival/libunarchive/Kbuild
archival/libunarchive/get_header_tar_bz2.c
archival/libunarchive/get_header_tar_gz.c
archival/libunarchive/get_header_tar_lzma.c
archival/libunarchive/open_transformer.c
archival/rpm.c
archival/tar.c
include/unarchive.h

index 56c742a49162f85f65012bce7ec032a8ce7be76d..a4e525f2e96de6b9acc5c7141a7ec10163308d06 100644 (file)
@@ -298,7 +298,7 @@ USE_DESKTOP(long long) int unpack_unlzma(void)
 int unlzma_main(int argc, char **argv);
 int unlzma_main(int argc, char **argv)
 {
-       getopt32(argv, "c");
+       getopt32(argv, "cf");
        argv += optind;
        /* lzmacat? */
        if (applet_name[4] == 'c')
index 3c29d541a88a386f1515af3047704938c097413f..d104524e4ca7c0d795d490f11e2b1a5ae012e39e 100644 (file)
@@ -35,36 +35,34 @@ DPKG_FILES:= \
        get_header_tar.o \
        filter_accept_list_reassign.o
 
-# open_transformer uses fork(). Compile it only if absolutely necessary
 lib-$(CONFIG_RPM)                       += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_BZIP2)                += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_LZMA)         += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_GZIP)         += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_COMPRESS)     += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_GZ)       += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_BZ2)      += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_LZMA)     += open_transformer.o
-
-lib-$(CONFIG_AR)                       += get_header_ar.o unpack_ar_archive.o
-lib-$(CONFIG_BUNZIP2)                  += decompress_bunzip2.o
-lib-$(CONFIG_UNLZMA)                   += decompress_unlzma.o
-lib-$(CONFIG_CPIO)                     += get_header_cpio.o
-lib-$(CONFIG_DPKG)                     += $(DPKG_FILES)
-lib-$(CONFIG_DPKG_DEB)                 += $(DPKG_FILES)
-lib-$(CONFIG_FEATURE_DEB_TAR_GZ)       += $(GUNZIP_FILES) get_header_tar_gz.o
-lib-$(CONFIG_FEATURE_DEB_TAR_BZ2)      += decompress_bunzip2.o get_header_tar_bz2.o
-lib-$(CONFIG_FEATURE_DEB_TAR_LZMA)     += decompress_unlzma.o get_header_tar_lzma.o
-lib-$(CONFIG_GUNZIP)                   += $(GUNZIP_FILES)
-lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS)        += decompress_uncompress.o
-lib-$(CONFIG_RPM2CPIO)                 += $(GUNZIP_FILES) get_header_cpio.o
-lib-$(CONFIG_RPM)                      += $(GUNZIP_FILES) get_header_cpio.o
-lib-$(CONFIG_FEATURE_RPM_BZ2)          += decompress_bunzip2.o
-lib-$(CONFIG_TAR)                      += get_header_tar.o
-lib-$(CONFIG_FEATURE_TAR_BZIP2)                += decompress_bunzip2.o get_header_tar_bz2.o
-lib-$(CONFIG_FEATURE_TAR_LZMA)         += decompress_unlzma.o get_header_tar_lzma.o
-lib-$(CONFIG_FEATURE_TAR_GZIP)         += $(GUNZIP_FILES) get_header_tar_gz.o
-lib-$(CONFIG_FEATURE_TAR_COMPRESS)     += decompress_uncompress.o
-lib-$(CONFIG_UNCOMPRESS)               += decompress_uncompress.o
-lib-$(CONFIG_UNZIP)                    += $(GUNZIP_FILES)
-lib-$(CONFIG_FEATURE_COMPRESS_USAGE)   += decompress_bunzip2.o
+lib-$(CONFIG_FEATURE_TAR_BZIP2)         += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_LZMA)          += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_GZIP)          += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_COMPRESS)      += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_GZ)        += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_BZ2)       += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_LZMA)      += open_transformer.o
 
+lib-$(CONFIG_AR)                        += get_header_ar.o unpack_ar_archive.o
+lib-$(CONFIG_BUNZIP2)                   += decompress_bunzip2.o
+lib-$(CONFIG_UNLZMA)                    += decompress_unlzma.o
+lib-$(CONFIG_CPIO)                      += get_header_cpio.o
+lib-$(CONFIG_DPKG)                      += $(DPKG_FILES)
+lib-$(CONFIG_DPKG_DEB)                  += $(DPKG_FILES)
+lib-$(CONFIG_FEATURE_DEB_TAR_GZ)        += $(GUNZIP_FILES) get_header_tar_gz.o
+lib-$(CONFIG_FEATURE_DEB_TAR_BZ2)       += decompress_bunzip2.o get_header_tar_bz2.o
+lib-$(CONFIG_FEATURE_DEB_TAR_LZMA)      += decompress_unlzma.o get_header_tar_lzma.o
+lib-$(CONFIG_GUNZIP)                    += $(GUNZIP_FILES)
+lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
+lib-$(CONFIG_RPM2CPIO)                  += $(GUNZIP_FILES) get_header_cpio.o
+lib-$(CONFIG_RPM)                       += $(GUNZIP_FILES) get_header_cpio.o
+lib-$(CONFIG_FEATURE_RPM_BZ2)           += decompress_bunzip2.o
+lib-$(CONFIG_TAR)                       += get_header_tar.o
+lib-$(CONFIG_FEATURE_TAR_BZIP2)         += decompress_bunzip2.o get_header_tar_bz2.o
+lib-$(CONFIG_FEATURE_TAR_LZMA)          += decompress_unlzma.o get_header_tar_lzma.o
+lib-$(CONFIG_FEATURE_TAR_GZIP)          += $(GUNZIP_FILES) get_header_tar_gz.o
+lib-$(CONFIG_FEATURE_TAR_COMPRESS)      += decompress_uncompress.o
+lib-$(CONFIG_UNCOMPRESS)                += decompress_uncompress.o
+lib-$(CONFIG_UNZIP)                     += $(GUNZIP_FILES)
+lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += decompress_bunzip2.o
index e11f44cad2ad4e83278d9dc6ee537d71ac198aa7..8f7f83fc2de65d9744202c2c7655d5c4c3bb1753 100644 (file)
@@ -11,7 +11,7 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
        /* Can't lseek over pipes */
        archive_handle->seek = seek_by_read;
 
-       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream);
+       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL);
        archive_handle->offset = 0;
        while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
 
index 85070d97855e0fd607b5ba190e9e98dc2445d756..a99061411fbeb6a5b37915937df0150dcf933bf0 100644 (file)
@@ -8,19 +8,26 @@
 
 char get_header_tar_gz(archive_handle_t *archive_handle)
 {
+#if BB_MMU
        unsigned char magic[2];
+#endif
 
        /* Can't lseek over pipes */
        archive_handle->seek = seek_by_read;
 
+       /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
+        * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
+        * need the header. */
+#if BB_MMU
        xread(archive_handle->src_fd, &magic, 2);
        if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
                bb_error_msg_and_die("invalid gzip magic");
        }
 
        check_header_gzip_or_die(archive_handle->src_fd);
+#endif
 
-       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream);
+       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
        archive_handle->offset = 0;
        while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
 
index 771f664f2a1719a2b696eab72c148fac16d27708..f0e45f2c5d874d44546f89f5b1a65bb3c75c6673 100644 (file)
@@ -14,7 +14,7 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
        /* Can't lseek over pipes */
        archive_handle->seek = seek_by_read;
 
-       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream);
+       archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL);
        archive_handle->offset = 0;
        while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
 
index 93f01be6f21e8118a54f3e8abeef9d7f643a7f0f..f8f587e8d3992b5c67b18846ea0c7d038c0c7b72 100644 (file)
@@ -7,29 +7,48 @@
 #include "unarchive.h"
 
 /* transformer(), more than meets the eye */
+/*
+ * On MMU machine, the transform_prog and ... are stripped
+ * by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
+ */
 int open_transformer(int src_fd,
-       USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
+       USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
+       const char *transform_prog, ...)
 {
        int fd_pipe[2];
        int pid;
 
        xpipe(fd_pipe);
 
+#if BB_MMU
        pid = fork();
-       if (pid == -1) {
+#else
+       pid = vfork();
+#endif
+       if (pid == -1)
                bb_perror_msg_and_die("fork failed");
-       }
 
        if (pid == 0) {
+#if !BB_MMU
+               va_list ap;
+#endif
                /* child process */
                close(fd_pipe[0]); /* We don't wan't to read from the parent */
                // FIXME: error check?
+#if BB_MMU
                transformer(src_fd, fd_pipe[1]);
                if (ENABLE_FEATURE_CLEAN_UP) {
                        close(fd_pipe[1]); /* Send EOF */
                        close(src_fd);
                }
                exit(0);
+#else
+               xmove_fd(src_fd, 0);
+               xmove_fd(fd_pipe[1], 1);
+               va_start(ap, transform_prog);
+               BB_EXECVP(transform_prog, ap);
+               bb_perror_and_die("exec failed");
+#endif
                /* notreached */
        }
 
index 674ee2640576af0c8cd507e95eb543f433ea8bc3..4d723b73f1e28619f29acd074c4ed132766764c7 100644 (file)
@@ -187,9 +187,15 @@ int rpm_main(int argc, char **argv)
 
 static void extract_cpio_gz(int fd)
 {
-       USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
        archive_handle_t *archive_handle;
        unsigned char magic[2];
+#if BB_MMU
+       USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
+       enum { xformer_prog = 0 };
+#else
+       enum { xformer = 0 };
+       const char *xformer_prog;
+#endif
 
        /* Initialize */
        archive_handle = init_handle();
@@ -202,11 +208,19 @@ static void extract_cpio_gz(int fd)
        archive_handle->offset = 0;
 
        xread(archive_handle->src_fd, &magic, 2);
+#if BB_MMU
        xformer = unpack_gz_stream;
+#else
+       xformer_prog = "gunzip";
+#endif
        if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
                if (ENABLE_FEATURE_RPM_BZ2
                 && (magic[0] == 0x42) && (magic[1] == 0x5a)) {
+#if BB_MMU
                        xformer = unpack_bz2_stream;
+#else
+                       xformer_prog = "bunzip2";
+#endif
        /* We can do better, need modifying unpack_bz2_stream to not require
         * first 2 bytes. Not very hard to do... I mean, TODO :) */
                        xlseek(archive_handle->src_fd, -2, SEEK_CUR);
@@ -214,11 +228,17 @@ static void extract_cpio_gz(int fd)
                        bb_error_msg_and_die("no gzip"
                                USE_FEATURE_RPM_BZ2("/bzip")
                                " magic");
-       } else
+       } else {
                check_header_gzip_or_die(archive_handle->src_fd);
+#if !BB_MMU
+               /* NOMMU version of open_transformer execs an external unzipper that should
+                * have the file position at the start of the file */
+               xlseek(archive_handle->src_fd, 0, SEEK_SET);
+#endif
+       }
 
        xchdir("/"); /* Install RPM's to root */
-       archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer);
+       archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL);
        archive_handle->offset = 0;
        while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
                continue;
index f0d3971140495fa18e12a12cfa0b55cc526660ce..e0d4daff7d93324729317c4373a43c00ab10c13a 100644 (file)
@@ -660,7 +660,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
                bb_error_msg_and_die("invalid magic");
        }
 
-       archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
+       archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL);
        archive_handle->offset = 0;
        while (get_header_tar(archive_handle) == EXIT_SUCCESS)
                /* nothing */;
index bea055852abad6c3bee578d14721a7cc6dcfecc2..51ec89cc00ef92fdce01bcae2a0fc478b7b3bc79 100644 (file)
@@ -115,7 +115,13 @@ extern USE_DESKTOP(long long) int inflate_unzip(inflate_unzip_result *res, unsig
 extern USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd);
 extern USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd);
 
+#if BB_MMU
 extern int open_transformer(int src_fd,
        USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd));
+#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transformer)
+#else
+extern int open_transformer(int src_fd, const char *transform_prog, ...);
+#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transform_prog, __VA_ARGS__)
+#endif
 
 #endif