diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-01-04 01:10:25 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-01-04 01:10:25 +0000 |
commit | 7dc160721ee3ceb76240a43d1454b45aaa9dbee4 (patch) | |
tree | 7532471be456e2c9f11eab88cb34f1e38abd184f /archival | |
parent | 9c88cac5cbfb2ff70f800ee5bb3289e925aaa65f (diff) | |
download | busybox-w32-7dc160721ee3ceb76240a43d1454b45aaa9dbee4.tar.gz busybox-w32-7dc160721ee3ceb76240a43d1454b45aaa9dbee4.tar.bz2 busybox-w32-7dc160721ee3ceb76240a43d1454b45aaa9dbee4.zip |
Bunches of fixes. Typos, bugs, etc.
Added 'gunzip -t'. inittab support _almost_ works (but it isn't
ready for prime time useage yet).
-Erik
Diffstat (limited to 'archival')
-rw-r--r-- | archival/gunzip.c | 32 | ||||
-rw-r--r-- | archival/tar.c | 121 |
2 files changed, 92 insertions, 61 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index 61391a33f..84f5d02b7 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -8,7 +8,8 @@ static const char gunzip_usage[] = | |||
8 | "gunzip [OPTION]... FILE\n\n" | 8 | "gunzip [OPTION]... FILE\n\n" |
9 | "Uncompress FILE (or standard input if FILE is '-').\n\n" | 9 | "Uncompress FILE (or standard input if FILE is '-').\n\n" |
10 | "Options:\n" | 10 | "Options:\n" |
11 | "\t-c\tWrite output to standard output\n"; | 11 | "\t-c\tWrite output to standard output\n" |
12 | "\t-t\tTest compressed file integrity\n"; | ||
12 | 13 | ||
13 | /* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface | 14 | /* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface |
14 | * Copyright (C) 1992-1993 Jean-loup Gailly | 15 | * Copyright (C) 1992-1993 Jean-loup Gailly |
@@ -653,7 +654,7 @@ DECLARE(uch, window, 2L*WSIZE); | |||
653 | 654 | ||
654 | /* local variables */ | 655 | /* local variables */ |
655 | 656 | ||
656 | int force = 0; /* don't ask questions, compress links (-f) */ | 657 | int test_mode = 0; /* check file integrity option */ |
657 | int foreground; /* set if program run in foreground */ | 658 | int foreground; /* set if program run in foreground */ |
658 | int maxbits = BITS; /* max bits per code for LZW */ | 659 | int maxbits = BITS; /* max bits per code for LZW */ |
659 | int method = DEFLATED;/* compression method */ | 660 | int method = DEFLATED;/* compression method */ |
@@ -714,6 +715,10 @@ int gunzip_main (int argc, char** argv) | |||
714 | case 'c': | 715 | case 'c': |
715 | to_stdout = 1; | 716 | to_stdout = 1; |
716 | break; | 717 | break; |
718 | case 't': | ||
719 | test_mode = 1; | ||
720 | break; | ||
721 | |||
717 | default: | 722 | default: |
718 | usage(gunzip_usage); | 723 | usage(gunzip_usage); |
719 | } | 724 | } |
@@ -786,6 +791,9 @@ int gunzip_main (int argc, char** argv) | |||
786 | /* Actually do the compression/decompression. */ | 791 | /* Actually do the compression/decompression. */ |
787 | unzip(inFileNum, outFileNum); | 792 | unzip(inFileNum, outFileNum); |
788 | 793 | ||
794 | } else if (test_mode) { | ||
795 | /* Actually do the compression/decompression. */ | ||
796 | unzip(inFileNum, 2); | ||
789 | } else { | 797 | } else { |
790 | char* pos; | 798 | char* pos; |
791 | 799 | ||
@@ -857,17 +865,8 @@ local int get_method(in) | |||
857 | uch flags; /* compression flags */ | 865 | uch flags; /* compression flags */ |
858 | char magic[2]; /* magic header */ | 866 | char magic[2]; /* magic header */ |
859 | 867 | ||
860 | /* If --force and --stdout, zcat == cat, so do not complain about | 868 | magic[0] = (char)get_byte(); |
861 | * premature end of file: use try_byte instead of get_byte. | 869 | magic[1] = (char)get_byte(); |
862 | */ | ||
863 | if (force) { | ||
864 | magic[0] = (char)try_byte(); | ||
865 | magic[1] = (char)try_byte(); | ||
866 | /* If try_byte returned EOF, magic[1] == 0xff */ | ||
867 | } else { | ||
868 | magic[0] = (char)get_byte(); | ||
869 | magic[1] = (char)get_byte(); | ||
870 | } | ||
871 | method = -1; /* unknown yet */ | 870 | method = -1; /* unknown yet */ |
872 | part_nb++; /* number of parts in gzip file */ | 871 | part_nb++; /* number of parts in gzip file */ |
873 | header_bytes = 0; | 872 | header_bytes = 0; |
@@ -1188,7 +1187,8 @@ void flush_outbuf() | |||
1188 | { | 1187 | { |
1189 | if (outcnt == 0) return; | 1188 | if (outcnt == 0) return; |
1190 | 1189 | ||
1191 | write_buf(ofd, (char *)outbuf, outcnt); | 1190 | if (!test_mode) |
1191 | write_buf(ofd, (char *)outbuf, outcnt); | ||
1192 | bytes_out += (ulg)outcnt; | 1192 | bytes_out += (ulg)outcnt; |
1193 | outcnt = 0; | 1193 | outcnt = 0; |
1194 | } | 1194 | } |
@@ -1202,8 +1202,8 @@ void flush_window() | |||
1202 | if (outcnt == 0) return; | 1202 | if (outcnt == 0) return; |
1203 | updcrc(window, outcnt); | 1203 | updcrc(window, outcnt); |
1204 | 1204 | ||
1205 | write_buf(ofd, (char *)window, outcnt); | 1205 | if (!test_mode) |
1206 | 1206 | write_buf(ofd, (char *)window, outcnt); | |
1207 | bytes_out += (ulg)outcnt; | 1207 | bytes_out += (ulg)outcnt; |
1208 | outcnt = 0; | 1208 | outcnt = 0; |
1209 | } | 1209 | } |
diff --git a/archival/tar.c b/archival/tar.c index 7167d95cd..a53370e85 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <fcntl.h> | 37 | #include <fcntl.h> |
38 | #include <signal.h> | 38 | #include <signal.h> |
39 | #include <time.h> | 39 | #include <time.h> |
40 | #include <utime.h> | ||
40 | #include <sys/types.h> | 41 | #include <sys/types.h> |
41 | #include <sys/sysmacros.h> | 42 | #include <sys/sysmacros.h> |
42 | 43 | ||
@@ -106,8 +107,12 @@ static int warnedRoot; | |||
106 | static int eofFlag; | 107 | static int eofFlag; |
107 | static long dataCc; | 108 | static long dataCc; |
108 | static int outFd; | 109 | static int outFd; |
109 | static char outName[TAR_NAME_SIZE]; | 110 | static const char *outName; |
110 | 111 | ||
112 | static int mode; | ||
113 | static int uid; | ||
114 | static int gid; | ||
115 | static time_t mtime; | ||
111 | 116 | ||
112 | /* | 117 | /* |
113 | * Static data associated with the tar file. | 118 | * Static data associated with the tar file. |
@@ -364,8 +369,9 @@ static void readTarFile (int fileCount, char **fileTable) | |||
364 | * message is required on errors. | 369 | * message is required on errors. |
365 | */ | 370 | */ |
366 | if (tostdoutFlag == FALSE) { | 371 | if (tostdoutFlag == FALSE) { |
367 | if (outFd >= 0) | 372 | if (outFd >= 0) { |
368 | (void) close (outFd); | 373 | close (outFd); |
374 | } | ||
369 | } | 375 | } |
370 | } | 376 | } |
371 | 377 | ||
@@ -378,29 +384,25 @@ static void readTarFile (int fileCount, char **fileTable) | |||
378 | static void | 384 | static void |
379 | readHeader (const TarHeader * hp, int fileCount, char **fileTable) | 385 | readHeader (const TarHeader * hp, int fileCount, char **fileTable) |
380 | { | 386 | { |
381 | int mode; | ||
382 | int uid; | ||
383 | int gid; | ||
384 | int checkSum; | 387 | int checkSum; |
385 | unsigned int major; | ||
386 | unsigned int minor; | ||
387 | long size; | ||
388 | time_t mtime; | ||
389 | const char *name; | ||
390 | int cc; | 388 | int cc; |
391 | int hardLink; | 389 | int hardLink; |
392 | int softLink; | 390 | int softLink; |
393 | int devFileFlag; | 391 | int devFileFlag; |
392 | unsigned int major; | ||
393 | unsigned int minor; | ||
394 | long size; | ||
395 | struct utimbuf utb; | ||
394 | 396 | ||
395 | /* | 397 | /* |
396 | * If the block is completely empty, then this is the end of the | 398 | * If the block is completely empty, then this is the end of the |
397 | * archive file. If the name is null, then just skip this header. | 399 | * archive file. If the name is null, then just skip this header. |
398 | */ | 400 | */ |
399 | name = hp->name; | 401 | outName = hp->name; |
400 | 402 | ||
401 | if (*name == '\0') { | 403 | if (*outName == '\0') { |
402 | for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) { | 404 | for (cc = TAR_BLOCK_SIZE; cc > 0; cc--) { |
403 | if (*name++) | 405 | if (*outName++) |
404 | return; | 406 | return; |
405 | } | 407 | } |
406 | 408 | ||
@@ -447,16 +449,16 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
447 | /* | 449 | /* |
448 | * Check for a directory. | 450 | * Check for a directory. |
449 | */ | 451 | */ |
450 | if (name[strlen (name) - 1] == '/') | 452 | if (outName[strlen (outName) - 1] == '/') |
451 | mode |= S_IFDIR; | 453 | mode |= S_IFDIR; |
452 | 454 | ||
453 | /* | 455 | /* |
454 | * Check for absolute paths in the file. | 456 | * Check for absolute paths in the file. |
455 | * If we find any, then warn the user and make them relative. | 457 | * If we find any, then warn the user and make them relative. |
456 | */ | 458 | */ |
457 | if (*name == '/') { | 459 | if (*outName == '/') { |
458 | while (*name == '/') | 460 | while (*outName == '/') |
459 | name++; | 461 | outName++; |
460 | 462 | ||
461 | if (warnedRoot==FALSE) { | 463 | if (warnedRoot==FALSE) { |
462 | fprintf (stderr, | 464 | fprintf (stderr, |
@@ -470,7 +472,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
470 | * See if we want this file to be restored. | 472 | * See if we want this file to be restored. |
471 | * If not, then set up to skip it. | 473 | * If not, then set up to skip it. |
472 | */ | 474 | */ |
473 | if (wantFileName (name, fileCount, fileTable) == FALSE) { | 475 | if (wantFileName (outName, fileCount, fileTable) == FALSE) { |
474 | if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode) | 476 | if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode) |
475 | || S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) { | 477 | || S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) { |
476 | inHeader = (size == 0)? TRUE : FALSE; | 478 | inHeader = (size == 0)? TRUE : FALSE; |
@@ -494,7 +496,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
494 | else | 496 | else |
495 | printf ("%9ld %s ", size, timeString (mtime)); | 497 | printf ("%9ld %s ", size, timeString (mtime)); |
496 | } | 498 | } |
497 | printf ("%s", name); | 499 | printf ("%s", outName); |
498 | 500 | ||
499 | if (hardLink) | 501 | if (hardLink) |
500 | printf (" (link to \"%s\")", hp->linkName); | 502 | printf (" (link to \"%s\")", hp->linkName); |
@@ -515,22 +517,35 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
515 | * We really want to extract the file. | 517 | * We really want to extract the file. |
516 | */ | 518 | */ |
517 | if (verboseFlag==TRUE) | 519 | if (verboseFlag==TRUE) |
518 | printf ("x %s\n", name); | 520 | printf ("x %s\n", outName); |
519 | 521 | ||
520 | if (hardLink) { | 522 | if (hardLink) { |
521 | if (link (hp->linkName, name) < 0) | 523 | if (link (hp->linkName, outName) < 0) |
522 | perror (name); | 524 | perror (outName); |
523 | chown(name, uid, gid); | 525 | /* Set the file time */ |
524 | chmod(name, mode); | 526 | utb.actime = mtime; |
527 | utb.modtime = mtime; | ||
528 | utime (outName, &utb); | ||
529 | /* Set the file permissions */ | ||
530 | chown(outName, uid, gid); | ||
531 | chmod(outName, mode); | ||
525 | return; | 532 | return; |
526 | } | 533 | } |
527 | 534 | ||
528 | if (softLink) { | 535 | if (softLink) { |
529 | #ifdef S_ISLNK | 536 | #ifdef S_ISLNK |
530 | if (symlink (hp->linkName, name) < 0) | 537 | if (symlink (hp->linkName, outName) < 0) |
531 | perror (name); | 538 | perror (outName); |
532 | chown(name, uid, gid); | 539 | /* Try to change ownership of the symlink. |
533 | chmod(name, mode); | 540 | * If libs doesn't support that, don't bother. |
541 | * Changing the pointed-to file is the Wrong Thing(tm). | ||
542 | */ | ||
543 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | ||
544 | lchown(outName, uid, gid); | ||
545 | #endif | ||
546 | |||
547 | /* Do not change permissions or date on symlink, | ||
548 | * since it changes the pointed to file instead. duh. */ | ||
534 | #else | 549 | #else |
535 | fprintf (stderr, "Cannot create symbolic links\n"); | 550 | fprintf (stderr, "Cannot create symbolic links\n"); |
536 | #endif | 551 | #endif |
@@ -545,10 +560,14 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
545 | * If the file is a directory, then just create the path. | 560 | * If the file is a directory, then just create the path. |
546 | */ | 561 | */ |
547 | if (S_ISDIR (mode)) { | 562 | if (S_ISDIR (mode)) { |
548 | createPath (name, mode); | 563 | createPath (outName, mode); |
549 | chown(name, uid, gid); | 564 | /* Set the file time */ |
550 | chmod(name, mode); | 565 | utb.actime = mtime; |
551 | 566 | utb.modtime = mtime; | |
567 | utime (outName, &utb); | ||
568 | /* Set the file permissions */ | ||
569 | chown(outName, uid, gid); | ||
570 | chmod(outName, mode); | ||
552 | return; | 571 | return; |
553 | } | 572 | } |
554 | 573 | ||
@@ -556,7 +575,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
556 | * There is a file to write. | 575 | * There is a file to write. |
557 | * First create the path to it if necessary with default permissions. | 576 | * First create the path to it if necessary with default permissions. |
558 | */ | 577 | */ |
559 | createPath (name, 0777); | 578 | createPath (outName, 0777); |
560 | 579 | ||
561 | inHeader = (size == 0)? TRUE : FALSE; | 580 | inHeader = (size == 0)? TRUE : FALSE; |
562 | dataCc = size; | 581 | dataCc = size; |
@@ -569,21 +588,26 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
569 | else { | 588 | else { |
570 | if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) { | 589 | if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) { |
571 | devFileFlag = TRUE; | 590 | devFileFlag = TRUE; |
572 | outFd = mknod (name, mode, makedev(major, minor) ); | 591 | outFd = mknod (outName, mode, makedev(major, minor) ); |
573 | } | 592 | } |
574 | else if (S_ISFIFO(mode) ) { | 593 | else if (S_ISFIFO(mode) ) { |
575 | devFileFlag = TRUE; | 594 | devFileFlag = TRUE; |
576 | outFd = mkfifo(name, mode); | 595 | outFd = mkfifo(outName, mode); |
577 | } else { | 596 | } else { |
578 | outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode); | 597 | outFd = open (outName, O_WRONLY | O_CREAT | O_TRUNC, mode); |
579 | } | 598 | } |
580 | if (outFd < 0) { | 599 | if (outFd < 0) { |
581 | perror (name); | 600 | perror (outName); |
582 | skipFileFlag = TRUE; | 601 | skipFileFlag = TRUE; |
583 | return; | 602 | return; |
584 | } | 603 | } |
585 | chown(name, uid, gid); | 604 | /* Set the file time */ |
586 | chmod(name, mode); | 605 | utb.actime = mtime; |
606 | utb.modtime = mtime; | ||
607 | utime (outName, &utb); | ||
608 | /* Set the file permissions */ | ||
609 | chown(outName, uid, gid); | ||
610 | chmod(outName, mode); | ||
587 | } | 611 | } |
588 | 612 | ||
589 | 613 | ||
@@ -591,7 +615,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
591 | * If the file is empty, then that's all we need to do. | 615 | * If the file is empty, then that's all we need to do. |
592 | */ | 616 | */ |
593 | if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) { | 617 | if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) { |
594 | (void) close (outFd); | 618 | close (outFd); |
595 | outFd = -1; | 619 | outFd = -1; |
596 | } | 620 | } |
597 | } | 621 | } |
@@ -625,7 +649,7 @@ static void readData (const char *cp, int count) | |||
625 | if (fullWrite (outFd, cp, count) < 0) { | 649 | if (fullWrite (outFd, cp, count) < 0) { |
626 | perror (outName); | 650 | perror (outName); |
627 | if (tostdoutFlag == FALSE) { | 651 | if (tostdoutFlag == FALSE) { |
628 | (void) close (outFd); | 652 | close (outFd); |
629 | outFd = -1; | 653 | outFd = -1; |
630 | } | 654 | } |
631 | skipFileFlag = TRUE; | 655 | skipFileFlag = TRUE; |
@@ -633,13 +657,21 @@ static void readData (const char *cp, int count) | |||
633 | } | 657 | } |
634 | 658 | ||
635 | /* | 659 | /* |
636 | * If the write failed, close the file and disable further | 660 | * Check if we are done writing to the file now. |
637 | * writes to this file. | ||
638 | */ | 661 | */ |
639 | if (dataCc <= 0 && tostdoutFlag == FALSE) { | 662 | if (dataCc <= 0 && tostdoutFlag == FALSE) { |
663 | struct utimbuf utb; | ||
640 | if (close (outFd)) | 664 | if (close (outFd)) |
641 | perror (outName); | 665 | perror (outName); |
642 | 666 | ||
667 | /* Set the file time */ | ||
668 | utb.actime = mtime; | ||
669 | utb.modtime = mtime; | ||
670 | utime (outName, &utb); | ||
671 | /* Set the file permissions */ | ||
672 | chown(outName, uid, gid); | ||
673 | chmod(outName, mode); | ||
674 | |||
643 | outFd = -1; | 675 | outFd = -1; |
644 | } | 676 | } |
645 | } | 677 | } |
@@ -720,7 +752,6 @@ static void writeTarFile (int fileCount, char **fileTable) | |||
720 | static void saveFile (const char *fileName, int seeLinks) | 752 | static void saveFile (const char *fileName, int seeLinks) |
721 | { | 753 | { |
722 | int status; | 754 | int status; |
723 | int mode; | ||
724 | struct stat statbuf; | 755 | struct stat statbuf; |
725 | 756 | ||
726 | if (verboseFlag==TRUE) | 757 | if (verboseFlag==TRUE) |