Compare commits

..
1306 changed files with 51605 additions and 106251 deletions

No files matched your search

-34
View File
@@ -1,34 +0,0 @@
#
# Kbuild ignores
#
.*
*.o
*.o.*
*.a
*.s
#
# Never ignore these
#
!.gitignore
#
# Normal output
#
/busybox
/busybox_unstripped*
#
# Backups / patches
#
*~
*.orig
*.rej
/*.patch
#
# debugging stuff
#
core
.gdb_history
.gdbinit
+1 -4
View File
@@ -166,11 +166,8 @@ Paul Fox <pgf@foxharp.boston.ma.us>
Roberto A. Foglietta <me@roberto.foglietta.name>
port: dnsd
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Bernhard Fischer <rep.nop@aon.at>
misc
Mike Frysinger <vapier@gentoo.org>
initial e2fsprogs, printenv, setarch, sum, misc
Jie Zhang <jie.zhang@analog.com>
fixed two bugs in msh and hush (exitcode of killed processes)
+94 -164
View File
@@ -13,6 +13,22 @@ menu "Busybox Settings"
menu "General Configuration"
config NITPICK
bool "See lots more (probably unnecessary) configuration options."
default n
help
Some BusyBox applets have more configuration options than anyone
will ever care about. To avoid drowining people in complexity, most
of the applet features that can be set to a sane default value are
hidden, unless you hit the above switch.
This is better than to telling people to edit the busybox source
code, but not by much.
See http://en.wikipedia.org/wiki/Fibber_McGee_and_Molly#The_Closet
You have been warned.
config DESKTOP
bool "Enable options for full-blown desktop systems"
default n
@@ -21,40 +37,15 @@ config DESKTOP
Select this only if you plan to use busybox on full-blown
desktop machine with common Linux distro, not on an embedded box.
config EXTRA_COMPAT
bool "Provide compatible behavior for rare corner cases (bigger code)"
default n
help
This option makes grep, sed etc handle rare corner cases
(embedded NUL bytes and such). This makes code bigger and uses
some GNU extensions in libc. You probably only need this option
if you plan to run busybox on desktop.
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3"
default y
help
This option will enable backwards compatibility with SuSv2,
specifically, old-style numeric options ('command -1 <file>')
will be supported in head, tail, and fold. (Note: should
affect renice too.)
config USE_PORTABLE_CODE
bool "Avoid using GCC-specific code constructs"
default n
help
Use this option if you are trying to compile busybox with
compiler other than gcc.
If you do use gcc, this option may needlessly increase code size.
choice
prompt "Buffer allocation policy"
default FEATURE_BUFFERS_USE_MALLOC
depends on NITPICK
help
There are 3 ways BusyBox can handle buffer allocations:
- Use malloc. This costs code size for the call to xmalloc.
- Put them on stack. For some very small machines with limited stack
space, this can be deadly. For most folks, this works just fine.
space, this can be deadly. For most folks, this works just fine.
- Put them in BSS. This works beautifully for computers with a real
MMU (and OS support), but wastes runtime RAM for uCLinux. This
behavior was the only one available for BusyBox versions 0.48 and
@@ -86,8 +77,8 @@ config FEATURE_VERBOSE_USAGE
select SHOW_USAGE
help
All BusyBox applets will show more verbose help messages when
busybox is invoked with --help. This will add a lot of text to the
busybox binary. In the default configuration, this will add about
busybox is invoked with --help. This will add a lot of text to the
busybox binary. In the default configuration, this will add about
13k, but it can add much more depending on your configuration.
config FEATURE_COMPRESS_USAGE
@@ -100,15 +91,15 @@ config FEATURE_COMPRESS_USAGE
If you have a really tiny busybox with few applets enabled (and
bunzip2 isn't one of them), the overhead of the decompressor might
be noticeable. Also, if you run executables directly from ROM
and have very little memory, this might not be a win. Otherwise,
be noticeable. Also, if you run executables directly from ROM
and have very little memory, this might not be a win. Otherwise,
you probably want this.
config FEATURE_INSTALLER
bool "Support --install [-s] to install applet links at runtime"
default n
help
Enable 'busybox --install [-s]' support. This will allow you to use
Enable 'busybox --install [-s]' support. This will allow you to use
busybox at runtime to create hard links or symlinks for all the
applets that are compiled into busybox.
@@ -119,30 +110,8 @@ config LOCALE_SUPPORT
Enable this if your system has locale support and you would like
busybox to support locale settings.
config FEATURE_ASSUME_UNICODE
bool "Support Unicode"
default n
help
This makes various applets aware that one byte is not
one character on screen.
Busybox aims to eventually work correctly with Unicode displays.
Any older encodings are not guaranteed to work.
Probably by the time when busybox will be fully Unicode-clean,
other encodings will be mainly of historic interest.
config FEATURE_CHECK_UNICODE_IN_ENV
bool "Check $LANG environment variable"
default y
depends on FEATURE_ASSUME_UNICODE && !LOCALE_SUPPORT
help
With this option on, Unicode support is activated
only if LANG variable has the value of the form "xxxx.utf8"
Otherwise, Unicode support will be always enabled and active.
config LONG_OPTS
bool "Support for --long-options"
config GETOPT_LONG
bool "Enable support for --long-options"
default y
help
Enable this if you want busybox applets to use the gnu --long-option
@@ -154,16 +123,17 @@ config FEATURE_DEVPTS
help
Enable if you want BusyBox to use Unix98 PTY support. If enabled,
busybox will use /dev/ptmx for the master side of the pseudoterminal
and /dev/pts/<number> for the slave side. Otherwise, BSD style
and /dev/pts/<number> for the slave side. Otherwise, BSD style
/dev/ttyp<number> will be used. To use this option, you should have
devpts mounted.
config FEATURE_CLEAN_UP
bool "Clean up all memory before exiting (usually not needed)"
default n
depends on NITPICK
help
As a size optimization, busybox normally exits without explicitly
freeing dynamically allocated memory or closing files. This saves
freeing dynamically allocated memory or closing files. This saves
space since the OS will clean up for us, but it can confuse debuggers
like valgrind, which report tons of memory and resource leaks.
@@ -182,17 +152,15 @@ config FEATURE_SUID
default n
help
With this option you can install the busybox binary belonging
to root with the suid bit set, and it will automatically drop
to root with the suid bit set, and it'll and it'll automatically drop
priviledges for applets that don't need root access.
If you are really paranoid and don't want to do this, build two
If you're really paranoid and don't want to do this, build two
busybox binaries with different applets in them (and the appropriate
symlinks pointing to each binary), and only set the suid bit on the
one that needs it. The applets currently marked to need the suid bit
are:
crontab, dnsd, findfs, ipcrm, ipcs, login, passwd, ping, su,
traceroute, vlock.
one that needs it. The applets currently marked to need the suid bit
are login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs,
and vlock.
config FEATURE_SUID_CONFIG
bool "Runtime SUID/SGID configuration via /etc/busybox.conf"
@@ -200,7 +168,7 @@ config FEATURE_SUID_CONFIG
depends on FEATURE_SUID
help
Allow the SUID / SGID state of an applet to be determined at runtime
by checking /etc/busybox.conf. (This is sort of a poor man's sudo.)
by checking /etc/busybox.conf. (This is sort of a poor man's sudo.)
The format of this file is as follows:
<applet> = [Ssx-][Ssx-][x-] (<username>|<uid>).(<groupname>|<gid>)
@@ -208,12 +176,11 @@ config FEATURE_SUID_CONFIG
An example might help:
[SUID]
su = ssx root.0 # applet su can be run by anyone and runs with
# euid=0/egid=0
su = ssx root.0 # applet su can be run by anyone and runs with euid=0/egid=0
su = ssx # exactly the same
mount = sx- root.disk # applet mount can be run by root and members
# of group disk and runs with euid=0
mount = sx- root.disk # applet mount can be run by root and members of group disk
# and runs with euid=0
cp = --- # disable applet cp for everyone
@@ -232,15 +199,14 @@ config FEATURE_SUID_CONFIG_QUIET
default y
depends on FEATURE_SUID_CONFIG
help
/etc/busybox.conf should be readable by the user needing the SUID,
check this option to avoid users to be notified about missing
permissions.
/etc/busybox.conf should be readable by the user needing the SUID, check
this option to avoid users to be notified about missing permissions.
config SELINUX
bool "Support NSA Security Enhanced Linux"
default n
help
Enable support for SELinux in applets ls, ps, and id. Also provide
Enable support for SELinux in applets ls, ps, and id. Also provide
the option of compiling in SELinux applets.
If you do not have a complete SELinux userland installed, this stuff
@@ -275,26 +241,26 @@ config BUSYBOX_EXEC_PATH
default "/proc/self/exe"
help
When Busybox applets need to run other busybox applets, BusyBox
sometimes needs to exec() itself. When the /proc filesystem is
sometimes needs to exec() itself. When the /proc filesystem is
mounted, /proc/self/exe always points to the currently running
executable. If you haven't got /proc, set this to wherever you
executable. If you haven't got /proc, set this to wherever you
want to run BusyBox from.
# These are auto-selected by other options
config FEATURE_SYSLOG
bool #No description makes it a hidden option
bool "Support for logging to syslog"
default n
#help
# This option is auto-selected when you select any applet which may
# send its output to syslog. You do not need to select it manually.
help
This option is auto-selected when you select any applet which may
send its output to syslog. You do not need to select it manually.
config FEATURE_HAVE_RPC
bool #No description makes it a hidden option
bool "RPC support"
default n
#help
# This is automatically selected if any of enabled applets need it.
# You do not need to select it manually.
help
This is automatically selected if any of enabled applets need it.
You do not need to select it manually.
endmenu
@@ -314,37 +280,16 @@ config STATIC
Most people will leave this set to 'N'.
config PIE
bool "Build BusyBox as a position independent executable"
default n
depends on !STATIC
help
(TODO: what is it and why/when is it useful?)
Most people will leave this set to 'N'.
config NOMMU
bool "Force NOMMU build"
default n
help
Busybox tries to detect whether architecture it is being
built against supports MMU or not. If this detection fails,
or if you want to build NOMMU version of busybox for testing,
you may force NOMMU build here.
Most people will leave this set to 'N'.
# PIE can be made to work with BUILD_LIBBUSYBOX, but currently
# build system does not support that
config BUILD_LIBBUSYBOX
bool "Build shared libbusybox"
default n
depends on !FEATURE_PREFER_APPLETS && !PIE && !STATIC
depends on !FEATURE_PREFER_APPLETS
help
Build a shared library libbusybox.so.N.N.N which contains all
busybox code.
This feature allows every applet to be built as a tiny
separate executable. Enabling it for "one big busybox binary"
separate executable. Enabling it for "one big busybox binary"
approach serves no purpose and increases code size.
You should almost certainly say "no" to this.
@@ -361,7 +306,7 @@ config BUILD_LIBBUSYBOX
### standalone application which uses libbusybox say 'Y'.
###
### Note: libbusybox is GPL, not LGPL, and exports no stable API that
### might act as a copyright barrier. We can and will modify the
### might act as a copyright barrier. We can and will modify the
### exported function set between releases (even minor version number
### changes), and happily break out-of-tree features.
###
@@ -370,7 +315,7 @@ config BUILD_LIBBUSYBOX
config FEATURE_INDIVIDUAL
bool "Produce a binary for each applet, linked against libbusybox"
default y
depends on BUILD_LIBBUSYBOX
depends on !STATIC && BUILD_LIBBUSYBOX
help
If your CPU architecture doesn't allow for sharing text/rodata
sections of running binaries, but allows for runtime dynamic
@@ -388,7 +333,7 @@ config FEATURE_INDIVIDUAL
config FEATURE_SHARED_BUSYBOX
bool "Produce additional busybox binary linked against libbusybox"
default y
depends on BUILD_LIBBUSYBOX
depends on !STATIC && BUILD_LIBBUSYBOX
help
Build busybox, dynamically linked against libbusybox.so.N.N.N.
@@ -419,30 +364,11 @@ config LFS
select FDISK_SUPPORT_LARGE_DISKS
help
If you want to build BusyBox with large file support, then enable
this option. This will have no effect if your kernel or your C
library lacks large file support for large files. Some of the
this option. This will have no effect if your kernel or your C
library lacks large file support for large files. Some of the
programs that can benefit from large file support include dd, gzip,
cp, mount, tar, and many others. If you want to access files larger
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
config CROSS_COMPILER_PREFIX
string "Cross Compiler prefix"
default ""
help
If you want to build BusyBox with a cross compiler, then you
will need to set this to the cross-compiler prefix, for example,
"i386-uclibc-".
Note that CROSS_COMPILE environment variable or
"make CROSS_COMPILE=xxx ..." will override this selection.
Native builds leave this empty.
config EXTRA_CFLAGS
string "Additional CFLAGS"
default ""
help
Additional CFLAGS to pass to the compiler verbatim.
cp, mount, tar, and many others. If you want to access files larger
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
endmenu
@@ -453,23 +379,12 @@ config DEBUG
default n
help
Say Y here if you wish to examine BusyBox internals while applets are
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
development and want to debug BusyBox, answer Y.
Most people should answer N.
config DEBUG_PESSIMIZE
bool "Disable compiler optimizations"
default n
depends on DEBUG
help
The compiler's optimization of source code can eliminate and reorder
code, resulting in an executable that's hard to understand when
stepping through it with a debugger. This switches it off, resulting
in a much bigger executable that more closely matches the source
code.
config WERROR
bool "Abort compilation on any warning"
default n
@@ -478,33 +393,44 @@ config WERROR
Most people should answer N.
# Seems to be unused
#config DEBUG_PESSIMIZE
# bool "Disable compiler optimizations."
# default n
# depends on DEBUG
# help
# The compiler's optimization of source code can eliminate and reorder
# code, resulting in an executable that's hard to understand when
# stepping through it with a debugger. This switches it off, resulting
# in a much bigger executable that more closely matches the source
# code.
choice
prompt "Additional debugging library"
default NO_DEBUG_LIB
help
Using an additional debugging library will make BusyBox become
considerable larger and will cause it to run more slowly. You
considerable larger and will cause it to run more slowly. You
should always leave this option disabled for production use.
dmalloc support:
----------------
This enables compiling with dmalloc ( http://dmalloc.com/ )
which is an excellent public domain mem leak and malloc problem
detector. To enable dmalloc, before running busybox you will
detector. To enable dmalloc, before running busybox you will
want to properly set your environment, for example:
export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
The 'debug=' value is generated using the following command
dmalloc -p log-stats -p log-non-free -p log-bad-space \
-p log-elapsed-time -p check-fence -p check-heap \
-p check-lists -p check-blank -p check-funcs -p realloc-copy \
-p allow-free-null
dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
-p check-fence -p check-heap -p check-lists -p check-blank \
-p check-funcs -p realloc-copy -p allow-free-null
Electric-fence support:
-----------------------
This enables compiling with Electric-fence support. Electric
This enables compiling with Electric-fence support. Electric
fence is another very useful malloc debugging library which uses
your computer's virtual memory hardware to detect illegal memory
accesses. This support will make BusyBox be considerable larger
accesses. This support will make BusyBox be considerable larger
and run slower, so you should leave this option disabled unless
you are hunting a hard to find memory problem.
@@ -520,8 +446,14 @@ config EFENCE
endchoice
### config PARSE
### bool "Uniform config file parser debugging applet: parse"
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3?"
default y
help
This option will enable backwards compatibility with SuSv2,
specifically, old-style numeric options ('command -1 <file>')
will be supported in head, tail, and fold. (Note: should
affect renice too.)
endmenu
@@ -550,8 +482,8 @@ config INSTALL_APPLET_SYMLINKS
config INSTALL_APPLET_HARDLINKS
bool "as hard-links"
help
Install applets as hard-links to the busybox binary. This might
count on a filesystem with few inodes.
Install applets as hard-links to the busybox binary. This might count
on a filesystem with few inodes.
config INSTALL_APPLET_SCRIPT_WRAPPERS
bool "as script wrappers"
@@ -587,8 +519,7 @@ config INSTALL_SH_APPLET_HARDLINK
config INSTALL_SH_APPLET_SCRIPT_WRAPPER
bool "as script wrapper"
help
Install /bin/sh applet as script wrapper that call the busybox
binary.
Install /bin/sh applet as script wrapper that call the busybox binary.
endchoice
@@ -619,10 +550,9 @@ source modutils/Config.in
source util-linux/Config.in
source miscutils/Config.in
source networking/Config.in
source printutils/Config.in
source mailutils/Config.in
source procps/Config.in
source runit/Config.in
source selinux/Config.in
source shell/Config.in
source sysklogd/Config.in
source runit/Config.in
source selinux/Config.in
source ipsvd/Config.in
+5 -17
View File
@@ -19,24 +19,11 @@ it, is to enable all features and then use "standalone shell" mode with a
blank command $PATH.
To enable all features, use "make defconfig", which produces the largest
general-purpose configuration. It's allyesconfig minus debugging options,
general-purpose configuration. (It's allyesconfig minus debugging options,
optional packaging choices, and a few special-purpose features requiring
extra configuration to use. Then enable "standalone shell" feature:
extra configuration to use.)
make defconfig
make menuconfig
# select Busybox Settings
# then General Configuration
# then exec prefers applets
# exit back to top level menu
# select Shells
# then Standalone shell
# exit back to top level menu
# exit and save new configuration
# OR
# use these commands to modify .config directly:
sed -e 's/.*FEATURE_PREFER_APPLETS.*/CONFIG_FEATURE_PREFER_APPLETS=y/' -i .config
sed -e 's/.*FEATURE_SH_STANDALONE.*/CONFIG_FEATURE_SH_STANDALONE=y/' -i .config
make
PATH= ./busybox ash
@@ -117,7 +104,7 @@ somewhere else.
To build out of tree, cd to an empty directory and configure busybox from there:
make KBUILD_SRC=/path/to/source -f /path/to/source/Makefile defconfig
make -f /path/to/source/Makefile defconfig
make
make install
@@ -134,4 +121,5 @@ More Information:
Se also the busybox FAQ, under the questions "How can I get started using
BusyBox" and "How do I build a BusyBox-based system?" The BusyBox FAQ is
available from http://www.busybox.net/FAQ.html
available from http://www.busybox.net/FAQ.html or as the file
docs/busybox.net/FAQ.html in this tarball.
+2 -2
View File
@@ -10,7 +10,7 @@ distributed under.
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -313,7 +313,7 @@ the "copyright" line and a pointer to where the full notice is found.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
+34 -69
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 16
SUBLEVEL = 2
PATCHLEVEL = 8
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
@@ -142,6 +142,17 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
export srctree objtree VPATH TOPDIR
# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
@@ -161,33 +172,8 @@ export srctree objtree VPATH TOPDIR
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
CROSS_COMPILE ?=
# bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
# and it has not been included yet... thus using an awkward syntax.
ifeq ($(CROSS_COMPILE),)
CROSS_COMPILE := $(shell grep ^CONFIG_CROSS_COMPILER_PREFIX .config 2>/dev/null)
CROSS_COMPILE := $(subst CONFIG_CROSS_COMPILER_PREFIX=,,$(CROSS_COMPILE))
CROSS_COMPILE := $(subst ",,$(CROSS_COMPILE))
#")
endif
# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.
ifneq ($(CROSS_COMPILE),)
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1)
else
SUBARCH := $(shell uname -m)
endif
SUBARCH := $(shell echo $(SUBARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
ARCH ?= $(SUBARCH)
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
# Architecture as present in compile.h
UTS_MACHINE := $(ARCH)
@@ -316,8 +302,6 @@ AFLAGS_KERNEL =
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
CFLAGS := $(CFLAGS)
# Added only to final link stage of busybox binary
CFLAGS_busybox := $(CFLAGS_busybox)
CPPFLAGS := $(CPPFLAGS)
AFLAGS := $(AFLAGS)
LDFLAGS := $(LDFLAGS)
@@ -358,15 +342,6 @@ scripts_basic:
# To avoid any implicit rule to kick in, define an empty command.
scripts/basic/%: scripts_basic ;
# 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
$(Q)$(MAKE) $(build)=applets
applets/%: applets_dir ;
PHONY += outputmakefile
# outputmakefile generates a Makefile in the output directory, if using a
# separate output directory. This allows convenient use of make in the
@@ -386,8 +361,7 @@ endif
# of make so .config is not included in this case either (for *config).
no-dot-config-targets := clean mrproper distclean \
cscope TAGS tags help %docs
#bbox# check% is removed from above
cscope TAGS tags help %docs check%
config-targets := 0
mixed-targets := 0
@@ -463,23 +437,21 @@ libs-y := \
editors/ \
findutils/ \
init/ \
ipsvd/ \
libbb/ \
libpwdgrp/ \
loginutils/ \
mailutils/ \
miscutils/ \
modutils/ \
networking/ \
networking/libiproute/ \
networking/udhcp/ \
printutils/ \
procps/ \
runit/ \
selinux/ \
shell/ \
sysklogd/ \
util-linux/ \
util-linux/volume_id/ \
endif # KBUILD_EXTMOD
@@ -516,7 +488,7 @@ endif
# command line.
# This allow a user to issue only 'make' to build a kernel including modules
# Defaults busybox but it is usually overridden in the arch makefile
all: busybox doc
all: busybox
-include $(srctree)/arch/$(ARCH)/Makefile
@@ -524,6 +496,12 @@ all: busybox doc
#bbox# NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
CHECKFLAGS += $(NOSTDINC_FLAGS)
# warn about C99 declaration after statement
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
# disable pointer signedness warnings in gcc 4.0
CFLAGS += $(call cc-option,-Wno-pointer-sign,)
# Default kernel image to build when no specific target is given.
# KBUILD_IMAGE may be overruled on the commandline or
# set in the environment
@@ -593,7 +571,6 @@ quiet_cmd_busybox__ ?= LINK $@
cmd_busybox__ ?= $(srctree)/scripts/trylink \
"$@" \
"$(CC)" \
"$(CFLAGS) $(CFLAGS_busybox)" \
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
@@ -709,8 +686,6 @@ ifeq ($(SKIP_STRIP),y)
else
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
busybox_unstripped -o $@
# strip is confused by PIE executable and does not set exec bits
$(Q)chmod a+x $@
endif
# The actual objects are generated when descending,
@@ -754,7 +729,7 @@ localver = $(subst $(space),, \
# Currently, only git is supported.
# Other SCMs can edit scripts/setlocalversion and add the appropriate
# checks as needed.
ifdef _BB_DISABLED_CONFIG_LOCALVERSION_AUTO
ifdef CONFIG_LOCALVERSION_AUTO
_localver-auto = $(shell $(CONFIG_SHELL) \
$(srctree)/scripts/setlocalversion $(srctree))
localver-auto = $(LOCALVERSION)$(_localver-auto)
@@ -806,7 +781,7 @@ ifneq ($(KBUILD_MODULES),)
$(Q)rm -f $(MODVERDIR)/*
endif
archprepare: prepare1 scripts_basic applets_dir
archprepare: prepare1 scripts_basic
prepare0: archprepare FORCE
$(Q)$(MAKE) $(build)=.
@@ -867,7 +842,7 @@ depend dep:
# ---------------------------------------------------------------------------
# Modules
ifdef _BB_DISABLED_CONFIG_MODULES
ifdef CONFIG_MODULES
# By default, build modules as well
@@ -943,9 +918,8 @@ endif # CONFIG_MODULES
# make distclean Remove editor backup files, patch leftover files and the like
# Directories & files removed with 'make clean'
CLEAN_DIRS += $(MODVERDIR) _install 0_lib
CLEAN_FILES += busybox busybox_unstripped* busybox.links \
System.map .kernelrelease \
CLEAN_DIRS += $(MODVERDIR)
CLEAN_FILES += busybox* System.map .kernelrelease \
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
# Directories & files removed with 'make mrproper'
@@ -954,10 +928,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/autoconf.h \
include/bbconfigopts.h \
include/usage_compressed.h \
include/applet_tables.h \
applets/usage \
.kernelrelease Module.symvers tags TAGS cscope* \
busybox_old
.kernelrelease Module.symvers tags TAGS cscope*
# clean - Delete most, but leave enough to build external modules
#
@@ -973,16 +944,10 @@ clean: archclean $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
@find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-type f -print | xargs rm -f
PHONY += doc-clean
doc-clean: rm-files := docs/busybox.pod \
docs/BusyBox.html docs/BusyBox.1 docs/BusyBox.txt
doc-clean:
$(call cmd,rmfiles)
# mrproper - Delete all generated files, including .config
#
mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
@@ -1003,9 +968,9 @@ PHONY += distclean
distclean: mrproper
@find $(srctree) $(RCS_FIND_IGNORE) \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f
@@ -1109,7 +1074,7 @@ clean: rm-dirs := $(MODVERDIR)
clean: $(clean-dirs)
$(call cmd,rmdirs)
@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-type f -print | xargs rm -f
+13 -26
View File
@@ -46,20 +46,15 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
done
endif
# Not very elegant: copies testsuite to objdir...
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
.PHONY: check
.PHONY: test
check test: busybox busybox.links
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
bindir=$(objtree) srcdir=$(srctree)/testsuite \
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
.PHONY: release
release: distclean
cd ..; \
rm -r -f busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION); \
cp -pPR busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
cp -a busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type d \
-name .svn \
-print \
@@ -95,35 +90,25 @@ objsizes: busybox_unstripped
.PHONY: stksizes
stksizes: busybox_unstripped
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH)
.PHONY: bigdata
bigdata: busybox_unstripped
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] '
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [tr] '
# Documentation Targets
.PHONY: doc
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
# FIXME: Doesn't belong here
cmd_doc =
quiet_cmd_doc = $(Q)echo " DOC $(@F)"
silent_cmd_doc =
disp_doc = $($(quiet)cmd_doc)
# sed adds newlines after "Options:" etc,
# this is needed in order to get good BusyBox.{1,txt,html}
docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
$(srctree)/include/usage.h \
$(srctree)/docs/busybox_footer.pod \
applets/usage_pod
$(srctree)/docs/autodocifier.pl
$(disp_doc)
$(Q)-mkdir -p docs
$(Q)-( \
cat $(srctree)/docs/busybox_header.pod; \
applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \
cat $(srctree)/docs/busybox_footer.pod; \
) > docs/busybox.pod
$(Q)-( cat $(srctree)/docs/busybox_header.pod ; \
$(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \
cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod
docs/BusyBox.txt: docs/busybox.pod
$(disp_doc)
@@ -133,7 +118,8 @@ docs/BusyBox.txt: docs/busybox.pod
docs/BusyBox.1: docs/busybox.pod
$(disp_doc)
$(Q)-mkdir -p docs
$(Q)-pod2man --center=BusyBox --release="version $(KERNELVERSION)" $< > $@
$(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
$< > $@
docs/BusyBox.html: docs/busybox.net/BusyBox.html
$(disp_doc)
@@ -143,7 +129,8 @@ docs/BusyBox.html: docs/busybox.net/BusyBox.html
docs/busybox.net/BusyBox.html: docs/busybox.pod
$(Q)-mkdir -p docs/busybox.net
$(Q)-pod2html --noindex $< > $@
$(Q)-pod2html --noindex $< > \
docs/busybox.net/BusyBox.html
$(Q)-rm -f pod2htm*
# documentation, cross-reference
+29 -60
View File
@@ -11,41 +11,37 @@ CPPFLAGS += $(call cc-option,-std=gnu99,)
CPPFLAGS += \
-Iinclude -Ilibbb \
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include -I$(srctree)/libbb) \
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
CFLAGS += $(call cc-option,-Wall,)
CFLAGS += $(call cc-option,-Wshadow,)
CFLAGS += $(call cc-option,-Wwrite-strings,)
CFLAGS += $(call cc-option,-Wundef,)
CFLAGS += $(call cc-option,-Wstrict-prototypes,)
CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
# warn about C99 declaration after statement
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
# If you want to add more -Wsomething above, make sure that it is
# still possible to build bbox without warnings.
# flag checks are grouped together to speed the checks up a bit..
CFLAGS += $(call cc-option,-Wall -Wshadow -Wwrite-strings,)
CFLAGS += $(call cc-option,-Wundef -Wstrict-prototypes,)
# If you want to add "-Wmissing-prototypes -Wmissing-declarations" above
# (or anything else for that matter) make sure that it is still possible
# to build bbox without warnings. Current offender: find.c:alloc_action().
# Looks more like gcc bug: gcc will warn on it with or without prototype.
# But still, warning-free compile is a must, or else we will drown
# in warnings pretty soon.
ifeq ($(CONFIG_WERROR),y)
CFLAGS += $(call cc-option,-Werror,)
## TODO:
## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
## and no easy way to convince it to shut the hell up.
## We have a lot of such things all over the place.
## Classic *(off_t*)(void*)ptr does not work,
## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
## stuff in macros. This would obfuscate the code too much.
#CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
else
# for development, warn a little bit about unused results..
CPPFLAGS += -D_FORTIFY_SOURCE=2
endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
# gcc emits bogus "no prev proto" warning on find.c:alloc_action()
ifneq ($(CONFIG_WERROR),y)
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
endif
CFLAGS += $(call cc-option,-Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
# -fno-guess-branch-probability: prohibit pseudo-random guessing
# of branch probabilities (hopefully makes bloatcheck more stable):
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
@@ -54,46 +50,23 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
# FIXME: These warnings are at least partially to be concerned about and should
# be fixed..
#CFLAGS += $(call cc-option,-Wconversion,)
#CFLAGS+=$(call cc-option,-Wconversion,)
ifneq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-Os,)
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,-Os,)
ifeq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-g)
endif
endif
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
ARCH_FPIC ?= -fpic
ARCH_FPIE ?= -fpie
ARCH_PIE ?= -pie
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
# on i386: 14% smaller libbusybox.so
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
CFLAGS += $(ARCH_FPIC)
CFLAGS += -fpic
# and another 4% reduction of libbusybox.so:
# (external entry points must be marked EXTERNALLY_VISIBLE)
CFLAGS += $(call cc-option,-fvisibility=hidden)
endif
ifeq ($(CONFIG_STATIC),y)
CFLAGS_busybox += -static
endif
ifeq ($(CONFIG_PIE),y)
CFLAGS_busybox += $(ARCH_PIE)
CFLAGS += $(ARCH_FPIE)
endif
ifneq ($(CONFIG_EXTRA_CFLAGS),)
CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
#"))
LDFLAGS += -static
endif
LDLIBS += m crypt
@@ -114,18 +87,14 @@ ifeq ($(CONFIG_DMALLOC),y)
LDLIBS += dmalloc
endif
# If a flat binary should be built, CFLAGS_busybox="-elf2flt"
# env var should be set for make invocation.
# Here we check whether CFLAGS_busybox indeed contains that flag.
# (For historical reasons, we also check LDFLAGS, which doesn't
# seem to be entirely correct variable to put "-elf2flt" into).
W_ELF2FLT = -elf2flt
ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
#LDFLAGS += -nostdlib
LDFLAGS_ELF2FLT = -Wl,-elf2flt
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
SKIP_STRIP = y
endif
# Busybox is a stack-fatty so make sure we increase default size
# TODO: use "make stksizes" to find & fix big stack users
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
# Reduced from 20k to 16k in 1.9.0.
FLTFLAGS += -s 16000
FLTFLAGS += -s 20000
+3 -3
View File
@@ -6,7 +6,6 @@ help:
@echo 'Cleaning:'
@echo ' clean - delete temporary files created by build'
@echo ' distclean - delete all non-source files (including .config)'
@echo ' doc-clean - delete all generated documentation'
@echo
@echo 'Build:'
@echo ' all - Executable and documentation'
@@ -17,6 +16,7 @@ help:
@echo 'Configuration:'
@echo ' allnoconfig - disable all symbols in .config'
@echo ' allyesconfig - enable all symbols in .config (see defconfig)'
@echo ' allbareconfig - enable all applets without any sub-features'
@echo ' config - text based configurator (of last resort)'
@echo ' defconfig - set .config to largest generic configuration'
@echo ' menuconfig - interactive curses-based configurator'
@@ -24,10 +24,10 @@ help:
@echo ' hosttools - build sed for the host.'
@echo ' You can use these commands if the commands on the host'
@echo ' is unusable. Afterwards use it like:'
@echo ' make SED="$(objtree)/sed"'
@echo ' make SED="$(objtree)/sed"'
@echo
@echo 'Installation:'
@echo ' install - install busybox into CONFIG_PREFIX'
@echo ' install - install busybox into $(CONFIG_PREFIX)'
@echo ' uninstall'
@echo
@echo 'Development:'
+9 -10
View File
@@ -68,9 +68,9 @@ Downloading the current source code:
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
Anonymous GIT access is available. For instructions, check out:
Anonymous SVN access is available. For instructions, check out:
http://www.busybox.net/source.html
http://busybox.net/subversion.html
For those that are actively contributing and would like to check files in,
see:
@@ -78,13 +78,10 @@ Downloading the current source code:
http://busybox.net/developer.html
The developers also have a bug and patch tracking system
(https://bugs.busybox.net) although posting a bug/patch to the mailing list
(http://bugs.busybox.net) although posting a bug/patch to the mailing list
is generally a faster way of getting it fixed, and the complete archive of
what happened is the subversion changelog.
Note: if you want to compile busybox in a busybox environment you must
select ENABLE_DESKTOP.
----------------
getting help:
@@ -122,7 +119,7 @@ bugs:
illegal instruction
i am using debian unstable, kernel version 2.4.25-vrs2 on a netwinder,
and the latest uclibc from cvs.
and the latest uclibc from cvs. thanks for the wonderful program!
-diligent
@@ -173,8 +170,10 @@ Portability:
you're into that sort of thing, start small (selecting just a few applets)
and work your way up.
In 2005 Shaun Jackman has ported busybox to a combination of newlib
and libgloss, and some of his patches have been integrated.
Shaun Jackman has recently (2005) ported busybox to a combination of newlib
and libgloss, and some of his patches have been integrated. This platform
may join glibc/uclibc and Linux as a supported combination with the 1.1
release, but is not supported in 1.0.
Supported hardware:
@@ -195,5 +194,5 @@ Supported hardware:
Please feed suggestions, bug reports, insults, and bribes back to the busybox
maintainer:
Denys Vlasenko
Denis Vlasenko
<vda.linux@googlemail.com>
+59 -116
View File
@@ -6,18 +6,37 @@ do one of these bounce an email off the person it's listed under to see if they
have any suggestions how they plan to go about it, and to minimize conflicts
between your work and theirs. But otherwise, all of these are fair game.
Rob Landley suggested this:
Implement bb_realpath() that can handle NULL on non-glibc.
Rob Landley <rob@landley.net>:
Add BB_NOMMU to platform.h and migrate __uClinux__ tests to that.
#if defined __UCLIBC__ && !defined __ARCH_USE_MMU__
Add a libbb/platform.c
Implement fdprintf() for platforms that haven't got one.
Implement bb_realpath() that can handle NULL on non-glibc.
Cleanup bb_asprintf()
Migrate calloc() and bb_calloc() occurrences to bb_xzalloc().
Remove obsolete _() wrapper crud for internationalization we don't do.
Figure out where we need utf8 support, and add it.
sh
The command shell situation is a mess. We have two different
The command shell situation is a big mess. We have three or four different
shells that don't really share any code, and the "standalone shell" doesn't
work all that well (especially not in a chroot environment), due to apps not
being reentrant.
being reentrant. I'm writing a new shell (bbsh) to unify the various
shells and configurably add the minimal set of bash features people
actually use. The hardest part is it has to configure down as small as
lash while providing lash's features. The rest is easy in comparison.
bzip2
Compression-side support.
init
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
depmod
busybox lacks a way to update module deps when running from firmware without the
use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
modutils. The orig depmod is rather pointless to have to add to a firmware image
in when we already have a insmod/rmmod and friends.
Unify base64 handling.
[done]
Do a SUSv3 audit
Look at the full Single Unix Specification version 3 (available online at
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
@@ -26,7 +45,6 @@ Rob Landley suggested this:
Even better would be some kind of automated compliance test harness that
exercises each command line option and the various corner cases.
Internationalization
How much internationalization should we do?
@@ -94,10 +112,15 @@ Rob Landley suggested this:
This one's open to everybody, but I'll wind up doing it...
Bernhard Reutner-Fischer <busybox@busybox.net> suggests to look at these:
Bernhard Fischer <busybox@busybox.net> suggests to look at these:
New debug options:
-Wlarger-than-127
Cleanup any big users
-Wunused-parameter
Facilitate applet PROTOTYPES to provide means for having applets that
do a) not take any arguments b) need only one of argc or argv c) need
both argc and argv. All of these three options should go for the most
feature complete denominator.
Collate BUFSIZ IOBUF_SIZE MY_BUF_SIZE PIPE_PROGRESS_SIZE BUFSIZE PIPESIZE
make bb_common_bufsiz1 configurable, size wise.
make pipesize configurable, size wise.
@@ -105,6 +128,9 @@ Bernhard Reutner-Fischer <busybox@busybox.net> suggests to look at these:
As yet unclaimed:
----
find
doesn't understand (), lots of susv3 stuff.
----
diff
Make sure we handle empty files properly:
@@ -122,8 +148,20 @@ patch
And while we're at it, a new patch filename quoting format is apparently
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
---
ps / top
Add support for both RSS and VSIZE rather than just one or the other.
Or make it a build option.
---
man
It would be nice to have a man command. Not one that handles troff or
anything, just one that can handle preformatted ascii man pages, possibly
compressed. This could probably be a script in the extras directory that
calls cat/zcat/bzcat | less
(How doclifter might work into this is anybody's guess.)
---
ar
Write support!
Write support?
---
stty / catv
stty's visible() function and catv's guts are identical. Merge them into
@@ -165,7 +203,8 @@ Unify archivers
---
Text buffer support.
Several existing applets (sort, vi, less...) read
a whole file into memory and act on it. Use open_read_close().
a whole file into memory and act on it. There might be an opportunity
for shared code in there that could be moved into libbb...
---
Memory Allocation
We have a CONFIG_BUFFER mechanism that lets us select whether to do memory
@@ -217,7 +256,7 @@ Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS
FEATURE_CLEAN_UP
This is more an unresolved issue than a to-do item. More thought is needed.
Normally we rely on exit() to free memory, close files and unmap segments
Normally we rely on exit() to free memory, close files, and unmap segments
for us. This makes most calls to free(), close(), and unmap() optional in
busybox applets that don't intend to run for very long, and optional stuff
can be omitted to save size.
@@ -246,6 +285,7 @@ FEATURE_CLEAN_UP
For right now, exit() handles it just fine.
Minor stuff:
watchdog.c could autodetect the timer duration via:
if(!ioctl (fd, WDIOC_GETTIMEOUT, &tmo)) timer_duration = 1 + (tmo / 2);
@@ -257,121 +297,24 @@ Minor stuff:
---
use bb_perror_msg where appropriate: See
egrep "[^_]perror"
---
Remove superfluous fmt occurances: e.g.
fprintf(stderr, "%s: %s not found\n", "unalias", *argptr);
-> fprintf(stderr, "unalias: %s not found\n", *argptr);
---
possible code duplication ingroup() and is_a_group_member()
---
Move __get_hz() to a better place and (re)use it in route.c, ash.c
Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
---
See grep -r strtod
Alot of duplication that wants cleanup.
---
in_ether duplicated in network/{interface,ifconfig}.c
---
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
---
support start-stop-daemon -d <chdir-path>
Code cleanup:
Replace deprecated functions.
bzero() -> memset()
---
sigblock(), siggetmask(), sigsetmask(), sigmask() -> sigprocmask et al
---
vdprintf() -> similar sized functionality
---
(TODO list after discussion 11.05.2009)
* shrink tc/brctl/ip
tc/brctl seem like fairly large things to try and tackle in your timeframe,
and i think people have posted attempts in the past. Adding additional
options to ip though seems reasonable.
* add tests for some applets
* implement POSIX utilities and audit them for POSIX conformance. then
audit them for GNU conformance. then document all your findings in a new
doc/conformance.txt file while perhaps implementing some of the missing
features.
you can find the latest POSIX documentation (1003.1-2008) here:
http://www.opengroup.org/onlinepubs/9699919799/
and the complete list of all utilities that POSIX covers:
http://www.opengroup.org/onlinepubs/9699919799/idx/utilities.html
The first step would to generate a file/matrix what is already archived
(also IPV6)
* ntpdate/ntpd (see ntpclient and openntp for examples)
* implement 'at'
* rpcbind (former portmap) or equivalent
so that we don't have to use -o nolock on nfs mounts
* check IPV6 compliance
* generate a mini example using kernel+busybox only (+libc) for example
* more support for advanced linux 2.6.x features, see: iotop
most likely there is more
* even more support for statistics: mpstat, iostat, powertop....
Unicode work needed:
Unicode support uses libc multibyte functions if LOCALE_SUPPORT is on
(in this case, the code will also support many more encodings),
or uses a limited subset of re-implemented multibyte functions
which only understand "one byte == one char" and unicode.
This is useful if you build against uclibc with locale support disabled.
Unicode-dependent applets must call check_unicode_in_env() when they
begin executing.
Applet code may conditionalize on FEATURE_ASSUME_UNICODE
in order to use more efficient code if unicode support is not requested.
Available functions (if you need more, implement them in libbb/unicode.c
so that they work without LOCALE_SUPPORT too):
int bb_mbstrlen(str) - multibyte-aware strlen
size_t mbstowcs(wdest, src, n)
size_t wcstombs(dest, wsrc, n)
size_t wcrtomb(str, wc, wstate)
int iswspace(wc)
int iswalnum(wc)
int iswpunct(wc)
Applets which only need to align columns on screen correctly:
ls - already done, use source as an example
df
dumpleases
lsmod
Applets which need to account for Unicode chars
while processing the output:
[un]expand
fold
man
watch
cut (-b and -c are currently the same, needs fixing)
These applets need to ensure that unicode input
is handled correctly (say, <unicode><backspace> sequence):
getty, login
rm -i
unzip (overwrite prompt)
Viewers/editors are more difficult (many cases to get right).
libbb/lineedit.c is an example how to do it:
less, most, ed, vi
awk
[ef]grep
sed
Probably needs some specialized work:
loadkeys
+171 -389
View File
@@ -1,7 +1,11 @@
# This .config compiles for NOMMU.
# TODO:
# Pick disabled applet, enable & try to make it compile & work on NOMMU
#
# Automatically generated make config: don't edit
# Busybox version: 1.16.0
# Wed Jan 27 21:01:26 2010
# Busybox version: 1.6.0.svn
# Wed Apr 11 01:29:04 2007
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -12,11 +16,9 @@ CONFIG_HAVE_DOT_CONFIG=y
#
# General Configuration
#
CONFIG_DESKTOP=y
CONFIG_EXTRA_COMPAT=y
CONFIG_INCLUDE_SUSv2=y
# CONFIG_USE_PORTABLE_CODE is not set
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_NITPICK is not set
# CONFIG_DESKTOP is not set
# CONFIG_FEATURE_BUFFERS_USE_MALLOC is not set
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
CONFIG_SHOW_USAGE=y
@@ -24,43 +26,38 @@ CONFIG_FEATURE_VERBOSE_USAGE=y
CONFIG_FEATURE_COMPRESS_USAGE=y
CONFIG_FEATURE_INSTALLER=y
# CONFIG_LOCALE_SUPPORT is not set
# CONFIG_FEATURE_ASSUME_UNICODE is not set
# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
CONFIG_LONG_OPTS=y
CONFIG_GETOPT_LONG=y
CONFIG_FEATURE_DEVPTS=y
# CONFIG_FEATURE_CLEAN_UP is not set
CONFIG_FEATURE_PIDFILE=y
CONFIG_FEATURE_SUID=y
CONFIG_FEATURE_SUID_CONFIG=y
CONFIG_FEATURE_SUID_CONFIG_QUIET=y
CONFIG_SELINUX=y
CONFIG_FEATURE_SYSLOG=y
# CONFIG_FEATURE_SUID_CONFIG is not set
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
# CONFIG_FEATURE_HAVE_RPC is not set
# CONFIG_SELINUX is not set
CONFIG_FEATURE_PREFER_APPLETS=y
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
CONFIG_FEATURE_SYSLOG=y
CONFIG_FEATURE_HAVE_RPC=y
#
# Build Options
#
# CONFIG_STATIC is not set
# CONFIG_PIE is not set
CONFIG_NOMMU=y
# CONFIG_BUILD_LIBBUSYBOX is not set
# CONFIG_FEATURE_INDIVIDUAL is not set
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
CONFIG_LFS=y
CONFIG_CROSS_COMPILER_PREFIX=""
CONFIG_EXTRA_CFLAGS=""
# CONFIG_BUILD_AT_ONCE is not set
#
# Debugging Options
#
# CONFIG_DEBUG is not set
# CONFIG_DEBUG_PESSIMIZE is not set
# CONFIG_WERROR is not set
CONFIG_WERROR=y
CONFIG_NO_DEBUG_LIB=y
# CONFIG_DMALLOC is not set
# CONFIG_EFENCE is not set
CONFIG_INCLUDE_SUSv2=y
#
# Installation Options
@@ -68,11 +65,7 @@ CONFIG_NO_DEBUG_LIB=y
# CONFIG_INSTALL_NO_USR is not set
CONFIG_INSTALL_APPLET_SYMLINKS=y
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
# CONFIG_INSTALL_APPLET_DONT is not set
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
CONFIG_PREFIX="./_install"
#
@@ -80,23 +73,14 @@ CONFIG_PREFIX="./_install"
#
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SIZE_VS_SPEED=2
CONFIG_FEATURE_FAST_TOP=y
CONFIG_FEATURE_ETC_NETWORKS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
CONFIG_FEATURE_EDITING_VI=y
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
# CONFIG_FEATURE_EDITING_VI is not set
CONFIG_FEATURE_EDITING_HISTORY=15
# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
CONFIG_FEATURE_TAB_COMPLETION=y
CONFIG_FEATURE_USERNAME_COMPLETION=y
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
CONFIG_FEATURE_EDITING_ASK_TERMINAL=y
CONFIG_FEATURE_NON_POSIX_CP=y
CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y
CONFIG_FEATURE_COPYBUF_KB=4
CONFIG_MONOTONIC_SYSCALL=y
CONFIG_IOCTL_HEX2STR_ERROR=y
CONFIG_FEATURE_HWIB=y
# CONFIG_FEATURE_TAB_COMPLETION is not set
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
#
# Applets
@@ -105,42 +89,41 @@ CONFIG_FEATURE_HWIB=y
#
# Archival Utilities
#
CONFIG_FEATURE_SEAMLESS_LZMA=y
CONFIG_FEATURE_SEAMLESS_BZ2=y
CONFIG_FEATURE_SEAMLESS_GZ=y
CONFIG_FEATURE_SEAMLESS_Z=y
CONFIG_AR=y
CONFIG_FEATURE_AR_LONG_FILENAMES=y
CONFIG_BUNZIP2=y
CONFIG_BZIP2=y
CONFIG_CPIO=y
CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
CONFIG_GZIP=y
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
CONFIG_LZOP=y
CONFIG_LZOP_COMPR_HIGH=y
CONFIG_RPM2CPIO=y
CONFIG_RPM=y
# CONFIG_RPM is not set
CONFIG_TAR=y
CONFIG_FEATURE_TAR_CREATE=y
CONFIG_FEATURE_TAR_AUTODETECT=y
# CONFIG_FEATURE_TAR_BZIP2 is not set
# CONFIG_FEATURE_TAR_LZMA is not set
CONFIG_FEATURE_TAR_FROM=y
# CONFIG_FEATURE_TAR_GZIP is not set
# CONFIG_FEATURE_TAR_COMPRESS is not set
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
CONFIG_FEATURE_TAR_UNAME_GNAME=y
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
CONFIG_UNCOMPRESS=y
CONFIG_UNLZMA=y
CONFIG_FEATURE_LZMA_FAST=y
CONFIG_UNZIP=y
#
# Common options for cpio and tar
#
CONFIG_FEATURE_UNARCHIVE_TAPE=y
# CONFIG_FEATURE_DEB_TAR_GZ is not set
# CONFIG_FEATURE_DEB_TAR_BZ2 is not set
# CONFIG_FEATURE_DEB_TAR_LZMA is not set
#
# Coreutils
#
@@ -151,22 +134,22 @@ CONFIG_CATV=y
CONFIG_CHGRP=y
CONFIG_CHMOD=y
CONFIG_CHOWN=y
CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
CONFIG_CHROOT=y
CONFIG_CKSUM=y
CONFIG_CMP=y
CONFIG_COMM=y
CONFIG_CP=y
CONFIG_FEATURE_CP_LONG_OPTIONS=y
CONFIG_CUT=y
CONFIG_DATE=y
CONFIG_FEATURE_DATE_ISOFMT=y
CONFIG_FEATURE_DATE_COMPAT=y
CONFIG_DD=y
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
CONFIG_FEATURE_DD_IBS_OBS=y
CONFIG_DF=y
CONFIG_FEATURE_DF_FANCY=y
CONFIG_DIFF=y
CONFIG_FEATURE_DIFF_BINARY=y
CONFIG_FEATURE_DIFF_DIR=y
CONFIG_FEATURE_DIFF_MINIMAL=y
CONFIG_DIRNAME=y
CONFIG_DOS2UNIX=y
CONFIG_UNIX2DOS=y
@@ -176,13 +159,10 @@ CONFIG_ECHO=y
CONFIG_FEATURE_FANCY_ECHO=y
CONFIG_ENV=y
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
CONFIG_EXPAND=y
CONFIG_FEATURE_EXPAND_LONG_OPTIONS=y
CONFIG_EXPR=y
CONFIG_EXPR_MATH_SUPPORT_64=y
CONFIG_FALSE=y
CONFIG_FOLD=y
CONFIG_FSYNC=y
CONFIG_HEAD=y
CONFIG_FEATURE_FANCY_HEAD=y
CONFIG_HOSTID=y
@@ -214,19 +194,13 @@ CONFIG_OD=y
CONFIG_PRINTENV=y
CONFIG_PRINTF=y
CONFIG_PWD=y
CONFIG_READLINK=y
CONFIG_FEATURE_READLINK_FOLLOW=y
CONFIG_REALPATH=y
CONFIG_RM=y
CONFIG_RMDIR=y
CONFIG_FEATURE_RMDIR_LONG_OPTIONS=y
CONFIG_SEQ=y
CONFIG_SHA1SUM=y
CONFIG_SHA256SUM=y
CONFIG_SHA512SUM=y
CONFIG_SLEEP=y
CONFIG_FEATURE_FANCY_SLEEP=y
CONFIG_FEATURE_FLOAT_SLEEP=y
CONFIG_SORT=y
CONFIG_FEATURE_SORT_BIG=y
CONFIG_SPLIT=y
@@ -236,7 +210,6 @@ CONFIG_FEATURE_STAT_FORMAT=y
CONFIG_STTY=y
CONFIG_SUM=y
CONFIG_SYNC=y
CONFIG_TAC=y
CONFIG_TAIL=y
CONFIG_FEATURE_FANCY_TAIL=y
CONFIG_TEE=y
@@ -250,12 +223,11 @@ CONFIG_FEATURE_TR_EQUIV=y
CONFIG_TRUE=y
CONFIG_TTY=y
CONFIG_UNAME=y
CONFIG_UNEXPAND=y
CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS=y
CONFIG_UNIQ=y
CONFIG_USLEEP=y
CONFIG_UUDECODE=y
CONFIG_UUENCODE=y
CONFIG_WATCH=y
CONFIG_WC=y
CONFIG_FEATURE_WC_LARGE=y
CONFIG_WHO=y
@@ -278,7 +250,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
CONFIG_FEATURE_HUMAN_READABLE=y
#
# Common options for md5sum, sha1sum, sha256sum, sha512sum
# Common options for md5sum, sha1sum
#
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
@@ -289,7 +261,6 @@ CONFIG_CHVT=y
CONFIG_CLEAR=y
CONFIG_DEALLOCVT=y
CONFIG_DUMPKMAP=y
CONFIG_KBD_MODE=y
CONFIG_LOADFONT=y
CONFIG_LOADKMAP=y
CONFIG_OPENVT=y
@@ -298,41 +269,33 @@ CONFIG_RESIZE=y
CONFIG_FEATURE_RESIZE_PRINT=y
CONFIG_SETCONSOLE=y
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
CONFIG_SETFONT=y
CONFIG_FEATURE_SETFONT_TEXTUAL_MAP=y
CONFIG_DEFAULT_SETFONT_DIR=""
CONFIG_SETKEYCODES=y
CONFIG_SETLOGCONS=y
CONFIG_SHOWKEY=y
#
# Debian Utilities
#
CONFIG_MKTEMP=y
CONFIG_PIPE_PROGRESS=y
CONFIG_READLINK=y
CONFIG_FEATURE_READLINK_FOLLOW=y
CONFIG_RUN_PARTS=y
CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y
CONFIG_FEATURE_RUN_PARTS_FANCY=y
CONFIG_START_STOP_DAEMON=y
CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y
CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y
# CONFIG_START_STOP_DAEMON is not set
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
CONFIG_WHICH=y
#
# Editors
#
CONFIG_AWK=y
CONFIG_FEATURE_AWK_LIBM=y
CONFIG_CMP=y
CONFIG_DIFF=y
CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
CONFIG_FEATURE_DIFF_DIR=y
CONFIG_FEATURE_AWK_MATH=y
CONFIG_ED=y
CONFIG_PATCH=y
CONFIG_SED=y
CONFIG_VI=y
CONFIG_FEATURE_VI_MAX_LEN=4096
CONFIG_FEATURE_VI_8BIT=y
CONFIG_FEATURE_VI_COLON=y
CONFIG_FEATURE_VI_YANKMARK=y
CONFIG_FEATURE_VI_SEARCH=y
@@ -355,7 +318,6 @@ CONFIG_FEATURE_FIND_MMIN=y
CONFIG_FEATURE_FIND_PERM=y
CONFIG_FEATURE_FIND_TYPE=y
CONFIG_FEATURE_FIND_XDEV=y
CONFIG_FEATURE_FIND_MAXDEPTH=y
CONFIG_FEATURE_FIND_NEWER=y
CONFIG_FEATURE_FIND_INUM=y
CONFIG_FEATURE_FIND_EXEC=y
@@ -366,11 +328,6 @@ CONFIG_FEATURE_FIND_DEPTH=y
CONFIG_FEATURE_FIND_PAREN=y
CONFIG_FEATURE_FIND_SIZE=y
CONFIG_FEATURE_FIND_PRUNE=y
CONFIG_FEATURE_FIND_DELETE=y
CONFIG_FEATURE_FIND_PATH=y
CONFIG_FEATURE_FIND_REGEX=y
CONFIG_FEATURE_FIND_CONTEXT=y
CONFIG_FEATURE_FIND_LINKS=y
CONFIG_GREP=y
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
@@ -384,51 +341,36 @@ CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
#
# Init Utilities
#
CONFIG_INIT=y
CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_REMOVED=y
CONFIG_FEATURE_KILL_DELAY=1
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
# CONFIG_INIT is not set
# CONFIG_DEBUG_INIT is not set
# CONFIG_FEATURE_USE_INITTAB is not set
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
CONFIG_HALT=y
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""
CONFIG_MESG=y
#
# Login/Password Management Utilities
#
CONFIG_FEATURE_SHADOWPASSWDS=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_USE_BB_SHADOW=y
CONFIG_USE_BB_CRYPT=y
CONFIG_USE_BB_CRYPT_SHA=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_ADDGROUP=y
CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS=y
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_DELGROUP=y
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
CONFIG_FEATURE_CHECK_NAMES=y
CONFIG_ADDUSER=y
CONFIG_FEATURE_ADDUSER_LONG_OPTIONS=y
CONFIG_FIRST_SYSTEM_ID=100
CONFIG_LAST_SYSTEM_ID=999
CONFIG_DELUSER=y
CONFIG_GETTY=y
CONFIG_FEATURE_UTMP=y
CONFIG_FEATURE_WTMP=y
CONFIG_LOGIN=y
# CONFIG_PAM is not set
CONFIG_LOGIN_SCRIPTS=y
CONFIG_FEATURE_NOLOGIN=y
CONFIG_FEATURE_SECURETTY=y
CONFIG_PASSWD=y
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
CONFIG_CRYPTPW=y
CONFIG_CHPASSWD=y
CONFIG_SU=y
CONFIG_FEATURE_SU_SYSLOG=y
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
@@ -445,39 +387,30 @@ CONFIG_LSATTR=y
#
# Linux Module Utilities
#
CONFIG_MODPROBE_SMALL=y
CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE=y
CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# CONFIG_INSMOD is not set
# CONFIG_RMMOD is not set
# CONFIG_LSMOD is not set
# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
# CONFIG_MODPROBE is not set
# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
# CONFIG_DEPMOD is not set
CONFIG_INSMOD=y
CONFIG_FEATURE_INSMOD_VERSION_CHECKING=y
CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS=y
CONFIG_FEATURE_INSMOD_LOADINKMEM=y
CONFIG_FEATURE_INSMOD_LOAD_MAP=y
CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL=y
CONFIG_RMMOD=y
CONFIG_LSMOD=y
CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
CONFIG_MODPROBE=y
CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS=y
CONFIG_FEATURE_MODPROBE_FANCY_ALIAS=y
#
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
CONFIG_FEATURE_INSMOD_TRY_MMAP=y
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
CONFIG_FEATURE_2_4_MODULES=y
CONFIG_FEATURE_2_6_MODULES=y
# CONFIG_FEATURE_QUERY_MODULE_INTERFACE is not set
#
# Linux System Utilities
#
# CONFIG_ACPID is not set
# CONFIG_FEATURE_ACPID_COMPAT is not set
CONFIG_BLKID=y
CONFIG_DMESG=y
CONFIG_FEATURE_DMESG_PRETTY=y
CONFIG_FBSET=y
@@ -493,78 +426,39 @@ CONFIG_FEATURE_SGI_LABEL=y
CONFIG_FEATURE_SUN_LABEL=y
CONFIG_FEATURE_OSF_LABEL=y
CONFIG_FEATURE_FDISK_ADVANCED=y
CONFIG_FINDFS=y
CONFIG_FREERAMDISK=y
CONFIG_FSCK_MINIX=y
CONFIG_MKFS_EXT2=y
CONFIG_MKFS_MINIX=y
#
# Minix filesystem support
#
CONFIG_FEATURE_MINIX2=y
CONFIG_MKFS_REISER=y
CONFIG_MKFS_VFAT=y
CONFIG_GETOPT=y
CONFIG_FEATURE_GETOPT_LONG=y
CONFIG_HEXDUMP=y
CONFIG_FEATURE_HEXDUMP_REVERSE=y
CONFIG_HD=y
CONFIG_HWCLOCK=y
CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y
CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
CONFIG_IPCRM=y
CONFIG_IPCS=y
CONFIG_LOSETUP=y
CONFIG_LSPCI=y
CONFIG_LSUSB=y
CONFIG_MDEV=y
CONFIG_FEATURE_MDEV_CONF=y
CONFIG_FEATURE_MDEV_RENAME=y
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
CONFIG_FEATURE_MDEV_EXEC=y
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_UUID=y
CONFIG_FEATURE_MKSWAP_V0=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_VOLUMEID=y
CONFIG_FEATURE_VOLUMEID_EXT=y
CONFIG_FEATURE_VOLUMEID_BTRFS=y
CONFIG_FEATURE_VOLUMEID_REISERFS=y
CONFIG_FEATURE_VOLUMEID_FAT=y
CONFIG_FEATURE_VOLUMEID_HFS=y
CONFIG_FEATURE_VOLUMEID_JFS=y
CONFIG_FEATURE_VOLUMEID_XFS=y
CONFIG_FEATURE_VOLUMEID_NTFS=y
CONFIG_FEATURE_VOLUMEID_ISO9660=y
CONFIG_FEATURE_VOLUMEID_UDF=y
CONFIG_FEATURE_VOLUMEID_LUKS=y
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
CONFIG_FEATURE_VOLUMEID_ROMFS=y
CONFIG_FEATURE_VOLUMEID_SYSV=y
CONFIG_FEATURE_VOLUMEID_OCFS2=y
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
CONFIG_MOUNT=y
CONFIG_FEATURE_MOUNT_FAKE=y
CONFIG_FEATURE_MOUNT_VERBOSE=y
CONFIG_FEATURE_MOUNT_HELPERS=y
CONFIG_FEATURE_MOUNT_LABEL=y
CONFIG_FEATURE_MOUNT_NFS=y
# CONFIG_FEATURE_MOUNT_NFS is not set
CONFIG_FEATURE_MOUNT_CIFS=y
CONFIG_FEATURE_MOUNT_FLAGS=y
CONFIG_FEATURE_MOUNT_FSTAB=y
CONFIG_PIVOT_ROOT=y
CONFIG_RDATE=y
CONFIG_RDEV=y
CONFIG_READPROFILE=y
CONFIG_RTCWAKE=y
CONFIG_SCRIPT=y
CONFIG_SCRIPTREPLAY=y
CONFIG_SETARCH=y
CONFIG_SWAPONOFF=y
CONFIG_FEATURE_SWAPON_PRI=y
CONFIG_SWITCH_ROOT=y
CONFIG_UMOUNT=y
CONFIG_FEATURE_UMOUNT_ALL=y
@@ -579,53 +473,27 @@ CONFIG_FEATURE_MOUNT_LOOP=y
# Miscellaneous Utilities
#
CONFIG_ADJTIMEX=y
CONFIG_BBCONFIG=y
CONFIG_BEEP=y
CONFIG_FEATURE_BEEP_FREQ=4000
CONFIG_FEATURE_BEEP_LENGTH_MS=30
CONFIG_CHAT=y
CONFIG_FEATURE_CHAT_NOFAIL=y
CONFIG_FEATURE_CHAT_TTY_HIFI=y
CONFIG_FEATURE_CHAT_IMPLICIT_CR=y
CONFIG_FEATURE_CHAT_SWALLOW_OPTS=y
CONFIG_FEATURE_CHAT_SEND_ESCAPES=y
CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
CONFIG_FEATURE_CHAT_CLR_ABORT=y
# CONFIG_BBCONFIG is not set
CONFIG_CHRT=y
CONFIG_CROND=y
CONFIG_FEATURE_CROND_D=y
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
CONFIG_CRONTAB=y
# CONFIG_CROND is not set
# CONFIG_DEBUG_CROND_OPTION is not set
# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
# CONFIG_CRONTAB is not set
CONFIG_DC=y
CONFIG_FEATURE_DC_LIBM=y
# CONFIG_DEVFSD is not set
# CONFIG_DEVFSD_MODLOAD is not set
# CONFIG_DEVFSD_FG_NP is not set
# CONFIG_DEVFSD_VERBOSE is not set
# CONFIG_FEATURE_DEVFS is not set
CONFIG_DEVMEM=y
CONFIG_EJECT=y
CONFIG_FEATURE_EJECT_SCSI=y
CONFIG_FBSPLASH=y
CONFIG_FLASHCP=y
# CONFIG_FLASH_LOCK is not set
# CONFIG_FLASH_UNLOCK is not set
# CONFIG_FLASH_ERASEALL is not set
CONFIG_IONICE=y
CONFIG_INOTIFYD=y
CONFIG_LAST=y
CONFIG_FEATURE_LAST_SMALL=y
# CONFIG_FEATURE_LAST_FANCY is not set
CONFIG_LESS=y
CONFIG_FEATURE_LESS_MAXLINES=9999999
CONFIG_FEATURE_LESS_BRACKETS=y
CONFIG_FEATURE_LESS_FLAGS=y
CONFIG_FEATURE_LESS_FLAGCS=y
CONFIG_FEATURE_LESS_MARKS=y
CONFIG_FEATURE_LESS_REGEXP=y
CONFIG_FEATURE_LESS_WINCH=y
CONFIG_FEATURE_LESS_DASHCMD=y
CONFIG_FEATURE_LESS_LINENUMS=y
CONFIG_HDPARM=y
CONFIG_FEATURE_HDPARM_GET_IDENTITY=y
CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y
@@ -636,83 +504,65 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
CONFIG_MAKEDEVS=y
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
CONFIG_FEATURE_MAKEDEVS_TABLE=y
CONFIG_MAN=y
CONFIG_MICROCOM=y
CONFIG_MOUNTPOINT=y
CONFIG_MT=y
CONFIG_NMETER=y
CONFIG_RAIDAUTORUN=y
CONFIG_READAHEAD=y
CONFIG_RUNLEVEL=y
CONFIG_RX=y
CONFIG_SETSID=y
CONFIG_STRINGS=y
CONFIG_TASKSET=y
CONFIG_FEATURE_TASKSET_FANCY=y
CONFIG_SETSID=y
# CONFIG_TASKSET is not set
# CONFIG_FEATURE_TASKSET_FANCY is not set
CONFIG_TIME=y
CONFIG_TIMEOUT=y
CONFIG_TTYSIZE=y
CONFIG_VOLNAME=y
CONFIG_WALL=y
CONFIG_WATCHDOG=y
#
# Networking Utilities
#
CONFIG_FEATURE_IPV6=y
CONFIG_FEATURE_UNIX_LOCAL=y
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
CONFIG_ARP=y
CONFIG_ARPING=y
CONFIG_BRCTL=y
CONFIG_FEATURE_BRCTL_FANCY=y
CONFIG_FEATURE_BRCTL_SHOW=y
CONFIG_DNSD=y
CONFIG_ETHER_WAKE=y
CONFIG_FAKEIDENTD=y
CONFIG_FTPD=y
CONFIG_FEATURE_FTP_WRITE=y
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
CONFIG_FTPGET=y
CONFIG_FTPPUT=y
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
CONFIG_HOSTNAME=y
CONFIG_HTTPD=y
CONFIG_FEATURE_HTTPD_RANGES=y
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
CONFIG_FEATURE_HTTPD_SETUID=y
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
CONFIG_FEATURE_HTTPD_CGI=y
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
CONFIG_FEATURE_HTTPD_ERROR_PAGES=y
CONFIG_FEATURE_HTTPD_PROXY=y
# CONFIG_HTTPD is not set
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
# CONFIG_FEATURE_HTTPD_SETUID is not set
# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES is not set
# CONFIG_FEATURE_HTTPD_CGI is not set
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
CONFIG_IFCONFIG=y
CONFIG_FEATURE_IFCONFIG_STATUS=y
CONFIG_FEATURE_IFCONFIG_SLIP=y
CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
CONFIG_FEATURE_IFCONFIG_HW=y
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
CONFIG_IFENSLAVE=y
CONFIG_IFPLUGD=y
CONFIG_IFUPDOWN=y
CONFIG_IFUPDOWN_IFSTATE_PATH="/var/run/ifstate"
CONFIG_FEATURE_IFUPDOWN_IP=y
CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN=y
# CONFIG_IFUPDOWN is not set
# CONFIG_FEATURE_IFUPDOWN_IP is not set
# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
CONFIG_FEATURE_IFUPDOWN_IPV4=y
CONFIG_FEATURE_IFUPDOWN_IPV6=y
CONFIG_FEATURE_IFUPDOWN_MAPPING=y
CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP=y
CONFIG_INETD=y
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO=y
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD=y
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME=y
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME=y
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN=y
CONFIG_FEATURE_INETD_RPC=y
# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
# CONFIG_FEATURE_IFUPDOWN_IPX is not set
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
# CONFIG_INETD is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
# CONFIG_FEATURE_INETD_RPC is not set
CONFIG_IP=y
CONFIG_FEATURE_IP_ADDRESS=y
CONFIG_FEATURE_IP_LINK=y
@@ -720,7 +570,6 @@ CONFIG_FEATURE_IP_ROUTE=y
CONFIG_FEATURE_IP_TUNNEL=y
CONFIG_FEATURE_IP_RULE=y
CONFIG_FEATURE_IP_SHORT_FORMS=y
CONFIG_FEATURE_IP_RARE_PROTOCOLS=y
CONFIG_IPADDR=y
CONFIG_IPLINK=y
CONFIG_IPROUTE=y
@@ -730,81 +579,41 @@ CONFIG_IPCALC=y
CONFIG_FEATURE_IPCALC_FANCY=y
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
CONFIG_NAMEIF=y
CONFIG_FEATURE_NAMEIF_EXTENDED=y
CONFIG_NC=y
CONFIG_NC_SERVER=y
CONFIG_NC_EXTRA=y
CONFIG_NETSTAT=y
CONFIG_FEATURE_NETSTAT_WIDE=y
CONFIG_FEATURE_NETSTAT_PRG=y
CONFIG_NSLOOKUP=y
CONFIG_NTPD=y
CONFIG_FEATURE_NTPD_SERVER=y
CONFIG_PING=y
CONFIG_PING6=y
CONFIG_FEATURE_FANCY_PING=y
CONFIG_PSCAN=y
CONFIG_ROUTE=y
CONFIG_SLATTACH=y
CONFIG_TELNET=y
CONFIG_FEATURE_TELNET_TTYPE=y
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
CONFIG_TELNETD=y
CONFIG_FEATURE_TELNETD_STANDALONE=y
CONFIG_FEATURE_TELNETD_INETD_WAIT=y
# CONFIG_TELNETD is not set
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
CONFIG_TFTP=y
CONFIG_TFTPD=y
CONFIG_FEATURE_TFTP_GET=y
CONFIG_FEATURE_TFTP_PUT=y
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
CONFIG_TFTP_DEBUG=y
# CONFIG_DEBUG_TFTP is not set
CONFIG_TRACEROUTE=y
CONFIG_TRACEROUTE6=y
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
CONFIG_UDHCPD=y
CONFIG_DHCPRELAY=y
CONFIG_DUMPLEASES=y
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
CONFIG_UDHCPC=y
CONFIG_FEATURE_UDHCPC_ARPING=y
CONFIG_FEATURE_UDHCP_PORT=y
CONFIG_UDHCP_DEBUG=9
CONFIG_FEATURE_UDHCP_RFC3397=y
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_APP_UDHCPD=y
CONFIG_APP_DHCPRELAY=y
CONFIG_APP_DUMPLEASES=y
# CONFIG_APP_UDHCPC is not set
# CONFIG_FEATURE_UDHCP_DEBUG is not set
CONFIG_FEATURE_RFC3397=y
CONFIG_VCONFIG=y
CONFIG_WGET=y
CONFIG_FEATURE_WGET_STATUSBAR=y
CONFIG_FEATURE_WGET_AUTHENTICATION=y
CONFIG_FEATURE_WGET_LONG_OPTIONS=y
CONFIG_ZCIP=y
CONFIG_TCPSVD=y
CONFIG_TUNCTL=y
CONFIG_FEATURE_TUNCTL_UG=y
CONFIG_UDPSVD=y
#
# Print Utilities
#
CONFIG_LPD=y
CONFIG_LPR=y
CONFIG_LPQ=y
#
# Mail Utilities
#
CONFIG_MAKEMIME=y
CONFIG_FEATURE_MIME_CHARSET="us-ascii"
CONFIG_POPMAILDIR=y
CONFIG_FEATURE_POPMAILDIR_DELIVERY=y
CONFIG_REFORMIME=y
CONFIG_FEATURE_REFORMIME_COMPAT=y
CONFIG_SENDMAIL=y
#
# Process Utilities
@@ -814,104 +623,49 @@ CONFIG_FUSER=y
CONFIG_KILL=y
CONFIG_KILLALL=y
CONFIG_KILLALL5=y
CONFIG_NMETER=y
CONFIG_PGREP=y
CONFIG_PIDOF=y
CONFIG_FEATURE_PIDOF_SINGLE=y
CONFIG_FEATURE_PIDOF_OMIT=y
CONFIG_PKILL=y
CONFIG_PS=y
CONFIG_FEATURE_PS_WIDE=y
CONFIG_FEATURE_PS_TIME=y
CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS=y
CONFIG_RENICE=y
CONFIG_BB_SYSCTL=y
CONFIG_TOP=y
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
CONFIG_FEATURE_TOP_SMP_CPU=y
CONFIG_FEATURE_TOP_DECIMALS=y
CONFIG_FEATURE_TOP_SMP_PROCESS=y
CONFIG_FEATURE_TOPMEM=y
CONFIG_FEATURE_SHOW_THREADS=y
CONFIG_UPTIME=y
CONFIG_WATCH=y
#
# Runit Utilities
#
CONFIG_RUNSV=y
CONFIG_RUNSVDIR=y
CONFIG_FEATURE_RUNSVDIR_LOG=y
CONFIG_SV=y
CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
CONFIG_SVLOGD=y
CONFIG_CHPST=y
CONFIG_SETUIDGID=y
CONFIG_ENVUIDGID=y
CONFIG_ENVDIR=y
CONFIG_SOFTLIMIT=y
#
# SELinux Utilities
#
CONFIG_CHCON=y
CONFIG_FEATURE_CHCON_LONG_OPTIONS=y
CONFIG_GETENFORCE=y
CONFIG_GETSEBOOL=y
CONFIG_LOAD_POLICY=y
CONFIG_MATCHPATHCON=y
CONFIG_RESTORECON=y
CONFIG_RUNCON=y
CONFIG_FEATURE_RUNCON_LONG_OPTIONS=y
CONFIG_SELINUXENABLED=y
CONFIG_SETENFORCE=y
CONFIG_SETFILES=y
CONFIG_FEATURE_SETFILES_CHECK_OPTION=y
CONFIG_SETSEBOOL=y
CONFIG_SESTATUS=y
#
# Shells
#
# CONFIG_FEATURE_SH_IS_ASH is not set
CONFIG_FEATURE_SH_IS_HUSH=y
# CONFIG_FEATURE_SH_IS_NONE is not set
# CONFIG_FEATURE_SH_IS_HUSH is not set
# CONFIG_FEATURE_SH_IS_LASH is not set
# CONFIG_FEATURE_SH_IS_MSH is not set
CONFIG_FEATURE_SH_IS_NONE=y
# CONFIG_ASH is not set
# CONFIG_ASH_BASH_COMPAT is not set
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_READ_NCHARS is not set
# CONFIG_ASH_READ_TIMEOUT is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_MATH_SUPPORT is not set
# CONFIG_ASH_MATH_SUPPORT_64 is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
# CONFIG_ASH_RANDOM_SUPPORT is not set
# CONFIG_ASH_EXPAND_PRMT is not set
CONFIG_HUSH=y
CONFIG_HUSH_BASH_COMPAT=y
CONFIG_HUSH_HELP=y
CONFIG_HUSH_INTERACTIVE=y
CONFIG_HUSH_JOB=y
CONFIG_HUSH_TICK=y
CONFIG_HUSH_IF=y
CONFIG_HUSH_LOOPS=y
CONFIG_HUSH_CASE=y
CONFIG_HUSH_FUNCTIONS=y
CONFIG_HUSH_LOCAL=y
CONFIG_HUSH_EXPORT_N=y
CONFIG_HUSH_RANDOM_SUPPORT=y
CONFIG_LASH=y
# CONFIG_HUSH is not set
# CONFIG_LASH is not set
CONFIG_MSH=y
CONFIG_SH_MATH_SUPPORT=y
CONFIG_SH_MATH_SUPPORT_64=y
#
# Bourne Shell Options
#
CONFIG_FEATURE_SH_EXTRA_QUIET=y
CONFIG_FEATURE_SH_STANDALONE=y
CONFIG_FEATURE_SH_NOFORK=y
CONFIG_CTTYHACK=y
#
# System Logging Utilities
@@ -919,10 +673,38 @@ CONFIG_CTTYHACK=y
CONFIG_SYSLOGD=y
CONFIG_FEATURE_ROTATE_LOGFILE=y
CONFIG_FEATURE_REMOTE_LOG=y
CONFIG_FEATURE_SYSLOGD_DUP=y
CONFIG_FEATURE_IPC_SYSLOG=y
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
CONFIG_LOGREAD=y
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
CONFIG_KLOGD=y
CONFIG_LOGGER=y
#
# Runit Utilities
#
# CONFIG_RUNSV is not set
# CONFIG_RUNSVDIR is not set
CONFIG_SV=y
# CONFIG_SVLOGD is not set
CONFIG_CHPST=y
CONFIG_SETUIDGID=y
CONFIG_ENVUIDGID=y
CONFIG_ENVDIR=y
CONFIG_SOFTLIMIT=y
# CONFIG_CHCON is not set
# CONFIG_FEATURE_CHCON_LONG_OPTIONS is not set
# CONFIG_GETENFORCE is not set
# CONFIG_GETSEBOOL is not set
# CONFIG_LOAD_POLICY is not set
# CONFIG_MATCHPATHCON is not set
# CONFIG_RUNCON is not set
# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
# CONFIG_SELINUXENABLED is not set
# CONFIG_SETENFORCE is not set
#
# ipsvd utilities
#
# CONFIG_TCPSVD is not set
# CONFIG_UDPSVD is not set
-2
View File
@@ -1,2 +0,0 @@
/applet_tables
/usage
+7 -26
View File
@@ -8,37 +8,18 @@ obj-y :=
obj-y += applets.o
hostprogs-y:=
hostprogs-y += usage usage_pod applet_tables
hostprogs-y += usage
always:= $(hostprogs-y)
# Generated files need additional love
# This trick decreases amount of rebuilds
# if tree is merely renamed/copied
ifeq ($(srctree),$(objtree))
srctree_slash =
else
srctree_slash = $(srctree)/
endif
HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
applets/applets.o: include/usage_compressed.h include/applet_tables.h
applets/applet_tables: .config $(srctree_slash)include/applets.h
applets/usage: .config $(srctree_slash)include/applets.h
applets/usage_pod: .config include/applet_tables.h $(srctree_slash)include/applets.h
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
include/usage_compressed.h: applets/usage $(srctree_slash)applets/usage_compressed
HOSTCFLAGS_usage.o = -I$(srctree)/include
applets/applets.o: include/usage_compressed.h
applets/usage: .config $(srctree)/applets/usage_compressed
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
$(call cmd,gen_usage_compressed)
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
include/applet_tables.h: applets/applet_tables
$(call cmd,gen_applet_tables)
-131
View File
@@ -1,131 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Applet table generator.
* Runs on host and produces include/applet_tables.h
*
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file License in this tarball for details.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "../include/autoconf.h"
#include "../include/busybox.h"
struct bb_applet {
const char *name;
const char *main;
enum bb_install_loc_t install_loc;
enum bb_suid_t need_suid;
/* true if instead of fork(); exec("applet"); waitpid();
* one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
unsigned char noexec;
/* Even nicer */
/* true if instead of fork(); exec("applet"); waitpid();
* one can simply call applet_main(argc,argv); */
unsigned char nofork;
};
/* Define struct bb_applet applets[] */
#include "../include/applets.h"
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
static int offset[NUM_APPLETS];
static int cmp_name(const void *a, const void *b)
{
const struct bb_applet *aa = a;
const struct bb_applet *bb = b;
return strcmp(aa->name, bb->name);
}
int main(int argc, char **argv)
{
int i;
int ofs;
unsigned MAX_APPLET_NAME_LEN = 1;
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
offset[i] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* We reuse 4 high-order bits of offset array for other purposes,
* so if they are indeed needed, refuse to proceed */
if (ofs > 0xfff)
return 1;
if (!argv[1])
return 1;
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (i < 0)
return 1;
dup2(i, 1);
/* Keep in sync with include/busybox.h! */
printf("/* This is a generated file, don't edit */\n\n");
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
if (NUM_APPLETS == 1) {
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
}
printf("\n");
printf("#ifndef SKIP_definitions\n");
printf("const char applet_names[] ALIGN1 = \"\"\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("\"%s\" \"\\0\"\n", applets[i].name);
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
}
printf(";\n\n");
printf("#ifndef SKIP_applet_main\n");
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("%s_main,\n", applets[i].main);
}
printf("};\n");
printf("#endif\n\n");
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("0x%04x,\n",
offset[i]
#if ENABLE_FEATURE_PREFER_APPLETS
+ (applets[i].nofork << 12)
+ (applets[i].noexec << 13)
#endif
#if ENABLE_FEATURE_SUID
+ (applets[i].need_suid << 14) /* 2 bits */
#endif
);
}
printf("};\n\n");
#if ENABLE_FEATURE_INSTALLER
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].install_loc; /* 3 bits */
if (++i < NUM_APPLETS)
v |= applets[i].install_loc << 4; /* 3 bits */
printf("0x%02x,\n", v);
i++;
}
printf("};\n");
#endif
printf("#endif /* SKIP_definitions */\n");
printf("\n");
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
return 0;
}
+14 -3
View File
@@ -2,7 +2,7 @@
/*
* Stub for linking busybox binary against libbusybox.
*
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
* Copyright (C) 2007 Denis Vlasenko
*
* Licensed under GPLv2, see file License in this tarball for details.
*/
@@ -10,9 +10,20 @@
#include <assert.h>
#include "busybox.h"
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from file scripts/trylink and remove this warning.
#error Aborting compilation.
#endif
#if ENABLE_BUILD_LIBBUSYBOX
int main(int argc UNUSED_PARAM, char **argv)
int main(int argc, char **argv)
{
return lbb_main(argv);
return lbb_main(argc, argv);
}
#endif
+4 -2
View File
@@ -14,11 +14,13 @@ const char *applet_name;
int main(int argc, char **argv)
{
applet_name = argv[0];
return APPLET_main(argc,argv);
}
void bb_show_usage(void)
{
fputs(APPLET_full_usage "\n", stdout);
exit(EXIT_FAILURE);
printf(APPLET_full_usage "\n");
exit(1);
}
+1 -1
View File
@@ -37,7 +37,7 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
for i in $DO_INSTALL_LIBS; do
rm -f $prefix/$libdir/$i || exit 1
if [ -f $i ]; then
cp -pPR $i $prefix/$libdir/ || exit 1
cp -a $i $prefix/$libdir/ || exit 1
chmod 0644 $prefix/$libdir/$i || exit 1
fi
done
+2 -18
View File
@@ -1,25 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2008 Denys Vlasenko.
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include <unistd.h>
/* Just #include "autoconf.h" doesn't work for builds in separate
* object directory */
#include "autoconf.h"
/* Since we can't use platform.h, have to do this again by hand: */
#if ENABLE_NOMMU
# define BB_MMU 0
# define USE_FOR_NOMMU(...) __VA_ARGS__
# define USE_FOR_MMU(...)
#else
# define BB_MMU 1
# define USE_FOR_NOMMU(...)
# define USE_FOR_MMU(...) __VA_ARGS__
#endif
#include "../include/autoconf.h"
static const char usage_messages[] = ""
#define MAKE_USAGE
@@ -29,6 +13,6 @@ static const char usage_messages[] = ""
int main(void)
{
write(STDOUT_FILENO, usage_messages, sizeof(usage_messages));
write(1, usage_messages, sizeof(usage_messages));
return 0;
}
+4 -20
View File
@@ -7,29 +7,13 @@ test "$target" || exit 1
test "$loc" || loc=.
test -x "$loc/usage" || exit 1
test "$SED" || SED=sed
test "$DD" || DD=dd
sz=`"$loc/usage" | wc -c` || exit 1
exec >"$target"
echo 'static const char packed_usage[] ALIGN1 = {'
## Breaks on big-endian systems!
## # Extra effort to avoid using "od -t x1": -t is not available
## # in non-CONFIG_DESKTOPed busybox od
##
## "$loc/usage" | bzip2 -1 | od -v -x \
## | $SED -e 's/^[^ ]*//' \
## -e 's/ //g' \
## -e '/^$/d' \
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
| $SED -e 's/^[^ ]*//' \
-e 's/ //g' \
-e '/^$/d' \
-e 's/\(..\)/0x\1,/g'
echo '};'
echo 'static const char packed_usage[] ALIGN1 = '
"$loc/usage" | bzip2 -1 | od -v -t x1 \
| $SED -e 's/^[^ ]*//' -e 's/ *\(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
echo ';'
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
-100
View File
@@ -1,100 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2009 Denys Vlasenko.
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
/* Just #include "autoconf.h" doesn't work for builds in separate
* object directory */
#include "autoconf.h"
#define SKIP_applet_main
#define ALIGN1 /* nothing, just to placate applet_tables.h */
#define ALIGN2 /* nothing, just to placate applet_tables.h */
#include "applet_tables.h"
/* Since we can't use platform.h, have to do this again by hand: */
#if ENABLE_NOMMU
# define BB_MMU 0
# define USE_FOR_NOMMU(...) __VA_ARGS__
# define USE_FOR_MMU(...)
#else
# define BB_MMU 1
# define USE_FOR_NOMMU(...)
# define USE_FOR_MMU(...) __VA_ARGS__
#endif
static const char usage_messages[] = ""
#define MAKE_USAGE
#include "usage.h"
#include "applets.h"
;
int main(void)
{
const char *names;
const char *usage;
int col, len2;
col = 0;
names = applet_names;
while (*names) {
len2 = strlen(names) + 2;
if (col >= 76 - len2) {
printf(",\n");
col = 0;
}
if (col == 0) {
col = 6;
printf("\t");
} else {
printf(", ");
}
printf(names);
col += len2;
names += len2 - 1;
}
printf("\n\n");
printf("=head1 COMMAND DESCRIPTIONS\n\n");
printf("=over 4\n\n");
names = applet_names;
usage = usage_messages;
while (*names) {
if (*names >= 'a' && *names <= 'z'
&& *usage != NOUSAGE_STR[0]
) {
printf("=item B<%s>\n\n", names);
if (*usage)
printf("%s %s\n\n", names, usage);
else
printf("%s\n\n", names);
}
names += strlen(names) + 1;
usage += strlen(usage) + 1;
}
return 0;
}
/* TODO: we used to make options bold with B<> and output an example too:
=item B<cat>
cat [B<-u>] [FILE]...
Concatenate FILE(s) and print them to stdout
Options:
-u Use unbuffered i/o (ignored)
Example:
$ cat /proc/uptime
110716.72 17.67
*/
+119 -122
View File
@@ -5,36 +5,12 @@
menu "Archival Utilities"
config FEATURE_SEAMLESS_LZMA
bool "Make tar, rpm, modprobe etc understand .lzma data"
default n
help
Make tar, rpm, modprobe etc understand .lzma data.
config FEATURE_SEAMLESS_BZ2
bool "Make tar, rpm, modprobe etc understand .bz2 data"
default n
help
Make tar, rpm, modprobe etc understand .bz2 data.
config FEATURE_SEAMLESS_GZ
bool "Make tar, rpm, modprobe etc understand .gz data"
default n
help
Make tar, rpm, modprobe etc understand .gz data.
config FEATURE_SEAMLESS_Z
bool "Make tar and gunzip understand .Z data"
default n
help
Make tar and gunzip understand .Z data.
config AR
bool "ar"
default n
help
ar is an archival utility program used to create, modify, and
extract contents from archives. An archive is a single file holding
extract contents from archives. An archive is a single file holding
a collection of other files in a structure that makes it possible to
retrieve the original individual files (called archive members).
The original files' contents, mode (permissions), timestamp, owner,
@@ -53,12 +29,12 @@ config AR
probably say N here.
config FEATURE_AR_LONG_FILENAMES
bool "Support for long filenames (not needed for debs)"
bool "Enable support for long filenames (not need for debs)"
default n
depends on AR
help
By default the ar format can only store the first 15 characters
of the filename, this option removes that limitation.
By default the ar format can only store the first 15 characters of the
filename, this option removes that limitation.
It supports the GNU ar long filename method which moves multiple long
filenames into a the data section of a new ar entry.
@@ -67,7 +43,7 @@ config BUNZIP2
default n
help
bunzip2 is a compression utility using the Burrows-Wheeler block
sorting text compression algorithm, and Huffman coding. Compression
sorting text compression algorithm, and Huffman coding. Compression
is generally considerably better than that achieved by more
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
@@ -80,7 +56,7 @@ config BZIP2
default n
help
bzip2 is a compression utility using the Burrows-Wheeler block
sorting text compression algorithm, and Huffman coding. Compression
sorting text compression algorithm, and Huffman coding. Compression
is generally considerably better than that achieved by more
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
@@ -92,63 +68,44 @@ config CPIO
bool "cpio"
default n
help
cpio is an archival utility program used to create, modify, and
extract contents from archives.
cpio is an archival utility program used to create, modify, and extract
contents from archives.
cpio has 110 bytes of overheads for every stored file.
This implementation of cpio can extract cpio archives created in the
"newc" or "crc" format, it cannot create or modify them.
Unless you have a specific application which requires cpio, you
should probably say N here.
config FEATURE_CPIO_O
bool "Support for archive creation"
default n
depends on CPIO
help
This implementation of cpio can create cpio archives in the "newc"
format only.
config FEATURE_CPIO_P
bool "Support for passthrough mode"
default n
depends on FEATURE_CPIO_O
help
Passthrough mode. Rarely used.
Unless you have a specific application which requires cpio, you should
probably say N here.
config DPKG
bool "dpkg"
default n
select FEATURE_SEAMLESS_GZ
help
dpkg is a medium-level tool to install, build, remove and manage
Debian packages.
dpkg is a medium-level tool to install, build, remove and manage Debian packages.
This implementation of dpkg has a number of limitations,
you should use the official dpkg if possible.
This implementation of dpkg has a number of limitations, you should use the
official dpkg if possible.
config DPKG_DEB
bool "dpkg_deb"
default n
select FEATURE_SEAMLESS_GZ
help
dpkg-deb unpacks and provides information about Debian archives.
dpkg-deb packs, unpacks and provides information about Debian archives.
This implementation of dpkg-deb cannot pack archives.
Unless you have a specific application which requires dpkg-deb,
say N here.
Unless you have a specific application which requires dpkg-deb, you should
probably say N here.
config FEATURE_DPKG_DEB_EXTRACT_ONLY
bool "Extract only (-x)"
bool "extract only (-x)"
default n
depends on DPKG_DEB
help
This reduces dpkg-deb to the equivalent of
"ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
of the extra dpkg-deb, ar or tar options are needed, they are linked
to internally.
This reduces dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
However it saves space as none of the extra dpkg-deb, ar or tar options are
needed, they are linked to internally.
config GUNZIP
bool "gunzip"
@@ -158,6 +115,15 @@ config GUNZIP
You can use the `-t' option to test the integrity of
an archive, without decompressing it.
config FEATURE_GUNZIP_UNCOMPRESS
bool "Uncompress support"
default n
depends on GUNZIP
help
Enable if you want gunzip to have the ability to decompress
archives created by the program compress (not much
used anymore).
config GZIP
bool "gzip"
default n
@@ -165,28 +131,6 @@ config GZIP
gzip is used to compress files.
It's probably the most widely used UNIX compression program.
config FEATURE_GZIP_LONG_OPTIONS
bool "Enable long options"
default n
depends on GZIP && LONG_OPTS
help
Enable use of long options, increases size by about 106 Bytes
config LZOP
bool "lzop"
default n
help
Lzop compression/decompresion.
config LZOP_COMPR_HIGH
bool "lzop complession levels 7,8,9 (not very useful)"
default n
depends on LZOP
help
High levels (7,8,9) of lzop compression. These levels
are actually slower than gzip at equivalent compression ratios
and take up 3.2K of code.
config RPM2CPIO
bool "rpm2cpio"
default n
@@ -199,6 +143,13 @@ config RPM
help
Mini RPM applet - queries and extracts RPM packages.
config FEATURE_RPM_BZ2
bool "Enable handling of rpms with bzip2-compressed data inside"
default n
depends on RPM
help
Enable handling of rpms with bzip2-compressed data inside.
config TAR
bool "tar"
default n
@@ -207,8 +158,6 @@ config TAR
create compressed archives. It's probably the most widely used
UNIX archive program.
if TAR
config FEATURE_TAR_CREATE
bool "Enable archive creation"
default y
@@ -217,13 +166,21 @@ config FEATURE_TAR_CREATE
If you enable this option you'll be able to create
tar archives using the `-c' option.
config FEATURE_TAR_AUTODETECT
bool "Autodetect compressed tarballs"
config FEATURE_TAR_BZIP2
bool "Enable -j option to handle .tar.bz2 files"
default n
depends on FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA
depends on TAR
help
With this option tar can automatically detect compressed
tarballs. Currently it works only on files (not pipes etc).
If you enable this option you'll be able to extract
archives compressed with bzip2.
config FEATURE_TAR_LZMA
bool "Enable -a option to handle .tar.lzma files"
default n
depends on TAR
help
If you enable this option you'll be able to extract
archives compressed with lzma.
config FEATURE_TAR_FROM
bool "Enable -X (exclude from) and -T (include from) options)"
@@ -233,8 +190,24 @@ config FEATURE_TAR_FROM
If you enable this option you'll be able to specify
a list of files to include or exclude from an archive.
config FEATURE_TAR_GZIP
bool "Enable -z option"
default y
depends on TAR
help
If you enable this option tar will be able to call gzip,
when creating or extracting tar gziped archives.
config FEATURE_TAR_COMPRESS
bool "Enable -Z option"
default n
depends on TAR
help
If you enable this option tar will be able to call uncompress,
when extracting .tar.Z archives.
config FEATURE_TAR_OLDGNU_COMPATIBILITY
bool "Support for old tar header format"
bool "Enable support for old tar header format"
default N
depends on TAR
help
@@ -248,12 +221,11 @@ config FEATURE_TAR_OLDSUN_COMPATIBILITY
depends on TAR
help
This option is required to unpack archives created by some old
version of Sun's tar (it was calculating checksum using signed
arithmetic). It is said to be fixed in newer Sun tar, but "old"
tarballs still exist.
version of Sun's tar (it was calculating checksum using signed arithmetic).
It is said to be fixed in newer Sun tar, but "old" tarballs still exist.
config FEATURE_TAR_GNU_EXTENSIONS
bool "Support for GNU tar extensions (long filenames)"
bool "Enable support for some GNU tar extensions"
default y
depends on TAR
help
@@ -263,28 +235,9 @@ config FEATURE_TAR_GNU_EXTENSIONS
config FEATURE_TAR_LONG_OPTIONS
bool "Enable long options"
default n
depends on TAR && LONG_OPTS
depends on TAR && GETOPT_LONG
help
Enable use of long options, increases size by about 400 Bytes
config FEATURE_TAR_UNAME_GNAME
bool "Enable use of user and group names"
default n
depends on TAR
help
Enables use of user and group names in tar. This affects contents
listings (-t) and preserving permissions when unpacking (-p).
+200 bytes.
config FEATURE_TAR_NOPRESERVE_TIME
bool "Enable -m (do not preserve time) option"
default n
depends on TAR
help
With this option busybox supports GNU tar -m
(do not preserve time) option.
endif #tar
Enable use of long options, increases size by about 400 Bytes
config UNCOMPRESS
bool "uncompress"
@@ -298,7 +251,7 @@ config UNLZMA
default n
help
unlzma is a compression utility using the Lempel-Ziv-Markov chain
compression algorithm, and range coding. Compression
compression algorithm, and range coding. Compression
is generally considerably better than that achieved by the bzip2
compressors.
@@ -309,12 +262,12 @@ config UNLZMA
should probably say N here.
config FEATURE_LZMA_FAST
bool "Optimize unlzma for speed"
bool "Optimze unlzma for speed"
default n
depends on UNLZMA
help
This option reduces decompression time by about 25% at the cost of
a 1K bigger binary.
This option reduces decompression time by about 33% at the cost of
a 2K bigger binary.
config UNZIP
bool "unzip"
@@ -326,4 +279,48 @@ config UNZIP
current directory. Use the `-d' option to extract to a
directory of your choice.
comment "Common options for cpio and tar"
depends on CPIO || TAR
config FEATURE_UNARCHIVE_TAPE
bool "Enable tape drive support"
default n
depends on CPIO || TAR
help
I don't think this is needed anymore.
comment "Common options for dpkg and dpkg_deb"
depends on DPKG || DPKG_DEB
config FEATURE_DEB_TAR_GZ
bool "gzip debian packages (normal)"
default y if DPKG || DPKG_DEB
depends on DPKG || DPKG_DEB
help
This is the default compression method inside the debian ar file.
If you want compatibility with standard .deb's you should say yes here.
config FEATURE_DEB_TAR_BZ2
bool "bzip2 debian packages"
default n
depends on DPKG || DPKG_DEB
help
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
with bzip2 instead of gzip.
You only want this if you are creating your own custom debian packages that
use an internal control.tar.bz2 or data.tar.bz2.
config FEATURE_DEB_TAR_LZMA
bool "lzma debian packages"
default n
depends on DPKG || DPKG_DEB
help
This allows dpkg and dpkg-deb to extract deb's that are compressed
internally with lzma instead of gzip.
You only want this if you are creating your own custom debian
packages that use an internal control.tar.lzma or data.tar.lzma.
endmenu
-2
View File
@@ -16,8 +16,6 @@ lib-$(CONFIG_DPKG) += dpkg.o
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
lib-$(CONFIG_GUNZIP) += bbunzip.o
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
lib-$(CONFIG_RPM) += rpm.o
lib-$(CONFIG_TAR) += tar.o
+15 -8
View File
@@ -16,7 +16,7 @@
#include "libbb.h"
#include "unarchive.h"
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
static void header_verbose_list_ar(const file_header_t *file_header)
{
const char *mode = bb_mode_string(file_header->mode);
char *mtime;
@@ -38,20 +38,20 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
#define AR_OPT_INSERT 0x40
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ar_main(int argc UNUSED_PARAM, char **argv)
int ar_main(int argc, char **argv)
{
static const char msg_unsupported_err[] ALIGN1 =
"archive %s is not supported";
archive_handle_t *archive_handle;
unsigned opt;
char magic[8];
archive_handle = init_handle();
/* Prepend '-' to the first argument if required */
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
opt = getopt32(argv, "ptxovcr");
argv += optind;
if (opt & AR_CTX_PRINT) {
archive_handle->action_data = data_extract_to_stdout;
@@ -63,7 +63,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
archive_handle->action_data = data_extract_all;
}
if (opt & AR_OPT_PRESERVE_DATE) {
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
}
if (opt & AR_OPT_VERBOSE) {
archive_handle->action_header = header_verbose_list_ar;
@@ -75,14 +75,21 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg_and_die(msg_unsupported_err, "insertion");
}
archive_handle->src_fd = xopen(*argv++, O_RDONLY);
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
while (*argv) {
while (optind < argc) {
archive_handle->filter = filter_accept_list;
llist_add_to(&archive_handle->accept, *argv++);
llist_add_to(&(archive_handle->accept), argv[optind++]);
}
unpack_ar_archive(archive_handle);
xread(archive_handle->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
bb_error_msg_and_die("invalid ar magic");
}
archive_handle->offset += 7;
while (get_header_ar(archive_handle) == EXIT_SUCCESS)
continue;
return EXIT_SUCCESS;
}
+23 -59
View File
@@ -28,16 +28,15 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
return 0;
}
int FAST_FUNC bbunpack(char **argv,
int bbunpack(char **argv,
char* (*make_new_name)(char *filename),
IF_DESKTOP(long long) int (*unpacker)(unpack_info_t *info)
USE_DESKTOP(long long) int (*unpacker)(void)
)
{
struct stat stat_buf;
IF_DESKTOP(long long) int status;
USE_DESKTOP(long long) int status;
char *filename, *new_name;
smallint exitcode = 0;
unpack_info_t info;
do {
/* NB: new_name is *maybe* malloc'ed! */
@@ -74,12 +73,6 @@ int FAST_FUNC bbunpack(char **argv,
bb_error_msg("%s: unknown suffix - ignored", filename);
goto err;
}
/* -f: overwrite existing output files */
if (option_mask32 & OPT_FORCE) {
unlink(new_name);
}
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
/* GNU gunzip does not bail out, but goes to next file */
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
@@ -93,29 +86,14 @@ int FAST_FUNC bbunpack(char **argv,
"use -f to force it");
}
/* memset(&info, 0, sizeof(info)); */
info.mtime = 0; /* so far it has one member only */
status = unpacker(&info);
status = unpacker();
if (status < 0)
exitcode = 1;
xclose(STDOUT_FILENO); /* with error check! */
if (filename) {
char *del = new_name;
if (status >= 0) {
/* TODO: restore other things? */
if (info.mtime) {
struct timeval times[2];
times[1].tv_sec = times[0].tv_sec = info.mtime;
times[1].tv_usec = times[0].tv_usec = 0;
/* Note: we closed it first.
* On some systems calling utimes
* then closing resets the mtime
* back to current time. */
utimes(new_name, times); /* ignoring errors */
}
/* TODO: restore user/group/times here? */
/* Delete _compressed_ file */
del = filename;
/* restore extension (unless tgz -> tar case) */
@@ -175,13 +153,13 @@ char* make_new_name_bunzip2(char *filename)
}
static
IF_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM)
USE_DESKTOP(long long) int unpack_bunzip2(void)
{
return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO);
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
}
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
int bunzip2_main(int argc, char **argv)
{
getopt32(argv, "cfvdt");
argv += optind;
@@ -234,8 +212,8 @@ char* make_new_name_gunzip(char *filename)
extension++;
if (strcmp(extension, "tgz" + 1) == 0
#if ENABLE_FEATURE_SEAMLESS_Z
|| (extension[0] == 'Z' && extension[1] == '\0')
#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
|| strcmp(extension, "Z") == 0
#endif
) {
extension[-1] = '\0';
@@ -251,19 +229,19 @@ char* make_new_name_gunzip(char *filename)
}
static
IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info)
USE_DESKTOP(long long) int unpack_gunzip(void)
{
IF_DESKTOP(long long) int status = -1;
USE_DESKTOP(long long) int status = -1;
/* do the decompression, and cleanup */
if (xread_char(STDIN_FILENO) == 0x1f) {
unsigned char magic2;
magic2 = xread_char(STDIN_FILENO);
if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
} else if (magic2 == 0x8b) {
status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info);
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
} else {
goto bad_magic;
}
@@ -278,24 +256,10 @@ IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info)
return status;
}
/*
* Linux kernel build uses gzip -d -n. We accept and ignore it.
* Man page says:
* -n --no-name
* gzip: do not save the original file name and time stamp.
* (The original name is always saved if the name had to be truncated.)
* gunzip: do not restore the original file name/time even if present
* (remove only the gzip suffix from the compressed file name).
* This option is the default when decompressing.
* -N --name
* gzip: always save the original file name and time stamp (this is the default)
* gunzip: restore the original file name and time stamp if present.
*/
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
int gunzip_main(int argc, char **argv)
{
getopt32(argv, "cfvdtn");
getopt32(argv, "cfvdt");
argv += optind;
/* if called as zcat */
if (applet_name[1] == 'c')
@@ -325,13 +289,13 @@ char* make_new_name_unlzma(char *filename)
}
static
IF_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM)
USE_DESKTOP(long long) int unpack_unlzma(void)
{
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
}
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
int unlzma_main(int argc, char **argv)
{
getopt32(argv, "cf");
argv += optind;
@@ -360,20 +324,20 @@ char* make_new_name_uncompress(char *filename)
}
static
IF_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM)
USE_DESKTOP(long long) int unpack_uncompress(void)
{
IF_DESKTOP(long long) int status = -1;
USE_DESKTOP(long long) int status = -1;
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
bb_error_msg("invalid magic");
} else {
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
}
return status;
}
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc UNUSED_PARAM, char **argv)
int uncompress_main(int argc, char **argv)
{
getopt32(argv, "cf");
argv += optind;
+1 -1
View File
@@ -1,4 +1,4 @@
This file is an abridged version of README from bzip2 1.0.4
This file is an abridged version of README from bizp2 1.0.4
Build instructions (which are not relevant to busyboxed bzip2)
are removed.
===========================================================
+7 -16
View File
@@ -585,7 +585,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
#define MAIN_QSORT_STACK_SIZE 100
static NOINLINE
static
void mainQSort3(uint32_t* ptr,
uint8_t* block,
uint16_t* quadrant,
@@ -721,8 +721,7 @@ void mainQSort3(uint32_t* ptr,
#define CLEARMASK (~(SETMASK))
static NOINLINE
void mainSort(EState* state,
uint32_t* ptr,
void mainSort(uint32_t* ptr,
uint8_t* block,
uint16_t* quadrant,
uint32_t* ftab,
@@ -730,18 +729,13 @@ void mainSort(EState* state,
int32_t* budget)
{
int32_t i, j, k, ss, sb;
int32_t runningOrder[256];
Bool bigDone[256];
int32_t copyStart[256];
int32_t copyEnd [256];
uint8_t c1;
int32_t numQSorted;
uint16_t s;
Bool bigDone[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)
/*-- set up the 2-byte frequency table --*/
/* was: for (i = 65536; i >= 0; i--) ftab[i] = 0; */
@@ -991,9 +985,6 @@ void mainSort(EState* state,
AssertH(((bbSize-1) >> shifts) <= 65535, 1002);
}
}
#undef runningOrder
#undef copyStart
#undef copyEnd
}
#undef BIGFREQ
@@ -1050,7 +1041,7 @@ void BZ2_blockSort(EState* s)
*/
budget = nblock * ((wfact-1) / 3);
mainSort(s, ptr, block, quadrant, ftab, nblock, &budget);
mainSort(ptr, block, quadrant, ftab, nblock, &budget);
if (budget < 0) {
fallbackSort(s->arr1, s->arr2, ftab, nblock);
}
+7 -16
View File
@@ -33,7 +33,7 @@ typedef unsigned char Bool;
#define False ((Bool)0)
#if BZ_LIGHT_DEBUG
static void bz_assert_fail(int errcode) NORETURN;
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
#define AssertH(cond, errcode) \
do { \
if (!(cond)) \
@@ -170,7 +170,7 @@ typedef struct EState {
/* map of bytes used in block */
int32_t nInUse;
Bool inUse[256] ALIGNED(sizeof(long));
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
uint8_t unseqToSeq[256];
/* stuff for coding the MTF values */
@@ -178,22 +178,13 @@ typedef struct EState {
uint8_t selector [BZ_MAX_SELECTORS];
uint8_t selectorMtf[BZ_MAX_SELECTORS];
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
/* 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];
uint8_t len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
/* second dimension: only 3 needed; 4 makes index calculations faster */
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
uint32_t len_pack[BZ_MAX_ALPHA_SIZE][4];
#endif
int32_t BZ2_hbMakeCodeLengths__heap [BZ_MAX_ALPHA_SIZE + 2];
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;
@@ -212,7 +203,7 @@ static void
BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
static void
BZ2_hbMakeCodeLengths(EState*, uint8_t*, int32_t*, int32_t, int32_t);
BZ2_hbMakeCodeLengths(uint8_t*, int32_t*, int32_t, int32_t);
/*-------------------------------------------------------------*/
/*--- end bzlib_private.h ---*/
+2 -8
View File
@@ -264,16 +264,13 @@ void sendMTFValues(EState* s)
* are also globals only used in this proc.
* Made global to keep stack frame size small.
*/
#define code sendMTFValues__code
#define rfreq sendMTFValues__rfreq
#define len_pack sendMTFValues__len_pack
uint16_t cost[BZ_N_GROUPS];
int32_t fave[BZ_N_GROUPS];
uint16_t* mtfv = s->mtfv;
alphaSize = s->nInUse + 2;
alphaSize = s->nInUse+2;
for (t = 0; t < BZ_N_GROUPS; t++)
for (v = 0; v < alphaSize; v++)
s->len[t][v] = BZ_GREATER_ICOST;
@@ -456,7 +453,7 @@ void sendMTFValues(EState* s)
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
* comment in huffman.c for details. */
for (t = 0; t < nGroups; t++)
BZ2_hbMakeCodeLengths(s, &(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
BZ2_hbMakeCodeLengths(&(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
}
AssertH(nGroups < 8, 3002);
@@ -605,9 +602,6 @@ void sendMTFValues(EState* s)
selCtr++;
}
AssertH(selCtr == nSelectors, 3007);
#undef code
#undef rfreq
#undef len_pack
}
+1 -10
View File
@@ -98,8 +98,7 @@ void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
/*---------------------------------------------------*/
static
void BZ2_hbMakeCodeLengths(EState *s,
uint8_t *len,
void BZ2_hbMakeCodeLengths(uint8_t *len,
int32_t *freq,
int32_t alphaSize,
int32_t maxLen)
@@ -111,14 +110,9 @@ void BZ2_hbMakeCodeLengths(EState *s,
int32_t nNodes, nHeap, n1, n2, i, j, k;
Bool tooLong;
/* bbox: moved to EState to save stack
int32_t heap [BZ_MAX_ALPHA_SIZE + 2];
int32_t weight[BZ_MAX_ALPHA_SIZE * 2];
int32_t parent[BZ_MAX_ALPHA_SIZE * 2];
*/
#define heap (s->BZ2_hbMakeCodeLengths__heap)
#define weight (s->BZ2_hbMakeCodeLengths__weight)
#define parent (s->BZ2_hbMakeCodeLengths__parent)
for (i = 0; i < alphaSize; i++)
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
@@ -195,9 +189,6 @@ void BZ2_hbMakeCodeLengths(EState *s,
weight[i] = j << 8;
}
}
#undef heap
#undef weight
#undef parent
}
+8 -9
View File
@@ -8,7 +8,6 @@
*/
#include "libbb.h"
#include "unarchive.h"
#define CONFIG_BZIP2_FEATURE_SPEED 1
@@ -64,7 +63,7 @@ static uint8_t level;
* total written bytes so far otherwise
*/
static
IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
{
int n, n2, ret;
@@ -98,13 +97,13 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
if (rlen && strm->avail_in == 0)
break;
}
return 0 IF_DESKTOP( + strm->total_out );
return 0 USE_DESKTOP( + strm->total_out );
}
static
IF_DESKTOP(long long) int compressStream(unpack_info_t *info UNUSED_PARAM)
USE_DESKTOP(long long) int compressStream(void)
{
IF_DESKTOP(long long) int total;
USE_DESKTOP(long long) int total;
ssize_t count;
bz_stream bzs; /* it's small */
#define strm (&bzs)
@@ -142,7 +141,7 @@ char* make_new_name_bzip2(char *filename)
}
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bzip2_main(int argc UNUSED_PARAM, char **argv)
int bzip2_main(int argc, char **argv)
{
unsigned opt;
@@ -163,11 +162,11 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs");
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
if (opt & 0x18) // -d and/or -t
if (opt & 0x8) // -d
return bunzip2_main(argc, argv);
opt >>= 5;
opt >>= 4;
#else
opt >>= 3;
#endif
+30 -378
View File
@@ -7,375 +7,35 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
* Limitations:
* Doesn't check CRC's
* Only supports new ASCII and CRC formats
* Doesn't check CRC's
* Only supports new ASCII and CRC formats
*
*/
#include "libbb.h"
#include "unarchive.h"
/* GNU cpio 2.9 --help (abridged):
Modes:
-t, --list List the archive
-i, --extract Extract files from an archive
-o, --create Create the archive
-p, --pass-through Copy-pass mode [was ist das?!]
Options valid in any mode:
--block-size=SIZE I/O block size = SIZE * 512 bytes
-B I/O block size = 5120 bytes
-c Use the old portable (ASCII) archive format
-C, --io-size=NUMBER I/O block size in bytes
-f, --nonmatching Only copy files that do not match given pattern
-F, --file=FILE Use FILE instead of standard input or output
-H, --format=FORMAT Use given archive FORMAT
-M, --message=STRING Print STRING when the end of a volume of the
backup media is reached
-n, --numeric-uid-gid If -v, show numeric UID and GID
--quiet Do not print the number of blocks copied
--rsh-command=COMMAND Use remote COMMAND instead of rsh
-v, --verbose Verbosely list the files processed
-V, --dot Print a "." for each file processed
-W, --warning=FLAG Control warning display: 'none','truncate','all';
multiple options accumulate
Options valid only in --extract mode:
-b, --swap Swap both halfwords of words and bytes of
halfwords in the data (equivalent to -sS)
-r, --rename Interactively rename files
-s, --swap-bytes Swap the bytes of each halfword in the files
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
--to-stdout Extract files to standard output
-E, --pattern-file=FILE Read additional patterns specifying filenames to
extract or list from FILE
--only-verify-crc Verify CRC's, don't actually extract the files
Options valid only in --create mode:
-A, --append Append to an existing archive
-O FILE File to use instead of standard output
Options valid only in --pass-through mode:
-l, --link Link files instead of copying them, when possible
Options valid in --extract and --create modes:
--absolute-filenames Do not strip file system prefix components from
the file names
--no-absolute-filenames Create all files relative to the current dir
Options valid in --create and --pass-through modes:
-0, --null A list of filenames is terminated by a NUL
-a, --reset-access-time Reset the access times of files after reading them
-I FILE File to use instead of standard input
-L, --dereference Dereference symbolic links (copy the files
that they point to instead of copying the links)
-R, --owner=[USER][:.][GROUP] Set owner of created files
Options valid in --extract and --pass-through modes:
-d, --make-directories Create leading directories where needed
-m, --preserve-modification-time Retain mtime when creating files
--no-preserve-owner Do not change the ownership of the files
--sparse Write files with blocks of zeros as sparse files
-u, --unconditional Replace all files unconditionally
*/
enum {
CPIO_OPT_EXTRACT = (1 << 0),
CPIO_OPT_TEST = (1 << 1),
CPIO_OPT_NUL_TERMINATED = (1 << 2),
CPIO_OPT_UNCONDITIONAL = (1 << 3),
CPIO_OPT_VERBOSE = (1 << 4),
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
CPIO_OPT_DEREF = (1 << 7),
CPIO_OPT_FILE = (1 << 8),
OPTBIT_FILE = 8,
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
IF_LONG_OPTS( OPTBIT_QUIET ,)
IF_LONG_OPTS( OPTBIT_2STDOUT ,)
CPIO_OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
CPIO_OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
CPIO_OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
CPIO_OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
CPIO_OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
};
#define OPTION_STR "it0uvdmLF:"
#if ENABLE_FEATURE_CPIO_O
static off_t cpio_pad4(off_t size)
{
int i;
i = (- size) & 3;
size += i;
while (--i >= 0)
bb_putchar('\0');
return size;
}
/* Return value will become exit code.
* It's ok to exit instead of return. */
static NOINLINE int cpio_o(void)
{
static const char trailer[] ALIGN1 = "TRAILER!!!";
struct name_s {
struct name_s *next;
char name[1];
};
struct inodes_s {
struct inodes_s *next;
struct name_s *names;
struct stat st;
};
struct inodes_s *links = NULL;
off_t bytes = 0; /* output bytes count */
while (1) {
const char *name;
char *line;
struct stat st;
line = (option_mask32 & CPIO_OPT_NUL_TERMINATED)
? bb_get_chunk_from_file(stdin, NULL)
: xmalloc_fgetline(stdin);
if (line) {
/* Strip leading "./[./]..." from the filename */
name = line;
while (name[0] == '.' && name[1] == '/') {
while (*++name == '/')
continue;
}
if (!*name) { /* line is empty */
free(line);
continue;
}
if ((option_mask32 & CPIO_OPT_DEREF)
? stat(name, &st)
: lstat(name, &st)
) {
abort_cpio_o:
bb_simple_perror_msg_and_die(name);
}
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
st.st_size = 0; /* paranoia */
/* Store hardlinks for later processing, dont output them */
if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
struct name_s *n;
struct inodes_s *l;
/* Do we have this hardlink remembered? */
l = links;
while (1) {
if (l == NULL) {
/* Not found: add new item to "links" list */
l = xzalloc(sizeof(*l));
l->st = st;
l->next = links;
links = l;
break;
}
if (l->st.st_ino == st.st_ino) {
/* found */
break;
}
l = l->next;
}
/* Add new name to "l->names" list */
n = xmalloc(sizeof(*n) + strlen(name));
strcpy(n->name, name);
n->next = l->names;
l->names = n;
free(line);
continue;
}
} else { /* line == NULL: EOF */
next_link:
if (links) {
/* Output hardlink's data */
st = links->st;
name = links->names->name;
links->names = links->names->next;
/* GNU cpio is reported to emit file data
* only for the last instance. Mimic that. */
if (links->names == NULL)
links = links->next;
else
st.st_size = 0;
/* NB: we leak links->names and/or links,
* this is intended (we exit soon anyway) */
} else {
/* If no (more) hardlinks to output,
* output "trailer" entry */
name = trailer;
/* st.st_size == 0 is a must, but for uniformity
* in the output, we zero out everything */
memset(&st, 0, sizeof(st));
/* st.st_nlink = 1; - GNU cpio does this */
}
}
bytes += printf("070701"
"%08X%08X%08X%08X%08X%08X%08X"
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
/* strlen+1: */ "%08X"
/* chksum: */ "00000000" /* (only for "070702" files) */
/* name,NUL: */ "%s%c",
(unsigned)(uint32_t) st.st_ino,
(unsigned)(uint32_t) st.st_mode,
(unsigned)(uint32_t) st.st_uid,
(unsigned)(uint32_t) st.st_gid,
(unsigned)(uint32_t) st.st_nlink,
(unsigned)(uint32_t) st.st_mtime,
(unsigned)(uint32_t) st.st_size,
(unsigned)(uint32_t) major(st.st_dev),
(unsigned)(uint32_t) minor(st.st_dev),
(unsigned)(uint32_t) major(st.st_rdev),
(unsigned)(uint32_t) minor(st.st_rdev),
(unsigned)(strlen(name) + 1),
name, '\0');
bytes = cpio_pad4(bytes);
if (st.st_size) {
if (S_ISLNK(st.st_mode)) {
char *lpath = xmalloc_readlink_or_warn(name);
if (!lpath)
goto abort_cpio_o;
bytes += printf("%s", lpath);
free(lpath);
} else { /* S_ISREG */
int fd = xopen(name, O_RDONLY);
fflush_all();
/* We must abort if file got shorter too! */
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
bytes += st.st_size;
close(fd);
}
bytes = cpio_pad4(bytes);
}
if (!line) {
if (name != trailer)
goto next_link;
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
return EXIT_SUCCESS;
}
free(line);
} /* end of "while (1)" */
}
#endif
#define CPIO_OPT_EXTRACT 0x01
#define CPIO_OPT_TEST 0x02
#define CPIO_OPT_UNCONDITIONAL 0x04
#define CPIO_OPT_VERBOSE 0x08
#define CPIO_OPT_FILE 0x10
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
#define CPIO_OPT_PRESERVE_MTIME 0x40
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cpio_main(int argc UNUSED_PARAM, char **argv)
int cpio_main(int argc, char **argv)
{
archive_handle_t *archive_handle;
char *cpio_filename;
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
char *cpio_filename = NULL;
unsigned opt;
#if ENABLE_LONG_OPTS
applet_long_options =
"extract\0" No_argument "i"
"list\0" No_argument "t"
#if ENABLE_FEATURE_CPIO_O
"create\0" No_argument "o"
"format\0" Required_argument "H"
#if ENABLE_FEATURE_CPIO_P
"pass-through\0" No_argument "p"
#endif
#endif
"verbose\0" No_argument "v"
"quiet\0" No_argument "\xff"
"to-stdout\0" No_argument "\xfe"
;
#endif
/* Initialise */
archive_handle = init_handle();
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
archive_handle->src_fd = STDIN_FILENO;
archive_handle->seek = seek_by_read;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
/* As of now we do not enforce this: */
/* -i,-t,-o,-p are mutually exclusive */
/* -u,-d,-m make sense only with -i or -p */
/* -L makes sense only with -o or -p */
#if !ENABLE_FEATURE_CPIO_O
/* no parameters */
opt_complementary = "=0";
opt = getopt32(argv, OPTION_STR, &cpio_filename);
if (opt & CPIO_OPT_FILE) { /* -F */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}
#else
/* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */
opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0";
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
argv += optind;
if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}
if (opt & CPIO_OPT_PASSTHROUGH) {
pid_t pid;
struct fd_pair pp;
if (argv[0] == NULL)
bb_show_usage();
if (opt & CPIO_OPT_CREATE_LEADING_DIR)
mkdir(argv[0], 0777);
/* Crude existence check:
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
* We can also xopen, fstat, IS_DIR, later fchdir.
* This would check for existence earlier and cleaner.
* As it stands now, if we fail xchdir later,
* child dies on EPIPE, unless it caught
* a diffrerent problem earlier.
* This is good enough for now.
*/
#if !BB_MMU
pp.rd = 3;
pp.wr = 4;
if (!re_execed) {
close(3);
close(4);
xpiped_pair(pp);
}
#else
xpiped_pair(pp);
#endif
pid = fork_or_rexec(argv - optind);
if (pid == 0) { /* child */
close(pp.rd);
xmove_fd(pp.wr, STDOUT_FILENO);
goto dump;
}
/* parent */
xchdir(*argv++);
close(pp.wr);
xmove_fd(pp.rd, STDIN_FILENO);
//opt &= ~CPIO_OPT_PASSTHROUGH;
opt |= CPIO_OPT_EXTRACT;
goto skip;
}
/* -o */
if (opt & CPIO_OPT_CREATE) {
if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
bb_show_usage();
if (opt & CPIO_OPT_FILE) {
xmove_fd(xopen3(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666), STDOUT_FILENO);
}
dump:
return cpio_o();
}
skip:
#endif
opt = getopt32(argv, "ituvF:dm", &cpio_filename);
/* One of either extract or test options must be given */
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
@@ -384,17 +44,17 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
if (opt & CPIO_OPT_TEST) {
/* if both extract and test options are given, ignore extract option */
opt &= ~CPIO_OPT_EXTRACT;
if (opt & CPIO_OPT_EXTRACT) {
opt &= ~CPIO_OPT_EXTRACT;
}
archive_handle->action_header = header_list;
}
if (opt & CPIO_OPT_EXTRACT) {
archive_handle->action_data = data_extract_all;
if (opt & CPIO_OPT_2STDOUT)
archive_handle->action_data = data_extract_to_stdout;
}
if (opt & CPIO_OPT_UNCONDITIONAL) {
archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
}
if (opt & CPIO_OPT_VERBOSE) {
if (archive_handle->action_header == header_list) {
@@ -403,29 +63,21 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
archive_handle->action_header = header_list;
}
}
if (cpio_filename) { /* CPIO_OPT_FILE */
archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
archive_handle->seek = seek_by_jump;
}
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
}
if (opt & CPIO_OPT_PRESERVE_MTIME) {
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
}
while (*argv) {
while (optind < argc) {
archive_handle->filter = filter_accept_list;
llist_add_to(&archive_handle->accept, *argv);
argv++;
llist_add_to(&(archive_handle->accept), argv[optind]);
optind++;
}
/* see get_header_cpio */
archive_handle->cpio__blocks = (off_t)-1;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & CPIO_OPT_QUIET)
) {
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
}
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
return EXIT_SUCCESS;
}
+207 -247
View File
@@ -6,10 +6,6 @@
* written by glenn mcgrath with the help of others
* copyright (c) 2001 by glenn mcgrath
*
* parts of the version comparison code is plucked from the real dpkg
* application which is licensed GPLv2 and
* copyright (c) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
*
* started life as a busybox implementation of udpkg
*
* licensed under gplv2 or later, see file license in this tarball for details.
@@ -29,7 +25,6 @@
*/
#include "libbb.h"
#include <fnmatch.h>
#include "unarchive.h"
/* note: if you vary hash_prime sizes be aware,
@@ -80,21 +75,10 @@ typedef struct status_node_s {
unsigned status:16; /* was:14 */ /* has to fit STATUS_HASH_PRIME */
} status_node_t;
/* Globals */
struct globals {
char *name_hashtable[NAME_HASH_PRIME + 1];
common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1];
status_node_t *status_hashtable[STATUS_HASH_PRIME + 1];
};
#define G (*ptr_to_globals)
#define name_hashtable (G.name_hashtable )
#define package_hashtable (G.package_hashtable)
#define status_hashtable (G.status_hashtable )
#define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0)
/* Were statically declared here, but such a big bss is nommu-unfriendly */
static char **name_hashtable; /* [NAME_HASH_PRIME + 1] */
static common_node_t **package_hashtable; /* [PACKAGE_HASH_PRIME + 1] */
static status_node_t **status_hashtable; /* [STATUS_HASH_PRIME + 1] */
/* Even numbers are for 'extras', like ored dependencies or null */
enum edge_type_e {
@@ -139,8 +123,8 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
/* shifts the ascii based value and adds it to previous value
* shift amount is mod 24 because long int is 32 bit and data
* to be shifted is 8, don't want to shift data to where it has
* no effect */
hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
* no effect*/
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
}
*start = (unsigned) hash_num % hash_prime;
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
@@ -149,8 +133,8 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
/* this adds the key to the hash table */
static int search_name_hashtable(const char *key)
{
unsigned probe_address;
unsigned probe_decrement;
unsigned probe_address = 0;
unsigned probe_decrement = 0;
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
while (name_hashtable[probe_address] != NULL) {
@@ -171,8 +155,8 @@ static int search_name_hashtable(const char *key)
*/
static unsigned search_status_hashtable(const char *key)
{
unsigned probe_address;
unsigned probe_decrement;
unsigned probe_address = 0;
unsigned probe_decrement = 0;
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
while (status_hashtable[probe_address] != NULL) {
@@ -187,52 +171,60 @@ static unsigned search_status_hashtable(const char *key)
return probe_address;
}
static int order(char x)
/* Need to rethink version comparison, maybe the official dpkg has something i can use ? */
static int version_compare_part(const char *version1, const char *version2)
{
return (x == '~' ? -1
: x == '\0' ? 0
: isdigit(x) ? 0
: isalpha(x) ? x
: (unsigned char)x + 256
);
}
int upstream_len1 = 0;
int upstream_len2 = 0;
char *name1_char;
char *name2_char;
int len1 = 0;
int len2 = 0;
int tmp_int;
int ver_num1;
int ver_num2;
/* This code is taken from dpkg and modified slightly to work with busybox */
static int version_compare_part(const char *val, const char *ref)
{
if (!val) val = "";
if (!ref) ref = "";
if (version1 == NULL) {
version1 = xstrdup("");
}
if (version2 == NULL) {
version2 = xstrdup("");
}
upstream_len1 = strlen(version1);
upstream_len2 = strlen(version2);
while (*val || *ref) {
int first_diff;
while ((*val && !isdigit(*val)) || (*ref && !isdigit(*ref))) {
int vc = order(*val);
int rc = order(*ref);
if (vc != rc)
return vc - rc;
val++;
ref++;
while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
/* Compare non-digit section */
tmp_int = strcspn(&version1[len1], "0123456789");
name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strcspn(&version2[len2], "0123456789");
name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
tmp_int = strcmp(name1_char, name2_char);
free(name1_char);
free(name2_char);
if (tmp_int != 0) {
return tmp_int;
}
while (*val == '0')
val++;
while (*ref == '0')
ref++;
first_diff = 0;
while (isdigit(*val) && isdigit(*ref)) {
if (first_diff == 0)
first_diff = *val - *ref;
val++;
ref++;
}
if (isdigit(*val))
return 1;
if (isdigit(*ref))
/* Compare digits */
tmp_int = strspn(&version1[len1], "0123456789");
name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strspn(&version2[len2], "0123456789");
name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
ver_num1 = atoi(name1_char);
ver_num2 = atoi(name2_char);
free(name1_char);
free(name2_char);
if (ver_num1 < ver_num2) {
return -1;
if (first_diff)
return first_diff;
}
if (ver_num1 > ver_num2) {
return 1;
}
}
return 0;
}
@@ -245,34 +237,39 @@ static int version_compare(const unsigned ver1, const unsigned ver2)
{
char *ch_ver1 = name_hashtable[ver1];
char *ch_ver2 = name_hashtable[ver2];
unsigned long epoch1 = 0, epoch2 = 0;
char *colon;
char epoch1, epoch2;
char *deb_ver1, *deb_ver2;
char *ver1_ptr, *ver2_ptr;
char *upstream_ver1;
char *upstream_ver2;
int result;
/* Compare epoch */
colon = strchr(ch_ver1, ':');
if (colon) {
epoch1 = atoi(ch_ver1);
ch_ver1 = colon + 1;
if (ch_ver1[1] == ':') {
epoch1 = ch_ver1[0];
ver1_ptr = strchr(ch_ver1, ':') + 1;
} else {
epoch1 = '0';
ver1_ptr = ch_ver1;
}
colon = strchr(ch_ver2, ':');
if (colon) {
epoch2 = atoi(ch_ver2);
ch_ver2 = colon + 1;
if (ch_ver2[1] == ':') {
epoch2 = ch_ver2[0];
ver2_ptr = strchr(ch_ver2, ':') + 1;
} else {
epoch2 = '0';
ver2_ptr = ch_ver2;
}
if (epoch1 < epoch2) {
return -1;
}
if (epoch1 > epoch2) {
else if (epoch1 > epoch2) {
return 1;
}
/* Compare upstream version */
upstream_ver1 = xstrdup(ch_ver1);
upstream_ver2 = xstrdup(ch_ver2);
upstream_ver1 = xstrdup(ver1_ptr);
upstream_ver2 = xstrdup(ver2_ptr);
/* Chop off debian version, and store for later use */
deb_ver1 = strrchr(upstream_ver1, '-');
@@ -315,10 +312,11 @@ static int test_version(const unsigned version1, const unsigned version2, const
return FALSE;
}
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
{
unsigned probe_address;
unsigned probe_decrement;
unsigned probe_address = 0;
unsigned probe_decrement = 0;
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
while (package_hashtable[probe_address] != NULL) {
@@ -374,8 +372,9 @@ static int search_for_provides(int needle, int start_at)
*/
static void add_edge_to_node(common_node_t *node, edge_t *edge)
{
node->edge = xrealloc_vector(node->edge, 2, node->num_of_edges);
node->edge[node->num_of_edges++] = edge;
node->num_of_edges++;
node->edge = xrealloc(node->edge, sizeof(edge_t) * (node->num_of_edges + 1));
node->edge[node->num_of_edges - 1] = edge;
}
/*
@@ -411,10 +410,10 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS)
&& (strcmp(field, field2) != 0)
) {
or_edge = xzalloc(sizeof(edge_t));
or_edge = xmalloc(sizeof(edge_t));
or_edge->type = edge_type + 1;
or_edge->name = search_name_hashtable(field);
//or_edge->version = 0; // tracks the number of alternatives
or_edge->version = 0; // tracks the number of alternatives
add_edge_to_node(parent_node, or_edge);
}
@@ -440,13 +439,17 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
if (offset_ch > 0) {
if (strncmp(version, "=", offset_ch) == 0) {
edge->operator = VER_EQUAL;
} else if (strncmp(version, "<<", offset_ch) == 0) {
}
else if (strncmp(version, "<<", offset_ch) == 0) {
edge->operator = VER_LESS;
} else if (strncmp(version, "<=", offset_ch) == 0) {
}
else if (strncmp(version, "<=", offset_ch) == 0) {
edge->operator = VER_LESS_EQUAL;
} else if (strncmp(version, ">>", offset_ch) == 0) {
}
else if (strncmp(version, ">>", offset_ch) == 0) {
edge->operator = VER_MORE;
} else if (strncmp(version, ">=", offset_ch) == 0) {
}
else if (strncmp(version, ">=", offset_ch) == 0) {
edge->operator = VER_MORE_EQUAL;
} else {
bb_error_msg_and_die("illegal operator");
@@ -493,7 +496,7 @@ static void free_package(common_node_t *node)
}
/*
* Gets the next package field from package_buffer, separated into the field name
* Gets the next package field from package_buffer, seperated 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 *package_buffer, char **field_name, char **field_value)
@@ -599,7 +602,7 @@ static unsigned fill_package_struct(char *control_buffer)
&field_name, &field_value);
if (field_name == NULL) {
goto fill_package_struct_cleanup;
goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement! */
}
field_num = index_in_strings(field_names, field_name);
@@ -732,6 +735,7 @@ static const char *describe_status(int status_num)
return "is not installed or flagged to be installed";
}
static void index_status_file(const char *filename)
{
FILE *status_file;
@@ -740,8 +744,8 @@ static void index_status_file(const char *filename)
status_node_t *status_node = NULL;
unsigned status_num;
status_file = xfopen_for_read(filename);
while ((control_buffer = xmalloc_fgetline_str(status_file, "\n\n")) != NULL) {
status_file = xfopen(filename, "r");
while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) {
const unsigned package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
status_node = xmalloc(sizeof(status_node_t));
@@ -782,8 +786,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
/* This could do with a cleanup */
static void write_status_file(deb_file_t **deb_file)
{
FILE *old_status_file = xfopen_for_read("/var/lib/dpkg/status");
FILE *new_status_file = xfopen_for_write("/var/lib/dpkg/status.udeb");
FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
char *package_name;
char *status_from_file;
char *control_buffer = NULL;
@@ -794,7 +798,7 @@ static void write_status_file(deb_file_t **deb_file)
int i = 0;
/* Update previously known packages */
while ((control_buffer = xmalloc_fgetline_str(old_status_file, "\n\n")) != NULL) {
while ((control_buffer = xmalloc_fgets_str(old_status_file, "\n\n")) != NULL) {
tmp_string = strstr(control_buffer, "Package:");
if (tmp_string == NULL) {
continue;
@@ -806,7 +810,7 @@ static void write_status_file(deb_file_t **deb_file)
write_flag = FALSE;
tmp_string = strstr(control_buffer, "Status:");
if (tmp_string != NULL) {
/* Separate the status value from the control buffer */
/* Seperate 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"));
@@ -909,16 +913,20 @@ static void write_status_file(deb_file_t **deb_file)
fclose(old_status_file);
fclose(new_status_file);
/* Create a separate backfile to dpkg */
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
if (errno != ENOENT)
bb_error_msg_and_die("can't create backup status file");
struct stat stat_buf;
xstat("/var/lib/dpkg/status", &stat_buf);
/* Its ok if renaming the status file fails because status
* file doesnt exist, maybe we are starting from scratch */
bb_error_msg("no status file found, creating new one");
}
xrename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status");
if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) {
bb_error_msg_and_die("DANGER: cannot create status file, "
"you need to manually repair your status file");
}
}
/* This function returns TRUE if the given package can satisfy a
@@ -945,7 +953,7 @@ static int package_satisfies_dependency(int package, int depend_type)
return 0;
}
static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count - ?? */)
static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
{
int *conflicts = NULL;
int conflicts_num = 0;
@@ -963,7 +971,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
* installed package for conflicts*/
while (deb_file[i] != NULL) {
const unsigned package_num = deb_file[i]->package;
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
conflicts[conflicts_num] = package_num;
conflicts_num++;
/* add provides to conflicts list */
@@ -980,7 +988,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
new_node->version = package_hashtable[package_num]->edge[j]->version;
package_hashtable[conflicts_package_num] = new_node;
}
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
conflicts[conflicts_num] = conflicts_package_num;
conflicts_num++;
}
@@ -1148,25 +1156,27 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
static char **create_list(const char *filename)
{
FILE *list_stream;
char **file_list;
char *line;
int count;
char **file_list = NULL;
char *line = NULL;
int count = 0;
/* don't use [xw]fopen here, handle error ourself */
list_stream = fopen_for_read(filename);
list_stream = fopen(filename, "r");
if (list_stream == NULL) {
return NULL;
}
file_list = NULL;
count = 0;
while ((line = xmalloc_fgetline(list_stream)) != NULL) {
file_list = xrealloc_vector(file_list, 2, count);
file_list[count++] = line;
/*file_list[count] = NULL; - xrealloc_vector did it */
while ((line = xmalloc_getline(list_stream)) != NULL) {
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
file_list[count] = line;
count++;
}
fclose(list_stream);
if (count == 0) {
return NULL;
}
file_list[count] = NULL;
return file_list;
}
@@ -1203,54 +1213,24 @@ static int remove_file_array(char **remove_names, char **exclude_names)
return (remove_flag == 0);
}
static void run_package_script_or_die(const char *package_name, const char *script_type)
static int run_package_script(const char *package_name, const char *script_type)
{
struct stat path_stat;
char *script_path;
int result;
script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesnt exist is isnt fatal */
result = access(script_path, F_OK) ? EXIT_SUCCESS : system(script_path);
/* If the file doesnt exist is isnt a fatal */
result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
free(script_path);
if (result)
bb_error_msg_and_die("%s failed, exit code %d", script_type, result);
return result;
}
/*
The policy manual defines what scripts get called when and with
what arguments. I realize that busybox does not support all of
these scenarios, but it does support some of them; it does not,
however, run them with any parameters in run_package_script_or_die().
Here are the scripts:
preinst install
preinst install <old_version>
preinst upgrade <old_version>
preinst abort_upgrade <new_version>
postinst configure <most_recent_version>
postinst abort-upgade <new_version>
postinst abort-remove
postinst abort-remove in-favour <package> <version>
postinst abort-deconfigure in-favor <failed_install_package> removing <conflicting_package> <version>
prerm remove
prerm upgrade <new_version>
prerm failed-upgrade <old_version>
prerm remove in-favor <package> <new_version>
prerm deconfigure in-favour <package> <version> removing <package> <version>
postrm remove
postrm purge
postrm upgrade <new_version>
postrm failed-upgrade <old_version>
postrm abort-install
postrm abort-install <old_version>
postrm abort-upgrade <old_version>
postrm disappear <overwriter> <version>
*/
static const char *const all_control_files[] = {
"preinst", "postinst", "prerm", "postrm",
"list", "md5sums", "shlibs", "conffiles",
"config", "templates"
"config", "templates", NULL
};
static char **all_control_list(const char *package_name)
@@ -1259,10 +1239,9 @@ static char **all_control_list(const char *package_name)
char **remove_files;
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = xzalloc(sizeof(all_control_files) + sizeof(char*));
while (i < ARRAY_SIZE(all_control_files)) {
remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s",
package_name, all_control_files[i]);
remove_files = xzalloc(sizeof(all_control_files));
while (all_control_files[i]) {
remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
i++;
}
@@ -1285,7 +1264,7 @@ static void free_array(char **array)
* the status_hashtable to retrieve the info. This results in smaller code than
* scanning the status file. The resulting list, however, is unsorted.
*/
static void list_packages(const char *pattern)
static void list_packages(void)
{
int i;
@@ -1306,9 +1285,6 @@ static void list_packages(const char *pattern)
name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
if (pattern && fnmatch(pattern, name_str, 0))
continue;
/* get abbreviation for status field 1 */
s1 = stat_str[0] == 'i' ? 'i' : 'r';
@@ -1338,26 +1314,27 @@ static void remove_package(const unsigned package_num, int noisy)
if (noisy)
printf("Removing %s (%s)...\n", package_name, package_version);
/* Run prerm script */
run_package_script_or_die(package_name, "prerm");
/* run prerm script */
if (run_package_script(package_name, "prerm") != 0) {
bb_error_msg_and_die("script failed, prerm failure");
}
/* Create a list of files to remove, and a separate list of those to keep */
sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
remove_files = create_list(list_name);
sprintf(conffile_name, "/var/lib/dpkg/info/%s.%s", package_name, "conffiles");
sprintf(conffile_name, "/var/lib/dpkg/info/%s.conffiles", package_name);
exclude_files = create_list(conffile_name);
/* Some directories can't be removed straight away, so do multiple passes */
while (remove_file_array(remove_files, exclude_files))
continue;
while (remove_file_array(remove_files, exclude_files)) /*repeat */;
free_array(exclude_files);
free_array(remove_files);
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
exclude_files = xzalloc(sizeof(exclude_files[0]) * 3);
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
exclude_files = xzalloc(sizeof(char*) * 3);
exclude_files[0] = xstrdup(conffile_name);
exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = all_control_list(package_name);
@@ -1366,9 +1343,7 @@ static void remove_package(const unsigned package_num, int noisy)
free_array(remove_files);
free_array(exclude_files);
/* rename <package>.conffiles to <package>.list
* The conffiles control file isn't required in Debian packages, so don't
* error out if it's missing. */
/* rename <package>.conffile to <package>.list */
rename(conffile_name, list_name);
/* Change package status */
@@ -1386,32 +1361,31 @@ static void purge_package(const unsigned package_num)
printf("Purging %s (%s)...\n", package_name, package_version);
/* Run prerm script */
run_package_script_or_die(package_name, "prerm");
/* run prerm script */
if (run_package_script(package_name, "prerm") != 0) {
bb_error_msg_and_die("script failed, prerm failure");
}
/* Create a list of files to remove */
sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
remove_files = create_list(list_name);
exclude_files = xzalloc(sizeof(char*));
/* Some directories cant be removed straight away, so do multiple passes */
while (remove_file_array(remove_files, NULL))
continue;
while (remove_file_array(remove_files, exclude_files)) /* repeat */;
free_array(remove_files);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = all_control_list(package_name);
/* Delete all of them except the postrm script */
exclude_files = xzalloc(sizeof(exclude_files[0]) * 2);
exclude_files[0] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
remove_file_array(remove_files, exclude_files);
free_array(exclude_files);
/* Run and remove postrm script */
run_package_script_or_die(package_name, "postrm");
remove_file_array(remove_files, NULL);
free_array(remove_files);
free(exclude_files);
/* run postrm script */
if (run_package_script(package_name, "postrm") != 0) {
bb_error_msg_and_die("postrm failure.. set status to what?");
}
/* Change package status */
set_status(status_num, "not-installed", 3);
@@ -1438,15 +1412,15 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
tar_handle->src_fd = ar_handle->src_fd;
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
#if ENABLE_FEATURE_SEAMLESS_GZ
#if ENABLE_FEATURE_DEB_TAR_GZ
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_DEB_TAR_BZ2
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
#endif
/* Assign the tar handle as a subarchive of the ar handle */
ar_handle->dpkg__sub_archive = tar_handle;
ar_handle->sub_archive = tar_handle;
}
static void init_archive_deb_data(archive_handle_t *ar_handle)
@@ -1458,55 +1432,36 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
tar_handle->src_fd = ar_handle->src_fd;
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
#if ENABLE_FEATURE_SEAMLESS_GZ
#if ENABLE_FEATURE_DEB_TAR_GZ
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_DEB_TAR_BZ2
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
#endif
/* Assign the tar handle as a subarchive of the ar handle */
ar_handle->dpkg__sub_archive = tar_handle;
}
static void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
{
unsigned size = archive_handle->file_header->size;
archive_handle->dpkg__buffer = xzalloc(size + 1);
xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
ar_handle->sub_archive = tar_handle;
}
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
{
ar_handle->dpkg__sub_archive->action_data = data_extract_to_buffer;
ar_handle->dpkg__sub_archive->accept = myaccept;
ar_handle->dpkg__sub_archive->filter = filter_accept_list;
ar_handle->sub_archive->action_data = data_extract_to_buffer;
ar_handle->sub_archive->accept = myaccept;
ar_handle->sub_archive->filter = filter_accept_list;
unpack_ar_archive(ar_handle);
close(ar_handle->src_fd);
return ar_handle->dpkg__sub_archive->dpkg__buffer;
return ar_handle->sub_archive->buffer;
}
static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
static void data_extract_all_prefix(archive_handle_t *archive_handle)
{
char *name_ptr = archive_handle->file_header->name;
/* Skip all leading "/" */
while (*name_ptr == '/')
name_ptr++;
/* Skip all leading "./" and "../" */
while (name_ptr[0] == '.') {
if (name_ptr[1] == '.' && name_ptr[2] == '/')
name_ptr++;
if (name_ptr[1] != '/')
break;
name_ptr += 2;
}
name_ptr += strspn(name_ptr, "./");
if (name_ptr[0] != '\0') {
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
data_extract_all(archive_handle);
}
}
@@ -1520,8 +1475,8 @@ static void unpack_package(deb_file_t *deb_file)
char *list_filename;
archive_handle_t *archive_handle;
FILE *out_stream;
llist_t *accept_list;
int i;
llist_t *accept_list = NULL;
int i = 0;
/* If existing version, remove it first */
if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
@@ -1535,43 +1490,44 @@ static void unpack_package(deb_file_t *deb_file)
}
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
info_prefix = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "");
info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name);
archive_handle = init_archive_deb_ar(deb_file->filename);
init_archive_deb_control(archive_handle);
accept_list = NULL;
i = 0;
while (i < ARRAY_SIZE(all_control_files)) {
while (all_control_files[i]) {
char *c = xasprintf("./%s", all_control_files[i]);
llist_add_to(&accept_list, c);
i++;
}
archive_handle->dpkg__sub_archive->accept = accept_list;
archive_handle->dpkg__sub_archive->filter = filter_accept_list;
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
archive_handle->dpkg__sub_archive->dpkg__buffer = info_prefix;
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
archive_handle->sub_archive->accept = accept_list;
archive_handle->sub_archive->filter = filter_accept_list;
archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = info_prefix;
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle);
/* Run the preinst prior to extracting */
run_package_script_or_die(package_name, "preinst");
if (run_package_script(package_name, "preinst") != 0) {
/* when preinst returns exit code != 0 then quit installation process */
bb_error_msg_and_die("subprocess pre-installation script returned error");
}
/* Extract data.tar.gz to the root directory */
archive_handle = init_archive_deb_ar(deb_file->filename);
init_archive_deb_data(archive_handle);
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle);
/* Create the list file */
list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
out_stream = xfopen_for_write(list_filename);
while (archive_handle->dpkg__sub_archive->passed) {
list_filename = xasprintf("/var/lib/dpkg/info/%s.list", package_name);
out_stream = xfopen(list_filename, "w");
while (archive_handle->sub_archive->passed) {
/* the leading . has been stripped by data_extract_all_prefix already */
fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream);
fputs(archive_handle->sub_archive->passed->data, out_stream);
fputc('\n', out_stream);
archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link;
archive_handle->sub_archive->passed = archive_handle->sub_archive->passed->link;
}
fclose(out_stream);
@@ -1592,16 +1548,17 @@ static void configure_package(deb_file_t *deb_file)
printf("Setting up %s (%s)...\n", package_name, package_version);
/* Run the postinst script */
/* TODO: handle failure gracefully */
run_package_script_or_die(package_name, "postinst");
if (run_package_script(package_name, "postinst") != 0) {
/* TODO: handle failure gracefully */
bb_error_msg_and_die("postinst failure.. set status to what?");
}
/* Change status to reflect success */
set_status(status_num, "install", 1);
set_status(status_num, "installed", 3);
}
int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dpkg_main(int argc UNUSED_PARAM, char **argv)
int dpkg_main(int argc, char **argv)
{
deb_file_t **deb_file = NULL;
status_node_t *status_node;
@@ -1622,8 +1579,6 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
OPT_unpack = 0x40,
};
INIT_G();
opt = getopt32(argv, "CF:ilPru", &str_f);
//if (opt & OPT_configure) ... // -C
if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
@@ -1635,24 +1590,29 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
//if (opt & OPT_purge) ... // -P
//if (opt & OPT_remove) ... // -r
//if (opt & OPT_unpack) ... // -u (--unpack in official dpkg)
argc -= optind;
argv += optind;
/* check for non-option argument if expected */
if (!opt || (!argv[0] && !(opt && OPT_list_installed)))
if (!opt || (!argc && !(opt && OPT_list_installed)))
bb_show_usage();
name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
/* puts("(Reading database ... xxxxx files and directories installed.)"); */
index_status_file("/var/lib/dpkg/status");
/* if the list action was given print the installed packages and exit */
if (opt & OPT_list_installed) {
list_packages(argv[0]);
list_packages();
return EXIT_SUCCESS;
}
/* Read arguments and store relevant info in structs */
while (*argv) {
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
deb_file = xrealloc_vector(deb_file, 2, deb_count);
deb_file = xrealloc(deb_file, sizeof(deb_file[0]) * (deb_count + 2));
deb_file[deb_count] = xzalloc(sizeof(deb_file[0][0]));
if (opt & (OPT_install | OPT_unpack)) {
/* -i/-u: require filename */
@@ -1665,7 +1625,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_error_msg_and_die("can't extract control file");
bb_error_msg_and_die("cannot extract control file");
}
deb_file[deb_count]->filename = xstrdup(argv[0]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
@@ -1733,7 +1693,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
/* Check that the deb file arguments are installable */
if (!(opt & OPT_force_ignore_depends)) {
if (!check_deps(deb_file, 0 /*, deb_count*/)) {
if (!check_deps(deb_file, 0, deb_count)) {
bb_error_msg_and_die("dependency check failed");
}
}
+15 -22
View File
@@ -20,44 +20,40 @@ int dpkg_deb_main(int argc, char **argv)
archive_handle_t *tar_archive;
llist_t *control_tar_llist = NULL;
unsigned opt;
const char *extract_dir;
int need_args;
const char *extract_dir = NULL;
short argcount = 1;
/* Setup the tar archive handle */
tar_archive = init_handle();
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_archive = init_handle();
ar_archive->dpkg__sub_archive = tar_archive;
ar_archive->sub_archive = tar_archive;
ar_archive->filter = filter_accept_list_reassign;
#if ENABLE_FEATURE_SEAMLESS_GZ
#if ENABLE_FEATURE_DEB_TAR_GZ
llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz");
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_DEB_TAR_BZ2
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
#endif
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argv, "cefXx");
argv += optind;
argc -= optind;
if (opt & DPKG_DEB_OPT_CONTENTS) {
tar_archive->action_header = header_verbose_list;
}
extract_dir = NULL;
need_args = 1;
if (opt & DPKG_DEB_OPT_CONTROL) {
ar_archive->accept = control_tar_llist;
tar_archive->action_data = data_extract_all;
if (1 == argc) {
if (optind + 1 == argc) {
extract_dir = "./DEBIAN";
} else {
need_args++;
argcount++;
}
}
if (opt & DPKG_DEB_OPT_FIELD) {
@@ -74,31 +70,28 @@ int dpkg_deb_main(int argc, char **argv)
}
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
tar_archive->action_data = data_extract_all;
need_args = 2;
argcount = 2;
}
if (need_args != argc) {
if ((optind + argcount) != argc) {
bb_show_usage();
}
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
/* Work out where to extract the files */
/* Workout where to extract the files */
/* 2nd argument is a dir name */
if (argv[1]) {
extract_dir = argv[1];
if (argv[optind]) {
extract_dir = argv[optind];
}
if (extract_dir) {
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
xchdir(extract_dir);
}
/* Do it */
unpack_ar_archive(ar_archive);
/* Cleanup */
if (ENABLE_FEATURE_CLEAN_UP)
close(ar_archive->src_fd);
close(ar_archive->src_fd);
return EXIT_SUCCESS;
}
+45 -78
View File
@@ -40,7 +40,6 @@ aa: 85.1% -- replaced with aa.gz
*/
#include "libbb.h"
#include "unarchive.h"
/* ===========================================================================
@@ -267,7 +266,7 @@ struct globals {
#define DECLARE(type, array, size) \
type * array
#define ALLOC(type, array, size) \
array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type))
array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type));
#define FREE(array) \
do { free(array); array = NULL; } while (0)
@@ -388,6 +387,19 @@ static void put_32bit(ulg n)
put_16bit(n >> 16);
}
/* ===========================================================================
* Clear input and output buffers
*/
static void clear_bufs(void)
{
G1.outcnt = 0;
#ifdef DEBUG
G1.insize = 0;
#endif
G1.isize = 0;
}
/* ===========================================================================
* Run a set of bytes through the crc shift register. If s is a NULL
* pointer, then initialize the crc shift register contents instead.
@@ -1173,7 +1185,7 @@ static void gen_codes(ct_data * tree, int max_code)
Tracec(tree != G2.static_ltree,
(stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
(n > ' ' ? n : ' '), len, tree[n].Code,
(isgraph(n) ? n : ' '), len, tree[n].Code,
next_code[len] - 1));
}
}
@@ -1541,7 +1553,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
lc = G1.l_buf[lx++];
if ((flag & 1) == 0) {
SEND_CODE(lc, ltree); /* send a literal byte */
Tracecv(lc > ' ', (stderr, " '%c' ", lc));
Tracecv(isgraph(lc), (stderr, " '%c' ", lc));
} else {
/* Here, lc is the match length - MIN_MATCH */
code = G2.length_code[lc];
@@ -2002,94 +2014,26 @@ char* make_new_name_gzip(char *filename)
}
static
IF_DESKTOP(long long) int pack_gzip(unpack_info_t *info UNUSED_PARAM)
USE_DESKTOP(long long) int pack_gzip(void)
{
struct stat s;
/* Clear input and output buffers */
G1.outcnt = 0;
#ifdef DEBUG
G1.insize = 0;
#endif
G1.isize = 0;
/* Reinit G2.xxx */
memset(&G2, 0, sizeof(G2));
G2.l_desc.dyn_tree = G2.dyn_ltree;
G2.l_desc.static_tree = G2.static_ltree;
G2.l_desc.extra_bits = extra_lbits;
G2.l_desc.extra_base = LITERALS + 1;
G2.l_desc.elems = L_CODES;
G2.l_desc.max_length = MAX_BITS;
//G2.l_desc.max_code = 0;
G2.d_desc.dyn_tree = G2.dyn_dtree;
G2.d_desc.static_tree = G2.static_dtree;
G2.d_desc.extra_bits = extra_dbits;
//G2.d_desc.extra_base = 0;
G2.d_desc.elems = D_CODES;
G2.d_desc.max_length = MAX_BITS;
//G2.d_desc.max_code = 0;
G2.bl_desc.dyn_tree = G2.bl_tree;
//G2.bl_desc.static_tree = NULL;
G2.bl_desc.extra_bits = extra_blbits,
//G2.bl_desc.extra_base = 0;
G2.bl_desc.elems = BL_CODES;
G2.bl_desc.max_length = MAX_BL_BITS;
//G2.bl_desc.max_code = 0;
clear_bufs();
s.st_ctime = 0;
fstat(STDIN_FILENO, &s);
zip(s.st_ctime);
return 0;
}
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
static const char gzip_longopts[] ALIGN1 =
"stdout\0" No_argument "c"
"to-stdout\0" No_argument "c"
"force\0" No_argument "f"
"verbose\0" No_argument "v"
#if ENABLE_GUNZIP
"decompress\0" No_argument "d"
"uncompress\0" No_argument "d"
"test\0" No_argument "t"
#endif
"quiet\0" No_argument "q"
"fast\0" No_argument "1"
"best\0" No_argument "9"
;
#endif
/*
* Linux kernel build uses gzip -d -n. We accept and ignore it.
* Man page says:
* -n --no-name
* gzip: do not save the original file name and time stamp.
* (The original name is always saved if the name had to be truncated.)
* gunzip: do not restore the original file name/time even if present
* (remove only the gzip suffix from the compressed file name).
* This option is the default when decompressing.
* -N --name
* gzip: always save the original file name and time stamp (this is the default)
* gunzip: restore the original file name and time stamp if present.
*/
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if ENABLE_GUNZIP
int gzip_main(int argc, char **argv)
#else
int gzip_main(int argc UNUSED_PARAM, char **argv)
#endif
{
unsigned opt;
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
applet_long_options = gzip_longopts;
#endif
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" );
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x18) // -d and/or -t
if (opt & 0x8) // -d
return gunzip_main(argc, argv);
#endif
option_mask32 &= 0x7; /* ignore -q, -0..9 */
@@ -2098,8 +2042,31 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
//if (opt & 0x4) // -v
argv += optind;
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
+ sizeof(struct globals));
PTR_TO_GLOBALS = xzalloc(sizeof(struct globals) + sizeof(struct globals2))
+ sizeof(struct globals);
G2.l_desc.dyn_tree = G2.dyn_ltree;
G2.l_desc.static_tree = G2.static_ltree;
G2.l_desc.extra_bits = extra_lbits;
G2.l_desc.extra_base = LITERALS + 1;
G2.l_desc.elems = L_CODES;
G2.l_desc.max_length = MAX_BITS;
//G2.l_desc.max_code = 0;
G2.d_desc.dyn_tree = G2.dyn_dtree;
G2.d_desc.static_tree = G2.static_dtree;
G2.d_desc.extra_bits = extra_dbits;
//G2.d_desc.extra_base = 0;
G2.d_desc.elems = D_CODES;
G2.d_desc.max_length = MAX_BITS;
//G2.d_desc.max_code = 0;
G2.bl_desc.dyn_tree = G2.bl_tree;
//G2.bl_desc.static_tree = NULL;
G2.bl_desc.extra_bits = extra_blbits,
//G2.bl_desc.extra_base = 0;
G2.bl_desc.elems = BL_CODES;
G2.bl_desc.max_length = MAX_BL_BITS;
//G2.bl_desc.max_code = 0;
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, G1.l_buf, INBUFSIZ);
-93
View File
@@ -1,93 +0,0 @@
/*
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "liblzo_interface.h"
/* lzo-2.03/src/config1x.h */
#define M2_MIN_LEN 3
#define M2_MAX_LEN 8
#define M3_MAX_LEN 33
#define M4_MAX_LEN 9
#define M1_MAX_OFFSET 0x0400
#define M2_MAX_OFFSET 0x0800
#define M3_MAX_OFFSET 0x4000
#define M4_MAX_OFFSET 0xbfff
#define M1_MARKER 0
#define M3_MARKER 32
#define M4_MARKER 16
#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
#define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
#define LZO_EOF_CODE
/* lzo-2.03/src/lzo_dict.h */
#define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
#define DX2(p,s1,s2) \
(((((unsigned)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
//#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
//#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
#define D_SIZE (1U << D_BITS)
#define D_MASK ((1U << D_BITS) - 1)
#define D_HIGH ((D_MASK >> 1) + 1)
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
( \
m_pos = ip - (unsigned)(ip - m_pos), \
((uintptr_t)m_pos < (uintptr_t)in \
|| (m_off = (unsigned)(ip - m_pos)) <= 0 \
|| m_off > max_offset) \
)
#define DENTRY(p,in) (p)
#define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
#define DMS(v,s) ((unsigned) (((v) & (D_MASK >> (s))) << (s)))
#define DM(v) ((unsigned) ((v) & D_MASK))
#define DMUL(a,b) ((unsigned) ((a) * (b)))
/* lzo-2.03/src/lzo_ptr.h */
#define pd(a,b) ((unsigned)((a)-(b)))
# define TEST_IP (ip < ip_end)
# define NEED_IP(x) \
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
# undef TEST_OP /* don't need both of the tests here */
# define TEST_OP 1
# define NEED_OP(x) \
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
#define HAVE_ANY_OP 1
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
//# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
//#else
//# define TEST_LB(m_pos) ((void) 0)
//# define TEST_LBO(m_pos,o) ((void) 0)
//#endif
-71
View File
@@ -1,71 +0,0 @@
/*
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define LZO1X
#undef LZO1Y
#undef assert
/*
static void die_at(int line)
{
bb_error_msg_and_die("internal error at %d", line);
}
#define assert(v) if (!(v)) die_at(__LINE__)
*/
#define assert(v) ((void)0)
int lzo1x_1_compress(const uint8_t* src, unsigned src_len,
uint8_t* dst, unsigned* dst_len,
void* wrkmem);
int lzo1x_1_15_compress(const uint8_t* src, unsigned src_len,
uint8_t* dst, unsigned* dst_len,
void* wrkmem);
int lzo1x_999_compress_level(const uint8_t* in, unsigned in_len,
uint8_t* out, unsigned* out_len,
void* wrkmem,
int compression_level);
/* decompression */
//int lzo1x_decompress(const uint8_t* src, unsigned src_len,
// uint8_t* dst, unsigned* dst_len,
// void* wrkmem /* NOT USED */);
/* safe decompression with overrun testing */
int lzo1x_decompress_safe(const uint8_t* src, unsigned src_len,
uint8_t* dst, unsigned* dst_len,
void* wrkmem /* NOT USED */);
#define LZO_E_OK 0
#define LZO_E_ERROR (-1)
#define LZO_E_OUT_OF_MEMORY (-2) /* [not used right now] */
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
#define LZO_E_INPUT_OVERRUN (-4)
#define LZO_E_OUTPUT_OVERRUN (-5)
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
#define LZO_E_EOF_NOT_FOUND (-7)
#define LZO_E_INPUT_NOT_CONSUMED (-8)
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
/* lzo-2.03/include/lzo/lzoconf.h */
#define LZO_VERSION 0x2030
+23 -12
View File
@@ -4,13 +4,12 @@
#
# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
lib-y:=
COMMON_FILES:= \
lib-y:= \
\
data_skip.o \
data_extract_all.o \
data_extract_to_stdout.o \
data_extract_to_buffer.o \
\
filter_accept_all.o \
filter_accept_list.o \
@@ -19,6 +18,8 @@ COMMON_FILES:= \
header_skip.o \
header_list.o \
header_verbose_list.o \
\
archive_xread_all_eof.o \
\
seek_by_read.o \
seek_by_jump.o \
@@ -33,24 +34,34 @@ DPKG_FILES:= \
get_header_tar.o \
filter_accept_list_reassign.o
lib-$(CONFIG_RPM) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
lib-$(CONFIG_CPIO) += get_header_cpio.o
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_GUNZIP) += decompress_unzip.o
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
lib-$(CONFIG_TAR) += get_header_tar.o
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNZIP) += decompress_unzip.o
lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o
lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
ifneq ($(lib-y),)
lib-y += $(COMMON_FILES)
endif
@@ -0,0 +1,20 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h"
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
unsigned char *buf, size_t count)
{
ssize_t size;
size = full_read(archive_handle->src_fd, buf, count);
if (size != 0 && size != count) {
bb_error_msg_and_die("short read: %u of %u",
(unsigned)size, (unsigned)count);
}
return size;
}
+5 -3
View File
@@ -3,13 +3,15 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
//#include <sys/types.h>
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
{
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
archive_handle->seek(archive_handle->src_fd, skip_amount);
archive_handle->seek(archive_handle, skip_amount);
archive_handle->offset += skip_amount;
}
+38 -68
View File
@@ -6,41 +6,39 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
void data_extract_all(archive_handle_t *archive_handle)
{
file_header_t *file_header = archive_handle->file_header;
int dst_fd;
int res;
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *slash = strrchr(file_header->name, '/');
if (slash) {
*slash = '\0';
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
*slash = '/';
}
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *name = xstrdup(file_header->name);
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
free(name);
}
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
/* Remove the entry if it exists */
if ((!S_ISDIR(file_header->mode))
/* Check if the file already exists */
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
/* Remove the existing entry if it exists */
if (((file_header->mode & S_IFMT) != S_IFDIR)
&& (unlink(file_header->name) == -1)
&& (errno != ENOENT)
) {
bb_perror_msg_and_die("can't remove old file %s",
bb_perror_msg_and_die("cannot remove old file %s",
file_header->name);
}
}
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
/* Remove the existing entry if its older than the extracted entry */
struct stat existing_sb;
if (lstat(file_header->name, &existing_sb) == -1) {
struct stat statbuf;
if (lstat(file_header->name, &statbuf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat old file");
bb_perror_msg_and_die("cannot stat old file");
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
else if (statbuf.st_mtime <= file_header->mtime) {
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_error_msg("%s not created: newer or "
"same age file exists", file_header->name);
}
@@ -48,21 +46,20 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
return;
}
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
bb_perror_msg_and_die("can't remove old file %s",
bb_perror_msg_and_die("cannot remove old file %s",
file_header->name);
}
}
/* Handle hard links separately
* We identified hard links as regular files of size 0 with a symlink */
if (S_ISREG(file_header->mode)
&& file_header->link_target
&& file_header->size == 0
if (S_ISREG(file_header->mode) && (file_header->link_target)
&& (file_header->size == 0)
) {
/* hard link */
res = link(file_header->link_target, file_header->name);
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("can't create %slink "
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("cannot create %slink "
"from %s to %s", "hard",
file_header->name,
file_header->link_target);
@@ -72,34 +69,27 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
switch (file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
int flags = O_WRONLY | O_CREAT | O_EXCL;
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
flags = O_WRONLY | O_CREAT | O_TRUNC;
dst_fd = xopen3(file_header->name,
flags,
file_header->mode
);
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
file_header->mode);
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
break;
}
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
if ((res == -1)
&& (errno != EISDIR) /* btw, Linux doesn't return this */
&& (errno != EEXIST)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
if ((res == -1) && (errno != EISDIR)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't make dir %s", file_header->name);
bb_perror_msg("cannot make dir %s", file_header->name);
}
break;
case S_IFLNK:
/* Symlink */
res = symlink(file_header->link_target, file_header->name);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create %slink "
bb_perror_msg("cannot create %slink "
"from %s to %s", "sym",
file_header->name,
file_header->link_target);
@@ -111,9 +101,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create node %s", file_header->name);
bb_perror_msg("cannot create node %s", file_header->name);
}
break;
default:
@@ -121,41 +111,21 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
}
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_OWNER)) {
#if ENABLE_FEATURE_TAR_UNAME_GNAME
if (!(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) {
uid_t uid = file_header->uid;
gid_t gid = file_header->gid;
if (file_header->tar__uname) {
//TODO: cache last name/id pair?
struct passwd *pwd = getpwnam(file_header->tar__uname);
if (pwd) uid = pwd->pw_uid;
}
if (file_header->tar__gname) {
struct group *grp = getgrnam(file_header->tar__gname);
if (grp) gid = grp->gr_gid;
}
/* GNU tar 1.15.1 uses chown, not lchown */
chown(file_header->name, uid, gid);
} else
#endif
chown(file_header->name, file_header->uid, file_header->gid);
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
lchown(file_header->name, file_header->uid, file_header->gid);
}
if (!S_ISLNK(file_header->mode)) {
if ((file_header->mode & S_IFMT) != S_IFLNK) {
/* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing!
* so we use chmod... */
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) {
chmod(file_header->name, file_header->mode);
}
/* same for utime */
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
struct timeval t[2];
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
t[1].tv_usec = t[0].tv_usec = 0;
utimes(file_header->name, t);
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
struct utimbuf t;
t.actime = t.modtime = file_header->mtime;
utime(file_header->name, &t);
}
}
}
@@ -0,0 +1,17 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright 2002 Glenn McGrath
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h"
void data_extract_to_buffer(archive_handle_t *archive_handle)
{
unsigned int size = archive_handle->file_header->size;
archive_handle->buffer = xzalloc(size + 1);
xread(archive_handle->src_fd, archive_handle->buffer, size);
}
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_extract_to_stdout(archive_handle_t *archive_handle)
void data_extract_to_stdout(archive_handle_t *archive_handle)
{
bb_copyfd_exact_size(archive_handle->src_fd,
STDOUT_FILENO,
+2 -2
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_skip(archive_handle_t *archive_handle)
void data_skip(archive_handle_t *archive_handle)
{
archive_handle->seek(archive_handle->src_fd, archive_handle->file_header->size);
archive_handle->seek(archive_handle, archive_handle->file_header->size);
}
+92 -47
View File
@@ -66,6 +66,7 @@ struct group_data {
* | grep 'bd->' | sed 's/^.*bd->/bd->/' | sort | $PAGER
* and moved it (inbufBitCount) to offset 0.
*/
struct bunzip_data {
/* I/O tracking data (file handles, buffers, positions, etc.) */
unsigned inbufBitCount, inbufBits;
@@ -101,9 +102,11 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
/* If we need to get more data from the byte buffer, do so. (Loop getting
one byte at a time to enforce endianness and avoid unaligned access.) */
while ((int)(bd->inbufBitCount) < bits_wanted) {
while (bd->inbufBitCount < bits_wanted) {
/* If we need to read more data from file into byte buffer, do so */
if (bd->inbufPos == bd->inbufCount) {
/* if "no input fd" case: in_fd == -1, read fails, we jump */
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
@@ -113,6 +116,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
if (bd->inbufBitCount >= 24) {
bits = bd->inbufBits & ((1 << bd->inbufBitCount) - 1);
bits_wanted -= bd->inbufBitCount;
@@ -121,11 +125,13 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Grab next 8 bits of input from buffer. */
bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++];
bd->inbufBitCount += 8;
}
/* Calculate result */
bd->inbufBitCount -= bits_wanted;
bits |= (bd->inbufBits >> bd->inbufBitCount) & ((1 << bits_wanted) - 1);
@@ -133,6 +139,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
@@ -146,11 +153,13 @@ static int get_next_block(bunzip_data *bd)
selectors = bd->selectors;
/* Reset longjmp I/O error handling */
i = setjmp(bd->jmpbuf);
if (i) return i;
/* Read in header signature and CRC, then validate signature.
(last block signature means CRC is for whole file, return now) */
i = get_bits(bd, 24);
j = get_bits(bd, 24);
bd->headerCRC = get_bits(bd, 32);
@@ -160,15 +169,17 @@ static int get_next_block(bunzip_data *bd)
/* 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;
origPtr = get_bits(bd, 24);
if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR;
if (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
symbols to deal with, and writes a sparse bitfield indicating which
values were present. We make a translation table to convert the symbols
back to the corresponding bytes. */
t = get_bits(bd, 16);
symTotal = 0;
for (i = 0; i < 16; i++) {
@@ -181,6 +192,7 @@ static int get_next_block(bunzip_data *bd)
}
/* How many different Huffman coding groups does this block use? */
groupCount = get_bits(bd, 3);
if (groupCount < 2 || groupCount > MAX_GROUPS)
return RETVAL_DATA_ERROR;
@@ -189,16 +201,19 @@ static int get_next_block(bunzip_data *bd)
group. Read in the group selector list, which is stored as MTF encoded
bit runs. (MTF=Move To Front, as each value is used it's moved to the
start of the list.) */
nSelectors = get_bits(bd, 15);
if (!nSelectors) return RETVAL_DATA_ERROR;
for (i = 0; i < groupCount; i++) mtfSymbol[i] = i;
for (i = 0; i < nSelectors; i++) {
/* Get next value */
for (j = 0; get_bits(bd, 1); j++)
if (j >= groupCount) return RETVAL_DATA_ERROR;
/* Decode MTF to get the next selector */
uc = mtfSymbol[j];
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
mtfSymbol[0] = selectors[i] = uc;
@@ -206,11 +221,10 @@ static int get_next_block(bunzip_data *bd)
/* Read the Huffman coding tables for each group, which code for symTotal
literal symbols, plus two run symbols (RUNA, RUNB) */
symCount = symTotal + 2;
for (j = 0; j < groupCount; j++) {
unsigned char length[MAX_SYMBOLS];
/* 8 bits is ALMOST enough for temp[], see below */
unsigned temp[MAX_HUFCODE_BITS+1];
unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
int minLen, maxLen, pp;
/* Read Huffman code lengths for each symbol. They're stored in
@@ -219,6 +233,7 @@ static int get_next_block(bunzip_data *bd)
(Subtracting 1 before the loop and then adding it back at the end is
an optimization that makes the test inside the loop simpler: symbol
length 0 becomes negative, so an unsigned inequality catches it.) */
t = get_bits(bd, 5) - 1;
for (i = 0; i < symCount; i++) {
for (;;) {
@@ -228,6 +243,7 @@ static int get_next_block(bunzip_data *bd)
/* If first bit is 0, stop. Else second bit indicates whether
to increment or decrement the value. Optimization: grab 2
bits and unget the second if the first was 0. */
k = get_bits(bd, 2);
if (k < 2) {
bd->inbufBitCount++;
@@ -235,14 +251,17 @@ static int get_next_block(bunzip_data *bd)
}
/* Add one if second bit 1, else subtract 1. Avoids if/else */
t += (((k+1) & 2) - 1);
}
/* Correct for the initial -1, to get the final symbol length */
length[i] = t + 1;
}
/* 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];
@@ -259,6 +278,7 @@ static int get_next_block(bunzip_data *bd)
* number of bits can have. This is how the Huffman codes can vary in
* length: each code with a value>limit[length] needs another bit.
*/
hufGroup = bd->groups + j;
hufGroup->minLen = minLen;
hufGroup->maxLen = maxLen;
@@ -266,10 +286,12 @@ static int get_next_block(bunzip_data *bd)
/* Note that minLen can't be smaller than 1, so we adjust the base
and limit array pointers so we're not always wasting the first
entry. We do this again when using them (during symbol decoding).*/
base = hufGroup->base - 1;
limit = hufGroup->limit - 1;
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
pp = 0;
for (i = minLen; i <= maxLen; i++) {
temp[i] = limit[i] = 0;
@@ -279,14 +301,14 @@ 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]]++;
/* Calculate limit[] (the largest symbol-coding value at each bit
* length, which is (previous limit<<1)+symbols at this level), and
* base[] (number of symbols to ignore at each bit length, which is
* limit minus the cumulative count of symbols coded for already). */
pp = t = 0;
for (i = minLen; i < maxLen; i++) {
pp += temp[i];
@@ -297,6 +319,7 @@ static int get_next_block(bunzip_data *bd)
each level we're really only interested in the first few bits,
so here we set all the trailing to-be-ignored bits to 1 so they
don't affect the value>limit[length] comparison. */
limit[i] = (pp << (maxLen - i)) - 1;
pp <<= 1;
t += temp[i];
@@ -312,6 +335,7 @@ static int get_next_block(bunzip_data *bd)
and run length encoding, saving the result into dbuf[dbufCount++] = uc */
/* Initialize symbol occurrence counters and symbol Move To Front table */
memset(byteCount, 0, sizeof(byteCount)); /* smaller, maybe slower? */
for (i = 0; i < 256; i++) {
//byteCount[i] = 0;
@@ -323,7 +347,8 @@ static int get_next_block(bunzip_data *bd)
runPos = dbufCount = selector = 0;
for (;;) {
/* Fetch next Huffman coding group from list. */
/* fetch next Huffman coding group from list. */
symCount = GROUP_SIZE - 1;
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
hufGroup = bd->groups + selectors[selector++];
@@ -342,7 +367,8 @@ static int get_next_block(bunzip_data *bd)
dry). The following (up to got_huff_bits:) is equivalent to
j = get_bits(bd, hufGroup->maxLen);
*/
while ((int)(bd->inbufBitCount) < hufGroup->maxLen) {
while (bd->inbufBitCount < hufGroup->maxLen) {
if (bd->inbufPos == bd->inbufCount) {
j = get_bits(bd, hufGroup->maxLen);
goto got_huff_bits;
@@ -356,11 +382,13 @@ static int get_next_block(bunzip_data *bd)
got_huff_bits:
/* Figure how how many bits are in next symbol and unget extras */
i = hufGroup->minLen;
while (j > limit[i]) ++i;
bd->inbufBitCount += (hufGroup->maxLen - i);
/* Huffman decode value to get nextSym (with bounds checking) */
if (i > hufGroup->maxLen)
return RETVAL_DATA_ERROR;
j = (j >> (hufGroup->maxLen - i)) - base[i];
@@ -372,9 +400,11 @@ static int get_next_block(bunzip_data *bd)
byte, or a repeated run of the most recent literal byte. First,
check if nextSym indicates a repeated run, and if so loop collecting
how many times to repeat the last literal. */
if ((unsigned)nextSym <= SYMBOL_RUNB) { /* RUNA or RUNB */
/* If this is the start of a new run, zero out counter */
if (!runPos) {
runPos = 1;
t = 0;
@@ -387,6 +417,7 @@ static int get_next_block(bunzip_data *bd)
the basic or 0/1 method (except all bits 0, which would use no
symbols, but a run of length 0 doesn't mean anything in this
context). Thus space is saved. */
t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
if (runPos < dbufSize) runPos <<= 1;
goto end_of_huffman_loop;
@@ -396,6 +427,7 @@ static int get_next_block(bunzip_data *bd)
how many times to repeat the last literal, so append that many
copies to our buffer of decoded symbols (dbuf) now. (The last
literal used is the one at the head of the mtfSymbol array.) */
if (runPos) {
runPos = 0;
if (dbufCount + t >= dbufSize) return RETVAL_DATA_ERROR;
@@ -406,6 +438,7 @@ static int get_next_block(bunzip_data *bd)
}
/* Is this the terminating symbol? */
if (nextSym > symTotal) break;
/* At this point, nextSym indicates a new literal character. Subtract
@@ -415,6 +448,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 >= dbufSize) return RETVAL_DATA_ERROR;
i = nextSym - 1;
uc = mtfSymbol[i];
@@ -423,6 +457,7 @@ static int get_next_block(bunzip_data *bd)
* small number of symbols, and are bound by 256 in any case, using
* memmove here would typically be bigger and slower due to function
* call overhead and other assorted setup costs. */
do {
mtfSymbol[i] = mtfSymbol[i-1];
} while (--i);
@@ -430,11 +465,13 @@ static int get_next_block(bunzip_data *bd)
uc = symToByte[uc];
/* We have our literal byte. Save it into dbuf. */
byteCount[uc]++;
dbuf[dbufCount++] = (unsigned)uc;
/* Skip group initialization if we're not done with this group. Done
* this way to avoid compiler warning. */
end_of_huffman_loop:
if (symCount--) goto continue_this_group;
}
@@ -447,6 +484,7 @@ static int get_next_block(bunzip_data *bd)
*/
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
j = 0;
for (i = 0; i < 256; i++) {
k = j + byteCount[i];
@@ -455,6 +493,7 @@ static int get_next_block(bunzip_data *bd)
}
/* Figure out what order dbuf would be in if we sorted it. */
for (i = 0; i < dbufCount; i++) {
uc = (unsigned char)(dbuf[i] & 0xff);
dbuf[byteCount[uc]] |= (i << 8);
@@ -464,10 +503,11 @@ static int get_next_block(bunzip_data *bd)
/* Decode first byte by hand to initialize "previous" byte. Note that it
doesn't get output, and if the first three characters are identical
it doesn't qualify as a run (hence writeRunCountdown=5). */
if (dbufCount) {
if ((int)origPtr >= dbufCount) return RETVAL_DATA_ERROR;
if (origPtr >= dbufCount) return RETVAL_DATA_ERROR;
bd->writePos = dbuf[origPtr];
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
bd->writePos >>= 8;
bd->writeRunCountdown = 5;
}
@@ -482,7 +522,8 @@ static int get_next_block(bunzip_data *bd)
error (all errors are negative numbers). If out_fd!=-1, outbuf and len
are ignored, data is written to out_fd and return is RETVAL_OK or error.
*/
int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
int read_bunzip(bunzip_data *bd, char *outbuf, int len)
{
const unsigned *dbuf;
int pos, current, previous, gotcount;
@@ -498,15 +539,19 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* We will always have pending decoded data to write into the output
buffer unless this is the very first call (in which case we haven't
Huffman-decoded a block into the intermediate buffer yet). */
if (bd->writeCopies) {
/* Inside the loop, writeCopies means extra copies (beyond 1) */
--bd->writeCopies;
/* Loop outputting bytes */
for (;;) {
/* If the output buffer is full, snapshot state and return */
if (gotcount >= len) {
bd->writePos = pos;
bd->writeCurrent = current;
@@ -515,11 +560,13 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
}
/* Write next byte into output buffer, updating CRC */
outbuf[gotcount++] = current;
bd->writeCRC = (bd->writeCRC << 8)
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
/* Loop now if we're outputting multiple copies of this byte */
if (bd->writeCopies) {
--bd->writeCopies;
continue;
@@ -535,29 +582,35 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* After 3 consecutive copies of the same byte, the 4th
* is a repeat count. We count down from 4 instead
* of counting up because testing for non-zero is faster */
if (--bd->writeRunCountdown) {
if (current != previous)
bd->writeRunCountdown = 4;
} else {
/* We have a repeated run, this byte indicates the count */
bd->writeCopies = current;
current = previous;
bd->writeRunCountdown = 5;
/* Sometimes there are just 3 bytes (run length 0) */
if (!bd->writeCopies) goto decode_next_byte;
/* Subtract the 1 copy we'd output anyway to get extras */
--bd->writeCopies;
}
}
/* Decompression of this block completed successfully */
bd->writeCRC = ~bd->writeCRC;
bd->totalCRC = ((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ bd->writeCRC;
/* If this block had a CRC error, force file level CRC error. */
if (bd->writeCRC != bd->headerCRC) {
bd->totalCRC = bd->headerCRC + 1;
return RETVAL_LAST_BLOCK;
@@ -566,6 +619,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Refill the intermediate buffer by Huffman-decoding next block of input */
/* (previous is just a convenient unused temp variable here) */
previous = get_next_block(bd);
if (previous) {
bd->writeCount = previous;
@@ -577,6 +631,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
goto decode_next_byte;
}
/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
ignored, and data is read from file handle into temporary buffer. */
@@ -584,24 +639,27 @@ int FAST_FUNC 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! */
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
int len)
{
bunzip_data *bd;
unsigned i;
enum {
BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0',
h0 = ('h' << 8) + '0',
BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0'
};
/* Figure out how much data to allocate */
i = sizeof(bunzip_data);
if (in_fd != -1) i += IOBUF_SIZE;
/* Allocate bunzip_data. Most fields initialize to zero. */
bd = *bdp = xzalloc(i);
/* Setup input buffer */
bd->in_fd = in_fd;
if (-1 == in_fd) {
/* in this case, bd->inbuf is read-only */
@@ -611,25 +669,23 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in
bd->inbuf = (unsigned char *)(bd + 1);
/* 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 */
/* was: */
/* i = get_bits(bd, 32); */
/* if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; */
i = get_bits(bd, 16);
if ((unsigned)(i - h0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
/* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of
i = get_bits(bd, 32);
if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
uncompressed data. Allocate intermediate buffer for block. */
/* bd->dbufSize = 100000 * (i - BZh0); */
bd->dbufSize = 100000 * (i - h0);
bd->dbufSize = 100000 * (i - BZh0);
/* Cannot use xmalloc - may leak bd in NOFORK case! */
bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(int));
@@ -640,7 +696,7 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in
return RETVAL_OK;
}
void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
void dealloc_bunzip(bunzip_data *bd)
{
free(bd->dbuf);
free(bd);
@@ -648,10 +704,11 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
IF_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
unpack_bz2_stream(int src_fd, int dst_fd)
{
IF_DESKTOP(long long total_written = 0;)
USE_DESKTOP(long long total_written = 0;)
char *outbuf;
bunzip_data *bd;
int i;
@@ -666,7 +723,7 @@ unpack_bz2_stream(int src_fd, int dst_fd)
i = RETVAL_SHORT_WRITE;
break;
}
IF_DESKTOP(total_written += i;)
USE_DESKTOP(total_written += i;)
}
}
@@ -686,18 +743,7 @@ unpack_bz2_stream(int src_fd, int dst_fd)
dealloc_bunzip(bd);
free(outbuf);
return i ? i : IF_DESKTOP(total_written) + 0;
}
IF_DESKTOP(long long) int FAST_FUNC
unpack_bz2_stream_prime(int src_fd, int dst_fd)
{
unsigned char magic[2];
xread(src_fd, magic, 2);
if (magic[0] != 'B' || magic[1] != 'Z') {
bb_error_msg_and_die("invalid magic");
}
return unpack_bz2_stream(src_fd, dst_fd);
return i ? i : USE_DESKTOP(total_written) + 0;
}
#ifdef TESTING
@@ -711,14 +757,13 @@ static char *const bunzip_errors[] = {
/* Dumb little test thing, decompress stdin to stdout */
int main(int argc, char **argv)
{
int i;
int i = unpack_bz2_stream(0, 1);
char c;
int i = unpack_bz2_stream_prime(0, 1);
if (i < 0)
fprintf(stderr, "%s\n", bunzip_errors[-i]);
else if (read(STDIN_FILENO, &c, 1))
fprintf(stderr, "Trailing garbage ignored\n");
fprintf(stderr,"%s\n", bunzip_errors[-i]);
else if (read(0, &c, 1))
fprintf(stderr,"Trailing garbage ignored\n");
return -i;
}
#endif
+9 -11
View File
@@ -1,4 +1,6 @@
/* vi: set sw=4 ts=4: */
#include "libbb.h"
/* uncompress for busybox -- (c) 2002 Robert Griebl
*
* based on the original compress42.c source
@@ -24,10 +26,6 @@
*
*/
#include "libbb.h"
#include "unarchive.h"
/* Default input buffer size */
#define IBUFSIZ 2048
@@ -72,11 +70,11 @@
* be stored in the compressed file.
*/
IF_DESKTOP(long long) int FAST_FUNC
unpack_Z_stream(int fd_in, int fd_out)
USE_DESKTOP(long long) int
uncompress(int fd_in, int fd_out)
{
IF_DESKTOP(long long total_written = 0;)
IF_DESKTOP(long long) int retval = -1;
USE_DESKTOP(long long total_written = 0;)
USE_DESKTOP(long long) int retval = -1;
unsigned char *stackp;
long code;
int finchar;
@@ -265,7 +263,7 @@ unpack_Z_stream(int fd_in, int fd_out)
if (outpos >= OBUFSIZ) {
full_write(fd_out, outbuf, outpos);
//error check??
IF_DESKTOP(total_written += outpos;)
USE_DESKTOP(total_written += outpos;)
outpos = 0;
}
stackp += i;
@@ -294,10 +292,10 @@ unpack_Z_stream(int fd_in, int fd_out)
if (outpos > 0) {
full_write(fd_out, outbuf, outpos);
//error check??
IF_DESKTOP(total_written += outpos;)
USE_DESKTOP(total_written += outpos;)
}
retval = IF_DESKTOP(total_written) + 0;
retval = USE_DESKTOP(total_written) + 0;
err:
free(inbuf);
free(outbuf);
+205 -171
View File
@@ -8,15 +8,14 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h"
#if ENABLE_FEATURE_LZMA_FAST
# define speed_inline ALWAYS_INLINE
# define size_inline
#else
# define speed_inline
# define size_inline ALWAYS_INLINE
#endif
@@ -45,90 +44,108 @@ typedef struct {
#define RC_MODEL_TOTAL_BITS 11
/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
static size_inline void rc_read(rc_t *rc)
/* Called twice: once at startup and once in rc_normalize() */
static void rc_read(rc_t * rc)
{
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
//TODO: return -1 instead
//This will make unlzma delete broken unpacked file on unpack errors
if (buffer_size <= 0)
bb_error_msg_and_die("unexpected EOF");
rc->ptr = RC_BUFFER;
rc->buffer_end = RC_BUFFER + buffer_size;
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
static void rc_do_normalize(rc_t *rc)
/* Called once */
static rc_t* rc_init(int fd) /*, int buffer_size) */
{
int i;
rc_t* rc;
rc = xmalloc(sizeof(rc_t) + RC_BUFFER_SIZE);
rc->fd = fd;
/* rc->buffer_size = buffer_size; */
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
rc->ptr = rc->buffer_end;
rc->code = 0;
rc->range = 0xFFFFFFFF;
for (i = 0; i < 5; i++) {
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->code = (rc->code << 8) | *rc->ptr++;
}
return rc;
}
/* Called once */
static ALWAYS_INLINE void rc_free(rc_t * rc)
{
if (ENABLE_FEATURE_CLEAN_UP)
free(rc);
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
static void rc_do_normalize(rc_t * rc)
{
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->range <<= 8;
rc->code = (rc->code << 8) | *rc->ptr++;
}
/* Called once */
static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
{
int i;
rc_t *rc;
rc = xzalloc(sizeof(*rc) + RC_BUFFER_SIZE);
rc->fd = fd;
/* rc->ptr = rc->buffer_end; */
for (i = 0; i < 5; i++) {
#if ENABLE_FEATURE_LZMA_FAST
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->code = (rc->code << 8) | *rc->ptr++;
#else
rc_do_normalize(rc);
#endif
}
rc->range = 0xFFFFFFFF;
return rc;
}
/* Called once */
static ALWAYS_INLINE void rc_free(rc_t *rc)
{
free(rc);
}
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
static ALWAYS_INLINE void rc_normalize(rc_t * rc)
{
if (rc->range < (1 << RC_TOP_BITS)) {
rc_do_normalize(rc);
}
}
/* rc_is_bit_1 is called 9 times */
static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
/* rc_is_bit_0 is called 9 times */
/* Why rc_is_bit_0_helper exists?
* Because we want to always expose (rc->code < rc->bound) to optimizer.
* Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined
* only if we compile for speed.
*/
static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p)
{
rc_normalize(rc);
rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
if (rc->code < rc->bound) {
rc->range = rc->bound;
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
return 0;
}
return rc->bound;
}
static ALWAYS_INLINE int rc_is_bit_0(rc_t * rc, uint16_t * p)
{
uint32_t t = rc_is_bit_0_helper(rc, p);
return rc->code < t;
}
/* Called ~10 times, but very small, thus inlined */
static speed_inline void rc_update_bit_0(rc_t * rc, uint16_t * p)
{
rc->range = rc->bound;
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
}
static speed_inline void rc_update_bit_1(rc_t * rc, uint16_t * p)
{
rc->range -= rc->bound;
rc->code -= rc->bound;
*p -= *p >> RC_MOVE_BITS;
return 1;
}
/* Called 4 times in unlzma loop */
static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol)
{
int ret = rc_is_bit_1(rc, p);
*symbol = *symbol * 2 + ret;
return ret;
if (rc_is_bit_0(rc, p)) {
rc_update_bit_0(rc, p);
*symbol *= 2;
return 0;
} else {
rc_update_bit_1(rc, p);
*symbol = *symbol * 2 + 1;
return 1;
}
}
/* Called once */
static ALWAYS_INLINE int rc_direct_bit(rc_t *rc)
static ALWAYS_INLINE int rc_direct_bit(rc_t * rc)
{
rc_normalize(rc);
rc->range >>= 1;
@@ -141,7 +158,7 @@ static ALWAYS_INLINE int rc_direct_bit(rc_t *rc)
/* Called twice */
static speed_inline void
rc_bit_tree_decode(rc_t *rc, uint16_t *p, int num_levels, int *symbol)
rc_bit_tree_decode(rc_t * rc, uint16_t * p, int num_levels, int *symbol)
{
int i = num_levels;
@@ -156,7 +173,7 @@ typedef struct {
uint8_t pos;
uint32_t dict_size;
uint64_t dst_size;
} PACKED lzma_header_t;
} __attribute__ ((packed)) lzma_header_t;
/* #defines will force compiler to compute/optimize each one with each usage.
@@ -212,19 +229,22 @@ enum {
};
IF_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
unpack_lzma_stream(int src_fd, int dst_fd)
{
IF_DESKTOP(long long total_written = 0;)
USE_DESKTOP(long long total_written = 0;)
lzma_header_t header;
int lc, pb, lp;
uint32_t pos_state_mask;
uint32_t literal_pos_mask;
uint32_t pos;
uint16_t *p;
uint16_t *prob;
uint16_t *prob_lit;
int num_bits;
int num_probs;
rc_t *rc;
int i;
int i, mi;
uint8_t *buffer;
uint8_t previous_byte = 0;
size_t buffer_pos = 0, global_pos = 0;
@@ -232,17 +252,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
int state = 0;
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
bb_error_msg("bad lzma header");
return -1;
}
xread(src_fd, &header, sizeof(header));
i = header.pos / 9;
if (header.pos >= (9 * 5 * 5))
bb_error_msg_and_die("bad header");
mi = header.pos / 9;
lc = header.pos % 9;
pb = i / 5;
lp = i % 5;
pb = mi / 5;
lp = mi % 5;
pos_state_mask = (1 << pb) - 1;
literal_pos_mask = (1 << lp) - 1;
@@ -250,13 +267,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
header.dst_size = SWAP_LE64(header.dst_size);
if (header.dict_size == 0)
header.dict_size++;
header.dict_size = 1;
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
p = xmalloc(num_probs * sizeof(*p));
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
for (i = 0; i < num_probs; i++)
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
@@ -264,24 +281,20 @@ unpack_lzma_stream(int src_fd, int dst_fd)
while (global_pos + buffer_pos < header.dst_size) {
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
uint16_t *prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
if (!rc_is_bit_1(rc, prob)) {
static const char next_state[LZMA_NUM_STATES] =
{ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
int mi = 1;
prob = (p + LZMA_LITERAL
+ (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
+ (previous_byte >> (8 - lc))
)
)
);
prob =
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
if (rc_is_bit_0(rc, prob)) {
mi = 1;
rc_update_bit_0(rc, prob);
prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE
* ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
+ (previous_byte >> (8 - lc)))));
if (state >= LZMA_NUM_LIT_STATES) {
int match_byte;
uint32_t pos = buffer_pos - rep0;
pos = buffer_pos - rep0;
while (pos >= header.dict_size)
pos += header.dict_size;
match_byte = buffer[pos];
@@ -290,74 +303,92 @@ unpack_lzma_stream(int src_fd, int dst_fd)
match_byte <<= 1;
bit = match_byte & 0x100;
bit ^= (rc_get_bit(rc, prob + 0x100 + bit + mi, &mi) << 8); /* 0x100 or 0 */
if (bit)
break;
prob_lit = prob + 0x100 + bit + mi;
if (rc_get_bit(rc, prob_lit, &mi)) {
if (!bit)
break;
} else {
if (bit)
break;
}
} while (mi < 0x100);
}
while (mi < 0x100) {
rc_get_bit(rc, prob + mi, &mi);
prob_lit = prob + mi;
rc_get_bit(rc, prob_lit, &mi);
}
state = next_state[state];
previous_byte = (uint8_t) mi;
#if ENABLE_FEATURE_LZMA_FAST
one_byte1:
buffer[buffer_pos++] = previous_byte;
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
IF_DESKTOP(total_written += header.dict_size;)
USE_DESKTOP(total_written += header.dict_size;)
}
#else
len = 1;
goto one_byte2;
#endif
if (state < 4)
state = 0;
else if (state < 10)
state -= 3;
else
state -= 6;
} else {
int offset;
uint16_t *prob2;
#define prob_len prob2
uint16_t *prob_len;
prob2 = p + LZMA_IS_REP + state;
if (!rc_is_bit_1(rc, prob2)) {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
prob2 = p + LZMA_LEN_CODER;
prob = p + LZMA_LEN_CODER;
} else {
prob2 += LZMA_IS_REP_G0 - LZMA_IS_REP;
if (!rc_is_bit_1(rc, prob2)) {
prob2 = (p + LZMA_IS_REP_0_LONG
+ (state << LZMA_NUM_POS_BITS_MAX)
+ pos_state
);
if (!rc_is_bit_1(rc, prob2)) {
#if ENABLE_FEATURE_LZMA_FAST
uint32_t pos = buffer_pos - rep0;
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G0 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
prob = (p + LZMA_IS_REP_0_LONG
+ (state << LZMA_NUM_POS_BITS_MAX) + pos_state);
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
pos = buffer_pos - rep0;
while (pos >= header.dict_size)
pos += header.dict_size;
previous_byte = buffer[pos];
goto one_byte1;
#else
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
len = 1;
goto string;
#endif
buffer[buffer_pos++] = previous_byte;
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
USE_DESKTOP(total_written += header.dict_size;)
}
continue;
} else {
rc_update_bit_1(rc, prob);
}
} else {
uint32_t distance;
prob2 += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
distance = rep1;
if (rc_is_bit_1(rc, prob2)) {
prob2 += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
distance = rep2;
if (rc_is_bit_1(rc, prob2)) {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G1 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
distance = rep1;
} else {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G2 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
distance = rep2;
} else {
rc_update_bit_1(rc, prob);
distance = rep3;
rep3 = rep2;
}
@@ -367,27 +398,31 @@ unpack_lzma_stream(int src_fd, int dst_fd)
rep0 = distance;
}
state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
prob2 = p + LZMA_REP_LEN_CODER;
prob = p + LZMA_REP_LEN_CODER;
}
prob_len = prob2 + LZMA_LEN_CHOICE;
num_bits = LZMA_LEN_NUM_LOW_BITS;
if (!rc_is_bit_1(rc, prob_len)) {
prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
+ (pos_state << LZMA_LEN_NUM_LOW_BITS);
prob_len = prob + LZMA_LEN_CHOICE;
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_LOW
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
offset = 0;
num_bits = LZMA_LEN_NUM_LOW_BITS;
} else {
prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
if (!rc_is_bit_1(rc, prob_len)) {
prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
+ (pos_state << LZMA_LEN_NUM_MID_BITS);
rc_update_bit_1(rc, prob_len);
prob_len = prob + LZMA_LEN_CHOICE_2;
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_MID
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
num_bits += LZMA_LEN_NUM_MID_BITS - LZMA_LEN_NUM_LOW_BITS;
num_bits = LZMA_LEN_NUM_MID_BITS;
} else {
prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
rc_update_bit_1(rc, prob_len);
prob_len = prob + LZMA_LEN_HIGH;
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
+ (1 << LZMA_LEN_NUM_MID_BITS));
num_bits += LZMA_LEN_NUM_HIGH_BITS - LZMA_LEN_NUM_LOW_BITS;
+ (1 << LZMA_LEN_NUM_MID_BITS));
num_bits = LZMA_LEN_NUM_HIGH_BITS;
}
}
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
@@ -395,71 +430,70 @@ unpack_lzma_stream(int src_fd, int dst_fd)
if (state < 4) {
int pos_slot;
uint16_t *prob3;
state += LZMA_NUM_LIT_STATES;
prob3 = p + LZMA_POS_SLOT +
((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
LZMA_NUM_LEN_TO_POS_STATES - 1)
<< LZMA_NUM_POS_SLOT_BITS);
rc_bit_tree_decode(rc, prob3,
LZMA_NUM_POS_SLOT_BITS, &pos_slot);
rep0 = pos_slot;
prob =
p + LZMA_POS_SLOT +
((len <
LZMA_NUM_LEN_TO_POS_STATES ? len :
LZMA_NUM_LEN_TO_POS_STATES - 1)
<< LZMA_NUM_POS_SLOT_BITS);
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
&pos_slot);
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
int i2, mi2, num_bits2 = (pos_slot >> 1) - 1;
num_bits = (pos_slot >> 1) - 1;
rep0 = 2 | (pos_slot & 1);
if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
rep0 <<= num_bits2;
prob3 = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
rep0 <<= num_bits;
prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
} else {
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
num_bits -= LZMA_NUM_ALIGN_BITS;
while (num_bits--)
rep0 = (rep0 << 1) | rc_direct_bit(rc);
prob = p + LZMA_ALIGN;
rep0 <<= LZMA_NUM_ALIGN_BITS;
prob3 = p + LZMA_ALIGN;
num_bits = LZMA_NUM_ALIGN_BITS;
}
i2 = 1;
mi2 = 1;
while (num_bits2--) {
if (rc_get_bit(rc, prob3 + mi2, &mi2))
rep0 |= i2;
i2 <<= 1;
i = 1;
mi = 1;
while (num_bits--) {
if (rc_get_bit(rc, prob + mi, &mi))
rep0 |= i;
i <<= 1;
}
}
} else
rep0 = pos_slot;
if (++rep0 == 0)
break;
}
len += LZMA_MATCH_MIN_LEN;
IF_NOT_FEATURE_LZMA_FAST(string:)
do {
uint32_t pos = buffer_pos - rep0;
pos = buffer_pos - rep0;
while (pos >= header.dict_size)
pos += header.dict_size;
previous_byte = buffer[pos];
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
buffer[buffer_pos++] = previous_byte;
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
IF_DESKTOP(total_written += header.dict_size;)
USE_DESKTOP(total_written += header.dict_size;)
}
len--;
} while (len != 0 && buffer_pos < header.dst_size);
}
}
{
IF_NOT_DESKTOP(int total_written = 0; /* success */)
IF_DESKTOP(total_written += buffer_pos;)
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
bad:
total_written = -1; /* failure */
}
rc_free(rc);
free(p);
free(buffer);
return total_written;
return -1;
}
rc_free(rc);
USE_DESKTOP(total_written += buffer_pos;)
return USE_DESKTOP(total_written) + 0;
}
+28 -50
View File
@@ -85,8 +85,7 @@ typedef struct state_t {
/* input (compressed) data */
unsigned char *bytebuffer; /* buffer itself */
off_t to_read; /* compressed bytes to read (unzip only, -1 for gunzip) */
// unsigned bytebuffer_max; /* buffer size */
unsigned bytebuffer_max; /* buffer size */
unsigned bytebuffer_offset; /* buffer position */
unsigned bytebuffer_size; /* how much data is there (size <= max) */
@@ -127,10 +126,7 @@ typedef struct state_t {
#define gunzip_crc_table (S()gunzip_crc_table )
#define gunzip_bb (S()gunzip_bb )
#define gunzip_bk (S()gunzip_bk )
#define to_read (S()to_read )
// #define bytebuffer_max (S()bytebuffer_max )
// Both gunzip and unzip can use constant buffer size now (16k):
#define bytebuffer_max 0x4000
#define bytebuffer_max (S()bytebuffer_max )
#define bytebuffer (S()bytebuffer )
#define bytebuffer_offset (S()bytebuffer_offset )
#define bytebuffer_size (S()bytebuffer_size )
@@ -244,7 +240,7 @@ static void huft_free_all(STATE_PARAM_ONLY)
inflate_codes_td = NULL;
}
static void abort_unzip(STATE_PARAM_ONLY) NORETURN;
static void abort_unzip(STATE_PARAM_ONLY) ATTRIBUTE_NORETURN;
static void abort_unzip(STATE_PARAM_ONLY)
{
huft_free_all(PASS_STATE_ONLY);
@@ -255,18 +251,13 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
{
while (*current < required) {
if (bytebuffer_offset >= bytebuffer_size) {
unsigned sz = bytebuffer_max - 4;
if (to_read >= 0 && to_read < sz) /* unzip only */
sz = to_read;
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
* to the front of the bytebuffer */
bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], sz);
bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 4);
if ((int)bytebuffer_size < 1) {
error_msg = "unexpected end of file";
abort_unzip(PASS_STATE_ONLY);
}
if (to_read >= 0) /* unzip only */
to_read -= bytebuffer_size;
bytebuffer_size += 4;
bytebuffer_offset = 4;
}
@@ -503,7 +494,7 @@ static void inflate_codes_setup(STATE_PARAM unsigned my_bl, unsigned my_bd)
md = mask_bits[bd];
}
/* called once from inflate_get_next_window */
static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
static int inflate_codes(STATE_PARAM_ONLY)
{
unsigned e; /* table entry flag/number of extra bits */
huft_t *t; /* pointer to table entry */
@@ -922,7 +913,7 @@ static int inflate_block(STATE_PARAM smallint *e)
/* Two callsites, both in inflate_get_next_window */
static void calculate_gunzip_crc(STATE_PARAM_ONLY)
{
unsigned n;
int n;
for (n = 0; n < gunzip_outbuf_count; n++) {
gunzip_crc = gunzip_crc_table[((int) gunzip_crc ^ (gunzip_window[n])) & 0xff] ^ (gunzip_crc >> 8);
}
@@ -970,10 +961,10 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
/* Called from unpack_gz_stream() and inflate_unzip() */
static IF_DESKTOP(long long) int
static USE_DESKTOP(long long) int
inflate_unzip_internal(STATE_PARAM int in, int out)
{
IF_DESKTOP(long long) int n = 0;
USE_DESKTOP(long long) int n = 0;
ssize_t nwrote;
/* Allocate all global buffers (for DYN_ALLOC option) */
@@ -1003,12 +994,12 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
while (1) {
int r = inflate_get_next_window(PASS_STATE_ONLY);
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
if (nwrote != (ssize_t)gunzip_outbuf_count) {
if (nwrote != gunzip_outbuf_count) {
bb_perror_msg("write");
n = -1;
goto ret;
}
IF_DESKTOP(n += nwrote;)
USE_DESKTOP(n += nwrote;)
if (r == 0) break;
}
@@ -1033,16 +1024,15 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
/* For unzip */
IF_DESKTOP(long long) int FAST_FUNC
inflate_unzip(inflate_unzip_result *res, off_t compr_size, int in, int out)
USE_DESKTOP(long long) int
inflate_unzip(inflate_unzip_result *res, unsigned bufsize, int in, int out)
{
IF_DESKTOP(long long) int n;
USE_DESKTOP(long long) int n;
DECLARE_STATE;
ALLOC_STATE;
to_read = compr_size;
// bytebuffer_max = 0x8000;
bytebuffer_max = bufsize + 4;
bytebuffer_offset = 4;
bytebuffer = xmalloc(bytebuffer_max);
n = inflate_unzip_internal(PASS_STATE in, out);
@@ -1064,7 +1054,7 @@ static int top_up(STATE_PARAM unsigned n)
{
int count = bytebuffer_size - bytebuffer_offset;
if (count < (int)n) {
if (count < n) {
memmove(bytebuffer, &bytebuffer[bytebuffer_offset], count);
bytebuffer_offset = 0;
bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
@@ -1083,7 +1073,8 @@ static uint16_t buffer_read_le_u16(STATE_PARAM_ONLY)
{
uint16_t res;
#if BB_LITTLE_ENDIAN
move_from_unaligned16(res, &bytebuffer[bytebuffer_offset]);
/* gcc 4.2.1 is very clever */
memcpy(&res, &bytebuffer[bytebuffer_offset], 2);
#else
res = bytebuffer[bytebuffer_offset];
res |= bytebuffer[bytebuffer_offset + 1] << 8;
@@ -1096,7 +1087,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
{
uint32_t res;
#if BB_LITTLE_ENDIAN
move_from_unaligned32(res, &bytebuffer[bytebuffer_offset]);
memcpy(&res, &bytebuffer[bytebuffer_offset], 4);
#else
res = bytebuffer[bytebuffer_offset];
res |= bytebuffer[bytebuffer_offset + 1] << 8;
@@ -1107,21 +1098,18 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
return res;
}
static int check_header_gzip(STATE_PARAM unpack_info_t *info)
static int check_header_gzip(STATE_PARAM_ONLY)
{
union {
unsigned char raw[8];
struct {
uint8_t gz_method;
uint8_t flags;
uint32_t mtime;
uint8_t xtra_flags_UNUSED;
uint8_t os_flags_UNUSED;
} PACKED formatted;
//uint32_t mtime; - unused fields
//uint8_t xtra_flags;
//uint8_t os_flags;
} formatted; /* packed */
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 8 ? 1 : -1];
};
/*
* Rewind bytebuffer. We use the beginning because the header has 8
@@ -1169,9 +1157,6 @@ static int check_header_gzip(STATE_PARAM unpack_info_t *info)
}
}
if (info)
info->mtime = SWAP_LE32(header.formatted.mtime);
/* Read the header checksum */
if (header.formatted.flags & 0x02) {
if (!top_up(PASS_STATE 2))
@@ -1181,23 +1166,22 @@ static int check_header_gzip(STATE_PARAM unpack_info_t *info)
return 1;
}
IF_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
USE_DESKTOP(long long) int
unpack_gz_stream(int in, int out)
{
uint32_t v32;
IF_DESKTOP(long long) int n;
USE_DESKTOP(long long) int n;
DECLARE_STATE;
n = 0;
ALLOC_STATE;
to_read = -1;
// bytebuffer_max = 0x8000;
bytebuffer_max = 0x8000;
bytebuffer = xmalloc(bytebuffer_max);
gunzip_src_fd = in;
again:
if (!check_header_gzip(PASS_STATE info)) {
if (!check_header_gzip(PASS_STATE_ONLY)) {
bb_error_msg("corrupted data");
n = -1;
goto ret;
@@ -1244,9 +1228,3 @@ unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
DEALLOC_STATE;
return n;
}
IF_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream(int in, int out)
{
return unpack_gz_stream_with_info(in, out, NULL);
}
+1 -1
View File
@@ -9,7 +9,7 @@
#include "unarchive.h"
/* Accept any non-null name, its not really a filter at all */
char FAST_FUNC filter_accept_all(archive_handle_t *archive_handle)
char filter_accept_all(archive_handle_t *archive_handle)
{
if (archive_handle->file_header->name)
return EXIT_SUCCESS;
+1 -1
View File
@@ -11,7 +11,7 @@
/*
* Accept names that are in the accept list, ignoring reject list.
*/
char FAST_FUNC filter_accept_list(archive_handle_t *archive_handle)
char filter_accept_list(archive_handle_t *archive_handle)
{
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name))
return EXIT_SUCCESS;
@@ -8,42 +8,35 @@
#include "libbb.h"
#include "unarchive.h"
/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
/*
* Reassign the subarchive metadata parser based on the filename extension
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
*/
char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
char filter_accept_list_reassign(archive_handle_t *archive_handle)
{
/* Check the file entry is in the accept list */
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
const char *name_ptr;
/* Find extension */
/* Extract the last 2 extensions */
name_ptr = strrchr(archive_handle->file_header->name, '.');
if (!name_ptr)
return EXIT_FAILURE;
name_ptr++;
/* Modify the subarchive handler based on the extension */
if (ENABLE_FEATURE_SEAMLESS_GZ
&& strcmp(name_ptr, "gz") == 0
) {
archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
#if ENABLE_FEATURE_DEB_TAR_GZ
if (strcmp(name_ptr, ".gz") == 0) {
archive_handle->action_data_subarchive = get_header_tar_gz;
return EXIT_SUCCESS;
}
if (ENABLE_FEATURE_SEAMLESS_BZ2
&& strcmp(name_ptr, "bz2") == 0
) {
archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
#endif
#if ENABLE_FEATURE_DEB_TAR_BZ2
if (strcmp(name_ptr, ".bz2") == 0) {
archive_handle->action_data_subarchive = get_header_tar_bz2;
return EXIT_SUCCESS;
}
if (ENABLE_FEATURE_SEAMLESS_LZMA
&& strcmp(name_ptr, "lzma") == 0
) {
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
#endif
if (ENABLE_FEATURE_DEB_TAR_LZMA && !strcmp(name_ptr, ".lzma")) {
archive_handle->action_data_subarchive = get_header_tar_lzma;
return EXIT_SUCCESS;
}
}
@@ -11,16 +11,13 @@
/*
* Accept names that are in the accept list and not in the reject list
*/
char FAST_FUNC filter_accept_reject_list(archive_handle_t *archive_handle)
char filter_accept_reject_list(archive_handle_t *archive_handle)
{
const char *key;
const llist_t *reject_entry;
const char *key = archive_handle->file_header->name;
const llist_t *reject_entry = find_list_entry2(archive_handle->reject, key);
const llist_t *accept_entry;
key = archive_handle->file_header->name;
/* If the key is in a reject list fail */
reject_entry = find_list_entry2(archive_handle->reject, key);
if (reject_entry) {
return EXIT_FAILURE;
}
+3 -3
View File
@@ -10,7 +10,7 @@
#include "unarchive.h"
/* Find a string in a shell pattern list */
const llist_t* FAST_FUNC find_list_entry(const llist_t *list, const char *filename)
const llist_t *find_list_entry(const llist_t *list, const char *filename)
{
while (list) {
if (fnmatch(list->data, filename, 0) == 0) {
@@ -24,7 +24,7 @@ const llist_t* FAST_FUNC find_list_entry(const llist_t *list, const char *filena
/* Same, but compares only path components present in pattern
* (extra trailing path components in filename are assumed to match)
*/
const llist_t* FAST_FUNC find_list_entry2(const llist_t *list, const char *filename)
const llist_t *find_list_entry2(const llist_t *list, const char *filename)
{
char buf[PATH_MAX];
int pattern_slash_cnt;
@@ -38,7 +38,7 @@ const llist_t* FAST_FUNC find_list_entry2(const llist_t *list, const char *filen
if (*c++ == '/') pattern_slash_cnt++;
c = filename;
d = buf;
/* paranoia is better than buffer overflows */
/* paranoia is better that buffer overflows */
while (*c && d != buf + sizeof(buf)-1) {
if (*c == '/' && --pattern_slash_cnt < 0)
break;
+43 -57
View File
@@ -7,20 +7,10 @@
#include "libbb.h"
#include "unarchive.h"
static unsigned read_num(const char *str, int base)
{
/* This code works because
* on misformatted numbers bb_strtou returns all-ones */
int err = bb_strtou(str, NULL, base);
if (err == -1)
bb_error_msg_and_die("invalid ar header");
return err;
}
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
char get_header_ar(archive_handle_t *archive_handle)
{
int err;
file_header_t *typed = archive_handle->file_header;
unsigned size;
union {
char raw[60];
struct {
@@ -59,60 +49,57 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
bb_error_msg_and_die("invalid ar header");
/* FIXME: more thorough routine would be in order here
* (we have something like that in tar)
* but for now we are lax. */
typed->size = size = read_num(ar.formatted.size, 10);
/* FIXME: more thorough routine would be in order here */
/* (we have something like that in tar) */
/* but for now we are lax. This code works because */
/* on misformatted numbers bb_strtou returns all-ones */
typed->mode = err = bb_strtou(ar.formatted.mode, NULL, 8);
if (err == -1) bb_error_msg_and_die("invalid ar header");
typed->mtime = err = bb_strtou(ar.formatted.date, NULL, 10);
if (err == -1) bb_error_msg_and_die("invalid ar header");
typed->uid = err = bb_strtou(ar.formatted.uid, NULL, 10);
if (err == -1) bb_error_msg_and_die("invalid ar header");
typed->gid = err = bb_strtou(ar.formatted.gid, NULL, 10);
if (err == -1) bb_error_msg_and_die("invalid ar header");
typed->size = err = bb_strtou(ar.formatted.size, NULL, 10);
if (err == -1) bb_error_msg_and_die("invalid ar header");
/* special filenames have '/' as the first character */
/* long filenames have '/' as the first character */
if (ar.formatted.name[0] == '/') {
if (ar.formatted.name[1] == ' ') {
/* This is the index of symbols in the file for compilers */
data_skip(archive_handle);
archive_handle->offset += size;
return get_header_ar(archive_handle); /* Return next header */
}
#if ENABLE_FEATURE_AR_LONG_FILENAMES
unsigned long_offset;
if (ar.formatted.name[1] == '/') {
/* If the second char is a '/' then this entries data section
* stores long filename for multiple entries, they are stored
* in static variable long_names for use in future entries
*/
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);
* in static variable long_names for use in future entries */
ar_long_name_size = typed->size;
ar_long_names = xmalloc(ar_long_name_size);
xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
archive_handle->offset += ar_long_name_size;
/* This ar entries data section only contained filenames for other records
* they are stored in the static ar_long_names for future reference */
return get_header_ar(archive_handle); /* Return next header */
}
#else
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.
*/
typed->mode = read_num(ar.formatted.mode, 8);
typed->mtime = read_num(ar.formatted.date, 10);
typed->uid = read_num(ar.formatted.uid, 10);
typed->gid = read_num(ar.formatted.gid, 10);
#if ENABLE_FEATURE_AR_LONG_FILENAMES
if (ar.formatted.name[0] == '/') {
unsigned long_offset;
if (ar.formatted.name[1] == ' ') {
/* This is the index of symbols in the file for compilers */
data_skip(archive_handle);
archive_handle->offset += typed->size;
return get_header_ar(archive_handle); /* Return next header */
}
/* The number after the '/' indicates the offset in the ar data section
* (saved in ar_long_names) that conatains the real filename */
long_offset = read_num(&ar.formatted.name[1], 10);
* (saved in variable long_name) that conatains the real filename */
long_offset = atoi(&ar.formatted.name[1]);
if (long_offset >= ar_long_name_size) {
bb_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(ar_long_names + long_offset);
} else
#else
bb_error_msg_and_die("long filenames not supported");
#endif
{
} else {
/* short filenames */
typed->name = xstrndup(ar.formatted.name, 16);
}
@@ -121,13 +108,12 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(typed);
#if ENABLE_DPKG || ENABLE_DPKG_DEB
if (archive_handle->dpkg__sub_archive) {
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
continue;
} else
#endif
if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
/* repeat */;
} else {
archive_handle->action_data(archive_handle);
}
} else {
data_skip(archive_handle);
}
+98 -123
View File
@@ -7,33 +7,71 @@
#include "libbb.h"
#include "unarchive.h"
typedef struct hardlinks_t {
struct hardlinks_t *next;
int inode; /* TODO: must match maj/min too! */
int mode ;
int mtime; /* These three are useful only in corner case */
int uid ; /* of hardlinks with zero size body */
int gid ;
char name[1];
typedef struct hardlinks_s {
char *name;
int inode;
struct hardlinks_s *next;
} hardlinks_t;
char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
char get_header_cpio(archive_handle_t *archive_handle)
{
static hardlinks_t *saved_hardlinks = NULL;
static unsigned pending_hardlinks = 0;
static int inode;
file_header_t *file_header = archive_handle->file_header;
char cpio_header[110];
int namesize;
int major, minor, nlink, mode, inode;
unsigned size, uid, gid, mtime;
char dummy[16];
int major, minor, nlink;
if (pending_hardlinks) { /* Deal with any pending hardlinks */
hardlinks_t *tmp, *oldtmp;
tmp = saved_hardlinks;
oldtmp = NULL;
file_header->link_target = file_header->name;
file_header->size = 0;
while (tmp) {
if (tmp->inode != inode) {
tmp = tmp->next;
continue;
}
file_header->name = tmp->name;
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_data(archive_handle);
archive_handle->action_header(archive_handle->file_header);
}
pending_hardlinks--;
oldtmp = tmp;
tmp = tmp->next;
free(oldtmp->name);
free(oldtmp);
if (oldtmp == saved_hardlinks)
saved_hardlinks = tmp;
}
file_header->name = file_header->link_target;
if (pending_hardlinks > 1) {
bb_error_msg("error resolving hardlink: archive made by GNU cpio 2.0-2.2?");
}
/* No more pending hardlinks, read next file entry */
pending_hardlinks = 0;
}
/* There can be padding before archive header */
data_align(archive_handle, 4);
size = full_read(archive_handle->src_fd, cpio_header, 110);
if (size == 0) {
goto create_hardlinks;
}
if (size != 110) {
bb_error_msg_and_die("short read");
if (archive_xread_all_eof(archive_handle, (unsigned char*)cpio_header, 110) == 0) {
return EXIT_FAILURE;
}
archive_handle->offset += 110;
@@ -43,83 +81,74 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
}
if (sscanf(cpio_header + 6,
"%8x" "%8x" "%8x" "%8x"
"%8x" "%8x" "%8x" /*maj,min:*/ "%*16c"
/*rmaj,rmin:*/"%8x" "%8x" "%8x" /*chksum: "%*8c"*/,
&inode, &mode, &uid, &gid,
&nlink, &mtime, &size,
&major, &minor, &namesize) != 10)
bb_error_msg_and_die("damaged cpio file");
file_header->mode = mode;
file_header->uid = uid;
file_header->gid = gid;
file_header->mtime = mtime;
file_header->size = size;
{
unsigned long tmpsize;
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
dummy, &inode, (unsigned int*)&file_header->mode,
(unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
&nlink, &file_header->mtime, &tmpsize,
dummy, &major, &minor, &namesize, dummy);
file_header->size = tmpsize;
}
namesize &= 0x1fff; /* paranoia: limit names to 8k chars */
free(file_header->name);
file_header->name = xzalloc(namesize + 1);
/* Read in filename */
xread(archive_handle->src_fd, file_header->name, namesize);
if (file_header->name[0] == '/') {
/* Testcase: echo /etc/hosts | cpio -pvd /tmp
* Without this code, it tries to unpack /etc/hosts
* into "/etc/hosts", not "etc/hosts".
*/
char *p = file_header->name;
do p++; while (*p == '/');
overlapping_strcpy(file_header->name, p);
}
archive_handle->offset += namesize;
/* Update offset amount and skip padding before file contents */
data_align(archive_handle, 4);
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
/* Always round up. ">> 9" divides by 512 */
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
goto create_hardlinks;
/* Always round up */
printf("%d blocks\n", (int) (archive_handle->offset % 512 ?
archive_handle->offset / 512 + 1 :
archive_handle->offset / 512
));
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
hardlinks_t *tmp = saved_hardlinks;
hardlinks_t *oldtmp = NULL;
while (tmp) {
bb_error_msg("%s not created: cannot resolve hardlink", tmp->name);
oldtmp = tmp;
tmp = tmp->next;
free(oldtmp->name);
free(oldtmp);
}
saved_hardlinks = NULL;
pending_hardlinks = 0;
}
return EXIT_FAILURE;
}
file_header->link_target = NULL;
if (S_ISLNK(file_header->mode)) {
file_header->size &= 0x1fff; /* paranoia: limit names to 8k chars */
file_header->link_target = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, file_header->link_target, file_header->size);
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */
} else {
file_header->link_target = NULL;
}
// TODO: data_extract_all can't deal with hardlinks to non-files...
// when fixed, change S_ISREG to !S_ISDIR here
if (nlink > 1 && S_ISREG(file_header->mode)) {
hardlinks_t *new = xmalloc(sizeof(*new) + namesize);
new->inode = inode;
new->mode = mode ;
new->mtime = mtime;
new->uid = uid ;
new->gid = gid ;
strcpy(new->name, file_header->name);
/* Put file on a linked list for later */
if (size == 0) {
new->next = archive_handle->cpio__hardlinks_to_create;
archive_handle->cpio__hardlinks_to_create = new;
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
if (file_header->size == 0) { /* Put file on a linked list for later */
hardlinks_t *new = xmalloc(sizeof(hardlinks_t));
new->next = saved_hardlinks;
new->inode = inode;
/* name current allocated, freed later */
new->name = file_header->name;
file_header->name = NULL;
saved_hardlinks = new;
return EXIT_SUCCESS; /* Skip this one */
/* TODO: this breaks cpio -t (it does not show hardlinks) */
}
new->next = archive_handle->cpio__created_hardlinks;
archive_handle->cpio__created_hardlinks = new;
/* Found the file with data in */
pending_hardlinks = nlink;
}
file_header->device = makedev(major, minor);
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_data(archive_handle);
//TODO: run "echo /etc/hosts | cpio -pv /tmp" twice. On 2nd run:
//cpio: etc/hosts not created: newer or same age file exists
//etc/hosts <-- should NOT show it
//2 blocks <-- should say "0 blocks"
archive_handle->action_header(file_header);
archive_handle->action_header(archive_handle->file_header);
} else {
data_skip(archive_handle);
}
@@ -127,60 +156,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
archive_handle->offset += file_header->size;
free(file_header->link_target);
free(file_header->name);
file_header->link_target = NULL;
file_header->name = NULL;
return EXIT_SUCCESS;
create_hardlinks:
free(file_header->link_target);
free(file_header->name);
while (archive_handle->cpio__hardlinks_to_create) {
hardlinks_t *cur;
hardlinks_t *make_me = archive_handle->cpio__hardlinks_to_create;
archive_handle->cpio__hardlinks_to_create = make_me->next;
memset(file_header, 0, sizeof(*file_header));
file_header->mtime = make_me->mtime;
file_header->name = make_me->name;
file_header->mode = make_me->mode;
file_header->uid = make_me->uid;
file_header->gid = make_me->gid;
/*file_header->size = 0;*/
/*file_header->link_target = NULL;*/
/* Try to find a file we are hardlinked to */
cur = archive_handle->cpio__created_hardlinks;
while (cur) {
/* TODO: must match maj/min too! */
if (cur->inode == make_me->inode) {
file_header->link_target = cur->name;
/* link_target != NULL, size = 0: "I am a hardlink" */
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
archive_handle->action_data(archive_handle);
free(make_me);
goto next_link;
}
cur = cur->next;
}
/* Oops... no file with such inode was created... do it now
* (happens when hardlinked files are empty (zero length)) */
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
archive_handle->action_data(archive_handle);
/* Move to the list of created hardlinked files */
make_me->next = archive_handle->cpio__created_hardlinks;
archive_handle->cpio__created_hardlinks = make_me;
next_link: ;
}
while (archive_handle->cpio__created_hardlinks) {
hardlinks_t *p = archive_handle->cpio__created_hardlinks;
archive_handle->cpio__created_hardlinks = p->next;
free(p);
}
return EXIT_FAILURE; /* "No more files to process" */
}
+76 -221
View File
@@ -14,94 +14,39 @@
#include "libbb.h"
#include "unarchive.h"
/*
* GNU tar uses "base-256 encoding" for very large numbers (>8 billion).
* Encoding is binary, with highest bit always set as a marker
* and sign in next-highest bit:
* 80 00 .. 00 - zero
* bf ff .. ff - largest positive number
* ff ff .. ff - minus 1
* c0 00 .. 00 - smallest negative number
*
* We expect it only in size field, where negative numbers don't make sense.
*/
static off_t getBase256_len12(const char *str)
{
off_t value;
int len;
/* if (*str & 0x40) error; - caller prevents this */
if (sizeof(off_t) >= 12) {
/* Probably 128-bit (16 byte) off_t. Can be optimized. */
len = 12;
value = *str++ & 0x3f;
while (--len)
value = (value << 8) + (unsigned char) *str++;
return value;
}
#ifdef CHECK_FOR_OVERFLOW
/* Can be optimized to eat 32-bit chunks */
char c = *str++ & 0x3f;
len = 12;
while (1) {
if (c)
bb_error_msg_and_die("overflow in base-256 encoded file size");
if (--len == sizeof(off_t))
break;
c = *str++;
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static char *longname;
static char *linkname;
#else
str += (12 - sizeof(off_t));
enum {
longname = 0,
linkname = 0,
};
#endif
/* Now str points to sizeof(off_t) least significant bytes.
*
* Example of tar file with 8914993153 (0x213600001) byte file.
* Field starts at offset 7c:
* 00070 30 30 30 00 30 30 30 30 30 30 30 00 80 00 00 00 |000.0000000.....|
* 00080 00 00 00 02 13 60 00 01 31 31 31 32 30 33 33 36 |.....`..11120336|
*
* str is at offset 80 or 84 now (64-bit or 32-bit off_t).
* We (ab)use the fact that value happens to be aligned,
* and fetch it in one go:
*/
if (sizeof(off_t) == 8) {
value = *(off_t*)str;
value = SWAP_BE64(value);
} else if (sizeof(off_t) == 4) {
value = *(off_t*)str;
value = SWAP_BE32(value);
} else {
value = 0;
len = sizeof(off_t);
while (--len)
value = (value << 8) + (unsigned char) *str++;
}
return value;
}
/* NB: _DESTROYS_ str[len] character! */
static unsigned long long getOctal(char *str, int len)
{
unsigned long long v;
/* NB: leading spaces are allowed. Using strtoull to handle that.
* The downside is that we accept e.g. "-123" too :(
*/
/* Actually, tar header allows leading spaces also.
* Oh well, we will be liberal and skip this...
* The only downside probably is that we allow "-123" too :)
if (*str < '0' || *str > '7')
bb_error_msg_and_die("corrupted octal value in tar header");
*/
str[len] = '\0';
v = strtoull(str, &str, 8);
/* std: "Each numeric field is terminated by one or more
* <space> or NUL characters". We must support ' '! */
if (*str != '\0' && *str != ' ')
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
bb_error_msg_and_die("corrupted octal value in tar header");
return v;
}
#define GET_OCTAL(a) getOctal((a), sizeof(a))
void BUG_tar_header_size(void);
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
char get_header_tar(archive_handle_t *archive_handle)
{
static smallint end;
file_header_t *file_header = archive_handle->file_header;
struct {
/* ustar header, Posix 1003.1 */
@@ -116,9 +61,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
char linkname[100]; /* 157-256 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by
* version[2], but we put them together to simplify code
*/
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
@@ -134,15 +76,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#endif
int parse_names;
/* Our "private data" */
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
# define p_longname (archive_handle->tar__longname)
# define p_linkname (archive_handle->tar__linkname)
#else
# define p_longname 0
# define p_linkname 0
#endif
if (sizeof(tar) != 512)
BUG_tar_header_size();
@@ -154,87 +87,32 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
again_after_align:
#if ENABLE_DESKTOP || ENABLE_FEATURE_TAR_AUTODETECT
/* to prevent misdetection of bz2 sig */
*(uint32_t*)(&tar) = 0;
i = full_read(archive_handle->src_fd, &tar, 512);
/* If GNU tar sees EOF in above read, it says:
* "tar: A lone zero block at N", where N = kilobyte
* where EOF was met (not EOF block, actual EOF!),
* and exits with EXIT_SUCCESS.
* We will mimic exit(EXIT_SUCCESS), although we will not mimic
* the message and we don't check whether we indeed
* saw zero block directly before this. */
if (i == 0) {
xfunc_error_retval = 0;
short_read:
bb_error_msg_and_die("short read");
}
if (i != 512) {
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
goto short_read;
}
#else
i = 512;
xread(archive_handle->src_fd, &tar, i);
#endif
archive_handle->offset += i;
xread(archive_handle->src_fd, &tar, 512);
archive_handle->offset += 512;
/* If there is no filename its an empty header */
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
if (archive_handle->tar__end) {
/* Second consecutive empty header - end of archive.
if (tar.name[0] == 0) {
if (end) {
/* This is the second consecutive empty header! End of archive!
* Read until the end to empty the pipe from gz or bz2
*/
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
continue;
/* repeat */;
return EXIT_FAILURE;
}
archive_handle->tar__end = 1;
end = 1;
return EXIT_SUCCESS;
}
archive_handle->tar__end = 0;
end = 0;
/* Check header has valid magic, "ustar" is for the proper tar,
* five NULs are for the old tar format */
if (strncmp(tar.magic, "ustar", 5) != 0
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
) {
#if ENABLE_FEATURE_TAR_AUTODETECT
char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
autodetect:
/* tar gz/bz autodetect: check for gz/bz2 magic.
* If we see the magic, and it is the very first block,
* we can switch to get_header_tar_gz/bz2/lzma().
* Needs seekable fd. I wish recv(MSG_PEEK) works
* on any fd... */
#if ENABLE_FEATURE_SEAMLESS_GZ
if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
get_header_ptr = get_header_tar_gz;
} else
/* Check header has valid magic, "ustar" is for the proper tar
* 0's are for the old tar format
*/
if (strncmp(tar.magic, "ustar", 5) != 0) {
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
if (memcmp(tar.magic, "\0\0\0\0", 5) != 0)
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
if (tar.name[0] == 'B' && tar.name[1] == 'Z'
&& tar.name[2] == 'h' && isdigit(tar.name[3])
) { /* bzip2 */
get_header_ptr = get_header_tar_bz2;
} else
#endif
goto err;
/* Two different causes for lseek() != 0:
* unseekable fd (would like to support that too, but...),
* or not first block (false positive, it's not .gz/.bz2!) */
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
goto err;
while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
continue;
return EXIT_FAILURE;
err:
#endif /* FEATURE_TAR_AUTODETECT */
bb_error_msg_and_die("invalid tar magic");
bb_error_msg_and_die("invalid tar magic");
}
/* Do checksum on headers.
@@ -257,21 +135,20 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
sum_s += ((signed char*)&tar)[i];
#endif
}
/* 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)) {
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
sum = strtoul(tar.chksum, &cp, 8);
if ((*cp && *cp != ' ')
|| (sum_u != sum USE_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
) {
bb_error_msg_and_die("invalid tar header checksum");
}
#else
/* This field does not need special treatment (getOctal) */
sum = xstrtoul(tar.chksum, 8);
if (sum_u != sum USE_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
bb_error_msg_and_die("invalid tar header checksum");
}
#endif
/* 0 is reserved for high perf file, treat as normal file */
if (!tar.typeflag) tar.typeflag = '0';
@@ -280,46 +157,32 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* getOctal trashes subsequent field, therefore we call it
* on fields in reverse order */
if (tar.devmajor[0]) {
char t = tar.prefix[0];
/* we trash prefix[0] here, but we DO need it later! */
unsigned minor = GET_OCTAL(tar.devminor);
unsigned major = GET_OCTAL(tar.devmajor);
file_header->device = makedev(major, minor);
tar.prefix[0] = t;
}
file_header->link_target = NULL;
if (!p_linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
if (!linkname && parse_names && tar.linkname[0]) {
/* we trash magic[0] here, it's ok */
tar.linkname[sizeof(tar.linkname)] = '\0';
file_header->link_target = xstrdup(tar.linkname);
/* FIXME: what if we have non-link object with link_target? */
/* Will link_target be free()ed? */
}
#if ENABLE_FEATURE_TAR_UNAME_GNAME
file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
#endif
/* mtime: rudimentally handle GNU tar's "base256 encoding"
* People report tarballs with NEGATIVE unix times encoded that way */
file_header->mtime = (tar.mtime[0] & 0x80) /* base256? */
? 0 /* bogus */
: GET_OCTAL(tar.mtime);
/* size: handle GNU tar's "base256 encoding" */
file_header->size = (tar.size[0] & 0xc0) == 0x80 /* positive base256? */
? getBase256_len12(tar.size)
: GET_OCTAL(tar.size);
file_header->mtime = GET_OCTAL(tar.mtime);
file_header->size = GET_OCTAL(tar.size);
file_header->gid = GET_OCTAL(tar.gid);
file_header->uid = GET_OCTAL(tar.uid);
/* Set bits 0-11 of the files mode */
file_header->mode = 07777 & GET_OCTAL(tar.mode);
file_header->name = NULL;
if (!p_longname && parse_names) {
if (!longname && parse_names) {
/* we trash mode[0] here, it's ok */
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
tar.mode[0] = '\0';
tar.name[sizeof(tar.name)] = '\0';
if (tar.prefix[0]) {
/* and padding[0] */
//tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain
tar.padding[0] = '\0';
tar.prefix[sizeof(tar.prefix)] = '\0';
file_header->name = concat_path_file(tar.prefix, tar.name);
} else
file_header->name = xstrdup(tar.name);
@@ -337,48 +200,43 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
case '0':
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
if (last_char_is(file_header->name, '/')) {
goto set_dir;
}
file_header->mode |= S_IFDIR;
} else
#endif
file_header->mode |= S_IFREG;
break;
case '2':
file_header->mode |= S_IFLNK;
/* have seen tarballs with size field containing
* the size of the link target's name */
size0:
file_header->size = 0;
break;
case '3':
file_header->mode |= S_IFCHR;
goto size0; /* paranoia */
break;
case '4':
file_header->mode |= S_IFBLK;
goto size0;
break;
case '5':
IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:)
file_header->mode |= S_IFDIR;
goto size0;
break;
case '6':
file_header->mode |= S_IFIFO;
goto size0;
break;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
case 'L':
/* free: paranoia: tar with several consecutive longnames */
free(p_longname);
free(longname);
/* For paranoia reasons we allocate extra NUL char */
p_longname = xzalloc(file_header->size + 1);
longname = xzalloc(file_header->size + 1);
/* We read ASCIZ string, including NUL */
xread(archive_handle->src_fd, p_longname, file_header->size);
xread(archive_handle->src_fd, longname, file_header->size);
archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */
/* gcc 4.1.1 didn't optimize it into jump */
/* so we will do it ourself, this also saves stack */
goto again;
case 'K':
free(p_linkname);
p_linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, p_linkname, file_header->size);
free(linkname);
linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, linkname, file_header->size);
archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */
goto again;
@@ -405,16 +263,16 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (p_longname) {
file_header->name = p_longname;
p_longname = NULL;
if (longname) {
file_header->name = longname;
longname = NULL;
}
if (p_linkname) {
file_header->link_target = p_linkname;
p_linkname = NULL;
if (linkname) {
file_header->link_target = linkname;
linkname = NULL;
}
#endif
if (strncmp(file_header->name, "/../"+1, 3) == 0
if (!strncmp(file_header->name, "/../"+1, 3)
|| strstr(file_header->name, "/../")
) {
bb_error_msg_and_die("name with '..' encountered: '%s'",
@@ -426,11 +284,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
cp = last_char_is(file_header->name, '/');
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(/*archive_handle->*/ file_header);
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) *cp = '\0';
archive_handle->ah_flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle);
llist_add_to(&(archive_handle->passed), file_header->name);
} else {
@@ -440,10 +298,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
archive_handle->offset += file_header->size;
free(file_header->link_target);
/* Do not free(file_header->name)! (why?) */
#if ENABLE_FEATURE_TAR_UNAME_GNAME
free(file_header->tar__uname);
free(file_header->tar__gname);
#endif
/* Do not free(file_header->name)! */
return EXIT_SUCCESS;
}
+2 -2
View File
@@ -6,12 +6,12 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
char get_header_tar_bz2(archive_handle_t *archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer(archive_handle->src_fd, unpack_bz2_stream_prime, "bunzip2");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+2 -3
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
char get_header_tar_gz(archive_handle_t *archive_handle)
{
#if BB_MMU
unsigned char magic[2];
@@ -20,13 +20,12 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
* need the header. */
#if BB_MMU
xread(archive_handle->src_fd, &magic, 2);
/* Can skip this check, but error message will be less clear */
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("invalid gzip magic");
}
#endif
open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+2 -2
View File
@@ -9,12 +9,12 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
char get_header_tar_lzma(archive_handle_t * archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -2
View File
@@ -5,8 +5,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_list(const file_header_t *file_header)
void header_list(const file_header_t *file_header)
{
//TODO: cpio -vp DIR should output "DIR/NAME", not just "NAME" */
puts(file_header->name);
}
+1 -1
View File
@@ -5,6 +5,6 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
void header_skip(const file_header_t *file_header ATTRIBUTE_UNUSED)
{
}
+11 -49
View File
@@ -6,61 +6,23 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
void header_verbose_list(const file_header_t *file_header)
{
struct tm tm_time;
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
struct tm *mtime = localtime(&(file_header->mtime));
#if ENABLE_FEATURE_TAR_UNAME_GNAME
char uid[sizeof(int)*3 + 2];
/*char gid[sizeof(int)*3 + 2];*/
char *user;
char *group;
localtime_r(&file_header->mtime, ptm);
user = file_header->tar__uname;
if (user == NULL) {
sprintf(uid, "%u", (unsigned)file_header->uid);
user = uid;
}
group = file_header->tar__gname;
if (group == NULL) {
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
group = utoa(file_header->gid);
}
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
bb_mode_string(file_header->mode),
user,
group,
file_header->uid,
file_header->gid,
file_header->size,
1900 + ptm->tm_year,
1 + ptm->tm_mon,
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
1900 + mtime->tm_year,
1 + mtime->tm_mon,
mtime->tm_mday,
mtime->tm_hour,
mtime->tm_min,
mtime->tm_sec,
file_header->name);
#else /* !FEATURE_TAR_UNAME_GNAME */
localtime_r(&file_header->mtime, ptm);
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,
1900 + ptm->tm_year,
1 + ptm->tm_mon,
ptm->tm_mday,
ptm->tm_hour,
ptm->tm_min,
ptm->tm_sec,
file_header->name);
#endif /* FEATURE_TAR_UNAME_GNAME */
if (file_header->link_target) {
printf(" -> %s", file_header->link_target);
}
+1 -1
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
archive_handle_t* FAST_FUNC init_handle(void)
archive_handle_t *init_handle(void)
{
archive_handle_t *archive_handle;
+26 -30
View File
@@ -8,57 +8,53 @@
/* transformer(), more than meets the eye */
/*
* On MMU machine, the transform_prog is removed by macro magic
* in include/unarchive.h. On NOMMU, transformer is removed.
* On MMU machine, the transform_prog and ... are stripped
* by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
*/
void FAST_FUNC open_transformer(int fd,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
const char *transform_prog)
int open_transformer(int src_fd,
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
const char *transform_prog, ...)
{
struct fd_pair fd_pipe;
int fd_pipe[2];
int pid;
xpiped_pair(fd_pipe);
xpipe(fd_pipe);
#if BB_MMU
pid = fork();
if (pid == -1)
bb_perror_msg_and_die("vfork" + 1);
#else
pid = vfork();
if (pid == -1)
bb_perror_msg_and_die("vfork");
#endif
if (pid == -1)
bb_perror_msg_and_die("fork failed");
if (pid == 0) {
#if !BB_MMU
va_list ap;
#endif
/* child process */
close(fd_pipe.rd); /* we don't want to read from the parent */
close(fd_pipe[0]); /* We don't wan't to read from the parent */
// FIXME: error check?
#if BB_MMU
transformer(fd, fd_pipe.wr);
transformer(src_fd, fd_pipe[1]);
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd_pipe.wr); /* send EOF */
close(fd);
close(fd_pipe[1]); /* Send EOF */
close(src_fd);
}
/* must be _exit! bug was actually seen here */
_exit(EXIT_SUCCESS);
exit(0);
#else
{
char *argv[4];
xmove_fd(fd, 0);
xmove_fd(fd_pipe.wr, 1);
argv[0] = (char*)transform_prog;
argv[1] = (char*)"-cf";
argv[2] = (char*)"-";
argv[3] = NULL;
BB_EXECVP(transform_prog, argv);
bb_perror_msg_and_die("can't execute '%s'", transform_prog);
}
xmove_fd(src_fd, 0);
xmove_fd(fd_pipe[1], 1);
va_start(ap, transform_prog);
/* hoping that va_list -> char** on our CPU is working... */
BB_EXECVP(transform_prog, (void*)ap);
bb_perror_msg_and_die("exec failed");
#endif
/* notreached */
}
/* parent process */
close(fd_pipe.wr); /* don't want to write to the child */
xmove_fd(fd_pipe.rd, fd);
close(fd_pipe[1]); /* Don't want to write to the child */
return fd_pipe[0];
}
+7 -7
View File
@@ -6,14 +6,14 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC seek_by_jump(int fd, off_t amount)
void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount)
{
if (amount
&& lseek(fd, amount, SEEK_CUR) == (off_t) -1
) {
if (errno == ESPIPE)
seek_by_read(fd, amount);
else
if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
#if ENABLE_FEATURE_UNARCHIVE_TAPE
if (errno == ESPIPE) {
seek_by_read(archive_handle, amount);
} else
#endif
bb_perror_msg_and_die("seek failure");
}
}
+4 -4
View File
@@ -6,11 +6,11 @@
#include "libbb.h"
#include "unarchive.h"
/* If we are reading through a pipe, or from stdin then we can't lseek,
/* If we are reading through a pipe(), or from stdin then we can't lseek,
* we must read and discard the data to skip over it.
*/
void FAST_FUNC seek_by_read(int fd, off_t amount)
void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
{
if (amount)
bb_copyfd_exact_size(fd, -1, amount);
if (jump_size)
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
}
+2 -3
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
void unpack_ar_archive(archive_handle_t *ar_archive)
{
char magic[7];
@@ -16,6 +16,5 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
}
ar_archive->offset += 7;
while (get_header_ar(ar_archive) == EXIT_SUCCESS)
continue;
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
}
-35
View File
@@ -1,35 +0,0 @@
/* LZO1X-1 compression
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "libbb.h"
#include "liblzo.h"
#define D_BITS 14
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
#define DO_COMPRESS lzo1x_1_compress
#include "lzo1x_c.c"
-35
View File
@@ -1,35 +0,0 @@
/* LZO1X-1(15) compression
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "libbb.h"
#include "liblzo.h"
#define D_BITS 15
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
#define DO_COMPRESS lzo1x_1_15_compress
#include "lzo1x_c.c"
-920
View File
@@ -1,920 +0,0 @@
/* lzo1x_9x.c -- implementation of the LZO1X-999 compression algorithm
This file is part of the LZO real-time data compression library.
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
#include "libbb.h"
/* The following is probably only safe on Intel-compatible processors ... */
#define LZO_UNALIGNED_OK_2
#define LZO_UNALIGNED_OK_4
#include "liblzo.h"
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
/***********************************************************************
//
************************************************************************/
#define SWD_N M4_MAX_OFFSET /* size of ring buffer */
#define SWD_F 2048 /* upper limit for match length */
#define SWD_BEST_OFF (LZO_MAX3(M2_MAX_LEN, M3_MAX_LEN, M4_MAX_LEN) + 1)
typedef struct {
int init;
unsigned look; /* bytes in lookahead buffer */
unsigned m_len;
unsigned m_off;
const uint8_t *bp;
const uint8_t *ip;
const uint8_t *in;
const uint8_t *in_end;
uint8_t *out;
unsigned r1_lit;
} lzo1x_999_t;
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
/* lzo_swd.c -- sliding window dictionary */
/***********************************************************************
//
************************************************************************/
#define SWD_UINT_MAX USHRT_MAX
#ifndef SWD_HSIZE
# define SWD_HSIZE 16384
#endif
#ifndef SWD_MAX_CHAIN
# define SWD_MAX_CHAIN 2048
#endif
#define HEAD3(b, p) \
( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) )
#if defined(LZO_UNALIGNED_OK_2)
# define HEAD2(b,p) (* (uint16_t *) &(b[p]))
#else
# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
#endif
#define NIL2 SWD_UINT_MAX
typedef struct lzo_swd {
/* public - "built-in" */
/* public - configuration */
unsigned max_chain;
int use_best_off;
/* public - output */
unsigned m_len;
unsigned m_off;
unsigned look;
int b_char;
#if defined(SWD_BEST_OFF)
unsigned best_off[SWD_BEST_OFF];
#endif
/* semi public */
lzo1x_999_t *c;
unsigned m_pos;
#if defined(SWD_BEST_OFF)
unsigned best_pos[SWD_BEST_OFF];
#endif
/* private */
unsigned ip; /* input pointer (lookahead) */
unsigned bp; /* buffer pointer */
unsigned rp; /* remove pointer */
unsigned node_count;
unsigned first_rp;
uint8_t b[SWD_N + SWD_F];
uint8_t b_wrap[SWD_F]; /* must follow b */
uint16_t head3[SWD_HSIZE];
uint16_t succ3[SWD_N + SWD_F];
uint16_t best3[SWD_N + SWD_F];
uint16_t llen3[SWD_HSIZE];
#ifdef HEAD2
uint16_t head2[65536L];
#endif
} lzo_swd_t, *lzo_swd_p;
#define SIZEOF_LZO_SWD_T (sizeof(lzo_swd_t))
/* Access macro for head3.
* head3[key] may be uninitialized, but then its value will never be used.
*/
#define s_get_head3(s,key) s->head3[key]
/***********************************************************************
//
************************************************************************/
#define B_SIZE (SWD_N + SWD_F)
static int swd_init(lzo_swd_p s)
{
/* defaults */
s->node_count = SWD_N;
memset(s->llen3, 0, sizeof(s->llen3[0]) * (unsigned)SWD_HSIZE);
#ifdef HEAD2
memset(s->head2, 0xff, sizeof(s->head2[0]) * 65536L);
assert(s->head2[0] == NIL2);
#endif
s->ip = 0;
s->bp = s->ip;
s->first_rp = s->ip;
assert(s->ip + SWD_F <= B_SIZE);
s->look = (unsigned) (s->c->in_end - s->c->ip);
if (s->look > 0) {
if (s->look > SWD_F)
s->look = SWD_F;
memcpy(&s->b[s->ip],s->c->ip,s->look);
s->c->ip += s->look;
s->ip += s->look;
}
if (s->ip == B_SIZE)
s->ip = 0;
s->rp = s->first_rp;
if (s->rp >= s->node_count)
s->rp -= s->node_count;
else
s->rp += B_SIZE - s->node_count;
return LZO_E_OK;
}
#define swd_pos2off(s,pos) \
(s->bp > (pos) ? s->bp - (pos) : B_SIZE - ((pos) - s->bp))
/***********************************************************************
//
************************************************************************/
static void swd_getbyte(lzo_swd_p s)
{
int c;
if ((c = getbyte(*(s->c))) < 0) {
if (s->look > 0)
--s->look;
} else {
s->b[s->ip] = c;
if (s->ip < SWD_F)
s->b_wrap[s->ip] = c;
}
if (++s->ip == B_SIZE)
s->ip = 0;
if (++s->bp == B_SIZE)
s->bp = 0;
if (++s->rp == B_SIZE)
s->rp = 0;
}
/***********************************************************************
// remove node from lists
************************************************************************/
static void swd_remove_node(lzo_swd_p s, unsigned node)
{
if (s->node_count == 0) {
unsigned key;
key = HEAD3(s->b,node);
assert(s->llen3[key] > 0);
--s->llen3[key];
#ifdef HEAD2
key = HEAD2(s->b,node);
assert(s->head2[key] != NIL2);
if ((unsigned) s->head2[key] == node)
s->head2[key] = NIL2;
#endif
} else
--s->node_count;
}
/***********************************************************************
//
************************************************************************/
static void swd_accept(lzo_swd_p s, unsigned n)
{
assert(n <= s->look);
while (n--) {
unsigned key;
swd_remove_node(s,s->rp);
/* add bp into HEAD3 */
key = HEAD3(s->b,s->bp);
s->succ3[s->bp] = s_get_head3(s,key);
s->head3[key] = s->bp;
s->best3[s->bp] = SWD_F + 1;
s->llen3[key]++;
assert(s->llen3[key] <= SWD_N);
#ifdef HEAD2
/* add bp into HEAD2 */
key = HEAD2(s->b,s->bp);
s->head2[key] = s->bp;
#endif
swd_getbyte(s);
}
}
/***********************************************************************
//
************************************************************************/
static void swd_search(lzo_swd_p s, unsigned node, unsigned cnt)
{
const uint8_t *p1;
const uint8_t *p2;
const uint8_t *px;
unsigned m_len = s->m_len;
const uint8_t *b = s->b;
const uint8_t *bp = s->b + s->bp;
const uint8_t *bx = s->b + s->bp + s->look;
unsigned char scan_end1;
assert(s->m_len > 0);
scan_end1 = bp[m_len - 1];
for ( ; cnt-- > 0; node = s->succ3[node]) {
p1 = bp;
p2 = b + node;
px = bx;
assert(m_len < s->look);
if (p2[m_len - 1] == scan_end1 &&
p2[m_len] == p1[m_len] &&
p2[0] == p1[0] &&
p2[1] == p1[1]) {
unsigned i;
assert(lzo_memcmp(bp,&b[node],3) == 0);
p1 += 2; p2 += 2;
do {} while (++p1 < px && *p1 == *++p2);
i = p1-bp;
assert(lzo_memcmp(bp,&b[node],i) == 0);
#if defined(SWD_BEST_OFF)
if (i < SWD_BEST_OFF) {
if (s->best_pos[i] == 0)
s->best_pos[i] = node + 1;
}
#endif
if (i > m_len) {
s->m_len = m_len = i;
s->m_pos = node;
if (m_len == s->look)
return;
if (m_len >= SWD_F)
return;
if (m_len > (unsigned) s->best3[node])
return;
scan_end1 = bp[m_len - 1];
}
}
}
}
/***********************************************************************
//
************************************************************************/
#ifdef HEAD2
static int swd_search2(lzo_swd_p s)
{
unsigned key;
assert(s->look >= 2);
assert(s->m_len > 0);
key = s->head2[ HEAD2(s->b,s->bp) ];
if (key == NIL2)
return 0;
assert(lzo_memcmp(&s->b[s->bp],&s->b[key],2) == 0);
#if defined(SWD_BEST_OFF)
if (s->best_pos[2] == 0)
s->best_pos[2] = key + 1;
#endif
if (s->m_len < 2) {
s->m_len = 2;
s->m_pos = key;
}
return 1;
}
#endif
/***********************************************************************
//
************************************************************************/
static void swd_findbest(lzo_swd_p s)
{
unsigned key;
unsigned cnt, node;
unsigned len;
assert(s->m_len > 0);
/* get current head, add bp into HEAD3 */
key = HEAD3(s->b,s->bp);
node = s->succ3[s->bp] = s_get_head3(s,key);
cnt = s->llen3[key]++;
assert(s->llen3[key] <= SWD_N + SWD_F);
if (cnt > s->max_chain)
cnt = s->max_chain;
s->head3[key] = s->bp;
s->b_char = s->b[s->bp];
len = s->m_len;
if (s->m_len >= s->look) {
if (s->look == 0)
s->b_char = -1;
s->m_off = 0;
s->best3[s->bp] = SWD_F + 1;
} else {
#ifdef HEAD2
if (swd_search2(s))
#endif
if (s->look >= 3)
swd_search(s,node,cnt);
if (s->m_len > len)
s->m_off = swd_pos2off(s,s->m_pos);
s->best3[s->bp] = s->m_len;
#if defined(SWD_BEST_OFF)
if (s->use_best_off) {
int i;
for (i = 2; i < SWD_BEST_OFF; i++)
if (s->best_pos[i] > 0)
s->best_off[i] = swd_pos2off(s,s->best_pos[i]-1);
else
s->best_off[i] = 0;
}
#endif
}
swd_remove_node(s,s->rp);
#ifdef HEAD2
/* add bp into HEAD2 */
key = HEAD2(s->b,s->bp);
s->head2[key] = s->bp;
#endif
}
#undef HEAD3
#undef HEAD2
#undef s_get_head3
/***********************************************************************
//
************************************************************************/
static int init_match(lzo1x_999_t *c, lzo_swd_p s, uint32_t use_best_off)
{
int r;
assert(!c->init);
c->init = 1;
s->c = c;
r = swd_init(s);
if (r != 0)
return r;
s->use_best_off = use_best_off;
return r;
}
/***********************************************************************
//
************************************************************************/
static int find_match(lzo1x_999_t *c, lzo_swd_p s,
unsigned this_len, unsigned skip)
{
assert(c->init);
if (skip > 0) {
assert(this_len >= skip);
swd_accept(s, this_len - skip);
} else {
assert(this_len <= 1);
}
s->m_len = 1;
s->m_len = 1;
#ifdef SWD_BEST_OFF
if (s->use_best_off)
memset(s->best_pos,0,sizeof(s->best_pos));
#endif
swd_findbest(s);
c->m_len = s->m_len;
c->m_off = s->m_off;
swd_getbyte(s);
if (s->b_char < 0) {
c->look = 0;
c->m_len = 0;
} else {
c->look = s->look + 1;
}
c->bp = c->ip - c->look;
return LZO_E_OK;
}
/* this is a public functions, but there is no prototype in a header file */
static int lzo1x_999_compress_internal(const uint8_t *in , unsigned in_len,
uint8_t *out, unsigned *out_len,
void *wrkmem,
unsigned good_length,
unsigned max_lazy,
unsigned max_chain,
uint32_t use_best_off);
/***********************************************************************
//
************************************************************************/
static uint8_t *code_match(lzo1x_999_t *c,
uint8_t *op, unsigned m_len, unsigned m_off)
{
assert(op > c->out);
if (m_len == 2) {
assert(m_off <= M1_MAX_OFFSET);
assert(c->r1_lit > 0); assert(c->r1_lit < 4);
m_off -= 1;
*op++ = M1_MARKER | ((m_off & 3) << 2);
*op++ = m_off >> 2;
} else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) {
assert(m_len >= 3);
m_off -= 1;
*op++ = ((m_len - 1) << 5) | ((m_off & 7) << 2);
*op++ = m_off >> 3;
assert(op[-2] >= M2_MARKER);
} else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4) {
assert(m_len == 3);
assert(m_off > M2_MAX_OFFSET);
m_off -= 1 + M2_MAX_OFFSET;
*op++ = M1_MARKER | ((m_off & 3) << 2);
*op++ = m_off >> 2;
} else if (m_off <= M3_MAX_OFFSET) {
assert(m_len >= 3);
m_off -= 1;
if (m_len <= M3_MAX_LEN)
*op++ = M3_MARKER | (m_len - 2);
else {
m_len -= M3_MAX_LEN;
*op++ = M3_MARKER | 0;
while (m_len > 255)
{
m_len -= 255;
*op++ = 0;
}
assert(m_len > 0);
*op++ = m_len;
}
*op++ = m_off << 2;
*op++ = m_off >> 6;
} else {
unsigned k;
assert(m_len >= 3);
assert(m_off > 0x4000); assert(m_off <= 0xbfff);
m_off -= 0x4000;
k = (m_off & 0x4000) >> 11;
if (m_len <= M4_MAX_LEN)
*op++ = M4_MARKER | k | (m_len - 2);
else {
m_len -= M4_MAX_LEN;
*op++ = M4_MARKER | k | 0;
while (m_len > 255)
{
m_len -= 255;
*op++ = 0;
}
assert(m_len > 0);
*op++ = m_len;
}
*op++ = m_off << 2;
*op++ = m_off >> 6;
}
return op;
}
static uint8_t *STORE_RUN(lzo1x_999_t *c, uint8_t *op,
const uint8_t *ii, unsigned t)
{
if (op == c->out && t <= 238) {
*op++ = 17 + t;
} else if (t <= 3) {
op[-2] |= t;
} else if (t <= 18) {
*op++ = t - 3;
} else {
unsigned tt = t - 18;
*op++ = 0;
while (tt > 255) {
tt -= 255;
*op++ = 0;
}
assert(tt > 0);
*op++ = tt;
}
do *op++ = *ii++; while (--t > 0);
return op;
}
static uint8_t *code_run(lzo1x_999_t *c, uint8_t *op, const uint8_t *ii,
unsigned lit)
{
if (lit > 0) {
assert(m_len >= 2);
op = STORE_RUN(c,op,ii,lit);
} else {
assert(m_len >= 3);
}
c->r1_lit = lit;
return op;
}
/***********************************************************************
//
************************************************************************/
static int len_of_coded_match(unsigned m_len, unsigned m_off, unsigned lit)
{
int n = 4;
if (m_len < 2)
return -1;
if (m_len == 2)
return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : -1;
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
return 2;
if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
return 2;
if (m_off <= M3_MAX_OFFSET) {
if (m_len <= M3_MAX_LEN)
return 3;
m_len -= M3_MAX_LEN;
} else if (m_off <= M4_MAX_OFFSET) {
if (m_len <= M4_MAX_LEN)
return 3;
m_len -= M4_MAX_LEN;
} else
return -1;
while (m_len > 255) {
m_len -= 255;
n++;
}
return n;
}
static int min_gain(unsigned ahead, unsigned lit1,
unsigned lit2, int l1, int l2, int l3)
{
int lazy_match_min_gain = 0;
assert (ahead >= 1);
lazy_match_min_gain += ahead;
if (lit1 <= 3)
lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
else if (lit1 <= 18)
lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
lazy_match_min_gain += (l2 - l1) * 2;
if (l3 > 0)
lazy_match_min_gain -= (ahead - l3) * 2;
if (lazy_match_min_gain < 0)
lazy_match_min_gain = 0;
return lazy_match_min_gain;
}
/***********************************************************************
//
************************************************************************/
#if defined(SWD_BEST_OFF)
static void better_match(const lzo_swd_p swd,
unsigned *m_len, unsigned *m_off)
{
if (*m_len <= M2_MIN_LEN)
return;
if (*m_off <= M2_MAX_OFFSET)
return;
/* M3/M4 -> M2 */
if (*m_off > M2_MAX_OFFSET &&
*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
{
*m_len = *m_len - 1;
*m_off = swd->best_off[*m_len];
return;
}
/* M4 -> M2 */
if (*m_off > M3_MAX_OFFSET &&
*m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
{
*m_len = *m_len - 2;
*m_off = swd->best_off[*m_len];
return;
}
/* M4 -> M3 */
if (*m_off > M3_MAX_OFFSET &&
*m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
{
*m_len = *m_len - 1;
*m_off = swd->best_off[*m_len];
}
}
#endif
/***********************************************************************
//
************************************************************************/
static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
uint8_t *out, unsigned *out_len,
void *wrkmem,
unsigned good_length,
unsigned max_lazy,
unsigned max_chain,
uint32_t use_best_off)
{
uint8_t *op;
const uint8_t *ii;
unsigned lit;
unsigned m_len, m_off;
lzo1x_999_t cc;
lzo1x_999_t * const c = &cc;
lzo_swd_p const swd = (lzo_swd_p) wrkmem;
int r;
c->init = 0;
c->ip = c->in = in;
c->in_end = in + in_len;
c->out = out;
op = out;
ii = c->ip; /* point to start of literal run */
lit = 0;
c->r1_lit = 0;
r = init_match(c, swd, use_best_off);
if (r != 0)
return r;
swd->max_chain = max_chain;
r = find_match(c, swd, 0, 0);
if (r != 0)
return r;
while (c->look > 0) {
unsigned ahead;
unsigned max_ahead;
int l1, l2, l3;
m_len = c->m_len;
m_off = c->m_off;
assert(c->bp == c->ip - c->look);
assert(c->bp >= in);
if (lit == 0)
ii = c->bp;
assert(ii + lit == c->bp);
assert(swd->b_char == *(c->bp));
if ( m_len < 2 ||
(m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
/* Do not accept this match for compressed-data compatibility
* with LZO v1.01 and before
* [ might be a problem for decompress() and optimize() ]
*/
(m_len == 2 && op == out) ||
(op == out && lit == 0))
{
/* a literal */
m_len = 0;
}
else if (m_len == M2_MIN_LEN) {
/* compression ratio improves if we code a literal in some cases */
if (m_off > MX_MAX_OFFSET && lit >= 4)
m_len = 0;
}
if (m_len == 0) {
/* a literal */
lit++;
swd->max_chain = max_chain;
r = find_match(c,swd,1,0);
assert(r == 0);
continue;
}
/* a match */
#if defined(SWD_BEST_OFF)
if (swd->use_best_off)
better_match(swd,&m_len,&m_off);
#endif
/* shall we try a lazy match ? */
ahead = 0;
if (m_len >= max_lazy) {
/* no */
l1 = 0;
max_ahead = 0;
} else {
/* yes, try a lazy match */
l1 = len_of_coded_match(m_len,m_off,lit);
assert(l1 > 0);
max_ahead = LZO_MIN(2, (unsigned)l1 - 1);
}
while (ahead < max_ahead && c->look > m_len) {
int lazy_match_min_gain;
if (m_len >= good_length)
swd->max_chain = max_chain >> 2;
else
swd->max_chain = max_chain;
r = find_match(c,swd,1,0);
ahead++;
assert(r == 0);
assert(c->look > 0);
assert(ii + lit + ahead == c->bp);
if (c->m_len < m_len)
continue;
if (c->m_len == m_len && c->m_off >= m_off)
continue;
#if defined(SWD_BEST_OFF)
if (swd->use_best_off)
better_match(swd,&c->m_len,&c->m_off);
#endif
l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
if (l2 < 0)
continue;
/* compressed-data compatibility [see above] */
l3 = (op == out) ? -1 : len_of_coded_match(ahead,m_off,lit);
lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
if (c->m_len >= m_len + lazy_match_min_gain) {
if (l3 > 0) {
/* code previous run */
op = code_run(c,op,ii,lit);
lit = 0;
/* code shortened match */
op = code_match(c,op,ahead,m_off);
} else {
lit += ahead;
assert(ii + lit == c->bp);
}
goto lazy_match_done;
}
}
assert(ii + lit + ahead == c->bp);
/* 1 - code run */
op = code_run(c,op,ii,lit);
lit = 0;
/* 2 - code match */
op = code_match(c,op,m_len,m_off);
swd->max_chain = max_chain;
r = find_match(c,swd,m_len,1+ahead);
assert(r == 0);
lazy_match_done: ;
}
/* store final run */
if (lit > 0)
op = STORE_RUN(c,op,ii,lit);
#if defined(LZO_EOF_CODE)
*op++ = M4_MARKER | 1;
*op++ = 0;
*op++ = 0;
#endif
*out_len = op - out;
return LZO_E_OK;
}
/***********************************************************************
//
************************************************************************/
int lzo1x_999_compress_level(const uint8_t *in, unsigned in_len,
uint8_t *out, unsigned *out_len,
void *wrkmem,
int compression_level)
{
static const struct {
uint16_t good_length;
uint16_t max_lazy;
uint16_t max_chain;
uint16_t use_best_off;
} c[3] = {
{ 8, 32, 256, 0 },
{ 32, 128, 2048, 1 },
{ SWD_F, SWD_F, 4096, 1 } /* max. compression */
};
if (compression_level < 7 || compression_level > 9)
return LZO_E_ERROR;
compression_level -= 7;
return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
c[compression_level].good_length,
c[compression_level].max_lazy,
c[compression_level].max_chain,
c[compression_level].use_best_off);
}
-296
View File
@@ -1,296 +0,0 @@
/* implementation of the LZO1[XY]-1 compression algorithm
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/***********************************************************************
// compress a block of data.
************************************************************************/
static NOINLINE unsigned
do_compress(const uint8_t* in, unsigned in_len,
uint8_t* out, unsigned* out_len,
void* wrkmem)
{
register const uint8_t* ip;
uint8_t* op;
const uint8_t* const in_end = in + in_len;
const uint8_t* const ip_end = in + in_len - M2_MAX_LEN - 5;
const uint8_t* ii;
const void* *const dict = (const void**) wrkmem;
op = out;
ip = in;
ii = ip;
ip += 4;
for (;;) {
register const uint8_t* m_pos;
unsigned m_off;
unsigned m_len;
unsigned dindex;
D_INDEX1(dindex,ip);
GINDEX(m_pos,m_off,dict,dindex,in);
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
goto literal;
#if 1
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match;
D_INDEX2(dindex,ip);
#endif
GINDEX(m_pos,m_off,dict,dindex,in);
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
goto literal;
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
goto try_match;
goto literal;
try_match:
#if 1 && defined(LZO_UNALIGNED_OK_2)
if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
#else
if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
#endif
{
} else {
if (m_pos[2] == ip[2]) {
#if 0
if (m_off <= M2_MAX_OFFSET)
goto match;
if (lit <= 3)
goto match;
if (lit == 3) { /* better compression, but slower */
assert(op - 2 > out); op[-2] |= (uint8_t)(3);
*op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
goto code_match;
}
if (m_pos[3] == ip[3])
#endif
goto match;
}
else {
/* still need a better way for finding M1 matches */
#if 0
/* a M1 match */
#if 0
if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
#else
if (m_off <= M1_MAX_OFFSET && lit == 3)
#endif
{
register unsigned t;
t = lit;
assert(op - 2 > out); op[-2] |= (uint8_t)(t);
do *op++ = *ii++; while (--t > 0);
assert(ii == ip);
m_off -= 1;
*op++ = (uint8_t)(M1_MARKER | ((m_off & 3) << 2));
*op++ = (uint8_t)(m_off >> 2);
ip += 2;
goto match_done;
}
#endif
}
}
/* a literal */
literal:
UPDATE_I(dict, 0, dindex, ip, in);
++ip;
if (ip >= ip_end)
break;
continue;
/* a match */
match:
UPDATE_I(dict, 0, dindex, ip, in);
/* store current literal run */
if (pd(ip, ii) > 0) {
register unsigned t = pd(ip, ii);
if (t <= 3) {
assert(op - 2 > out);
op[-2] |= (uint8_t)(t);
}
else if (t <= 18)
*op++ = (uint8_t)(t - 3);
else {
register unsigned tt = t - 18;
*op++ = 0;
while (tt > 255) {
tt -= 255;
*op++ = 0;
}
assert(tt > 0);
*op++ = (uint8_t)(tt);
}
do *op++ = *ii++; while (--t > 0);
}
/* code the match */
assert(ii == ip);
ip += 3;
if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++
|| m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++
#ifdef LZO1Y
|| m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++
|| m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++
#endif
) {
--ip;
m_len = pd(ip, ii);
assert(m_len >= 3);
assert(m_len <= M2_MAX_LEN);
if (m_off <= M2_MAX_OFFSET) {
m_off -= 1;
#if defined(LZO1X)
*op++ = (uint8_t)(((m_len - 1) << 5) | ((m_off & 7) << 2));
*op++ = (uint8_t)(m_off >> 3);
#elif defined(LZO1Y)
*op++ = (uint8_t)(((m_len + 1) << 4) | ((m_off & 3) << 2));
*op++ = (uint8_t)(m_off >> 2);
#endif
}
else if (m_off <= M3_MAX_OFFSET) {
m_off -= 1;
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
goto m3_m4_offset;
} else {
#if defined(LZO1X)
m_off -= 0x4000;
assert(m_off > 0);
assert(m_off <= 0x7fff);
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
goto m3_m4_offset;
#elif defined(LZO1Y)
goto m4_match;
#endif
}
}
else {
{
const uint8_t* end = in_end;
const uint8_t* m = m_pos + M2_MAX_LEN + 1;
while (ip < end && *m == *ip)
m++, ip++;
m_len = pd(ip, ii);
}
assert(m_len > M2_MAX_LEN);
if (m_off <= M3_MAX_OFFSET) {
m_off -= 1;
if (m_len <= 33)
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
else {
m_len -= 33;
*op++ = M3_MARKER | 0;
goto m3_m4_len;
}
} else {
#if defined(LZO1Y)
m4_match:
#endif
m_off -= 0x4000;
assert(m_off > 0);
assert(m_off <= 0x7fff);
if (m_len <= M4_MAX_LEN)
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
else {
m_len -= M4_MAX_LEN;
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11));
m3_m4_len:
while (m_len > 255) {
m_len -= 255;
*op++ = 0;
}
assert(m_len > 0);
*op++ = (uint8_t)(m_len);
}
}
m3_m4_offset:
*op++ = (uint8_t)((m_off & 63) << 2);
*op++ = (uint8_t)(m_off >> 6);
}
#if 0
match_done:
#endif
ii = ip;
if (ip >= ip_end)
break;
}
*out_len = pd(op, out);
return pd(in_end, ii);
}
/***********************************************************************
// public entry point
************************************************************************/
int DO_COMPRESS(const uint8_t* in, unsigned in_len,
uint8_t* out, unsigned* out_len,
void* wrkmem)
{
uint8_t* op = out;
unsigned t;
if (in_len <= M2_MAX_LEN + 5)
t = in_len;
else {
t = do_compress(in,in_len,op,out_len,wrkmem);
op += *out_len;
}
if (t > 0) {
const uint8_t* ii = in + in_len - t;
if (op == out && t <= 238)
*op++ = (uint8_t)(17 + t);
else if (t <= 3)
op[-2] |= (uint8_t)(t);
else if (t <= 18)
*op++ = (uint8_t)(t - 3);
else {
unsigned tt = t - 18;
*op++ = 0;
while (tt > 255) {
tt -= 255;
*op++ = 0;
}
assert(tt > 0);
*op++ = (uint8_t)(tt);
}
do *op++ = *ii++; while (--t > 0);
}
*op++ = M4_MARKER | 1;
*op++ = 0;
*op++ = 0;
*out_len = pd(op, out);
return 0; /*LZO_E_OK*/
}
-420
View File
@@ -1,420 +0,0 @@
/* implementation of the LZO1X decompression algorithm
This file is part of the LZO real-time data compression library.
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
Markus F.X.J. Oberhumer <markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "libbb.h"
#include "liblzo.h"
/***********************************************************************
// decompress a block of data.
************************************************************************/
/* safe decompression with overrun testing */
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
uint8_t* out, unsigned* out_len,
void* wrkmem UNUSED_PARAM)
{
register uint8_t* op;
register const uint8_t* ip;
register unsigned t;
#if defined(COPY_DICT)
unsigned m_off;
const uint8_t* dict_end;
#else
register const uint8_t* m_pos = NULL; /* possibly not needed */
#endif
const uint8_t* const ip_end = in + in_len;
#if defined(HAVE_ANY_OP)
uint8_t* const op_end = out + *out_len;
#endif
#if defined(LZO1Z)
unsigned last_m_off = 0;
#endif
// LZO_UNUSED(wrkmem);
#if defined(COPY_DICT)
if (dict) {
if (dict_len > M4_MAX_OFFSET) {
dict += dict_len - M4_MAX_OFFSET;
dict_len = M4_MAX_OFFSET;
}
dict_end = dict + dict_len;
} else {
dict_len = 0;
dict_end = NULL;
}
#endif /* COPY_DICT */
*out_len = 0;
op = out;
ip = in;
if (*ip > 17) {
t = *ip++ - 17;
if (t < 4)
goto match_next;
assert(t > 0); NEED_OP(t); NEED_IP(t+1);
do *op++ = *ip++; while (--t > 0);
goto first_literal_run;
}
while (TEST_IP && TEST_OP) {
t = *ip++;
if (t >= 16)
goto match;
/* a literal run */
if (t == 0) {
NEED_IP(1);
while (*ip == 0) {
t += 255;
ip++;
NEED_IP(1);
}
t += 15 + *ip++;
}
/* copy literals */
assert(t > 0);
NEED_OP(t+3);
NEED_IP(t+4);
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
# if !defined(LZO_UNALIGNED_OK_4)
if (PTR_ALIGNED2_4(op, ip))
# endif
{
COPY4(op, ip);
op += 4;
ip += 4;
if (--t > 0) {
if (t >= 4) {
do {
COPY4(op, ip);
op += 4;
ip += 4;
t -= 4;
} while (t >= 4);
if (t > 0)
do *op++ = *ip++; while (--t > 0);
} else {
do *op++ = *ip++; while (--t > 0);
}
}
}
# if !defined(LZO_UNALIGNED_OK_4)
else
# endif
#endif
#if !defined(LZO_UNALIGNED_OK_4)
{
*op++ = *ip++;
*op++ = *ip++;
*op++ = *ip++;
do *op++ = *ip++; while (--t > 0);
}
#endif
first_literal_run:
t = *ip++;
if (t >= 16)
goto match;
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
last_m_off = m_off;
#else
m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
#endif
NEED_OP(3);
t = 3; COPY_DICT(t,m_off)
#else /* !COPY_DICT */
#if defined(LZO1Z)
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
m_pos = op - t;
last_m_off = t;
#else
m_pos = op - (1 + M2_MAX_OFFSET);
m_pos -= t >> 2;
m_pos -= *ip++ << 2;
#endif
TEST_LB(m_pos); NEED_OP(3);
*op++ = *m_pos++;
*op++ = *m_pos++;
*op++ = *m_pos;
#endif /* COPY_DICT */
goto match_done;
/* handle matches */
do {
match:
if (t >= 64) { /* a M2 match */
#if defined(COPY_DICT)
#if defined(LZO1X)
m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
t = (t >> 5) - 1;
#elif defined(LZO1Y)
m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
t = (t >> 4) - 3;
#elif defined(LZO1Z)
m_off = t & 0x1f;
if (m_off >= 0x1c)
m_off = last_m_off;
else {
m_off = 1 + (m_off << 6) + (*ip++ >> 2);
last_m_off = m_off;
}
t = (t >> 5) - 1;
#endif
#else /* !COPY_DICT */
#if defined(LZO1X)
m_pos = op - 1;
m_pos -= (t >> 2) & 7;
m_pos -= *ip++ << 3;
t = (t >> 5) - 1;
#elif defined(LZO1Y)
m_pos = op - 1;
m_pos -= (t >> 2) & 3;
m_pos -= *ip++ << 2;
t = (t >> 4) - 3;
#elif defined(LZO1Z)
{
unsigned off = t & 0x1f;
m_pos = op;
if (off >= 0x1c) {
assert(last_m_off > 0);
m_pos -= last_m_off;
} else {
off = 1 + (off << 6) + (*ip++ >> 2);
m_pos -= off;
last_m_off = off;
}
}
t = (t >> 5) - 1;
#endif
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
goto copy_match;
#endif /* COPY_DICT */
}
else if (t >= 32) { /* a M3 match */
t &= 31;
if (t == 0) {
NEED_IP(1);
while (*ip == 0) {
t += 255;
ip++;
NEED_IP(1);
}
t += 31 + *ip++;
}
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
last_m_off = m_off;
#else
m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
#endif
#else /* !COPY_DICT */
#if defined(LZO1Z)
{
unsigned off = 1 + (ip[0] << 6) + (ip[1] >> 2);
m_pos = op - off;
last_m_off = off;
}
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
m_pos = op - 1;
m_pos -= (* (const lzo_ushortp) ip) >> 2;
#else
m_pos = op - 1;
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
#endif
#endif /* COPY_DICT */
ip += 2;
}
else if (t >= 16) { /* a M4 match */
#if defined(COPY_DICT)
m_off = (t & 8) << 11;
#else /* !COPY_DICT */
m_pos = op;
m_pos -= (t & 8) << 11;
#endif /* COPY_DICT */
t &= 7;
if (t == 0) {
NEED_IP(1);
while (*ip == 0) {
t += 255;
ip++;
NEED_IP(1);
}
t += 7 + *ip++;
}
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off += (ip[0] << 6) + (ip[1] >> 2);
#else
m_off += (ip[0] >> 2) + (ip[1] << 6);
#endif
ip += 2;
if (m_off == 0)
goto eof_found;
m_off += 0x4000;
#if defined(LZO1Z)
last_m_off = m_off;
#endif
#else /* !COPY_DICT */
#if defined(LZO1Z)
m_pos -= (ip[0] << 6) + (ip[1] >> 2);
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
m_pos -= (* (const lzo_ushortp) ip) >> 2;
#else
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
#endif
ip += 2;
if (m_pos == op)
goto eof_found;
m_pos -= 0x4000;
#if defined(LZO1Z)
last_m_off = pd((const uint8_t*)op, m_pos);
#endif
#endif /* COPY_DICT */
}
else { /* a M1 match */
#if defined(COPY_DICT)
#if defined(LZO1Z)
m_off = 1 + (t << 6) + (*ip++ >> 2);
last_m_off = m_off;
#else
m_off = 1 + (t >> 2) + (*ip++ << 2);
#endif
NEED_OP(2);
t = 2; COPY_DICT(t,m_off)
#else /* !COPY_DICT */
#if defined(LZO1Z)
t = 1 + (t << 6) + (*ip++ >> 2);
m_pos = op - t;
last_m_off = t;
#else
m_pos = op - 1;
m_pos -= t >> 2;
m_pos -= *ip++ << 2;
#endif
TEST_LB(m_pos); NEED_OP(2);
*op++ = *m_pos++;
*op++ = *m_pos;
#endif /* COPY_DICT */
goto match_done;
}
/* copy match */
#if defined(COPY_DICT)
NEED_OP(t+3-1);
t += 3-1; COPY_DICT(t,m_off)
#else /* !COPY_DICT */
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
# if !defined(LZO_UNALIGNED_OK_4)
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) {
assert((op - m_pos) >= 4); /* both pointers are aligned */
# else
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
# endif
COPY4(op,m_pos);
op += 4; m_pos += 4; t -= 4 - (3 - 1);
do {
COPY4(op,m_pos);
op += 4; m_pos += 4; t -= 4;
} while (t >= 4);
if (t > 0)
do *op++ = *m_pos++; while (--t > 0);
}
else
#endif
{
copy_match:
*op++ = *m_pos++; *op++ = *m_pos++;
do *op++ = *m_pos++; while (--t > 0);
}
#endif /* COPY_DICT */
match_done:
#if defined(LZO1Z)
t = ip[-1] & 3;
#else
t = ip[-2] & 3;
#endif
if (t == 0)
break;
/* copy literals */
match_next:
assert(t > 0);
assert(t < 4);
NEED_OP(t);
NEED_IP(t+1);
#if 0
do *op++ = *ip++; while (--t > 0);
#else
*op++ = *ip++;
if (t > 1) {
*op++ = *ip++;
if (t > 2)
*op++ = *ip++;
}
#endif
t = *ip++;
} while (TEST_IP && TEST_OP);
}
//#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
/* no EOF code was found */
*out_len = pd(op, out);
return LZO_E_EOF_NOT_FOUND;
//#endif
eof_found:
assert(t == 1);
*out_len = pd(op, out);
return (ip == ip_end ? LZO_E_OK :
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
//#if defined(HAVE_NEED_IP)
input_overrun:
*out_len = pd(op, out);
return LZO_E_INPUT_OVERRUN;
//#endif
//#if defined(HAVE_NEED_OP)
output_overrun:
*out_len = pd(op, out);
return LZO_E_OUTPUT_OVERRUN;
//#endif
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
lookbehind_overrun:
*out_len = pd(op, out);
return LZO_E_LOOKBEHIND_OVERRUN;
//#endif
}
-1075
View File
File diff suppressed because it is too large. Load diff
+33 -44
View File
@@ -115,10 +115,8 @@ int rpm_main(int argc, char **argv)
}
}
argv += optind;
//argc -= optind;
if (!argv[0]) {
bb_show_usage();
}
argc -= optind;
if (!argc) bb_show_usage();
while (*argv) {
rpm_fd = xopen(*argv++, O_RDONLY);
@@ -145,13 +143,13 @@ int rpm_main(int argc, char **argv)
if (func & rpm_query_info) {
/* Do the nice printout */
time_t bdate_time;
struct tm *bdate_ptm;
struct tm *bdate;
char bdatestring[50];
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)");
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)");
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
bdate_ptm = localtime(&bdate_time);
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
bdate = localtime((time_t *) &bdate_time);
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate);
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0));
@@ -192,7 +190,7 @@ static void extract_cpio_gz(int fd)
archive_handle_t *archive_handle;
unsigned char magic[2];
#if BB_MMU
IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd);
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
enum { xformer_prog = 0 };
#else
enum { xformer = 0 };
@@ -204,16 +202,10 @@ static void extract_cpio_gz(int fd)
archive_handle->seek = seek_by_read;
//archive_handle->action_header = header_list;
archive_handle->action_data = data_extract_all;
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.
* (TODO? real rpm creates "file;1234" and then renames it) */
| ARCHIVE_UNLINK_OLD;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
// TODO: open_zipped does the same
archive_handle->offset = 0;
xread(archive_handle->src_fd, &magic, 2);
#if BB_MMU
@@ -221,19 +213,21 @@ static void extract_cpio_gz(int fd)
#else
xformer_prog = "gunzip";
#endif
if (magic[0] != 0x1f || magic[1] != 0x8b) {
if (!ENABLE_FEATURE_SEAMLESS_BZ2
|| magic[0] != 'B' || magic[1] != 'Z'
) {
bb_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
" magic");
}
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
if (ENABLE_FEATURE_RPM_BZ2
&& (magic[0] == 0x42) && (magic[1] == 0x5a)) {
#if BB_MMU
xformer = unpack_bz2_stream;
xformer = unpack_bz2_stream;
#else
xformer_prog = "bunzip2";
xformer_prog = "bunzip2";
#endif
/* We can do better, need modifying unpack_bz2_stream to not require
* first 2 bytes. Not very hard to do... I mean, TODO :) */
xlseek(archive_handle->src_fd, -2, SEEK_CUR);
} else
bb_error_msg_and_die("no gzip"
USE_FEATURE_RPM_BZ2("/bzip")
" magic");
} else {
#if !BB_MMU
/* NOMMU version of open_transformer execs an external unzipper that should
@@ -243,7 +237,7 @@ static void extract_cpio_gz(int fd)
}
xchdir("/"); /* Install RPM's to root */
open_transformer(archive_handle->src_fd, xformer, xformer_prog);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
@@ -253,7 +247,7 @@ static void extract_cpio_gz(int fd)
static rpm_index **rpm_gettags(int fd, int *num_tags)
{
/* We should never need mode than 200, and realloc later */
rpm_index **tags = xzalloc(200 * sizeof(tags[0]));
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *));
int pass, tagindex = 0;
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
@@ -267,9 +261,6 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
uint32_t entries; /* Number of entries in header (4 bytes) */
uint32_t size; /* Size of store (4 bytes) */
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 16 ? 1 : -1];
};
rpm_index *tmpindex;
int storepos;
@@ -283,21 +274,21 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
while (header.entries--) {
tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex));
xread(fd, tmpindex, sizeof(*tmpindex));
tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index));
xread(fd, tmpindex, sizeof(rpm_index));
tmpindex->tag = ntohl(tmpindex->tag);
tmpindex->type = ntohl(tmpindex->type);
tmpindex->count = ntohl(tmpindex->count);
tmpindex->offset = storepos + ntohl(tmpindex->offset);
if (pass == 0)
if (pass==0)
tmpindex->tag -= 743;
}
xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
/* Skip padding to 8 byte boundary after reading signature headers */
if (pass == 0)
if (pass==0)
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
}
tags = xrealloc(tags, tagindex * sizeof(tags[0])); /* realloc tags to save space */
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
*num_tags = tagindex;
return tags; /* All done, leave the file at the start of the gzipped cpio archive */
}
@@ -326,7 +317,7 @@ static char *rpm_getstr(int tag, int itemindex)
return NULL;
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 *) map + found[0]->offset;
char *tmpstr = (char *) (map + found[0]->offset);
for (n=0; n < itemindex; n++)
tmpstr = tmpstr + strlen(tmpstr) + 1;
return tmpstr;
@@ -345,7 +336,7 @@ static int rpm_getint(int tag, int itemindex)
if (!found || itemindex >= found[0]->count)
return -1;
tmpint = (int *) ((char *) map + found[0]->offset);
tmpint = (int *) (map + found[0]->offset);
if (found[0]->type == RPM_INT32_TYPE) {
tmpint = (int *) ((char *) tmpint + itemindex*4);
@@ -388,11 +379,9 @@ static void fileaction_dobackup(char *filename, int fileref)
static void fileaction_setowngrp(char *filename, int fileref)
{
/* real rpm warns: "user foo does not exist - using <you>" */
struct passwd *pw = getpwnam(rpm_getstr(TAG_FILEUSERNAME, fileref));
int uid = pw ? pw->pw_uid : getuid(); /* or euid? */
struct group *gr = getgrnam(rpm_getstr(TAG_FILEGROUPNAME, fileref));
int gid = gr ? gr->gr_gid : getgid();
int uid, gid;
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
chown(filename, uid, gid);
}
+43 -64
View File
@@ -9,102 +9,81 @@
#include "libbb.h"
#include "unarchive.h"
#define RPM_MAGIC 0xedabeedb
#define RPM_MAGIC_STR "\355\253\356\333"
#define RPM_MAGIC "\355\253\356\333"
#define RPM_HEADER_MAGIC "\216\255\350"
struct rpm_lead {
uint32_t magic;
uint8_t major, minor;
uint16_t type;
uint16_t archnum;
char name[66];
uint16_t osnum;
uint16_t signature_type;
char reserved[16];
unsigned char magic[4];
uint8_t major, minor;
uint16_t type;
uint16_t archnum;
char name[66];
uint16_t osnum;
uint16_t signature_type;
char reserved[16];
};
#define RPM_HEADER_MAGICnVER 0x8eade801
#define RPM_HEADER_MAGIC_STR "\216\255\350"
struct rpm_header {
uint32_t magic_and_ver; /* 3 byte magic: 0x8e 0xad 0xe8; 1 byte version */
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
uint8_t version; /* 1 byte version number */
uint32_t reserved; /* 4 bytes reserved */
uint32_t entries; /* Number of entries in header (4 bytes) */
uint32_t size; /* Size of store (4 bytes) */
};
enum { rpm_fd = STDIN_FILENO };
static unsigned skip_header(void)
static void skip_header(int rpm_fd)
{
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));
xread(rpm_fd, &header, sizeof(struct rpm_header));
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
bb_error_msg_and_die("invalid RPM header magic"); /* Invalid magic */
}
/* 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;
if (header.version != 1) {
bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
}
header.entries = ntohl(header.entries);
header.size = ntohl(header.size);
lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
}
/* No getopt required */
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
int rpm2cpio_main(int argc, char **argv)
{
struct rpm_lead lead;
unsigned pos;
int rpm_fd;
unsigned char magic[2];
IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
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_MAGIC)) {
bb_error_msg_and_die("invalid RPM magic");
if (argc == 1) {
rpm_fd = STDIN_FILENO;
} else {
rpm_fd = xopen(argv[1], O_RDONLY);
}
/* Skip the signature header, align to 8 bytes */
pos = skip_header();
seek_by_jump(rpm_fd, (8 - pos) & 7);
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
}
/* Skip the signature header */
skip_header(rpm_fd);
lseek(rpm_fd, (8 - (lseek(rpm_fd, 0, SEEK_CUR) % 8)) % 8, SEEK_CUR);
/* Skip the main header */
skip_header();
skip_header(rpm_fd);
xread(rpm_fd, &magic, 2);
unpack = unpack_gz_stream;
if (magic[0] != 0x1f || magic[1] != 0x8b) {
if (!ENABLE_FEATURE_SEAMLESS_BZ2
|| magic[0] != 'B' || magic[1] != 'Z'
) {
bb_error_msg_and_die("invalid gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
" magic");
}
unpack = unpack_bz2_stream;
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("invalid gzip magic");
}
if (unpack(rpm_fd, STDOUT_FILENO) < 0) {
bb_error_msg_and_die("error unpacking");
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
bb_error_msg("error inflating");
}
if (ENABLE_FEATURE_CLEAN_UP) {
close(rpm_fd);
}
close(rpm_fd);
return 0;
}
+223 -324
View File
@@ -24,28 +24,12 @@
*/
#include <fnmatch.h>
#include <getopt.h>
#include "libbb.h"
#include "unarchive.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR
# define FNM_LEADING_DIR 0
#endif
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
#define DBG(...) ((void)0)
#define block_buf bb_common_bufsiz1
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
/* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude)
#endif
#if ENABLE_FEATURE_TAR_CREATE
/* Tar file constants */
@@ -55,7 +39,8 @@
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
#define NAME_SIZE 100
#define NAME_SIZE_STR "100"
typedef struct TarHeader { /* byte offset */
typedef struct TarHeader TarHeader;
struct TarHeader { /* byte offset */
char name[NAME_SIZE]; /* 0-99 */
char mode[8]; /* 100-107 */
char uid[8]; /* 108-115 */
@@ -67,48 +52,46 @@ typedef struct TarHeader { /* byte offset */
char linkname[NAME_SIZE]; /* 157-256 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by
* version[2], but we put them together to save code.
*/
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
char devmajor[8]; /* 329-336 */
char devminor[8]; /* 337-344 */
char prefix[155]; /* 345-499 */
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
} TarHeader;
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
};
/*
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
** the only functions that deal with the HardLinkInfo structure.
** Even these functions use the xxxHardLinkInfo() functions.
*/
typedef struct HardLinkInfo {
struct HardLinkInfo *next; /* Next entry in list */
dev_t dev; /* Device number */
ino_t ino; /* Inode number */
// short linkCount; /* (Hard) Link Count */
char name[1]; /* Start of filename (must be last) */
} HardLinkInfo;
typedef struct HardLinkInfo HardLinkInfo;
struct HardLinkInfo {
HardLinkInfo *next; /* Next entry in list */
dev_t dev; /* Device number */
ino_t ino; /* Inode number */
short linkCount; /* (Hard) Link Count */
char name[1]; /* Start of filename (must be last) */
};
/* Some info to be carried along when creating a new tarball */
typedef struct TarBallInfo {
int tarFd; /* Open-for-write file descriptor
* for the tarball */
int verboseFlag; /* Whether to print extra stuff or not */
const llist_t *excludeList; /* List of files to not include */
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
//TODO: save only st_dev + st_ino
struct stat tarFileStatBuf; /* Stat info for the tarball, letting
* us know the inode and device that the
* tarball lives, so we can avoid trying
* to include the tarball into itself */
} TarBallInfo;
typedef struct TarBallInfo TarBallInfo;
struct TarBallInfo {
int tarFd; /* Open-for-write file descriptor
for the tarball */
struct stat statBuf; /* Stat info for the tarball, letting
us know the inode and device that the
tarball lives, so we can avoid trying
to include the tarball into itself */
int verboseFlag; /* Whether to print extra stuff or not */
const llist_t *excludeList; /* List of files to not include */
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
};
/* A nice enum with all the possible tar file content types */
enum {
enum TarFileType {
REGTYPE = '0', /* regular file */
REGTYPE0 = '\0', /* regular file (ancient bug compat) */
LNKTYPE = '1', /* hard link */
@@ -121,6 +104,7 @@ enum {
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
};
typedef enum TarFileType TarFileType;
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
@@ -135,7 +119,7 @@ static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
*hlInfoHeadPtr = hlInfo;
hlInfo->dev = statbuf->st_dev;
hlInfo->ino = statbuf->st_ino;
// hlInfo->linkCount = statbuf->st_nlink;
hlInfo->linkCount = statbuf->st_nlink;
strcpy(hlInfo->name, fileName);
}
@@ -155,16 +139,12 @@ static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
}
}
/* Might be faster (and bigger) if the dev/ino were stored in numeric order ;) */
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf)
{
while (hlInfo) {
if (statbuf->st_ino == hlInfo->ino
&& statbuf->st_dev == hlInfo->dev
) {
DBG("found hardlink:'%s'", hlInfo->name);
if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev))
break;
}
hlInfo = hlInfo->next;
}
return hlInfo;
@@ -175,7 +155,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
* Stores low-order bits only if whole value does not fit. */
static void putOctal(char *cp, int len, off_t value)
{
char tempBuffer[sizeof(off_t)*3 + 1];
char tempBuffer[sizeof(off_t)*3+1];
char *tempString = tempBuffer;
int width;
@@ -335,8 +315,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
if (sizeof(statbuf->st_size) > 4
&& statbuf->st_size > (off_t)0777777777777LL
) {
bb_error_msg_and_die("can't store file '%s' "
"of size %"OFF_FMT"u, aborting",
bb_error_msg_and_die("cannot store file '%s' "
"of size %"OFF_FMT"d, aborting",
fileName, statbuf->st_size);
}
header.typeflag = REGTYPE;
@@ -361,8 +341,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
if (tbInfo->verboseFlag) {
FILE *vbFd = stdout;
/* If archive goes to stdout, verbose goes to stderr */
if (tbInfo->tarFd == STDOUT_FILENO)
if (tbInfo->tarFd == STDOUT_FILENO) /* If the archive goes to stdout, verbose to stderr */
vbFd = stderr;
/* GNU "tar cvvf" prints "extended" listing a-la "ls -l" */
/* We don't have such excesses here: for us "v" == "vv" */
@@ -380,19 +359,16 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
while (excluded_files) {
if (excluded_files->data[0] == '/') {
if (fnmatch(excluded_files->data, file,
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
return 1;
} else {
const char *p;
for (p = file; p[0] != '\0'; p++) {
if ((p == file || p[-1] == '/')
&& p[0] != '/'
&& fnmatch(excluded_files->data, p,
FNM_PATHNAME | FNM_LEADING_DIR) == 0
) {
if ((p == file || p[-1] == '/') && p[0] != '/' &&
fnmatch(excluded_files->data, p,
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
return 1;
}
}
}
excluded_files = excluded_files->link;
@@ -401,18 +377,16 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
return 0;
}
#else
# define exclude_file(excluded_files, file) 0
#define exclude_file(excluded_files, file) 0
#endif
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth UNUSED_PARAM)
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth ATTRIBUTE_UNUSED)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
int inputFileFd = -1;
DBG("writeFileToTarball('%s')", fileName);
/* Strip leading '/' (must be before memorizing hardlink's name) */
header_name = fileName;
while (header_name[0] == '/') {
@@ -442,20 +416,17 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
* by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
if (!S_ISDIR(statbuf->st_mode) && statbuf->st_nlink > 1) {
DBG("'%s': st_nlink > 1", header_name);
if (statbuf->st_nlink > 1) {
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
if (tbInfo->hlInfo == NULL) {
DBG("'%s': addHardLinkInfo", header_name);
if (tbInfo->hlInfo == NULL)
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name);
}
}
/* It is a bad idea to store the archive we are in the process of creating,
* so check the device and inode to be sure that this particular file isn't
* the new tarball */
if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev
&& tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino
if (tbInfo->statBuf.st_dev == statbuf->st_dev
&& tbInfo->statBuf.st_ino == statbuf->st_ino
) {
bb_error_msg("%s: file is the archive; skipping", fileName);
return TRUE;
@@ -516,106 +487,92 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
# endif
/* Don't inline: vfork scares gcc and pessimizes code */
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
{
pid_t gzipPid;
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
# elif ENABLE_FEATURE_SEAMLESS_GZ
const char *zip_exec = "gzip";
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
const char *zip_exec = "bzip2";
# endif
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
# define WAIT_FOR_CHILD 0
volatile int vfork_exec_errno = 0;
struct fd_pair gzipDataPipe;
# if WAIT_FOR_CHILD
struct fd_pair gzipStatusPipe;
xpiped_pair(gzipStatusPipe);
# endif
xpiped_pair(gzipDataPipe);
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
# if defined(__GNUC__) && __GNUC__
/* Avoid vfork clobbering */
(void) &zip_exec;
# endif
gzipPid = vfork();
if (gzipPid < 0)
bb_perror_msg_and_die("vfork");
if (gzipPid == 0) {
/* child */
/* NB: close _first_, then move fds! */
close(gzipDataPipe.wr);
# if WAIT_FOR_CHILD
close(gzipStatusPipe.rd);
/* gzipStatusPipe.wr will close only on exec -
* parent waits for this close to happen */
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
# endif
xmove_fd(gzipDataPipe.rd, 0);
xmove_fd(tar_fd, 1);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
}
/* parent */
xmove_fd(gzipDataPipe.wr, tar_fd);
close(gzipDataPipe.rd);
# if WAIT_FOR_CHILD
close(gzipStatusPipe.wr);
while (1) {
char buf;
int n;
/* Wait until child execs (or fails to) */
n = full_read(gzipStatusPipe.rd, &buf, 1);
if (n < 0 /* && errno == EAGAIN */)
continue; /* try it again */
}
close(gzipStatusPipe.rd);
# endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
}
}
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
/* gcc 4.2.1 inlines it, making code bigger */
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
int dereferenceFlag, const llist_t *include,
const llist_t *exclude, int gzip)
static int writeTarFile(const int tar_fd, const int verboseFlag,
const unsigned long dereferenceFlag, const llist_t *include,
const llist_t *exclude, const int gzip)
{
pid_t gzipPid = 0;
int errorFlag = FALSE;
struct TarBallInfo tbInfo;
tbInfo.hlInfoHead = NULL;
fchmod(tar_fd, 0644);
tbInfo.tarFd = tar_fd;
tbInfo.verboseFlag = verboseFlag;
/* Store the stat info for the tarball's file, so
* can avoid including the tarball into itself.... */
if (fstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf) < 0)
bb_perror_msg_and_die("can't stat tar file");
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
bb_perror_msg_and_die("cannot stat tar file");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
if (gzip)
vfork_compressor(tbInfo.tarFd, gzip);
if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) {
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
#define WAIT_FOR_CHILD 0
volatile int vfork_exec_errno = 0;
#if WAIT_FOR_CHILD
struct { int rd; int wr; } gzipStatusPipe;
#endif
struct { int rd; int wr; } gzipDataPipe;
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
xpipe(&gzipDataPipe.rd);
#if WAIT_FOR_CHILD
xpipe(&gzipStatusPipe.rd);
#endif
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
#if defined(__GNUC__) && __GNUC__
/* Avoid vfork clobbering */
(void) &include;
(void) &errorFlag;
(void) &zip_exec;
#endif
gzipPid = vfork();
if (gzipPid < 0)
bb_perror_msg_and_die("vfork gzip");
if (gzipPid == 0) {
/* child */
xmove_fd(tbInfo.tarFd, 1);
xmove_fd(gzipDataPipe.rd, 0);
close(gzipDataPipe.wr);
#if WAIT_FOR_CHILD
close(gzipStatusPipe.rd);
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
#endif
/* exec gzip/bzip2 program/applet */
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
vfork_exec_errno = errno;
_exit(1);
}
/* parent */
xmove_fd(gzipDataPipe.wr, tbInfo.tarFd);
close(gzipDataPipe.rd);
#if WAIT_FOR_CHILD
close(gzipStatusPipe.wr);
while (1) {
char buf;
int n;
/* Wait until child execs (or fails to) */
n = full_read(gzipStatusPipe.rd, &buf, 1);
if ((n < 0) && (/*errno == EAGAIN ||*/ errno == EINTR))
continue; /* try it again */
}
close(gzipStatusPipe.rd);
#endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("cannot exec %s", zip_exec);
}
}
tbInfo.excludeList = exclude;
@@ -623,8 +580,8 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
while (include) {
if (!recursive_action(include->data, ACTION_RECURSE |
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
writeFileToTarball, writeFileToTarball, &tbInfo, 0)
) {
writeFileToTarball, writeFileToTarball, &tbInfo, 0))
{
errorFlag = TRUE;
}
include = include->link;
@@ -648,34 +605,37 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
if (gzip) {
if (gzipPid) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
if (waitpid(gzipPid, &status, 0) == -1)
bb_perror_msg("waitpid");
else if (!WIFEXITED(status) || WEXITSTATUS(status))
/* gzip was killed or has exited with nonzero! */
errorFlag = TRUE;
}
#endif
return errorFlag;
}
#else
int writeTarFile(int tar_fd, int verboseFlag,
int dereferenceFlag, const llist_t *include,
const llist_t *exclude, int gzip);
int writeTarFile(const int tar_fd, const int verboseFlag,
const unsigned long dereferenceFlag, const llist_t *include,
const llist_t *exclude, const int gzip);
#endif /* FEATURE_TAR_CREATE */
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
{
FILE *src_stream;
llist_t *cur = list;
llist_t *tmp;
char *line;
llist_t *newlist = NULL;
while (list) {
src_stream = xfopen_for_read(llist_pop(&list));
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
while (cur) {
src_stream = xfopen(cur->data, "r");
tmp = cur;
cur = cur->link;
free(tmp);
while ((line = xmalloc_getline(src_stream)) != NULL) {
/* kill trailing '/' unless the string is just "/" */
char *cp = last_char_is(line, '/');
if (cp > line)
@@ -687,11 +647,11 @@ static llist_t *append_file_list_to_list(llist_t *list)
return newlist;
}
#else
# define append_file_list_to_list(x) 0
#define append_file_list_to_list(x) 0
#endif
#if ENABLE_FEATURE_SEAMLESS_Z
static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
#if ENABLE_FEATURE_TAR_COMPRESS
static char get_header_tar_Z(archive_handle_t *archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
@@ -703,7 +663,7 @@ static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
bb_error_msg_and_die("invalid magic");
}
open_transformer(archive_handle->src_fd, unpack_Z_stream, "uncompress");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
@@ -712,7 +672,7 @@ static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
return EXIT_FAILURE;
}
#else
# define get_header_tar_Z NULL
#define get_header_tar_Z NULL
#endif
#ifdef CHECK_FOR_CHILD_EXITCODE
@@ -725,11 +685,11 @@ static void handle_SIGCHLD(int status)
/* Actually, 'status' is a signo. We reuse it for other needs */
/* Wait for any child without blocking */
if (wait_any_nohang(&status) < 0)
if (waitpid(-1, &status, WNOHANG) < 0)
/* wait failed?! I'm confused... */
return;
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
/* child exited with 0 */
return;
/* Cannot happen?
@@ -739,42 +699,35 @@ static void handle_SIGCHLD(int status)
#endif
enum {
OPTBIT_KEEP_OLD = 8,
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
IF_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
IF_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_NUMERIC_OWNER,
OPTBIT_KEEP_OLD = 7,
USE_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
USE_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
USE_FEATURE_TAR_BZIP2( OPTBIT_BZIP2 ,)
USE_FEATURE_TAR_LZMA( OPTBIT_LZMA ,)
USE_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
USE_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
USE_FEATURE_TAR_GZIP( OPTBIT_GZIP ,)
USE_FEATURE_TAR_COMPRESS(OPTBIT_COMPRESS ,)
OPTBIT_NOPRESERVE_OWN,
OPTBIT_NOPRESERVE_PERM,
OPTBIT_OVERWRITE,
#endif
OPT_TEST = 1 << 0, // t
OPT_EXTRACT = 1 << 1, // x
OPT_BASEDIR = 1 << 2, // C
OPT_TARNAME = 1 << 3, // f
OPT_2STDOUT = 1 << 4, // O
OPT_NOPRESERVE_OWNER = 1 << 5, // o == no-same-owner
OPT_P = 1 << 6, // p
OPT_VERBOSE = 1 << 7, // v
OPT_KEEP_OLD = 1 << 8, // k
OPT_CREATE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = IF_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
OPT_P = 1 << 5, // p
OPT_VERBOSE = 1 << 6, // v
OPT_KEEP_OLD = 1 << 7, // k
OPT_CREATE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = USE_FEATURE_TAR_BZIP2( (1<<OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = USE_FEATURE_TAR_LZMA( (1<<OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_EXCLUDE_FROM)) + 0, // X
OPT_GZIP = USE_FEATURE_TAR_GZIP( (1<<OPTBIT_GZIP )) + 0, // z
OPT_COMPRESS = USE_FEATURE_TAR_COMPRESS((1<<OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
};
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
static const char tar_longopts[] ALIGN1 =
@@ -783,10 +736,6 @@ static const char tar_longopts[] ALIGN1 =
"directory\0" Required_argument "C"
"file\0" Required_argument "f"
"to-stdout\0" No_argument "O"
/* do not restore owner */
/* Note: GNU tar handles 'o' as no-same-owner only on extract,
* on create, 'o' is --old-archive. We do not support --old-archive. */
"no-same-owner\0" No_argument "o"
"same-permissions\0" No_argument "p"
"verbose\0" No_argument "v"
"keep-old\0" No_argument "k"
@@ -794,33 +743,27 @@ static const char tar_longopts[] ALIGN1 =
"create\0" No_argument "c"
"dereference\0" No_argument "h"
# endif
# if ENABLE_FEATURE_SEAMLESS_BZ2
# if ENABLE_FEATURE_TAR_BZIP2
"bzip2\0" No_argument "j"
# endif
# if ENABLE_FEATURE_SEAMLESS_LZMA
# if ENABLE_FEATURE_TAR_LZMA
"lzma\0" No_argument "a"
# endif
# if ENABLE_FEATURE_TAR_FROM
"files-from\0" Required_argument "T"
"exclude-from\0" Required_argument "X"
# endif
# if ENABLE_FEATURE_SEAMLESS_GZ
# if ENABLE_FEATURE_TAR_GZIP
"gzip\0" No_argument "z"
# endif
# if ENABLE_FEATURE_SEAMLESS_Z
# if ENABLE_FEATURE_TAR_COMPRESS
"compress\0" No_argument "Z"
# endif
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m"
# endif
/* use numeric uid/gid from tar header, not textual */
"numeric-owner\0" No_argument "\xfc"
/* do not restore mode */
"no-same-permissions\0" No_argument "\xfd"
/* on unpack, open with O_TRUNC and !O_EXCL */
"overwrite\0" No_argument "\xfe"
"no-same-owner\0" No_argument "\xfd"
"no-same-permissions\0" No_argument "\xfe"
/* --exclude takes next bit position in option mask, */
/* therefore we have to put it _after_ --no-same-permissions */
/* therefore we have to either put it _after_ --no-same-perm */
/* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */
# if ENABLE_FEATURE_TAR_FROM
"exclude\0" Required_argument "\xff"
# endif
@@ -828,9 +771,9 @@ static const char tar_longopts[] ALIGN1 =
#endif
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tar_main(int argc UNUSED_PARAM, char **argv)
int tar_main(int argc, char **argv)
{
char FAST_FUNC (*get_header_ptr)(archive_handle_t *) = get_header_tar;
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
archive_handle_t *tar_handle;
char *base_dir = NULL;
const char *tar_filename = "-";
@@ -842,13 +785,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Initialise default values */
tar_handle = init_handle();
tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
| ARCHIVE_RESTORE_DATE
| ARCHIVE_UNLINK_OLD;
/* Apparently only root's tar preserves perms (see bug 3844) */
if (getuid() != 0)
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS
| ARCHIVE_PRESERVE_DATE
| ARCHIVE_EXTRACT_UNCONDITIONAL;
/* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options
@@ -858,60 +797,30 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // cumulative lists for --exclude
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_longopts;
#endif
#if ENABLE_DESKTOP
if (argv[1] && argv[1][0] != '-') {
/* Compat:
* 1st argument without dash handles options with parameters
* differently from dashed one: it takes *next argv[i]*
* as paramenter even if there are more chars in 1st argument:
* "tar fx TARFILE" - "x" is not taken as f's param
* but is interpreted as -x option
* "tar -xf TARFILE" - dashed equivalent of the above
* "tar -fx ..." - "x" is taken as f's param
* getopt32 wouldn't handle 1st command correctly.
* Unfortunately, people do use such commands.
* We massage argv[1] to work around it by moving 'f'
* to the end of the string.
* More contrived "tar fCx TARFILE DIR" still fails,
* but such commands are much less likely to be used.
*/
char *f = strchr(argv[1], 'f');
if (f) {
while (f[1] != '\0') {
*f = f[1];
f++;
}
*f = 'f';
}
}
#endif
opt = getopt32(argv,
"txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
IF_FEATURE_SEAMLESS_LZMA("a" )
IF_FEATURE_TAR_FROM( "T:X:")
IF_FEATURE_SEAMLESS_GZ( "z" )
IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
"txC:f:Opvk"
USE_FEATURE_TAR_CREATE( "ch" )
USE_FEATURE_TAR_BZIP2( "j" )
USE_FEATURE_TAR_LZMA( "a" )
USE_FEATURE_TAR_FROM( "T:X:")
USE_FEATURE_TAR_GZIP( "z" )
USE_FEATURE_TAR_COMPRESS("Z" )
, &base_dir // -C dir
, &tar_filename // -f filename
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
USE_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
USE_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
, &excludes // --exclude
#endif
, &verboseFlag // combined count for -t and -v
, &verboseFlag // combined count for -t and -v
);
//bb_error_msg("opt:%08x", opt);
argv += optind;
if (verboseFlag) tar_handle->action_header = header_verbose_list;
if (verboseFlag == 1) tar_handle->action_header = header_list;
@@ -923,21 +832,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->action_data = data_extract_to_stdout;
if (opt & OPT_KEEP_OLD)
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
if (opt & OPT_NUMERIC_OWNER)
tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
if (opt & OPT_NOPRESERVE_OWNER)
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_OWNER;
if (opt & OPT_NOPRESERVE_OWN)
tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN;
if (opt & OPT_NOPRESERVE_PERM)
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
if (opt & OPT_OVERWRITE) {
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
tar_handle->ah_flags |= ARCHIVE_O_TRUNC;
}
tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM;
if (opt & OPT_GZIP)
get_header_ptr = get_header_tar_gz;
@@ -951,12 +852,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_COMPRESS)
get_header_ptr = get_header_tar_Z;
if (opt & OPT_NOPRESERVE_TIME)
tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE;
#if ENABLE_FEATURE_TAR_FROM
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
/* Append excludes to reject */
while (excludes) {
llist_t *next = excludes->link;
@@ -964,19 +862,25 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->reject = excludes;
excludes = next;
}
# endif
#endif
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
#endif
/* Check if we are reading from stdin */
if (argv[optind] && *argv[optind] == '-') {
/* Default is to read from stdin, so just skip to next arg */
optind++;
}
/* Setup an array of filenames to work with */
/* TODO: This is the same as in ar, make a separate function? */
while (*argv) {
/* TODO: This is the same as in ar, separate function ? */
while (optind < argc) {
/* kill trailing '/' unless the string is just "/" */
char *cp = last_char_is(*argv, '/');
if (cp > *argv)
char *cp = last_char_is(argv[optind], '/');
if (cp > argv[optind])
*cp = '\0';
llist_add_to_end(&tar_handle->accept, *argv);
argv++;
llist_add_to_end(&tar_handle->accept, argv[optind]);
optind++;
}
if (tar_handle->accept || tar_handle->reject)
@@ -984,31 +888,28 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Open the tar file */
{
int tar_fd = STDIN_FILENO;
int flags = O_RDONLY;
FILE *tar_stream;
int flags;
if (opt & OPT_CREATE) {
/* Make sure there is at least one file to tar up */
/* Make sure there is at least one file to tar up. */
if (tar_handle->accept == NULL)
bb_error_msg_and_die("empty archive");
tar_fd = STDOUT_FILENO;
tar_stream = stdout;
/* Mimicking GNU tar 1.15.1: */
flags = O_WRONLY | O_CREAT | O_TRUNC;
flags = O_WRONLY|O_CREAT|O_TRUNC;
/* was doing unlink; open(O_WRONLY|O_CREAT|O_EXCL); why? */
} else {
tar_stream = stdin;
flags = O_RDONLY;
}
if (LONE_DASH(tar_filename)) {
tar_handle->src_fd = tar_fd;
tar_handle->src_fd = fileno(tar_stream);
tar_handle->seek = seek_by_read;
} else {
if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) {
get_header_ptr = get_header_tar;
tar_handle->src_fd = open_zipped(tar_filename);
if (tar_handle->src_fd < 0)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
tar_handle->src_fd = xopen(tar_filename, flags);
}
tar_handle->src_fd = xopen(tar_filename, flags);
}
}
@@ -1020,15 +921,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
signal(SIGCHLD, handle_SIGCHLD);
#endif
/* Create an archive */
/* create an archive */
if (opt & OPT_CREATE) {
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
int zipMode = 0;
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
if (ENABLE_FEATURE_TAR_GZIP && get_header_ptr == get_header_tar_gz)
zipMode = 1;
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
zipMode = 2;
#endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
tar_handle->accept,
@@ -1036,7 +935,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
}
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
continue;
/* nothing */;
/* Check that every file that should have been extracted was */
while (tar_handle->accept) {
+80 -327
View File
@@ -16,7 +16,12 @@
*/
/* TODO
* Endian issues
* Zip64 + other methods
* Improve handling of zip format, ie.
* - deferred CRC, comp. & uncomp. lengths (zip header flags bit 3)
* - unix file permissions, etc.
* - central directory
*/
#include "libbb.h"
@@ -26,12 +31,12 @@ enum {
#if BB_BIG_ENDIAN
ZIP_FILEHEADER_MAGIC = 0x504b0304,
ZIP_CDS_MAGIC = 0x504b0102,
ZIP_CDE_MAGIC = 0x504b0506,
ZIP_CDS_END_MAGIC = 0x504b0506,
ZIP_DD_MAGIC = 0x504b0708,
#else
ZIP_FILEHEADER_MAGIC = 0x04034b50,
ZIP_CDS_MAGIC = 0x02014b50,
ZIP_CDE_MAGIC = 0x06054b50,
ZIP_CDS_END_MAGIC = 0x06054b50,
ZIP_DD_MAGIC = 0x08074b50,
#endif
};
@@ -41,18 +46,18 @@ enum {
typedef union {
uint8_t raw[ZIP_HEADER_LEN];
struct {
uint16_t version; /* 0-1 */
uint16_t flags; /* 2-3 */
uint16_t method; /* 4-5 */
uint16_t modtime; /* 6-7 */
uint16_t moddate; /* 8-9 */
uint32_t crc32 PACKED; /* 10-13 */
uint32_t cmpsize PACKED; /* 14-17 */
uint32_t ucmpsize PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted PACKED;
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
uint16_t version; /* 0-1 */
uint16_t flags; /* 2-3 */
uint16_t method; /* 4-5 */
uint16_t modtime; /* 6-7 */
uint16_t moddate; /* 8-9 */
uint32_t crc32 ATTRIBUTE_PACKED; /* 10-13 */
uint32_t cmpsize ATTRIBUTE_PACKED; /* 14-17 */
uint32_t ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted ATTRIBUTE_PACKED;
} zip_header_t;
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
@@ -60,11 +65,11 @@ typedef union {
*/
struct BUG_zip_header_must_be_26_bytes {
char BUG_zip_header_must_be_26_bytes[
offsetof(zip_header_t, formatted.extra_len) + 2
== ZIP_HEADER_LEN ? 1 : -1];
offsetof(zip_header_t, formatted.extra_len) + 2 ==
ZIP_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_ZIP(zip_header) do { \
#define FIX_ENDIANNESS(zip_header) do { \
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
(zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
@@ -77,139 +82,9 @@ struct BUG_zip_header_must_be_26_bytes {
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
} while (0)
#define CDS_HEADER_LEN 42
typedef union {
uint8_t raw[CDS_HEADER_LEN];
struct {
/* uint32_t signature; 50 4b 01 02 */
uint16_t version_made_by; /* 0-1 */
uint16_t version_needed; /* 2-3 */
uint16_t cds_flags; /* 4-5 */
uint16_t method; /* 6-7 */
uint16_t mtime; /* 8-9 */
uint16_t mdate; /* 10-11 */
uint32_t crc32; /* 12-15 */
uint32_t cmpsize; /* 16-19 */
uint32_t ucmpsize; /* 20-23 */
uint16_t file_name_length; /* 24-25 */
uint16_t extra_field_length; /* 26-27 */
uint16_t file_comment_length; /* 28-29 */
uint16_t disk_number_start; /* 30-31 */
uint16_t internal_file_attributes; /* 32-33 */
uint32_t external_file_attributes PACKED; /* 34-37 */
uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
} formatted PACKED;
} cds_header_t;
struct BUG_cds_header_must_be_42_bytes {
char BUG_cds_header_must_be_42_bytes[
offsetof(cds_header_t, formatted.relative_offset_of_local_header) + 4
== CDS_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_CDS(cds_header) do { \
(cds_header).formatted.crc32 = SWAP_LE32((cds_header).formatted.crc32 ); \
(cds_header).formatted.cmpsize = SWAP_LE32((cds_header).formatted.cmpsize ); \
(cds_header).formatted.ucmpsize = SWAP_LE32((cds_header).formatted.ucmpsize ); \
(cds_header).formatted.file_name_length = SWAP_LE16((cds_header).formatted.file_name_length); \
(cds_header).formatted.extra_field_length = SWAP_LE16((cds_header).formatted.extra_field_length); \
(cds_header).formatted.file_comment_length = SWAP_LE16((cds_header).formatted.file_comment_length); \
} while (0)
#define CDE_HEADER_LEN 16
typedef union {
uint8_t raw[CDE_HEADER_LEN];
struct {
/* uint32_t signature; 50 4b 05 06 */
uint16_t this_disk_no;
uint16_t disk_with_cds_no;
uint16_t cds_entries_on_this_disk;
uint16_t cds_entries_total;
uint32_t cds_size;
uint32_t cds_offset;
/* uint16_t file_comment_length; */
/* .ZIP file comment (variable size) */
} formatted PACKED;
} cde_header_t;
struct BUG_cde_header_must_be_16_bytes {
char BUG_cde_header_must_be_16_bytes[
sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_CDE(cde_header) do { \
(cde_header).formatted.cds_offset = SWAP_LE32((cde_header).formatted.cds_offset); \
} while (0)
enum { zip_fd = 3 };
#if ENABLE_DESKTOP
/* NB: does not preserve file position! */
static uint32_t find_cds_offset(void)
static void unzip_skip(int fd, off_t skip)
{
unsigned char buf[1024];
cde_header_t cde_header;
unsigned char *p;
off_t end;
end = xlseek(zip_fd, 0, SEEK_END);
if (end < 1024)
end = 1024;
end -= 1024;
xlseek(zip_fd, end, SEEK_SET);
full_read(zip_fd, buf, 1024);
p = buf;
while (p <= buf + 1024 - CDE_HEADER_LEN - 4) {
if (*p != 'P') {
p++;
continue;
}
if (*++p != 'K')
continue;
if (*++p != 5)
continue;
if (*++p != 6)
continue;
/* we found CDE! */
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
FIX_ENDIANNESS_CDE(cde_header);
return cde_header.formatted.cds_offset;
}
bb_error_msg_and_die("can't find file table");
};
static uint32_t read_next_cds(int count_m1, uint32_t cds_offset, cds_header_t *cds_ptr)
{
off_t org;
org = xlseek(zip_fd, 0, SEEK_CUR);
if (!cds_offset)
cds_offset = find_cds_offset();
while (count_m1-- >= 0) {
xlseek(zip_fd, cds_offset + 4, SEEK_SET);
xread(zip_fd, cds_ptr->raw, CDS_HEADER_LEN);
FIX_ENDIANNESS_CDS(*cds_ptr);
cds_offset += 4 + CDS_HEADER_LEN
+ cds_ptr->formatted.file_name_length
+ cds_ptr->formatted.extra_field_length
+ cds_ptr->formatted.file_comment_length;
}
xlseek(zip_fd, org, SEEK_SET);
return cds_offset;
};
#endif
static void unzip_skip(off_t skip)
{
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
bb_copyfd_exact_size(zip_fd, -1, skip);
bb_copyfd_exact_size(fd, -1, skip);
}
static void unzip_create_leading_dirs(const char *fn)
@@ -222,17 +97,17 @@ static void unzip_create_leading_dirs(const char *fn)
free(name);
}
static void unzip_extract(zip_header_t *zip_header, int dst_fd)
static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
{
if (zip_header->formatted.method == 0) {
/* Method 0 - stored (not compressed) */
off_t size = zip_header->formatted.ucmpsize;
if (size)
bb_copyfd_exact_size(zip_fd, dst_fd, size);
bb_copyfd_exact_size(src_fd, dst_fd, size);
} else {
/* Method 8 - inflate */
inflate_unzip_result res;
if (inflate_unzip(&res, zip_header->formatted.cmpsize, zip_fd, dst_fd) < 0)
if (inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd) < 0)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
@@ -253,17 +128,12 @@ int unzip_main(int argc, char **argv)
enum { O_PROMPT, O_NEVER, O_ALWAYS };
zip_header_t zip_header;
smallint quiet = 0;
IF_NOT_DESKTOP(const) smallint verbose = 0;
smallint verbose = 1;
smallint listing = 0;
smallint overwrite = O_PROMPT;
#if ENABLE_DESKTOP
uint32_t cds_offset;
unsigned cds_entries;
#endif
unsigned long total_usize;
unsigned long total_size;
unsigned total_size;
unsigned total_entries;
int src_fd = -1;
int dst_fd = -1;
char *src_fn = NULL;
char *dst_fn = NULL;
@@ -275,49 +145,8 @@ int unzip_main(int argc, char **argv)
char key_buf[80];
struct stat stat_buf;
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
*
* # /usr/bin/unzip -qq -v decompress_unlzma.i.zip
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
* # /usr/bin/unzip -q -v decompress_unlzma.i.zip
* Length Method Size Ratio Date Time CRC-32 Name
* -------- ------ ------- ----- ---- ---- ------ ----
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
* -------- ------- --- -------
* 204372 35278 83% 1 file
* # /usr/bin/unzip -v decompress_unlzma.i.zip
* Archive: decompress_unlzma.i.zip
* Length Method Size Ratio Date Time CRC-32 Name
* -------- ------ ------- ----- ---- ---- ------ ----
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
* -------- ------- --- -------
* 204372 35278 83% 1 file
* # unzip -v decompress_unlzma.i.zip
* Archive: decompress_unlzma.i.zip
* Length Date Time Name
* -------- ---- ---- ----
* 204372 09-06-09 14:23 decompress_unlzma.i
* -------- -------
* 204372 1 files
* # /usr/bin/unzip -l -qq decompress_unlzma.i.zip
* 204372 09-06-09 14:23 decompress_unlzma.i
* # /usr/bin/unzip -l -q decompress_unlzma.i.zip
* Length Date Time Name
* -------- ---- ---- ----
* 204372 09-06-09 14:23 decompress_unlzma.i
* -------- -------
* 204372 1 file
* # /usr/bin/unzip -l decompress_unlzma.i.zip
* Archive: decompress_unlzma.i.zip
* Length Date Time Name
* -------- ---- ---- ----
* 204372 09-06-09 14:23 decompress_unlzma.i
* -------- -------
* 204372 1 file
*/
/* '-' makes getopt return 1 for non-options */
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
switch (opt_range) {
case 0: /* Options */
switch (opt) {
@@ -337,12 +166,7 @@ int unzip_main(int argc, char **argv)
dst_fd = STDOUT_FILENO;
case 'q': /* Be quiet */
quiet++;
break;
case 'v': /* Verbose list */
IF_DESKTOP(verbose++;)
listing = 1;
verbose = 0;
break;
case 1: /* The zip file */
@@ -397,14 +221,13 @@ int unzip_main(int argc, char **argv)
/* Open input file */
if (LONE_DASH(src_fn)) {
xdup2(STDIN_FILENO, zip_fd);
src_fd = STDIN_FILENO;
/* Cannot use prompt mode since zip data is arriving on STDIN */
if (overwrite == O_PROMPT)
overwrite = O_NEVER;
} else {
static const char extn[][5] = {"", ".zip", ".ZIP"};
int orig_src_fn_len = strlen(src_fn);
int src_fd = -1;
for (i = 0; (i < 3) && (src_fd == -1); i++) {
strcpy(src_fn + orig_src_fn_len, extn[i]);
@@ -414,87 +237,46 @@ int unzip_main(int argc, char **argv)
src_fn[orig_src_fn_len] = '\0';
bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
}
xmove_fd(src_fd, zip_fd);
}
/* Change dir if necessary */
if (base_dir)
xchdir(base_dir);
if (quiet <= 1) { /* not -qq */
if (quiet == 0)
printf("Archive: %s\n", src_fn);
if (listing) {
puts(verbose ?
" Length Method Size Ratio Date Time CRC-32 Name\n"
"-------- ------ ------- ----- ---- ---- ------ ----"
:
" Length Date Time Name\n"
" -------- ---- ---- ----"
);
if (verbose) {
printf("Archive: %s\n", src_fn);
if (listing){
puts(" Length Date Time Name\n"
" -------- ---- ---- ----");
}
}
total_usize = 0;
total_size = 0;
total_entries = 0;
#if ENABLE_DESKTOP
cds_entries = 0;
cds_offset = 0;
#endif
while (1) {
uint32_t magic;
/* Check magic number */
xread(zip_fd, &magic, 4);
/* Central directory? It's at the end, so exit */
xread(src_fd, &magic, 4);
if (magic == ZIP_CDS_MAGIC)
break;
#if ENABLE_DESKTOP
/* Data descriptor? It was a streaming file, go on */
if (magic == ZIP_DD_MAGIC) {
/* skip over duplicate crc32, cmpsize and ucmpsize */
unzip_skip(3 * 4);
continue;
}
#endif
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
bb_error_msg_and_die("invalid zip magic %08X", magic);
/* Read the file header */
xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS_ZIP(zip_header);
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS(zip_header);
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
}
#if !ENABLE_DESKTOP
if (zip_header.formatted.flags & 0x0009) {
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
}
#else
if (zip_header.formatted.flags & 0x0001) {
/* 0x0001 - encrypted */
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
}
if (zip_header.formatted.flags & 0x0008) {
cds_header_t cds_header;
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
* only from Central Directory. See unzip_doc.txt */
cds_offset = read_next_cds(total_entries - cds_entries, cds_offset, &cds_header);
cds_entries = total_entries + 1;
zip_header.formatted.crc32 = cds_header.formatted.crc32;
zip_header.formatted.cmpsize = cds_header.formatted.cmpsize;
zip_header.formatted.ucmpsize = cds_header.formatted.ucmpsize;
}
#endif
/* Read filename */
free(dst_fn);
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
xread(src_fd, dst_fn, zip_header.formatted.filename_len);
/* Skip extra header bytes */
unzip_skip(zip_header.formatted.extra_len);
unzip_skip(src_fd, zip_header.formatted.extra_len);
/* Filter zip entries */
if (find_list_entry(zreject, dst_fn)
@@ -504,39 +286,21 @@ int unzip_main(int argc, char **argv)
} else { /* Extract entry */
if (listing) { /* List entry */
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
if (!verbose) {
// " Length Date Time Name\n"
// " -------- ---- ---- ----"
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
(unsigned)zip_header.formatted.ucmpsize,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
if (verbose) {
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
zip_header.formatted.ucmpsize,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dst_fn);
total_size += zip_header.formatted.ucmpsize;
total_entries++;
} else {
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
percents = percents * 100;
if (zip_header.formatted.ucmpsize)
percents /= zip_header.formatted.ucmpsize;
// " Length Method Size Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
(unsigned)zip_header.formatted.ucmpsize,
(unsigned)zip_header.formatted.cmpsize,
(unsigned)percents,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
zip_header.formatted.crc32,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
total_size += zip_header.formatted.cmpsize;
/* short listing -- filenames only */
puts(dst_fn);
}
i = 'n';
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
@@ -544,9 +308,9 @@ int unzip_main(int argc, char **argv)
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
if (!quiet) {
if (verbose) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
@@ -561,10 +325,10 @@ int unzip_main(int argc, char **argv)
i = 'n';
} else { /* Extract file */
check_file:
_check_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);
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
i = 'y';
} else { /* File already exists */
@@ -576,12 +340,12 @@ int unzip_main(int argc, char **argv)
} else {
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
bb_perror_msg_and_die("can't read input");
bb_perror_msg_and_die("cannot read input");
}
i = key_buf[0];
}
} else { /* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn);
bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
}
}
}
@@ -594,10 +358,10 @@ int unzip_main(int argc, char **argv)
unzip_create_leading_dirs(dst_fn);
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
case -1: /* Unzip */
if (!quiet) {
if (verbose) {
printf(" inflating: %s\n", dst_fn);
}
unzip_extract(&zip_header, dst_fd);
unzip_extract(&zip_header, src_fd, dst_fd);
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
close(dst_fd);
@@ -608,47 +372,36 @@ int unzip_main(int argc, char **argv)
overwrite = O_NEVER;
case 'n':
/* Skip entry data */
unzip_skip(zip_header.formatted.cmpsize);
unzip_skip(src_fd, zip_header.formatted.cmpsize);
break;
case 'r':
/* Prompt for new name */
printf("new name: ");
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
bb_perror_msg_and_die("can't read input");
bb_perror_msg_and_die("cannot read input");
}
free(dst_fn);
dst_fn = xstrdup(key_buf);
chomp(dst_fn);
goto check_file;
goto _check_file;
default:
printf("error: invalid response [%c]\n", (char)i);
goto check_file;
printf("error: invalid response [%c]\n",(char)i);
goto _check_file;
}
total_entries++;
/* Data descriptor section */
if (zip_header.formatted.flags & 4) {
/* skip over duplicate crc, compressed size and uncompressed size */
unzip_skip(src_fd, 12);
}
}
if (listing && quiet <= 1) {
if (!verbose) {
// " Length Date Time Name\n"
// " -------- ---- ---- ----"
printf( " -------- -------\n"
"%9lu" " %u files\n",
total_usize, total_entries);
} else {
unsigned long percents = total_usize - total_size;
percents = percents * 100;
if (total_usize)
percents /= total_usize;
// " Length Method Size Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "-------- ------- --- -------\n"
"%8lu" "%17lu%4u%% %u files\n",
total_usize, total_size, (unsigned)percents,
total_entries);
}
if (listing && verbose) {
printf(" -------- -------\n"
"%9d %d files\n",
total_size, total_entries);
}
return 0;
Binary file not shown.
+2 -29
View File
@@ -72,7 +72,7 @@ config RESIZE
terminal.
config FEATURE_RESIZE_PRINT
bool "Print environment variables"
bool "print environment variables"
default n
depends on RESIZE
help
@@ -91,31 +91,10 @@ config SETCONSOLE
config FEATURE_SETCONSOLE_LONG_OPTIONS
bool "Enable long options"
default n
depends on SETCONSOLE && LONG_OPTS
depends on SETCONSOLE && GETOPT_LONG
help
Support long options for the setconsole applet.
config SETFONT
bool "setfont"
default n
help
Allows to load console screen map. Useful for i18n.
config FEATURE_SETFONT_TEXTUAL_MAP
bool "Support reading textual screen maps"
default n
depends on SETFONT
help
Support reading textual screen maps.
config DEFAULT_SETFONT_DIR
string "Default directory for console-tools files"
default ""
depends on SETFONT
help
Directory to use if setfont's params are simple filenames
(not /path/to/file or ./file). Default is "" (no default directory).
config SETKEYCODES
bool "setkeycodes"
default n
@@ -129,10 +108,4 @@ config SETLOGCONS
help
This program redirects the output console of kernel messages.
config SHOWKEY
bool "showkey"
default n
help
Shows keys pressed.
endmenu
-2
View File
@@ -16,7 +16,5 @@ lib-$(CONFIG_LOADKMAP) += loadkmap.o
lib-$(CONFIG_OPENVT) += openvt.o
lib-$(CONFIG_RESET) += reset.o
lib-$(CONFIG_RESIZE) += resize.o
lib-$(CONFIG_SETFONT) += loadfont.o
lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
lib-$(CONFIG_SETLOGCONS) += setlogcons.o
lib-$(CONFIG_SHOWKEY) += showkey.o
+19 -3
View File
@@ -6,12 +6,28 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
/* From <linux/vt.h> */
enum {
VT_ACTIVATE = 0x5606, /* make vt active */
VT_WAITACTIVE = 0x5607 /* wait for vt active */
};
int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chvt_main(int argc UNUSED_PARAM, char **argv)
int chvt_main(int argc, char **argv)
{
int num = xatou_range(single_argv(argv), 1, 63);
console_make_active(get_console_fd_or_die(), num);
int fd, num;
if (argc != 2) {
bb_show_usage();
}
fd = get_console_fd();
num = xatou_range(argv[1], 1, 63);
/* double cast suppresses "cast to ptr from int of different size" */
xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num);
xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -13,7 +13,7 @@
#include "libbb.h"
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int clear_main(int argc, char **argv)
{
return printf("\033[H\033[J") != 6;
}
+9 -5
View File
@@ -16,18 +16,22 @@
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int deallocvt_main(int argc UNUSED_PARAM, char **argv)
int deallocvt_main(int argc, char **argv)
{
/* num = 0 deallocate all unused consoles */
int num = 0;
if (argv[1]) {
if (argv[2])
bb_show_usage();
switch (argc) {
case 2:
num = xatou_range(argv[1], 1, 63);
/* Fallthrough */
case 1:
break;
default:
bb_show_usage();
}
/* double cast suppresses "cast to ptr from int of different size" */
xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
return EXIT_SUCCESS;
}
+9 -12
View File
@@ -7,7 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
*/
/* no options, no getopt */
#include "libbb.h"
@@ -24,17 +23,18 @@ struct kbentry {
#define MAX_NR_KEYMAPS 256
int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int dumpkmap_main(int argc, char **argv)
{
struct kbentry ke;
int i, j, fd;
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
char flags[MAX_NR_KEYMAPS];
/* bb_warn_ignoring_args(argv[1]);*/
if (argc >= 2 && argv[1][0] == '-')
bb_show_usage();
fd = get_console_fd_or_die();
fd = xopen(CURRENT_VC, O_RDWR);
write(STDOUT_FILENO, "bkeymap", 7);
write(1, "bkeymap", 7);
/* Here we want to set everything to 0 except for indexes:
* [0-2] [4-6] [8-10] [12] */
@@ -43,7 +43,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
flags[3] = flags[7] = flags[11] = 0;
/* dump flags */
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
write(1, flags, MAX_NR_KEYMAPS);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
@@ -56,14 +56,11 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
(char *)&ke.kb_table,
&ke.kb_value)
) {
write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
write(1, (void*)&ke.kb_value, 2);
}
}
}
}
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd);
RELEASE_CONFIG_BUFFER(flags);
}
close(fd);
return EXIT_SUCCESS;
}
+48 -32
View File
@@ -1,52 +1,68 @@
/* vi: set sw=4 ts=4: */
/*
* Mini kbd_mode implementation for busybox
* Mini loadkmap implementation for busybox
*
* Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
* Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
* console-utils v0.2.3, licensed under GNU GPLv2
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
*/
#include <getopt.h>
#include "libbb.h"
#include <linux/kd.h>
int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
int kbd_mode_main(int argc, char **argv)
{
enum {
SCANCODE = (1 << 0),
ASCII = (1 << 1),
MEDIUMRAW = (1 << 2),
UNICODE = (1 << 3),
};
static const char opts[] = "saku";
const char *opt = argv[1];
const char *p;
int fd;
unsigned opt;
const char *tty_name = CURRENT_TTY;
opt = getopt32(argv, "sakuC:", &tty_name);
fd = xopen_nonblocking(tty_name);
opt &= 0xf; /* clear -C bit, see (*) */
fd = get_console_fd();
if (fd < 0) /* get_console_fd() already complained */
return EXIT_FAILURE;
if (!opt) { /* print current setting */
const char *mode = "unknown";
int m;
if (opt == NULL) {
/* No arg */
const char *msg = "unknown";
int mode;
xioctl(fd, KDGKBMODE, &m);
if (m == K_RAW)
mode = "raw (scancode)";
else if (m == K_XLATE)
mode = "default (ASCII)";
else if (m == K_MEDIUMRAW)
mode = "mediumraw (keycode)";
else if (m == K_UNICODE)
mode = "Unicode (UTF-8)";
printf("The keyboard is in %s mode\n", mode);
} else {
/* 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);
ioctl(fd, KDGKBMODE, &mode);
switch(mode) {
case K_RAW:
msg = "raw (scancode)";
break;
case K_XLATE:
msg = "default (ASCII)";
break;
case K_MEDIUMRAW:
msg = "mediumraw (keycode)";
break;
case K_UNICODE:
msg = "Unicode (UTF-8)";
break;
}
printf("The keyboard is in %s mode\n", msg);
}
else if (argc > 2 /* more than 1 arg */
|| *opt != '-' /* not an option */
|| (p = strchr(opts, opt[1])) == NULL /* not an option we expect */
|| opt[2] != '\0' /* more than one option char */
) {
bb_show_usage();
/* return EXIT_FAILURE; - not reached */
}
else {
#if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3
#error kbd_mode must be changed
#endif
/* The options are in the order of the various K_xxx */
ioctl(fd, KDSKBMODE, p - opts);
}
if (ENABLE_FEATURE_CLEAN_UP)
+69 -261
View File
@@ -6,34 +6,10 @@
*
* Loads the console font, and possibly the corresponding screen map(s).
* (Adapted for busybox by Matej Vela.)
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include <sys/kd.h>
#ifndef KDFONTOP
#define KDFONTOP 0x4B72
struct console_font_op {
unsigned op; /* KD_FONT_OP_* */
unsigned flags; /* KD_FONT_FLAG_* */
unsigned width, height;
unsigned charcount;
unsigned char *data; /* font data with height fixed to 32 */
};
#define KD_FONT_OP_SET 0 /* Set font */
#define KD_FONT_OP_GET 1 /* Get font */
#define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default,
data points to name / NULL */
#define KD_FONT_OP_COPY 3 /* Copy from another console */
#define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
#define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
/* (Used internally for PIO_FONT support) */
#endif /* KDFONTOP */
enum {
PSF_MAGIC1 = 0x36,
PSF_MAGIC2 = 0x04,
@@ -41,7 +17,7 @@ enum {
PSF_MODE512 = 0x01,
PSF_MODEHASTAB = 0x02,
PSF_MAXMODE = 0x03,
PSF_SEPARATOR = 0xffff
PSF_SEPARATOR = 0xFFFF
};
struct psf_header {
@@ -50,7 +26,7 @@ struct psf_header {
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x)->magic1 == PSF_MAGIC1 && (x)->magic2 == PSF_MAGIC2)
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
{
@@ -61,31 +37,10 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
bb_error_msg_and_die("bad character size %d", unit);
buf = xzalloc(16 * 1024);
/*memset(buf, 0, 16 * 1024);*/
for (i = 0; i < fontsize; i++)
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
{ /* KDFONTOP */
struct console_font_op cfo;
cfo.op = KD_FONT_OP_SET;
cfo.flags = 0;
cfo.width = 8;
cfo.height = unit;
cfo.charcount = fontsize;
cfo.data = (void*)buf;
#if 0
if (!ioctl_or_perror(fd, KDFONTOP, &cfo, "KDFONTOP ioctl failed (will try PIO_FONTX)"))
goto ret; /* success */
#else
xioctl(fd, KDFONTOP, &cfo);
#endif
}
#if 0
/* These ones do not honour -C tty (they set font on current tty regardless)
* On x86, this distinction is visible on framebuffer consoles
* (regular character consoles may have only one shared font anyway)
*/
#if defined(PIO_FONTX) && !defined(__sparc__)
{
struct consolefontdesc cfd;
@@ -95,16 +50,16 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
cfd.chardata = buf;
if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
goto ret; /* success */
goto ret; /* success */
}
#endif
xioctl(fd, PIO_FONT, buf);
ret:
#endif /* 0 */
free(buf);
}
static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
{
struct unimapinit advice;
struct unimapdesc ud;
@@ -113,7 +68,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
int glyph;
uint16_t unicode;
maxct = tailsz; /* more than enough */
maxct = tailsz; /* more than enough */
up = xmalloc(maxct * sizeof(struct unipair));
for (glyph = 0; glyph < fontsize; glyph++) {
@@ -141,233 +96,86 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
xioctl(fd, PIO_UNIMAP, &ud);
}
static void do_load(int fd, struct psf_header *psfhdr, size_t len)
static void loadnewfont(int fd)
{
enum { INBUF_SIZE = 32*1024 + 1 };
int unit;
int fontsize;
int hastable;
unsigned head0, head = head;
/* test for psf first */
if (len >= sizeof(struct psf_header) && PSF_MAGIC_OK(psfhdr)) {
if (psfhdr->mode > PSF_MAXMODE)
bb_error_msg_and_die("unsupported psf file mode");
fontsize = ((psfhdr->mode & PSF_MODE512) ? 512 : 256);
#if !defined(PIO_FONTX) || defined(__sparc__)
if (fontsize != 256)
bb_error_msg_and_die("only fontsize 256 supported");
#endif
hastable = (psfhdr->mode & PSF_MODEHASTAB);
unit = psfhdr->charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize * unit;
if (head > len || (!hastable && head != len))
bb_error_msg_and_die("input file: bad length");
} else {
/* file with three code pages? */
if (len == 9780) {
head0 = 40;
unit = 16;
} else {
/* bare font */
if (len & 0377)
bb_error_msg_and_die("input file: bad length");
head0 = 0;
unit = len / 256;
}
fontsize = 256;
hastable = 0;
}
do_loadfont(fd, (unsigned char *)psfhdr + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, (unsigned char *)psfhdr + head, len - head, fontsize);
}
#if ENABLE_LOADFONT
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc UNUSED_PARAM, char **argv)
{
size_t len;
struct psf_header *psfhdr;
// no arguments allowed!
opt_complementary = "=0";
getopt32(argv, "");
unsigned inputlth, offset;
/* Was on stack, but 32k is a bit too much: */
unsigned char *inbuf = xmalloc(INBUF_SIZE);
/*
* We used to look at the length of the input file
* with stat(); now that we accept compressed files,
* just read the entire file.
*/
len = 32*1024; // can't be larger
psfhdr = xmalloc_read(STDIN_FILENO, &len);
// xmalloc_open_zipped_read_close(filename, &len);
if (!psfhdr)
inputlth = full_read(STDIN_FILENO, inbuf, INBUF_SIZE);
if (inputlth < 0)
bb_perror_msg_and_die("error reading input font");
do_load(get_console_fd_or_die(), psfhdr, len);
if (inputlth >= INBUF_SIZE)
bb_error_msg_and_die("font too large");
return EXIT_SUCCESS;
}
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
unsigned head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = *(struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (psfhdr.mode > PSF_MAXMODE)
bb_error_msg_and_die("unsupported psf file mode");
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
#if !defined(PIO_FONTX) || defined(__sparc__)
if (fontsize != 256)
bb_error_msg_and_die("only fontsize 256 supported");
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
#if ENABLE_SETFONT
/*
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]
-h NN Override font height
-o file
Save previous font in file
-O file
Save previous font and Unicode map in file
-om file
Store console map in file
-ou file
Save previous Unicode map in file
-m file
Load console map or Unicode console map from file
-u file
Load Unicode table describing the font from file
Example:
# cp866
0x00-0x7f idem
#
0x80 U+0410 # CYRILLIC CAPITAL LETTER A
0x81 U+0411 # CYRILLIC CAPITAL LETTER BE
0x82 U+0412 # CYRILLIC CAPITAL LETTER VE
-C console
Set the font for the indicated console
-v Verbose
-V Version
*/
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
static int ctoi(char *s)
{
if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
return s[1];
// U+ means 0x
if (s[0] == 'U' && s[1] == '+') {
s[0] = '0';
s[1] = 'x';
head = head0 + fontsize * unit;
if (head > inputlth || (!hastable && head != inputlth))
bb_error_msg_and_die("input file: bad length");
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
return;
}
if (!isdigit(s[0]))
return -1;
return xstrtoul(s, 0);
}
#endif
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setfont_main(int argc UNUSED_PARAM, char **argv)
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377)
bb_error_msg_and_die("bad input file size");
offset = 0;
unit = inputlth / 256;
}
do_loadfont(fd, inbuf + offset, unit, 256);
}
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc, char **argv)
{
size_t len;
unsigned opts;
int fd;
struct psf_header *psfhdr;
char *mapfilename;
const char *tty_name = CURRENT_TTY;
opt_complementary = "=1";
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
argv += optind;
if (argc != 1)
bb_show_usage();
fd = xopen_nonblocking(tty_name);
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
if (*argv[0] != '/') {
// goto default fonts location. don't die if doesn't exist
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
}
}
// load font
len = 32*1024; // can't be larger
psfhdr = xmalloc_open_zipped_read_close(*argv, &len);
if (!psfhdr)
bb_simple_perror_msg_and_die(*argv);
do_load(fd, psfhdr, len);
// load the screen map, if any
if (opts & 1) { // -m
unsigned mode = PIO_SCRNMAP;
void *map;
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
if (mapfilename[0] != '/') {
// goto default keymaps location
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
}
}
// fetch keymap
map = xmalloc_open_zipped_read_close(mapfilename, &len);
if (!map)
bb_simple_perror_msg_and_die(mapfilename);
// file size is 256 or 512 bytes? -> assume binary map
if (len == E_TABSZ || len == 2*E_TABSZ) {
if (len == 2*E_TABSZ)
mode = PIO_UNISCRNMAP;
}
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
// assume textual Unicode console maps:
// 0x00 U+0000 # NULL (NUL)
// 0x01 U+0001 # START OF HEADING (SOH)
// 0x02 U+0002 # START OF TEXT (STX)
// 0x03 U+0003 # END OF TEXT (ETX)
else {
int i;
char *token[2];
parser_t *parser;
if (ENABLE_FEATURE_CLEAN_UP)
free(map);
map = xmalloc(E_TABSZ * sizeof(unsigned short));
#define unicodes ((unsigned short *)map)
// fill vanilla map
for (i = 0; i < E_TABSZ; i++)
unicodes[i] = 0xf000 + i;
parser = config_open(mapfilename);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
// parse code/value pair
int a = ctoi(token[0]);
int b = ctoi(token[1]);
if (a < 0 || a >= E_TABSZ
|| b < 0 || b > 65535
) {
bb_error_msg_and_die("map format");
}
// patch map
unicodes[a] = b;
// unicode character is met?
if (b > 255)
mode = PIO_UNISCRNMAP;
}
if (ENABLE_FEATURE_CLEAN_UP)
config_close(parser);
if (mode != PIO_UNISCRNMAP) {
#define asciis ((unsigned char *)map)
for (i = 0; i < E_TABSZ; i++)
asciis[i] = unicodes[i];
#undef asciis
}
#undef unicodes
}
#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
// do set screen map
xioctl(fd, mode, map);
if (ENABLE_FEATURE_CLEAN_UP)
free(map);
}
fd = xopen(CURRENT_VC, O_RDWR);
loadnewfont(fd);
return EXIT_SUCCESS;
}
#endif
+16 -19
View File
@@ -5,7 +5,9 @@
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*
*/
#include "libbb.h"
#define BINARY_KEYMAP_MAGIC "bkeymap"
@@ -24,30 +26,28 @@ struct kbentry {
#define MAX_NR_KEYMAPS 256
int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int loadkmap_main(int argc, char **argv)
{
struct kbentry ke;
int i, j, fd;
uint16_t ibuff[NR_KEYS];
/* const char *tty_name = CURRENT_TTY; */
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
char flags[MAX_NR_KEYMAPS];
char buff[7];
/* bb_warn_ignoring_args(argv[1]); */
fd = get_console_fd_or_die();
/* or maybe:
opt = getopt32(argv, "C:", &tty_name);
fd = xopen_nonblocking(tty_name);
*/
if (argc != 1)
bb_show_usage();
xread(STDIN_FILENO, flags, 7);
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
bb_error_msg_and_die("not a valid binary keymap");
fd = xopen(CURRENT_VC, O_RDWR);
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
xread(0, buff, 7);
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
bb_error_msg_and_die("this is not a valid binary keymap");
xread(0, flags, MAX_NR_KEYMAPS);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
for (j = 0; j < NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
@@ -57,9 +57,6 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
}
}
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd);
RELEASE_CONFIG_BUFFER(flags);
}
return EXIT_SUCCESS;
if (ENABLE_FEATURE_CLEAN_UP) close(fd);
return 0;
}
+15 -159
View File
@@ -8,172 +8,28 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <linux/vt.h>
/* getopt not needed */
#include "libbb.h"
/* "Standard" openvt's man page (we do not support all of this):
openvt [-c NUM] [-fsulv] [--] [command [args]]
Find the first available VT, and run command on it. Stdio is directed
to that VT. If no command is specified then $SHELL is used.
-c NUM
Use the given VT number, not the first free one.
-f
Force opening a VT: don't try to check if VT is already in use.
-s
Switch to the new VT when starting the command.
The VT of the new command will be made the new current VT.
-u
Figure out the owner of the current VT, and run login as that user.
Suitable to be called by init. Shouldn't be used with -c or -l.
-l
Make the command a login shell: a "-" is prepended to the argv[0]
when command is executed.
-v
Verbose.
-w
Wait for command to complete. If -w and -s are used together,
switch back to the controlling terminal when the command completes.
bbox:
-u: not implemented
-f: always in effect
-l: not implemented, ignored
-v: ignored
-ws: does NOT switch back
*/
/* Helper: does this fd understand VT_xxx? */
static int not_vt_fd(int fd)
{
struct vt_stat vtstat;
return ioctl(fd, VT_GETSTATE, &vtstat); /* !0: error, it's not VT fd */
}
/* Helper: get a fd suitable for VT_xxx */
static int get_vt_fd(void)
{
int fd;
/* Do we, by chance, already have it? */
for (fd = 0; fd < 3; fd++)
if (!not_vt_fd(fd))
return fd;
fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
if (fd >= 0 && !not_vt_fd(fd))
return fd;
bb_error_msg_and_die("can't find open VT");
}
static int find_free_vtno(void)
{
int vtno;
int fd = get_vt_fd();
errno = 0;
/*xfunc_error_retval = 3; - do we need compat? */
if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
bb_perror_msg_and_die("can't find open VT");
// Not really needed, grep for DAEMON_ONLY_SANITIZE
// if (fd > 2)
// close(fd);
return vtno;
}
/* vfork scares gcc, it generates bigger code.
* Keep it away from main program.
* TODO: move to libbb; or adapt existing libbb's spawn().
*/
static NOINLINE void vfork_child(char **argv)
{
if (vfork() == 0) {
/* CHILD */
/* Try to make this VT our controlling tty */
setsid(); /* lose old ctty */
ioctl(STDIN_FILENO, TIOCSCTTY, 0 /* 0: don't forcibly steal */);
//bb_error_msg("our sid %d", getsid(0));
//bb_error_msg("our pgrp %d", getpgrp());
//bb_error_msg("VT's sid %d", tcgetsid(0));
//bb_error_msg("VT's pgrp %d", tcgetpgrp(0));
BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
}
int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int openvt_main(int argc UNUSED_PARAM, char **argv)
int openvt_main(int argc, char **argv)
{
char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
struct vt_stat vtstat;
char *str_c;
int vtno;
int flags;
enum {
OPT_c = (1 << 0),
OPT_w = (1 << 1),
OPT_s = (1 << 2),
OPT_l = (1 << 3),
OPT_f = (1 << 4),
OPT_v = (1 << 5),
};
char vtname[sizeof(VC_FORMAT) + 2];
/* "+" - stop on first non-option */
flags = getopt32(argv, "+c:wslfv", &str_c);
argv += optind;
if (argc < 3)
bb_show_usage();
if (flags & OPT_c) {
/* Check for illegal vt number: < 1 or > 63 */
vtno = xatou_range(str_c, 1, 63);
} else {
vtno = find_free_vtno();
}
/* check for illegal vt number: < 1 or > 63 */
sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
/* Grab new VT */
sprintf(vtname, VC_FORMAT, vtno);
/* (Try to) clean up stray open fds above fd 2 */
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
close(STDIN_FILENO);
/*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
/* grab new one */
close(0);
xopen(vtname, O_RDWR);
xioctl(STDIN_FILENO, VT_GETSTATE, &vtstat);
dup2(0, STDOUT_FILENO);
dup2(0, STDERR_FILENO);
if (flags & OPT_s) {
console_make_active(STDIN_FILENO, vtno);
}
if (!argv[0]) {
argv--;
argv[0] = getenv("SHELL");
if (!argv[0])
argv[0] = (char *) DEFAULT_SHELL;
/*argv[1] = NULL; - already is */
}
xdup2(STDIN_FILENO, STDOUT_FILENO);
xdup2(STDIN_FILENO, STDERR_FILENO);
#ifdef BLOAT
{
/* Handle -l (login shell) option */
const char *prog = argv[0];
if (flags & OPT_l)
argv[0] = xasprintf("-%s", argv[0]);
}
#endif
vfork_child(argv);
if (flags & OPT_w) {
/* We have only one child, wait for it */
safe_waitpid(-1, NULL, 0); /* loops on EINTR */
if (flags & OPT_s) {
console_make_active(STDIN_FILENO, vtstat.v_active);
// Compat: even with -c N (try to) disallocate:
// # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5
// openvt: could not deallocate console 9
xioctl(STDIN_FILENO, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
}
}
return EXIT_SUCCESS;
BB_EXECVP(argv[2], &argv[2]);
_exit(1);
}
+5 -22
View File
@@ -8,25 +8,14 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* no options, no getopt */
#include "libbb.h"
/* BTW, which "standard" package has this utility? It doesn't seem
* to be ncurses, coreutils, console-tools... then what? */
#if ENABLE_STTY
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#endif
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int reset_main(int argc, char **argv)
{
static const char *const args[] = {
"stty", "sane", NULL
};
/* no options, no getopt */
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
if (isatty(1)) {
/* See 'man 4 console_codes' for details:
* "ESC c" -- Reset
* "ESC ( K" -- Select user mapping
@@ -35,13 +24,7 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
* "ESC [ ? 25 h" -- Make cursor visible.
*/
printf("\033c\033(K\033[J\033[0m\033[?25h");
/* http://bugs.busybox.net/view.php?id=1414:
* people want it to reset echo etc: */
#if ENABLE_STTY
return stty_main(2, (char**)args);
#else
execvp("stty", (char**)args);
#endif
}
return EXIT_SUCCESS;
}
+9 -11
View File
@@ -2,7 +2,7 @@
/*
* resize - set terminal width and height.
*
* Copyright 2006 Bernhard Reutner-Fischer
* Copyright 2006 Bernhard Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
@@ -14,17 +14,17 @@
#define old_termios (*(struct termios*)&bb_common_bufsiz1)
static void
onintr(int sig UNUSED_PARAM)
onintr(int sig ATTRIBUTE_UNUSED)
{
tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
exit(EXIT_FAILURE);
exit(1);
}
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int resize_main(int argc, char **argv)
{
struct termios new;
struct winsize w = { 0, 0, 0, 0 };
struct winsize w = { 0,0,0,0 };
int ret;
/* We use _stderr_ in order to make resize usable
@@ -37,12 +37,10 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
new = old_termios;
new.c_cflag |= (CLOCAL | CREAD);
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
bb_signals(0
+ (1 << SIGINT)
+ (1 << SIGQUIT)
+ (1 << SIGTERM)
+ (1 << SIGALRM)
, onintr);
signal(SIGINT, onintr);
signal(SIGQUIT, onintr);
signal(SIGTERM, onintr);
signal(SIGALRM, onintr);
tcsetattr(STDERR_FILENO, TCSANOW, &new);
/* save_cursor_pos 7
+20 -13
View File
@@ -3,34 +3,41 @@
* setconsole.c - redirect system console output
*
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
* Copyright (C) 2008 Bernhard Reutner-Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <getopt.h>
#include "libbb.h"
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
static const char setconsole_longopts[] ALIGN1 =
"reset\0" No_argument "r"
;
#endif
#define OPT_SETCONS_RESET 1
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setconsole_main(int argc UNUSED_PARAM, char **argv)
int setconsole_main(int argc, char **argv)
{
unsigned long flags;
const char *device = CURRENT_TTY;
bool reset;
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
static const char setconsole_longopts[] ALIGN1 =
"reset\0" No_argument "r"
;
applet_long_options = setconsole_longopts;
#endif
/* at most one non-option argument */
opt_complementary = "?1";
reset = getopt32(argv, "r");
flags = getopt32(argv, "r");
argv += 1 + reset;
if (*argv) {
device = *argv;
if (argc - optind > 1)
bb_show_usage();
if (argc - optind == 1) {
if (flags & OPT_SETCONS_RESET)
bb_show_usage();
device = argv[optind];
} else {
if (reset)
if (flags & OPT_SETCONS_RESET)
device = DEV_CONSOLE;
}
+5 -5
View File
@@ -14,7 +14,7 @@
/* From <linux/kd.h> */
struct kbkeycode {
unsigned scancode, keycode;
unsigned int scancode, keycode;
};
enum {
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
@@ -26,21 +26,21 @@ int setkeycodes_main(int argc, char **argv)
int fd, sc;
struct kbkeycode a;
if (!(argc & 1) /* if even */ || argc < 2) {
if (argc % 2 != 1 || argc < 2) {
bb_show_usage();
}
fd = get_console_fd_or_die();
fd = get_console_fd();
while (argc > 2) {
a.keycode = xatou_range(argv[2], 0, 127);
a.keycode = xatoul_range(argv[2], 0, 127);
a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
if (a.scancode > 127) {
a.scancode -= 0xe000;
a.scancode += 128;
}
ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
"can't set SCANCODE %x to KEYCODE %d",
"failed to set SCANCODE %x to KEYCODE %d",
sc, a.keycode);
argc -= 2;
argv += 2;
+8 -7
View File
@@ -12,19 +12,20 @@
#include "libbb.h"
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setlogcons_main(int argc UNUSED_PARAM, char **argv)
int setlogcons_main(int argc, char **argv)
{
struct {
char fn;
char subarg;
} arg = { 11, /* redirect kernel messages */
0 /* to specified console (current as default) */
};
} arg;
if (argv[1])
arg.subarg = xatou_range(argv[1], 0, 63);
arg.fn = 11; /* redirect kernel messages */
arg.subarg = 0; /* to specified console (current as default) */
if (argc == 2)
arg.subarg = xatoul_range(argv[1], 0, 63);
xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
return EXIT_SUCCESS;
return 0;
}
-138
View File
@@ -1,138 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* shows keys pressed. inspired by kbd package
*
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include <linux/kd.h>
// set raw tty mode
// also used by microcom
// libbb candidates?
static void xget1(int fd, struct termios *t, struct termios *oldt)
{
tcgetattr(fd, oldt);
*t = *oldt;
cfmakeraw(t);
}
static int xset1(int fd, struct termios *tio, const char *device)
{
int ret = tcsetattr(fd, TCSAFLUSH, tio);
if (ret) {
bb_perror_msg("can't tcsetattr for %s", device);
}
return ret;
}
/*
* GLOBALS
*/
struct globals {
int kbmode;
struct termios tio, tio0;
};
#define G (*ptr_to_globals)
#define kbmode (G.kbmode)
#define tio (G.tio)
#define tio0 (G.tio0)
#define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0)
static void signal_handler(int signo)
{
// restore keyboard and console settings
xset1(STDIN_FILENO, &tio0, "stdin");
xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
// alarmed? -> exit 0
exit(SIGALRM == signo);
}
int showkey_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int showkey_main(int argc UNUSED_PARAM, char **argv)
{
enum {
OPT_a = (1<<0), // display the decimal/octal/hex values of the keys
OPT_k = (1<<1), // display only the interpreted keycodes (default)
OPT_s = (1<<2), // display only the raw scan-codes
};
// FIXME: aks are all mutually exclusive
getopt32(argv, "aks");
INIT_G();
// get keyboard settings
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",
kbmode == K_RAW ? "RAW" :
(kbmode == K_XLATE ? "XLATE" :
(kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
(kbmode == K_UNICODE ? "UNICODE" : "?UNKNOWN?")))
, (option_mask32 & OPT_a) ? "when CTRL+D pressed" : "10s after last keypress"
);
// prepare for raw mode
xget1(STDIN_FILENO, &tio, &tio0);
// put stdin in raw mode
xset1(STDIN_FILENO, &tio, "stdin");
if (option_mask32 & OPT_a) {
char c;
// just read stdin char by char
while (1 == safe_read(STDIN_FILENO, &c, 1)) {
printf("%3d 0%03o 0x%02x\r\n", c, c, c);
if (04 /*CTRL-D*/ == c)
break;
}
} else {
// we should exit on any signal
bb_signals(BB_FATAL_SIGS, signal_handler);
// set raw keyboard mode
xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW));
// read and show scancodes
while (1) {
char buf[18];
int i, n;
// setup 10s watchdog
alarm(10);
// read scancodes
n = read(STDIN_FILENO, buf, sizeof(buf));
i = 0;
while (i < n) {
char c = buf[i];
// show raw scancodes ordered? ->
if (option_mask32 & OPT_s) {
printf("0x%02x ", buf[i++]);
// show interpreted scancodes (default) ? ->
} else {
int kc;
if (i+2 < n && (c & 0x7f) == 0
&& (buf[i+1] & 0x80) != 0
&& (buf[i+2] & 0x80) != 0) {
kc = ((buf[i+1] & 0x7f) << 7) | (buf[i+2] & 0x7f);
i += 3;
} else {
kc = (c & 0x7f);
i++;
}
printf("keycode %3d %s", kc, (c & 0x80) ? "release" : "press");
}
}
puts("\r");
}
}
// cleanup
signal_handler(SIGALRM);
// should never be here!
return EXIT_SUCCESS;
}
+31 -126
View File
@@ -10,7 +10,7 @@ config BASENAME
default n
help
basename is used to strip the directory and suffix from filenames,
leaving just the filename itself. Enable this option if you wish
leaving just the filename itself. Enable this option if you wish
to enable the 'basename' utility.
config CAL
@@ -24,7 +24,7 @@ config CAT
default n
help
cat is used to concatenate files and print them to the standard
output. Enable this option if you wish to enable the 'cat' utility.
output. Enable this option if you wish to enable the 'cat' utility.
config CATV
bool "catv"
@@ -52,13 +52,6 @@ config CHOWN
chown is used to change the user and/or group ownership
of files.
config FEATURE_CHOWN_LONG_OPTIONS
bool "Enable long options"
default n
depends on CHOWN && LONG_OPTS
help
Enable use of long options
config CHROOT
bool "chroot"
default n
@@ -85,14 +78,6 @@ config CP
help
cp is used to copy files and directories.
config FEATURE_CP_LONG_OPTIONS
bool "Enable long options for cp"
default n
depends on CP && LONG_OPTS
help
Enable long options for cp.
Also add support for --parents option.
config CUT
bool "cut"
default n
@@ -115,22 +100,6 @@ config FEATURE_DATE_ISOFMT
Enable option (-I) to output an ISO-8601 compliant
date/time string.
config FEATURE_DATE_COMPAT
bool "Support weird 'date MMDDhhmm[[YY]YY][.ss]' format"
default y
depends on DATE
help
System time can be set by 'date -s DATE' and simply 'date DATE',
but formats of DATE string are different. 'date DATE' accepts
a rather weird MMDDhhmm[[YY]YY][.ss] format with completely
unnatural placement of year between minutes and seconds.
date -s (and other commands like touch -d) use more sensible
formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
With this option off, 'date DATE' is 'date -s DATE' support
the same format. With it on, 'date DATE' additionally supports
MMDDhhmm[[YY]YY][.ss] format.
config DD
bool "dd"
default n
@@ -144,22 +113,12 @@ config FEATURE_DD_SIGNAL_HANDLING
default y
depends on DD
help
Sending a SIGUSR1 signal to a running `dd' process makes it
sending a SIGUSR1 signal to a running `dd' process makes it
print to standard error the number of records read and written
so far, then to resume copying.
$ dd if=/dev/zero of=/dev/null&
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
10899206+0 records in
10899206+0 records out
config FEATURE_DD_THIRD_STATUS_LINE
bool "Enable the third status line upon signal"
default n
depends on DD && FEATURE_DD_SIGNAL_HANDLING
help
Displays a coreutils-like third status line with transferred bytes,
elapsed time and speed.
$ dd if=/dev/zero of=/dev/null& pid=$! $ kill -USR1 $pid; sleep 1; kill $pid
10899206+0 records in 10899206+0 records out
config FEATURE_DD_IBS_OBS
bool "Enable ibs, obs and conv options"
@@ -176,13 +135,6 @@ config DF
df reports the amount of disk space used and available
on filesystems.
config FEATURE_DF_FANCY
bool "Enable -a, -i, -B"
default n
depends on DF
help
This option enables -a, -i and -B.
config DIRNAME
bool "dirname"
default n
@@ -229,7 +181,7 @@ config ECHO
config FEATURE_FANCY_ECHO
bool "Enable echo options (-n and -e)"
default y
depends on ECHO || ASH_BUILTIN_ECHO || HUSH
depends on ECHO
help
This adds options (-n and -e) to echo.
@@ -244,7 +196,7 @@ config ENV
config FEATURE_ENV_LONG_OPTIONS
bool "Enable long options"
default n
depends on ENV && LONG_OPTS
depends on ENV && GETOPT_LONG
help
Support long options for the env applet.
@@ -257,7 +209,7 @@ config EXPAND
config FEATURE_EXPAND_LONG_OPTIONS
bool "Enable long options"
default n
depends on EXPAND && LONG_OPTS
depends on EXPAND && GETOPT_LONG
help
Support long options for the expand applet.
@@ -273,7 +225,7 @@ config EXPR_MATH_SUPPORT_64
default n
depends on EXPR
help
Enable 64-bit math support in the expr applet. This will make
Enable 64-bit math support in the expr applet. This will make
the applet slightly larger, but will allow computation with very
large numbers.
@@ -289,12 +241,6 @@ config FOLD
help
Wrap text to fit a specific width.
config FSYNC
bool "fsync"
default n
help
fsync is used to flush file-related cached blocks to disk.
config HEAD
bool "head"
default n
@@ -331,7 +277,7 @@ config INSTALL
config FEATURE_INSTALL_LONG_OPTIONS
bool "Enable long options"
default n
depends on INSTALL && LONG_OPTS
depends on INSTALL && GETOPT_LONG
help
Support long options for the install applet.
@@ -404,7 +350,7 @@ config FEATURE_LS_USERNAME
config FEATURE_LS_COLOR
bool "Allow use of color to identify file types"
default y
depends on LS && LONG_OPTS
depends on LS && GETOPT_LONG
help
This enables the --color option to ls.
@@ -434,7 +380,7 @@ config MKDIR
config FEATURE_MKDIR_LONG_OPTIONS
bool "Enable long options"
default n
depends on MKDIR && LONG_OPTS
depends on MKDIR && GETOPT_LONG
help
Support long options for the mkdir applet.
@@ -461,7 +407,7 @@ config MV
config FEATURE_MV_LONG_OPTIONS
bool "Enable long options"
default n
depends on MV && LONG_OPTS
depends on MV && GETOPT_LONG
help
Support long options for the mv applet.
@@ -535,14 +481,6 @@ config RMDIR
help
rmdir is used to remove empty directories.
config FEATURE_RMDIR_LONG_OPTIONS
bool "Enable long options"
default n
depends on RMDIR && LONG_OPTS
help
Support long options for the rmdir applet, including
--ignore-fail-on-non-empty for compatibility with GNU rmdir.
config SEQ
bool "seq"
default n
@@ -555,46 +493,19 @@ config SHA1SUM
help
Compute and check SHA1 message digest
config SHA256SUM
bool "sha256sum"
default n
help
Compute and check SHA256 message digest
config SHA512SUM
bool "sha512sum"
default n
help
Compute and check SHA512 message digest
config SLEEP
bool "sleep"
bool "sleep (single integer arg with no suffix)"
default n
help
sleep is used to pause for a specified number of seconds.
It comes in 3 versions:
- small: takes one integer parameter
- fancy: takes multiple integer arguments with suffixes:
sleep 1d 2h 3m 15s
- fancy with fractional numbers:
sleep 2.3s 4.5h sleeps for 16202.3 seconds
Last one is "the most compatible" with coreutils sleep,
but it adds around 1k of code.
sleep is used to pause for a specified number of seconds,
config FEATURE_FANCY_SLEEP
bool "Enable multiple arguments and s/m/h/d suffixes"
bool "Enable multiple integer args and optional time suffixes"
default n
depends on SLEEP
help
Allow sleep to pause for specified minutes, hours, and days.
config FEATURE_FLOAT_SLEEP
bool "Enable fractional arguments"
default n
depends on FEATURE_FANCY_SLEEP
help
Allow for fractional numeric parameters.
config SORT
bool "sort"
default n
@@ -602,13 +513,13 @@ config SORT
sort is used to sort lines of text in specified files.
config FEATURE_SORT_BIG
bool "Full SuSv3 compliant sort (support -ktcsbdfiozgM)"
bool "full SuSv3 compliant sort (Support -ktcsbdfiozgM)"
default y
depends on SORT
help
Without this, sort only supports -r, -u, and an integer version
of -n. Selecting this adds sort keys, floating point support, and
more. This adds a little over 3k to a nonstatic build on x86.
Without this, sort only supports -r, -u, and an integer version
of -n. Selecting this adds sort keys, floating point support, and
more. This adds a little over 3k to a nonstatic build on x86.
The SuSv3 sort standard is available at:
http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
@@ -620,7 +531,7 @@ config SPLIT
split a file into pieces.
config FEATURE_SPLIT_FANCY
bool "Fancy extensions"
bool "fancy extensions"
default n
depends on SPLIT
help
@@ -640,7 +551,7 @@ config FEATURE_STAT_FORMAT
depends on STAT
help
Without this, stat will not support the '-c format' option where
users can pass a custom format string for output. This adds about
users can pass a custom format string for output. This adds about
7k to a nonstatic build on amd64.
config STTY
@@ -661,12 +572,6 @@ config SYNC
help
sync is used to flush filesystem buffers.
config TAC
bool "tac"
default n
help
tac is used to concatenate and print files in reverse.
config TAIL
bool "tail"
default n
@@ -675,7 +580,7 @@ config TAIL
from files.
config FEATURE_FANCY_TAIL
bool "Enable extra tail options (-q, -s, -v, and -F)"
bool "Enable extra tail options (-q, -s, and -v)"
default y
depends on TAIL
help
@@ -690,7 +595,7 @@ config TEE
to standard output and files.
config FEATURE_TEE_USE_BLOCK_IO
bool "Enable block I/O (larger/faster) instead of byte I/O"
bool "Enable block i/o (larger/faster) instead of byte i/o."
default n
depends on TEE
help
@@ -701,13 +606,13 @@ config TEST
default n
help
test is used to check file types and compare values,
returning an appropriate exit code. The bash shell
returning an appropriate exit code. The bash shell
has test built in, ash can build it in optionally.
config FEATURE_TEST_64
bool "Extend test to 64 bit"
default n
depends on TEST || ASH_BUILTIN_TEST || HUSH
depends on TEST
help
Enable 64-bit support in test.
@@ -772,7 +677,7 @@ config UNEXPAND
config FEATURE_UNEXPAND_LONG_OPTIONS
bool "Enable long options"
default n
depends on UNEXPAND && LONG_OPTS
depends on UNEXPAND && GETOPT_LONG
help
Support long options for the unexpand applet.
@@ -812,7 +717,7 @@ config FEATURE_WC_LARGE
default n
depends on WC
help
Use "unsigned long long" in wc for counter variables.
Use "unsigned long long" in wc for count variables
config WHO
bool "who"
@@ -869,13 +774,13 @@ config FEATURE_HUMAN_READABLE
help
Allow df, du, and ls to have human readable output.
comment "Common options for md5sum, sha1sum, sha256sum, sha512sum"
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
comment "Common options for md5sum, sha1sum"
depends on MD5SUM || SHA1SUM
config FEATURE_MD5_SHA1_SUM_CHECK
bool "Enable -c, -s and -w options"
default n
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
depends on MD5SUM || SHA1SUM
help
Enabling the -c options allows files to be checked
against pre-calculated hash values.
+2 -12
View File
@@ -12,7 +12,6 @@ lib-$(CONFIG_CAL) += cal.o
lib-$(CONFIG_CAT) += cat.o
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
lib-$(CONFIG_LESS) += cat.o # less too
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
@@ -30,13 +29,11 @@ lib-$(CONFIG_DOS2UNIX) += dos2unix.o
lib-$(CONFIG_DU) += du.o
lib-$(CONFIG_ECHO) += echo.o
lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_HUSH) += echo.o # used by hush
lib-$(CONFIG_ENV) += env.o
lib-$(CONFIG_EXPR) += expr.o
lib-$(CONFIG_EXPAND) += expand.o
lib-$(CONFIG_FALSE) += false.o
lib-$(CONFIG_FOLD) += fold.o
lib-$(CONFIG_FSYNC) += fsync.o
lib-$(CONFIG_HEAD) += head.o
lib-$(CONFIG_HOSTID) += hostid.o
lib-$(CONFIG_ID) += id.o
@@ -45,7 +42,6 @@ lib-$(CONFIG_LENGTH) += length.o
lib-$(CONFIG_LN) += ln.o
lib-$(CONFIG_LOGNAME) += logname.o
lib-$(CONFIG_LS) += ls.o
lib-$(CONFIG_FTPD) += ls.o
lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
lib-$(CONFIG_MKDIR) += mkdir.o
lib-$(CONFIG_MKFIFO) += mkfifo.o
@@ -56,7 +52,6 @@ lib-$(CONFIG_NOHUP) += nohup.o
lib-$(CONFIG_OD) += od.o
lib-$(CONFIG_PRINTENV) += printenv.o
lib-$(CONFIG_PRINTF) += printf.o
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
lib-$(CONFIG_PWD) += pwd.o
lib-$(CONFIG_READLINK) += readlink.o
lib-$(CONFIG_REALPATH) += realpath.o
@@ -64,8 +59,6 @@ lib-$(CONFIG_RM) += rm.o
lib-$(CONFIG_RMDIR) += rmdir.o
lib-$(CONFIG_SEQ) += seq.o
lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
lib-$(CONFIG_SLEEP) += sleep.o
lib-$(CONFIG_SPLIT) += split.o
lib-$(CONFIG_SORT) += sort.o
@@ -73,13 +66,10 @@ lib-$(CONFIG_STAT) += stat.o
lib-$(CONFIG_STTY) += stty.o
lib-$(CONFIG_SUM) += sum.o
lib-$(CONFIG_SYNC) += sync.o
lib-$(CONFIG_TAC) += tac.o
lib-$(CONFIG_TAIL) += tail.o
lib-$(CONFIG_TEE) += tee.o
lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
lib-$(CONFIG_ASH) += test.o test_ptr_hack.o # used by ash
lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o # used by hush
lib-$(CONFIG_MSH) += test.o test_ptr_hack.o # used by msh
lib-$(CONFIG_TEST) += test.o
lib-$(CONFIG_ASH) += test.o # used by ash
lib-$(CONFIG_TOUCH) += touch.o
lib-$(CONFIG_TR) += tr.o
lib-$(CONFIG_TRUE) += true.o
+5 -7
View File
@@ -37,17 +37,15 @@ int basename_main(int argc, char **argv)
/* It should strip slash: /abc/def/ -> def */
s = bb_get_last_path_component_strip(*++argv);
m = strlen(s);
if (*++argv) {
n = strlen(*argv);
m = strlen(s);
if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) {
m -= n;
/*s[m] = '\0'; - redundant */
s[m-n] = '\0';
}
}
/* puts(s) will do, but we can do without stdio this way: */
s[m++] = '\n';
/* NB: != is correct here: */
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
puts(s);
return fflush(stdout);
}
+19 -42
View File
@@ -16,8 +16,8 @@
*
* Major size reduction... over 50% (>1.5k) on i386.
*/
#include "libbb.h"
#include "unicode.h"
/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
@@ -40,8 +40,7 @@ static const unsigned char sep1752[] ALIGN1 = {
24, 25, 26, 27, 28, 29, 30
};
/* Set to 0 or 1 in main */
#define julian ((unsigned)option_mask32)
static unsigned julian;
/* leap year -- account for Gregorian reformation in 1752 */
static int leap_year(unsigned yr)
@@ -77,42 +76,35 @@ static char *build_row(char *p, unsigned *dp);
#define HEAD_SEP 2 /* spaces between day headings */
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cal_main(int argc UNUSED_PARAM, char **argv)
int cal_main(int argc, char **argv)
{
struct tm *local_time;
struct tm zero_tm;
time_t now;
unsigned month, year, flags, i;
char *month_names[12];
/* normal heading: */
/* "Su Mo Tu We Th Fr Sa" */
/* -j heading: */
/* " Su Mo Tu We Th Fr Sa" */
char day_headings[ENABLE_FEATURE_ASSUME_UNICODE ? 28 * 6 : 28];
IF_FEATURE_ASSUME_UNICODE(char *hp = day_headings;)
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
char buf[40];
init_unicode();
flags = getopt32(argv, "jy");
/* This sets julian = flags & 1: */
option_mask32 &= 1;
julian = flags & 1;
month = 0;
argv += optind;
argc -= optind;
if (!argv[0]) {
struct tm *ptm;
if (argc > 2) {
bb_show_usage();
}
if (!argc) {
time(&now);
ptm = localtime(&now);
year = ptm->tm_year + 1900;
if (!(flags & 2)) { /* no -y */
month = ptm->tm_mon + 1;
local_time = localtime(&now);
year = local_time->tm_year + 1900;
if (!(flags & 2)) {
month = local_time->tm_mon + 1;
}
} else {
if (argv[1]) {
if (argv[2]) {
bb_show_usage();
}
if (argc == 2) {
month = xatou_range(*argv++, 1, 12);
}
year = xatou_range(*argv, 1, 9999);
@@ -123,30 +115,15 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
i = 0;
do {
zero_tm.tm_mon = i;
/* full month name according to locale */
strftime(buf, sizeof(buf), "%B", &zero_tm);
month_names[i] = xstrdup(buf);
if (i < 7) {
zero_tm.tm_wday = i;
/* abbreviated weekday name according to locale */
strftime(buf, sizeof(buf), "%a", &zero_tm);
#if ENABLE_FEATURE_ASSUME_UNICODE
if (julian)
*hp++ = ' ';
{
char *two_wchars = unicode_cut_nchars(2, buf);
strcpy(hp, two_wchars);
free(two_wchars);
}
hp += strlen(hp);
*hp++ = ' ';
#else
strncpy(day_headings + i * (3+julian) + julian, buf, 2);
#endif
}
} while (++i < 12);
IF_FEATURE_ASSUME_UNICODE(hp[-1] = '\0';)
if (month) {
unsigned row, len, days[MAXDAYS];
@@ -168,7 +145,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
unsigned *dp;
char lineout[80];
sprintf(lineout, "%u", year);
sprintf(lineout, "%d", year);
center(lineout,
(WEEK_LEN * 3 + HEAD_SEP * 2)
+ julian * (J_WEEK_LEN * 2 + HEAD_SEP
@@ -202,7 +179,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
}
}
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit(0);
}
/*
@@ -283,7 +260,7 @@ static void trim_trailing_spaces_and_print(char *s)
}
while (p != s) {
--p;
if (!isspace(*p)) {
if (!(isspace)(*p)) { /* We want the function... not the inline. */
p[1] = '\0';
break;
}
+8 -4
View File
@@ -17,16 +17,20 @@
int bb_cat(char **argv)
{
static const char *const argv_dash[] = { "-", NULL };
int fd;
int retval = EXIT_SUCCESS;
if (!*argv)
argv = (char**) &bb_argv_dash;
argv = (char**) &argv_dash;
do {
fd = open_or_warn_stdin(*argv);
fd = STDIN_FILENO;
if (!LONE_DASH(*argv))
fd = open_or_warn(*argv, O_RDONLY);
if (fd >= 0) {
/* This is not a xfunc - never exits */
/* This is not an xfunc - never exits */
off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
if (fd != STDIN_FILENO)
close(fd);
@@ -40,7 +44,7 @@ int bb_cat(char **argv)
}
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc UNUSED_PARAM, char **argv)
int cat_main(int argc, char **argv)
{
getopt32(argv, "u");
argv += optind;
+8 -4
View File
@@ -13,7 +13,7 @@
#include "libbb.h"
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc UNUSED_PARAM, char **argv)
int catv_main(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
@@ -27,14 +27,18 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
fd = 0;
if (!argv[0]) {
argv--;
goto jump_in;
}
do {
fd = open_or_warn_stdin(*argv);
fd = open_or_warn(*argv, O_RDONLY);
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
}
jump_in:
for (;;) {
int i, res;
Loaded 100 of 1306 files, more files were not shown because too many files have changed in this diff. Show more