Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e73f3c1d3d |
No files matched your search
@@ -35,10 +35,3 @@ Config.in
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
#
|
||||
# testing output
|
||||
#
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
@@ -161,13 +161,12 @@ config UNICODE_USING_LOCALE
|
||||
Internal implementation is smaller.
|
||||
|
||||
config FEATURE_CHECK_UNICODE_IN_ENV
|
||||
bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables"
|
||||
bool "Check $LANG environment variable"
|
||||
default n
|
||||
depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE
|
||||
help
|
||||
With this option on, Unicode support is activated
|
||||
only if locale-related variables have the value of the form
|
||||
"xxxx.utf8"
|
||||
only if LANG variable has the value of the form "xxxx.utf8"
|
||||
|
||||
Otherwise, Unicode support will be always enabled and active.
|
||||
|
||||
@@ -257,26 +256,6 @@ config UNICODE_PRESERVE_BROKEN
|
||||
at shell prompt will list file named 0xff (single char name
|
||||
with char value 255), not file named '?'.
|
||||
|
||||
config PAM
|
||||
bool "Support for PAM (Pluggable Authentication Modules)"
|
||||
default n
|
||||
help
|
||||
Use PAM in some busybox applets (currently login and httpd) instead
|
||||
of direct access to password database.
|
||||
|
||||
config FEATURE_USE_SENDFILE
|
||||
bool "Use sendfile system call"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
When enabled, busybox will use the kernel sendfile() function
|
||||
instead of read/write loops to copy data between file descriptors
|
||||
(for example, cp command does this a lot).
|
||||
If sendfile() doesn't work, copying code falls back to read/write
|
||||
loop. sendfile() was originally implemented for faster I/O
|
||||
from files to sockets, but since Linux 2.6.33 it was extended
|
||||
to work for many more file types.
|
||||
|
||||
config LONG_OPTS
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
@@ -436,7 +415,10 @@ config SELINUX
|
||||
the option of compiling in SELinux applets.
|
||||
|
||||
If you do not have a complete SELinux userland installed, this stuff
|
||||
will not compile. Specifially, libselinux 1.28 or better is
|
||||
will not compile. Go visit
|
||||
http://www.nsa.gov/selinux/index.html
|
||||
to download the necessary stuff to allow busybox to compile with
|
||||
this option enabled. Specifially, libselinux 1.28 or better is
|
||||
directly required by busybox. If the installation is located in a
|
||||
non-standard directory, provide it by invoking make as follows:
|
||||
CFLAGS=-I<libselinux-include-path> \
|
||||
@@ -688,14 +670,6 @@ config DEBUG_PESSIMIZE
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
config UNIT_TEST
|
||||
bool "Build unit tests"
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to build unit tests (both the framework and
|
||||
test cases) as a Busybox applet. This results in bigger code, so you
|
||||
probably don't want this option in production builds.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 23
|
||||
SUBLEVEL = 2
|
||||
PATCHLEVEL = 21
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
+1
-14
@@ -3,12 +3,7 @@
|
||||
# ==========================================================================
|
||||
|
||||
busybox.links: $(srctree)/applets/busybox.mkll $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-$(SHELL) $^ > $@
|
||||
|
||||
busybox.cfg.suid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-SUID="yes" $(SHELL) $^ > $@
|
||||
busybox.cfg.nosuid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autoconf.h include/applets.h
|
||||
$(Q)-SUID="DROP" $(SHELL) $^ > $@
|
||||
$(Q)-$(SHELL) $^ >$@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
@@ -55,11 +50,7 @@ endif
|
||||
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
|
||||
.PHONY: check
|
||||
.PHONY: test
|
||||
ifeq ($(CONFIG_UNIT_TEST),y)
|
||||
UNIT_CMD = ./busybox unit
|
||||
endif
|
||||
check test: busybox busybox.links
|
||||
$(UNIT_CMD)
|
||||
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite \
|
||||
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
|
||||
@@ -77,10 +68,6 @@ release: distclean
|
||||
-name .git \
|
||||
-print \
|
||||
-exec rm -r -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \
|
||||
-name .gitignore \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
|
||||
@@ -21,6 +21,10 @@ help:
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@echo ' oldconfig - resolve any unresolved symbols in .config'
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@$(if $(boards), \
|
||||
$(foreach b, $(boards), \
|
||||
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
|
||||
|
||||
@@ -127,6 +127,20 @@ patch
|
||||
|
||||
And while we're at it, a new patch filename quoting format is apparently
|
||||
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
|
||||
---
|
||||
stty / catv
|
||||
stty's visible() function and catv's guts are identical. Merge them into
|
||||
an appropriate libbb function.
|
||||
---
|
||||
struct suffix_mult
|
||||
Several duplicate users of: grep -r "1024\*1024" * -B2 -A1
|
||||
Merge to a single size_suffixes[] in libbb.
|
||||
Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd
|
||||
---
|
||||
tail
|
||||
./busybox tail -f foo.c~ TODO
|
||||
should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
|
||||
fmt+ if another (not the current) file did change
|
||||
|
||||
Architectural issues:
|
||||
|
||||
@@ -219,6 +233,8 @@ Minor stuff:
|
||||
---
|
||||
See grep -r strtod
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
in_ether duplicated in network/{interface,ifconfig}.c
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
---
|
||||
|
||||
+5
-22
@@ -14,7 +14,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#undef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||
@@ -50,21 +49,11 @@ static int cmp_name(const void *a, const void *b)
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int ofs;
|
||||
// unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
@@ -100,17 +89,11 @@ int main(int argc, char **argv)
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
// if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
// MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
}
|
||||
printf(";\n\n");
|
||||
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
if (str_isalnum_(applets[i].name))
|
||||
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
@@ -147,8 +130,8 @@ int main(int argc, char **argv)
|
||||
printf("};\n");
|
||||
#endif
|
||||
//printf("#endif /* SKIP_definitions */\n");
|
||||
// printf("\n");
|
||||
// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
printf("\n");
|
||||
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
if (argv[2]) {
|
||||
char line_old[80];
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Make list of configuration variables regarding suid handling
|
||||
|
||||
# input $1: full path to autoconf.h
|
||||
# input $2: full path to applets.h
|
||||
# input $3: full path to .config
|
||||
# output (stdout): list of CONFIG_ that do or may require suid
|
||||
|
||||
# If the environment variable SUID is not set or set to DROP,
|
||||
# lists all config options that do not require suid permissions.
|
||||
# Otherwise, lists all config options for applets that DO or MAY require
|
||||
# suid permissions.
|
||||
|
||||
# Maintainer: Bernhard Reutner-Fischer
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
DOT_CONFIG=${3:-.config}
|
||||
|
||||
case ${SUID:-DROP} in
|
||||
[dD][rR][oO][pP]) USE="DROP" ;;
|
||||
*) USE="suid" ;;
|
||||
esac
|
||||
|
||||
$HOSTCC -E -DMAKE_SUID -include $CONFIG_H $APPLETS_H |
|
||||
awk -v USE=${USE} '
|
||||
/^SUID[ \t]/{
|
||||
if (USE == "DROP") {
|
||||
if ($2 != "BB_SUID_DROP") next
|
||||
} else {
|
||||
if ($2 == "BB_SUID_DROP") next
|
||||
}
|
||||
cfg = $NF
|
||||
gsub("\"", "", cfg)
|
||||
cfg = substr(cfg, 8)
|
||||
s[i++] = "CONFIG_" cfg
|
||||
s[i++] = "CONFIG_FEATURE_" cfg "_.*"
|
||||
}
|
||||
END{
|
||||
while (getline < ARGV[2]) {
|
||||
for (j in s) {
|
||||
if ($0 ~ "^" s[j] "=y$") {
|
||||
sub(/=.*/, "")
|
||||
print
|
||||
if (s[j] !~ /\*$/) delete s[j] # can drop this applet now
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
' - $DOT_CONFIG
|
||||
|
||||
@@ -10,20 +10,20 @@ test "$SED" || SED=sed
|
||||
test "$DD" || DD=dd
|
||||
|
||||
# Some people were bitten by their system lacking a (proper) od
|
||||
od -v -b </dev/null >/dev/null
|
||||
od -v -t x1 </dev/null >/dev/null
|
||||
if test $? != 0; then
|
||||
echo 'od tool is not installed or cannot accept "-v -b" options'
|
||||
echo 'od tool is not installed or cannot accept "-v -t x1" options'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec >"$target.$$"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -b \
|
||||
"$loc/usage" | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(...\)/\\\1/g' \
|
||||
-e 's/\(..\)/\\x\1/g' \
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
@@ -39,11 +39,11 @@ echo '#define PACKED_USAGE \'
|
||||
## -e '/^$/d' \
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/$/ \\/'
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(...\)/0\1,/g' \
|
||||
-e 's/\(..\)/0x\1,/g' \
|
||||
-e 's/$/ \\/'
|
||||
echo ''
|
||||
|
||||
|
||||
+349
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
INSERT
|
||||
|
||||
config FEATURE_SEAMLESS_XZ
|
||||
bool "Make tar, rpm, modprobe etc understand .xz data"
|
||||
default y
|
||||
@@ -35,6 +37,352 @@ config FEATURE_SEAMLESS_Z
|
||||
help
|
||||
Make tar, rpm, modprobe etc understand .Z data.
|
||||
|
||||
INSERT
|
||||
config AR
|
||||
bool "ar"
|
||||
default n # needs to be improved to be able to replace binutils ar
|
||||
help
|
||||
ar is an archival utility program used to create, modify, and
|
||||
extract contents from archives. An archive is a single file holding
|
||||
a collection of other files in a structure that makes it possible to
|
||||
retrieve the original individual files (called archive members).
|
||||
The original files' contents, mode (permissions), timestamp, owner,
|
||||
and group are preserved in the archive, and can be restored on
|
||||
extraction.
|
||||
|
||||
The stored filename is limited to 15 characters. (for more information
|
||||
see long filename support).
|
||||
ar has 60 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of ar can extract archives, it cannot create or
|
||||
modify them.
|
||||
On an x86 system, the ar applet adds about 1K.
|
||||
|
||||
Unless you have a specific application which requires ar, you should
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Support for long filenames (not needed for debs)"
|
||||
default y
|
||||
depends on AR
|
||||
help
|
||||
By default the ar format can only store the first 15 characters
|
||||
of the filename, this option removes that limitation.
|
||||
It supports the GNU ar long filename method which moves multiple long
|
||||
filenames into a the data section of a new ar entry.
|
||||
|
||||
config FEATURE_AR_CREATE
|
||||
bool "Support archive creation"
|
||||
default y
|
||||
depends on AR
|
||||
help
|
||||
This enables archive creation (-c and -r) with busybox ar.
|
||||
|
||||
config BUNZIP2
|
||||
bool "bunzip2"
|
||||
default y
|
||||
help
|
||||
bunzip2 is a compression utility using the Burrows-Wheeler block
|
||||
sorting text compression algorithm, and Huffman coding. Compression
|
||||
is generally considerably better than that achieved by more
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
Unless you have a specific application which requires bunzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config BZIP2
|
||||
bool "bzip2"
|
||||
default y
|
||||
help
|
||||
bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
sorting text compression algorithm, and Huffman coding. Compression
|
||||
is generally considerably better than that achieved by more
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
Unless you have a specific application which requires bzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config CPIO
|
||||
bool "cpio"
|
||||
default y
|
||||
help
|
||||
cpio is an archival utility program used to create, modify, and
|
||||
extract contents from archives.
|
||||
cpio has 110 bytes of overheads for every stored file.
|
||||
|
||||
This implementation of cpio can extract cpio archives created in the
|
||||
"newc" or "crc" format, it cannot create or modify them.
|
||||
|
||||
Unless you have a specific application which requires cpio, you
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_CPIO_O
|
||||
bool "Support for archive creation"
|
||||
default y
|
||||
depends on CPIO
|
||||
help
|
||||
This implementation of cpio can create cpio archives in the "newc"
|
||||
format only.
|
||||
|
||||
config FEATURE_CPIO_P
|
||||
bool "Support for passthrough mode"
|
||||
default y
|
||||
depends on FEATURE_CPIO_O
|
||||
help
|
||||
Passthrough mode. Rarely used.
|
||||
|
||||
config DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg is a medium-level tool to install, build, remove and manage
|
||||
Debian packages.
|
||||
|
||||
This implementation of dpkg has a number of limitations,
|
||||
you should use the official dpkg if possible.
|
||||
|
||||
config DPKG_DEB
|
||||
bool "dpkg_deb"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg-deb unpacks and provides information about Debian archives.
|
||||
|
||||
This implementation of dpkg-deb cannot pack archives.
|
||||
|
||||
Unless you have a specific application which requires dpkg-deb,
|
||||
say N here.
|
||||
|
||||
config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool "Extract only (-x)"
|
||||
default n
|
||||
depends on DPKG_DEB
|
||||
help
|
||||
This reduces dpkg-deb to the equivalent of
|
||||
"ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
|
||||
of the extra dpkg-deb, ar or tar options are needed, they are linked
|
||||
to internally.
|
||||
|
||||
config GUNZIP
|
||||
bool "gunzip"
|
||||
default y
|
||||
help
|
||||
gunzip is used to decompress archives created by gzip.
|
||||
You can use the `-t' option to test the integrity of
|
||||
an archive, without decompressing it.
|
||||
|
||||
config GZIP
|
||||
bool "gzip"
|
||||
default y
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config FEATURE_GZIP_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default y
|
||||
depends on GZIP && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 106 Bytes
|
||||
|
||||
config GZIP_FAST
|
||||
int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
|
||||
default 0
|
||||
range 0 2
|
||||
depends on GZIP
|
||||
help
|
||||
Enable big memory options for gzip.
|
||||
0: small buffers, small hash-tables
|
||||
1: larger buffers, larger hash-tables
|
||||
2: larger buffers, largest hash-tables
|
||||
Larger models may give slightly better compression
|
||||
|
||||
config LZOP
|
||||
bool "lzop"
|
||||
default y
|
||||
help
|
||||
Lzop compression/decompresion.
|
||||
|
||||
config LZOP_COMPR_HIGH
|
||||
bool "lzop compression levels 7,8,9 (not very useful)"
|
||||
default n
|
||||
depends on LZOP
|
||||
help
|
||||
High levels (7,8,9) of lzop compression. These levels
|
||||
are actually slower than gzip at equivalent compression ratios
|
||||
and take up 3.2K of code.
|
||||
|
||||
config RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default y
|
||||
help
|
||||
Converts a RPM file into a CPIO archive.
|
||||
|
||||
config RPM
|
||||
bool "rpm"
|
||||
default y
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
config TAR
|
||||
bool "tar"
|
||||
default y
|
||||
help
|
||||
tar is an archiving program. It's commonly used with gzip to
|
||||
create compressed archives. It's probably the most widely used
|
||||
UNIX archive program.
|
||||
|
||||
config FEATURE_TAR_CREATE
|
||||
bool "Enable archive creation"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to create
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config FEATURE_TAR_AUTODETECT
|
||||
bool "Autodetect compressed tarballs"
|
||||
default y
|
||||
depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
|
||||
help
|
||||
With this option tar can automatically detect compressed
|
||||
tarballs. Currently it works only on files (not pipes etc).
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
bool "Support for old tar header format"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
This option is required to unpack archives created in
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
This option is required to unpack archives created by some old
|
||||
version of Sun's tar (it was calculating checksum using signed
|
||||
arithmetic). It is said to be fixed in newer Sun tar, but "old"
|
||||
tarballs still exist.
|
||||
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Support for GNU tar extensions (long filenames)"
|
||||
default y
|
||||
depends on TAR || DPKG
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default y
|
||||
depends on TAR && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config FEATURE_TAR_TO_COMMAND
|
||||
bool "Support for writing to an external program"
|
||||
default y
|
||||
depends on TAR && FEATURE_TAR_LONG_OPTIONS
|
||||
help
|
||||
If you enable this option you'll be able to instruct tar to send
|
||||
the contents of each extracted file to the standard input of an
|
||||
external program.
|
||||
|
||||
config FEATURE_TAR_UNAME_GNAME
|
||||
bool "Enable use of user and group names"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
Enables use of user and group names in tar. This affects contents
|
||||
listings (-t) and preserving permissions when unpacking (-p).
|
||||
+200 bytes.
|
||||
|
||||
config FEATURE_TAR_NOPRESERVE_TIME
|
||||
bool "Enable -m (do not preserve time) option"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
With this option busybox supports GNU tar -m
|
||||
(do not preserve time) option.
|
||||
|
||||
config FEATURE_TAR_SELINUX
|
||||
bool "Support for extracting SELinux labels"
|
||||
default n
|
||||
depends on TAR && SELINUX
|
||||
help
|
||||
With this option busybox supports restoring SELinux labels
|
||||
when extracting files from tar archives.
|
||||
|
||||
config UNCOMPRESS
|
||||
bool "uncompress"
|
||||
default n
|
||||
help
|
||||
uncompress is used to decompress archives created by compress.
|
||||
Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
config UNLZMA
|
||||
bool "unlzma"
|
||||
default y
|
||||
help
|
||||
unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
compression algorithm, and range coding. Compression
|
||||
is generally considerably better than that achieved by the bzip2
|
||||
compressors.
|
||||
|
||||
The BusyBox unlzma applet is limited to decompression only.
|
||||
On an x86 system, this applet adds about 4K.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimize unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 25% at the cost of
|
||||
a 1K bigger binary.
|
||||
|
||||
config LZMA
|
||||
bool "Provide lzma alias which supports only unpacking"
|
||||
default y
|
||||
depends on UNLZMA
|
||||
help
|
||||
Enable this option if you want commands like "lzma -d" to work.
|
||||
IOW: you'll get lzma applet, but it will always require -d option.
|
||||
|
||||
config UNXZ
|
||||
bool "unxz"
|
||||
default y
|
||||
help
|
||||
unxz is a unlzma successor.
|
||||
|
||||
config XZ
|
||||
bool "Provide xz alias which supports only unpacking"
|
||||
default y
|
||||
depends on UNXZ
|
||||
help
|
||||
Enable this option if you want commands like "xz -d" to work.
|
||||
IOW: you'll get xz applet, but it will always require -d option.
|
||||
|
||||
config UNZIP
|
||||
bool "unzip"
|
||||
default y
|
||||
help
|
||||
unzip will list or extract files from a ZIP archive,
|
||||
commonly found on DOS/WIN systems. The default behavior
|
||||
(with no options) is to extract the archive into the
|
||||
current directory. Use the `-d' option to extract to a
|
||||
directory of your choice.
|
||||
|
||||
endmenu
|
||||
@@ -9,3 +9,22 @@ libs-y += libarchive/
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
|
||||
|
||||
lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
@@ -17,49 +17,6 @@
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
|
||||
//config:config AR
|
||||
//config: bool "ar"
|
||||
//config: default n # needs to be improved to be able to replace binutils ar
|
||||
//config: help
|
||||
//config: ar is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives. An archive is a single file holding
|
||||
//config: a collection of other files in a structure that makes it possible to
|
||||
//config: retrieve the original individual files (called archive members).
|
||||
//config: The original files' contents, mode (permissions), timestamp, owner,
|
||||
//config: and group are preserved in the archive, and can be restored on
|
||||
//config: extraction.
|
||||
//config:
|
||||
//config: The stored filename is limited to 15 characters. (for more information
|
||||
//config: see long filename support).
|
||||
//config: ar has 60 bytes of overheads for every stored file.
|
||||
//config:
|
||||
//config: This implementation of ar can extract archives, it cannot create or
|
||||
//config: modify them.
|
||||
//config: On an x86 system, the ar applet adds about 1K.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires ar, you should
|
||||
//config: probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_AR_LONG_FILENAMES
|
||||
//config: bool "Support for long filenames (not needed for debs)"
|
||||
//config: default y
|
||||
//config: depends on AR
|
||||
//config: help
|
||||
//config: By default the ar format can only store the first 15 characters
|
||||
//config: of the filename, this option removes that limitation.
|
||||
//config: It supports the GNU ar long filename method which moves multiple long
|
||||
//config: filenames into a the data section of a new ar entry.
|
||||
//config:
|
||||
//config:config FEATURE_AR_CREATE
|
||||
//config: bool "Support archive creation"
|
||||
//config: default y
|
||||
//config: depends on AR
|
||||
//config: help
|
||||
//config: This enables archive creation (-c and -r) with busybox ar.
|
||||
|
||||
//applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_AR) += ar.o
|
||||
|
||||
//usage:#define ar_trivial_usage
|
||||
//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
|
||||
//usage:#define ar_full_usage "\n\n"
|
||||
|
||||
+78
-177
@@ -7,19 +7,13 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
/* lzop_main() uses bbunpack(), need this: */
|
||||
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
|
||||
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
OPT_STDOUT = 1 << 0,
|
||||
OPT_FORCE = 1 << 1,
|
||||
/* only some decompressors: */
|
||||
OPT_VERBOSE = 1 << 2,
|
||||
OPT_QUIET = 1 << 3,
|
||||
OPT_DECOMPRESS = 1 << 4,
|
||||
OPT_TEST = 1 << 5,
|
||||
SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
|
||||
OPT_DECOMPRESS = 1 << 3,
|
||||
OPT_TEST = 1 << 4,
|
||||
};
|
||||
|
||||
static
|
||||
@@ -39,16 +33,16 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
||||
}
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
IF_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_state_t xstate;
|
||||
transformer_aux_data_t aux;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -60,28 +54,13 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
err_name:
|
||||
bb_simple_perror_msg(filename);
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_simple_perror_msg(filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
} else {
|
||||
/* "clever zcat" with FILE */
|
||||
/* fail_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
} else
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -89,7 +68,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
||||
if (option_mask32 & OPT_TEST)
|
||||
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
||||
xfunc_die();
|
||||
goto err;
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
@@ -114,39 +93,28 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = 1;
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
xstate.dst_fd = STDOUT_FILENO;
|
||||
status = unpacker(&xstate);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
} else {
|
||||
if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0)
|
||||
/* Disk full, tty closed, etc. No point in continuing */
|
||||
xfunc_die();
|
||||
}
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
|
||||
if (!(option_mask32 & OPT_STDOUT))
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
|
||||
if (status >= 0) {
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (xstate.mtime != 0) {
|
||||
if (aux.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
|
||||
times[1].tv_sec = times[0].tv_sec = aux.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
@@ -155,29 +123,22 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
utimes(new_name, times); /* ignoring errors */
|
||||
}
|
||||
|
||||
if (ENABLE_DESKTOP)
|
||||
new_name_len = strlen(new_name);
|
||||
/* Restore source filename (unless tgz -> tar case) */
|
||||
if (new_name == filename) {
|
||||
new_name_len = strlen(filename);
|
||||
filename[new_name_len] = '.';
|
||||
}
|
||||
/* Extreme bloat for gunzip compat */
|
||||
/* Some users do want this info... */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
|
||||
unsigned percent = status
|
||||
? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
|
||||
: 0;
|
||||
fprintf(stderr, "%s: %u%% - replaced with %.*s\n",
|
||||
filename,
|
||||
100u - percent,
|
||||
new_name_len, new_name
|
||||
);
|
||||
}
|
||||
/* Delete _source_ file */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
xunlink(del);
|
||||
|
||||
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
|
||||
/* Extreme bloat for gunzip compat */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
free_name:
|
||||
if (new_name != filename)
|
||||
free(new_name);
|
||||
@@ -211,6 +172,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//usage:#define uncompress_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define uncompress_full_usage "\n\n"
|
||||
@@ -218,23 +180,19 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Overwrite"
|
||||
|
||||
//config:config UNCOMPRESS
|
||||
//config: bool "uncompress"
|
||||
//config: default n
|
||||
//config: help
|
||||
//config: uncompress is used to decompress archives created by compress.
|
||||
//config: Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
|
||||
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -262,7 +220,11 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
//usage:#define gunzip_trivial_usage
|
||||
//usage: "[-cft] [FILE]..."
|
||||
//usage:#define gunzip_full_usage "\n\n"
|
||||
@@ -279,22 +241,10 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n"
|
||||
//usage:
|
||||
//usage:#define zcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage: "FILE"
|
||||
//usage:#define zcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config GUNZIP
|
||||
//config: bool "gunzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: gunzip is used to decompress archives created by gzip.
|
||||
//config: You can use the `-t' option to test the integrity of
|
||||
//config: an archive, without decompressing it.
|
||||
|
||||
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
#if ENABLE_GUNZIP
|
||||
static
|
||||
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
@@ -321,6 +271,11 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -337,17 +292,13 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvqdtn");
|
||||
getopt32(argv, "cfvdtn");
|
||||
argv += optind;
|
||||
|
||||
/* If called as zcat...
|
||||
* Normally, "zcat" is just "gunzip -c".
|
||||
* But if seamless magic is enabled, then we are much more clever.
|
||||
*/
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -365,37 +316,26 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage:#define bzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage: "FILE"
|
||||
//usage:#define bzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config BUNZIP2
|
||||
//config: bool "bunzip2"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
|
||||
//config: sorting text compression algorithm, and Huffman coding. Compression
|
||||
//config: is generally considerably better than that achieved by more
|
||||
//config: conventional LZ77/LZ78-based compressors, and approaches the
|
||||
//config: performance of the PPM family of statistical compressors.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires bunzip2, you
|
||||
//config: should probably say N here.
|
||||
|
||||
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvqdt");
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -408,6 +348,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//usage:#define unlzma_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define unlzma_full_usage "\n\n"
|
||||
@@ -424,7 +365,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -f Force"
|
||||
//usage:
|
||||
//usage:#define lzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage: "FILE"
|
||||
//usage:#define lzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
//usage:
|
||||
@@ -444,47 +385,20 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -f Force"
|
||||
//usage:
|
||||
//usage:#define xzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage: "FILE"
|
||||
//usage:#define xzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNLZMA
|
||||
//config: bool "unlzma"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
//config: compression algorithm, and range coding. Compression
|
||||
//config: is generally considerably better than that achieved by the bzip2
|
||||
//config: compressors.
|
||||
//config:
|
||||
//config: The BusyBox unlzma applet is limited to decompression only.
|
||||
//config: On an x86 system, this applet adds about 4K.
|
||||
//config:
|
||||
//config:config FEATURE_LZMA_FAST
|
||||
//config: bool "Optimize unlzma for speed"
|
||||
//config: default n
|
||||
//config: depends on UNLZMA
|
||||
//config: help
|
||||
//config: This option reduces decompression time by about 25% at the cost of
|
||||
//config: a 1K bigger binary.
|
||||
//config:
|
||||
//config:config LZMA
|
||||
//config: bool "Provide lzma alias which supports only unpacking"
|
||||
//config: default y
|
||||
//config: depends on UNLZMA
|
||||
//config: help
|
||||
//config: Enable this option if you want commands like "lzma -d" to work.
|
||||
//config: IOW: you'll get lzma applet, but it will always require -d option.
|
||||
|
||||
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
|
||||
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfvqdt");
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfvdt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
@@ -495,34 +409,21 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//config:config UNXZ
|
||||
//config: bool "unxz"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unxz is a unlzma successor.
|
||||
//config:
|
||||
//config:config XZ
|
||||
//config: bool "Provide xz alias which supports only unpacking"
|
||||
//config: default y
|
||||
//config: depends on UNXZ
|
||||
//config: help
|
||||
//config: Enable this option if you want commands like "xz -d" to work.
|
||||
//config: IOW: you'll get xz applet, but it will always require -d option.
|
||||
|
||||
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
|
||||
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_XZ(int opts =) getopt32(argv, "cfvqdt");
|
||||
IF_XZ(int opts =) getopt32(argv, "cfvdt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
@@ -533,6 +434,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
|
||||
}
|
||||
#endif
|
||||
+1
-17
@@ -7,22 +7,6 @@
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
|
||||
//config:config BZIP2
|
||||
//config: bool "bzip2"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
//config: sorting text compression algorithm, and Huffman coding. Compression
|
||||
//config: is generally considerably better than that achieved by more
|
||||
//config: conventional LZ77/LZ78-based compressors, and approaches the
|
||||
//config: performance of the PPM family of statistical compressors.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires bzip2, you
|
||||
//config: should probably say N here.
|
||||
|
||||
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
|
||||
|
||||
//usage:#define bzip2_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define bzip2_full_usage "\n\n"
|
||||
@@ -127,7 +111,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
|
||||
+1
-33
@@ -9,42 +9,11 @@
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
//config:config CPIO
|
||||
//config: bool "cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cpio is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives.
|
||||
//config: cpio has 110 bytes of overheads for every stored file.
|
||||
//config:
|
||||
//config: This implementation of cpio can extract cpio archives created in the
|
||||
//config: "newc" or "crc" format, it cannot create or modify them.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires cpio, you
|
||||
//config: should probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_O
|
||||
//config: bool "Support for archive creation"
|
||||
//config: default y
|
||||
//config: depends on CPIO
|
||||
//config: help
|
||||
//config: This implementation of cpio can create cpio archives in the "newc"
|
||||
//config: format only.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_P
|
||||
//config: bool "Support for passthrough mode"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O
|
||||
//config: help
|
||||
//config: Passthrough mode. Rarely used.
|
||||
|
||||
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
|
||||
|
||||
//usage:#define cpio_trivial_usage
|
||||
//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
|
||||
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
|
||||
@@ -65,7 +34,6 @@
|
||||
//usage: IF_FEATURE_CPIO_P(
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: "\n -d Make leading directories"
|
||||
//usage: "\n -m Preserve mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
|
||||
+2
-14
@@ -14,6 +14,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* known difference between busybox dpkg and the official dpkg that i don't
|
||||
* consider important, its worth keeping a note of differences anyway, just to
|
||||
@@ -24,22 +25,9 @@
|
||||
*
|
||||
* bugs that need to be fixed
|
||||
* - (unknown, please let me know when you find any)
|
||||
*
|
||||
*/
|
||||
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg"
|
||||
//config: default n
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
//config: Debian packages.
|
||||
//config:
|
||||
//config: This implementation of dpkg has a number of limitations,
|
||||
//config: you should use the official dpkg if possible.
|
||||
|
||||
//applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
|
||||
|
||||
//usage:#define dpkg_trivial_usage
|
||||
//usage: "[-ilCPru] [-F OPT] PACKAGE"
|
||||
//usage:#define dpkg_full_usage "\n\n"
|
||||
|
||||
+1
-26
@@ -5,33 +5,8 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default n
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
//config:
|
||||
//config: This implementation of dpkg-deb cannot pack archives.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires dpkg-deb,
|
||||
//config: say N here.
|
||||
//config:
|
||||
//config:config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
//config: bool "Extract only (-x)"
|
||||
//config: default n
|
||||
//config: depends on DPKG_DEB
|
||||
//config: help
|
||||
//config: This reduces dpkg-deb to the equivalent of
|
||||
//config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
|
||||
//config: of the extra dpkg-deb, ar or tar options are needed, they are linked
|
||||
//config: to internally.
|
||||
|
||||
//applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
|
||||
//kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
|
||||
//usage:#define dpkg_deb_trivial_usage
|
||||
//usage: "[-cefxX] FILE [argument]"
|
||||
//usage: "[-cefxX] FILE [argument"
|
||||
//usage:#define dpkg_deb_full_usage "\n\n"
|
||||
//usage: "Perform actions on Debian packages (.debs)\n"
|
||||
//usage: "\n -c List contents of filesystem tree"
|
||||
|
||||
+3
-30
@@ -15,6 +15,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* big objects in bss:
|
||||
* 00000020 b bl_count
|
||||
* 00000074 b base_length
|
||||
@@ -30,6 +31,7 @@
|
||||
* 00000480 b static_ltree
|
||||
* 000008f4 b dyn_ltree
|
||||
*/
|
||||
|
||||
/* TODO: full support for -v for DESKTOP
|
||||
* "/usr/bin/gzip -v a bogus aa" should say:
|
||||
a: 85.1% -- replaced with a.gz
|
||||
@@ -37,35 +39,6 @@ gzip: bogus: No such file or directory
|
||||
aa: 85.1% -- replaced with aa.gz
|
||||
*/
|
||||
|
||||
//config:config GZIP
|
||||
//config: bool "gzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: gzip is used to compress files.
|
||||
//config: It's probably the most widely used UNIX compression program.
|
||||
//config:
|
||||
//config:config FEATURE_GZIP_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on GZIP && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options, increases size by about 106 Bytes
|
||||
//config:
|
||||
//config:config GZIP_FAST
|
||||
//config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
|
||||
//config: default 0
|
||||
//config: range 0 2
|
||||
//config: depends on GZIP
|
||||
//config: help
|
||||
//config: Enable big memory options for gzip.
|
||||
//config: 0: small buffers, small hash-tables
|
||||
//config: 1: larger buffers, larger hash-tables
|
||||
//config: 2: larger buffers, largest hash-tables
|
||||
//config: Larger models may give slightly better compression
|
||||
|
||||
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
|
||||
|
||||
//usage:#define gzip_trivial_usage
|
||||
//usage: "[-cfd] [FILE]..."
|
||||
//usage:#define gzip_full_usage "\n\n"
|
||||
@@ -2042,7 +2015,7 @@ static void zip(ulg time_stamp)
|
||||
|
||||
/* ======================================================================== */
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
|
||||
@@ -38,45 +38,31 @@ DPKG_FILES:= \
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_UNXZ) += decompress_unxz.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += decompress_gunzip.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
lib-$(CONFIG_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_LZOP) += open_transformer.o
|
||||
lib-$(CONFIG_MAN) += open_transformer.o
|
||||
lib-$(CONFIG_SETFONT) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_2_4_MODULES) += open_transformer.o
|
||||
lib-$(CONFIG_MODINFO) += open_transformer.o
|
||||
lib-$(CONFIG_INSMOD) += open_transformer.o
|
||||
lib-$(CONFIG_DEPMOD) += open_transformer.o
|
||||
lib-$(CONFIG_RMMOD) += open_transformer.o
|
||||
lib-$(CONFIG_LSMOD) += open_transformer.o
|
||||
lib-$(CONFIG_MODPROBE) += open_transformer.o
|
||||
lib-$(CONFIG_MODPROBE_SMALL) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
|
||||
ifneq ($(lib-y),)
|
||||
lib-y += $(COMMON_FILES)
|
||||
|
||||
@@ -249,7 +249,7 @@ void generateMTFValues(EState* s)
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t v, t, i, j, gs, ge, bt, bc, iter;
|
||||
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups;
|
||||
|
||||
@@ -345,6 +345,7 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
#endif
|
||||
nSelectors = 0;
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
/*--- Set group start & end marks. --*/
|
||||
@@ -410,6 +411,7 @@ void sendMTFValues(EState* s)
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
totc += bc;
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
@@ -499,14 +501,14 @@ void sendMTFValues(EState* s)
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (sizeof(long) <= 4) {
|
||||
inUse16 = inUse16*2 +
|
||||
((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4])
|
||||
| *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8])
|
||||
| *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
|
||||
((*(uint32_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 4])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 8])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
|
||||
} else { /* Our CPU can do better */
|
||||
inUse16 = inUse16*2 +
|
||||
((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
|
||||
((*(uint64_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,28 +106,15 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
char *dst_name;
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_name = file_header->name;
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
|
||||
/* rpm-style temp file name */
|
||||
dst_name = xasprintf("%s;%x", dst_name, (int)getpid());
|
||||
#endif
|
||||
dst_fd = xopen3(dst_name,
|
||||
dst_fd = xopen3(file_header->name,
|
||||
flags,
|
||||
file_header->mode
|
||||
);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
|
||||
xrename(dst_name, file_header->name);
|
||||
free(dst_name);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
|
||||
@@ -103,7 +103,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
archive_handle->tar__to_command_shell,
|
||||
"-c",
|
||||
archive_handle->tar__to_command,
|
||||
(char *)0);
|
||||
NULL);
|
||||
bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
|
||||
}
|
||||
close(p[0]);
|
||||
|
||||
@@ -42,12 +42,6 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#else
|
||||
# define dbg(...) ((void)0)
|
||||
#endif
|
||||
|
||||
/* Constants for Huffman coding */
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
@@ -58,13 +52,13 @@
|
||||
|
||||
/* Status return values */
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1)
|
||||
#define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3)
|
||||
#define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4)
|
||||
#define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5)
|
||||
#define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6)
|
||||
#define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7)
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_SHORT_WRITE (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
|
||||
/* Other housekeeping constants */
|
||||
#define IOBUF_SIZE 4096
|
||||
@@ -446,11 +440,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
if (runPos != 0) {
|
||||
uint8_t tmp_byte;
|
||||
if (dbufCount + runCnt > dbufSize) {
|
||||
dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
|
||||
dbufCount, runCnt, dbufCount + runCnt, dbufSize);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
tmp_byte = symToByte[mtfSymbol[0]];
|
||||
byteCount[tmp_byte] += runCnt;
|
||||
while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
|
||||
@@ -731,7 +721,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream(transformer_state_t *xstate)
|
||||
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
bunzip_data *bd;
|
||||
@@ -739,14 +729,14 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
int i;
|
||||
unsigned len;
|
||||
|
||||
if (check_signature16(xstate, BZIP2_MAGIC))
|
||||
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
|
||||
return -1;
|
||||
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -756,7 +746,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
i = IOBUF_SIZE - i; /* number of bytes produced */
|
||||
if (i == 0) /* EOF? */
|
||||
break;
|
||||
if (i != transformer_write(xstate, outbuf, i)) {
|
||||
if (i != full_write(dst_fd, outbuf, i)) {
|
||||
bb_error_msg("short write");
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
goto release_mem;
|
||||
}
|
||||
@@ -789,7 +780,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
len = bd->inbufCount - bd->inbufPos;
|
||||
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
|
||||
if (len < 2) {
|
||||
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
break;
|
||||
len = 2;
|
||||
}
|
||||
@@ -817,6 +808,7 @@ static char *const bunzip_errors[] = {
|
||||
/* Dumb little test thing, decompress stdin to stdout */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
int i = unpack_bz2_stream(0, 1);
|
||||
|
||||
@@ -336,7 +336,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
for (j = 1; (j <= BMAX) && (c[j] == 0); j++)
|
||||
for (j = 1; (c[j] == 0) && (j <= BMAX); j++)
|
||||
continue;
|
||||
k = j; /* minimum code length */
|
||||
for (i = BMAX; (c[i] == 0) && i; i--)
|
||||
@@ -971,7 +971,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
|
||||
|
||||
/* Called from unpack_gz_stream() and inflate_unzip() */
|
||||
static IF_DESKTOP(long long) int
|
||||
inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n = 0;
|
||||
ssize_t nwrote;
|
||||
@@ -980,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
gunzip_window = xmalloc(GUNZIP_WSIZE);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = in;
|
||||
|
||||
/* (re) initialize state */
|
||||
method = -1;
|
||||
@@ -1002,8 +1002,9 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
|
||||
while (1) {
|
||||
int r = inflate_get_next_window(PASS_STATE_ONLY);
|
||||
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == (ssize_t)-1) {
|
||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote != (ssize_t)gunzip_outbuf_count) {
|
||||
bb_perror_msg("write");
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1033,22 +1034,22 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
/* For unzip */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
inflate_unzip(transformer_state_t *xstate)
|
||||
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
ALLOC_STATE;
|
||||
|
||||
to_read = xstate->bytes_in;
|
||||
to_read = aux->bytes_in;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE in, out);
|
||||
free(bytebuffer);
|
||||
|
||||
xstate->crc32 = gunzip_crc;
|
||||
xstate->bytes_out = gunzip_bytes_out;
|
||||
aux->crc32 = gunzip_crc;
|
||||
aux->bytes_out = gunzip_bytes_out;
|
||||
DEALLOC_STATE;
|
||||
return n;
|
||||
}
|
||||
@@ -1106,7 +1107,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -1168,7 +1169,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
}
|
||||
|
||||
xstate->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
if (aux)
|
||||
aux->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
@@ -1180,27 +1182,27 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(transformer_state_t *xstate)
|
||||
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
uint32_t v32;
|
||||
IF_DESKTOP(long long) int total, n;
|
||||
DECLARE_STATE;
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_Z
|
||||
if (check_signature16(xstate, GZIP_MAGIC))
|
||||
if (check_signature16(aux, src_fd, GZIP_MAGIC))
|
||||
return -1;
|
||||
#else
|
||||
if (xstate->check_signature) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2) {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
if (magic2 == COMPRESS_MAGIC) {
|
||||
xstate->check_signature = 0;
|
||||
return unpack_Z_stream(xstate);
|
||||
aux->check_signature = 0;
|
||||
return unpack_Z_stream(aux, src_fd, dst_fd);
|
||||
}
|
||||
if (magic2 != GZIP_MAGIC)
|
||||
goto bad_magic;
|
||||
@@ -1213,16 +1215,16 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
to_read = -1;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = src_fd;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE xstate)) {
|
||||
if (!check_header_gzip(PASS_STATE aux)) {
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
|
||||
if (n < 0) {
|
||||
total = -1;
|
||||
goto ret;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_Z_stream(transformer_state_t *xstate)
|
||||
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
IF_DESKTOP(long long) int retval = -1;
|
||||
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
if (check_signature16(xstate, COMPRESS_MAGIC))
|
||||
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
|
||||
return -1;
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
||||
if (full_read(src_fd, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
||||
rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
|
||||
if (rsize < 0)
|
||||
bb_error_msg_and_die(bb_msg_read_error);
|
||||
insize += rsize;
|
||||
@@ -274,7 +274,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,16 +45,16 @@ typedef struct {
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
|
||||
|
||||
/* Called once in rc_do_normalize() */
|
||||
static void rc_read(rc_t *rc)
|
||||
/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
|
||||
static size_inline void rc_read(rc_t *rc)
|
||||
{
|
||||
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
|
||||
//TODO: return -1 instead
|
||||
//This will make unlzma delete broken unpacked file on unpack errors
|
||||
if (buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
|
||||
@@ -65,12 +65,6 @@ static void rc_do_normalize(rc_t *rc)
|
||||
rc->range <<= 8;
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
@@ -84,9 +78,15 @@ static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
/* rc->ptr = rc->buffer_end; */
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
if (rc->ptr >= rc->buffer_end)
|
||||
rc_read(rc);
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
#else
|
||||
rc_do_normalize(rc);
|
||||
#endif
|
||||
}
|
||||
rc->range = 0xffffffff;
|
||||
rc->range = 0xFFFFFFFF;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,13 @@ static ALWAYS_INLINE void rc_free(rc_t *rc)
|
||||
free(rc);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* rc_is_bit_1 is called 9 times */
|
||||
static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
@@ -113,7 +120,7 @@ static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
|
||||
}
|
||||
|
||||
/* Called 4 times in unlzma loop */
|
||||
static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
{
|
||||
int ret = rc_is_bit_1(rc, p);
|
||||
*symbol = *symbol * 2 + ret;
|
||||
@@ -206,7 +213,7 @@ enum {
|
||||
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_lzma_stream(transformer_state_t *xstate)
|
||||
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
@@ -214,6 +221,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint16_t *p;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
@@ -223,7 +232,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
@@ -237,9 +246,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
/* Example values from linux-3.3.4.tar.lzma:
|
||||
* dict_size: 64M, dst_size: 2^64-1
|
||||
*/
|
||||
header.dict_size = SWAP_LE32(header.dict_size);
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
@@ -248,17 +254,13 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
{
|
||||
int num_probs;
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
}
|
||||
|
||||
rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
@@ -306,7 +308,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
@@ -315,7 +317,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
goto one_byte2;
|
||||
#endif
|
||||
} else {
|
||||
int num_bits;
|
||||
int offset;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
@@ -440,22 +441,19 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
/* FIXME: ...........^^^^^
|
||||
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
IF_NOT_DESKTOP(int total_written = 0; /* success */)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
#include "unxz/xz_dec_stream.c"
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_state_t *xstate)
|
||||
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
iobuf.out = membuf + BUFSIZ;
|
||||
iobuf.out_size = BUFSIZ;
|
||||
|
||||
if (!xstate || xstate->check_signature == 0) {
|
||||
if (!aux || aux->check_signature == 0) {
|
||||
/* Preload XZ file signature */
|
||||
strcpy((char*)membuf, HEADER_MAGIC);
|
||||
iobuf.in_size = HEADER_MAGIC_SIZE;
|
||||
@@ -67,7 +67,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
|
||||
int rd = safe_read(src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
||||
if (iobuf.out_pos) {
|
||||
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
|
||||
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,11 @@
|
||||
#include "bb_archive.h"
|
||||
#include "ar.h"
|
||||
|
||||
/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
|
||||
static unsigned read_num(char *str, int base, int len)
|
||||
static unsigned read_num(const char *str, int base)
|
||||
{
|
||||
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;
|
||||
|
||||
/* This code works because
|
||||
* on misformatted numbers bb_strtou returns all-ones */
|
||||
err = bb_strtou(str, NULL, base);
|
||||
int err = bb_strtou(str, NULL, base);
|
||||
if (err == -1)
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
@@ -59,13 +51,11 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
typed->size = size = read_num(ar.formatted.size, 10,
|
||||
sizeof(ar.formatted.size));
|
||||
/* FIXME: more thorough routine would be in order here
|
||||
* (we have something like that in tar)
|
||||
* but for now we are lax. */
|
||||
ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */
|
||||
typed->size = size = read_num(ar.formatted.size, 10);
|
||||
|
||||
/* special filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
@@ -97,10 +87,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*/
|
||||
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));
|
||||
typed->mode = read_num(ar.formatted.mode, 8);
|
||||
typed->mtime = read_num(ar.formatted.date, 10);
|
||||
typed->uid = read_num(ar.formatted.uid, 10);
|
||||
typed->gid = read_num(ar.formatted.gid, 10);
|
||||
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
@@ -108,8 +98,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in ar_long_names) that conatains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10,
|
||||
sizeof(ar.formatted.name) - 1);
|
||||
long_offset = read_num(&ar.formatted.name[1], 10);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
|
||||
@@ -115,9 +115,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
*/
|
||||
p += len;
|
||||
sz -= len;
|
||||
if (
|
||||
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
|
||||
(int)(sz|len) < 0 /* this works */
|
||||
if ((int)sz < 0
|
||||
|| len == 0
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
@@ -200,13 +198,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* the message and we don't check whether we indeed
|
||||
* saw zero block directly before this. */
|
||||
if (i == 0) {
|
||||
bb_error_msg("short read");
|
||||
/* this merely signals end of archive, not exit(1): */
|
||||
return EXIT_FAILURE;
|
||||
xfunc_error_retval = 0;
|
||||
short_read:
|
||||
bb_error_msg_and_die("short read");
|
||||
}
|
||||
if (i != 512) {
|
||||
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
|
||||
bb_error_msg_and_die("short read");
|
||||
goto short_read;
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -223,10 +221,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
*/
|
||||
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
|
||||
continue;
|
||||
return EXIT_FAILURE; /* "end of archive" */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
archive_handle->tar__end = 1;
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
archive_handle->tar__end = 0;
|
||||
|
||||
@@ -243,7 +241,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* or not first block (false positive, it's not .gz/.bz2!) */
|
||||
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
|
||||
err:
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
archive_handle->offset = 0;
|
||||
@@ -473,5 +471,5 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
free(file_header->tar__uname);
|
||||
free(file_header->tar__gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,7 @@ char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -76,13 +76,11 @@
|
||||
# define TEST_IP (ip < ip_end)
|
||||
# define NEED_IP(x) \
|
||||
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
|
||||
# define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun
|
||||
|
||||
# undef TEST_OP /* don't need both of the tests here */
|
||||
# define TEST_OP 1
|
||||
# define NEED_OP(x) \
|
||||
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
|
||||
# define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun
|
||||
|
||||
#define HAVE_ANY_OP 1
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ typedef struct {
|
||||
( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) )
|
||||
|
||||
#if defined(LZO_UNALIGNED_OK_2)
|
||||
# define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p]))
|
||||
# define HEAD2(b,p) (* (uint16_t *) &(b[p]))
|
||||
#else
|
||||
# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
|
||||
#endif
|
||||
@@ -466,6 +466,7 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
}
|
||||
|
||||
s->m_len = 1;
|
||||
s->m_len = 1;
|
||||
#ifdef SWD_BEST_OFF
|
||||
if (s->use_best_off)
|
||||
memset(s->best_pos, 0, sizeof(s->best_pos));
|
||||
|
||||
@@ -92,7 +92,6 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 15 + *ip++;
|
||||
}
|
||||
/* copy literals */
|
||||
@@ -225,7 +224,6 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 31 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
@@ -267,7 +265,6 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 7 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
|
||||
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
|
||||
{
|
||||
memset(xstate, 0, sizeof(*xstate));
|
||||
memset(aux, 0, sizeof(*aux));
|
||||
}
|
||||
|
||||
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
|
||||
{
|
||||
if (xstate->check_signature) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
bb_error_msg("invalid magic");
|
||||
#if 0 /* possible future extension */
|
||||
if (xstate->check_signature > 1)
|
||||
if (aux->check_signature > 1)
|
||||
xfunc_die();
|
||||
#endif
|
||||
return -1;
|
||||
@@ -27,47 +27,6 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
|
||||
if (xstate->mem_output_size_max != 0) {
|
||||
size_t pos = xstate->mem_output_size;
|
||||
size_t size;
|
||||
|
||||
size = (xstate->mem_output_size += bufsize);
|
||||
if (size > xstate->mem_output_size_max) {
|
||||
free(xstate->mem_output_buf);
|
||||
xstate->mem_output_buf = NULL;
|
||||
bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
|
||||
memcpy(xstate->mem_output_buf + pos, buf, bufsize);
|
||||
xstate->mem_output_buf[size] = '\0';
|
||||
nwrote = bufsize;
|
||||
} else {
|
||||
nwrote = full_write(xstate->dst_fd, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
bb_perror_msg("write");
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
ret:
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote = transformer_write(xstate, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
xfunc_die();
|
||||
}
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
void check_errors_in_children(int signo)
|
||||
{
|
||||
int status;
|
||||
@@ -75,7 +34,6 @@ void check_errors_in_children(int signo)
|
||||
if (!signo) {
|
||||
/* block waiting for any child */
|
||||
if (wait(&status) < 0)
|
||||
//FIXME: check EINTR?
|
||||
return; /* probably there are no children */
|
||||
goto check_status;
|
||||
}
|
||||
@@ -83,30 +41,26 @@ void check_errors_in_children(int signo)
|
||||
/* Wait for any child without blocking */
|
||||
for (;;) {
|
||||
if (wait_any_nohang(&status) < 0)
|
||||
//FIXME: check EINTR?
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
check_status:
|
||||
/*if (WIFEXITED(status) && WEXITSTATUS(status) == 0)*/
|
||||
/* On Linux, the above can be checked simply as: */
|
||||
if (status == 0)
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
/* this child exited with 0 */
|
||||
continue;
|
||||
/* Cannot happen:
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???;
|
||||
*/
|
||||
/* Cannot happen?
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
|
||||
bb_got_signal = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
#if BB_MMU
|
||||
void FAST_FUNC fork_transformer(int fd,
|
||||
void FAST_FUNC open_transformer(int fd,
|
||||
int check_signature,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
)
|
||||
#else
|
||||
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
#endif
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
@@ -120,19 +74,16 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
// FIXME: error check?
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = check_signature;
|
||||
xstate.src_fd = fd;
|
||||
xstate.dst_fd = fd_pipe.wr;
|
||||
r = transformer(&xstate);
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = check_signature;
|
||||
transformer(&aux, fd, fd_pipe.wr);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* send EOF */
|
||||
close(fd);
|
||||
}
|
||||
/* must be _exit! bug was actually seen here */
|
||||
_exit(/*error if:*/ r < 0);
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
{
|
||||
@@ -161,19 +112,16 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
{
|
||||
union {
|
||||
uint8_t b[4];
|
||||
uint16_t b16[2];
|
||||
uint32_t b32[1];
|
||||
} magic;
|
||||
int offset;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
offset = -2;
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
int offset = -2;
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
/* .gz and .bz2 both have 2-byte signature, and their
|
||||
* unpack_XXX_stream wants this header skipped. */
|
||||
@@ -181,15 +129,15 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& magic.b16[0] == GZIP_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_gz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
USE_FOR_MMU(xformer = unpack_gz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_bz2_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
|
||||
USE_FOR_MMU(xformer = unpack_bz2_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
@@ -198,146 +146,69 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
offset = -6;
|
||||
xread(fd, magic.b32, sizeof(magic.b32[0]));
|
||||
if (magic.b32[0] == XZ_MAGIC2) {
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
}
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (fail_if_not_compressed)
|
||||
if (fail_if_not_detected)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
IF_FEATURE_SEAMLESS_XZ("/xz")
|
||||
" magic");
|
||||
|
||||
/* Some callers expect this function to "consume" fd
|
||||
* even if data is not compressed. In this case,
|
||||
* we return a state with trivial transformer.
|
||||
*/
|
||||
// USE_FOR_MMU(xstate->xformer = copy_stream;)
|
||||
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
|
||||
/* fall through to seeking bck over bytes we read earlier */
|
||||
|
||||
USE_FOR_NOMMU(found_magic:)
|
||||
/* NOMMU version of fork_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
return 1;
|
||||
|
||||
USE_FOR_MMU(found_magic:)
|
||||
/* In MMU case, if magic was found, seeking back is not necessary */
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
if (!xstate || !xstate->xformer) {
|
||||
free(xstate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
found_magic:
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
open_transformer_with_no_sig(fd, xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
/* NOMMU version of open_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file */
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
open_transformer_with_sig(fd, xformer, xformer_prog);
|
||||
# endif
|
||||
free(xstate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
|
||||
int FAST_FUNC open_zipped(const char *fname)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
char *sfx;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
return fd;
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
return xstate;
|
||||
sfx = strrchr(fname, '.');
|
||||
if (sfx) {
|
||||
sfx++;
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
|
||||
/* .lzma has no header/signature, just trust it */
|
||||
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
|
||||
else
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, fail_if_not_compressed);
|
||||
if (!xstate)
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
if (xstate->xformer) {
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
# endif
|
||||
}
|
||||
/* else: the file is not compressed */
|
||||
|
||||
free(xstate);
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
|
||||
void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
|
||||
{
|
||||
# if 1
|
||||
transformer_state_t *xstate;
|
||||
char *image;
|
||||
|
||||
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (!xstate) /* file open error */
|
||||
return NULL;
|
||||
|
||||
image = NULL;
|
||||
if (xstate->xformer) {
|
||||
/* In-memory decompression */
|
||||
xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
|
||||
xstate->xformer(xstate);
|
||||
if (xstate->mem_output_buf) {
|
||||
image = xstate->mem_output_buf;
|
||||
if (maxsz_p)
|
||||
*maxsz_p = xstate->mem_output_size;
|
||||
}
|
||||
} else {
|
||||
/* File is not compressed */
|
||||
image = xmalloc_read(xstate->src_fd, maxsz_p);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(xstate->src_fd);
|
||||
free(xstate);
|
||||
return image;
|
||||
# else
|
||||
/* This version forks a subprocess - much more expensive */
|
||||
int fd;
|
||||
char *image;
|
||||
|
||||
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
|
||||
fd = open_zipped(fname);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -345,8 +216,6 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(fd);
|
||||
return image;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
return image;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ XZ Embedded
|
||||
|
||||
XZ Embedded was written for use in the Linux kernel, but the code can
|
||||
be easily used in other environments too, including regular userspace
|
||||
applications. See userspace/xzminidec.c for an example program.
|
||||
applications.
|
||||
|
||||
This README contains information that is useful only when the copy
|
||||
of XZ Embedded isn't part of the Linux kernel tree. You should also
|
||||
@@ -55,7 +55,7 @@ Compiler requirements
|
||||
code is modified not to support large files, which needs some more
|
||||
care than just using 32-bit integer instead of 64-bit).
|
||||
|
||||
If you use GCC, try to use a recent version. For example, on x86-32,
|
||||
If you use GCC, try to use a recent version. For example, on x86,
|
||||
xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when
|
||||
compiled with GCC 4.3.3.
|
||||
|
||||
@@ -93,7 +93,7 @@ BCJ filter support
|
||||
them always #defined doesn't hurt either.
|
||||
|
||||
#define Instruction set BCJ filter endianness
|
||||
XZ_DEC_X86 x86-32 or x86-64 Little endian only
|
||||
XZ_DEC_X86 x86 or x86-64 Little endian only
|
||||
XZ_DEC_POWERPC PowerPC Big endian only
|
||||
XZ_DEC_IA64 Itanium (IA-64) Big or little endian
|
||||
XZ_DEC_ARM ARM Little endian only
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* In Linux, this is used to make extern functions static when needed. */
|
||||
#ifndef XZ_EXTERN
|
||||
# define XZ_EXTERN extern
|
||||
@@ -74,7 +70,7 @@ enum xz_mode {
|
||||
* @XZ_UNSUPPORTED_CHECK: Integrity check type is not supported. Decoding
|
||||
* is still possible in multi-call mode by simply
|
||||
* calling xz_dec_run() again.
|
||||
* Note that this return value is used only if
|
||||
* NOTE: This return value is used only if
|
||||
* XZ_DEC_ANY_CHECK was defined at build time,
|
||||
* which is not used in the kernel. Unsupported
|
||||
* check types return XZ_OPTIONS_ERROR if
|
||||
@@ -109,7 +105,7 @@ enum xz_mode {
|
||||
* stream that is truncated or otherwise corrupt.
|
||||
*
|
||||
* In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
|
||||
* is too small or the compressed input is corrupt in a way that makes the
|
||||
* is too small, or the compressed input is corrupt in a way that makes the
|
||||
* decoder produce more output than the caller expected. When it is
|
||||
* (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
|
||||
* is used instead of XZ_BUF_ERROR.
|
||||
@@ -211,8 +207,8 @@ XZ_EXTERN struct xz_dec * XZ_FUNC xz_dec_init(
|
||||
* The possible return values depend on build options and operation mode.
|
||||
* See enum xz_ret for details.
|
||||
*
|
||||
* Note that if an error occurs in single-call mode (return value is not
|
||||
* XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the
|
||||
* NOTE: If an error occurs in single-call mode (return value is not
|
||||
* XZ_STREAM_END), b->in_pos and b->out_pos are not modified, and the
|
||||
* contents of the output buffer from b->out[b->out_pos] onward are
|
||||
* undefined. This is true even after XZ_BUF_ERROR, because with some filter
|
||||
* chains, there may be a second pass over the output buffer, and this pass
|
||||
@@ -272,9 +268,4 @@ XZ_EXTERN void XZ_FUNC xz_crc32_init(void);
|
||||
XZ_EXTERN uint32_t XZ_FUNC xz_crc32(
|
||||
const uint8_t *buf, size_t size, uint32_t crc);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -77,13 +77,10 @@ struct xz_dec_bcj {
|
||||
|
||||
#ifdef XZ_DEC_X86
|
||||
/*
|
||||
* This is used to test the most significant byte of a memory address
|
||||
* This is macro used to test the most significant byte of a memory address
|
||||
* in an x86 instruction.
|
||||
*/
|
||||
static inline int bcj_x86_test_msbyte(uint8_t b)
|
||||
{
|
||||
return b == 0x00 || b == 0xFF;
|
||||
}
|
||||
#define bcj_x86_test_msbyte(b) ((b) == 0x00 || (b) == 0xFF)
|
||||
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_x86(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
@@ -446,12 +443,8 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
* next filter in the chain. Apply the BCJ filter on the new data
|
||||
* in the output buffer. If everything cannot be filtered, copy it
|
||||
* to temp and rewind the output buffer position accordingly.
|
||||
*
|
||||
* This needs to be always run when temp.size == 0 to handle a special
|
||||
* case where the output buffer is full and the next filter has no
|
||||
* more output coming but hasn't returned XZ_STREAM_END yet.
|
||||
*/
|
||||
if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
|
||||
if (s->temp.size < b->out_size - b->out_pos) {
|
||||
out_start = b->out_pos;
|
||||
memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
|
||||
b->out_pos += s->temp.size;
|
||||
@@ -474,25 +467,16 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
s->temp.size = b->out_pos - out_start;
|
||||
b->out_pos -= s->temp.size;
|
||||
memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
|
||||
|
||||
/*
|
||||
* If there wasn't enough input to the next filter to fill
|
||||
* the output buffer with unfiltered data, there's no point
|
||||
* to try decoding more data to temp.
|
||||
*/
|
||||
if (b->out_pos + s->temp.size < b->out_size)
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have unfiltered data in temp. If the output buffer isn't full
|
||||
* yet, try to fill the temp buffer by decoding more data from the
|
||||
* next filter. Apply the BCJ filter on temp. Then we hopefully can
|
||||
* fill the actual output buffer by copying filtered data from temp.
|
||||
* A mix of filtered and unfiltered data may be left in temp; it will
|
||||
* be taken care on the next call to this function.
|
||||
* If we have unfiltered data in temp, try to fill by decoding more
|
||||
* data from the next filter. Apply the BCJ filter on temp. Then we
|
||||
* hopefully can fill the actual output buffer by copying filtered
|
||||
* data from temp. A mix of filtered and unfiltered data may be left
|
||||
* in temp; it will be taken care on the next call to this function.
|
||||
*/
|
||||
if (b->out_pos < b->out_size) {
|
||||
if (s->temp.size > 0) {
|
||||
/* Make b->out{,_pos,_size} temporarily point to s->temp. */
|
||||
s->out = b->out;
|
||||
s->out_pos = b->out_pos;
|
||||
|
||||
@@ -407,6 +407,7 @@ static void XZ_FUNC dict_uncompressed(
|
||||
|
||||
b->out_pos += copy_size;
|
||||
b->in_pos += copy_size;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,9 +972,6 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
*/
|
||||
tmp = b->in[b->in_pos++];
|
||||
|
||||
if (tmp == 0x00)
|
||||
return XZ_STREAM_END;
|
||||
|
||||
if (tmp >= 0xE0 || tmp == 0x01) {
|
||||
s->lzma2.need_props = true;
|
||||
s->lzma2.need_dict_reset = false;
|
||||
@@ -1006,6 +1004,9 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
lzma_reset(s);
|
||||
}
|
||||
} else {
|
||||
if (tmp == 0x00)
|
||||
return XZ_STREAM_END;
|
||||
|
||||
if (tmp > 0x02)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
|
||||
@@ -25,20 +25,15 @@
|
||||
|
||||
#define STREAM_HEADER_SIZE 12
|
||||
|
||||
#define HEADER_MAGIC "\3757zXZ"
|
||||
#define HEADER_MAGIC "\3757zXZ\0"
|
||||
#define HEADER_MAGIC_SIZE 6
|
||||
|
||||
#define FOOTER_MAGIC "YZ"
|
||||
#define FOOTER_MAGIC_SIZE 2
|
||||
|
||||
/*
|
||||
* Variable-length integer can hold a 63-bit unsigned integer or a special
|
||||
* value indicating that the value is unknown.
|
||||
*
|
||||
* Experimental: vli_type can be defined to uint32_t to save a few bytes
|
||||
* in code size (no effect on speed). Doing so limits the uncompressed and
|
||||
* compressed size of the file to less than 256 MiB and may also weaken
|
||||
* error detection slightly.
|
||||
* Variable-length integer can hold a 63-bit unsigned integer, or a special
|
||||
* value to indicate that the value is unknown.
|
||||
*/
|
||||
typedef uint64_t vli_type;
|
||||
|
||||
|
||||
+16
-38
@@ -25,26 +25,6 @@
|
||||
"Minimalized" for busybox by Alain Knaff
|
||||
*/
|
||||
|
||||
//config:config LZOP
|
||||
//config: bool "lzop"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Lzop compression/decompresion.
|
||||
//config:
|
||||
//config:config LZOP_COMPR_HIGH
|
||||
//config: bool "lzop compression levels 7,8,9 (not very useful)"
|
||||
//config: default n
|
||||
//config: depends on LZOP
|
||||
//config: help
|
||||
//config: High levels (7,8,9) of lzop compression. These levels
|
||||
//config: are actually slower than gzip at equivalent compression ratios
|
||||
//config: and take up 3.2K of code.
|
||||
|
||||
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
|
||||
//applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
|
||||
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
|
||||
|
||||
//usage:#define lzop_trivial_usage
|
||||
//usage: "[-cfvd123456789CF] [FILE]..."
|
||||
//usage:#define lzop_full_usage "\n\n"
|
||||
@@ -456,27 +436,25 @@ struct globals {
|
||||
//#define LZOP_VERSION_STRING "1.01"
|
||||
//#define LZOP_VERSION_DATE "Apr 27th 2003"
|
||||
|
||||
#define OPTION_STRING "cfvqdt123456789CF"
|
||||
#define OPTION_STRING "cfvdt123456789CF"
|
||||
|
||||
/* Note: must be kept in sync with archival/bbunzip.c */
|
||||
enum {
|
||||
OPT_STDOUT = (1 << 0),
|
||||
OPT_FORCE = (1 << 1),
|
||||
OPT_VERBOSE = (1 << 2),
|
||||
OPT_QUIET = (1 << 3),
|
||||
OPT_DECOMPRESS = (1 << 4),
|
||||
OPT_TEST = (1 << 5),
|
||||
OPT_1 = (1 << 6),
|
||||
OPT_2 = (1 << 7),
|
||||
OPT_3 = (1 << 8),
|
||||
OPT_4 = (1 << 9),
|
||||
OPT_5 = (1 << 10),
|
||||
OPT_6 = (1 << 11),
|
||||
OPT_789 = (7 << 12),
|
||||
OPT_7 = (1 << 13),
|
||||
OPT_8 = (1 << 14),
|
||||
OPT_C = (1 << 15),
|
||||
OPT_F = (1 << 16),
|
||||
OPT_DECOMPRESS = (1 << 3),
|
||||
OPT_TEST = (1 << 4),
|
||||
OPT_1 = (1 << 5),
|
||||
OPT_2 = (1 << 6),
|
||||
OPT_3 = (1 << 7),
|
||||
OPT_4 = (1 << 8),
|
||||
OPT_5 = (1 << 9),
|
||||
OPT_6 = (1 << 10),
|
||||
OPT_789 = (7 << 11),
|
||||
OPT_7 = (1 << 11),
|
||||
OPT_8 = (1 << 12),
|
||||
OPT_C = (1 << 14),
|
||||
OPT_F = (1 << 15),
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -1099,7 +1077,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
|
||||
return xasprintf("%s.lzo", filename);
|
||||
}
|
||||
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM)
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
if (option_mask32 & OPT_DECOMPRESS)
|
||||
return do_lzo_decompress();
|
||||
@@ -1115,7 +1093,7 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
|
||||
/* unlzop? */
|
||||
if (applet_name[4] == 'o')
|
||||
if (applet_name[0] == 'u')
|
||||
option_mask32 |= OPT_DECOMPRESS;
|
||||
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
+153
-163
@@ -7,15 +7,6 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM
|
||||
//config: bool "rpm"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
//applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_RPM) += rpm.o
|
||||
|
||||
//usage:#define rpm_trivial_usage
|
||||
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
|
||||
//usage:#define rpm_full_usage "\n\n"
|
||||
@@ -23,10 +14,10 @@
|
||||
//usage: "\nCommands:"
|
||||
//usage: "\n -i Install package"
|
||||
//usage: "\n -qp Query package"
|
||||
//usage: "\n -qpi Show information"
|
||||
//usage: "\n -qpl List contents"
|
||||
//usage: "\n -qpd List documents"
|
||||
//usage: "\n -qpc List config files"
|
||||
//usage: "\n -i Show information"
|
||||
//usage: "\n -l List contents"
|
||||
//usage: "\n -d List documents"
|
||||
//usage: "\n -c List config files"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -88,13 +79,136 @@ typedef struct {
|
||||
uint32_t count; /* 4 byte count */
|
||||
} rpm_index;
|
||||
|
||||
struct globals {
|
||||
void *map;
|
||||
rpm_index **mytags;
|
||||
int tagcount;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
static void *map;
|
||||
static rpm_index **mytags;
|
||||
static int tagcount;
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm);
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
static int bsearch_rpmtag(const void *key, const void *item);
|
||||
static char *rpm_getstr(int tag, int itemindex);
|
||||
static int rpm_getint(int tag, int itemindex);
|
||||
static int rpm_getcount(int tag);
|
||||
static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
const int pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
const char *source_rpm;
|
||||
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, &tagcount);
|
||||
if (!mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
offset = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
/* Mimimum is one page */
|
||||
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
|
||||
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio(rpm_fd, source_rpm);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate_ptm;
|
||||
char bdatestring[50];
|
||||
const char *p;
|
||||
|
||||
p = rpm_getstr(TAG_PREFIXS, 0);
|
||||
if (!p) p = "(not relocateable)";
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), p);
|
||||
p = rpm_getstr(TAG_VENDOR, 0);
|
||||
if (!p) p = "(none)";
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), p);
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), source_rpm);
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mytags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm)
|
||||
{
|
||||
@@ -117,12 +231,12 @@ static void extract_cpio(int fd, const char *source_rpm)
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
*/
|
||||
| ARCHIVE_REPLACE_VIA_RENAME;
|
||||
* (TODO? real rpm creates "file;1234" and then renames it) */
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
@@ -180,7 +294,7 @@ static int bsearch_rpmtag(const void *key, const void *item)
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
@@ -189,7 +303,7 @@ static int rpm_getcount(int tag)
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE
|
||||
@@ -197,7 +311,7 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
|| found[0]->type == RPM_STRING_ARRAY_TYPE
|
||||
) {
|
||||
int n;
|
||||
char *tmpstr = (char *) G.map + found[0]->offset;
|
||||
char *tmpstr = (char *) map + found[0]->offset;
|
||||
for (n = 0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
@@ -208,25 +322,32 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
char *tmpint;
|
||||
int *tmpint; /* NB: using int8_t* would be easier to code */
|
||||
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (char *) G.map + found[0]->offset;
|
||||
tmpint = (int *) ((char *) map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint += itemindex*4;
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
/*return ntohl(*tmpint);*/
|
||||
/* int can be != int32_t */
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint += itemindex*2;
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*2);
|
||||
/* ??? read int, and THEN ntohs() it?? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint += itemindex;
|
||||
tmpint = (int *) ((char *) tmpint + itemindex);
|
||||
/* ??? why we don't read byte here??? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
@@ -271,134 +392,3 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt, func = 0;
|
||||
const unsigned pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
int rpm_fd;
|
||||
unsigned mapsize;
|
||||
const char *source_rpm;
|
||||
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
G.mytags = rpm_gettags(rpm_fd, &G.tagcount);
|
||||
if (!G.mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
mapsize = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
mapsize = (mapsize + pagesize) & -(int)pagesize;
|
||||
/* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||
G.map = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
//FIXME: error check?
|
||||
|
||||
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio(rpm_fd, source_rpm);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate_ptm;
|
||||
char bdatestring[50];
|
||||
const char *p;
|
||||
|
||||
printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0));
|
||||
/* TODO compat: add "Epoch" here */
|
||||
printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0));
|
||||
printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0));
|
||||
/* add "Architecture" */
|
||||
printf("%-12s: %s\n", "Install Date", "(not installed)");
|
||||
printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0));
|
||||
printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0));
|
||||
printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0));
|
||||
/* add "Signature" */
|
||||
printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("%-12s: %s\n", "Build Date" , bdatestring);
|
||||
printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0));
|
||||
p = rpm_getstr(TAG_PREFIXS, 0);
|
||||
printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)");
|
||||
/* add "Packager" */
|
||||
p = rpm_getstr(TAG_VENDOR, 0);
|
||||
printf("%-12s: %s\n", "Vendor" , p ? p : "(none)");
|
||||
printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0));
|
||||
printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
munmap(G.map, mapsize);
|
||||
free(G.mytags);
|
||||
close(rpm_fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1
-10
@@ -7,15 +7,6 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM2CPIO
|
||||
//config: bool "rpm2cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Converts a RPM file into a CPIO archive.
|
||||
|
||||
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
|
||||
//usage:#define rpm2cpio_trivial_usage
|
||||
//usage: "package.rpm"
|
||||
//usage:#define rpm2cpio_full_usage "\n\n"
|
||||
@@ -80,7 +71,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* This works, but doesn't report uncompress errors (they happen in child) */
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
|
||||
|
||||
+52
-147
@@ -22,6 +22,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* TODO: security with -C DESTDIR option can be enhanced.
|
||||
* Consider tar file created via:
|
||||
* $ tar cvf bug.tar anything.txt
|
||||
@@ -41,109 +42,6 @@
|
||||
* This doesn't feel right, and IIRC GNU tar doesn't do that.
|
||||
*/
|
||||
|
||||
//config:config TAR
|
||||
//config: bool "tar"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: tar is an archiving program. It's commonly used with gzip to
|
||||
//config: create compressed archives. It's probably the most widely used
|
||||
//config: UNIX archive program.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_CREATE
|
||||
//config: bool "Enable archive creation"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to create
|
||||
//config: tar archives using the `-c' option.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_AUTODETECT
|
||||
//config: bool "Autodetect compressed tarballs"
|
||||
//config: default y
|
||||
//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
|
||||
//config: help
|
||||
//config: With this option tar can automatically detect compressed
|
||||
//config: tarballs. Currently it works only on files (not pipes etc).
|
||||
//config:
|
||||
//config:config FEATURE_TAR_FROM
|
||||
//config: bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to specify
|
||||
//config: a list of files to include or exclude from an archive.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
//config: bool "Support for old tar header format"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: This option is required to unpack archives created in
|
||||
//config: the old GNU format; help to kill this old format by
|
||||
//config: repacking your ancient archives with the new format.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
//config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: This option is required to unpack archives created by some old
|
||||
//config: version of Sun's tar (it was calculating checksum using signed
|
||||
//config: arithmetic). It is said to be fixed in newer Sun tar, but "old"
|
||||
//config: tarballs still exist.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_GNU_EXTENSIONS
|
||||
//config: bool "Support for GNU tar extensions (long filenames)"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
//config: With this option busybox supports GNU long filenames and
|
||||
//config: linknames.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on TAR && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options, increases size by about 400 Bytes
|
||||
//config:
|
||||
//config:config FEATURE_TAR_TO_COMMAND
|
||||
//config: bool "Support for writing to an external program"
|
||||
//config: default y
|
||||
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
|
||||
//config: help
|
||||
//config: If you enable this option you'll be able to instruct tar to send
|
||||
//config: the contents of each extracted file to the standard input of an
|
||||
//config: external program.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_UNAME_GNAME
|
||||
//config: bool "Enable use of user and group names"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: Enables use of user and group names in tar. This affects contents
|
||||
//config: listings (-t) and preserving permissions when unpacking (-p).
|
||||
//config: +200 bytes.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_NOPRESERVE_TIME
|
||||
//config: bool "Enable -m (do not preserve time) option"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: With this option busybox supports GNU tar -m
|
||||
//config: (do not preserve time) option.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_SELINUX
|
||||
//config: bool "Support for extracting SELinux labels"
|
||||
//config: default n
|
||||
//config: depends on TAR && SELINUX
|
||||
//config: help
|
||||
//config: With this option busybox supports restoring SELinux labels
|
||||
//config: when extracting files from tar archives.
|
||||
|
||||
//applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_TAR) += tar.o
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -160,6 +58,13 @@
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
/*
|
||||
@@ -614,12 +519,21 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
# endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
# define WAIT_FOR_CHILD 0
|
||||
@@ -633,6 +547,11 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
# endif
|
||||
|
||||
gzipPid = xvfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
@@ -648,7 +567,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(gzip, gzip, "-f", (char *)0);
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -671,21 +590,16 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", gzip);
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
}
|
||||
}
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
|
||||
|
||||
#if !SEAMLESS_COMPRESSION
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
/* gcc 4.2.1 inlines it, making code bigger */
|
||||
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, const char *gzip)
|
||||
const llist_t *exclude, int gzip)
|
||||
{
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
@@ -698,7 +612,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
* can avoid including the tarball into itself.... */
|
||||
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
#endif
|
||||
@@ -733,7 +647,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip) {
|
||||
int status;
|
||||
if (safe_waitpid(-1, &status, 0) == -1)
|
||||
@@ -745,9 +659,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
#endif
|
||||
return errorFlag;
|
||||
}
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
# define writeTarFile(...) 0
|
||||
#endif
|
||||
#else
|
||||
int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -763,12 +679,14 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
char *cp = last_char_is(line, '/');
|
||||
if (cp > line)
|
||||
*cp = '\0';
|
||||
llist_add_to_end(&newlist, line);
|
||||
llist_add_to(&newlist, line);
|
||||
}
|
||||
fclose(src_stream);
|
||||
}
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
# define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
//usage:#define tar_trivial_usage
|
||||
@@ -1119,7 +1037,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
tar_handle->src_fd = open_zipped(tar_filename);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
@@ -1131,24 +1049,18 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if SEAMLESS_COMPRESSION
|
||||
const char *zipMode = NULL;
|
||||
if (opt & OPT_COMPRESS)
|
||||
zipMode = "compress";
|
||||
if (opt & OPT_GZIP)
|
||||
zipMode = "gzip";
|
||||
if (opt & OPT_BZIP2)
|
||||
zipMode = "bzip2";
|
||||
if (opt & OPT_LZMA)
|
||||
zipMode = "lzma";
|
||||
if (opt & OPT_XZ)
|
||||
zipMode = "xz";
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
|
||||
zipMode = 2;
|
||||
#endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag,
|
||||
@@ -1159,7 +1071,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (opt & OPT_ANY_COMPRESS) {
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
if (opt & OPT_COMPRESS)
|
||||
@@ -1178,20 +1090,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
|
||||
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
/* Can't lseek over pipes */
|
||||
tar_handle->seek = seek_by_read;
|
||||
/*tar_handle->offset = 0; - already is */
|
||||
}
|
||||
|
||||
/* Zero processed headers (== empty file) is not a valid tarball.
|
||||
* We (ab)use bb_got_signal as exitcode here,
|
||||
* because check_errors_in_children() uses _it_ as error indicator.
|
||||
*/
|
||||
bb_got_signal = EXIT_FAILURE;
|
||||
|
||||
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
|
||||
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
|
||||
continue;
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
@@ -1207,9 +1113,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
close(tar_handle->src_fd);
|
||||
|
||||
if (SEAMLESS_COMPRESSION || OPT_COMPRESS) {
|
||||
/* Set bb_got_signal to 1 if a child died with !0 exitcode */
|
||||
check_errors_in_children(0);
|
||||
return bb_got_signal;
|
||||
}
|
||||
|
||||
return bb_got_signal;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+35
-81
@@ -9,26 +9,15 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* For reference see
|
||||
* http://www.pkware.com/company/standards/appnote/
|
||||
* http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
|
||||
*
|
||||
* TODO
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory. Use the `-d' option to extract to a
|
||||
//config: directory of your choice.
|
||||
|
||||
//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
|
||||
/* TODO
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
|
||||
//usage:#define unzip_trivial_usage
|
||||
//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
|
||||
@@ -174,17 +163,7 @@ enum { zip_fd = 3 };
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
|
||||
/* Seen in the wild:
|
||||
* Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive,
|
||||
* where CDE was nearly 48 kbytes before EOF.
|
||||
* (Surprisingly, it also apparently has *another* CDE structure
|
||||
* closer to the end, with bogus cdf_offset).
|
||||
* To make extraction work, bumped PEEK_FROM_END from 16k to 64k.
|
||||
*/
|
||||
#define PEEK_FROM_END (64*1024)
|
||||
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
#define PEEK_FROM_END 16384
|
||||
|
||||
/* NB: does not preserve file position! */
|
||||
static uint32_t find_cdf_offset(void)
|
||||
@@ -201,7 +180,6 @@ static uint32_t find_cdf_offset(void)
|
||||
xlseek(zip_fd, end, SEEK_SET);
|
||||
full_read(zip_fd, buf, PEEK_FROM_END);
|
||||
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
p = buf;
|
||||
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
@@ -217,17 +195,11 @@ static uint32_t find_cdf_offset(void)
|
||||
/* we found CDE! */
|
||||
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde_header);
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
* where cdf_offset points past EOF - ??
|
||||
* Ignore such CDEs:
|
||||
*/
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf))
|
||||
break;
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
free(buf);
|
||||
return cde_header.formatted.cdf_offset;
|
||||
}
|
||||
free(buf);
|
||||
return cde_header.formatted.cdf_offset;
|
||||
//free(buf);
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
};
|
||||
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
@@ -239,15 +211,13 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
if (!cdf_offset)
|
||||
cdf_offset = find_cdf_offset();
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
}
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cdf_offset;
|
||||
@@ -256,9 +226,8 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
|
||||
static void unzip_skip(off_t skip)
|
||||
{
|
||||
if (skip != 0)
|
||||
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
|
||||
bb_copyfd_exact_size(zip_fd, -1, skip);
|
||||
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
|
||||
bb_copyfd_exact_size(zip_fd, -1, skip);
|
||||
}
|
||||
|
||||
static void unzip_create_leading_dirs(const char *fn)
|
||||
@@ -280,19 +249,17 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.bytes_in = zip_header->formatted.cmpsize;
|
||||
xstate.src_fd = zip_fd;
|
||||
xstate.dst_fd = dst_fd;
|
||||
if (inflate_unzip(&xstate) < 0)
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.bytes_in = zip_header->formatted.cmpsize;
|
||||
if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
@@ -300,14 +267,6 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
}
|
||||
}
|
||||
|
||||
static void my_fgets80(char *buf80)
|
||||
{
|
||||
fflush_all();
|
||||
if (!fgets(buf80, 80, stdin)) {
|
||||
bb_perror_msg_and_die("can't read standard input");
|
||||
}
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
@@ -332,7 +291,7 @@ int unzip_main(int argc, char **argv)
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
int i, opt;
|
||||
char key_buf[80]; /* must match size used by my_fgets80 */
|
||||
char key_buf[80];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
|
||||
@@ -561,31 +520,21 @@ int unzip_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
}
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
{
|
||||
cdf_header_t cdf_header;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
|
||||
/*
|
||||
* Note: cdf_offset can become BAD_CDF_OFFSET after the above call.
|
||||
*/
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory. See unzip_doc.txt
|
||||
*/
|
||||
* only from Central Directory. See unzip_doc.txt */
|
||||
zip_header.formatted.crc32 = cdf_header.formatted.crc32;
|
||||
zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
|
||||
zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
|
||||
}
|
||||
if ((cdf_header.formatted.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
/* this archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
|
||||
}
|
||||
}
|
||||
if (cdf_offset == BAD_CDF_OFFSET
|
||||
&& (zip_header.formatted.zip_flags & SWAP_LE16(0x0008))
|
||||
) {
|
||||
/* If it's a streaming zip, we _require_ CDF */
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read filename */
|
||||
@@ -675,7 +624,10 @@ int unzip_main(int argc, char **argv)
|
||||
i = 'y';
|
||||
} else {
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
my_fgets80(key_buf);
|
||||
fflush_all();
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
}
|
||||
i = key_buf[0];
|
||||
}
|
||||
} else { /* File is not regular file */
|
||||
@@ -716,7 +668,9 @@ int unzip_main(int argc, char **argv)
|
||||
case 'r':
|
||||
/* Prompt for new name */
|
||||
printf("new name: ");
|
||||
my_fgets80(key_buf);
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
}
|
||||
free(dst_fn);
|
||||
dst_fn = xstrdup(key_buf);
|
||||
chomp(dst_fn);
|
||||
|
||||
+14
-23
@@ -36,56 +36,47 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
#define flags bb_common_bufsiz1
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
|
||||
/* When user accidentally runs "dumpkmap FILE"
|
||||
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
||||
* Let's prevent it:
|
||||
*/
|
||||
* Let's prevent it: */
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argv[1]);*/
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
#if 0
|
||||
write(STDOUT_FILENO, "bkeymap", 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12]
|
||||
*/
|
||||
/*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
||||
memset(flags, 0x01, 13);
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
|
||||
/* dump flags */
|
||||
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
#define flags7 flags
|
||||
#else
|
||||
/* Same effect */
|
||||
/* 0 1 2 3 4 5 6 7 8 9 a b c=12 */
|
||||
memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1",
|
||||
/* Can use sizeof, or sizeof-1. sizeof is even, using that */
|
||||
/****/ sizeof("bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1")
|
||||
);
|
||||
write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS);
|
||||
#define flags7 (flags + 7)
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 13; i++) {
|
||||
if (flags7[i]) {
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
||||
"ioctl(KDGKBENT{%d,%d}) failed",
|
||||
j, i)
|
||||
"ioctl failed with %s, %s, %p",
|
||||
(char *)&ke.kb_index,
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value)
|
||||
) {
|
||||
write(STDOUT_FILENO, &ke.kb_value, 2);
|
||||
write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd);
|
||||
RELEASE_CONFIG_BUFFER(flags);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -48,7 +48,6 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[1])
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argv[1]); */
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
/* or maybe:
|
||||
opt = getopt32(argv, "C:", &tty_name);
|
||||
@@ -62,24 +61,14 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] != 1)
|
||||
continue;
|
||||
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
/*
|
||||
* Note: table[idx:0] can contain special value
|
||||
* K_ALLOCATED (marks allocated tables in kernel).
|
||||
* dumpkmap saves the value as-is; but attempts
|
||||
* to load it here fail, since it isn't a valid
|
||||
* key value: it is K(KT_SPEC,126) == 2<<8 + 126,
|
||||
* whereas last valid KT_SPEC is
|
||||
* K_BARENUMLOCK == K(KT_SPEC,19).
|
||||
* So far we just ignore these errors:
|
||||
*/
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
if (flags[i] == 1) {
|
||||
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
//usage:#define setlogcons_trivial_usage
|
||||
//usage: "[N]"
|
||||
//usage: "N"
|
||||
//usage:#define setlogcons_full_usage "\n\n"
|
||||
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
|
||||
//usage: "Redirect the kernel output to console N (0 for current)"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
+1
-12
@@ -633,13 +633,12 @@ config FEATURE_FANCY_TAIL
|
||||
default y
|
||||
depends on TAIL
|
||||
help
|
||||
The options (-q, -s, -v and -F) are provided by GNU tail, but
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
-q Never output headers giving file names
|
||||
-s SEC Wait SEC seconds between reads with -f
|
||||
-v Always output headers giving file names
|
||||
-F Same as -f, but keep retrying
|
||||
|
||||
config TEE
|
||||
bool "tee"
|
||||
@@ -739,16 +738,6 @@ config YES
|
||||
yes is used to repeatedly output a specific string, or
|
||||
the default string `y'.
|
||||
|
||||
comment "Common options"
|
||||
|
||||
config FEATURE_VERBOSE
|
||||
bool "Support verbose options (usually -v) for various applets"
|
||||
default y
|
||||
help
|
||||
Enable cp -v, rm -v and similar messages.
|
||||
Also enables long option (--verbose) if it exists.
|
||||
Without this option, -v is accepted but ignored.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CP || MV
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ lib-$(CONFIG_EXPAND) += expand.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
lib-$(CONFIG_FOLD) += fold.o
|
||||
lib-$(CONFIG_FSYNC) += fsync.o
|
||||
lib-$(CONFIG_HEAD) += head.o
|
||||
lib-$(CONFIG_INSTALL) += install.o
|
||||
#lib-$(CONFIG_LENGTH) += length.o
|
||||
lib-$(CONFIG_LN) += ln.o
|
||||
@@ -70,6 +71,7 @@ lib-$(CONFIG_STTY) += stty.o
|
||||
lib-$(CONFIG_SUM) += sum.o
|
||||
lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAC) += tac.o
|
||||
lib-$(CONFIG_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
lib-$(CONFIG_TTY) += tty.o
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
char lineout[30];
|
||||
|
||||
day_array(month, year, dp);
|
||||
len = sprintf(lineout, "%s %u", month_names[month - 1], year);
|
||||
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
|
||||
printf("%*s%s\n%s\n",
|
||||
((7*julian + WEEK_LEN) - len) / 2, "",
|
||||
lineout, day_headings);
|
||||
|
||||
+26
-25
@@ -20,30 +20,19 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
struct BUG_const_mismatch {
|
||||
char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
};
|
||||
|
||||
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
unsigned opts;
|
||||
opts = getopt32(argv, "etv");
|
||||
unsigned flags;
|
||||
|
||||
flags = getopt32(argv, "etv");
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
flags ^= CATV_OPT_v;
|
||||
argv += optind;
|
||||
#if 0 /* These consts match, we can just pass "opts" to visible() */
|
||||
if (opts & CATV_OPT_e)
|
||||
flags |= VISIBLE_ENDLINE;
|
||||
if (opts & CATV_OPT_t)
|
||||
flags |= VISIBLE_SHOW_TABS;
|
||||
#endif
|
||||
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
if (!argv[0])
|
||||
@@ -61,17 +50,29 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
res = read(fd, read_buf, COMMON_BUFSIZE);
|
||||
if (res < 0)
|
||||
retval = EXIT_FAILURE;
|
||||
if (res <= 0)
|
||||
if (res < 1)
|
||||
break;
|
||||
for (i = 0; i < res; i++) {
|
||||
unsigned char c = read_buf[i];
|
||||
if (opts & CATV_OPT_v) {
|
||||
putchar(c);
|
||||
} else {
|
||||
char buf[sizeof("M-^c")];
|
||||
visible(c, buf, opts);
|
||||
fputs(buf, stdout);
|
||||
|
||||
if (c > 126 && (flags & CATV_OPT_v)) {
|
||||
if (c == 127) {
|
||||
printf("^?");
|
||||
continue;
|
||||
}
|
||||
printf("M-");
|
||||
c -= 128;
|
||||
}
|
||||
if (c < 32) {
|
||||
if (c == 10) {
|
||||
if (flags & CATV_OPT_e)
|
||||
bb_putchar('$');
|
||||
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
|
||||
printf("^%c", c+'@');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bb_putchar(c);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && fd)
|
||||
|
||||
+1
-1
@@ -16,10 +16,10 @@
|
||||
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: "\n -h Affect symlinks instead of symlink targets"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -L Traverse all symlinks to directories"
|
||||
//usage: "\n -H Traverse symlinks on command line only"
|
||||
//usage: "\n -P Don't traverse symlinks (default)"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
|
||||
@@ -79,6 +79,7 @@ int cp_main(int argc, char **argv)
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
|
||||
+35
-76
@@ -30,10 +30,10 @@
|
||||
//usage: "\n conv=noerror Continue after read errors"
|
||||
//usage: "\n conv=sync Pad blocks with zeros"
|
||||
//usage: "\n conv=fsync Physically write data out before finishing"
|
||||
//usage: "\n conv=swab Swap every pair of bytes"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kD (1000), k (1024), MD, M, GD, G"
|
||||
//usage: "\nNumbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),"
|
||||
//usage: "\nMD (x1000000), M (x1048576), GD (x1000000000) or G (x1073741824)"
|
||||
//usage:
|
||||
//usage:#define dd_example_usage
|
||||
//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
|
||||
@@ -151,14 +151,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOTRUNC = 1 << 0,
|
||||
FLAG_SYNC = 1 << 1,
|
||||
FLAG_NOERROR = 1 << 2,
|
||||
FLAG_FSYNC = 1 << 3,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
FLAG_TWOBUFS = 1 << 4,
|
||||
FLAG_COUNT = 1 << 5,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"
|
||||
@@ -168,7 +167,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 0,
|
||||
@@ -186,11 +185,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_conv_sync,
|
||||
OP_conv_noerror,
|
||||
OP_conv_fsync,
|
||||
OP_conv_swab,
|
||||
/* Unimplemented conv=XXX: */
|
||||
//nocreat do not create the output file
|
||||
//excl fail if the output file already exists
|
||||
//fdatasync physically write output file data before finishing
|
||||
//swab swap every pair of input bytes
|
||||
//lcase change upper case to lower case
|
||||
//ucase change lower case to upper case
|
||||
//block pad newline-terminated records with spaces to cbs-size
|
||||
@@ -198,33 +197,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
//ascii from EBCDIC to ASCII
|
||||
//ebcdic from ASCII to EBCDIC
|
||||
//ibm from ASCII to alternate EBCDIC
|
||||
/* Partially implemented: */
|
||||
//swab swap every pair of input bytes: will abort on non-even reads
|
||||
#endif
|
||||
};
|
||||
smallint exitcode = EXIT_FAILURE;
|
||||
int i;
|
||||
size_t ibs = 512;
|
||||
char *ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
size_t obs = 512;
|
||||
char *obuf;
|
||||
#else
|
||||
# define obs ibs
|
||||
# define obuf ibuf
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
int exitcode = EXIT_FAILURE;
|
||||
size_t ibs = 512, obs = 512;
|
||||
ssize_t n, w;
|
||||
char *ibuf, *obuf;
|
||||
/* And these are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
size_t oc;
|
||||
ssize_t prev_read_size; /* for detecting swab failure */
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
#define skip (Z.skip )
|
||||
@@ -235,10 +223,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
//fflush_all(); - is this needed because of NOEXEC?
|
||||
|
||||
for (i = 1; argv[i]; i++) {
|
||||
for (n = 1; argv[n]; n++) {
|
||||
int what;
|
||||
char *val;
|
||||
char *arg = argv[i];
|
||||
char *arg = argv[n];
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
/* "dd --". NB: coreutils 6.9 will complain if they see
|
||||
@@ -267,7 +255,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
while (1) {
|
||||
int n;
|
||||
/* find ',', replace them with NUL so we can use val for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on val being non-null, else strchr would fault.
|
||||
@@ -275,21 +262,20 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
arg = strchr(val, ',');
|
||||
if (arg)
|
||||
*arg = '\0';
|
||||
n = index_in_strings(conv_words, val);
|
||||
if (n < 0)
|
||||
what = index_in_strings(conv_words, val);
|
||||
if (what < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
flags |= (1 << n);
|
||||
flags |= (1 << what);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
val = arg + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
/*continue;*/
|
||||
continue; /* we trashed 'what', can't fall through */
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
obs = ibs;
|
||||
ibs = obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
@@ -314,17 +300,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
} /* end of "for (argv[i])" */
|
||||
} /* end of "for (argv[n])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
ibuf = xmalloc(ibs);
|
||||
obuf = ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
ibuf = obuf = xmalloc(ibs);
|
||||
if (ibs != obs) {
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
@@ -333,12 +316,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.begin_time_us = monotonic_us();
|
||||
#endif
|
||||
|
||||
if (infile) {
|
||||
if (infile != NULL)
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
} else {
|
||||
else {
|
||||
infile = bb_msg_standard_input;
|
||||
}
|
||||
if (outfile) {
|
||||
if (outfile != NULL) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
@@ -363,13 +346,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (skip) {
|
||||
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
|
||||
do {
|
||||
ssize_t n = safe_read(ifd, ibuf, ibs);
|
||||
while (skip-- > 0) {
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n < 0)
|
||||
goto die_infile;
|
||||
if (n == 0)
|
||||
break;
|
||||
} while (--skip != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (seek) {
|
||||
@@ -378,8 +361,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
@@ -394,27 +375,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if (flags & FLAG_SWAB) {
|
||||
uint16_t *p16;
|
||||
ssize_t n2;
|
||||
|
||||
/* Our code allows only last read to be odd-sized */
|
||||
if (prev_read_size & 1)
|
||||
bb_error_msg_and_die("can't swab %lu byte buffer",
|
||||
(unsigned long)prev_read_size);
|
||||
prev_read_size = n;
|
||||
|
||||
/* If n is odd, last byte is not swapped:
|
||||
* echo -n "qwe" | dd conv=swab
|
||||
* prints "wqe".
|
||||
*/
|
||||
p16 = (void*) ibuf;
|
||||
n2 = (n >> 1);
|
||||
while (--n2 >= 0) {
|
||||
*p16 = bswap_16(*p16);
|
||||
p16++;
|
||||
}
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
else {
|
||||
@@ -441,10 +401,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
} else if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
@@ -453,8 +411,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
if (write_and_stats(obuf, oc, obs, outfile))
|
||||
goto out_status;
|
||||
w = full_write_or_warn(obuf, oc, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w > 0) G.out_part++;
|
||||
}
|
||||
if (close(ifd) < 0) {
|
||||
die_infile:
|
||||
|
||||
+8
-28
@@ -25,7 +25,6 @@
|
||||
//usage:#define df_trivial_usage
|
||||
//usage: "[-Pk"
|
||||
//usage: IF_FEATURE_HUMAN_READABLE("mh")
|
||||
//usage: "T"
|
||||
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
|
||||
//usage: "] [FILESYSTEM]..."
|
||||
//usage:#define df_full_usage "\n\n"
|
||||
@@ -36,7 +35,6 @@
|
||||
//usage: "\n -m 1M-byte blocks"
|
||||
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: "\n -T Print filesystem type"
|
||||
//usage: IF_FEATURE_DF_FANCY(
|
||||
//usage: "\n -a Show all filesystems"
|
||||
//usage: "\n -i Inodes"
|
||||
@@ -85,12 +83,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
@@ -102,7 +99,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kPT"
|
||||
opt = getopt32(argv, "kP"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
IF_FEATURE_DF_FANCY(, &chp));
|
||||
@@ -137,11 +134,8 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
|
||||
(opt & OPT_FSTYPE) ? "Type " : "",
|
||||
disp_units_hdr,
|
||||
(opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
printf("Filesystem %-15sUsed Available %s Mounted on\n",
|
||||
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -154,7 +148,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
const char *fs_type;
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -177,7 +170,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
device = mount_entry->mnt_fsname;
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
@@ -226,22 +218,10 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
|
||||
}
|
||||
free(uni_dev);
|
||||
if (opt & OPT_FSTYPE) {
|
||||
char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
|
||||
if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
|
||||
printf(" %s\n%31s", uni_type, "");
|
||||
else
|
||||
printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
|
||||
free(uni_type);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
|
||||
printf("\n%-20s", "");
|
||||
if (opt & OPT_FSTYPE) {
|
||||
if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
|
||||
printf("\n%-30s", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
|
||||
+10
-3
@@ -78,7 +78,11 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
unsigned len;
|
||||
*ptr = '\0';
|
||||
# if ENABLE_UNICODE_SUPPORT
|
||||
len = unicode_strwidth(ptr_strbeg);
|
||||
{
|
||||
uni_stat_t uni_stat;
|
||||
printable_string(&uni_stat, ptr_strbeg);
|
||||
len = uni_stat.unicode_width;
|
||||
}
|
||||
# else
|
||||
len = ptr - ptr_strbeg;
|
||||
# endif
|
||||
@@ -134,9 +138,12 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
printf("%*s%.*s", len, "", n, ptr);
|
||||
# if ENABLE_UNICODE_SUPPORT
|
||||
{
|
||||
char c = ptr[n];
|
||||
char c;
|
||||
uni_stat_t uni_stat;
|
||||
c = ptr[n];
|
||||
ptr[n] = '\0';
|
||||
len = unicode_strwidth(ptr);
|
||||
printable_string(&uni_stat, ptr);
|
||||
len = uni_stat.unicode_width;
|
||||
ptr[n] = c;
|
||||
}
|
||||
# else
|
||||
|
||||
+27
-130
@@ -11,8 +11,6 @@
|
||||
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
|
||||
|
||||
//kbuild:lib-$(CONFIG_HEAD) += head.o
|
||||
|
||||
//usage:#define head_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define head_full_usage "\n\n"
|
||||
@@ -20,8 +18,7 @@
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -n N[kbm] Print first N lines"
|
||||
//usage: IF_FEATURE_FANCY_HEAD(
|
||||
//usage: "\n -n -N[kbm] Print all except N last lines"
|
||||
//usage: "\n -c [-]N[kbm] Print first N bytes"
|
||||
//usage: "\n -c N[kbm] Print first N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: )
|
||||
@@ -37,110 +34,6 @@
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
# define print_first_N(fp,count,bytes) print_first_N(fp,count)
|
||||
#endif
|
||||
static void
|
||||
print_first_N(FILE *fp, unsigned long count, bool count_bytes)
|
||||
{
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
const int count_bytes = 0;
|
||||
#endif
|
||||
while (count) {
|
||||
int c = getc(fp);
|
||||
if (c == EOF)
|
||||
break;
|
||||
if (count_bytes || (c == '\n'))
|
||||
--count;
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
static void
|
||||
print_except_N_last_bytes(FILE *fp, unsigned count)
|
||||
{
|
||||
unsigned char *circle = xmalloc(++count);
|
||||
unsigned head = 0;
|
||||
for(;;) {
|
||||
int c;
|
||||
c = getc(fp);
|
||||
if (c == EOF)
|
||||
goto ret;
|
||||
circle[head++] = c;
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
int c;
|
||||
if (head == count)
|
||||
head = 0;
|
||||
putchar(circle[head]);
|
||||
c = getc(fp);
|
||||
if (c == EOF)
|
||||
goto ret;
|
||||
circle[head] = c;
|
||||
head++;
|
||||
}
|
||||
ret:
|
||||
free(circle);
|
||||
}
|
||||
|
||||
static void
|
||||
print_except_N_last_lines(FILE *fp, unsigned count)
|
||||
{
|
||||
char **circle = xzalloc((++count) * sizeof(circle[0]));
|
||||
unsigned head = 0;
|
||||
for(;;) {
|
||||
char *c;
|
||||
c = xmalloc_fgets(fp);
|
||||
if (!c)
|
||||
goto ret;
|
||||
circle[head++] = c;
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
for (;;) {
|
||||
char *c;
|
||||
if (head == count)
|
||||
head = 0;
|
||||
fputs(circle[head], stdout);
|
||||
c = xmalloc_fgets(fp);
|
||||
if (!c)
|
||||
goto ret;
|
||||
free(circle[head]);
|
||||
circle[head++] = c;
|
||||
}
|
||||
ret:
|
||||
head = 0;
|
||||
for(;;) {
|
||||
free(circle[head++]);
|
||||
if (head == count)
|
||||
break;
|
||||
}
|
||||
free(circle);
|
||||
}
|
||||
#else
|
||||
/* Must never be called */
|
||||
void print_except_N_last_bytes(FILE *fp, unsigned count);
|
||||
void print_except_N_last_lines(FILE *fp, unsigned count);
|
||||
#endif
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
# define eat_num(negative_N,p) eat_num(p)
|
||||
#endif
|
||||
static unsigned long
|
||||
eat_num(bool *negative_N, const char *p)
|
||||
{
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
if (*p == '-') {
|
||||
*negative_N = 1;
|
||||
p++;
|
||||
}
|
||||
#endif
|
||||
return xatoul_sfx(p, bkm_suffixes);
|
||||
}
|
||||
|
||||
static const char head_opts[] ALIGN1 =
|
||||
"n:"
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
@@ -148,25 +41,29 @@ static const char head_opts[] ALIGN1 =
|
||||
#endif
|
||||
;
|
||||
|
||||
static const struct suffix_mult head_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
#define header_fmt_str "\n==> %s <==\n"
|
||||
|
||||
int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int head_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long count = 10;
|
||||
unsigned long i;
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
int count_bytes = 0;
|
||||
int header_threshhold = 1;
|
||||
bool count_bytes = 0;
|
||||
bool negative_N = 0;
|
||||
#else
|
||||
# define header_threshhold 1
|
||||
# define count_bytes 0
|
||||
# define negative_N 0
|
||||
#endif
|
||||
FILE *fp;
|
||||
const char *fmt;
|
||||
char *p;
|
||||
int opt;
|
||||
int c;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
@@ -176,7 +73,7 @@ int head_main(int argc, char **argv)
|
||||
) {
|
||||
--argc;
|
||||
++argv;
|
||||
p = argv[0] + 1;
|
||||
p = (*argv) + 1;
|
||||
goto GET_COUNT;
|
||||
}
|
||||
#endif
|
||||
@@ -200,7 +97,7 @@ int head_main(int argc, char **argv)
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
GET_COUNT:
|
||||
#endif
|
||||
count = eat_num(&negative_N, p);
|
||||
count = xatoul_sfx(p, head_suffixes);
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
@@ -213,17 +110,19 @@ int head_main(int argc, char **argv)
|
||||
*--argv = (char*)"-";
|
||||
|
||||
fmt = header_fmt_str + 1;
|
||||
if (argc <= header_threshhold) {
|
||||
#if ENABLE_FEATURE_FANCY_HEAD
|
||||
if (argc <= header_threshhold) {
|
||||
header_threshhold = 0;
|
||||
}
|
||||
#else
|
||||
if (argc <= 1) {
|
||||
fmt += 11; /* "" */
|
||||
}
|
||||
/* Now define some things here to avoid #ifdefs in the code below.
|
||||
* These should optimize out of the if conditions below. */
|
||||
#define header_threshhold 1
|
||||
#define count_bytes 0
|
||||
#endif
|
||||
}
|
||||
if (negative_N) {
|
||||
if (count >= INT_MAX / sizeof(char*))
|
||||
bb_error_msg("count is too big: %lu", count);
|
||||
}
|
||||
|
||||
do {
|
||||
fp = fopen_or_warn_stdin(*argv);
|
||||
@@ -234,20 +133,18 @@ int head_main(int argc, char **argv)
|
||||
if (header_threshhold) {
|
||||
printf(fmt, *argv);
|
||||
}
|
||||
if (negative_N) {
|
||||
if (count_bytes) {
|
||||
print_except_N_last_bytes(fp, count);
|
||||
} else {
|
||||
print_except_N_last_lines(fp, count);
|
||||
i = count;
|
||||
while (i && ((c = getc(fp)) != EOF)) {
|
||||
if (count_bytes || (c == '\n')) {
|
||||
--i;
|
||||
}
|
||||
} else {
|
||||
print_first_N(fp, count, count_bytes);
|
||||
putchar(c);
|
||||
}
|
||||
die_if_ferror_stdout();
|
||||
if (fclose_if_not_stdin(fp)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
die_if_ferror_stdout();
|
||||
} else {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+1
-2
@@ -36,8 +36,7 @@ int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* POSIX says gethostid returns a "32-bit identifier" */
|
||||
printf("%08x\n", (unsigned)(uint32_t)gethostid());
|
||||
printf("%08lx\n", gethostid());
|
||||
|
||||
return fflush_all();
|
||||
}
|
||||
+3
-1
@@ -64,10 +64,12 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#if !ENABLE_USE_BB_PWD_GRP
|
||||
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 30)
|
||||
#if defined(__UCLIBC_MAJOR__) && (__UCLIBC_MAJOR__ == 0)
|
||||
#if (__UCLIBC_MINOR__ < 9) || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 30)
|
||||
#error "Sorry, you need at least uClibc version 0.9.30 for id applet to build"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PRINT_REAL = (1 << 0),
|
||||
|
||||
+18
-33
@@ -8,7 +8,7 @@
|
||||
|
||||
/* -v, -b, -c are ignored */
|
||||
//usage:#define install_trivial_usage
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
|
||||
//usage:#define install_full_usage "\n\n"
|
||||
//usage: "Copy files and set attributes\n"
|
||||
//usage: "\n -c Just copy (default)"
|
||||
@@ -19,7 +19,6 @@
|
||||
//usage: "\n -o USER Set ownership"
|
||||
//usage: "\n -g GRP Set group ownership"
|
||||
//usage: "\n -m MODE Set permissions"
|
||||
//usage: "\n -t DIR Install to DIR"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -Z Set security context"
|
||||
//usage: )
|
||||
@@ -29,16 +28,12 @@
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
static const char install_longopts[] ALIGN1 =
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
"directory\0" No_argument "d"
|
||||
"preserve-timestamps\0" No_argument "p"
|
||||
"strip\0" No_argument "s"
|
||||
"group\0" Required_argument "g"
|
||||
"mode\0" Required_argument "m"
|
||||
"owner\0" Required_argument "o"
|
||||
"target-directory\0" Required_argument "t"
|
||||
/* autofs build insists of using -b --suffix=.orig */
|
||||
/* TODO? (short option for --suffix is -S) */
|
||||
#if ENABLE_SELINUX
|
||||
@@ -94,11 +89,11 @@ int install_main(int argc, char **argv)
|
||||
const char *gid_str;
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
int mkdir_flags = FILEUTILS_RECUR;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int opts;
|
||||
int min_args = 1;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int isdir;
|
||||
int isdir = 0;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
bool use_default_selinux_context = 1;
|
||||
@@ -114,22 +109,21 @@ int install_main(int argc, char **argv)
|
||||
OPT_GROUP = 1 << 7,
|
||||
OPT_MODE = 1 << 8,
|
||||
OPT_OWNER = 1 << 9,
|
||||
OPT_TARGET = 1 << 10,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str, &last
|
||||
IF_SELINUX(, &scontext));
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@@ -147,11 +141,6 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
|
||||
mkdir_flags |= FILEUTILS_VERBOSE;
|
||||
copy_flags |= FILEUTILS_VERBOSE;
|
||||
}
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour,
|
||||
* BSD only preserves modification time */
|
||||
if (opts & OPT_PRESERVE_TIME) {
|
||||
@@ -163,37 +152,33 @@ int install_main(int argc, char **argv)
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
/* If -t DIR is in use, then isdir=true, last="DIR" */
|
||||
isdir = (opts & OPT_TARGET);
|
||||
if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
|
||||
/* Neither -t DIR nor -d is in use */
|
||||
argc--;
|
||||
last = argv[argc];
|
||||
argv[argc] = NULL;
|
||||
last = argv[argc - 1];
|
||||
if (!(opts & OPT_DIRECTORY)) {
|
||||
argv[argc - 1] = NULL;
|
||||
min_args++;
|
||||
|
||||
/* coreutils install resolves link in this case, don't use lstat */
|
||||
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
if (argc < min_args)
|
||||
bb_show_usage();
|
||||
|
||||
while ((arg = *argv++) != NULL) {
|
||||
char *dest;
|
||||
|
||||
char *dest = last;
|
||||
if (opts & OPT_DIRECTORY) {
|
||||
dest = arg;
|
||||
/* GNU coreutils 6.9 does not set uid:gid
|
||||
* on intermediate created directories
|
||||
* (only on last one) */
|
||||
if (bb_make_directory(dest, 0755, mkdir_flags)) {
|
||||
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
} else {
|
||||
dest = last;
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
|
||||
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created. */
|
||||
free(ddir);
|
||||
|
||||
+1
-1
@@ -1032,7 +1032,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
}
|
||||
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
|
||||
@@ -151,9 +151,7 @@ static uint8_t *hash_file(const char *filename)
|
||||
update(&context, in_buf, count);
|
||||
}
|
||||
hash_value = NULL;
|
||||
if (count < 0)
|
||||
bb_perror_msg("can't read '%s'", filename);
|
||||
else /* count == 0 */ {
|
||||
if (count == 0) {
|
||||
final(&context, in_buf);
|
||||
hash_value = hash_bin_to_hex(in_buf, hash_len);
|
||||
}
|
||||
|
||||
+2
-6
@@ -48,9 +48,7 @@ static const char mkdir_longopts[] ALIGN1 =
|
||||
#if ENABLE_SELINUX
|
||||
"context\0" Required_argument "Z"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_VERBOSE
|
||||
"verbose\0" No_argument "v"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -69,7 +67,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
||||
applet_long_options = mkdir_longopts;
|
||||
#endif
|
||||
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode_t mmode = 0777;
|
||||
if (!bb_parse_mode(smode, &mmode)) {
|
||||
@@ -79,10 +77,8 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (opt & 2)
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 4) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 8) {
|
||||
if (opt & 4) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
|
||||
+1
-7
@@ -33,17 +33,13 @@ static const char mv_longopts[] ALIGN1 =
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
#endif
|
||||
|
||||
#define OPT_FORCE (1 << 0)
|
||||
#define OPT_INTERACTIVE (1 << 1)
|
||||
#define OPT_NOCLOBBER (1 << 2)
|
||||
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
|
||||
|
||||
|
||||
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mv_main(int argc, char **argv)
|
||||
@@ -62,6 +58,7 @@ int mv_main(int argc, char **argv)
|
||||
/* Need at least two arguments.
|
||||
* If more than one of -f, -i, -n is specified , only the final one
|
||||
* takes effect (it unsets previous options).
|
||||
* -v is accepted but ignored.
|
||||
*/
|
||||
opt_complementary = "-2:f-in:i-fn:n-fi";
|
||||
flags = getopt32(argv, "finv");
|
||||
@@ -151,9 +148,6 @@ int mv_main(int argc, char **argv)
|
||||
status = 1;
|
||||
}
|
||||
RET_0:
|
||||
if (flags & OPT_VERBOSE) {
|
||||
printf("'%s' -> '%s'\n", *argv, dest);
|
||||
}
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
|
||||
@@ -1166,6 +1166,12 @@ parse_old_offset(const char *s, off_t *offset)
|
||||
int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
static const struct suffix_mult bkm[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char od_longopts[] ALIGN1 =
|
||||
"skip-bytes\0" Required_argument "j"
|
||||
@@ -1224,7 +1230,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
address_pad_len_char = doxn_address_pad_len_char[pos];
|
||||
}
|
||||
if (opt & OPT_N) {
|
||||
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes);
|
||||
max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm);
|
||||
}
|
||||
if (opt & OPT_a) decode_format_string("a");
|
||||
if (opt & OPT_b) decode_format_string("oC");
|
||||
@@ -1233,7 +1239,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_f) decode_format_string("fF");
|
||||
if (opt & OPT_h) decode_format_string("x2");
|
||||
if (opt & OPT_i) decode_format_string("d2");
|
||||
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
|
||||
if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm);
|
||||
if (opt & OPT_l) decode_format_string("d4");
|
||||
if (opt & OPT_o) decode_format_string("o2");
|
||||
while (lst_t) {
|
||||
@@ -1242,7 +1248,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_x) decode_format_string("x2");
|
||||
if (opt & OPT_s) decode_format_string("d2");
|
||||
if (opt & OPT_S) {
|
||||
string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
|
||||
string_min = xstrtou_sfx(str_S, 0, bkm);
|
||||
}
|
||||
|
||||
// Bloat:
|
||||
|
||||
@@ -39,10 +39,7 @@
|
||||
* -q, --quiet, -s, --silent suppress most error messages
|
||||
* -v, --verbose report error messages
|
||||
*
|
||||
* bbox supports: -f (partially) -n -v (fully), -q -s (accepts but ignores)
|
||||
* Note: we export the -f flag, but our -f behaves like coreutils' -e.
|
||||
* Unfortunately, there isn't a C lib function we can leverage to get this
|
||||
* behavior which means we'd have to implement the full stack ourselves :(.
|
||||
* bbox supports: -f -n -v (fully), -q -s (accepts but ignores)
|
||||
*/
|
||||
|
||||
int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
|
||||
+1
-2
@@ -38,6 +38,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "f-i:i-f";
|
||||
/* -v (verbose) is ignored */
|
||||
opt = getopt32(argv, "fiRrv");
|
||||
argv += optind;
|
||||
if (opt & 1)
|
||||
@@ -46,8 +47,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FILEUTILS_INTERACTIVE;
|
||||
if (opt & (8|4))
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 16) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
|
||||
if (*argv != NULL) {
|
||||
do {
|
||||
|
||||
+2
-8
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#define PARENTS (1 << 0)
|
||||
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
|
||||
//efine VERBOSE (1 << 1) //accepted but ignored
|
||||
#define IGNORE_NON_EMPTY (1 << 2)
|
||||
|
||||
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -44,12 +44,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
static const char rmdir_longopts[] ALIGN1 =
|
||||
"parents\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
/* Debian etch: many packages fail to be purged or installed
|
||||
* because they desperately want this option: */
|
||||
"ignore-fail-on-non-empty\0" No_argument "\xff"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
applet_long_options = rmdir_longopts;
|
||||
#endif
|
||||
@@ -64,10 +62,6 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
path = *argv;
|
||||
|
||||
while (1) {
|
||||
if (flags & VERBOSE) {
|
||||
printf("rmdir: removing directory, '%s'\n", path);
|
||||
}
|
||||
|
||||
if (rmdir(path) < 0) {
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* shuf: Write a random permutation of the input lines to standard output.
|
||||
*
|
||||
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config SHUF
|
||||
//config: bool "shuf"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Generate random permutations
|
||||
|
||||
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
|
||||
//applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf))
|
||||
|
||||
//usage:#define shuf_trivial_usage
|
||||
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
|
||||
//usage:#define shuf_full_usage "\n\n"
|
||||
//usage: "Randomly permute lines\n"
|
||||
//usage: "\n -e Treat ARGs as lines"
|
||||
//usage: "\n -i L-H Treat numbers L-H as lines"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z End lines with zero byte, not newline"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#define OPT_e (1 << 0)
|
||||
#define OPT_i (1 << 1)
|
||||
#define OPT_n (1 << 2)
|
||||
#define OPT_o (1 << 3)
|
||||
#define OPT_z (1 << 4)
|
||||
#define OPT_STR "ei:n:o:z"
|
||||
|
||||
/*
|
||||
* Use the Fisher-Yates shuffle algorithm on an array of lines.
|
||||
*/
|
||||
static void shuffle_lines(char **lines, unsigned numlines)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned r;
|
||||
char *tmp;
|
||||
|
||||
srand(monotonic_us());
|
||||
|
||||
for (i = numlines-1; i > 0; i--) {
|
||||
r = rand();
|
||||
/* RAND_MAX can be as small as 32767 */
|
||||
if (i > RAND_MAX)
|
||||
r ^= rand() << 15;
|
||||
r %= i;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int shuf_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
char *opt_i_str, *opt_n_str, *opt_o_str;
|
||||
unsigned i;
|
||||
char **lines;
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opt_complementary = "e--i:i--e"; /* mutually exclusive */
|
||||
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Prepare lines for shuffling - either: */
|
||||
if (opts & OPT_e) {
|
||||
/* make lines from command-line arguments */
|
||||
numlines = argc;
|
||||
lines = argv;
|
||||
} else
|
||||
if (opts & OPT_i) {
|
||||
/* create a range of numbers */
|
||||
char *dash;
|
||||
unsigned lo, hi;
|
||||
|
||||
dash = strchr(opt_i_str, '-');
|
||||
if (!dash) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
*dash = '\0';
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
numlines = (hi+1) - lo;
|
||||
lines = xmalloc(numlines * sizeof(lines[0]));
|
||||
for (i = 0; i < numlines; i++) {
|
||||
lines[i] = (char*)(uintptr_t)lo;
|
||||
lo++;
|
||||
}
|
||||
} else {
|
||||
/* default - read lines from stdin or the input file */
|
||||
FILE *fp;
|
||||
|
||||
if (argc > 1)
|
||||
bb_show_usage();
|
||||
|
||||
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
|
||||
lines = NULL;
|
||||
numlines = 0;
|
||||
for (;;) {
|
||||
char *line = xmalloc_fgetline(fp);
|
||||
if (!line)
|
||||
break;
|
||||
lines = xrealloc_vector(lines, 6, numlines);
|
||||
lines[numlines++] = line;
|
||||
}
|
||||
fclose_if_not_stdin(fp);
|
||||
}
|
||||
|
||||
if (numlines != 0)
|
||||
shuffle_lines(lines, numlines);
|
||||
|
||||
if (opts & OPT_o)
|
||||
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
|
||||
if (opts & OPT_n) {
|
||||
unsigned maxlines;
|
||||
maxlines = xatou(opt_n_str);
|
||||
if (numlines > maxlines)
|
||||
numlines = maxlines;
|
||||
}
|
||||
|
||||
eol = '\n';
|
||||
if (opts & OPT_z)
|
||||
eol = '\0';
|
||||
|
||||
for (i = 0; i < numlines; i++) {
|
||||
if (opts & OPT_i)
|
||||
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
|
||||
else
|
||||
printf("%s%c", lines[i], eol);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+3
-7
@@ -225,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
y = *(char **)yarg;
|
||||
#endif
|
||||
/* Perform actual comparison */
|
||||
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
|
||||
switch (flags & 7) {
|
||||
default:
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
break;
|
||||
@@ -302,14 +302,10 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
} /* for */
|
||||
|
||||
/* Perform fallback sort if necessary */
|
||||
if (!retval && !(option_mask32 & FLAG_s)) {
|
||||
if (!retval && !(option_mask32 & FLAG_s))
|
||||
retval = strcmp(*(char **)xarg, *(char **)yarg);
|
||||
flags = option_mask32;
|
||||
}
|
||||
|
||||
if (flags & FLAG_r)
|
||||
return -retval;
|
||||
|
||||
if (flags & FLAG_r) return -retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -23,15 +23,17 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const struct suffix_mult split_suffices[] = {
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
static const struct suffix_mult split_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
#endif
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
{ "g", 1024*1024*1024 },
|
||||
#endif
|
||||
{ "", 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Increment the suffix part of the filename.
|
||||
* Returns NULL if we are out of filenames.
|
||||
@@ -84,10 +86,7 @@ int split_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & SPLIT_OPT_l)
|
||||
cnt = XATOOFF(count_p);
|
||||
if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF
|
||||
cnt = xatoull_sfx(count_p,
|
||||
IF_FEATURE_SPLIT_FANCY(split_suffixes)
|
||||
IF_NOT_FEATURE_SPLIT_FANCY(km_suffixes)
|
||||
);
|
||||
cnt = xatoull_sfx(count_p, split_suffices);
|
||||
sfx = "x";
|
||||
|
||||
argv += optind;
|
||||
|
||||
+3
-4
@@ -127,7 +127,7 @@ static const char *human_time(time_t t)
|
||||
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
|
||||
#define buf bb_common_bufsiz1
|
||||
|
||||
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t));
|
||||
return buf;
|
||||
#undef buf
|
||||
}
|
||||
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
);
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" %s\n", scontext);
|
||||
printf(" %lc\n", *scontext);
|
||||
else
|
||||
bb_putchar('\n');
|
||||
# endif
|
||||
@@ -700,8 +700,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
(unsigned long) statbuf.st_gid,
|
||||
(gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" S_Context: %s\n", scontext);
|
||||
printf(" S_Context: %lc\n", *scontext);
|
||||
# endif
|
||||
printf("Access: %s\n", human_time(statbuf.st_atime));
|
||||
printf("Modify: %s\n", human_time(statbuf.st_mtime));
|
||||
|
||||
+63
-42
@@ -246,21 +246,10 @@ enum speed_setting {
|
||||
|
||||
/* Which member(s) of 'struct termios' a mode uses */
|
||||
enum {
|
||||
/* Do NOT change the order or values, as mode_type_flag()
|
||||
* depends on them */
|
||||
control, input, output, local, combination
|
||||
};
|
||||
static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode)
|
||||
{
|
||||
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
||||
offsetof(struct termios, c_cflag), /* control */
|
||||
offsetof(struct termios, c_iflag), /* input */
|
||||
offsetof(struct termios, c_oflag), /* output */
|
||||
offsetof(struct termios, c_lflag) /* local */
|
||||
};
|
||||
if (type <= local) {
|
||||
return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Flags for 'struct mode_info' */
|
||||
#define SANE_SET 1 /* Set in 'sane' mode */
|
||||
@@ -781,6 +770,51 @@ struct globals {
|
||||
G.max_col = 80; \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Return a string that is the printable representation of character CH */
|
||||
/* Adapted from 'cat' by Torbjorn Granlund */
|
||||
static const char *visible(unsigned ch)
|
||||
{
|
||||
char *bpout = G.buf;
|
||||
|
||||
if (ch == _POSIX_VDISABLE)
|
||||
return "<undef>";
|
||||
|
||||
if (ch >= 128) {
|
||||
ch -= 128;
|
||||
*bpout++ = 'M';
|
||||
*bpout++ = '-';
|
||||
}
|
||||
|
||||
if (ch < 32) {
|
||||
*bpout++ = '^';
|
||||
*bpout++ = ch + 64;
|
||||
} else if (ch < 127) {
|
||||
*bpout++ = ch;
|
||||
} else {
|
||||
*bpout++ = '^';
|
||||
*bpout++ = '?';
|
||||
}
|
||||
|
||||
*bpout = '\0';
|
||||
return G.buf;
|
||||
}
|
||||
|
||||
static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
|
||||
{
|
||||
static const uint8_t tcflag_offsets[] ALIGN1 = {
|
||||
offsetof(struct termios, c_cflag), /* control */
|
||||
offsetof(struct termios, c_iflag), /* input */
|
||||
offsetof(struct termios, c_oflag), /* output */
|
||||
offsetof(struct termios, c_lflag) /* local */
|
||||
};
|
||||
|
||||
if (type <= local) {
|
||||
return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void set_speed_or_die(enum speed_setting type, const char *arg,
|
||||
struct termios *mode)
|
||||
{
|
||||
@@ -1008,7 +1042,6 @@ static void do_display(const struct termios *mode, int all)
|
||||
#endif
|
||||
|
||||
for (i = 0; i != CIDX_min; ++i) {
|
||||
char ch;
|
||||
/* If swtch is the same as susp, don't print both */
|
||||
#if VSWTCH == VSUSP
|
||||
if (i == CIDX_swtch)
|
||||
@@ -1022,12 +1055,8 @@ static void do_display(const struct termios *mode, int all)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
ch = mode->c_cc[control_info[i].offset];
|
||||
if (ch == _POSIX_VDISABLE)
|
||||
strcpy(G.buf, "<undef>");
|
||||
else
|
||||
visible(ch, G.buf, 0);
|
||||
wrapf("%s = %s;", nth_string(control_name, i), G.buf);
|
||||
wrapf("%s = %s;", nth_string(control_name, i),
|
||||
visible(mode->c_cc[control_info[i].offset]));
|
||||
}
|
||||
#if VEOF == VMIN
|
||||
if ((mode->c_lflag & ICANON) == 0)
|
||||
@@ -1043,7 +1072,7 @@ static void do_display(const struct termios *mode, int all)
|
||||
prev_type = mode_info[i].type;
|
||||
}
|
||||
|
||||
bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
|
||||
if ((*bitsp & mask) == mode_info[i].bits) {
|
||||
if (all || (mode_info[i].flags & SANE_UNSET))
|
||||
@@ -1062,6 +1091,7 @@ static void do_display(const struct termios *mode, int all)
|
||||
static void sane_mode(struct termios *mode)
|
||||
{
|
||||
int i;
|
||||
tcflag_t *bitsp;
|
||||
|
||||
for (i = 0; i < NUM_control_info; ++i) {
|
||||
#if VMIN == VEOF
|
||||
@@ -1072,17 +1102,14 @@ static void sane_mode(struct termios *mode)
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_mode_info; ++i) {
|
||||
tcflag_t val;
|
||||
tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
|
||||
|
||||
if (!bitsp)
|
||||
continue;
|
||||
val = *bitsp & ~((unsigned long)mode_info[i].mask);
|
||||
if (mode_info[i].flags & SANE_SET) {
|
||||
*bitsp = val | mode_info[i].bits;
|
||||
} else
|
||||
if (mode_info[i].flags & SANE_UNSET) {
|
||||
*bitsp = val & ~mode_info[i].bits;
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
*bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask))
|
||||
| mode_info[i].bits;
|
||||
} else if (mode_info[i].flags & SANE_UNSET) {
|
||||
bitsp = mode_type_flag(mode_info[i].type, mode);
|
||||
*bitsp = *bitsp & ~((unsigned long)mode_info[i].mask)
|
||||
& ~mode_info[i].bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1092,18 +1119,17 @@ static void set_mode(const struct mode_info *info, int reversed,
|
||||
{
|
||||
tcflag_t *bitsp;
|
||||
|
||||
bitsp = get_ptr_to_tcflag(info->type, mode);
|
||||
bitsp = mode_type_flag(info->type, mode);
|
||||
|
||||
if (bitsp) {
|
||||
tcflag_t val = *bitsp & ~info->mask;
|
||||
if (reversed)
|
||||
*bitsp = val & ~info->bits;
|
||||
*bitsp = *bitsp & ~info->mask & ~info->bits;
|
||||
else
|
||||
*bitsp = val | info->bits;
|
||||
*bitsp = (*bitsp & ~info->mask) | info->bits;
|
||||
return;
|
||||
}
|
||||
|
||||
/* !bitsp - it's a "combination" mode */
|
||||
/* Combination mode */
|
||||
if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) {
|
||||
if (reversed)
|
||||
mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
|
||||
@@ -1508,12 +1534,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
|
||||
perror_on_device_and_die("%s");
|
||||
|
||||
if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
|
||||
/*
|
||||
* I think the below chunk is not necessary on Linux.
|
||||
* If you are deleting it, also delete STTY_speed_was_set bit -
|
||||
* it is only ever checked here.
|
||||
*/
|
||||
#if 0 /* was "if CIBAUD" */
|
||||
#if CIBAUD
|
||||
/* SunOS 4.1.3 (at least) has the problem that after this sequence,
|
||||
tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
|
||||
sometimes (m1 != m2). The only difference is in the four bits
|
||||
|
||||
+2
-2
@@ -70,9 +70,9 @@ static unsigned sum_file(const char *file, unsigned type)
|
||||
if (type >= SUM_SYSV) {
|
||||
r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
|
||||
s = (r & 0xffff) + (r >> 16);
|
||||
printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file);
|
||||
printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file);
|
||||
} else
|
||||
printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
|
||||
printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
|
||||
return 1;
|
||||
#undef buf
|
||||
}
|
||||
|
||||
+26
-25
@@ -24,24 +24,24 @@
|
||||
* 7) lseek attempted when count==0 even if arg was +0 (from top)
|
||||
*/
|
||||
|
||||
//kbuild:lib-$(CONFIG_TAIL) += tail.o
|
||||
|
||||
//usage:#define tail_trivial_usage
|
||||
//usage: "[OPTIONS] [FILE]..."
|
||||
//usage:#define tail_full_usage "\n\n"
|
||||
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: )
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -c N[kbm] Print last N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: "\nIf N starts with a '+', output begins with the Nth item from the start"
|
||||
//usage: "\nof each file, not from the end."
|
||||
//usage: )
|
||||
//usage:
|
||||
//usage:#define tail_example_usage
|
||||
@@ -50,6 +50,13 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static const struct suffix_mult tail_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
bool from_top;
|
||||
bool exitcode;
|
||||
@@ -66,6 +73,15 @@ static void tail_xprint_header(const char *fmt, const char *filename)
|
||||
static ssize_t tail_read(int fd, char *buf, size_t count)
|
||||
{
|
||||
ssize_t r;
|
||||
off_t current;
|
||||
struct stat sbuf;
|
||||
|
||||
/* /proc files report zero st_size, don't lseek them. */
|
||||
if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {
|
||||
current = lseek(fd, 0, SEEK_CUR);
|
||||
if (sbuf.st_size < current)
|
||||
xlseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
r = full_read(fd, buf, count);
|
||||
if (r < 0) {
|
||||
@@ -86,7 +102,7 @@ static unsigned eat_num(const char *p)
|
||||
p++;
|
||||
G.from_top = 1;
|
||||
}
|
||||
return xatou_sfx(p, bkm_suffixes);
|
||||
return xatou_sfx(p, tail_suffixes);
|
||||
}
|
||||
|
||||
int tail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -104,7 +120,6 @@ int tail_main(int argc, char **argv)
|
||||
|
||||
int *fds;
|
||||
const char *fmt;
|
||||
int prev_fd;
|
||||
|
||||
INIT_G();
|
||||
|
||||
@@ -309,7 +324,6 @@ int tail_main(int argc, char **argv)
|
||||
xwrite(STDOUT_FILENO, tailbuf, taillen);
|
||||
}
|
||||
} while (++i < nfiles);
|
||||
prev_fd = fds[i-1];
|
||||
|
||||
tailbuf = xrealloc(tailbuf, BUFSIZ);
|
||||
|
||||
@@ -353,23 +367,10 @@ int tail_main(int argc, char **argv)
|
||||
if (nfiles > header_threshhold) {
|
||||
fmt = header_fmt_str;
|
||||
}
|
||||
for (;;) {
|
||||
/* tail -f keeps following files even if they are truncated */
|
||||
struct stat sbuf;
|
||||
/* /proc files report zero st_size, don't lseek them */
|
||||
if (fstat(fd, &sbuf) == 0 && sbuf.st_size > 0) {
|
||||
off_t current = lseek(fd, 0, SEEK_CUR);
|
||||
if (sbuf.st_size < current)
|
||||
xlseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
nread = tail_read(fd, tailbuf, BUFSIZ);
|
||||
if (nread <= 0)
|
||||
break;
|
||||
if (fmt && (fd != prev_fd)) {
|
||||
while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) {
|
||||
if (fmt) {
|
||||
tail_xprint_header(fmt, filename);
|
||||
fmt = NULL;
|
||||
prev_fd = fd;
|
||||
}
|
||||
xwrite(STDOUT_FILENO, tailbuf, nread);
|
||||
}
|
||||
|
||||
+34
-35
@@ -826,6 +826,7 @@ int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
// bool negate = 0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
@@ -843,7 +844,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
/* argc is unused after this point */
|
||||
|
||||
/* We must do DEINIT_S() prior to returning */
|
||||
INIT_S();
|
||||
@@ -862,45 +862,43 @@ int test_main(int argc, char **argv)
|
||||
*/
|
||||
/*ngroups = 0; - done by INIT_S() */
|
||||
|
||||
//argc--;
|
||||
argv++;
|
||||
args = argv;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4.
|
||||
* Testcase: "test '(' = '('"
|
||||
* The general parser would misinterpret '(' as group start.
|
||||
*/
|
||||
if (1) {
|
||||
int negate = 0;
|
||||
again:
|
||||
if (!argv[0]) {
|
||||
/* "test" */
|
||||
res = 1;
|
||||
goto ret_special;
|
||||
}
|
||||
if (!argv[1]) {
|
||||
/* "test [!] arg" */
|
||||
res = (argv[0][0] == '\0');
|
||||
goto ret_special;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
ret_special:
|
||||
/* If there was leading "!" op... */
|
||||
res ^= negate;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
if (LONE_CHAR(argv[0], '!')) {
|
||||
argv++;
|
||||
negate ^= 1;
|
||||
goto again;
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (!argv[0]) { /* "test" */
|
||||
res = 1;
|
||||
goto ret;
|
||||
}
|
||||
#if 0
|
||||
// Now it's fixed in the parser and should not be needed
|
||||
if (LONE_CHAR(argv[0], '!') && argv[1]) {
|
||||
negate = 1;
|
||||
//argc--;
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1]) { /* "test [!] arg" */
|
||||
res = (*argv[0] == '\0');
|
||||
goto ret;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Some complex expression. Undo '!' removal */
|
||||
if (negate) {
|
||||
negate = 0;
|
||||
//argc++;
|
||||
argv--;
|
||||
}
|
||||
#endif
|
||||
args = argv;
|
||||
res = !oexpr(check_operator(*args));
|
||||
|
||||
if (*args != NULL && *++args != NULL) {
|
||||
@@ -913,5 +911,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
ret:
|
||||
DEINIT_S();
|
||||
// return negate ? !res : res;
|
||||
return res;
|
||||
}
|
||||
+4
-35
@@ -26,14 +26,6 @@
|
||||
//config: touch is used to create or change the access and/or
|
||||
//config: modification timestamp of specified files.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_NODEREF
|
||||
//config: bool "Add support for -h"
|
||||
//config: default y
|
||||
//config: depends on TOUCH
|
||||
//config: help
|
||||
//config: Enable touch to have the -h option.
|
||||
//config: This requires libc support for lutimes() function.
|
||||
//config:
|
||||
//config:config FEATURE_TOUCH_SUSV3
|
||||
//config: bool "Add support for SUSV3 features (-d -t -r)"
|
||||
//config: default y
|
||||
@@ -50,9 +42,6 @@
|
||||
//usage:#define touch_full_usage "\n\n"
|
||||
//usage: "Update the last-modified date on the given FILE[s]\n"
|
||||
//usage: "\n -c Don't create files"
|
||||
//usage: IF_FEATURE_TOUCH_NODEREF(
|
||||
//usage: "\n -h Don't follow links"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TOUCH_SUSV3(
|
||||
//usage: "\n -d DT Date/time to use"
|
||||
//usage: "\n -t DT Date/time to use"
|
||||
@@ -76,7 +65,6 @@
|
||||
* parse STRING and use it instead of current time
|
||||
* -f (ignored, BSD compat)
|
||||
* -m change only the modification time
|
||||
* -h, --no-dereference
|
||||
* -r, --reference=FILE
|
||||
* use this file's times instead of current time
|
||||
* -t STAMP
|
||||
@@ -91,13 +79,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int opts;
|
||||
enum {
|
||||
OPT_c = (1 << 0),
|
||||
OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3,
|
||||
OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF,
|
||||
};
|
||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||
# if ENABLE_LONG_OPTS
|
||||
static const char touch_longopts[] ALIGN1 =
|
||||
@@ -105,7 +86,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
"no-create\0" No_argument "c"
|
||||
"reference\0" Required_argument "r"
|
||||
"date\0" Required_argument "d"
|
||||
IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
|
||||
;
|
||||
# endif
|
||||
char *reference_file = NULL;
|
||||
@@ -125,13 +105,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
* accepted data format differs a bit between -d and -t.
|
||||
* We accept the same formats for both */
|
||||
opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:")
|
||||
IF_FEATURE_TOUCH_NODEREF("h")
|
||||
/*ignored:*/ "fma"
|
||||
IF_FEATURE_TOUCH_SUSV3(, &reference_file)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
IF_FEATURE_TOUCH_SUSV3(, &date_str)
|
||||
);
|
||||
|
||||
opts &= 1; /* only -c bit is left */
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
bb_show_usage();
|
||||
@@ -141,10 +121,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct stat stbuf;
|
||||
xstat(reference_file, &stbuf);
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
|
||||
/* Can use .st_mtim.tv_nsec
|
||||
* (or is it .st_mtimensec?? see date.c)
|
||||
* to set microseconds too.
|
||||
*/
|
||||
}
|
||||
|
||||
if (date_str) {
|
||||
@@ -165,16 +141,9 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
do {
|
||||
int result;
|
||||
result = (
|
||||
#if ENABLE_FEATURE_TOUCH_NODEREF
|
||||
(opts & OPT_h) ? lutimes :
|
||||
#endif
|
||||
utimes)(*argv, (reference_file || date_str) ? timebuf : NULL);
|
||||
if (result != 0) {
|
||||
if (errno == ENOENT) { /* no such file? */
|
||||
if (opts & OPT_c) {
|
||||
/* Creation is disabled, so ignore */
|
||||
if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) {
|
||||
if (errno == ENOENT) { /* no such file */
|
||||
if (opts) { /* creation is disabled, so ignore */
|
||||
continue;
|
||||
}
|
||||
/* Try to create the file */
|
||||
|
||||
+4
-6
@@ -49,18 +49,16 @@
|
||||
*/
|
||||
|
||||
//usage:#define uname_trivial_usage
|
||||
//usage: "[-amnrspvio]"
|
||||
//usage: "[-amnrspv]"
|
||||
//usage:#define uname_full_usage "\n\n"
|
||||
//usage: "Print system information\n"
|
||||
//usage: "\n -a Print all"
|
||||
//usage: "\n -m The machine (hardware) type"
|
||||
//usage: "\n -n Hostname"
|
||||
//usage: "\n -r Kernel release"
|
||||
//usage: "\n -s Kernel name (default)"
|
||||
//usage: "\n -r OS release"
|
||||
//usage: "\n -s OS name (default)"
|
||||
//usage: "\n -p Processor type"
|
||||
//usage: "\n -v Kernel version"
|
||||
//usage: "\n -i The hardware platform"
|
||||
//usage: "\n -o OS name"
|
||||
//usage: "\n -v OS version"
|
||||
//usage:
|
||||
//usage:#define uname_example_usage
|
||||
//usage: "$ uname -a\n"
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* unlink for busybox
|
||||
*
|
||||
* Copyright (C) 2014 Isaac Dunham <ibid.ag@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see LICENSE in this source tree
|
||||
*/
|
||||
|
||||
//config:config UNLINK
|
||||
//config: bool "unlink"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlink deletes a file by calling unlink()
|
||||
|
||||
//kbuild:lib-$(CONFIG_UNLINK) += unlink.o
|
||||
|
||||
//applet:IF_UNLINK(APPLET(unlink, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define unlink_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage:#define unlink_full_usage "\n\n"
|
||||
//usage: "Delete FILE by calling unlink()"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlink_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
opt_complementary = "=1"; /* must have exactly 1 param */
|
||||
getopt32(argv, "");
|
||||
argv += optind;
|
||||
xunlink(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
+29
-29
@@ -21,24 +21,24 @@
|
||||
* taken from debian-utils. I've only removed the long options and the
|
||||
* report mode. As the original run-parts support only long options, I've
|
||||
* broken compatibility because the BusyBox policy doesn't allow them.
|
||||
* The supported options are:
|
||||
* -t test. Print the name of the files to be executed, without
|
||||
* execute them.
|
||||
* -a ARG argument. Pass ARG as an argument the program executed. It can
|
||||
* be repeated to pass multiple arguments.
|
||||
* -u MASK umask. Set the umask of the program executed to MASK.
|
||||
*/
|
||||
|
||||
//usage:#define run_parts_trivial_usage
|
||||
//usage: "[-a ARG]... [-u UMASK] "
|
||||
//usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS("[--reverse] [--test] [--exit-on-error] "IF_FEATURE_RUN_PARTS_FANCY("[--list] "))
|
||||
//usage: "DIRECTORY"
|
||||
//usage: "[-t"IF_FEATURE_RUN_PARTS_FANCY("l")"] [-a ARG]... [-u MASK] DIRECTORY"
|
||||
//usage:#define run_parts_full_usage "\n\n"
|
||||
//usage: "Run a bunch of scripts in DIRECTORY\n"
|
||||
//usage: "\n -a ARG Pass ARG as argument to scripts"
|
||||
//usage: "\n -u UMASK Set UMASK before running scripts"
|
||||
//usage: IF_FEATURE_RUN_PARTS_LONG_OPTIONS(
|
||||
//usage: "\n --reverse Reverse execution order"
|
||||
//usage: "\n --test Dry run"
|
||||
//usage: "\n --exit-on-error Exit if a script exits with non-zero"
|
||||
//usage: "\n -t Dry run"
|
||||
//usage: IF_FEATURE_RUN_PARTS_FANCY(
|
||||
//usage: "\n --list Print names of matching files even if they are not executable"
|
||||
//usage: )
|
||||
//usage: "\n -l Print names of matching files even if they are not executable"
|
||||
//usage: )
|
||||
//usage: "\n -a ARG Pass ARG as argument to programs"
|
||||
//usage: "\n -u MASK Set umask to MASK before running programs"
|
||||
//usage:
|
||||
//usage:#define run_parts_example_usage
|
||||
//usage: "$ run-parts -a start /etc/init.d\n"
|
||||
@@ -59,7 +59,7 @@
|
||||
struct globals {
|
||||
char **names;
|
||||
int cur;
|
||||
char *cmd[2 /* using 1 provokes compiler warning */];
|
||||
char *cmd[1];
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define names (G.names)
|
||||
@@ -70,15 +70,19 @@ struct globals {
|
||||
enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 };
|
||||
|
||||
enum {
|
||||
OPT_a = (1 << 0),
|
||||
OPT_u = (1 << 1),
|
||||
OPT_r = (1 << 2) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_t = (1 << 3) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_e = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS,
|
||||
OPT_l = (1 << 5) * ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
|
||||
* ENABLE_FEATURE_RUN_PARTS_FANCY,
|
||||
OPT_r = (1 << 0),
|
||||
OPT_a = (1 << 1),
|
||||
OPT_u = (1 << 2),
|
||||
OPT_t = (1 << 3),
|
||||
OPT_l = (1 << 4) * ENABLE_FEATURE_RUN_PARTS_FANCY,
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_RUN_PARTS_FANCY
|
||||
#define list_mode (option_mask32 & OPT_l)
|
||||
#else
|
||||
#define list_mode 0
|
||||
#endif
|
||||
|
||||
/* Is this a valid filename (upper/lower alpha, digits,
|
||||
* underscores, and hyphens only?)
|
||||
*/
|
||||
@@ -106,7 +110,7 @@ static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUS
|
||||
if (depth == 2
|
||||
&& ( !(statbuf->st_mode & (S_IFREG | S_IFLNK))
|
||||
|| invalid_name(file)
|
||||
|| (!(option_mask32 & OPT_l) && access(file, X_OK) != 0))
|
||||
|| (!list_mode && access(file, X_OK) != 0))
|
||||
) {
|
||||
return SKIP;
|
||||
}
|
||||
@@ -122,12 +126,11 @@ static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUS
|
||||
static const char runparts_longopts[] ALIGN1 =
|
||||
"arg\0" Required_argument "a"
|
||||
"umask\0" Required_argument "u"
|
||||
//TODO: "verbose\0" No_argument "v"
|
||||
"reverse\0" No_argument "\xf0"
|
||||
"test\0" No_argument "\xf1"
|
||||
"exit-on-error\0" No_argument "\xf2"
|
||||
"test\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_RUN_PARTS_FANCY
|
||||
"list\0" No_argument "\xf3"
|
||||
"list\0" No_argument "l"
|
||||
"reverse\0" No_argument "r"
|
||||
//TODO: "verbose\0" No_argument "v"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
@@ -147,7 +150,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* We require exactly one argument: the directory name */
|
||||
opt_complementary = "=1:a::";
|
||||
getopt32(argv, "a:u:", &arg_list, &umask_p);
|
||||
getopt32(argv, "ra:u:t"IF_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p);
|
||||
|
||||
umask(xstrtou_range(umask_p, 8, 0, 07777));
|
||||
|
||||
@@ -190,9 +193,6 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_perror_msg("can't execute '%s'", name);
|
||||
else /* ret > 0 */
|
||||
bb_error_msg("%s exited with code %d", name, ret & 0xff);
|
||||
|
||||
if (option_mask32 & OPT_e)
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
+61
-24
@@ -1,9 +1,13 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Which implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
* Based on which from debianutils
|
||||
*/
|
||||
|
||||
//usage:#define which_trivial_usage
|
||||
@@ -20,43 +24,76 @@
|
||||
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int which_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
const char *env_path;
|
||||
int status = 0;
|
||||
|
||||
env_path = getenv("PATH");
|
||||
if (!env_path)
|
||||
env_path = bb_default_root_path;
|
||||
IF_DESKTOP(int opt;)
|
||||
int status = EXIT_SUCCESS;
|
||||
char *path;
|
||||
char *p;
|
||||
|
||||
opt_complementary = "-1"; /* at least one argument */
|
||||
getopt32(argv, "a");
|
||||
IF_DESKTOP(opt =) getopt32(argv, "a");
|
||||
argv += optind;
|
||||
|
||||
/* This matches what is seen on e.g. ubuntu.
|
||||
* "which" there is a shell script. */
|
||||
path = getenv("PATH");
|
||||
if (!path) {
|
||||
path = (char*)bb_PATH_root_path;
|
||||
putenv(path);
|
||||
path += 5; /* skip "PATH=" */
|
||||
}
|
||||
|
||||
do {
|
||||
int missing = 1;
|
||||
|
||||
/* If file contains a slash don't use PATH */
|
||||
#if ENABLE_DESKTOP
|
||||
/* Much bloat just to support -a */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (file_is_executable(*argv)) {
|
||||
missing = 0;
|
||||
if (execable_file(*argv)) {
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
} else {
|
||||
char *path;
|
||||
char *tmp;
|
||||
char *p;
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
|
||||
path = tmp = xstrdup(env_path);
|
||||
while ((p = find_executable(*argv, &tmp)) != NULL) {
|
||||
missing = 0;
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (!p)
|
||||
status = EXIT_FAILURE;
|
||||
else {
|
||||
print:
|
||||
puts(p);
|
||||
free(p);
|
||||
if (!option_mask32) /* -a not set */
|
||||
break;
|
||||
if (opt) {
|
||||
/* -a: show matches in all PATH components */
|
||||
if (tmp) {
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (p)
|
||||
goto print;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
free(path2);
|
||||
}
|
||||
status |= missing;
|
||||
} while (*++argv);
|
||||
#else
|
||||
/* Just ignoring -a */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (execable_file(*argv)) {
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
p = find_execable(*argv, &tmp);
|
||||
free(path2);
|
||||
if (p) {
|
||||
puts(p);
|
||||
free(p);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
#endif
|
||||
} while (*(++argv) != NULL);
|
||||
|
||||
return status;
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
||||
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
||||
int i ;
|
||||
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||
if (executable_exists(ext_dhcp_clients[i].name))
|
||||
if (exists_execable(ext_dhcp_clients[i].name))
|
||||
return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
||||
}
|
||||
bb_error_msg("no dhcp clients found, using static interface shutdown");
|
||||
|
||||
@@ -103,15 +103,7 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro:
|
||||
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
|
||||
Typically it is done in <applet>_main(). Another variation is
|
||||
to use stack:
|
||||
|
||||
int <applet>_main(...)
|
||||
{
|
||||
#undef G
|
||||
struct globals G;
|
||||
memset(&G, 0, sizeof(G));
|
||||
SET_PTR_TO_GLOBALS(&G);
|
||||
Typically it is done in <applet>_main().
|
||||
|
||||
Now you can reference "globals" by G.a, G.buf and so on, in any function.
|
||||
|
||||
@@ -146,6 +138,13 @@ less readable, use #defines:
|
||||
#define sector (G.sector)
|
||||
|
||||
|
||||
Word of caution
|
||||
|
||||
If applet doesn't use much of global data, converting it to use
|
||||
one of above methods is not worth the resulting code obfuscation.
|
||||
If you have less than ~300 bytes of global data - don't bother.
|
||||
|
||||
|
||||
Finding non-shared duplicated strings
|
||||
|
||||
strings busybox | sort | uniq -c | sort -nr
|
||||
@@ -225,14 +224,6 @@ Result (non-static busybox built against glibc):
|
||||
|
||||
Keeping code small
|
||||
|
||||
Use scripts/bloat-o-meter to check whether introduced changes
|
||||
didn't generate unnecessary bloat. This script needs unstripped binaries
|
||||
to generate a detailed report. To automate this, just use
|
||||
"make bloatcheck". It requires busybox_old binary to be present,
|
||||
use "make baseline" to generate it from unmodified source, or
|
||||
copy busybox_unstripped to busybox_old before modifying sources
|
||||
and rebuilding.
|
||||
|
||||
Set CONFIG_EXTRA_CFLAGS="-fno-inline-functions-called-once",
|
||||
produce "make bloatcheck", see the biggest auto-inlined functions.
|
||||
Now, set CONFIG_EXTRA_CFLAGS back to "", but add NOINLINE
|
||||
|
||||
@@ -45,8 +45,6 @@ udhcpc - auto-backgrounds unless -f after lease is obtained,
|
||||
udhcpd - auto-backgrounds and do not log to stderr unless -f,
|
||||
otherwise logs to stderr, but option -S makes it log *also* to syslog
|
||||
zcip - auto-backgrounds and logs *also* to syslog unless -f
|
||||
behaviour can be overridden with experimental LOGGING env.var
|
||||
(can be set to either "none" or "syslog")
|
||||
|
||||
Total: 13 applets (+1 obsolete),
|
||||
4 log to syslog by default (crond fakeidentd inetd zcip),
|
||||
|
||||
+2
-2
@@ -51,9 +51,9 @@ device nodes if your system needs something more than the default root/root
|
||||
660 permissions.
|
||||
|
||||
The file has the format:
|
||||
[-][envmatch]<device regex> <uid>:<gid> <permissions>
|
||||
[-]<device regex> <uid>:<gid> <permissions>
|
||||
or
|
||||
[envmatch]@<maj[,min1[-min2]]> <uid>:<gid> <permissions>
|
||||
@<maj[,min1[-min2]]> <uid>:<gid> <permissions>
|
||||
or
|
||||
$envvar=<regex> <uid>:<gid> <permissions>
|
||||
|
||||
|
||||
+40
-64
@@ -6,7 +6,7 @@ This document details the steps you must take to add a new applet to BusyBox.
|
||||
Credits:
|
||||
Matt Kraai - initial writeup
|
||||
Mark Whitley - the remix
|
||||
Thomas Lundquist - trying to keep it updated
|
||||
Thomas Lundquist - Trying to keep it updated.
|
||||
|
||||
When doing this you should consider using the latest git HEAD.
|
||||
This is a good thing if you plan to getting it committed into mainline.
|
||||
@@ -16,14 +16,14 @@ Initial Write
|
||||
|
||||
First, write your applet. Be sure to include copyright information at the top,
|
||||
such as who you stole the code from and so forth. Also include the mini-GPL
|
||||
boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
|
||||
in this document). Be sure to name the main function <applet>_main instead
|
||||
of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
|
||||
as the first include file in your applet.
|
||||
boilerplate. Be sure to name the main function <applet>_main instead of main.
|
||||
And be sure to put it in <applet>.c. Usage does not have to be taken care of by
|
||||
your applet.
|
||||
Make sure to #include "libbb.h" as the first include file in your applet.
|
||||
|
||||
For a new applet mu, here is the code that would go in mu.c:
|
||||
|
||||
(libbb.h already includes most usual header files. You do not need
|
||||
(busybox.h already includes most usual header files. You do not need
|
||||
#include <stdio.h> etc...)
|
||||
|
||||
|
||||
@@ -41,22 +41,6 @@ For a new applet mu, here is the code that would go in mu.c:
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
|
||||
int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mu_main(int argc, char **argv)
|
||||
{
|
||||
@@ -106,8 +90,6 @@ Make a new file named <function_name>.c
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//kbuild:lib-y += function.o
|
||||
|
||||
int function(char *a)
|
||||
{
|
||||
return *a;
|
||||
@@ -115,7 +97,9 @@ int function(char *a)
|
||||
|
||||
----end example code------
|
||||
|
||||
Remember about the kbuild snippet.
|
||||
Add <function_name>.o in the right alphabetically sorted place
|
||||
in libbb/Kbuild.src. You should look at the conditional part of
|
||||
libbb/Kbuild.src as well.
|
||||
|
||||
You should also try to find a suitable place in include/libbb.h for
|
||||
the function declaration. If not, add it somewhere anyway, with or without
|
||||
@@ -125,68 +109,60 @@ You can look at libbb/Config.src and try to find out if the function is
|
||||
tunable and add it there if it is.
|
||||
|
||||
|
||||
Kbuild/Config.in/usage/applets.h snippets in .c files
|
||||
-----------------------------------------------------
|
||||
|
||||
The old way of adding new applets was to put all the information needed by the
|
||||
configuration and build system into appropriate files (namely: Kbuild.src and
|
||||
Config.src in new applet's directory) and to add the applet declaration and
|
||||
usage info text to include/applets.src.h and include/usage.src.h respectively.
|
||||
|
||||
Since the scripts/gen_build_files.sh script had been introduced, the preferred
|
||||
way is to have all these declarations contained within the applet .c files.
|
||||
|
||||
Every line intended to be processed by gen_build_files.sh should start as a
|
||||
comment without any preceding whitespaces and be followed by an appropriate
|
||||
keyword - kbuild, config, usage or applet - and a colon, just like shown in the
|
||||
first example above.
|
||||
|
||||
|
||||
Placement / Directory
|
||||
---------------------
|
||||
|
||||
Find the appropriate directory for your new applet.
|
||||
|
||||
Add the kbuild snippet to the .c file:
|
||||
Make sure you find the appropriate places in the files, the applets are
|
||||
sorted alphabetically.
|
||||
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
Add the applet to Kbuild.src in the chosen directory:
|
||||
|
||||
Add the config snippet to the .c file:
|
||||
lib-$(CONFIG_MU) += mu.o
|
||||
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
Add the applet to Config.src in the chosen directory:
|
||||
|
||||
config MU
|
||||
bool "MU"
|
||||
default n
|
||||
help
|
||||
Returns an indeterminate value.
|
||||
|
||||
|
||||
Usage String(s)
|
||||
---------------
|
||||
|
||||
Next, add usage information for your applet to the .c file.
|
||||
Next, add usage information for you applet to include/usage.src.h.
|
||||
This should look like the following:
|
||||
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
//usage: ...
|
||||
#define mu_trivial_usage \
|
||||
"-[abcde] FILES"
|
||||
#define mu_full_usage \
|
||||
"Returns an indeterminate value.\n\n" \
|
||||
"Options:\n" \
|
||||
"\t-a\t\tfirst function\n" \
|
||||
"\t-b\t\tsecond function\n" \
|
||||
...
|
||||
|
||||
If your program supports flags, the flags should be mentioned on the first
|
||||
line ([-abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line.
|
||||
line (-[abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line. (Numerous examples of this
|
||||
currently exist in usage.src.h.)
|
||||
|
||||
|
||||
Header Files
|
||||
------------
|
||||
|
||||
Finally add the applet declaration snippet. Be sure to read the top of
|
||||
applets.src.h before adding your applet - it contains important info
|
||||
on applet macros and conventions.
|
||||
Next, add an entry to include/applets.src.h. Be *sure* to keep the list
|
||||
in alphabetical order, or else it will break the binary-search lookup
|
||||
algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
|
||||
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
Be sure to read the top of applets.src.h before adding your applet.
|
||||
|
||||
/* all programs above here are alphabetically "less than" 'mu' */
|
||||
IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* all programs below here are alphabetically "greater than" 'mu' */
|
||||
|
||||
|
||||
The Grand Announcement
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
Some less-widely known details of TCP connections.
|
||||
|
||||
Properly closing the connection.
|
||||
|
||||
After this code sequence:
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
connect(sock, &remote, sizeof(remote));
|
||||
write(sock, buffer, 1000000);
|
||||
|
||||
a large block of data is only buffered by kernel, it can't be sent all at once.
|
||||
What will happen if we close the socket?
|
||||
|
||||
"A host MAY implement a 'half-duplex' TCP close sequence, so that
|
||||
an application that has called close() cannot continue to read
|
||||
data from the connection. If such a host issues a close() call
|
||||
while received data is still pending in TCP, or if new data is
|
||||
received after close() is called, its TCP SHOULD send a RST
|
||||
to show that data was lost."
|
||||
|
||||
IOW: if we just close(sock) now, kernel can reset the TCP connection
|
||||
(send RST packet).
|
||||
|
||||
This is problematic for two reasons: it discards some not-yet sent
|
||||
data, and it may be reported as error, not EOF, on peer's side.
|
||||
|
||||
What can be done about it?
|
||||
|
||||
Solution #1: block until sending is done:
|
||||
|
||||
/* When enabled, a close(2) or shutdown(2) will not return until
|
||||
* all queued messages for the socket have been successfully sent
|
||||
* or the linger timeout has been reached.
|
||||
*/
|
||||
struct linger {
|
||||
int l_onoff; /* linger active */
|
||||
int l_linger; /* how many seconds to linger for */
|
||||
} linger;
|
||||
linger.l_onoff = 1;
|
||||
linger.l_linger = SOME_NUM;
|
||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
|
||||
close(sock);
|
||||
|
||||
Solution #2: tell kernel that you are done sending.
|
||||
This makes kernel send FIN after all data is written:
|
||||
|
||||
shutdown(sock, SHUT_WR);
|
||||
close(sock);
|
||||
|
||||
However, experiments on Linux 3.9.4 show that kernel can return from
|
||||
shutdown() and from close() before all data is sent,
|
||||
and if peer sends any data to us after this, kernel still responds with
|
||||
RST before all our data is sent.
|
||||
|
||||
In practice the protocol in use often does not allow peer to send
|
||||
such data to us, in which case this solution is acceptable.
|
||||
|
||||
Solution #3: if you know that peer is going to close its end after it sees
|
||||
our FIN (as EOF), it might be a good idea to perform a read after shutdown().
|
||||
When read finishes with 0-sized result, we conclude that peer received all
|
||||
the data, saw EOF, and closed its end.
|
||||
|
||||
However, this incurs small performance penalty (we run for a longer time)
|
||||
and requires safeguards (nonblocking reads, timeouts etc) against
|
||||
malicious peers which don't close the connection.
|
||||
|
||||
Solutions #1 and #2 can be combined:
|
||||
|
||||
/* ...set up struct linger... then: */
|
||||
setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
|
||||
shutdown(sock, SHUT_WR);
|
||||
/* At this point, kernel sent FIN packet, not RST, to the peer, */
|
||||
/* even if there is buffered read data from the peer. */
|
||||
close(sock);
|
||||
|
||||
Defeating Nagle.
|
||||
|
||||
Method #1: manually control whether partial sends are allowed:
|
||||
|
||||
This prevents partially filled packets being sent:
|
||||
|
||||
int state = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
|
||||
|
||||
and this forces last, partially filled packet (if any) to be sent:
|
||||
|
||||
int state = 0;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
|
||||
|
||||
Method #2: make any write to immediately send data, even if it's partial:
|
||||
|
||||
int state = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &state, sizeof(state));
|
||||
@@ -1,50 +0,0 @@
|
||||
Busybox unit test framework
|
||||
===========================
|
||||
|
||||
This document describes what you need to do to write test cases using the
|
||||
Busybox unit test framework.
|
||||
|
||||
|
||||
Building unit tests
|
||||
-------------------
|
||||
|
||||
The framework and all tests are built as a regular Busybox applet if option
|
||||
CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
|
||||
|
||||
|
||||
Writing test cases
|
||||
------------------
|
||||
|
||||
Unit testing interface can be found in include/bbunit.h.
|
||||
|
||||
Tests can be placed in any .c file in Busybox tree - preferably right next to
|
||||
the functions they test. Test cases should be enclosed within an #if, and
|
||||
should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
|
||||
the test curly brackets. If an assertion fails the test ends immediately, ie.
|
||||
the following assertions will not be reached. Any code placed after
|
||||
BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
|
||||
|
||||
#if ENABLE_UNIT_TEST
|
||||
|
||||
BBUNIT_DEFINE_TEST(test_name)
|
||||
{
|
||||
int *i;
|
||||
|
||||
i = malloc(sizeof(int));
|
||||
BBUNIT_ASSERT_NOTNULL(i);
|
||||
*i = 2;
|
||||
BBUNIT_ASSERT_EQ((*i)*(*i), 4);
|
||||
|
||||
BBUNIT_ENDTEST;
|
||||
|
||||
free(i);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_UNIT_TEST */
|
||||
|
||||
|
||||
Running the unit test suite
|
||||
---------------------------
|
||||
|
||||
To run the tests you can either directly run 'busybox unit' or use 'make test'
|
||||
to run both the unit tests (if compiled) and regular test suite.
|
||||
@@ -179,4 +179,8 @@ extern int blkid_set_tag(blkid_dev dev, const char *name,
|
||||
extern blkid_dev blkid_new_dev(void);
|
||||
extern void blkid_free_dev(blkid_dev dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -115,7 +115,7 @@ int main(int argc, char** argv)
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_probe_all(cache)) < 0)
|
||||
if ((ret = blkid_probe_all(cache) < 0))
|
||||
fprintf(stderr, "error probing devices\n");
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
@@ -153,7 +153,7 @@ extern int optind;
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog);
|
||||
fprintf(stderr, "\tList all devices and exit\n");
|
||||
fprintf(stderr, "\tList all devices and exit\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
fprintf(stderr, "Invalid debug mask: %d\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ void blkid_read_cache(blkid_cache cache)
|
||||
continue;
|
||||
end = strlen(buf) - 1;
|
||||
/* Continue reading next line if it ends with a backslash */
|
||||
while (end < sizeof(buf) - 2 && buf[end] == '\\' &&
|
||||
while (buf[end] == '\\' && end < sizeof(buf) - 2 &&
|
||||
fgets(buf + end, sizeof(buf) - end, file)) {
|
||||
end = strlen(buf) - 1;
|
||||
lineno++;
|
||||
|
||||
@@ -356,7 +356,7 @@ void usage(char *prog)
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device "
|
||||
"[type value]\n",
|
||||
prog);
|
||||
fprintf(stderr, "\tList all tags for a device and exit\n");
|
||||
fprintf(stderr, "\tList all tags for a device and exit\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
fprintf(stderr, "Invalid debug mask: %d\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
@@ -407,7 +407,7 @@ int main(int argc, char **argv)
|
||||
|
||||
dev = blkid_get_dev(cache, devname, flags);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "%s: cannot find device in blkid cache\n", devname);
|
||||
fprintf(stderr, "%s: cannot find device in blkid cache\n");
|
||||
exit(1);
|
||||
}
|
||||
if (search_type) {
|
||||
|
||||
@@ -1050,7 +1050,7 @@ static errcode_t ea_refcount_create(int size, ext2_refcount_t *ret)
|
||||
refcount->size = size;
|
||||
bytes = (size_t) (size * sizeof(struct ea_refcount_el));
|
||||
#ifdef DEBUG
|
||||
printf("Refcount allocated %d entries, %lu bytes.\n",
|
||||
printf("Refcount allocated %d entries, %d bytes.\n",
|
||||
refcount->size, bytes);
|
||||
#endif
|
||||
retval = ext2fs_get_mem(bytes, &refcount->list);
|
||||
@@ -3424,7 +3424,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
|
||||
continue;
|
||||
}
|
||||
if ((inode->i_links_count || inode->i_blocks ||
|
||||
inode->i_block[0]) &&
|
||||
inode->i_blocks || inode->i_block[0]) &&
|
||||
fix_problem(ctx, PR_1_JOURNAL_INODE_NOT_CLEAR,
|
||||
&pctx)) {
|
||||
memset(inode, 0, inode_size);
|
||||
@@ -12195,7 +12195,11 @@ static void swap_filesys(e2fsck_t ctx)
|
||||
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
|
||||
const char *description)
|
||||
{
|
||||
return xzalloc(size);
|
||||
void *ret;
|
||||
char buf[256];
|
||||
|
||||
ret = xzalloc(size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *string_copy(const char *str, int len)
|
||||
|
||||
@@ -83,7 +83,7 @@ static int calc_reserved_gdt_blocks(ext2_filsys fs)
|
||||
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
|
||||
rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
|
||||
#ifdef RES_GDT_DEBUG
|
||||
printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %u\n",
|
||||
printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %lu\n",
|
||||
max_blocks, rsv_groups, rsv_gdb);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -544,7 +544,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block,
|
||||
/* If it's in the cache, use it! */
|
||||
if ((cache = find_cached_block(data, block, &reuse[0]))) {
|
||||
#ifdef DEBUG
|
||||
printf("Using cached block %lu\n", block);
|
||||
printf("Using cached block %d\n", block);
|
||||
#endif
|
||||
memcpy(cp, cache->buf, channel->block_size);
|
||||
count--;
|
||||
@@ -560,7 +560,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block,
|
||||
if (find_cached_block(data, block+i, &reuse[i]))
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
printf("Reading %d blocks starting at %lu\n", i, block);
|
||||
printf("Reading %d blocks starting at %d\n", i, block);
|
||||
#endif
|
||||
if ((retval = raw_read_blk(channel, data, block, i, cp)))
|
||||
return retval;
|
||||
|
||||
@@ -1239,6 +1239,7 @@ static void PRS(int argc, char **argv)
|
||||
progress_fd = 0;
|
||||
else {
|
||||
goto next_arg;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -239,7 +239,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
|
||||
errcode_t retval;
|
||||
char buf[1024];
|
||||
|
||||
sprintf(buf, "badblocks -b %u %s%s%s %d", fs->blocksize,
|
||||
sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
|
||||
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
|
||||
fs->device_name, fs->super->s_blocks_count);
|
||||
mke2fs_verbose("Running command: %s\n", buf);
|
||||
@@ -385,7 +385,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
|
||||
struct progress_struct *progress,
|
||||
blk_t *ret_blk, int *ret_count)
|
||||
{
|
||||
int j, count, next_update;
|
||||
int j, count, next_update, next_update_incr;
|
||||
static char *buf;
|
||||
errcode_t retval;
|
||||
|
||||
@@ -403,7 +403,9 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num,
|
||||
}
|
||||
/* OK, do the write loop */
|
||||
next_update = 0;
|
||||
|
||||
next_update_incr = num / 100;
|
||||
if (next_update_incr < 1)
|
||||
next_update_incr = 1;
|
||||
for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) {
|
||||
count = num - j;
|
||||
if (count > STRIDE_LENGTH)
|
||||
|
||||
Loaded 100 of 391 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user