aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-12-10 01:57:30 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-12-10 01:57:30 +0000
commit46f44d24fcc25a5d6e13e0453485881bdf147e91 (patch)
tree669e07b8bbe267e0f6185509686f87b9e94aa71c
parent00732b57c7392df0fad6fbe392628e3f2174ea57 (diff)
downloadbusybox-w32-46f44d24fcc25a5d6e13e0453485881bdf147e91.tar.gz
busybox-w32-46f44d24fcc25a5d6e13e0453485881bdf147e91.tar.bz2
busybox-w32-46f44d24fcc25a5d6e13e0453485881bdf147e91.zip
Support for tar -z option for uncompressing only
-rw-r--r--Changelog2
-rw-r--r--Config.h9
-rw-r--r--archival/gunzip.c4
-rw-r--r--archival/tar.c96
-rw-r--r--gunzip.c4
-rw-r--r--tar.c96
6 files changed, 163 insertions, 48 deletions
diff --git a/Changelog b/Changelog
index 2c6fbabd9..6a1612876 100644
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,7 @@
10.48 10.48
2 2
3 * Glenn McGrath -- tar now supports uncompressing tar files,
4 define BB_FEATURE_TAR_GZIP to use the -z option.
3 * Matt Kraai -- fix all usage of TRUE and FALSE so all apps now 5 * Matt Kraai -- fix all usage of TRUE and FALSE so all apps now
4 return EXIT_SUCCESS or EXIT_FAILURE to the system. 6 return EXIT_SUCCESS or EXIT_FAILURE to the system.
5 Now TRUE and FALSE are set to the C standard where TRUE=1. 7 Now TRUE and FALSE are set to the C standard where TRUE=1.
diff --git a/Config.h b/Config.h
index 50f9e3ac7..d95942a65 100644
--- a/Config.h
+++ b/Config.h
@@ -225,6 +225,9 @@
225// Enable support for "--exclude" and "-X" for excluding files 225// Enable support for "--exclude" and "-X" for excluding files
226#define BB_FEATURE_TAR_EXCLUDE 226#define BB_FEATURE_TAR_EXCLUDE
227// 227//
228// Enable support for tar -z option (currently only works for inflating)
229#define BB_FEATURE_TAR_GZIP
230//
228//// Enable reverse sort 231//// Enable reverse sort
229#define BB_FEATURE_SORT_REVERSE 232#define BB_FEATURE_SORT_REVERSE
230// 233//
@@ -324,6 +327,12 @@
324#endif 327#endif
325#endif 328#endif
326// 329//
330#ifdef BB_FEATURE_TAR_GZIP
331#ifndef BB_GUNZIP
332#define BB_GUNZIP
333#endif
334#endif
335//
327#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT 336#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
328#define BB_NFSMOUNT 337#define BB_NFSMOUNT
329#endif 338#endif
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 48db7cfd7..8558573ba 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -1084,7 +1084,7 @@ int inflate()
1084 * the compressed data, from offsets inptr to insize-1 included. 1084 * the compressed data, from offsets inptr to insize-1 included.
1085 * The magic header has already been checked. The output buffer is cleared. 1085 * The magic header has already been checked. The output buffer is cleared.
1086 */ 1086 */
1087int unzip(in, out) 1087extern int unzip(in, out)
1088int in, out; /* input and output file descriptors */ 1088int in, out; /* input and output file descriptors */
1089{ 1089{
1090 int ext_header = 0; /* set if extended local header */ 1090 int ext_header = 0; /* set if extended local header */
@@ -1179,7 +1179,7 @@ void clear_bufs(void)
1179/* =========================================================================== 1179/* ===========================================================================
1180 * Initialize gunzip buffers and signals 1180 * Initialize gunzip buffers and signals
1181 */ 1181 */
1182static int gunzip_init() 1182extern int gunzip_init()
1183{ 1183{
1184 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; 1184 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
1185 if (foreground) { 1185 if (foreground) {
diff --git a/archival/tar.c b/archival/tar.c
index cc7ba3b80..8c2650e2b 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -52,6 +52,11 @@
52#include <sys/sysmacros.h> 52#include <sys/sysmacros.h>
53#include <getopt.h> 53#include <getopt.h>
54 54
55#ifdef BB_FEATURE_TAR_GZIP
56extern int unzip(int in, int out);
57extern int gunzip_init();
58#endif
59
55/* Tar file constants */ 60/* Tar file constants */
56#ifndef MAJOR 61#ifndef MAJOR
57#define MAJOR(dev) (((dev)>>8)&0xff) 62#define MAJOR(dev) (((dev)>>8)&0xff)
@@ -129,29 +134,64 @@ struct TarInfo
129typedef struct TarInfo TarInfo; 134typedef struct TarInfo TarInfo;
130 135
131/* Local procedures to restore files from a tar file. */ 136/* Local procedures to restore files from a tar file. */
132static int readTarFile(const char* tarName, int extractFlag, int listFlag, 137static int readTarFile(int tarFd, int extractFlag, int listFlag,
133 int tostdoutFlag, int verboseFlag, char** extractList, 138 int tostdoutFlag, int verboseFlag, char** extractList,
134 char** excludeList); 139 char** excludeList);
135 140
136
137
138#ifdef BB_FEATURE_TAR_CREATE 141#ifdef BB_FEATURE_TAR_CREATE
139/* Local procedures to save files into a tar file. */ 142/* Local procedures to save files into a tar file. */
140static int writeTarFile(const char* tarName, int verboseFlag, char **argv, 143static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
141 char** excludeList); 144 char** excludeList);
142#endif 145#endif
143 146
147#ifdef BB_FEATURE_TAR_GZIP
148/* Signal handler for when child gzip process dies... */
149void child_died()
150{
151 fflush(stdout);
152 fflush(stderr);
153 exit(EXIT_FAILURE);
154}
155
156static int tar_unzip_init(int tarFd)
157{
158 int child_pid;
159 static int unzip_pipe[2];
160 /* Cope if child dies... Otherwise we block forever in read()... */
161 signal(SIGCHLD, child_died);
162
163 if (pipe(unzip_pipe)!=0)
164 error_msg_and_die("pipe error\n");
165
166 if ( (child_pid = fork()) == -1)
167 error_msg_and_die("fork failure\n");
168
169 if (child_pid==0) {
170 /* child process */
171 gunzip_init();
172 unzip(tarFd, unzip_pipe[1]);
173 exit(EXIT_SUCCESS);
174 }
175 else
176 /* return fd of uncompressed data to parent process */
177 return(unzip_pipe[0]);
178}
179#endif
180
144extern int tar_main(int argc, char **argv) 181extern int tar_main(int argc, char **argv)
145{ 182{
146 char** excludeList=NULL; 183 char** excludeList=NULL;
147 char** extractList=NULL; 184 char** extractList=NULL;
185 const char *tarName="-";
148#if defined BB_FEATURE_TAR_EXCLUDE 186#if defined BB_FEATURE_TAR_EXCLUDE
149 int excludeListSize=0; 187 int excludeListSize=0;
150 char *excludeFileName ="-"; 188 char *excludeFileName ="-";
151 FILE *fileList; 189 FILE *fileList;
152 char file[256]; 190 char file[256];
191#endif
192#if defined BB_FEATURE_TAR_GZIP
193 int unzipFlag = FALSE;
153#endif 194#endif
154 const char *tarName="-";
155 int listFlag = FALSE; 195 int listFlag = FALSE;
156 int extractFlag = FALSE; 196 int extractFlag = FALSE;
157 int createFlag = FALSE; 197 int createFlag = FALSE;
@@ -160,7 +200,6 @@ extern int tar_main(int argc, char **argv)
160 int status = FALSE; 200 int status = FALSE;
161 int firstOpt = TRUE; 201 int firstOpt = TRUE;
162 int stopIt; 202 int stopIt;
163
164 203
165 if (argc <= 1) 204 if (argc <= 1)
166 usage(tar_usage); 205 usage(tar_usage);
@@ -185,6 +224,11 @@ extern int tar_main(int argc, char **argv)
185 goto flagError; 224 goto flagError;
186 listFlag = TRUE; 225 listFlag = TRUE;
187 break; 226 break;
227#ifdef BB_FEATURE_TAR_GZIP
228 case 'z':
229 unzipFlag = TRUE;
230 break;
231#endif
188 case 'v': 232 case 'v':
189 verboseFlag = TRUE; 233 verboseFlag = TRUE;
190 break; 234 break;
@@ -255,13 +299,31 @@ extern int tar_main(int argc, char **argv)
255#ifndef BB_FEATURE_TAR_CREATE 299#ifndef BB_FEATURE_TAR_CREATE
256 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n"); 300 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n");
257#else 301#else
302#ifdef BB_FEATURE_TAR_GZIP
303 if (unzipFlag==TRUE)
304 error_msg_and_die("Creation of compressed not internally support by tar, pipe to busybox gunzip\n");
305#endif
258 status = writeTarFile(tarName, verboseFlag, argv, excludeList); 306 status = writeTarFile(tarName, verboseFlag, argv, excludeList);
259#endif 307#endif
260 } 308 }
261 if (listFlag == TRUE || extractFlag == TRUE) { 309 if (listFlag == TRUE || extractFlag == TRUE) {
310 int tarFd;
262 if (*argv) 311 if (*argv)
263 extractList = argv; 312 extractList = argv;
264 status = readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, 313 /* Open the tar file for reading. */
314 if (!strcmp(tarName, "-"))
315 tarFd = fileno(stdin);
316 else
317 tarFd = open(tarName, O_RDONLY);
318 if (tarFd < 0)
319 error_msg_and_die( "Error opening '%s': %s\n", tarName, strerror(errno));
320
321#ifdef BB_FEATURE_TAR_GZIP
322 /* unzip tarFd in a seperate process */
323 if (unzipFlag == TRUE)
324 tarFd = tar_unzip_init(tarFd);
325#endif
326 status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
265 verboseFlag, extractList, excludeList); 327 verboseFlag, extractList, excludeList);
266 } 328 }
267 329
@@ -521,27 +583,17 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
521 * Read a tar file and extract or list the specified files within it. 583 * Read a tar file and extract or list the specified files within it.
522 * If the list is empty than all files are extracted or listed. 584 * If the list is empty than all files are extracted or listed.
523 */ 585 */
524static int readTarFile(const char* tarName, int extractFlag, int listFlag, 586extern int readTarFile(int tarFd, int extractFlag, int listFlag,
525 int tostdoutFlag, int verboseFlag, char** extractList, 587 int tostdoutFlag, int verboseFlag, char** extractList,
526 char** excludeList) 588 char** excludeList)
527{ 589{
528 int status, tarFd=-1; 590 int status;
529 int errorFlag=FALSE; 591 int errorFlag=FALSE;
530 int skipNextHeaderFlag=FALSE; 592 int skipNextHeaderFlag=FALSE;
531 TarHeader rawHeader; 593 TarHeader rawHeader;
532 TarInfo header; 594 TarInfo header;
533 char** tmpList; 595 char** tmpList;
534 596
535 /* Open the tar file for reading. */
536 if (!strcmp(tarName, "-"))
537 tarFd = fileno(stdin);
538 else
539 tarFd = open(tarName, O_RDONLY);
540 if (tarFd < 0) {
541 error_msg( "Error opening '%s': %s\n", tarName, strerror(errno));
542 return ( FALSE);
543 }
544
545 /* Set the umask for this process so it doesn't 597 /* Set the umask for this process so it doesn't
546 * screw up permission setting for us later. */ 598 * screw up permission setting for us later. */
547 umask(0); 599 umask(0);
@@ -739,7 +791,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
739 close(tarFd); 791 close(tarFd);
740 if (status > 0) { 792 if (status > 0) {
741 /* Bummer - we read a partial header */ 793 /* Bummer - we read a partial header */
742 error_msg( "Error reading '%s': %s\n", tarName, strerror(errno)); 794 error_msg( "Error reading tar file: %s\n", strerror(errno));
743 return ( FALSE); 795 return ( FALSE);
744 } 796 }
745 else if (errorFlag==TRUE) { 797 else if (errorFlag==TRUE) {
diff --git a/gunzip.c b/gunzip.c
index 48db7cfd7..8558573ba 100644
--- a/gunzip.c
+++ b/gunzip.c
@@ -1084,7 +1084,7 @@ int inflate()
1084 * the compressed data, from offsets inptr to insize-1 included. 1084 * the compressed data, from offsets inptr to insize-1 included.
1085 * The magic header has already been checked. The output buffer is cleared. 1085 * The magic header has already been checked. The output buffer is cleared.
1086 */ 1086 */
1087int unzip(in, out) 1087extern int unzip(in, out)
1088int in, out; /* input and output file descriptors */ 1088int in, out; /* input and output file descriptors */
1089{ 1089{
1090 int ext_header = 0; /* set if extended local header */ 1090 int ext_header = 0; /* set if extended local header */
@@ -1179,7 +1179,7 @@ void clear_bufs(void)
1179/* =========================================================================== 1179/* ===========================================================================
1180 * Initialize gunzip buffers and signals 1180 * Initialize gunzip buffers and signals
1181 */ 1181 */
1182static int gunzip_init() 1182extern int gunzip_init()
1183{ 1183{
1184 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; 1184 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
1185 if (foreground) { 1185 if (foreground) {
diff --git a/tar.c b/tar.c
index cc7ba3b80..8c2650e2b 100644
--- a/tar.c
+++ b/tar.c
@@ -52,6 +52,11 @@
52#include <sys/sysmacros.h> 52#include <sys/sysmacros.h>
53#include <getopt.h> 53#include <getopt.h>
54 54
55#ifdef BB_FEATURE_TAR_GZIP
56extern int unzip(int in, int out);
57extern int gunzip_init();
58#endif
59
55/* Tar file constants */ 60/* Tar file constants */
56#ifndef MAJOR 61#ifndef MAJOR
57#define MAJOR(dev) (((dev)>>8)&0xff) 62#define MAJOR(dev) (((dev)>>8)&0xff)
@@ -129,29 +134,64 @@ struct TarInfo
129typedef struct TarInfo TarInfo; 134typedef struct TarInfo TarInfo;
130 135
131/* Local procedures to restore files from a tar file. */ 136/* Local procedures to restore files from a tar file. */
132static int readTarFile(const char* tarName, int extractFlag, int listFlag, 137static int readTarFile(int tarFd, int extractFlag, int listFlag,
133 int tostdoutFlag, int verboseFlag, char** extractList, 138 int tostdoutFlag, int verboseFlag, char** extractList,
134 char** excludeList); 139 char** excludeList);
135 140
136
137
138#ifdef BB_FEATURE_TAR_CREATE 141#ifdef BB_FEATURE_TAR_CREATE
139/* Local procedures to save files into a tar file. */ 142/* Local procedures to save files into a tar file. */
140static int writeTarFile(const char* tarName, int verboseFlag, char **argv, 143static int writeTarFile(const char* tarName, int verboseFlag, char **argv,
141 char** excludeList); 144 char** excludeList);
142#endif 145#endif
143 146
147#ifdef BB_FEATURE_TAR_GZIP
148/* Signal handler for when child gzip process dies... */
149void child_died()
150{
151 fflush(stdout);
152 fflush(stderr);
153 exit(EXIT_FAILURE);
154}
155
156static int tar_unzip_init(int tarFd)
157{
158 int child_pid;
159 static int unzip_pipe[2];
160 /* Cope if child dies... Otherwise we block forever in read()... */
161 signal(SIGCHLD, child_died);
162
163 if (pipe(unzip_pipe)!=0)
164 error_msg_and_die("pipe error\n");
165
166 if ( (child_pid = fork()) == -1)
167 error_msg_and_die("fork failure\n");
168
169 if (child_pid==0) {
170 /* child process */
171 gunzip_init();
172 unzip(tarFd, unzip_pipe[1]);
173 exit(EXIT_SUCCESS);
174 }
175 else
176 /* return fd of uncompressed data to parent process */
177 return(unzip_pipe[0]);
178}
179#endif
180
144extern int tar_main(int argc, char **argv) 181extern int tar_main(int argc, char **argv)
145{ 182{
146 char** excludeList=NULL; 183 char** excludeList=NULL;
147 char** extractList=NULL; 184 char** extractList=NULL;
185 const char *tarName="-";
148#if defined BB_FEATURE_TAR_EXCLUDE 186#if defined BB_FEATURE_TAR_EXCLUDE
149 int excludeListSize=0; 187 int excludeListSize=0;
150 char *excludeFileName ="-"; 188 char *excludeFileName ="-";
151 FILE *fileList; 189 FILE *fileList;
152 char file[256]; 190 char file[256];
191#endif
192#if defined BB_FEATURE_TAR_GZIP
193 int unzipFlag = FALSE;
153#endif 194#endif
154 const char *tarName="-";
155 int listFlag = FALSE; 195 int listFlag = FALSE;
156 int extractFlag = FALSE; 196 int extractFlag = FALSE;
157 int createFlag = FALSE; 197 int createFlag = FALSE;
@@ -160,7 +200,6 @@ extern int tar_main(int argc, char **argv)
160 int status = FALSE; 200 int status = FALSE;
161 int firstOpt = TRUE; 201 int firstOpt = TRUE;
162 int stopIt; 202 int stopIt;
163
164 203
165 if (argc <= 1) 204 if (argc <= 1)
166 usage(tar_usage); 205 usage(tar_usage);
@@ -185,6 +224,11 @@ extern int tar_main(int argc, char **argv)
185 goto flagError; 224 goto flagError;
186 listFlag = TRUE; 225 listFlag = TRUE;
187 break; 226 break;
227#ifdef BB_FEATURE_TAR_GZIP
228 case 'z':
229 unzipFlag = TRUE;
230 break;
231#endif
188 case 'v': 232 case 'v':
189 verboseFlag = TRUE; 233 verboseFlag = TRUE;
190 break; 234 break;
@@ -255,13 +299,31 @@ extern int tar_main(int argc, char **argv)
255#ifndef BB_FEATURE_TAR_CREATE 299#ifndef BB_FEATURE_TAR_CREATE
256 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n"); 300 error_msg_and_die( "This version of tar was not compiled with tar creation support.\n");
257#else 301#else
302#ifdef BB_FEATURE_TAR_GZIP
303 if (unzipFlag==TRUE)
304 error_msg_and_die("Creation of compressed not internally support by tar, pipe to busybox gunzip\n");
305#endif
258 status = writeTarFile(tarName, verboseFlag, argv, excludeList); 306 status = writeTarFile(tarName, verboseFlag, argv, excludeList);
259#endif 307#endif
260 } 308 }
261 if (listFlag == TRUE || extractFlag == TRUE) { 309 if (listFlag == TRUE || extractFlag == TRUE) {
310 int tarFd;
262 if (*argv) 311 if (*argv)
263 extractList = argv; 312 extractList = argv;
264 status = readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, 313 /* Open the tar file for reading. */
314 if (!strcmp(tarName, "-"))
315 tarFd = fileno(stdin);
316 else
317 tarFd = open(tarName, O_RDONLY);
318 if (tarFd < 0)
319 error_msg_and_die( "Error opening '%s': %s\n", tarName, strerror(errno));
320
321#ifdef BB_FEATURE_TAR_GZIP
322 /* unzip tarFd in a seperate process */
323 if (unzipFlag == TRUE)
324 tarFd = tar_unzip_init(tarFd);
325#endif
326 status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
265 verboseFlag, extractList, excludeList); 327 verboseFlag, extractList, excludeList);
266 } 328 }
267 329
@@ -521,27 +583,17 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
521 * Read a tar file and extract or list the specified files within it. 583 * Read a tar file and extract or list the specified files within it.
522 * If the list is empty than all files are extracted or listed. 584 * If the list is empty than all files are extracted or listed.
523 */ 585 */
524static int readTarFile(const char* tarName, int extractFlag, int listFlag, 586extern int readTarFile(int tarFd, int extractFlag, int listFlag,
525 int tostdoutFlag, int verboseFlag, char** extractList, 587 int tostdoutFlag, int verboseFlag, char** extractList,
526 char** excludeList) 588 char** excludeList)
527{ 589{
528 int status, tarFd=-1; 590 int status;
529 int errorFlag=FALSE; 591 int errorFlag=FALSE;
530 int skipNextHeaderFlag=FALSE; 592 int skipNextHeaderFlag=FALSE;
531 TarHeader rawHeader; 593 TarHeader rawHeader;
532 TarInfo header; 594 TarInfo header;
533 char** tmpList; 595 char** tmpList;
534 596
535 /* Open the tar file for reading. */
536 if (!strcmp(tarName, "-"))
537 tarFd = fileno(stdin);
538 else
539 tarFd = open(tarName, O_RDONLY);
540 if (tarFd < 0) {
541 error_msg( "Error opening '%s': %s\n", tarName, strerror(errno));
542 return ( FALSE);
543 }
544
545 /* Set the umask for this process so it doesn't 597 /* Set the umask for this process so it doesn't
546 * screw up permission setting for us later. */ 598 * screw up permission setting for us later. */
547 umask(0); 599 umask(0);
@@ -739,7 +791,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
739 close(tarFd); 791 close(tarFd);
740 if (status > 0) { 792 if (status > 0) {
741 /* Bummer - we read a partial header */ 793 /* Bummer - we read a partial header */
742 error_msg( "Error reading '%s': %s\n", tarName, strerror(errno)); 794 error_msg( "Error reading tar file: %s\n", strerror(errno));
743 return ( FALSE); 795 return ( FALSE);
744 } 796 }
745 else if (errorFlag==TRUE) { 797 else if (errorFlag==TRUE) {