Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49b78fc1a8 | ||
|
|
a3087ca749 | ||
|
|
0abe9d96ee | ||
|
|
378481ed1e | ||
|
|
fc9fc1f929 |
No files matched your search
-63
@@ -1,63 +0,0 @@
|
||||
#
|
||||
# Kbuild ignores
|
||||
#
|
||||
.*
|
||||
*.o
|
||||
*.o.*
|
||||
*.a
|
||||
*.s
|
||||
Kbuild
|
||||
Config.in
|
||||
|
||||
#
|
||||
# Never ignore these
|
||||
#
|
||||
!.gitignore
|
||||
|
||||
#
|
||||
# Normal output
|
||||
#
|
||||
/busybox
|
||||
/busybox_old
|
||||
/busybox_unstripped*
|
||||
|
||||
#
|
||||
# Backups / patches
|
||||
#
|
||||
*~
|
||||
*.orig
|
||||
*.rej
|
||||
/*.patch
|
||||
|
||||
#
|
||||
# debugging stuff
|
||||
#
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
#
|
||||
# testing output
|
||||
#
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
|
||||
#
|
||||
# cscope output
|
||||
#
|
||||
cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
|
||||
#
|
||||
# ctags output
|
||||
#
|
||||
tags
|
||||
TAGS
|
||||
|
||||
#
|
||||
# user-supplied scripts
|
||||
#
|
||||
/embed
|
||||
@@ -146,10 +146,6 @@ Rob Sullivan <cogito.ergo.cogito@gmail.com>
|
||||
Linus Torvalds
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Linus Walleij
|
||||
fbset and fbsplash config RGBA parsing
|
||||
rewrite of mdev helper to create devices from /sys/dev
|
||||
|
||||
Mark Whitley <markw@codepoet.org>
|
||||
grep, sed, cut, xargs(previous),
|
||||
style-guide, new-applet-HOWTO, bug fixes, etc.
|
||||
@@ -170,17 +166,8 @@ Paul Fox <pgf@foxharp.boston.ma.us>
|
||||
Roberto A. Foglietta <me@roberto.foglietta.name>
|
||||
port: dnsd
|
||||
|
||||
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
|
||||
Bernhard Fischer <rep.nop@aon.at>
|
||||
misc
|
||||
|
||||
Mike Frysinger <vapier@gentoo.org>
|
||||
initial e2fsprogs, printenv, setarch, sum, misc
|
||||
|
||||
Jie Zhang <jie.zhang@analog.com>
|
||||
fixed two bugs in msh and hush (exitcode of killed processes)
|
||||
|
||||
Maxime Coste <mawww@kakoune.org>
|
||||
paste implementation
|
||||
|
||||
Roger Knecht <rknecht@pm.me>
|
||||
tree
|
||||
@@ -19,24 +19,11 @@ it, is to enable all features and then use "standalone shell" mode with a
|
||||
blank command $PATH.
|
||||
|
||||
To enable all features, use "make defconfig", which produces the largest
|
||||
general-purpose configuration. It's allyesconfig minus debugging options,
|
||||
general-purpose configuration. (It's allyesconfig minus debugging options,
|
||||
optional packaging choices, and a few special-purpose features requiring
|
||||
extra configuration to use. Then enable "standalone shell" feature:
|
||||
extra configuration to use.)
|
||||
|
||||
make defconfig
|
||||
make menuconfig
|
||||
# select Busybox Settings
|
||||
# then General Configuration
|
||||
# then exec prefers applets
|
||||
# exit back to top level menu
|
||||
# select Shells
|
||||
# then Standalone shell
|
||||
# exit back to top level menu
|
||||
# exit and save new configuration
|
||||
# OR
|
||||
# use these commands to modify .config directly:
|
||||
sed -e 's/.*FEATURE_PREFER_APPLETS.*/CONFIG_FEATURE_PREFER_APPLETS=y/' -i .config
|
||||
sed -e 's/.*FEATURE_SH_STANDALONE.*/CONFIG_FEATURE_SH_STANDALONE=y/' -i .config
|
||||
make
|
||||
PATH= ./busybox ash
|
||||
|
||||
@@ -47,11 +34,8 @@ the only commands busybox can find are the built-in ones.
|
||||
|
||||
Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
|
||||
to be set appropriately, depending on whether or not /proc/self/exe is
|
||||
available. If you do not have /proc, then point that config option
|
||||
available or not. If you do not have /proc, then point that config option
|
||||
to the location of your busybox binary, usually /bin/busybox.
|
||||
Another solution is to patch the kernel (see
|
||||
examples/linux-*_proc_self_exe.patch) to make exec("/proc/self/exe")
|
||||
always work.
|
||||
|
||||
Configuring Busybox:
|
||||
====================
|
||||
@@ -73,9 +57,7 @@ create a known starting point.
|
||||
Other starting configurations (mostly used for testing purposes) include
|
||||
"make allbareconfig" (enables all applets but disables all optional features),
|
||||
"make allyesconfig" (enables absolutely everything including debug features),
|
||||
and "make randconfig" (produce a random configuration). The configs/ directory
|
||||
contains a number of additional configuration files ending in _defconfig which
|
||||
are useful in specific cases. "make help" will list them.
|
||||
and "make randconfig" (produce a random configuration).
|
||||
|
||||
Configuring BusyBox produces a file ".config", which can be saved for future
|
||||
use. Run "make oldconfig" to bring a .config file from an older version of
|
||||
@@ -102,7 +84,7 @@ first argument to determine which applet to behave as, for example
|
||||
"./busybox cat LICENSE". (Running the busybox applet with no arguments gives
|
||||
a list of all enabled applets.) The standalone shell can also call busybox
|
||||
applets without links to busybox under other names in the filesystem. You can
|
||||
also configure a standalone install capability into the busybox base applet,
|
||||
also configure a standaone install capability into the busybox base applet,
|
||||
and then install such links at runtime with one of "busybox --install" (for
|
||||
hardlinks) or "busybox --install -s" (for symlinks).
|
||||
|
||||
@@ -122,7 +104,7 @@ somewhere else.
|
||||
|
||||
To build out of tree, cd to an empty directory and configure busybox from there:
|
||||
|
||||
make KBUILD_SRC=/path/to/source -f /path/to/source/Makefile defconfig
|
||||
make -f /path/to/source/Makefile defconfig
|
||||
make
|
||||
make install
|
||||
|
||||
@@ -139,4 +121,5 @@ More Information:
|
||||
|
||||
Se also the busybox FAQ, under the questions "How can I get started using
|
||||
BusyBox" and "How do I build a BusyBox-based system?" The BusyBox FAQ is
|
||||
available from http://www.busybox.net/FAQ.html
|
||||
available from http://www.busybox.net/FAQ.html or as the file
|
||||
docs/busybox.net/FAQ.html in this tarball.
|
||||
@@ -10,7 +10,7 @@ distributed under.
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@@ -313,7 +313,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 39
|
||||
SUBLEVEL = 0
|
||||
EXTRAVERSION = .git
|
||||
PATCHLEVEL = 10
|
||||
SUBLEVEL = 3
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
# *DOCUMENTATION*
|
||||
@@ -142,6 +142,17 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
|
||||
export srctree objtree VPATH TOPDIR
|
||||
|
||||
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
-e s/arm.*/arm/ -e s/sa110/arm/ \
|
||||
-e s/s390x/s390/ -e s/parisc64/parisc/ \
|
||||
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
|
||||
|
||||
# Cross compiling and selecting different set of gcc/bin-utils
|
||||
# ---------------------------------------------------------------------------
|
||||
#
|
||||
@@ -161,33 +172,8 @@ export srctree objtree VPATH TOPDIR
|
||||
# Default value for CROSS_COMPILE is not to prefix executables
|
||||
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
|
||||
|
||||
CROSS_COMPILE ?=
|
||||
# bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
|
||||
# and it has not been included yet... thus using an awkward syntax.
|
||||
ifeq ($(CROSS_COMPILE),)
|
||||
CROSS_COMPILE := $(shell grep ^CONFIG_CROSS_COMPILER_PREFIX .config 2>/dev/null)
|
||||
CROSS_COMPILE := $(subst CONFIG_CROSS_COMPILER_PREFIX=,,$(CROSS_COMPILE))
|
||||
CROSS_COMPILE := $(subst ",,$(CROSS_COMPILE))
|
||||
#")
|
||||
endif
|
||||
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1 | sed 's:^.*/::g')
|
||||
else
|
||||
SUBARCH := $(shell uname -m)
|
||||
endif
|
||||
SUBARCH := $(shell echo $(SUBARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
-e s/arm.*/arm/ -e s/sa110/arm/ \
|
||||
-e s/s390x/s390/ -e s/parisc64/parisc/ \
|
||||
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
|
||||
|
||||
ARCH ?= $(SUBARCH)
|
||||
ARCH ?= $(SUBARCH)
|
||||
CROSS_COMPILE ?=
|
||||
|
||||
# Architecture as present in compile.h
|
||||
UTS_MACHINE := $(ARCH)
|
||||
@@ -297,7 +283,6 @@ NM = $(CROSS_COMPILE)nm
|
||||
STRIP = $(CROSS_COMPILE)strip
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||
PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
|
||||
AWK = awk
|
||||
GENKSYMS = scripts/genksyms/genksyms
|
||||
DEPMOD = /sbin/depmod
|
||||
@@ -317,8 +302,6 @@ AFLAGS_KERNEL =
|
||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
CFLAGS := $(CFLAGS)
|
||||
# Added only to final link stage of busybox binary
|
||||
CFLAGS_busybox := $(CFLAGS_busybox)
|
||||
CPPFLAGS := $(CPPFLAGS)
|
||||
AFLAGS := $(AFLAGS)
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
@@ -359,20 +342,6 @@ scripts_basic:
|
||||
# To avoid any implicit rule to kick in, define an empty command.
|
||||
scripts/basic/%: scripts_basic ;
|
||||
|
||||
# This target generates Kbuild's and Config.in's from *.c files
|
||||
PHONY += gen_build_files
|
||||
gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c) $(wildcard $(srctree)/embed/*)
|
||||
$(Q)$(srctree)/scripts/gen_build_files.sh $(srctree) $(objtree)
|
||||
|
||||
# bbox: we have helpers in applets/
|
||||
# we depend on scripts_basic, since scripts/basic/fixdep
|
||||
# must be built before any other host prog
|
||||
PHONY += applets_dir
|
||||
applets_dir: scripts_basic gen_build_files include/config/MARKER
|
||||
$(Q)$(MAKE) $(build)=applets
|
||||
|
||||
applets/%: applets_dir ;
|
||||
|
||||
PHONY += outputmakefile
|
||||
# outputmakefile generates a Makefile in the output directory, if using a
|
||||
# separate output directory. This allows convenient use of make in the
|
||||
@@ -392,8 +361,7 @@ endif
|
||||
# of make so .config is not included in this case either (for *config).
|
||||
|
||||
no-dot-config-targets := clean mrproper distclean \
|
||||
cscope TAGS tags help %docs
|
||||
#bbox# check% is removed from above
|
||||
cscope TAGS tags help %docs check%
|
||||
|
||||
config-targets := 0
|
||||
mixed-targets := 0
|
||||
@@ -434,12 +402,7 @@ ifeq ($(config-targets),1)
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
export KBUILD_DEFCONFIG
|
||||
|
||||
config: scripts_basic outputmakefile gen_build_files FORCE
|
||||
$(Q)mkdir -p include
|
||||
$(Q)$(MAKE) $(build)=scripts/kconfig $@
|
||||
$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= .kernelrelease
|
||||
|
||||
%config: scripts_basic outputmakefile gen_build_files FORCE
|
||||
config %config: scripts_basic outputmakefile FORCE
|
||||
$(Q)mkdir -p include
|
||||
$(Q)$(MAKE) $(build)=scripts/kconfig $@
|
||||
$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= .kernelrelease
|
||||
@@ -452,9 +415,9 @@ else
|
||||
ifeq ($(KBUILD_EXTMOD),)
|
||||
# Additional helpers built in scripts/
|
||||
# Carefully list dependencies so we do not try to build scripts twice
|
||||
# in parallel
|
||||
# in parrallel
|
||||
PHONY += scripts
|
||||
scripts: gen_build_files scripts_basic include/config/MARKER
|
||||
scripts: scripts_basic include/config/MARKER
|
||||
$(Q)$(MAKE) $(build)=$(@)
|
||||
|
||||
scripts_basic: include/autoconf.h
|
||||
@@ -465,21 +428,18 @@ core-y := \
|
||||
|
||||
libs-y := \
|
||||
archival/ \
|
||||
archival/libarchive/ \
|
||||
archival/libunarchive/ \
|
||||
console-tools/ \
|
||||
coreutils/ \
|
||||
coreutils/libcoreutils/ \
|
||||
debianutils/ \
|
||||
klibc-utils/ \
|
||||
e2fsprogs/ \
|
||||
editors/ \
|
||||
findutils/ \
|
||||
init/ \
|
||||
libbb/ \
|
||||
libbb/yescrypt/ \
|
||||
libpwdgrp/ \
|
||||
loginutils/ \
|
||||
mailutils/ \
|
||||
miscutils/ \
|
||||
modutils/ \
|
||||
networking/ \
|
||||
@@ -510,8 +470,6 @@ ifeq ($(dot-config),1)
|
||||
# To avoid any implicit rule to kick in, define an empty command
|
||||
.config .kconfig.d: ;
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
|
||||
# Now we can define CFLAGS etc according to .config
|
||||
include $(srctree)/Makefile.flags
|
||||
|
||||
@@ -519,11 +477,9 @@ include $(srctree)/Makefile.flags
|
||||
# with it and forgot to run make oldconfig.
|
||||
# If kconfig.d is missing then we are probarly in a cleaned tree so
|
||||
# we execute the config step to be sure to catch updated Kconfig files
|
||||
include/autoconf.h: .kconfig.d .config $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c) | gen_build_files
|
||||
include/autoconf.h: .kconfig.d .config
|
||||
$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
|
||||
|
||||
include/usage.h: gen_build_files
|
||||
|
||||
else
|
||||
# Dummy target needed, because used as prerequisite
|
||||
include/autoconf.h: ;
|
||||
@@ -533,12 +489,20 @@ endif
|
||||
# command line.
|
||||
# This allow a user to issue only 'make' to build a kernel including modules
|
||||
# Defaults busybox but it is usually overridden in the arch makefile
|
||||
all: busybox doc
|
||||
all: busybox
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
|
||||
# arch Makefile may override CC so keep this after arch Makefile is included
|
||||
#bbox# NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
|
||||
CHECKFLAGS += $(NOSTDINC_FLAGS)
|
||||
|
||||
# warn about C99 declaration after statement
|
||||
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
|
||||
# disable pointer signedness warnings in gcc 4.0
|
||||
CFLAGS += $(call cc-option,-Wno-pointer-sign,)
|
||||
|
||||
# Default kernel image to build when no specific target is given.
|
||||
# KBUILD_IMAGE may be overruled on the commandline or
|
||||
# set in the environment
|
||||
@@ -554,7 +518,7 @@ export INSTALL_PATH ?= /boot
|
||||
#
|
||||
# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
|
||||
# relocations required by build roots. This is not defined in the
|
||||
# makefile but the argument can be passed to make if needed.
|
||||
# makefile but the arguement can be passed to make if needed.
|
||||
#
|
||||
|
||||
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
|
||||
@@ -608,17 +572,11 @@ quiet_cmd_busybox__ ?= LINK $@
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink \
|
||||
"$@" \
|
||||
"$(CC)" \
|
||||
"$(CFLAGS) $(CFLAGS_busybox)" \
|
||||
"$(CFLAGS)" \
|
||||
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
|
||||
"$(core-y)" \
|
||||
"$(libs-y)" \
|
||||
"$(LDLIBS)" \
|
||||
$(CONFIG_EXTRA_LDLIBS) \
|
||||
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
|
||||
# ^^^ note: CONFIG_xyz strings already have double quotes: their value
|
||||
# is '"LIB LIB2"', therefore $(CONFIG_EXTRA_LDLIBS) above must NOT be written
|
||||
# as "$(CONFIG_EXTRA_LDLIBS)", it would be passed as ""LIB LIB2"",
|
||||
# and LIB2 would end up in $9, not $8 (and lost or misinterpreted).
|
||||
"$(LDLIBS)"
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
@@ -730,8 +688,6 @@ ifeq ($(SKIP_STRIP),y)
|
||||
else
|
||||
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
|
||||
busybox_unstripped -o $@
|
||||
# strip is confused by PIE executable and does not set exec bits
|
||||
$(Q)chmod a+x $@
|
||||
endif
|
||||
|
||||
# The actual objects are generated when descending,
|
||||
@@ -827,7 +783,7 @@ ifneq ($(KBUILD_MODULES),)
|
||||
$(Q)rm -f $(MODVERDIR)/*
|
||||
endif
|
||||
|
||||
archprepare: prepare1 scripts_basic applets_dir
|
||||
archprepare: prepare1 scripts_basic
|
||||
|
||||
prepare0: archprepare FORCE
|
||||
$(Q)$(MAKE) $(build)=.
|
||||
@@ -851,19 +807,13 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
|
||||
|
||||
# Split autoconf.h into include/linux/config/*
|
||||
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
|
||||
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
|
||||
quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
|
||||
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
|
||||
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs > include/bbconfigopts.h
|
||||
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
|
||||
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
|
||||
quiet_cmd_gen_embedded_scripts = GEN include/embedded_scripts.h
|
||||
cmd_gen_embedded_scripts = $(srctree)/scripts/embedded_scripts include/embedded_scripts.h $(srctree)/embed $(srctree)/applets_sh
|
||||
#bbox# piggybacked generation of few .h files
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h $(wildcard $(srctree)/embed/*) $(wildcard $(srctree)/applets_sh/*) $(srctree)/scripts/embedded_scripts
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h
|
||||
$(call cmd,split_autoconf)
|
||||
$(call cmd,gen_bbconfigopts)
|
||||
$(call cmd,gen_common_bufsiz)
|
||||
$(call cmd,gen_embedded_scripts)
|
||||
@touch $@
|
||||
|
||||
# Generate some files
|
||||
@@ -970,28 +920,19 @@ endif # CONFIG_MODULES
|
||||
# make distclean Remove editor backup files, patch leftover files and the like
|
||||
|
||||
# Directories & files removed with 'make clean'
|
||||
CLEAN_DIRS += $(MODVERDIR) _install 0_lib
|
||||
CLEAN_FILES += busybox busybox_unstripped* busybox.links \
|
||||
busybox*.suid busybox*.nosuid \
|
||||
System.map .kernelrelease \
|
||||
CLEAN_DIRS += $(MODVERDIR)
|
||||
CLEAN_FILES += busybox* System.map .kernelrelease \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
MRPROPER_DIRS += include/config include2
|
||||
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
include/NUM_APPLETS.h \
|
||||
include/common_bufsiz.h \
|
||||
include/autoconf.h \
|
||||
include/bbconfigopts.h \
|
||||
include/bbconfigopts_bz2.h \
|
||||
include/embedded_scripts.h \
|
||||
include/usage_compressed.h \
|
||||
include/applet_tables.h \
|
||||
include/applets.h \
|
||||
include/usage.h \
|
||||
applets/usage \
|
||||
.kernelrelease Module.symvers tags TAGS cscope* \
|
||||
busybox_old
|
||||
.kernelrelease Module.symvers tags TAGS cscope*
|
||||
|
||||
# clean - Delete most, but leave enough to build external modules
|
||||
#
|
||||
@@ -1007,16 +948,10 @@ clean: archclean $(clean-dirs)
|
||||
$(call cmd,rmdirs)
|
||||
$(call cmd,rmfiles)
|
||||
@find . $(RCS_FIND_IGNORE) \
|
||||
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
|
||||
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
|
||||
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
|
||||
-type f -print | xargs rm -f
|
||||
|
||||
PHONY += doc-clean
|
||||
doc-clean: rm-files := docs/busybox.pod \
|
||||
docs/BusyBox.html docs/busybox.1 docs/BusyBox.txt
|
||||
doc-clean:
|
||||
$(call cmd,rmfiles)
|
||||
|
||||
# mrproper - Delete all generated files, including .config
|
||||
#
|
||||
mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
|
||||
@@ -1030,8 +965,6 @@ $(mrproper-dirs):
|
||||
mrproper: clean archmrproper $(mrproper-dirs)
|
||||
$(call cmd,rmdirs)
|
||||
$(call cmd,rmfiles)
|
||||
@find . -name Config.src | sed 's/.src$$/.in/' | xargs -r rm -f
|
||||
@find . -name Kbuild.src | sed 's/.src$$//' | xargs -r rm -f
|
||||
|
||||
# distclean
|
||||
#
|
||||
@@ -1039,9 +972,9 @@ PHONY += distclean
|
||||
|
||||
distclean: mrproper
|
||||
@find $(srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
|
||||
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
|
||||
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
|
||||
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
|
||||
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
|
||||
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
|
||||
-type f -print | xargs rm -f
|
||||
|
||||
@@ -1060,7 +993,7 @@ rpm: FORCE
|
||||
# Brief documentation of the typical targets used
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
boards := $(wildcard $(srctree)/configs/*_defconfig)
|
||||
boards := $(wildcard $(srctree)/arch/$(ARCH)/configs/*_defconfig)
|
||||
boards := $(notdir $(boards))
|
||||
|
||||
-include $(srctree)/Makefile.help
|
||||
@@ -1145,10 +1078,19 @@ clean: rm-dirs := $(MODVERDIR)
|
||||
clean: $(clean-dirs)
|
||||
$(call cmd,rmdirs)
|
||||
@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
|
||||
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
|
||||
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
|
||||
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
|
||||
-type f -print | xargs rm -f
|
||||
|
||||
help:
|
||||
@echo ' Building external modules.'
|
||||
@echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
|
||||
@echo ''
|
||||
@echo ' modules - default target, build the module(s)'
|
||||
@echo ' modules_install - install the module'
|
||||
@echo ' clean - remove generated files in module directory only'
|
||||
@echo ''
|
||||
|
||||
# Dummies...
|
||||
PHONY += prepare scripts
|
||||
prepare: ;
|
||||
@@ -1182,7 +1124,24 @@ endif
|
||||
ALLSOURCE_ARCHS := $(ARCH)
|
||||
|
||||
define all-sources
|
||||
( find -regex '.*\.[ch]$$' )
|
||||
( find $(__srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name include -o -name arch \) -prune -o \
|
||||
-name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLSOURCE_ARCHS) ; do \
|
||||
find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
find $(__srctree)include $(RCS_FIND_IGNORE) \
|
||||
\( -name config -o -name 'asm-*' \) -prune \
|
||||
-o -name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLINCLUDE_ARCHS) ; do \
|
||||
find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print )
|
||||
endef
|
||||
|
||||
quiet_cmd_cscope-file = FILELST cscope.files
|
||||
@@ -1286,13 +1245,9 @@ endif
|
||||
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
|
||||
|
||||
# Modules
|
||||
%/: prepare scripts FORCE
|
||||
/ %/: prepare scripts FORCE
|
||||
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
|
||||
$(build)=$(build-dir)
|
||||
/: prepare scripts FORCE
|
||||
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
|
||||
$(build)=$(build-dir)
|
||||
|
||||
%.ko: prepare scripts FORCE
|
||||
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
|
||||
$(build)=$(build-dir) $(@:.ko=.o)
|
||||
@@ -1307,6 +1262,14 @@ quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
|
||||
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
|
||||
cmd_rmfiles = rm -f $(rm-files)
|
||||
|
||||
|
||||
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
|
||||
$(NOSTDINC_FLAGS) $(CPPFLAGS) \
|
||||
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
|
||||
|
||||
quiet_cmd_as_o_S = AS $@
|
||||
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
|
||||
|
||||
# read all saved command lines
|
||||
|
||||
targets := $(wildcard $(sort $(targets)))
|
||||
|
||||
+18
-59
@@ -2,18 +2,10 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
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) $^ > $@
|
||||
busybox.links: $(srctree)/applets/busybox.mkll $(objtree)/include/autoconf.h $(srctree)/include/applets.h
|
||||
$(Q)-$(SHELL) $^ >$@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_DONT),y)
|
||||
INSTALL_OPTS:= --none
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
INSTALL_OPTS:= --symlinks
|
||||
endif
|
||||
@@ -31,10 +23,6 @@ ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_FEATURE_INDIVIDUAL),y)
|
||||
INSTALL_OPTS:= --binaries
|
||||
LIBBUSYBOX_SONAME:= 0_lib/libbusybox.so.$(BB_VER)
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
@@ -49,9 +37,6 @@ ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
|
||||
@echo
|
||||
endif
|
||||
|
||||
install-noclobber: INSTALL_OPTS+=--noclobber
|
||||
install-noclobber: install
|
||||
|
||||
uninstall: busybox.links
|
||||
rm -f $(CONFIG_PREFIX)/bin/busybox
|
||||
for i in `cat busybox.links` ; do rm -f $(CONFIG_PREFIX)$$i; done
|
||||
@@ -61,36 +46,19 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
|
||||
done
|
||||
endif
|
||||
|
||||
# Not very elegant: copies testsuite to objdir...
|
||||
# (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)"
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
|
||||
|
||||
.PHONY: release
|
||||
release: distclean
|
||||
cd ..; \
|
||||
rm -r -f busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION); \
|
||||
cp -pPR busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
|
||||
cp -a busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type d \
|
||||
-name .svn \
|
||||
-print \
|
||||
-exec rm -r -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type d \
|
||||
-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 \
|
||||
@@ -126,42 +94,32 @@ stksizes: busybox_unstripped
|
||||
|
||||
.PHONY: bigdata
|
||||
bigdata: busybox_unstripped
|
||||
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] '
|
||||
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [tr] '
|
||||
|
||||
# Documentation Targets
|
||||
.PHONY: doc
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/busybox.1 docs/BusyBox.html
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
# FIXME: Doesn't belong here
|
||||
cmd_doc =
|
||||
quiet_cmd_doc = $(Q)echo " DOC $(@F)"
|
||||
silent_cmd_doc =
|
||||
disp_doc = $($(quiet)cmd_doc)
|
||||
|
||||
# sed adds newlines after "Options:" etc,
|
||||
# this is needed in order to get good BusyBox.{1,txt,html}
|
||||
docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
|
||||
include/usage.h \
|
||||
$(srctree)/include/usage.h \
|
||||
$(srctree)/docs/busybox_footer.pod \
|
||||
applets/usage_pod
|
||||
$(srctree)/docs/autodocifier.pl
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-( \
|
||||
cat $(srctree)/docs/busybox_header.pod; \
|
||||
echo; \
|
||||
applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \
|
||||
cat $(srctree)/docs/busybox_footer.pod; \
|
||||
) > docs/busybox.pod
|
||||
$(Q)-( cat $(srctree)/docs/busybox_header.pod ; \
|
||||
$(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \
|
||||
cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2text --quotes=none $< > $@
|
||||
$(Q)-pod2text $< > $@
|
||||
|
||||
docs/busybox.1: docs/busybox.pod
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2man --quotes=none --center=busybox --release="version $(KERNELVERSION)" $< > $@
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
$(disp_doc)
|
||||
@@ -171,7 +129,8 @@ docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
$(Q)-mkdir -p docs/busybox.net
|
||||
$(Q)-pod2html --noindex $< > $@
|
||||
$(Q)-pod2html --noindex $< > \
|
||||
docs/busybox.net/BusyBox.html
|
||||
$(Q)-rm -f pod2htm*
|
||||
|
||||
# documentation, cross-reference
|
||||
|
||||
+32
-155
@@ -4,195 +4,80 @@
|
||||
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
export BB_VER
|
||||
SKIP_STRIP ?= n
|
||||
SKIP_STRIP = n
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
CPPFLAGS += $(call cc-option,-std=gnu99,)
|
||||
|
||||
CPPFLAGS += \
|
||||
-Iinclude -Ilibbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include -I$(srctree)/libbb) \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
|
||||
-include include/autoconf.h \
|
||||
-D_GNU_SOURCE -DNDEBUG \
|
||||
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
|
||||
$(if $(CONFIG_TIME64),-D_TIME_BITS=64) \
|
||||
-DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
|
||||
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
|
||||
|
||||
CFLAGS += $(call cc-option,-Wall,)
|
||||
CFLAGS += $(call cc-option,-Wshadow,)
|
||||
CFLAGS += $(call cc-option,-Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef,)
|
||||
CFLAGS += $(call cc-option,-Wstrict-prototypes,)
|
||||
# flag checks are grouped together to speed the checks up a bit..
|
||||
CFLAGS += $(call cc-option,-Wall -Wshadow -Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef -Wstrict-prototypes,)
|
||||
CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
|
||||
CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
CFLAGS += $(call cc-option,-Wno-format-security,)
|
||||
# we use "" format in ioctl_or_perror_and_die(a, b, c, "")
|
||||
CFLAGS += $(call cc-option,-Wno-format-zero-length,)
|
||||
# warn about C99 declaration after statement
|
||||
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
# If you want to add more -Wsomething above, make sure that it is
|
||||
# still possible to build bbox without warnings.
|
||||
# If you want to add "-Wmissing-prototypes -Wmissing-declarations" above
|
||||
# (or anything else for that matter) make sure that it is still possible
|
||||
# to build bbox without warnings. Current offender: find.c:alloc_action().
|
||||
# Looks more like gcc bug: gcc will warn on it with or without prototype.
|
||||
# But still, warning-free compile is a must, or else we will drown
|
||||
# in warnings pretty soon.
|
||||
|
||||
ifeq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Werror,)
|
||||
## TODO:
|
||||
## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
|
||||
## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
|
||||
## and no easy way to convince it to shut the hell up.
|
||||
## We have a lot of such things all over the place.
|
||||
## Classic *(off_t*)(void*)ptr does not work,
|
||||
## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
|
||||
## stuff in macros. This would obfuscate the code too much.
|
||||
## Maybe try __attribute__((__may_alias__))?
|
||||
#CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
|
||||
else
|
||||
# for development, warn a little bit about unused results..
|
||||
CPPFLAGS += -D_FORTIFY_SOURCE=2
|
||||
endif
|
||||
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
|
||||
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
|
||||
|
||||
ifneq ($(lastword $(subst -, ,$(CC))),clang)
|
||||
# "clang-9: warning: optimization flag '-finline-limit=0' is not supported
|
||||
CFLAGS += $(call cc-option,-finline-limit=0,)
|
||||
# gcc emits bogus "no prev proto" warning on find.c:alloc_action()
|
||||
ifneq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
CFLAGS += $(call cc-option,-Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
# -fno-guess-branch-probability: prohibit pseudo-random guessing
|
||||
# of branch probabilities (hopefully makes bloatcheck more stable):
|
||||
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
|
||||
CFLAGS += $(call cc-option,-funsigned-char,)
|
||||
|
||||
ifeq ($(CONFIG_STATIC_LIBGCC),y)
|
||||
# Disable it, for example, if you get
|
||||
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
|
||||
CFLAGS += $(call cc-option,-static-libgcc,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-falign-functions=1,)
|
||||
ifneq ($(lastword $(subst -, ,$(CC))),clang)
|
||||
# "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
|
||||
CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
endif
|
||||
|
||||
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
|
||||
CFLAGS += $(call cc-option,-fno-unwind-tables,)
|
||||
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
|
||||
# No automatic printf->puts,putchar conversions
|
||||
# (try disabling this and comparing assembly, it's instructive)
|
||||
CFLAGS += $(call cc-option,-fno-builtin-printf,)
|
||||
|
||||
# clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
|
||||
ifeq ($(lastword $(subst -, ,$(CC))),clang)
|
||||
CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
|
||||
endif
|
||||
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
|
||||
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
#CFLAGS += $(call cc-option,-Wconversion,)
|
||||
#CFLAGS+=$(call cc-option,-Wconversion,)
|
||||
|
||||
ifneq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
|
||||
else
|
||||
CFLAGS += $(call cc-option,-g,)
|
||||
#CFLAGS += "-D_FORTIFY_SOURCE=2"
|
||||
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
|
||||
CFLAGS += $(call cc-option,-O0,)
|
||||
else
|
||||
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
|
||||
CFLAGS += $(call cc-option,-fsanitize=address,)
|
||||
CFLAGS += $(call cc-option,-fsanitize=leak,)
|
||||
CFLAGS += $(call cc-option,-fsanitize=undefined,)
|
||||
endif
|
||||
|
||||
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
|
||||
ARCH_FPIC ?= -fpic
|
||||
ARCH_FPIE ?= -fpie
|
||||
ARCH_PIE ?= -pie
|
||||
|
||||
# Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
|
||||
define pkg_check_modules
|
||||
$(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
|
||||
$(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
|
||||
endef
|
||||
|
||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||
# on i386: 14% smaller libbusybox.so
|
||||
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
|
||||
CFLAGS += $(ARCH_FPIC)
|
||||
CFLAGS += -fpic
|
||||
# and another 4% reduction of libbusybox.so:
|
||||
# (external entry points must be marked EXTERNALLY_VISIBLE)
|
||||
CFLAGS += $(call cc-option,-fvisibility=hidden)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STATIC),y)
|
||||
CFLAGS_busybox += -static
|
||||
PKG_CONFIG_FLAGS += --static
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_PIE),y)
|
||||
CFLAGS_busybox += $(ARCH_PIE)
|
||||
CFLAGS += $(ARCH_FPIE)
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_CFLAGS),)
|
||||
CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
# Note: both "" (string consisting of two quote chars) and empty string
|
||||
# are possible, and should be skipped below.
|
||||
ifneq ($(subst "",,$(CONFIG_SYSROOT)),)
|
||||
CFLAGS += --sysroot=$(CONFIG_SYSROOT)
|
||||
export SYSROOT=$(CONFIG_SYSROOT)
|
||||
endif
|
||||
|
||||
# libm may be needed for dc, awk, ntpd
|
||||
LDLIBS += m
|
||||
# Android has no separate crypt library
|
||||
# gcc-4.2.1 fails if we try to feed C source on stdin:
|
||||
# echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
|
||||
# fall back to using a temp file:
|
||||
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lcrypt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
|
||||
RT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -lrt -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
|
||||
ifeq ($(CRYPT_AVAILABLE),y)
|
||||
LDLIBS += crypt
|
||||
endif
|
||||
# librt may be needed for clock_gettime()
|
||||
ifeq ($(RT_AVAILABLE),y)
|
||||
LDLIBS += rt
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
# However, on *other platforms* it fails when some of those flags
|
||||
# given needlessly. On some systems, crypt needs pthread.
|
||||
#
|
||||
# I even had a system where a runtime test for pthread
|
||||
# (similar to CRYPT_AVAILABLE test above) was not reliable.
|
||||
#
|
||||
# Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
|
||||
# Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
|
||||
LDLIBS += m crypt
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
LDLIBS += pam pam_misc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
SELINUX_PC_MODULES = libselinux libsepol
|
||||
$(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES)))
|
||||
CPPFLAGS += $(SELINUX_CFLAGS)
|
||||
LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
|
||||
ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
|
||||
LDLIBS += resolv
|
||||
endif
|
||||
ifneq (,$(findstring gnu,$(shell $(CC) $(CFLAGS) -dumpmachine)))
|
||||
LDLIBS += resolv
|
||||
endif
|
||||
LDLIBS += selinux sepol
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
@@ -203,19 +88,11 @@ ifeq ($(CONFIG_DMALLOC),y)
|
||||
LDLIBS += dmalloc
|
||||
endif
|
||||
|
||||
# If a flat binary should be built, CFLAGS_busybox="-elf2flt"
|
||||
# env var should be set for make invocation.
|
||||
# Here we check whether CFLAGS_busybox indeed contains that flag.
|
||||
# (For historical reasons, we also check LDFLAGS, which doesn't
|
||||
# seem to be entirely correct variable to put "-elf2flt" into).
|
||||
W_ELF2FLT = -elf2flt
|
||||
ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
|
||||
SKIP_STRIP = y
|
||||
endif
|
||||
#LDFLAGS += -nostdlib
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDFLAGS),)
|
||||
LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
LDFLAGS_ELF2FLT = -Wl,-elf2flt
|
||||
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
|
||||
SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
|
||||
+4
-5
@@ -6,7 +6,6 @@ help:
|
||||
@echo 'Cleaning:'
|
||||
@echo ' clean - delete temporary files created by build'
|
||||
@echo ' distclean - delete all non-source files (including .config)'
|
||||
@echo ' doc-clean - delete all generated documentation'
|
||||
@echo
|
||||
@echo 'Build:'
|
||||
@echo ' all - Executable and documentation'
|
||||
@@ -21,10 +20,10 @@ help:
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@echo ' oldconfig - resolve any unresolved symbols in .config'
|
||||
@$(if $(boards), \
|
||||
$(foreach b, $(boards), \
|
||||
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
|
||||
echo '')
|
||||
@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"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into CONFIG_PREFIX'
|
||||
|
||||
@@ -1,438 +0,0 @@
|
||||
Why an applet can't be NOFORK or NOEXEC?
|
||||
|
||||
Why can't be NOFORK:
|
||||
interactive: may wait for user input, ^C has to work
|
||||
spawner: "tool PROG ARGS" which changes program state and execs - must fork
|
||||
changes state: e.g. environment, signal handlers
|
||||
leaks: does not free allocated memory or opened fds
|
||||
alloc+xfunc: xmalloc, then xfunc - leaks memory if xfunc dies
|
||||
open+xfunc: opens fd, then calls xfunc - fd is leaked if xfunc dies
|
||||
talks to network/serial/etc: it's not known how long the delay can be,
|
||||
it's reasonable to expect it might be many seconds
|
||||
(even if usually it is not), so ^C has to work
|
||||
runner: sometimes may run for long(ish) time, and/or works with network:
|
||||
^C has to work (cat BIGFILE, chmod -R, ftpget, nc)
|
||||
|
||||
"runners" can become eligible after shell is taught ^C to interrupt NOFORKs,
|
||||
need to be inspected that they do not fall into alloc+xfunc, open+xfunc,
|
||||
leak categories.
|
||||
|
||||
Why can't be NOEXEC:
|
||||
suid: runs under different uid - must fork+exec
|
||||
if it's important that /proc/PID/cmdline and comm are correct.
|
||||
("pkill sh" killing itself before it kills real "sh" is no fun)
|
||||
|
||||
Why shouldn't be NOFORK/NOEXEC:
|
||||
rare: not started often enough to bother optimizing (example: poweroff)
|
||||
daemon: runs indefinitely; these are also always fit "rare" category
|
||||
longterm: often runs for a long time (many seconds), execing makes
|
||||
memory footprint smaller
|
||||
complex: no immediately obvious reason why NOFORK wouldn't work,
|
||||
but does some non-obvoius operations (example: fuser, lsof, losetup);
|
||||
detailed audit often turns out that it's a leaker
|
||||
hardware: performs unusual hardware ops which may take long,
|
||||
or even hang due to hardware or firmware bugs
|
||||
|
||||
Interesting example of "interactive" applet which is nevertheless can be
|
||||
(and is) NOEXEC is "rm". Yes, "rm -i" is interactive - but it's not that typical
|
||||
for users to keep it waiting for many minutes, whereas running "rm" in shell
|
||||
is very typical, and speeding up this common use via NOEXEC is useful.
|
||||
IOW: rm is "interactive", but not "longterm".
|
||||
|
||||
Interesting example of an applet which can be NOFORK but if not,
|
||||
then should not be NOEXEC, is "usleep". As NOFORK, it amount to simply
|
||||
nanosleep()ing in the calling program (usually shell). No memory wasted.
|
||||
But if ran as NOEXEC, it would create a potentially long-term process,
|
||||
which would be taking more memory because it did not exec
|
||||
and did not free much of the copied memory of the parent
|
||||
(COW helps with this only as long as parent doesn't modify its memory).
|
||||
|
||||
|
||||
[ - NOFORK
|
||||
[[ - NOFORK
|
||||
acpid - daemon
|
||||
add-shell - noexec. leaks: open+xfunc
|
||||
addgroup - noexec. leaks
|
||||
adduser - noexec. leaks
|
||||
adjtimex - NOFORK
|
||||
ar - runner
|
||||
arch - NOFORK
|
||||
arp - talks to network: arp -n queries DNS
|
||||
arping - longterm
|
||||
ash - interactive, longterm
|
||||
awk - noexec. runner
|
||||
base64 - runner
|
||||
basename - NOFORK
|
||||
beep - longterm: beep -r 999999999
|
||||
blkdiscard - noexec. leaks: open+xioctl
|
||||
blkid - noexec
|
||||
blockdev - noexec. leaks fd
|
||||
bootchartd - daemon
|
||||
brctl - noexec
|
||||
bunzip2 - runner
|
||||
bzcat - runner
|
||||
bzip2 - runner
|
||||
cal - noexec. can be runner: cal -n9999
|
||||
cat - runner: cat HUGEFILE
|
||||
chat - longterm (when used as intended - talking to modem over stdin/out)
|
||||
chattr - noexec. runner
|
||||
chgrp - noexec. runner
|
||||
chmod - noexec. runner
|
||||
chown - noexec. runner
|
||||
chpasswd - longterm? (list of "user:password"s from stdin)
|
||||
chpst - noexec. spawner
|
||||
chroot - noexec. spawner
|
||||
chrt - noexec. spawner
|
||||
chvt - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
|
||||
cksum - noexec. runner
|
||||
clear - NOFORK
|
||||
cmp - runner
|
||||
comm - runner
|
||||
conspy - interactive, longterm
|
||||
cp - noexec. sometimes runner
|
||||
cpio - runner
|
||||
crond - daemon
|
||||
crontab - longterm (runs $EDITOR), leaks: open+xasprintf
|
||||
cryptpw - noexec. changes state: with --password-fd=N, moves N to stdin
|
||||
cttyhack - noexec. spawner
|
||||
cut - noexec. runner
|
||||
date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf)
|
||||
dc - longterm (eats stdin if no params)
|
||||
dd - noexec. runner
|
||||
deallocvt - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
|
||||
delgroup - noexec. leaks
|
||||
deluser - noexec. leaks
|
||||
depmod - longterm(ish)
|
||||
devmem - hardware (access to device memory may hang)
|
||||
df - noexec. leaks: nested allocs
|
||||
dhcprelay - daemon
|
||||
diff - runner
|
||||
dirname - NOFORK
|
||||
dmesg - runner
|
||||
dnsd - daemon
|
||||
dnsdomainname - noexec. talks to network (may query DNS)
|
||||
dos2unix - noexec. runner
|
||||
dpkg - runner
|
||||
du - runner
|
||||
dumpkmap - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
|
||||
dumpleases - noexec. leaks: open+xread
|
||||
echo - NOFORK
|
||||
ed - interactive, longterm
|
||||
egrep - longterm runner ("CMD | egrep ..." may run indefinitely, better to exec to conserve memory)
|
||||
eject - hardware, leaks: open+ioctl_or_perror_and_die, changes state (moves fds)
|
||||
env - noexec. spawner, changes state (env)
|
||||
envdir - noexec. spawner
|
||||
envuidgid - noexec. spawner
|
||||
expand - runner
|
||||
expr - noexec. leaks: nested allocs
|
||||
factor - longterm (eats stdin if no params)
|
||||
fakeidentd - daemon
|
||||
false - NOFORK
|
||||
fatattr - noexec. leaks: open+xioctl, complex
|
||||
fbset - hardware, leaks: open+xfunc
|
||||
fbsplash - runner, longterm
|
||||
fdflush - hardware, leaks: open+ioctl_or_perror_and_die
|
||||
fdformat - hardware, longterm
|
||||
fdisk - interactive, longterm
|
||||
fgconsole - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
|
||||
fgrep - longterm runner ("CMD | fgrep ..." may run indefinitely, better to exec to conserve memory)
|
||||
find - noexec. runner
|
||||
findfs - suid
|
||||
flash_eraseall - hardware
|
||||
flash_lock - hardware
|
||||
flash_unlock - hardware
|
||||
flashcp - hardware
|
||||
flock - spawner, changes state (file locks), let's play safe and not be noexec
|
||||
fold - noexec. runner
|
||||
free - NOFORK
|
||||
freeramdisk - noexec. leaks: open+ioctl_or_perror_and_die
|
||||
fsck - interactive, longterm
|
||||
fsck.minix - needs ^C
|
||||
fsfreeze - noexec. leaks: open+xioctl
|
||||
fstrim - noexec. leaks: open+xioctl, find_block_device -> readdir+xstrdup
|
||||
fsync - NOFORK
|
||||
ftpd - daemon
|
||||
ftpget - runner
|
||||
ftpput - runner
|
||||
fuser - complex
|
||||
getopt - noexec. leaks: many allocs
|
||||
getty - interactive, longterm
|
||||
grep - longterm runner ("CMD | grep ..." may run indefinitely, better to exec to conserve memory)
|
||||
groups - noexec
|
||||
gunzip - runner
|
||||
gzip - runner
|
||||
halt - rare
|
||||
hd - noexec. runner
|
||||
hdparm - hardware
|
||||
head - noexec. runner
|
||||
hexdump - noexec. runner
|
||||
hexedit - interactive, longterm
|
||||
hostid - NOFORK
|
||||
hostname - noexec. talks to network (hostname -d may query DNS)
|
||||
httpd - daemon
|
||||
hush - interactive, longterm
|
||||
hwclock - hardware (xioctl(RTC_RD_TIME))
|
||||
i2cdetect - hardware
|
||||
i2cdump - hardware
|
||||
i2cget - hardware
|
||||
i2cset - hardware
|
||||
id - noexec
|
||||
ifconfig - hardware? (mem_start NN io_addr NN irq NN), leaks: xsocket+ioctl_or_perror_and_die
|
||||
ifenslave - noexec. leaks: xsocket+bb_perror_msg_and_die
|
||||
ifplugd - daemon
|
||||
inetd - daemon
|
||||
init - daemon
|
||||
inotifyd - daemon
|
||||
insmod - noexec
|
||||
install - runner
|
||||
ionice - noexec. spawner
|
||||
iostat - longterm: "iostat 1" runs indefinitely
|
||||
ip - noexec
|
||||
ipaddr - noexec
|
||||
ipcalc - noexec. ipcalc -h talks to network
|
||||
ipcrm - noexec
|
||||
ipcs - noexec
|
||||
iplink - noexec
|
||||
ipneigh - noexec
|
||||
iproute - noexec
|
||||
iprule - noexec
|
||||
iptunnel - noexec
|
||||
kbd_mode - noexec. leaks: xopen_nonblocking+xioctl
|
||||
kill - NOFORK
|
||||
killall - NOFORK
|
||||
killall5 - NOFORK
|
||||
klogd - daemon
|
||||
last - runner (I've got 1300 lines of output when tried it)
|
||||
less - interactive, longterm
|
||||
link - NOFORK
|
||||
linux32 - noexec. spawner
|
||||
linux64 - noexec. spawner
|
||||
linuxrc - daemon
|
||||
ln - noexec
|
||||
loadfont - noexec. leaks: config_open+bb_error_msg_and_die("map format")
|
||||
loadkmap - noexec. leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds
|
||||
logger - runner
|
||||
login - suid, interactive, longterm
|
||||
logname - NOFORK
|
||||
losetup - noexec. complex
|
||||
lpd - daemon
|
||||
lpq - runner
|
||||
lpr - runner
|
||||
ls - noexec. runner
|
||||
lsattr - noexec. runner
|
||||
lsmod - noexec
|
||||
lsof - complex
|
||||
lspci - noexec. too rare to bother for nofork
|
||||
lsscsi - noexec. too rare to bother for nofork
|
||||
lsusb - noexec. too rare to bother for nofork
|
||||
lzcat - runner
|
||||
lzma - runner
|
||||
lzop - runner
|
||||
lzopcat - runner
|
||||
makedevs - noexec
|
||||
makemime - runner
|
||||
man - spawner, interactive, longterm
|
||||
md5sum - noexec. runner
|
||||
mdev - daemon
|
||||
mesg - NOFORK
|
||||
microcom - interactive, longterm
|
||||
minips - noexec
|
||||
mkdir - NOFORK
|
||||
mkdosfs - needs ^C
|
||||
mke2fs - needs ^C
|
||||
mkfifo - noexec
|
||||
mkfs.ext2 - needs ^C
|
||||
mkfs.minix - needs ^C
|
||||
mkfs.vfat - needs ^C
|
||||
mknod - noexec
|
||||
mkpasswd - noexec. changes state: with --password-fd=N, moves N to stdin
|
||||
mkswap - needs ^C
|
||||
mktemp - noexec. leaks: xstrdup+concat_path_file
|
||||
modinfo - noexec
|
||||
modprobe - noexec
|
||||
more - interactive, longterm
|
||||
mount - suid
|
||||
mountpoint - noexec. leaks: option -n "print dev name": find_block_device -> readdir+xstrdup
|
||||
mpstat - longterm: "mpstat 1" runs indefinitely
|
||||
mt - hardware
|
||||
mv - noexec. sometimes runner
|
||||
nameif - noexec. openlog(), leaks: config_open2+ioctl_or_perror_and_die
|
||||
nbd-client - noexec
|
||||
nc - runner
|
||||
netstat - longterm with -c (continuous listing)
|
||||
nice - noexec. spawner
|
||||
nl - runner
|
||||
nmeter - longterm
|
||||
nohup - noexec. spawner
|
||||
nproc - NOFORK
|
||||
ntpd - daemon
|
||||
nuke - noexec
|
||||
od - runner
|
||||
openvt - longterm: spawns a child and waits for it
|
||||
partprobe - noexec. leaks: open+ioctl_or_perror_and_die(BLKRRPART)
|
||||
passwd - suid
|
||||
paste - noexec. runner
|
||||
patch - needs ^C
|
||||
pgrep - must fork+exec to get correct /proc/PID/cmdline and comm field
|
||||
pidof - must fork+exec to get correct /proc/PID/cmdline and comm field
|
||||
ping - suid, longterm
|
||||
ping6 - suid, longterm
|
||||
pipe_progress - longterm
|
||||
pivot_root - NOFORK
|
||||
pkill - must fork+exec to get correct /proc/PID/cmdline and comm field
|
||||
pmap - noexec candidate, leaks: open+xstrdup
|
||||
popmaildir - runner
|
||||
poweroff - rare
|
||||
powertop - interactive, longterm
|
||||
printenv - NOFORK
|
||||
printf - NOFORK
|
||||
ps - noexec
|
||||
pscan - talks to network
|
||||
pstree - noexec
|
||||
pwd - NOFORK
|
||||
pwdx - NOFORK
|
||||
raidautorun - noexec. very simple. leaks: open+xioctl
|
||||
rdate - talks to network
|
||||
rdev - noexec. leaks: find_block_device -> readdir+xstrdup
|
||||
readlink - NOFORK
|
||||
readprofile - reads /boot/System.map and /proc/profile, better to free more memory by execing?
|
||||
realpath - NOFORK
|
||||
reboot - rare
|
||||
reformime - runner
|
||||
remove-shell - noexec. leaks: open+xfunc
|
||||
renice - noexec. nofork candidate(uses getpwnam, is that ok?)
|
||||
reset - noexec. spawner (execs "stty")
|
||||
resize - noexec. changes state (signal handlers)
|
||||
resume - noexec
|
||||
rev - runner
|
||||
rm - noexec. rm -i interactive
|
||||
rmdir - NOFORK
|
||||
rmmod - noexec
|
||||
route - talks to network (may query DNS to convert IPs to names)
|
||||
rpm - runner
|
||||
rpm2cpio - runner
|
||||
rtcwake - longterm: puts system to sleep, optimizing this for speed is pointless
|
||||
run-init - spawner, rare, changes state (oh yes), execing may be important to free binary's inode
|
||||
run-parts - longterm
|
||||
runlevel - noexec. can be nofork if "endutxent()" is called unconditionally, but too rare to bother?
|
||||
runsv - daemon
|
||||
runsvdir - daemon
|
||||
rx - runner
|
||||
script - longterm: pumps script output from slave pty
|
||||
scriptreplay - longterm: plays back "script" saved output, sleeping as necessary.
|
||||
sed - runner
|
||||
sendmail - runner
|
||||
seq - noexec. runner
|
||||
setarch - noexec. spawner
|
||||
setconsole - noexec
|
||||
setfattr - noexec
|
||||
setfont - noexec. leaks a lot of stuff
|
||||
setkeycodes - noexec
|
||||
setlogcons - noexec
|
||||
setpriv - spawner, changes state, let's play safe and not be noexec
|
||||
setserial - noexec
|
||||
setsid - spawner, uses fork_or_rexec() [not audited to work in noexec], let's play safe and not be noexec
|
||||
setuidgid - noexec. spawner
|
||||
sha1sum - noexec. runner
|
||||
sha256sum - noexec. runner
|
||||
sha3sum - noexec. runner
|
||||
sha384sum - noexec. runner
|
||||
sha512sum - noexec. runner
|
||||
showkey - interactive, longterm
|
||||
shred - runner
|
||||
shuf - noexec. runner
|
||||
slattach - longterm (may sleep forever), uses bb_common_bufsiz1
|
||||
sleep - longterm. Could be nofork, if not the problem of "killall sleep" not killing it.
|
||||
smemcap - runner
|
||||
softlimit - noexec. spawner
|
||||
sort - noexec. runner
|
||||
split - runner
|
||||
ssl_client - longterm
|
||||
start-stop-daemon - not noexec: uses bb_common_bufsiz1
|
||||
stat - noexec. nofork candidate(needs fewer allocs)
|
||||
strings - runner
|
||||
stty - noexec. nofork candidate: has no allocs or opens except xmove_fd(xopen("-F DEVICE"),STDIN). tcsetattr(STDIN) is not a problem: it would work the same across processes sharing this fd
|
||||
su - suid, spawner
|
||||
sulogin - noexec. spawner
|
||||
sum - runner
|
||||
sv - noexec. needs ^C (uses usleep(420000))
|
||||
svc - noexec. needs ^C (uses usleep(420000))
|
||||
svlogd - daemon
|
||||
swapoff - longterm: may cause memory pressure, execing is beneficial
|
||||
swapon - rare
|
||||
switch_root - spawner, rare, changes state (oh yes), execing may be important to free binary's inode
|
||||
sync - NOFORK
|
||||
sysctl - noexec. leaks: xstrdup+xmalloc_read
|
||||
syslogd - daemon
|
||||
tac - noexec. runner
|
||||
tail - runner
|
||||
tar - runner
|
||||
taskset - noexec. spawner
|
||||
tcpsvd - daemon
|
||||
tee - runner
|
||||
telnet - interactive, longterm
|
||||
telnetd - daemon
|
||||
test - NOFORK
|
||||
tftp - runner
|
||||
tftpd - daemon
|
||||
time - spawner, longterm, changes state (signals)
|
||||
timeout - spawner, longterm, changes state (signals)
|
||||
top - interactive, longterm
|
||||
touch - NOFORK
|
||||
tr - runner
|
||||
traceroute - suid, longterm
|
||||
traceroute6 - suid, longterm
|
||||
true - NOFORK
|
||||
truncate - NOFORK
|
||||
tty - NOFORK
|
||||
ttysize - NOFORK
|
||||
tunctl - noexec
|
||||
tune2fs - noexec. leaks: open+xfunc
|
||||
ubiattach - hardware
|
||||
ubidetach - hardware
|
||||
ubimkvol - hardware
|
||||
ubirename - hardware
|
||||
ubirmvol - hardware
|
||||
ubirsvol - hardware
|
||||
ubiupdatevol - hardware
|
||||
udhcpc - daemon
|
||||
udhcpd - daemon
|
||||
udpsvd - daemon
|
||||
uevent - daemon
|
||||
umount - noexec. leaks: nested xmalloc
|
||||
uname - NOFORK
|
||||
uncompress - runner
|
||||
unexpand - runner
|
||||
uniq - runner
|
||||
unix2dos - noexec. runner
|
||||
unlink - NOFORK
|
||||
unlzma - runner
|
||||
unlzop - runner
|
||||
unxz - runner
|
||||
unzip - runner
|
||||
uptime - noexec. nofork candidate(is getutxent ok?)
|
||||
users - noexec. nofork candidate(is getutxent ok?)
|
||||
usleep - NOFORK. But what about "killall usleep"?
|
||||
uudecode - runner
|
||||
uuencode - runner
|
||||
vconfig - noexec. leaks: xsocket+ioctl_or_perror_and_die
|
||||
vi - interactive, longterm
|
||||
vlock - suid
|
||||
volname - hardware (reads CDROM, this can take long-ish if need to spin up)
|
||||
w - noexec. nofork candidate(is getutxent ok?)
|
||||
wall - suid
|
||||
watch - longterm
|
||||
watchdog - daemon
|
||||
wc - runner
|
||||
wget - longterm
|
||||
which - NOFORK
|
||||
who - noexec. nofork candidate(is getutxent ok?)
|
||||
whoami - NOFORK
|
||||
whois - talks to network
|
||||
xargs - noexec. spawner
|
||||
xxd - noexec. runner
|
||||
xz - runner
|
||||
xzcat - runner
|
||||
yes - noexec. runner
|
||||
zcat - runner
|
||||
zcip - daemon
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec >NOFORK_NOEXEC.lst1
|
||||
|
||||
false && grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
|
||||
| grep -v 'noexec.' | grep -v 'noexec$' \
|
||||
| grep -v ' suid' \
|
||||
| grep -v ' daemon' \
|
||||
| grep -v ' longterm' \
|
||||
| grep rare
|
||||
|
||||
echo === nofork candidate
|
||||
grep -F 'nofork candidate' NOFORK_NOEXEC.lst \
|
||||
|
||||
echo === noexec candidate
|
||||
grep -F 'noexec candidate' NOFORK_NOEXEC.lst \
|
||||
|
||||
echo === ^C
|
||||
grep -F '^C' NOFORK_NOEXEC.lst \
|
||||
| grep -F ' - ' \
|
||||
|
||||
echo === talks
|
||||
grep -F 'talks' NOFORK_NOEXEC.lst \
|
||||
| grep -F ' - ' \
|
||||
|
||||
echo ===
|
||||
grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
|
||||
| grep '^[^ ][^ ]* - ' \
|
||||
| grep -v 'noexec.' | grep -v ' - noexec$' \
|
||||
| grep -v ' suid' \
|
||||
| grep -v ' daemon' \
|
||||
| grep -v 'longterm' \
|
||||
| grep -v 'interactive' \
|
||||
| grep -v 'hardware' \
|
||||
@@ -44,7 +44,7 @@ Using busybox:
|
||||
run (I.E. "./busybox ls -l /proc").
|
||||
|
||||
The "standalone shell" mode is an easy way to try out busybox; this is a
|
||||
command shell that calls the built-in applets without needing them to be
|
||||
command shell that calls the builtin applets without needing them to be
|
||||
installed in the path. (Note that this requires /proc to be mounted, if
|
||||
testing from a boot floppy or in a chroot environment.)
|
||||
|
||||
@@ -66,11 +66,11 @@ Downloading the current source code:
|
||||
|
||||
You can browse the up to the minute source code and change history online.
|
||||
|
||||
http://git.busybox.net/busybox/
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
|
||||
|
||||
Anonymous GIT access is available. For instructions, check out:
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
|
||||
http://www.busybox.net/source.html
|
||||
http://busybox.net/subversion.html
|
||||
|
||||
For those that are actively contributing and would like to check files in,
|
||||
see:
|
||||
@@ -78,16 +78,16 @@ Downloading the current source code:
|
||||
http://busybox.net/developer.html
|
||||
|
||||
The developers also have a bug and patch tracking system
|
||||
(https://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
(http://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
is generally a faster way of getting it fixed, and the complete archive of
|
||||
what happened is the git changelog.
|
||||
what happened is the subversion changelog.
|
||||
|
||||
Note: if you want to compile busybox in a busybox environment you must
|
||||
select CONFIG_DESKTOP.
|
||||
select ENABLE_DESKTOP.
|
||||
|
||||
----------------
|
||||
|
||||
Getting help:
|
||||
getting help:
|
||||
|
||||
when you find you need help, you can check out the busybox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
@@ -95,7 +95,7 @@ Getting help:
|
||||
|
||||
----------------
|
||||
|
||||
Bugs:
|
||||
bugs:
|
||||
|
||||
if you find bugs, please submit a detailed bug report to the busybox mailing
|
||||
list at busybox@busybox.net. a well-written bug report should include a
|
||||
@@ -122,7 +122,7 @@ Bugs:
|
||||
illegal instruction
|
||||
|
||||
i am using debian unstable, kernel version 2.4.25-vrs2 on a netwinder,
|
||||
and the latest uclibc from cvs.
|
||||
and the latest uclibc from cvs. thanks for the wonderful program!
|
||||
|
||||
-diligent
|
||||
|
||||
@@ -169,12 +169,14 @@ Portability:
|
||||
MacOS X, Solaris, Cygwin, or the BSD Fork Du Jour). This generally involves
|
||||
a different kernel and a different C library at the same time. While it
|
||||
should be possible to port the majority of the code to work in one of
|
||||
these environments, don't be surprised if it doesn't work out of the box. If
|
||||
these environments, don't be suprised if it doesn't work out of the box. If
|
||||
you're into that sort of thing, start small (selecting just a few applets)
|
||||
and work your way up.
|
||||
|
||||
In 2005 Shaun Jackman has ported busybox to a combination of newlib
|
||||
and libgloss, and some of his patches have been integrated.
|
||||
Shaun Jackman has recently (2005) ported busybox to a combination of newlib
|
||||
and libgloss, and some of his patches have been integrated. This platform
|
||||
may join glibc/uclibc and Linux as a supported combination with the 1.1
|
||||
release, but is not supported in 1.0.
|
||||
|
||||
Supported hardware:
|
||||
|
||||
@@ -185,7 +187,7 @@ Supported hardware:
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, and v850e. Anything else probably won't work.
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
@@ -194,11 +196,6 @@ Supported hardware:
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to the busybox
|
||||
mailing list:
|
||||
|
||||
busybox@busybox.net
|
||||
|
||||
and/or maintainer:
|
||||
|
||||
Denys Vlasenko
|
||||
<vda.linux@googlemail.com>
|
||||
maintainer:
|
||||
Denis Vlasenko
|
||||
<vda.linux@googlemail.com>
|
||||
@@ -1,25 +1,34 @@
|
||||
Busybox TODO
|
||||
|
||||
Harvest patches from
|
||||
http://git.openembedded.org/cgit.cgi/openembedded/tree/recipes/busybox/
|
||||
https://dev.openwrt.org/browser/trunk/package/busybox/patches/
|
||||
|
||||
|
||||
Stuff that needs to be done. This is organized by who plans to get around to
|
||||
doing it eventually, but that doesn't mean they "own" the item. If you want to
|
||||
do one of these bounce an email off the person it's listed under to see if they
|
||||
have any suggestions how they plan to go about it, and to minimize conflicts
|
||||
between your work and theirs. But otherwise, all of these are fair game.
|
||||
|
||||
Rob Landley suggested this:
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Rob Landley <rob@landley.net>:
|
||||
Add a libbb/platform.c
|
||||
Implement fdprintf() for platforms that haven't got one.
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Cleanup bb_asprintf()
|
||||
|
||||
Remove obsolete _() wrapper crud for internationalization we don't do.
|
||||
Figure out where we need utf8 support, and add it.
|
||||
|
||||
sh
|
||||
The command shell situation is a mess. We have two different
|
||||
The command shell situation is a big mess. We have three different
|
||||
shells that don't really share any code, and the "standalone shell" doesn't
|
||||
work all that well (especially not in a chroot environment), due to apps not
|
||||
being reentrant.
|
||||
|
||||
lash is phased out. hush can be configured down to be nearly as small,
|
||||
but less buggy :)
|
||||
init
|
||||
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
|
||||
depmod
|
||||
busybox lacks a way to update module deps when running from firmware without the
|
||||
use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
|
||||
modutils. The orig depmod is rather pointless to have to add to a firmware image
|
||||
in when we already have a insmod/rmmod and friends.
|
||||
Do a SUSv3 audit
|
||||
Look at the full Single Unix Specification version 3 (available online at
|
||||
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
|
||||
@@ -28,12 +37,11 @@ Rob Landley suggested this:
|
||||
|
||||
Even better would be some kind of automated compliance test harness that
|
||||
exercises each command line option and the various corner cases.
|
||||
|
||||
Internationalization
|
||||
How much internationalization should we do?
|
||||
|
||||
The low hanging fruit is UTF-8 character set support. We should do this.
|
||||
See TODO_unicode file.
|
||||
(Vodz pointed out the shell's cmdedit as needing work here. What else?)
|
||||
|
||||
We also have lots of hardwired english text messages. Consolidating this
|
||||
into some kind of message table not only makes translation easier, but
|
||||
@@ -61,7 +69,6 @@ Rob Landley suggested this:
|
||||
Turning libbb into a real dll is another possibility, especially if libbb
|
||||
could export some of the other library interfaces we've already more or less
|
||||
got the code for (like zlib).
|
||||
|
||||
buildroot - Make a "dogfood" option
|
||||
Busybox 1.1 will be capable of replacing most gnu packages for real world
|
||||
use, such as developing software or in a live CD. It needs wider testing.
|
||||
@@ -81,29 +88,31 @@ Rob Landley suggested this:
|
||||
|
||||
One example of an existing system that does this already is Firmware Linux:
|
||||
http://www.landley.net/code/firmware
|
||||
|
||||
initramfs
|
||||
Busybox should have a sample initramfs build script. This depends on
|
||||
shell, mdev, and switch_root.
|
||||
|
||||
bbsh, mdev, and switch_root.
|
||||
mkdep
|
||||
Write a mkdep that doesn't segfault if there's a directory it doesn't
|
||||
have permission to read, isn't based on manually editing the output of
|
||||
lexx and yacc, doesn't make such a mess under include/config, etc.
|
||||
|
||||
Group globals into unions of structures.
|
||||
Go through and turn all the global and static variables into structures,
|
||||
and have all those structures be in a big union shared between processes,
|
||||
so busybox uses less bss. (This is a big win on nommu machines.) See
|
||||
sed.c and mdev.c for examples.
|
||||
|
||||
Go through bugs.busybox.net and close out all of that somehow.
|
||||
This one's open to everybody, but I'll wind up doing it...
|
||||
|
||||
Bernhard Reutner-Fischer <busybox@busybox.net> suggests to look at these:
|
||||
|
||||
Bernhard Fischer <busybox@busybox.net> suggests to look at these:
|
||||
New debug options:
|
||||
-Wlarger-than-127
|
||||
Cleanup any big users
|
||||
-Wunused-parameter
|
||||
Facilitate applet PROTOTYPES to provide means for having applets that
|
||||
do a) not take any arguments b) need only one of argc or argv c) need
|
||||
both argc and argv. All of these three options should go for the most
|
||||
feature complete denominator.
|
||||
Collate BUFSIZ IOBUF_SIZE MY_BUF_SIZE PIPE_PROGRESS_SIZE BUFSIZE PIPESIZE
|
||||
make bb_common_bufsiz1 configurable, size wise.
|
||||
make pipesize configurable, size wise.
|
||||
@@ -127,6 +136,31 @@ 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
|
||||
---
|
||||
man
|
||||
It would be nice to have a man command. Not one that handles troff or
|
||||
anything, just one that can handle preformatted ascii man pages, possibly
|
||||
compressed. This could probably be a script in the extras directory that
|
||||
calls cat/zcat/bzcat | less
|
||||
|
||||
(How doclifter might work into this is anybody's guess.)
|
||||
---
|
||||
ar
|
||||
Write support?
|
||||
---
|
||||
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:
|
||||
|
||||
@@ -154,7 +188,8 @@ Unify archivers
|
||||
---
|
||||
Text buffer support.
|
||||
Several existing applets (sort, vi, less...) read
|
||||
a whole file into memory and act on it. Use open_read_close().
|
||||
a whole file into memory and act on it. There might be an opportunity
|
||||
for shared code in there that could be moved into libbb...
|
||||
---
|
||||
Memory Allocation
|
||||
We have a CONFIG_BUFFER mechanism that lets us select whether to do memory
|
||||
@@ -169,10 +204,44 @@ Memory Allocation
|
||||
call free might also be optimized out by the compiler if written right, so
|
||||
we can yank those #ifdefs too, and generally clean up the code.
|
||||
---
|
||||
Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS
|
||||
|
||||
In busybox 1.0 and earlier, configuration was done by CONFIG_SYMBOLS
|
||||
that were either defined or undefined to indicate whether the symbol was
|
||||
selected in the .config file. They were used with #ifdefs, ala:
|
||||
|
||||
#ifdef CONFIG_SYMBOL
|
||||
if (other_test) {
|
||||
do_code();
|
||||
}
|
||||
#endif
|
||||
|
||||
In 1.1, we have new ENABLE_SYMBOLS which are always defined (as 0 or 1),
|
||||
meaning you can still use them for preprocessor tests by replacing
|
||||
"#ifdef CONFIG_SYMBOL" with "#if ENABLE_SYMBOL". But more importantly, we
|
||||
can use them as a true or false test in normal C code:
|
||||
|
||||
if (ENABLE_SYMBOL && other_test) {
|
||||
do_code();
|
||||
}
|
||||
|
||||
(Optimizing away if() statements that resolve to a constant value
|
||||
is known as "dead code elimination", an optimization so old and simple that
|
||||
Turbo Pascal for DOS did it twenty years ago. Even modern mini-compilers
|
||||
like the Tiny C Compiler (tcc) and the Small Device C Compiler (SDCC)
|
||||
perform dead code elimination.)
|
||||
|
||||
Right now, busybox.h is #including both "config.h" (defining the
|
||||
CONFIG_SYMBOLS) and "bb_config.h" (defining the ENABLE_SYMBOLS). At some
|
||||
point in the future, it would be nice to wean ourselves off of the
|
||||
CONFIG versions. (Among other things, some defective build environments
|
||||
leak the Linux kernel's CONFIG_SYMBOLS into the system's standard #include
|
||||
files. We've experienced collisions before.)
|
||||
---
|
||||
FEATURE_CLEAN_UP
|
||||
This is more an unresolved issue than a to-do item. More thought is needed.
|
||||
|
||||
Normally we rely on exit() to free memory, close files and unmap segments
|
||||
Normally we rely on exit() to free memory, close files, and unmap segments
|
||||
for us. This makes most calls to free(), close(), and unmap() optional in
|
||||
busybox applets that don't intend to run for very long, and optional stuff
|
||||
can be omitted to save size.
|
||||
@@ -201,6 +270,7 @@ FEATURE_CLEAN_UP
|
||||
For right now, exit() handles it just fine.
|
||||
|
||||
|
||||
|
||||
Minor stuff:
|
||||
watchdog.c could autodetect the timer duration via:
|
||||
if(!ioctl (fd, WDIOC_GETTIMEOUT, &tmo)) timer_duration = 1 + (tmo / 2);
|
||||
@@ -212,45 +282,24 @@ Minor stuff:
|
||||
---
|
||||
use bb_perror_msg where appropriate: See
|
||||
egrep "[^_]perror"
|
||||
---
|
||||
Remove superfluous fmt occurances: e.g.
|
||||
fprintf(stderr, "%s: %s not found\n", "unalias", *argptr);
|
||||
-> fprintf(stderr, "unalias: %s not found\n", *argptr);
|
||||
---
|
||||
possible code duplication ingroup() and is_a_group_member()
|
||||
---
|
||||
Move __get_hz() to a better place and (re)use it in route.c, ash.c
|
||||
Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
|
||||
---
|
||||
See grep -r strtod
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
|
||||
|
||||
Code cleanup:
|
||||
|
||||
Replace deprecated functions.
|
||||
|
||||
---
|
||||
vdprintf() -> similar sized functionality
|
||||
---
|
||||
|
||||
(TODO list after discussion 11.05.2009)
|
||||
|
||||
* shrink tc/brctl/ip
|
||||
tc/brctl seem like fairly large things to try and tackle in your timeframe,
|
||||
and i think people have posted attempts in the past. Adding additional
|
||||
options to ip though seems reasonable.
|
||||
|
||||
* add tests for some applets
|
||||
|
||||
* implement POSIX utilities and audit them for POSIX conformance. then
|
||||
audit them for GNU conformance. then document all your findings in a new
|
||||
doc/conformance.txt file while perhaps implementing some of the missing
|
||||
features.
|
||||
you can find the latest POSIX documentation (1003.1-2008) here:
|
||||
http://www.opengroup.org/onlinepubs/9699919799/
|
||||
and the complete list of all utilities that POSIX covers:
|
||||
http://www.opengroup.org/onlinepubs/9699919799/idx/utilities.html
|
||||
The first step would to generate a file/matrix what is already archived
|
||||
(also IPV6)
|
||||
|
||||
* implement 'at'
|
||||
|
||||
* rpcbind (former portmap) or equivalent
|
||||
so that we don't have to use -o nolock on nfs mounts
|
||||
|
||||
* check IPV6 compliance
|
||||
|
||||
* generate a mini example using kernel+busybox only (+libc) for example
|
||||
|
||||
* more support for advanced linux 2.6.x features, see: iotop
|
||||
most likely there is more
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.16.0
|
||||
# Wed Jan 27 21:01:26 2010
|
||||
# Busybox version: 1.10.0.svn
|
||||
# Thu Mar 20 14:54:21 2008
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -12,10 +12,8 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
#
|
||||
# General Configuration
|
||||
#
|
||||
CONFIG_NITPICK=y
|
||||
CONFIG_DESKTOP=y
|
||||
CONFIG_EXTRA_COMPAT=y
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -24,9 +22,7 @@ CONFIG_FEATURE_VERBOSE_USAGE=y
|
||||
CONFIG_FEATURE_COMPRESS_USAGE=y
|
||||
CONFIG_FEATURE_INSTALLER=y
|
||||
# CONFIG_LOCALE_SUPPORT is not set
|
||||
# CONFIG_UNICODE_SUPPORT is not set
|
||||
# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
|
||||
CONFIG_LONG_OPTS=y
|
||||
CONFIG_GETOPT_LONG=y
|
||||
CONFIG_FEATURE_DEVPTS=y
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
CONFIG_FEATURE_PIDFILE=y
|
||||
@@ -37,29 +33,27 @@ CONFIG_SELINUX=y
|
||||
CONFIG_FEATURE_PREFER_APPLETS=y
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
CONFIG_FEATURE_HAVE_RPC=y
|
||||
|
||||
#
|
||||
# Build Options
|
||||
#
|
||||
# CONFIG_STATIC is not set
|
||||
# CONFIG_PIE is not set
|
||||
CONFIG_NOMMU=y
|
||||
# CONFIG_BUILD_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_INDIVIDUAL is not set
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
CONFIG_CROSS_COMPILER_PREFIX=""
|
||||
CONFIG_EXTRA_CFLAGS=""
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
# CONFIG_DEBUG_PESSIMIZE is not set
|
||||
# CONFIG_WERROR is not set
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
# CONFIG_EFENCE is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
|
||||
#
|
||||
# Installation Options
|
||||
@@ -78,7 +72,7 @@ CONFIG_PREFIX="./_install"
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
CONFIG_MD5_SIZE_VS_SPEED=2
|
||||
CONFIG_FEATURE_FAST_TOP=y
|
||||
CONFIG_FEATURE_ETC_NETWORKS=y
|
||||
CONFIG_FEATURE_EDITING=y
|
||||
@@ -89,13 +83,10 @@ CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
CONFIG_FEATURE_TAB_COMPLETION=y
|
||||
CONFIG_FEATURE_USERNAME_COMPLETION=y
|
||||
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
|
||||
CONFIG_FEATURE_EDITING_ASK_TERMINAL=y
|
||||
CONFIG_FEATURE_NON_POSIX_CP=y
|
||||
CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y
|
||||
CONFIG_FEATURE_COPYBUF_KB=4
|
||||
CONFIG_MONOTONIC_SYSCALL=y
|
||||
CONFIG_IOCTL_HEX2STR_ERROR=y
|
||||
CONFIG_FEATURE_HWIB=y
|
||||
|
||||
#
|
||||
# Applets
|
||||
@@ -104,28 +95,26 @@ CONFIG_FEATURE_HWIB=y
|
||||
#
|
||||
# Archival Utilities
|
||||
#
|
||||
CONFIG_FEATURE_SEAMLESS_LZMA=y
|
||||
CONFIG_FEATURE_SEAMLESS_BZ2=y
|
||||
CONFIG_FEATURE_SEAMLESS_GZ=y
|
||||
CONFIG_FEATURE_SEAMLESS_Z=y
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
CONFIG_FEATURE_CPIO_P=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_FEATURE_RPM_BZ2=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
CONFIG_FEATURE_TAR_GZIP=y
|
||||
CONFIG_FEATURE_TAR_BZIP2=y
|
||||
CONFIG_FEATURE_TAR_LZMA=y
|
||||
CONFIG_FEATURE_TAR_COMPRESS=y
|
||||
CONFIG_FEATURE_TAR_AUTODETECT=y
|
||||
CONFIG_FEATURE_TAR_FROM=y
|
||||
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
|
||||
@@ -133,12 +122,23 @@ CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_UNZIP=y
|
||||
|
||||
#
|
||||
# Common options for cpio and tar
|
||||
#
|
||||
CONFIG_FEATURE_UNARCHIVE_TAPE=y
|
||||
|
||||
#
|
||||
# Common options for dpkg and dpkg_deb
|
||||
#
|
||||
CONFIG_FEATURE_DEB_TAR_GZ=y
|
||||
CONFIG_FEATURE_DEB_TAR_BZ2=y
|
||||
CONFIG_FEATURE_DEB_TAR_LZMA=y
|
||||
|
||||
#
|
||||
# Coreutils
|
||||
#
|
||||
@@ -149,22 +149,18 @@ CONFIG_CATV=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_FEATURE_CP_LONG_OPTIONS=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_FEATURE_DATE_ISOFMT=y
|
||||
CONFIG_FEATURE_DATE_COMPAT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_FEATURE_DF_FANCY=y
|
||||
CONFIG_FEATURE_DF_INODE=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
@@ -180,13 +176,13 @@ CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_FSYNC=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_FEATURE_FANCY_HEAD=y
|
||||
CONFIG_HOSTID=y
|
||||
CONFIG_ID=y
|
||||
CONFIG_INSTALL=y
|
||||
CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y
|
||||
CONFIG_LENGTH=y
|
||||
CONFIG_LN=y
|
||||
CONFIG_LOGNAME=y
|
||||
CONFIG_LS=y
|
||||
@@ -219,11 +215,8 @@ CONFIG_RMDIR=y
|
||||
CONFIG_FEATURE_RMDIR_LONG_OPTIONS=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_FEATURE_FLOAT_SLEEP=y
|
||||
CONFIG_SORT=y
|
||||
CONFIG_FEATURE_SORT_BIG=y
|
||||
CONFIG_SPLIT=y
|
||||
@@ -264,13 +257,18 @@ CONFIG_YES=y
|
||||
#
|
||||
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
|
||||
|
||||
#
|
||||
# Common options for ls, more and telnet
|
||||
#
|
||||
CONFIG_FEATURE_AUTOWIDTH=y
|
||||
|
||||
#
|
||||
# Common options for df, du, ls
|
||||
#
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
# Common options for md5sum, sha1sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -290,12 +288,8 @@ CONFIG_RESIZE=y
|
||||
CONFIG_FEATURE_RESIZE_PRINT=y
|
||||
CONFIG_SETCONSOLE=y
|
||||
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
|
||||
CONFIG_SETFONT=y
|
||||
CONFIG_FEATURE_SETFONT_TEXTUAL_MAP=y
|
||||
CONFIG_DEFAULT_SETFONT_DIR=""
|
||||
CONFIG_SETKEYCODES=y
|
||||
CONFIG_SETLOGCONS=y
|
||||
CONFIG_SHOWKEY=y
|
||||
|
||||
#
|
||||
# Debian Utilities
|
||||
@@ -314,11 +308,12 @@ CONFIG_WHICH=y
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_FEATURE_AWK_MATH=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
@@ -334,6 +329,7 @@ CONFIG_FEATURE_VI_READONLY=y
|
||||
CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
@@ -361,7 +357,6 @@ CONFIG_FEATURE_FIND_DELETE=y
|
||||
CONFIG_FEATURE_FIND_PATH=y
|
||||
CONFIG_FEATURE_FIND_REGEX=y
|
||||
CONFIG_FEATURE_FIND_CONTEXT=y
|
||||
CONFIG_FEATURE_FIND_LINKS=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
@@ -376,37 +371,31 @@ CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
# Init Utilities
|
||||
#
|
||||
CONFIG_INIT=y
|
||||
# CONFIG_DEBUG_INIT is not set
|
||||
CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_REMOVED=y
|
||||
CONFIG_FEATURE_KILL_DELAY=1
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_HALT=y
|
||||
# CONFIG_FEATURE_CALL_TELINIT is not set
|
||||
CONFIG_TELINIT_PATH=""
|
||||
CONFIG_MESG=y
|
||||
|
||||
#
|
||||
# Login/Password Management Utilities
|
||||
#
|
||||
CONFIG_FEATURE_SHADOWPASSWDS=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_USE_BB_SHADOW=y
|
||||
CONFIG_USE_BB_CRYPT=y
|
||||
CONFIG_USE_BB_CRYPT_SHA=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
|
||||
CONFIG_FEATURE_CHECK_NAMES=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_FEATURE_ADDUSER_LONG_OPTIONS=y
|
||||
CONFIG_FIRST_SYSTEM_ID=100
|
||||
CONFIG_LAST_SYSTEM_ID=999
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
@@ -436,36 +425,30 @@ CONFIG_LSATTR=y
|
||||
#
|
||||
# Linux Module Utilities
|
||||
#
|
||||
CONFIG_MODPROBE_SMALL=y
|
||||
CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE=y
|
||||
CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
|
||||
# CONFIG_INSMOD is not set
|
||||
# CONFIG_RMMOD is not set
|
||||
# CONFIG_LSMOD is not set
|
||||
# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
|
||||
# CONFIG_MODPROBE is not set
|
||||
# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
|
||||
# CONFIG_DEPMOD is not set
|
||||
CONFIG_INSMOD=y
|
||||
CONFIG_FEATURE_INSMOD_VERSION_CHECKING=y
|
||||
CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS=y
|
||||
CONFIG_FEATURE_INSMOD_LOADINKMEM=y
|
||||
CONFIG_FEATURE_INSMOD_LOAD_MAP=y
|
||||
CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL=y
|
||||
CONFIG_RMMOD=y
|
||||
CONFIG_LSMOD=y
|
||||
CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
|
||||
CONFIG_MODPROBE=y
|
||||
CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS=y
|
||||
CONFIG_FEATURE_MODPROBE_FANCY_ALIAS=y
|
||||
|
||||
#
|
||||
# Options common to multiple modutils
|
||||
#
|
||||
# CONFIG_FEATURE_2_4_MODULES is not set
|
||||
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
|
||||
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
|
||||
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
|
||||
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
|
||||
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
|
||||
CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
|
||||
CONFIG_FEATURE_2_4_MODULES=y
|
||||
CONFIG_FEATURE_2_6_MODULES=y
|
||||
# CONFIG_FEATURE_QUERY_MODULE_INTERFACE is not set
|
||||
|
||||
#
|
||||
# Linux System Utilities
|
||||
#
|
||||
# CONFIG_ACPID is not set
|
||||
# CONFIG_FEATURE_ACPID_COMPAT is not set
|
||||
CONFIG_BLKID=y
|
||||
CONFIG_DMESG=y
|
||||
CONFIG_FEATURE_DMESG_PRETTY=y
|
||||
CONFIG_FBSET=y
|
||||
@@ -484,17 +467,13 @@ CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FINDFS=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_EXT2=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
|
||||
#
|
||||
# Minix filesystem support
|
||||
#
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_MKFS_REISER=y
|
||||
CONFIG_MKFS_VFAT=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_FEATURE_GETOPT_LONG=y
|
||||
CONFIG_HEXDUMP=y
|
||||
CONFIG_FEATURE_HEXDUMP_REVERSE=y
|
||||
CONFIG_HD=y
|
||||
@@ -504,20 +483,17 @@ CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
CONFIG_IPCRM=y
|
||||
CONFIG_IPCS=y
|
||||
CONFIG_LOSETUP=y
|
||||
CONFIG_LSPCI=y
|
||||
CONFIG_LSUSB=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_UUID=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_VOLUMEID=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
@@ -544,14 +520,10 @@ CONFIG_FEATURE_MOUNT_FLAGS=y
|
||||
CONFIG_FEATURE_MOUNT_FSTAB=y
|
||||
CONFIG_PIVOT_ROOT=y
|
||||
CONFIG_RDATE=y
|
||||
CONFIG_RDEV=y
|
||||
CONFIG_READPROFILE=y
|
||||
CONFIG_RTCWAKE=y
|
||||
CONFIG_SCRIPT=y
|
||||
CONFIG_SCRIPTREPLAY=y
|
||||
CONFIG_SETARCH=y
|
||||
CONFIG_SWAPONOFF=y
|
||||
CONFIG_FEATURE_SWAPON_PRI=y
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
CONFIG_UMOUNT=y
|
||||
CONFIG_FEATURE_UMOUNT_ALL=y
|
||||
@@ -567,9 +539,6 @@ CONFIG_FEATURE_MOUNT_LOOP=y
|
||||
#
|
||||
CONFIG_ADJTIMEX=y
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_BEEP=y
|
||||
CONFIG_FEATURE_BEEP_FREQ=4000
|
||||
CONFIG_FEATURE_BEEP_LENGTH_MS=30
|
||||
CONFIG_CHAT=y
|
||||
CONFIG_FEATURE_CHAT_NOFAIL=y
|
||||
CONFIG_FEATURE_CHAT_TTY_HIFI=y
|
||||
@@ -580,39 +549,25 @@ CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_DEBUG_CROND_OPTION=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
CONFIG_FEATURE_DC_LIBM=y
|
||||
# CONFIG_DEVFSD is not set
|
||||
# CONFIG_DEVFSD_MODLOAD is not set
|
||||
# CONFIG_DEVFSD_FG_NP is not set
|
||||
# CONFIG_DEVFSD_VERBOSE is not set
|
||||
# CONFIG_FEATURE_DEVFS is not set
|
||||
CONFIG_DEVMEM=y
|
||||
CONFIG_EJECT=y
|
||||
CONFIG_FEATURE_EJECT_SCSI=y
|
||||
CONFIG_FBSPLASH=y
|
||||
CONFIG_FLASHCP=y
|
||||
# CONFIG_FLASH_LOCK is not set
|
||||
# CONFIG_FLASH_UNLOCK is not set
|
||||
# CONFIG_FLASH_ERASEALL is not set
|
||||
CONFIG_IONICE=y
|
||||
CONFIG_INOTIFYD=y
|
||||
CONFIG_LAST=y
|
||||
CONFIG_FEATURE_LAST_SMALL=y
|
||||
# CONFIG_FEATURE_LAST_FANCY is not set
|
||||
CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
CONFIG_FEATURE_LESS_BRACKETS=y
|
||||
CONFIG_FEATURE_LESS_FLAGS=y
|
||||
CONFIG_FEATURE_LESS_FLAGCS=y
|
||||
CONFIG_FEATURE_LESS_MARKS=y
|
||||
CONFIG_FEATURE_LESS_REGEXP=y
|
||||
CONFIG_FEATURE_LESS_WINCH=y
|
||||
CONFIG_FEATURE_LESS_DASHCMD=y
|
||||
CONFIG_FEATURE_LESS_LINENUMS=y
|
||||
CONFIG_HDPARM=y
|
||||
CONFIG_FEATURE_HDPARM_GET_IDENTITY=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y
|
||||
@@ -623,7 +578,6 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
|
||||
CONFIG_FEATURE_MAKEDEVS_TABLE=y
|
||||
CONFIG_MAN=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_MT=y
|
||||
@@ -631,35 +585,28 @@ CONFIG_RAIDAUTORUN=y
|
||||
CONFIG_READAHEAD=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
CONFIG_RX=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_SCRIPT=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_TASKSET=y
|
||||
CONFIG_FEATURE_TASKSET_FANCY=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
CONFIG_WALL=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
CONFIG_FEATURE_UNIX_LOCAL=y
|
||||
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
|
||||
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
|
||||
CONFIG_ARP=y
|
||||
CONFIG_ARPING=y
|
||||
CONFIG_BRCTL=y
|
||||
CONFIG_FEATURE_BRCTL_FANCY=y
|
||||
CONFIG_FEATURE_BRCTL_SHOW=y
|
||||
CONFIG_DNSD=y
|
||||
CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
@@ -667,9 +614,11 @@ CONFIG_HOSTNAME=y
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
|
||||
CONFIG_FEATURE_HTTPD_CGI=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
|
||||
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
|
||||
@@ -683,7 +632,6 @@ CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
|
||||
CONFIG_FEATURE_IFCONFIG_HW=y
|
||||
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
|
||||
CONFIG_IFENSLAVE=y
|
||||
CONFIG_IFPLUGD=y
|
||||
CONFIG_IFUPDOWN=y
|
||||
CONFIG_IFUPDOWN_IFSTATE_PATH="/var/run/ifstate"
|
||||
CONFIG_FEATURE_IFUPDOWN_IP=y
|
||||
@@ -703,7 +651,6 @@ CONFIG_FEATURE_INETD_RPC=y
|
||||
CONFIG_IP=y
|
||||
CONFIG_FEATURE_IP_ADDRESS=y
|
||||
CONFIG_FEATURE_IP_LINK=y
|
||||
CONFIG_FEATURE_IP_LINK_CAN=y
|
||||
CONFIG_FEATURE_IP_ROUTE=y
|
||||
CONFIG_FEATURE_IP_TUNNEL=y
|
||||
CONFIG_FEATURE_IP_RULE=y
|
||||
@@ -724,46 +671,42 @@ CONFIG_NC_SERVER=y
|
||||
CONFIG_NC_EXTRA=y
|
||||
CONFIG_NETSTAT=y
|
||||
CONFIG_FEATURE_NETSTAT_WIDE=y
|
||||
CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_NTPD=y
|
||||
CONFIG_FEATURE_NTPD_SERVER=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_SENDMAIL=y
|
||||
CONFIG_FETCHMAIL=y
|
||||
CONFIG_SLATTACH=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
CONFIG_TELNETD=y
|
||||
CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
CONFIG_FEATURE_TELNETD_INETD_WAIT=y
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_TFTPD=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
|
||||
CONFIG_TFTP_DEBUG=y
|
||||
CONFIG_DEBUG_TFTP=y
|
||||
CONFIG_TRACEROUTE=y
|
||||
CONFIG_TRACEROUTE6=y
|
||||
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
|
||||
CONFIG_UDHCPD=y
|
||||
CONFIG_DHCPRELAY=y
|
||||
CONFIG_DUMPLEASES=y
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
|
||||
CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_APP_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
CONFIG_FEATURE_UDHCP_RFC3397=y
|
||||
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
CONFIG_FEATURE_UDHCP_DEBUG=y
|
||||
CONFIG_FEATURE_RFC3397=y
|
||||
CONFIG_DHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
|
||||
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"
|
||||
CONFIG_VCONFIG=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_FEATURE_WGET_STATUSBAR=y
|
||||
@@ -771,28 +714,8 @@ CONFIG_FEATURE_WGET_AUTHENTICATION=y
|
||||
CONFIG_FEATURE_WGET_LONG_OPTIONS=y
|
||||
CONFIG_ZCIP=y
|
||||
CONFIG_TCPSVD=y
|
||||
CONFIG_TUNCTL=y
|
||||
CONFIG_FEATURE_TUNCTL_UG=y
|
||||
CONFIG_UDPSVD=y
|
||||
|
||||
#
|
||||
# Print Utilities
|
||||
#
|
||||
CONFIG_LPD=y
|
||||
CONFIG_LPR=y
|
||||
CONFIG_LPQ=y
|
||||
|
||||
#
|
||||
# Mail Utilities
|
||||
#
|
||||
CONFIG_MAKEMIME=y
|
||||
CONFIG_FEATURE_MIME_CHARSET="us-ascii"
|
||||
CONFIG_POPMAILDIR=y
|
||||
CONFIG_FEATURE_POPMAILDIR_DELIVERY=y
|
||||
CONFIG_REFORMIME=y
|
||||
CONFIG_FEATURE_REFORMIME_COMPAT=y
|
||||
CONFIG_SENDMAIL=y
|
||||
|
||||
#
|
||||
# Process Utilities
|
||||
#
|
||||
@@ -810,29 +733,76 @@ CONFIG_PKILL=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_FEATURE_PS_TIME=y
|
||||
CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
|
||||
CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_UPTIME=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH is not set
|
||||
# CONFIG_ASH_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_READ_NCHARS is not set
|
||||
# CONFIG_ASH_READ_TIMEOUT is not set
|
||||
# CONFIG_ASH_ALIAS is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT_64 is not set
|
||||
# CONFIG_ASH_GETOPTS is not set
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
CONFIG_HUSH=y
|
||||
CONFIG_HUSH_HELP=y
|
||||
CONFIG_HUSH_INTERACTIVE=y
|
||||
CONFIG_HUSH_JOB=y
|
||||
CONFIG_HUSH_TICK=y
|
||||
CONFIG_HUSH_IF=y
|
||||
CONFIG_HUSH_LOOPS=y
|
||||
CONFIG_LASH=y
|
||||
CONFIG_MSH=y
|
||||
|
||||
#
|
||||
# Bourne Shell Options
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_CTTYHACK=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
#
|
||||
CONFIG_SYSLOGD=y
|
||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||
CONFIG_FEATURE_REMOTE_LOG=y
|
||||
CONFIG_FEATURE_SYSLOGD_DUP=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
|
||||
CONFIG_LOGREAD=y
|
||||
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_LOGGER=y
|
||||
|
||||
#
|
||||
# Runit Utilities
|
||||
#
|
||||
CONFIG_RUNSV=y
|
||||
CONFIG_RUNSVDIR=y
|
||||
CONFIG_FEATURE_RUNSVDIR_LOG=y
|
||||
CONFIG_SV=y
|
||||
CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
|
||||
CONFIG_SVLOGD=y
|
||||
CONFIG_CHPST=y
|
||||
CONFIG_SETUIDGID=y
|
||||
@@ -841,7 +811,7 @@ CONFIG_ENVDIR=y
|
||||
CONFIG_SOFTLIMIT=y
|
||||
|
||||
#
|
||||
# SELinux Utilities
|
||||
# Selinux Utilities
|
||||
#
|
||||
CONFIG_CHCON=y
|
||||
CONFIG_FEATURE_CHCON_LONG_OPTIONS=y
|
||||
@@ -860,54 +830,8 @@ CONFIG_SETSEBOOL=y
|
||||
CONFIG_SESTATUS=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
# Print Utilities
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
CONFIG_FEATURE_SH_IS_HUSH=y
|
||||
# CONFIG_FEATURE_SH_IS_NONE is not set
|
||||
# CONFIG_ASH is not set
|
||||
# CONFIG_ASH_BASH_COMPAT is not set
|
||||
# CONFIG_ASH_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_ALIAS is not set
|
||||
# CONFIG_ASH_GETOPTS is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
CONFIG_HUSH=y
|
||||
CONFIG_HUSH_BASH_COMPAT=y
|
||||
CONFIG_HUSH_HELP=y
|
||||
CONFIG_HUSH_INTERACTIVE=y
|
||||
CONFIG_HUSH_JOB=y
|
||||
CONFIG_HUSH_TICK=y
|
||||
CONFIG_HUSH_IF=y
|
||||
CONFIG_HUSH_LOOPS=y
|
||||
CONFIG_HUSH_CASE=y
|
||||
CONFIG_HUSH_FUNCTIONS=y
|
||||
CONFIG_HUSH_LOCAL=y
|
||||
CONFIG_HUSH_EXPORT_N=y
|
||||
CONFIG_HUSH_RANDOM_SUPPORT=y
|
||||
CONFIG_SH_MATH_SUPPORT=y
|
||||
CONFIG_SH_MATH_SUPPORT_64=y
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_FEATURE_SH_NOFORK=y
|
||||
CONFIG_CTTYHACK=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
#
|
||||
CONFIG_SYSLOGD=y
|
||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||
CONFIG_FEATURE_REMOTE_LOG=y
|
||||
CONFIG_FEATURE_SYSLOGD_DUP=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
|
||||
CONFIG_LOGREAD=y
|
||||
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_LOGGER=y
|
||||
CONFIG_LPD=y
|
||||
CONFIG_LPR=y
|
||||
CONFIG_LPQ=y
|
||||
@@ -1,45 +0,0 @@
|
||||
Already fixed applets:
|
||||
cal
|
||||
lsmod
|
||||
df
|
||||
dumpleases
|
||||
|
||||
Applets which may need unicode handling (more extensive than sanitizing
|
||||
of filenames in error messages):
|
||||
|
||||
ls - work in progress
|
||||
expand, unexpand - uses unicode_strlen, not scrlen
|
||||
ash, hush through lineedit - uses unicode_strlen, not scrlen
|
||||
top - need to sanitize process args
|
||||
ps - need to sanitize process args
|
||||
less
|
||||
more
|
||||
vi
|
||||
ed
|
||||
cut
|
||||
awk
|
||||
sed
|
||||
tr
|
||||
grep egrep fgrep
|
||||
fold
|
||||
sort
|
||||
head, tail
|
||||
catv - "display nonprinting chars" - what this could mean for unicode?
|
||||
wc
|
||||
chat
|
||||
dumpkmap
|
||||
last - just line up columns
|
||||
man
|
||||
microcom
|
||||
strings
|
||||
watch
|
||||
|
||||
Unsure, may need fixing:
|
||||
|
||||
hostname - do we really want to protect against bad chars in it?
|
||||
patch
|
||||
addgroup, adduser, delgroup, deluser
|
||||
telnet
|
||||
telnetd
|
||||
od
|
||||
printf
|
||||
@@ -1,3 +0,0 @@
|
||||
/applet_tables
|
||||
/usage
|
||||
/usage_pod
|
||||
@@ -0,0 +1,34 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
applets/applet_tables: .config
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
|
||||
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
|
||||
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
|
||||
|
||||
include/applet_tables.h: applets/applet_tables
|
||||
$(call cmd,gen_applet_tables)
|
||||
@@ -1,57 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage usage_pod applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
# This trick decreases amount of rebuilds
|
||||
# if tree is merely renamed/copied
|
||||
ifeq ($(srctree),$(objtree))
|
||||
srctree_slash =
|
||||
else
|
||||
srctree_slash = $(srctree)/
|
||||
endif
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
|
||||
HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/applet_tables: .config include/applets.h
|
||||
applets/usage: .config include/applets.h
|
||||
applets/usage_pod: .config include/applets.h include/applet_tables.h
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
include/usage_compressed.h: applets/usage $(srctree_slash)applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
|
||||
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h include/NUM_APPLETS.h
|
||||
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h include/NUM_APPLETS.h
|
||||
|
||||
include/NUM_APPLETS.h: applets/applet_tables
|
||||
$(call cmd,gen_applet_tables)
|
||||
|
||||
# In fact, include/applet_tables.h depends only on applets/applet_tables,
|
||||
# and is generated by it. But specifying only it can run
|
||||
# applets/applet_tables twice, possibly in parallel.
|
||||
# We say that it also needs NUM_APPLETS.h
|
||||
#
|
||||
# Unfortunately, we need to list the same command,
|
||||
# and it can be executed twice (sequentially).
|
||||
# The alternative is to not list any command,
|
||||
# and then if include/applet_tables.h is deleted, it won't be rebuilt.
|
||||
#
|
||||
include/applet_tables.h: include/NUM_APPLETS.h applets/applet_tables
|
||||
$(call cmd,gen_applet_tables)
|
||||
+36
-165
@@ -5,27 +5,15 @@
|
||||
*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#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])))
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/applet_metadata.h"
|
||||
#include "../include/busybox.h"
|
||||
|
||||
struct bb_applet {
|
||||
const char *name;
|
||||
@@ -46,6 +34,8 @@ struct bb_applet {
|
||||
|
||||
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
|
||||
|
||||
static int offset[NUM_APPLETS];
|
||||
|
||||
static int cmp_name(const void *a, const void *b)
|
||||
{
|
||||
const struct bb_applet *aa = a;
|
||||
@@ -53,149 +43,63 @@ 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((unsigned char)*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
char tmp1[PATH_MAX], tmp2[PATH_MAX];
|
||||
|
||||
// In find_applet_by_name(), before linear search, narrow it down
|
||||
// by looking at N "equidistant" names. With ~350 applets:
|
||||
// KNOWN_APPNAME_OFFSETS cycles
|
||||
// 0 9057
|
||||
// 2 4604 + ~100 bytes of code
|
||||
// 4 2407 + 4 bytes
|
||||
// 8 1342 + 8 bytes
|
||||
// 16 908 + 16 bytes
|
||||
// 32 884 + 32 bytes
|
||||
// With 8, int16_t applet_nameofs[] table has 7 elements.
|
||||
int KNOWN_APPNAME_OFFSETS = 8;
|
||||
// With 128 applets we do two linear searches, with 1..7 strcmp's in the first one
|
||||
// and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's.
|
||||
if (NUM_APPLETS < 128)
|
||||
KNOWN_APPNAME_OFFSETS = 4;
|
||||
if (NUM_APPLETS < 32)
|
||||
KNOWN_APPNAME_OFFSETS = 0;
|
||||
int i;
|
||||
int ofs;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
for (i = j = 0; i < NUM_APPLETS-1; ++i) {
|
||||
if (cmp_name(applets+i, applets+i+1) == 0) {
|
||||
fprintf(stderr, "%s: duplicate applet name '%s'\n", argv[0],
|
||||
applets[i].name);
|
||||
j = 1;
|
||||
}
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
offset[i] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
|
||||
if (j != 0 || !argv[1])
|
||||
/* We reuse 4 high-order bits of offset array for other purposes,
|
||||
* so if they are indeed needed, refuse to proceed */
|
||||
if (ofs > 0xfff)
|
||||
return 1;
|
||||
snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
|
||||
i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
dup2(i, 1);
|
||||
|
||||
/* Keep in sync with include/busybox.h! */
|
||||
|
||||
printf("/* This is a generated file, don't edit */\n\n");
|
||||
puts("/* This is a generated file, don't edit */");
|
||||
|
||||
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
|
||||
if (NUM_APPLETS == 1) {
|
||||
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
|
||||
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
|
||||
}
|
||||
|
||||
printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
|
||||
if (KNOWN_APPNAME_OFFSETS > 0) {
|
||||
int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
|
||||
for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
|
||||
index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS;
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++)
|
||||
if (i == index[j])
|
||||
offset[j] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
/* If the list of names is too long refuse to proceed */
|
||||
if (ofs > 0xffff)
|
||||
return 1;
|
||||
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
|
||||
for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++)
|
||||
printf("%d,\n", offset[i]);
|
||||
printf("};\n\n");
|
||||
}
|
||||
|
||||
//printf("#ifndef SKIP_definitions\n");
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
puts("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);
|
||||
}
|
||||
printf(";\n\n");
|
||||
puts(";");
|
||||
|
||||
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");
|
||||
puts("int (*const applet_main[])(int argc, char **argv) = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("%s_main,\n", applets[i].main);
|
||||
}
|
||||
printf("};\n");
|
||||
printf("#endif\n\n");
|
||||
puts("};");
|
||||
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS \
|
||||
|| ENABLE_FEATURE_SH_STANDALONE \
|
||||
|| ENABLE_FEATURE_SH_NOFORK
|
||||
printf("const uint8_t applet_flags[] ALIGN1 = {\n");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].nofork + (applets[i].noexec << 1);
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6;
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
printf("};\n\n");
|
||||
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
+ (applets[i].nofork << 12)
|
||||
+ (applets[i].noexec << 13)
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
printf("const uint8_t applet_suid[] ALIGN1 = {\n");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].need_suid; /* 2 bits */
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 2;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 4;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 6;
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
printf("};\n\n");
|
||||
+ (applets[i].need_suid << 14) /* 2 bits */
|
||||
#endif
|
||||
);
|
||||
}
|
||||
puts("};");
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
|
||||
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].install_loc; /* 3 bits */
|
||||
@@ -204,41 +108,8 @@ int main(int argc, char **argv)
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
printf("};\n");
|
||||
puts("};");
|
||||
#endif
|
||||
//printf("#endif /* SKIP_definitions */\n");
|
||||
|
||||
// printf("\n");
|
||||
// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
if (argv[2]) {
|
||||
FILE *fp;
|
||||
char line_new[80];
|
||||
// char line_old[80];
|
||||
|
||||
sprintf(line_new, "#define NUM_APPLETS %u\n", NUM_APPLETS);
|
||||
// line_old[0] = 0;
|
||||
// fp = fopen(argv[2], "r");
|
||||
// if (fp) {
|
||||
// fgets(line_old, sizeof(line_old), fp);
|
||||
// fclose(fp);
|
||||
// }
|
||||
// if (strcmp(line_old, line_new) != 0) {
|
||||
snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid());
|
||||
fp = fopen(tmp2, "w");
|
||||
if (!fp)
|
||||
return 1;
|
||||
fputs(line_new, fp);
|
||||
if (fclose(fp))
|
||||
return 1;
|
||||
// }
|
||||
}
|
||||
|
||||
if (fclose(stdout))
|
||||
return 1;
|
||||
if (rename(tmp1, argv[1]))
|
||||
return 1;
|
||||
if (rename(tmp2, argv[2]))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
+4
-2
@@ -4,12 +4,14 @@
|
||||
*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#if ENABLE_BUILD_LIBBUSYBOX
|
||||
int main(int argc UNUSED_PARAM, char **argv)
|
||||
int main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
return lbb_main(argv);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
$HOSTCC -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*LINK/{
|
||||
dir=substr($2,7)
|
||||
dir=substr($2,8)
|
||||
gsub("_","/",dir)
|
||||
if(dir=="/ROOT") dir=""
|
||||
file=$3
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Make busybox scripted applet list file.
|
||||
|
||||
# input $1: full path to Config.h
|
||||
# input $2: full path to applets.h
|
||||
# output (stdout): list of pathnames that should be linked to busybox
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
$HOSTCC -E -DMAKE_SCRIPTS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*SCRIPT/{
|
||||
print $2
|
||||
}'
|
||||
@@ -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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* Copyright 2005 Rob Landley <rob@landley.net
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
* Licensed under GPL version 2, see file LICENSE in this tarball for details
|
||||
*/
|
||||
|
||||
const char *applet_name;
|
||||
@@ -14,11 +14,13 @@ const char *applet_name;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
applet_name = argv[0];
|
||||
return APPLET_main(argc, argv);
|
||||
|
||||
return APPLET_main(argc,argv);
|
||||
}
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
fputs_stdout(APPLET_full_usage "\n");
|
||||
exit_FAILURE();
|
||||
printf(APPLET_full_usage "\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
+53
-80
@@ -3,44 +3,28 @@
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
prefix=${1}
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]"
|
||||
echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none"
|
||||
echo " OPTS is one or more of: --cleanup --noclobber"
|
||||
exit 1
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
exit 1;
|
||||
fi
|
||||
shift # Keep only remaining options
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
sharedlib_dir="0_lib"
|
||||
|
||||
linkopts=""
|
||||
scriptwrapper="n"
|
||||
binaries="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
while [ ${#} -gt 0 ]; do
|
||||
case "$1" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--binaries) binaries="y";;
|
||||
--scriptwrapper) scriptwrapper="y"; swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y"; linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y"; linkopts="-fs";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
--none) h="";;
|
||||
*) echo "Unknown install option: $1"; exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
"") h="";;
|
||||
*) echo "Unknown install option: $2"; exit 1;;
|
||||
esac
|
||||
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
# get the target dir for the libs
|
||||
# assume it starts with lib
|
||||
libdir=$($CC -print-file-name=libc.so | \
|
||||
@@ -49,65 +33,50 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
|
||||
libdir=/lib
|
||||
fi
|
||||
|
||||
mkdir -p "$prefix/$libdir" || exit 1
|
||||
mkdir -p $prefix/$libdir || exit 1
|
||||
for i in $DO_INSTALL_LIBS; do
|
||||
rm -f "$prefix/$libdir/$i" || exit 1
|
||||
if [ -f "$i" ]; then
|
||||
echo " Installing $i to the target at $prefix/$libdir/"
|
||||
cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
||||
rm -f $prefix/$libdir/$i || exit 1
|
||||
if [ -f $i ]; then
|
||||
cp -a $i $prefix/$libdir/ || exit 1
|
||||
chmod 0644 $prefix/$libdir/$i || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
||||
sub_shell_it=`
|
||||
cd "$prefix"
|
||||
for d in usr/sbin usr/bin sbin bin; do
|
||||
pd=$PWD
|
||||
if [ -d "$d" ]; then
|
||||
cd "$d"
|
||||
ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
|
||||
fi
|
||||
cd "$pd"
|
||||
done
|
||||
`
|
||||
cd "$prefix"
|
||||
for d in usr/sbin usr/bin sbin bin; do
|
||||
pd=$PWD
|
||||
if [ -d "$d" ]; then
|
||||
cd $d
|
||||
ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
|
||||
fi
|
||||
cd "$pd"
|
||||
done
|
||||
`
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rm -f "$prefix/bin/busybox" || exit 1
|
||||
mkdir -p "$prefix/bin" || exit 1
|
||||
install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
|
||||
for i in $h; do
|
||||
appdir=`dirname "$i"`
|
||||
app=`basename "$i"`
|
||||
if [ x"$noclobber" = x"1" ] && ([ -e "$prefix/$i" ] || [ -h "$prefix/$i" ]); then
|
||||
echo " $prefix/$i already exists"
|
||||
continue
|
||||
fi
|
||||
mkdir -p "$prefix/$appdir" || exit 1
|
||||
if [ x"$scriptwrapper" = x"y" ]; then
|
||||
if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then
|
||||
ln $linkopts busybox "$prefix/$i" || exit 1
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
ln $linkopts busybox $prefix$i || exit 1
|
||||
else
|
||||
rm -f "$prefix/$i"
|
||||
echo "#!/bin/busybox" >"$prefix/$i"
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ x"$binaries" = x"y" ]; then
|
||||
# Copy the binary over rather
|
||||
if [ -e "$sharedlib_dir/$app" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1
|
||||
else
|
||||
echo "Error: Could not find $sharedlib_dir/$app"
|
||||
exit 1
|
||||
rm -f $prefix$i
|
||||
echo "#!/bin/busybox" > $prefix$i
|
||||
chmod +x $prefix/$i
|
||||
fi
|
||||
echo " $prefix$i"
|
||||
else
|
||||
if [ x"$linkopts" = x"-f" ]; then
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
@@ -120,17 +89,21 @@ for i in $h; do
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin | /usr/sbin)
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo " $prefix/$i -> $bb_path"
|
||||
ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
else
|
||||
echo " $prefix$i already exists"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
+7
-44
@@ -1,55 +1,18 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2008 Denys Vlasenko.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "autoconf.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#else
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "../include/autoconf.h"
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#define MAKE_USAGE(aname, usage) { aname, usage },
|
||||
static struct usage_data {
|
||||
const char *aname;
|
||||
const char *usage;
|
||||
} usage_array[] = {
|
||||
#include "applets.h"
|
||||
};
|
||||
|
||||
static int compare_func(const void *a, const void *b)
|
||||
{
|
||||
const struct usage_data *ua = a;
|
||||
const struct usage_data *ub = b;
|
||||
return strcmp(ua->aname, ub->aname);
|
||||
}
|
||||
;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
int num_messages = sizeof(usage_array) / sizeof(usage_array[0]);
|
||||
|
||||
if (num_messages == 0)
|
||||
return 0;
|
||||
|
||||
qsort(usage_array,
|
||||
num_messages, sizeof(usage_array[0]),
|
||||
compare_func);
|
||||
for (i = 0; i < num_messages; i++)
|
||||
write(STDOUT_FILENO, usage_array[i].usage, strlen(usage_array[i].usage) + 1);
|
||||
|
||||
write(1, usage_messages, sizeof(usage_messages));
|
||||
return 0;
|
||||
}
|
||||
+13
-48
@@ -7,56 +7,21 @@ test "$target" || exit 1
|
||||
test "$loc" || loc=.
|
||||
test -x "$loc/usage" || exit 1
|
||||
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
|
||||
if test $? != 0; then
|
||||
echo 'od tool is not installed or cannot accept "-v -b" options'
|
||||
exit 1
|
||||
fi
|
||||
sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
exec >"$target.$$"
|
||||
exec >"$target"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
echo 'static const char packed_usage[] ALIGN1 = {'
|
||||
|
||||
# Extra effort to avoid using "od -t x1": -t is not available
|
||||
# in non-CONFIG_DESKTOPed busybox od
|
||||
|
||||
"$loc/usage" | bzip2 -1 | od -v -x \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(...\)/\\\1/g' \
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
# "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
|
||||
#0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
|
||||
# 000010 000010 026533 063144 020135 026533 020143 047503
|
||||
#0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
|
||||
# 043116 044504 056522 055440 066055 046040 043517 044506
|
||||
#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
|
||||
# 042514 020135 026533 020141 041501 044524 047117 044506
|
||||
| $SED -e 's/ //g' \
|
||||
| grep -v '^$' \
|
||||
| $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
|
||||
echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`"
|
||||
echo
|
||||
|
||||
echo '#define PACKED_USAGE \'
|
||||
## Breaks on big-endian systems!
|
||||
## # Extra effort to avoid using "od -t x1": -t is not available
|
||||
## # in non-CONFIG_DESKTOPed busybox od
|
||||
##
|
||||
## "$loc/usage" | bzip2 -1 | od -v -x \
|
||||
## | $SED -e 's/^[^ ]*//' \
|
||||
## -e 's/ //g' \
|
||||
## -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 \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(...\)/0\1,/g' \
|
||||
-e 's/$/ \\/'
|
||||
echo ''
|
||||
|
||||
mv -- "$target.$$" "$target"
|
||||
echo '};'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
@@ -1,120 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2009 Denys Vlasenko.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "autoconf.h"
|
||||
|
||||
#define SKIP_applet_main
|
||||
#define ALIGN1 /* nothing, just to placate applet_tables.h */
|
||||
#define ALIGN2 /* nothing, just to placate applet_tables.h */
|
||||
#include "applet_tables.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#else
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
#include "usage.h"
|
||||
#define MAKE_USAGE(aname, usage) { aname, usage },
|
||||
static struct usage_data {
|
||||
const char *aname;
|
||||
const char *usage;
|
||||
} usage_array[] = {
|
||||
#include "applets.h"
|
||||
};
|
||||
|
||||
static int compare_func(const void *a, const void *b)
|
||||
{
|
||||
const struct usage_data *ua = a;
|
||||
const struct usage_data *ub = b;
|
||||
return strcmp(ua->aname, ub->aname);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int col, len2;
|
||||
|
||||
int i;
|
||||
int num_messages = sizeof(usage_array) / sizeof(usage_array[0]);
|
||||
|
||||
if (num_messages == 0)
|
||||
return 0;
|
||||
|
||||
qsort(usage_array,
|
||||
num_messages, sizeof(usage_array[0]),
|
||||
compare_func);
|
||||
|
||||
col = 0;
|
||||
for (i = 0; i < num_messages; i++) {
|
||||
len2 = strlen(usage_array[i].aname) + 2;
|
||||
if (col >= 76 - len2) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
if (col == 0) {
|
||||
col = 6;
|
||||
} else {
|
||||
printf(", ");
|
||||
}
|
||||
if (usage_array[i].usage[0] != NOUSAGE_STR[0]) {
|
||||
/*
|
||||
* If the applet usage string will be included in the final document
|
||||
* optimistically link to its header (which is just the applet name).
|
||||
*/
|
||||
printf("L<C<%1$s>|/\"%1$s\">", usage_array[i].aname);
|
||||
} else {
|
||||
/* Without a usage string, just output the applet name with no link. */
|
||||
printf("C<%s>", usage_array[i].aname);
|
||||
}
|
||||
col += len2;
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("=head1 COMMAND DESCRIPTIONS\n\n");
|
||||
|
||||
for (i = 0; i < num_messages; i++) {
|
||||
if (usage_array[i].aname[0] >= 'a' && usage_array[i].aname[0] <= 'z'
|
||||
&& usage_array[i].usage[0] != NOUSAGE_STR[0]
|
||||
) {
|
||||
/* This is the heading that will be linked from the command list. */
|
||||
printf("=head2 %s\n\n", usage_array[i].aname);
|
||||
if (usage_array[i].usage[0])
|
||||
printf("%s %s\n\n", usage_array[i].aname, usage_array[i].usage);
|
||||
else
|
||||
printf("%s\n\n", usage_array[i].aname);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: we used to make options bold with B<> and output an example too:
|
||||
|
||||
=item B<cat>
|
||||
|
||||
cat [B<-u>] [FILE]...
|
||||
|
||||
Concatenate FILE(s) and print them to stdout
|
||||
|
||||
Options:
|
||||
-u Use unbuffered i/o (ignored)
|
||||
|
||||
Example:
|
||||
$ cat /proc/uptime
|
||||
110716.72 17.67
|
||||
|
||||
*/
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/bin/sh
|
||||
MIMFILE="Mimfile"
|
||||
if [ $# -ge 2 ] && [ "$1" = "-f" ]
|
||||
then
|
||||
MIMFILE="$2"
|
||||
shift 2
|
||||
fi
|
||||
exec <"$MIMFILE" || exit 1
|
||||
{
|
||||
INCASE=false
|
||||
while read -r REPLY
|
||||
do
|
||||
case $REPLY in
|
||||
*:)
|
||||
if ! $INCASE
|
||||
then
|
||||
printf '[ $# -eq 0 ] && set -- "%s"
|
||||
TARGET="$1"
|
||||
shift
|
||||
case "$TARGET" in
|
||||
' "${REPLY%:}"
|
||||
else
|
||||
printf ';;\n'
|
||||
fi
|
||||
printf '%s)\n' "${REPLY%:}"
|
||||
INCASE=true
|
||||
;;
|
||||
"") ;;
|
||||
*) printf '%s\n' "${REPLY##[ ]}";;
|
||||
esac
|
||||
done
|
||||
$INCASE && printf ';;\n'
|
||||
printf '*)
|
||||
echo "Unknown command $TARGET"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
'
|
||||
} | sh -s "$@"
|
||||
@@ -1,3 +0,0 @@
|
||||
cat /etc/nologin.txt 2>/dev/null || echo This account is not available
|
||||
sleep 5
|
||||
exit 1
|
||||
+1
-15
@@ -2,20 +2,6 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
# Allow i486 insns (basically, bswap insn)
|
||||
# Do not try to tune for 486+ (might add padding)
|
||||
CFLAGS += $(call cc-option,-march=i486 -mtune=i386,)
|
||||
|
||||
ifeq ($(CONFIG_STACK_OPTIMIZATION_386),y)
|
||||
# -mpreferred-stack-boundary=2 is essential in preventing gcc 4.2.x
|
||||
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
|
||||
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,)
|
||||
endif
|
||||
|
||||
# "Control how GCC aligns variables.
|
||||
# Supported values for type are compat uses increased alignment value
|
||||
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
|
||||
# and cacheline uses increased alignment value to match the cache line size.
|
||||
# compat is the default."
|
||||
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
|
||||
CFLAGS += $(call cc-option,-malign-data=abi,)
|
||||
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
@@ -1,11 +0,0 @@
|
||||
# When building a library, even intra-library references,
|
||||
# such as from find_applet_by_name() to applet_names[],
|
||||
# don't work with -fpic on sparc, needs -fPIC.
|
||||
# Don't know why it fails in this case but works when
|
||||
# a binary is being built.
|
||||
#
|
||||
# (if is superfluous, ARCH_FPIC is only used by library build, but it
|
||||
# demonstrates the point: non-pic binary does not need it)
|
||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||
ARCH_FPIC = -fPIC
|
||||
endif
|
||||
@@ -1,11 +0,0 @@
|
||||
# When building a library, even intra-library references,
|
||||
# such as from find_applet_by_name() to applet_names[],
|
||||
# don't work with -fpic on sparc, needs -fPIC.
|
||||
# Don't know why it fails in this case but works when
|
||||
# a binary is being built.
|
||||
#
|
||||
# (if is superfluous, ARCH_FPIC is only used by library build, but it
|
||||
# demonstrates the point: non-pic binary does not need it)
|
||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||
ARCH_FPIC = -fPIC
|
||||
endif
|
||||
@@ -1,11 +0,0 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
# "Control how GCC aligns variables.
|
||||
# Supported values for type are compat uses increased alignment value
|
||||
# compatible uses GCC 4.8 and earlier, abi uses alignment value as specified by the psABI,
|
||||
# and cacheline uses increased alignment value to match the cache line size.
|
||||
# compat is the default."
|
||||
# "abi" seems to be somewhat successful in preventing oversealous data alignment.
|
||||
CFLAGS += $(call cc-option,-malign-data=abi,)
|
||||
@@ -0,0 +1,343 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
config AR
|
||||
bool "ar"
|
||||
default n
|
||||
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 need for debs)"
|
||||
default n
|
||||
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 BUNZIP2
|
||||
bool "bunzip2"
|
||||
default n
|
||||
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 n
|
||||
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 n
|
||||
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 DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
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
|
||||
help
|
||||
dpkg-deb packs, 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, you should
|
||||
probably 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 n
|
||||
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 FEATURE_GUNZIP_UNCOMPRESS
|
||||
bool "Uncompress support"
|
||||
default n
|
||||
depends on GUNZIP
|
||||
help
|
||||
Enable if you want gunzip to have the ability to decompress
|
||||
archives created by the program compress (not much
|
||||
used anymore).
|
||||
|
||||
config GZIP
|
||||
bool "gzip"
|
||||
default n
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default n
|
||||
help
|
||||
Converts an RPM file into a CPIO archive.
|
||||
|
||||
config RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
config FEATURE_RPM_BZ2
|
||||
bool "Enable handling of rpms with bzip2-compressed data inside"
|
||||
default n
|
||||
depends on RPM
|
||||
help
|
||||
Enable handling of rpms with bzip2-compressed data inside.
|
||||
|
||||
config TAR
|
||||
bool "tar"
|
||||
default n
|
||||
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_GZIP
|
||||
bool "Enable -z option"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call gzip,
|
||||
when creating or extracting tar gziped archives.
|
||||
|
||||
config FEATURE_TAR_BZIP2
|
||||
bool "Enable -j option to handle .tar.bz2 files"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with bzip2.
|
||||
|
||||
config FEATURE_TAR_LZMA
|
||||
bool "Enable -a option to handle .tar.lzma files"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with lzma.
|
||||
|
||||
config FEATURE_TAR_COMPRESS
|
||||
bool "Enable -Z option"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call uncompress,
|
||||
when extracting .tar.Z archives.
|
||||
|
||||
config FEATURE_TAR_AUTODETECT
|
||||
bool "Let tar autodetect gz/bz2 compresses tarballs"
|
||||
default n
|
||||
depends on FEATURE_TAR_GZIP || FEATURE_TAR_BZIP2
|
||||
help
|
||||
With this option tar can automatically detect gzip/bzip2 compressed
|
||||
tarballs. Currently it works only on seekable streams.
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
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 N
|
||||
depends on TAR
|
||||
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 N
|
||||
depends on TAR
|
||||
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
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on TAR && GETOPT_LONG
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config FEATURE_TAR_UNAME_GNAME
|
||||
bool "Enable use of user and group names"
|
||||
default n
|
||||
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 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 n
|
||||
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 de-compression only.
|
||||
On an x86 system, this applet adds about 4K.
|
||||
|
||||
Unless you have a specific application which requires unlzma, you
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimze unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 33% at the cost of
|
||||
a 2K bigger binary.
|
||||
|
||||
config UNZIP
|
||||
bool "unzip"
|
||||
default n
|
||||
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.
|
||||
|
||||
comment "Common options for cpio and tar"
|
||||
depends on CPIO || TAR
|
||||
|
||||
config FEATURE_UNARCHIVE_TAPE
|
||||
bool "Enable tape drive support"
|
||||
default n
|
||||
depends on CPIO || TAR
|
||||
help
|
||||
I don't think this is needed anymore.
|
||||
|
||||
comment "Common options for dpkg and dpkg_deb"
|
||||
depends on DPKG || DPKG_DEB
|
||||
|
||||
config FEATURE_DEB_TAR_GZ
|
||||
bool "gzip debian packages (normal)"
|
||||
default y if DPKG || DPKG_DEB
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This is the default compression method inside the debian ar file.
|
||||
|
||||
If you want compatibility with standard .deb's you should say yes here.
|
||||
|
||||
config FEATURE_DEB_TAR_BZ2
|
||||
bool "bzip2 debian packages"
|
||||
default n
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
|
||||
with bzip2 instead of gzip.
|
||||
|
||||
You only want this if you are creating your own custom debian packages that
|
||||
use an internal control.tar.bz2 or data.tar.bz2.
|
||||
|
||||
config FEATURE_DEB_TAR_LZMA
|
||||
bool "lzma debian packages"
|
||||
default n
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed
|
||||
internally with lzma instead of gzip.
|
||||
|
||||
You only want this if you are creating your own custom debian
|
||||
packages that use an internal control.tar.lzma or data.tar.lzma.
|
||||
|
||||
endmenu
|
||||
@@ -1,49 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
#
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
config FEATURE_SEAMLESS_XZ
|
||||
bool "Make tar, rpm, modprobe etc understand .xz data"
|
||||
default y
|
||||
|
||||
config FEATURE_SEAMLESS_LZMA
|
||||
bool "Make tar, rpm, modprobe etc understand .lzma data"
|
||||
default y
|
||||
|
||||
config FEATURE_SEAMLESS_BZ2
|
||||
bool "Make tar, rpm, modprobe etc understand .bz2 data"
|
||||
default y
|
||||
|
||||
config FEATURE_SEAMLESS_GZ
|
||||
bool "Make tar, rpm, modprobe etc understand .gz data"
|
||||
default y
|
||||
|
||||
config FEATURE_SEAMLESS_Z
|
||||
bool "Make tar, rpm, modprobe etc understand .Z data"
|
||||
default n # it is ancient
|
||||
|
||||
INSERT
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimize lzma for speed"
|
||||
default n
|
||||
depends on UNLZMA || LZCAT || LZMA || FEATURE_SEAMLESS_LZMA
|
||||
help
|
||||
This option reduces decompression time by about 25% at the cost of
|
||||
a 1K bigger binary.
|
||||
|
||||
config FEATURE_PATH_TRAVERSAL_PROTECTION
|
||||
bool "Prevent extraction of filenames with /../ path component"
|
||||
default n
|
||||
help
|
||||
busybox tar and unzip remove "PREFIX/../" (if it exists)
|
||||
from extracted names.
|
||||
This option enables this behavior for all other unpacking applets,
|
||||
such as cpio, ar, rpm.
|
||||
GNU cpio 2.15 has NO such sanity check.
|
||||
# try other archivers and document their behavior?
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,23 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
libs-y += libunarchive/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
@@ -1,11 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
libs-y += libarchive/
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
+47
-254
@@ -6,297 +6,90 @@
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
* Archive creation support:
|
||||
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
|
||||
* Written by Alexander Shishkin.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* There is no single standard to adhere to so ar may not portable
|
||||
* between different systems
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
//config:config AR
|
||||
//config: bool "ar (9.5 kb)"
|
||||
//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. In practice, it is used exclusively
|
||||
//config: for object module archives used by compilers.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires ar, you should
|
||||
//config: probably say N here: most compilers come with their own ar utility.
|
||||
//config:
|
||||
//config:config FEATURE_AR_LONG_FILENAMES
|
||||
//config: bool "Support 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
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "ar_.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#if ENABLE_FEATURE_AR_CREATE
|
||||
/* filter out entries with same names as specified on the command line */
|
||||
static char FAST_FUNC filter_replaceable(archive_handle_t *handle)
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
if (find_list_entry(handle->accept, handle->file_header->name))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void output_ar_header(archive_handle_t *handle)
|
||||
{
|
||||
/* GNU ar 2.19.51.0.14 creates malformed archives
|
||||
* if input files are >10G. It also truncates files >4GB
|
||||
* (uses "size mod 4G"). We abort in this case:
|
||||
* We could add support for up to 10G files, but this is unlikely to be useful.
|
||||
* Note that unpacking side limits all fields to "unsigned int" data type,
|
||||
* and treats "all ones" as an error indicator. Thus max we allow here is UINT_MAX-1.
|
||||
*/
|
||||
enum {
|
||||
/* for 2nd field: mtime */
|
||||
MAX11CHARS = UINT_MAX > 0xffffffff ? (unsigned)99999999999 : UINT_MAX-1,
|
||||
/* for last field: filesize */
|
||||
MAX10CHARS = UINT_MAX > 0xffffffff ? (unsigned)9999999999 : UINT_MAX-1,
|
||||
};
|
||||
|
||||
struct file_header_t *fh = handle->file_header;
|
||||
|
||||
if (handle->offset & 1) {
|
||||
xwrite(handle->src_fd, "\n", 1);
|
||||
handle->offset++;
|
||||
}
|
||||
|
||||
/* Careful! The widths should be exact. Fields must be separated */
|
||||
if (sizeof(off_t) > 4 && fh->size > (off_t)MAX10CHARS) {
|
||||
bb_error_msg_and_die("'%s' is bigger than ar can handle", fh->name);
|
||||
}
|
||||
fdprintf(handle->src_fd, "%-16.16s%-12lu%-6u%-6u%-8o%-10"OFF_FMT"u`\n",
|
||||
fh->name,
|
||||
(sizeof(time_t) > 4 && fh->mtime > MAX11CHARS) ? (long)0 : (long)fh->mtime,
|
||||
fh->uid > 99999 ? 0 : (int)fh->uid,
|
||||
fh->gid > 99999 ? 0 : (int)fh->gid,
|
||||
(int)fh->mode & 07777777,
|
||||
fh->size
|
||||
);
|
||||
|
||||
handle->offset += AR_HEADER_LEN;
|
||||
}
|
||||
|
||||
/*
|
||||
* when replacing files in an existing archive, copy from the
|
||||
* original archive those files that are to be left intact
|
||||
*/
|
||||
static void FAST_FUNC copy_data(archive_handle_t *handle)
|
||||
{
|
||||
archive_handle_t *out_handle = handle->ar__out;
|
||||
struct file_header_t *fh = handle->file_header;
|
||||
|
||||
out_handle->file_header = fh;
|
||||
output_ar_header(out_handle);
|
||||
|
||||
bb_copyfd_exact_size(handle->src_fd, out_handle->src_fd, fh->size);
|
||||
out_handle->offset += fh->size;
|
||||
}
|
||||
|
||||
static int write_ar_header(archive_handle_t *handle)
|
||||
{
|
||||
char *fn;
|
||||
char fn_h[17]; /* 15 + "/" + NUL */
|
||||
struct stat st;
|
||||
int fd;
|
||||
|
||||
fn = llist_pop(&handle->accept);
|
||||
if (!fn)
|
||||
return -1;
|
||||
|
||||
xstat(fn, &st);
|
||||
|
||||
handle->file_header->mtime = st.st_mtime;
|
||||
handle->file_header->uid = st.st_uid;
|
||||
handle->file_header->gid = st.st_gid;
|
||||
handle->file_header->mode = st.st_mode;
|
||||
handle->file_header->size = st.st_size;
|
||||
handle->file_header->name = fn_h;
|
||||
//TODO: if ENABLE_FEATURE_AR_LONG_FILENAMES...
|
||||
sprintf(fn_h, "%.15s/", bb_basename(fn));
|
||||
|
||||
output_ar_header(handle);
|
||||
|
||||
fd = xopen(fn, O_RDONLY);
|
||||
bb_copyfd_exact_size(fd, handle->src_fd, st.st_size);
|
||||
close(fd);
|
||||
handle->offset += st.st_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_ar_archive(archive_handle_t *handle)
|
||||
{
|
||||
off_t st_size;
|
||||
archive_handle_t *out_handle;
|
||||
|
||||
st_size = xfstat_size(handle->src_fd, handle->ar__name);
|
||||
|
||||
/* if archive exists, create a new handle for output.
|
||||
* we create it in place of the old one.
|
||||
*/
|
||||
if (st_size != 0) {
|
||||
out_handle = init_handle();
|
||||
xunlink(handle->ar__name);
|
||||
out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
out_handle->accept = handle->accept;
|
||||
} else {
|
||||
out_handle = handle;
|
||||
}
|
||||
|
||||
handle->ar__out = out_handle;
|
||||
|
||||
xwrite(out_handle->src_fd, AR_MAGIC "\n", AR_MAGIC_LEN + 1);
|
||||
out_handle->offset += AR_MAGIC_LEN + 1;
|
||||
|
||||
/* skip to the end of the archive if we have to append stuff */
|
||||
if (st_size != 0) {
|
||||
handle->filter = filter_replaceable;
|
||||
handle->action_data = copy_data;
|
||||
unpack_ar_archive(handle);
|
||||
}
|
||||
|
||||
while (write_ar_header(out_handle) == 0)
|
||||
continue;
|
||||
|
||||
/* optional, since we exit right after we return */
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(handle->src_fd);
|
||||
if (out_handle->src_fd != handle->src_fd)
|
||||
close(out_handle->src_fd);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif /* FEATURE_AR_CREATE */
|
||||
|
||||
static void FAST_FUNC header_verbose_list_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
const file_header_t *file_header = archive_handle->file_header;
|
||||
char mode[12];
|
||||
const char *mode = bb_mode_string(file_header->mode);
|
||||
char *mtime;
|
||||
|
||||
bb_mode_string(mode, file_header->mode);
|
||||
mtime = ctime(&file_header->mtime);
|
||||
mtime[16] = ' ';
|
||||
memmove(&mtime[17], &mtime[20], 4);
|
||||
mtime[21] = '\0';
|
||||
printf("%s %u/%u%7"OFF_FMT"u %s %s\n", &mode[1],
|
||||
(int)file_header->uid, (int)file_header->gid,
|
||||
file_header->size,
|
||||
&mtime[4], file_header->name
|
||||
);
|
||||
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid,
|
||||
(int) file_header->size, &mtime[4], file_header->name);
|
||||
}
|
||||
|
||||
//usage:#define ar_trivial_usage
|
||||
//usage: "x|p|t"IF_FEATURE_AR_CREATE("|r")" [-ov] ARCHIVE [FILE]..."
|
||||
//usage:#define ar_full_usage "\n\n"
|
||||
//usage: "Extract or list FILEs from an ar archive"IF_FEATURE_AR_CREATE(", or create it")"\n"
|
||||
//usage: "\n x Extract"
|
||||
//usage: "\n p Extract to stdout"
|
||||
//usage: "\n t List"
|
||||
//usage: IF_FEATURE_AR_CREATE(
|
||||
//usage: "\n r Create"
|
||||
//usage: )
|
||||
//usage: "\n -o Restore mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
#define AR_CTX_PRINT 0x01
|
||||
#define AR_CTX_LIST 0x02
|
||||
#define AR_CTX_EXTRACT 0x04
|
||||
#define AR_OPT_PRESERVE_DATE 0x08
|
||||
#define AR_OPT_VERBOSE 0x10
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
static const char msg_unsupported_err[] ALIGN1 =
|
||||
"archive %s is not supported";
|
||||
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned opt, t;
|
||||
enum {
|
||||
OPT_VERBOSE = (1 << 0),
|
||||
OPT_PRESERVE_DATE = (1 << 1),
|
||||
/* "ar r" implies create, but warns about it. c suppresses warning.
|
||||
* bbox accepts but ignores it: */
|
||||
OPT_CREATE = (1 << 2),
|
||||
CMD_PRINT = (1 << 3),
|
||||
FIRST_CMD = CMD_PRINT,
|
||||
CMD_LIST = (1 << 4),
|
||||
CMD_EXTRACT = (1 << 5),
|
||||
CMD_INSERT = ((1 << 6) * ENABLE_FEATURE_AR_CREATE),
|
||||
};
|
||||
unsigned opt;
|
||||
char magic[8];
|
||||
|
||||
archive_handle = init_handle();
|
||||
|
||||
/* prepend '-' to the first argument if required */
|
||||
if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0')
|
||||
argv[1] = xasprintf("-%s", argv[1]);
|
||||
opt = getopt32(argv, "^"
|
||||
"voc""ptx"IF_FEATURE_AR_CREATE("r")
|
||||
"\0"
|
||||
/* -1: at least one arg is reqd */
|
||||
/* one of p,t,x[,r] is required */
|
||||
"-1:p:t:x"IF_FEATURE_AR_CREATE(":r")
|
||||
);
|
||||
argv += optind;
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argv, "ptxovcr");
|
||||
|
||||
t = opt / FIRST_CMD;
|
||||
if (t & (t-1)) /* more than one of p,t,x[,r] are specified */
|
||||
bb_show_usage();
|
||||
|
||||
if (opt & CMD_PRINT) {
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & CMD_LIST) {
|
||||
if (opt & AR_CTX_LIST) {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & CMD_EXTRACT) {
|
||||
if (opt & AR_CTX_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & OPT_PRESERVE_DATE) {
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
if (opt & OPT_VERBOSE) {
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
}
|
||||
#if ENABLE_FEATURE_AR_CREATE
|
||||
archive_handle->ar__name = *argv;
|
||||
#endif
|
||||
archive_handle->src_fd = xopen(*argv++,
|
||||
(opt & CMD_INSERT)
|
||||
? O_RDWR | O_CREAT
|
||||
: O_RDONLY
|
||||
);
|
||||
|
||||
if (*argv)
|
||||
archive_handle->filter = filter_accept_list;
|
||||
while (*argv) {
|
||||
llist_add_to_end(&archive_handle->accept, *argv++);
|
||||
if (opt & AR_OPT_CREATE) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "creation");
|
||||
}
|
||||
if (opt & AR_OPT_INSERT) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_AR_CREATE
|
||||
if (opt & CMD_INSERT)
|
||||
return write_ar_archive(archive_handle);
|
||||
#endif
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
unpack_ar_archive(archive_handle);
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind++]);
|
||||
}
|
||||
|
||||
xread(archive_handle->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+169
-424
@@ -1,25 +1,21 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Common code for gunzip-like applets
|
||||
* Common code for gunzip-like applets
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
|
||||
/* lzop_main() uses bbunpack(), need this: */
|
||||
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
|
||||
/* bzip2_main() too: */
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
/* gzip_main() too: */
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
OPT_STDOUT = 0x1,
|
||||
OPT_FORCE = 0x2,
|
||||
/* gunzip and bunzip2 only: */
|
||||
OPT_VERBOSE = 0x4,
|
||||
OPT_DECOMPRESS = 0x8,
|
||||
OPT_TEST = 0x10,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
@@ -32,22 +28,15 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
||||
{
|
||||
return xasprintf("%s.%s", filename, expected_ext);
|
||||
}
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
int bbunpack(char **argv,
|
||||
char* (*make_new_name)(char *filename),
|
||||
USE_DESKTOP(long long) int (*unpacker)(void)
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_state_t xstate;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -59,52 +48,31 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (!(option_mask32 & BBUNPK_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 */
|
||||
/* die_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*die_if_not_compressed:*/ 1);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
} else
|
||||
if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*die_if_not_compressed*/ 1))
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Special cases: test, stdout */
|
||||
if (option_mask32 & (BBUNPK_OPT_STDOUT|BBUNPK_OPT_TEST)) {
|
||||
if (option_mask32 & BBUNPK_OPT_TEST)
|
||||
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;
|
||||
}
|
||||
|
||||
/* Open dst if we are going to unpack to file */
|
||||
if (filename) {
|
||||
new_name = make_new_name(filename, expected_ext);
|
||||
new_name = make_new_name(filename);
|
||||
if (!new_name) {
|
||||
bb_error_msg("%s: unknown suffix - ignored", filename);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* -f: overwrite existing output files */
|
||||
if (option_mask32 & BBUNPK_OPT_FORCE) {
|
||||
unlink(new_name);
|
||||
}
|
||||
|
||||
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
|
||||
/* GNU gunzip does not bail out, but goes to next file */
|
||||
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
@@ -113,91 +81,48 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
bb_simple_error_msg_and_die("compressed data not read from terminal, "
|
||||
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 & BBUNPK_SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
/*xstate.signature_skipped = 0; - already is */
|
||||
/*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();
|
||||
}
|
||||
|
||||
if (!(option_mask32 & BBUNPK_OPT_STDOUT))
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
status = unpacker();
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
|
||||
if (status >= 0) {
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (xstate.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
* then closing resets the mtime
|
||||
* back to current time. */
|
||||
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 & BBUNPK_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 */
|
||||
/* TODO: restore user/group/times here? */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
|
||||
del = NULL;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
if (del)
|
||||
xunlink(del);
|
||||
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);
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
if (option_mask32 & BBUNPK_OPT_STDOUT)
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
#if ENABLE_UNCOMPRESS \
|
||||
|| ENABLE_FEATURE_BZIP2_DECOMPRESS \
|
||||
|| ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
|
||||
|| ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
|
||||
#if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
char* make_new_name_generic(char *filename, const char *expected_ext)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension + 1, expected_ext) != 0) {
|
||||
@@ -208,48 +133,42 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
*extension = '\0';
|
||||
return filename;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
* Modified for busybox by Glenn McGrath
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
//usage:#define uncompress_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define uncompress_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Overwrite"
|
||||
|
||||
//config:config UNCOMPRESS
|
||||
//config: bool "uncompress (7.1 kb)"
|
||||
//config: default n # ancient
|
||||
//config: help
|
||||
//config: uncompress is used to decompress archives created by compress.
|
||||
//config: Not much used anymore, replaced by gzip/gunzip.
|
||||
#if ENABLE_BUNZIP2
|
||||
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
static
|
||||
char* make_new_name_bunzip2(char *filename)
|
||||
{
|
||||
// (N)compress 4.2.4.4:
|
||||
// -d If given, decompression is done instead
|
||||
// -c Write output on stdout, don't remove original
|
||||
// -b Parameter limits the max number of bits/code
|
||||
// -f Forces output file to be generated
|
||||
// -v Write compression statistics
|
||||
// -V Output vesion and compile options
|
||||
// -r Recursive. If a filename is a directory, descend into it and compress everything
|
||||
getopt32(argv, "cf");
|
||||
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
|
||||
return make_new_name_generic(filename, "bz2");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
{
|
||||
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -268,7 +187,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -276,55 +195,15 @@ 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: "[-cfkt] [FILE]..."
|
||||
//usage:#define gunzip_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define gunzip_example_usage
|
||||
//usage: "$ ls -la /tmp/BusyBox*\n"
|
||||
//usage: "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n"
|
||||
//usage: "$ gunzip /tmp/BusyBox-0.43.tar.gz\n"
|
||||
//usage: "$ ls -la /tmp/BusyBox*\n"
|
||||
//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:#define zcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config GUNZIP
|
||||
//config: bool "gunzip (11 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_GZIP_DECOMPRESS
|
||||
//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.
|
||||
//config:
|
||||
//config:config ZCAT
|
||||
//config: bool "zcat (24 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_GZIP_DECOMPRESS
|
||||
//config: help
|
||||
//config: Alias to "gunzip -c".
|
||||
//config:
|
||||
//config:config FEATURE_GUNZIP_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on (GUNZIP || ZCAT) && LONG_OPTS
|
||||
#if ENABLE_GUNZIP
|
||||
|
||||
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
|
||||
#if ENABLE_FEATURE_GZIP_DECOMPRESS
|
||||
static
|
||||
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
char* make_new_name_gunzip(char *filename)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
|
||||
@@ -333,8 +212,8 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
|
||||
extension++;
|
||||
if (strcmp(extension, "tgz" + 1) == 0
|
||||
#if ENABLE_FEATURE_SEAMLESS_Z
|
||||
|| (extension[0] == 'Z' && extension[1] == '\0')
|
||||
#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|| strcmp(extension, "Z") == 0
|
||||
#endif
|
||||
) {
|
||||
extension[-1] = '\0';
|
||||
@@ -349,106 +228,46 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
return filename;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
static const char gunzip_longopts[] ALIGN1 =
|
||||
"stdout\0" No_argument "c"
|
||||
"to-stdout\0" No_argument "c"
|
||||
"force\0" No_argument "f"
|
||||
"test\0" No_argument "t"
|
||||
"no-name\0" No_argument "n"
|
||||
;
|
||||
#endif
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(STDIN_FILENO) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(STDIN_FILENO);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
} else {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
/* status is still == -1 */
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
* -n --no-name
|
||||
* gzip: do not save the original file name and time stamp.
|
||||
* (The original name is always saved if the name had to be truncated.)
|
||||
* gunzip: do not restore the original file name/time even if present
|
||||
* (remove only the gzip suffix from the compressed file name).
|
||||
* This option is the default when decompressing.
|
||||
* -N --name
|
||||
* gzip: always save the original file name and time stamp (this is the default)
|
||||
* gunzip: restore the original file name and time stamp if present.
|
||||
*/
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
int gunzip_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts);
|
||||
#else
|
||||
getopt32(argv, BBUNPK_OPTSTR "dtn");
|
||||
#endif
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
/* If called as zcat...
|
||||
* Normally, "zcat" is just "gunzip -c".
|
||||
* But if seamless magic is enabled, then we are much more clever.
|
||||
*/
|
||||
if (ENABLE_ZCAT && applet_name[1] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
return bbunpack(argv, make_new_name_gunzip, unpack_gunzip);
|
||||
}
|
||||
#endif /* FEATURE_GZIP_DECOMPRESS */
|
||||
|
||||
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//usage:#define bunzip2_trivial_usage
|
||||
//usage: "[-cfk] [FILE]..."
|
||||
//usage:#define bunzip2_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define bzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define bzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config BUNZIP2
|
||||
//config: bool "bunzip2 (9.1 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_BZIP2_DECOMPRESS
|
||||
//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.
|
||||
//config:
|
||||
//config:config BZCAT
|
||||
//config: bool "bzcat (9 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_BZIP2_DECOMPRESS
|
||||
//config: help
|
||||
//config: Alias to "bunzip2 -c".
|
||||
|
||||
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
|
||||
#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 || ENABLE_BZCAT
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
argv += optind;
|
||||
if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -458,146 +277,72 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
//usage:#define unlzma_trivial_usage
|
||||
//usage: "[-cfk] [FILE]..."
|
||||
//usage:#define unlzma_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define lzma_trivial_usage
|
||||
//usage: "-d [-cfk] [FILE]..."
|
||||
//usage:#define lzma_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define lzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define lzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNLZMA
|
||||
//config: bool "unlzma (7.8 kb)"
|
||||
//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:config LZCAT
|
||||
//config: bool "lzcat (7.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Alias to "unlzma -c".
|
||||
//config:
|
||||
//config:config LZMA
|
||||
//config: bool "lzma -d"
|
||||
//config: default y
|
||||
//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.
|
||||
#if ENABLE_UNLZMA
|
||||
|
||||
static
|
||||
char* make_new_name_unlzma(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "lzma");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
{
|
||||
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
//applet:IF_LZCAT(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
|
||||
//kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_LZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
int unlzma_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* lzcat? */
|
||||
if (ENABLE_LZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
/* lzmacat? */
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_unlzma, unpack_unlzma);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//usage:#define unxz_trivial_usage
|
||||
//usage: "[-cfk] [FILE]..."
|
||||
//usage:#define unxz_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define xz_trivial_usage
|
||||
//usage: "-d [-cfk] [FILE]..."
|
||||
//usage:#define xz_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage:
|
||||
//usage:#define xzcat_trivial_usage
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define xzcat_full_usage "\n\n"
|
||||
//usage: "Decompress to stdout"
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
//config:config UNXZ
|
||||
//config: bool "unxz (13 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unxz is a unlzma successor.
|
||||
//config:
|
||||
//config:config XZCAT
|
||||
//config: bool "xzcat (13 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Alias to "unxz -c".
|
||||
//config:
|
||||
//config:config XZ
|
||||
//config: bool "xz -d"
|
||||
//config: default y
|
||||
//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.
|
||||
#if ENABLE_UNCOMPRESS
|
||||
|
||||
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
//applet:IF_XZCAT(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
|
||||
//kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_XZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
static
|
||||
char* make_new_name_uncompress(char *filename)
|
||||
{
|
||||
IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* xzcat? */
|
||||
if (ENABLE_XZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
return make_new_name_generic(filename, "Z");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
|
||||
bb_error_msg("invalid magic");
|
||||
} else {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);
|
||||
}
|
||||
|
||||
#endif
|
||||
File renamed without changes.
@@ -1,4 +1,4 @@
|
||||
This file is an abridged version of README from bzip2 1.0.4
|
||||
This file is an abridged version of README from bizp2 1.0.4
|
||||
Build instructions (which are not relevant to busyboxed bzip2)
|
||||
are removed.
|
||||
===========================================================
|
||||
@@ -107,14 +107,15 @@ void fallbackSimpleSort(uint32_t* fmap,
|
||||
#define FALLBACK_QSORT_SMALL_THRESH 10
|
||||
#define FALLBACK_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
static
|
||||
void fallbackQSort3(uint32_t* fmap,
|
||||
uint32_t* eclass,
|
||||
int32_t loSt,
|
||||
int32_t hiSt)
|
||||
{
|
||||
int32_t sp;
|
||||
uint32_t r;
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m;
|
||||
int32_t sp, lo, hi;
|
||||
uint32_t med, r, r3;
|
||||
int32_t stackLo[FALLBACK_QSORT_STACK_SIZE];
|
||||
int32_t stackHi[FALLBACK_QSORT_STACK_SIZE];
|
||||
|
||||
@@ -124,11 +125,6 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
fpush(loSt, hiSt);
|
||||
|
||||
while (sp > 0) {
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m;
|
||||
int32_t lo, hi;
|
||||
uint32_t med;
|
||||
uint32_t r3;
|
||||
|
||||
AssertH(sp < FALLBACK_QSORT_STACK_SIZE - 1, 1004);
|
||||
|
||||
fpop(lo, hi);
|
||||
@@ -165,7 +161,7 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
ltLo++;
|
||||
unLo++;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
}
|
||||
@@ -176,7 +172,7 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
mswap(fmap[unHi], fmap[gtHi]);
|
||||
gtHi--; unHi--;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
}
|
||||
@@ -231,19 +227,17 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
#define UNALIGNED_BH(zz) ((zz) & 0x01f)
|
||||
|
||||
static
|
||||
void fallbackSort(EState* state)
|
||||
void fallbackSort(uint32_t* fmap,
|
||||
uint32_t* eclass,
|
||||
uint32_t* bhtab,
|
||||
int32_t nblock)
|
||||
{
|
||||
int32_t ftab[257];
|
||||
int32_t ftabCopy[256];
|
||||
int32_t H, i, j, k, l, r, cc, cc1;
|
||||
int32_t nNotDone;
|
||||
int32_t nBhtab;
|
||||
/* params */
|
||||
uint32_t *const fmap = state->arr1;
|
||||
uint32_t *const eclass = state->arr2;
|
||||
#define eclass8 ((uint8_t*)eclass)
|
||||
uint32_t *const bhtab = state->ftab;
|
||||
const int32_t nblock = state->nblock;
|
||||
uint8_t* eclass8 = (uint8_t*)eclass;
|
||||
|
||||
/*
|
||||
* Initial 1-char radix sort to generate
|
||||
@@ -332,7 +326,7 @@ void fallbackSort(EState* state)
|
||||
if (cc != cc1) {
|
||||
SET_BH(i);
|
||||
cc = cc1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,7 +349,6 @@ void fallbackSort(EState* state)
|
||||
eclass8[fmap[i]] = (uint8_t)j;
|
||||
}
|
||||
AssertH(j < 256, 1005);
|
||||
#undef eclass8
|
||||
}
|
||||
|
||||
#undef SET_BH
|
||||
@@ -374,25 +367,25 @@ void fallbackSort(EState* state)
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
NOINLINE
|
||||
int mainGtU(EState* state,
|
||||
int mainGtU(
|
||||
uint32_t i1,
|
||||
uint32_t i2)
|
||||
uint32_t i2,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
uint32_t nblock,
|
||||
int32_t* budget)
|
||||
{
|
||||
int32_t k;
|
||||
uint8_t c1, c2;
|
||||
uint16_t s1, s2;
|
||||
|
||||
uint8_t *const block = state->block;
|
||||
uint16_t *const quadrant = state->quadrant;
|
||||
const int32_t nblock = state->nblock;
|
||||
|
||||
/* Loop unrolling here is actually very useful
|
||||
* (generated code is much simpler),
|
||||
* code size increase is only 270 bytes (i386)
|
||||
* but speeds up compression 10% overall
|
||||
*/
|
||||
|
||||
#if BZIP2_SPEED >= 1
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 1
|
||||
|
||||
#define TIMES_8(code) \
|
||||
code; code; code; code; \
|
||||
@@ -442,7 +435,7 @@ int mainGtU(EState* state,
|
||||
if (i1 >= nblock) i1 -= nblock;
|
||||
if (i2 >= nblock) i2 -= nblock;
|
||||
|
||||
state->budget--;
|
||||
(*budget)--;
|
||||
k -= 8;
|
||||
} while (k >= 0);
|
||||
|
||||
@@ -459,45 +452,42 @@ int mainGtU(EState* state,
|
||||
* usually small, typically <= 20.
|
||||
*/
|
||||
static
|
||||
const uint32_t incs[14] ALIGN4 = {
|
||||
const int32_t incs[14] = {
|
||||
1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
9841, 29524, 88573, 265720,
|
||||
797161, 2391484
|
||||
};
|
||||
|
||||
static
|
||||
void mainSimpleSort(EState* state,
|
||||
void mainSimpleSort(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
int32_t nblock,
|
||||
int32_t lo,
|
||||
int32_t hi,
|
||||
int32_t d)
|
||||
int32_t d,
|
||||
int32_t* budget)
|
||||
{
|
||||
uint32_t *const ptr = state->ptr;
|
||||
int32_t i, j, h, bigN, hp;
|
||||
uint32_t v;
|
||||
|
||||
/* At which increment to start? */
|
||||
int hp = 0;
|
||||
{
|
||||
int bigN = hi - lo;
|
||||
if (bigN <= 0)
|
||||
return;
|
||||
while (incs[hp] <= bigN)
|
||||
hp++;
|
||||
hp--;
|
||||
}
|
||||
bigN = hi - lo + 1;
|
||||
if (bigN < 2) return;
|
||||
|
||||
hp = 0;
|
||||
while (incs[hp] < bigN) hp++;
|
||||
hp--;
|
||||
|
||||
for (; hp >= 0; hp--) {
|
||||
int32_t i;
|
||||
unsigned h;
|
||||
|
||||
h = incs[hp];
|
||||
|
||||
i = lo + h;
|
||||
while (1) {
|
||||
unsigned j;
|
||||
unsigned v;
|
||||
|
||||
/*-- copy 1 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
@@ -506,23 +496,24 @@ void mainSimpleSort(EState* state,
|
||||
i++;
|
||||
|
||||
/* 1.5% overall speedup, +290 bytes */
|
||||
#if BZIP2_SPEED >= 3
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 3
|
||||
/*-- copy 2 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
}
|
||||
ptr[j] = v;
|
||||
i++;
|
||||
|
||||
/*-- copy 3 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
@@ -530,7 +521,7 @@ void mainSimpleSort(EState* state,
|
||||
ptr[j] = v;
|
||||
i++;
|
||||
#endif
|
||||
if (state->budget < 0) return;
|
||||
if (*budget < 0) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -554,7 +545,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
};
|
||||
/* here b >= a */
|
||||
if (b > c) {
|
||||
b = c;
|
||||
@@ -594,13 +585,16 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
|
||||
#define MAIN_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
void mainQSort3(EState* state,
|
||||
static
|
||||
void mainQSort3(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
int32_t nblock,
|
||||
int32_t loSt,
|
||||
int32_t hiSt
|
||||
/*int32_t dSt*/)
|
||||
int32_t hiSt,
|
||||
int32_t dSt,
|
||||
int32_t* budget)
|
||||
{
|
||||
enum { dSt = BZ_N_RADIX };
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m, med;
|
||||
int32_t sp, lo, hi, d;
|
||||
|
||||
@@ -612,9 +606,6 @@ void mainQSort3(EState* state,
|
||||
int32_t nextHi[3];
|
||||
int32_t nextD [3];
|
||||
|
||||
uint32_t *const ptr = state->ptr;
|
||||
uint8_t *const block = state->block;
|
||||
|
||||
sp = 0;
|
||||
mpush(loSt, hiSt, dSt);
|
||||
|
||||
@@ -625,8 +616,8 @@ void mainQSort3(EState* state,
|
||||
if (hi - lo < MAIN_QSORT_SMALL_THRESH
|
||||
|| d > MAIN_QSORT_DEPTH_THRESH
|
||||
) {
|
||||
mainSimpleSort(state, lo, hi, d);
|
||||
if (state->budget < 0)
|
||||
mainSimpleSort(ptr, block, quadrant, nblock, lo, hi, d, budget);
|
||||
if (*budget < 0)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
@@ -647,8 +638,8 @@ void mainQSort3(EState* state,
|
||||
ltLo++;
|
||||
unLo++;
|
||||
continue;
|
||||
}
|
||||
if (n > 0) break;
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
}
|
||||
while (1) {
|
||||
@@ -660,8 +651,8 @@ void mainQSort3(EState* state,
|
||||
gtHi--;
|
||||
unHi--;
|
||||
continue;
|
||||
}
|
||||
if (n < 0) break;
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
}
|
||||
if (unLo > unHi)
|
||||
@@ -730,24 +721,28 @@ void mainQSort3(EState* state,
|
||||
#define CLEARMASK (~(SETMASK))
|
||||
|
||||
static NOINLINE
|
||||
void mainSort(EState* state)
|
||||
void mainSort(EState* state,
|
||||
uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
uint32_t* ftab,
|
||||
int32_t nblock,
|
||||
int32_t* budget)
|
||||
{
|
||||
int32_t i, j;
|
||||
int32_t i, j, k, ss, sb;
|
||||
uint8_t c1;
|
||||
int32_t numQSorted;
|
||||
uint16_t s;
|
||||
Bool bigDone[256];
|
||||
uint8_t runningOrder[256];
|
||||
/* bbox: moved to EState to save stack
|
||||
int32_t runningOrder[256];
|
||||
int32_t copyStart[256];
|
||||
int32_t copyEnd [256];
|
||||
*/
|
||||
#define runningOrder (state->mainSort__runningOrder)
|
||||
#define copyStart (state->mainSort__copyStart)
|
||||
#define copyEnd (state->mainSort__copyEnd)
|
||||
|
||||
uint32_t *const ptr = state->ptr;
|
||||
uint8_t *const block = state->block;
|
||||
uint32_t *const ftab = state->ftab;
|
||||
const int32_t nblock = state->nblock;
|
||||
uint16_t *const quadrant = state->quadrant;
|
||||
|
||||
/*-- set up the 2-byte frequency table --*/
|
||||
/* was: for (i = 65536; i >= 0; i--) ftab[i] = 0; */
|
||||
memset(ftab, 0, 65537 * sizeof(ftab[0]));
|
||||
@@ -755,25 +750,25 @@ void mainSort(EState* state)
|
||||
j = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
/* 3%, +300 bytes */
|
||||
#if BZIP2_SPEED >= 2
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
quadrant[i] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-1] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-1]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-1]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-2] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-2]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-2]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-3] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-3]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-3]) << 8);
|
||||
ftab[j]++;
|
||||
}
|
||||
#endif
|
||||
for (; i >= 0; i--) {
|
||||
quadrant[i] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i]) << 8);
|
||||
ftab[j]++;
|
||||
}
|
||||
|
||||
@@ -790,36 +785,33 @@ void mainSort(EState* state)
|
||||
ftab[i] = j;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned s;
|
||||
s = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
#if BZIP2_SPEED >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
s = (s >> 8) | (block[i-1] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-1;
|
||||
s = (s >> 8) | (block[i-2] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-2;
|
||||
s = (s >> 8) | (block[i-3] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-3;
|
||||
}
|
||||
s = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
s = (s >> 8) | (block[i-1] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-1;
|
||||
s = (s >> 8) | (block[i-2] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-2;
|
||||
s = (s >> 8) | (block[i-3] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-3;
|
||||
}
|
||||
#endif
|
||||
for (; i >= 0; i--) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
}
|
||||
for (; i >= 0; i--) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -833,23 +825,24 @@ void mainSort(EState* state)
|
||||
}
|
||||
|
||||
{
|
||||
int32_t vv;
|
||||
/* bbox: was: int32_t h = 1; */
|
||||
/* do h = 3 * h + 1; while (h <= 256); */
|
||||
unsigned h = 364;
|
||||
uint32_t h = 364;
|
||||
|
||||
do {
|
||||
/*h = h / 3;*/
|
||||
h = (h * 171) >> 9; /* bbox: fast h/3 */
|
||||
for (i = h; i <= 255; i++) {
|
||||
unsigned vv, jh;
|
||||
vv = runningOrder[i]; /* uint8[] */
|
||||
vv = runningOrder[i];
|
||||
j = i;
|
||||
while (jh = j - h, BIGFREQ(runningOrder[jh]) > BIGFREQ(vv)) {
|
||||
runningOrder[j] = runningOrder[jh];
|
||||
j = jh;
|
||||
if (j < h)
|
||||
break;
|
||||
while (BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv)) {
|
||||
runningOrder[j] = runningOrder[j-h];
|
||||
j = j - h;
|
||||
if (j <= (h - 1))
|
||||
goto zero;
|
||||
}
|
||||
zero:
|
||||
runningOrder[j] = vv;
|
||||
}
|
||||
} while (h != 1);
|
||||
@@ -859,8 +852,9 @@ void mainSort(EState* state)
|
||||
* The main sorting loop.
|
||||
*/
|
||||
|
||||
for (i = 0; /*i <= 255*/; i++) {
|
||||
unsigned ss;
|
||||
numQSorted = 0;
|
||||
|
||||
for (i = 0; i <= 255; i++) {
|
||||
|
||||
/*
|
||||
* Process big buckets, starting with the least full.
|
||||
@@ -880,14 +874,17 @@ void mainSort(EState* state)
|
||||
*/
|
||||
for (j = 0; j <= 255; j++) {
|
||||
if (j != ss) {
|
||||
unsigned sb;
|
||||
sb = (ss << 8) + j;
|
||||
if (!(ftab[sb] & SETMASK)) {
|
||||
int32_t lo = ftab[sb] /*& CLEARMASK (redundant)*/;
|
||||
int32_t lo = ftab[sb] & CLEARMASK;
|
||||
int32_t hi = (ftab[sb+1] & CLEARMASK) - 1;
|
||||
if (hi > lo) {
|
||||
mainQSort3(state, lo, hi /*,BZ_N_RADIX*/);
|
||||
if (state->budget < 0) return;
|
||||
mainQSort3(
|
||||
ptr, block, quadrant, nblock,
|
||||
lo, hi, BZ_N_RADIX, budget
|
||||
);
|
||||
if (*budget < 0) return;
|
||||
numQSorted += (hi - lo + 1);
|
||||
}
|
||||
}
|
||||
ftab[sb] |= SETMASK;
|
||||
@@ -909,8 +906,6 @@ void mainSort(EState* state)
|
||||
copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
|
||||
}
|
||||
for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
|
||||
unsigned c1;
|
||||
int32_t k;
|
||||
k = ptr[j] - 1;
|
||||
if (k < 0)
|
||||
k += nblock;
|
||||
@@ -919,8 +914,6 @@ void mainSort(EState* state)
|
||||
ptr[copyStart[c1]++] = k;
|
||||
}
|
||||
for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
|
||||
unsigned c1;
|
||||
int32_t k;
|
||||
k = ptr[j]-1;
|
||||
if (k < 0)
|
||||
k += nblock;
|
||||
@@ -940,9 +933,6 @@ void mainSort(EState* state)
|
||||
for (j = 0; j <= 255; j++)
|
||||
ftab[(j << 8) + ss] |= SETMASK;
|
||||
|
||||
if (i == 255)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Step 3:
|
||||
* The [ss] big bucket is now done. Record this fact,
|
||||
@@ -984,15 +974,15 @@ void mainSort(EState* state)
|
||||
*/
|
||||
bigDone[ss] = True;
|
||||
|
||||
{
|
||||
unsigned bbStart = ftab[ss << 8] & CLEARMASK;
|
||||
unsigned bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
|
||||
unsigned shifts = 0;
|
||||
if (i < 255) {
|
||||
int32_t bbStart = ftab[ss << 8] & CLEARMASK;
|
||||
int32_t bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
|
||||
int32_t shifts = 0;
|
||||
|
||||
while ((bbSize >> shifts) > 65534) shifts++;
|
||||
|
||||
for (j = bbSize-1; j >= 0; j--) {
|
||||
unsigned a2update = ptr[bbStart + j]; /* uint32[] */
|
||||
int32_t a2update = ptr[bbStart + j];
|
||||
uint16_t qVal = (uint16_t)(j >> shifts);
|
||||
quadrant[a2update] = qVal;
|
||||
if (a2update < BZ_N_OVERSHOOT)
|
||||
@@ -1025,24 +1015,31 @@ void mainSort(EState* state)
|
||||
* arr1[0 .. nblock-1] holds sorted order
|
||||
*/
|
||||
static NOINLINE
|
||||
int32_t BZ2_blockSort(EState* state)
|
||||
void BZ2_blockSort(EState* s)
|
||||
{
|
||||
/* In original bzip2 1.0.4, it's a parameter, but 30
|
||||
* (which was the default) should work ok. */
|
||||
enum { wfact = 30 };
|
||||
unsigned i;
|
||||
int32_t origPtr = origPtr;
|
||||
|
||||
if (state->nblock >= 10000) {
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint32_t* ftab = s->ftab;
|
||||
int32_t nblock = s->nblock;
|
||||
uint16_t* quadrant;
|
||||
int32_t budget;
|
||||
int32_t i;
|
||||
|
||||
if (nblock < 10000) {
|
||||
fallbackSort(s->arr1, s->arr2, ftab, nblock);
|
||||
} else {
|
||||
/* Calculate the location for quadrant, remembering to get
|
||||
* the alignment right. Assumes that &(block[0]) is at least
|
||||
* 2-byte aligned -- this should be ok since block is really
|
||||
* the first section of arr2.
|
||||
*/
|
||||
i = state->nblock + BZ_N_OVERSHOOT;
|
||||
if (i & 1)
|
||||
i++;
|
||||
state->quadrant = (uint16_t*) &(state->block[i]);
|
||||
i = nblock + BZ_N_OVERSHOOT;
|
||||
if (i & 1) i++;
|
||||
quadrant = (uint16_t*)(&(block[i]));
|
||||
|
||||
/* (wfact-1) / 3 puts the default-factor-30
|
||||
* transition point at very roughly the same place as
|
||||
@@ -1051,26 +1048,22 @@ int32_t BZ2_blockSort(EState* state)
|
||||
* resulting compressed stream is now the same regardless
|
||||
* of whether or not we use the main sort or fallback sort.
|
||||
*/
|
||||
state->budget = state->nblock * ((wfact-1) / 3);
|
||||
mainSort(state);
|
||||
if (state->budget >= 0)
|
||||
goto good;
|
||||
}
|
||||
fallbackSort(state);
|
||||
good:
|
||||
budget = nblock * ((wfact-1) / 3);
|
||||
|
||||
#if BZ_LIGHT_DEBUG
|
||||
origPtr = -1;
|
||||
#endif
|
||||
for (i = 0; i < state->nblock; i++) {
|
||||
if (state->ptr[i] == 0) {
|
||||
origPtr = i;
|
||||
break;
|
||||
mainSort(s, ptr, block, quadrant, ftab, nblock, &budget);
|
||||
if (budget < 0) {
|
||||
fallbackSort(s->arr1, s->arr2, ftab, nblock);
|
||||
}
|
||||
}
|
||||
|
||||
AssertH(origPtr != -1, 1003);
|
||||
return origPtr;
|
||||
s->origPtr = -1;
|
||||
for (i = 0; i < s->nblock; i++)
|
||||
if (ptr[i] == 0) {
|
||||
s->origPtr = i;
|
||||
break;
|
||||
};
|
||||
|
||||
AssertH(s->origPtr != -1, 1003);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ in the file LICENSE.
|
||||
* 0.9.0a/b -- no changes in this file.
|
||||
* 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
|
||||
* fixed bzWrite/bzRead to ignore zero-length requests.
|
||||
* fixed bzread to correctly handle read requests after EOF.
|
||||
* fixed bzread to correctly handle read requests after EOF.
|
||||
* wrong parameter order in call to bzDecompressInit in
|
||||
* bzBuffToBuffDecompress. Fixed.
|
||||
*/
|
||||
@@ -55,9 +55,8 @@ void prepare_new_block(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nblock = 0;
|
||||
//indexes into s->zbits[], initialzation moved to init of s->zbits
|
||||
//s->posZ = s->zbits; // was: s->numZ = 0;
|
||||
//s->state_out_pos = s->zbits;
|
||||
s->numZ = 0;
|
||||
s->state_out_pos = 0;
|
||||
BZ_INITIALISE_CRC(s->blockCRC);
|
||||
/* inlined memset would be nice to have here */
|
||||
for (i = 0; i < 256; i++)
|
||||
@@ -87,7 +86,7 @@ int isempty_RL(EState* s)
|
||||
static
|
||||
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
{
|
||||
unsigned n;
|
||||
int32_t n;
|
||||
EState* s;
|
||||
|
||||
s = xzalloc(sizeof(EState));
|
||||
@@ -99,8 +98,9 @@ void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
s->ptr = (uint32_t*)s->arr1;
|
||||
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
|
||||
s->block = (uint8_t*)s->arr2;
|
||||
s->ftab = xmalloc(65537 * sizeof(uint32_t));
|
||||
|
||||
crc32_filltable(s->crc32table, 1);
|
||||
s->crc32table = crc32_filltable(NULL, 1);
|
||||
|
||||
s->state = BZ_S_INPUT;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
@@ -237,10 +237,11 @@ void /*Bool*/ copy_output_until_stop(EState* s)
|
||||
if (s->strm->avail_out == 0) break;
|
||||
|
||||
/*-- block done? --*/
|
||||
if (s->state_out_pos >= s->posZ) break;
|
||||
if (s->state_out_pos >= s->numZ) break;
|
||||
|
||||
/*progress_out = True;*/
|
||||
*(s->strm->next_out) = *s->state_out_pos++;
|
||||
*(s->strm->next_out) = s->zbits[s->state_out_pos];
|
||||
s->state_out_pos++;
|
||||
s->strm->avail_out--;
|
||||
s->strm->next_out++;
|
||||
s->strm->total_out++;
|
||||
@@ -260,7 +261,7 @@ void /*Bool*/ handle_compress(bz_stream *strm)
|
||||
while (1) {
|
||||
if (s->state == BZ_S_OUTPUT) {
|
||||
/*progress_out |=*/ copy_output_until_stop(s);
|
||||
if (s->state_out_pos < s->posZ) break;
|
||||
if (s->state_out_pos < s->numZ) break;
|
||||
if (s->mode == BZ_M_FINISHING
|
||||
//# && s->avail_in_expect == 0
|
||||
&& s->strm->avail_in == 0
|
||||
@@ -335,7 +336,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FLUSH_OK;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
return BZ_RUN_OK;
|
||||
@@ -348,9 +349,9 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
//# return BZ_FINISH_OK;
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FINISH_OK;
|
||||
/*s->mode = BZ_M_IDLE;*/
|
||||
return BZ_STREAM_END;
|
||||
@@ -360,6 +361,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static
|
||||
void BZ2_bzCompressEnd(bz_stream *strm)
|
||||
{
|
||||
@@ -368,10 +370,11 @@ void BZ2_bzCompressEnd(bz_stream *strm)
|
||||
s = strm->state;
|
||||
free(s->arr1);
|
||||
free(s->arr2);
|
||||
//free(s->ftab); // made it array member of s
|
||||
//free(s->crc32table); // ditto
|
||||
free(s);
|
||||
free(s->ftab);
|
||||
free(s->crc32table);
|
||||
free(strm->state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
@@ -390,12 +393,10 @@ int BZ2_bzBuffToBuffCompress(char* dest,
|
||||
bz_stream strm;
|
||||
int ret;
|
||||
|
||||
if (dest == NULL || destLen == NULL
|
||||
|| source == NULL
|
||||
|| blockSize100k < 1 || blockSize100k > 9
|
||||
) {
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
source == NULL ||
|
||||
blockSize100k < 1 || blockSize100k > 9)
|
||||
return BZ_PARAM_ERROR;
|
||||
}
|
||||
|
||||
BZ2_bzCompressInit(&strm, blockSize100k);
|
||||
|
||||
File renamed without changes.
@@ -33,7 +33,7 @@ typedef unsigned char Bool;
|
||||
#define False ((Bool)0)
|
||||
|
||||
#if BZ_LIGHT_DEBUG
|
||||
static void bz_assert_fail(int errcode) NORETURN;
|
||||
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
|
||||
#define AssertH(cond, errcode) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
@@ -120,11 +120,8 @@ typedef struct EState {
|
||||
|
||||
/* mode this stream is in, and whether inputting */
|
||||
/* or outputting data */
|
||||
uint8_t mode;
|
||||
uint8_t state;
|
||||
|
||||
/* misc administratium */
|
||||
uint8_t blockSize100k;
|
||||
int32_t mode;
|
||||
int32_t state;
|
||||
|
||||
/* remembers avail_in when flush/finish requested */
|
||||
/* bbox: not needed, strm->avail_in always has the same value */
|
||||
@@ -132,12 +129,10 @@ typedef struct EState {
|
||||
/* uint32_t avail_in_expect; */
|
||||
|
||||
/* for doing the block sorting */
|
||||
int32_t origPtr;
|
||||
uint32_t *arr1;
|
||||
uint32_t *arr2;
|
||||
//uint32_t *ftab; //moved into this struct, see below
|
||||
|
||||
uint16_t *quadrant;
|
||||
int32_t budget;
|
||||
uint32_t *ftab;
|
||||
|
||||
/* aliases for arr1 and arr2 */
|
||||
uint32_t *ptr;
|
||||
@@ -145,6 +140,9 @@ typedef struct EState {
|
||||
uint16_t *mtfv;
|
||||
uint8_t *zbits;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* run-length-encoding of the input */
|
||||
uint32_t state_in_ch;
|
||||
int32_t state_in_len;
|
||||
@@ -152,9 +150,8 @@ typedef struct EState {
|
||||
/* input and output limits and current posns */
|
||||
int32_t nblock;
|
||||
int32_t nblockMAX;
|
||||
//int32_t numZ; // index into s->zbits[], replaced by pointer:
|
||||
uint8_t *posZ;
|
||||
uint8_t *state_out_pos;
|
||||
int32_t numZ;
|
||||
int32_t state_out_pos;
|
||||
|
||||
/* the buffer for bit stream creation */
|
||||
uint32_t bsBuff;
|
||||
@@ -166,13 +163,14 @@ typedef struct EState {
|
||||
|
||||
/* misc administratium */
|
||||
int32_t blockNo;
|
||||
int32_t blockSize100k;
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t nMTF;
|
||||
|
||||
/* map of bytes used in block */
|
||||
int32_t nInUse;
|
||||
Bool inUse[256] ALIGNED(sizeof(long));
|
||||
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
|
||||
uint8_t unseqToSeq[256];
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
@@ -182,16 +180,10 @@ typedef struct EState {
|
||||
|
||||
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
|
||||
/* guess what */
|
||||
uint32_t crc32table[256];
|
||||
|
||||
/* for doing the block sorting */
|
||||
uint32_t ftab[65537];
|
||||
|
||||
/* stack-saving measures: these can be local, but they are too big */
|
||||
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/* second dimension: only 3 needed; 4 makes index calculations faster */
|
||||
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
#endif
|
||||
@@ -199,6 +191,7 @@ typedef struct EState {
|
||||
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
|
||||
int32_t mainSort__runningOrder[256];
|
||||
int32_t mainSort__copyStart[256];
|
||||
int32_t mainSort__copyEnd[256];
|
||||
} EState;
|
||||
@@ -206,7 +199,7 @@ typedef struct EState {
|
||||
|
||||
/*-- compression. --*/
|
||||
|
||||
static int32_t
|
||||
static void
|
||||
BZ2_blockSort(EState*);
|
||||
|
||||
static void
|
||||
@@ -32,12 +32,6 @@ in the file LICENSE.
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
#if BZIP2_SPEED >= 5
|
||||
# define ALWAYS_INLINE_5 ALWAYS_INLINE
|
||||
#else
|
||||
# define ALWAYS_INLINE_5 /*nothing*/
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Bit stream I/O ---*/
|
||||
/*---------------------------------------------------*/
|
||||
@@ -56,7 +50,8 @@ static NOINLINE
|
||||
void bsFinishWrite(EState* s)
|
||||
{
|
||||
while (s->bsLive > 0) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
@@ -66,74 +61,39 @@ void bsFinishWrite(EState* s)
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
/* Helps only on level 5, on other levels hurts. ? */
|
||||
ALWAYS_INLINE_5
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
ALWAYS_INLINE
|
||||
#endif
|
||||
void bsW(EState* s, int32_t n, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (32 - s->bsLive - n));
|
||||
s->bsLive += n;
|
||||
}
|
||||
/* Same with n == 16: */
|
||||
static
|
||||
ALWAYS_INLINE_5
|
||||
void bsW16(EState* s, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (16 - s->bsLive));
|
||||
s->bsLive += 16;
|
||||
}
|
||||
/* Same with n == 1: */
|
||||
static
|
||||
ALWAYS_INLINE /* one callsite */
|
||||
void bsW1_1(EState* s)
|
||||
{
|
||||
/* need space for only 1 bit, no need for loop freeing > 8 bits */
|
||||
if (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (1 << (31 - s->bsLive));
|
||||
s->bsLive += 1;
|
||||
}
|
||||
static
|
||||
ALWAYS_INLINE_5
|
||||
void bsW1_0(EState* s)
|
||||
{
|
||||
/* need space for only 1 bit, no need for loop freeing > 8 bits */
|
||||
if (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
//s->bsBuff |= (0 << (31 - s->bsLive));
|
||||
s->bsLive += 1;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static ALWAYS_INLINE
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW16(s, u);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU32(EState* s, unsigned u)
|
||||
{
|
||||
//bsW(s, 32, u); // can't use: may try "uint32 << -n"
|
||||
bsW16(s, (u >> 16) & 0xffff);
|
||||
bsW16(s, u & 0xffff);
|
||||
bsW(s, 8, (u >> 24) & 0xff);
|
||||
bsW(s, 8, (u >> 16) & 0xff);
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,57 +106,25 @@ static
|
||||
void makeMaps_e(EState* s)
|
||||
{
|
||||
int i;
|
||||
unsigned cnt = 0;
|
||||
s->nInUse = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (s->inUse[i]) {
|
||||
s->unseqToSeq[i] = cnt;
|
||||
cnt++;
|
||||
s->unseqToSeq[i] = s->nInUse;
|
||||
s->nInUse++;
|
||||
}
|
||||
}
|
||||
s->nInUse = cnt;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*
|
||||
* This bit of code is performance-critical.
|
||||
* On 32bit x86, gcc-6.3.0 was observed to spill ryy_j to stack,
|
||||
* resulting in abysmal performance (x3 slowdown).
|
||||
* Forcing it into a separate function alleviates register pressure,
|
||||
* and spillage no longer happens.
|
||||
* Other versions of gcc do not exhibit this problem, but out-of-line code
|
||||
* seems to be helping them too (code is both smaller and faster).
|
||||
* Therefore NOINLINE is enabled for the entire 32bit x86 arch for now,
|
||||
* without a check for gcc version.
|
||||
*/
|
||||
static
|
||||
#if defined __i386__
|
||||
NOINLINE
|
||||
#endif
|
||||
int inner_loop(uint8_t *yy, uint8_t ll_i)
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
while (ll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
}
|
||||
yy[0] = rtmp;
|
||||
return ryy_j - &(yy[0]);
|
||||
}
|
||||
static NOINLINE
|
||||
void generateMTFValues(EState* s)
|
||||
{
|
||||
uint8_t yy[256];
|
||||
int i;
|
||||
int zPend;
|
||||
int32_t i, j;
|
||||
int32_t zPend;
|
||||
int32_t wr;
|
||||
int32_t EOB;
|
||||
|
||||
/*
|
||||
* After sorting (eg, here),
|
||||
@@ -206,88 +134,111 @@ void generateMTFValues(EState* s)
|
||||
* holds the original block data.
|
||||
*
|
||||
* The first thing to do is generate the MTF values,
|
||||
* and put them in ((uint16_t*)s->arr1)[0 .. s->nblock-1].
|
||||
*
|
||||
* and put them in
|
||||
* ((uint16_t*)s->arr1)[0 .. s->nblock-1].
|
||||
* Because there are strictly fewer or equal MTF values
|
||||
* than block values, ptr values in this area are overwritten
|
||||
* with MTF values only when they are no longer needed.
|
||||
*
|
||||
* The final compressed bitstream is generated into the
|
||||
* area starting at &((uint8_t*)s->arr2)[s->nblock]
|
||||
* area starting at
|
||||
* &((uint8_t*)s->arr2)[s->nblock]
|
||||
*
|
||||
* These storage aliases are set up in bzCompressInit(),
|
||||
* except for the last one, which is arranged in
|
||||
* compressBlock().
|
||||
*/
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
makeMaps_e(s);
|
||||
EOB = s->nInUse+1;
|
||||
|
||||
for (i = 0; i <= EOB; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
wr = 0;
|
||||
zPend = 0;
|
||||
for (i = 0; i <= s->nInUse+1; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
for (i = 0; i < s->nInUse; i++)
|
||||
yy[i] = (uint8_t) i;
|
||||
|
||||
for (i = 0; i < s->nblock; i++) {
|
||||
uint8_t ll_i = ll_i; /* gcc 4.3.1 thinks it may be used w/o init */
|
||||
int32_t j;
|
||||
|
||||
uint8_t ll_i;
|
||||
AssertD(wr <= i, "generateMTFValues(1)");
|
||||
j = ptr[i] - 1;
|
||||
if (j < 0)
|
||||
j += s->nblock;
|
||||
ll_i = s->unseqToSeq[s->block[j]];
|
||||
ll_i = s->unseqToSeq[block[j]];
|
||||
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
|
||||
|
||||
if (yy[0] == ll_i) {
|
||||
zPend++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zPend > 0) {
|
||||
process_zPend:
|
||||
zPend--;
|
||||
while (1) {
|
||||
#if 0
|
||||
if (zPend & 1) {
|
||||
s->mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
s->mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
|
||||
unsigned run = zPend & 1;
|
||||
s->mtfv[wr] = run;
|
||||
wr++;
|
||||
s->mtfFreq[run]++;
|
||||
#endif
|
||||
zPend -= 2;
|
||||
if (zPend < 0)
|
||||
break;
|
||||
zPend = (unsigned)zPend / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
} else {
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
if (i < 0) /* came via "goto process_zPend"? exit */
|
||||
goto end;
|
||||
zPend = 0;
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
register uint8_t rll_i;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
rll_i = ll_i;
|
||||
while (rll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
};
|
||||
yy[0] = rtmp;
|
||||
j = ryy_j - &(yy[0]);
|
||||
mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
|
||||
}
|
||||
j = inner_loop(yy, ll_i);
|
||||
s->mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
|
||||
i = -1;
|
||||
if (zPend > 0)
|
||||
goto process_zPend; /* "process it and come back here" */
|
||||
end:
|
||||
s->mtfv[wr] = s->nInUse+1;
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2)
|
||||
break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
|
||||
mtfv[wr] = EOB;
|
||||
wr++;
|
||||
s->mtfFreq[s->nInUse+1]++;
|
||||
s->mtfFreq[EOB]++;
|
||||
|
||||
s->nMTF = wr;
|
||||
}
|
||||
@@ -300,12 +251,9 @@ void generateMTFValues(EState* s)
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t t, i;
|
||||
unsigned iter;
|
||||
unsigned gs;
|
||||
int32_t alphaSize;
|
||||
unsigned nSelectors, selCtr;
|
||||
int32_t nGroups;
|
||||
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups, nBytes;
|
||||
|
||||
/*
|
||||
* uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
@@ -320,49 +268,39 @@ void sendMTFValues(EState* s)
|
||||
#define rfreq sendMTFValues__rfreq
|
||||
#define len_pack sendMTFValues__len_pack
|
||||
|
||||
unsigned /*uint16_t*/ cost[BZ_N_GROUPS];
|
||||
uint16_t cost[BZ_N_GROUPS];
|
||||
int32_t fave[BZ_N_GROUPS];
|
||||
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
alphaSize = s->nInUse + 2;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++) {
|
||||
unsigned v;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->len[t][v] = BZ_GREATER_ICOST;
|
||||
}
|
||||
|
||||
/*--- Decide how many coding tables to use ---*/
|
||||
AssertH(s->nMTF > 0, 3001);
|
||||
// 1..199 = 2
|
||||
// 200..599 = 3
|
||||
// 600..1199 = 4
|
||||
// 1200..2399 = 5
|
||||
// 2400..99999 = 6
|
||||
nGroups = 2;
|
||||
nGroups += (s->nMTF >= 200);
|
||||
nGroups += (s->nMTF >= 600);
|
||||
nGroups += (s->nMTF >= 1200);
|
||||
nGroups += (s->nMTF >= 2400);
|
||||
if (s->nMTF < 200) nGroups = 2; else
|
||||
if (s->nMTF < 600) nGroups = 3; else
|
||||
if (s->nMTF < 1200) nGroups = 4; else
|
||||
if (s->nMTF < 2400) nGroups = 5; else
|
||||
nGroups = 6;
|
||||
|
||||
/*--- Generate an initial set of coding tables ---*/
|
||||
{
|
||||
unsigned nPart, remF;
|
||||
int32_t nPart, remF, tFreq, aFreq;
|
||||
|
||||
nPart = nGroups;
|
||||
remF = s->nMTF;
|
||||
gs = 0;
|
||||
while (nPart > 0) {
|
||||
unsigned v;
|
||||
unsigned ge;
|
||||
unsigned tFreq, aFreq;
|
||||
|
||||
tFreq = remF / nPart;
|
||||
ge = gs;
|
||||
ge = gs - 1;
|
||||
aFreq = 0;
|
||||
while (aFreq < tFreq && ge < alphaSize) {
|
||||
aFreq += s->mtfFreq[ge++];
|
||||
while (aFreq < tFreq && ge < alphaSize-1) {
|
||||
ge++;
|
||||
aFreq += s->mtfFreq[ge];
|
||||
}
|
||||
ge--;
|
||||
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
@@ -388,19 +326,19 @@ void sendMTFValues(EState* s)
|
||||
* Iterate up to BZ_N_ITERS times to improve the tables.
|
||||
*/
|
||||
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned v;
|
||||
for (t = 0; t < nGroups; t++)
|
||||
fave[t] = 0;
|
||||
|
||||
for (t = 0; t < nGroups; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->rfreq[t][v] = 0;
|
||||
}
|
||||
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/*
|
||||
* Set up an auxiliary length table which is used to fast-track
|
||||
* the common case (nGroups == 6).
|
||||
*/
|
||||
if (nGroups == 6) {
|
||||
unsigned v;
|
||||
for (v = 0; v < alphaSize; v++) {
|
||||
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||
@@ -409,11 +347,9 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
#endif
|
||||
nSelectors = 0;
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
unsigned bt, bc;
|
||||
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
@@ -427,7 +363,7 @@ void sendMTFValues(EState* s)
|
||||
*/
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] = 0;
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
register uint32_t cost01, cost23, cost45;
|
||||
@@ -452,12 +388,13 @@ void sendMTFValues(EState* s)
|
||||
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
unsigned /*uint16_t*/ icv = mtfv[i];
|
||||
uint16_t icv = mtfv[i];
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] += s->len[t][icv];
|
||||
}
|
||||
@@ -476,6 +413,8 @@ void sendMTFValues(EState* s)
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
totc += bc;
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
@@ -483,7 +422,7 @@ void sendMTFValues(EState* s)
|
||||
* Increment the symbol frequencies for the selected table.
|
||||
*/
|
||||
/* 1% faster compress. +800 bytes */
|
||||
#if BZIP2_SPEED >= 4
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 4
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
|
||||
@@ -521,7 +460,7 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
|
||||
AssertH(nGroups < 8, 3002);
|
||||
AssertH(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZ_G_SIZE)), 3003);
|
||||
AssertH(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZ_G_SIZE)), 3003);
|
||||
|
||||
/*--- Compute MTF values for the selectors. ---*/
|
||||
{
|
||||
@@ -530,7 +469,6 @@ void sendMTFValues(EState* s)
|
||||
for (i = 0; i < nGroups; i++)
|
||||
pos[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
unsigned j;
|
||||
ll_i = s->selector[i];
|
||||
j = 0;
|
||||
tmp = pos[j];
|
||||
@@ -539,16 +477,16 @@ void sendMTFValues(EState* s)
|
||||
tmp2 = tmp;
|
||||
tmp = pos[j];
|
||||
pos[j] = tmp2;
|
||||
}
|
||||
};
|
||||
pos[0] = tmp;
|
||||
s->selectorMtf[i] = j;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*--- Assign actual codes for the tables. --*/
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned minLen = 32; //todo: s->len[t][0];
|
||||
unsigned maxLen = 0; //todo: s->len[t][0];
|
||||
minLen = 32;
|
||||
maxLen = 0;
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||
@@ -565,59 +503,60 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
bsW16(s, inUse16);
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 16, inUse16);
|
||||
|
||||
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (inUse16 < 0) {
|
||||
unsigned v16 = 0;
|
||||
unsigned j;
|
||||
for (j = 0; j < 16; j++)
|
||||
v16 = v16*2 + s->inUse[i * 16 + j];
|
||||
bsW16(s, v16);
|
||||
bsW(s, 16, v16);
|
||||
}
|
||||
inUse16 <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*--- Now the selectors. ---*/
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 3, nGroups);
|
||||
bsW(s, 15, nSelectors);
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
unsigned j;
|
||||
for (j = 0; j < s->selectorMtf[i]; j++)
|
||||
bsW1_1(s);
|
||||
bsW1_0(s);
|
||||
bsW(s, 1, 1);
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
|
||||
/*--- Now the coding tables. ---*/
|
||||
nBytes = s->numZ;
|
||||
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned curr = s->len[t][0];
|
||||
int32_t curr = s->len[t][0];
|
||||
bsW(s, 5, curr);
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }
|
||||
bsW1_0(s);
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*--- And finally, the block data proper ---*/
|
||||
nBytes = s->numZ;
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
@@ -676,21 +615,17 @@ void sendMTFValues(EState* s)
|
||||
static
|
||||
void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
{
|
||||
int32_t origPtr = origPtr;
|
||||
|
||||
if (s->nblock > 0) {
|
||||
BZ_FINALISE_CRC(s->blockCRC);
|
||||
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
|
||||
s->combinedCRC ^= s->blockCRC;
|
||||
if (s->blockNo > 1)
|
||||
s->posZ = s->zbits; // was: s->numZ = 0;
|
||||
s->numZ = 0;
|
||||
|
||||
origPtr = BZ2_blockSort(s);
|
||||
BZ2_blockSort(s);
|
||||
}
|
||||
|
||||
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
|
||||
s->posZ = s->zbits;
|
||||
s->state_out_pos = s->zbits;
|
||||
|
||||
/*-- If this is the first block, create the stream header. --*/
|
||||
if (s->blockNo == 1) {
|
||||
@@ -724,9 +659,9 @@ void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
* so as to maintain backwards compatibility with
|
||||
* older versions of bzip2.
|
||||
*/
|
||||
bsW1_0(s);
|
||||
bsW(s, 1, 0);
|
||||
|
||||
bsW(s, 24, origPtr);
|
||||
bsW(s, 24, s->origPtr);
|
||||
generateMTFValues(s);
|
||||
sendMTFValues(s);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ in the file LICENSE.
|
||||
|
||||
|
||||
/* 90 bytes, 0.3% of overall compress speed */
|
||||
#if BZIP2_SPEED >= 1
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 1
|
||||
|
||||
/* macro works better than inline (gcc 4.2.1) */
|
||||
#define DOWNHEAP1(heap, weight, Heap) \
|
||||
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
|
||||
if (length[i] == n) {
|
||||
code[i] = vec;
|
||||
vec++;
|
||||
}
|
||||
};
|
||||
}
|
||||
vec <<= 1;
|
||||
}
|
||||
+42
-105
@@ -6,72 +6,10 @@
|
||||
* See README and LICENSE files in bz/ directory for more information
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
//config:config BZIP2
|
||||
//config: bool "bzip2 (16 kb)"
|
||||
//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.
|
||||
//config:
|
||||
//config:config BZIP2_SMALL
|
||||
//config: int "Trade bytes for speed (0:fast, 9:small)"
|
||||
//config: default 8 # all "fast or small" options default to small
|
||||
//config: range 0 9
|
||||
//config: depends on BZIP2
|
||||
//config: help
|
||||
//config: Trade code size versus speed.
|
||||
//config: Approximate values with gcc-6.3.0 "bzip -9" compressing
|
||||
//config: linux-4.15.tar were:
|
||||
//config: value time (sec) code size (386)
|
||||
//config: 9 (smallest) 70.11 7687
|
||||
//config: 8 67.93 8091
|
||||
//config: 7 67.88 8405
|
||||
//config: 6 67.78 8624
|
||||
//config: 5 67.05 9427
|
||||
//config: 4-0 (fastest) 64.14 12083
|
||||
//config:
|
||||
//config:config FEATURE_BZIP2_DECOMPRESS
|
||||
//config: bool "Enable decompression"
|
||||
//config: default y
|
||||
//config: depends on BZIP2 || BUNZIP2 || BZCAT
|
||||
//config: help
|
||||
//config: Enable -d (--decompress) and -t (--test) options for bzip2.
|
||||
//config: This will be automatically selected if bunzip2 or bzcat is
|
||||
//config: enabled.
|
||||
|
||||
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
|
||||
|
||||
//usage:#define bzip2_trivial_usage
|
||||
//usage: "[-cfk" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789] [FILE]..."
|
||||
//usage:#define bzip2_full_usage "\n\n"
|
||||
//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
|
||||
//usage: "\n -1..9 Compression level"
|
||||
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: )
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if CONFIG_BZIP2_SMALL >= 4
|
||||
#define BZIP2_SPEED (9 - CONFIG_BZIP2_SMALL)
|
||||
#else
|
||||
#define BZIP2_SPEED 5
|
||||
#endif
|
||||
#define CONFIG_BZIP2_FEATURE_SPEED 1
|
||||
|
||||
/* Speed test:
|
||||
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
|
||||
@@ -79,7 +17,7 @@
|
||||
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
|
||||
* At SPEED 5 difference is 32.7%.
|
||||
*
|
||||
* Test run of all BZIP2_SPEED values on a 11Mb text file:
|
||||
* Test run of all CONFIG_BZIP2_FEATURE_SPEED values on a 11Mb text file:
|
||||
* Size Time (3 runs)
|
||||
* 0: 10828 4.145 4.146 4.148
|
||||
* 1: 11097 3.845 3.860 3.861
|
||||
@@ -94,25 +32,27 @@
|
||||
/* Takes ~300 bytes, detects corruption caused by bad RAM etc */
|
||||
#define BZ_LIGHT_DEBUG 0
|
||||
|
||||
#include "libarchive/bz/bzlib.h"
|
||||
#include "bz/bzlib.h"
|
||||
|
||||
#include "libarchive/bz/bzlib_private.h"
|
||||
#include "bz/bzlib_private.h"
|
||||
|
||||
#include "libarchive/bz/blocksort.c"
|
||||
#include "libarchive/bz/bzlib.c"
|
||||
#include "libarchive/bz/compress.c"
|
||||
#include "libarchive/bz/huffman.c"
|
||||
#include "bz/blocksort.c"
|
||||
#include "bz/bzlib.c"
|
||||
#include "bz/compress.c"
|
||||
#include "bz/huffman.c"
|
||||
|
||||
/* No point in being shy and having very small buffer here.
|
||||
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
|
||||
* If iobuf is several pages long, malloc() may use mmap,
|
||||
* making iobuf page aligned and thus (maybe) have one memcpy less
|
||||
* making iobuf is page aligned and thus (maybe) have one memcpy less
|
||||
* if kernel is clever enough.
|
||||
*/
|
||||
enum {
|
||||
IOBUF_SIZE = 8 * 1024
|
||||
};
|
||||
|
||||
static uint8_t level;
|
||||
|
||||
/* NB: compressStream() has to return -1 on errors, not die.
|
||||
* bbunpack() will correctly clean up in this case
|
||||
* (delete incomplete .bz2 file)
|
||||
@@ -123,7 +63,7 @@ enum {
|
||||
* total written bytes so far otherwise
|
||||
*/
|
||||
static
|
||||
IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
{
|
||||
int n, n2, ret;
|
||||
|
||||
@@ -147,7 +87,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
if (n2 != n) {
|
||||
if (n2 >= 0)
|
||||
errno = 0; /* prevent bogus error message */
|
||||
bb_simple_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
|
||||
bb_perror_msg(n2 >= 0 ? "short write" : "write error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -157,14 +97,13 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
if (rlen && strm->avail_in == 0)
|
||||
break;
|
||||
}
|
||||
return 0 IF_DESKTOP( + strm->total_out );
|
||||
return 0 USE_DESKTOP( + strm->total_out );
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int compressStream(void)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
unsigned opt, level;
|
||||
USE_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
@@ -173,23 +112,12 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
|
||||
#define wbuf (iobuf + IOBUF_SIZE)
|
||||
|
||||
iobuf = xmalloc(2 * IOBUF_SIZE);
|
||||
|
||||
opt = option_mask32 >> (BBUNPK_OPTSTRLEN IF_FEATURE_BZIP2_DECOMPRESS(+ 2) + 2);
|
||||
/* skipped BBUNPK_OPTSTR, "dt" and "zs" bits */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 0;
|
||||
for (;;) {
|
||||
level++;
|
||||
if (opt & 1) break;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
BZ2_bzCompressInit(strm, level);
|
||||
|
||||
while (1) {
|
||||
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
|
||||
if (count < 0) {
|
||||
bb_simple_perror_msg(bb_msg_read_error);
|
||||
bb_perror_msg("read error");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
@@ -199,17 +127,21 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
|
||||
break;
|
||||
}
|
||||
|
||||
/* Can't be conditional on ENABLE_FEATURE_CLEAN_UP -
|
||||
* we are called repeatedly
|
||||
*/
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
BZ2_bzCompressEnd(strm);
|
||||
free(iobuf);
|
||||
|
||||
#endif
|
||||
return total;
|
||||
}
|
||||
|
||||
static
|
||||
char* make_new_name_bzip2(char *filename)
|
||||
{
|
||||
return xasprintf("%s.bz2", filename);
|
||||
}
|
||||
|
||||
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
int bzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
@@ -228,20 +160,25 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
* --best alias for -9
|
||||
*/
|
||||
|
||||
opt = getopt32(argv, "^"
|
||||
/* Must match BBUNPK_foo constants! */
|
||||
BBUNPK_OPTSTR IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789"
|
||||
"\0" "s2" /* -s means -2 (compatibility) */
|
||||
);
|
||||
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
|
||||
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
|
||||
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
|
||||
if (opt & 0x8) // -d
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 4;
|
||||
#else
|
||||
/* clear "decompress" and "test" bits (or bbunpack() can get confused) */
|
||||
/* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */
|
||||
option_mask32 = opt & ~(BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST);
|
||||
opt >>= 3;
|
||||
#endif
|
||||
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 1;
|
||||
while (!(opt & 1)) {
|
||||
level++;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, compressStream, append_ext, "bz2");
|
||||
option_mask32 &= 0x7; /* ignore all except -cfv */
|
||||
return bbunpack(argv, make_new_name_bzip2, compressStream);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//kbuild:lib-$(CONFIG_FEATURE_TAR_CREATE) += chksum_and_xwrite_tar_header.o
|
||||
//kbuild:lib-$(CONFIG_SMEMCAP) += chksum_and_xwrite_tar_header.o
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC chksum_and_xwrite_tar_header(int fd, struct tar_header_t *hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
unsigned int chksum, size;
|
||||
|
||||
strcpy(hp->magic, "ustar ");
|
||||
|
||||
/* Calculate and store the checksum (the sum of all of the bytes of
|
||||
* the header). The checksum field must be filled with blanks for the
|
||||
* calculation. The checksum field is formatted differently from the
|
||||
* other fields: it has 6 digits, a NUL, then a space -- rather than
|
||||
* digits, followed by a NUL like the other fields... */
|
||||
memset(hp->chksum, ' ', sizeof(hp->chksum));
|
||||
cp = (const unsigned char *) hp;
|
||||
chksum = 0;
|
||||
size = sizeof(*hp);
|
||||
do { chksum += *cp++; } while (--size);
|
||||
sprintf(hp->chksum, "%06o", chksum);
|
||||
|
||||
xwrite(fd, hp, sizeof(*hp));
|
||||
}
|
||||
+38
-543
@@ -4,585 +4,80 @@
|
||||
*
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
//config:config CPIO
|
||||
//config: bool "cpio (15 kb)"
|
||||
//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.
|
||||
//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 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 passthrough mode"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O
|
||||
//config: help
|
||||
//config: Passthrough mode. Rarely used.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_IGNORE_DEVNO
|
||||
//config: bool "Support --ignore-devno like GNU cpio"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O && LONG_OPTS
|
||||
//config: help
|
||||
//config: Optionally ignore device numbers when creating archives.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_RENUMBER_INODES
|
||||
//config: bool "Support --renumber-inodes like GNU cpio"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O && LONG_OPTS
|
||||
//config: help
|
||||
//config: Optionally renumber inodes when creating archives.
|
||||
|
||||
//applet:IF_CPIO(APPLET(cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
|
||||
|
||||
//usage:#define cpio_trivial_usage
|
||||
//usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
|
||||
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
|
||||
//usage: " [EXTR_FILE]..."
|
||||
//usage:#define cpio_full_usage "\n\n"
|
||||
//usage: "Extract (-i) or list (-t) files from a cpio archive on stdin"
|
||||
//usage: IF_FEATURE_CPIO_O(", or"
|
||||
//usage: "\ntake file list from stdin and create an archive (-o)"
|
||||
//usage: IF_FEATURE_CPIO_P(" or copy files (-p)")
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nMain operation mode:"
|
||||
//usage: "\n -t List"
|
||||
//usage: "\n -i Extract EXTR_FILEs (or all)"
|
||||
//usage: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -o Create (requires -H newc)"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_CPIO_P(
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -H newc Archive format"
|
||||
//usage: )
|
||||
//usage: "\n -d Make leading directories"
|
||||
//usage: "\n -m Restore mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -u Overwrite"
|
||||
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
|
||||
//usage: "\n -R USER[:GRP] Set owner of created files"
|
||||
//usage: "\n -L Dereference symlinks"
|
||||
//usage: "\n -0 NUL terminated input"
|
||||
//usage: IF_FEATURE_CPIO_IGNORE_DEVNO(
|
||||
//usage: "\n --ignore-devno"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_CPIO_RENUMBER_INODES(
|
||||
//usage: "\n --renumber-inodes"
|
||||
//usage: )
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
|
||||
Modes:
|
||||
-t, --list List the archive
|
||||
-i, --extract Extract files from an archive
|
||||
-o, --create Create the archive
|
||||
-p, --pass-through Copy-pass mode
|
||||
|
||||
Options valid in any mode:
|
||||
--block-size=SIZE I/O block size = SIZE * 512 bytes
|
||||
-B I/O block size = 5120 bytes
|
||||
-c Use the old portable (ASCII) archive format
|
||||
-C, --io-size=NUMBER I/O block size in bytes
|
||||
-f, --nonmatching Only copy files that do not match given pattern
|
||||
-F, --file=FILE Use FILE instead of standard input or output
|
||||
-H, --format=FORMAT Use given archive FORMAT
|
||||
-M, --message=STRING Print STRING when the end of a volume of the
|
||||
backup media is reached
|
||||
-n, --numeric-uid-gid If -v, show numeric UID and GID
|
||||
--quiet Do not print the number of blocks copied
|
||||
--rsh-command=COMMAND Use remote COMMAND instead of rsh
|
||||
-v, --verbose Verbosely list the files processed
|
||||
-V, --dot Print a "." for each file processed
|
||||
-W, --warning=FLAG Control warning display: 'none','truncate','all';
|
||||
multiple options accumulate
|
||||
|
||||
Options valid only in --extract mode:
|
||||
-b, --swap Swap both halfwords of words and bytes of
|
||||
halfwords in the data (equivalent to -sS)
|
||||
-r, --rename Interactively rename files
|
||||
-s, --swap-bytes Swap the bytes of each halfword in the files
|
||||
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
|
||||
--to-stdout Extract files to standard output
|
||||
-E, --pattern-file=FILE Read additional patterns specifying filenames to
|
||||
extract or list from FILE
|
||||
--only-verify-crc Verify CRC's, don't actually extract the files
|
||||
|
||||
Options valid only in --create mode:
|
||||
-A, --append Append to an existing archive
|
||||
-O FILE File to use instead of standard output
|
||||
|
||||
Options valid only in --pass-through mode:
|
||||
-l, --link Link files instead of copying them, when possible
|
||||
|
||||
Options valid in --extract and --create modes:
|
||||
--absolute-filenames Do not strip file system prefix components from
|
||||
the file names
|
||||
--no-absolute-filenames Create all files relative to the current dir
|
||||
|
||||
Options valid in --create and --pass-through modes:
|
||||
-0, --null A list of filenames is terminated by a NUL
|
||||
-a, --reset-access-time Reset the access times of files after reading them
|
||||
-I FILE File to use instead of standard input
|
||||
-L, --dereference Dereference symbolic links (copy the files
|
||||
that they point to instead of copying the links)
|
||||
-R, --owner=[USER][:.][GRP] Set owner of created files
|
||||
|
||||
Options valid in --extract and --pass-through modes:
|
||||
-d, --make-directories Create leading directories where needed
|
||||
-m, --preserve-modification-time Retain mtime when creating files
|
||||
--no-preserve-owner Do not change the ownership of the files
|
||||
--sparse Write files with blocks of zeros as sparse files
|
||||
-u, --unconditional Replace all files unconditionally
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
OPT_EXTRACT = (1 << 0),
|
||||
OPT_TEST = (1 << 1),
|
||||
OPT_NUL_TERMINATED = (1 << 2),
|
||||
OPT_UNCONDITIONAL = (1 << 3),
|
||||
OPT_VERBOSE = (1 << 4),
|
||||
OPT_CREATE_LEADING_DIR = (1 << 5),
|
||||
OPT_PRESERVE_MTIME = (1 << 6),
|
||||
OPT_DEREF = (1 << 7),
|
||||
OPT_FILE = (1 << 8),
|
||||
OPT_OWNER = (1 << 9),
|
||||
OPTBIT_OWNER = 9,
|
||||
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
|
||||
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
|
||||
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
|
||||
IF_LONG_OPTS( OPTBIT_QUIET ,)
|
||||
IF_LONG_OPTS( OPTBIT_2STDOUT ,)
|
||||
IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,)
|
||||
IF_FEATURE_CPIO_RENUMBER_INODES(OPTBIT_RENUMBER_INODES,)
|
||||
OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
|
||||
OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
|
||||
OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
|
||||
OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
|
||||
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
|
||||
OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0,
|
||||
OPT_RENUMBER_INODES = IF_FEATURE_CPIO_RENUMBER_INODES((1 << OPTBIT_RENUMBER_INODES)) + 0,
|
||||
};
|
||||
|
||||
#define OPTION_STR "it0uvdmLF:R:"
|
||||
|
||||
struct globals {
|
||||
struct bb_uidgid_t owner_ugid;
|
||||
ino_t next_inode;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
void BUG_cpio_globals_too_big(void);
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
G.owner_ugid.uid = -1L; \
|
||||
G.owner_ugid.gid = -1L; \
|
||||
} while (0)
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
static off_t cpio_pad4(off_t size)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = (- size) & 3;
|
||||
size += i;
|
||||
while (--i >= 0)
|
||||
bb_putchar('\0');
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Return value will become exit code.
|
||||
* It's ok to exit instead of return. */
|
||||
static NOINLINE int cpio_o(void)
|
||||
{
|
||||
struct name_s {
|
||||
struct name_s *next;
|
||||
char name[1];
|
||||
};
|
||||
struct inodes_s {
|
||||
struct inodes_s *next;
|
||||
struct name_s *names;
|
||||
struct stat st;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
ino_t mapped_inode;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct inodes_s *links = NULL;
|
||||
off_t bytes = 0; /* output bytes count */
|
||||
|
||||
while (1) {
|
||||
const char *name;
|
||||
char *line;
|
||||
struct stat st;
|
||||
|
||||
line = (option_mask32 & OPT_NUL_TERMINATED)
|
||||
? bb_get_chunk_from_file(stdin, NULL)
|
||||
: xmalloc_fgetline(stdin);
|
||||
|
||||
if (line) {
|
||||
/* Strip leading "./[./]..." from the filename */
|
||||
name = line;
|
||||
while (name[0] == '.' && name[1] == '/') {
|
||||
while (*++name == '/')
|
||||
continue;
|
||||
}
|
||||
if (!*name) { /* line is empty */
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
if ((option_mask32 & OPT_DEREF)
|
||||
? stat(name, &st)
|
||||
: lstat(name, &st)
|
||||
) {
|
||||
abort_cpio_o:
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
|
||||
if (G.owner_ugid.uid != (uid_t)-1L)
|
||||
st.st_uid = G.owner_ugid.uid;
|
||||
if (G.owner_ugid.gid != (gid_t)-1L)
|
||||
st.st_gid = G.owner_ugid.gid;
|
||||
|
||||
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
|
||||
st.st_size = 0; /* paranoia */
|
||||
|
||||
/* Store hardlinks for later processing, dont output them */
|
||||
if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
|
||||
struct name_s *n;
|
||||
struct inodes_s *l;
|
||||
|
||||
/* Do we have this hardlink remembered? */
|
||||
l = links;
|
||||
while (1) {
|
||||
if (l == NULL) {
|
||||
/* Not found: add new item to "links" list */
|
||||
l = xzalloc(sizeof(*l));
|
||||
l->st = st;
|
||||
l->next = links;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
if (option_mask32 & OPT_RENUMBER_INODES)
|
||||
l->mapped_inode = ++G.next_inode;
|
||||
#endif
|
||||
links = l;
|
||||
break;
|
||||
}
|
||||
if (l->st.st_ino == st.st_ino) {
|
||||
/* found */
|
||||
break;
|
||||
}
|
||||
l = l->next;
|
||||
}
|
||||
/* Add new name to "l->names" list */
|
||||
n = xmalloc(sizeof(*n) + strlen(name));
|
||||
strcpy(n->name, name);
|
||||
n->next = l->names;
|
||||
l->names = n;
|
||||
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
else if (option_mask32 & OPT_RENUMBER_INODES) {
|
||||
st.st_ino = ++G.next_inode;
|
||||
}
|
||||
#endif
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
/* Output hardlink's data */
|
||||
st = links->st;
|
||||
name = links->names->name;
|
||||
links->names = links->names->next;
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
if (links->mapped_inode)
|
||||
st.st_ino = links->mapped_inode;
|
||||
#endif
|
||||
/* GNU cpio is reported to emit file data
|
||||
* only for the last instance. Mimic that. */
|
||||
if (links->names == NULL)
|
||||
links = links->next;
|
||||
else
|
||||
st.st_size = 0;
|
||||
/* NB: we leak links->names and/or links,
|
||||
* this is intended (we exit soon anyway) */
|
||||
} else {
|
||||
/* If no (more) hardlinks to output,
|
||||
* output "trailer" entry */
|
||||
name = cpio_TRAILER;
|
||||
/* st.st_size == 0 is a must, but for uniformity
|
||||
* in the output, we zero out everything */
|
||||
memset(&st, 0, sizeof(st));
|
||||
/* st.st_nlink = 1; - GNU cpio does this */
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
|
||||
if (option_mask32 & OPT_IGNORE_DEVNO)
|
||||
st.st_dev = st.st_rdev = 0;
|
||||
#endif
|
||||
|
||||
if (sizeof(st.st_size) > 4
|
||||
&& st.st_size > (off_t)0xffffffff
|
||||
) {
|
||||
bb_error_msg_and_die("error: file '%s' is larger than 4GB", name);
|
||||
}
|
||||
|
||||
bytes += printf("070701"
|
||||
"%08X%08X%08X%08X%08X%08X%08X"
|
||||
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
|
||||
/* strlen+1: */ "%08X"
|
||||
/* chksum: */ "00000000" /* (only for "070702" files) */
|
||||
/* name,NUL: */ "%s%c",
|
||||
(unsigned)(uint32_t) st.st_ino,
|
||||
(unsigned)(uint32_t) st.st_mode,
|
||||
(unsigned)(uint32_t) st.st_uid,
|
||||
(unsigned)(uint32_t) st.st_gid,
|
||||
(unsigned)(uint32_t) st.st_nlink,
|
||||
(unsigned)(uint32_t) st.st_mtime,
|
||||
(unsigned)(uint32_t) st.st_size,
|
||||
(unsigned)(uint32_t) major(st.st_dev),
|
||||
(unsigned)(uint32_t) minor(st.st_dev),
|
||||
(unsigned)(uint32_t) major(st.st_rdev),
|
||||
(unsigned)(uint32_t) minor(st.st_rdev),
|
||||
(unsigned)(strlen(name) + 1),
|
||||
name, '\0');
|
||||
bytes = cpio_pad4(bytes);
|
||||
|
||||
if (st.st_size) {
|
||||
if (S_ISLNK(st.st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(name);
|
||||
if (!lpath)
|
||||
goto abort_cpio_o;
|
||||
bytes += printf("%s", lpath);
|
||||
free(lpath);
|
||||
} else { /* S_ISREG */
|
||||
int fd = xopen(name, O_RDONLY);
|
||||
fflush_all();
|
||||
/* We must abort if file got shorter too! */
|
||||
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
|
||||
bytes += st.st_size;
|
||||
close(fd);
|
||||
}
|
||||
bytes = cpio_pad4(bytes);
|
||||
}
|
||||
|
||||
if (!line) {
|
||||
if (name != cpio_TRAILER)
|
||||
goto next_link;
|
||||
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
free(line);
|
||||
} /* end of "while (1)" */
|
||||
}
|
||||
#endif
|
||||
#define CPIO_OPT_EXTRACT 0x01
|
||||
#define CPIO_OPT_TEST 0x02
|
||||
#define CPIO_OPT_UNCONDITIONAL 0x04
|
||||
#define CPIO_OPT_VERBOSE 0x08
|
||||
#define CPIO_OPT_FILE 0x10
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
|
||||
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename;
|
||||
char *cpio_owner;
|
||||
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
char *cpio_filename = NULL;
|
||||
unsigned opt;
|
||||
#if ENABLE_LONG_OPTS
|
||||
const char *long_opts =
|
||||
"extract\0" No_argument "i"
|
||||
"list\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
"create\0" No_argument "o"
|
||||
"format\0" Required_argument "H"
|
||||
#if ENABLE_FEATURE_CPIO_P
|
||||
"pass-through\0" No_argument "p"
|
||||
#endif
|
||||
#endif
|
||||
"owner\0" Required_argument "R"
|
||||
"file\0" Required_argument "F"
|
||||
"verbose\0" No_argument "v"
|
||||
"null\0" No_argument "0"
|
||||
"quiet\0" No_argument "\xff"
|
||||
"to-stdout\0" No_argument "\xfe"
|
||||
#if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
|
||||
"ignore-devno\0" No_argument "\xfd"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_CPIO_RENUMBER_INODES
|
||||
"renumber-inodes\0" No_argument "\xfc"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
INIT_G();
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
|
||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
/* As of now we do not enforce this: */
|
||||
/* -i,-t,-o,-p are mutually exclusive */
|
||||
/* -u,-d,-m make sense only with -i or -p */
|
||||
/* -L makes sense only with -o or -p */
|
||||
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner);
|
||||
#else
|
||||
opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts,
|
||||
&cpio_filename, &cpio_owner, &cpio_fmt);
|
||||
#endif
|
||||
argv += optind;
|
||||
if (opt & OPT_OWNER) { /* -R */
|
||||
parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
|
||||
archive_handle->cpio__owner = G.owner_ugid;
|
||||
}
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
if (opt & OPT_FILE) { /* -F */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
#else
|
||||
if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
if (opt & OPT_PASSTHROUGH) {
|
||||
pid_t pid;
|
||||
struct fd_pair pp;
|
||||
|
||||
if (argv[0] == NULL)
|
||||
bb_show_usage();
|
||||
if (opt & OPT_CREATE_LEADING_DIR)
|
||||
/* GNU cpio 2.13: "cpio -d -p a/b/c" works */
|
||||
bb_make_directory(argv[0], -1, FILEUTILS_RECUR);
|
||||
/* Crude existence check:
|
||||
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||
* This would check for existence earlier and cleaner.
|
||||
* As it stands now, if we fail xchdir later,
|
||||
* child dies on EPIPE, unless it caught
|
||||
* a diffrerent problem earlier.
|
||||
* This is good enough for now.
|
||||
*/
|
||||
//FIXME: GNU cpio -d -p DIR does not immediately create DIR -
|
||||
//it just prepends "DIR/" to the names of files to be created.
|
||||
//The first file (fails to) be copied, and then the -d logic
|
||||
//triggers and creates all necessary directories.
|
||||
//IOW: bare "cpio -d -p DIR" + ^C shouldn't create anything.
|
||||
#if !BB_MMU
|
||||
pp.rd = 3;
|
||||
pp.wr = 4;
|
||||
if (!re_execed) {
|
||||
close(3);
|
||||
close(4);
|
||||
xpiped_pair(pp);
|
||||
}
|
||||
#else
|
||||
xpiped_pair(pp);
|
||||
#endif
|
||||
pid = fork_or_rexec(argv - optind);
|
||||
if (pid == 0) { /* child */
|
||||
close(pp.rd);
|
||||
xmove_fd(pp.wr, STDOUT_FILENO);
|
||||
goto dump;
|
||||
}
|
||||
/* parent */
|
||||
xchdir(*argv++);
|
||||
close(pp.wr);
|
||||
xmove_fd(pp.rd, STDIN_FILENO);
|
||||
//opt &= ~OPT_PASSTHROUGH;
|
||||
opt |= OPT_EXTRACT;
|
||||
goto skip;
|
||||
}
|
||||
/* -o */
|
||||
if (opt & OPT_CREATE) {
|
||||
if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
|
||||
bb_show_usage();
|
||||
if (opt & OPT_FILE) {
|
||||
xmove_fd(xopen(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
|
||||
}
|
||||
dump:
|
||||
return cpio_o();
|
||||
}
|
||||
skip:
|
||||
#endif
|
||||
opt = getopt32(argv, "ituvF:dm", &cpio_filename);
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (OPT_TEST | OPT_EXTRACT)) == 0) {
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & OPT_TEST) {
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test options are given, ignore extract option */
|
||||
opt &= ~OPT_EXTRACT;
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
opt &= ~CPIO_OPT_EXTRACT;
|
||||
}
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & OPT_EXTRACT) {
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
if (opt & OPT_2STDOUT)
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & OPT_UNCONDITIONAL) {
|
||||
archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
if (opt & CPIO_OPT_UNCONDITIONAL) {
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & OPT_VERBOSE) {
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
if (archive_handle->action_header == header_list) {
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (opt & OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
if (cpio_filename) { /* CPIO_OPT_FILE */
|
||||
archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & OPT_PRESERVE_MTIME) {
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&archive_handle->accept, *argv);
|
||||
argv++;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
/* see get_header_cpio */
|
||||
archive_handle->cpio__blocks = (off_t)-1;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
create_links_from_list(archive_handle->link_placeholders);
|
||||
|
||||
if (archive_handle->cpio__blocks != (off_t)-1
|
||||
&& !(opt & OPT_QUIET)
|
||||
) {
|
||||
fflush_all();
|
||||
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
|
||||
}
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+391
-643
File diff suppressed because it is too large.
Load diff
+47
-84
@@ -2,133 +2,96 @@
|
||||
/*
|
||||
* dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg-deb (29 kb)"
|
||||
//config: default y
|
||||
//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.
|
||||
|
||||
//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 [DIR]"
|
||||
//usage:#define dpkg_deb_full_usage "\n\n"
|
||||
//usage: "Perform actions on Debian packages (.deb)\n"
|
||||
//usage: "\n -c List files"
|
||||
//usage: "\n -f Print control fields"
|
||||
//usage: "\n -e Extract control files to DIR (default: ./DEBIAN)"
|
||||
//usage: "\n -x Extract files to DIR (no default)"
|
||||
//usage: "\n -X Verbose extract"
|
||||
//usage:
|
||||
//usage:#define dpkg_deb_example_usage
|
||||
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
#define DPKG_DEB_OPT_FIELD 4
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 8
|
||||
#define DPKG_DEB_OPT_EXTRACT 16
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
#define DPKG_DEB_OPT_FIELD 4
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned opt;
|
||||
const char *extract_dir;
|
||||
const char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
tar_archive = init_handle();
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
||||
#if ENABLE_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
|
||||
|
||||
#if ENABLE_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Must have 1 or 2 args */
|
||||
opt = getopt32(argv, "^" "cefXx"
|
||||
"\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"
|
||||
);
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
extract_dir = argv[1];
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) { // -c
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
if (extract_dir)
|
||||
bb_show_usage();
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_FIELD) { // -f
|
||||
/* Print the entire control file */
|
||||
//TODO: standard tool accepts an optional list of fields to print
|
||||
if (opt & DPKG_DEB_OPT_CONTROL) {
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (optind + 1 == argc) {
|
||||
extract_dir = "./DEBIAN";
|
||||
} else {
|
||||
argcount++;
|
||||
}
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_FIELD) {
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
llist_add_to(&(tar_archive->accept), (char*)"./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
if (extract_dir)
|
||||
bb_show_usage();
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_CONTROL) { // -e
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (!extract_dir)
|
||||
extract_dir = "./DEBIAN";
|
||||
if (opt & DPKG_DEB_OPT_EXTRACT) {
|
||||
tar_archive->action_header = header_list;
|
||||
}
|
||||
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { // -Xx
|
||||
if (opt & DPKG_DEB_OPT_EXTRACT_VERBOSE)
|
||||
tar_archive->action_header = header_list;
|
||||
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (!extract_dir)
|
||||
bb_show_usage();
|
||||
argcount = 2;
|
||||
}
|
||||
|
||||
/* Standard tool supports "-" */
|
||||
tar_archive->src_fd = ar_archive->src_fd = xopen_stdin(argv[0]);
|
||||
if ((optind + argcount) != argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* Workout where to extract the files */
|
||||
/* 2nd argument is a dir name */
|
||||
if (argv[optind]) {
|
||||
extract_dir = argv[optind];
|
||||
}
|
||||
if (extract_dir) {
|
||||
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
|
||||
xchdir(extract_dir);
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
unpack_ar_archive(ar_archive);
|
||||
|
||||
/* Cleanup */
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
close(ar_archive->src_fd);
|
||||
close(ar_archive->src_fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+350
-525
File diff suppressed because it is too large.
Load diff
@@ -1,98 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
|
||||
lib-y:= common.o
|
||||
|
||||
COMMON_FILES:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
\
|
||||
unsafe_prefix.o \
|
||||
unsafe_symlink_target.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
seek_by_read.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
init_handle.o
|
||||
|
||||
DPKG_FILES:= \
|
||||
unpack_ar_archive.o \
|
||||
filter_accept_list_reassign.o \
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
get_header_tar_bz2.o \
|
||||
get_header_tar_lzma.o \
|
||||
get_header_tar_xz.o \
|
||||
|
||||
INSERT
|
||||
|
||||
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_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_UNLZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOPCAT) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
# 'bzip2 -d', bunzip2 or bzcat selects FEATURE_BZIP2_DECOMPRESS
|
||||
lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_UNZIP_BZIP2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_LZCAT) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_LZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_FEATURE_UNZIP_LZMA) += open_transformer.o decompress_unlzma.o
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_XZCAT) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_XZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_FEATURE_UNZIP_XZ) += open_transformer.o decompress_unxz.o
|
||||
# 'gzip -d', gunzip or zcat selects FEATURE_GZIP_DECOMPRESS
|
||||
lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += 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_SH_EMBEDDED_SCRIPTS) += open_transformer.o decompress_bunzip2.o
|
||||
|
||||
ifneq ($(lib-y),)
|
||||
lib-y += $(COMMON_FILES)
|
||||
endif
|
||||
@@ -1,8 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char cpio_TRAILER[] ALIGN1 = "TRAILER!!!";
|
||||
@@ -1,14 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
|
||||
{
|
||||
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle->src_fd, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
char *hard_link;
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
char *dst_name;
|
||||
#else
|
||||
# define dst_name (file_header->name)
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_SELINUX
|
||||
char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
|
||||
if (!sctx)
|
||||
sctx = archive_handle->tar__sctx[PAX_GLOBAL];
|
||||
if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
|
||||
setfscreatecon(sctx);
|
||||
free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
|
||||
archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Hard links are encoded as regular files of size 0
|
||||
* with a nonempty link field */
|
||||
hard_link = NULL;
|
||||
if (S_ISREG(file_header->mode) && file_header->size == 0)
|
||||
hard_link = file_header->link_target;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
dst_name = file_header->name;
|
||||
if (archive_handle->tar__strip_components) {
|
||||
unsigned n = archive_handle->tar__strip_components;
|
||||
do {
|
||||
dst_name = strchr(dst_name, '/');
|
||||
if (!dst_name || dst_name[1] == '\0') {
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
dst_name++;
|
||||
/*
|
||||
* Link target is shortened only for hardlinks:
|
||||
* softlinks restored unchanged.
|
||||
*/
|
||||
if (hard_link) {
|
||||
// GNU tar 1.26 does not check that we reached end of link name:
|
||||
// if "dir/hardlink" is hardlinked to "file",
|
||||
// tar xvf a.tar --strip-components=1 says:
|
||||
// tar: hardlink: Cannot hard link to '': No such file or directory
|
||||
// and continues processing. We silently skip such entries.
|
||||
hard_link = strchr(hard_link, '/');
|
||||
if (!hard_link || hard_link[1] == '\0') {
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
hard_link++;
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_PATH_TRAVERSAL_PROTECTION
|
||||
/* Skip leading "/" and past last ".." path component */
|
||||
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
dst_name = (char *)skip_unsafe_prefix(dst_name);
|
||||
# else /* dst_name is file_header->name, which is free()d by e.g. cpio - must copy, can't just advance the ptr */
|
||||
strip_unsafe_prefix(dst_name);
|
||||
# endif
|
||||
#endif
|
||||
// ^^^ This may be a problem if some applets do need to extract absolute names.
|
||||
// (Probably will need to invent ARCHIVE_ALLOW_UNSAFE_NAME flag).
|
||||
// You might think that rpm needs it, but in my tests rpm's internal cpio
|
||||
// archive has names like "./usr/bin/FOO", not "/usr/bin/FOO".
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *slash = strrchr(dst_name, '/');
|
||||
if (slash) {
|
||||
*slash = '\0';
|
||||
bb_make_directory(dst_name, -1, FILEUTILS_RECUR);
|
||||
*slash = '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
|
||||
/* Remove the entry if it exists */
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
if (hard_link) {
|
||||
/* Ugly special case:
|
||||
* tar cf t.tar hardlink1 hardlink2 hardlink1
|
||||
* results in this tarball structure:
|
||||
* hardlink1
|
||||
* hardlink2 -> hardlink1
|
||||
* hardlink1 -> hardlink1 <== !!!
|
||||
*/
|
||||
if (strcmp(hard_link, dst_name) == 0)
|
||||
goto ret;
|
||||
}
|
||||
/* Proceed with deleting */
|
||||
if (unlink(dst_name) == -1
|
||||
&& errno != ENOENT
|
||||
) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
dst_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat existing_sb;
|
||||
if (lstat(dst_name, &existing_sb) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_simple_perror_msg_and_die("can't stat old file");
|
||||
}
|
||||
}
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", dst_name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
else if ((unlink(dst_name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
dst_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
create_or_remember_link(&archive_handle->link_placeholders,
|
||||
hard_link,
|
||||
dst_name,
|
||||
1);
|
||||
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
|
||||
goto ret;
|
||||
}
|
||||
|
||||
/* Create the filesystem entry */
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
char *dst_nameN;
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_nameN = dst_name;
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
|
||||
/* rpm-style temp file name */
|
||||
dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid());
|
||||
#endif
|
||||
dst_fd = xopen3(dst_nameN,
|
||||
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_nameN, dst_name);
|
||||
free(dst_nameN);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
//TODO: this causes problems if tarball contains a r-xr-xr-x directory:
|
||||
// we create this directory, and then fail to create files inside it
|
||||
// (if tar xf isn't run as root).
|
||||
// GNU tar works around this by chmod-ing directories *after* all files are extracted.
|
||||
res = mkdir(dst_name, file_header->mode);
|
||||
if ((res != 0)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", dst_name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
|
||||
|
||||
/* To avoid a directory traversal attack via symlinks,
|
||||
* do not restore symlinks with ".." components
|
||||
* or symlinks starting with "/"
|
||||
*
|
||||
* For example, consider a .tar created via:
|
||||
* $ tar cvf bug.tar anything.txt
|
||||
* $ ln -s /tmp symlink
|
||||
* $ tar --append -f bug.tar symlink
|
||||
* $ rm symlink
|
||||
* $ mkdir symlink
|
||||
* $ tar --append -f bug.tar symlink/evil.py
|
||||
*
|
||||
* This will result in an archive that contains:
|
||||
* $ tar --list -f bug.tar
|
||||
* anything.txt
|
||||
* symlink [-> /tmp]
|
||||
* symlink/evil.py
|
||||
*
|
||||
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
|
||||
*/
|
||||
create_or_remember_link(&archive_handle->link_placeholders,
|
||||
file_header->link_target,
|
||||
dst_name,
|
||||
0);
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(dst_name, file_header->mode, file_header->device);
|
||||
if (res != 0) {
|
||||
bb_perror_msg("can't create node %s", dst_name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_simple_error_msg_and_die("unrecognized file type");
|
||||
}
|
||||
|
||||
if (!S_ISLNK(file_header->mode)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_OWNER)) {
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) {
|
||||
if (file_header->tar__uname) {
|
||||
//TODO: cache last name/id pair?
|
||||
struct passwd *pwd = getpwnam(file_header->tar__uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->tar__gname) {
|
||||
struct group *grp = getgrnam(file_header->tar__gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* GNU tar 1.15.1 uses chown, not lchown */
|
||||
chown(dst_name, uid, gid);
|
||||
}
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
|
||||
chmod(dst_name, file_header->mode);
|
||||
}
|
||||
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
|
||||
struct timeval t[2];
|
||||
|
||||
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
|
||||
t[1].tv_usec = t[0].tv_usec = 0;
|
||||
utimes(dst_name, t);
|
||||
}
|
||||
}
|
||||
|
||||
ret: ;
|
||||
#if ENABLE_FEATURE_TAR_SELINUX
|
||||
if (sctx) {
|
||||
/* reset the context after creating an entry */
|
||||
setfscreatecon(NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
enum {
|
||||
//TAR_FILETYPE,
|
||||
TAR_MODE,
|
||||
TAR_FILENAME,
|
||||
TAR_REALNAME,
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
TAR_UNAME,
|
||||
TAR_GNAME,
|
||||
#endif
|
||||
TAR_SIZE,
|
||||
TAR_UID,
|
||||
TAR_GID,
|
||||
TAR_MAX,
|
||||
};
|
||||
|
||||
static const char *const tar_var[] ALIGN_PTR = {
|
||||
// "FILETYPE",
|
||||
"MODE",
|
||||
"FILENAME",
|
||||
"REALNAME",
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
"UNAME",
|
||||
"GNAME",
|
||||
#endif
|
||||
"SIZE",
|
||||
"UID",
|
||||
"GID",
|
||||
};
|
||||
|
||||
static void xputenv(char *str)
|
||||
{
|
||||
if (putenv(str))
|
||||
bb_die_memory_exhausted();
|
||||
}
|
||||
|
||||
static void str2env(char *env[], int idx, const char *str)
|
||||
{
|
||||
env[idx] = xasprintf("TAR_%s=%s", tar_var[idx], str);
|
||||
xputenv(env[idx]);
|
||||
}
|
||||
|
||||
static void dec2env(char *env[], int idx, unsigned long long val)
|
||||
{
|
||||
env[idx] = xasprintf("TAR_%s=%llu", tar_var[idx], val);
|
||||
xputenv(env[idx]);
|
||||
}
|
||||
|
||||
static void oct2env(char *env[], int idx, unsigned long val)
|
||||
{
|
||||
env[idx] = xasprintf("TAR_%s=%lo", tar_var[idx], val);
|
||||
xputenv(env[idx]);
|
||||
}
|
||||
|
||||
void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
|
||||
#if 0 /* do we need this? ENABLE_FEATURE_TAR_SELINUX */
|
||||
char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
|
||||
if (!sctx)
|
||||
sctx = archive_handle->tar__sctx[PAX_GLOBAL];
|
||||
if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
|
||||
setfscreatecon(sctx);
|
||||
free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
|
||||
archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((file_header->mode & S_IFMT) == S_IFREG) {
|
||||
pid_t pid;
|
||||
int p[2], status;
|
||||
char *tar_env[TAR_MAX];
|
||||
|
||||
memset(tar_env, 0, sizeof(tar_env));
|
||||
|
||||
xpipe(p);
|
||||
pid = BB_MMU ? xfork() : xvfork();
|
||||
if (pid == 0) {
|
||||
/* Child */
|
||||
/* str2env(tar_env, TAR_FILETYPE, "f"); - parent should do it once */
|
||||
oct2env(tar_env, TAR_MODE, file_header->mode);
|
||||
str2env(tar_env, TAR_FILENAME, file_header->name);
|
||||
str2env(tar_env, TAR_REALNAME, file_header->name);
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
str2env(tar_env, TAR_UNAME, file_header->tar__uname);
|
||||
str2env(tar_env, TAR_GNAME, file_header->tar__gname);
|
||||
#endif
|
||||
dec2env(tar_env, TAR_SIZE, file_header->size);
|
||||
dec2env(tar_env, TAR_UID, file_header->uid);
|
||||
dec2env(tar_env, TAR_GID, file_header->gid);
|
||||
close(p[1]);
|
||||
xdup2(p[0], STDIN_FILENO);
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
execl(archive_handle->tar__to_command_shell,
|
||||
archive_handle->tar__to_command_shell,
|
||||
"-c",
|
||||
archive_handle->tar__to_command,
|
||||
(char *)0);
|
||||
bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
|
||||
}
|
||||
close(p[0]);
|
||||
/* Our caller is expected to do signal(SIGPIPE, SIG_IGN)
|
||||
* so that we don't die if child don't read all the input: */
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size);
|
||||
close(p[1]);
|
||||
|
||||
status = wait_for_exitstatus(pid);
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status))
|
||||
bb_error_msg_and_die("'%s' returned status %d",
|
||||
archive_handle->tar__to_command, WEXITSTATUS(status));
|
||||
if (WIFSIGNALED(status))
|
||||
bb_error_msg_and_die("'%s' terminated by signal %d",
|
||||
archive_handle->tar__to_command, WTERMSIG(status));
|
||||
|
||||
if (!BB_MMU) {
|
||||
int i;
|
||||
for (i = 0; i < TAR_MAX; i++) {
|
||||
if (tar_env[i])
|
||||
bb_unsetenv_and_free(tar_env[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 /* ENABLE_FEATURE_TAR_SELINUX */
|
||||
if (sctx)
|
||||
/* reset the context after creating an entry */
|
||||
setfscreatecon(NULL);
|
||||
#endif
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_exact_size(archive_handle->src_fd,
|
||||
STDOUT_FILENO,
|
||||
archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle->src_fd, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* This file uses XZ Embedded library code which is written
|
||||
* by Lasse Collin <lasse.collin@tukaani.org>
|
||||
* and Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* See README file in unxz/ directory for more information.
|
||||
*
|
||||
* This file is:
|
||||
* Copyright (C) 2010 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#define XZ_FUNC FAST_FUNC
|
||||
#define XZ_EXTERN static
|
||||
|
||||
#define XZ_DEC_DYNALLOC
|
||||
|
||||
/* Skip check (rather than fail) of unsupported hash functions */
|
||||
#define XZ_DEC_ANY_CHECK 1
|
||||
|
||||
/* We use our own crc32 function */
|
||||
#define XZ_INTERNAL_CRC32 0
|
||||
static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
return ~crc32_block_endian0(~crc, buf, size, global_crc32_table);
|
||||
}
|
||||
|
||||
/* We use arch-optimized unaligned fixed-endian accessors.
|
||||
* They have been moved to libbb (proved to be useful elsewhere as well),
|
||||
* just check that we have them defined:
|
||||
*/
|
||||
#if !defined(get_unaligned_le32) \
|
||||
|| !defined(get_unaligned_be32) \
|
||||
|| !defined(put_unaligned_le32) \
|
||||
|| !defined(put_unaligned_be32)
|
||||
# error get_unaligned_le32 accessors are not defined
|
||||
#endif
|
||||
|
||||
#include "unxz/xz_dec_bcj.c"
|
||||
#include "unxz/xz_dec_lzma2.c"
|
||||
#include "unxz/xz_dec_stream.c"
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_state_t *xstate)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
struct xz_dec *state;
|
||||
unsigned char *membuf;
|
||||
IF_DESKTOP(long long) int total = 0;
|
||||
|
||||
if (!global_crc32_table)
|
||||
global_crc32_new_table_le();
|
||||
|
||||
memset(&iobuf, 0, sizeof(iobuf));
|
||||
membuf = xmalloc(2 * BUFSIZ);
|
||||
iobuf.in = membuf;
|
||||
iobuf.out = membuf + BUFSIZ;
|
||||
iobuf.out_size = BUFSIZ;
|
||||
|
||||
if (!xstate || xstate->signature_skipped) {
|
||||
/* Preload XZ file signature */
|
||||
strcpy((char*)membuf, HEADER_MAGIC);
|
||||
iobuf.in_size = HEADER_MAGIC_SIZE;
|
||||
} /* else: let xz code read & check it */
|
||||
|
||||
/* Limit memory usage to about 64 MiB. */
|
||||
state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
|
||||
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
bb_simple_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
if (rd == 0 && xz_result == XZ_STREAM_END)
|
||||
break;
|
||||
iobuf.in_size = rd;
|
||||
iobuf.in_pos = 0;
|
||||
}
|
||||
if (xz_result == XZ_STREAM_END) {
|
||||
/*
|
||||
* Try to start decoding next concatenated stream.
|
||||
* Stream padding must always be a multiple of four
|
||||
* bytes to preserve four-byte alignment. To keep the
|
||||
* code slightly smaller, we aren't as strict here as
|
||||
* the .xz spec requires. We just skip all zero-bytes
|
||||
* without checking the alignment and thus can accept
|
||||
* files that aren't valid, e.g. the XZ utils test
|
||||
* files bad-0pad-empty.xz and bad-0catpad-empty.xz.
|
||||
*/
|
||||
do {
|
||||
if (membuf[iobuf.in_pos] != 0) {
|
||||
/* There is more data, but is it XZ data?
|
||||
* Example: dpkg-deb -f busybox_1.30.1-4_amd64.deb
|
||||
* reads control.tar.xz "control" file
|
||||
* inside the ar archive, but tar.xz
|
||||
* extraction code reaches end of xz data,
|
||||
* reached this code and reads the beginning
|
||||
* of data.tar.xz's ar header, which isn't xz data,
|
||||
* and prints "corrupted data".
|
||||
* The correct solution is to not read
|
||||
* past nested archive (to simulate EOF).
|
||||
* This is a workaround:
|
||||
*/
|
||||
if (membuf[iobuf.in_pos] != 0xfd) {
|
||||
/* It's definitely not a xz signature
|
||||
* (which is 0xfd,"7zXZ",0x00).
|
||||
*/
|
||||
goto end;
|
||||
}
|
||||
xz_dec_reset(state);
|
||||
goto do_run;
|
||||
}
|
||||
iobuf.in_pos++;
|
||||
} while (iobuf.in_pos < iobuf.in_size);
|
||||
}
|
||||
do_run:
|
||||
// bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
|
||||
xz_result = xz_dec_run(state, &iobuf);
|
||||
// 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);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
if (xz_result == XZ_STREAM_END) {
|
||||
/*
|
||||
* Can just "break;" here, if not for concatenated
|
||||
* .xz streams.
|
||||
* Checking for padding may require buffer
|
||||
* replenishment. Can't do it here.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
|
||||
bb_simple_error_msg("corrupted data");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
end:
|
||||
xz_dec_end(state);
|
||||
free(membuf);
|
||||
|
||||
return total;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
|
||||
|
||||
/*
|
||||
* Reassign the subarchive metadata parser based on the filename extension
|
||||
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
*/
|
||||
char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Check the file entry is in the accept list */
|
||||
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
|
||||
const char *name_ptr;
|
||||
|
||||
/* Find extension */
|
||||
name_ptr = strrchr(archive_handle->file_header->name, '.');
|
||||
if (!name_ptr)
|
||||
return EXIT_FAILURE;
|
||||
name_ptr++;
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
if (strcmp(name_ptr, "tar") == 0) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& strcmp(name_ptr, "bz2") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
&& strcmp(name_ptr, "lzma") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& strcmp(name_ptr, "xz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2001 Glenn McGrath.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#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)
|
||||
{
|
||||
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);
|
||||
if (err == -1)
|
||||
bb_simple_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
}
|
||||
|
||||
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
unsigned size;
|
||||
union {
|
||||
char raw[60];
|
||||
struct ar_header formatted;
|
||||
} ar;
|
||||
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
/* End Of File */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* ar header starts on an even byte (2 byte aligned)
|
||||
* '\n' is used for padding
|
||||
*/
|
||||
if (ar.raw[0] == '\n') {
|
||||
/* fix up the header, we started reading 1 byte too early */
|
||||
memmove(ar.raw, &ar.raw[1], 59);
|
||||
ar.raw[59] = xread_char(archive_handle->src_fd);
|
||||
archive_handle->offset++;
|
||||
}
|
||||
archive_handle->offset += 60;
|
||||
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_simple_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));
|
||||
|
||||
/* special filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += size;
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries
|
||||
*/
|
||||
archive_handle->ar__long_name_size = size;
|
||||
free(archive_handle->ar__long_names);
|
||||
archive_handle->ar__long_names = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->ar__long_names, size);
|
||||
archive_handle->offset += size;
|
||||
/* Return next header */
|
||||
return get_header_ar(archive_handle);
|
||||
}
|
||||
#else
|
||||
bb_simple_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
}
|
||||
/* Only size is always present, the rest may be missing in
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*
|
||||
* GNU binutils in deterministic mode hard codes mode to 0644 (NOT
|
||||
* 0100644). AR archives can only contain files, so force file
|
||||
* mode.
|
||||
*/
|
||||
typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)) | S_IFREG;
|
||||
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));
|
||||
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
unsigned long_offset;
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in ar__long_names) that contains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10,
|
||||
sizeof(ar.formatted.name) - 1);
|
||||
if (long_offset >= archive_handle->ar__long_name_size) {
|
||||
bb_simple_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* short filenames */
|
||||
typed->name = xstrndup(ar.formatted.name, 16);
|
||||
}
|
||||
|
||||
typed->name[strcspn(typed->name, " /")] = '\0';
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle);
|
||||
#if ENABLE_DPKG || ENABLE_DPKG_DEB
|
||||
if (archive_handle->dpkg__sub_archive) {
|
||||
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
|
||||
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
|
||||
continue;
|
||||
create_links_from_list(sa->link_placeholders);
|
||||
} else
|
||||
#endif
|
||||
archive_handle->action_data(archive_handle);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += typed->size;
|
||||
/* Set the file pointer to the correct spot, we may have been reading a compressed file */
|
||||
lseek(archive_handle->src_fd, archive_handle->offset, SEEK_SET);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2002 Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
typedef struct hardlinks_t {
|
||||
struct hardlinks_t *next;
|
||||
int inode; /* TODO: must match maj/min too! */
|
||||
int mode ;
|
||||
int mtime; /* These three are useful only in corner case */
|
||||
int uid ; /* of hardlinks with zero size body */
|
||||
int gid ;
|
||||
char name[1];
|
||||
} hardlinks_t;
|
||||
|
||||
char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
char cpio_header[111];
|
||||
int namesize;
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
|
||||
/* There can be padding before archive header */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
size = full_read(archive_handle->src_fd, cpio_header, 110);
|
||||
if (size == 0) {
|
||||
goto create_hardlinks;
|
||||
}
|
||||
if (size != 110) {
|
||||
bb_simple_error_msg_and_die("short read");
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (!is_prefixed_with(&cpio_header[0], "07070")
|
||||
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
|
||||
) {
|
||||
bb_simple_error_msg_and_die("unsupported cpio format, use newc or crc");
|
||||
}
|
||||
|
||||
cpio_header[110] = '\0'; /* sscanf may call strlen which may break without this */
|
||||
if (sscanf(cpio_header + 6,
|
||||
"%8x" "%8x" "%8x" "%8x"
|
||||
"%8x" "%8x" "%8x" /*maj,min:*/ "%*16c"
|
||||
/*rmaj,rmin:*/"%8x" "%8x" "%8x" /*chksum: "%*8c"*/,
|
||||
&inode, &mode, &uid, &gid,
|
||||
&nlink, &mtime, &size,
|
||||
&major, &minor, &namesize) != 10)
|
||||
bb_simple_error_msg_and_die("damaged cpio file");
|
||||
file_header->mode = mode;
|
||||
/* "cpio -R USER:GRP" support: */
|
||||
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
|
||||
uid = archive_handle->cpio__owner.uid;
|
||||
if (archive_handle->cpio__owner.gid != (gid_t)-1L)
|
||||
gid = archive_handle->cpio__owner.gid;
|
||||
file_header->uid = uid;
|
||||
file_header->gid = gid;
|
||||
file_header->mtime = mtime;
|
||||
file_header->size = size;
|
||||
|
||||
namesize &= 0x1fff; /* paranoia: limit names to 8k chars */
|
||||
file_header->name = xzalloc(namesize + 1);
|
||||
/* Read in filename */
|
||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||
if (file_header->name[0] == '/') {
|
||||
/* Testcase: echo /etc/hosts | cpio -pvd /tmp
|
||||
* Without this code, it tries to unpack /etc/hosts
|
||||
* into "/etc/hosts", not "etc/hosts".
|
||||
*/
|
||||
char *p = file_header->name;
|
||||
do p++; while (*p == '/');
|
||||
overlapping_strcpy(file_header->name, p);
|
||||
}
|
||||
archive_handle->offset += namesize;
|
||||
|
||||
/* Update offset amount and skip padding before file contents */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
if (strcmp(file_header->name, cpio_TRAILER) == 0) {
|
||||
/* Always round up. ">> 9" divides by 512 */
|
||||
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
|
||||
goto create_hardlinks;
|
||||
}
|
||||
|
||||
file_header->link_target = NULL;
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
file_header->size &= 0x1fff; /* paranoia: limit names to 8k chars */
|
||||
file_header->link_target = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, file_header->link_target, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
file_header->size = 0; /* Stop possible seeks in future */
|
||||
}
|
||||
|
||||
// TODO: data_extract_all can't deal with hardlinks to non-files...
|
||||
// when fixed, change S_ISREG to !S_ISDIR here
|
||||
|
||||
if (nlink > 1 && S_ISREG(file_header->mode)) {
|
||||
hardlinks_t *new = xmalloc(sizeof(*new) + namesize);
|
||||
new->inode = inode;
|
||||
new->mode = mode ;
|
||||
new->mtime = mtime;
|
||||
new->uid = uid ;
|
||||
new->gid = gid ;
|
||||
strcpy(new->name, file_header->name);
|
||||
/* Put file on a linked list for later */
|
||||
if (size == 0) {
|
||||
new->next = archive_handle->cpio__hardlinks_to_create;
|
||||
archive_handle->cpio__hardlinks_to_create = new;
|
||||
return EXIT_SUCCESS; /* Skip this one */
|
||||
/* TODO: this breaks cpio -t (it does not show hardlinks) */
|
||||
}
|
||||
new->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = new;
|
||||
}
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
//TODO: run "echo /etc/hosts | cpio -pv /tmp" twice. On 2nd run:
|
||||
//cpio: etc/hosts not created: newer or same age file exists
|
||||
//etc/hosts <-- should NOT show it
|
||||
//2 blocks <-- should say "0 blocks"
|
||||
archive_handle->action_header(archive_handle);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
file_header->link_target = NULL;
|
||||
file_header->name = NULL;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
create_hardlinks:
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
|
||||
while (archive_handle->cpio__hardlinks_to_create) {
|
||||
hardlinks_t *cur;
|
||||
hardlinks_t *make_me = archive_handle->cpio__hardlinks_to_create;
|
||||
|
||||
archive_handle->cpio__hardlinks_to_create = make_me->next;
|
||||
|
||||
memset(file_header, 0, sizeof(*file_header));
|
||||
file_header->mtime = make_me->mtime;
|
||||
file_header->name = make_me->name;
|
||||
file_header->mode = make_me->mode;
|
||||
file_header->uid = make_me->uid;
|
||||
file_header->gid = make_me->gid;
|
||||
/*file_header->size = 0;*/
|
||||
/*file_header->link_target = NULL;*/
|
||||
|
||||
/* Try to find a file we are hardlinked to */
|
||||
cur = archive_handle->cpio__created_hardlinks;
|
||||
while (cur) {
|
||||
/* TODO: must match maj/min too! */
|
||||
if (cur->inode == make_me->inode) {
|
||||
file_header->link_target = cur->name;
|
||||
/* link_target != NULL, size = 0: "I am a hardlink" */
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
free(make_me);
|
||||
goto next_link;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
/* Oops... no file with such inode was created... do it now
|
||||
* (happens when hardlinked files are empty (zero length)) */
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
/* Move to the list of created hardlinked files */
|
||||
make_me->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = make_me;
|
||||
next_link: ;
|
||||
}
|
||||
|
||||
while (archive_handle->cpio__created_hardlinks) {
|
||||
hardlinks_t *p = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = p->next;
|
||||
free(p);
|
||||
}
|
||||
|
||||
return EXIT_FAILURE; /* "No more files to process" */
|
||||
}
|
||||
@@ -1,498 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
* FIXME:
|
||||
* In privileged mode if uname and gname map to a uid and gid then use the
|
||||
* mapped value instead of the uid/gid values in tar header
|
||||
*
|
||||
* References:
|
||||
* GNU tar and star man pages,
|
||||
* Opengroup's ustar interchange format,
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
typedef uint32_t aliased_uint32_t FIX_ALIASING;
|
||||
typedef off_t aliased_off_t FIX_ALIASING;
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
unsigned long long v;
|
||||
char *end;
|
||||
/* NB: leading spaces are allowed. Using strtoull to handle that.
|
||||
* The downside is that we accept e.g. "-123" too :(
|
||||
*/
|
||||
str[len] = '\0';
|
||||
v = strtoull(str, &end, 8);
|
||||
/* std: "Each numeric field is terminated by one or more
|
||||
* <space> or NUL characters". We must support ' '! */
|
||||
if (*end != '\0' && *end != ' ') {
|
||||
int8_t first = str[0];
|
||||
if (!(first & 0x80))
|
||||
bb_simple_error_msg_and_die("corrupted octal value in tar header");
|
||||
/*
|
||||
* GNU tar uses "base-256 encoding" for very large numbers.
|
||||
* Encoding is binary, with highest bit always set as a marker
|
||||
* and sign in next-highest bit:
|
||||
* 80 00 .. 00 - zero
|
||||
* bf ff .. ff - largest positive number
|
||||
* ff ff .. ff - minus 1
|
||||
* c0 00 .. 00 - smallest negative number
|
||||
*
|
||||
* Example of tar file with 8914993153 (0x213600001) byte file.
|
||||
* Field starts at offset 7c:
|
||||
* 00070 30 30 30 00 30 30 30 30 30 30 30 00 80 00 00 00 |000.0000000.....|
|
||||
* 00080 00 00 00 02 13 60 00 01 31 31 31 32 30 33 33 36 |.....`..11120336|
|
||||
*
|
||||
* NB: tarballs with NEGATIVE unix times encoded that way were seen!
|
||||
*/
|
||||
/* Sign-extend 7bit 'first' to 64bit 'v' (that is, using 6th bit as sign): */
|
||||
first <<= 1;
|
||||
first >>= 1; /* now 7th bit = 6th bit */
|
||||
v = first; /* sign-extend 8 bits to 64 */
|
||||
while (--len != 0)
|
||||
v = (v << 8) + (uint8_t) *++str;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
#define GET_OCTAL(a) getOctal((a), sizeof(a))
|
||||
|
||||
#define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX)
|
||||
#if !TAR_EXTD
|
||||
#define process_pax_hdr(archive_handle, sz, global) \
|
||||
process_pax_hdr(archive_handle, sz)
|
||||
#endif
|
||||
/* "global" is 0 or 1 */
|
||||
static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
|
||||
{
|
||||
#if !TAR_EXTD
|
||||
unsigned blk_sz = (sz + 511) & (~511);
|
||||
seek_by_read(archive_handle->src_fd, blk_sz);
|
||||
#else
|
||||
unsigned blk_sz = (sz + 511) & (~511);
|
||||
char *buf, *p;
|
||||
|
||||
p = buf = xmalloc(blk_sz + 1);
|
||||
xread(archive_handle->src_fd, buf, blk_sz);
|
||||
archive_handle->offset += blk_sz;
|
||||
|
||||
/* prevent bb_strtou from running off the buffer */
|
||||
buf[sz] = '\0';
|
||||
|
||||
while (sz != 0) {
|
||||
char *end, *value;
|
||||
unsigned len;
|
||||
|
||||
/* Every record has this format: "LEN NAME=VALUE\n" */
|
||||
len = bb_strtou(p, &end, 10);
|
||||
/* expect errno to be EINVAL, because the character
|
||||
* following the digits should be a space
|
||||
*/
|
||||
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 */
|
||||
|| len == 0
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
) {
|
||||
bb_simple_error_msg("malformed extended header, skipped");
|
||||
// More verbose version:
|
||||
//bb_error_msg("malformed extended header at %"OFF_FMT"d, skipped",
|
||||
// archive_handle->offset - (sz + len));
|
||||
break;
|
||||
}
|
||||
/* overwrite the terminating newline with NUL
|
||||
* (we do not bother to check that it *was* a newline)
|
||||
*/
|
||||
p[-1] = '\0';
|
||||
value = end + 1;
|
||||
|
||||
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (!global) {
|
||||
if (is_prefixed_with(value, "path=")) {
|
||||
value += sizeof("path=") - 1;
|
||||
free(archive_handle->tar__longname);
|
||||
archive_handle->tar__longname = xstrdup(value);
|
||||
continue;
|
||||
}
|
||||
if (is_prefixed_with(value, "linkpath=")) {
|
||||
value += sizeof("linkpath=") - 1;
|
||||
free(archive_handle->tar__linkname);
|
||||
archive_handle->tar__linkname = xstrdup(value);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if ENABLE_FEATURE_TAR_SELINUX
|
||||
/* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
|
||||
* This is what Red Hat's patched version of tar uses.
|
||||
*/
|
||||
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
|
||||
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
|
||||
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
|
||||
free(archive_handle->tar__sctx[global]);
|
||||
archive_handle->tar__sctx[global] = xstrdup(value);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
free(buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static void die_if_bad_fnamesize(off_t sz)
|
||||
{
|
||||
if ((uoff_t)sz > 0xfff) /* more than 4k?! no funny business please */
|
||||
bb_simple_error_msg_and_die("bad archive");
|
||||
}
|
||||
#endif
|
||||
|
||||
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
struct tar_header_t tar;
|
||||
char *cp;
|
||||
int tar_typeflag; /* can be "char", "int" seems give smaller code */
|
||||
int i, sum_u, sum;
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
int sum_s;
|
||||
#endif
|
||||
int parse_names;
|
||||
|
||||
/* Our "private data" */
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
# define p_longname (archive_handle->tar__longname)
|
||||
# define p_linkname (archive_handle->tar__linkname)
|
||||
#else
|
||||
# define p_longname 0
|
||||
# define p_linkname 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX
|
||||
again:
|
||||
#endif
|
||||
/* Align header */
|
||||
data_align(archive_handle, 512);
|
||||
|
||||
again_after_align:
|
||||
|
||||
#if ENABLE_DESKTOP || ENABLE_FEATURE_TAR_AUTODETECT
|
||||
/* to prevent misdetection of bz2 sig */
|
||||
*(aliased_uint32_t*)&tar = 0;
|
||||
i = full_read(archive_handle->src_fd, &tar, 512);
|
||||
/* If GNU tar sees EOF in above read, it says:
|
||||
* "tar: A lone zero block at N", where N = kilobyte
|
||||
* where EOF was met (not EOF block, actual EOF!),
|
||||
* and exits with EXIT_SUCCESS.
|
||||
* We will mimic exit(EXIT_SUCCESS), although we will not mimic
|
||||
* the message and we don't check whether we indeed
|
||||
* saw zero block directly before this. */
|
||||
if (i == 0) {
|
||||
/* GNU tar 1.29 will be silent if tar archive ends abruptly
|
||||
* (if there are no zero blocks at all, and last read returns zero,
|
||||
* not short read 0 < len < 512). Complain only if
|
||||
* the very first read fails. Grrr.
|
||||
*/
|
||||
if (archive_handle->offset == 0)
|
||||
bb_simple_error_msg("short read");
|
||||
/* this merely signals end of archive, not exit(1): */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (i != 512) {
|
||||
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
|
||||
bb_simple_error_msg_and_die("short read");
|
||||
}
|
||||
|
||||
#else
|
||||
i = 512;
|
||||
xread(archive_handle->src_fd, &tar, i);
|
||||
#endif
|
||||
archive_handle->offset += i;
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.name[0] == 0 && tar.prefix[0] == 0
|
||||
/* Have seen a tar archive with pax 'x' header supplying UTF8 filename,
|
||||
* with actual file having all name fields NUL-filled. Check this: */
|
||||
&& !p_longname
|
||||
) {
|
||||
if (archive_handle->tar__end) {
|
||||
/* Second consecutive empty header - end of archive.
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
|
||||
continue;
|
||||
return EXIT_FAILURE; /* "end of archive" */
|
||||
}
|
||||
archive_handle->tar__end = 1;
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
}
|
||||
archive_handle->tar__end = 0;
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
if (!is_prefixed_with(tar.magic, "ustar")
|
||||
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
) {
|
||||
#if ENABLE_FEATURE_TAR_AUTODETECT
|
||||
autodetect:
|
||||
/* Two different causes for lseek() != 0:
|
||||
* unseekable fd (would like to support that too, but...),
|
||||
* or not first block (false positive, it's not .gz/.bz2!) */
|
||||
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
|
||||
err:
|
||||
bb_simple_error_msg_and_die("invalid tar magic");
|
||||
archive_handle->offset = 0;
|
||||
goto again_after_align;
|
||||
#endif
|
||||
bb_simple_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
|
||||
/* Do checksum on headers.
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source. */
|
||||
sum_u = ' ' * sizeof(tar.chksum);
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s = sum_u;
|
||||
#endif
|
||||
for (i = 0; i < 148; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
for (i = 156; i < 512; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
/* Most tarfiles have tar.chksum NUL or space terminated, but
|
||||
* github.com decided to be "special" and have unterminated field:
|
||||
* 0090: 30343300 30303031 33323731 30000000 |043.000132710...|
|
||||
* ^^^^^^^^|
|
||||
* Need to use GET_OCTAL. This overwrites tar.typeflag ---+
|
||||
* (the '0' char immediately after chksum in example above) with NUL.
|
||||
*/
|
||||
tar_typeflag = (uint8_t)tar.typeflag; /* save it */
|
||||
sum = GET_OCTAL(tar.chksum);
|
||||
if (sum_u != sum
|
||||
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
|
||||
) {
|
||||
bb_simple_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
/* GET_OCTAL trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
char t = tar.prefix[0];
|
||||
/* we trash prefix[0] here, but we DO need it later! */
|
||||
unsigned minor = GET_OCTAL(tar.devminor);
|
||||
unsigned major = GET_OCTAL(tar.devmajor);
|
||||
file_header->device = makedev(major, minor);
|
||||
tar.prefix[0] = t;
|
||||
}
|
||||
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (tar_typeflag == '\0') tar_typeflag = '0';
|
||||
parse_names = (tar_typeflag >= '0' && tar_typeflag <= '7');
|
||||
|
||||
file_header->link_target = NULL;
|
||||
if (!p_linkname && parse_names && tar.linkname[0]) {
|
||||
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
|
||||
/* FIXME: what if we have non-link object with link_target? */
|
||||
/* Will link_target be free()ed? */
|
||||
}
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
#endif
|
||||
file_header->mtime = GET_OCTAL(tar.mtime);
|
||||
file_header->size = GET_OCTAL(tar.size);
|
||||
file_header->gid = GET_OCTAL(tar.gid);
|
||||
file_header->uid = GET_OCTAL(tar.uid);
|
||||
/* Set bits 0-11 of the files mode */
|
||||
file_header->mode = 07777 & GET_OCTAL(tar.mode);
|
||||
|
||||
file_header->name = NULL;
|
||||
if (!p_longname && parse_names) {
|
||||
/* we trash mode[0] here, it's ok */
|
||||
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.mode[0] = '\0';
|
||||
if (tar.prefix[0]) {
|
||||
/* and padding[0] */
|
||||
//tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.padding[0] = '\0';
|
||||
file_header->name = concat_path_file(tar.prefix, tar.name);
|
||||
} else
|
||||
file_header->name = xstrdup(tar.name);
|
||||
}
|
||||
|
||||
switch (tar_typeflag) {
|
||||
case '1': /* hardlink */
|
||||
/* we mark hardlinks as regular files with zero size and a link name */
|
||||
file_header->mode |= S_IFREG;
|
||||
/* on size of link fields from star(4)
|
||||
* ... For tar archives written by pre POSIX.1-1988
|
||||
* implementations, the size field usually contains the size of
|
||||
* the file and needs to be ignored as no data may follow this
|
||||
* header type. For POSIX.1-1988 compliant archives, the size
|
||||
* field needs to be 0. For POSIX.1-2001 compliant archives,
|
||||
* the size field may be non zero, indicating that file data is
|
||||
* included in the archive.
|
||||
* i.e; always assume this is zero for safety.
|
||||
*/
|
||||
goto size0;
|
||||
case '7':
|
||||
/* case 0: */
|
||||
case '0':
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
if (file_header->name && last_char_is(file_header->name, '/')) {
|
||||
goto set_dir;
|
||||
}
|
||||
#endif
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '2':
|
||||
file_header->mode |= S_IFLNK;
|
||||
/* have seen tarballs with size field containing
|
||||
* the size of the link target's name */
|
||||
size0:
|
||||
file_header->size = 0;
|
||||
break;
|
||||
case '3':
|
||||
file_header->mode |= S_IFCHR;
|
||||
goto size0; /* paranoia */
|
||||
case '4':
|
||||
file_header->mode |= S_IFBLK;
|
||||
goto size0;
|
||||
case '5':
|
||||
IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:)
|
||||
file_header->mode |= S_IFDIR;
|
||||
goto size0;
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
goto size0;
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar_typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
|
||||
case 'L':
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(p_longname);
|
||||
/* For paranoia reasons we allocate extra NUL char */
|
||||
die_if_bad_fnamesize(file_header->size);
|
||||
p_longname = xzalloc(file_header->size + 1);
|
||||
/* We read ASCIZ string, including NUL */
|
||||
xread(archive_handle->src_fd, p_longname, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
/* return get_header_tar(archive_handle); */
|
||||
/* gcc 4.1.1 didn't optimize it into jump */
|
||||
/* so we will do it ourself, this also saves stack */
|
||||
goto again;
|
||||
case 'K':
|
||||
free(p_linkname);
|
||||
die_if_bad_fnamesize(file_header->size);
|
||||
p_linkname = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, p_linkname, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again;
|
||||
/*
|
||||
* case 'S': // Sparse file
|
||||
* Was seen in the wild. Not supported (yet?).
|
||||
* See https://www.gnu.org/software/tar/manual/html_section/tar_92.html
|
||||
* for the format. (An "Old GNU Format" was seen, not PAX formats).
|
||||
*/
|
||||
// case 'D': /* GNU dump dir */
|
||||
// case 'M': /* Continuation of multi volume archive */
|
||||
// case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'V': /* Volume header */
|
||||
; /* Fall through to skip it */
|
||||
#endif
|
||||
}
|
||||
skip_ext_hdr:
|
||||
{
|
||||
off_t sz;
|
||||
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
|
||||
sz = (file_header->size + 511) & ~(off_t)511;
|
||||
archive_handle->offset += sz;
|
||||
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
|
||||
while (sz--)
|
||||
xread(archive_handle->src_fd, &tar, 512);
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again_after_align;
|
||||
}
|
||||
default:
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (p_longname) {
|
||||
file_header->name = p_longname;
|
||||
p_longname = NULL;
|
||||
}
|
||||
if (p_linkname) {
|
||||
file_header->link_target = p_linkname;
|
||||
p_linkname = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Everything up to and including last ".." component is stripped */
|
||||
strip_unsafe_prefix(file_header->name);
|
||||
if (file_header->link_target && !S_ISLNK(file_header->mode)) {
|
||||
/* GNU tar 1.34 examples:
|
||||
* tar: Removing leading '/' from hard link targets
|
||||
* tar: Removing leading '../' from hard link targets
|
||||
* tar: Removing leading 'etc/../' from hard link targets
|
||||
*/
|
||||
strip_unsafe_prefix(file_header->link_target);
|
||||
}
|
||||
|
||||
/* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if it's a directory */
|
||||
cp = last_char_is(file_header->name, '/');
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle);
|
||||
/* Note that we kill the '/' only after action_header() */
|
||||
/* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */
|
||||
if (cp)
|
||||
*cp = '\0';
|
||||
archive_handle->action_data(archive_handle);
|
||||
if (archive_handle->accept || archive_handle->reject
|
||||
|| (archive_handle->ah_flags & ARCHIVE_REMEMBER_NAMES)
|
||||
) {
|
||||
llist_add_to(&archive_handle->passed, file_header->name);
|
||||
} else /* Caller isn't interested in list of unpacked files */
|
||||
free(file_header->name);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
free(file_header->name);
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
/* Do not free(file_header->name)!
|
||||
* It might be inserted in archive_handle->passed - see above */
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
free(file_header->tar__uname);
|
||||
free(file_header->tar__gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS; /* "decoded one header" */
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
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");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
char FAST_FUNC get_header_tar_xz(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_xz_stream, "unxz");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC header_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
//TODO: cpio -vp DIR should output "DIR/NAME", not just "NAME" */
|
||||
|
||||
const file_header_t *file_header = archive_handle->file_header;
|
||||
/* "tar xvOf TARFILE >OUTFILE" should use stderr for file list output: */
|
||||
FILE *fp = (archive_handle->action_data == data_extract_to_stdout) ? stderr : stdout;
|
||||
|
||||
fprintf(fp, "%s\n", printable_string(file_header->name));
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC header_skip(archive_handle_t *archive_handle UNUSED_PARAM)
|
||||
{
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC header_verbose_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
const file_header_t *file_header = archive_handle->file_header;
|
||||
struct tm tm_time;
|
||||
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
|
||||
char modestr[12];
|
||||
/* "tar xvvOf TARFILE >OUTFILE" should use stderr for file list output: */
|
||||
FILE *fp = (archive_handle->action_data == data_extract_to_stdout) ? stderr : stdout;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
char uid[sizeof(int)*3 + 2];
|
||||
/*char gid[sizeof(int)*3 + 2];*/
|
||||
char *user;
|
||||
char *group;
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
user = file_header->tar__uname;
|
||||
if (user == NULL) {
|
||||
sprintf(uid, "%u", (unsigned)file_header->uid);
|
||||
user = uid;
|
||||
}
|
||||
group = file_header->tar__gname;
|
||||
if (group == NULL) {
|
||||
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
|
||||
group = utoa(file_header->gid);
|
||||
}
|
||||
fprintf(fp, "%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(modestr, file_header->mode),
|
||||
user,
|
||||
group,
|
||||
file_header->size,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
printable_string(file_header->name));
|
||||
|
||||
#else /* !FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
fprintf(fp, "%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(modestr, file_header->mode),
|
||||
(unsigned)file_header->uid,
|
||||
(unsigned)file_header->gid,
|
||||
file_header->size,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
printable_string(file_header->name));
|
||||
|
||||
#endif /* FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
/* NB: GNU tar shows "->" for symlinks and "link to" for hardlinks */
|
||||
if (file_header->link_target) {
|
||||
fprintf(fp, " -> %s", printable_string(file_header->link_target));
|
||||
}
|
||||
putc('\n', fp);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "liblzo_interface.h"
|
||||
|
||||
/* lzo-2.03/src/config1x.h */
|
||||
#define M2_MIN_LEN 3
|
||||
#define M2_MAX_LEN 8
|
||||
#define M3_MAX_LEN 33
|
||||
#define M4_MAX_LEN 9
|
||||
#define M1_MAX_OFFSET 0x0400
|
||||
#define M2_MAX_OFFSET 0x0800
|
||||
#define M3_MAX_OFFSET 0x4000
|
||||
#define M4_MAX_OFFSET 0xbfff
|
||||
#define M1_MARKER 0
|
||||
#define M3_MARKER 32
|
||||
#define M4_MARKER 16
|
||||
|
||||
#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
|
||||
#define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
|
||||
|
||||
#define LZO_EOF_CODE
|
||||
|
||||
/* lzo-2.03/src/lzo_dict.h */
|
||||
#define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
|
||||
#define DX2(p,s1,s2) \
|
||||
(((((unsigned)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
|
||||
//#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
|
||||
//#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
|
||||
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
|
||||
|
||||
#define D_SIZE (1U << D_BITS)
|
||||
#define D_MASK ((1U << D_BITS) - 1)
|
||||
#define D_HIGH ((D_MASK >> 1) + 1)
|
||||
|
||||
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
||||
( \
|
||||
m_pos = ip - (unsigned)(ip - m_pos), \
|
||||
((uintptr_t)m_pos < (uintptr_t)in \
|
||||
|| (m_off = (unsigned)(ip - m_pos)) <= 0 \
|
||||
|| m_off > max_offset) \
|
||||
)
|
||||
|
||||
#define DENTRY(p,in) (p)
|
||||
#define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
|
||||
|
||||
#define DMS(v,s) ((unsigned) (((v) & (D_MASK >> (s))) << (s)))
|
||||
#define DM(v) ((unsigned) ((v) & D_MASK))
|
||||
#define DMUL(a,b) ((unsigned) ((a) * (b)))
|
||||
|
||||
/* lzo-2.03/src/lzo_ptr.h */
|
||||
#define pd(a,b) ((unsigned)((a)-(b)))
|
||||
|
||||
# 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
|
||||
|
||||
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
|
||||
# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
|
||||
//# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
|
||||
//#else
|
||||
//# define TEST_LB(m_pos) ((void) 0)
|
||||
//# define TEST_LBO(m_pos,o) ((void) 0)
|
||||
//#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
/* LZO1X-1 compression
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
#define D_BITS 14
|
||||
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
|
||||
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
|
||||
|
||||
#define DO_COMPRESS lzo1x_1_compress
|
||||
|
||||
#include "lzo1x_c.c"
|
||||
@@ -1,35 +0,0 @@
|
||||
/* LZO1X-1(15) compression
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
#define D_BITS 15
|
||||
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
|
||||
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
|
||||
|
||||
#define DO_COMPRESS lzo1x_1_15_compress
|
||||
|
||||
#include "lzo1x_c.c"
|
||||
@@ -1,917 +0,0 @@
|
||||
/* lzo1x_9x.c -- implementation of the LZO1X-999 compression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
#include "libbb.h"
|
||||
|
||||
/* The following is probably only safe on Intel-compatible processors ... */
|
||||
#define LZO_UNALIGNED_OK_2
|
||||
#define LZO_UNALIGNED_OK_4
|
||||
|
||||
#include "liblzo.h"
|
||||
|
||||
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define SWD_N M4_MAX_OFFSET /* size of ring buffer */
|
||||
#define SWD_F 2048 /* upper limit for match length */
|
||||
|
||||
#define SWD_BEST_OFF (LZO_MAX3(M2_MAX_LEN, M3_MAX_LEN, M4_MAX_LEN) + 1)
|
||||
|
||||
typedef struct {
|
||||
int init;
|
||||
|
||||
unsigned look; /* bytes in lookahead buffer */
|
||||
|
||||
unsigned m_len;
|
||||
unsigned m_off;
|
||||
|
||||
const uint8_t *bp;
|
||||
const uint8_t *ip;
|
||||
const uint8_t *in;
|
||||
const uint8_t *in_end;
|
||||
uint8_t *out;
|
||||
|
||||
unsigned r1_lit;
|
||||
} lzo1x_999_t;
|
||||
|
||||
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
|
||||
|
||||
/* lzo_swd.c -- sliding window dictionary */
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define SWD_UINT_MAX USHRT_MAX
|
||||
|
||||
#ifndef SWD_HSIZE
|
||||
# define SWD_HSIZE 16384
|
||||
#endif
|
||||
#ifndef SWD_MAX_CHAIN
|
||||
# define SWD_MAX_CHAIN 2048
|
||||
#endif
|
||||
|
||||
#define HEAD3(b, p) \
|
||||
( ((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]))
|
||||
#else
|
||||
# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
|
||||
#endif
|
||||
#define NIL2 SWD_UINT_MAX
|
||||
|
||||
typedef struct lzo_swd {
|
||||
/* public - "built-in" */
|
||||
|
||||
/* public - configuration */
|
||||
unsigned max_chain;
|
||||
int use_best_off;
|
||||
|
||||
/* public - output */
|
||||
unsigned m_len;
|
||||
unsigned m_off;
|
||||
unsigned look;
|
||||
int b_char;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
unsigned best_off[SWD_BEST_OFF];
|
||||
#endif
|
||||
|
||||
/* semi public */
|
||||
lzo1x_999_t *c;
|
||||
unsigned m_pos;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
unsigned best_pos[SWD_BEST_OFF];
|
||||
#endif
|
||||
|
||||
/* private */
|
||||
unsigned ip; /* input pointer (lookahead) */
|
||||
unsigned bp; /* buffer pointer */
|
||||
unsigned rp; /* remove pointer */
|
||||
|
||||
unsigned node_count;
|
||||
unsigned first_rp;
|
||||
|
||||
uint8_t b[SWD_N + SWD_F];
|
||||
uint8_t b_wrap[SWD_F]; /* must follow b */
|
||||
uint16_t head3[SWD_HSIZE];
|
||||
uint16_t succ3[SWD_N + SWD_F];
|
||||
uint16_t best3[SWD_N + SWD_F];
|
||||
uint16_t llen3[SWD_HSIZE];
|
||||
#ifdef HEAD2
|
||||
uint16_t head2[65536L];
|
||||
#endif
|
||||
} lzo_swd_t, *lzo_swd_p;
|
||||
|
||||
#define SIZEOF_LZO_SWD_T (sizeof(lzo_swd_t))
|
||||
|
||||
|
||||
/* Access macro for head3.
|
||||
* head3[key] may be uninitialized, but then its value will never be used.
|
||||
*/
|
||||
#define s_get_head3(s,key) s->head3[key]
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define B_SIZE (SWD_N + SWD_F)
|
||||
|
||||
static int swd_init(lzo_swd_p s)
|
||||
{
|
||||
/* defaults */
|
||||
s->node_count = SWD_N;
|
||||
|
||||
memset(s->llen3, 0, sizeof(s->llen3[0]) * (unsigned)SWD_HSIZE);
|
||||
#ifdef HEAD2
|
||||
memset(s->head2, 0xff, sizeof(s->head2[0]) * 65536L);
|
||||
assert(s->head2[0] == NIL2);
|
||||
#endif
|
||||
|
||||
s->ip = 0;
|
||||
s->bp = s->ip;
|
||||
s->first_rp = s->ip;
|
||||
|
||||
assert(s->ip + SWD_F <= B_SIZE);
|
||||
s->look = (unsigned) (s->c->in_end - s->c->ip);
|
||||
if (s->look > 0) {
|
||||
if (s->look > SWD_F)
|
||||
s->look = SWD_F;
|
||||
memcpy(&s->b[s->ip], s->c->ip, s->look);
|
||||
s->c->ip += s->look;
|
||||
s->ip += s->look;
|
||||
}
|
||||
if (s->ip == B_SIZE)
|
||||
s->ip = 0;
|
||||
|
||||
s->rp = s->first_rp;
|
||||
if (s->rp >= s->node_count)
|
||||
s->rp -= s->node_count;
|
||||
else
|
||||
s->rp += B_SIZE - s->node_count;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
#define swd_pos2off(s,pos) \
|
||||
(s->bp > (pos) ? s->bp - (pos) : B_SIZE - ((pos) - s->bp))
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_getbyte(lzo_swd_p s)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ((c = getbyte(*(s->c))) < 0) {
|
||||
if (s->look > 0)
|
||||
--s->look;
|
||||
} else {
|
||||
s->b[s->ip] = c;
|
||||
if (s->ip < SWD_F)
|
||||
s->b_wrap[s->ip] = c;
|
||||
}
|
||||
if (++s->ip == B_SIZE)
|
||||
s->ip = 0;
|
||||
if (++s->bp == B_SIZE)
|
||||
s->bp = 0;
|
||||
if (++s->rp == B_SIZE)
|
||||
s->rp = 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// remove node from lists
|
||||
************************************************************************/
|
||||
static void swd_remove_node(lzo_swd_p s, unsigned node)
|
||||
{
|
||||
if (s->node_count == 0) {
|
||||
unsigned key;
|
||||
|
||||
key = HEAD3(s->b,node);
|
||||
assert(s->llen3[key] > 0);
|
||||
--s->llen3[key];
|
||||
|
||||
#ifdef HEAD2
|
||||
key = HEAD2(s->b,node);
|
||||
assert(s->head2[key] != NIL2);
|
||||
if ((unsigned) s->head2[key] == node)
|
||||
s->head2[key] = NIL2;
|
||||
#endif
|
||||
} else
|
||||
--s->node_count;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_accept(lzo_swd_p s, unsigned n)
|
||||
{
|
||||
assert(n <= s->look);
|
||||
|
||||
while (n--) {
|
||||
unsigned key;
|
||||
|
||||
swd_remove_node(s,s->rp);
|
||||
|
||||
/* add bp into HEAD3 */
|
||||
key = HEAD3(s->b, s->bp);
|
||||
s->succ3[s->bp] = s_get_head3(s, key);
|
||||
s->head3[key] = s->bp;
|
||||
s->best3[s->bp] = SWD_F + 1;
|
||||
s->llen3[key]++;
|
||||
assert(s->llen3[key] <= SWD_N);
|
||||
|
||||
#ifdef HEAD2
|
||||
/* add bp into HEAD2 */
|
||||
key = HEAD2(s->b, s->bp);
|
||||
s->head2[key] = s->bp;
|
||||
#endif
|
||||
|
||||
swd_getbyte(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_search(lzo_swd_p s, unsigned node, unsigned cnt)
|
||||
{
|
||||
const uint8_t *p1;
|
||||
const uint8_t *p2;
|
||||
const uint8_t *px;
|
||||
unsigned m_len = s->m_len;
|
||||
const uint8_t *b = s->b;
|
||||
const uint8_t *bp = s->b + s->bp;
|
||||
const uint8_t *bx = s->b + s->bp + s->look;
|
||||
unsigned char scan_end1;
|
||||
|
||||
assert(s->m_len > 0);
|
||||
|
||||
scan_end1 = bp[m_len - 1];
|
||||
for ( ; cnt-- > 0; node = s->succ3[node]) {
|
||||
p1 = bp;
|
||||
p2 = b + node;
|
||||
px = bx;
|
||||
|
||||
assert(m_len < s->look);
|
||||
|
||||
if (p2[m_len - 1] == scan_end1
|
||||
&& p2[m_len] == p1[m_len]
|
||||
&& p2[0] == p1[0]
|
||||
&& p2[1] == p1[1]
|
||||
) {
|
||||
unsigned i;
|
||||
assert(lzo_memcmp(bp, &b[node], 3) == 0);
|
||||
|
||||
p1 += 2; p2 += 2;
|
||||
do {} while (++p1 < px && *p1 == *++p2);
|
||||
i = p1-bp;
|
||||
|
||||
assert(lzo_memcmp(bp, &b[node], i) == 0);
|
||||
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (i < SWD_BEST_OFF) {
|
||||
if (s->best_pos[i] == 0)
|
||||
s->best_pos[i] = node + 1;
|
||||
}
|
||||
#endif
|
||||
if (i > m_len) {
|
||||
s->m_len = m_len = i;
|
||||
s->m_pos = node;
|
||||
if (m_len == s->look)
|
||||
return;
|
||||
if (m_len >= SWD_F)
|
||||
return;
|
||||
if (m_len > (unsigned) s->best3[node])
|
||||
return;
|
||||
scan_end1 = bp[m_len - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#ifdef HEAD2
|
||||
|
||||
static int swd_search2(lzo_swd_p s)
|
||||
{
|
||||
unsigned key;
|
||||
|
||||
assert(s->look >= 2);
|
||||
assert(s->m_len > 0);
|
||||
|
||||
key = s->head2[HEAD2(s->b, s->bp)];
|
||||
if (key == NIL2)
|
||||
return 0;
|
||||
assert(lzo_memcmp(&s->b[s->bp], &s->b[key], 2) == 0);
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (s->best_pos[2] == 0)
|
||||
s->best_pos[2] = key + 1;
|
||||
#endif
|
||||
|
||||
if (s->m_len < 2) {
|
||||
s->m_len = 2;
|
||||
s->m_pos = key;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_findbest(lzo_swd_p s)
|
||||
{
|
||||
unsigned key;
|
||||
unsigned cnt, node;
|
||||
unsigned len;
|
||||
|
||||
assert(s->m_len > 0);
|
||||
|
||||
/* get current head, add bp into HEAD3 */
|
||||
key = HEAD3(s->b,s->bp);
|
||||
node = s->succ3[s->bp] = s_get_head3(s, key);
|
||||
cnt = s->llen3[key]++;
|
||||
assert(s->llen3[key] <= SWD_N + SWD_F);
|
||||
if (cnt > s->max_chain)
|
||||
cnt = s->max_chain;
|
||||
s->head3[key] = s->bp;
|
||||
|
||||
s->b_char = s->b[s->bp];
|
||||
len = s->m_len;
|
||||
if (s->m_len >= s->look) {
|
||||
if (s->look == 0)
|
||||
s->b_char = -1;
|
||||
s->m_off = 0;
|
||||
s->best3[s->bp] = SWD_F + 1;
|
||||
} else {
|
||||
#ifdef HEAD2
|
||||
if (swd_search2(s))
|
||||
#endif
|
||||
if (s->look >= 3)
|
||||
swd_search(s, node, cnt);
|
||||
if (s->m_len > len)
|
||||
s->m_off = swd_pos2off(s,s->m_pos);
|
||||
s->best3[s->bp] = s->m_len;
|
||||
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (s->use_best_off) {
|
||||
int i;
|
||||
for (i = 2; i < SWD_BEST_OFF; i++) {
|
||||
if (s->best_pos[i] > 0)
|
||||
s->best_off[i] = swd_pos2off(s, s->best_pos[i]-1);
|
||||
else
|
||||
s->best_off[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
swd_remove_node(s,s->rp);
|
||||
|
||||
#ifdef HEAD2
|
||||
/* add bp into HEAD2 */
|
||||
key = HEAD2(s->b, s->bp);
|
||||
s->head2[key] = s->bp;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef HEAD3
|
||||
#undef HEAD2
|
||||
#undef s_get_head3
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int init_match(lzo1x_999_t *c, lzo_swd_p s, uint32_t use_best_off)
|
||||
{
|
||||
int r;
|
||||
|
||||
assert(!c->init);
|
||||
c->init = 1;
|
||||
|
||||
s->c = c;
|
||||
|
||||
r = swd_init(s);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
s->use_best_off = use_best_off;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
unsigned this_len, unsigned skip)
|
||||
{
|
||||
assert(c->init);
|
||||
|
||||
if (skip > 0) {
|
||||
assert(this_len >= skip);
|
||||
swd_accept(s, this_len - skip);
|
||||
} else {
|
||||
assert(this_len <= 1);
|
||||
}
|
||||
|
||||
s->m_len = 1;
|
||||
#ifdef SWD_BEST_OFF
|
||||
if (s->use_best_off)
|
||||
memset(s->best_pos, 0, sizeof(s->best_pos));
|
||||
#endif
|
||||
swd_findbest(s);
|
||||
c->m_len = s->m_len;
|
||||
c->m_off = s->m_off;
|
||||
|
||||
swd_getbyte(s);
|
||||
|
||||
if (s->b_char < 0) {
|
||||
c->look = 0;
|
||||
c->m_len = 0;
|
||||
} else {
|
||||
c->look = s->look + 1;
|
||||
}
|
||||
c->bp = c->ip - c->look;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
/* this is a public functions, but there is no prototype in a header file */
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
unsigned max_lazy,
|
||||
unsigned max_chain,
|
||||
uint32_t use_best_off);
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static uint8_t *code_match(lzo1x_999_t *c,
|
||||
uint8_t *op, unsigned m_len, unsigned m_off)
|
||||
{
|
||||
assert(op > c->out);
|
||||
if (m_len == 2) {
|
||||
assert(m_off <= M1_MAX_OFFSET);
|
||||
assert(c->r1_lit > 0);
|
||||
assert(c->r1_lit < 4);
|
||||
m_off -= 1;
|
||||
*op++ = M1_MARKER | ((m_off & 3) << 2);
|
||||
*op++ = m_off >> 2;
|
||||
} else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) {
|
||||
assert(m_len >= 3);
|
||||
m_off -= 1;
|
||||
*op++ = ((m_len - 1) << 5) | ((m_off & 7) << 2);
|
||||
*op++ = m_off >> 3;
|
||||
assert(op[-2] >= M2_MARKER);
|
||||
} else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4) {
|
||||
assert(m_len == 3);
|
||||
assert(m_off > M2_MAX_OFFSET);
|
||||
m_off -= 1 + M2_MAX_OFFSET;
|
||||
*op++ = M1_MARKER | ((m_off & 3) << 2);
|
||||
*op++ = m_off >> 2;
|
||||
} else if (m_off <= M3_MAX_OFFSET) {
|
||||
assert(m_len >= 3);
|
||||
m_off -= 1;
|
||||
if (m_len <= M3_MAX_LEN)
|
||||
*op++ = M3_MARKER | (m_len - 2);
|
||||
else {
|
||||
m_len -= M3_MAX_LEN;
|
||||
*op++ = M3_MARKER | 0;
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = m_len;
|
||||
}
|
||||
*op++ = m_off << 2;
|
||||
*op++ = m_off >> 6;
|
||||
} else {
|
||||
unsigned k;
|
||||
|
||||
assert(m_len >= 3);
|
||||
assert(m_off > 0x4000);
|
||||
assert(m_off <= 0xbfff);
|
||||
m_off -= 0x4000;
|
||||
k = (m_off & 0x4000) >> 11;
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
*op++ = M4_MARKER | k | (m_len - 2);
|
||||
else {
|
||||
m_len -= M4_MAX_LEN;
|
||||
*op++ = M4_MARKER | k | 0;
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = m_len;
|
||||
}
|
||||
*op++ = m_off << 2;
|
||||
*op++ = m_off >> 6;
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t *STORE_RUN(lzo1x_999_t *c, uint8_t *op,
|
||||
const uint8_t *ii, unsigned t)
|
||||
{
|
||||
if (op == c->out && t <= 238) {
|
||||
*op++ = 17 + t;
|
||||
} else if (t <= 3) {
|
||||
op[-2] |= t;
|
||||
} else if (t <= 18) {
|
||||
*op++ = t - 3;
|
||||
} else {
|
||||
unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = tt;
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t *code_run(lzo1x_999_t *c, uint8_t *op, const uint8_t *ii,
|
||||
unsigned lit)
|
||||
{
|
||||
if (lit > 0) {
|
||||
assert(m_len >= 2);
|
||||
op = STORE_RUN(c, op, ii, lit);
|
||||
} else {
|
||||
assert(m_len >= 3);
|
||||
}
|
||||
c->r1_lit = lit;
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int len_of_coded_match(unsigned m_len, unsigned m_off, unsigned lit)
|
||||
{
|
||||
int n = 4;
|
||||
|
||||
if (m_len < 2)
|
||||
return -1;
|
||||
if (m_len == 2)
|
||||
return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : -1;
|
||||
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
|
||||
return 2;
|
||||
if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
|
||||
return 2;
|
||||
if (m_off <= M3_MAX_OFFSET) {
|
||||
if (m_len <= M3_MAX_LEN)
|
||||
return 3;
|
||||
m_len -= M3_MAX_LEN;
|
||||
} else if (m_off <= M4_MAX_OFFSET) {
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
return 3;
|
||||
m_len -= M4_MAX_LEN;
|
||||
} else
|
||||
return -1;
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
static int min_gain(unsigned ahead, unsigned lit1,
|
||||
unsigned lit2, int l1, int l2, int l3)
|
||||
{
|
||||
int lazy_match_min_gain = 0;
|
||||
|
||||
assert (ahead >= 1);
|
||||
lazy_match_min_gain += ahead;
|
||||
|
||||
if (lit1 <= 3)
|
||||
lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
|
||||
else if (lit1 <= 18)
|
||||
lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
|
||||
|
||||
lazy_match_min_gain += (l2 - l1) * 2;
|
||||
if (l3 > 0)
|
||||
lazy_match_min_gain -= (ahead - l3) * 2;
|
||||
|
||||
if (lazy_match_min_gain < 0)
|
||||
lazy_match_min_gain = 0;
|
||||
|
||||
return lazy_match_min_gain;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#if defined(SWD_BEST_OFF)
|
||||
|
||||
static void better_match(const lzo_swd_p swd,
|
||||
unsigned *m_len, unsigned *m_off)
|
||||
{
|
||||
if (*m_len <= M2_MIN_LEN)
|
||||
return;
|
||||
|
||||
if (*m_off <= M2_MAX_OFFSET)
|
||||
return;
|
||||
|
||||
/* M3/M4 -> M2 */
|
||||
if (*m_off > M2_MAX_OFFSET
|
||||
&& *m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1
|
||||
&& swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET
|
||||
) {
|
||||
*m_len = *m_len - 1;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
return;
|
||||
}
|
||||
|
||||
/* M4 -> M2 */
|
||||
if (*m_off > M3_MAX_OFFSET
|
||||
&& *m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2
|
||||
&& swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET
|
||||
) {
|
||||
*m_len = *m_len - 2;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
return;
|
||||
}
|
||||
/* M4 -> M3 */
|
||||
if (*m_off > M3_MAX_OFFSET
|
||||
&& *m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1
|
||||
&& swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET
|
||||
) {
|
||||
*m_len = *m_len - 1;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
unsigned max_lazy,
|
||||
unsigned max_chain,
|
||||
uint32_t use_best_off)
|
||||
{
|
||||
uint8_t *op;
|
||||
const uint8_t *ii;
|
||||
unsigned lit;
|
||||
unsigned m_len, m_off;
|
||||
lzo1x_999_t cc;
|
||||
lzo1x_999_t *const c = &cc;
|
||||
const lzo_swd_p swd = (lzo_swd_p) wrkmem;
|
||||
int r;
|
||||
|
||||
c->init = 0;
|
||||
c->ip = c->in = in;
|
||||
c->in_end = in + in_len;
|
||||
c->out = out;
|
||||
|
||||
op = out;
|
||||
ii = c->ip; /* point to start of literal run */
|
||||
lit = 0;
|
||||
c->r1_lit = 0;
|
||||
|
||||
r = init_match(c, swd, use_best_off);
|
||||
if (r != 0)
|
||||
return r;
|
||||
swd->max_chain = max_chain;
|
||||
|
||||
r = find_match(c, swd, 0, 0);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
while (c->look > 0) {
|
||||
unsigned ahead;
|
||||
unsigned max_ahead;
|
||||
int l1, l2, l3;
|
||||
|
||||
m_len = c->m_len;
|
||||
m_off = c->m_off;
|
||||
|
||||
assert(c->bp == c->ip - c->look);
|
||||
assert(c->bp >= in);
|
||||
if (lit == 0)
|
||||
ii = c->bp;
|
||||
assert(ii + lit == c->bp);
|
||||
assert(swd->b_char == *(c->bp));
|
||||
|
||||
if (m_len < 2
|
||||
|| (m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4))
|
||||
/* Do not accept this match for compressed-data compatibility
|
||||
* with LZO v1.01 and before
|
||||
* [ might be a problem for decompress() and optimize() ]
|
||||
*/
|
||||
|| (m_len == 2 && op == out)
|
||||
|| (op == out && lit == 0)
|
||||
) {
|
||||
/* a literal */
|
||||
m_len = 0;
|
||||
}
|
||||
else if (m_len == M2_MIN_LEN) {
|
||||
/* compression ratio improves if we code a literal in some cases */
|
||||
if (m_off > MX_MAX_OFFSET && lit >= 4)
|
||||
m_len = 0;
|
||||
}
|
||||
|
||||
if (m_len == 0) {
|
||||
/* a literal */
|
||||
lit++;
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c, swd, 1, 0);
|
||||
assert(r == 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* a match */
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (swd->use_best_off)
|
||||
better_match(swd, &m_len, &m_off);
|
||||
#endif
|
||||
/* shall we try a lazy match ? */
|
||||
ahead = 0;
|
||||
if (m_len >= max_lazy) {
|
||||
/* no */
|
||||
l1 = 0;
|
||||
max_ahead = 0;
|
||||
} else {
|
||||
/* yes, try a lazy match */
|
||||
l1 = len_of_coded_match(m_len, m_off, lit);
|
||||
assert(l1 > 0);
|
||||
max_ahead = LZO_MIN(2, (unsigned)l1 - 1);
|
||||
}
|
||||
|
||||
while (ahead < max_ahead && c->look > m_len) {
|
||||
int lazy_match_min_gain;
|
||||
|
||||
if (m_len >= good_length)
|
||||
swd->max_chain = max_chain >> 2;
|
||||
else
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c, swd, 1, 0);
|
||||
ahead++;
|
||||
|
||||
assert(r == 0);
|
||||
assert(c->look > 0);
|
||||
assert(ii + lit + ahead == c->bp);
|
||||
|
||||
if (c->m_len < m_len)
|
||||
continue;
|
||||
if (c->m_len == m_len && c->m_off >= m_off)
|
||||
continue;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (swd->use_best_off)
|
||||
better_match(swd, &c->m_len, &c->m_off);
|
||||
#endif
|
||||
l2 = len_of_coded_match(c->m_len, c->m_off, lit+ahead);
|
||||
if (l2 < 0)
|
||||
continue;
|
||||
|
||||
/* compressed-data compatibility [see above] */
|
||||
l3 = (op == out) ? -1 : len_of_coded_match(ahead, m_off, lit);
|
||||
|
||||
lazy_match_min_gain = min_gain(ahead, lit, lit+ahead, l1, l2, l3);
|
||||
if (c->m_len >= m_len + lazy_match_min_gain) {
|
||||
if (l3 > 0) {
|
||||
/* code previous run */
|
||||
op = code_run(c, op, ii, lit);
|
||||
lit = 0;
|
||||
/* code shortened match */
|
||||
op = code_match(c, op, ahead, m_off);
|
||||
} else {
|
||||
lit += ahead;
|
||||
assert(ii + lit == c->bp);
|
||||
}
|
||||
goto lazy_match_done;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ii + lit + ahead == c->bp);
|
||||
|
||||
/* 1 - code run */
|
||||
op = code_run(c, op, ii, lit);
|
||||
lit = 0;
|
||||
|
||||
/* 2 - code match */
|
||||
op = code_match(c, op, m_len, m_off);
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c, swd, m_len, 1+ahead);
|
||||
assert(r == 0);
|
||||
|
||||
lazy_match_done: ;
|
||||
}
|
||||
|
||||
/* store final run */
|
||||
if (lit > 0)
|
||||
op = STORE_RUN(c, op, ii, lit);
|
||||
|
||||
#if defined(LZO_EOF_CODE)
|
||||
*op++ = M4_MARKER | 1;
|
||||
*op++ = 0;
|
||||
*op++ = 0;
|
||||
#endif
|
||||
|
||||
*out_len = op - out;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
int lzo1x_999_compress_level(const uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
int compression_level)
|
||||
{
|
||||
static const struct {
|
||||
uint16_t good_length;
|
||||
uint16_t max_lazy;
|
||||
uint16_t max_chain;
|
||||
uint16_t use_best_off;
|
||||
} c[3] = {
|
||||
{ 8, 32, 256, 0 },
|
||||
{ 32, 128, 2048, 1 },
|
||||
{ SWD_F, SWD_F, 4096, 1 } /* max. compression */
|
||||
};
|
||||
|
||||
if (compression_level < 7 || compression_level > 9)
|
||||
return LZO_E_ERROR;
|
||||
|
||||
compression_level -= 7;
|
||||
return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
|
||||
c[compression_level].good_length,
|
||||
c[compression_level].max_lazy,
|
||||
c[compression_level].max_chain,
|
||||
c[compression_level].use_best_off);
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
/* implementation of the LZO1[XY]-1 compression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/***********************************************************************
|
||||
// compress a block of data.
|
||||
************************************************************************/
|
||||
static NOINLINE unsigned
|
||||
do_compress(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem)
|
||||
{
|
||||
register const uint8_t* ip;
|
||||
uint8_t* op;
|
||||
const uint8_t* const in_end = in + in_len;
|
||||
const uint8_t* const ip_end = in + in_len - M2_MAX_LEN - 5;
|
||||
const uint8_t* ii;
|
||||
const void* *const dict = (const void**) wrkmem;
|
||||
|
||||
op = out;
|
||||
ip = in;
|
||||
ii = ip;
|
||||
|
||||
ip += 4;
|
||||
for (;;) {
|
||||
register const uint8_t* m_pos;
|
||||
unsigned m_off;
|
||||
unsigned m_len;
|
||||
unsigned dindex;
|
||||
|
||||
D_INDEX1(dindex,ip);
|
||||
GINDEX(m_pos,m_off,dict,dindex,in);
|
||||
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
||||
goto literal;
|
||||
#if 1
|
||||
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
||||
goto try_match;
|
||||
D_INDEX2(dindex,ip);
|
||||
#endif
|
||||
GINDEX(m_pos,m_off,dict,dindex,in);
|
||||
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
||||
goto literal;
|
||||
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
||||
goto try_match;
|
||||
goto literal;
|
||||
|
||||
try_match:
|
||||
#if 1 && defined(LZO_UNALIGNED_OK_2)
|
||||
if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
|
||||
#else
|
||||
if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
if (m_pos[2] == ip[2]) {
|
||||
#if 0
|
||||
if (m_off <= M2_MAX_OFFSET)
|
||||
goto match;
|
||||
if (lit <= 3)
|
||||
goto match;
|
||||
if (lit == 3) { /* better compression, but slower */
|
||||
assert(op - 2 > out); op[-2] |= (uint8_t)(3);
|
||||
*op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
|
||||
goto code_match;
|
||||
}
|
||||
if (m_pos[3] == ip[3])
|
||||
#endif
|
||||
goto match;
|
||||
}
|
||||
else {
|
||||
/* still need a better way for finding M1 matches */
|
||||
#if 0
|
||||
/* a M1 match */
|
||||
#if 0
|
||||
if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
|
||||
#else
|
||||
if (m_off <= M1_MAX_OFFSET && lit == 3)
|
||||
#endif
|
||||
{
|
||||
register unsigned t;
|
||||
|
||||
t = lit;
|
||||
assert(op - 2 > out); op[-2] |= (uint8_t)(t);
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
assert(ii == ip);
|
||||
m_off -= 1;
|
||||
*op++ = (uint8_t)(M1_MARKER | ((m_off & 3) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 2);
|
||||
ip += 2;
|
||||
goto match_done;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* a literal */
|
||||
literal:
|
||||
UPDATE_I(dict, 0, dindex, ip, in);
|
||||
++ip;
|
||||
if (ip >= ip_end)
|
||||
break;
|
||||
continue;
|
||||
|
||||
/* a match */
|
||||
match:
|
||||
UPDATE_I(dict, 0, dindex, ip, in);
|
||||
/* store current literal run */
|
||||
if (pd(ip, ii) > 0) {
|
||||
register unsigned t = pd(ip, ii);
|
||||
|
||||
if (t <= 3) {
|
||||
assert(op - 2 > out);
|
||||
op[-2] |= (uint8_t)(t);
|
||||
}
|
||||
else if (t <= 18)
|
||||
*op++ = (uint8_t)(t - 3);
|
||||
else {
|
||||
register unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = (uint8_t)(tt);
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
}
|
||||
|
||||
/* code the match */
|
||||
assert(ii == ip);
|
||||
ip += 3;
|
||||
if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++
|
||||
|| m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++
|
||||
#ifdef LZO1Y
|
||||
|| m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++
|
||||
|| m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++
|
||||
#endif
|
||||
) {
|
||||
--ip;
|
||||
m_len = pd(ip, ii);
|
||||
assert(m_len >= 3);
|
||||
assert(m_len <= M2_MAX_LEN);
|
||||
|
||||
if (m_off <= M2_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
#if defined(LZO1X)
|
||||
*op++ = (uint8_t)(((m_len - 1) << 5) | ((m_off & 7) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 3);
|
||||
#elif defined(LZO1Y)
|
||||
*op++ = (uint8_t)(((m_len + 1) << 4) | ((m_off & 3) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 2);
|
||||
#endif
|
||||
}
|
||||
else if (m_off <= M3_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
|
||||
goto m3_m4_offset;
|
||||
} else {
|
||||
#if defined(LZO1X)
|
||||
m_off -= 0x4000;
|
||||
assert(m_off > 0);
|
||||
assert(m_off <= 0x7fff);
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
||||
goto m3_m4_offset;
|
||||
#elif defined(LZO1Y)
|
||||
goto m4_match;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
{
|
||||
const uint8_t* end = in_end;
|
||||
const uint8_t* m = m_pos + M2_MAX_LEN + 1;
|
||||
while (ip < end && *m == *ip)
|
||||
m++, ip++;
|
||||
m_len = pd(ip, ii);
|
||||
}
|
||||
assert(m_len > M2_MAX_LEN);
|
||||
|
||||
if (m_off <= M3_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
if (m_len <= 33)
|
||||
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
|
||||
else {
|
||||
m_len -= 33;
|
||||
*op++ = M3_MARKER | 0;
|
||||
goto m3_m4_len;
|
||||
}
|
||||
} else {
|
||||
#if defined(LZO1Y)
|
||||
m4_match:
|
||||
#endif
|
||||
m_off -= 0x4000;
|
||||
assert(m_off > 0);
|
||||
assert(m_off <= 0x7fff);
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
||||
else {
|
||||
m_len -= M4_MAX_LEN;
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11));
|
||||
m3_m4_len:
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = (uint8_t)(m_len);
|
||||
}
|
||||
}
|
||||
m3_m4_offset:
|
||||
*op++ = (uint8_t)((m_off & 63) << 2);
|
||||
*op++ = (uint8_t)(m_off >> 6);
|
||||
}
|
||||
#if 0
|
||||
match_done:
|
||||
#endif
|
||||
ii = ip;
|
||||
if (ip >= ip_end)
|
||||
break;
|
||||
}
|
||||
|
||||
*out_len = pd(op, out);
|
||||
return pd(in_end, ii);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
// public entry point
|
||||
************************************************************************/
|
||||
int DO_COMPRESS(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem)
|
||||
{
|
||||
uint8_t* op = out;
|
||||
unsigned t;
|
||||
|
||||
if (in_len <= M2_MAX_LEN + 5)
|
||||
t = in_len;
|
||||
else {
|
||||
t = do_compress(in,in_len,op,out_len,wrkmem);
|
||||
op += *out_len;
|
||||
}
|
||||
|
||||
if (t > 0) {
|
||||
const uint8_t* ii = in + in_len - t;
|
||||
|
||||
if (op == out && t <= 238)
|
||||
*op++ = (uint8_t)(17 + t);
|
||||
else if (t <= 3)
|
||||
op[-2] |= (uint8_t)(t);
|
||||
else if (t <= 18)
|
||||
*op++ = (uint8_t)(t - 3);
|
||||
else {
|
||||
unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = (uint8_t)(tt);
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
}
|
||||
|
||||
*op++ = M4_MARKER | 1;
|
||||
*op++ = 0;
|
||||
*op++ = 0;
|
||||
|
||||
*out_len = pd(op, out);
|
||||
return 0; /*LZO_E_OK*/
|
||||
}
|
||||
@@ -1,422 +0,0 @@
|
||||
/* implementation of the LZO1X decompression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
/***********************************************************************
|
||||
// decompress a block of data.
|
||||
************************************************************************/
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len /*, void* wrkmem */)
|
||||
{
|
||||
register uint8_t* op;
|
||||
register const uint8_t* ip;
|
||||
register unsigned t;
|
||||
#if defined(COPY_DICT)
|
||||
unsigned m_off;
|
||||
const uint8_t* dict_end;
|
||||
#else
|
||||
register const uint8_t* m_pos = NULL; /* possibly not needed */
|
||||
#endif
|
||||
const uint8_t* const ip_end = in + in_len;
|
||||
#if defined(HAVE_ANY_OP)
|
||||
uint8_t* const op_end = out + *out_len;
|
||||
#endif
|
||||
#if defined(LZO1Z)
|
||||
unsigned last_m_off = 0;
|
||||
#endif
|
||||
|
||||
// LZO_UNUSED(wrkmem);
|
||||
|
||||
#if defined(COPY_DICT)
|
||||
if (dict) {
|
||||
if (dict_len > M4_MAX_OFFSET) {
|
||||
dict += dict_len - M4_MAX_OFFSET;
|
||||
dict_len = M4_MAX_OFFSET;
|
||||
}
|
||||
dict_end = dict + dict_len;
|
||||
} else {
|
||||
dict_len = 0;
|
||||
dict_end = NULL;
|
||||
}
|
||||
#endif /* COPY_DICT */
|
||||
|
||||
*out_len = 0;
|
||||
|
||||
op = out;
|
||||
ip = in;
|
||||
|
||||
if (*ip > 17) {
|
||||
t = *ip++ - 17;
|
||||
if (t < 4)
|
||||
goto match_next;
|
||||
assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
goto first_literal_run;
|
||||
}
|
||||
|
||||
while (TEST_IP && TEST_OP) {
|
||||
t = *ip++;
|
||||
if (t >= 16)
|
||||
goto match;
|
||||
/* a literal run */
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 15 + *ip++;
|
||||
}
|
||||
/* copy literals */
|
||||
assert(t > 0);
|
||||
NEED_OP(t+3);
|
||||
NEED_IP(t+4);
|
||||
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
if (PTR_ALIGNED2_4(op, ip))
|
||||
# endif
|
||||
{
|
||||
COPY4(op, ip);
|
||||
op += 4;
|
||||
ip += 4;
|
||||
if (--t > 0) {
|
||||
if (t >= 4) {
|
||||
do {
|
||||
COPY4(op, ip);
|
||||
op += 4;
|
||||
ip += 4;
|
||||
t -= 4;
|
||||
} while (t >= 4);
|
||||
if (t > 0)
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
} else {
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
else
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(LZO_UNALIGNED_OK_4)
|
||||
{
|
||||
*op++ = *ip++;
|
||||
*op++ = *ip++;
|
||||
*op++ = *ip++;
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
first_literal_run:
|
||||
t = *ip++;
|
||||
if (t >= 16)
|
||||
goto match;
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
|
||||
#endif
|
||||
NEED_OP(3);
|
||||
t = 3; COPY_DICT(t,m_off)
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
||||
m_pos = op - t;
|
||||
last_m_off = t;
|
||||
#else
|
||||
m_pos = op - (1 + M2_MAX_OFFSET);
|
||||
m_pos -= t >> 2;
|
||||
m_pos -= *ip++ << 2;
|
||||
#endif
|
||||
TEST_LB(m_pos); NEED_OP(3);
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos;
|
||||
#endif /* COPY_DICT */
|
||||
goto match_done;
|
||||
|
||||
/* handle matches */
|
||||
do {
|
||||
match:
|
||||
if (t >= 64) { /* a M2 match */
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1X)
|
||||
m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
|
||||
t = (t >> 5) - 1;
|
||||
#elif defined(LZO1Y)
|
||||
m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
|
||||
t = (t >> 4) - 3;
|
||||
#elif defined(LZO1Z)
|
||||
m_off = t & 0x1f;
|
||||
if (m_off >= 0x1c)
|
||||
m_off = last_m_off;
|
||||
else {
|
||||
m_off = 1 + (m_off << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
}
|
||||
t = (t >> 5) - 1;
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1X)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (t >> 2) & 7;
|
||||
m_pos -= *ip++ << 3;
|
||||
t = (t >> 5) - 1;
|
||||
#elif defined(LZO1Y)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (t >> 2) & 3;
|
||||
m_pos -= *ip++ << 2;
|
||||
t = (t >> 4) - 3;
|
||||
#elif defined(LZO1Z)
|
||||
{
|
||||
unsigned off = t & 0x1f;
|
||||
m_pos = op;
|
||||
if (off >= 0x1c) {
|
||||
assert(last_m_off > 0);
|
||||
m_pos -= last_m_off;
|
||||
} else {
|
||||
off = 1 + (off << 6) + (*ip++ >> 2);
|
||||
m_pos -= off;
|
||||
last_m_off = off;
|
||||
}
|
||||
}
|
||||
t = (t >> 5) - 1;
|
||||
#endif
|
||||
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
|
||||
goto copy_match;
|
||||
#endif /* COPY_DICT */
|
||||
}
|
||||
else if (t >= 32) { /* a M3 match */
|
||||
t &= 31;
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 31 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
{
|
||||
unsigned off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
||||
m_pos = op - off;
|
||||
last_m_off = off;
|
||||
}
|
||||
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
||||
#else
|
||||
m_pos = op - 1;
|
||||
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
#endif /* COPY_DICT */
|
||||
ip += 2;
|
||||
}
|
||||
else if (t >= 16) { /* a M4 match */
|
||||
#if defined(COPY_DICT)
|
||||
m_off = (t & 8) << 11;
|
||||
#else /* !COPY_DICT */
|
||||
m_pos = op;
|
||||
m_pos -= (t & 8) << 11;
|
||||
#endif /* COPY_DICT */
|
||||
t &= 7;
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 7 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off += (ip[0] << 6) + (ip[1] >> 2);
|
||||
#else
|
||||
m_off += (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
ip += 2;
|
||||
if (m_off == 0)
|
||||
goto eof_found;
|
||||
m_off += 0x4000;
|
||||
#if defined(LZO1Z)
|
||||
last_m_off = m_off;
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
m_pos -= (ip[0] << 6) + (ip[1] >> 2);
|
||||
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
|
||||
m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
||||
#else
|
||||
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
ip += 2;
|
||||
if (m_pos == op)
|
||||
goto eof_found;
|
||||
m_pos -= 0x4000;
|
||||
#if defined(LZO1Z)
|
||||
last_m_off = pd((const uint8_t*)op, m_pos);
|
||||
#endif
|
||||
#endif /* COPY_DICT */
|
||||
}
|
||||
else { /* a M1 match */
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = 1 + (t << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = 1 + (t >> 2) + (*ip++ << 2);
|
||||
#endif
|
||||
NEED_OP(2);
|
||||
t = 2; COPY_DICT(t,m_off)
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
t = 1 + (t << 6) + (*ip++ >> 2);
|
||||
m_pos = op - t;
|
||||
last_m_off = t;
|
||||
#else
|
||||
m_pos = op - 1;
|
||||
m_pos -= t >> 2;
|
||||
m_pos -= *ip++ << 2;
|
||||
#endif
|
||||
TEST_LB(m_pos); NEED_OP(2);
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos;
|
||||
#endif /* COPY_DICT */
|
||||
goto match_done;
|
||||
}
|
||||
|
||||
/* copy match */
|
||||
#if defined(COPY_DICT)
|
||||
|
||||
NEED_OP(t+3-1);
|
||||
t += 3-1; COPY_DICT(t,m_off)
|
||||
|
||||
#else /* !COPY_DICT */
|
||||
|
||||
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
|
||||
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) {
|
||||
assert((op - m_pos) >= 4); /* both pointers are aligned */
|
||||
# else
|
||||
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
|
||||
# endif
|
||||
COPY4(op,m_pos);
|
||||
op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
||||
do {
|
||||
COPY4(op,m_pos);
|
||||
op += 4; m_pos += 4; t -= 4;
|
||||
} while (t >= 4);
|
||||
if (t > 0)
|
||||
do *op++ = *m_pos++; while (--t > 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
copy_match:
|
||||
*op++ = *m_pos++; *op++ = *m_pos++;
|
||||
do *op++ = *m_pos++; while (--t > 0);
|
||||
}
|
||||
|
||||
#endif /* COPY_DICT */
|
||||
|
||||
match_done:
|
||||
#if defined(LZO1Z)
|
||||
t = ip[-1] & 3;
|
||||
#else
|
||||
t = ip[-2] & 3;
|
||||
#endif
|
||||
if (t == 0)
|
||||
break;
|
||||
|
||||
/* copy literals */
|
||||
match_next:
|
||||
assert(t > 0);
|
||||
assert(t < 4);
|
||||
NEED_OP(t);
|
||||
NEED_IP(t+1);
|
||||
#if 0
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
#else
|
||||
*op++ = *ip++;
|
||||
if (t > 1) {
|
||||
*op++ = *ip++;
|
||||
if (t > 2)
|
||||
*op++ = *ip++;
|
||||
}
|
||||
#endif
|
||||
t = *ip++;
|
||||
} while (TEST_IP && TEST_OP);
|
||||
}
|
||||
|
||||
//#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
||||
/* no EOF code was found */
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_EOF_NOT_FOUND;
|
||||
//#endif
|
||||
|
||||
eof_found:
|
||||
assert(t == 1);
|
||||
*out_len = pd(op, out);
|
||||
return (ip == ip_end ? LZO_E_OK :
|
||||
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
||||
|
||||
//#if defined(HAVE_NEED_IP)
|
||||
input_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_INPUT_OVERRUN;
|
||||
//#endif
|
||||
|
||||
//#if defined(HAVE_NEED_OP)
|
||||
output_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_OUTPUT_OVERRUN;
|
||||
//#endif
|
||||
|
||||
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
|
||||
lookbehind_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_LOOKBEHIND_OVERRUN;
|
||||
//#endif
|
||||
}
|
||||
@@ -1,388 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
|
||||
{
|
||||
memset(xstate, 0, sizeof(*xstate));
|
||||
}
|
||||
|
||||
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
{
|
||||
if (!xstate->signature_skipped) {
|
||||
uint16_t magic2;
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
bb_simple_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
xstate->signature_skipped = 2;
|
||||
}
|
||||
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_simple_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;
|
||||
|
||||
if (!signo) {
|
||||
/* block waiting for any child */
|
||||
if (wait(&status) < 0)
|
||||
//FIXME: check EINTR?
|
||||
return; /* probably there are no children */
|
||||
goto check_status;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
/* this child exited with 0 */
|
||||
continue;
|
||||
/* 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,
|
||||
int signature_skipped,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
)
|
||||
#else
|
||||
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
#endif
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
int pid;
|
||||
|
||||
xpiped_pair(fd_pipe);
|
||||
pid = BB_MMU ? xfork() : xvfork();
|
||||
if (pid == 0) {
|
||||
/* Child */
|
||||
close(fd_pipe.rd); /* we don't want to read from the parent */
|
||||
// FIXME: error check?
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.signature_skipped = signature_skipped;
|
||||
xstate.src_fd = fd;
|
||||
xstate.dst_fd = fd_pipe.wr;
|
||||
r = transformer(&xstate);
|
||||
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);
|
||||
}
|
||||
#else
|
||||
{
|
||||
char *argv[4];
|
||||
xmove_fd(fd, 0);
|
||||
xmove_fd(fd_pipe.wr, 1);
|
||||
argv[0] = (char*)transform_prog;
|
||||
argv[1] = (char*)"-cf";
|
||||
argv[2] = (char*)"-";
|
||||
argv[3] = NULL;
|
||||
BB_EXECVP(transform_prog, argv);
|
||||
bb_perror_msg_and_die("can't execute '%s'", transform_prog);
|
||||
}
|
||||
#endif
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
/* parent process */
|
||||
close(fd_pipe.wr); /* don't want to write to the child */
|
||||
xmove_fd(fd_pipe.rd, fd);
|
||||
}
|
||||
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
|
||||
/* 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 die_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
|
||||
/* .gz and .bz2 both have 2-byte signature, and their
|
||||
* unpack_XXX_stream wants this header skipped. */
|
||||
xstate->signature_skipped = 2;
|
||||
xread(fd, xstate->magic.b16, 2);
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& xstate->magic.b16[0] == GZIP_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_gz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_Z
|
||||
&& xstate->magic.b16[0] == COMPRESS_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_Z_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& xstate->magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_bz2_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& xstate->magic.b16[0] == XZ_MAGIC1
|
||||
) {
|
||||
uint32_t v32;
|
||||
xstate->signature_skipped = 6;
|
||||
xread(fd, &xstate->magic.b16[1], 4);
|
||||
move_from_unaligned32(v32, &xstate->magic.b16[1]);
|
||||
if (v32 == XZ_MAGIC2) {
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
}
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (die_if_not_compressed)
|
||||
bb_simple_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";)
|
||||
|
||||
found_magic:
|
||||
return xstate;
|
||||
}
|
||||
|
||||
static void fork_transformer_and_free(transformer_state_t *xstate)
|
||||
{
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
/* NOMMU version of fork_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
# endif
|
||||
free(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 die_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, die_if_not_compressed);
|
||||
|
||||
if (!xstate->xformer) {
|
||||
/* Not compressed */
|
||||
int retval = xstate->signature_skipped; /* never zero */
|
||||
free(xstate);
|
||||
return retval;
|
||||
}
|
||||
|
||||
fork_transformer_and_free(xstate);
|
||||
return 0;
|
||||
}
|
||||
#if ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
/* ...and custom version for LZMA */
|
||||
void FAST_FUNC setup_lzma_on_fd(int fd)
|
||||
{
|
||||
transformer_state_t *xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
fork_transformer_and_free(xstate);
|
||||
}
|
||||
#endif
|
||||
|
||||
static transformer_state_t *open_transformer(const char *fname, int die_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
if (is_suffixed_with(fname, ".lzma")) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
return xstate;
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, die_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int die_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, die_if_not_compressed);
|
||||
if (!xstate) /* open error */
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
# if BB_MMU
|
||||
if (xstate->xformer) {
|
||||
fork_transformer_with_no_sig(fd, xstate->xformer);
|
||||
} else {
|
||||
/* the file is not compressed */
|
||||
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
}
|
||||
# else
|
||||
/* NOMMU can't avoid the seek :( */
|
||||
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
if (xstate->xformer) {
|
||||
fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
|
||||
} /* else: the file is not compressed */
|
||||
# endif
|
||||
|
||||
free(xstate);
|
||||
return fd;
|
||||
}
|
||||
|
||||
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, /*die_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.
|
||||
* We already read first few bytes, account for that.
|
||||
* Example where it happens:
|
||||
* "modinfo MODULE.ko" (not compressed)
|
||||
* open("MODULE.ko", O_RDONLY|O_LARGEFILE) = 4
|
||||
* read(4, "\177E", 2) = 2
|
||||
* fstat64(4, ...)
|
||||
* mmap(...)
|
||||
* read(4, "LF\2\1\1\0\0\0\0"...
|
||||
* ...and we avoided seeking on the fd! :)
|
||||
*/
|
||||
image = xmalloc_read_with_initial_buf(
|
||||
xstate->src_fd,
|
||||
maxsz_p,
|
||||
xmemdup(&xstate->magic, xstate->signature_skipped),
|
||||
xstate->signature_skipped
|
||||
);
|
||||
xstate->signature_skipped = 0;
|
||||
}
|
||||
|
||||
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, /*die_if_not_compressed:*/ 0);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
image = xmalloc_read(fd, maxsz_p);
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(fd);
|
||||
return image;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
@@ -1,18 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC seek_by_jump(int fd, off_t amount)
|
||||
{
|
||||
if (amount
|
||||
&& lseek(fd, amount, SEEK_CUR) == (off_t) -1
|
||||
) {
|
||||
if (errno == ESPIPE)
|
||||
seek_by_read(fd, amount);
|
||||
else
|
||||
bb_simple_perror_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
/* If we are reading through a pipe, or from stdin then we can't lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*/
|
||||
void FAST_FUNC seek_by_read(int fd, off_t amount)
|
||||
{
|
||||
if (amount)
|
||||
bb_copyfd_exact_size(fd, -1, amount);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "ar_.h"
|
||||
|
||||
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
char magic[7];
|
||||
|
||||
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
|
||||
if (!is_prefixed_with(magic, AR_MAGIC)) {
|
||||
bb_simple_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += AR_MAGIC_LEN;
|
||||
|
||||
while (get_header_ar(ar_archive) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char* FAST_FUNC skip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
|
||||
/* if "..": malicious, return "" */
|
||||
/* (causes harmless errors trying to create or hardlink a file named "") */
|
||||
if (cp[0] == '.' && cp[1] == '.' && cp[2] == '\0')
|
||||
return cp + 2;
|
||||
|
||||
while (1) {
|
||||
const char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
/* We are called lots of times.
|
||||
* is_prefixed_with(cp, "../") is slower than open-coding it,
|
||||
* with minimal code growth (~few bytes).
|
||||
*/
|
||||
if (cp[0] == '.' && cp[1] == '.' && cp[2] == '/') {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = cp;
|
||||
find_dotdot:
|
||||
cp2 = strstr(cp2, "/..");
|
||||
if (!cp2)
|
||||
break; /* No (more) malicious components */
|
||||
|
||||
/* We found "/..something" */
|
||||
cp2 += 3;
|
||||
if (*cp2 != '/') {
|
||||
if (*cp2 == '\0') {
|
||||
/* Trailing "/..": malicious, return "" */
|
||||
/* (causes harmless errors trying to create or hardlink a file named "") */
|
||||
return cp2;
|
||||
}
|
||||
/* "/..name" is not malicious, look for next "/.." */
|
||||
goto find_dotdot;
|
||||
}
|
||||
/* Found "/../": malicious, advance past it */
|
||||
cp = cp2 + 1;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
void FAST_FUNC strip_unsafe_prefix(char *str)
|
||||
{
|
||||
overlapping_strcpy(str, skip_unsafe_prefix(str));
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
|
||||
const char *target,
|
||||
const char *linkname,
|
||||
int hard_link)
|
||||
{
|
||||
if (hard_link || target[0] == '/' || strstr(target, "..")) {
|
||||
llist_add_to_end(link_placeholders,
|
||||
xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (symlink(target, linkname) != 0) {
|
||||
// shared message
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
"sym", linkname, target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static int all_dir_components_are_dirs(char *path)
|
||||
{
|
||||
struct stat sb;
|
||||
char *slash;
|
||||
|
||||
slash = path;
|
||||
while ((slash = strchr(slash, '/')) != NULL) {
|
||||
int ok;
|
||||
*slash = '\0';
|
||||
ok = (lstat(path, &sb) == 0 && S_ISDIR(sb.st_mode));
|
||||
*slash++ = '/';
|
||||
if (!ok)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void FAST_FUNC create_links_from_list(llist_t *list)
|
||||
{
|
||||
// This idea sounds better (fewer file ops):
|
||||
// Create hardlinks first, then symlinks.
|
||||
// ^^^ but it breaks the "hardlink to symlink" case:
|
||||
// mkdir dir
|
||||
// >dir/a
|
||||
// ln -s ../dir/a dir/b
|
||||
// ln dir/b dir/c
|
||||
// mkdir new; tar cf - dir/a dir/b dir/c | tar -C new -xvf -
|
||||
// On extract, 'c' will have no 'b' to be a hardlink to.
|
||||
|
||||
while (list) {
|
||||
char *target;
|
||||
char *linkname = list->data + 1;
|
||||
|
||||
target = linkname + strlen(linkname) + 1;
|
||||
|
||||
// Check whether the linkname has suspicious components:
|
||||
// SYMLINK_OUTSIDE_EXTRACT_DIR/etc/passwd sort of thing.
|
||||
// (Our delayed creation of symlinks is not defending against it,
|
||||
// we could create SYMLINK_OUTSIDE_EXTRACT_DIR ourself!)
|
||||
if (!all_dir_components_are_dirs(linkname)) {
|
||||
errno = ENOTDIR;
|
||||
goto err;
|
||||
}
|
||||
if ((list->data[0] ? link : symlink) (target, linkname)) {
|
||||
// shared message
|
||||
err:
|
||||
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
list->data[0] ? "hard" : "sym",
|
||||
linkname, target
|
||||
);
|
||||
// Note: GNU tar 1.34 errors out only _after_ all links are (attempted to be) created
|
||||
// We bail out at once
|
||||
}
|
||||
list = list->link;
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
|
||||
XZ Embedded
|
||||
===========
|
||||
|
||||
XZ Embedded is a relatively small, limited implementation of the .xz
|
||||
file format. Currently only decoding is implemented.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
read linux/Documentation/xz.txt even if you aren't using XZ Embedded
|
||||
as part of Linux; information in that file is not repeated in this
|
||||
README.
|
||||
|
||||
Compiling the Linux kernel module
|
||||
|
||||
The xz_dec module depends on crc32 module, so make sure that you have
|
||||
it enabled (CONFIG_CRC32).
|
||||
|
||||
Building the xz_dec and xz_dec_test modules without support for BCJ
|
||||
filters:
|
||||
|
||||
cd linux/lib/xz
|
||||
make -C /path/to/kernel/source \
|
||||
KCPPFLAGS=-I"$(pwd)/../../include" M="$(pwd)" \
|
||||
CONFIG_XZ_DEC=m CONFIG_XZ_DEC_TEST=m
|
||||
|
||||
Building the xz_dec and xz_dec_test modules with support for BCJ
|
||||
filters:
|
||||
|
||||
cd linux/lib/xz
|
||||
make -C /path/to/kernel/source \
|
||||
KCPPFLAGS=-I"$(pwd)/../../include" M="$(pwd)" \
|
||||
CONFIG_XZ_DEC=m CONFIG_XZ_DEC_TEST=m CONFIG_XZ_DEC_BCJ=y \
|
||||
CONFIG_XZ_DEC_X86=y CONFIG_XZ_DEC_POWERPC=y \
|
||||
CONFIG_XZ_DEC_IA64=y CONFIG_XZ_DEC_ARM=y \
|
||||
CONFIG_XZ_DEC_ARMTHUMB=y CONFIG_XZ_DEC_SPARC=y
|
||||
|
||||
If you want only one or a few of the BCJ filters, omit the appropriate
|
||||
variables. CONFIG_XZ_DEC_BCJ=y is always required to build the support
|
||||
code shared between all BCJ filters.
|
||||
|
||||
Most people don't need the xz_dec_test module. You can skip building
|
||||
it by omitting CONFIG_XZ_DEC_TEST=m from the make command line.
|
||||
|
||||
Compiler requirements
|
||||
|
||||
XZ Embedded should compile as either GNU-C89 (used in the Linux
|
||||
kernel) or with any C99 compiler. Getting the code to compile with
|
||||
non-GNU C89 compiler or a C++ compiler should be quite easy as
|
||||
long as there is a data type for unsigned 64-bit integer (or the
|
||||
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,
|
||||
xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when
|
||||
compiled with GCC 4.3.3.
|
||||
|
||||
Embedding into userspace applications
|
||||
|
||||
To embed the XZ decoder, copy the following files into a single
|
||||
directory in your source code tree:
|
||||
|
||||
linux/include/linux/xz.h
|
||||
linux/lib/xz/xz_crc32.c
|
||||
linux/lib/xz/xz_dec_lzma2.c
|
||||
linux/lib/xz/xz_dec_stream.c
|
||||
linux/lib/xz/xz_lzma2.h
|
||||
linux/lib/xz/xz_private.h
|
||||
linux/lib/xz/xz_stream.h
|
||||
userspace/xz_config.h
|
||||
|
||||
Alternatively, xz.h may be placed into a different directory but then
|
||||
that directory must be in the compiler include path when compiling
|
||||
the .c files.
|
||||
|
||||
Your code should use only the functions declared in xz.h. The rest of
|
||||
the .h files are meant only for internal use in XZ Embedded.
|
||||
|
||||
You may want to modify xz_config.h to be more suitable for your build
|
||||
environment. Probably you should at least skim through it even if the
|
||||
default file works as is.
|
||||
|
||||
BCJ filter support
|
||||
|
||||
If you want support for one or more BCJ filters, you need to copy also
|
||||
linux/lib/xz/xz_dec_bcj.c into your application, and use appropriate
|
||||
#defines in xz_config.h or in compiler flags. You don't need these
|
||||
#defines in the code that just uses XZ Embedded via xz.h, but having
|
||||
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_POWERPC PowerPC Big endian only
|
||||
XZ_DEC_IA64 Itanium (IA-64) Big or little endian
|
||||
XZ_DEC_ARM ARM Little endian only
|
||||
XZ_DEC_ARMTHUMB ARM-Thumb Little endian only
|
||||
XZ_DEC_SPARC SPARC Big or little endian
|
||||
|
||||
While some architectures are (partially) bi-endian, the endianness
|
||||
setting doesn't change the endianness of the instructions on all
|
||||
architectures. That's why Itanium and SPARC filters work for both big
|
||||
and little endian executables (Itanium has little endian instructions
|
||||
and SPARC has big endian instructions).
|
||||
|
||||
There currently is no filter for little endian PowerPC or big endian
|
||||
ARM or ARM-Thumb. Implementing filters for them can be considered if
|
||||
there is a need for such filters in real-world applications.
|
||||
|
||||
Notes about shared libraries
|
||||
|
||||
If you are including XZ Embedded into a shared library, you very
|
||||
probably should rename the xz_* functions to prevent symbol
|
||||
conflicts in case your library is linked against some other library
|
||||
or application that also has XZ Embedded in it (which may even be
|
||||
a different version of XZ Embedded). TODO: Provide an easy way
|
||||
to do this.
|
||||
|
||||
Please don't create a shared library of XZ Embedded itself unless
|
||||
it is fine to rebuild everything depending on that shared library
|
||||
everytime you upgrade to a newer version of XZ Embedded. There are
|
||||
no API or ABI stability guarantees between different versions of
|
||||
XZ Embedded.
|
||||
|
||||
Specifying the calling convention
|
||||
|
||||
XZ_FUNC macro was included to support declaring functions with __init
|
||||
in Linux. Outside Linux, it can be used to specify the calling
|
||||
convention on systems that support multiple calling conventions.
|
||||
For example, on Windows, you may make all functions use the stdcall
|
||||
calling convention by defining XZ_FUNC=__stdcall when building and
|
||||
using the functions from XZ Embedded.
|
||||
@@ -1,280 +0,0 @@
|
||||
/*
|
||||
* XZ decompressor
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef XZ_H
|
||||
#define XZ_H
|
||||
|
||||
#ifdef __KERNEL__
|
||||
# include <linux/stddef.h>
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <stddef.h>
|
||||
# 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
|
||||
#endif
|
||||
|
||||
/* In Linux, this is used to mark the functions with __init when needed. */
|
||||
#ifndef XZ_FUNC
|
||||
# define XZ_FUNC
|
||||
#endif
|
||||
|
||||
/**
|
||||
* enum xz_mode - Operation mode
|
||||
*
|
||||
* @XZ_SINGLE: Single-call mode. This uses less RAM than
|
||||
* than multi-call modes, because the LZMA2
|
||||
* dictionary doesn't need to be allocated as
|
||||
* part of the decoder state. All required data
|
||||
* structures are allocated at initialization,
|
||||
* so xz_dec_run() cannot return XZ_MEM_ERROR.
|
||||
* @XZ_PREALLOC: Multi-call mode with preallocated LZMA2
|
||||
* dictionary buffer. All data structures are
|
||||
* allocated at initialization, so xz_dec_run()
|
||||
* cannot return XZ_MEM_ERROR.
|
||||
* @XZ_DYNALLOC: Multi-call mode. The LZMA2 dictionary is
|
||||
* allocated once the required size has been
|
||||
* parsed from the stream headers. If the
|
||||
* allocation fails, xz_dec_run() will return
|
||||
* XZ_MEM_ERROR.
|
||||
*
|
||||
* It is possible to enable support only for a subset of the above
|
||||
* modes at compile time by defining XZ_DEC_SINGLE, XZ_DEC_PREALLOC,
|
||||
* or XZ_DEC_DYNALLOC. The xz_dec kernel module is always compiled
|
||||
* with support for all operation modes, but the preboot code may
|
||||
* be built with fewer features to minimize code size.
|
||||
*/
|
||||
enum xz_mode {
|
||||
XZ_SINGLE,
|
||||
XZ_PREALLOC,
|
||||
XZ_DYNALLOC
|
||||
};
|
||||
|
||||
/**
|
||||
* enum xz_ret - Return codes
|
||||
* @XZ_OK: Everything is OK so far. More input or more
|
||||
* output space is required to continue. This
|
||||
* return code is possible only in multi-call mode
|
||||
* (XZ_PREALLOC or XZ_DYNALLOC).
|
||||
* @XZ_STREAM_END: Operation finished successfully.
|
||||
* @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
|
||||
* XZ_DEC_ANY_CHECK was defined at build time,
|
||||
* which is not used in the kernel. Unsupported
|
||||
* check types return XZ_OPTIONS_ERROR if
|
||||
* XZ_DEC_ANY_CHECK was not defined at build time.
|
||||
* @XZ_MEM_ERROR: Allocating memory failed. This return code is
|
||||
* possible only if the decoder was initialized
|
||||
* with XZ_DYNALLOC. The amount of memory that was
|
||||
* tried to be allocated was no more than the
|
||||
* dict_max argument given to xz_dec_init().
|
||||
* @XZ_MEMLIMIT_ERROR: A bigger LZMA2 dictionary would be needed than
|
||||
* allowed by the dict_max argument given to
|
||||
* xz_dec_init(). This return value is possible
|
||||
* only in multi-call mode (XZ_PREALLOC or
|
||||
* XZ_DYNALLOC); the single-call mode (XZ_SINGLE)
|
||||
* ignores the dict_max argument.
|
||||
* @XZ_FORMAT_ERROR: File format was not recognized (wrong magic
|
||||
* bytes).
|
||||
* @XZ_OPTIONS_ERROR: This implementation doesn't support the requested
|
||||
* compression options. In the decoder this means
|
||||
* that the header CRC32 matches, but the header
|
||||
* itself specifies something that we don't support.
|
||||
* @XZ_DATA_ERROR: Compressed data is corrupt.
|
||||
* @XZ_BUF_ERROR: Cannot make any progress. Details are slightly
|
||||
* different between multi-call and single-call
|
||||
* mode; more information below.
|
||||
*
|
||||
* In multi-call mode, XZ_BUF_ERROR is returned when two consecutive calls
|
||||
* to XZ code cannot consume any input and cannot produce any new output.
|
||||
* This happens when there is no new input available, or the output buffer
|
||||
* is full while at least one output byte is still pending. Assuming your
|
||||
* code is not buggy, you can get this error only when decoding a compressed
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
enum xz_ret {
|
||||
XZ_OK,
|
||||
XZ_STREAM_END,
|
||||
XZ_UNSUPPORTED_CHECK,
|
||||
XZ_MEM_ERROR,
|
||||
XZ_MEMLIMIT_ERROR,
|
||||
XZ_FORMAT_ERROR,
|
||||
XZ_OPTIONS_ERROR,
|
||||
XZ_DATA_ERROR,
|
||||
XZ_BUF_ERROR
|
||||
};
|
||||
|
||||
/**
|
||||
* struct xz_buf - Passing input and output buffers to XZ code
|
||||
* @in: Beginning of the input buffer. This may be NULL if and only
|
||||
* if in_pos is equal to in_size.
|
||||
* @in_pos: Current position in the input buffer. This must not exceed
|
||||
* in_size.
|
||||
* @in_size: Size of the input buffer
|
||||
* @out: Beginning of the output buffer. This may be NULL if and only
|
||||
* if out_pos is equal to out_size.
|
||||
* @out_pos: Current position in the output buffer. This must not exceed
|
||||
* out_size.
|
||||
* @out_size: Size of the output buffer
|
||||
*
|
||||
* Only the contents of the output buffer from out[out_pos] onward, and
|
||||
* the variables in_pos and out_pos are modified by the XZ code.
|
||||
*/
|
||||
struct xz_buf {
|
||||
const uint8_t *in;
|
||||
size_t in_pos;
|
||||
size_t in_size;
|
||||
|
||||
uint8_t *out;
|
||||
size_t out_pos;
|
||||
size_t out_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct xz_dec - Opaque type to hold the XZ decoder state
|
||||
*/
|
||||
struct xz_dec;
|
||||
|
||||
/**
|
||||
* xz_dec_init() - Allocate and initialize a XZ decoder state
|
||||
* @mode: Operation mode
|
||||
* @dict_max: Maximum size of the LZMA2 dictionary (history buffer) for
|
||||
* multi-call decoding. This is ignored in single-call mode
|
||||
* (mode == XZ_SINGLE). LZMA2 dictionary is always 2^n bytes
|
||||
* or 2^n + 2^(n-1) bytes (the latter sizes are less common
|
||||
* in practice), so other values for dict_max don't make sense.
|
||||
* In the kernel, dictionary sizes of 64 KiB, 128 KiB, 256 KiB,
|
||||
* 512 KiB, and 1 MiB are probably the only reasonable values,
|
||||
* except for kernel and initramfs images where a bigger
|
||||
* dictionary can be fine and useful.
|
||||
*
|
||||
* Single-call mode (XZ_SINGLE): xz_dec_run() decodes the whole stream at
|
||||
* once. The caller must provide enough output space or the decoding will
|
||||
* fail. The output space is used as the dictionary buffer, which is why
|
||||
* there is no need to allocate the dictionary as part of the decoder's
|
||||
* internal state.
|
||||
*
|
||||
* Because the output buffer is used as the workspace, streams encoded using
|
||||
* a big dictionary are not a problem in single-call mode. It is enough that
|
||||
* the output buffer is big enough to hold the actual uncompressed data; it
|
||||
* can be smaller than the dictionary size stored in the stream headers.
|
||||
*
|
||||
* Multi-call mode with preallocated dictionary (XZ_PREALLOC): dict_max bytes
|
||||
* of memory is preallocated for the LZMA2 dictionary. This way there is no
|
||||
* risk that xz_dec_run() could run out of memory, since xz_dec_run() will
|
||||
* never allocate any memory. Instead, if the preallocated dictionary is too
|
||||
* small for decoding the given input stream, xz_dec_run() will return
|
||||
* XZ_MEMLIMIT_ERROR. Thus, it is important to know what kind of data will be
|
||||
* decoded to avoid allocating excessive amount of memory for the dictionary.
|
||||
*
|
||||
* Multi-call mode with dynamically allocated dictionary (XZ_DYNALLOC):
|
||||
* dict_max specifies the maximum allowed dictionary size that xz_dec_run()
|
||||
* may allocate once it has parsed the dictionary size from the stream
|
||||
* headers. This way excessive allocations can be avoided while still
|
||||
* limiting the maximum memory usage to a sane value to prevent running the
|
||||
* system out of memory when decompressing streams from untrusted sources.
|
||||
*
|
||||
* On success, xz_dec_init() returns a pointer to struct xz_dec, which is
|
||||
* ready to be used with xz_dec_run(). If memory allocation fails,
|
||||
* xz_dec_init() returns NULL.
|
||||
*/
|
||||
XZ_EXTERN struct xz_dec * XZ_FUNC xz_dec_init(
|
||||
enum xz_mode mode, uint32_t dict_max);
|
||||
|
||||
/**
|
||||
* xz_dec_run() - Run the XZ decoder
|
||||
* @s: Decoder state allocated using xz_dec_init()
|
||||
* @b: Input and output buffers
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* cannot be properly done if the output buffer is truncated. Thus, you
|
||||
* cannot give the single-call decoder a too small buffer and then expect to
|
||||
* get that amount valid data from the beginning of the stream. You must use
|
||||
* the multi-call decoder if you don't want to uncompress the whole stream.
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_run(struct xz_dec *s, struct xz_buf *b);
|
||||
|
||||
/**
|
||||
* xz_dec_reset() - Reset an already allocated decoder state
|
||||
* @s: Decoder state allocated using xz_dec_init()
|
||||
*
|
||||
* This function can be used to reset the multi-call decoder state without
|
||||
* freeing and reallocating memory with xz_dec_end() and xz_dec_init().
|
||||
*
|
||||
* In single-call mode, xz_dec_reset() is always called in the beginning of
|
||||
* xz_dec_run(). Thus, explicit call to xz_dec_reset() is useful only in
|
||||
* multi-call mode.
|
||||
*/
|
||||
XZ_EXTERN void XZ_FUNC xz_dec_reset(struct xz_dec *s);
|
||||
|
||||
/**
|
||||
* xz_dec_end() - Free the memory allocated for the decoder state
|
||||
* @s: Decoder state allocated using xz_dec_init(). If s is NULL,
|
||||
* this function does nothing.
|
||||
*/
|
||||
XZ_EXTERN void XZ_FUNC xz_dec_end(struct xz_dec *s);
|
||||
|
||||
/*
|
||||
* Standalone build (userspace build or in-kernel build for boot time use)
|
||||
* needs a CRC32 implementation. For normal in-kernel use, kernel's own
|
||||
* CRC32 module is used instead, and users of this module don't need to
|
||||
* care about the functions below.
|
||||
*/
|
||||
#ifndef XZ_INTERNAL_CRC32
|
||||
# ifdef __KERNEL__
|
||||
# define XZ_INTERNAL_CRC32 0
|
||||
# else
|
||||
# define XZ_INTERNAL_CRC32 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if XZ_INTERNAL_CRC32
|
||||
/*
|
||||
* This must be called before any other xz_* function to initialize
|
||||
* the CRC32 lookup table.
|
||||
*/
|
||||
XZ_EXTERN void XZ_FUNC xz_crc32_init(void);
|
||||
|
||||
/*
|
||||
* Update CRC32 value using the polynomial from IEEE-802.3. To start a new
|
||||
* calculation, the third argument must be zero. To continue the calculation,
|
||||
* the previously returned value is passed as the third argument.
|
||||
*/
|
||||
XZ_EXTERN uint32_t XZ_FUNC xz_crc32(
|
||||
const uint8_t *buf, size_t size, uint32_t crc);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Private includes and definitions for userspace use of XZ Embedded
|
||||
*
|
||||
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef XZ_CONFIG_H
|
||||
#define XZ_CONFIG_H
|
||||
|
||||
/* Uncomment as needed to enable BCJ filter decoders. */
|
||||
/* #define XZ_DEC_X86 */
|
||||
/* #define XZ_DEC_POWERPC */
|
||||
/* #define XZ_DEC_IA64 */
|
||||
/* #define XZ_DEC_ARM */
|
||||
/* #define XZ_DEC_ARMTHUMB */
|
||||
/* #define XZ_DEC_SPARC */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xz.h"
|
||||
|
||||
#define kmalloc(size, flags) malloc(size)
|
||||
#define kfree(ptr) free(ptr)
|
||||
#define vmalloc(size) malloc(size)
|
||||
#define vfree(ptr) free(ptr)
|
||||
|
||||
#define memeq(a, b, size) (memcmp(a, b, size) == 0)
|
||||
#define memzero(buf, size) memset(buf, 0, size)
|
||||
|
||||
#undef min
|
||||
#undef min_t
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define min_t(type, x, y) min(x, y)
|
||||
|
||||
/*
|
||||
* Some functions have been marked with __always_inline to keep the
|
||||
* performance reasonable even when the compiler is optimizing for
|
||||
* small code size. You may be able to save a few bytes by #defining
|
||||
* __always_inline to plain inline, but don't complain if the code
|
||||
* becomes slow.
|
||||
*
|
||||
* NOTE: System headers on GNU/Linux may #define this macro already,
|
||||
* so if you want to change it, you need to #undef it first.
|
||||
*/
|
||||
#ifndef __always_inline
|
||||
# ifdef __GNUC__
|
||||
# define __always_inline \
|
||||
inline __attribute__((__always_inline__))
|
||||
# else
|
||||
# define __always_inline inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some functions are marked to never be inlined to reduce stack usage.
|
||||
* If you don't care about stack usage, you may want to modify this so
|
||||
* that noinline_for_stack is #defined to be empty even when using GCC.
|
||||
* Doing so may save a few bytes in binary size.
|
||||
*/
|
||||
#ifndef noinline_for_stack
|
||||
# ifdef __GNUC__
|
||||
# define noinline_for_stack __attribute__((__noinline__))
|
||||
# else
|
||||
# define noinline_for_stack
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Inline functions to access unaligned unsigned 32-bit integers */
|
||||
#ifndef get_unaligned_le32
|
||||
static inline uint32_t XZ_FUNC get_unaligned_le32(const uint8_t *buf)
|
||||
{
|
||||
return (uint32_t)buf[0]
|
||||
| ((uint32_t)buf[1] << 8)
|
||||
| ((uint32_t)buf[2] << 16)
|
||||
| ((uint32_t)buf[3] << 24);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef get_unaligned_be32
|
||||
static inline uint32_t XZ_FUNC get_unaligned_be32(const uint8_t *buf)
|
||||
{
|
||||
return (uint32_t)(buf[0] << 24)
|
||||
| ((uint32_t)buf[1] << 16)
|
||||
| ((uint32_t)buf[2] << 8)
|
||||
| (uint32_t)buf[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef put_unaligned_le32
|
||||
static inline void XZ_FUNC put_unaligned_le32(uint32_t val, uint8_t *buf)
|
||||
{
|
||||
buf[0] = (uint8_t)val;
|
||||
buf[1] = (uint8_t)(val >> 8);
|
||||
buf[2] = (uint8_t)(val >> 16);
|
||||
buf[3] = (uint8_t)(val >> 24);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef put_unaligned_be32
|
||||
static inline void XZ_FUNC put_unaligned_be32(uint32_t val, uint8_t *buf)
|
||||
{
|
||||
buf[0] = (uint8_t)(val >> 24);
|
||||
buf[1] = (uint8_t)(val >> 16);
|
||||
buf[2] = (uint8_t)(val >> 8);
|
||||
buf[3] = (uint8_t)val;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Use get_unaligned_le32() also for aligned access for simplicity. On
|
||||
* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
|
||||
* could save a few bytes in code size.
|
||||
*/
|
||||
#ifndef get_le32
|
||||
# define get_le32 get_unaligned_le32
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,580 +0,0 @@
|
||||
/*
|
||||
* Branch/Call/Jump (BCJ) filter decoders
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#include "xz_private.h"
|
||||
|
||||
/*
|
||||
* The rest of the file is inside this ifdef. It makes things a little more
|
||||
* convenient when building without support for any BCJ filters.
|
||||
*/
|
||||
#ifdef XZ_DEC_BCJ
|
||||
|
||||
struct xz_dec_bcj {
|
||||
/* Type of the BCJ filter being used */
|
||||
enum {
|
||||
BCJ_X86 = 4, /* x86 or x86-64 */
|
||||
BCJ_POWERPC = 5, /* Big endian only */
|
||||
BCJ_IA64 = 6, /* Big or little endian */
|
||||
BCJ_ARM = 7, /* Little endian only */
|
||||
BCJ_ARMTHUMB = 8, /* Little endian only */
|
||||
BCJ_SPARC = 9 /* Big or little endian */
|
||||
} type;
|
||||
|
||||
/*
|
||||
* Return value of the next filter in the chain. We need to preserve
|
||||
* this information across calls, because we must not call the next
|
||||
* filter anymore once it has returned XZ_STREAM_END.
|
||||
*/
|
||||
enum xz_ret ret;
|
||||
|
||||
/* True if we are operating in single-call mode. */
|
||||
bool single_call;
|
||||
|
||||
/*
|
||||
* Absolute position relative to the beginning of the uncompressed
|
||||
* data (in a single .xz Block). We care only about the lowest 32
|
||||
* bits so this doesn't need to be uint64_t even with big files.
|
||||
*/
|
||||
uint32_t pos;
|
||||
|
||||
/* x86 filter state */
|
||||
uint32_t x86_prev_mask;
|
||||
|
||||
/* Temporary space to hold the variables from struct xz_buf */
|
||||
uint8_t *out;
|
||||
size_t out_pos;
|
||||
size_t out_size;
|
||||
|
||||
struct {
|
||||
/* Amount of already filtered data in the beginning of buf */
|
||||
size_t filtered;
|
||||
|
||||
/* Total amount of data currently stored in buf */
|
||||
size_t size;
|
||||
|
||||
/*
|
||||
* Buffer to hold a mix of filtered and unfiltered data. This
|
||||
* needs to be big enough to hold Alignment + 2 * Look-ahead:
|
||||
*
|
||||
* Type Alignment Look-ahead
|
||||
* x86 1 4
|
||||
* PowerPC 4 0
|
||||
* IA-64 16 0
|
||||
* ARM 4 0
|
||||
* ARM-Thumb 2 2
|
||||
* SPARC 4 0
|
||||
*/
|
||||
uint8_t buf[16];
|
||||
} temp;
|
||||
};
|
||||
|
||||
#ifdef XZ_DEC_X86
|
||||
/*
|
||||
* This is 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;
|
||||
}
|
||||
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_x86(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
static const bool mask_to_allowed_status[8]
|
||||
= { true, true, true, false, true, false, false, false };
|
||||
|
||||
static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
|
||||
|
||||
size_t i;
|
||||
size_t prev_pos = (size_t)-1;
|
||||
uint32_t prev_mask = s->x86_prev_mask;
|
||||
uint32_t src;
|
||||
uint32_t dest;
|
||||
uint32_t j;
|
||||
uint8_t b;
|
||||
|
||||
if (size <= 4)
|
||||
return 0;
|
||||
|
||||
size -= 4;
|
||||
for (i = 0; i < size; ++i) {
|
||||
if ((buf[i] & 0xFE) != 0xE8)
|
||||
continue;
|
||||
|
||||
prev_pos = i - prev_pos;
|
||||
if (prev_pos > 3) {
|
||||
prev_mask = 0;
|
||||
} else {
|
||||
prev_mask = (prev_mask << (prev_pos - 1)) & 7;
|
||||
if (prev_mask != 0) {
|
||||
b = buf[i + 4 - mask_to_bit_num[prev_mask]];
|
||||
if (!mask_to_allowed_status[prev_mask]
|
||||
|| bcj_x86_test_msbyte(b)) {
|
||||
prev_pos = i;
|
||||
prev_mask = (prev_mask << 1) | 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prev_pos = i;
|
||||
|
||||
if (bcj_x86_test_msbyte(buf[i + 4])) {
|
||||
src = get_unaligned_le32(buf + i + 1);
|
||||
while (true) {
|
||||
dest = src - (s->pos + (uint32_t)i + 5);
|
||||
if (prev_mask == 0)
|
||||
break;
|
||||
|
||||
j = mask_to_bit_num[prev_mask] * 8;
|
||||
b = (uint8_t)(dest >> (24 - j));
|
||||
if (!bcj_x86_test_msbyte(b))
|
||||
break;
|
||||
|
||||
src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
|
||||
}
|
||||
|
||||
dest &= 0x01FFFFFF;
|
||||
dest |= (uint32_t)0 - (dest & 0x01000000);
|
||||
put_unaligned_le32(dest, buf + i + 1);
|
||||
i += 4;
|
||||
} else {
|
||||
prev_mask = (prev_mask << 1) | 1;
|
||||
}
|
||||
}
|
||||
|
||||
prev_pos = i - prev_pos;
|
||||
s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_POWERPC
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_powerpc(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t instr;
|
||||
|
||||
for (i = 0; i + 4 <= size; i += 4) {
|
||||
instr = get_unaligned_be32(buf + i);
|
||||
if ((instr & 0xFC000003) == 0x48000001) {
|
||||
instr &= 0x03FFFFFC;
|
||||
instr -= s->pos + (uint32_t)i;
|
||||
instr &= 0x03FFFFFC;
|
||||
instr |= 0x48000001;
|
||||
put_unaligned_be32(instr, buf + i);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_IA64
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_ia64(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
static const uint8_t branch_table[32] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0
|
||||
};
|
||||
|
||||
/*
|
||||
* The local variables take a little bit stack space, but it's less
|
||||
* than what LZMA2 decoder takes, so it doesn't make sense to reduce
|
||||
* stack usage here without doing that for the LZMA2 decoder too.
|
||||
*/
|
||||
|
||||
/* Loop counters */
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
/* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
|
||||
uint32_t slot;
|
||||
|
||||
/* Bitwise offset of the instruction indicated by slot */
|
||||
uint32_t bit_pos;
|
||||
|
||||
/* bit_pos split into byte and bit parts */
|
||||
uint32_t byte_pos;
|
||||
uint32_t bit_res;
|
||||
|
||||
/* Address part of an instruction */
|
||||
uint32_t addr;
|
||||
|
||||
/* Mask used to detect which instructions to convert */
|
||||
uint32_t mask;
|
||||
|
||||
/* 41-bit instruction stored somewhere in the lowest 48 bits */
|
||||
uint64_t instr;
|
||||
|
||||
/* Instruction normalized with bit_res for easier manipulation */
|
||||
uint64_t norm;
|
||||
|
||||
for (i = 0; i + 16 <= size; i += 16) {
|
||||
mask = branch_table[buf[i] & 0x1F];
|
||||
for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
|
||||
if (((mask >> slot) & 1) == 0)
|
||||
continue;
|
||||
|
||||
byte_pos = bit_pos >> 3;
|
||||
bit_res = bit_pos & 7;
|
||||
instr = 0;
|
||||
for (j = 0; j < 6; ++j)
|
||||
instr |= (uint64_t)(buf[i + j + byte_pos])
|
||||
<< (8 * j);
|
||||
|
||||
norm = instr >> bit_res;
|
||||
|
||||
if (((norm >> 37) & 0x0F) == 0x05
|
||||
&& ((norm >> 9) & 0x07) == 0) {
|
||||
addr = (norm >> 13) & 0x0FFFFF;
|
||||
addr |= ((uint32_t)(norm >> 36) & 1) << 20;
|
||||
addr <<= 4;
|
||||
addr -= s->pos + (uint32_t)i;
|
||||
addr >>= 4;
|
||||
|
||||
norm &= ~((uint64_t)0x8FFFFF << 13);
|
||||
norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
|
||||
norm |= (uint64_t)(addr & 0x100000)
|
||||
<< (36 - 20);
|
||||
|
||||
instr &= (1 << bit_res) - 1;
|
||||
instr |= norm << bit_res;
|
||||
|
||||
for (j = 0; j < 6; j++)
|
||||
buf[i + j + byte_pos]
|
||||
= (uint8_t)(instr >> (8 * j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_ARM
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_arm(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t addr;
|
||||
|
||||
for (i = 0; i + 4 <= size; i += 4) {
|
||||
if (buf[i + 3] == 0xEB) {
|
||||
addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
|
||||
| ((uint32_t)buf[i + 2] << 16);
|
||||
addr <<= 2;
|
||||
addr -= s->pos + (uint32_t)i + 8;
|
||||
addr >>= 2;
|
||||
buf[i] = (uint8_t)addr;
|
||||
buf[i + 1] = (uint8_t)(addr >> 8);
|
||||
buf[i + 2] = (uint8_t)(addr >> 16);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_ARMTHUMB
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_armthumb(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t addr;
|
||||
|
||||
for (i = 0; i + 4 <= size; i += 2) {
|
||||
if ((buf[i + 1] & 0xF8) == 0xF0
|
||||
&& (buf[i + 3] & 0xF8) == 0xF8) {
|
||||
addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
|
||||
| ((uint32_t)buf[i] << 11)
|
||||
| (((uint32_t)buf[i + 3] & 0x07) << 8)
|
||||
| (uint32_t)buf[i + 2];
|
||||
addr <<= 1;
|
||||
addr -= s->pos + (uint32_t)i + 4;
|
||||
addr >>= 1;
|
||||
buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
|
||||
buf[i] = (uint8_t)(addr >> 11);
|
||||
buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
|
||||
buf[i + 2] = (uint8_t)addr;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_SPARC
|
||||
static noinline_for_stack size_t XZ_FUNC bcj_sparc(
|
||||
struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t instr;
|
||||
|
||||
for (i = 0; i + 4 <= size; i += 4) {
|
||||
instr = get_unaligned_be32(buf + i);
|
||||
if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
|
||||
instr <<= 2;
|
||||
instr -= s->pos + (uint32_t)i;
|
||||
instr >>= 2;
|
||||
instr = ((uint32_t)0x40000000 - (instr & 0x400000))
|
||||
| 0x40000000 | (instr & 0x3FFFFF);
|
||||
put_unaligned_be32(instr, buf + i);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Apply the selected BCJ filter. Update *pos and s->pos to match the amount
|
||||
* of data that got filtered.
|
||||
*
|
||||
* NOTE: This is implemented as a switch statement to avoid using function
|
||||
* pointers, which could be problematic in the kernel boot code, which must
|
||||
* avoid pointers to static data (at least on x86).
|
||||
*/
|
||||
static void XZ_FUNC bcj_apply(struct xz_dec_bcj *s,
|
||||
uint8_t *buf, size_t *pos, size_t size)
|
||||
{
|
||||
size_t filtered;
|
||||
|
||||
buf += *pos;
|
||||
size -= *pos;
|
||||
|
||||
switch (s->type) {
|
||||
#ifdef XZ_DEC_X86
|
||||
case BCJ_X86:
|
||||
filtered = bcj_x86(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
#ifdef XZ_DEC_POWERPC
|
||||
case BCJ_POWERPC:
|
||||
filtered = bcj_powerpc(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
#ifdef XZ_DEC_IA64
|
||||
case BCJ_IA64:
|
||||
filtered = bcj_ia64(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
#ifdef XZ_DEC_ARM
|
||||
case BCJ_ARM:
|
||||
filtered = bcj_arm(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
#ifdef XZ_DEC_ARMTHUMB
|
||||
case BCJ_ARMTHUMB:
|
||||
filtered = bcj_armthumb(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
#ifdef XZ_DEC_SPARC
|
||||
case BCJ_SPARC:
|
||||
filtered = bcj_sparc(s, buf, size);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* Never reached but silence compiler warnings. */
|
||||
filtered = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
*pos += filtered;
|
||||
s->pos += filtered;
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush pending filtered data from temp to the output buffer.
|
||||
* Move the remaining mixture of possibly filtered and unfiltered
|
||||
* data to the beginning of temp.
|
||||
*/
|
||||
static void XZ_FUNC bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
|
||||
{
|
||||
size_t copy_size;
|
||||
|
||||
copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
|
||||
memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
|
||||
b->out_pos += copy_size;
|
||||
|
||||
s->temp.filtered -= copy_size;
|
||||
s->temp.size -= copy_size;
|
||||
memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
|
||||
}
|
||||
|
||||
/*
|
||||
* The BCJ filter functions are primitive in sense that they process the
|
||||
* data in chunks of 1-16 bytes. To hide this issue, this function does
|
||||
* some buffering.
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
struct xz_dec_lzma2 *lzma2, struct xz_buf *b)
|
||||
{
|
||||
size_t out_start;
|
||||
|
||||
/*
|
||||
* Flush pending already filtered data to the output buffer. Return
|
||||
* immediatelly if we couldn't flush everything, or if the next
|
||||
* filter in the chain had already returned XZ_STREAM_END.
|
||||
*/
|
||||
if (s->temp.filtered > 0) {
|
||||
bcj_flush(s, b);
|
||||
if (s->temp.filtered > 0)
|
||||
return XZ_OK;
|
||||
|
||||
if (s->ret == XZ_STREAM_END)
|
||||
return XZ_STREAM_END;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have more output space than what is currently pending in
|
||||
* temp, copy the unfiltered data from temp to the output buffer
|
||||
* and try to fill the output buffer by decoding more data from the
|
||||
* 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) {
|
||||
out_start = b->out_pos;
|
||||
memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
|
||||
b->out_pos += s->temp.size;
|
||||
|
||||
s->ret = xz_dec_lzma2_run(lzma2, b);
|
||||
if (s->ret != XZ_STREAM_END
|
||||
&& (s->ret != XZ_OK || s->single_call))
|
||||
return s->ret;
|
||||
|
||||
bcj_apply(s, b->out, &out_start, b->out_pos);
|
||||
|
||||
/*
|
||||
* As an exception, if the next filter returned XZ_STREAM_END,
|
||||
* we can do that too, since the last few bytes that remain
|
||||
* unfiltered are meant to remain unfiltered.
|
||||
*/
|
||||
if (s->ret == XZ_STREAM_END)
|
||||
return XZ_STREAM_END;
|
||||
|
||||
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 (b->out_pos < b->out_size) {
|
||||
/* Make b->out{,_pos,_size} temporarily point to s->temp. */
|
||||
s->out = b->out;
|
||||
s->out_pos = b->out_pos;
|
||||
s->out_size = b->out_size;
|
||||
b->out = s->temp.buf;
|
||||
b->out_pos = s->temp.size;
|
||||
b->out_size = sizeof(s->temp.buf);
|
||||
|
||||
s->ret = xz_dec_lzma2_run(lzma2, b);
|
||||
|
||||
s->temp.size = b->out_pos;
|
||||
b->out = s->out;
|
||||
b->out_pos = s->out_pos;
|
||||
b->out_size = s->out_size;
|
||||
|
||||
if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
|
||||
return s->ret;
|
||||
|
||||
bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
|
||||
|
||||
/*
|
||||
* If the next filter returned XZ_STREAM_END, we mark that
|
||||
* everything is filtered, since the last unfiltered bytes
|
||||
* of the stream are meant to be left as is.
|
||||
*/
|
||||
if (s->ret == XZ_STREAM_END)
|
||||
s->temp.filtered = s->temp.size;
|
||||
|
||||
bcj_flush(s, b);
|
||||
if (s->temp.filtered > 0)
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
return s->ret;
|
||||
}
|
||||
|
||||
XZ_EXTERN struct xz_dec_bcj * XZ_FUNC xz_dec_bcj_create(bool single_call)
|
||||
{
|
||||
struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
|
||||
if (s != NULL)
|
||||
s->single_call = single_call;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_reset(
|
||||
struct xz_dec_bcj *s, uint8_t id)
|
||||
{
|
||||
switch (id) {
|
||||
#ifdef XZ_DEC_X86
|
||||
case BCJ_X86:
|
||||
#endif
|
||||
#ifdef XZ_DEC_POWERPC
|
||||
case BCJ_POWERPC:
|
||||
#endif
|
||||
#ifdef XZ_DEC_IA64
|
||||
case BCJ_IA64:
|
||||
#endif
|
||||
#ifdef XZ_DEC_ARM
|
||||
case BCJ_ARM:
|
||||
#endif
|
||||
#ifdef XZ_DEC_ARMTHUMB
|
||||
case BCJ_ARMTHUMB:
|
||||
#endif
|
||||
#ifdef XZ_DEC_SPARC
|
||||
case BCJ_SPARC:
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Unsupported Filter ID */
|
||||
return XZ_OPTIONS_ERROR;
|
||||
}
|
||||
|
||||
s->type = id;
|
||||
s->ret = XZ_OK;
|
||||
s->pos = 0;
|
||||
s->x86_prev_mask = 0;
|
||||
s->temp.filtered = 0;
|
||||
s->temp.size = 0;
|
||||
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,820 +0,0 @@
|
||||
/*
|
||||
* .xz Stream decoder
|
||||
*
|
||||
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#include "xz_private.h"
|
||||
#include "xz_stream.h"
|
||||
|
||||
/* Hash used to validate the Index field */
|
||||
struct xz_dec_hash {
|
||||
vli_type unpadded;
|
||||
vli_type uncompressed;
|
||||
uint32_t crc32;
|
||||
};
|
||||
|
||||
struct xz_dec {
|
||||
/* Position in dec_main() */
|
||||
enum {
|
||||
SEQ_STREAM_HEADER,
|
||||
SEQ_BLOCK_START,
|
||||
SEQ_BLOCK_HEADER,
|
||||
SEQ_BLOCK_UNCOMPRESS,
|
||||
SEQ_BLOCK_PADDING,
|
||||
SEQ_BLOCK_CHECK,
|
||||
SEQ_INDEX,
|
||||
SEQ_INDEX_PADDING,
|
||||
SEQ_INDEX_CRC32,
|
||||
SEQ_STREAM_FOOTER
|
||||
} sequence;
|
||||
|
||||
/* Position in variable-length integers and Check fields */
|
||||
uint32_t pos;
|
||||
|
||||
/* Variable-length integer decoded by dec_vli() */
|
||||
vli_type vli;
|
||||
|
||||
/* Saved in_pos and out_pos */
|
||||
size_t in_start;
|
||||
size_t out_start;
|
||||
|
||||
/* CRC32 value in Block or Index */
|
||||
uint32_t crc32;
|
||||
|
||||
/* Type of the integrity check calculated from uncompressed data */
|
||||
enum xz_check check_type;
|
||||
|
||||
/* Operation mode */
|
||||
enum xz_mode mode;
|
||||
|
||||
/*
|
||||
* True if the next call to xz_dec_run() is allowed to return
|
||||
* XZ_BUF_ERROR.
|
||||
*/
|
||||
bool allow_buf_error;
|
||||
|
||||
/* Information stored in Block Header */
|
||||
struct {
|
||||
/*
|
||||
* Value stored in the Compressed Size field, or
|
||||
* VLI_UNKNOWN if Compressed Size is not present.
|
||||
*/
|
||||
vli_type compressed;
|
||||
|
||||
/*
|
||||
* Value stored in the Uncompressed Size field, or
|
||||
* VLI_UNKNOWN if Uncompressed Size is not present.
|
||||
*/
|
||||
vli_type uncompressed;
|
||||
|
||||
/* Size of the Block Header field */
|
||||
uint32_t size;
|
||||
} block_header;
|
||||
|
||||
/* Information collected when decoding Blocks */
|
||||
struct {
|
||||
/* Observed compressed size of the current Block */
|
||||
vli_type compressed;
|
||||
|
||||
/* Observed uncompressed size of the current Block */
|
||||
vli_type uncompressed;
|
||||
|
||||
/* Number of Blocks decoded so far */
|
||||
vli_type count;
|
||||
|
||||
/*
|
||||
* Hash calculated from the Block sizes. This is used to
|
||||
* validate the Index field.
|
||||
*/
|
||||
struct xz_dec_hash hash;
|
||||
} block;
|
||||
|
||||
/* Variables needed when verifying the Index field */
|
||||
struct {
|
||||
/* Position in dec_index() */
|
||||
enum {
|
||||
SEQ_INDEX_COUNT,
|
||||
SEQ_INDEX_UNPADDED,
|
||||
SEQ_INDEX_UNCOMPRESSED
|
||||
} sequence;
|
||||
|
||||
/* Size of the Index in bytes */
|
||||
vli_type size;
|
||||
|
||||
/* Number of Records (matches block.count in valid files) */
|
||||
vli_type count;
|
||||
|
||||
/*
|
||||
* Hash calculated from the Records (matches block.hash in
|
||||
* valid files).
|
||||
*/
|
||||
struct xz_dec_hash hash;
|
||||
} index;
|
||||
|
||||
/*
|
||||
* Temporary buffer needed to hold Stream Header, Block Header,
|
||||
* and Stream Footer. The Block Header is the biggest (1 KiB)
|
||||
* so we reserve space according to that. buf[] has to be aligned
|
||||
* to a multiple of four bytes; the size_t variables before it
|
||||
* should guarantee this.
|
||||
*/
|
||||
struct {
|
||||
size_t pos;
|
||||
size_t size;
|
||||
uint8_t buf[1024];
|
||||
} temp;
|
||||
|
||||
struct xz_dec_lzma2 *lzma2;
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
struct xz_dec_bcj *bcj;
|
||||
bool bcj_active;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef XZ_DEC_ANY_CHECK
|
||||
/* Sizes of the Check field with different Check IDs */
|
||||
static const uint8_t check_sizes[16] = {
|
||||
0,
|
||||
4, 4, 4,
|
||||
8, 8, 8,
|
||||
16, 16, 16,
|
||||
32, 32, 32,
|
||||
64, 64, 64
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Fill s->temp by copying data starting from b->in[b->in_pos]. Caller
|
||||
* must have set s->temp.pos to indicate how much data we are supposed
|
||||
* to copy into s->temp.buf. Return true once s->temp.pos has reached
|
||||
* s->temp.size.
|
||||
*/
|
||||
static bool XZ_FUNC fill_temp(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
size_t copy_size = min_t(size_t,
|
||||
b->in_size - b->in_pos, s->temp.size - s->temp.pos);
|
||||
|
||||
memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size);
|
||||
b->in_pos += copy_size;
|
||||
s->temp.pos += copy_size;
|
||||
|
||||
if (s->temp.pos == s->temp.size) {
|
||||
s->temp.pos = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Decode a variable-length integer (little-endian base-128 encoding) */
|
||||
static enum xz_ret XZ_FUNC dec_vli(struct xz_dec *s,
|
||||
const uint8_t *in, size_t *in_pos, size_t in_size)
|
||||
{
|
||||
uint8_t byte;
|
||||
|
||||
if (s->pos == 0)
|
||||
s->vli = 0;
|
||||
|
||||
while (*in_pos < in_size) {
|
||||
byte = in[*in_pos];
|
||||
++*in_pos;
|
||||
|
||||
s->vli |= (vli_type)(byte & 0x7F) << s->pos;
|
||||
|
||||
if ((byte & 0x80) == 0) {
|
||||
/* Don't allow non-minimal encodings. */
|
||||
if (byte == 0 && s->pos != 0)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->pos = 0;
|
||||
return XZ_STREAM_END;
|
||||
}
|
||||
|
||||
s->pos += 7;
|
||||
if (s->pos == 7 * VLI_BYTES_MAX)
|
||||
return XZ_DATA_ERROR;
|
||||
}
|
||||
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode the Compressed Data field from a Block. Update and validate
|
||||
* the observed compressed and uncompressed sizes of the Block so that
|
||||
* they don't exceed the values possibly stored in the Block Header
|
||||
* (validation assumes that no integer overflow occurs, since vli_type
|
||||
* is normally uint64_t). Update the CRC32 if presence of the CRC32
|
||||
* field was indicated in Stream Header.
|
||||
*
|
||||
* Once the decoding is finished, validate that the observed sizes match
|
||||
* the sizes possibly stored in the Block Header. Update the hash and
|
||||
* Block count, which are later used to validate the Index field.
|
||||
*/
|
||||
static enum xz_ret XZ_FUNC dec_block(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
s->in_start = b->in_pos;
|
||||
s->out_start = b->out_pos;
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
if (s->bcj_active)
|
||||
ret = xz_dec_bcj_run(s->bcj, s->lzma2, b);
|
||||
else
|
||||
#endif
|
||||
ret = xz_dec_lzma2_run(s->lzma2, b);
|
||||
|
||||
s->block.compressed += b->in_pos - s->in_start;
|
||||
s->block.uncompressed += b->out_pos - s->out_start;
|
||||
|
||||
/*
|
||||
* There is no need to separately check for VLI_UNKNOWN, since
|
||||
* the observed sizes are always smaller than VLI_UNKNOWN.
|
||||
*/
|
||||
if (s->block.compressed > s->block_header.compressed
|
||||
|| s->block.uncompressed
|
||||
> s->block_header.uncompressed)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
if (s->check_type == XZ_CHECK_CRC32)
|
||||
s->crc32 = xz_crc32(b->out + s->out_start,
|
||||
b->out_pos - s->out_start, s->crc32);
|
||||
|
||||
if (ret == XZ_STREAM_END) {
|
||||
if (s->block_header.compressed != VLI_UNKNOWN
|
||||
&& s->block_header.compressed
|
||||
!= s->block.compressed)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
if (s->block_header.uncompressed != VLI_UNKNOWN
|
||||
&& s->block_header.uncompressed
|
||||
!= s->block.uncompressed)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->block.hash.unpadded += s->block_header.size
|
||||
+ s->block.compressed;
|
||||
|
||||
#ifdef XZ_DEC_ANY_CHECK
|
||||
s->block.hash.unpadded += check_sizes[s->check_type];
|
||||
#else
|
||||
if (s->check_type == XZ_CHECK_CRC32)
|
||||
s->block.hash.unpadded += 4;
|
||||
#endif
|
||||
|
||||
s->block.hash.uncompressed += s->block.uncompressed;
|
||||
s->block.hash.crc32 = xz_crc32(
|
||||
(const uint8_t *)&s->block.hash,
|
||||
sizeof(s->block.hash), s->block.hash.crc32);
|
||||
|
||||
++s->block.count;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Update the Index size and the CRC32 value. */
|
||||
static void XZ_FUNC index_update(struct xz_dec *s, const struct xz_buf *b)
|
||||
{
|
||||
size_t in_used = b->in_pos - s->in_start;
|
||||
s->index.size += in_used;
|
||||
s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode the Number of Records, Unpadded Size, and Uncompressed Size
|
||||
* fields from the Index field. That is, Index Padding and CRC32 are not
|
||||
* decoded by this function.
|
||||
*
|
||||
* This can return XZ_OK (more input needed), XZ_STREAM_END (everything
|
||||
* successfully decoded), or XZ_DATA_ERROR (input is corrupt).
|
||||
*/
|
||||
static enum xz_ret XZ_FUNC dec_index(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
do {
|
||||
ret = dec_vli(s, b->in, &b->in_pos, b->in_size);
|
||||
if (ret != XZ_STREAM_END) {
|
||||
index_update(s, b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (s->index.sequence) {
|
||||
case SEQ_INDEX_COUNT:
|
||||
s->index.count = s->vli;
|
||||
|
||||
/*
|
||||
* Validate that the Number of Records field
|
||||
* indicates the same number of Records as
|
||||
* there were Blocks in the Stream.
|
||||
*/
|
||||
if (s->index.count != s->block.count)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->index.sequence = SEQ_INDEX_UNPADDED;
|
||||
break;
|
||||
|
||||
case SEQ_INDEX_UNPADDED:
|
||||
s->index.hash.unpadded += s->vli;
|
||||
s->index.sequence = SEQ_INDEX_UNCOMPRESSED;
|
||||
break;
|
||||
|
||||
case SEQ_INDEX_UNCOMPRESSED:
|
||||
s->index.hash.uncompressed += s->vli;
|
||||
s->index.hash.crc32 = xz_crc32(
|
||||
(const uint8_t *)&s->index.hash,
|
||||
sizeof(s->index.hash),
|
||||
s->index.hash.crc32);
|
||||
--s->index.count;
|
||||
s->index.sequence = SEQ_INDEX_UNPADDED;
|
||||
break;
|
||||
}
|
||||
} while (s->index.count > 0);
|
||||
|
||||
return XZ_STREAM_END;
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the next four input bytes match the value of s->crc32.
|
||||
* s->pos must be zero when starting to validate the first byte.
|
||||
*/
|
||||
static enum xz_ret XZ_FUNC crc32_validate(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
do {
|
||||
if (b->in_pos == b->in_size)
|
||||
return XZ_OK;
|
||||
|
||||
if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++])
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->pos += 8;
|
||||
} while (s->pos < 32);
|
||||
|
||||
s->crc32 = 0;
|
||||
s->pos = 0;
|
||||
|
||||
return XZ_STREAM_END;
|
||||
}
|
||||
|
||||
#ifdef XZ_DEC_ANY_CHECK
|
||||
/*
|
||||
* Skip over the Check field when the Check ID is not supported.
|
||||
* Returns true once the whole Check field has been skipped over.
|
||||
*/
|
||||
static bool XZ_FUNC check_skip(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
while (s->pos < check_sizes[s->check_type]) {
|
||||
if (b->in_pos == b->in_size)
|
||||
return false;
|
||||
|
||||
++b->in_pos;
|
||||
++s->pos;
|
||||
}
|
||||
|
||||
s->pos = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */
|
||||
static enum xz_ret XZ_FUNC dec_stream_header(struct xz_dec *s)
|
||||
{
|
||||
if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE))
|
||||
return XZ_FORMAT_ERROR;
|
||||
|
||||
if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0)
|
||||
!= get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
if (s->temp.buf[HEADER_MAGIC_SIZE] != 0)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
/*
|
||||
* Of integrity checks, we support only none (Check ID = 0) and
|
||||
* CRC32 (Check ID = 1). However, if XZ_DEC_ANY_CHECK is defined,
|
||||
* we will accept other check types too, but then the check won't
|
||||
* be verified and a warning (XZ_UNSUPPORTED_CHECK) will be given.
|
||||
*/
|
||||
s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
|
||||
|
||||
#ifdef XZ_DEC_ANY_CHECK
|
||||
if (s->check_type > XZ_CHECK_MAX)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
if (s->check_type > XZ_CHECK_CRC32)
|
||||
return XZ_UNSUPPORTED_CHECK;
|
||||
#else
|
||||
if (s->check_type > XZ_CHECK_CRC32)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
#endif
|
||||
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
/* Decode the Stream Footer field (the last 12 bytes of the .xz Stream) */
|
||||
static enum xz_ret XZ_FUNC dec_stream_footer(struct xz_dec *s)
|
||||
{
|
||||
if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
/*
|
||||
* Validate Backward Size. Note that we never added the size of the
|
||||
* Index CRC32 field to s->index.size, thus we use s->index.size / 4
|
||||
* instead of s->index.size / 4 - 1.
|
||||
*/
|
||||
if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
/*
|
||||
* Use XZ_STREAM_END instead of XZ_OK to be more convenient
|
||||
* for the caller.
|
||||
*/
|
||||
return XZ_STREAM_END;
|
||||
}
|
||||
|
||||
/* Decode the Block Header and initialize the filter chain. */
|
||||
static enum xz_ret XZ_FUNC dec_block_header(struct xz_dec *s)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
/*
|
||||
* Validate the CRC32. We know that the temp buffer is at least
|
||||
* eight bytes so this is safe.
|
||||
*/
|
||||
s->temp.size -= 4;
|
||||
if (xz_crc32(s->temp.buf, s->temp.size, 0)
|
||||
!= get_le32(s->temp.buf + s->temp.size))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->temp.pos = 2;
|
||||
|
||||
/*
|
||||
* Catch unsupported Block Flags. We support only one or two filters
|
||||
* in the chain, so we catch that with the same test.
|
||||
*/
|
||||
#ifdef XZ_DEC_BCJ
|
||||
if (s->temp.buf[1] & 0x3E)
|
||||
#else
|
||||
if (s->temp.buf[1] & 0x3F)
|
||||
#endif
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
/* Compressed Size */
|
||||
if (s->temp.buf[1] & 0x40) {
|
||||
if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
|
||||
!= XZ_STREAM_END)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->block_header.compressed = s->vli;
|
||||
} else {
|
||||
s->block_header.compressed = VLI_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Uncompressed Size */
|
||||
if (s->temp.buf[1] & 0x80) {
|
||||
if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
|
||||
!= XZ_STREAM_END)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->block_header.uncompressed = s->vli;
|
||||
} else {
|
||||
s->block_header.uncompressed = VLI_UNKNOWN;
|
||||
}
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
/* If there are two filters, the first one must be a BCJ filter. */
|
||||
s->bcj_active = s->temp.buf[1] & 0x01;
|
||||
if (s->bcj_active) {
|
||||
if (s->temp.size - s->temp.pos < 2)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]);
|
||||
if (ret != XZ_OK)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* We don't support custom start offset,
|
||||
* so Size of Properties must be zero.
|
||||
*/
|
||||
if (s->temp.buf[s->temp.pos++] != 0x00)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Valid Filter Flags always take at least two bytes. */
|
||||
if (s->temp.size - s->temp.pos < 2)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
/* Filter ID = LZMA2 */
|
||||
if (s->temp.buf[s->temp.pos++] != 0x21)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
/* Size of Properties = 1-byte Filter Properties */
|
||||
if (s->temp.buf[s->temp.pos++] != 0x01)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
/* Filter Properties contains LZMA2 dictionary size. */
|
||||
if (s->temp.size - s->temp.pos < 1)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]);
|
||||
if (ret != XZ_OK)
|
||||
return ret;
|
||||
|
||||
/* The rest must be Header Padding. */
|
||||
while (s->temp.pos < s->temp.size)
|
||||
if (s->temp.buf[s->temp.pos++] != 0x00)
|
||||
return XZ_OPTIONS_ERROR;
|
||||
|
||||
s->temp.pos = 0;
|
||||
s->block.compressed = 0;
|
||||
s->block.uncompressed = 0;
|
||||
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
static NOINLINE enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
/*
|
||||
* Store the start position for the case when we are in the middle
|
||||
* of the Index field.
|
||||
*/
|
||||
s->in_start = b->in_pos;
|
||||
|
||||
while (true) {
|
||||
switch (s->sequence) {
|
||||
case SEQ_STREAM_HEADER:
|
||||
/*
|
||||
* Stream Header is copied to s->temp, and then
|
||||
* decoded from there. This way if the caller
|
||||
* gives us only little input at a time, we can
|
||||
* still keep the Stream Header decoding code
|
||||
* simple. Similar approach is used in many places
|
||||
* in this file.
|
||||
*/
|
||||
if (!fill_temp(s, b))
|
||||
return XZ_OK;
|
||||
|
||||
/*
|
||||
* If dec_stream_header() returns
|
||||
* XZ_UNSUPPORTED_CHECK, it is still possible
|
||||
* to continue decoding if working in multi-call
|
||||
* mode. Thus, update s->sequence before calling
|
||||
* dec_stream_header().
|
||||
*/
|
||||
s->sequence = SEQ_BLOCK_START;
|
||||
|
||||
ret = dec_stream_header(s);
|
||||
if (ret != XZ_OK)
|
||||
return ret;
|
||||
|
||||
case SEQ_BLOCK_START:
|
||||
/* We need one byte of input to continue. */
|
||||
if (b->in_pos == b->in_size)
|
||||
return XZ_OK;
|
||||
|
||||
/* See if this is the beginning of the Index field. */
|
||||
if (b->in[b->in_pos] == 0) {
|
||||
s->in_start = b->in_pos++;
|
||||
s->sequence = SEQ_INDEX;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the size of the Block Header and
|
||||
* prepare to decode it.
|
||||
*/
|
||||
s->block_header.size
|
||||
= ((uint32_t)b->in[b->in_pos] + 1) * 4;
|
||||
|
||||
s->temp.size = s->block_header.size;
|
||||
s->temp.pos = 0;
|
||||
s->sequence = SEQ_BLOCK_HEADER;
|
||||
|
||||
case SEQ_BLOCK_HEADER:
|
||||
if (!fill_temp(s, b))
|
||||
return XZ_OK;
|
||||
|
||||
ret = dec_block_header(s);
|
||||
if (ret != XZ_OK)
|
||||
return ret;
|
||||
|
||||
s->sequence = SEQ_BLOCK_UNCOMPRESS;
|
||||
|
||||
case SEQ_BLOCK_UNCOMPRESS:
|
||||
ret = dec_block(s, b);
|
||||
if (ret != XZ_STREAM_END)
|
||||
return ret;
|
||||
|
||||
s->sequence = SEQ_BLOCK_PADDING;
|
||||
|
||||
case SEQ_BLOCK_PADDING:
|
||||
/*
|
||||
* Size of Compressed Data + Block Padding
|
||||
* must be a multiple of four. We don't need
|
||||
* s->block.compressed for anything else
|
||||
* anymore, so we use it here to test the size
|
||||
* of the Block Padding field.
|
||||
*/
|
||||
while (s->block.compressed & 3) {
|
||||
if (b->in_pos == b->in_size)
|
||||
return XZ_OK;
|
||||
|
||||
if (b->in[b->in_pos++] != 0)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
++s->block.compressed;
|
||||
}
|
||||
|
||||
s->sequence = SEQ_BLOCK_CHECK;
|
||||
|
||||
case SEQ_BLOCK_CHECK:
|
||||
if (s->check_type == XZ_CHECK_CRC32) {
|
||||
ret = crc32_validate(s, b);
|
||||
if (ret != XZ_STREAM_END)
|
||||
return ret;
|
||||
}
|
||||
#ifdef XZ_DEC_ANY_CHECK
|
||||
else if (!check_skip(s, b)) {
|
||||
return XZ_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
s->sequence = SEQ_BLOCK_START;
|
||||
break;
|
||||
|
||||
case SEQ_INDEX:
|
||||
ret = dec_index(s, b);
|
||||
if (ret != XZ_STREAM_END)
|
||||
return ret;
|
||||
|
||||
s->sequence = SEQ_INDEX_PADDING;
|
||||
|
||||
case SEQ_INDEX_PADDING:
|
||||
while ((s->index.size + (b->in_pos - s->in_start))
|
||||
& 3) {
|
||||
if (b->in_pos == b->in_size) {
|
||||
index_update(s, b);
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
if (b->in[b->in_pos++] != 0)
|
||||
return XZ_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* Finish the CRC32 value and Index size. */
|
||||
index_update(s, b);
|
||||
|
||||
/* Compare the hashes to validate the Index field. */
|
||||
if (!memeq(&s->block.hash, &s->index.hash,
|
||||
sizeof(s->block.hash)))
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->sequence = SEQ_INDEX_CRC32;
|
||||
|
||||
case SEQ_INDEX_CRC32:
|
||||
ret = crc32_validate(s, b);
|
||||
if (ret != XZ_STREAM_END)
|
||||
return ret;
|
||||
|
||||
s->temp.size = STREAM_HEADER_SIZE;
|
||||
s->sequence = SEQ_STREAM_FOOTER;
|
||||
|
||||
case SEQ_STREAM_FOOTER:
|
||||
if (!fill_temp(s, b))
|
||||
return XZ_OK;
|
||||
|
||||
return dec_stream_footer(s);
|
||||
}
|
||||
}
|
||||
|
||||
/* Never reached */
|
||||
}
|
||||
|
||||
/*
|
||||
* xz_dec_run() is a wrapper for dec_main() to handle some special cases in
|
||||
* multi-call and single-call decoding.
|
||||
*
|
||||
* In multi-call mode, we must return XZ_BUF_ERROR when it seems clear that we
|
||||
* are not going to make any progress anymore. This is to prevent the caller
|
||||
* from calling us infinitely when the input file is truncated or otherwise
|
||||
* corrupt. Since zlib-style API allows that the caller fills the input buffer
|
||||
* only when the decoder doesn't produce any new output, we have to be careful
|
||||
* to avoid returning XZ_BUF_ERROR too easily: XZ_BUF_ERROR is returned only
|
||||
* after the second consecutive call to xz_dec_run() that makes no progress.
|
||||
*
|
||||
* In single-call mode, if we couldn't decode everything and no error
|
||||
* occurred, either the input is truncated or the output buffer is too small.
|
||||
* Since we know that the last input byte never produces any output, we know
|
||||
* that if all the input was consumed and decoding wasn't finished, the file
|
||||
* must be corrupt. Otherwise the output buffer has to be too small or the
|
||||
* file is corrupt in a way that decoding it produces too big output.
|
||||
*
|
||||
* If single-call decoding fails, we reset b->in_pos and b->out_pos back to
|
||||
* their original values. This is because with some filter chains there won't
|
||||
* be any valid uncompressed data in the output buffer unless the decoding
|
||||
* actually succeeds (that's the price to pay of using the output buffer as
|
||||
* the workspace).
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_run(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
size_t in_start;
|
||||
size_t out_start;
|
||||
enum xz_ret ret;
|
||||
|
||||
if (DEC_IS_SINGLE(s->mode))
|
||||
xz_dec_reset(s);
|
||||
|
||||
in_start = b->in_pos;
|
||||
out_start = b->out_pos;
|
||||
ret = dec_main(s, b);
|
||||
|
||||
if (DEC_IS_SINGLE(s->mode)) {
|
||||
if (ret == XZ_OK)
|
||||
ret = b->in_pos == b->in_size
|
||||
? XZ_DATA_ERROR : XZ_BUF_ERROR;
|
||||
|
||||
if (ret != XZ_STREAM_END) {
|
||||
b->in_pos = in_start;
|
||||
b->out_pos = out_start;
|
||||
}
|
||||
} else if (ret == XZ_OK && in_start == b->in_pos
|
||||
&& out_start == b->out_pos) {
|
||||
if (s->allow_buf_error)
|
||||
ret = XZ_BUF_ERROR;
|
||||
|
||||
s->allow_buf_error = true;
|
||||
} else {
|
||||
s->allow_buf_error = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
XZ_EXTERN struct xz_dec * XZ_FUNC xz_dec_init(
|
||||
enum xz_mode mode, uint32_t dict_max)
|
||||
{
|
||||
struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL);
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
s->mode = mode;
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode));
|
||||
if (s->bcj == NULL)
|
||||
goto error_bcj;
|
||||
#endif
|
||||
|
||||
s->lzma2 = xz_dec_lzma2_create(mode, dict_max);
|
||||
if (s->lzma2 == NULL)
|
||||
goto error_lzma2;
|
||||
|
||||
xz_dec_reset(s);
|
||||
return s;
|
||||
|
||||
error_lzma2:
|
||||
#ifdef XZ_DEC_BCJ
|
||||
xz_dec_bcj_end(s->bcj);
|
||||
error_bcj:
|
||||
#endif
|
||||
kfree(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XZ_EXTERN void XZ_FUNC xz_dec_reset(struct xz_dec *s)
|
||||
{
|
||||
s->sequence = SEQ_STREAM_HEADER;
|
||||
s->allow_buf_error = false;
|
||||
s->pos = 0;
|
||||
s->crc32 = 0;
|
||||
memzero(&s->block, sizeof(s->block));
|
||||
memzero(&s->index, sizeof(s->index));
|
||||
s->temp.pos = 0;
|
||||
s->temp.size = STREAM_HEADER_SIZE;
|
||||
}
|
||||
|
||||
XZ_EXTERN void XZ_FUNC xz_dec_end(struct xz_dec *s)
|
||||
{
|
||||
if (s != NULL) {
|
||||
xz_dec_lzma2_end(s->lzma2);
|
||||
#ifdef XZ_DEC_BCJ
|
||||
xz_dec_bcj_end(s->bcj);
|
||||
#endif
|
||||
kfree(s);
|
||||
}
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* LZMA2 definitions
|
||||
*
|
||||
* Authors: Lasse Collin <lasse.collin@tukaani.org>
|
||||
* Igor Pavlov <http://7-zip.org/>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef XZ_LZMA2_H
|
||||
#define XZ_LZMA2_H
|
||||
|
||||
/* Range coder constants */
|
||||
#define RC_SHIFT_BITS 8
|
||||
#define RC_TOP_BITS 24
|
||||
#define RC_TOP_VALUE (1 << RC_TOP_BITS)
|
||||
#define RC_BIT_MODEL_TOTAL_BITS 11
|
||||
#define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS)
|
||||
#define RC_MOVE_BITS 5
|
||||
|
||||
/*
|
||||
* Maximum number of position states. A position state is the lowest pb
|
||||
* number of bits of the current uncompressed offset. In some places there
|
||||
* are different sets of probabilities for different position states.
|
||||
*/
|
||||
#define POS_STATES_MAX (1 << 4)
|
||||
|
||||
/*
|
||||
* This enum is used to track which LZMA symbols have occurred most recently
|
||||
* and in which order. This information is used to predict the next symbol.
|
||||
*
|
||||
* Symbols:
|
||||
* - Literal: One 8-bit byte
|
||||
* - Match: Repeat a chunk of data at some distance
|
||||
* - Long repeat: Multi-byte match at a recently seen distance
|
||||
* - Short repeat: One-byte repeat at a recently seen distance
|
||||
*
|
||||
* The symbol names are in from STATE_oldest_older_previous. REP means
|
||||
* either short or long repeated match, and NONLIT means any non-literal.
|
||||
*/
|
||||
enum lzma_state {
|
||||
STATE_LIT_LIT,
|
||||
STATE_MATCH_LIT_LIT,
|
||||
STATE_REP_LIT_LIT,
|
||||
STATE_SHORTREP_LIT_LIT,
|
||||
STATE_MATCH_LIT,
|
||||
STATE_REP_LIT,
|
||||
STATE_SHORTREP_LIT,
|
||||
STATE_LIT_MATCH,
|
||||
STATE_LIT_LONGREP,
|
||||
STATE_LIT_SHORTREP,
|
||||
STATE_NONLIT_MATCH,
|
||||
STATE_NONLIT_REP
|
||||
};
|
||||
|
||||
/* Total number of states */
|
||||
#define STATES 12
|
||||
|
||||
/* The lowest 7 states indicate that the previous state was a literal. */
|
||||
#define LIT_STATES 7
|
||||
|
||||
/* Indicate that the latest symbol was a literal. */
|
||||
static inline void XZ_FUNC lzma_state_literal(enum lzma_state *state)
|
||||
{
|
||||
if (*state <= STATE_SHORTREP_LIT_LIT)
|
||||
*state = STATE_LIT_LIT;
|
||||
else if (*state <= STATE_LIT_SHORTREP)
|
||||
*state -= 3;
|
||||
else
|
||||
*state -= 6;
|
||||
}
|
||||
|
||||
/* Indicate that the latest symbol was a match. */
|
||||
static inline void XZ_FUNC lzma_state_match(enum lzma_state *state)
|
||||
{
|
||||
*state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
|
||||
}
|
||||
|
||||
/* Indicate that the latest state was a long repeated match. */
|
||||
static inline void XZ_FUNC lzma_state_long_rep(enum lzma_state *state)
|
||||
{
|
||||
*state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
|
||||
}
|
||||
|
||||
/* Indicate that the latest symbol was a short match. */
|
||||
static inline void XZ_FUNC lzma_state_short_rep(enum lzma_state *state)
|
||||
{
|
||||
*state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
|
||||
}
|
||||
|
||||
/* Test if the previous symbol was a literal. */
|
||||
static inline bool XZ_FUNC lzma_state_is_literal(enum lzma_state state)
|
||||
{
|
||||
return state < LIT_STATES;
|
||||
}
|
||||
|
||||
/* Each literal coder is divided in three sections:
|
||||
* - 0x001-0x0FF: Without match byte
|
||||
* - 0x101-0x1FF: With match byte; match bit is 0
|
||||
* - 0x201-0x2FF: With match byte; match bit is 1
|
||||
*
|
||||
* Match byte is used when the previous LZMA symbol was something else than
|
||||
* a literal (that is, it was some kind of match).
|
||||
*/
|
||||
#define LITERAL_CODER_SIZE 0x300
|
||||
|
||||
/* Maximum number of literal coders */
|
||||
#define LITERAL_CODERS_MAX (1 << 4)
|
||||
|
||||
/* Minimum length of a match is two bytes. */
|
||||
#define MATCH_LEN_MIN 2
|
||||
|
||||
/* Match length is encoded with 4, 5, or 10 bits.
|
||||
*
|
||||
* Length Bits
|
||||
* 2-9 4 = Choice=0 + 3 bits
|
||||
* 10-17 5 = Choice=1 + Choice2=0 + 3 bits
|
||||
* 18-273 10 = Choice=1 + Choice2=1 + 8 bits
|
||||
*/
|
||||
#define LEN_LOW_BITS 3
|
||||
#define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
|
||||
#define LEN_MID_BITS 3
|
||||
#define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
|
||||
#define LEN_HIGH_BITS 8
|
||||
#define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
|
||||
#define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
|
||||
|
||||
/*
|
||||
* Maximum length of a match is 273 which is a result of the encoding
|
||||
* described above.
|
||||
*/
|
||||
#define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
|
||||
|
||||
/*
|
||||
* Different sets of probabilities are used for match distances that have
|
||||
* very short match length: Lengths of 2, 3, and 4 bytes have a separate
|
||||
* set of probabilities for each length. The matches with longer length
|
||||
* use a shared set of probabilities.
|
||||
*/
|
||||
#define DIST_STATES 4
|
||||
|
||||
/*
|
||||
* Get the index of the appropriate probability array for decoding
|
||||
* the distance slot.
|
||||
*/
|
||||
static inline uint32_t XZ_FUNC lzma_get_dist_state(uint32_t len)
|
||||
{
|
||||
return len < DIST_STATES + MATCH_LEN_MIN
|
||||
? len - MATCH_LEN_MIN : DIST_STATES - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The highest two bits of a 32-bit match distance are encoded using six bits.
|
||||
* This six-bit value is called a distance slot. This way encoding a 32-bit
|
||||
* value takes 6-36 bits, larger values taking more bits.
|
||||
*/
|
||||
#define DIST_SLOT_BITS 6
|
||||
#define DIST_SLOTS (1 << DIST_SLOT_BITS)
|
||||
|
||||
/* Match distances up to 127 are fully encoded using probabilities. Since
|
||||
* the highest two bits (distance slot) are always encoded using six bits,
|
||||
* the distances 0-3 don't need any additional bits to encode, since the
|
||||
* distance slot itself is the same as the actual distance. DIST_MODEL_START
|
||||
* indicates the first distance slot where at least one additional bit is
|
||||
* needed.
|
||||
*/
|
||||
#define DIST_MODEL_START 4
|
||||
|
||||
/*
|
||||
* Match distances greater than 127 are encoded in three pieces:
|
||||
* - distance slot: the highest two bits
|
||||
* - direct bits: 2-26 bits below the highest two bits
|
||||
* - alignment bits: four lowest bits
|
||||
*
|
||||
* Direct bits don't use any probabilities.
|
||||
*
|
||||
* The distance slot value of 14 is for distances 128-191.
|
||||
*/
|
||||
#define DIST_MODEL_END 14
|
||||
|
||||
/* Distance slots that indicate a distance <= 127. */
|
||||
#define FULL_DISTANCES_BITS (DIST_MODEL_END / 2)
|
||||
#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
|
||||
|
||||
/*
|
||||
* For match distances greater than 127, only the highest two bits and the
|
||||
* lowest four bits (alignment) is encoded using probabilities.
|
||||
*/
|
||||
#define ALIGN_BITS 4
|
||||
#define ALIGN_SIZE (1 << ALIGN_BITS)
|
||||
#define ALIGN_MASK (ALIGN_SIZE - 1)
|
||||
|
||||
/* Total number of all probability variables */
|
||||
#define PROBS_TOTAL (1846 + LITERAL_CODERS_MAX * LITERAL_CODER_SIZE)
|
||||
|
||||
/*
|
||||
* LZMA remembers the four most recent match distances. Reusing these
|
||||
* distances tends to take less space than re-encoding the actual
|
||||
* distance value.
|
||||
*/
|
||||
#define REPS 4
|
||||
|
||||
#endif
|
||||
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Private includes and definitions
|
||||
*
|
||||
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef XZ_PRIVATE_H
|
||||
#define XZ_PRIVATE_H
|
||||
|
||||
#ifdef __KERNEL__
|
||||
/* XZ_PREBOOT may be defined only via decompress_unxz.c. */
|
||||
# ifndef XZ_PREBOOT
|
||||
# include <linux/slab.h>
|
||||
# include <linux/vmalloc.h>
|
||||
# include <linux/string.h>
|
||||
# define memeq(a, b, size) (memcmp(a, b, size) == 0)
|
||||
# define memzero(buf, size) memset(buf, 0, size)
|
||||
# endif
|
||||
# include <asm/byteorder.h>
|
||||
# include <asm/unaligned.h>
|
||||
# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
|
||||
/* XZ_IGNORE_KCONFIG may be defined only via decompress_unxz.c. */
|
||||
# ifndef XZ_IGNORE_KCONFIG
|
||||
# ifdef CONFIG_XZ_DEC_X86
|
||||
# define XZ_DEC_X86
|
||||
# endif
|
||||
# ifdef CONFIG_XZ_DEC_POWERPC
|
||||
# define XZ_DEC_POWERPC
|
||||
# endif
|
||||
# ifdef CONFIG_XZ_DEC_IA64
|
||||
# define XZ_DEC_IA64
|
||||
# endif
|
||||
# ifdef CONFIG_XZ_DEC_ARM
|
||||
# define XZ_DEC_ARM
|
||||
# endif
|
||||
# ifdef CONFIG_XZ_DEC_ARMTHUMB
|
||||
# define XZ_DEC_ARMTHUMB
|
||||
# endif
|
||||
# ifdef CONFIG_XZ_DEC_SPARC
|
||||
# define XZ_DEC_SPARC
|
||||
# endif
|
||||
# endif
|
||||
# include <linux/xz.h>
|
||||
#else
|
||||
/*
|
||||
* For userspace builds, use a separate header to define the required
|
||||
* macros and functions. This makes it easier to adapt the code into
|
||||
* different environments and avoids clutter in the Linux kernel tree.
|
||||
*/
|
||||
# include "xz_config.h"
|
||||
#endif
|
||||
|
||||
/* If no specific decoding mode is requested, enable support for all modes. */
|
||||
#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
|
||||
&& !defined(XZ_DEC_DYNALLOC)
|
||||
# define XZ_DEC_SINGLE
|
||||
# define XZ_DEC_PREALLOC
|
||||
# define XZ_DEC_DYNALLOC
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The DEC_IS_foo(mode) macros are used in "if" statements. If only some
|
||||
* of the supported modes are enabled, these macros will evaluate to true or
|
||||
* false at compile time and thus allow the compiler to omit unneeded code.
|
||||
*/
|
||||
#ifdef XZ_DEC_SINGLE
|
||||
# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
|
||||
#else
|
||||
# define DEC_IS_SINGLE(mode) (false)
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_PREALLOC
|
||||
# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
|
||||
#else
|
||||
# define DEC_IS_PREALLOC(mode) (false)
|
||||
#endif
|
||||
|
||||
#ifdef XZ_DEC_DYNALLOC
|
||||
# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
|
||||
#else
|
||||
# define DEC_IS_DYNALLOC(mode) (false)
|
||||
#endif
|
||||
|
||||
#if !defined(XZ_DEC_SINGLE)
|
||||
# define DEC_IS_MULTI(mode) (true)
|
||||
#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
|
||||
# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
|
||||
#else
|
||||
# define DEC_IS_MULTI(mode) (false)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
|
||||
* XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
|
||||
*/
|
||||
#ifndef XZ_DEC_BCJ
|
||||
# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
|
||||
|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
|
||||
|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
|
||||
|| defined(XZ_DEC_SPARC)
|
||||
# define XZ_DEC_BCJ
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
|
||||
* before calling xz_dec_lzma2_run().
|
||||
*/
|
||||
XZ_EXTERN struct xz_dec_lzma2 * XZ_FUNC xz_dec_lzma2_create(
|
||||
enum xz_mode mode, uint32_t dict_max);
|
||||
|
||||
/*
|
||||
* Decode the LZMA2 properties (one byte) and reset the decoder. Return
|
||||
* XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
|
||||
* big enough, and XZ_OPTIONS_ERROR if props indicates something that this
|
||||
* decoder doesn't support.
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_lzma2_reset(
|
||||
struct xz_dec_lzma2 *s, uint8_t props);
|
||||
|
||||
/* Decode raw LZMA2 stream from b->in to b->out. */
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
struct xz_dec_lzma2 *s, struct xz_buf *b);
|
||||
|
||||
/* Free the memory allocated for the LZMA2 decoder. */
|
||||
XZ_EXTERN void XZ_FUNC xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
|
||||
|
||||
#ifdef XZ_DEC_BCJ
|
||||
/*
|
||||
* Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
|
||||
* calling xz_dec_bcj_run().
|
||||
*/
|
||||
XZ_EXTERN struct xz_dec_bcj * XZ_FUNC xz_dec_bcj_create(bool single_call);
|
||||
|
||||
/*
|
||||
* Decode the Filter ID of a BCJ filter. This implementation doesn't
|
||||
* support custom start offsets, so no decoding of Filter Properties
|
||||
* is needed. Returns XZ_OK if the given Filter ID is supported.
|
||||
* Otherwise XZ_OPTIONS_ERROR is returned.
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_reset(
|
||||
struct xz_dec_bcj *s, uint8_t id);
|
||||
|
||||
/*
|
||||
* Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
|
||||
* a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
|
||||
* must be called directly.
|
||||
*/
|
||||
XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||
struct xz_dec_lzma2 *lzma2, struct xz_buf *b);
|
||||
|
||||
/* Free the memory allocated for the BCJ filters. */
|
||||
#define xz_dec_bcj_end(s) kfree(s)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Definitions for handling the .xz file format
|
||||
*
|
||||
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
||||
*
|
||||
* This file has been put into the public domain.
|
||||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
#ifndef XZ_STREAM_H
|
||||
#define XZ_STREAM_H
|
||||
|
||||
#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
|
||||
# include <linux/crc32.h>
|
||||
# undef crc32
|
||||
# define xz_crc32(buf, size, crc) \
|
||||
(~crc32_le(~(uint32_t)(crc), buf, size))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* See the .xz file format specification at
|
||||
* http://tukaani.org/xz/xz-file-format.txt
|
||||
* to understand the container format.
|
||||
*/
|
||||
|
||||
#define STREAM_HEADER_SIZE 12
|
||||
|
||||
#define HEADER_MAGIC "\375""7zXZ"
|
||||
#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.
|
||||
*/
|
||||
typedef uint64_t vli_type;
|
||||
|
||||
#define VLI_MAX ((vli_type)-1 / 2)
|
||||
#define VLI_UNKNOWN ((vli_type)-1)
|
||||
|
||||
/* Maximum encoded size of a VLI */
|
||||
#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
|
||||
|
||||
/* Integrity Check types */
|
||||
enum xz_check {
|
||||
XZ_CHECK_NONE = 0,
|
||||
XZ_CHECK_CRC32 = 1,
|
||||
XZ_CHECK_CRC64 = 4,
|
||||
XZ_CHECK_SHA256 = 10
|
||||
};
|
||||
|
||||
/* Maximum possible Check ID */
|
||||
#define XZ_CHECK_MAX 15
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
|
||||
lib-y:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
archive_xread_all_eof.o \
|
||||
\
|
||||
seek_by_read.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
init_handle.o
|
||||
|
||||
DPKG_FILES:= \
|
||||
get_header_ar.o \
|
||||
unpack_ar_archive.o \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
lib-$(CONFIG_RPM) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
|
||||
|
||||
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_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
@@ -0,0 +1,20 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
|
||||
unsigned char *buf, size_t count)
|
||||
{
|
||||
ssize_t size;
|
||||
|
||||
size = full_read(archive_handle->src_fd, buf, count);
|
||||
if (size != 0 && size != count) {
|
||||
bb_error_msg_and_die("short read: %u of %u",
|
||||
(unsigned)size, (unsigned)count);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_align(archive_handle_t *archive_handle, unsigned boundary)
|
||||
{
|
||||
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_extract_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = xstrdup(file_header->name);
|
||||
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the existing entry if it exists */
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat old file");
|
||||
}
|
||||
}
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", file_header->name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately
|
||||
* We identified hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_target)
|
||||
&& (file_header->size == 0)
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "hard",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
} else {
|
||||
/* Create the filesystem entry */
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
file_header->mode);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1) && (errno != EISDIR)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot make dir %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_target, file_header->name);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "sym",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_error_msg_and_die("unrecognized file type");
|
||||
}
|
||||
}
|
||||
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
|
||||
if (file_header->uname) {
|
||||
struct passwd *pwd = getpwnam(file_header->uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->gname) {
|
||||
struct group *grp = getgrnam(file_header->gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
lchown(file_header->name, uid, gid);
|
||||
#else
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
#endif
|
||||
}
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_exact_size(archive_handle->src_fd,
|
||||
STDOUT_FILENO,
|
||||
archive_handle->file_header->size);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
}
|
||||
+295
-425
File diff suppressed because it is too large.
Load diff
Loaded 100 of 3155 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user