diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-03-26 14:03:20 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-03-26 14:03:20 +0000 |
| commit | 6acaa40f27de0da935c3063b6be2ead9eeee5d0b (patch) | |
| tree | 36a5fe3513df3e022abdfac248c03dff6570153c | |
| parent | deea048becd9d2d013537755ffad9bb615efeadc (diff) | |
| download | busybox-w32-6acaa40f27de0da935c3063b6be2ead9eeee5d0b.tar.gz busybox-w32-6acaa40f27de0da935c3063b6be2ead9eeee5d0b.tar.bz2 busybox-w32-6acaa40f27de0da935c3063b6be2ead9eeee5d0b.zip | |
First stages of (re-)writing busybox's tar creation support.
-Erik
| -rw-r--r-- | Changelog | 10 | ||||
| -rw-r--r-- | archival/tar.c | 125 | ||||
| -rw-r--r-- | busybox.def.h | 2 | ||||
| -rw-r--r-- | lash.c | 2 | ||||
| -rw-r--r-- | sh.c | 2 | ||||
| -rw-r--r-- | shell/lash.c | 2 | ||||
| -rw-r--r-- | tar.c | 125 |
7 files changed, 225 insertions, 43 deletions
| @@ -507,11 +507,11 @@ | |||
| 507 | * from Matthew Grant <grantma@anathoth.gen.nz> | 507 | * from Matthew Grant <grantma@anathoth.gen.nz> |
| 508 | to accomodate glibc timezone support. I then ripped out GNU | 508 | to accomodate glibc timezone support. I then ripped out GNU |
| 509 | getopt. | 509 | getopt. |
| 510 | * mkswap -- new version merged from util-linux. Can now make | 510 | * mkswap -- new version merged from util-linux. Can now make |
| 511 | * >128Meg swaps. Replaced the old and star, unstar, and tarcat | 511 | >128Meg swaps. |
| 512 | * with the tar | 512 | * Replaced the old and star, unstar, and tarcat with the tar |
| 513 | implementation from sash. Now tar behaves as god intended it | 513 | implementation from sash. Now tar behaves as god intended it |
| 514 | to (i.e. tar -xvf <file> and tar -cf <file> <dir> work). | 514 | to (i.e. tar -xvf <file> and tar -cf <file> <dir> work). |
| 515 | * dd -- rewritten. Can with with files, stdin, stdout. Added the | 515 | * dd -- rewritten. Can with with files, stdin, stdout. Added the |
| 516 | * following new apps: loadfont -- added from debian boot floppies | 516 | * following new apps: loadfont -- added from debian boot floppies |
| 517 | * chroot -- added based on a patch from Paolo Molaro | 517 | * chroot -- added based on a patch from Paolo Molaro |
diff --git a/archival/tar.c b/archival/tar.c index 477487a50..37a28a3d0 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
| @@ -1,10 +1,24 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * Mini tar implementation for busybox | 3 | * |
| 4 | * Mini tar implementation for busybox Note, that as of BusyBox 0.43 tar has | ||
| 5 | * been completely rewritten from the ground up. It still has remnents of the | ||
| 6 | * old code lying about, but it pretty different (i.e. cleaner, less global | ||
| 7 | * variables, etc) | ||
| 4 | * | 8 | * |
| 5 | * Copyright (C) 1999 by Lineo, inc. | 9 | * Copyright (C) 1999 by Lineo, inc. |
| 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | 10 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| 7 | * | 11 | * |
| 12 | * Based in part in the tar implementation in sash | ||
| 13 | * Copyright (c) 1999 by David I. Bell | ||
| 14 | * Permission is granted to use, distribute, or modify this source, | ||
| 15 | * provided that this copyright notice remains intact. | ||
| 16 | * Permission to distribute sash derived code under the GPL has been granted. | ||
| 17 | * | ||
| 18 | * Based in part on the tar implementation in busybox-0.28 | ||
| 19 | * Copyright (C) 1995 Bruce Perens | ||
| 20 | * This is free software under the GNU General Public License. | ||
| 21 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | 22 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | 23 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or | 24 | * the Free Software Foundation; either version 2 of the License, or |
| @@ -147,17 +161,9 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
| 147 | 161 | ||
| 148 | 162 | ||
| 149 | #ifdef BB_FEATURE_TAR_CREATE | 163 | #ifdef BB_FEATURE_TAR_CREATE |
| 150 | /* | 164 | /* Local procedures to save files into a tar file. */ |
| 151 | * Local procedures to save files into a tar file. | 165 | static int writeTarFile(const char* tarName, int extractFlag, int listFlag, |
| 152 | */ | 166 | int tostdoutFlag, int verboseFlag, int argc, char **argv); |
| 153 | static void saveFile(const char *fileName, int seeLinks); | ||
| 154 | static void saveRegularFile(const char *fileName, | ||
| 155 | const struct stat *statbuf); | ||
| 156 | static void saveDirectory(const char *fileName, | ||
| 157 | const struct stat *statbuf); | ||
| 158 | static void writeHeader(const char *fileName, const struct stat *statbuf); | ||
| 159 | static void writeTarFile(int argc, char **argv); | ||
| 160 | static void writeTarBlock(const char *buf, int len); | ||
| 161 | static int putOctal(char *cp, int len, long value); | 167 | static int putOctal(char *cp, int len, long value); |
| 162 | 168 | ||
| 163 | #endif | 169 | #endif |
| @@ -242,7 +248,7 @@ extern int tar_main(int argc, char **argv) | |||
| 242 | #ifndef BB_FEATURE_TAR_CREATE | 248 | #ifndef BB_FEATURE_TAR_CREATE |
| 243 | fatalError( "This version of tar was not compiled with tar creation support.\n"); | 249 | fatalError( "This version of tar was not compiled with tar creation support.\n"); |
| 244 | #else | 250 | #else |
| 245 | exit(writeTarFile(argc, argv)); | 251 | exit(writeTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, argc, argv)); |
| 246 | #endif | 252 | #endif |
| 247 | } else { | 253 | } else { |
| 248 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag)); | 254 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag)); |
| @@ -347,10 +353,9 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag) | |||
| 347 | /* make the final component, just in case it was | 353 | /* make the final component, just in case it was |
| 348 | * omitted by createPath() (which will skip the | 354 | * omitted by createPath() (which will skip the |
| 349 | * directory if it doesn't have a terminating '/') */ | 355 | * directory if it doesn't have a terminating '/') */ |
| 350 | mkdir(header->name, header->mode); | 356 | if (mkdir(header->name, header->mode) == 0) { |
| 351 | 357 | fixUpPermissions(header); | |
| 352 | /* Now set permissions etc for the new directory */ | 358 | } |
| 353 | fixUpPermissions(header); | ||
| 354 | } | 359 | } |
| 355 | 360 | ||
| 356 | static void | 361 | static void |
| @@ -616,3 +621,89 @@ endgame: | |||
| 616 | return( FALSE); | 621 | return( FALSE); |
| 617 | } | 622 | } |
| 618 | 623 | ||
| 624 | |||
| 625 | #ifdef BB_FEATURE_TAR_CREATE | ||
| 626 | |||
| 627 | /* Put an octal string into the specified buffer. | ||
| 628 | * The number is zero and space padded and possibly null padded. | ||
| 629 | * Returns TRUE if successful. */ | ||
| 630 | static int putOctal (char *cp, int len, long value) | ||
| 631 | { | ||
| 632 | int tempLength; | ||
| 633 | char *tempString; | ||
| 634 | char tempBuffer[32]; | ||
| 635 | |||
| 636 | /* Create a string of the specified length with an initial space, | ||
| 637 | * leading zeroes and the octal number, and a trailing null. */ | ||
| 638 | tempString = tempBuffer; | ||
| 639 | |||
| 640 | sprintf (tempString, " %0*lo", len - 2, value); | ||
| 641 | |||
| 642 | tempLength = strlen (tempString) + 1; | ||
| 643 | |||
| 644 | /* If the string is too large, suppress the leading space. */ | ||
| 645 | if (tempLength > len) { | ||
| 646 | tempLength--; | ||
| 647 | tempString++; | ||
| 648 | } | ||
| 649 | |||
| 650 | /* If the string is still too large, suppress the trailing null. */ | ||
| 651 | if (tempLength > len) | ||
| 652 | tempLength--; | ||
| 653 | |||
| 654 | /* If the string is still too large, fail. */ | ||
| 655 | if (tempLength > len) | ||
| 656 | return FALSE; | ||
| 657 | |||
| 658 | /* Copy the string to the field. */ | ||
| 659 | memcpy (cp, tempString, len); | ||
| 660 | |||
| 661 | return TRUE; | ||
| 662 | } | ||
| 663 | |||
| 664 | static int fileAction(const char *fileName, struct stat *statbuf) | ||
| 665 | { | ||
| 666 | fprintf(stdout, "%s\n", fileName); | ||
| 667 | return (TRUE); | ||
| 668 | } | ||
| 669 | |||
| 670 | static int writeTarFile(const char* tarName, int extractFlag, int listFlag, | ||
| 671 | int tostdoutFlag, int verboseFlag, int argc, char **argv) | ||
| 672 | { | ||
| 673 | int tarFd=0; | ||
| 674 | //int errorFlag=FALSE; | ||
| 675 | //TarHeader rawHeader; | ||
| 676 | //TarInfo header; | ||
| 677 | //int alreadyWarned=FALSE; | ||
| 678 | char *directory = "."; | ||
| 679 | //int skipFileFlag=FALSE; | ||
| 680 | |||
| 681 | /* Open the tar file for writing. */ | ||
| 682 | if (!strcmp(tarName, "-")) | ||
| 683 | tarFd = fileno(stdout); | ||
| 684 | else | ||
| 685 | tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); | ||
| 686 | if (tarFd < 0) { | ||
| 687 | errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno)); | ||
| 688 | return ( FALSE); | ||
| 689 | } | ||
| 690 | |||
| 691 | /* Set the umask for this process so it doesn't | ||
| 692 | * screw up permission setting for us later. */ | ||
| 693 | umask(0); | ||
| 694 | |||
| 695 | /* Read the directory/files and iterate over them one at a time */ | ||
| 696 | if (recursiveAction(directory, TRUE, FALSE, FALSE, | ||
| 697 | fileAction, fileAction) == FALSE) { | ||
| 698 | exit(FALSE); | ||
| 699 | } | ||
| 700 | |||
| 701 | |||
| 702 | // TODO: DO STUFF HERE | ||
| 703 | close(tarFd); | ||
| 704 | return( TRUE); | ||
| 705 | } | ||
| 706 | |||
| 707 | |||
| 708 | #endif | ||
| 709 | |||
diff --git a/busybox.def.h b/busybox.def.h index 388219a52..53229ce1b 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
| @@ -161,7 +161,7 @@ | |||
| 161 | #define BB_FEATURE_REMOUNT | 161 | #define BB_FEATURE_REMOUNT |
| 162 | // | 162 | // |
| 163 | // Enable support for creation of tar files. | 163 | // Enable support for creation of tar files. |
| 164 | //#define BB_FEATURE_TAR_CREATE | 164 | #define BB_FEATURE_TAR_CREATE |
| 165 | // | 165 | // |
| 166 | //// Enable reverse sort | 166 | //// Enable reverse sort |
| 167 | //#define BB_FEATURE_SORT_REVERSE | 167 | //#define BB_FEATURE_SORT_REVERSE |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * BusyBox Shell | 3 | * lash -- the BusyBox Lame-Ass SHell |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2000 by Lineo, inc. | 5 | * Copyright (C) 2000 by Lineo, inc. |
| 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * BusyBox Shell | 3 | * lash -- the BusyBox Lame-Ass SHell |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2000 by Lineo, inc. | 5 | * Copyright (C) 2000 by Lineo, inc. |
| 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
diff --git a/shell/lash.c b/shell/lash.c index 8c1503ff4..ad7d7613c 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * BusyBox Shell | 3 | * lash -- the BusyBox Lame-Ass SHell |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2000 by Lineo, inc. | 5 | * Copyright (C) 2000 by Lineo, inc. |
| 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| @@ -1,10 +1,24 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * Mini tar implementation for busybox | 3 | * |
| 4 | * Mini tar implementation for busybox Note, that as of BusyBox 0.43 tar has | ||
| 5 | * been completely rewritten from the ground up. It still has remnents of the | ||
| 6 | * old code lying about, but it pretty different (i.e. cleaner, less global | ||
| 7 | * variables, etc) | ||
| 4 | * | 8 | * |
| 5 | * Copyright (C) 1999 by Lineo, inc. | 9 | * Copyright (C) 1999 by Lineo, inc. |
| 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | 10 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| 7 | * | 11 | * |
| 12 | * Based in part in the tar implementation in sash | ||
| 13 | * Copyright (c) 1999 by David I. Bell | ||
| 14 | * Permission is granted to use, distribute, or modify this source, | ||
| 15 | * provided that this copyright notice remains intact. | ||
| 16 | * Permission to distribute sash derived code under the GPL has been granted. | ||
| 17 | * | ||
| 18 | * Based in part on the tar implementation in busybox-0.28 | ||
| 19 | * Copyright (C) 1995 Bruce Perens | ||
| 20 | * This is free software under the GNU General Public License. | ||
| 21 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | 22 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | 23 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or | 24 | * the Free Software Foundation; either version 2 of the License, or |
| @@ -147,17 +161,9 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag, | |||
| 147 | 161 | ||
| 148 | 162 | ||
| 149 | #ifdef BB_FEATURE_TAR_CREATE | 163 | #ifdef BB_FEATURE_TAR_CREATE |
| 150 | /* | 164 | /* Local procedures to save files into a tar file. */ |
| 151 | * Local procedures to save files into a tar file. | 165 | static int writeTarFile(const char* tarName, int extractFlag, int listFlag, |
| 152 | */ | 166 | int tostdoutFlag, int verboseFlag, int argc, char **argv); |
| 153 | static void saveFile(const char *fileName, int seeLinks); | ||
| 154 | static void saveRegularFile(const char *fileName, | ||
| 155 | const struct stat *statbuf); | ||
| 156 | static void saveDirectory(const char *fileName, | ||
| 157 | const struct stat *statbuf); | ||
| 158 | static void writeHeader(const char *fileName, const struct stat *statbuf); | ||
| 159 | static void writeTarFile(int argc, char **argv); | ||
| 160 | static void writeTarBlock(const char *buf, int len); | ||
| 161 | static int putOctal(char *cp, int len, long value); | 167 | static int putOctal(char *cp, int len, long value); |
| 162 | 168 | ||
| 163 | #endif | 169 | #endif |
| @@ -242,7 +248,7 @@ extern int tar_main(int argc, char **argv) | |||
| 242 | #ifndef BB_FEATURE_TAR_CREATE | 248 | #ifndef BB_FEATURE_TAR_CREATE |
| 243 | fatalError( "This version of tar was not compiled with tar creation support.\n"); | 249 | fatalError( "This version of tar was not compiled with tar creation support.\n"); |
| 244 | #else | 250 | #else |
| 245 | exit(writeTarFile(argc, argv)); | 251 | exit(writeTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, argc, argv)); |
| 246 | #endif | 252 | #endif |
| 247 | } else { | 253 | } else { |
| 248 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag)); | 254 | exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag)); |
| @@ -347,10 +353,9 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag) | |||
| 347 | /* make the final component, just in case it was | 353 | /* make the final component, just in case it was |
| 348 | * omitted by createPath() (which will skip the | 354 | * omitted by createPath() (which will skip the |
| 349 | * directory if it doesn't have a terminating '/') */ | 355 | * directory if it doesn't have a terminating '/') */ |
| 350 | mkdir(header->name, header->mode); | 356 | if (mkdir(header->name, header->mode) == 0) { |
| 351 | 357 | fixUpPermissions(header); | |
| 352 | /* Now set permissions etc for the new directory */ | 358 | } |
| 353 | fixUpPermissions(header); | ||
| 354 | } | 359 | } |
| 355 | 360 | ||
| 356 | static void | 361 | static void |
| @@ -616,3 +621,89 @@ endgame: | |||
| 616 | return( FALSE); | 621 | return( FALSE); |
| 617 | } | 622 | } |
| 618 | 623 | ||
| 624 | |||
| 625 | #ifdef BB_FEATURE_TAR_CREATE | ||
| 626 | |||
| 627 | /* Put an octal string into the specified buffer. | ||
| 628 | * The number is zero and space padded and possibly null padded. | ||
| 629 | * Returns TRUE if successful. */ | ||
| 630 | static int putOctal (char *cp, int len, long value) | ||
| 631 | { | ||
| 632 | int tempLength; | ||
| 633 | char *tempString; | ||
| 634 | char tempBuffer[32]; | ||
| 635 | |||
| 636 | /* Create a string of the specified length with an initial space, | ||
| 637 | * leading zeroes and the octal number, and a trailing null. */ | ||
| 638 | tempString = tempBuffer; | ||
| 639 | |||
| 640 | sprintf (tempString, " %0*lo", len - 2, value); | ||
| 641 | |||
| 642 | tempLength = strlen (tempString) + 1; | ||
| 643 | |||
| 644 | /* If the string is too large, suppress the leading space. */ | ||
| 645 | if (tempLength > len) { | ||
| 646 | tempLength--; | ||
| 647 | tempString++; | ||
| 648 | } | ||
| 649 | |||
| 650 | /* If the string is still too large, suppress the trailing null. */ | ||
| 651 | if (tempLength > len) | ||
| 652 | tempLength--; | ||
| 653 | |||
| 654 | /* If the string is still too large, fail. */ | ||
| 655 | if (tempLength > len) | ||
| 656 | return FALSE; | ||
| 657 | |||
| 658 | /* Copy the string to the field. */ | ||
| 659 | memcpy (cp, tempString, len); | ||
| 660 | |||
| 661 | return TRUE; | ||
| 662 | } | ||
| 663 | |||
| 664 | static int fileAction(const char *fileName, struct stat *statbuf) | ||
| 665 | { | ||
| 666 | fprintf(stdout, "%s\n", fileName); | ||
| 667 | return (TRUE); | ||
| 668 | } | ||
| 669 | |||
| 670 | static int writeTarFile(const char* tarName, int extractFlag, int listFlag, | ||
| 671 | int tostdoutFlag, int verboseFlag, int argc, char **argv) | ||
| 672 | { | ||
| 673 | int tarFd=0; | ||
| 674 | //int errorFlag=FALSE; | ||
| 675 | //TarHeader rawHeader; | ||
| 676 | //TarInfo header; | ||
| 677 | //int alreadyWarned=FALSE; | ||
| 678 | char *directory = "."; | ||
| 679 | //int skipFileFlag=FALSE; | ||
| 680 | |||
| 681 | /* Open the tar file for writing. */ | ||
| 682 | if (!strcmp(tarName, "-")) | ||
| 683 | tarFd = fileno(stdout); | ||
| 684 | else | ||
| 685 | tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644); | ||
| 686 | if (tarFd < 0) { | ||
| 687 | errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno)); | ||
| 688 | return ( FALSE); | ||
| 689 | } | ||
| 690 | |||
| 691 | /* Set the umask for this process so it doesn't | ||
| 692 | * screw up permission setting for us later. */ | ||
| 693 | umask(0); | ||
| 694 | |||
| 695 | /* Read the directory/files and iterate over them one at a time */ | ||
| 696 | if (recursiveAction(directory, TRUE, FALSE, FALSE, | ||
| 697 | fileAction, fileAction) == FALSE) { | ||
| 698 | exit(FALSE); | ||
| 699 | } | ||
| 700 | |||
| 701 | |||
| 702 | // TODO: DO STUFF HERE | ||
| 703 | close(tarFd); | ||
| 704 | return( TRUE); | ||
| 705 | } | ||
| 706 | |||
| 707 | |||
| 708 | #endif | ||
| 709 | |||
