Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b400d9b2b | ||
|
|
81e26c4b8e | ||
|
|
0b16a67959 | ||
|
|
4989d05174 | ||
|
|
21e5d0f841 | ||
|
|
cf792a58ab | ||
|
|
0a53eadea5 | ||
|
|
25f07f5898 | ||
|
|
6bb89e1622 | ||
|
|
310bcec4dc | ||
|
|
8fd69c7bdb | ||
|
|
56a361bec1 | ||
|
|
6f13dd1d65 | ||
|
|
3df48bdde9 | ||
|
|
1f684bcde4 | ||
|
|
2cb72bb8de | ||
|
|
87d8ae94a2 | ||
|
|
a3de7190a5 | ||
|
|
f807b8e96e | ||
|
|
2f6dc07d8f | ||
|
|
54916641be | ||
|
|
80cb8796f8 | ||
|
|
ee67c9a60a | ||
|
|
8965e5089e | ||
|
|
e916d48e5a | ||
|
|
442d522f0b |
No files matched your search
-11
@@ -50,14 +50,3 @@ cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
|
||||
#
|
||||
# ctags output
|
||||
#
|
||||
tags
|
||||
TAGS
|
||||
|
||||
#
|
||||
# user-supplied scripts
|
||||
#
|
||||
/embed
|
||||
@@ -181,6 +181,3 @@ Jie Zhang <jie.zhang@analog.com>
|
||||
|
||||
Maxime Coste <mawww@kakoune.org>
|
||||
paste implementation
|
||||
|
||||
Roger Knecht <rknecht@pm.me>
|
||||
tree
|
||||
@@ -1,7 +1,7 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 39
|
||||
SUBLEVEL = 0
|
||||
EXTRAVERSION = .git
|
||||
PATCHLEVEL = 27
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
# *DOCUMENTATION*
|
||||
@@ -178,7 +178,7 @@ endif
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1 | sed 's:^.*/::g')
|
||||
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1)
|
||||
else
|
||||
SUBARCH := $(shell uname -m)
|
||||
endif
|
||||
@@ -361,14 +361,14 @@ 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/*)
|
||||
gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c)
|
||||
$(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
|
||||
applets_dir: scripts_basic gen_build_files
|
||||
$(Q)$(MAKE) $(build)=applets
|
||||
|
||||
applets/%: applets_dir ;
|
||||
@@ -470,13 +470,11 @@ libs-y := \
|
||||
coreutils/ \
|
||||
coreutils/libcoreutils/ \
|
||||
debianutils/ \
|
||||
klibc-utils/ \
|
||||
e2fsprogs/ \
|
||||
editors/ \
|
||||
findutils/ \
|
||||
init/ \
|
||||
libbb/ \
|
||||
libbb/yescrypt/ \
|
||||
libpwdgrp/ \
|
||||
loginutils/ \
|
||||
mailutils/ \
|
||||
@@ -510,8 +508,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
|
||||
|
||||
@@ -535,6 +531,8 @@ endif
|
||||
# Defaults busybox but it is usually overridden in the arch makefile
|
||||
all: busybox doc
|
||||
|
||||
-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)
|
||||
@@ -613,12 +611,7 @@ quiet_cmd_busybox__ ?= LINK $@
|
||||
"$(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).
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
@@ -856,14 +849,11 @@ quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
|
||||
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.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
|
||||
@@ -972,7 +962,6 @@ endif # CONFIG_MODULES
|
||||
# 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 \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
@@ -984,7 +973,6 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
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 \
|
||||
@@ -1307,6 +1295,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)))
|
||||
|
||||
+2
-8
@@ -11,9 +11,6 @@ busybox.cfg.nosuid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autocon
|
||||
$(Q)-SUID="DROP" $(SHELL) $^ > $@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_DONT),y)
|
||||
INSTALL_OPTS:= --none
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
INSTALL_OPTS:= --symlinks
|
||||
endif
|
||||
@@ -49,9 +46,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
|
||||
@@ -156,12 +150,12 @@ docs/busybox.pod: $(srctree)/docs/busybox_header.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
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2man --quotes=none --center=busybox --release="version $(KERNELVERSION)" $< > $@
|
||||
$(Q)-pod2man --center=busybox --release="version $(KERNELVERSION)" $< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
$(disp_doc)
|
||||
|
||||
+15
-49
@@ -15,8 +15,7 @@ CPPFLAGS += \
|
||||
-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,)
|
||||
@@ -27,8 +26,6 @@ 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
|
||||
@@ -50,29 +47,12 @@ 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,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
CFLAGS += $(call cc-option,-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
|
||||
|
||||
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
|
||||
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
# 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,)
|
||||
@@ -80,24 +60,19 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
|
||||
# (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
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
#CFLAGS += $(call cc-option,-Wconversion,)
|
||||
|
||||
ifneq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-Oz,$(call cc-option,-Os,$(call cc-option,-O2,)))
|
||||
CFLAGS += $(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,)))
|
||||
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
|
||||
@@ -148,20 +123,15 @@ 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)
|
||||
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >crypttest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null crypttest.c >/dev/null 2>&1 && echo "y"; rm crypttest.c)
|
||||
ifeq ($(CRYPT_AVAILABLE),y)
|
||||
LDLIBS += crypt
|
||||
endif
|
||||
# librt may be needed for clock_gettime()
|
||||
ifeq ($(RT_AVAILABLE),y)
|
||||
LDLIBS += rt
|
||||
LDLIBS += m crypt
|
||||
else
|
||||
LDLIBS += m
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
@@ -186,15 +156,6 @@ 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
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
LDLIBS += efence
|
||||
endif
|
||||
@@ -218,6 +179,11 @@ LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDLIBS),)
|
||||
LDLIBS += $(strip $(subst ",,$(CONFIG_EXTRA_LDLIBS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
# TODO: use "make stksizes" to find & fix big stack users
|
||||
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
|
||||
|
||||
@@ -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' \
|
||||
@@ -221,6 +221,10 @@ Minor stuff:
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
---
|
||||
support start-stop-daemon -d <chdir-path>
|
||||
---
|
||||
vdprintf() -> similar sized functionality
|
||||
---
|
||||
|
||||
(TODO list after discussion 11.05.2009)
|
||||
|
||||
+4
-28
@@ -10,7 +10,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -20,10 +19,6 @@
|
||||
#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"
|
||||
|
||||
@@ -56,7 +51,7 @@ static int cmp_name(const void *a, const void *b)
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum((unsigned char)*s) && *s != '_')
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
@@ -66,7 +61,6 @@ static int str_isalnum_(const char *s)
|
||||
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:
|
||||
@@ -88,18 +82,9 @@ int main(int argc, char **argv)
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (j != 0 || !argv[1])
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
|
||||
i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
dup2(i, 1);
|
||||
@@ -224,21 +209,12 @@ int main(int argc, char **argv)
|
||||
// fclose(fp);
|
||||
// }
|
||||
// if (strcmp(line_old, line_new) != 0) {
|
||||
snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid());
|
||||
fp = fopen(tmp2, "w");
|
||||
fp = fopen(argv[2], "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;
|
||||
}
|
||||
@@ -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
|
||||
}'
|
||||
@@ -19,6 +19,6 @@ int main(int argc, char **argv)
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
fputs_stdout(APPLET_full_usage "\n");
|
||||
exit_FAILURE();
|
||||
fputs(APPLET_full_usage "\n", stdout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
+32
-34
@@ -5,12 +5,9 @@ export LC_CTYPE=POSIX
|
||||
|
||||
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"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
||||
exit 1
|
||||
fi
|
||||
shift # Keep only remaining options
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
@@ -24,23 +21,20 @@ 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";;
|
||||
--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";;
|
||||
"") 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 | \
|
||||
@@ -60,7 +54,7 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
|
||||
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"
|
||||
@@ -83,13 +77,9 @@ 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
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
ln $linkopts busybox "$prefix/$i" || exit 1
|
||||
else
|
||||
rm -f "$prefix/$i"
|
||||
@@ -97,17 +87,21 @@ for i in $h; do
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ x"$binaries" = x"y" ]; then
|
||||
elif [ "$binaries" = "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
|
||||
if [ -e $sharedlib_dir/$app ]; then
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
|
||||
else
|
||||
echo " $prefix/$i already exists"
|
||||
fi
|
||||
else
|
||||
echo "Error: Could not find $sharedlib_dir/$app"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ x"$linkopts" = x"-f" ]; then
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
@@ -129,8 +123,12 @@ for i in $h; do
|
||||
;;
|
||||
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
|
||||
|
||||
|
||||
+5
-12
@@ -67,37 +67,30 @@ int main(void)
|
||||
}
|
||||
if (col == 0) {
|
||||
col = 6;
|
||||
printf("\t");
|
||||
} 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);
|
||||
}
|
||||
printf(usage_array[i].aname);
|
||||
col += len2;
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("=head1 COMMAND DESCRIPTIONS\n\n");
|
||||
printf("=over 4\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);
|
||||
printf("=item B<%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);
|
||||
}
|
||||
}
|
||||
printf("=back\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
This directory contains examples of applets implemented as shell scripts.
|
||||
|
||||
So far these scripts are not hooked to the build system and are not
|
||||
installed by "make install". If you want to use them,
|
||||
you need to install them by hand.
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
[ $# -ne 0 ] && DASH_I=-i
|
||||
sed $DASH_I -e 's/\r$//' "$@"
|
||||
@@ -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 "$@"
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
cat /etc/nologin.txt 2>/dev/null || echo This account is not available
|
||||
#!/bin/sh
|
||||
cat /etc/nologin.txt 2>/dev/null || echo "This account is not available"
|
||||
sleep 5
|
||||
exit 1
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
for i in "$@"
|
||||
do
|
||||
sed -e '1!G;h;$!d' "$i"
|
||||
done
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
[ $# -ne 0 ] && DASH_I=-i
|
||||
sed $DASH_I -e 's/$/\r/' "$@"
|
||||
+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,)
|
||||
+1
-20
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Archival Utilities"
|
||||
@@ -27,23 +27,4 @@ config FEATURE_SEAMLESS_Z
|
||||
|
||||
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
|
||||
+54
-62
@@ -16,41 +16,53 @@
|
||||
* 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: bool "ar"
|
||||
//config: default n # needs to be improved to be able to replace binutils ar
|
||||
//config: help
|
||||
//config: ar is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives. In practice, it is used exclusively
|
||||
//config: for object module archives used by compilers.
|
||||
//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: On an x86 system, the ar applet adds about 1K.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires ar, you should
|
||||
//config: probably say N here: 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: 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.
|
||||
//config: This enables archive creation (-c and -r) with busybox ar.
|
||||
|
||||
//applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_AR) += ar.o
|
||||
|
||||
//usage:#define ar_trivial_usage
|
||||
//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
|
||||
//usage:#define ar_full_usage "\n\n"
|
||||
//usage: "Extract or list FILES from an ar archive\n"
|
||||
//usage: "\n -o Preserve original dates"
|
||||
//usage: "\n -p Extract to stdout"
|
||||
//usage: "\n -t List"
|
||||
//usage: "\n -x Extract"
|
||||
//usage: "\n -v Verbose"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "ar_.h"
|
||||
#include "ar.h"
|
||||
|
||||
#if ENABLE_FEATURE_AR_CREATE
|
||||
/* filter out entries with same names as specified on the command line */
|
||||
@@ -151,15 +163,15 @@ static int write_ar_header(archive_handle_t *handle)
|
||||
|
||||
static int write_ar_archive(archive_handle_t *handle)
|
||||
{
|
||||
off_t st_size;
|
||||
struct stat st;
|
||||
archive_handle_t *out_handle;
|
||||
|
||||
st_size = xfstat_size(handle->src_fd, handle->ar__name);
|
||||
xfstat(handle->src_fd, &st, 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) {
|
||||
if (st.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);
|
||||
@@ -174,7 +186,7 @@ static int write_ar_archive(archive_handle_t *handle)
|
||||
out_handle->offset += AR_MAGIC_LEN + 1;
|
||||
|
||||
/* skip to the end of the archive if we have to append stuff */
|
||||
if (st_size != 0) {
|
||||
if (st.st_size != 0) {
|
||||
handle->filter = filter_replaceable;
|
||||
handle->action_data = copy_data;
|
||||
unpack_ar_archive(handle);
|
||||
@@ -194,13 +206,11 @@ static int write_ar_archive(archive_handle_t *handle)
|
||||
}
|
||||
#endif /* FEATURE_AR_CREATE */
|
||||
|
||||
static void FAST_FUNC header_verbose_list_ar(archive_handle_t *archive_handle)
|
||||
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
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);
|
||||
@@ -212,75 +222,57 @@ static void FAST_FUNC header_verbose_list_ar(archive_handle_t *archive_handle)
|
||||
);
|
||||
}
|
||||
|
||||
//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_OPT_VERBOSE (1 << 0)
|
||||
#define AR_OPT_PRESERVE_DATE (1 << 1)
|
||||
/* "ar r" implies create, but warns about it. c suppresses warning.
|
||||
* bbox accepts but ignores it: */
|
||||
#define AR_OPT_CREATE (1 << 2)
|
||||
|
||||
#define AR_CMD_PRINT (1 << 3)
|
||||
#define FIRST_CMD AR_CMD_PRINT
|
||||
#define AR_CMD_LIST (1 << 4)
|
||||
#define AR_CMD_EXTRACT (1 << 5)
|
||||
#define AR_CMD_INSERT (1 << 6)
|
||||
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
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),
|
||||
};
|
||||
|
||||
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")
|
||||
);
|
||||
/* --: prepend '-' to the first argument if required */
|
||||
/* -1: at least one param is reqd */
|
||||
/* one of p,t,x[,r] is required */
|
||||
opt_complementary = "--:-1:p:t:x"IF_FEATURE_AR_CREATE(":r");
|
||||
opt = getopt32(argv, "voc""ptx"IF_FEATURE_AR_CREATE("r"));
|
||||
argv += optind;
|
||||
|
||||
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_CMD_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & CMD_LIST) {
|
||||
if (opt & AR_CMD_LIST) {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & CMD_EXTRACT) {
|
||||
if (opt & AR_CMD_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & OPT_PRESERVE_DATE) {
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_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)
|
||||
(opt & AR_CMD_INSERT)
|
||||
? O_RDWR | O_CREAT
|
||||
: O_RDONLY
|
||||
);
|
||||
@@ -292,7 +284,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_AR_CREATE
|
||||
if (opt & CMD_INSERT)
|
||||
if (opt & AR_CMD_INSERT)
|
||||
return write_ar_archive(archive_handle);
|
||||
#endif
|
||||
|
||||
|
||||
+99
-76
@@ -4,6 +4,9 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
|
||||
@@ -18,8 +21,18 @@
|
||||
/* gzip_main() too: */
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
OPT_STDOUT = 1 << 0,
|
||||
OPT_FORCE = 1 << 1,
|
||||
/* only some decompressors: */
|
||||
OPT_KEEP = 1 << 2,
|
||||
OPT_VERBOSE = 1 << 3,
|
||||
OPT_QUIET = 1 << 4,
|
||||
OPT_DECOMPRESS = 1 << 5,
|
||||
OPT_TEST = 1 << 6,
|
||||
SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
@@ -59,7 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
err_name:
|
||||
bb_simple_perror_msg(filename);
|
||||
@@ -71,22 +84,22 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
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);
|
||||
/* fail_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
}
|
||||
} else
|
||||
if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*die_if_not_compressed*/ 1))
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
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();
|
||||
filename = NULL;
|
||||
@@ -101,7 +114,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* -f: overwrite existing output files */
|
||||
if (option_mask32 & BBUNPK_OPT_FORCE) {
|
||||
if (option_mask32 & OPT_FORCE) {
|
||||
unlink(new_name);
|
||||
}
|
||||
|
||||
@@ -113,12 +126,12 @@ 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 (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
/*xstate.signature_skipped = 0; - already is */
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
@@ -132,7 +145,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
if (!(option_mask32 & BBUNPK_OPT_STDOUT))
|
||||
if (!(option_mask32 & OPT_STDOUT))
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
@@ -163,7 +176,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
/* Extreme bloat for gunzip compat */
|
||||
/* Some users do want this info... */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & BBUNPK_OPT_VERBOSE)) {
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
|
||||
unsigned percent = status
|
||||
? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
|
||||
: 0;
|
||||
@@ -175,7 +188,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
/* Delete _source_ file */
|
||||
del = filename;
|
||||
if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
|
||||
if (option_mask32 & OPT_KEEP) /* ... unless -k */
|
||||
del = NULL;
|
||||
}
|
||||
if (del)
|
||||
@@ -186,7 +199,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
if (option_mask32 & BBUNPK_OPT_STDOUT)
|
||||
if (option_mask32 & OPT_STDOUT)
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
return exitcode;
|
||||
@@ -219,16 +232,16 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//usage:#define uncompress_trivial_usage
|
||||
//usage: "[-cf] [FILE]..."
|
||||
//usage:#define uncompress_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "Decompress .Z file[s]\n"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Overwrite"
|
||||
|
||||
//config:config UNCOMPRESS
|
||||
//config: bool "uncompress (7.1 kb)"
|
||||
//config: bool "uncompress"
|
||||
//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.
|
||||
//config: uncompress is used to decompress archives created by compress.
|
||||
//config: Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
@@ -284,7 +297,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -k Keep input files"
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: "\n -t Test file integrity"
|
||||
//usage:
|
||||
//usage:#define gunzip_example_usage
|
||||
//usage: "$ ls -la /tmp/BusyBox*\n"
|
||||
@@ -299,20 +312,20 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config GUNZIP
|
||||
//config: bool "gunzip (11 kb)"
|
||||
//config: bool "gunzip"
|
||||
//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: 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: bool "zcat"
|
||||
//config: default y
|
||||
//config: select FEATURE_GZIP_DECOMPRESS
|
||||
//config: help
|
||||
//config: Alias to "gunzip -c".
|
||||
//config: Alias to "gunzip -c".
|
||||
//config:
|
||||
//config:config FEATURE_GUNZIP_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
@@ -376,10 +389,9 @@ int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts);
|
||||
#else
|
||||
getopt32(argv, BBUNPK_OPTSTR "dtn");
|
||||
applet_long_options = gunzip_longopts;
|
||||
#endif
|
||||
getopt32(argv, "cfkvqdtn");
|
||||
argv += optind;
|
||||
|
||||
/* If called as zcat...
|
||||
@@ -387,7 +399,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
* 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;
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
@@ -407,33 +419,31 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//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: bool "bunzip2"
|
||||
//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: 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: 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: bool "bzcat"
|
||||
//config: default y
|
||||
//config: select FEATURE_BZIP2_DECOMPRESS
|
||||
//config: help
|
||||
//config: Alias to "bunzip2 -c".
|
||||
//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
|
||||
@@ -442,10 +452,10 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
getopt32(argv, "cfkvqdt");
|
||||
argv += optind;
|
||||
if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
}
|
||||
@@ -463,21 +473,19 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage:#define unlzma_trivial_usage
|
||||
//usage: "[-cfk] [FILE]..."
|
||||
//usage:#define unlzma_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "Decompress FILE (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: "Decompress FILE (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]..."
|
||||
@@ -485,26 +493,43 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNLZMA
|
||||
//config: bool "unlzma (7.8 kb)"
|
||||
//config: bool "unlzma"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
//config: compression algorithm, and range coding. Compression
|
||||
//config: is generally considerably better than that achieved by the bzip2
|
||||
//config: compressors.
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
//config: compression algorithm, and range coding. Compression
|
||||
//config: is generally considerably better than that achieved by the bzip2
|
||||
//config: compressors.
|
||||
//config:
|
||||
//config: The BusyBox unlzma applet is limited to decompression only.
|
||||
//config: On an x86 system, this applet adds about 4K.
|
||||
//config:
|
||||
//config:config LZCAT
|
||||
//config: bool "lzcat (7.8 kb)"
|
||||
//config: bool "lzcat"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Alias to "unlzma -c".
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
//config: compression algorithm, and range coding. Compression
|
||||
//config: is generally considerably better than that achieved by the bzip2
|
||||
//config: compressors.
|
||||
//config:
|
||||
//config: The BusyBox unlzma applet is limited to decompression only.
|
||||
//config: On an x86 system, this applet adds about 4K.
|
||||
//config:
|
||||
//config:config 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.
|
||||
//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.
|
||||
//config:
|
||||
//config:config FEATURE_LZMA_FAST
|
||||
//config: bool "Optimize for speed"
|
||||
//config: default n
|
||||
//config: depends on UNLZMA || LZCAT || LZMA
|
||||
//config: help
|
||||
//config: This option reduces decompression time by about 25% at the cost of
|
||||
//config: a 1K bigger binary.
|
||||
|
||||
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
@@ -517,15 +542,15 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* lzcat? */
|
||||
if (ENABLE_LZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
@@ -536,21 +561,19 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage:#define unxz_trivial_usage
|
||||
//usage: "[-cfk] [FILE]..."
|
||||
//usage:#define unxz_full_usage "\n\n"
|
||||
//usage: "Decompress FILEs (or stdin)\n"
|
||||
//usage: "Decompress FILE (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: "Decompress FILE (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]..."
|
||||
@@ -558,23 +581,23 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNXZ
|
||||
//config: bool "unxz (13 kb)"
|
||||
//config: bool "unxz"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unxz is a unlzma successor.
|
||||
//config: unxz is a unlzma successor.
|
||||
//config:
|
||||
//config:config XZCAT
|
||||
//config: bool "xzcat (13 kb)"
|
||||
//config: bool "xzcat"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Alias to "unxz -c".
|
||||
//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.
|
||||
//config: Enable this option if you want commands like "xz -d" to work.
|
||||
//config: IOW: you'll get xz applet, but it will always require -d option.
|
||||
|
||||
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
@@ -587,15 +610,15 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* xzcat? */
|
||||
if (ENABLE_XZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
|
||||
+35
-63
@@ -6,72 +6,49 @@
|
||||
* See README and LICENSE files in bz/ directory for more information
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
|
||||
//config:config BZIP2
|
||||
//config: bool "bzip2 (16 kb)"
|
||||
//config: bool "bzip2"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
//config: sorting text compression algorithm, and Huffman coding. Compression
|
||||
//config: is generally considerably better than that achieved by more
|
||||
//config: conventional LZ77/LZ78-based compressors, and approaches the
|
||||
//config: performance of the PPM family of statistical compressors.
|
||||
//config: 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: Unless you have a specific application which requires bzip2, you
|
||||
//config: should probably say N here.
|
||||
//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.
|
||||
//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: "[OPTIONS] [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: "\n -t Test file integrity"
|
||||
//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_FAST 1
|
||||
|
||||
/* Speed test:
|
||||
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
|
||||
@@ -79,7 +56,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_FAST 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
|
||||
@@ -106,13 +83,15 @@
|
||||
/* 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)
|
||||
@@ -147,7 +126,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" : bb_msg_write_error);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -164,7 +143,6 @@ static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
unsigned opt, level;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
@@ -173,23 +151,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(bb_msg_read_error);
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
@@ -228,20 +195,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) */
|
||||
);
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs");
|
||||
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
|
||||
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
|
||||
if (opt & 0x30) // -d and/or -t
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 6;
|
||||
#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 >>= 4;
|
||||
#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;
|
||||
option_mask32 &= 0xf; /* ignore all except -cfkv */
|
||||
return bbunpack(argv, compressStream, append_ext, "bz2");
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
+26
-96
@@ -10,51 +10,40 @@
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
//config:config CPIO
|
||||
//config: bool "cpio (15 kb)"
|
||||
//config: bool "cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cpio is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives.
|
||||
//config: cpio has 110 bytes of overheads for every stored file.
|
||||
//config: 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: 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: 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: 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))
|
||||
//config: Passthrough mode. Rarely used.
|
||||
|
||||
//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
|
||||
|
||||
//usage:#define cpio_trivial_usage
|
||||
@@ -62,7 +51,7 @@
|
||||
//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: "Extract (-i) or list (-t) files from a cpio archive"
|
||||
//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)")
|
||||
@@ -78,22 +67,14 @@
|
||||
//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 -m Preserve 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: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -H newc Archive format"
|
||||
//usage: )
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
@@ -161,10 +142,6 @@
|
||||
-u, --unconditional Replace all files unconditionally
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
enum {
|
||||
OPT_EXTRACT = (1 << 0),
|
||||
OPT_TEST = (1 << 1),
|
||||
@@ -182,22 +159,17 @@ enum {
|
||||
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);
|
||||
@@ -231,9 +203,6 @@ static NOINLINE int cpio_o(void)
|
||||
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;
|
||||
@@ -288,10 +257,6 @@ static NOINLINE int cpio_o(void)
|
||||
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;
|
||||
}
|
||||
@@ -310,11 +275,6 @@ static NOINLINE int cpio_o(void)
|
||||
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) {
|
||||
@@ -322,10 +282,6 @@ static NOINLINE int cpio_o(void)
|
||||
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)
|
||||
@@ -345,17 +301,6 @@ static NOINLINE int cpio_o(void)
|
||||
}
|
||||
}
|
||||
|
||||
#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 */
|
||||
@@ -415,8 +360,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *cpio_owner;
|
||||
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
const char *long_opts =
|
||||
applet_long_options =
|
||||
"extract\0" No_argument "i"
|
||||
"list\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
@@ -427,17 +373,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
#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
|
||||
|
||||
@@ -452,9 +390,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* -L makes sense only with -o or -p */
|
||||
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner);
|
||||
opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
|
||||
#else
|
||||
opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts,
|
||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
|
||||
&cpio_filename, &cpio_owner, &cpio_fmt);
|
||||
#endif
|
||||
argv += optind;
|
||||
@@ -477,8 +415,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
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);
|
||||
mkdir(argv[0], 0777);
|
||||
/* Crude existence check:
|
||||
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||
@@ -488,11 +425,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
* 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;
|
||||
@@ -511,6 +443,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto dump;
|
||||
}
|
||||
/* parent */
|
||||
USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
|
||||
xchdir(*argv++);
|
||||
close(pp.wr);
|
||||
xmove_fd(pp.rd, STDIN_FILENO);
|
||||
@@ -575,12 +508,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+156
-216
@@ -25,46 +25,46 @@
|
||||
* bugs that need to be fixed
|
||||
* - (unknown, please let me know when you find any)
|
||||
*/
|
||||
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg (43 kb)"
|
||||
//config: bool "dpkg"
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
//config: Debian packages.
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
//config: Debian packages.
|
||||
//config:
|
||||
//config: This implementation of dpkg has a number of limitations,
|
||||
//config: you should use the official dpkg if possible.
|
||||
//config: This implementation of dpkg has a number of limitations,
|
||||
//config: you should use the official dpkg if possible.
|
||||
|
||||
//applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_DPKG) += dpkg.o
|
||||
|
||||
//usage:#define dpkg_trivial_usage
|
||||
//usage: IF_LONG_OPTS("-i|P|r|--unpack|--configure [--force-OPT]")IF_NOT_LONG_OPTS("-i|P|r|u|C [-F OPT]")" PACKAGE | -l [PATTERN]"
|
||||
//usage: "[-ilCPru] [-F OPT] PACKAGE"
|
||||
//usage:#define dpkg_full_usage "\n\n"
|
||||
//usage: "Manage Debian packages\n"
|
||||
//usage: "Install, remove and manage Debian packages\n"
|
||||
//usage: IF_LONG_OPTS(
|
||||
//usage: "\n -i,--install Install PACKAGE.deb"
|
||||
//usage: "\n -P,--purge Purge all files of PACKAGE"
|
||||
//usage: "\n -r,--remove Remove all but configuration files of PACKAGE"
|
||||
//usage: "\n --unpack Unpack PACKAGE.deb relative to /, don't configure"
|
||||
//usage: "\n --configure Configure unpacked PACKAGE"
|
||||
//usage: "\n -i,--install Install the package"
|
||||
//usage: "\n -l,--list List of installed packages"
|
||||
//usage: "\n --configure Configure an unpackaged package"
|
||||
//usage: "\n -P,--purge Purge all files of a package"
|
||||
//usage: "\n -r,--remove Remove all but the configuration files for a package"
|
||||
//usage: "\n --unpack Unpack a package, but don't configure it"
|
||||
//usage: "\n --force-depends Ignore dependency problems"
|
||||
//usage: "\n --force-confnew Overwrite existing config files when installing"
|
||||
//usage: "\n --force-confold Keep old config files when installing"
|
||||
//usage: "\n -l,--list List installed packages"
|
||||
//usage: )
|
||||
//usage: IF_NOT_LONG_OPTS(
|
||||
//usage: "\n -i Install PACKAGE.deb"
|
||||
//usage: "\n -P Purge all files of PACKAGE"
|
||||
//usage: "\n -r Remove all but configuration files of PACKAGE"
|
||||
//usage: "\n -u Unpack PACKAGE.deb relative to /, don't configure"
|
||||
//usage: "\n -C Configure unpacked PACKAGE"
|
||||
//usage: "\n -i Install the package"
|
||||
//usage: "\n -l List of installed packages"
|
||||
//usage: "\n -C Configure an unpackaged package"
|
||||
//usage: "\n -P Purge all files of a package"
|
||||
//usage: "\n -r Remove all but the configuration files for a package"
|
||||
//usage: "\n -u Unpack a package, but don't configure it"
|
||||
//usage: "\n -F depends Ignore dependency problems"
|
||||
//usage: "\n -F confnew Overwrite existing config files when installing"
|
||||
//usage: "\n -F confold Keep old config files when installing"
|
||||
//usage: "\n -l List installed packages"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -166,9 +166,8 @@ typedef struct deb_file_s {
|
||||
} deb_file_t;
|
||||
|
||||
|
||||
static unsigned make_hash(const char *key, unsigned *decrement, int hash_prime)
|
||||
static void make_hash(const char *key, unsigned *start, unsigned *decrement, const int hash_prime)
|
||||
{
|
||||
unsigned start;
|
||||
unsigned long hash_num = key[0];
|
||||
int len = strlen(key);
|
||||
int i;
|
||||
@@ -182,9 +181,8 @@ static unsigned make_hash(const char *key, unsigned *decrement, int hash_prime)
|
||||
* no effect */
|
||||
hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
|
||||
}
|
||||
start = (unsigned) hash_num % hash_prime;
|
||||
*start = (unsigned) hash_num % hash_prime;
|
||||
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
|
||||
return start;
|
||||
}
|
||||
|
||||
/* this adds the key to the hash table */
|
||||
@@ -193,7 +191,7 @@ static int search_name_hashtable(const char *key)
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
probe_address = make_hash(key, &probe_decrement, NAME_HASH_PRIME);
|
||||
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
|
||||
while (name_hashtable[probe_address] != NULL) {
|
||||
if (strcmp(name_hashtable[probe_address], key) == 0) {
|
||||
return probe_address;
|
||||
@@ -215,7 +213,7 @@ static unsigned search_status_hashtable(const char *key)
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
probe_address = make_hash(key, &probe_decrement, STATUS_HASH_PRIME);
|
||||
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
|
||||
while (status_hashtable[probe_address] != NULL) {
|
||||
if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) {
|
||||
break;
|
||||
@@ -282,7 +280,7 @@ static int version_compare_part(const char *val, const char *ref)
|
||||
* if ver1 = ver2 return 0,
|
||||
* if ver1 > ver2 return 1,
|
||||
*/
|
||||
static int version_compare(unsigned ver1, unsigned ver2)
|
||||
static int version_compare(const unsigned ver1, const unsigned ver2)
|
||||
{
|
||||
char *ch_ver1 = name_hashtable[ver1];
|
||||
char *ch_ver2 = name_hashtable[ver2];
|
||||
@@ -335,9 +333,9 @@ static int version_compare(unsigned ver1, unsigned ver2)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int test_version(unsigned version1, unsigned version2, unsigned operator)
|
||||
static int test_version(const unsigned version1, const unsigned version2, const unsigned operator)
|
||||
{
|
||||
int version_result = version_compare(version1, version2);
|
||||
const int version_result = version_compare(version1, version2);
|
||||
switch (operator) {
|
||||
case VER_ANY:
|
||||
return TRUE;
|
||||
@@ -355,12 +353,12 @@ static int test_version(unsigned version1, unsigned version2, unsigned operator)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int search_package_hashtable(unsigned name, unsigned version, unsigned operator)
|
||||
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
|
||||
{
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
probe_address = make_hash(name_hashtable[name], &probe_decrement, PACKAGE_HASH_PRIME);
|
||||
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
|
||||
while (package_hashtable[probe_address] != NULL) {
|
||||
if (package_hashtable[probe_address]->name == name) {
|
||||
if (operator == VER_ANY) {
|
||||
@@ -489,7 +487,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
} else if (strncmp(version, ">=", offset_ch) == 0) {
|
||||
edge->operator = VER_MORE_EQUAL;
|
||||
} else {
|
||||
bb_simple_error_msg_and_die("illegal operator");
|
||||
bb_error_msg_and_die("illegal operator");
|
||||
}
|
||||
}
|
||||
/* skip to start of version numbers */
|
||||
@@ -533,98 +531,90 @@ static void free_package(common_node_t *node)
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the next package field from pkg_buf:
|
||||
* "NAME:<spaces|tabs>VALUE{\n|NUL}"
|
||||
* "NAME:<spaces|tabs>VALUE\n
|
||||
* " VALUE_LINE2{\n|NUL}"
|
||||
* separated into "NAME" and "VALUE", both strdup()ed.
|
||||
* (Debian does not allow whitespace before/after NAME).
|
||||
* Returns offset to the first character of the next field (or to NUL).
|
||||
* The pkg_buf parameter is NUL-terminated.
|
||||
*
|
||||
* https://manpages.debian.org/testing/dpkg-dev/deb-control.5.en.html
|
||||
* """
|
||||
* This file contains a number of fields. Each field begins with a tag,
|
||||
* such as Package or Version (case insensitive), followed by a colon,
|
||||
* and the body of the field (case sensitive unless stated otherwise).
|
||||
* Fields are delimited only by field tags. In other words, field text
|
||||
* may be multiple lines in length, but the installation tools will
|
||||
* generally join lines when processing the body of the field (except
|
||||
* in the case of the Description field, see below).
|
||||
* ...
|
||||
* Description: short-description (recommended)
|
||||
* long-description
|
||||
* The format for the package description is a short brief summary
|
||||
* on the first line (after the Description field). The following lines
|
||||
* should be used as a longer, more detailed description. Each line
|
||||
* of the long description must be preceded by a space, and blank
|
||||
* lines in the long description must contain a single '.' following
|
||||
* the preceding space."""
|
||||
*
|
||||
* Seen in libgtk-3-0t64_3.24.52: source package's control:
|
||||
* Recommends: ibus-gtk3,
|
||||
* libgtk-3-bin,
|
||||
* librsvg2-common
|
||||
* gets translated to this in binary package's control:
|
||||
* Recommends: ibus-gtk3, libgtk-3-bin, librsvg2-common
|
||||
* Gets the next package field from package_buffer, separated into the field name
|
||||
* and field value, it returns the int offset to the first character of the next field
|
||||
*/
|
||||
static int read_package_field(const char *pkg_buf, char **pname, char **pvalue)
|
||||
static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
|
||||
{
|
||||
int name_start;
|
||||
int name_end;
|
||||
int value_start = value_start;
|
||||
int offset;
|
||||
int offset_name_start = 0;
|
||||
int offset_name_end = 0;
|
||||
int offset_value_start = 0;
|
||||
int offset_value_end = 0;
|
||||
int offset = 0;
|
||||
int next_offset;
|
||||
int name_length;
|
||||
int value_length;
|
||||
int exit_flag = FALSE;
|
||||
|
||||
*pname = NULL;
|
||||
*pvalue = NULL;
|
||||
|
||||
offset = 0;
|
||||
name_start = 0;
|
||||
name_end = 0; /* "we did not see ':' yet" */
|
||||
if (package_buffer == NULL) {
|
||||
*field_name = NULL;
|
||||
*field_value = NULL;
|
||||
return -1;
|
||||
}
|
||||
while (1) {
|
||||
char ch = pkg_buf[offset];
|
||||
switch (ch) {
|
||||
case ':':
|
||||
if (name_end == 0) {
|
||||
offset++;
|
||||
name_end = offset; /* points AFTER ':' - think of empty NAME case */
|
||||
while (isblank(pkg_buf[offset])) /* skip spaces/tabs (not newlines!) */
|
||||
offset++;
|
||||
value_start = offset;
|
||||
continue; /* check next char */
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
if (pkg_buf[offset + 1] == ' ')
|
||||
next_offset = offset + 1;
|
||||
switch (package_buffer[offset]) {
|
||||
case '\0':
|
||||
exit_flag = TRUE;
|
||||
break;
|
||||
/* end of VALUE - fall through */
|
||||
case '\0':
|
||||
/* Did we see the ':'? */
|
||||
if (name_end != 0) {
|
||||
/* Yes. Check that NAME is not empty */
|
||||
int nlen = (name_end - 1) - name_start;
|
||||
if (nlen > 0) {
|
||||
//TODO: why do we disallow empty NAME? Imagine a ": VALUE\n" line
|
||||
*pname = xstrndup(&pkg_buf[name_start], nlen);
|
||||
*pvalue = xstrndup(&pkg_buf[value_start], offset - value_start); /* could be "" */
|
||||
if (ch)
|
||||
offset++; /* skip '\n' */
|
||||
return offset;
|
||||
case ':':
|
||||
if (offset_name_end == 0) {
|
||||
offset_name_end = offset;
|
||||
offset_value_start = next_offset;
|
||||
}
|
||||
/* TODO: Name might still have trailing spaces if ':' isn't
|
||||
* immediately after name */
|
||||
break;
|
||||
case '\n':
|
||||
/* TODO: The char next_offset may be out of bounds */
|
||||
if (package_buffer[next_offset] != ' ') {
|
||||
exit_flag = TRUE;
|
||||
break;
|
||||
}
|
||||
case '\t':
|
||||
case ' ':
|
||||
/* increment the value start point if its a just filler */
|
||||
if (offset_name_start == offset) {
|
||||
offset_name_start++;
|
||||
}
|
||||
if (offset_value_start == offset) {
|
||||
offset_value_start++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (exit_flag) {
|
||||
/* Check that the names are valid */
|
||||
offset_value_end = offset;
|
||||
name_length = offset_name_end - offset_name_start;
|
||||
value_length = offset_value_end - offset_value_start;
|
||||
if (name_length == 0) {
|
||||
break;
|
||||
}
|
||||
if ((name_length > 0) && (value_length > 0)) {
|
||||
break;
|
||||
}
|
||||
if (!ch)
|
||||
return offset; /* stop at NUL */
|
||||
|
||||
/* Not valid: skip '\n', start fresh with next field */
|
||||
name_start = offset + 1;
|
||||
name_end = 0; /* "we did not see ':' yet" */
|
||||
break;
|
||||
/* If not valid, start fresh with next field */
|
||||
exit_flag = FALSE;
|
||||
offset_name_start = offset + 1;
|
||||
offset_name_end = 0;
|
||||
offset_value_start = offset + 1;
|
||||
offset_value_end = offset + 1;
|
||||
offset++;
|
||||
}
|
||||
offset++;
|
||||
} /* while (1) */
|
||||
}
|
||||
*field_name = NULL;
|
||||
if (name_length) {
|
||||
*field_name = xstrndup(&package_buffer[offset_name_start], name_length);
|
||||
}
|
||||
*field_value = NULL;
|
||||
if (value_length > 0) {
|
||||
*field_value = xstrndup(&package_buffer[offset_value_start], value_length);
|
||||
}
|
||||
return next_offset;
|
||||
}
|
||||
|
||||
/* The parameter is NUL-terminated */
|
||||
static unsigned fill_package_struct(char *control_buffer)
|
||||
{
|
||||
static const char field_names[] ALIGN1 =
|
||||
@@ -633,13 +623,14 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
"Conflicts\0""Suggests\0""Recommends\0""Enhances\0";
|
||||
|
||||
common_node_t *new_node = xzalloc(sizeof(common_node_t));
|
||||
char *field_name;
|
||||
char *field_value;
|
||||
int field_start = 0;
|
||||
int num;
|
||||
int num = -1;
|
||||
int buffer_length = strlen(control_buffer);
|
||||
|
||||
new_node->version = search_name_hashtable("unknown");
|
||||
while (control_buffer[field_start]) {
|
||||
char *field_name;
|
||||
char *field_value;
|
||||
while (field_start < buffer_length) {
|
||||
unsigned field_num;
|
||||
|
||||
field_start += read_package_field(&control_buffer[field_start],
|
||||
@@ -698,7 +689,7 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
}
|
||||
|
||||
/* if num = 1, it returns the want status, 2 returns flag, 3 returns status */
|
||||
static unsigned get_status(unsigned status_node, int num)
|
||||
static unsigned get_status(const unsigned status_node, const int num)
|
||||
{
|
||||
char *status_string = name_hashtable[status_hashtable[status_node]->status];
|
||||
char *state_sub_string;
|
||||
@@ -720,9 +711,9 @@ static unsigned get_status(unsigned status_node, int num)
|
||||
return state_sub_num;
|
||||
}
|
||||
|
||||
static void set_status(unsigned status_node_num, const char *new_value, int position)
|
||||
static void set_status(const unsigned status_node_num, const char *new_value, const int position)
|
||||
{
|
||||
unsigned new_value_num = search_name_hashtable(new_value);
|
||||
const unsigned new_value_num = search_name_hashtable(new_value);
|
||||
unsigned want = get_status(status_node_num, 1);
|
||||
unsigned flag = get_status(status_node_num, 2);
|
||||
unsigned status = get_status(status_node_num, 3);
|
||||
@@ -739,7 +730,7 @@ static void set_status(unsigned status_node_num, const char *new_value, int posi
|
||||
status = new_value_num;
|
||||
break;
|
||||
default:
|
||||
bb_simple_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
|
||||
bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
|
||||
}
|
||||
|
||||
new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
|
||||
@@ -780,10 +771,9 @@ static void index_status_file(const char *filename)
|
||||
status_node_t *status_node = NULL;
|
||||
unsigned status_num;
|
||||
|
||||
//FIXME: dpkg 1.22.22 recreates empty /var/lib/dpkg/status if it's missing - does not fail
|
||||
status_file = xfopen_for_read(filename);
|
||||
while ((control_buffer = xmalloc_fgetline_str(status_file, "\n\n")) != NULL) {
|
||||
unsigned package_num = fill_package_struct(control_buffer);
|
||||
const unsigned package_num = fill_package_struct(control_buffer);
|
||||
if (package_num != -1) {
|
||||
status_node = xmalloc(sizeof(status_node_t));
|
||||
/* fill_package_struct doesn't handle the status field */
|
||||
@@ -809,7 +799,7 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
|
||||
char *name;
|
||||
char *value;
|
||||
int start = 0;
|
||||
while (control_buffer[start]) {
|
||||
while (1) {
|
||||
start += read_package_field(&control_buffer[start], &name, &value);
|
||||
if (name == NULL) {
|
||||
break;
|
||||
@@ -817,42 +807,42 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
|
||||
if (strcmp(name, "Status") != 0) {
|
||||
fprintf(new_status_file, "%s: %s\n", name, value);
|
||||
}
|
||||
free(name);
|
||||
free(value);
|
||||
}
|
||||
}
|
||||
|
||||
/* This could do with a cleanup */
|
||||
static void write_status_file(deb_file_t **deb_file)
|
||||
{
|
||||
//FIXME: dpkg 1.22.22 recreates empty /var/lib/dpkg/status if it's missing - does not fail
|
||||
FILE *old_status_file = xfopen_for_read("/var/lib/dpkg/status");
|
||||
FILE *new_status_file = xfopen_for_write("/var/lib/dpkg/status.udeb");
|
||||
char *control_buffer;
|
||||
char *package_name;
|
||||
char *status_from_file;
|
||||
char *control_buffer = NULL;
|
||||
char *tmp_string;
|
||||
int status_num;
|
||||
int i;
|
||||
int field_start = 0;
|
||||
int write_flag;
|
||||
int i = 0;
|
||||
|
||||
/* Update previously known packages */
|
||||
while ((control_buffer = xmalloc_fgetline_str(old_status_file, "\n\n")) != NULL) {
|
||||
char *package_name;
|
||||
char *status_from_file;
|
||||
char *tmp_string;
|
||||
int write_flag;
|
||||
|
||||
tmp_string = strstr(control_buffer, "Package:");
|
||||
if (tmp_string == NULL) {
|
||||
free(control_buffer);
|
||||
continue;
|
||||
}
|
||||
tmp_string = skip_whitespace(tmp_string + 8);
|
||||
package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
|
||||
|
||||
tmp_string += 8;
|
||||
tmp_string += strspn(tmp_string, " \n\t");
|
||||
package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
|
||||
write_flag = FALSE;
|
||||
status_from_file = NULL;
|
||||
tmp_string = strstr(control_buffer, "Status:");
|
||||
if (tmp_string != NULL) {
|
||||
tmp_string = skip_whitespace(tmp_string + 7);
|
||||
/* Separate the status value from the control buffer */
|
||||
tmp_string += 7;
|
||||
tmp_string += strspn(tmp_string, " \n\t");
|
||||
status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
|
||||
} else {
|
||||
status_from_file = NULL;
|
||||
}
|
||||
|
||||
/* Find this package in the status hashtable */
|
||||
@@ -861,7 +851,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
const char *status_from_hashtable = name_hashtable[status_hashtable[status_num]->status];
|
||||
if (strcmp(status_from_file, status_from_hashtable) != 0) {
|
||||
/* New status isn't exactly the same as old status */
|
||||
int state_status = get_status(status_num, 3);
|
||||
const int state_status = get_status(status_num, 3);
|
||||
if ((strcmp("installed", name_hashtable[state_status]) == 0)
|
||||
|| (strcmp("unpacked", name_hashtable[state_status]) == 0)
|
||||
) {
|
||||
@@ -880,7 +870,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
/* This is temporary, debugging only */
|
||||
/* This is temperary, debugging only */
|
||||
if (deb_file[i] == NULL) {
|
||||
bb_error_msg_and_die("ALERT: cannot find a control file, "
|
||||
"your status file may be broken, status may be "
|
||||
@@ -888,18 +878,14 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
}
|
||||
}
|
||||
else if (strcmp("not-installed", name_hashtable[state_status]) == 0) {
|
||||
int field_start = 0;
|
||||
|
||||
/* Only write the Package, Status, Priority and Section lines */
|
||||
fprintf(new_status_file, "Package: %s\n", package_name);
|
||||
fprintf(new_status_file, "Status: %s\n", status_from_hashtable);
|
||||
|
||||
while (control_buffer[field_start]) {
|
||||
while (1) {
|
||||
char *field_name;
|
||||
char *field_value;
|
||||
field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value);
|
||||
//FIXME: the questionable ": VALUE" lines (empty NAME)
|
||||
//probably should not stop parsing of the entire file?
|
||||
if (field_name == NULL) {
|
||||
break;
|
||||
}
|
||||
@@ -908,17 +894,13 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
) {
|
||||
fprintf(new_status_file, "%s: %s\n", field_name, field_value);
|
||||
}
|
||||
free(field_name);
|
||||
free(field_value);
|
||||
}
|
||||
write_flag = TRUE;
|
||||
fputs("\n", new_status_file);
|
||||
}
|
||||
else if (strcmp("config-files", name_hashtable[state_status]) == 0) {
|
||||
int field_start = 0;
|
||||
|
||||
/* only change the status line */
|
||||
while (control_buffer[field_start]) {
|
||||
while (1) {
|
||||
char *field_name;
|
||||
char *field_value;
|
||||
field_start += read_package_field(&control_buffer[field_start], &field_name, &field_value);
|
||||
@@ -931,15 +913,13 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
} else {
|
||||
fprintf(new_status_file, "%s: %s\n", field_name, field_value);
|
||||
}
|
||||
free(field_name);
|
||||
free(field_value);
|
||||
}
|
||||
write_flag = TRUE;
|
||||
fputs("\n", new_status_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If the package from the status file wasn't handled above, do it now */
|
||||
/* If the package from the status file wasn't handle above, do it now*/
|
||||
if (!write_flag) {
|
||||
fprintf(new_status_file, "%s\n\n", control_buffer);
|
||||
}
|
||||
@@ -947,7 +927,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
free(status_from_file);
|
||||
free(package_name);
|
||||
free(control_buffer);
|
||||
} /* while (control_buffer) */
|
||||
}
|
||||
|
||||
/* Write any new packages */
|
||||
for (i = 0; deb_file[i] != NULL; i++) {
|
||||
@@ -964,10 +944,10 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
/* Create a separate backfile to dpkg */
|
||||
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
|
||||
if (errno != ENOENT)
|
||||
bb_simple_error_msg_and_die("can't create backup status file");
|
||||
bb_error_msg_and_die("can't create backup status file");
|
||||
/* Its ok if renaming the status file fails because status
|
||||
* file doesn't exist, maybe we are starting from scratch */
|
||||
bb_simple_error_msg("no status file found, creating new one");
|
||||
bb_error_msg("no status file found, creating new one");
|
||||
}
|
||||
|
||||
xrename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status");
|
||||
@@ -1014,14 +994,14 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
/* Create array of package numbers to check against
|
||||
* installed package for conflicts*/
|
||||
while (deb_file[i] != NULL) {
|
||||
unsigned package_num = deb_file[i]->package;
|
||||
const unsigned package_num = deb_file[i]->package;
|
||||
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
|
||||
conflicts[conflicts_num] = package_num;
|
||||
conflicts_num++;
|
||||
/* add provides to conflicts list */
|
||||
for (j = 0; j < package_hashtable[package_num]->num_of_edges; j++) {
|
||||
if (package_hashtable[package_num]->edge[j]->type == EDGE_PROVIDES) {
|
||||
int conflicts_package_num = search_package_hashtable(
|
||||
const int conflicts_package_num = search_package_hashtable(
|
||||
package_hashtable[package_num]->edge[j]->name,
|
||||
package_hashtable[package_num]->edge[j]->version,
|
||||
package_hashtable[package_num]->edge[j]->operator);
|
||||
@@ -1056,7 +1036,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
const edge_t *package_edge = package_node->edge[j];
|
||||
|
||||
if (package_edge->type == EDGE_CONFLICTS) {
|
||||
unsigned package_num =
|
||||
const unsigned package_num =
|
||||
search_package_hashtable(package_edge->name,
|
||||
package_edge->version,
|
||||
package_edge->operator);
|
||||
@@ -1085,7 +1065,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
|
||||
int status_num = 0;
|
||||
int number_of_alternatives = 0;
|
||||
const edge_t *root_of_alternatives = NULL;
|
||||
const edge_t * root_of_alternatives = NULL;
|
||||
const common_node_t *package_node = package_hashtable[i];
|
||||
|
||||
/* If the package node does not exist then this
|
||||
@@ -1135,7 +1115,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
if (package_edge->type == EDGE_PRE_DEPENDS
|
||||
|| package_edge->type == EDGE_DEPENDS
|
||||
) {
|
||||
int result = 1;
|
||||
int result=1;
|
||||
status_num = 0;
|
||||
|
||||
/* If we are inside an alternative then check
|
||||
@@ -1224,27 +1204,6 @@ static char **create_list(const char *filename)
|
||||
return file_list;
|
||||
}
|
||||
|
||||
/** This tests if the filename is an "important" directory, which might be symlinked.
|
||||
* Debians dpkg test if directories are used by other packages, this
|
||||
* implementation doesn't and would remove for ex. an lib -> usr/lib symlink.
|
||||
*/
|
||||
static int is_builtin_exclude(const char *name)
|
||||
{
|
||||
if (*name++ != '/')
|
||||
return 0;
|
||||
if (index_in_strings(".\0" "etc\0" "opt\0" "srv\0" "var\0" "var/lib\0",
|
||||
name) >= 0)
|
||||
return 1;
|
||||
if (is_prefixed_with(name, "usr/")) {
|
||||
name += sizeof("usr/") - 1;
|
||||
if (is_prefixed_with(name, "local/"))
|
||||
name += sizeof("local/") - 1;
|
||||
}
|
||||
|
||||
return index_in_strings("bin\0" "lib\0" "lib32\0" "lib64\0" "sbin\0",
|
||||
name) >= 0;
|
||||
}
|
||||
|
||||
/* maybe i should try and hook this into remove_file.c somehow */
|
||||
static int remove_file_array(char **remove_names, char **exclude_names)
|
||||
{
|
||||
@@ -1256,8 +1215,6 @@ static int remove_file_array(char **remove_names, char **exclude_names)
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; remove_names[i] != NULL; i++) {
|
||||
if (is_builtin_exclude(remove_names[i]))
|
||||
continue;
|
||||
if (exclude_names != NULL) {
|
||||
for (j = 0; exclude_names[j] != NULL; j++) {
|
||||
if (strcmp(remove_names[i], exclude_names[j]) == 0) {
|
||||
@@ -1324,7 +1281,7 @@ postrm abort-install <old_version>
|
||||
postrm abort-upgrade <old_version>
|
||||
postrm disappear <overwriter> <version>
|
||||
*/
|
||||
static const char *const all_control_files[] ALIGN_PTR = {
|
||||
static const char *const all_control_files[] = {
|
||||
"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles",
|
||||
"config", "templates"
|
||||
@@ -1401,12 +1358,12 @@ static void list_packages(const char *pattern)
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_package(unsigned package_num, int noisy)
|
||||
static void remove_package(const unsigned package_num, int noisy)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
|
||||
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
|
||||
unsigned status_num = search_status_hashtable(package_name);
|
||||
int package_name_length = strlen(package_name);
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
const int package_name_length = strlen(package_name);
|
||||
char **remove_files;
|
||||
char **exclude_files;
|
||||
char list_name[package_name_length + 25];
|
||||
@@ -1452,11 +1409,11 @@ static void remove_package(unsigned package_num, int noisy)
|
||||
set_status(status_num, "config-files", 3);
|
||||
}
|
||||
|
||||
static void purge_package(unsigned package_num)
|
||||
static void purge_package(const unsigned package_num)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
|
||||
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
|
||||
unsigned status_num = search_status_hashtable(package_name);
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
char **remove_files;
|
||||
char **exclude_files;
|
||||
char list_name[strlen(package_name) + 25];
|
||||
@@ -1674,8 +1631,8 @@ enum {
|
||||
static void unpack_package(deb_file_t *deb_file)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
|
||||
unsigned status_num = search_status_hashtable(package_name);
|
||||
unsigned status_package_num = status_hashtable[status_num]->package;
|
||||
const unsigned status_num = search_status_hashtable(package_name);
|
||||
const unsigned status_package_num = status_hashtable[status_num]->package;
|
||||
char *info_prefix;
|
||||
char *list_filename;
|
||||
archive_handle_t *archive_handle;
|
||||
@@ -1709,7 +1666,7 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
accept_list = NULL;
|
||||
i = 0;
|
||||
while (i < ARRAY_SIZE(all_control_files)) {
|
||||
char *c = concat_path_file(".", all_control_files[i]);
|
||||
char *c = xasprintf("./%s", all_control_files[i]);
|
||||
llist_add_to(&accept_list, c);
|
||||
i++;
|
||||
}
|
||||
@@ -1765,7 +1722,7 @@ static void configure_package(deb_file_t *deb_file)
|
||||
{
|
||||
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
|
||||
const char *package_version = name_hashtable[package_hashtable[deb_file->package]->version];
|
||||
int status_num = search_status_hashtable(package_name);
|
||||
const int status_num = search_status_hashtable(package_name);
|
||||
|
||||
printf("Setting up %s (%s)...\n", package_name, package_version);
|
||||
|
||||
@@ -1806,28 +1763,11 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
"force-confold\0" No_argument "\xfd"
|
||||
;
|
||||
#endif
|
||||
//--admindir=DIR
|
||||
// Set the administrative directory to DIR. This directory
|
||||
// contains many files that give information about status of
|
||||
// installed or uninstalled packages, etc. Defaults to
|
||||
// /var/lib/dpkg if DPKG_ADMINDIR has not been set.
|
||||
//--instdir=DIR
|
||||
// Set the installation directory, which refers to the directory
|
||||
// where packages are to be installed. DIR is also the
|
||||
// directory passed to chroot(2) before running package's
|
||||
// installation scripts, which means that the scripts see DIR
|
||||
// as a root directory. Defaults to / if DPKG_ROOT has not
|
||||
// been set (since dpkg 1.21.10).
|
||||
//--root=DIR
|
||||
// Set the root directory to DIR, which sets the
|
||||
// installation directory to DIR and the administrative
|
||||
// directory to DIR/var/lib/dpkg if DPKG_ROOT
|
||||
// has not been set (since dpkg 1.21.10).
|
||||
//TODO: implement --root=DIR? necessary for testing
|
||||
|
||||
INIT_G();
|
||||
|
||||
opt = getopt32long(argv, "CilPruF:", dpkg_longopts, &str_f);
|
||||
IF_LONG_OPTS(applet_long_options = dpkg_longopts);
|
||||
opt = getopt32(argv, "CilPruF:", &str_f);
|
||||
argv += optind;
|
||||
//if (opt & OPT_configure) ... // -C
|
||||
if (opt & OPT_force) { // -F (--force in official dpkg)
|
||||
@@ -1877,7 +1817,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
init_archive_deb_control(archive_handle);
|
||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||
if (deb_file[deb_count]->control_file == NULL) {
|
||||
bb_simple_error_msg_and_die("can't extract control file");
|
||||
bb_error_msg_and_die("can't extract control file");
|
||||
}
|
||||
deb_file[deb_count]->filename = xstrdup(argv[0]);
|
||||
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
||||
@@ -1940,13 +1880,13 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
argv++;
|
||||
}
|
||||
if (!deb_count)
|
||||
bb_simple_error_msg_and_die("no package files specified");
|
||||
bb_error_msg_and_die("no package files specified");
|
||||
deb_file[deb_count] = NULL;
|
||||
|
||||
/* Check that the deb file arguments are installable */
|
||||
if (!(opt & OPT_force_ignore_depends)) {
|
||||
if (!check_deps(deb_file, 0 /*, deb_count*/)) {
|
||||
bb_simple_error_msg_and_die("dependency check failed");
|
||||
bb_error_msg_and_die("dependency check failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -4,17 +4,18 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg-deb (29 kb)"
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
//config:
|
||||
//config: This implementation of dpkg-deb cannot pack archives.
|
||||
//config: This implementation of dpkg-deb cannot pack archives.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires dpkg-deb,
|
||||
//config: say N here.
|
||||
//config: 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))
|
||||
|
||||
@@ -28,7 +29,7 @@
|
||||
//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: "\n -X Verbose -x"
|
||||
//usage:
|
||||
//usage:#define dpkg_deb_example_usage
|
||||
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
|
||||
@@ -79,9 +80,8 @@ int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
/* Must have 1 or 2 args */
|
||||
opt = getopt32(argv, "^" "cefXx"
|
||||
"\0" "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"
|
||||
);
|
||||
opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
|
||||
|
||||
+286
-295
File diff suppressed because it is too large.
Load diff
@@ -11,9 +11,6 @@ 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 \
|
||||
@@ -33,6 +30,7 @@ COMMON_FILES:= \
|
||||
DPKG_FILES:= \
|
||||
unpack_ar_archive.o \
|
||||
filter_accept_list_reassign.o \
|
||||
unsafe_prefix.o \
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
@@ -47,7 +45,7 @@ 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_TAR) += get_header_tar.o unsafe_prefix.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
|
||||
@@ -67,7 +65,7 @@ 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_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.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
|
||||
@@ -91,7 +89,6 @@ lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.
|
||||
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)
|
||||
|
||||
+153
-160
@@ -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_FAST >= 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_FAST >= 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;
|
||||
@@ -595,12 +586,15 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
#define MAIN_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
void mainQSort3(EState* state,
|
||||
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_FAST >= 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_FAST >= 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -368,8 +369,8 @@ 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->ftab);
|
||||
free(s->crc32table);
|
||||
free(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,6 +163,7 @@ typedef struct EState {
|
||||
|
||||
/* misc administratium */
|
||||
int32_t blockNo;
|
||||
int32_t blockSize100k;
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t nMTF;
|
||||
@@ -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_FAST >= 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
|
||||
|
||||
+132
-207
@@ -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_FAST >= 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),
|
||||
@@ -220,74 +148,95 @@ void generateMTFValues(EState* s)
|
||||
* 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;
|
||||
} 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;
|
||||
}
|
||||
{
|
||||
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[run]++;
|
||||
#endif
|
||||
zPend -= 2;
|
||||
if (zPend < 0)
|
||||
break;
|
||||
zPend = (unsigned)zPend / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
if (i < 0) /* came via "goto process_zPend"? exit */
|
||||
goto end;
|
||||
zPend = 0;
|
||||
}
|
||||
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,11 +249,8 @@ 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 v, t, i, j, gs, ge, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups;
|
||||
|
||||
/*
|
||||
@@ -320,49 +266,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 +324,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_FAST >= 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];
|
||||
@@ -411,9 +347,6 @@ void sendMTFValues(EState* s)
|
||||
nSelectors = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
unsigned bt, bc;
|
||||
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
@@ -427,7 +360,7 @@ void sendMTFValues(EState* s)
|
||||
*/
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] = 0;
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FAST >= 5
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
register uint32_t cost01, cost23, cost45;
|
||||
@@ -457,7 +390,7 @@ void sendMTFValues(EState* s)
|
||||
{
|
||||
/*--- 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 +409,7 @@ void sendMTFValues(EState* s)
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
@@ -483,7 +417,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_FAST >= 4
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
|
||||
@@ -530,7 +464,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 +472,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];
|
||||
@@ -576,16 +509,15 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
}
|
||||
|
||||
bsW16(s, inUse16);
|
||||
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;
|
||||
}
|
||||
@@ -595,20 +527,19 @@ void sendMTFValues(EState* s)
|
||||
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. ---*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,8 +547,6 @@ void sendMTFValues(EState* s)
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
@@ -676,21 +605,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 +649,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_FAST >= 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;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -65,18 +66,6 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
} 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, '/');
|
||||
@@ -115,11 +104,13 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
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");
|
||||
bb_perror_msg_and_die("can't stat old file");
|
||||
}
|
||||
}
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
&& !S_ISDIR(file_header->mode)
|
||||
) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", dst_name);
|
||||
}
|
||||
@@ -134,10 +125,14 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
create_or_remember_link(&archive_handle->link_placeholders,
|
||||
hard_link,
|
||||
dst_name,
|
||||
1);
|
||||
res = link(hard_link, dst_name);
|
||||
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink "
|
||||
"%s to %s", "hard",
|
||||
dst_name,
|
||||
hard_link);
|
||||
}
|
||||
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
|
||||
goto ret;
|
||||
}
|
||||
@@ -171,14 +166,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
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)
|
||||
if ((res == -1)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", dst_name);
|
||||
}
|
||||
@@ -186,43 +178,30 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
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,
|
||||
res = symlink(file_header->link_target, dst_name);
|
||||
if (res != 0
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink "
|
||||
"%s to %s", "sym",
|
||||
dst_name,
|
||||
0);
|
||||
file_header->link_target);
|
||||
}
|
||||
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) {
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't create node %s", dst_name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_simple_error_msg_and_die("unrecognized file type");
|
||||
bb_error_msg_and_die("unrecognized file type");
|
||||
}
|
||||
|
||||
if (!S_ISLNK(file_header->mode)) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -20,7 +21,7 @@ enum {
|
||||
TAR_MAX,
|
||||
};
|
||||
|
||||
static const char *const tar_var[] ALIGN_PTR = {
|
||||
static const char *const tar_var[] = {
|
||||
// "FILETYPE",
|
||||
"MODE",
|
||||
"FILENAME",
|
||||
@@ -37,7 +38,7 @@ static const char *const tar_var[] ALIGN_PTR = {
|
||||
static void xputenv(char *str)
|
||||
{
|
||||
if (putenv(str))
|
||||
bb_die_memory_exhausted();
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
}
|
||||
|
||||
static void str2env(char *env[], int idx, const char *str)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
|
||||
*
|
||||
* Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
|
||||
* which also acknowledges contributions by Mike Burrows, David Wheeler,
|
||||
* Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
|
||||
* Robert Sedgewick, and Jon L. Bentley.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
|
||||
|
||||
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
|
||||
which also acknowledges contributions by Mike Burrows, David Wheeler,
|
||||
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
|
||||
Robert Sedgewick, and Jon L. Bentley.
|
||||
|
||||
Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org).
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
Manuel
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -100,14 +101,14 @@ struct bunzip_data {
|
||||
unsigned dbufSize;
|
||||
|
||||
/* For I/O error handling */
|
||||
jmp_buf *jmpbuf;
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Big things go last (register-relative addressing can be larger for big offsets) */
|
||||
uint32_t crc32Table[256];
|
||||
uint8_t selectors[32768]; /* nSelectors=15 bits */
|
||||
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
||||
};
|
||||
typedef struct bunzip_data bunzip_data;
|
||||
/* typedef struct bunzip_data bunzip_data; -- done in .h file */
|
||||
|
||||
|
||||
/* Return the next nnn bits of input. All reads from the compressed input
|
||||
@@ -127,7 +128,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
|
||||
/* if "no input fd" case: in_fd == -1, read fails, we jump */
|
||||
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
|
||||
if (bd->inbufCount <= 0)
|
||||
longjmp(*bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
longjmp(bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
bd->inbufPos = 0;
|
||||
}
|
||||
|
||||
@@ -151,20 +152,20 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
|
||||
|
||||
return bits;
|
||||
}
|
||||
//#define get_bits(bd, n) (dbg("%d:get_bits()", __LINE__), get_bits(bd, n))
|
||||
|
||||
/* Unpacks the next block and sets up for the inverse Burrows-Wheeler step. */
|
||||
static int get_next_block(bunzip_data *bd)
|
||||
{
|
||||
int groupCount, selector,
|
||||
i, j, symCount, symTotal, nSelectors, byteCount[256];
|
||||
struct group_data *hufGroup;
|
||||
int dbufCount, dbufSize, groupCount, *base, *limit, selector,
|
||||
i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
|
||||
int runCnt = runCnt; /* for compiler */
|
||||
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
|
||||
uint32_t *dbuf;
|
||||
unsigned origPtr, t;
|
||||
unsigned dbufCount, runPos;
|
||||
unsigned runCnt = runCnt; /* for compiler */
|
||||
|
||||
dbuf = bd->dbuf;
|
||||
dbufSize = bd->dbufSize;
|
||||
selectors = bd->selectors;
|
||||
|
||||
/* In bbox, we are ok with aborting through setjmp which is set up in start_bunzip */
|
||||
@@ -179,19 +180,15 @@ static int get_next_block(bunzip_data *bd)
|
||||
i = get_bits(bd, 24);
|
||||
j = get_bits(bd, 24);
|
||||
bd->headerCRC = get_bits(bd, 32);
|
||||
if ((i == 0x177245) && (j == 0x385090))
|
||||
return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359))
|
||||
return RETVAL_NOT_BZIP_DATA;
|
||||
if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* We can add support for blockRandomised if anybody complains. There was
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
if (get_bits(bd, 1))
|
||||
return RETVAL_OBSOLETE_INPUT;
|
||||
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
|
||||
origPtr = get_bits(bd, 24);
|
||||
if (origPtr > bd->dbufSize)
|
||||
return RETVAL_DATA_ERROR;
|
||||
if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
@@ -235,21 +232,13 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Get next value */
|
||||
int n = 0;
|
||||
while (get_bits(bd, 1)) {
|
||||
if (n >= groupCount) return RETVAL_DATA_ERROR;
|
||||
n++;
|
||||
if (n >= groupCount)
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
/* Decode MTF to get the next selector */
|
||||
tmp_byte = mtfSymbol[n];
|
||||
while (--n >= 0)
|
||||
mtfSymbol[n + 1] = mtfSymbol[n];
|
||||
//We catch it later, in the second loop where we use selectors[i].
|
||||
//Maybe this is a better place, though?
|
||||
// if (tmp_byte >= groupCount) {
|
||||
// dbg("%d: selectors[%d]:%d groupCount:%d",
|
||||
// __LINE__, i, tmp_byte, groupCount);
|
||||
// return RETVAL_DATA_ERROR;
|
||||
// }
|
||||
mtfSymbol[0] = selectors[i] = tmp_byte;
|
||||
}
|
||||
|
||||
@@ -260,8 +249,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
uint8_t length[MAX_SYMBOLS];
|
||||
/* 8 bits is ALMOST enough for temp[], see below */
|
||||
unsigned temp[MAX_HUFCODE_BITS+1];
|
||||
struct group_data *hufGroup;
|
||||
int *base, *limit;
|
||||
int minLen, maxLen, pp, len_m1;
|
||||
|
||||
/* Read Huffman code lengths for each symbol. They're stored in
|
||||
@@ -297,10 +284,8 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Find largest and smallest lengths in this group */
|
||||
minLen = maxLen = length[0];
|
||||
for (i = 1; i < symCount; i++) {
|
||||
if (length[i] > maxLen)
|
||||
maxLen = length[i];
|
||||
else if (length[i] < minLen)
|
||||
minLen = length[i];
|
||||
if (length[i] > maxLen) maxLen = length[i];
|
||||
else if (length[i] < minLen) minLen = length[i];
|
||||
}
|
||||
|
||||
/* Calculate permute[], base[], and limit[] tables from length[].
|
||||
@@ -336,8 +321,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Count symbols coded for at each bit length */
|
||||
/* NB: in pathological cases, temp[8] can end ip being 256.
|
||||
* That's why uint8_t is too small for temp[]. */
|
||||
for (i = 0; i < symCount; i++)
|
||||
temp[length[i]]++;
|
||||
for (i = 0; i < symCount; i++) temp[length[i]]++;
|
||||
|
||||
/* Calculate limit[] (the largest symbol-coding value at each bit
|
||||
* length, which is (previous limit<<1)+symbols at this level), and
|
||||
@@ -380,22 +364,12 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
runPos = dbufCount = selector = 0;
|
||||
for (;;) {
|
||||
struct group_data *hufGroup;
|
||||
int *base, *limit;
|
||||
int nextSym;
|
||||
uint8_t ngrp;
|
||||
|
||||
/* Fetch next Huffman coding group from list. */
|
||||
symCount = GROUP_SIZE - 1;
|
||||
if (selector >= nSelectors)
|
||||
return RETVAL_DATA_ERROR;
|
||||
ngrp = selectors[selector++];
|
||||
if (ngrp >= groupCount) {
|
||||
dbg("%d selectors[%d]:%d groupCount:%d",
|
||||
__LINE__, selector-1, ngrp, groupCount);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
hufGroup = bd->groups + ngrp;
|
||||
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup = bd->groups + selectors[selector++];
|
||||
base = hufGroup->base - 1;
|
||||
limit = hufGroup->limit - 1;
|
||||
|
||||
@@ -430,8 +404,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
/* Figure how many bits are in next symbol and unget extras */
|
||||
i = hufGroup->minLen;
|
||||
while (nextSym > limit[i])
|
||||
++i;
|
||||
while (nextSym > limit[i]) ++i;
|
||||
j = hufGroup->maxLen - i;
|
||||
if (j < 0)
|
||||
return RETVAL_DATA_ERROR;
|
||||
@@ -463,13 +436,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
symbols, but a run of length 0 doesn't mean anything in this
|
||||
context). Thus space is saved. */
|
||||
runCnt += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
|
||||
/* Catch 32-bit overflow (we have an example .bz2 file) */
|
||||
if ((int)runCnt < 0) {
|
||||
dbg("runCnt:%u > dbufSize:%u RETVAL_DATA_ERROR",
|
||||
runCnt, bd->dbufSize);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
if (runPos < bd->dbufSize) runPos <<= 1;
|
||||
if (runPos < dbufSize) runPos <<= 1;
|
||||
goto end_of_huffman_loop;
|
||||
}
|
||||
|
||||
@@ -479,15 +446,14 @@ static int get_next_block(bunzip_data *bd)
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
if (runPos != 0) {
|
||||
uint8_t tmp_byte;
|
||||
if (dbufCount + runCnt > bd->dbufSize) {
|
||||
dbg("dbufCount:%u+runCnt:%u %u > dbufSize:%u RETVAL_DATA_ERROR",
|
||||
dbufCount, runCnt, dbufCount + runCnt, bd->dbufSize);
|
||||
if (dbufCount + runCnt > dbufSize) {
|
||||
dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
|
||||
dbufCount, runCnt, dbufCount + runCnt, dbufSize);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
tmp_byte = symToByte[mtfSymbol[0]];
|
||||
byteCount[tmp_byte] += runCnt;
|
||||
while ((int)--runCnt >= 0)
|
||||
dbuf[dbufCount++] = (uint32_t)tmp_byte;
|
||||
while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
|
||||
runPos = 0;
|
||||
}
|
||||
|
||||
@@ -501,7 +467,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
first symbol in the mtf array, position 0, would have been handled
|
||||
as part of a run above. Therefore 1 unused mtf position minus
|
||||
2 non-literal nextSym values equals -1.) */
|
||||
if (dbufCount >= bd->dbufSize) return RETVAL_DATA_ERROR;
|
||||
if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
i = nextSym - 1;
|
||||
uc = mtfSymbol[i];
|
||||
|
||||
@@ -574,7 +540,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0.
|
||||
(Why? This allows to get rid of one local variable)
|
||||
*/
|
||||
static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
{
|
||||
const uint32_t *dbuf;
|
||||
int pos, current, previous;
|
||||
@@ -653,7 +619,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Subtract the 1 copy we'd output anyway to get extras */
|
||||
--bd->writeCopies;
|
||||
}
|
||||
} /* for (;;) */
|
||||
} /* for(;;) */
|
||||
|
||||
/* Decompression of this input block completed successfully */
|
||||
bd->writeCRC = CRC = ~CRC;
|
||||
@@ -698,10 +664,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
|
||||
should work for NOFORK applets too, we must be extremely careful to not leak
|
||||
any allocations! */
|
||||
static int FAST_FUNC start_bunzip(
|
||||
void *jmpbuf,
|
||||
bunzip_data **bdp,
|
||||
int in_fd,
|
||||
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd,
|
||||
const void *inbuf, int len)
|
||||
{
|
||||
bunzip_data *bd;
|
||||
@@ -713,14 +676,11 @@ static int FAST_FUNC start_bunzip(
|
||||
|
||||
/* Figure out how much data to allocate */
|
||||
i = sizeof(bunzip_data);
|
||||
if (in_fd != -1)
|
||||
i += IOBUF_SIZE;
|
||||
if (in_fd != -1) i += IOBUF_SIZE;
|
||||
|
||||
/* Allocate bunzip_data. Most fields initialize to zero. */
|
||||
bd = *bdp = xzalloc(i);
|
||||
|
||||
bd->jmpbuf = jmpbuf;
|
||||
|
||||
/* Setup input buffer */
|
||||
bd->in_fd = in_fd;
|
||||
if (-1 == in_fd) {
|
||||
@@ -735,6 +695,10 @@ static int FAST_FUNC start_bunzip(
|
||||
/* Init the CRC32 table (big endian) */
|
||||
crc32_filltable(bd->crc32Table, 1);
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
|
||||
/* Ensure that file starts with "BZh['1'-'9']." */
|
||||
/* Update: now caller verifies 1st two bytes, makes .gz/.bz2
|
||||
* integration easier */
|
||||
@@ -758,7 +722,7 @@ static int FAST_FUNC start_bunzip(
|
||||
return RETVAL_OK;
|
||||
}
|
||||
|
||||
static void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
{
|
||||
free(bd->dbuf);
|
||||
free(bd);
|
||||
@@ -781,12 +745,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(jmpbuf);
|
||||
if (i == 0)
|
||||
i = start_bunzip(&jmpbuf, &bd, xstate->src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -808,7 +768,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
/* Observed case when i == RETVAL_OK:
|
||||
* "bzcat z.bz2", where "z.bz2" is a bzipped zero-length file
|
||||
* (to be exact, z.bz2 is exactly these 14 bytes:
|
||||
* 42 5a 68 39 17 72 45 38 50 90 00 00 00 00).
|
||||
* 42 5a 68 39 17 72 45 38 50 90 00 00 00 00).
|
||||
*/
|
||||
&& i != RETVAL_OK
|
||||
) {
|
||||
@@ -816,7 +776,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
break;
|
||||
}
|
||||
if (bd->headerCRC != bd->totalCRC) {
|
||||
bb_simple_error_msg("CRC error");
|
||||
bb_error_msg("CRC error");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -846,36 +806,6 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
return i ? i : IF_DESKTOP(total_written) + 0;
|
||||
}
|
||||
|
||||
char* FAST_FUNC
|
||||
unpack_bz2_data(const char *packed, int packed_len, int unpacked_len)
|
||||
{
|
||||
char *outbuf = NULL;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(jmpbuf);
|
||||
if (i == 0) {
|
||||
i = start_bunzip(&jmpbuf,
|
||||
&bd,
|
||||
/* src_fd: */ -1,
|
||||
/* inbuf: */ packed,
|
||||
/* len: */ packed_len
|
||||
);
|
||||
}
|
||||
/* read_bunzip can longjmp and end up here with i != 0
|
||||
* on read data errors! Not trivial */
|
||||
if (i == 0) {
|
||||
/* Cannot use xmalloc: will leak bd in NOFORK case! */
|
||||
outbuf = malloc_or_warn(unpacked_len);
|
||||
if (outbuf)
|
||||
read_bunzip(bd, outbuf, unpacked_len);
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static char *const bunzip_errors[] = {
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -39,8 +41,7 @@ typedef struct huft_t {
|
||||
unsigned char e; /* number of extra bits or operation */
|
||||
unsigned char b; /* number of bits in this code or subcode */
|
||||
union {
|
||||
unsigned n; /* literal, length base, or distance base */
|
||||
/* ^^^^^ was "unsigned short", but that results in larger code */
|
||||
unsigned short n; /* literal, length base, or distance base */
|
||||
struct huft_t *t; /* pointer to next level of table */
|
||||
} v;
|
||||
} huft_t;
|
||||
@@ -185,26 +186,29 @@ static const uint16_t mask_bits[] ALIGN2 = {
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
};
|
||||
|
||||
/* Put lengths/offsets and extra bits in a struct of arrays
|
||||
* to make calls to huft_build() have one fewer parameter.
|
||||
*/
|
||||
struct cp_ext {
|
||||
uint16_t cp[31];
|
||||
uint8_t ext[31];
|
||||
/* Copy lengths for literal codes 257..285 */
|
||||
static const uint16_t cplens[] ALIGN2 = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
|
||||
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
};
|
||||
/* Copy lengths and extra bits for literal codes 257..285 */
|
||||
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
static const struct cp_ext lit ALIGN2 = {
|
||||
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */
|
||||
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
|
||||
/* Extra bits for literal codes 257..285 */
|
||||
static const uint8_t cplext[] ALIGN1 = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
|
||||
5, 5, 5, 0, 99, 99
|
||||
}; /* 99 == invalid */
|
||||
|
||||
/* Copy offsets for distance codes 0..29 */
|
||||
static const uint16_t cpdist[] ALIGN2 = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
|
||||
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
||||
};
|
||||
/* Copy offsets and extra bits for distance codes 0..29 */
|
||||
static const struct cp_ext dist ALIGN2 = {
|
||||
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */
|
||||
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
|
||||
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
|
||||
|
||||
/* Extra bits for distance codes */
|
||||
static const uint8_t cpdext[] ALIGN1 = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
@@ -220,19 +224,10 @@ static const uint8_t border[] ALIGN1 = {
|
||||
* each table.
|
||||
* t: table to free
|
||||
*/
|
||||
#define BAD_HUFT(p) ((uintptr_t)(p) & 1)
|
||||
#define ERR_RET ((huft_t*)(uintptr_t)1)
|
||||
static void huft_free(huft_t *p)
|
||||
{
|
||||
huft_t *q;
|
||||
|
||||
/*
|
||||
* If 'p' has the error bit set we have to clear it, otherwise we might run
|
||||
* into a segmentation fault or an invalid pointer to free(p)
|
||||
*/
|
||||
//if (BAD_HUFT(p)) // commented out, since bit clearing has effect only if condition is true
|
||||
p = (huft_t*)((uintptr_t)p & ~(uintptr_t)ERR_RET);
|
||||
|
||||
/* Go through linked list, freeing from the malloced (t[-1]) address. */
|
||||
while (p) {
|
||||
q = (--p)->v.t;
|
||||
@@ -284,23 +279,22 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
|
||||
|
||||
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
* tables to decode that set of codes.
|
||||
* tables to decode that set of codes. Return zero on success, one if
|
||||
* the given code set is incomplete (the tables are still built in this
|
||||
* case), two if the input is invalid (all zero length codes or an
|
||||
* oversubscribed set of lengths) - in this case stores NULL in *t.
|
||||
*
|
||||
* b: code lengths in bits (all assumed <= BMAX)
|
||||
* n: number of codes (assumed <= N_MAX)
|
||||
* s: number of simple-valued codes (0..s-1)
|
||||
* cp_ext->cp,ext: list of base values/extra bits for non-simple codes
|
||||
* d: list of base values for non-simple codes
|
||||
* e: list of extra bits for non-simple codes
|
||||
* t: result: starting table
|
||||
* m: maximum lookup bits, returns actual
|
||||
* result: starting table
|
||||
*
|
||||
* On error, returns a value with lowest-bit set on error.
|
||||
* It can be just the value of 0x1,
|
||||
* or a valid pointer to a Huffman table, ORed with 0x1 if incompete table
|
||||
* is given: "fixed inflate" decoder feeds us such data.
|
||||
*/
|
||||
static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
const unsigned s, const struct cp_ext *cp_ext,
|
||||
unsigned *m)
|
||||
static int huft_build(const unsigned *b, const unsigned n,
|
||||
const unsigned s, const unsigned short *d,
|
||||
const unsigned char *e, huft_t **t, unsigned *m)
|
||||
{
|
||||
unsigned a; /* counter for codes of length k */
|
||||
unsigned c[BMAX + 1]; /* bit length count table */
|
||||
@@ -322,12 +316,12 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
unsigned *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
unsigned z; /* number of entries in current table */
|
||||
huft_t *result;
|
||||
huft_t **t;
|
||||
|
||||
/* Length of EOB code, if any */
|
||||
eob_len = n > 256 ? b[256] : BMAX;
|
||||
|
||||
*t = NULL;
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset(c, 0, sizeof(c));
|
||||
p = b;
|
||||
@@ -337,14 +331,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
p++; /* can't combine with above line (Solaris bug) */
|
||||
} while (--i);
|
||||
if (c[0] == n) { /* null input - all zero length codes */
|
||||
q = xzalloc(3 * sizeof(*q));
|
||||
//q[0].v.t = NULL;
|
||||
q[1].e = 99; /* invalid code marker */
|
||||
q[1].b = 1;
|
||||
q[2].e = 99; /* invalid code marker */
|
||||
q[2].b = 1;
|
||||
*m = 1;
|
||||
return q + 1;
|
||||
*m = 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
@@ -360,11 +348,11 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||
y -= c[j];
|
||||
if (y < 0)
|
||||
return ERR_RET; /* bad input: more codes than bits */
|
||||
return 2; /* bad input: more codes than bits */
|
||||
}
|
||||
y -= c[i];
|
||||
if (y < 0)
|
||||
return ERR_RET;
|
||||
return 2;
|
||||
c[i] += y;
|
||||
|
||||
/* Generate starting offsets into the value table for each length */
|
||||
@@ -391,8 +379,6 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
} while (++i < n);
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
result = ERR_RET;
|
||||
t = &result;
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
htl = -1; /* no tables yet--level -1 */
|
||||
@@ -458,8 +444,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
|
||||
} else {
|
||||
r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */
|
||||
r.v.n = cp_ext->cp[*p++ - s];
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.v.n = d[*p++ - s];
|
||||
}
|
||||
|
||||
/* fill code-like entries with r */
|
||||
@@ -484,11 +470,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||
/* return actual size of base table */
|
||||
*m = ws[1];
|
||||
|
||||
if (y != 0 && g != 1) /* we were given an incomplete table */
|
||||
/* return "result" ORed with 1 */
|
||||
return (void*)((uintptr_t)result | 1);
|
||||
|
||||
return result;
|
||||
/* Return 1 if we were given an incomplete table */
|
||||
return y != 0 && g != 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -789,17 +772,14 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
for (; i < 288; i++) /* make a complete, but wrong code set */
|
||||
ll[i] = 8;
|
||||
bl = 7;
|
||||
inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl);
|
||||
/* ^^^ never returns error here - we use known data */
|
||||
huft_build(ll, 288, 257, cplens, cplext, &inflate_codes_tl, &bl);
|
||||
/* huft_build() never return nonzero - we use known data */
|
||||
|
||||
/* set up distance table */
|
||||
for (i = 0; i < 30; i++) /* make an incomplete code set */
|
||||
ll[i] = 5;
|
||||
bd = 5;
|
||||
inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd);
|
||||
/* ^^^ does return error here! (lsb bit is set) - we gave it incomplete code set */
|
||||
/* clearing error bit: */
|
||||
inflate_codes_td = (void*)((uintptr_t)inflate_codes_td & ~(uintptr_t)1);
|
||||
huft_build(ll, 30, 0, cpdist, cpdext, &inflate_codes_td, &bd);
|
||||
|
||||
/* set up data for inflate_codes() */
|
||||
inflate_codes_setup(PASS_STATE bl, bd);
|
||||
@@ -865,9 +845,9 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
|
||||
/* build decoding table for trees - single level, 7 bit lookup */
|
||||
bl = 7;
|
||||
inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl);
|
||||
if (BAD_HUFT(inflate_codes_tl)) {
|
||||
abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
|
||||
i = huft_build(ll, 19, 19, NULL, NULL, &inflate_codes_tl, &bl);
|
||||
if (i != 0) {
|
||||
abort_unzip(PASS_STATE_ONLY); //return i; /* incomplete code set */
|
||||
}
|
||||
|
||||
/* read in literal and distance code lengths */
|
||||
@@ -930,13 +910,14 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
|
||||
/* build the decoding tables for literal/length and distance codes */
|
||||
bl = lbits;
|
||||
inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl);
|
||||
if (BAD_HUFT(inflate_codes_tl)) {
|
||||
|
||||
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
|
||||
if (i != 0) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bd = dbits;
|
||||
inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd);
|
||||
if (BAD_HUFT(inflate_codes_td)) {
|
||||
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
|
||||
if (i != 0) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
|
||||
@@ -1020,13 +1001,13 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
gunzip_bb = 0;
|
||||
|
||||
/* Create the crc table */
|
||||
gunzip_crc_table = crc32_new_table_le();
|
||||
gunzip_crc_table = crc32_filltable(NULL, 0);
|
||||
gunzip_crc = ~0;
|
||||
|
||||
error_msg = "corrupted data";
|
||||
if (setjmp(error_jmp)) {
|
||||
/* Error from deep inside zip machinery */
|
||||
bb_simple_error_msg(error_msg);
|
||||
bb_error_msg(error_msg);
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1099,7 +1080,7 @@ static int top_up(STATE_PARAM unsigned n)
|
||||
bytebuffer_offset = 0;
|
||||
bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
|
||||
if ((int)bytebuffer_size < 0) {
|
||||
bb_simple_error_msg(bb_msg_read_error);
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
return 0;
|
||||
}
|
||||
bytebuffer_size += count;
|
||||
@@ -1225,7 +1206,7 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
|
||||
bad_magic:
|
||||
bb_simple_error_msg("invalid magic");
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
if (magic2 == COMPRESS_MAGIC) {
|
||||
@@ -1247,7 +1228,7 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE xstate)) {
|
||||
bb_simple_error_msg("corrupted data");
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1260,7 +1241,7 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
total += n;
|
||||
|
||||
if (!top_up(PASS_STATE 8)) {
|
||||
bb_simple_error_msg("corrupted data");
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1268,7 +1249,7 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
/* Validate decompression - crc */
|
||||
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
|
||||
if ((~gunzip_crc) != v32) {
|
||||
bb_simple_error_msg("crc error");
|
||||
bb_error_msg("crc error");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1276,7 +1257,7 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
/* Validate decompression - size */
|
||||
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
|
||||
if ((uint32_t)gunzip_bytes_out != v32) {
|
||||
bb_simple_error_msg("incorrect length");
|
||||
bb_error_msg("incorrect length");
|
||||
total = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
/* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
*
|
||||
* based on the original compress42.c source
|
||||
* (see disclaimer below)
|
||||
*/
|
||||
|
||||
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
|
||||
*
|
||||
* Authors:
|
||||
@@ -21,7 +21,9 @@
|
||||
* marc@suse.de : a small security fix for a buffer overflow
|
||||
*
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -113,7 +115,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
||||
bb_simple_error_msg("short read");
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -166,7 +168,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
||||
if (rsize < 0)
|
||||
bb_simple_error_msg_and_die(bb_msg_read_error);
|
||||
bb_error_msg_and_die(bb_msg_read_error);
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
|
||||
if (oldcode == -1) {
|
||||
if (code >= 256)
|
||||
bb_simple_error_msg_and_die("corrupted data"); /* %ld", code); */
|
||||
bb_error_msg_and_die("corrupted data"); /* %ld", code); */
|
||||
oldcode = code;
|
||||
finchar = (int) oldcode;
|
||||
outbuf[outpos++] = (unsigned char) finchar;
|
||||
@@ -236,7 +238,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
|
||||
(posbits & 07));
|
||||
*/
|
||||
bb_simple_error_msg("corrupted data");
|
||||
bb_error_msg("corrupted data");
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -247,7 +249,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* Generate output characters in reverse order */
|
||||
while (code >= 256) {
|
||||
if (stackp <= &htabof(0))
|
||||
bb_simple_error_msg_and_die("corrupted data");
|
||||
bb_error_msg_and_die("corrupted data");
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,6 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#else
|
||||
# define dbg(...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
# define speed_inline ALWAYS_INLINE
|
||||
# define size_inline
|
||||
@@ -59,7 +52,7 @@ static void rc_read(rc_t *rc)
|
||||
//TODO: return -1 instead
|
||||
//This will make unlzma delete broken unpacked file on unpack errors
|
||||
if (buffer_size <= 0)
|
||||
bb_simple_error_msg_and_die("unexpected EOF");
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
rc->ptr = RC_BUFFER;
|
||||
}
|
||||
@@ -224,7 +217,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
uint32_t buffer_size;
|
||||
uint8_t previous_byte = 0;
|
||||
size_t buffer_pos = 0, global_pos = 0;
|
||||
int len = 0;
|
||||
@@ -234,7 +226,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_simple_error_msg("bad lzma header");
|
||||
bb_error_msg("bad lzma header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -254,8 +246,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (header.dict_size == 0)
|
||||
header.dict_size++;
|
||||
|
||||
buffer_size = MIN(header.dst_size, header.dict_size);
|
||||
buffer = xmalloc(buffer_size);
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
{
|
||||
int num_probs;
|
||||
@@ -290,11 +281,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
uint32_t pos;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0) {
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
if ((int32_t)pos < 0)
|
||||
goto bad;
|
||||
}
|
||||
match_byte = buffer[pos];
|
||||
do {
|
||||
int bit;
|
||||
@@ -353,14 +341,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0) {
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
/* see unzip_bad_lzma_2.zip: */
|
||||
if (pos >= buffer_size) {
|
||||
dbg("%d pos:%d buffer_size:%d", __LINE__, pos, buffer_size);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
previous_byte = buffer[pos];
|
||||
goto one_byte1;
|
||||
#else
|
||||
@@ -435,9 +417,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
// Note: (int32_t)rep0 may be < 0 here
|
||||
// (I have linux-3.3.4.tar.lzma which has it).
|
||||
// I moved the check after "++rep0 == 0" check below.
|
||||
prob3 = p + LZMA_ALIGN;
|
||||
}
|
||||
i2 = 1;
|
||||
@@ -448,13 +427,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
i2 <<= 1;
|
||||
}
|
||||
}
|
||||
rep0++;
|
||||
if ((int32_t)rep0 <= 0) {
|
||||
if (rep0 == 0)
|
||||
break;
|
||||
dbg("%d rep0:%d", __LINE__, rep0);
|
||||
goto bad;
|
||||
}
|
||||
if (++rep0 == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
len += LZMA_MATCH_MIN_LEN;
|
||||
@@ -476,15 +450,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
IF_NOT_FEATURE_LZMA_FAST(string:)
|
||||
do {
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0) {
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
/* bug 10436 has an example file where this triggers: */
|
||||
//if ((int32_t)pos < 0)
|
||||
// goto bad;
|
||||
/* more stringent test (see unzip_bad_lzma_1.zip): */
|
||||
if (pos >= buffer_size)
|
||||
goto bad;
|
||||
}
|
||||
previous_byte = buffer[pos];
|
||||
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
|
||||
buffer[buffer_pos++] = previous_byte;
|
||||
@@ -511,12 +478,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
/* One of our users, bbunpack(), expects _us_ to emit
|
||||
* the error message (since it's the best place to give
|
||||
* potentially more detailed information).
|
||||
* Do not fail silently.
|
||||
*/
|
||||
bb_simple_error_msg("corrupted data");
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
rc_free(rc);
|
||||
|
||||
@@ -27,16 +27,11 @@ 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
|
||||
/* We use arch-optimized unaligned accessors */
|
||||
#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
|
||||
#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
|
||||
#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
|
||||
#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
|
||||
|
||||
#include "unxz/xz_dec_bcj.c"
|
||||
#include "unxz/xz_dec_lzma2.c"
|
||||
@@ -52,7 +47,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
IF_DESKTOP(long long) int total = 0;
|
||||
|
||||
if (!global_crc32_table)
|
||||
global_crc32_new_table_le();
|
||||
global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
|
||||
|
||||
memset(&iobuf, 0, sizeof(iobuf));
|
||||
membuf = xmalloc(2 * BUFSIZ);
|
||||
@@ -74,7 +69,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
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);
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
@@ -96,24 +91,6 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@@ -141,12 +118,12 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
continue;
|
||||
}
|
||||
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
|
||||
bb_simple_error_msg("corrupted data");
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
xz_dec_end(state);
|
||||
free(membuf);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
* 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"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2001 Glenn McGrath.
|
||||
/* 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"
|
||||
#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)
|
||||
@@ -22,7 +22,7 @@ static unsigned read_num(char *str, int base, int len)
|
||||
* 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");
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
char raw[60];
|
||||
struct ar_header formatted;
|
||||
} ar;
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned ar_long_name_size;
|
||||
#endif
|
||||
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
@@ -53,7 +57,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += 60;
|
||||
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_simple_error_msg_and_die("invalid ar header");
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/*
|
||||
* Note that the fields MUST be read in reverse order as
|
||||
@@ -77,27 +81,23 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
* 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);
|
||||
ar_long_name_size = size;
|
||||
free(ar_long_names);
|
||||
ar_long_names = xmalloc(size);
|
||||
xread(archive_handle->src_fd, 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");
|
||||
bb_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->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
|
||||
typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
|
||||
typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
|
||||
typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
|
||||
@@ -107,13 +107,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
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 */
|
||||
* (saved in ar_long_names) that conatains 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");
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -124,13 +124,11 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
typed->name[strcspn(typed->name, " /")] = '\0';
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle);
|
||||
archive_handle->action_header(typed);
|
||||
#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)
|
||||
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
|
||||
continue;
|
||||
create_links_from_list(sa->link_placeholders);
|
||||
} else
|
||||
#endif
|
||||
archive_handle->action_data(archive_handle);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2002 Laurence Anderson
|
||||
/* Copyright 2002 Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef struct 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];
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
@@ -33,17 +33,16 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
goto create_hardlinks;
|
||||
}
|
||||
if (size != 110) {
|
||||
bb_simple_error_msg_and_die("short read");
|
||||
bb_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");
|
||||
bb_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"
|
||||
@@ -51,7 +50,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
&inode, &mode, &uid, &gid,
|
||||
&nlink, &mtime, &size,
|
||||
&major, &minor, &namesize) != 10)
|
||||
bb_simple_error_msg_and_die("damaged cpio file");
|
||||
bb_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)
|
||||
@@ -125,7 +124,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
//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);
|
||||
archive_handle->action_header(file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
/* 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
|
||||
@@ -11,6 +10,7 @@
|
||||
* Opengroup's ustar interchange format,
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -32,7 +32,7 @@ static unsigned long long getOctal(char *str, int len)
|
||||
if (*end != '\0' && *end != ' ') {
|
||||
int8_t first = str[0];
|
||||
if (!(first & 0x80))
|
||||
bb_simple_error_msg_and_die("corrupted octal value in tar header");
|
||||
bb_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
|
||||
@@ -100,7 +100,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
) {
|
||||
bb_simple_error_msg("malformed extended header, skipped");
|
||||
bb_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));
|
||||
@@ -147,20 +147,11 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
#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;
|
||||
@@ -202,13 +193,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* the very first read fails. Grrr.
|
||||
*/
|
||||
if (archive_handle->offset == 0)
|
||||
bb_simple_error_msg("short read");
|
||||
bb_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");
|
||||
bb_error_msg_and_die("short read");
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -251,21 +242,21 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
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");
|
||||
bb_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");
|
||||
bb_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;
|
||||
sum_s = ' ' * sizeof(tar.chksum);
|
||||
#endif
|
||||
sum_u = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
@@ -278,22 +269,27 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
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");
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
{
|
||||
char *endp; /* gcc likes temp var for &endp */
|
||||
sum = strtoul(tar.chksum, &endp, 8);
|
||||
if ((*endp != '\0' && *endp != ' ')
|
||||
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
}
|
||||
/* don't use xstrtoul, tar.chksum may have leading spaces */
|
||||
sum = strtoul(tar.chksum, NULL, 8);
|
||||
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
/* GET_OCTAL trashes subsequent field, therefore we call it
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (!tar.typeflag) tar.typeflag = '0';
|
||||
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
|
||||
|
||||
/* getOctal trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
char t = tar.prefix[0];
|
||||
@@ -303,11 +299,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
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));
|
||||
@@ -339,7 +330,9 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->name = xstrdup(tar.name);
|
||||
}
|
||||
|
||||
switch (tar_typeflag) {
|
||||
/* Set bits 12-15 of the files mode */
|
||||
/* (typeflag was not trashed because chksum does not use getOctal) */
|
||||
switch (tar.typeflag) {
|
||||
case '1': /* hardlink */
|
||||
/* we mark hardlinks as regular files with zero size and a link name */
|
||||
file_header->mode |= S_IFREG;
|
||||
@@ -347,7 +340,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* ... 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
|
||||
* 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.
|
||||
@@ -358,7 +351,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
/* case 0: */
|
||||
case '0':
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
if (file_header->name && last_char_is(file_header->name, '/')) {
|
||||
if (last_char_is(file_header->name, '/')) {
|
||||
goto set_dir;
|
||||
}
|
||||
#endif
|
||||
@@ -388,7 +381,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
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'));
|
||||
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 */
|
||||
@@ -396,7 +389,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
/* 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);
|
||||
@@ -407,7 +399,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
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;
|
||||
@@ -422,14 +413,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
// 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 */
|
||||
// case 'V': /* Volume header */
|
||||
#endif
|
||||
}
|
||||
skip_ext_hdr:
|
||||
{
|
||||
off_t sz;
|
||||
bb_error_msg("warning: skipping header '%c'", tar_typeflag);
|
||||
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 */
|
||||
@@ -439,7 +429,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
goto again_after_align;
|
||||
}
|
||||
default:
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar_typeflag);
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
@@ -454,22 +444,15 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
#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);
|
||||
}
|
||||
overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
|
||||
//TODO: do the same for 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);
|
||||
archive_handle->action_header(/*archive_handle->*/ file_header);
|
||||
/* Note that we kill the '/' only after action_header() */
|
||||
/* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */
|
||||
if (cp)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -5,13 +5,8 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC header_list(archive_handle_t *archive_handle)
|
||||
void FAST_FUNC header_list(const file_header_t *file_header)
|
||||
{
|
||||
//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));
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC header_skip(archive_handle_t *archive_handle UNUSED_PARAM)
|
||||
void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
|
||||
{
|
||||
}
|
||||
@@ -2,17 +2,14 @@
|
||||
/*
|
||||
* 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)
|
||||
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
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];
|
||||
@@ -32,8 +29,8 @@ void FAST_FUNC header_verbose_list(archive_handle_t *archive_handle)
|
||||
/*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),
|
||||
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
user,
|
||||
group,
|
||||
file_header->size,
|
||||
@@ -43,14 +40,14 @@ void FAST_FUNC header_verbose_list(archive_handle_t *archive_handle)
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
printable_string(file_header->name));
|
||||
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),
|
||||
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
(unsigned)file_header->uid,
|
||||
(unsigned)file_header->gid,
|
||||
file_header->size,
|
||||
@@ -60,13 +57,13 @@ void FAST_FUNC header_verbose_list(archive_handle_t *archive_handle)
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
printable_string(file_header->name));
|
||||
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));
|
||||
printf(" -> %s", file_header->link_target);
|
||||
}
|
||||
putc('\n', fp);
|
||||
bb_putchar('\n');
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
}
|
||||
|
||||
/* 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,
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in , unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
@@ -797,6 +797,7 @@ static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
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) {
|
||||
@@ -810,6 +811,7 @@ static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
max_ahead = LZO_MIN(2, (unsigned)l1 - 1);
|
||||
}
|
||||
|
||||
|
||||
while (ahead < max_ahead && c->look > m_len) {
|
||||
int lazy_match_min_gain;
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
************************************************************************/
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len /*, void* wrkmem */)
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
register uint8_t* op;
|
||||
register const uint8_t* ip;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -15,7 +16,7 @@ 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");
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
xstate->signature_skipped = 2;
|
||||
@@ -46,7 +47,7 @@ ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf
|
||||
} else {
|
||||
nwrote = full_write(xstate->dst_fd, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
bb_simple_perror_msg("write");
|
||||
bb_perror_msg("write");
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -157,46 +158,49 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
static transformer_state_t *setup_transformer_on_fd(int fd, int die_if_not_compressed)
|
||||
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
union {
|
||||
uint8_t b[4];
|
||||
uint16_t b16[2];
|
||||
uint32_t b32[1];
|
||||
} magic;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->signature_skipped = 2;
|
||||
|
||||
/* .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);
|
||||
xread(fd, magic.b16, sizeof(magic.b16[0]));
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& xstate->magic.b16[0] == GZIP_MAGIC
|
||||
&& 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
|
||||
&& 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
|
||||
&& 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
|
||||
&& 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) {
|
||||
xread(fd, magic.b32, sizeof(magic.b32[0]));
|
||||
if (magic.b32[0] == XZ_MAGIC2) {
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
@@ -204,8 +208,8 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int die_if_not_compr
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (die_if_not_compressed)
|
||||
bb_simple_error_msg_and_die("no gzip"
|
||||
if (fail_if_not_compressed)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
IF_FEATURE_SEAMLESS_XZ("/xz")
|
||||
" magic");
|
||||
@@ -221,8 +225,18 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int die_if_not_compr
|
||||
return xstate;
|
||||
}
|
||||
|
||||
static void fork_transformer_and_free(transformer_state_t *xstate)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
if (!xstate || !xstate->xformer) {
|
||||
free(xstate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
@@ -230,43 +244,15 @@ static void fork_transformer_and_free(transformer_state_t *xstate)
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xlseek(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)
|
||||
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
int fd;
|
||||
@@ -277,7 +263,8 @@ static transformer_state_t *open_transformer(const char *fname, int die_if_not_c
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
if (is_suffixed_with(fname, ".lzma")) {
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
@@ -286,18 +273,18 @@ static transformer_state_t *open_transformer(const char *fname, int die_if_not_c
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, die_if_not_compressed);
|
||||
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int die_if_not_compressed)
|
||||
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, die_if_not_compressed);
|
||||
if (!xstate) /* open error */
|
||||
xstate = open_transformer(fname, fail_if_not_compressed);
|
||||
if (!xstate)
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
@@ -328,7 +315,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
transformer_state_t *xstate;
|
||||
char *image;
|
||||
|
||||
xstate = open_transformer(fname, /*die_if_not_compressed:*/ 0);
|
||||
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (!xstate) /* file open error */
|
||||
return NULL;
|
||||
|
||||
@@ -343,24 +330,11 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
*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
|
||||
);
|
||||
/* File is not compressed */
|
||||
//FIXME: avoid seek
|
||||
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
image = xmalloc_read(xstate->src_fd, maxsz_p);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
@@ -373,7 +347,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
int fd;
|
||||
char *image;
|
||||
|
||||
fd = open_zipped(fname, /*die_if_not_compressed:*/ 0);
|
||||
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -13,6 +14,6 @@ void FAST_FUNC seek_by_jump(int fd, off_t amount)
|
||||
if (errno == ESPIPE)
|
||||
seek_by_read(fd, amount);
|
||||
else
|
||||
bb_simple_perror_msg_and_die("seek failure");
|
||||
bb_perror_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "ar_.h"
|
||||
#include "ar.h"
|
||||
|
||||
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
@@ -12,7 +13,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
|
||||
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");
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += AR_MAGIC_LEN;
|
||||
|
||||
|
||||
@@ -2,51 +2,27 @@
|
||||
/*
|
||||
* 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* FAST_FUNC strip_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;
|
||||
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] == '/') {
|
||||
if (is_prefixed_with(cp, "/../"+1)) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = cp;
|
||||
find_dotdot:
|
||||
cp2 = strstr(cp2, "/..");
|
||||
cp2 = strstr(cp, "/../");
|
||||
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;
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
@@ -58,8 +34,3 @@ const char* FAST_FUNC skip_unsafe_prefix(const char *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;
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ static enum xz_ret XZ_FUNC dec_block_header(struct xz_dec *s)
|
||||
return XZ_OK;
|
||||
}
|
||||
|
||||
static NOINLINE enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
|
||||
static enum xz_ret XZ_FUNC dec_main(struct xz_dec *s, struct xz_buf *b)
|
||||
{
|
||||
enum xz_ret ret;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#define STREAM_HEADER_SIZE 12
|
||||
|
||||
#define HEADER_MAGIC "\375""7zXZ"
|
||||
#define HEADER_MAGIC "\3757zXZ"
|
||||
#define HEADER_MAGIC_SIZE 6
|
||||
|
||||
#define FOOTER_MAGIC "YZ"
|
||||
|
||||
+251
-241
@@ -24,38 +24,38 @@
|
||||
|
||||
"Minimalized" for busybox by Alain Knaff
|
||||
*/
|
||||
|
||||
//config:config LZOP
|
||||
//config: bool "lzop (13 kb)"
|
||||
//config: bool "lzop"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Lzop compression/decompresion.
|
||||
//config: Lzop compression/decompresion.
|
||||
//config:
|
||||
//config:config UNLZOP
|
||||
//config: bool "unlzop (13 kb)"
|
||||
//config: bool "unlzop"
|
||||
//config: default n # INCOMPAT: upstream lzop does not provide such tool
|
||||
//config: help
|
||||
//config: Lzop decompresion.
|
||||
//config: Lzop decompresion.
|
||||
//config:
|
||||
//config:config LZOPCAT
|
||||
//config: bool "lzopcat (13 kb)"
|
||||
//config: bool "lzopcat"
|
||||
//config: default n # INCOMPAT: upstream lzop does not provide such tool
|
||||
//config: help
|
||||
//config: Alias to "lzop -dc".
|
||||
//config: Alias to "unlzop -c".
|
||||
//config:
|
||||
//config:config LZOP_COMPR_HIGH
|
||||
//config: bool "lzop compression levels 7,8,9 (not very useful)"
|
||||
//config: default n
|
||||
//config: depends on LZOP || UNLZOP || LZOPCAT
|
||||
//config: help
|
||||
//config: High levels (7,8,9) of lzop compression. These levels
|
||||
//config: are actually slower than gzip at equivalent compression ratios
|
||||
//config: and take up 3.2K of code.
|
||||
//config: High levels (7,8,9) of lzop compression. These levels
|
||||
//config: are actually slower than gzip at equivalent compression ratios
|
||||
//config: and take up 3.2K of code.
|
||||
|
||||
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
|
||||
// APPLET_ODDNAME:name main location suid_type help
|
||||
//applet:IF_UNLZOP( APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
|
||||
//applet:IF_LZOPCAT(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
|
||||
|
||||
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
|
||||
//kbuild:lib-$(CONFIG_UNLZOP) += lzop.o
|
||||
//kbuild:lib-$(CONFIG_LZOPCAT) += lzop.o
|
||||
@@ -80,13 +80,12 @@
|
||||
//usage: "\n -F Don't verify checksum"
|
||||
//usage:
|
||||
//usage:#define unlzop_trivial_usage
|
||||
//usage: "[-cfUvF] [FILE]..."
|
||||
//usage: "[-cfkvF] [FILE]..."
|
||||
//usage:#define unlzop_full_usage "\n\n"
|
||||
//usage: " -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage: "\n -U Delete input files"
|
||||
///////: "\n -k Keep input files" (default, so why bother documenting?)
|
||||
//usage: "\n -t Test integrity"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -F Don't verify checksum"
|
||||
|
||||
@@ -142,7 +141,8 @@ static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
|
||||
#define TEST_OP (op <= op_end)
|
||||
|
||||
static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len /*, void* wrkmem */)
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
uint8_t* op;
|
||||
uint8_t* ip;
|
||||
@@ -154,7 +154,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
unsigned lit = 0;
|
||||
unsigned next_lit = NO_LIT;
|
||||
unsigned nl;
|
||||
// unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
|
||||
unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
|
||||
|
||||
// LZO_UNUSED(wrkmem);
|
||||
|
||||
@@ -208,6 +208,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
lit = 0;
|
||||
goto match_done;
|
||||
|
||||
|
||||
/* handle matches */
|
||||
do {
|
||||
if (t < 16) { /* a M1 match */
|
||||
@@ -227,7 +228,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
*litp = (unsigned char)((*litp & ~3) | lit);
|
||||
/* copy over the 2 literals that replace the match */
|
||||
copy2(ip-2, m_pos, pd(op, m_pos));
|
||||
// o_m1_a++;
|
||||
o_m1_a++;
|
||||
}
|
||||
/* test if a literal run follows */
|
||||
else
|
||||
@@ -249,7 +250,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
lit += 2 + t + 3;
|
||||
*litp = (unsigned char)(lit - 3);
|
||||
|
||||
// o_m1_b++;
|
||||
o_m1_b++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
goto copy_literal_run;
|
||||
@@ -284,7 +285,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
/* set new length of previous literal run */
|
||||
lit += 3 + t + 3;
|
||||
*litp = (unsigned char)(lit - 3);
|
||||
// o_m2++;
|
||||
o_m2++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
@@ -330,7 +331,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
*litp = (unsigned char)((*litp & ~3) | lit);
|
||||
/* copy over the 3 literals that replace the match */
|
||||
copy3(ip-3, m_pos, pd(op, m_pos));
|
||||
// o_m3_a++;
|
||||
o_m3_a++;
|
||||
}
|
||||
/* test if a literal run follows */
|
||||
else if (t == 1 && lit <= 3 && nl == 0
|
||||
@@ -349,7 +350,7 @@ static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
lit += 3 + t + 3;
|
||||
*litp = (unsigned char)(lit - 3);
|
||||
|
||||
// o_m3_b++;
|
||||
o_m3_b++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
@@ -438,33 +439,36 @@ typedef struct chksum_t {
|
||||
} chksum_t;
|
||||
|
||||
typedef struct header_t {
|
||||
/* used to have auxiliary fields here */
|
||||
unsigned version;
|
||||
unsigned lib_version;
|
||||
unsigned version_needed_to_extract;
|
||||
uint32_t flags;
|
||||
uint32_t mode;
|
||||
uint32_t mtime;
|
||||
uint32_t gmtdiff;
|
||||
uint32_t header_checksum;
|
||||
|
||||
/* Starting from here, the layout and endianness
|
||||
* are exactly in on-disk format.
|
||||
*/
|
||||
uint16_t version_be16;
|
||||
uint16_t lib_version_be16;
|
||||
uint16_t version_needed_to_extract_be16;
|
||||
uint8_t method;
|
||||
uint8_t level;
|
||||
uint32_t flags32; /* be32 on disk, but we keep this field in native order */
|
||||
uint32_t mode_be32;
|
||||
uint32_t mtime_be32;
|
||||
uint32_t gmtdiff_be32;
|
||||
char len_and_name[1+255+1];
|
||||
uint32_t extra_field_len;
|
||||
uint32_t extra_field_checksum;
|
||||
|
||||
unsigned char method;
|
||||
unsigned char level;
|
||||
|
||||
/* info */
|
||||
char name[255+1];
|
||||
} header_t;
|
||||
|
||||
struct globals {
|
||||
/*const uint32_t *lzo_crc32_table;*/
|
||||
chksum_t chksum;
|
||||
chksum_t chksum_in;
|
||||
chksum_t chksum_out;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
//#define G (*ptr_to_globals)
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
/*SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));*/ \
|
||||
} while (0)
|
||||
//#define INIT_G() do {
|
||||
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
//} while (0)
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -545,24 +549,24 @@ lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
static void init_chksum(void)
|
||||
static void init_chksum(chksum_t *ct)
|
||||
{
|
||||
G.chksum.f_adler32 = ADLER32_INIT_VALUE;
|
||||
G.chksum.f_crc32 = CRC32_INIT_VALUE;
|
||||
ct->f_adler32 = ADLER32_INIT_VALUE;
|
||||
ct->f_crc32 = CRC32_INIT_VALUE;
|
||||
}
|
||||
|
||||
static void add_bytes_to_chksum(const void* buf, int cnt)
|
||||
static void add_bytes_to_chksum(chksum_t *ct, const void* buf, int cnt)
|
||||
{
|
||||
/* We need to handle the two checksums at once, because at the
|
||||
* beginning of the header, we don't know yet which one we'll
|
||||
* eventually need */
|
||||
G.chksum.f_adler32 = lzo_adler32(G.chksum.f_adler32, (const uint8_t*)buf, cnt);
|
||||
G.chksum.f_crc32 = lzo_crc32(G.chksum.f_crc32, (const uint8_t*)buf, cnt);
|
||||
ct->f_adler32 = lzo_adler32(ct->f_adler32, (const uint8_t*)buf, cnt);
|
||||
ct->f_crc32 = lzo_crc32(ct->f_crc32, (const uint8_t*)buf, cnt);
|
||||
}
|
||||
|
||||
static uint32_t chksum_getresult(uint32_t h_flags32)
|
||||
static uint32_t chksum_getresult(chksum_t *ct, const header_t *h)
|
||||
{
|
||||
return (h_flags32 & F_H_CRC32) ? G.chksum.f_crc32 : G.chksum.f_adler32;
|
||||
return (h->flags & F_H_CRC32) ? ct->f_crc32 : ct->f_adler32;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -572,23 +576,50 @@ static uint32_t read32(void)
|
||||
xread(0, &v, 4);
|
||||
return ntohl(v);
|
||||
}
|
||||
|
||||
static void write32(uint32_t v)
|
||||
{
|
||||
v = htonl(v);
|
||||
xwrite(1, &v, 4);
|
||||
}
|
||||
|
||||
static void f_write(const void* buf, int cnt)
|
||||
{
|
||||
xwrite(1, buf, cnt);
|
||||
add_bytes_to_chksum(&G.chksum_out, buf, cnt);
|
||||
}
|
||||
|
||||
static void f_read(void* buf, int cnt)
|
||||
{
|
||||
xread(0, buf, cnt);
|
||||
add_bytes_to_chksum(buf, cnt);
|
||||
add_bytes_to_chksum(&G.chksum_in, buf, cnt);
|
||||
}
|
||||
//static int f_read8(void)
|
||||
//{
|
||||
// uint8_t v;
|
||||
// f_read(&v, 1);
|
||||
// return v;
|
||||
//}
|
||||
//static unsigned f_read16(void)
|
||||
//{
|
||||
// uint16_t v;
|
||||
// f_read(&v, 2);
|
||||
// return ntohs(v);
|
||||
//}
|
||||
|
||||
static int f_read8(void)
|
||||
{
|
||||
uint8_t v;
|
||||
f_read(&v, 1);
|
||||
return v;
|
||||
}
|
||||
|
||||
static void f_write8(uint8_t v)
|
||||
{
|
||||
f_write(&v, 1);
|
||||
}
|
||||
|
||||
static unsigned f_read16(void)
|
||||
{
|
||||
uint16_t v;
|
||||
f_read(&v, 2);
|
||||
return ntohs(v);
|
||||
}
|
||||
|
||||
static void f_write16(uint16_t v)
|
||||
{
|
||||
v = htons(v);
|
||||
f_write(&v, 2);
|
||||
}
|
||||
|
||||
static uint32_t f_read32(void)
|
||||
{
|
||||
uint32_t v;
|
||||
@@ -596,30 +627,34 @@ static uint32_t f_read32(void)
|
||||
return ntohl(v);
|
||||
}
|
||||
|
||||
static void write32(uint32_t v)
|
||||
static void f_write32(uint32_t v)
|
||||
{
|
||||
v = htonl(v);
|
||||
xwrite(1, &v, 4);
|
||||
f_write(&v, 4);
|
||||
}
|
||||
static void f_write(const void* buf, int cnt)
|
||||
|
||||
/**********************************************************************/
|
||||
static int lzo_get_method(header_t *h)
|
||||
{
|
||||
xwrite(1, buf, cnt);
|
||||
add_bytes_to_chksum(buf, cnt);
|
||||
/* check method */
|
||||
if (h->method == M_LZO1X_1) {
|
||||
if (h->level == 0)
|
||||
h->level = 3;
|
||||
} else if (h->method == M_LZO1X_1_15) {
|
||||
if (h->level == 0)
|
||||
h->level = 1;
|
||||
} else if (h->method == M_LZO1X_999) {
|
||||
if (h->level == 0)
|
||||
h->level = 9;
|
||||
} else
|
||||
return -1; /* not a LZO method */
|
||||
|
||||
/* check compression level */
|
||||
if (h->level < 1 || h->level > 9)
|
||||
return 15;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//static void f_write8(uint8_t v)
|
||||
//{
|
||||
// f_write(&v, 1);
|
||||
//}
|
||||
//static void f_write16(uint16_t v)
|
||||
//{
|
||||
// v = htons(v);
|
||||
// f_write(&v, 2);
|
||||
//}
|
||||
//static void f_write32(uint32_t v)
|
||||
//{
|
||||
// v = htonl(v);
|
||||
// f_write(&v, 4);
|
||||
//}
|
||||
|
||||
/**********************************************************************/
|
||||
#define LZO_BLOCK_SIZE (256 * 1024l)
|
||||
@@ -637,101 +672,86 @@ static NOINLINE int lzo_compress(const header_t *h)
|
||||
int r = 0; /* LZO_E_OK */
|
||||
uint8_t *const b1 = xzalloc(block_size);
|
||||
uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size));
|
||||
unsigned src_len = 0, dst_len = 0;
|
||||
uint32_t d_adler32 = ADLER32_INIT_VALUE;
|
||||
uint32_t d_crc32 = CRC32_INIT_VALUE;
|
||||
int l;
|
||||
uint8_t *wrk_mem = NULL;
|
||||
|
||||
/* Only these methods are possible, see lzo_set_method():
|
||||
* -1: M_LZO1X_1_15
|
||||
* -2..6: M_LZO1X_1
|
||||
* -7..9: M_LZO1X_999 if ENABLE_LZOP_COMPR_HIGH
|
||||
*/
|
||||
if (h->method == M_LZO1X_1)
|
||||
wrk_mem = xzalloc(LZO1X_1_MEM_COMPRESS);
|
||||
else /* check only if it's not the only possibility */
|
||||
IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
|
||||
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
else /* must be h->method == M_LZO1X_999 */
|
||||
else if (h->method == M_LZO1X_1_15)
|
||||
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
|
||||
else if (h->method == M_LZO1X_999)
|
||||
wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
unsigned src_len, dst_len;
|
||||
int l;
|
||||
uint32_t wordbuf[6];
|
||||
uint32_t *wordptr = wordbuf;
|
||||
|
||||
/* read a block */
|
||||
l = full_read(0, b1, block_size);
|
||||
src_len = (l > 0 ? l : 0);
|
||||
|
||||
/* write uncompressed block size */
|
||||
write32(src_len);
|
||||
|
||||
/* exit if last block */
|
||||
if (src_len == 0) {
|
||||
write32(0);
|
||||
if (src_len == 0)
|
||||
break;
|
||||
}
|
||||
*wordptr++ = htonl(src_len);
|
||||
|
||||
/* compute checksum of uncompressed block */
|
||||
if (h->flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
d_adler32 = lzo_adler32(ADLER32_INIT_VALUE, b1, src_len);
|
||||
if (h->flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
d_crc32 = lzo_crc32(CRC32_INIT_VALUE, b1, src_len);
|
||||
|
||||
/* compress */
|
||||
if (h->method == M_LZO1X_1)
|
||||
r = lzo1x_1_compress(b1, src_len, b2, &dst_len, wrk_mem);
|
||||
else IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
|
||||
else if (h->method == M_LZO1X_1_15)
|
||||
r = lzo1x_1_15_compress(b1, src_len, b2, &dst_len, wrk_mem);
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
else /* must be h->method == M_LZO1X_999 */
|
||||
else if (h->method == M_LZO1X_999)
|
||||
r = lzo1x_999_compress_level(b1, src_len, b2, &dst_len,
|
||||
wrk_mem, h->level);
|
||||
#endif
|
||||
else
|
||||
bb_error_msg_and_die("internal error");
|
||||
|
||||
if (r != 0) /* not LZO_E_OK */
|
||||
bb_error_msg_and_die("%s: %s", "internal error", "compression");
|
||||
bb_error_msg_and_die("internal error - compression failed");
|
||||
|
||||
/* write compressed block size */
|
||||
if (dst_len < src_len) {
|
||||
/* optimize */
|
||||
if (h->method == M_LZO1X_999) {
|
||||
unsigned new_len = src_len;
|
||||
r = lzo1x_optimize(b2, dst_len, b1, &new_len /*, NULL*/);
|
||||
r = lzo1x_optimize(b2, dst_len, b1, &new_len, NULL);
|
||||
if (r != 0 /*LZO_E_OK*/ || new_len != src_len)
|
||||
bb_error_msg_and_die("%s: %s", "internal error", "optimization");
|
||||
bb_error_msg_and_die("internal error - optimization failed");
|
||||
}
|
||||
*wordptr++ = htonl(dst_len);
|
||||
write32(dst_len);
|
||||
} else {
|
||||
/* data actually expanded => store data uncompressed */
|
||||
*wordptr++ = htonl(src_len);
|
||||
write32(src_len);
|
||||
}
|
||||
|
||||
/* write checksum of uncompressed block */
|
||||
if (h->flags32 & F_ADLER32_D)
|
||||
*wordptr++ = htonl(d_adler32);
|
||||
if (h->flags32 & F_CRC32_D)
|
||||
*wordptr++ = htonl(d_crc32);
|
||||
if (h->flags & F_ADLER32_D)
|
||||
write32(d_adler32);
|
||||
if (h->flags & F_CRC32_D)
|
||||
write32(d_crc32);
|
||||
|
||||
if (dst_len < src_len) {
|
||||
/* write checksum of compressed block */
|
||||
if (h->flags32 & F_ADLER32_C)
|
||||
*wordptr++ = htonl(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
|
||||
if (h->flags32 & F_CRC32_C)
|
||||
*wordptr++ = htonl(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
|
||||
}
|
||||
xwrite(1, wordbuf, ((char*)wordptr) - ((char*)wordbuf));
|
||||
if (dst_len < src_len) {
|
||||
if (h->flags & F_ADLER32_C)
|
||||
write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
|
||||
if (h->flags & F_CRC32_C)
|
||||
write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
|
||||
/* write compressed block data */
|
||||
xwrite(1, b2, dst_len);
|
||||
} else {
|
||||
/* write uncompressed block data */
|
||||
xwrite(1, b1, src_len);
|
||||
}
|
||||
// /* if full_read() was nevertheless "short", it was EOF */
|
||||
// if (src_len < block_size)
|
||||
// break;
|
||||
}
|
||||
|
||||
free(wrk_mem);
|
||||
@@ -752,15 +772,13 @@ static FAST_FUNC void lzo_check(
|
||||
*/
|
||||
uint32_t c = fn(init, buf, len);
|
||||
if (c != ref)
|
||||
bb_simple_error_msg_and_die("checksum error");
|
||||
bb_error_msg_and_die("checksum error");
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
// decompress a file
|
||||
/**********************************************************************/
|
||||
// used to have "const header_t *h" parameter, but since it uses
|
||||
// only flags32 field, changed to receive only that.
|
||||
static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
static NOINLINE int lzo_decompress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r;
|
||||
@@ -785,15 +803,15 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
/* error if split file */
|
||||
if (dst_len == 0xffffffffL)
|
||||
/* should not happen - not yet implemented */
|
||||
bb_simple_error_msg_and_die("this file is a split lzop file");
|
||||
bb_error_msg_and_die("this file is a split lzop file");
|
||||
|
||||
if (dst_len > MAX_BLOCK_SIZE)
|
||||
bb_simple_error_msg_and_die("corrupted data");
|
||||
bb_error_msg_and_die("corrupted data");
|
||||
|
||||
/* read compressed block size */
|
||||
src_len = read32();
|
||||
if (src_len <= 0 || src_len > dst_len)
|
||||
bb_simple_error_msg_and_die("corrupted data");
|
||||
bb_error_msg_and_die("corrupted data");
|
||||
|
||||
if (dst_len > block_size) {
|
||||
if (b2) {
|
||||
@@ -805,16 +823,16 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
}
|
||||
|
||||
/* read checksum of uncompressed block */
|
||||
if (h_flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
d_adler32 = read32();
|
||||
if (h_flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
d_crc32 = read32();
|
||||
|
||||
/* read checksum of compressed block */
|
||||
if (src_len < dst_len) {
|
||||
if (h_flags32 & F_ADLER32_C)
|
||||
if (h->flags & F_ADLER32_C)
|
||||
c_adler32 = read32();
|
||||
if (h_flags32 & F_CRC32_C)
|
||||
if (h->flags & F_CRC32_C)
|
||||
c_crc32 = read32();
|
||||
}
|
||||
|
||||
@@ -829,11 +847,11 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
if (!(option_mask32 & OPT_F)) {
|
||||
/* verify checksum of compressed block */
|
||||
if (h_flags32 & F_ADLER32_C)
|
||||
if (h->flags & F_ADLER32_C)
|
||||
lzo_check(ADLER32_INIT_VALUE,
|
||||
b1, src_len,
|
||||
lzo_adler32, c_adler32);
|
||||
if (h_flags32 & F_CRC32_C)
|
||||
if (h->flags & F_CRC32_C)
|
||||
lzo_check(CRC32_INIT_VALUE,
|
||||
b1, src_len,
|
||||
lzo_crc32, c_crc32);
|
||||
@@ -841,12 +859,12 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
/* decompress */
|
||||
// if (option_mask32 & OPT_F)
|
||||
// r = lzo1x_decompress(b1, src_len, b2, &d /*, NULL*/);
|
||||
// r = lzo1x_decompress(b1, src_len, b2, &d, NULL);
|
||||
// else
|
||||
r = lzo1x_decompress_safe(b1, src_len, b2, &d /*, NULL*/);
|
||||
r = lzo1x_decompress_safe(b1, src_len, b2, &d, NULL);
|
||||
|
||||
if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
|
||||
bb_simple_error_msg_and_die("corrupted data");
|
||||
bb_error_msg_and_die("corrupted data");
|
||||
}
|
||||
dst = b2;
|
||||
} else {
|
||||
@@ -856,11 +874,11 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
if (!(option_mask32 & OPT_F)) {
|
||||
/* verify checksum of uncompressed block */
|
||||
if (h_flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
lzo_check(ADLER32_INIT_VALUE,
|
||||
dst, dst_len,
|
||||
lzo_adler32, d_adler32);
|
||||
if (h_flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
lzo_check(CRC32_INIT_VALUE,
|
||||
dst, dst_len,
|
||||
lzo_crc32, d_crc32);
|
||||
@@ -900,7 +918,7 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
* -00000020 00 00 2d 67 04 17 00 04 00 00 00 03 ed ec 9d 6d
|
||||
* +00000020 00 00 10 5f 00 c1 00 04 00 00 00 03 ed ec 9d 6d
|
||||
* ^^^^^^^^^^^
|
||||
* chksum
|
||||
* chksum_out
|
||||
* The rest is identical.
|
||||
*/
|
||||
static const unsigned char lzop_magic[9] ALIGN1 = {
|
||||
@@ -913,144 +931,144 @@ static void check_magic(void)
|
||||
unsigned char magic[sizeof(lzop_magic)];
|
||||
xread(0, magic, sizeof(magic));
|
||||
if (memcmp(magic, lzop_magic, sizeof(lzop_magic)) != 0)
|
||||
bb_simple_error_msg_and_die("bad magic number");
|
||||
bb_error_msg_and_die("bad magic number");
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
// lzop file header
|
||||
/**********************************************************************/
|
||||
static void write_header(header_t *h)
|
||||
static void write_header(const header_t *h)
|
||||
{
|
||||
char *end;
|
||||
int l;
|
||||
|
||||
xwrite(1, lzop_magic, sizeof(lzop_magic));
|
||||
|
||||
init_chksum();
|
||||
init_chksum(&G.chksum_out);
|
||||
|
||||
/* Our caller leaves name zero-filled, so len == 0 */
|
||||
end = h->len_and_name+1 + 0; /* 0 is strlen(h->len_and_name+1) */
|
||||
/* Store length byte */
|
||||
/*h->len_and_name[0] = end - (h->len_and_name+1); - zero already */
|
||||
f_write16(h->version);
|
||||
f_write16(h->lib_version);
|
||||
f_write16(h->version_needed_to_extract);
|
||||
f_write8(h->method);
|
||||
f_write8(h->level);
|
||||
f_write32(h->flags);
|
||||
f_write32(h->mode);
|
||||
f_write32(h->mtime);
|
||||
f_write32(h->gmtdiff);
|
||||
|
||||
f_write(&h->version_be16, end - (char*)&h->version_be16);
|
||||
l = (int) strlen(h->name);
|
||||
f_write8(l);
|
||||
if (l)
|
||||
f_write(h->name, l);
|
||||
|
||||
h->flags32 = htonl(h->flags32); /* native endianness for lzo_compress() */
|
||||
|
||||
write32(chksum_getresult(h->flags32));
|
||||
f_write32(chksum_getresult(&G.chksum_out, h));
|
||||
}
|
||||
|
||||
static int read_header(header_t *h)
|
||||
{
|
||||
int r;
|
||||
int l;
|
||||
uint32_t checksum;
|
||||
/* As it stands now, only h->flags32 is used by our caller.
|
||||
* Therefore we don't store many fields in h->FIELD.
|
||||
*/
|
||||
unsigned h_version;
|
||||
unsigned h_version_needed_to_extract;
|
||||
|
||||
init_chksum();
|
||||
memset(h, 0, sizeof(*h));
|
||||
h->version_needed_to_extract = 0x0900; /* first lzop version */
|
||||
h->level = 0;
|
||||
|
||||
/* We don't support versions < 0.94, since 0.94
|
||||
* came only 2 months after 0.90:
|
||||
* 0.90 (10 Aug 1997): First public release of lzop
|
||||
* 0.94 (15 Oct 1997): Header format change
|
||||
*/
|
||||
init_chksum(&G.chksum_in);
|
||||
|
||||
/* Read up to and including name length byte */
|
||||
f_read(&h->version_be16, ((char*)&h->len_and_name[1]) - ((char*)&h->version_be16));
|
||||
|
||||
h_version = htons(h->version_be16);
|
||||
if (h_version < 0x0940)
|
||||
return 3;
|
||||
h_version_needed_to_extract = htons(h->version_needed_to_extract_be16);
|
||||
if (h_version_needed_to_extract > LZOP_VERSION)
|
||||
return 16;
|
||||
if (h_version_needed_to_extract < 0x0940)
|
||||
h->version = f_read16();
|
||||
if (h->version < 0x0900)
|
||||
return 3;
|
||||
h->lib_version = f_read16();
|
||||
if (h->version >= 0x0940) {
|
||||
h->version_needed_to_extract = f_read16();
|
||||
if (h->version_needed_to_extract > LZOP_VERSION)
|
||||
return 16;
|
||||
if (h->version_needed_to_extract < 0x0900)
|
||||
return 3;
|
||||
}
|
||||
h->method = f_read8();
|
||||
if (h->version >= 0x0940)
|
||||
h->level = f_read8();
|
||||
h->flags = f_read32();
|
||||
if (h->flags & F_H_FILTER)
|
||||
return 16; /* filter not supported */
|
||||
h->mode = f_read32();
|
||||
h->mtime = f_read32();
|
||||
if (h->version >= 0x0940)
|
||||
h->gmtdiff = f_read32();
|
||||
|
||||
l = f_read8();
|
||||
if (l > 0)
|
||||
f_read(h->name, l);
|
||||
h->name[l] = 0;
|
||||
|
||||
checksum = chksum_getresult(&G.chksum_in, h);
|
||||
h->header_checksum = f_read32();
|
||||
if (h->header_checksum != checksum)
|
||||
return 2;
|
||||
|
||||
if (h->method <= 0)
|
||||
return 14;
|
||||
r = lzo_get_method(h);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
/* former lzo_get_method(h): */
|
||||
if (h->method == M_LZO1X_1) {
|
||||
if (h->level == 0)
|
||||
h->level = 3;
|
||||
} else if (h->method == M_LZO1X_1_15) {
|
||||
if (h->level == 0)
|
||||
h->level = 1;
|
||||
} else if (h->method == M_LZO1X_999) {
|
||||
if (h->level == 0)
|
||||
h->level = 9;
|
||||
} else
|
||||
return -1; /* not a LZO method */
|
||||
/* check compression level */
|
||||
if (h->level < 1 || h->level > 9)
|
||||
return 15;
|
||||
|
||||
h->flags32 = ntohl(h->flags32);
|
||||
if (h->flags32 & F_H_FILTER)
|
||||
return 16; /* filter not supported */
|
||||
/* check reserved flags */
|
||||
if (h->flags32 & F_RESERVED)
|
||||
if (h->flags & F_RESERVED)
|
||||
return -13;
|
||||
|
||||
l = h->len_and_name[0];
|
||||
if (l > 0)
|
||||
/* UNUSED */ f_read(h->len_and_name+1, l);
|
||||
/* UNUSED h->len_and_name[1+l] = 0; */
|
||||
|
||||
checksum = chksum_getresult(h->flags32);
|
||||
if (read32() != checksum)
|
||||
return 2;
|
||||
|
||||
/* skip extra field [not used yet] */
|
||||
if (h->flags32 & F_H_EXTRA_FIELD) {
|
||||
uint32_t extra_field_len;
|
||||
uint32_t extra_field_checksum;
|
||||
if (h->flags & F_H_EXTRA_FIELD) {
|
||||
uint32_t k;
|
||||
char dummy;
|
||||
|
||||
/* note: the checksum also covers the length */
|
||||
init_chksum();
|
||||
extra_field_len = f_read32();
|
||||
for (k = 0; k < extra_field_len; k++)
|
||||
f_read(&dummy, 1);
|
||||
checksum = chksum_getresult(h->flags32);
|
||||
extra_field_checksum = read32();
|
||||
if (extra_field_checksum != checksum)
|
||||
init_chksum(&G.chksum_in);
|
||||
h->extra_field_len = f_read32();
|
||||
for (k = 0; k < h->extra_field_len; k++)
|
||||
f_read8();
|
||||
checksum = chksum_getresult(&G.chksum_in, h);
|
||||
h->extra_field_checksum = f_read32();
|
||||
if (h->extra_field_checksum != checksum)
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void p_header(header_t *h)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = read_header(h);
|
||||
if (r == 0)
|
||||
return;
|
||||
bb_error_msg_and_die("header_error %d", r);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
// compress
|
||||
/**********************************************************************/
|
||||
static void lzo_set_method(header_t *h)
|
||||
{
|
||||
smallint level;
|
||||
|
||||
/* levels 2..6 or none (defaults to level 3) */
|
||||
h->method = M_LZO1X_1;
|
||||
level = 5; /* levels 2-6 are actually the same */
|
||||
int level = 1;
|
||||
|
||||
if (option_mask32 & OPT_1) {
|
||||
h->method = M_LZO1X_1_15;
|
||||
level = 1;
|
||||
}
|
||||
if (option_mask32 & OPT_789) {
|
||||
} else if (option_mask32 & OPT_789) {
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
h->method = M_LZO1X_999;
|
||||
level = 9;
|
||||
if (option_mask32 & OPT_7)
|
||||
level = 7;
|
||||
else if (option_mask32 & OPT_8)
|
||||
level = 8;
|
||||
else
|
||||
level = 9;
|
||||
#else
|
||||
bb_simple_error_msg_and_die("high compression not compiled in");
|
||||
bb_error_msg_and_die("high compression not compiled in");
|
||||
#endif
|
||||
} else { /* levels 2..6 or none (defaults to level 3) */
|
||||
h->method = M_LZO1X_1;
|
||||
level = 5; /* levels 2-6 are actually the same */
|
||||
}
|
||||
|
||||
h->level = level;
|
||||
@@ -1065,21 +1083,18 @@ static int do_lzo_compress(void)
|
||||
|
||||
lzo_set_method(h);
|
||||
|
||||
h->version_be16 = htons(LZOP_VERSION & 0xffff);
|
||||
h->version_needed_to_extract_be16 = htons(0x0940);
|
||||
h->lib_version_be16 = htons(lzo_version() & 0xffff);
|
||||
h->version = (LZOP_VERSION & 0xffff);
|
||||
h->version_needed_to_extract = 0x0940;
|
||||
h->lib_version = lzo_version() & 0xffff;
|
||||
|
||||
h->flags32 = htonl((F_OS & F_OS_MASK) | (F_CS & F_CS_MASK));
|
||||
h->flags = (F_OS & F_OS_MASK) | (F_CS & F_CS_MASK);
|
||||
|
||||
if (!(option_mask32 & OPT_F) || h->method == M_LZO1X_999) {
|
||||
h->flags32 |= htonl(F_ADLER32_D);
|
||||
h->flags |= F_ADLER32_D;
|
||||
if (option_mask32 & OPT_C)
|
||||
h->flags32 |= htonl(F_ADLER32_C);
|
||||
h->flags |= F_ADLER32_C;
|
||||
}
|
||||
|
||||
/* write_header() also converts h->flags32 to native endianness */
|
||||
write_header(h);
|
||||
|
||||
return lzo_compress(h);
|
||||
#undef h
|
||||
}
|
||||
@@ -1089,14 +1104,11 @@ static int do_lzo_compress(void)
|
||||
/**********************************************************************/
|
||||
static int do_lzo_decompress(void)
|
||||
{
|
||||
int r;
|
||||
header_t header;
|
||||
|
||||
check_magic();
|
||||
r = read_header(&header);
|
||||
if (r != 0)
|
||||
bb_error_msg_and_die("header_error %d", r);
|
||||
return lzo_decompress(header.flags32);
|
||||
p_header(&header);
|
||||
return lzo_decompress(&header);
|
||||
}
|
||||
|
||||
static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
@@ -1121,14 +1133,12 @@ static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate
|
||||
int lzop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
INIT_G();
|
||||
|
||||
getopt32(argv, OPTION_STRING);
|
||||
argv += optind;
|
||||
/* -U is "anti -k", invert bit for bbunpack(): */
|
||||
option_mask32 ^= OPT_KEEP;
|
||||
/* -k disables -U (if any): */
|
||||
/* opt_complementary "k-U"? - nope, only handles -Uk, not -kU */
|
||||
/* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */
|
||||
if (option_mask32 & OPT_k)
|
||||
option_mask32 |= OPT_KEEP;
|
||||
|
||||
@@ -1139,6 +1149,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (ENABLE_UNLZOP && applet_name[4] == 'o')
|
||||
option_mask32 |= OPT_DECOMPRESS;
|
||||
|
||||
global_crc32_new_table_le();
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
|
||||
}
|
||||
+129
-296
@@ -6,16 +6,28 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM
|
||||
//config: bool "rpm (32 kb)"
|
||||
//config: bool "rpm"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Mini RPM applet - queries and extracts RPM packages.
|
||||
//config: Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
//applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_RPM) += rpm.o
|
||||
|
||||
//usage:#define rpm_trivial_usage
|
||||
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
|
||||
//usage:#define rpm_full_usage "\n\n"
|
||||
//usage: "Manipulate RPM packages\n"
|
||||
//usage: "\nCommands:"
|
||||
//usage: "\n -i Install package"
|
||||
//usage: "\n -qp Query package"
|
||||
//usage: "\n -qpi Show information"
|
||||
//usage: "\n -qpl List contents"
|
||||
//usage: "\n -qpd List documents"
|
||||
//usage: "\n -qpc List config files"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
@@ -56,8 +68,6 @@
|
||||
#define TAG_DIRINDEXES 1116
|
||||
#define TAG_BASENAMES 1117
|
||||
#define TAG_DIRNAMES 1118
|
||||
#define TAG_PAYLOADCOMPRESSOR 1125
|
||||
|
||||
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
@@ -81,153 +91,148 @@ typedef struct {
|
||||
|
||||
struct globals {
|
||||
void *map;
|
||||
rpm_index *mytags;
|
||||
rpm_index **mytags;
|
||||
int tagcount;
|
||||
unsigned mapsize;
|
||||
IF_VARIABLE_ARCH_PAGESIZE(unsigned pagesize;)
|
||||
#define G_pagesize cached_pagesize(G.pagesize)
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
|
||||
static int rpm_gettags(const char *filename)
|
||||
static void extract_cpio(int fd, const char *source_rpm)
|
||||
{
|
||||
rpm_index *tags;
|
||||
int fd;
|
||||
unsigned pass, idx;
|
||||
unsigned storepos;
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
if (!filename) { /* rpm2cpio w/o filename? */
|
||||
filename = bb_msg_standard_output;
|
||||
fd = 0;
|
||||
} else {
|
||||
fd = xopen(filename, O_RDONLY);
|
||||
}
|
||||
if (source_rpm != NULL) {
|
||||
/* Binary rpm (it was built from some SRPM), install to root */
|
||||
xchdir("/");
|
||||
} /* else: SRPM, install to current dir */
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
#if 0 /* For testing (rpm -i only lists the files in internal cpio): */
|
||||
archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_skip;
|
||||
#endif
|
||||
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
*/
|
||||
| ARCHIVE_REPLACE_VIA_RENAME;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
{
|
||||
/* We should never need more than 200 (shrink via realloc later) */
|
||||
rpm_index **tags = xzalloc(200 * sizeof(tags[0]));
|
||||
int pass, tagindex = 0;
|
||||
|
||||
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
G.tagcount = 0;
|
||||
tags = NULL;
|
||||
idx = 0;
|
||||
/* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
struct rpm_header header;
|
||||
unsigned cnt;
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
xread(fd, &header, sizeof(header));
|
||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER))
|
||||
bb_error_msg_and_die("invalid RPM header magic in '%s'", filename);
|
||||
#if BB_LITTLE_ENDIAN
|
||||
return NULL; /* Invalid magic, or not version 1 */
|
||||
header.size = ntohl(header.size);
|
||||
#endif
|
||||
cnt = ntohl(header.entries);
|
||||
/* Prevent multiplication overflow leading to undersized allocations */
|
||||
if (sizeof(cnt) <= 4 && cnt >= 0x00400000) /* ~4 million */
|
||||
bb_error_msg_and_die("bad RPM header.entries:%u", cnt);
|
||||
storepos += sizeof(header) + cnt * 16;
|
||||
header.entries = ntohl(header.entries);
|
||||
storepos = xlseek(fd, 0, SEEK_CUR) + header.entries * 16;
|
||||
|
||||
G.tagcount += cnt;
|
||||
tags = xrealloc(tags, sizeof(tags[0]) * G.tagcount);
|
||||
xread(fd, &tags[idx], sizeof(tags[0]) * cnt);
|
||||
while (cnt--) {
|
||||
rpm_index *tag = &tags[idx];
|
||||
#if BB_LITTLE_ENDIAN
|
||||
tag->tag = ntohl(tag->tag);
|
||||
tag->type = ntohl(tag->type);
|
||||
tag->count = ntohl(tag->count);
|
||||
#endif
|
||||
tag->offset = storepos + ntohl(tag->offset);
|
||||
while (header.entries--) {
|
||||
tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex));
|
||||
xread(fd, tmpindex, sizeof(*tmpindex));
|
||||
tmpindex->tag = ntohl(tmpindex->tag);
|
||||
tmpindex->type = ntohl(tmpindex->type);
|
||||
tmpindex->count = ntohl(tmpindex->count);
|
||||
tmpindex->offset = storepos + ntohl(tmpindex->offset);
|
||||
if (pass == 0)
|
||||
tag->tag -= 743;
|
||||
idx++;
|
||||
tmpindex->tag -= 743;
|
||||
}
|
||||
storepos = xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
/* Skip padding to 8 byte boundary after reading signature headers */
|
||||
if (pass == 0)
|
||||
while (header.size & 7)
|
||||
header.size++;
|
||||
/* Seek past store */
|
||||
storepos = xlseek(fd, header.size, SEEK_CUR);
|
||||
xlseek(fd, (-storepos) & 0x7, SEEK_CUR);
|
||||
}
|
||||
G.mytags = tags;
|
||||
|
||||
/* Map the store */
|
||||
storepos = (storepos + G_pagesize) & -(int)G_pagesize;
|
||||
/* remember size for munmap */
|
||||
G.mapsize = storepos;
|
||||
G.map = mmap_read(fd, storepos);
|
||||
if (G.map == MAP_FAILED)
|
||||
bb_perror_msg_and_die("mmap '%s'", filename);
|
||||
|
||||
return fd;
|
||||
/* realloc tags to save space */
|
||||
tags = xrealloc(tags, tagindex * sizeof(tags[0]));
|
||||
*num_tags = tagindex;
|
||||
/* All done, leave the file at the start of the gzipped cpio archive */
|
||||
return tags;
|
||||
}
|
||||
|
||||
static int bsearch_rpmtag(const void *key, const void *item)
|
||||
{
|
||||
int *tag = (int *)key;
|
||||
rpm_index *tmp = (rpm_index *) item;
|
||||
return (*tag - tmp->tag);
|
||||
rpm_index **tmp = (rpm_index **) item;
|
||||
return (*tag - tmp[0]->tag);
|
||||
}
|
||||
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
}
|
||||
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
{
|
||||
rpm_index *found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found->count)
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return NULL;
|
||||
if (found->type == RPM_STRING_TYPE
|
||||
|| found->type == RPM_I18NSTRING_TYPE
|
||||
|| found->type == RPM_STRING_ARRAY_TYPE
|
||||
if (found[0]->type == RPM_STRING_TYPE
|
||||
|| found[0]->type == RPM_I18NSTRING_TYPE
|
||||
|| found[0]->type == RPM_STRING_ARRAY_TYPE
|
||||
) {
|
||||
int n;
|
||||
char *tmpstr = (char *) G.map + found->offset;
|
||||
char *tmpstr = (char *) G.map + found[0]->offset;
|
||||
for (n = 0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static char *rpm_getstr0(int tag)
|
||||
{
|
||||
return rpm_getstr(tag, 0);
|
||||
}
|
||||
|
||||
#if ENABLE_RPM
|
||||
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index *found;
|
||||
rpm_index **found;
|
||||
char *tmpint;
|
||||
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found->count)
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (char *) G.map + found->offset;
|
||||
if (found->type == RPM_INT32_TYPE) {
|
||||
tmpint = (char *) G.map + found[0]->offset;
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint += itemindex*4;
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found->type == RPM_INT16_TYPE) {
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint += itemindex*2;
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found->type == RPM_INT8_TYPE) {
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint += itemindex;
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index *found;
|
||||
found = bsearch(&tag, G.mytags, G.tagcount, sizeof(G.mytags[0]), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found->count;
|
||||
}
|
||||
|
||||
static void fileaction_dobackup(char *filename, int fileref)
|
||||
{
|
||||
struct stat oldfile;
|
||||
@@ -268,103 +273,11 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 //DEBUG
|
||||
static void print_all_tags(void)
|
||||
{
|
||||
unsigned i = 0;
|
||||
while (i < G.tagcount) {
|
||||
rpm_index *tag = &G.mytags[i];
|
||||
if (tag->type == RPM_STRING_TYPE
|
||||
|| tag->type == RPM_I18NSTRING_TYPE
|
||||
|| tag->type == RPM_STRING_ARRAY_TYPE
|
||||
) {
|
||||
unsigned n;
|
||||
char *str = (char *) G.map + tag->offset;
|
||||
|
||||
printf("tag[%u] %08x type %08x offset %08x count %d '%s'\n",
|
||||
i, tag->tag, tag->type, tag->offset, tag->count, str
|
||||
);
|
||||
for (n = 1; n < tag->count; n++) {
|
||||
str += strlen(str) + 1;
|
||||
printf("\t'%s'\n", str);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define print_all_tags() ((void)0)
|
||||
#endif
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
if (source_rpm != NULL) {
|
||||
/* Binary rpm (it was built from some SRPM), install to root */
|
||||
xchdir("/");
|
||||
} /* else: SRPM, install to current dir */
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
#if 0 /* For testing (rpm -i only lists the files in internal cpio): */
|
||||
archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_skip;
|
||||
#endif
|
||||
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
*/
|
||||
| ARCHIVE_REPLACE_VIA_RENAME;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*die_if_not_compressed:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
|
||||
//usage:#define rpm_trivial_usage
|
||||
//usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm"
|
||||
//usage:#define rpm_full_usage "\n\n"
|
||||
//usage: "Manipulate RPM packages\n"
|
||||
//usage: "\nCommands:"
|
||||
//usage: "\n -i Install package"
|
||||
//usage: "\n -qp Query package"
|
||||
//usage: "\n -qpi Show information"
|
||||
//usage: "\n -qpl List contents"
|
||||
//usage: "\n -qpd List documents"
|
||||
//usage: "\n -qpc List config files"
|
||||
|
||||
/* RPM version 4.13.0.1:
|
||||
* Unlike -q, -i seems to imply -p: -i, -ip and -pi work the same.
|
||||
* OTOH, with -q order is important: "-piq FILE.rpm" works as -qp, not -qpi
|
||||
* (IOW: shows only package name, not package info).
|
||||
* "-iq ARG" works as -q: treats ARG as package name, not a file.
|
||||
*
|
||||
* "man rpm" on -l option and options implying it:
|
||||
* -l, --list List files in package.
|
||||
* -c, --configfiles List only configuration files (implies -l).
|
||||
* -d, --docfiles List only documentation files (implies -l).
|
||||
* -L, --licensefiles List only license files (implies -l).
|
||||
* --dump Dump file information as follows (implies -l):
|
||||
* path size mtime digest mode owner group isconfig isdoc rdev symlink
|
||||
* -s, --state Display the states of files in the package (implies -l).
|
||||
* The state of each file is one of normal, not installed, or replaced.
|
||||
*
|
||||
* Looks like we can switch to getopt32 here: in practice, people
|
||||
* do place -q first if they intend to use it (misinterpreting "-piq" wouldn't matter).
|
||||
*/
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt, func = 0;
|
||||
|
||||
INIT_G();
|
||||
INIT_PAGESIZE(G.pagesize);
|
||||
const unsigned pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
@@ -376,17 +289,17 @@ int rpm_main(int argc, char **argv)
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package (IOW: .rpm file, we are not querying RPMDB) */
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies -l) */
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies -l) */
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
@@ -400,18 +313,24 @@ int rpm_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
while (*argv) {
|
||||
int rpm_fd;
|
||||
unsigned mapsize;
|
||||
const char *source_rpm;
|
||||
|
||||
rpm_fd = rpm_gettags(*argv);
|
||||
print_all_tags();
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
G.mytags = rpm_gettags(rpm_fd, &G.tagcount);
|
||||
if (!G.mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
mapsize = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
mapsize = (mapsize + pagesize) & -(int)pagesize;
|
||||
/* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */
|
||||
G.map = mmap(0, mapsize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
//FIXME: error check?
|
||||
|
||||
source_rpm = rpm_getstr0(TAG_SOURCERPM);
|
||||
source_rpm = rpm_getstr(TAG_SOURCERPM, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* -i (and not -qi) */
|
||||
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
@@ -419,13 +338,10 @@ int rpm_main(int argc, char **argv)
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else
|
||||
if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
/* -qp */
|
||||
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr0(TAG_NAME), rpm_getstr0(TAG_VERSION), rpm_getstr0(TAG_RELEASE));
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
@@ -434,33 +350,30 @@ int rpm_main(int argc, char **argv)
|
||||
char bdatestring[50];
|
||||
const char *p;
|
||||
|
||||
printf("%-12s: %s\n", "Name" , rpm_getstr0(TAG_NAME));
|
||||
printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0));
|
||||
/* TODO compat: add "Epoch" here */
|
||||
printf("%-12s: %s\n", "Version" , rpm_getstr0(TAG_VERSION));
|
||||
printf("%-12s: %s\n", "Release" , rpm_getstr0(TAG_RELEASE));
|
||||
printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0));
|
||||
printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0));
|
||||
/* add "Architecture" */
|
||||
/* printf("%-12s: %s\n", "Install Date", "(not installed)"); - we don't know */
|
||||
printf("%-12s: %s\n", "Group" , rpm_getstr0(TAG_GROUP));
|
||||
printf("%-12s: %s\n", "Install Date", "(not installed)");
|
||||
printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0));
|
||||
printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0));
|
||||
printf("%-12s: %s\n", "License" , rpm_getstr0(TAG_LICENSE));
|
||||
printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0));
|
||||
/* add "Signature" */
|
||||
printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("%-12s: %s\n", "Build Date" , bdatestring);
|
||||
printf("%-12s: %s\n", "Build Host" , rpm_getstr0(TAG_BUILDHOST));
|
||||
p = rpm_getstr0(TAG_PREFIXS);
|
||||
printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0));
|
||||
p = rpm_getstr(TAG_PREFIXS, 0);
|
||||
printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)");
|
||||
/* add "Packager" */
|
||||
p = rpm_getstr0(TAG_VENDOR);
|
||||
if (p) /* rpm 4.13.0.1 does not show "(none)" for Vendor: */
|
||||
printf("%-12s: %s\n", "Vendor" , p);
|
||||
p = rpm_getstr0(TAG_URL);
|
||||
if (p) /* rpm 4.13.0.1 does not show "(none)"/"(null)" for URL: */
|
||||
printf("%-12s: %s\n", "URL" , p);
|
||||
printf("%-12s: %s\n", "Summary" , rpm_getstr0(TAG_SUMMARY));
|
||||
printf("Description :\n%s\n", rpm_getstr0(TAG_DESCRIPTION));
|
||||
p = rpm_getstr(TAG_VENDOR, 0);
|
||||
printf("%-12s: %s\n", "Vendor" , p ? p : "(none)");
|
||||
printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0));
|
||||
printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
@@ -483,90 +396,10 @@ int rpm_main(int argc, char **argv)
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Unsupported (help text shows what we support) */
|
||||
bb_show_usage();
|
||||
}
|
||||
if (!*++argv)
|
||||
break;
|
||||
munmap(G.map, G.mapsize);
|
||||
munmap(G.map, mapsize);
|
||||
free(G.mytags);
|
||||
close(rpm_fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* RPM */
|
||||
|
||||
/*
|
||||
* Mini rpm2cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config RPM2CPIO
|
||||
//config: bool "rpm2cpio (21 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Converts a RPM file into a CPIO archive.
|
||||
|
||||
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm.o
|
||||
|
||||
//usage:#define rpm2cpio_trivial_usage
|
||||
//usage: "PACKAGE.rpm"
|
||||
//usage:#define rpm2cpio_full_usage "\n\n"
|
||||
//usage: "Output a cpio archive of the rpm file"
|
||||
|
||||
#if ENABLE_RPM2CPIO
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
const char *str;
|
||||
int rpm_fd;
|
||||
|
||||
INIT_G();
|
||||
INIT_PAGESIZE(G.pagesize);
|
||||
|
||||
rpm_fd = rpm_gettags(argv[1]);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION) - we do this at the end instead.
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
str = rpm_getstr0(TAG_PAYLOADCOMPRESSOR);
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
&& str != NULL
|
||||
&& strcmp(str, "lzma") == 0
|
||||
) {
|
||||
// lzma compression can't be detected
|
||||
// set up decompressor without detection
|
||||
setup_lzma_on_fd(rpm_fd);
|
||||
} else {
|
||||
int signature_bytes = setup_unzip_on_fd(rpm_fd, /*die_if_not_compressed:*/ 0);
|
||||
if (signature_bytes != 0) {
|
||||
xlseek(rpm_fd, - signature_bytes, SEEK_CUR);
|
||||
bb_error_msg("warning, unknown compression '%s'", str);
|
||||
}
|
||||
}
|
||||
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_simple_error_msg_and_die("error unpacking");
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(rpm_fd);
|
||||
}
|
||||
|
||||
if (SEAMLESS_COMPRESSION) {
|
||||
check_errors_in_children(0);
|
||||
return bb_got_signal;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* RPM2CPIO */
|
||||
@@ -0,0 +1,96 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini rpm2cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config RPM2CPIO
|
||||
//config: bool "rpm2cpio"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Converts a RPM file into a CPIO archive.
|
||||
|
||||
//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
|
||||
//usage:#define rpm2cpio_trivial_usage
|
||||
//usage: "package.rpm"
|
||||
//usage:#define rpm2cpio_full_usage "\n\n"
|
||||
//usage: "Output a cpio archive of the rpm file"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
#include "rpm.h"
|
||||
|
||||
enum { rpm_fd = STDIN_FILENO };
|
||||
|
||||
static unsigned skip_header(void)
|
||||
{
|
||||
struct rpm_header header;
|
||||
unsigned len;
|
||||
|
||||
xread(rpm_fd, &header, sizeof(header));
|
||||
// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
|
||||
// bb_error_msg_and_die("invalid RPM header magic");
|
||||
// }
|
||||
// if (header.version != 1) {
|
||||
// bb_error_msg_and_die("unsupported RPM header version");
|
||||
// }
|
||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
|
||||
bb_error_msg_and_die("invalid RPM header magic or unsupported version");
|
||||
// ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
|
||||
}
|
||||
|
||||
/* Seek past index entries, and past store */
|
||||
len = 16 * ntohl(header.entries) + ntohl(header.size);
|
||||
seek_by_jump(rpm_fd, len);
|
||||
|
||||
return sizeof(header) + len;
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
unsigned pos;
|
||||
|
||||
if (argv[1]) {
|
||||
xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
|
||||
}
|
||||
xread(rpm_fd, &lead, sizeof(lead));
|
||||
|
||||
/* Just check the magic, the rest is irrelevant */
|
||||
if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
|
||||
bb_error_msg_and_die("invalid RPM magic");
|
||||
}
|
||||
|
||||
/* Skip the signature header, align to 8 bytes */
|
||||
pos = skip_header();
|
||||
seek_by_jump(rpm_fd, (-(int)pos) & 7);
|
||||
|
||||
/* Skip the main header */
|
||||
skip_header();
|
||||
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* This works, but doesn't report uncompress errors (they happen in child) */
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(rpm_fd);
|
||||
}
|
||||
|
||||
if (SEAMLESS_COMPRESSION) {
|
||||
check_errors_in_children(0);
|
||||
return bb_got_signal;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+269
-285
File diff suppressed because it is too large.
Load diff
@@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Makes "symlink attack" tarball (needs GNU tar for --append)
|
||||
|
||||
true >anything.txt
|
||||
tar cvf tar_symlink_attack.tar anything.txt
|
||||
rm anything.txt
|
||||
|
||||
ln -s /tmp symlink
|
||||
tar --append -f tar_symlink_attack.tar symlink
|
||||
rm symlink
|
||||
|
||||
mkdir symlink
|
||||
echo BUG >symlink/bb_test_evilfile
|
||||
tar --append -f tar_symlink_attack.tar symlink/bb_test_evilfile
|
||||
rm symlink/bb_test_evilfile
|
||||
rmdir symlink
|
||||
+91
-267
@@ -17,23 +17,23 @@
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip (26 kb)"
|
||||
//config: bool "unzip"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory.
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory.
|
||||
//config:
|
||||
//config:config FEATURE_UNZIP_CDF
|
||||
//config: bool "Read and use Central Directory data"
|
||||
//config: default y
|
||||
//config: depends on UNZIP
|
||||
//config: help
|
||||
//config: If you know that you only need to deal with simple
|
||||
//config: ZIP files without deleted/updated files, SFX archives etc,
|
||||
//config: you can reduce code size by unselecting this option.
|
||||
//config: To support less trivial ZIPs, say Y.
|
||||
//config: If you know that you only need to deal with simple
|
||||
//config: ZIP files without deleted/updated files, SFX archives etc,
|
||||
//config: you can reduce code size by unselecting this option.
|
||||
//config: To support less trivial ZIPs, say Y.
|
||||
//config:
|
||||
//config:config FEATURE_UNZIP_BZIP2
|
||||
//config: bool "Support compression method 12 (bzip2)"
|
||||
@@ -56,17 +56,14 @@
|
||||
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
//usage:#define unzip_trivial_usage
|
||||
//usage: "[-lnojpqK] FILE[.zip] [FILE]... [-x FILE]... [-d DIR]"
|
||||
//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
|
||||
//usage:#define unzip_full_usage "\n\n"
|
||||
//usage: "Extract FILEs from ZIP archive\n"
|
||||
//usage: "\n -l List contents (with -q for short form)"
|
||||
//usage: "\n -n Never overwrite files (default: ask)"
|
||||
//usage: "\n -o Overwrite"
|
||||
//usage: "\n -j Do not restore paths"
|
||||
//usage: "\n -p Write to stdout"
|
||||
//usage: "\n -t Test"
|
||||
//usage: "\n -p Print to stdout"
|
||||
//usage: "\n -q Quiet"
|
||||
//usage: "\n -K Do not clear SUID bit"
|
||||
//usage: "\n -x FILE Exclude FILEs"
|
||||
//usage: "\n -d DIR Extract into DIR"
|
||||
|
||||
@@ -84,13 +81,11 @@ enum {
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* CDF item */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* End of CDF */
|
||||
ZIP64_CDE_MAGIC = 0x504b0606, /* End of Zip64 CDF */
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
ZIP_CDF_MAGIC = 0x02014b50,
|
||||
ZIP_CDE_MAGIC = 0x06054b50,
|
||||
ZIP64_CDE_MAGIC = 0x06064b50,
|
||||
ZIP_DD_MAGIC = 0x08074b50,
|
||||
#endif
|
||||
};
|
||||
@@ -119,8 +114,6 @@ typedef union {
|
||||
#define FIX_ENDIANNESS_ZIP(zip) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(zip).fmt.method = SWAP_LE16((zip).fmt.method ); \
|
||||
(zip).fmt.modtime = SWAP_LE16((zip).fmt.modtime ); \
|
||||
(zip).fmt.moddate = SWAP_LE16((zip).fmt.moddate ); \
|
||||
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
|
||||
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
|
||||
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
|
||||
@@ -159,15 +152,15 @@ typedef union {
|
||||
#define FIX_ENDIANNESS_CDF(cdf) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed ); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len ); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
|
||||
(cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
|
||||
}} while (0)
|
||||
@@ -266,12 +259,6 @@ static uint32_t find_cdf_offset(void)
|
||||
continue;
|
||||
/* we found CDE! */
|
||||
memcpy(cde.raw, p + 1, CDE_LEN);
|
||||
dbg("cde.this_disk_no:%d", cde.fmt.this_disk_no );
|
||||
dbg("cde.disk_with_cdf_no:%d", cde.fmt.disk_with_cdf_no );
|
||||
dbg("cde.cdf_entries_on_this_disk:%d", cde.fmt.cdf_entries_on_this_disk);
|
||||
dbg("cde.cdf_entries_total:%d", cde.fmt.cdf_entries_total );
|
||||
dbg("cde.cdf_size:%d", cde.fmt.cdf_size );
|
||||
dbg("cde.cdf_offset:%x", cde.fmt.cdf_offset );
|
||||
FIX_ENDIANNESS_CDE(cde);
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
@@ -314,37 +301,23 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
|
||||
dbg("got ZIP_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
if (magic == ZIP64_CDE_MAGIC) { /* seen in .zip with >4GB files */
|
||||
dbg("got ZIP64_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
xread(zip_fd, cdf->raw, CDF_HEADER_LEN);
|
||||
|
||||
FIX_ENDIANNESS_CDF(*cdf);
|
||||
dbg(" magic:%08x filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
magic,
|
||||
dbg(" filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
(unsigned)cdf->fmt.filename_len,
|
||||
(unsigned)cdf->fmt.extra_len,
|
||||
(unsigned)cdf->fmt.file_comment_length
|
||||
);
|
||||
//TODO: require that magic == ZIP_CDF_MAGIC?
|
||||
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf->fmt.filename_len
|
||||
+ cdf->fmt.extra_len
|
||||
+ cdf->fmt.file_comment_length;
|
||||
|
||||
dbg("Next cdf_offset 0x%x", cdf_offset);
|
||||
return cdf_offset;
|
||||
};
|
||||
#endif
|
||||
|
||||
static void die_if_bad_fnamesize(unsigned sz)
|
||||
{
|
||||
if (sz > 0xfff) /* more than 4k?! no funny business please */
|
||||
bb_simple_error_msg_and_die("bad archive");
|
||||
}
|
||||
|
||||
static void unzip_skip(off_t skip)
|
||||
{
|
||||
if (skip != 0)
|
||||
@@ -356,50 +329,12 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
{
|
||||
/* Create all leading directories */
|
||||
char *name = xstrdup(fn);
|
||||
|
||||
/* mode of -1: set mode according to umask */
|
||||
if (bb_make_directory(dirname(name), -1, FILEUTILS_RECUR)) {
|
||||
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
|
||||
xfunc_die(); /* bb_make_directory is noisy */
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
static void unzip_extract_symlink(llist_t **symlink_placeholders,
|
||||
zip_header_t *zip,
|
||||
const char *dst_fn)
|
||||
{
|
||||
char *target;
|
||||
|
||||
die_if_bad_fnamesize(zip->fmt.ucmpsize);
|
||||
|
||||
if (zip->fmt.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
target = xzalloc(zip->fmt.ucmpsize + 1);
|
||||
xread(zip_fd, target, zip->fmt.ucmpsize);
|
||||
} else {
|
||||
#if 1
|
||||
bb_simple_error_msg_and_die("compressed symlink is not supported");
|
||||
#else
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.mem_output_size_max = zip->fmt.ucmpsize;
|
||||
/* ...unpack... */
|
||||
if (!xstate.mem_output_buf)
|
||||
WTF();
|
||||
target = xstate.mem_output_buf;
|
||||
target = xrealloc(target, xstate.mem_output_size + 1);
|
||||
target[xstate.mem_output_size] = '\0';
|
||||
#endif
|
||||
}
|
||||
create_or_remember_link(symlink_placeholders,
|
||||
target,
|
||||
dst_fn,
|
||||
0);
|
||||
free(target);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
{
|
||||
transformer_state_t xstate;
|
||||
@@ -419,10 +354,10 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
if (zip->fmt.method == 8) {
|
||||
/* Method 8 - inflate */
|
||||
if (inflate_unzip(&xstate) < 0)
|
||||
bb_simple_error_msg_and_die("inflate error");
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
bb_simple_error_msg_and_die("crc error");
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_UNZIP_BZIP2
|
||||
@@ -432,7 +367,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
*/
|
||||
xstate.bytes_out = unpack_bz2_stream(&xstate);
|
||||
if (xstate.bytes_out < 0)
|
||||
bb_simple_error_msg_and_die("inflate error");
|
||||
bb_error_msg_and_die("inflate error");
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_UNZIP_LZMA
|
||||
@@ -440,7 +375,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
/* Not tested yet */
|
||||
xstate.bytes_out = unpack_lzma_stream(&xstate);
|
||||
if (xstate.bytes_out < 0)
|
||||
bb_simple_error_msg_and_die("inflate error");
|
||||
bb_error_msg_and_die("inflate error");
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_UNZIP_XZ
|
||||
@@ -448,7 +383,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
/* Not tested yet */
|
||||
xstate.bytes_out = unpack_xz_stream(&xstate);
|
||||
if (xstate.bytes_out < 0)
|
||||
bb_simple_error_msg_and_die("inflate error");
|
||||
bb_error_msg_and_die("inflate error");
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
@@ -456,12 +391,10 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (zip->fmt.ucmpsize != 0xffffffff /* seen on files with >4GB uncompressed data */
|
||||
&& zip->fmt.ucmpsize != xstate.bytes_out
|
||||
) {
|
||||
if (zip->fmt.ucmpsize != xstate.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_simple_error_msg("bad length");
|
||||
bb_error_msg("bad length");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,39 +402,20 @@ static void my_fgets80(char *buf80)
|
||||
{
|
||||
fflush_all();
|
||||
if (!fgets(buf80, 80, stdin)) {
|
||||
bb_simple_perror_msg_and_die("can't read standard input");
|
||||
bb_perror_msg_and_die("can't read standard input");
|
||||
}
|
||||
}
|
||||
|
||||
static int get_lstat_mode(const char *dst_fn)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
if (lstat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'",
|
||||
dst_fn
|
||||
);
|
||||
}
|
||||
/* File does not exist */
|
||||
return -1;
|
||||
}
|
||||
return stat_buf.st_mode;
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
enum {
|
||||
OPT_l = (1 << 0),
|
||||
OPT_x = (1 << 1),
|
||||
OPT_j = (1 << 2),
|
||||
OPT_K = (1 << 3),
|
||||
};
|
||||
unsigned opts;
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
smallint quiet = 0;
|
||||
IF_NOT_FEATURE_UNZIP_CDF(const) smallint verbose = 0;
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
smallint x_opt_seen;
|
||||
uint32_t cdf_offset;
|
||||
unsigned long total_usize;
|
||||
unsigned long total_size;
|
||||
@@ -512,11 +426,9 @@ int unzip_main(int argc, char **argv)
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
llist_t *symlink_placeholders = NULL;
|
||||
#endif
|
||||
int i;
|
||||
int i, opt;
|
||||
char key_buf[80]; /* must match size used by my_fgets80 */
|
||||
struct stat stat_buf;
|
||||
|
||||
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
|
||||
*
|
||||
@@ -559,21 +471,16 @@ int unzip_main(int argc, char **argv)
|
||||
* 204372 1 file
|
||||
*/
|
||||
|
||||
//TODO: accept and ignore these?
|
||||
// -a convert to text files with 't' label, -aa: all files
|
||||
// -b do not convert to text - bbox: we don't convert anything
|
||||
// -D skip restoration of timestamps for extracted items - bbox: we don't restore these (yet?)
|
||||
// -X restore user:group ownership
|
||||
opts = 0;
|
||||
x_opt_seen = 0;
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((i = getopt(argc, argv, "-d:lnotpqxjvK")) != -1) {
|
||||
switch (i) {
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd': /* Extract to base directory */
|
||||
base_dir = optarg;
|
||||
break;
|
||||
|
||||
case 'l': /* List */
|
||||
opts |= OPT_l;
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
case 'n': /* Never overwrite existing files */
|
||||
@@ -584,14 +491,8 @@ int unzip_main(int argc, char **argv)
|
||||
overwrite = O_ALWAYS;
|
||||
break;
|
||||
|
||||
case 't': /* Extract files to /dev/null */
|
||||
xmove_fd(xopen("/dev/null", O_WRONLY), STDOUT_FILENO);
|
||||
/*fallthrough*/
|
||||
|
||||
// NB: -c extract files to stdout/screen (unlike -p, also prints .zip and file names to stdout)
|
||||
case 'p': /* Extract files to stdout */
|
||||
case 'p': /* Extract files to stdout and fall through to set verbosity */
|
||||
dst_fd = STDOUT_FILENO;
|
||||
/*fallthrough*/
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
quiet++;
|
||||
@@ -599,19 +500,11 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
case 'v': /* Verbose list */
|
||||
IF_FEATURE_UNZIP_CDF(verbose++;)
|
||||
opts |= OPT_l;
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
opts |= OPT_x;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
opts |= OPT_j;
|
||||
break;
|
||||
|
||||
case 'K':
|
||||
opts |= OPT_K;
|
||||
x_opt_seen = 1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
@@ -620,7 +513,7 @@ int unzip_main(int argc, char **argv)
|
||||
/* +5: space for ".zip" and NUL */
|
||||
src_fn = xmalloc(strlen(optarg) + 5);
|
||||
strcpy(src_fn, optarg);
|
||||
} else if (!(opts & OPT_x)) {
|
||||
} else if (!x_opt_seen) {
|
||||
/* Include files */
|
||||
llist_add_to(&zaccept, optarg);
|
||||
} else {
|
||||
@@ -674,9 +567,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
if (++i > 2) {
|
||||
*ext = '\0';
|
||||
bb_error_msg_and_die("can't open %s[.zip]",
|
||||
src_fn
|
||||
);
|
||||
bb_error_msg_and_die("can't open %s[.zip]", src_fn);
|
||||
}
|
||||
strcpy(ext, extn[i - 1]);
|
||||
}
|
||||
@@ -684,22 +575,13 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Change dir if necessary */
|
||||
if (base_dir) {
|
||||
/* -p DIR: try to create, errors don't matter.
|
||||
* UnZip 6.00 does no multi-level mkdir (-p DIR1/DIR2 syntax),
|
||||
* not using bb_make_directory() here (yet?)
|
||||
*/
|
||||
mkdir(base_dir, 0777);
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
}
|
||||
|
||||
if (quiet <= 1) { /* not -qq */
|
||||
if (quiet == 0) {
|
||||
printf("Archive: %s\n",
|
||||
printable_string(src_fn)
|
||||
);
|
||||
}
|
||||
if (opts & OPT_l) {
|
||||
if (quiet == 0)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing) {
|
||||
puts(verbose ?
|
||||
" Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
"-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
@@ -804,20 +686,6 @@ int unzip_main(int argc, char **argv)
|
||||
zip.fmt.cmpsize = cdf.fmt.cmpsize;
|
||||
zip.fmt.ucmpsize = cdf.fmt.ucmpsize;
|
||||
}
|
||||
// Seen in some zipfiles: central directory 9 byte extra field contains
|
||||
// a subfield with ID 0x5455 and 5 data bytes, which is a Unix-style UTC mtime.
|
||||
// Local header version:
|
||||
// u16 0x5455 ("UT")
|
||||
// u16 size (1 + 4 * n)
|
||||
// u8 flags: bit 0:mtime is present, bit 1:atime is present, bit 2:ctime is present
|
||||
// u32 mtime
|
||||
// u32 atime
|
||||
// u32 ctime
|
||||
// Central header version:
|
||||
// u16 0x5455 ("UT")
|
||||
// u16 size (5 (or 1?))
|
||||
// u8 flags: bit 0:mtime is present, bit 1:atime is present, bit 2:ctime is present
|
||||
// u32 mtime (CDF does not store atime/ctime)
|
||||
# else
|
||||
/* CDF has the same data as local header, no need to read the latter...
|
||||
* ...not really. An archive was seen with cdf.extra_len == 6 but
|
||||
@@ -831,10 +699,7 @@ int unzip_main(int argc, char **argv)
|
||||
# endif
|
||||
if ((cdf.fmt.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
file_mode = (cdf.fmt.external_attributes >> 16);
|
||||
if (!(opts & OPT_K))
|
||||
file_mode &= ~(mode_t)(S_ISUID | S_ISGID);
|
||||
dir_mode = file_mode;
|
||||
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -852,15 +717,14 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
die_if_bad_fnamesize(zip.fmt.filename_len);
|
||||
dst_fn = xzalloc(zip.fmt.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip.fmt.filename_len);
|
||||
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip.fmt.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
// NB: UnZip 6.00 has option -: to disable this
|
||||
strip_unsafe_prefix(dst_fn);
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
@@ -869,7 +733,7 @@ int unzip_main(int argc, char **argv)
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
|
||||
if (opts & OPT_l) {
|
||||
if (listing) {
|
||||
/* List entry */
|
||||
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
|
||||
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
|
||||
@@ -886,8 +750,7 @@ int unzip_main(int argc, char **argv)
|
||||
printf( "%9u " "%s " "%s\n",
|
||||
(unsigned)zip.fmt.ucmpsize,
|
||||
dtbuf,
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
dst_fn);
|
||||
} else {
|
||||
char method6[7];
|
||||
unsigned long percents;
|
||||
@@ -916,8 +779,7 @@ int unzip_main(int argc, char **argv)
|
||||
(unsigned)percents,
|
||||
dtbuf,
|
||||
zip.fmt.crc32,
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
dst_fn);
|
||||
total_size += zip.fmt.cmpsize;
|
||||
}
|
||||
total_usize += zip.fmt.ucmpsize;
|
||||
@@ -928,69 +790,51 @@ int unzip_main(int argc, char **argv)
|
||||
/* Extracting to STDOUT */
|
||||
goto do_extract;
|
||||
}
|
||||
|
||||
/* Strip paths (after -l: unzip -lj a.zip lists full names) */
|
||||
if (opts & OPT_j)
|
||||
overlapping_strcpy(dst_fn, bb_basename(dst_fn));
|
||||
/* Did this strip everything ("DIR/" case)? Then skip */
|
||||
if (!dst_fn[0])
|
||||
goto skip_cmpsize;
|
||||
|
||||
if (last_char_is(dst_fn, '/')) {
|
||||
int mode;
|
||||
|
||||
/* Extract directory */
|
||||
mode = get_lstat_mode(dst_fn);
|
||||
if (mode == -1) { /* ENOENT */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
if (!quiet) {
|
||||
printf(" creating: %s\n", printable_string(dst_fn));
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
|
||||
xfunc_die();
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(mode)) {
|
||||
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
printable_string(dst_fn),
|
||||
"directory"
|
||||
);
|
||||
dst_fn, "directory");
|
||||
}
|
||||
}
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
check_file:
|
||||
/* Does target file already exist? */
|
||||
{
|
||||
int mode = get_lstat_mode(dst_fn);
|
||||
if (mode == -1) {
|
||||
/* ENOENT: does not exist */
|
||||
goto do_open_and_extract;
|
||||
/* Extract file */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
/* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
if (overwrite == O_NEVER) {
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
if (!S_ISREG(mode)) {
|
||||
fishy:
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
printable_string(dst_fn),
|
||||
"regular file"
|
||||
);
|
||||
}
|
||||
if (overwrite == O_ALWAYS) {
|
||||
goto do_open_and_extract;
|
||||
}
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ",
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
my_fgets80(key_buf);
|
||||
/* User input could take a long time. Is it still a regular file? */
|
||||
mode = get_lstat_mode(dst_fn);
|
||||
if (!S_ISREG(mode))
|
||||
goto fishy;
|
||||
goto do_open_and_extract;
|
||||
}
|
||||
/* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
goto skip_cmpsize;
|
||||
}
|
||||
if (!S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "regular file");
|
||||
}
|
||||
/* File is regular file */
|
||||
if (overwrite == O_ALWAYS)
|
||||
goto do_open_and_extract;
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
my_fgets80(key_buf);
|
||||
|
||||
/* Extract (or skip) it */
|
||||
switch (key_buf[0]) {
|
||||
case 'A':
|
||||
overwrite = O_ALWAYS;
|
||||
@@ -998,36 +842,20 @@ int unzip_main(int argc, char **argv)
|
||||
do_open_and_extract:
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
dst_fd = -1;
|
||||
if (!S_ISLNK(file_mode)) {
|
||||
dst_fd = xopen3(dst_fn,
|
||||
O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW,
|
||||
file_mode);
|
||||
}
|
||||
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
|
||||
#else
|
||||
/* O_NOFOLLOW defends against symlink attacks */
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW);
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
#endif
|
||||
do_extract:
|
||||
if (!quiet) {
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
: */ " inflating: %s\n",
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
: */ " inflating: %s\n", dst_fn);
|
||||
}
|
||||
do_extract:
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
if (S_ISLNK(file_mode)) {
|
||||
if (dst_fd != STDOUT_FILENO) /* not -p? */
|
||||
unzip_extract_symlink(&symlink_placeholders, &zip, dst_fn);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
unzip_extract(&zip, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
}
|
||||
unzip_extract(&zip, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1055,11 +883,7 @@ int unzip_main(int argc, char **argv)
|
||||
total_entries++;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
create_links_from_list(symlink_placeholders);
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_l) && quiet <= 1) {
|
||||
if (listing && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// "--------- ---------- ----- ----"
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/* Add SORT_BY_ALIGNMENT to linker script (found in busybox_unstripped.out):
|
||||
## .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
|
||||
## .data : { *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) }
|
||||
## .bss : { *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) }
|
||||
## This will eliminate most of the padding (~3kb).
|
||||
## Hmm, "ld --sort-section alignment" should do it too.
|
||||
##
|
||||
## There is a ld hack which is meant to decrease disk usage
|
||||
## at the cost of more RAM usage (??!!) in standard ld script:
|
||||
## . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
|
||||
## Replace it with:
|
||||
## . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
|
||||
## to unconditionally align .data to the next page boundary,
|
||||
## instead of "next page, plus current offset in this page"
|
||||
*/
|
||||
|
||||
/* To reduce the number of VMAs each bbox process has,
|
||||
## move *(.bss SORT_BY_ALIGNMENT(.bss.*) ...)
|
||||
## part from .bss : {...} block to .data : { ... } block.
|
||||
## (This usually increases .data section by only one page).
|
||||
## Result:
|
||||
##
|
||||
## text data bss dec hex filename
|
||||
## 1050792 560 7580 1058932 102874 busybox.bss
|
||||
## 1050792 8149 0 1058941 10287d busybox.nobss
|
||||
##
|
||||
## $ exec busybox.bss pmap $$
|
||||
## 0000000008048000 1028K r-xp /path/to/busybox.bss
|
||||
## 0000000008149000 8K rw-p /path/to/busybox.bss
|
||||
## 000000000814b000 4K rw-p [ anon ] <---- this VMA is eliminated
|
||||
## 00000000085f5000 4K ---p [heap]
|
||||
## 00000000085f6000 4K rw-p [heap]
|
||||
## 00000000f7778000 8K rw-p [ anon ]
|
||||
## 00000000f777a000 12K r--p [vvar]
|
||||
## 00000000f777d000 8K r-xp [vdso]
|
||||
## 00000000ff7e9000 132K rw-p [stack]
|
||||
##
|
||||
## $ exec busybox.nobss pmap $$
|
||||
## 0000000008048000 1028K r-xp /path/to/busybox.nobss
|
||||
## 0000000008149000 12K rw-p /path/to/busybox.nobss
|
||||
## 00000000086f0000 4K ---p [heap]
|
||||
## 00000000086f1000 4K rw-p [heap]
|
||||
## 00000000f7783000 8K rw-p [ anon ]
|
||||
## 00000000f7785000 12K r--p [vvar]
|
||||
## 00000000f7788000 8K r-xp [vdso]
|
||||
## 00000000ffac0000 132K rw-p [stack]
|
||||
*/
|
||||
@@ -37,6 +37,7 @@ 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
|
||||
@@ -703,7 +704,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
|
||||
@@ -891,6 +891,7 @@ CONFIG_HUSH_FUNCTIONS=y
|
||||
CONFIG_HUSH_LOCAL=y
|
||||
CONFIG_HUSH_EXPORT_N=y
|
||||
CONFIG_HUSH_RANDOM_SUPPORT=y
|
||||
CONFIG_MSH=y
|
||||
CONFIG_SH_MATH_SUPPORT=y
|
||||
CONFIG_SH_MATH_SUPPORT_64=y
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
|
||||
@@ -47,6 +47,7 @@ CONFIG_FEATURE_PIDFILE=y
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
# CONFIG_FEATURE_SYSLOG is not set
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -897,6 +898,7 @@ CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_FEATURE_BASH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_BASH_IS_HUSH is not set
|
||||
CONFIG_FEATURE_BASH_IS_NONE=y
|
||||
# CONFIG_MSH is not set
|
||||
# CONFIG_SH_MATH_SUPPORT is not set
|
||||
# CONFIG_SH_MATH_SUPPORT_64 is not set
|
||||
# CONFIG_FEATURE_SH_EXTRA_QUIET is not set
|
||||
|
||||
@@ -46,6 +46,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
CONFIG_FEATURE_HAVE_RPC=y
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -904,6 +905,7 @@ CONFIG_HUSH_FUNCTIONS=y
|
||||
CONFIG_HUSH_LOCAL=y
|
||||
CONFIG_HUSH_EXPORT_N=y
|
||||
CONFIG_HUSH_RANDOM_SUPPORT=y
|
||||
CONFIG_MSH=y
|
||||
CONFIG_SH_MATH_SUPPORT=y
|
||||
CONFIG_SH_MATH_SUPPORT_64=y
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
|
||||
@@ -16,6 +16,7 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
# CONFIG_INCLUDE_SUSv2 is not set
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_PLATFORM_LINUX=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -48,6 +49,7 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -950,6 +952,7 @@ CONFIG_CTTYHACK=y
|
||||
# CONFIG_HUSH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_HUSH_EXPORT_N is not set
|
||||
# CONFIG_HUSH_MODE_X is not set
|
||||
# CONFIG_MSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
## Assorted header problems:
|
||||
## # CONFIG_HOSTID is not set
|
||||
## # CONFIG_FEATURE_SYNC_FANCY is not set - syncfs()
|
||||
## # CONFIG_FEATURE_TOUCH_NODEREF is not set - lutimes()
|
||||
## # CONFIG_LOGNAME is not set - getlogin_r()
|
||||
## # CONFIG_LOADFONT is not set
|
||||
## # CONFIG_SETFONT is not set
|
||||
@@ -86,6 +87,7 @@ CONFIG_DESKTOP=y
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_PLATFORM_LINUX=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -121,6 +123,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -268,6 +271,7 @@ CONFIG_SYNC=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
@@ -1094,6 +1098,7 @@ CONFIG_CTTYHACK=y
|
||||
# CONFIG_HUSH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_HUSH_EXPORT_N is not set
|
||||
# CONFIG_HUSH_MODE_X is not set
|
||||
# CONFIG_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_ASH=y
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_NONE is not set
|
||||
|
||||
@@ -16,6 +16,7 @@ CONFIG_DESKTOP=y
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
# CONFIG_INCLUDE_SUSv2 is not set
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_PLATFORM_LINUX=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -48,6 +49,7 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -982,6 +984,7 @@ CONFIG_CTTYHACK=y
|
||||
# CONFIG_HUSH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_HUSH_EXPORT_N is not set
|
||||
# CONFIG_HUSH_MODE_X is not set
|
||||
# CONFIG_MSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
|
||||
@@ -16,6 +16,7 @@ CONFIG_DESKTOP=y
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
# CONFIG_INCLUDE_SUSv2 is not set
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_PLATFORM_LINUX=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -51,6 +52,7 @@ CONFIG_PID_FILE_PATH=""
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -193,6 +195,7 @@ CONFIG_SYNC=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
@@ -1010,6 +1013,7 @@ CONFIG_CTTYHACK=y
|
||||
# CONFIG_HUSH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_HUSH_EXPORT_N is not set
|
||||
# CONFIG_HUSH_MODE_X is not set
|
||||
# CONFIG_MSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
|
||||
+369
-604
File diff suppressed because it is too large.
Load diff
@@ -16,6 +16,7 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
CONFIG_USE_PORTABLE_CODE=y
|
||||
# CONFIG_PLATFORM_LINUX 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
|
||||
@@ -48,6 +49,7 @@ CONFIG_FEATURE_SUID_CONFIG_QUIET=y
|
||||
# CONFIG_FEATURE_PREFER_APPLETS is not set
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
|
||||
#
|
||||
# Build Options
|
||||
@@ -929,6 +931,7 @@ CONFIG_ASH=y
|
||||
# CONFIG_HUSH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_HUSH_EXPORT_N is not set
|
||||
# CONFIG_HUSH_MODE_X is not set
|
||||
# CONFIG_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_ASH=y
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_NONE is not set
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Console Utilities"
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CHVT
|
||||
//config: bool "chvt (2.2 kb)"
|
||||
//config: bool "chvt"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program is used to change to another terminal.
|
||||
//config: Example: chvt 4 (change to terminal /dev/tty4)
|
||||
//config: This program is used to change to another terminal.
|
||||
//config: Example: chvt 4 (change to terminal /dev/tty4)
|
||||
|
||||
//applet:IF_CHVT(APPLET_NOEXEC(chvt, chvt, BB_DIR_USR_BIN, BB_SUID_DROP, chvt))
|
||||
//applet:IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_CHVT) += chvt.o
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CLEAR
|
||||
//config: bool "clear (371 bytes)"
|
||||
//config: bool "clear"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: This program clears the terminal screen.
|
||||
//config: This program clears the terminal screen.
|
||||
|
||||
//applet:IF_CLEAR(APPLET_NOFORK(clear, clear, BB_DIR_USR_BIN, BB_SUID_DROP, clear))
|
||||
//applet:IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_CLEAR) += clear.o
|
||||
|
||||
@@ -23,11 +23,9 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define ESC "\033"
|
||||
|
||||
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
/* home; clear to the end of screen */
|
||||
return full_write1_str(ESC"[H" ESC"[J") != 6;
|
||||
return full_write1_str("\033[H""\033[J") != 6;
|
||||
}
|
||||
@@ -8,12 +8,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DEALLOCVT
|
||||
//config: bool "deallocvt (2.2 kb)"
|
||||
//config: bool "deallocvt"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program deallocates unused virtual consoles.
|
||||
//config: This program deallocates unused virtual consoles.
|
||||
|
||||
//applet:IF_DEALLOCVT(APPLET_NOEXEC(deallocvt, deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP, deallocvt))
|
||||
//applet:IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
*/
|
||||
//config:config DUMPKMAP
|
||||
//config: bool "dumpkmap (1.9 kb)"
|
||||
//config: bool "dumpkmap"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program dumps the kernel's keyboard translation table to
|
||||
//config: stdout, in binary format. You can then use loadkmap to load it.
|
||||
//config: This program dumps the kernel's keyboard translation table to
|
||||
//config: stdout, in binary format. You can then use loadkmap to load it.
|
||||
|
||||
//applet:IF_DUMPKMAP(APPLET_NOEXEC(dumpkmap, dumpkmap, BB_DIR_BIN, BB_SUID_DROP, dumpkmap))
|
||||
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
|
||||
//applet:IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
|
||||
@@ -46,6 +47,8 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
#define flags bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
|
||||
/* When user accidentally runs "dumpkmap FILE"
|
||||
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
||||
@@ -57,8 +60,19 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
#define flags bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
#if 0
|
||||
write(STDOUT_FILENO, "bkeymap", 7);
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12]
|
||||
*/
|
||||
/*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */
|
||||
memset(flags, 0x01, 13);
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
/* dump flags */
|
||||
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
#define flags7 flags
|
||||
#else
|
||||
/* Same effect */
|
||||
/* 0 1 2 3 4 5 6 7 8 9 a b c=12 */
|
||||
memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1",
|
||||
/* Can use sizeof, or sizeof-1. sizeof is even, using that */
|
||||
@@ -66,6 +80,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
);
|
||||
write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS);
|
||||
#define flags7 (flags + 7)
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 13; i++) {
|
||||
if (flags7[i]) {
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config FGCONSOLE
|
||||
//config: bool "fgconsole (1.8 kb)"
|
||||
//config: bool "fgconsole"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program prints active (foreground) console number.
|
||||
//config: This program prints active (foreground) console number.
|
||||
|
||||
//applet:IF_FGCONSOLE(APPLET_NOEXEC(fgconsole, fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP, fgconsole))
|
||||
//applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
|
||||
|
||||
|
||||
+11
-29
@@ -9,24 +9,25 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config KBD_MODE
|
||||
//config: bool "kbd_mode (4.3 kb)"
|
||||
//config: bool "kbd_mode"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program reports and sets keyboard mode.
|
||||
//config: This program reports and sets keyboard mode.
|
||||
|
||||
//applet:IF_KBD_MODE(APPLET_NOEXEC(kbd_mode, kbd_mode, BB_DIR_BIN, BB_SUID_DROP, kbd_mode))
|
||||
//applet:IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_KBD_MODE) += kbd_mode.o
|
||||
|
||||
//usage:#define kbd_mode_trivial_usage
|
||||
//usage: "[-a|k|s|u] [-C TTY]"
|
||||
//usage:#define kbd_mode_full_usage "\n\n"
|
||||
//usage: "Report or set VT console keyboard mode\n"
|
||||
//usage: "Report or set the keyboard mode\n"
|
||||
//usage: "\n -a Default (ASCII)"
|
||||
//usage: "\n -k Medium-raw (keycode)"
|
||||
//usage: "\n -k Medium-raw (keyboard)"
|
||||
//usage: "\n -s Raw (scancode)"
|
||||
//usage: "\n -u Unicode (utf-8)"
|
||||
//usage: "\n -C TTY Affect TTY"
|
||||
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
|
||||
#include "libbb.h"
|
||||
#include <linux/kd.h>
|
||||
@@ -42,20 +43,11 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
|
||||
};
|
||||
int fd;
|
||||
unsigned opt;
|
||||
const char *tty_name;
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
|
||||
opt = getopt32(argv, "sakuC:", &tty_name);
|
||||
if (opt & 0x10) {
|
||||
opt &= 0xf; /* clear -C bit, see (*) */
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
} else {
|
||||
/* kbd-2.0.3 tries in sequence:
|
||||
* fd#0, /dev/tty, /dev/tty0.
|
||||
* get_console_fd_or_die: /dev/console, /dev/tty0, /dev/tty.
|
||||
* kbd-2.0.3 checks KDGKBTYPE, get_console_fd_or_die checks too.
|
||||
*/
|
||||
fd = get_console_fd_or_die();
|
||||
}
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
opt &= 0xf; /* clear -C bit, see (*) */
|
||||
|
||||
if (!opt) { /* print current setting */
|
||||
const char *mode = "unknown";
|
||||
@@ -70,19 +62,9 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
|
||||
mode = "mediumraw (keycode)";
|
||||
else if (m == K_UNICODE)
|
||||
mode = "Unicode (UTF-8)";
|
||||
else if (m == 4 /*K_OFF*/) /* kbd-2.0.3 does not show this mode, says "unknown" */
|
||||
mode = "off";
|
||||
printf("The keyboard is in %s mode\n", mode);
|
||||
} else {
|
||||
/* here we depend on specific bits assigned to options (*)
|
||||
* KDSKBMODE constants have these values:
|
||||
* #define K_RAW 0x00
|
||||
* #define K_XLATE 0x01
|
||||
* #define K_MEDIUMRAW 0x02
|
||||
* #define K_UNICODE 0x03
|
||||
* #define K_OFF 0x04
|
||||
* (looks like "-ak" together would cause the same effect as -u)
|
||||
*/
|
||||
/* here we depend on specific bits assigned to options (*) */
|
||||
opt = opt & UNICODE ? 3 : opt >> 1;
|
||||
/* double cast prevents warnings about widening conversion */
|
||||
xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
|
||||
|
||||
+52
-44
@@ -10,31 +10,33 @@
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config LOADFONT
|
||||
//config: bool "loadfont (5.4 kb)"
|
||||
//config: bool "loadfont"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program loads a console font from standard input.
|
||||
//config: This program loads a console font from standard input.
|
||||
//config:
|
||||
//config:config SETFONT
|
||||
//config: bool "setfont (24 kb)"
|
||||
//config: bool "setfont"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Allows to load console screen map. Useful for i18n.
|
||||
//config: Allows to load console screen map. Useful for i18n.
|
||||
//config:
|
||||
//config:config FEATURE_SETFONT_TEXTUAL_MAP
|
||||
//config: bool "Support reading textual screen maps"
|
||||
//config: default y
|
||||
//config: depends on SETFONT
|
||||
//config: help
|
||||
//config: Support reading textual screen maps.
|
||||
//config: Support reading textual screen maps.
|
||||
//config:
|
||||
//config:config DEFAULT_SETFONT_DIR
|
||||
//config: string "Default directory for console-tools files"
|
||||
//config: default ""
|
||||
//config: depends on SETFONT
|
||||
//config: help
|
||||
//config: Directory to use if setfont's params are simple filenames
|
||||
//config: (not /path/to/file or ./file). Default is "" (no default directory).
|
||||
//config: Directory to use if setfont's params are simple filenames
|
||||
//config: (not /path/to/file or ./file). Default is "" (no default directory).
|
||||
//config:
|
||||
//config:comment "Common options for loadfont and setfont"
|
||||
//config: depends on LOADFONT || SETFONT
|
||||
@@ -49,12 +51,31 @@
|
||||
//config: default y
|
||||
//config: depends on LOADFONT || SETFONT
|
||||
|
||||
//applet:IF_LOADFONT(APPLET_NOEXEC(loadfont, loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP, loadfont))
|
||||
//applet:IF_SETFONT(APPLET_NOEXEC(setfont, setfont, BB_DIR_USR_SBIN, BB_SUID_DROP, setfont))
|
||||
//applet:IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
//applet:IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_LOADFONT) += loadfont.o
|
||||
//kbuild:lib-$(CONFIG_SETFONT) += loadfont.o
|
||||
|
||||
//usage:#define loadfont_trivial_usage
|
||||
//usage: "< font"
|
||||
//usage:#define loadfont_full_usage "\n\n"
|
||||
//usage: "Load a console font from stdin"
|
||||
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
||||
//usage:
|
||||
//usage:#define loadfont_example_usage
|
||||
//usage: "$ loadfont < /etc/i18n/fontname\n"
|
||||
//usage:
|
||||
//usage:#define setfont_trivial_usage
|
||||
//usage: "FONT [-m MAPFILE] [-C TTY]"
|
||||
//usage:#define setfont_full_usage "\n\n"
|
||||
//usage: "Load a console font\n"
|
||||
//usage: "\n -m MAPFILE Load console screen map"
|
||||
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
//usage:
|
||||
//usage:#define setfont_example_usage
|
||||
//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include <sys/kd.h>
|
||||
|
||||
@@ -223,7 +244,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
|
||||
if (unicode == PSF2_SEPARATOR) {
|
||||
break;
|
||||
} else if (unicode == PSF2_STARTSEQ) {
|
||||
bb_simple_error_msg_and_die("unicode sequences not implemented");
|
||||
bb_error_msg_and_die("unicode sequences not implemented");
|
||||
} else if (unicode >= 0xC0) {
|
||||
if (unicode >= 0xFC)
|
||||
unicode &= 0x01, maxct = 5;
|
||||
@@ -237,12 +258,12 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
|
||||
unicode &= 0x1F, maxct = 1;
|
||||
do {
|
||||
if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
|
||||
bb_simple_error_msg_and_die("illegal UTF-8 character");
|
||||
bb_error_msg_and_die("illegal UTF-8 character");
|
||||
--tailsz;
|
||||
unicode = (unicode << 6) + (*inbuf++ & 0x3F);
|
||||
} while (--maxct > 0);
|
||||
} else if (unicode >= 0x80) {
|
||||
bb_simple_error_msg_and_die("illegal UTF-8 character");
|
||||
bb_error_msg_and_die("illegal UTF-8 character");
|
||||
}
|
||||
#else
|
||||
return;
|
||||
@@ -279,7 +300,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
|
||||
|
||||
if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
|
||||
if (psf1h(buffer)->mode > PSF1_MAXMODE)
|
||||
bb_simple_error_msg_and_die("unsupported psf file mode");
|
||||
bb_error_msg_and_die("unsupported psf file mode");
|
||||
if (psf1h(buffer)->mode & PSF1_MODE512)
|
||||
fontsize = 512;
|
||||
if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
|
||||
@@ -290,7 +311,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
|
||||
#if ENABLE_FEATURE_LOADFONT_PSF2
|
||||
if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
|
||||
if (psf2h(buffer)->version > PSF2_MAXVERSION)
|
||||
bb_simple_error_msg_and_die("unsupported psf file version");
|
||||
bb_error_msg_and_die("unsupported psf file version");
|
||||
fontsize = psf2h(buffer)->length;
|
||||
if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
|
||||
has_table = 2;
|
||||
@@ -309,19 +330,19 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
bb_simple_error_msg_and_die("input file: bad length or unsupported font type");
|
||||
bb_error_msg_and_die("input file: bad length or unsupported font type");
|
||||
}
|
||||
|
||||
#if !defined(PIO_FONTX) || defined(__sparc__)
|
||||
if (fontsize != 256)
|
||||
bb_simple_error_msg_and_die("only fontsize 256 supported");
|
||||
bb_error_msg_and_die("only fontsize 256 supported");
|
||||
#endif
|
||||
|
||||
table = font + fontsize * charsize;
|
||||
buffer += len;
|
||||
|
||||
if (table > buffer || (!has_table && table != buffer))
|
||||
bb_simple_error_msg_and_die("input file: bad length");
|
||||
bb_error_msg_and_die("input file: bad length");
|
||||
|
||||
do_loadfont(fd, font, height, width, charsize, fontsize);
|
||||
|
||||
@@ -331,14 +352,6 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
|
||||
|
||||
|
||||
#if ENABLE_LOADFONT
|
||||
//usage:#define loadfont_trivial_usage
|
||||
//usage: "< font"
|
||||
//usage:#define loadfont_full_usage "\n\n"
|
||||
//usage: "Load a console font from stdin"
|
||||
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
||||
//usage:
|
||||
//usage:#define loadfont_example_usage
|
||||
//usage: "$ loadfont < /etc/i18n/fontname\n"
|
||||
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -346,7 +359,8 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned char *buffer;
|
||||
|
||||
// no arguments allowed!
|
||||
getopt32(argv, "^" "" "\0" "=0");
|
||||
opt_complementary = "=0";
|
||||
getopt32(argv, "");
|
||||
|
||||
/*
|
||||
* We used to look at the length of the input file
|
||||
@@ -359,16 +373,18 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
buffer = xmalloc_read(STDIN_FILENO, &len);
|
||||
// xmalloc_open_zipped_read_close(filename, &len);
|
||||
if (!buffer)
|
||||
bb_simple_perror_msg_and_die("error reading input font");
|
||||
bb_perror_msg_and_die("error reading input font");
|
||||
do_load(get_console_fd_or_die(), buffer, len);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_SETFONT
|
||||
/* kbd-1.12:
|
||||
|
||||
/*
|
||||
kbd-1.12:
|
||||
|
||||
setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
|
||||
[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
|
||||
[-hNN] [-v] [-V]
|
||||
@@ -398,17 +414,8 @@ setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
|
||||
-v Verbose
|
||||
-V Version
|
||||
*/
|
||||
//usage:#define setfont_trivial_usage
|
||||
//usage: "[-m MAPFILE] [-C TTY] FILE"
|
||||
//usage:#define setfont_full_usage "\n\n"
|
||||
//usage: "Load a console font\n"
|
||||
//usage: "\n -m MAPFILE Load console screen map"
|
||||
//usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
//usage:
|
||||
//usage:#define setfont_example_usage
|
||||
//usage: "$ setfont -m koi8-r /etc/i18n/fontname\n"
|
||||
|
||||
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
static int ctoi(char *s)
|
||||
{
|
||||
if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
|
||||
@@ -422,7 +429,7 @@ static int ctoi(char *s)
|
||||
return -1;
|
||||
return xstrtoul(s, 0);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
@@ -434,7 +441,8 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *mapfilename;
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
|
||||
opts = getopt32(argv, "^" "m:C:" "\0" "=1", &mapfilename, &tty_name);
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
|
||||
argv += optind;
|
||||
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
@@ -472,7 +480,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (len == 2*E_TABSZ)
|
||||
mode = PIO_UNISCRNMAP;
|
||||
}
|
||||
# if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
// assume textual Unicode console maps:
|
||||
// 0x00 U+0000 # NULL (NUL)
|
||||
// 0x01 U+0001 # START OF HEADING (SOH)
|
||||
@@ -500,7 +508,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (a < 0 || a >= E_TABSZ
|
||||
|| b < 0 || b > 65535
|
||||
) {
|
||||
bb_simple_error_msg_and_die("map format");
|
||||
bb_error_msg_and_die("map format");
|
||||
}
|
||||
// patch map
|
||||
unicodes[a] = b;
|
||||
@@ -519,7 +527,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#undef unicodes
|
||||
}
|
||||
# endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
|
||||
// do set screen map
|
||||
xioctl(fd, mode, map);
|
||||
|
||||
Loaded 100 of 1914 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user