2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2017-10-05 19:03:28 +05:30
|
|
|
/*
|
|
|
|
* Copyright 2001 Glenn McGrath.
|
2001-10-25 19:48:08 +05:30
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2001-10-25 19:48:08 +05:30
|
|
|
*/
|
|
|
|
#include "libbb.h"
|
2011-09-22 16:15:14 +05:30
|
|
|
#include "bb_archive.h"
|
2010-03-15 20:08:09 +05:30
|
|
|
#include "ar.h"
|
2001-10-25 19:48:08 +05:30
|
|
|
|
2013-09-10 15:22:35 +05:30
|
|
|
/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
|
|
|
|
static unsigned read_num(char *str, int base, int len)
|
2009-09-20 04:58:27 +05:30
|
|
|
{
|
2013-09-10 15:22:35 +05:30
|
|
|
int err;
|
|
|
|
|
|
|
|
/* ar fields are fixed length text strings (padded with spaces).
|
|
|
|
* Ensure bb_strtou doesn't read past the field in case the full
|
|
|
|
* width is used. */
|
|
|
|
str[len] = 0;
|
|
|
|
|
2009-09-20 04:58:27 +05:30
|
|
|
/* This code works because
|
|
|
|
* on misformatted numbers bb_strtou returns all-ones */
|
2013-09-10 15:22:35 +05:30
|
|
|
err = bb_strtou(str, NULL, base);
|
2009-09-20 04:58:27 +05:30
|
|
|
if (err == -1)
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("invalid ar header");
|
2009-09-20 04:58:27 +05:30
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
2001-10-25 19:48:08 +05:30
|
|
|
{
|
2002-09-25 08:17:48 +05:30
|
|
|
file_header_t *typed = archive_handle->file_header;
|
2009-09-20 04:58:27 +05:30
|
|
|
unsigned size;
|
2001-10-25 19:48:08 +05:30
|
|
|
union {
|
|
|
|
char raw[60];
|
2010-03-15 20:08:09 +05:30
|
|
|
struct ar_header formatted;
|
2001-10-25 19:48:08 +05:30
|
|
|
} ar;
|
|
|
|
|
2006-08-03 21:11:12 +05:30
|
|
|
/* dont use xread as we want to handle the error ourself */
|
2002-09-25 08:17:48 +05:30
|
|
|
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
|
|
|
/* End Of File */
|
2006-11-27 22:19:31 +05:30
|
|
|
return EXIT_FAILURE;
|
2003-07-31 07:23:50 +05:30
|
|
|
}
|
2002-09-25 08:17:48 +05:30
|
|
|
|
2004-04-09 12:29:05 +05:30
|
|
|
/* ar header starts on an even byte (2 byte aligned)
|
|
|
|
* '\n' is used for padding
|
|
|
|
*/
|
2002-09-25 08:17:48 +05:30
|
|
|
if (ar.raw[0] == '\n') {
|
2001-10-25 19:48:08 +05:30
|
|
|
/* fix up the header, we started reading 1 byte too early */
|
|
|
|
memmove(ar.raw, &ar.raw[1], 59);
|
2006-07-16 13:44:35 +05:30
|
|
|
ar.raw[59] = xread_char(archive_handle->src_fd);
|
2002-09-25 08:17:48 +05:30
|
|
|
archive_handle->offset++;
|
2001-10-25 19:48:08 +05:30
|
|
|
}
|
2002-09-25 08:17:48 +05:30
|
|
|
archive_handle->offset += 60;
|
2003-07-31 07:23:50 +05:30
|
|
|
|
2006-12-26 23:47:42 +05:30
|
|
|
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("invalid ar header");
|
2002-09-25 08:17:48 +05:30
|
|
|
|
2013-09-10 19:57:08 +05:30
|
|
|
/*
|
|
|
|
* Note that the fields MUST be read in reverse order as
|
|
|
|
* read_num() clobbers the next byte after the field!
|
|
|
|
* Order is: name, date, uid, gid, mode, size, magic.
|
|
|
|
*/
|
2013-09-10 15:22:35 +05:30
|
|
|
typed->size = size = read_num(ar.formatted.size, 10,
|
|
|
|
sizeof(ar.formatted.size));
|
2001-10-25 19:48:08 +05:30
|
|
|
|
2009-09-20 04:58:27 +05:30
|
|
|
/* special filenames have '/' as the first character */
|
2006-07-21 00:32:24 +05:30
|
|
|
if (ar.formatted.name[0] == '/') {
|
2009-09-20 04:58:27 +05:30
|
|
|
if (ar.formatted.name[1] == ' ') {
|
|
|
|
/* This is the index of symbols in the file for compilers */
|
|
|
|
data_skip(archive_handle);
|
|
|
|
archive_handle->offset += size;
|
|
|
|
return get_header_ar(archive_handle); /* Return next header */
|
|
|
|
}
|
2007-03-20 02:29:20 +05:30
|
|
|
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
2006-07-21 00:32:24 +05:30
|
|
|
if (ar.formatted.name[1] == '/') {
|
2001-10-25 19:48:08 +05:30
|
|
|
/* If the second char is a '/' then this entries data section
|
|
|
|
* stores long filename for multiple entries, they are stored
|
2009-09-20 04:58:27 +05:30
|
|
|
* in static variable long_names for use in future entries
|
|
|
|
*/
|
2018-04-15 17:48:16 +05:30
|
|
|
archive_handle->ar__long_name_size = size;
|
|
|
|
free(archive_handle->ar__long_names);
|
|
|
|
archive_handle->ar__long_names = xzalloc(size + 1);
|
|
|
|
xread(archive_handle->src_fd, archive_handle->ar__long_names, size);
|
2009-09-20 04:58:27 +05:30
|
|
|
archive_handle->offset += size;
|
|
|
|
/* Return next header */
|
|
|
|
return get_header_ar(archive_handle);
|
2007-03-15 03:38:53 +05:30
|
|
|
}
|
2009-09-20 04:58:27 +05:30
|
|
|
#else
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("long filenames not supported");
|
2009-09-20 04:58:27 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* Only size is always present, the rest may be missing in
|
|
|
|
* long filename pseudo file. Thus we decode the rest
|
|
|
|
* after dealing with long filename pseudo file.
|
|
|
|
*/
|
2013-09-10 15:22:35 +05:30
|
|
|
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
|
|
|
|
typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
|
|
|
|
typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
|
|
|
|
typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
|
2007-03-15 03:38:53 +05:30
|
|
|
|
2009-09-20 04:58:27 +05:30
|
|
|
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
|
|
|
if (ar.formatted.name[0] == '/') {
|
|
|
|
unsigned long_offset;
|
2007-03-15 03:38:53 +05:30
|
|
|
|
|
|
|
/* The number after the '/' indicates the offset in the ar data section
|
2018-04-15 17:48:16 +05:30
|
|
|
* (saved in ar__long_names) that contains the real filename */
|
2013-09-10 15:22:35 +05:30
|
|
|
long_offset = read_num(&ar.formatted.name[1], 10,
|
|
|
|
sizeof(ar.formatted.name) - 1);
|
2018-04-15 17:48:16 +05:30
|
|
|
if (long_offset >= archive_handle->ar__long_name_size) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_error_msg_and_die("can't resolve long filename");
|
2007-03-15 03:38:53 +05:30
|
|
|
}
|
2018-04-15 17:48:16 +05:30
|
|
|
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
|
2009-09-20 04:58:27 +05:30
|
|
|
} else
|
2002-09-25 08:17:48 +05:30
|
|
|
#endif
|
2009-09-20 04:58:27 +05:30
|
|
|
{
|
2001-10-25 19:48:08 +05:30
|
|
|
/* short filenames */
|
2006-11-24 22:51:44 +05:30
|
|
|
typed->name = xstrndup(ar.formatted.name, 16);
|
2001-10-25 19:48:08 +05:30
|
|
|
}
|
|
|
|
|
2002-09-25 08:17:48 +05:30
|
|
|
typed->name[strcspn(typed->name, " /")] = '\0';
|
|
|
|
|
2002-11-05 05:17:31 +05:30
|
|
|
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
2002-09-25 08:17:48 +05:30
|
|
|
archive_handle->action_header(typed);
|
2008-07-11 04:36:00 +05:30
|
|
|
#if ENABLE_DPKG || ENABLE_DPKG_DEB
|
2010-01-06 15:23:17 +05:30
|
|
|
if (archive_handle->dpkg__sub_archive) {
|
2018-04-13 16:56:33 +05:30
|
|
|
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
|
|
|
|
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
|
2008-06-28 10:34:09 +05:30
|
|
|
continue;
|
2018-05-22 21:04:31 +05:30
|
|
|
create_links_from_list(sa->link_placeholders);
|
2008-07-11 04:36:00 +05:30
|
|
|
} else
|
|
|
|
#endif
|
2002-09-25 08:17:48 +05:30
|
|
|
archive_handle->action_data(archive_handle);
|
|
|
|
} else {
|
2004-03-15 13:59:22 +05:30
|
|
|
data_skip(archive_handle);
|
2002-09-25 08:17:48 +05:30
|
|
|
}
|
|
|
|
|
2003-07-31 07:23:50 +05:30
|
|
|
archive_handle->offset += typed->size;
|
|
|
|
/* Set the file pointer to the correct spot, we may have been reading a compressed file */
|
|
|
|
lseek(archive_handle->src_fd, archive_handle->offset, SEEK_SET);
|
2001-10-25 19:48:08 +05:30
|
|
|
|
2006-11-27 22:19:31 +05:30
|
|
|
return EXIT_SUCCESS;
|
2002-07-11 16:41:56 +05:30
|
|
|
}
|