aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/gzip.c98
-rw-r--r--archival/tar.c41
2 files changed, 96 insertions, 43 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index 500d6d7e0..8f2c1c454 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -12,10 +12,11 @@
12//#endif 12//#endif
13 13
14static const char gzip_usage[] = 14static const char gzip_usage[] =
15 "gzip [OPTION]... [FILE]...\n\n" 15 "gzip [OPTION]... FILE\n\n"
16 "Compress FILEs with maximum compression.\n\n" 16 "Compress FILE with maximum compression.\n"
17 "When FILE is -, reads standard input. Implies -c.\n\n"
17 "Options:\n" 18 "Options:\n"
18 "\t-c\tWrite output on standard output\n"; 19 "\t-c\tWrite output to standard output instead of FILE.gz\n";
19 20
20 21
21/* gzip.h -- common declarations for all gzip modules 22/* gzip.h -- common declarations for all gzip modules
@@ -1731,7 +1732,6 @@ DECLARE(uch, window, 2L*WSIZE);
1731 1732
1732int ascii = 0; /* convert end-of-lines to local OS conventions */ 1733int ascii = 0; /* convert end-of-lines to local OS conventions */
1733int decompress = 0; /* decompress (-d) */ 1734int decompress = 0; /* decompress (-d) */
1734int tostdout = 0; /* uncompress to stdout (-c) */
1735int no_name = -1; /* don't save or restore the original file name */ 1735int no_name = -1; /* don't save or restore the original file name */
1736int no_time = -1; /* don't save or restore the original file time */ 1736int no_time = -1; /* don't save or restore the original file time */
1737int foreground; /* set if program run in foreground */ 1737int foreground; /* set if program run in foreground */
@@ -1770,13 +1770,25 @@ unsigned outcnt; /* bytes in output buffer */
1770// char **argv; 1770// char **argv;
1771int gzip_main(int argc, char ** argv) 1771int gzip_main(int argc, char ** argv)
1772{ 1772{
1773 1773 int result;
1774 int inFileNum; 1774 int inFileNum;
1775 int outFileNum; 1775 int outFileNum;
1776 struct stat statBuf;
1777 char* delFileName;
1778 int tostdout = 0;
1779 int fromstdin = 0;
1780
1781 if (argc==1)
1782 usage(gzip_usage);
1776 1783
1777 /* Parse any options */ 1784 /* Parse any options */
1778 while (--argc > 0 && **(++argv) == '-') { 1785 while (--argc > 0 && **(++argv) == '-') {
1786 if (*((*argv)+1) == '\0') {
1787 fromstdin = 1;
1788 tostdout = 1;
1789 }
1779 while (*(++(*argv))) { 1790 while (*(++(*argv))) {
1791 fprintf(stderr, "**argv='%c'\n", **argv);
1780 switch (**argv) { 1792 switch (**argv) {
1781 case 'c': 1793 case 'c':
1782 tostdout = 1; 1794 tostdout = 1;
@@ -1817,64 +1829,81 @@ int gzip_main(int argc, char ** argv)
1817 ALLOC(ush, tab_prefix1, 1L<<(BITS-1)); 1829 ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
1818#endif 1830#endif
1819 1831
1820 if (tostdout==1) { 1832 if (fromstdin==1) {
1821 /* And get to work */ 1833 strcpy(ofname, "stdin");
1822 SET_BINARY_MODE(fileno(stdout));
1823 strcpy(ifname, "stdin");
1824 strcpy(ofname, "stdout");
1825 inFileNum=fileno(stdin);
1826 outFileNum=fileno(stdout);
1827 1834
1828 /* Get the time stamp on the input file. */ 1835 inFileNum=fileno(stdin);
1829 time_stamp = 0; /* time unknown by default */ 1836 time_stamp = 0; /* time unknown by default */
1830
1831 ifile_size = -1L; /* convention for unknown size */ 1837 ifile_size = -1L; /* convention for unknown size */
1832
1833 clear_bufs(); /* clear input and output buffers */
1834 part_nb = 0;
1835
1836 /* Actually do the compression/decompression. */
1837 zip(inFileNum, outFileNum);
1838
1839 } else { 1838 } else {
1840 int result; 1839 /* Open up the input file */
1841 struct stat statBuf;
1842
1843 /* And get to work */
1844 if (*argv=='\0') 1840 if (*argv=='\0')
1845 usage(gzip_usage); 1841 usage(gzip_usage);
1846 strncpy(ifname, *argv, MAX_PATH_LEN); 1842 strncpy(ifname, *argv, MAX_PATH_LEN);
1847 strncpy(ofname, *argv, MAX_PATH_LEN-4);
1848 strcat(ofname, ".gz");
1849 1843
1844 /* Open input fille */
1850 inFileNum=open( ifname, O_RDONLY); 1845 inFileNum=open( ifname, O_RDONLY);
1851 if (inFileNum < 0) { 1846 if (inFileNum < 0) {
1852 perror(ifname); 1847 perror(ifname);
1853 do_exit(WARNING); 1848 do_exit(WARNING);
1854 } 1849 }
1850 /* Get the time stamp on the input file. */
1855 result = stat(ifname, &statBuf); 1851 result = stat(ifname, &statBuf);
1856 if (result < 0) { 1852 if (result < 0) {
1857 perror(ifname); 1853 perror(ifname);
1858 do_exit(WARNING); 1854 do_exit(WARNING);
1859 } 1855 }
1856 time_stamp = statBuf.st_ctime;
1857 ifile_size = statBuf.st_size;
1858 }
1859
1860 1860
1861 outFileNum=open( ofname, O_RDONLY); 1861 if (tostdout==1) {
1862 /* And get to work */
1863 strcpy(ofname, "stdout");
1864 outFileNum=fileno(stdout);
1865 SET_BINARY_MODE(fileno(stdout));
1866
1867 clear_bufs(); /* clear input and output buffers */
1868 part_nb = 0;
1869
1870 /* Actually do the compression/decompression. */
1871 zip(inFileNum, outFileNum);
1872
1873 } else {
1874
1875 /* And get to work */
1876 strncpy(ofname, ifname, MAX_PATH_LEN-4);
1877 strcat(ofname, ".gz");
1878
1879
1880 /* Open output fille */
1881 outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
1862 if (outFileNum < 0) { 1882 if (outFileNum < 0) {
1863 perror(ofname); 1883 perror(ofname);
1864 do_exit(WARNING); 1884 do_exit(WARNING);
1865 } 1885 }
1866 SET_BINARY_MODE(outFileNum); 1886 SET_BINARY_MODE(outFileNum);
1867 1887 /* Set permissions on the file */
1868 /* Get the time stamp on the input file. */ 1888 fchmod(outFileNum, statBuf.st_mode);
1869 time_stamp = statBuf.st_ctime; /* time unknown by default */
1870
1871 ifile_size = statBuf.st_size; /* convention for unknown size */
1872 1889
1873 clear_bufs(); /* clear input and output buffers */ 1890 clear_bufs(); /* clear input and output buffers */
1874 part_nb = 0; 1891 part_nb = 0;
1875 1892
1876 /* Actually do the compression/decompression. */ 1893 /* Actually do the compression/decompression. */
1877 zip(inFileNum, outFileNum); 1894 result=zip(inFileNum, outFileNum);
1895 close( outFileNum);
1896 close( inFileNum);
1897 /* Delete the original file */
1898 if (result == OK)
1899 delFileName=ifname;
1900 else
1901 delFileName=ofname;
1902
1903 if (unlink (delFileName) < 0) {
1904 perror (delFileName);
1905 exit( FALSE);
1906 }
1878 } 1907 }
1879 1908
1880 do_exit(exit_code); 1909 do_exit(exit_code);
@@ -3198,6 +3227,7 @@ int zip(in, out)
3198 3227
3199 /* Write the header to the gzip file. See algorithm.doc for the format */ 3228 /* Write the header to the gzip file. See algorithm.doc for the format */
3200 3229
3230
3201 method = DEFLATED; 3231 method = DEFLATED;
3202 put_byte(GZIP_MAGIC[0]); /* magic header */ 3232 put_byte(GZIP_MAGIC[0]); /* magic header */
3203 put_byte(GZIP_MAGIC[1]); 3233 put_byte(GZIP_MAGIC[1]);
diff --git a/archival/tar.c b/archival/tar.c
index ed6f3b6b5..5478af86e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -10,6 +10,9 @@
10 * Modified for busybox by Erik Andersen <andersee@debian.org> 10 * Modified for busybox by Erik Andersen <andersee@debian.org>
11 * Adjusted to grok stdin/stdout options. 11 * Adjusted to grok stdin/stdout options.
12 * 12 *
13 * Modified to handle device special files by Matt Porter
14 * <porter@debian.org>
15 *
13 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or 18 * the Free Software Foundation; either version 2 of the License, or
@@ -34,6 +37,7 @@
34#include <fcntl.h> 37#include <fcntl.h>
35#include <signal.h> 38#include <signal.h>
36#include <time.h> 39#include <time.h>
40#include <sys/types.h>
37 41
38 42
39static const char tar_usage[] = 43static const char tar_usage[] =
@@ -377,12 +381,15 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
377 int uid; 381 int uid;
378 int gid; 382 int gid;
379 int checkSum; 383 int checkSum;
384 int major;
385 int minor;
380 long size; 386 long size;
381 time_t mtime; 387 time_t mtime;
382 const char *name; 388 const char *name;
383 int cc; 389 int cc;
384 int hardLink; 390 int hardLink;
385 int softLink; 391 int softLink;
392 int devFileFlag;
386 393
387 /* 394 /*
388 * If the block is completely empty, then this is the end of the 395 * If the block is completely empty, then this is the end of the
@@ -411,6 +418,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
411 size = getOctal (hp->size, sizeof (hp->size)); 418 size = getOctal (hp->size, sizeof (hp->size));
412 mtime = getOctal (hp->mtime, sizeof (hp->mtime)); 419 mtime = getOctal (hp->mtime, sizeof (hp->mtime));
413 checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum)); 420 checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
421 major = getOctal (hp->devMajor, sizeof (hp->devMajor));
422 minor = getOctal (hp->devMinor, sizeof (hp->devMinor));
414 423
415 if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) { 424 if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
416 if (badHeader==FALSE) 425 if (badHeader==FALSE)
@@ -423,6 +432,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
423 432
424 badHeader = FALSE; 433 badHeader = FALSE;
425 skipFileFlag = FALSE; 434 skipFileFlag = FALSE;
435 devFileFlag = FALSE;
426 436
427 /* 437 /*
428 * Check for the file modes. 438 * Check for the file modes.
@@ -434,12 +444,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
434 (hp->typeFlag == TAR_TYPE_SOFT_LINK - '0')); 444 (hp->typeFlag == TAR_TYPE_SOFT_LINK - '0'));
435 445
436 /* 446 /*
437 * Check for a directory or a regular file. 447 * Check for a directory.
438 */ 448 */
439 if (name[strlen (name) - 1] == '/') 449 if (name[strlen (name) - 1] == '/')
440 mode |= S_IFDIR; 450 mode |= S_IFDIR;
441 else if ((mode & S_IFMT) == 0)
442 mode |= S_IFREG;
443 451
444 /* 452 /*
445 * Check for absolute paths in the file. 453 * Check for absolute paths in the file.
@@ -462,7 +470,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
462 * If not, then set up to skip it. 470 * If not, then set up to skip it.
463 */ 471 */
464 if (wantFileName (name, fileCount, fileTable) == FALSE) { 472 if (wantFileName (name, fileCount, fileTable) == FALSE) {
465 if (!hardLink && !softLink && S_ISREG (mode)) { 473 if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
474 || S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
466 inHeader = (size == 0)? TRUE : FALSE; 475 inHeader = (size == 0)? TRUE : FALSE;
467 dataCc = size; 476 dataCc = size;
468 } 477 }
@@ -487,7 +496,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
487 printf (" (link to \"%s\")", hp->linkName); 496 printf (" (link to \"%s\")", hp->linkName);
488 else if (softLink) 497 else if (softLink)
489 printf (" (symlink to \"%s\")", hp->linkName); 498 printf (" (symlink to \"%s\")", hp->linkName);
490 else if (S_ISREG (mode)) { 499 else if (S_ISREG (mode) || S_ISCHR (mode) || S_ISBLK (mode) ||
500 S_ISSOCK(mode) || S_ISFIFO(mode) ) {
491 inHeader = (size == 0)? TRUE : FALSE; 501 inHeader = (size == 0)? TRUE : FALSE;
492 dataCc = size; 502 dataCc = size;
493 } 503 }
@@ -543,8 +553,17 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
543 */ 553 */
544 if (tostdoutFlag == TRUE) 554 if (tostdoutFlag == TRUE)
545 outFd = STDOUT; 555 outFd = STDOUT;
546 else 556 else {
547 outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode); 557 if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
558 devFileFlag = TRUE;
559 outFd = mknod (name, mode, makedev(major, minor) );
560 }
561 else if (S_ISFIFO(mode) ) {
562 outFd = mkfifo(name, mode);
563 } else {
564 outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
565 }
566 }
548 567
549 if (outFd < 0) { 568 if (outFd < 0) {
550 perror (name); 569 perror (name);
@@ -555,7 +574,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
555 /* 574 /*
556 * If the file is empty, then that's all we need to do. 575 * If the file is empty, then that's all we need to do.
557 */ 576 */
558 if (size == 0 && tostdoutFlag == FALSE) { 577 if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
559 (void) close (outFd); 578 (void) close (outFd);
560 outFd = -1; 579 outFd = -1;
561 } 580 }
@@ -735,12 +754,16 @@ static void saveFile (const char *fileName, int seeLinks)
735 754
736 return; 755 return;
737 } 756 }
738
739 if (S_ISREG (mode)) { 757 if (S_ISREG (mode)) {
740 saveRegularFile (fileName, &statbuf); 758 saveRegularFile (fileName, &statbuf);
741 759
742 return; 760 return;
743 } 761 }
762
763 /* Some day add support for tarring these up... but not today. :) */
764// if (S_ISLNK(mode) || S_ISFIFO(mode) || S_ISBLK(mode) || S_ISCHR (mode) ) {
765// fprintf (stderr, "%s: This version of tar can't store this type of file\n", fileName);
766// }
744 767
745 /* 768 /*
746 * The file is a strange type of file, ignore it. 769 * The file is a strange type of file, ignore it.