libunarchive: stop using static data in archivers - archive_handle_t

can trivially provide space for that.
rpm: code shrink
tar: simplify autodetection of bz2/.gz


function                                             old     new   delta
static.not_first                                       1       -      -1
static.end                                             1       -      -1
bb_makedev                                            51      49      -2
static.saved_hardlinks_created                         4       -      -4
static.saved_hardlinks                                 4       -      -4
longname                                               4       -      -4
linkname                                               4       -      -4
hash_file                                            251     247      -4
get_header_tar                                      1528    1521      -7
rpm_main                                            1711    1697     -14
get_header_cpio                                      965     944     -21
------------------------------------------------------------------------------
(add/remove: 0/6 grow/shrink: 0/5 up/down: 0/-66)             Total: -66 bytes
   text    data     bss     dec     hex filename
 804926     611    6868  812405   c6575 busybox_old
 804878     611    6852  812341   c6535 busybox_unstripped
This commit is contained in:
Denis Vlasenko 2008-06-28 05:04:09 +00:00
parent 9579d87be4
commit a60936da06
11 changed files with 89 additions and 86 deletions

View File

@ -63,7 +63,7 @@ int ar_main(int argc, char **argv)
archive_handle->action_data = data_extract_all; archive_handle->action_data = data_extract_all;
} }
if (opt & AR_OPT_PRESERVE_DATE) { if (opt & AR_OPT_PRESERVE_DATE) {
archive_handle->flags |= ARCHIVE_PRESERVE_DATE; archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
} }
if (opt & AR_OPT_VERBOSE) { if (opt & AR_OPT_VERBOSE) {
archive_handle->action_header = header_verbose_list_ar; archive_handle->action_header = header_verbose_list_ar;

View File

@ -204,7 +204,7 @@ int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
archive_handle = init_handle(); archive_handle = init_handle();
archive_handle->src_fd = STDIN_FILENO; archive_handle->src_fd = STDIN_FILENO;
archive_handle->seek = seek_by_read; archive_handle->seek = seek_by_read;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER; archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
#if ENABLE_FEATURE_CPIO_O #if ENABLE_FEATURE_CPIO_O
opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt); opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
@ -241,8 +241,8 @@ int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
archive_handle->action_data = data_extract_all; archive_handle->action_data = data_extract_all;
} }
if (opt & CPIO_OPT_UNCONDITIONAL) { if (opt & CPIO_OPT_UNCONDITIONAL) {
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER; archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
} }
if (opt & CPIO_OPT_VERBOSE) { if (opt & CPIO_OPT_VERBOSE) {
if (archive_handle->action_header == header_list) { if (archive_handle->action_header == header_list) {
@ -256,10 +256,10 @@ int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
archive_handle->seek = seek_by_jump; archive_handle->seek = seek_by_jump;
} }
if (opt & CPIO_OPT_CREATE_LEADING_DIR) { if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS; archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
} }
if (opt & CPIO_OPT_PRESERVE_MTIME) { if (opt & CPIO_OPT_PRESERVE_MTIME) {
archive_handle->flags |= ARCHIVE_PRESERVE_DATE; archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
} }
while (*argv) { while (*argv) {

View File

@ -1532,7 +1532,7 @@ static void unpack_package(deb_file_t *deb_file)
archive_handle->sub_archive->filter = filter_accept_list; archive_handle->sub_archive->filter = filter_accept_list;
archive_handle->sub_archive->action_data = data_extract_all_prefix; archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = info_prefix; archive_handle->sub_archive->buffer = info_prefix;
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle); unpack_ar_archive(archive_handle);
/* Run the preinst prior to extracting */ /* Run the preinst prior to extracting */
@ -1543,7 +1543,7 @@ static void unpack_package(deb_file_t *deb_file)
init_archive_deb_data(archive_handle); init_archive_deb_data(archive_handle);
archive_handle->sub_archive->action_data = data_extract_all_prefix; archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */ archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle); unpack_ar_archive(archive_handle);
/* Create the list file */ /* Create the list file */

View File

@ -12,14 +12,14 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
int dst_fd; int dst_fd;
int res; int res;
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *name = xstrdup(file_header->name); char *name = xstrdup(file_header->name);
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR); bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
free(name); free(name);
} }
/* Check if the file already exists */ /* Check if the file already exists */
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
/* Remove the entry if it exists */ /* Remove the entry if it exists */
if (((file_header->mode & S_IFMT) != S_IFDIR) if (((file_header->mode & S_IFMT) != S_IFDIR)
&& (unlink(file_header->name) == -1) && (unlink(file_header->name) == -1)
@ -29,7 +29,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
file_header->name); file_header->name);
} }
} }
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) { else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
/* Remove the existing entry if its older than the extracted entry */ /* Remove the existing entry if its older than the extracted entry */
struct stat statbuf; struct stat statbuf;
if (lstat(file_header->name, &statbuf) == -1) { if (lstat(file_header->name, &statbuf) == -1) {
@ -38,7 +38,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
} }
} }
else if (statbuf.st_mtime <= file_header->mtime) { else if (statbuf.st_mtime <= file_header->mtime) {
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
bb_error_msg("%s not created: newer or " bb_error_msg("%s not created: newer or "
"same age file exists", file_header->name); "same age file exists", file_header->name);
} }
@ -58,7 +58,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
) { ) {
/* hard link */ /* hard link */
res = link(file_header->link_target, file_header->name); res = link(file_header->link_target, file_header->name);
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) { if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("cannot create %slink " bb_perror_msg("cannot create %slink "
"from %s to %s", "hard", "from %s to %s", "hard",
file_header->name, file_header->name,
@ -78,7 +78,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFDIR: case S_IFDIR:
res = mkdir(file_header->name, file_header->mode); res = mkdir(file_header->name, file_header->mode);
if ((res == -1) && (errno != EISDIR) if ((res == -1) && (errno != EISDIR)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) { ) {
bb_perror_msg("cannot make dir %s", file_header->name); bb_perror_msg("cannot make dir %s", file_header->name);
} }
@ -87,7 +87,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* Symlink */ /* Symlink */
res = symlink(file_header->link_target, file_header->name); res = symlink(file_header->link_target, file_header->name);
if ((res == -1) if ((res == -1)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) { ) {
bb_perror_msg("cannot create %slink " bb_perror_msg("cannot create %slink "
"from %s to %s", "sym", "from %s to %s", "sym",
@ -101,7 +101,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFIFO: case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device); res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1) if ((res == -1)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) { ) {
bb_perror_msg("cannot create node %s", file_header->name); bb_perror_msg("cannot create node %s", file_header->name);
} }
@ -111,7 +111,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
} }
} }
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) { if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
#if ENABLE_FEATURE_TAR_UNAME_GNAME #if ENABLE_FEATURE_TAR_UNAME_GNAME
uid_t uid = file_header->uid; uid_t uid = file_header->uid;
gid_t gid = file_header->gid; gid_t gid = file_header->gid;
@ -133,11 +133,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* uclibc has no lchmod, glibc is even stranger - /* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing! * it has lchmod which seems to do nothing!
* so we use chmod... */ * so we use chmod... */
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) { if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_PERM)) {
chmod(file_header->name, file_header->mode); chmod(file_header->name, file_header->mode);
} }
/* same for utime */ /* same for utime */
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) { if (archive_handle->ah_flags & ARCHIVE_PRESERVE_DATE) {
struct utimbuf t; struct utimbuf t;
t.actime = t.modtime = file_header->mtime; t.actime = t.modtime = file_header->mtime;
utime(file_header->name, &t); utime(file_header->name, &t);

View File

@ -110,7 +110,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->action_header(typed); archive_handle->action_header(typed);
if (archive_handle->sub_archive) { if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS) while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
/* repeat */; continue;
} else { } else {
archive_handle->action_data(archive_handle); archive_handle->action_data(archive_handle);
} }

View File

@ -19,9 +19,6 @@ typedef struct hardlinks_s {
char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
{ {
static hardlinks_t *saved_hardlinks = NULL;
static hardlinks_t *saved_hardlinks_created = NULL;
file_header_t *file_header = archive_handle->file_header; file_header_t *file_header = archive_handle->file_header;
char cpio_header[110]; char cpio_header[110];
char dummy[16]; char dummy[16];
@ -29,6 +26,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
int major, minor, nlink, mode, inode; int major, minor, nlink, mode, inode;
unsigned size, uid, gid, mtime; unsigned size, uid, gid, mtime;
#define saved_hardlinks (*(hardlinks_t **)(&archive_handle->ah_priv[0]))
#define saved_hardlinks_created (*(hardlinks_t **)(&archive_handle->ah_priv[1]))
// if (!archive_handle->ah_priv_inited) {
// archive_handle->ah_priv_inited = 1;
// saved_hardlinks = NULL;
// saved_hardlinks_created = NULL;
// }
/* There can be padding before archive header */ /* There can be padding before archive header */
data_align(archive_handle, 4); data_align(archive_handle, 4);

View File

@ -14,26 +14,13 @@
#include "libbb.h" #include "libbb.h"
#include "unarchive.h" #include "unarchive.h"
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static char *longname;
static char *linkname;
#else
enum {
longname = 0,
linkname = 0,
};
#endif
/* NB: _DESTROYS_ str[len] character! */ /* NB: _DESTROYS_ str[len] character! */
static unsigned long long getOctal(char *str, int len) static unsigned long long getOctal(char *str, int len)
{ {
unsigned long long v; unsigned long long v;
/* Actually, tar header allows leading spaces also. /* NB: leading spaces are allowed. Using strtoull to handle that.
* Oh well, we will be liberal and skip this... * The downside is that we accept e.g. "-123" too :)
* The only downside probably is that we allow "-123" too :) */
if (*str < '0' || *str > '7')
bb_error_msg_and_die("corrupted octal value in tar header");
*/
str[len] = '\0'; str[len] = '\0';
v = strtoull(str, &str, 8); v = strtoull(str, &str, 8);
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' ')) if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
@ -45,11 +32,6 @@ static unsigned long long getOctal(char *str, int len)
void BUG_tar_header_size(void); void BUG_tar_header_size(void);
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
{ {
static smallint end;
#if ENABLE_FEATURE_TAR_AUTODETECT
static smallint not_first;
#endif
file_header_t *file_header = archive_handle->file_header; file_header_t *file_header = archive_handle->file_header;
struct { struct {
/* ustar header, Posix 1003.1 */ /* ustar header, Posix 1003.1 */
@ -65,7 +47,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* POSIX: "ustar" NUL "00" */ /* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */ /* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by /* Normally it's defined as magic[6] followed by
* version[2], but we put them together to save code. * version[2], but we put them together to simplify code
*/ */
char magic[8]; /* 257-264 */ char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */ char uname[32]; /* 265-296 */
@ -82,6 +64,22 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#endif #endif
int parse_names; int parse_names;
/* Our "private data" */
#define p_end (*(smallint *)(&archive_handle->ah_priv[0]))
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#define p_longname (*(char* *)(&archive_handle->ah_priv[1]))
#define p_linkname (*(char* *)(&archive_handle->ah_priv[2]))
#else
#define p_longname 0
#define p_linkname 0
#endif
// if (!archive_handle->ah_priv_inited) {
// archive_handle->ah_priv_inited = 1;
// p_end = 0;
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_longname = NULL;)
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_linkname = NULL;)
// }
if (sizeof(tar) != 512) if (sizeof(tar) != 512)
BUG_tar_header_size(); BUG_tar_header_size();
@ -95,7 +93,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#if ENABLE_DESKTOP #if ENABLE_DESKTOP
i = full_read(archive_handle->src_fd, &tar, 512); i = full_read(archive_handle->src_fd, &tar, 512);
/* if GNU tar sees EOF in above read, it says: /* If GNU tar sees EOF in above read, it says:
* "tar: A lone zero block at N", where N = kilobyte * "tar: A lone zero block at N", where N = kilobyte
* where EOF was met (not EOF block, actual EOF!), * where EOF was met (not EOF block, actual EOF!),
* and tar will exit with error code 0. * and tar will exit with error code 0.
@ -113,18 +111,18 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* If there is no filename its an empty header */ /* If there is no filename its an empty header */
if (tar.name[0] == 0 && tar.prefix[0] == 0) { if (tar.name[0] == 0 && tar.prefix[0] == 0) {
if (end) { if (p_end) {
/* This is the second consecutive empty header! End of archive! /* Second consecutive empty header - end of archive.
* Read until the end to empty the pipe from gz or bz2 * Read until the end to empty the pipe from gz or bz2
*/ */
while (full_read(archive_handle->src_fd, &tar, 512) == 512) while (full_read(archive_handle->src_fd, &tar, 512) == 512)
continue; continue;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
end = 1; p_end = 1;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
end = 0; p_end = 0;
/* Check header has valid magic, "ustar" is for the proper tar, /* Check header has valid magic, "ustar" is for the proper tar,
* five NULs are for the old tar format */ * five NULs are for the old tar format */
@ -136,12 +134,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
char FAST_FUNC (*get_header_ptr)(archive_handle_t *); char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
/* tar gz/bz autodetect: check for gz/bz2 magic. /* tar gz/bz autodetect: check for gz/bz2 magic.
* If it is the very first block, and we see the magic, * If we see the magic, and it is the very first block,
* we can switch to get_header_tar_gz/bz2/lzma(). * we can switch to get_header_tar_gz/bz2/lzma().
* Needs seekable fd. I wish recv(MSG_PEEK) works * Needs seekable fd. I wish recv(MSG_PEEK) works
* on any fd... */ * on any fd... */
if (not_first)
goto err;
#if ENABLE_FEATURE_TAR_GZIP #if ENABLE_FEATURE_TAR_GZIP
if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
get_header_ptr = get_header_tar_gz; get_header_ptr = get_header_tar_gz;
@ -155,6 +151,9 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
} else } else
#endif #endif
goto err; goto err;
/* Two different causes for lseek() != 0:
* unseekable fd (would like to support that too, but...),
* or not first block (false positive, it's not .gz/.bz2!) */
if (lseek(archive_handle->src_fd, -512, SEEK_CUR) != 0) if (lseek(archive_handle->src_fd, -512, SEEK_CUR) != 0)
goto err; goto err;
while (get_header_ptr(archive_handle) == EXIT_SUCCESS) while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
@ -165,10 +164,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
bb_error_msg_and_die("invalid tar magic"); bb_error_msg_and_die("invalid tar magic");
} }
#if ENABLE_FEATURE_TAR_AUTODETECT
not_first = 1;
#endif
/* Do checksum on headers. /* Do checksum on headers.
* POSIX says that checksum is done on unsigned bytes, but * POSIX says that checksum is done on unsigned bytes, but
* Sun and HP-UX gets it wrong... more details in * Sun and HP-UX gets it wrong... more details in
@ -219,7 +214,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
tar.prefix[0] = t; tar.prefix[0] = t;
} }
file_header->link_target = NULL; file_header->link_target = NULL;
if (!linkname && parse_names && tar.linkname[0]) { if (!p_linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname)); file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
/* FIXME: what if we have non-link object with link_target? */ /* FIXME: what if we have non-link object with link_target? */
/* Will link_target be free()ed? */ /* Will link_target be free()ed? */
@ -236,7 +231,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->mode = 07777 & GET_OCTAL(tar.mode); file_header->mode = 07777 & GET_OCTAL(tar.mode);
file_header->name = NULL; file_header->name = NULL;
if (!longname && parse_names) { if (!p_longname && parse_names) {
/* we trash mode[0] here, it's ok */ /* we trash mode[0] here, it's ok */
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain //tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
tar.mode[0] = '\0'; tar.mode[0] = '\0';
@ -284,20 +279,20 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
case 'L': case 'L':
/* free: paranoia: tar with several consecutive longnames */ /* free: paranoia: tar with several consecutive longnames */
free(longname); free(p_longname);
/* For paranoia reasons we allocate extra NUL char */ /* For paranoia reasons we allocate extra NUL char */
longname = xzalloc(file_header->size + 1); p_longname = xzalloc(file_header->size + 1);
/* We read ASCIZ string, including NUL */ /* We read ASCIZ string, including NUL */
xread(archive_handle->src_fd, longname, file_header->size); xread(archive_handle->src_fd, p_longname, file_header->size);
archive_handle->offset += file_header->size; archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */ /* return get_header_tar(archive_handle); */
/* gcc 4.1.1 didn't optimize it into jump */ /* gcc 4.1.1 didn't optimize it into jump */
/* so we will do it ourself, this also saves stack */ /* so we will do it ourself, this also saves stack */
goto again; goto again;
case 'K': case 'K':
free(linkname); free(p_linkname);
linkname = xzalloc(file_header->size + 1); p_linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, linkname, file_header->size); xread(archive_handle->src_fd, p_linkname, file_header->size);
archive_handle->offset += file_header->size; archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */ /* return get_header_tar(archive_handle); */
goto again; goto again;
@ -324,13 +319,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
} }
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (longname) { if (p_longname) {
file_header->name = longname; file_header->name = p_longname;
longname = NULL; p_longname = NULL;
} }
if (linkname) { if (p_linkname) {
file_header->link_target = linkname; file_header->link_target = p_linkname;
linkname = NULL; p_linkname = NULL;
} }
#endif #endif
if (!strncmp(file_header->name, "/../"+1, 3) if (!strncmp(file_header->name, "/../"+1, 3)
@ -349,7 +344,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Note that we kill the '/' only after action_header() */ /* Note that we kill the '/' only after action_header() */
/* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */ /* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */
if (cp) *cp = '\0'; if (cp) *cp = '\0';
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; archive_handle->ah_flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle); archive_handle->action_data(archive_handle);
llist_add_to(&(archive_handle->passed), file_header->name); llist_add_to(&(archive_handle->passed), file_header->name);
} else { } else {

View File

@ -9,7 +9,7 @@
#include "libbb.h" #include "libbb.h"
#include "unarchive.h" #include "unarchive.h"
char FAST_FUNC get_header_tar_lzma(archive_handle_t * archive_handle) char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
{ {
/* Can't lseek over pipes */ /* Can't lseek over pipes */
archive_handle->seek = seek_by_read; archive_handle->seek = seek_by_read;

View File

@ -202,10 +202,9 @@ static void extract_cpio_gz(int fd)
archive_handle->seek = seek_by_read; archive_handle->seek = seek_by_read;
//archive_handle->action_header = header_list; //archive_handle->action_header = header_list;
archive_handle->action_data = data_extract_all; archive_handle->action_data = data_extract_all;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE; archive_handle->ah_flags = ARCHIVE_PRESERVE_DATE | ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->src_fd = fd; archive_handle->src_fd = fd;
archive_handle->offset = 0; /*archive_handle->offset = 0; - init_handle() did it */
xread(archive_handle->src_fd, &magic, 2); xread(archive_handle->src_fd, &magic, 2);
#if BB_MMU #if BB_MMU

View File

@ -814,9 +814,9 @@ int tar_main(int argc ATTRIBUTE_UNUSED, char **argv)
/* Initialise default values */ /* Initialise default values */
tar_handle = init_handle(); tar_handle = init_handle();
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
| ARCHIVE_PRESERVE_DATE | ARCHIVE_PRESERVE_DATE
| ARCHIVE_EXTRACT_UNCONDITIONAL; | ARCHIVE_EXTRACT_UNCONDITIONAL;
/* Prepend '-' to the first argument if required */ /* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options opt_complementary = "--:" // first arg is options
@ -862,13 +862,13 @@ int tar_main(int argc ATTRIBUTE_UNUSED, char **argv)
tar_handle->action_data = data_extract_to_stdout; tar_handle->action_data = data_extract_to_stdout;
if (opt & OPT_KEEP_OLD) if (opt & OPT_KEEP_OLD)
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL; tar_handle->ah_flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
if (opt & OPT_NOPRESERVE_OWN) if (opt & OPT_NOPRESERVE_OWN)
tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN; tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_OWN;
if (opt & OPT_NOPRESERVE_PERM) if (opt & OPT_NOPRESERVE_PERM)
tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM; tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
if (opt & OPT_GZIP) if (opt & OPT_GZIP)
get_header_ptr = get_header_tar_gz; get_header_ptr = get_header_tar_gz;

View File

@ -30,7 +30,7 @@ typedef struct file_header_t {
} file_header_t; } file_header_t;
typedef struct archive_handle_t { typedef struct archive_handle_t {
/* define if the header and data component should be processed */ /* Define if the header and data component should be processed */
char FAST_FUNC (*filter)(struct archive_handle_t *); char FAST_FUNC (*filter)(struct archive_handle_t *);
llist_t *accept; llist_t *accept;
/* List of files that have been rejected */ /* List of files that have been rejected */
@ -41,10 +41,10 @@ typedef struct archive_handle_t {
/* Contains the processed header entry */ /* Contains the processed header entry */
file_header_t *file_header; file_header_t *file_header;
/* process the header component, e.g. tar -t */ /* Process the header component, e.g. tar -t */
void FAST_FUNC (*action_header)(const file_header_t *); void FAST_FUNC (*action_header)(const file_header_t *);
/* process the data component, e.g. extract to filesystem */ /* Process the data component, e.g. extract to filesystem */
void FAST_FUNC (*action_data)(struct archive_handle_t *); void FAST_FUNC (*action_data)(struct archive_handle_t *);
/* How to process any sub archive, e.g. get_header_tar_gz */ /* How to process any sub archive, e.g. get_header_tar_gz */
@ -66,7 +66,11 @@ typedef struct archive_handle_t {
char *buffer; char *buffer;
/* Flags and misc. stuff */ /* Flags and misc. stuff */
unsigned char flags; unsigned char ah_flags;
/* "Private" storage for archivers */
// unsigned char ah_priv_inited;
void *ah_priv[8];
} archive_handle_t; } archive_handle_t;