Compare commits
26
Commits
1_8_stable
..
1_01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3986eb7ec | ||
|
|
9e78a1772d | ||
|
|
f7c7dde158 | ||
|
|
830c040f6f | ||
|
|
045dedad91 | ||
|
|
b309ec71c8 | ||
|
|
866bad310f | ||
|
|
5e1f2d429d | ||
|
|
0be69b1693 | ||
|
|
c7cba1ae3b | ||
|
|
be3dae145f | ||
|
|
6022fc8723 | ||
|
|
fc455b2101 | ||
|
|
365a345e92 | ||
|
|
d5138f44fe | ||
|
|
9344d8aa10 | ||
|
|
44dbd4bc65 | ||
|
|
25b8652b4f | ||
|
|
091a3e510e | ||
|
|
ffaa3deeeb | ||
|
|
5f07779aca | ||
|
|
ab6399a4c6 | ||
|
|
ca17c937c2 | ||
|
|
d62df011a0 | ||
|
|
164a716f96 | ||
|
|
8c59a0bf0e |
No files matched your search
@@ -1,558 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
mainmenu "BusyBox Configuration"
|
||||
|
||||
config HAVE_DOT_CONFIG
|
||||
bool
|
||||
default y
|
||||
|
||||
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
|
||||
help
|
||||
Enable options and features which are not essential.
|
||||
Select this only if you plan to use busybox on full-blown
|
||||
desktop machine with common Linux distro, not on an embedded box.
|
||||
|
||||
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.
|
||||
- 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
|
||||
earlier.
|
||||
|
||||
config FEATURE_BUFFERS_USE_MALLOC
|
||||
bool "Allocate with Malloc"
|
||||
|
||||
config FEATURE_BUFFERS_GO_ON_STACK
|
||||
bool "Allocate on the Stack"
|
||||
|
||||
config FEATURE_BUFFERS_GO_IN_BSS
|
||||
bool "Allocate in the .bss section"
|
||||
|
||||
endchoice
|
||||
|
||||
config SHOW_USAGE
|
||||
bool "Show terse applet usage messages"
|
||||
default y
|
||||
help
|
||||
All BusyBox applets will show help messages when invoked with
|
||||
wrong arguments. You can turn off printing these terse usage
|
||||
messages if you say no here.
|
||||
This will save you up to 7k.
|
||||
|
||||
config FEATURE_VERBOSE_USAGE
|
||||
bool "Show verbose applet usage messages"
|
||||
default n
|
||||
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
|
||||
13k, but it can add much more depending on your configuration.
|
||||
|
||||
config FEATURE_COMPRESS_USAGE
|
||||
bool "Store applet usage messages in compressed form"
|
||||
default y
|
||||
depends on SHOW_USAGE
|
||||
help
|
||||
Store usage messages in compressed form, uncompress them on-the-fly
|
||||
when <applet> --help is called.
|
||||
|
||||
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,
|
||||
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
|
||||
busybox at runtime to create hard links or symlinks for all the
|
||||
applets that are compiled into busybox.
|
||||
|
||||
config LOCALE_SUPPORT
|
||||
bool "Enable locale support (system needs locale for this to work)"
|
||||
default n
|
||||
help
|
||||
Enable this if your system has locale support and you would like
|
||||
busybox to support locale settings.
|
||||
|
||||
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
|
||||
style, in addition to single character -a -b -c style options.
|
||||
|
||||
config FEATURE_DEVPTS
|
||||
bool "Use the devpts filesystem for Unix98 PTYs"
|
||||
default y
|
||||
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
|
||||
/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
|
||||
space since the OS will clean up for us, but it can confuse debuggers
|
||||
like valgrind, which report tons of memory and resource leaks.
|
||||
|
||||
Don't enable this unless you have a really good reason to clean
|
||||
things up manually.
|
||||
|
||||
config FEATURE_PIDFILE
|
||||
bool "Support writing pidfiles"
|
||||
default n
|
||||
help
|
||||
This option makes some applets (e.g. crond, syslogd, inetd) write
|
||||
a pidfile in /var/run. Some applications rely on them.
|
||||
|
||||
config FEATURE_SUID
|
||||
bool "Support for SUID/SGID handling"
|
||||
default n
|
||||
help
|
||||
With this option you can install the busybox binary belonging
|
||||
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'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 login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs,
|
||||
and vlock.
|
||||
|
||||
config FEATURE_SUID_CONFIG
|
||||
bool "Runtime SUID/SGID configuration via /etc/busybox.conf"
|
||||
default n if FEATURE_SUID
|
||||
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.)
|
||||
The format of this file is as follows:
|
||||
|
||||
<applet> = [Ssx-][Ssx-][x-] (<username>|<uid>).(<groupname>|<gid>)
|
||||
|
||||
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 # exactly the same
|
||||
|
||||
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
|
||||
|
||||
The file has to be owned by user root, group root and has to be
|
||||
writeable only by root:
|
||||
(chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
|
||||
The busybox executable has to be owned by user root, group
|
||||
root and has to be setuid root for this to work:
|
||||
(chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)
|
||||
|
||||
Robert 'sandman' Griebl has more information here:
|
||||
<url: http://www.softforge.de/bb/suid.html >.
|
||||
|
||||
config FEATURE_SUID_CONFIG_QUIET
|
||||
bool "Suppress warning message if /etc/busybox.conf is not readable"
|
||||
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.
|
||||
|
||||
config SELINUX
|
||||
bool "Support NSA Security Enhanced Linux"
|
||||
default n
|
||||
help
|
||||
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
|
||||
will not compile. Go visit
|
||||
http://www.nsa.gov/selinux/index.html
|
||||
to download the necessary stuff to allow busybox to compile with
|
||||
this option enabled. Specifially, libselinux 1.28 or better is
|
||||
directly required by busybox. If the installation is located in a
|
||||
non-standard directory, provide it by invoking make as follows:
|
||||
CFLAGS=-I<libselinux-include-path> \
|
||||
LDFLAGS=-L<libselinux-lib-path> \
|
||||
make
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config FEATURE_PREFER_APPLETS
|
||||
bool "exec prefers applets"
|
||||
default n
|
||||
help
|
||||
This is an experimental option which directs applets about to
|
||||
call 'exec' to try and find an applicable busybox applet before
|
||||
searching the PATH. This is typically done by exec'ing
|
||||
/proc/self/exe.
|
||||
This may affect shell, find -exec, xargs and similar applets.
|
||||
They will use applets even if /bin/<applet> -> busybox link
|
||||
is missing (or is not a link to busybox). However, this causes
|
||||
problems in chroot jails without mounted /proc and with ps/top
|
||||
(command name can be shown as 'exe' for applets started this way).
|
||||
|
||||
config BUSYBOX_EXEC_PATH
|
||||
string "Path to BusyBox executable"
|
||||
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
|
||||
mounted, /proc/self/exe always points to the currently running
|
||||
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 "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.
|
||||
|
||||
config FEATURE_HAVE_RPC
|
||||
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.
|
||||
|
||||
endmenu
|
||||
|
||||
menu 'Build Options'
|
||||
|
||||
config STATIC
|
||||
bool "Build BusyBox as a static binary (no shared libs)"
|
||||
default n
|
||||
help
|
||||
If you want to build a static BusyBox binary, which does not
|
||||
use or require any shared libraries, then enable this option.
|
||||
This can cause BusyBox to be considerably larger, so you should
|
||||
leave this option false unless you have a good reason (i.e.
|
||||
your target platform does not support shared libraries, or
|
||||
you are building an initrd which doesn't need anything but
|
||||
BusyBox, etc).
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config BUILD_LIBBUSYBOX
|
||||
bool "Build shared libbusybox"
|
||||
default n
|
||||
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"
|
||||
approach serves no purpose and increases code size.
|
||||
You should almost certainly say "no" to this.
|
||||
|
||||
### config FEATURE_FULL_LIBBUSYBOX
|
||||
### bool "Feature-complete libbusybox"
|
||||
### default n if !FEATURE_SHARED_BUSYBOX
|
||||
### depends on BUILD_LIBBUSYBOX
|
||||
### help
|
||||
### Build a libbusybox with the complete feature-set, disregarding
|
||||
### the actually selected config.
|
||||
###
|
||||
### Normally, libbusybox will only contain the features which are
|
||||
### used by busybox itself. If you plan to write a separate
|
||||
### 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
|
||||
### exported function set between releases (even minor version number
|
||||
### changes), and happily break out-of-tree features.
|
||||
###
|
||||
### Say 'N' if in doubt.
|
||||
|
||||
config FEATURE_INDIVIDUAL
|
||||
bool "Produce a binary for each applet, linked against libbusybox"
|
||||
default y
|
||||
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
|
||||
libraries, this option will allow you to reduce memory footprint
|
||||
when you have many different applets running at once.
|
||||
|
||||
If your CPU architecture allows for sharing text/rodata,
|
||||
having single binary is more optimal.
|
||||
|
||||
Each applet will be a tiny program, dynamically linked
|
||||
against libbusybox.so.N.N.N.
|
||||
|
||||
You need to have a working dynamic linker.
|
||||
|
||||
config FEATURE_SHARED_BUSYBOX
|
||||
bool "Produce additional busybox binary linked against libbusybox"
|
||||
default y
|
||||
depends on !STATIC && BUILD_LIBBUSYBOX
|
||||
help
|
||||
Build busybox, dynamically linked against libbusybox.so.N.N.N.
|
||||
|
||||
You need to have a working dynamic linker.
|
||||
|
||||
### config BUILD_AT_ONCE
|
||||
### bool "Compile all sources at once"
|
||||
### default n
|
||||
### help
|
||||
### Normally each source-file is compiled with one invocation of
|
||||
### the compiler.
|
||||
### If you set this option, all sources are compiled at once.
|
||||
### This gives the compiler more opportunities to optimize which can
|
||||
### result in smaller and/or faster binaries.
|
||||
###
|
||||
### Setting this option will consume alot of memory, e.g. if you
|
||||
### enable all applets with all features, gcc uses more than 300MB
|
||||
### RAM during compilation of busybox.
|
||||
###
|
||||
### This option is most likely only beneficial for newer compilers
|
||||
### such as gcc-4.1 and above.
|
||||
###
|
||||
### Say 'N' unless you know what you are doing.
|
||||
|
||||
config LFS
|
||||
bool "Build with Large File Support (for accessing files > 2 GB)"
|
||||
default n
|
||||
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
|
||||
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'.
|
||||
|
||||
endmenu
|
||||
|
||||
menu 'Debugging Options'
|
||||
|
||||
config DEBUG
|
||||
bool "Build BusyBox with extra Debugging symbols"
|
||||
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
|
||||
development and want to debug BusyBox, answer Y.
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
help
|
||||
Selecting this will add -Werror to gcc command line.
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
Electric-fence support:
|
||||
-----------------------
|
||||
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
|
||||
and run slower, so you should leave this option disabled unless
|
||||
you are hunting a hard to find memory problem.
|
||||
|
||||
|
||||
config NO_DEBUG_LIB
|
||||
bool "None"
|
||||
|
||||
config DMALLOC
|
||||
bool "Dmalloc"
|
||||
|
||||
config EFENCE
|
||||
bool "Electric-fence"
|
||||
|
||||
endchoice
|
||||
|
||||
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
|
||||
|
||||
menu 'Installation Options'
|
||||
|
||||
config INSTALL_NO_USR
|
||||
bool "Don't use /usr"
|
||||
default n
|
||||
help
|
||||
Disable use of /usr. Don't activate this option if you don't know
|
||||
that you really want this behaviour.
|
||||
|
||||
choice
|
||||
prompt "Applets links"
|
||||
default INSTALL_APPLET_SYMLINKS
|
||||
help
|
||||
Choose how you install applets links.
|
||||
|
||||
config INSTALL_APPLET_SYMLINKS
|
||||
bool "as soft-links"
|
||||
help
|
||||
Install applets as soft-links to the busybox binary. This needs some
|
||||
free inodes on the filesystem, but might help with filesystem
|
||||
generators that can't cope with hard-links.
|
||||
|
||||
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.
|
||||
|
||||
config INSTALL_APPLET_SCRIPT_WRAPPERS
|
||||
bool "as script wrappers"
|
||||
help
|
||||
Install applets as script wrappers that call the busybox binary.
|
||||
|
||||
config INSTALL_APPLET_DONT
|
||||
bool "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
|
||||
help
|
||||
Do not install applet links. Useful when using the -install feature
|
||||
or a standalone shell for rescue purposes.
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "/bin/sh applet link"
|
||||
default INSTALL_SH_APPLET_SYMLINK
|
||||
depends on INSTALL_APPLET_SCRIPT_WRAPPERS
|
||||
help
|
||||
Choose how you install /bin/sh applet link.
|
||||
|
||||
config INSTALL_SH_APPLET_SYMLINK
|
||||
bool "as soft-link"
|
||||
help
|
||||
Install /bin/sh applet as soft-link to the busybox binary.
|
||||
|
||||
config INSTALL_SH_APPLET_HARDLINK
|
||||
bool "as hard-link"
|
||||
help
|
||||
Install /bin/sh applet as hard-link to the busybox binary.
|
||||
|
||||
config INSTALL_SH_APPLET_SCRIPT_WRAPPER
|
||||
bool "as script wrapper"
|
||||
help
|
||||
Install /bin/sh applet as script wrapper that call the busybox binary.
|
||||
|
||||
endchoice
|
||||
|
||||
config PREFIX
|
||||
string "BusyBox installation prefix"
|
||||
default "./_install"
|
||||
help
|
||||
Define your directory to install BusyBox files/subdirs in.
|
||||
|
||||
endmenu
|
||||
|
||||
source libbb/Config.in
|
||||
|
||||
endmenu
|
||||
|
||||
comment "Applets"
|
||||
|
||||
source archival/Config.in
|
||||
source coreutils/Config.in
|
||||
source console-tools/Config.in
|
||||
source debianutils/Config.in
|
||||
source editors/Config.in
|
||||
source findutils/Config.in
|
||||
source init/Config.in
|
||||
source loginutils/Config.in
|
||||
source e2fsprogs/Config.in
|
||||
source modutils/Config.in
|
||||
source util-linux/Config.in
|
||||
source miscutils/Config.in
|
||||
source networking/Config.in
|
||||
source procps/Config.in
|
||||
source shell/Config.in
|
||||
source sysklogd/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
source ipsvd/Config.in
|
||||
@@ -1,125 +0,0 @@
|
||||
Building:
|
||||
=========
|
||||
|
||||
The BusyBox build process is similar to the Linux kernel build:
|
||||
|
||||
make menuconfig # This creates a file called ".config"
|
||||
make # This creates the "busybox" executable
|
||||
make install # or make CONFIG_PREFIX=/path/from/root install
|
||||
|
||||
The full list of configuration and install options is available by typing:
|
||||
|
||||
make help
|
||||
|
||||
Quick Start:
|
||||
============
|
||||
|
||||
The easy way to try out BusyBox for the first time, without having to install
|
||||
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,
|
||||
optional packaging choices, and a few special-purpose features requiring
|
||||
extra configuration to use.)
|
||||
|
||||
make defconfig
|
||||
make
|
||||
PATH= ./busybox ash
|
||||
|
||||
Standalone shell mode causes busybox's built-in command shell to run
|
||||
any built-in busybox applets directly, without looking for external
|
||||
programs by that name. Supplying an empty command path (as above) means
|
||||
the only commands busybox can find are the built-in ones.
|
||||
|
||||
Note that the standalone shell requires CONFIG_BUSYBOX_EXEC_PATH
|
||||
to be set appropriately, depending on whether or not /proc/self/exe is
|
||||
available or not. If you do not have /proc, then point that config option
|
||||
to the location of your busybox binary, usually /bin/busybox.
|
||||
|
||||
Configuring Busybox:
|
||||
====================
|
||||
|
||||
Busybox is optimized for size, but enabling the full set of functionality
|
||||
still results in a fairly large executable -- more than 1 megabyte when
|
||||
statically linked. To save space, busybox can be configured with only the
|
||||
set of applets needed for each environment. The minimal configuration, with
|
||||
all applets disabled, produces a 4k executable. (It's useless, but very small.)
|
||||
|
||||
The manual configurator "make menuconfig" modifies the existing configuration.
|
||||
(For systems without ncurses, try "make config" instead.) The two most
|
||||
interesting starting configurations are "make allnoconfig" (to start with
|
||||
everything disabled and add just what you need), and "make defconfig" (to
|
||||
start with everything enabled and remove what you don't need). If menuconfig
|
||||
is run without an existing configuration, make defconfig will run first to
|
||||
create a known starting point.
|
||||
|
||||
Other starting configurations (mostly used for testing purposes) include
|
||||
"make allbareconfig" (enables all applets but disables all optional features),
|
||||
"make allyesconfig" (enables absolutely everything including debug features),
|
||||
and "make randconfig" (produce a random configuration).
|
||||
|
||||
Configuring BusyBox produces a file ".config", which can be saved for future
|
||||
use. Run "make oldconfig" to bring a .config file from an older version of
|
||||
busybox up to date.
|
||||
|
||||
Installing Busybox:
|
||||
===================
|
||||
|
||||
Busybox is a single executable that can behave like many different commands,
|
||||
and BusyBox uses the name it was invoked under to determine the desired
|
||||
behavior. (Try "mv busybox ls" and then "./ls -l".)
|
||||
|
||||
Installing busybox consists of creating symlinks (or hardlinks) to the busybox
|
||||
binary for each applet enabled in busybox, and making sure these symlinks are
|
||||
in the shell's command $PATH. Running "make install" creates these symlinks,
|
||||
or "make install-hardlinks" creates hardlinks instead (useful on systems with
|
||||
a limited number of inodes). This install process uses the file
|
||||
"busybox.links" (created by make), which contains the list of enabled applets
|
||||
and the path at which to install them.
|
||||
|
||||
Installing links to busybox is not always necessary. The special applet name
|
||||
"busybox" (or with any optional suffix, such as "busybox-static") uses the
|
||||
first argument to determine which applet to behave as, for example
|
||||
"./busybox cat LICENSE". (Running the busybox applet with no arguments gives
|
||||
a list of all enabled applets.) The standalone shell can also call busybox
|
||||
applets without links to busybox under other names in the filesystem. You can
|
||||
also configure a standaone install capability into the busybox base applet,
|
||||
and then install such links at runtime with one of "busybox --install" (for
|
||||
hardlinks) or "busybox --install -s" (for symlinks).
|
||||
|
||||
If you enabled the busybox shared library feature (libbusybox.so) and want
|
||||
to run tests without installing, set your LD_LIBRARY_PATH accordingly when
|
||||
running the executable:
|
||||
|
||||
LD_LIBRARY_PATH=`pwd` ./busybox
|
||||
|
||||
Building out-of-tree:
|
||||
=====================
|
||||
|
||||
By default, the BusyBox build puts its temporary files in the source tree.
|
||||
Building from a read-only source tree, or building multiple configurations from
|
||||
the same source directory, requires the ability to put the temporary files
|
||||
somewhere else.
|
||||
|
||||
To build out of tree, cd to an empty directory and configure busybox from there:
|
||||
|
||||
make -f /path/to/source/Makefile defconfig
|
||||
make
|
||||
make install
|
||||
|
||||
Alternately, use the O=$BUILDPATH option (with an absolute path) during the
|
||||
configuration step, as in:
|
||||
|
||||
make O=/some/empty/directory allyesconfig
|
||||
cd /some/empty/directory
|
||||
make
|
||||
make CONFIG_PREFIX=. install
|
||||
|
||||
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 or as the file
|
||||
docs/busybox.net/FAQ.html in this tarball.
|
||||
-160
@@ -1,160 +0,0 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
busybox.links: $(srctree)/applets/busybox.mkll $(objtree)/include/autoconf.h $(srctree)/include/applets.h
|
||||
$(Q)-$(SHELL) $^ >$@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
INSTALL_OPTS:= --symlinks
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_HARDLINKS),y)
|
||||
INSTALL_OPTS:= --hardlinks
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS),y)
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_SYMLINK),y)
|
||||
INSTALL_OPTS:= --sw-sh-sym
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_HARDLINK),y)
|
||||
INSTALL_OPTS:= --sw-sh-hard
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
|
||||
@echo
|
||||
@echo
|
||||
@echo --------------------------------------------------
|
||||
@echo You will probably need to make your busybox binary
|
||||
@echo setuid root to ensure all configured applets will
|
||||
@echo work properly.
|
||||
@echo --------------------------------------------------
|
||||
@echo
|
||||
endif
|
||||
|
||||
uninstall: busybox.links
|
||||
rm -f $(CONFIG_PREFIX)/bin/busybox
|
||||
for i in `cat busybox.links` ; do rm -f $(CONFIG_PREFIX)$$i; done
|
||||
ifneq ($(strip $(DO_INSTALL_LIBS)),n)
|
||||
for i in $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS); do \
|
||||
rm -f $(CONFIG_PREFIX)$$i; \
|
||||
done
|
||||
endif
|
||||
|
||||
check test: busybox busybox.links
|
||||
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 -a busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type d \
|
||||
-name .svn \
|
||||
-print \
|
||||
-exec rm -r -f {} \; ; \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
tar -czf busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION).tar.gz \
|
||||
busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ ; }
|
||||
|
||||
.PHONY: checkhelp
|
||||
checkhelp:
|
||||
$(Q)$(srctree)/scripts/checkhelp.awk \
|
||||
$(patsubst %,$(srctree)/%,$(wildcard $(patsubst %,%/Config.in,$(busybox-dirs) ./)))
|
||||
|
||||
.PHONY: sizes
|
||||
sizes: busybox_unstripped
|
||||
$(NM) --size-sort $(<)
|
||||
|
||||
.PHONY: bloatcheck
|
||||
bloatcheck: busybox_old busybox_unstripped
|
||||
@$(srctree)/scripts/bloat-o-meter busybox_old busybox_unstripped
|
||||
@$(CROSS_COMPILE)size busybox_old busybox_unstripped
|
||||
|
||||
.PHONY: baseline
|
||||
baseline: busybox_unstripped
|
||||
@mv busybox_unstripped busybox_old
|
||||
|
||||
.PHONY: objsizes
|
||||
objsizes: busybox_unstripped
|
||||
$(srctree)/scripts/objsizes
|
||||
|
||||
.PHONY: stksizes
|
||||
stksizes: busybox_unstripped
|
||||
$(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 ' [tr] '
|
||||
|
||||
# Documentation Targets
|
||||
.PHONY: doc
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
|
||||
$(srctree)/include/usage.h \
|
||||
$(srctree)/docs/busybox_footer.pod \
|
||||
$(srctree)/docs/autodocifier.pl
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-( cat $(srctree)/docs/busybox_header.pod ; \
|
||||
$(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \
|
||||
cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2text $< > $@
|
||||
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-rm -f docs/BusyBox.html
|
||||
$(Q)-cp docs/busybox.net/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
$(Q)-mkdir -p docs/busybox.net
|
||||
$(Q)-pod2html --noindex $< > \
|
||||
docs/busybox.net/BusyBox.html
|
||||
$(Q)-rm -f pod2htm*
|
||||
|
||||
# documentation, cross-reference
|
||||
# Modern distributions already ship synopsis packages (e.g. debian)
|
||||
# If you have an old distribution go to http://synopsis.fresco.org/
|
||||
syn_tgt = $(wildcard $(patsubst %,%/*.c,$(busybox-alldirs)))
|
||||
syn = $(patsubst %.c, %.syn, $(syn_tgt))
|
||||
|
||||
comma:= ,
|
||||
brace_open:= (
|
||||
brace_close:= )
|
||||
|
||||
SYN_CPPFLAGS := $(strip $(CPPFLAGS) $(EXTRA_CPPFLAGS))
|
||||
SYN_CPPFLAGS := $(subst $(brace_open),\$(brace_open),$(SYN_CPPFLAGS))
|
||||
SYN_CPPFLAGS := $(subst $(brace_close),\$(brace_close),$(SYN_CPPFLAGS))
|
||||
#SYN_CPPFLAGS := $(subst ",\",$(SYN_CPPFLAGS))
|
||||
#")
|
||||
#SYN_CPPFLAGS := [$(patsubst %,'%'$(comma),$(SYN_CPPFLAGS))'']
|
||||
|
||||
%.syn: %.c
|
||||
synopsis -p C -l Comments.SSDFilter,Comments.Previous -Wp,preprocess=True,cppflags="'$(SYN_CPPFLAGS)'" -o $@ $<
|
||||
|
||||
.PHONY: html
|
||||
html: $(syn)
|
||||
synopsis -f HTML -Wf,title="'BusyBox Documentation'" -o $@ $^
|
||||
|
||||
-include $(srctree)/Makefile.local
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
export BB_VER
|
||||
SKIP_STRIP = n
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
CPPFLAGS += $(call cc-option,-std=gnu99,)
|
||||
|
||||
CPPFLAGS += \
|
||||
-Iinclude -Ilibbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
|
||||
-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
|
||||
|
||||
# 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,)
|
||||
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)
|
||||
|
||||
# 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,)
|
||||
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
|
||||
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
#CFLAGS+=$(call cc-option,-Wconversion,)
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||
# on i386: 14% smaller libbusybox.so
|
||||
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
|
||||
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)
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
|
||||
LDLIBS += m crypt
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
LDLIBS += pam pam_misc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
LDLIBS += selinux sepol
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
LDLIBS += efence
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DMALLOC),y)
|
||||
LDLIBS += dmalloc
|
||||
endif
|
||||
|
||||
#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!)
|
||||
FLTFLAGS += -s 20000
|
||||
@@ -1,44 +0,0 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
help:
|
||||
@echo 'Cleaning:'
|
||||
@echo ' clean - delete temporary files created by build'
|
||||
@echo ' distclean - delete all non-source files (including .config)'
|
||||
@echo
|
||||
@echo 'Build:'
|
||||
@echo ' all - Executable and documentation'
|
||||
@echo ' busybox - the swiss-army executable'
|
||||
@echo ' doc - docs/BusyBox.{txt,html,1}'
|
||||
@echo ' html - create html-based cross-reference'
|
||||
@echo
|
||||
@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'
|
||||
@echo ' oldconfig - resolve any unresolved symbols in .config'
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into $(CONFIG_PREFIX)'
|
||||
@echo ' uninstall'
|
||||
@echo
|
||||
@echo 'Development:'
|
||||
@echo ' baseline - create busybox_old for bloatcheck.'
|
||||
@echo ' bloatcheck - show size difference between old and new versions'
|
||||
@echo ' check - run the test suite for all applets'
|
||||
@echo ' checkhelp - check for missing help-entries in Config.in'
|
||||
@echo ' randconfig - generate a random configuration'
|
||||
@echo ' release - create a distribution tarball'
|
||||
@echo ' sizes - show size of all enabled busybox symbols'
|
||||
@echo ' objsizes - show size of each .o object built'
|
||||
@echo ' bigdata - show data objects, biggest first'
|
||||
@echo ' stksizes - show stack users, biggest first'
|
||||
@echo
|
||||
@@ -1,320 +0,0 @@
|
||||
Busybox TODO
|
||||
|
||||
Stuff that needs to be done. This is organized by who plans to get around to
|
||||
doing it eventually, but that doesn't mean they "own" the item. If you want to
|
||||
do one of these bounce an email off the person it's listed under to see if they
|
||||
have any suggestions how they plan to go about it, and to minimize conflicts
|
||||
between your work and theirs. But otherwise, all of these are fair game.
|
||||
|
||||
Rob Landley <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 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. 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
|
||||
figure out which of our apps are compliant, and what we're missing that
|
||||
we might actually care about.
|
||||
|
||||
Even better would be some kind of automated compliance test harness that
|
||||
exercises each command line option and the various corner cases.
|
||||
Internationalization
|
||||
How much internationalization should we do?
|
||||
|
||||
The low hanging fruit is UTF-8 character set support. We should do this.
|
||||
(Vodz pointed out the shell's cmdedit as needing work here. What else?)
|
||||
|
||||
We also have lots of hardwired english text messages. Consolidating this
|
||||
into some kind of message table not only makes translation easier, but
|
||||
also allows us to consolidate redundant (or close) strings.
|
||||
|
||||
We probably don't want to be bloated with locale support. (Not unless we
|
||||
can cleanly export it from our underlying C library without having to
|
||||
concern ourselves with it directly. Perhaps a few specific things like a
|
||||
config option for "date" are low hanging fruit here?)
|
||||
|
||||
What level should things happen at? How much do we care about
|
||||
internationalizing the text console when X11 and xterms are so much better
|
||||
at it? (There's some infrastructure here we don't implement: The
|
||||
"unicode_start" and "unicode_stop" shell scripts need "vt-is-UTF8" and a
|
||||
--unicode option to loadkeys. That implies a real loadkeys/dumpkeys
|
||||
implementation to replace loadkmap/dumpkmap. Plus messing with console font
|
||||
loading. Is it worth it, or do we just say "use X"?)
|
||||
|
||||
Individual compilation of applets.
|
||||
It would be nice if busybox had the option to compile to individual applets,
|
||||
for people who want an alternate implementation less bloated than the gnu
|
||||
utils (or simply with less political baggage), but without it being one big
|
||||
executable.
|
||||
|
||||
Turning libbb into a real dll is another possibility, especially if libbb
|
||||
could export some of the other library interfaces we've already more or less
|
||||
got the code for (like zlib).
|
||||
buildroot - Make a "dogfood" option
|
||||
Busybox 1.1 will be capable of replacing most gnu packages for real world
|
||||
use, such as developing software or in a live CD. It needs wider testing.
|
||||
|
||||
Busybox should now be able to replace bzip2, coreutils, e2fsprogs, file,
|
||||
findutils, gawk, grep, inetutils, less, modutils, net-tools, patch, procps,
|
||||
sed, shadow, sysklogd, sysvinit, tar, util-linux, and vim. The resulting
|
||||
system should be self-hosting (I.E. able to rebuild itself from source
|
||||
code). This means it would need (at least) binutils, gcc, and make, or
|
||||
equivalents.
|
||||
|
||||
It would be a good "eating our own dogfood" test if buildroot had the option
|
||||
of using a "make allyesconfig" busybox instead of the all of the above
|
||||
packages. Anything that's wrong with the resulting system, we can fix. (It
|
||||
would be nice to be able to upgrade busybox to be able to replace bash and
|
||||
diffutils as well, but we're not there yet.)
|
||||
|
||||
One example of an existing system that does this already is Firmware Linux:
|
||||
http://www.landley.net/code/firmware
|
||||
initramfs
|
||||
Busybox should have a sample initramfs build script. This depends on
|
||||
bbsh, mdev, and switch_root.
|
||||
mkdep
|
||||
Write a mkdep that doesn't segfault if there's a directory it doesn't
|
||||
have permission to read, isn't based on manually editing the output of
|
||||
lexx and yacc, doesn't make such a mess under include/config, etc.
|
||||
Group globals into unions of structures.
|
||||
Go through and turn all the global and static variables into structures,
|
||||
and have all those structures be in a big union shared between processes,
|
||||
so busybox uses less bss. (This is a big win on nommu machines.) See
|
||||
sed.c and mdev.c for examples.
|
||||
Go through bugs.busybox.net and close out all of that somehow.
|
||||
This one's open to everybody, but I'll wind up doing it...
|
||||
|
||||
|
||||
Bernhard 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.
|
||||
Use bb_common_bufsiz1 throughout applets!
|
||||
|
||||
As yet unclaimed:
|
||||
|
||||
----
|
||||
find
|
||||
doesn't understand (), lots of susv3 stuff.
|
||||
----
|
||||
diff
|
||||
Make sure we handle empty files properly:
|
||||
From the patch man page:
|
||||
|
||||
you can remove a file by sending out a context diff that compares
|
||||
the file to be deleted with an empty file dated the Epoch. The
|
||||
file will be removed unless patch is conforming to POSIX and the
|
||||
-E or --remove-empty-files option is not given.
|
||||
---
|
||||
patch
|
||||
Should have simple fuzz factor support to apply patches at an offset which
|
||||
shouldn't take up too much space.
|
||||
|
||||
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?
|
||||
---
|
||||
stty / catv
|
||||
stty's visible() function and catv's guts are identical. Merge them into
|
||||
an appropriate libbb function.
|
||||
---
|
||||
struct suffix_mult
|
||||
Several duplicate users of: grep -r "1024\*1024" * -B2 -A1
|
||||
Merge to a single size_suffixes[] in libbb.
|
||||
Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd
|
||||
---
|
||||
tail
|
||||
./busybox tail -f foo.c~ TODO
|
||||
should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
|
||||
fmt+ if another (not the current) file did change
|
||||
|
||||
Architectural issues:
|
||||
|
||||
bb_close() with fsync()
|
||||
We should have a bb_close() in place of normal close, with a CONFIG_ option
|
||||
to not just check the return value of close() for an error, but fsync().
|
||||
Close can't reliably report anything useful because if write() accepted the
|
||||
data then it either went out to the network or it's in cache or a pipe
|
||||
buffer. Either way, there's no guarantee it'll make it to its final
|
||||
destination before close() gets called, so there's no guarantee that any
|
||||
error will be reported.
|
||||
|
||||
You need to call fsync() if you care about errors that occur after write(),
|
||||
but that can have a big performance impact. So make it a config option.
|
||||
---
|
||||
Unify archivers
|
||||
Lots of archivers have the same general infrastructure. The directory
|
||||
traversal code should be factored out, and the guts of each archiver could
|
||||
be some setup code and a series of callbacks for "add this file",
|
||||
"add this directory", "add this symlink" and so on.
|
||||
|
||||
This could clean up tar and zip, and make it cheaper to add cpio and ar
|
||||
write support, and possibly even cheaply add things like mkisofs or
|
||||
mksquashfs someday, if they become relevant.
|
||||
---
|
||||
Text buffer support.
|
||||
Several existing applets (sort, vi, less...) read
|
||||
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
|
||||
allocation on the stack or the heap. Unfortunately, we're not using it much.
|
||||
We need to audit our memory allocations and turn a lot of malloc/free calls
|
||||
into RESERVE_CONFIG_BUFFER/RELEASE_CONFIG_BUFFER.
|
||||
For a start, see e.g. make EXTRA_CFLAGS=-Wlarger-than-64
|
||||
|
||||
And while we're at it, many of the CONFIG_FEATURE_CLEAN_UP #ifdefs will be
|
||||
optimized out by the compiler in the stack allocation case (since there's no
|
||||
free for an alloca()), and this means that various cleanup loops that just
|
||||
call free might also be optimized out by the compiler if written right, so
|
||||
we can yank those #ifdefs too, and generally clean up the code.
|
||||
---
|
||||
Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS
|
||||
|
||||
In busybox 1.0 and earlier, configuration was done by CONFIG_SYMBOLS
|
||||
that were either defined or undefined to indicate whether the symbol was
|
||||
selected in the .config file. They were used with #ifdefs, ala:
|
||||
|
||||
#ifdef CONFIG_SYMBOL
|
||||
if (other_test) {
|
||||
do_code();
|
||||
}
|
||||
#endif
|
||||
|
||||
In 1.1, we have new ENABLE_SYMBOLS which are always defined (as 0 or 1),
|
||||
meaning you can still use them for preprocessor tests by replacing
|
||||
"#ifdef CONFIG_SYMBOL" with "#if ENABLE_SYMBOL". But more importantly, we
|
||||
can use them as a true or false test in normal C code:
|
||||
|
||||
if (ENABLE_SYMBOL && other_test) {
|
||||
do_code();
|
||||
}
|
||||
|
||||
(Optimizing away if() statements that resolve to a constant value
|
||||
is known as "dead code elimination", an optimization so old and simple that
|
||||
Turbo Pascal for DOS did it twenty years ago. Even modern mini-compilers
|
||||
like the Tiny C Compiler (tcc) and the Small Device C Compiler (SDCC)
|
||||
perform dead code elimination.)
|
||||
|
||||
Right now, busybox.h is #including both "config.h" (defining the
|
||||
CONFIG_SYMBOLS) and "bb_config.h" (defining the ENABLE_SYMBOLS). At some
|
||||
point in the future, it would be nice to wean ourselves off of the
|
||||
CONFIG versions. (Among other things, some defective build environments
|
||||
leak the Linux kernel's CONFIG_SYMBOLS into the system's standard #include
|
||||
files. We've experienced collisions before.)
|
||||
---
|
||||
FEATURE_CLEAN_UP
|
||||
This is more an unresolved issue than a to-do item. More thought is needed.
|
||||
|
||||
Normally we rely on exit() to free memory, close files, and unmap segments
|
||||
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.
|
||||
|
||||
The idea was raised that we could simulate fork/exit with setjmp/longjmp
|
||||
for _really_ brainless embedded systems, or speed up the standalone shell
|
||||
by not forking. Doing so would require a reliable FEATURE_CLEAN_UP.
|
||||
Unfortunately, this isn't as easy as it sounds.
|
||||
|
||||
The problem is, lots of things exit(), sometimes unexpectedly (xmalloc())
|
||||
and sometimes reliably (bb_perror_msg_and_die() or show_usage()). This
|
||||
jumps out of the normal flow control and bypasses any cleanup code we
|
||||
put at the end of our applets.
|
||||
|
||||
It's possible to add hooks to libbb functions like xmalloc() and xopen()
|
||||
to add their entries to a linked list, which could be traversed and
|
||||
freed/closed automatically. (This would need to be able to free just the
|
||||
entries after a checkpoint to be usable for a forkless standalone shell.
|
||||
You don't want to free the shell's own resources.)
|
||||
|
||||
Right now, FEATURE_CLEAN_UP is more or less a debugging aid, to make things
|
||||
like valgrind happy. It's also documentation of _what_ we're trusting
|
||||
exit() to clean up for us. But new infrastructure to auto-free stuff would
|
||||
render the existing FEATURE_CLEAN_UP code redundant.
|
||||
|
||||
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);
|
||||
Unfortunately, that needs linux/watchdog.h and that contains unfiltered
|
||||
kernel types on some distros, which breaks the build.
|
||||
---
|
||||
use bb_error_msg where appropriate: See
|
||||
egrep "(printf.*\([[:space:]]*(stderr|2)|[^_]write.*\([[:space:]]*(stderr|2))"
|
||||
---
|
||||
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, msh.c
|
||||
---
|
||||
|
||||
|
||||
Code cleanup:
|
||||
|
||||
Replace deprecated functions.
|
||||
|
||||
bzero() -> memset()
|
||||
---
|
||||
sigblock(), siggetmask(), sigsetmask(), sigmask() -> sigprocmask et al
|
||||
---
|
||||
vdprintf() -> similar sized functionality
|
||||
---
|
||||
@@ -1,710 +0,0 @@
|
||||
# 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.6.0.svn
|
||||
# Wed Apr 11 01:29:04 2007
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
#
|
||||
# Busybox Settings
|
||||
#
|
||||
|
||||
#
|
||||
# General Configuration
|
||||
#
|
||||
# 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
|
||||
CONFIG_FEATURE_VERBOSE_USAGE=y
|
||||
CONFIG_FEATURE_COMPRESS_USAGE=y
|
||||
CONFIG_FEATURE_INSTALLER=y
|
||||
# CONFIG_LOCALE_SUPPORT is not set
|
||||
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_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"
|
||||
|
||||
#
|
||||
# Build Options
|
||||
#
|
||||
# CONFIG_STATIC is not set
|
||||
# CONFIG_BUILD_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
# CONFIG_BUILD_AT_ONCE is not set
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
#
|
||||
# CONFIG_DEBUG 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
|
||||
#
|
||||
# CONFIG_INSTALL_NO_USR is not set
|
||||
CONFIG_INSTALL_APPLET_SYMLINKS=y
|
||||
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
|
||||
# CONFIG_INSTALL_APPLET_DONT is not set
|
||||
CONFIG_PREFIX="./_install"
|
||||
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SIZE_VS_SPEED=2
|
||||
CONFIG_FEATURE_EDITING=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 is not set
|
||||
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
|
||||
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
|
||||
|
||||
#
|
||||
# Applets
|
||||
#
|
||||
|
||||
#
|
||||
# Archival Utilities
|
||||
#
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_CPIO=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_RPM2CPIO=y
|
||||
# CONFIG_RPM is not set
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=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_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=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
|
||||
#
|
||||
CONFIG_BASENAME=y
|
||||
CONFIG_CAL=y
|
||||
CONFIG_CAT=y
|
||||
CONFIG_CATV=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_FEATURE_DATE_ISOFMT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=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
|
||||
CONFIG_DU=y
|
||||
CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
|
||||
CONFIG_ECHO=y
|
||||
CONFIG_FEATURE_FANCY_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
|
||||
CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_FEATURE_FANCY_HEAD=y
|
||||
CONFIG_HOSTID=y
|
||||
CONFIG_ID=y
|
||||
CONFIG_INSTALL=y
|
||||
CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y
|
||||
CONFIG_LENGTH=y
|
||||
CONFIG_LN=y
|
||||
CONFIG_LOGNAME=y
|
||||
CONFIG_LS=y
|
||||
CONFIG_FEATURE_LS_FILETYPES=y
|
||||
CONFIG_FEATURE_LS_FOLLOWLINKS=y
|
||||
CONFIG_FEATURE_LS_RECURSIVE=y
|
||||
CONFIG_FEATURE_LS_SORTFILES=y
|
||||
CONFIG_FEATURE_LS_TIMESTAMPS=y
|
||||
CONFIG_FEATURE_LS_USERNAME=y
|
||||
CONFIG_FEATURE_LS_COLOR=y
|
||||
CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
|
||||
CONFIG_MD5SUM=y
|
||||
CONFIG_MKDIR=y
|
||||
CONFIG_FEATURE_MKDIR_LONG_OPTIONS=y
|
||||
CONFIG_MKFIFO=y
|
||||
CONFIG_MKNOD=y
|
||||
CONFIG_MV=y
|
||||
CONFIG_FEATURE_MV_LONG_OPTIONS=y
|
||||
CONFIG_NICE=y
|
||||
CONFIG_NOHUP=y
|
||||
CONFIG_OD=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PRINTF=y
|
||||
CONFIG_PWD=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RM=y
|
||||
CONFIG_RMDIR=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_SORT=y
|
||||
CONFIG_FEATURE_SORT_BIG=y
|
||||
CONFIG_SPLIT=y
|
||||
CONFIG_FEATURE_SPLIT_FANCY=y
|
||||
CONFIG_STAT=y
|
||||
CONFIG_FEATURE_STAT_FORMAT=y
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
CONFIG_TEE=y
|
||||
CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=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
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_YES=y
|
||||
|
||||
#
|
||||
# Common options for cp and mv
|
||||
#
|
||||
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
|
||||
|
||||
#
|
||||
# Common options for ls, more and telnet
|
||||
#
|
||||
CONFIG_FEATURE_AUTOWIDTH=y
|
||||
|
||||
#
|
||||
# Common options for df, du, ls
|
||||
#
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
#
|
||||
# Console Utilities
|
||||
#
|
||||
CONFIG_CHVT=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_DEALLOCVT=y
|
||||
CONFIG_DUMPKMAP=y
|
||||
CONFIG_LOADFONT=y
|
||||
CONFIG_LOADKMAP=y
|
||||
CONFIG_OPENVT=y
|
||||
CONFIG_RESET=y
|
||||
CONFIG_RESIZE=y
|
||||
CONFIG_FEATURE_RESIZE_PRINT=y
|
||||
CONFIG_SETCONSOLE=y
|
||||
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
|
||||
CONFIG_SETKEYCODES=y
|
||||
CONFIG_SETLOGCONS=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 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_MATH=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_COLON=y
|
||||
CONFIG_FEATURE_VI_YANKMARK=y
|
||||
CONFIG_FEATURE_VI_SEARCH=y
|
||||
CONFIG_FEATURE_VI_USE_SIGNALS=y
|
||||
CONFIG_FEATURE_VI_DOT_CMD=y
|
||||
CONFIG_FEATURE_VI_READONLY=y
|
||||
CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
# Finding Utilities
|
||||
#
|
||||
CONFIG_FIND=y
|
||||
CONFIG_FEATURE_FIND_PRINT0=y
|
||||
CONFIG_FEATURE_FIND_MTIME=y
|
||||
CONFIG_FEATURE_FIND_MMIN=y
|
||||
CONFIG_FEATURE_FIND_PERM=y
|
||||
CONFIG_FEATURE_FIND_TYPE=y
|
||||
CONFIG_FEATURE_FIND_XDEV=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
CONFIG_FEATURE_FIND_USER=y
|
||||
CONFIG_FEATURE_FIND_GROUP=y
|
||||
CONFIG_FEATURE_FIND_NOT=y
|
||||
CONFIG_FEATURE_FIND_DEPTH=y
|
||||
CONFIG_FEATURE_FIND_PAREN=y
|
||||
CONFIG_FEATURE_FIND_SIZE=y
|
||||
CONFIG_FEATURE_FIND_PRUNE=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_CONTEXT=y
|
||||
CONFIG_XARGS=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
|
||||
#
|
||||
# Init Utilities
|
||||
#
|
||||
# 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_MESG=y
|
||||
|
||||
#
|
||||
# Login/Password Management Utilities
|
||||
#
|
||||
CONFIG_FEATURE_SHADOWPASSWDS=y
|
||||
CONFIG_USE_BB_SHADOW=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
CONFIG_FEATURE_WTMP=y
|
||||
CONFIG_LOGIN=y
|
||||
CONFIG_LOGIN_SCRIPTS=y
|
||||
CONFIG_FEATURE_SECURETTY=y
|
||||
CONFIG_PASSWD=y
|
||||
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
|
||||
CONFIG_SU=y
|
||||
CONFIG_FEATURE_SU_SYSLOG=y
|
||||
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
|
||||
CONFIG_SULOGIN=y
|
||||
CONFIG_VLOCK=y
|
||||
|
||||
#
|
||||
# Linux Ext2 FS Progs
|
||||
#
|
||||
CONFIG_CHATTR=y
|
||||
CONFIG_FSCK=y
|
||||
CONFIG_LSATTR=y
|
||||
|
||||
#
|
||||
# Linux Module Utilities
|
||||
#
|
||||
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_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_DMESG=y
|
||||
CONFIG_FEATURE_DMESG_PRETTY=y
|
||||
CONFIG_FBSET=y
|
||||
CONFIG_FEATURE_FBSET_FANCY=y
|
||||
CONFIG_FEATURE_FBSET_READMODE=y
|
||||
CONFIG_FDFLUSH=y
|
||||
CONFIG_FDFORMAT=y
|
||||
CONFIG_FDISK=y
|
||||
CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
|
||||
CONFIG_FEATURE_FDISK_WRITABLE=y
|
||||
CONFIG_FEATURE_AIX_LABEL=y
|
||||
CONFIG_FEATURE_SGI_LABEL=y
|
||||
CONFIG_FEATURE_SUN_LABEL=y
|
||||
CONFIG_FEATURE_OSF_LABEL=y
|
||||
CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
|
||||
#
|
||||
# Minix filesystem support
|
||||
#
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_HEXDUMP=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_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_MOUNT=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_READPROFILE=y
|
||||
CONFIG_SETARCH=y
|
||||
CONFIG_SWAPONOFF=y
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
CONFIG_UMOUNT=y
|
||||
CONFIG_FEATURE_UMOUNT_ALL=y
|
||||
|
||||
#
|
||||
# Common options for mount/umount
|
||||
#
|
||||
CONFIG_FEATURE_MOUNT_LOOP=y
|
||||
# CONFIG_FEATURE_MTAB_SUPPORT is not set
|
||||
|
||||
#
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
CONFIG_ADJTIMEX=y
|
||||
# CONFIG_BBCONFIG is not set
|
||||
CONFIG_CHRT=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_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_EJECT=y
|
||||
CONFIG_LAST=y
|
||||
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_HDPARM=y
|
||||
CONFIG_FEATURE_HDPARM_GET_IDENTITY=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
|
||||
CONFIG_FEATURE_MAKEDEVS_TABLE=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_MT=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
CONFIG_READAHEAD=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
CONFIG_RX=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SETSID=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TIME=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
|
||||
CONFIG_ARP=y
|
||||
CONFIG_ARPING=y
|
||||
CONFIG_DNSD=y
|
||||
CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
CONFIG_HOSTNAME=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_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 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
|
||||
CONFIG_FEATURE_IP_ROUTE=y
|
||||
CONFIG_FEATURE_IP_TUNNEL=y
|
||||
CONFIG_FEATURE_IP_RULE=y
|
||||
CONFIG_FEATURE_IP_SHORT_FORMS=y
|
||||
CONFIG_IPADDR=y
|
||||
CONFIG_IPLINK=y
|
||||
CONFIG_IPROUTE=y
|
||||
CONFIG_IPTUNNEL=y
|
||||
CONFIG_IPRULE=y
|
||||
CONFIG_IPCALC=y
|
||||
CONFIG_FEATURE_IPCALC_FANCY=y
|
||||
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
|
||||
CONFIG_NAMEIF=y
|
||||
CONFIG_NC=y
|
||||
CONFIG_NC_SERVER=y
|
||||
CONFIG_NC_EXTRA=y
|
||||
CONFIG_NETSTAT=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
# CONFIG_TELNETD is not set
|
||||
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
# CONFIG_DEBUG_TFTP is not set
|
||||
CONFIG_TRACEROUTE=y
|
||||
# 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
|
||||
|
||||
#
|
||||
# Process Utilities
|
||||
#
|
||||
CONFIG_FREE=y
|
||||
CONFIG_FUSER=y
|
||||
CONFIG_KILL=y
|
||||
CONFIG_KILLALL=y
|
||||
CONFIG_KILLALL5=y
|
||||
CONFIG_PIDOF=y
|
||||
CONFIG_FEATURE_PIDOF_SINGLE=y
|
||||
CONFIG_FEATURE_PIDOF_OMIT=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_UPTIME=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH 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_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_READ_NCHARS is not set
|
||||
# CONFIG_ASH_READ_TIMEOUT is not set
|
||||
# CONFIG_ASH_ALIAS is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT_64 is not set
|
||||
# CONFIG_ASH_GETOPTS is not set
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
# CONFIG_HUSH is not set
|
||||
# CONFIG_LASH is not set
|
||||
CONFIG_MSH=y
|
||||
|
||||
#
|
||||
# Bourne Shell Options
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
#
|
||||
CONFIG_SYSLOGD=y
|
||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||
CONFIG_FEATURE_REMOTE_LOG=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
|
||||
@@ -1,25 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
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)
|
||||
@@ -1,29 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Stub for linking busybox binary against libbusybox.
|
||||
*
|
||||
* Copyright (C) 2007 Denis Vlasenko
|
||||
*
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#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, char **argv)
|
||||
{
|
||||
return lbb_main(argc, argv);
|
||||
}
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
/* Minimal wrapper to build an individual busybox applet.
|
||||
*
|
||||
* Copyright 2005 Rob Landley <rob@landley.net
|
||||
*
|
||||
* Licensed under GPL version 2, see file LICENSE in this tarball for details
|
||||
*/
|
||||
|
||||
const char *applet_name;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "usage.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
applet_name = argv[0];
|
||||
|
||||
return APPLET_main(argc,argv);
|
||||
}
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
printf(APPLET_full_usage "\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
prefix=${1}
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
exit 1;
|
||||
fi
|
||||
h=`sort busybox.links | uniq`
|
||||
scriptwrapper="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
"") h="";;
|
||||
*) echo "Unknown install option: $2"; exit 1;;
|
||||
esac
|
||||
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
# get the target dir for the libs
|
||||
# assume it starts with lib
|
||||
libdir=$($CC -print-file-name=libc.so | \
|
||||
sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
|
||||
if test -z "$libdir"; then
|
||||
libdir=/lib
|
||||
fi
|
||||
|
||||
mkdir -p $prefix/$libdir || exit 1
|
||||
for i in $DO_INSTALL_LIBS; do
|
||||
rm -f $prefix/$libdir/$i || exit 1
|
||||
if [ -f $i ]; then
|
||||
cp -a $i $prefix/$libdir/ || exit 1
|
||||
chmod 0644 $prefix/$libdir/$i || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
||||
sub_shell_it=`
|
||||
cd "$prefix"
|
||||
for d in usr/sbin usr/bin sbin bin; do
|
||||
pd=$PWD
|
||||
if [ -d "$d" ]; then
|
||||
cd $d
|
||||
ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
|
||||
fi
|
||||
cd "$pd"
|
||||
done
|
||||
`
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
|
||||
for i in $h; do
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
ln $linkopts busybox $prefix$i || exit 1
|
||||
else
|
||||
rm -f $prefix$i
|
||||
echo "#!/bin/busybox" > $prefix$i
|
||||
chmod +x $prefix/$i
|
||||
fi
|
||||
echo " $prefix$i"
|
||||
else
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
else
|
||||
echo " $prefix$i already exists"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -1,18 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <unistd.h>
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "../include/autoconf.h"
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
write(1, usage_messages, sizeof(usage_messages));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
target="$1"
|
||||
loc="$2"
|
||||
|
||||
test "$target" || exit 1
|
||||
test "$loc" || loc=.
|
||||
test -x "$loc/usage" || exit 1
|
||||
test "$SED" || SED=sed
|
||||
|
||||
sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
exec >"$target"
|
||||
|
||||
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`
|
||||
@@ -1,7 +0,0 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
# -mpreferred-stack-boundary=2 is essential in preventing gcc 4.2.x
|
||||
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
|
||||
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
@@ -1,23 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
libs-y += libunarchive/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
@@ -1,95 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* There is no single standard to adhere to so ar may not portable
|
||||
* between different systems
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
const char *mode = bb_mode_string(file_header->mode);
|
||||
char *mtime;
|
||||
|
||||
mtime = ctime(&file_header->mtime);
|
||||
mtime[16] = ' ';
|
||||
memmove(&mtime[17], &mtime[20], 4);
|
||||
mtime[21] = '\0';
|
||||
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid,
|
||||
(int) file_header->size, &mtime[4], file_header->name);
|
||||
}
|
||||
|
||||
#define AR_CTX_PRINT 0x01
|
||||
#define AR_CTX_LIST 0x02
|
||||
#define AR_CTX_EXTRACT 0x04
|
||||
#define AR_OPT_PRESERVE_DATE 0x08
|
||||
#define AR_OPT_VERBOSE 0x10
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc, 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");
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & AR_CTX_LIST) {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & AR_CTX_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
}
|
||||
if (opt & AR_OPT_CREATE) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "creation");
|
||||
}
|
||||
if (opt & AR_OPT_INSERT) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind++]);
|
||||
}
|
||||
|
||||
xread(archive_handle->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Common code for gunzip-like applets
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
OPT_STDOUT = 0x1,
|
||||
OPT_FORCE = 0x2,
|
||||
/* gunzip and bunzip2 only: */
|
||||
OPT_VERBOSE = 0x4,
|
||||
OPT_DECOMPRESS = 0x8,
|
||||
OPT_TEST = 0x10,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
{
|
||||
int fd = open3_or_warn(filename, flags, mode);
|
||||
if (fd < 0) {
|
||||
return 1;
|
||||
}
|
||||
xmove_fd(fd, to_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbunpack(char **argv,
|
||||
char* (*make_new_name)(char *filename),
|
||||
USE_DESKTOP(long long) int (*unpacker)(void)
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
new_name = NULL;
|
||||
filename = *argv; /* can be NULL - 'streaming' bunzip2 */
|
||||
|
||||
if (filename && LONE_DASH(filename))
|
||||
filename = NULL;
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_simple_perror_msg(filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Special cases: test, stdout */
|
||||
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
||||
if (option_mask32 & OPT_TEST)
|
||||
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
||||
goto err;
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
/* Open dst if we are going to unpack to file */
|
||||
if (filename) {
|
||||
new_name = make_new_name(filename);
|
||||
if (!new_name) {
|
||||
bb_error_msg("%s: unknown suffix - ignored", filename);
|
||||
goto err;
|
||||
}
|
||||
/* 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,
|
||||
stat_buf.st_mode))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
status = unpacker();
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
if (status >= 0) {
|
||||
/* TODO: restore user/group/times here? */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
xunlink(del);
|
||||
|
||||
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
|
||||
/* Extreme bloat for gunzip compat */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
free_name:
|
||||
if (new_name != filename)
|
||||
free(new_name);
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
#if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_generic(char *filename, const char *expected_ext)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension + 1, expected_ext) != 0) {
|
||||
/* Mimic GNU gunzip - "real" bunzip2 tries to */
|
||||
/* unpack file anyway, to file.out */
|
||||
return NULL;
|
||||
}
|
||||
*extension = '\0';
|
||||
return filename;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_BUNZIP2
|
||||
|
||||
static
|
||||
char* make_new_name_bunzip2(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "bz2");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
{
|
||||
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
#if ENABLE_GUNZIP
|
||||
|
||||
static
|
||||
char* make_new_name_gunzip(char *filename)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
|
||||
if (!extension)
|
||||
return NULL;
|
||||
|
||||
extension++;
|
||||
if (strcmp(extension, "tgz" + 1) == 0
|
||||
#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|| strcmp(extension, "Z") == 0
|
||||
#endif
|
||||
) {
|
||||
extension[-1] = '\0';
|
||||
} else if (strcmp(extension, "tgz") == 0) {
|
||||
filename = xstrdup(filename);
|
||||
extension = strrchr(filename, '.');
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(STDIN_FILENO) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(STDIN_FILENO);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
} else {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
/* status is still == -1 */
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_gunzip, unpack_gunzip);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNLZMA
|
||||
|
||||
static
|
||||
char* make_new_name_unlzma(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "lzma");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
{
|
||||
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
/* lzmacat? */
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_unlzma, unpack_unlzma);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_uncompress(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "Z");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
|
||||
bb_error_msg("invalid magic");
|
||||
} else {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Test that concatenated gz files are unpacking correctly.
|
||||
# It also tests that unpacking in general is working right.
|
||||
# Since zip code has many corner cases, run it for a few hours
|
||||
# to get a decent coverage (200000 tests or more).
|
||||
|
||||
gzip="gzip"
|
||||
gunzip="../busybox gunzip"
|
||||
# Or the other way around:
|
||||
#gzip="../busybox gzip"
|
||||
#gunzip="gunzip"
|
||||
|
||||
c=0
|
||||
i=$PID
|
||||
while true; do
|
||||
c=$((c+1))
|
||||
|
||||
# RANDOM is not very random on some shells. Spice it up.
|
||||
# 100003 is prime
|
||||
len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
i=$((i * 1664525 + 1013904223))
|
||||
len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len1 count=1 >z1 2>/dev/null
|
||||
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len2 count=1 >z2 2>/dev/null
|
||||
|
||||
$gzip <z1 >zz.gz
|
||||
$gzip <z2 >>zz.gz
|
||||
$gunzip -c zz.gz >z9 || {
|
||||
echo "Exitcode $?"
|
||||
exit
|
||||
}
|
||||
sum=`cat z1 z2 | md5sum`
|
||||
sum9=`md5sum <z9`
|
||||
test "$sum" == "$sum9" || {
|
||||
echo "md5sums don't match"
|
||||
exit
|
||||
}
|
||||
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum"
|
||||
|
||||
sum=`cat z1 z2 z1 z2 | md5sum`
|
||||
rm z1.gz z2.gz 2>/dev/null
|
||||
$gzip z1
|
||||
$gzip z2
|
||||
cat z1.gz z2.gz z1.gz z2.gz >zz.gz
|
||||
$gunzip -c zz.gz >z9 || {
|
||||
echo "Exitcode $? (2)"
|
||||
exit
|
||||
}
|
||||
sum9=`md5sum <z9`
|
||||
test "$sum" == "$sum9" || {
|
||||
echo "md5sums don't match (1)"
|
||||
exit
|
||||
}
|
||||
|
||||
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum (2)"
|
||||
done
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Leak test for gunzip. Watch top for growing process size.
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
|
||||
cat /dev/urandom \
|
||||
| while true; do read junk; echo "junk $RANDOM $junk"; done \
|
||||
| ../busybox gzip \
|
||||
| ../busybox gunzip -c >/dev/null
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Leak test for gunzip. Watch top for growing process size.
|
||||
# In this case we look for leaks in "concatenated .gz" code -
|
||||
# we feed gunzip with a stream of .gz files.
|
||||
|
||||
i=$PID
|
||||
c=0
|
||||
while true; do
|
||||
c=$((c + 1))
|
||||
echo "Block# $c" >&2
|
||||
# RANDOM is not very random on some shells. Spice it up.
|
||||
i=$((i * 1664525 + 1013904223))
|
||||
# 100003 is prime
|
||||
len=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
cat /dev/urandom \
|
||||
| while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len count=1 2>/dev/null \
|
||||
| gzip >xxx.gz
|
||||
cat xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz
|
||||
done | ../busybox gunzip -c >/dev/null
|
||||
@@ -1,44 +0,0 @@
|
||||
bzip2 applet in busybox is based on lightly-modified source
|
||||
of bzip2 version 1.0.4. bzip2 source is distributed
|
||||
under the following conditions (copied verbatim from LICENSE file)
|
||||
===========================================================
|
||||
|
||||
|
||||
This program, "bzip2", the associated library "libbzip2", and all
|
||||
documentation, are copyright (C) 1996-2006 Julian R Seward. All
|
||||
rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Julian Seward, Cambridge, UK.
|
||||
jseward@bzip.org
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
@@ -1,90 +0,0 @@
|
||||
This file is an abridged version of README from bizp2 1.0.4
|
||||
Build instructions (which are not relevant to busyboxed bzip2)
|
||||
are removed.
|
||||
===========================================================
|
||||
|
||||
|
||||
This is the README for bzip2/libzip2.
|
||||
This version is fully compatible with the previous public releases.
|
||||
|
||||
------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------
|
||||
|
||||
Please read and be aware of the following:
|
||||
|
||||
|
||||
WARNING:
|
||||
|
||||
This program and library (attempts to) compress data by
|
||||
performing several non-trivial transformations on it.
|
||||
Unless you are 100% familiar with *all* the algorithms
|
||||
contained herein, and with the consequences of modifying them,
|
||||
you should NOT meddle with the compression or decompression
|
||||
machinery. Incorrect changes can and very likely *will*
|
||||
lead to disastrous loss of data.
|
||||
|
||||
|
||||
DISCLAIMER:
|
||||
|
||||
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
|
||||
USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
|
||||
|
||||
Every compression of a file implies an assumption that the
|
||||
compressed file can be decompressed to reproduce the original.
|
||||
Great efforts in design, coding and testing have been made to
|
||||
ensure that this program works correctly. However, the complexity
|
||||
of the algorithms, and, in particular, the presence of various
|
||||
special cases in the code which occur with very low but non-zero
|
||||
probability make it impossible to rule out the possibility of bugs
|
||||
remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
|
||||
PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
|
||||
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
|
||||
|
||||
That is not to say this program is inherently unreliable.
|
||||
Indeed, I very much hope the opposite is true. bzip2/libbzip2
|
||||
has been carefully constructed and extensively tested.
|
||||
|
||||
|
||||
PATENTS:
|
||||
|
||||
To the best of my knowledge, bzip2/libbzip2 does not use any
|
||||
patented algorithms. However, I do not have the resources
|
||||
to carry out a patent search. Therefore I cannot give any
|
||||
guarantee of the above statement.
|
||||
|
||||
|
||||
I hope you find bzip2 useful. Feel free to contact me at
|
||||
jseward@bzip.org
|
||||
if you have any suggestions or queries. Many people mailed me with
|
||||
comments, suggestions and patches after the releases of bzip-0.15,
|
||||
bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
|
||||
1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
|
||||
feedback. I thank you for your comments.
|
||||
|
||||
bzip2's "home" is http://www.bzip.org/
|
||||
|
||||
Julian Seward
|
||||
jseward@bzip.org
|
||||
Cambridge, UK.
|
||||
|
||||
18 July 1996 (version 0.15)
|
||||
25 August 1996 (version 0.21)
|
||||
7 August 1997 (bzip2, version 0.1)
|
||||
29 August 1997 (bzip2, version 0.1pl2)
|
||||
23 August 1998 (bzip2, version 0.9.0)
|
||||
8 June 1999 (bzip2, version 0.9.5)
|
||||
4 Sept 1999 (bzip2, version 0.9.5d)
|
||||
5 May 2000 (bzip2, version 1.0pre8)
|
||||
30 December 2001 (bzip2, version 1.0.2pre1)
|
||||
15 February 2005 (bzip2, version 1.0.3)
|
||||
20 December 2006 (bzip2, version 1.0.4)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,429 +0,0 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Library top-level functions. ---*/
|
||||
/*--- bzlib.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* CHANGES
|
||||
* 0.9.0 -- original version.
|
||||
* 0.9.0a/b -- no changes in this file.
|
||||
* 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
|
||||
* fixed bzWrite/bzRead to ignore zero-length requests.
|
||||
* fixed bzread to correctly handle read requests after EOF.
|
||||
* wrong parameter order in call to bzDecompressInit in
|
||||
* bzBuffToBuffDecompress. Fixed.
|
||||
*/
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Compression stuff ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#if BZ_LIGHT_DEBUG
|
||||
static
|
||||
void bz_assert_fail(int errcode)
|
||||
{
|
||||
/* if (errcode == 1007) bb_error_msg_and_die("probably bad RAM"); */
|
||||
bb_error_msg_and_die("internal error %d", errcode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void prepare_new_block(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nblock = 0;
|
||||
s->numZ = 0;
|
||||
s->state_out_pos = 0;
|
||||
BZ_INITIALISE_CRC(s->blockCRC);
|
||||
/* inlined memset would be nice to have here */
|
||||
for (i = 0; i < 256; i++)
|
||||
s->inUse[i] = 0;
|
||||
s->blockNo++;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
ALWAYS_INLINE
|
||||
void init_RL(EState* s)
|
||||
{
|
||||
s->state_in_ch = 256;
|
||||
s->state_in_len = 0;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int isempty_RL(EState* s)
|
||||
{
|
||||
return (s->state_in_ch >= 256 || s->state_in_len <= 0);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
{
|
||||
int32_t n;
|
||||
EState* s;
|
||||
|
||||
s = xzalloc(sizeof(EState));
|
||||
s->strm = strm;
|
||||
|
||||
n = 100000 * blockSize100k;
|
||||
s->arr1 = xmalloc(n * sizeof(uint32_t));
|
||||
s->mtfv = (uint16_t*)s->arr1;
|
||||
s->ptr = (uint32_t*)s->arr1;
|
||||
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
|
||||
s->block = (uint8_t*)s->arr2;
|
||||
s->ftab = xmalloc(65537 * sizeof(uint32_t));
|
||||
|
||||
s->crc32table = crc32_filltable(NULL, 1);
|
||||
|
||||
s->state = BZ_S_INPUT;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
s->blockSize100k = blockSize100k;
|
||||
s->nblockMAX = n - 19;
|
||||
|
||||
strm->state = s;
|
||||
/*strm->total_in = 0;*/
|
||||
strm->total_out = 0;
|
||||
init_RL(s);
|
||||
prepare_new_block(s);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void add_pair_to_block(EState* s)
|
||||
{
|
||||
int32_t i;
|
||||
uint8_t ch = (uint8_t)(s->state_in_ch);
|
||||
for (i = 0; i < s->state_in_len; i++) {
|
||||
BZ_UPDATE_CRC(s, s->blockCRC, ch);
|
||||
}
|
||||
s->inUse[s->state_in_ch] = 1;
|
||||
switch (s->state_in_len) {
|
||||
case 3:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
/* fall through */
|
||||
case 2:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
/* fall through */
|
||||
case 1:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
break;
|
||||
default:
|
||||
s->inUse[s->state_in_len - 4] = 1;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)(s->state_in_len - 4);
|
||||
s->nblock++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void flush_RL(EState* s)
|
||||
{
|
||||
if (s->state_in_ch < 256) add_pair_to_block(s);
|
||||
init_RL(s);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define ADD_CHAR_TO_BLOCK(zs, zchh0) \
|
||||
{ \
|
||||
uint32_t zchh = (uint32_t)(zchh0); \
|
||||
/*-- fast track the common case --*/ \
|
||||
if (zchh != zs->state_in_ch && zs->state_in_len == 1) { \
|
||||
uint8_t ch = (uint8_t)(zs->state_in_ch); \
|
||||
BZ_UPDATE_CRC(zs, zs->blockCRC, ch); \
|
||||
zs->inUse[zs->state_in_ch] = 1; \
|
||||
zs->block[zs->nblock] = (uint8_t)ch; \
|
||||
zs->nblock++; \
|
||||
zs->state_in_ch = zchh; \
|
||||
} \
|
||||
else \
|
||||
/*-- general, uncommon cases --*/ \
|
||||
if (zchh != zs->state_in_ch || zs->state_in_len == 255) { \
|
||||
if (zs->state_in_ch < 256) \
|
||||
add_pair_to_block(zs); \
|
||||
zs->state_in_ch = zchh; \
|
||||
zs->state_in_len = 1; \
|
||||
} else { \
|
||||
zs->state_in_len++; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ copy_input_until_stop(EState* s)
|
||||
{
|
||||
/*Bool progress_in = False;*/
|
||||
|
||||
#ifdef SAME_CODE_AS_BELOW
|
||||
if (s->mode == BZ_M_RUNNING) {
|
||||
/*-- fast track the common case --*/
|
||||
while (1) {
|
||||
/*-- no input? --*/
|
||||
if (s->strm->avail_in == 0) break;
|
||||
/*-- block full? --*/
|
||||
if (s->nblock >= s->nblockMAX) break;
|
||||
/*progress_in = True;*/
|
||||
ADD_CHAR_TO_BLOCK(s, (uint32_t)(*(uint8_t*)(s->strm->next_in)));
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
/*s->strm->total_in++;*/
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*-- general, uncommon case --*/
|
||||
while (1) {
|
||||
/*-- no input? --*/
|
||||
if (s->strm->avail_in == 0) break;
|
||||
/*-- block full? --*/
|
||||
if (s->nblock >= s->nblockMAX) break;
|
||||
//# /*-- flush/finish end? --*/
|
||||
//# if (s->avail_in_expect == 0) break;
|
||||
/*progress_in = True;*/
|
||||
ADD_CHAR_TO_BLOCK(s, *(uint8_t*)(s->strm->next_in));
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
/*s->strm->total_in++;*/
|
||||
//# s->avail_in_expect--;
|
||||
}
|
||||
}
|
||||
/*return progress_in;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ copy_output_until_stop(EState* s)
|
||||
{
|
||||
/*Bool progress_out = False;*/
|
||||
|
||||
while (1) {
|
||||
/*-- no output space? --*/
|
||||
if (s->strm->avail_out == 0) break;
|
||||
|
||||
/*-- block done? --*/
|
||||
if (s->state_out_pos >= s->numZ) break;
|
||||
|
||||
/*progress_out = True;*/
|
||||
*(s->strm->next_out) = s->zbits[s->state_out_pos];
|
||||
s->state_out_pos++;
|
||||
s->strm->avail_out--;
|
||||
s->strm->next_out++;
|
||||
s->strm->total_out++;
|
||||
}
|
||||
/*return progress_out;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ handle_compress(bz_stream *strm)
|
||||
{
|
||||
/*Bool progress_in = False;*/
|
||||
/*Bool progress_out = False;*/
|
||||
EState* s = strm->state;
|
||||
|
||||
while (1) {
|
||||
if (s->state == BZ_S_OUTPUT) {
|
||||
/*progress_out |=*/ copy_output_until_stop(s);
|
||||
if (s->state_out_pos < s->numZ) break;
|
||||
if (s->mode == BZ_M_FINISHING
|
||||
//# && s->avail_in_expect == 0
|
||||
&& s->strm->avail_in == 0
|
||||
&& isempty_RL(s))
|
||||
break;
|
||||
prepare_new_block(s);
|
||||
s->state = BZ_S_INPUT;
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
if (s->mode == BZ_M_FLUSHING
|
||||
&& s->avail_in_expect == 0
|
||||
&& isempty_RL(s))
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (s->state == BZ_S_INPUT) {
|
||||
/*progress_in |=*/ copy_input_until_stop(s);
|
||||
//#if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
|
||||
if (s->mode != BZ_M_RUNNING && s->strm->avail_in == 0) {
|
||||
flush_RL(s);
|
||||
BZ2_compressBlock(s, (s->mode == BZ_M_FINISHING));
|
||||
s->state = BZ_S_OUTPUT;
|
||||
} else
|
||||
if (s->nblock >= s->nblockMAX) {
|
||||
BZ2_compressBlock(s, 0);
|
||||
s->state = BZ_S_OUTPUT;
|
||||
} else
|
||||
if (s->strm->avail_in == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*return progress_in || progress_out;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
{
|
||||
/*Bool progress;*/
|
||||
EState* s;
|
||||
|
||||
s = strm->state;
|
||||
|
||||
switch (s->mode) {
|
||||
case BZ_M_RUNNING:
|
||||
if (action == BZ_RUN) {
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;*/
|
||||
return BZ_RUN_OK;
|
||||
}
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
else
|
||||
if (action == BZ_FLUSH) {
|
||||
//#s->avail_in_expect = strm->avail_in;
|
||||
s->mode = BZ_M_FLUSHING;
|
||||
goto case_BZ_M_FLUSHING;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
/*if (action == BZ_FINISH)*/ {
|
||||
//#s->avail_in_expect = strm->avail_in;
|
||||
s->mode = BZ_M_FINISHING;
|
||||
goto case_BZ_M_FINISHING;
|
||||
}
|
||||
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
case_BZ_M_FLUSHING:
|
||||
case BZ_M_FLUSHING:
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FLUSH_OK;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
return BZ_RUN_OK;
|
||||
#endif
|
||||
|
||||
case_BZ_M_FINISHING:
|
||||
/*case BZ_M_FINISHING:*/
|
||||
default:
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
//# return BZ_FINISH_OK;
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FINISH_OK;
|
||||
/*s->mode = BZ_M_IDLE;*/
|
||||
return BZ_STREAM_END;
|
||||
}
|
||||
/* return BZ_OK; --not reached--*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static
|
||||
void BZ2_bzCompressEnd(bz_stream *strm)
|
||||
{
|
||||
EState* s;
|
||||
|
||||
s = strm->state;
|
||||
free(s->arr1);
|
||||
free(s->arr2);
|
||||
free(s->ftab);
|
||||
free(s->crc32table);
|
||||
free(strm->state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Misc convenience stuff ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#ifdef EXAMPLE_CODE_FOR_MEM_TO_MEM_COMPRESSION
|
||||
static
|
||||
int BZ2_bzBuffToBuffCompress(char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int blockSize100k)
|
||||
{
|
||||
bz_stream strm;
|
||||
int ret;
|
||||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
source == NULL ||
|
||||
blockSize100k < 1 || blockSize100k > 9)
|
||||
return BZ_PARAM_ERROR;
|
||||
|
||||
BZ2_bzCompressInit(&strm, blockSize100k);
|
||||
|
||||
strm.next_in = source;
|
||||
strm.next_out = dest;
|
||||
strm.avail_in = sourceLen;
|
||||
strm.avail_out = *destLen;
|
||||
|
||||
ret = BZ2_bzCompress(&strm, BZ_FINISH);
|
||||
if (ret == BZ_FINISH_OK) goto output_overflow;
|
||||
if (ret != BZ_STREAM_END) goto errhandler;
|
||||
|
||||
/* normal termination */
|
||||
*destLen -= strm.avail_out;
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return BZ_OK;
|
||||
|
||||
output_overflow:
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return BZ_OUTBUFF_FULL;
|
||||
|
||||
errhandler:
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Public header file for the library. ---*/
|
||||
/*--- bzlib.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
#define BZ_RUN 0
|
||||
#define BZ_FLUSH 1
|
||||
#define BZ_FINISH 2
|
||||
|
||||
#define BZ_OK 0
|
||||
#define BZ_RUN_OK 1
|
||||
#define BZ_FLUSH_OK 2
|
||||
#define BZ_FINISH_OK 3
|
||||
#define BZ_STREAM_END 4
|
||||
#define BZ_SEQUENCE_ERROR (-1)
|
||||
#define BZ_PARAM_ERROR (-2)
|
||||
#define BZ_MEM_ERROR (-3)
|
||||
#define BZ_DATA_ERROR (-4)
|
||||
#define BZ_DATA_ERROR_MAGIC (-5)
|
||||
#define BZ_IO_ERROR (-6)
|
||||
#define BZ_UNEXPECTED_EOF (-7)
|
||||
#define BZ_OUTBUFF_FULL (-8)
|
||||
#define BZ_CONFIG_ERROR (-9)
|
||||
|
||||
typedef struct bz_stream {
|
||||
void *state;
|
||||
char *next_in;
|
||||
char *next_out;
|
||||
unsigned avail_in;
|
||||
unsigned avail_out;
|
||||
/*unsigned long long total_in;*/
|
||||
unsigned long long total_out;
|
||||
} bz_stream;
|
||||
|
||||
/*-- Core (low-level) library functions --*/
|
||||
|
||||
static void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k);
|
||||
static int BZ2_bzCompress(bz_stream *strm, int action);
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static void BZ2_bzCompressEnd(bz_stream *strm);
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Private header file for the library. ---*/
|
||||
/*--- bzlib_private.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* #include "bzlib.h" */
|
||||
|
||||
/*-- General stuff. --*/
|
||||
|
||||
typedef unsigned char Bool;
|
||||
|
||||
#define True ((Bool)1)
|
||||
#define False ((Bool)0)
|
||||
|
||||
#if BZ_LIGHT_DEBUG
|
||||
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
|
||||
#define AssertH(cond, errcode) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
bz_assert_fail(errcode); \
|
||||
} while (0)
|
||||
#else
|
||||
#define AssertH(cond, msg) do { } while (0)
|
||||
#endif
|
||||
|
||||
#if BZ_DEBUG
|
||||
#define AssertD(cond, msg) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
bb_error_msg_and_die("(debug build): internal error %s", msg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define AssertD(cond, msg) do { } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
/*-- Header bytes. --*/
|
||||
|
||||
#define BZ_HDR_B 0x42 /* 'B' */
|
||||
#define BZ_HDR_Z 0x5a /* 'Z' */
|
||||
#define BZ_HDR_h 0x68 /* 'h' */
|
||||
#define BZ_HDR_0 0x30 /* '0' */
|
||||
|
||||
#define BZ_HDR_BZh0 0x425a6830
|
||||
|
||||
/*-- Constants for the back end. --*/
|
||||
|
||||
#define BZ_MAX_ALPHA_SIZE 258
|
||||
#define BZ_MAX_CODE_LEN 23
|
||||
|
||||
#define BZ_RUNA 0
|
||||
#define BZ_RUNB 1
|
||||
|
||||
#define BZ_N_GROUPS 6
|
||||
#define BZ_G_SIZE 50
|
||||
#define BZ_N_ITERS 4
|
||||
|
||||
#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
|
||||
|
||||
|
||||
/*-- Stuff for doing CRCs. --*/
|
||||
|
||||
#define BZ_INITIALISE_CRC(crcVar) \
|
||||
{ \
|
||||
crcVar = 0xffffffffL; \
|
||||
}
|
||||
|
||||
#define BZ_FINALISE_CRC(crcVar) \
|
||||
{ \
|
||||
crcVar = ~(crcVar); \
|
||||
}
|
||||
|
||||
#define BZ_UPDATE_CRC(s, crcVar, cha) \
|
||||
{ \
|
||||
crcVar = (crcVar << 8) ^ s->crc32table[(crcVar >> 24) ^ ((uint8_t)cha)]; \
|
||||
}
|
||||
|
||||
|
||||
/*-- States and modes for compression. --*/
|
||||
|
||||
#define BZ_M_IDLE 1
|
||||
#define BZ_M_RUNNING 2
|
||||
#define BZ_M_FLUSHING 3
|
||||
#define BZ_M_FINISHING 4
|
||||
|
||||
#define BZ_S_OUTPUT 1
|
||||
#define BZ_S_INPUT 2
|
||||
|
||||
#define BZ_N_RADIX 2
|
||||
#define BZ_N_QSORT 12
|
||||
#define BZ_N_SHELL 18
|
||||
#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
|
||||
|
||||
|
||||
/*-- Structure holding all the compression-side stuff. --*/
|
||||
|
||||
typedef struct EState {
|
||||
/* pointer back to the struct bz_stream */
|
||||
bz_stream *strm;
|
||||
|
||||
/* mode this stream is in, and whether inputting */
|
||||
/* or outputting data */
|
||||
int32_t mode;
|
||||
int32_t state;
|
||||
|
||||
/* remembers avail_in when flush/finish requested */
|
||||
/* bbox: not needed, strm->avail_in always has the same value */
|
||||
/* commented out with '//#' throughout the code */
|
||||
/* uint32_t avail_in_expect; */
|
||||
|
||||
/* for doing the block sorting */
|
||||
int32_t origPtr;
|
||||
uint32_t *arr1;
|
||||
uint32_t *arr2;
|
||||
uint32_t *ftab;
|
||||
|
||||
/* aliases for arr1 and arr2 */
|
||||
uint32_t *ptr;
|
||||
uint8_t *block;
|
||||
uint16_t *mtfv;
|
||||
uint8_t *zbits;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* run-length-encoding of the input */
|
||||
uint32_t state_in_ch;
|
||||
int32_t state_in_len;
|
||||
|
||||
/* input and output limits and current posns */
|
||||
int32_t nblock;
|
||||
int32_t nblockMAX;
|
||||
int32_t numZ;
|
||||
int32_t state_out_pos;
|
||||
|
||||
/* the buffer for bit stream creation */
|
||||
uint32_t bsBuff;
|
||||
int32_t bsLive;
|
||||
|
||||
/* block and combined CRCs */
|
||||
uint32_t blockCRC;
|
||||
uint32_t combinedCRC;
|
||||
|
||||
/* misc administratium */
|
||||
int32_t blockNo;
|
||||
int32_t blockSize100k;
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t nMTF;
|
||||
|
||||
/* map of bytes used in block */
|
||||
int32_t nInUse;
|
||||
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
|
||||
uint8_t unseqToSeq[256];
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t mtfFreq [BZ_MAX_ALPHA_SIZE];
|
||||
uint8_t selector [BZ_MAX_SELECTORS];
|
||||
uint8_t selectorMtf[BZ_MAX_SELECTORS];
|
||||
|
||||
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 len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
#endif
|
||||
} EState;
|
||||
|
||||
|
||||
/*-- compression. --*/
|
||||
|
||||
static void
|
||||
BZ2_blockSort(EState*);
|
||||
|
||||
static void
|
||||
BZ2_compressBlock(EState*, int);
|
||||
|
||||
static void
|
||||
BZ2_bsInitWrite(EState*);
|
||||
|
||||
static void
|
||||
BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
|
||||
|
||||
static void
|
||||
BZ2_hbMakeCodeLengths(uint8_t*, int32_t*, int32_t, int32_t);
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib_private.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -1,681 +0,0 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Compression machinery (not incl block sorting) ---*/
|
||||
/*--- compress.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* CHANGES
|
||||
* 0.9.0 -- original version.
|
||||
* 0.9.0a/b -- no changes in this file.
|
||||
* 0.9.0c -- changed setting of nGroups in sendMTFValues()
|
||||
* so as to do a bit better on small files
|
||||
*/
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Bit stream I/O ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_bsInitWrite(EState* s)
|
||||
{
|
||||
s->bsLive = 0;
|
||||
s->bsBuff = 0;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static NOINLINE
|
||||
void bsFinishWrite(EState* s)
|
||||
{
|
||||
while (s->bsLive > 0) {
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
/* Helps only on level 5, on other levels hurts. ? */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
ALWAYS_INLINE
|
||||
#endif
|
||||
void bsW(EState* s, int32_t n, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (32 - s->bsLive - n));
|
||||
s->bsLive += n;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU32(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 24) & 0xff);
|
||||
bsW(s, 8, (u >> 16) & 0xff);
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- The back end proper ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void makeMaps_e(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nInUse = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (s->inUse[i]) {
|
||||
s->unseqToSeq[i] = s->nInUse;
|
||||
s->nInUse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static NOINLINE
|
||||
void generateMTFValues(EState* s)
|
||||
{
|
||||
uint8_t yy[256];
|
||||
int32_t i, j;
|
||||
int32_t zPend;
|
||||
int32_t wr;
|
||||
int32_t EOB;
|
||||
|
||||
/*
|
||||
* After sorting (eg, here),
|
||||
* s->arr1[0 .. s->nblock-1] holds sorted order,
|
||||
* and
|
||||
* ((uint8_t*)s->arr2)[0 .. s->nblock-1]
|
||||
* holds the original block data.
|
||||
*
|
||||
* The first thing to do is generate the MTF values,
|
||||
* and put them in
|
||||
* ((uint16_t*)s->arr1)[0 .. s->nblock-1].
|
||||
* Because there are strictly fewer or equal MTF values
|
||||
* than block values, ptr values in this area are overwritten
|
||||
* with MTF values only when they are no longer needed.
|
||||
*
|
||||
* The final compressed bitstream is generated into the
|
||||
* area starting at
|
||||
* &((uint8_t*)s->arr2)[s->nblock]
|
||||
*
|
||||
* These storage aliases are set up in bzCompressInit(),
|
||||
* except for the last one, which is arranged in
|
||||
* compressBlock().
|
||||
*/
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
makeMaps_e(s);
|
||||
EOB = s->nInUse+1;
|
||||
|
||||
for (i = 0; i <= EOB; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
wr = 0;
|
||||
zPend = 0;
|
||||
for (i = 0; i < s->nInUse; i++)
|
||||
yy[i] = (uint8_t) i;
|
||||
|
||||
for (i = 0; i < s->nblock; i++) {
|
||||
uint8_t ll_i;
|
||||
AssertD(wr <= i, "generateMTFValues(1)");
|
||||
j = ptr[i] - 1;
|
||||
if (j < 0)
|
||||
j += s->nblock;
|
||||
ll_i = s->unseqToSeq[block[j]];
|
||||
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
|
||||
|
||||
if (yy[0] == ll_i) {
|
||||
zPend++;
|
||||
} else {
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
register uint8_t rll_i;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
rll_i = ll_i;
|
||||
while (rll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
};
|
||||
yy[0] = rtmp;
|
||||
j = ryy_j - &(yy[0]);
|
||||
mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2)
|
||||
break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
|
||||
mtfv[wr] = EOB;
|
||||
wr++;
|
||||
s->mtfFreq[EOB]++;
|
||||
|
||||
s->nMTF = wr;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define BZ_LESSER_ICOST 0
|
||||
#define BZ_GREATER_ICOST 15
|
||||
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups, nBytes;
|
||||
|
||||
/*
|
||||
* uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* is a global since the decoder also needs it.
|
||||
*
|
||||
* int32_t code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* are also globals only used in this proc.
|
||||
* Made global to keep stack frame size small.
|
||||
*/
|
||||
|
||||
uint16_t cost[BZ_N_GROUPS];
|
||||
int32_t fave[BZ_N_GROUPS];
|
||||
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
alphaSize = s->nInUse+2;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->len[t][v] = BZ_GREATER_ICOST;
|
||||
|
||||
/*--- Decide how many coding tables to use ---*/
|
||||
AssertH(s->nMTF > 0, 3001);
|
||||
if (s->nMTF < 200) nGroups = 2; else
|
||||
if (s->nMTF < 600) nGroups = 3; else
|
||||
if (s->nMTF < 1200) nGroups = 4; else
|
||||
if (s->nMTF < 2400) nGroups = 5; else
|
||||
nGroups = 6;
|
||||
|
||||
/*--- Generate an initial set of coding tables ---*/
|
||||
{
|
||||
int32_t nPart, remF, tFreq, aFreq;
|
||||
|
||||
nPart = nGroups;
|
||||
remF = s->nMTF;
|
||||
gs = 0;
|
||||
while (nPart > 0) {
|
||||
tFreq = remF / nPart;
|
||||
ge = gs - 1;
|
||||
aFreq = 0;
|
||||
while (aFreq < tFreq && ge < alphaSize-1) {
|
||||
ge++;
|
||||
aFreq += s->mtfFreq[ge];
|
||||
}
|
||||
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
&& ((nGroups - nPart) % 2 == 1) /* bbox: can this be replaced by x & 1? */
|
||||
) {
|
||||
aFreq -= s->mtfFreq[ge];
|
||||
ge--;
|
||||
}
|
||||
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
if (v >= gs && v <= ge)
|
||||
s->len[nPart-1][v] = BZ_LESSER_ICOST;
|
||||
else
|
||||
s->len[nPart-1][v] = BZ_GREATER_ICOST;
|
||||
|
||||
nPart--;
|
||||
gs = ge + 1;
|
||||
remF -= aFreq;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate up to BZ_N_ITERS times to improve the tables.
|
||||
*/
|
||||
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||
for (t = 0; t < nGroups; t++)
|
||||
fave[t] = 0;
|
||||
|
||||
for (t = 0; t < nGroups; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->rfreq[t][v] = 0;
|
||||
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/*
|
||||
* Set up an auxiliary length table which is used to fast-track
|
||||
* the common case (nGroups == 6).
|
||||
*/
|
||||
if (nGroups == 6) {
|
||||
for (v = 0; v < alphaSize; v++) {
|
||||
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
nSelectors = 0;
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF)
|
||||
ge = s->nMTF-1;
|
||||
|
||||
/*
|
||||
* Calculate the cost of this group as coded
|
||||
* by each of the coding tables.
|
||||
*/
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] = 0;
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
register uint32_t cost01, cost23, cost45;
|
||||
register uint16_t icv;
|
||||
cost01 = cost23 = cost45 = 0;
|
||||
#define BZ_ITER(nn) \
|
||||
icv = mtfv[gs+(nn)]; \
|
||||
cost01 += s->len_pack[icv][0]; \
|
||||
cost23 += s->len_pack[icv][1]; \
|
||||
cost45 += s->len_pack[icv][2];
|
||||
BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4);
|
||||
BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9);
|
||||
BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
|
||||
BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
|
||||
BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
|
||||
BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
|
||||
BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
|
||||
BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
|
||||
BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
|
||||
BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
|
||||
#undef BZ_ITER
|
||||
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
uint16_t icv = mtfv[i];
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] += s->len[t][icv];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Find the coding table which is best for this group,
|
||||
* and record its identity in the selector table.
|
||||
*/
|
||||
/*bc = 999999999;*/
|
||||
/*bt = -1;*/
|
||||
bc = cost[0];
|
||||
bt = 0;
|
||||
for (t = 1 /*0*/; t < nGroups; t++) {
|
||||
if (cost[t] < bc) {
|
||||
bc = cost[t];
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
totc += bc;
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
/*
|
||||
* Increment the symbol frequencies for the selected table.
|
||||
*/
|
||||
/* 1% faster compress. +800 bytes */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 4
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
|
||||
BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4);
|
||||
BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9);
|
||||
BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
|
||||
BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
|
||||
BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
|
||||
BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
|
||||
BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
|
||||
BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
|
||||
BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
|
||||
BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
|
||||
#undef BZ_ITUR
|
||||
gs = ge + 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
while (gs <= ge) {
|
||||
s->rfreq[bt][mtfv[gs]]++;
|
||||
gs++;
|
||||
}
|
||||
/* already is: gs = ge + 1; */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recompute the tables based on the accumulated frequencies.
|
||||
*/
|
||||
/* 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->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
|
||||
}
|
||||
|
||||
AssertH(nGroups < 8, 3002);
|
||||
AssertH(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZ_G_SIZE)), 3003);
|
||||
|
||||
/*--- Compute MTF values for the selectors. ---*/
|
||||
{
|
||||
uint8_t pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
|
||||
|
||||
for (i = 0; i < nGroups; i++)
|
||||
pos[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
ll_i = s->selector[i];
|
||||
j = 0;
|
||||
tmp = pos[j];
|
||||
while (ll_i != tmp) {
|
||||
j++;
|
||||
tmp2 = tmp;
|
||||
tmp = pos[j];
|
||||
pos[j] = tmp2;
|
||||
};
|
||||
pos[0] = tmp;
|
||||
s->selectorMtf[i] = j;
|
||||
}
|
||||
};
|
||||
|
||||
/*--- Assign actual codes for the tables. --*/
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
minLen = 32;
|
||||
maxLen = 0;
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||
}
|
||||
AssertH(!(maxLen > 17 /*20*/), 3004);
|
||||
AssertH(!(minLen < 1), 3005);
|
||||
BZ2_hbAssignCodes(&(s->code[t][0]), &(s->len[t][0]), minLen, maxLen, alphaSize);
|
||||
}
|
||||
|
||||
/*--- Transmit the mapping table. ---*/
|
||||
{
|
||||
/* bbox: optimized a bit more than in bzip2 */
|
||||
int inUse16 = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (sizeof(long) <= 4) {
|
||||
inUse16 = inUse16*2 +
|
||||
((*(uint32_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 4])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 8])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
|
||||
} else { /* Our CPU can do better */
|
||||
inUse16 = inUse16*2 +
|
||||
((*(uint64_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 16, inUse16);
|
||||
|
||||
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (inUse16 < 0) {
|
||||
unsigned v16 = 0;
|
||||
for (j = 0; j < 16; j++)
|
||||
v16 = v16*2 + s->inUse[i * 16 + j];
|
||||
bsW(s, 16, v16);
|
||||
}
|
||||
inUse16 <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*--- Now the selectors. ---*/
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 3, nGroups);
|
||||
bsW(s, 15, nSelectors);
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
for (j = 0; j < s->selectorMtf[i]; j++)
|
||||
bsW(s, 1, 1);
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
|
||||
/*--- Now the coding tables. ---*/
|
||||
nBytes = s->numZ;
|
||||
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
int32_t curr = s->len[t][0];
|
||||
bsW(s, 5, curr);
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*--- And finally, the block data proper ---*/
|
||||
nBytes = s->numZ;
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF)
|
||||
ge = s->nMTF-1;
|
||||
AssertH(s->selector[selCtr] < nGroups, 3006);
|
||||
|
||||
/* Costs 1300 bytes and is _slower_ (on Intel Core 2) */
|
||||
#if 0
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
uint16_t mtfv_i;
|
||||
uint8_t* s_len_sel_selCtr = &(s->len[s->selector[selCtr]][0]);
|
||||
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
|
||||
#define BZ_ITAH(nn) \
|
||||
mtfv_i = mtfv[gs+(nn)]; \
|
||||
bsW(s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i])
|
||||
BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4);
|
||||
BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9);
|
||||
BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
|
||||
BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
|
||||
BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
|
||||
BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
|
||||
BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
|
||||
BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
|
||||
BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
|
||||
BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
|
||||
#undef BZ_ITAH
|
||||
gs = ge+1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
/* code is bit bigger, but moves multiply out of the loop */
|
||||
uint8_t* s_len_sel_selCtr = &(s->len [s->selector[selCtr]][0]);
|
||||
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
|
||||
while (gs <= ge) {
|
||||
bsW(s,
|
||||
s_len_sel_selCtr[mtfv[gs]],
|
||||
s_code_sel_selCtr[mtfv[gs]]
|
||||
);
|
||||
gs++;
|
||||
}
|
||||
/* already is: gs = ge+1; */
|
||||
}
|
||||
selCtr++;
|
||||
}
|
||||
AssertH(selCtr == nSelectors, 3007);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
{
|
||||
if (s->nblock > 0) {
|
||||
BZ_FINALISE_CRC(s->blockCRC);
|
||||
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
|
||||
s->combinedCRC ^= s->blockCRC;
|
||||
if (s->blockNo > 1)
|
||||
s->numZ = 0;
|
||||
|
||||
BZ2_blockSort(s);
|
||||
}
|
||||
|
||||
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
|
||||
|
||||
/*-- If this is the first block, create the stream header. --*/
|
||||
if (s->blockNo == 1) {
|
||||
BZ2_bsInitWrite(s);
|
||||
/*bsPutU8(s, BZ_HDR_B);*/
|
||||
/*bsPutU8(s, BZ_HDR_Z);*/
|
||||
/*bsPutU8(s, BZ_HDR_h);*/
|
||||
/*bsPutU8(s, BZ_HDR_0 + s->blockSize100k);*/
|
||||
bsPutU32(s, BZ_HDR_BZh0 + s->blockSize100k);
|
||||
}
|
||||
|
||||
if (s->nblock > 0) {
|
||||
/*bsPutU8(s, 0x31);*/
|
||||
/*bsPutU8(s, 0x41);*/
|
||||
/*bsPutU8(s, 0x59);*/
|
||||
/*bsPutU8(s, 0x26);*/
|
||||
bsPutU32(s, 0x31415926);
|
||||
/*bsPutU8(s, 0x53);*/
|
||||
/*bsPutU8(s, 0x59);*/
|
||||
bsPutU16(s, 0x5359);
|
||||
|
||||
/*-- Now the block's CRC, so it is in a known place. --*/
|
||||
bsPutU32(s, s->blockCRC);
|
||||
|
||||
/*
|
||||
* Now a single bit indicating (non-)randomisation.
|
||||
* As of version 0.9.5, we use a better sorting algorithm
|
||||
* which makes randomisation unnecessary. So always set
|
||||
* the randomised bit to 'no'. Of course, the decoder
|
||||
* still needs to be able to handle randomised blocks
|
||||
* so as to maintain backwards compatibility with
|
||||
* older versions of bzip2.
|
||||
*/
|
||||
bsW(s, 1, 0);
|
||||
|
||||
bsW(s, 24, s->origPtr);
|
||||
generateMTFValues(s);
|
||||
sendMTFValues(s);
|
||||
}
|
||||
|
||||
/*-- If this is the last block, add the stream trailer. --*/
|
||||
if (is_last_block) {
|
||||
/*bsPutU8(s, 0x17);*/
|
||||
/*bsPutU8(s, 0x72);*/
|
||||
/*bsPutU8(s, 0x45);*/
|
||||
/*bsPutU8(s, 0x38);*/
|
||||
bsPutU32(s, 0x17724538);
|
||||
/*bsPutU8(s, 0x50);*/
|
||||
/*bsPutU8(s, 0x90);*/
|
||||
bsPutU16(s, 0x5090);
|
||||
bsPutU32(s, s->combinedCRC);
|
||||
bsFinishWrite(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end compress.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Huffman coding low-level stuff ---*/
|
||||
/*--- huffman.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
|
||||
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
|
||||
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
|
||||
|
||||
#define ADDWEIGHTS(zw1,zw2) \
|
||||
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
|
||||
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
|
||||
|
||||
#define UPHEAP(z) \
|
||||
{ \
|
||||
int32_t zz, tmp; \
|
||||
zz = z; \
|
||||
tmp = heap[zz]; \
|
||||
while (weight[tmp] < weight[heap[zz >> 1]]) { \
|
||||
heap[zz] = heap[zz >> 1]; \
|
||||
zz >>= 1; \
|
||||
} \
|
||||
heap[zz] = tmp; \
|
||||
}
|
||||
|
||||
|
||||
/* 90 bytes, 0.3% of overall compress speed */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 1
|
||||
|
||||
/* macro works better than inline (gcc 4.2.1) */
|
||||
#define DOWNHEAP1(heap, weight, Heap) \
|
||||
{ \
|
||||
int32_t zz, yy, tmp; \
|
||||
zz = 1; \
|
||||
tmp = heap[zz]; \
|
||||
while (1) { \
|
||||
yy = zz << 1; \
|
||||
if (yy > nHeap) \
|
||||
break; \
|
||||
if (yy < nHeap \
|
||||
&& weight[heap[yy+1]] < weight[heap[yy]]) \
|
||||
yy++; \
|
||||
if (weight[tmp] < weight[heap[yy]]) \
|
||||
break; \
|
||||
heap[zz] = heap[yy]; \
|
||||
zz = yy; \
|
||||
} \
|
||||
heap[zz] = tmp; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static
|
||||
void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
|
||||
{
|
||||
int32_t zz, yy, tmp;
|
||||
zz = 1;
|
||||
tmp = heap[zz];
|
||||
while (1) {
|
||||
yy = zz << 1;
|
||||
if (yy > nHeap)
|
||||
break;
|
||||
if (yy < nHeap
|
||||
&& weight[heap[yy + 1]] < weight[heap[yy]])
|
||||
yy++;
|
||||
if (weight[tmp] < weight[heap[yy]])
|
||||
break;
|
||||
heap[zz] = heap[yy];
|
||||
zz = yy;
|
||||
}
|
||||
heap[zz] = tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_hbMakeCodeLengths(uint8_t *len,
|
||||
int32_t *freq,
|
||||
int32_t alphaSize,
|
||||
int32_t maxLen)
|
||||
{
|
||||
/*
|
||||
* Nodes and heap entries run from 1. Entry 0
|
||||
* for both the heap and nodes is a sentinel.
|
||||
*/
|
||||
int32_t nNodes, nHeap, n1, n2, i, j, k;
|
||||
Bool tooLong;
|
||||
|
||||
int32_t heap [BZ_MAX_ALPHA_SIZE + 2];
|
||||
int32_t weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
|
||||
|
||||
while (1) {
|
||||
nNodes = alphaSize;
|
||||
nHeap = 0;
|
||||
|
||||
heap[0] = 0;
|
||||
weight[0] = 0;
|
||||
parent[0] = -2;
|
||||
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
parent[i] = -1;
|
||||
nHeap++;
|
||||
heap[nHeap] = i;
|
||||
UPHEAP(nHeap);
|
||||
}
|
||||
|
||||
AssertH(nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001);
|
||||
|
||||
while (nHeap > 1) {
|
||||
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
|
||||
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
|
||||
nNodes++;
|
||||
parent[n1] = parent[n2] = nNodes;
|
||||
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
|
||||
parent[nNodes] = -1;
|
||||
nHeap++;
|
||||
heap[nHeap] = nNodes;
|
||||
UPHEAP(nHeap);
|
||||
}
|
||||
|
||||
AssertH(nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002);
|
||||
|
||||
tooLong = False;
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
j = 0;
|
||||
k = i;
|
||||
while (parent[k] >= 0) {
|
||||
k = parent[k];
|
||||
j++;
|
||||
}
|
||||
len[i-1] = j;
|
||||
if (j > maxLen)
|
||||
tooLong = True;
|
||||
}
|
||||
|
||||
if (!tooLong)
|
||||
break;
|
||||
|
||||
/* 17 Oct 04: keep-going condition for the following loop used
|
||||
to be 'i < alphaSize', which missed the last element,
|
||||
theoretically leading to the possibility of the compressor
|
||||
looping. However, this count-scaling step is only needed if
|
||||
one of the generated Huffman code words is longer than
|
||||
maxLen, which up to and including version 1.0.2 was 20 bits,
|
||||
which is extremely unlikely. In version 1.0.3 maxLen was
|
||||
changed to 17 bits, which has minimal effect on compression
|
||||
ratio, but does mean this scaling step is used from time to
|
||||
time, enough to verify that it works.
|
||||
|
||||
This means that bzip2-1.0.3 and later will only produce
|
||||
Huffman codes with a maximum length of 17 bits. However, in
|
||||
order to preserve backwards compatibility with bitstreams
|
||||
produced by versions pre-1.0.3, the decompressor must still
|
||||
handle lengths of up to 20. */
|
||||
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
j = weight[i] >> 8;
|
||||
/* bbox: yes, it is a signed division.
|
||||
* don't replace with shift! */
|
||||
j = 1 + (j / 2);
|
||||
weight[i] = j << 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_hbAssignCodes(int32_t *code,
|
||||
uint8_t *length,
|
||||
int32_t minLen,
|
||||
int32_t maxLen,
|
||||
int32_t alphaSize)
|
||||
{
|
||||
int32_t n, vec, i;
|
||||
|
||||
vec = 0;
|
||||
for (n = minLen; n <= maxLen; n++) {
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (length[i] == n) {
|
||||
code[i] = vec;
|
||||
vec++;
|
||||
};
|
||||
}
|
||||
vec <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end huffman.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* This file uses bzip2 library code which is written
|
||||
* by Julian Seward <jseward@bzip.org>.
|
||||
* See README and LICENSE files in bz/ directory for more information
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define CONFIG_BZIP2_FEATURE_SPEED 1
|
||||
|
||||
/* Speed test:
|
||||
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
|
||||
* Stock bzip2 is 26.4% slower than bbox bzip2 at SPEED 1
|
||||
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
|
||||
* At SPEED 5 difference is 32.7%.
|
||||
*
|
||||
* Test run of all CONFIG_BZIP2_FEATURE_SPEED values on a 11Mb text file:
|
||||
* Size Time (3 runs)
|
||||
* 0: 10828 4.145 4.146 4.148
|
||||
* 1: 11097 3.845 3.860 3.861
|
||||
* 2: 11392 3.763 3.767 3.768
|
||||
* 3: 11892 3.722 3.724 3.727
|
||||
* 4: 12740 3.637 3.640 3.644
|
||||
* 5: 17273 3.497 3.509 3.509
|
||||
*/
|
||||
|
||||
|
||||
#define BZ_DEBUG 0
|
||||
/* Takes ~300 bytes, detects corruption caused by bad RAM etc */
|
||||
#define BZ_LIGHT_DEBUG 0
|
||||
|
||||
#include "bz/bzlib.h"
|
||||
|
||||
#include "bz/bzlib_private.h"
|
||||
|
||||
#include "bz/blocksort.c"
|
||||
#include "bz/bzlib.c"
|
||||
#include "bz/compress.c"
|
||||
#include "bz/huffman.c"
|
||||
|
||||
/* No point in being shy and having very small buffer here.
|
||||
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
|
||||
* If iobuf is several pages long, malloc() may use mmap,
|
||||
* making iobuf is page aligned and thus (maybe) have one memcpy less
|
||||
* if kernel is clever enough.
|
||||
*/
|
||||
enum {
|
||||
IOBUF_SIZE = 8 * 1024
|
||||
};
|
||||
|
||||
static uint8_t level;
|
||||
|
||||
/* NB: compressStream() has to return -1 on errors, not die.
|
||||
* bbunpack() will correctly clean up in this case
|
||||
* (delete incomplete .bz2 file)
|
||||
*/
|
||||
|
||||
/* Returns:
|
||||
* -1 on errors
|
||||
* total written bytes so far otherwise
|
||||
*/
|
||||
static
|
||||
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
{
|
||||
int n, n2, ret;
|
||||
|
||||
strm->avail_in = rlen;
|
||||
strm->next_in = rbuf;
|
||||
while (1) {
|
||||
strm->avail_out = IOBUF_SIZE;
|
||||
strm->next_out = wbuf;
|
||||
|
||||
ret = BZ2_bzCompress(strm, rlen ? BZ_RUN : BZ_FINISH);
|
||||
if (ret != BZ_RUN_OK /* BZ_RUNning */
|
||||
&& ret != BZ_FINISH_OK /* BZ_FINISHing, but not done yet */
|
||||
&& ret != BZ_STREAM_END /* BZ_FINISHed */
|
||||
) {
|
||||
bb_error_msg_and_die("internal error %d", ret);
|
||||
}
|
||||
|
||||
n = IOBUF_SIZE - strm->avail_out;
|
||||
if (n) {
|
||||
n2 = full_write(STDOUT_FILENO, wbuf, n);
|
||||
if (n2 != n) {
|
||||
if (n2 >= 0)
|
||||
errno = 0; /* prevent bogus error message */
|
||||
bb_perror_msg(n2 >= 0 ? "short write" : "write error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == BZ_STREAM_END)
|
||||
break;
|
||||
if (rlen && strm->avail_in == 0)
|
||||
break;
|
||||
}
|
||||
return 0 USE_DESKTOP( + strm->total_out );
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int compressStream(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
char *iobuf;
|
||||
#define rbuf iobuf
|
||||
#define wbuf (iobuf + IOBUF_SIZE)
|
||||
|
||||
iobuf = xmalloc(2 * IOBUF_SIZE);
|
||||
BZ2_bzCompressInit(strm, level);
|
||||
|
||||
while (1) {
|
||||
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
|
||||
if (count < 0) {
|
||||
bb_perror_msg("read error");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
/* if count == 0, bz_write finalizes compression */
|
||||
total = bz_write(strm, rbuf, count, wbuf);
|
||||
if (count == 0 || total < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
BZ2_bzCompressEnd(strm);
|
||||
free(iobuf);
|
||||
#endif
|
||||
return total;
|
||||
}
|
||||
|
||||
static
|
||||
char* make_new_name_bzip2(char *filename)
|
||||
{
|
||||
return xasprintf("%s.bz2", filename);
|
||||
}
|
||||
|
||||
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bzip2_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
/* standard bzip2 flags
|
||||
* -d --decompress force decompression
|
||||
* -z --compress force compression
|
||||
* -k --keep keep (don't delete) input files
|
||||
* -f --force overwrite existing output files
|
||||
* -t --test test compressed file integrity
|
||||
* -c --stdout output to standard out
|
||||
* -q --quiet suppress noncritical error messages
|
||||
* -v --verbose be verbose (a 2nd -v gives more)
|
||||
* -s --small use less memory (at most 2500k)
|
||||
* -1 .. -9 set block size to 100k .. 900k
|
||||
* --fast alias for -1
|
||||
* --best alias for -9
|
||||
*/
|
||||
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
|
||||
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
|
||||
if (opt & 0x8) // -d
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 4;
|
||||
#else
|
||||
opt >>= 3;
|
||||
#endif
|
||||
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 1;
|
||||
while (!(opt & 1)) {
|
||||
level++;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
option_mask32 &= 0x7; /* ignore all except -cfv */
|
||||
return bbunpack(argv, make_new_name_bzip2, compressStream);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#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, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename = NULL;
|
||||
unsigned opt;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
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) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test options are given, ignore extract option */
|
||||
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_UNCONDITIONAL) {
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
if (archive_handle->action_header == header_list) {
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (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->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
#define DPKG_DEB_OPT_FIELD 4
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned opt;
|
||||
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->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#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_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 = getopt32(argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_CONTROL) {
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (optind + 1 == argc) {
|
||||
extract_dir = "./DEBIAN";
|
||||
} else {
|
||||
argcount++;
|
||||
}
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_FIELD) {
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
llist_add_to(&(tar_archive->accept), (char*)"./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_EXTRACT) {
|
||||
tar_archive->action_header = header_list;
|
||||
}
|
||||
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
||||
tar_archive->action_data = data_extract_all;
|
||||
argcount = 2;
|
||||
}
|
||||
|
||||
if ((optind + argcount) != argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* Workout where to extract the files */
|
||||
/* 2nd argument is a dir name */
|
||||
if (argv[optind]) {
|
||||
extract_dir = argv[optind];
|
||||
}
|
||||
if (extract_dir) {
|
||||
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
|
||||
xchdir(extract_dir);
|
||||
}
|
||||
unpack_ar_archive(ar_archive);
|
||||
|
||||
/* Cleanup */
|
||||
close(ar_archive->src_fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
|
||||
lib-y:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
archive_xread_all_eof.o \
|
||||
\
|
||||
seek_by_read.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
init_handle.o
|
||||
|
||||
DPKG_FILES:= \
|
||||
get_header_ar.o \
|
||||
unpack_ar_archive.o \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
lib-$(CONFIG_RPM) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
@@ -1,20 +0,0 @@
|
||||
/* 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;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
//#include <sys/types.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
{
|
||||
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_extract_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = xstrdup(file_header->name);
|
||||
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the existing entry if it exists */
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat old file");
|
||||
}
|
||||
}
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", file_header->name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately
|
||||
* We identified hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_target)
|
||||
&& (file_header->size == 0)
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "hard",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
} else {
|
||||
/* Create the filesystem entry */
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
file_header->mode);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1) && (errno != EISDIR)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot make dir %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_target, file_header->name);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "sym",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_error_msg_and_die("unrecognized file type");
|
||||
}
|
||||
}
|
||||
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_exact_size(archive_handle->src_fd,
|
||||
STDOUT_FILENO,
|
||||
archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,499 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on LzmaDecode.c from the LZMA SDK 4.22 (http://www.7-zip.org/)
|
||||
* Copyright (C) 1999-2005 Igor Pavlov
|
||||
*
|
||||
* 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
|
||||
#else
|
||||
# define speed_inline
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
uint8_t *ptr;
|
||||
|
||||
/* Was keeping rc on stack in unlzma and separately allocating buffer,
|
||||
* but with "buffer 'attached to' allocated rc" code is smaller: */
|
||||
/* uint8_t *buffer; */
|
||||
#define RC_BUFFER ((uint8_t*)(rc+1))
|
||||
|
||||
uint8_t *buffer_end;
|
||||
|
||||
/* Had provisions for variable buffer, but we don't need it here */
|
||||
/* int buffer_size; */
|
||||
#define RC_BUFFER_SIZE 0x10000
|
||||
|
||||
uint32_t code;
|
||||
uint32_t range;
|
||||
uint32_t bound;
|
||||
} rc_t;
|
||||
|
||||
#define RC_TOP_BITS 24
|
||||
#define RC_MOVE_BITS 5
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
|
||||
|
||||
/* 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);
|
||||
if (buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
}
|
||||
|
||||
/* 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++;
|
||||
}
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t * rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
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;
|
||||
}
|
||||
|
||||
/* Called 4 times in unlzma loop */
|
||||
static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol)
|
||||
{
|
||||
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)
|
||||
{
|
||||
rc_normalize(rc);
|
||||
rc->range >>= 1;
|
||||
if (rc->code >= rc->range) {
|
||||
rc->code -= rc->range;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called twice */
|
||||
static speed_inline void
|
||||
rc_bit_tree_decode(rc_t * rc, uint16_t * p, int num_levels, int *symbol)
|
||||
{
|
||||
int i = num_levels;
|
||||
|
||||
*symbol = 1;
|
||||
while (i--)
|
||||
rc_get_bit(rc, p + *symbol, symbol);
|
||||
*symbol -= 1 << num_levels;
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t pos;
|
||||
uint32_t dict_size;
|
||||
uint64_t dst_size;
|
||||
} __attribute__ ((packed)) lzma_header_t;
|
||||
|
||||
|
||||
/* #defines will force compiler to compute/optimize each one with each usage.
|
||||
* Have heart and use enum instead. */
|
||||
enum {
|
||||
LZMA_BASE_SIZE = 1846,
|
||||
LZMA_LIT_SIZE = 768,
|
||||
|
||||
LZMA_NUM_POS_BITS_MAX = 4,
|
||||
|
||||
LZMA_LEN_NUM_LOW_BITS = 3,
|
||||
LZMA_LEN_NUM_MID_BITS = 3,
|
||||
LZMA_LEN_NUM_HIGH_BITS = 8,
|
||||
|
||||
LZMA_LEN_CHOICE = 0,
|
||||
LZMA_LEN_CHOICE_2 = (LZMA_LEN_CHOICE + 1),
|
||||
LZMA_LEN_LOW = (LZMA_LEN_CHOICE_2 + 1),
|
||||
LZMA_LEN_MID = (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS))),
|
||||
LZMA_LEN_HIGH = (LZMA_LEN_MID \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS))),
|
||||
LZMA_NUM_LEN_PROBS = (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS)),
|
||||
|
||||
LZMA_NUM_STATES = 12,
|
||||
LZMA_NUM_LIT_STATES = 7,
|
||||
|
||||
LZMA_START_POS_MODEL_INDEX = 4,
|
||||
LZMA_END_POS_MODEL_INDEX = 14,
|
||||
LZMA_NUM_FULL_DISTANCES = (1 << (LZMA_END_POS_MODEL_INDEX >> 1)),
|
||||
|
||||
LZMA_NUM_POS_SLOT_BITS = 6,
|
||||
LZMA_NUM_LEN_TO_POS_STATES = 4,
|
||||
|
||||
LZMA_NUM_ALIGN_BITS = 4,
|
||||
|
||||
LZMA_MATCH_MIN_LEN = 2,
|
||||
|
||||
LZMA_IS_MATCH = 0,
|
||||
LZMA_IS_REP = (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_IS_REP_G0 = (LZMA_IS_REP + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G1 = (LZMA_IS_REP_G0 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G2 = (LZMA_IS_REP_G1 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_0_LONG = (LZMA_IS_REP_G2 + LZMA_NUM_STATES),
|
||||
LZMA_POS_SLOT = (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_SPEC_POS = (LZMA_POS_SLOT \
|
||||
+ (LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS)),
|
||||
LZMA_ALIGN = (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX),
|
||||
LZMA_LEN_CODER = (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS)),
|
||||
LZMA_REP_LEN_CODER = (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
LZMA_LITERAL = (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
};
|
||||
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
{
|
||||
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, mi;
|
||||
uint8_t *buffer;
|
||||
uint8_t previous_byte = 0;
|
||||
size_t buffer_pos = 0, global_pos = 0;
|
||||
int len = 0;
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
xread(src_fd, &header, sizeof(header));
|
||||
|
||||
if (header.pos >= (9 * 5 * 5))
|
||||
bb_error_msg_and_die("bad header");
|
||||
mi = header.pos / 9;
|
||||
lc = header.pos % 9;
|
||||
pb = mi / 5;
|
||||
lp = mi % 5;
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
header.dict_size = SWAP_LE32(header.dict_size);
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
if (header.dict_size == 0)
|
||||
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_LIT_SIZE << (lc + lp));
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
|
||||
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;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
match_byte = buffer[pos];
|
||||
do {
|
||||
int bit;
|
||||
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
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) {
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
}
|
||||
previous_byte = (uint8_t) mi;
|
||||
|
||||
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;)
|
||||
}
|
||||
if (state < 4)
|
||||
state = 0;
|
||||
else if (state < 10)
|
||||
state -= 3;
|
||||
else
|
||||
state -= 6;
|
||||
} else {
|
||||
int offset;
|
||||
uint16_t *prob_len;
|
||||
|
||||
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;
|
||||
prob = p + LZMA_LEN_CODER;
|
||||
} else {
|
||||
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];
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
rep2 = rep1;
|
||||
}
|
||||
rep1 = rep0;
|
||||
rep0 = distance;
|
||||
}
|
||||
state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
|
||||
prob = p + LZMA_REP_LEN_CODER;
|
||||
}
|
||||
|
||||
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 {
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
|
||||
len += offset;
|
||||
|
||||
if (state < 4) {
|
||||
int pos_slot;
|
||||
|
||||
state += LZMA_NUM_LIT_STATES;
|
||||
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) {
|
||||
num_bits = (pos_slot >> 1) - 1;
|
||||
rep0 = 2 | (pos_slot & 1);
|
||||
if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
|
||||
rep0 <<= num_bits;
|
||||
prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
|
||||
} else {
|
||||
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;
|
||||
num_bits = LZMA_NUM_ALIGN_BITS;
|
||||
}
|
||||
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;
|
||||
|
||||
do {
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
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;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
|
||||
bad:
|
||||
rc_free(rc);
|
||||
return -1;
|
||||
}
|
||||
rc_free(rc);
|
||||
USE_DESKTOP(total_written += buffer_pos;)
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,17 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Accept any non-null name, its not really a filter at all */
|
||||
char filter_accept_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
if (archive_handle->file_header->name)
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list, ignoring reject list.
|
||||
*/
|
||||
char filter_accept_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name))
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* 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 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;
|
||||
|
||||
/* Extract the last 2 extensions */
|
||||
name_ptr = strrchr(archive_handle->file_header->name, '.');
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
#if ENABLE_FEATURE_DEB_TAR_GZ
|
||||
if (strcmp(name_ptr, ".gz") == 0) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
#endif
|
||||
if (ENABLE_FEATURE_DEB_TAR_LZMA && !strcmp(name_ptr, ".lzma")) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list and not in the reject list
|
||||
*/
|
||||
char filter_accept_reject_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
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;
|
||||
|
||||
/* If the key is in a reject list fail */
|
||||
if (reject_entry) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
accept_entry = find_list_entry2(archive_handle->accept, key);
|
||||
|
||||
/* Fail if an accept list was specified and the key wasnt in there */
|
||||
if ((accept_entry == NULL) && archive_handle->accept) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Accepted */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Find a string in a shell pattern list */
|
||||
const llist_t *find_list_entry(const llist_t *list, const char *filename)
|
||||
{
|
||||
while (list) {
|
||||
if (fnmatch(list->data, filename, 0) == 0) {
|
||||
return list;
|
||||
}
|
||||
list = list->link;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Same, but compares only path components present in pattern
|
||||
* (extra trailing path components in filename are assumed to match)
|
||||
*/
|
||||
const llist_t *find_list_entry2(const llist_t *list, const char *filename)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
int pattern_slash_cnt;
|
||||
const char *c;
|
||||
char *d;
|
||||
|
||||
while (list) {
|
||||
c = list->data;
|
||||
pattern_slash_cnt = 0;
|
||||
while (*c)
|
||||
if (*c++ == '/') pattern_slash_cnt++;
|
||||
c = filename;
|
||||
d = buf;
|
||||
/* paranoia is better that buffer overflows */
|
||||
while (*c && d != buf + sizeof(buf)-1) {
|
||||
if (*c == '/' && --pattern_slash_cnt < 0)
|
||||
break;
|
||||
*d++ = *c++;
|
||||
}
|
||||
*d = '\0';
|
||||
if (fnmatch(list->data, buf, 0) == 0) {
|
||||
return list;
|
||||
}
|
||||
list = list->link;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Copyright 2001 Glenn McGrath.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
char get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
int err;
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
union {
|
||||
char raw[60];
|
||||
struct {
|
||||
char name[16];
|
||||
char date[12];
|
||||
char uid[6];
|
||||
char gid[6];
|
||||
char mode[8];
|
||||
char size[10];
|
||||
char magic[2];
|
||||
} formatted;
|
||||
} ar;
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned ar_long_name_size;
|
||||
#endif
|
||||
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
/* End Of File */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* ar header starts on an even byte (2 byte aligned)
|
||||
* '\n' is used for padding
|
||||
*/
|
||||
if (ar.raw[0] == '\n') {
|
||||
/* fix up the header, we started reading 1 byte too early */
|
||||
memmove(ar.raw, &ar.raw[1], 59);
|
||||
ar.raw[59] = xread_char(archive_handle->src_fd);
|
||||
archive_handle->offset++;
|
||||
}
|
||||
archive_handle->offset += 60;
|
||||
|
||||
/* align the headers based on the header magic */
|
||||
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. 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");
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#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 = 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 */
|
||||
}
|
||||
|
||||
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 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
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
} else {
|
||||
/* short filenames */
|
||||
typed->name = xstrndup(ar.formatted.name, 16);
|
||||
}
|
||||
|
||||
typed->name[strcspn(typed->name, " /")] = '\0';
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
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);
|
||||
}
|
||||
|
||||
archive_handle->offset += typed->size;
|
||||
/* Set the file pointer to the correct spot, we may have been reading a compressed file */
|
||||
lseek(archive_handle->src_fd, archive_handle->offset, SEEK_SET);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Copyright 2002 Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
typedef struct hardlinks_s {
|
||||
char *name;
|
||||
int inode;
|
||||
struct hardlinks_s *next;
|
||||
} hardlinks_t;
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
if (archive_xread_all_eof(archive_handle, (unsigned char*)cpio_header, 110) == 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (strncmp(&cpio_header[0], "07070", 5) != 0
|
||||
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
|
||||
) {
|
||||
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
|
||||
}
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
free(file_header->name);
|
||||
file_header->name = xzalloc(namesize + 1);
|
||||
/* Read in filename */
|
||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||
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 */
|
||||
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;
|
||||
}
|
||||
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
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;
|
||||
}
|
||||
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 */
|
||||
}
|
||||
/* 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);
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,304 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* FIXME:
|
||||
* In privileged mode if uname and gname map to a uid and gid then use the
|
||||
* mapped value instead of the uid/gid values in tar header
|
||||
*
|
||||
* References:
|
||||
* GNU tar and star man pages,
|
||||
* Opengroup's ustar interchange format,
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static char *longname;
|
||||
static char *linkname;
|
||||
#else
|
||||
enum {
|
||||
longname = 0,
|
||||
linkname = 0,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
unsigned long long v;
|
||||
/* 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);
|
||||
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 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 */
|
||||
char name[100]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
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 */
|
||||
} tar;
|
||||
char *cp;
|
||||
int i, sum_u, sum;
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
int sum_s;
|
||||
#endif
|
||||
int parse_names;
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
BUG_tar_header_size();
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
again:
|
||||
#endif
|
||||
/* Align header */
|
||||
data_align(archive_handle, 512);
|
||||
|
||||
again_after_align:
|
||||
|
||||
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) {
|
||||
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)
|
||||
/* repeat */;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
end = 1;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
end = 0;
|
||||
|
||||
/* 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
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
|
||||
/* Do checksum on headers.
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source. */
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s = ' ' * sizeof(tar.chksum);
|
||||
#endif
|
||||
sum_u = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
for (i = 156; i < 512; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
#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';
|
||||
parse_names = (tar.typeflag >= '0' && tar.typeflag <= '7');
|
||||
|
||||
/* getOctal trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
unsigned minor = GET_OCTAL(tar.devminor);
|
||||
unsigned major = GET_OCTAL(tar.devmajor);
|
||||
file_header->device = makedev(major, minor);
|
||||
}
|
||||
file_header->link_target = NULL;
|
||||
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? */
|
||||
}
|
||||
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 (!longname && parse_names) {
|
||||
/* we trash mode[0] here, it's ok */
|
||||
tar.name[sizeof(tar.name)] = '\0';
|
||||
if (tar.prefix[0]) {
|
||||
/* and padding[0] */
|
||||
tar.prefix[sizeof(tar.prefix)] = '\0';
|
||||
file_header->name = concat_path_file(tar.prefix, tar.name);
|
||||
} else
|
||||
file_header->name = xstrdup(tar.name);
|
||||
}
|
||||
|
||||
/* Set bits 12-15 of the files mode */
|
||||
/* (typeflag was not trashed because chksum does not use getOctal) */
|
||||
switch (tar.typeflag) {
|
||||
/* busybox identifies hard links as being regular files with 0 size and a link name */
|
||||
case '1':
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '7':
|
||||
/* case 0: */
|
||||
case '0':
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
if (last_char_is(file_header->name, '/')) {
|
||||
file_header->mode |= S_IFDIR;
|
||||
} else
|
||||
#endif
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '2':
|
||||
file_header->mode |= S_IFLNK;
|
||||
break;
|
||||
case '3':
|
||||
file_header->mode |= S_IFCHR;
|
||||
break;
|
||||
case '4':
|
||||
file_header->mode |= S_IFBLK;
|
||||
break;
|
||||
case '5':
|
||||
file_header->mode |= S_IFDIR;
|
||||
break;
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
break;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
case 'L':
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(longname);
|
||||
/* For paranoia reasons we allocate extra NUL char */
|
||||
longname = xzalloc(file_header->size + 1);
|
||||
/* We read ASCIZ string, including NUL */
|
||||
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(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;
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive */
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
#endif
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
off_t sz;
|
||||
bb_error_msg("warning: skipping header '%c'", tar.typeflag);
|
||||
sz = (file_header->size + 511) & ~(off_t)511;
|
||||
archive_handle->offset += sz;
|
||||
sz >>= 9; /* sz /= 512 but w/o contortions for signed div */
|
||||
while (sz--)
|
||||
xread(archive_handle->src_fd, &tar, 512);
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again_after_align;
|
||||
}
|
||||
default:
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (longname) {
|
||||
file_header->name = longname;
|
||||
longname = NULL;
|
||||
}
|
||||
if (linkname) {
|
||||
file_header->link_target = linkname;
|
||||
linkname = NULL;
|
||||
}
|
||||
#endif
|
||||
if (!strncmp(file_header->name, "/../"+1, 3)
|
||||
|| strstr(file_header->name, "/../")
|
||||
) {
|
||||
bb_error_msg_and_die("name with '..' encountered: '%s'",
|
||||
file_header->name);
|
||||
}
|
||||
|
||||
/* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if it's a directory */
|
||||
cp = last_char_is(file_header->name, '/');
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(archive_handle->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->flags |= ARCHIVE_EXTRACT_QUIET;
|
||||
archive_handle->action_data(archive_handle);
|
||||
llist_add_to(&(archive_handle->passed), file_header->name);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
free(file_header->name);
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
/* Do not free(file_header->name)! */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
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;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
#if BB_MMU
|
||||
unsigned char magic[2];
|
||||
#endif
|
||||
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
/* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
|
||||
* Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
|
||||
* need the header. */
|
||||
#if BB_MMU
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
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;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void header_list(const file_header_t *file_header)
|
||||
{
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void header_skip(const file_header_t *file_header ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm *mtime = localtime(&(file_header->mtime));
|
||||
|
||||
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
file_header->uid,
|
||||
file_header->gid,
|
||||
file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
if (file_header->link_target) {
|
||||
printf(" -> %s", file_header->link_target);
|
||||
}
|
||||
bb_putchar('\n');
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
archive_handle_t *init_handle(void)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
/* Initialize default values */
|
||||
archive_handle = xzalloc(sizeof(archive_handle_t));
|
||||
archive_handle->file_header = xzalloc(sizeof(file_header_t));
|
||||
archive_handle->action_header = header_skip;
|
||||
archive_handle->action_data = data_skip;
|
||||
archive_handle->filter = filter_accept_all;
|
||||
archive_handle->seek = seek_by_jump;
|
||||
|
||||
return archive_handle;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
/*
|
||||
* On MMU machine, the transform_prog and ... are stripped
|
||||
* by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
|
||||
*/
|
||||
int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
|
||||
const char *transform_prog, ...)
|
||||
{
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
|
||||
xpipe(fd_pipe);
|
||||
|
||||
#if BB_MMU
|
||||
pid = fork();
|
||||
#else
|
||||
pid = 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[0]); /* We don't wan't to read from the parent */
|
||||
// FIXME: error check?
|
||||
#if BB_MMU
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
}
|
||||
exit(0);
|
||||
#else
|
||||
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[1]); /* Don't want to write to the child */
|
||||
|
||||
return fd_pipe[0];
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
/* 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 seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
char magic[7];
|
||||
|
||||
xread(ar_archive->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += 7;
|
||||
|
||||
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
|
||||
}
|
||||
-398
@@ -1,398 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini rpm applet for busybox
|
||||
*
|
||||
* Copyright (C) 2001,2002 by Laurence Anderson
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_CHAR_TYPE 1
|
||||
#define RPM_INT8_TYPE 2
|
||||
#define RPM_INT16_TYPE 3
|
||||
#define RPM_INT32_TYPE 4
|
||||
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
|
||||
#define RPM_STRING_TYPE 6
|
||||
#define RPM_BIN_TYPE 7
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
|
||||
#define TAG_NAME 1000
|
||||
#define TAG_VERSION 1001
|
||||
#define TAG_RELEASE 1002
|
||||
#define TAG_SUMMARY 1004
|
||||
#define TAG_DESCRIPTION 1005
|
||||
#define TAG_BUILDTIME 1006
|
||||
#define TAG_BUILDHOST 1007
|
||||
#define TAG_SIZE 1009
|
||||
#define TAG_VENDOR 1011
|
||||
#define TAG_LICENSE 1014
|
||||
#define TAG_PACKAGER 1015
|
||||
#define TAG_GROUP 1016
|
||||
#define TAG_URL 1020
|
||||
#define TAG_PREIN 1023
|
||||
#define TAG_POSTIN 1024
|
||||
#define TAG_FILEFLAGS 1037
|
||||
#define TAG_FILEUSERNAME 1039
|
||||
#define TAG_FILEGROUPNAME 1040
|
||||
#define TAG_SOURCERPM 1044
|
||||
#define TAG_PREINPROG 1085
|
||||
#define TAG_POSTINPROG 1086
|
||||
#define TAG_PREFIXS 1098
|
||||
#define TAG_DIRINDEXES 1116
|
||||
#define TAG_BASENAMES 1117
|
||||
#define TAG_DIRNAMES 1118
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
|
||||
enum rpm_functions_e {
|
||||
rpm_query = 1,
|
||||
rpm_install = 2,
|
||||
rpm_query_info = 4,
|
||||
rpm_query_package = 8,
|
||||
rpm_query_list = 16,
|
||||
rpm_query_list_doc = 32,
|
||||
rpm_query_list_config = 64
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t tag; /* 4 byte tag */
|
||||
uint32_t type; /* 4 byte type */
|
||||
uint32_t offset; /* 4 byte offset */
|
||||
uint32_t count; /* 4 byte count */
|
||||
} rpm_index;
|
||||
|
||||
static void *map;
|
||||
static rpm_index **mytags;
|
||||
static int tagcount;
|
||||
|
||||
static void extract_cpio_gz(int fd);
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
static int bsearch_rpmtag(const void *key, const void *item);
|
||||
static char *rpm_getstr(int tag, int itemindex);
|
||||
static int rpm_getint(int tag, int itemindex);
|
||||
static int rpm_getcount(int tag);
|
||||
static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
const int pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (!argc) bb_show_usage();
|
||||
|
||||
while (*argv) {
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, &tagcount);
|
||||
if (!mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
offset = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
/* Mimimum is one page */
|
||||
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio_gz(rpm_fd);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate;
|
||||
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 = 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));
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mytags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extract_cpio_gz(int fd)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned char magic[2];
|
||||
#if BB_MMU
|
||||
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
|
||||
enum { xformer_prog = 0 };
|
||||
#else
|
||||
enum { xformer = 0 };
|
||||
const char *xformer_prog;
|
||||
#endif
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_read;
|
||||
//archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
archive_handle->src_fd = fd;
|
||||
archive_handle->offset = 0;
|
||||
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
#if BB_MMU
|
||||
xformer = unpack_gz_stream;
|
||||
#else
|
||||
xformer_prog = "gunzip";
|
||||
#endif
|
||||
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;
|
||||
#else
|
||||
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
|
||||
* have the file position at the start of the file */
|
||||
xlseek(archive_handle->src_fd, 0, SEEK_SET);
|
||||
#endif
|
||||
}
|
||||
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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(struct rpmtag *));
|
||||
int pass, tagindex = 0;
|
||||
|
||||
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
/* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
struct {
|
||||
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) */
|
||||
} header;
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
xread(fd, &header, sizeof(header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0)
|
||||
return NULL; /* Invalid magic */
|
||||
if (header.version != 1)
|
||||
return NULL; /* This program only supports v1 headers */
|
||||
header.size = ntohl(header.size);
|
||||
header.entries = ntohl(header.entries);
|
||||
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
|
||||
while (header.entries--) {
|
||||
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)
|
||||
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)
|
||||
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
}
|
||||
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 */
|
||||
}
|
||||
|
||||
static int bsearch_rpmtag(const void *key, const void *item)
|
||||
{
|
||||
int *tag = (int *)key;
|
||||
rpm_index **tmp = (rpm_index **) item;
|
||||
return (*tag - tmp[0]->tag);
|
||||
}
|
||||
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
}
|
||||
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
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);
|
||||
for (n=0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
int *tmpint; /* NB: using int8_t* would be easier to code */
|
||||
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (int *) (map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
/*return ntohl(*tmpint);*/
|
||||
/* int can be != int32_t */
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*2);
|
||||
/* ??? read int, and THEN ntohs() it?? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex);
|
||||
/* ??? why we don't read byte here??? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void fileaction_dobackup(char *filename, int fileref)
|
||||
{
|
||||
struct stat oldfile;
|
||||
int stat_res;
|
||||
char *newname;
|
||||
if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) {
|
||||
/* Only need to backup config files */
|
||||
stat_res = lstat(filename, &oldfile);
|
||||
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) {
|
||||
/* File already exists - really should check MD5's etc to see if different */
|
||||
newname = xasprintf("%s.rpmorig", filename);
|
||||
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
|
||||
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
|
||||
free(newname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void fileaction_setowngrp(char *filename, int fileref)
|
||||
{
|
||||
int uid, gid;
|
||||
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
|
||||
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
|
||||
chown(filename, uid, gid);
|
||||
}
|
||||
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
|
||||
{
|
||||
int count = 0;
|
||||
while (rpm_getstr(filetag, count)) {
|
||||
char* filename = xasprintf("%s%s",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)),
|
||||
rpm_getstr(TAG_BASENAMES, count));
|
||||
fileaction(filename, count++);
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
-954
@@ -1,954 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini tar implementation for busybox
|
||||
*
|
||||
* Modified to use common extraction code used by ar, cpio, dpkg-deb, dpkg
|
||||
* by Glenn McGrath
|
||||
*
|
||||
* Note, that as of BusyBox-0.43, tar has been completely rewritten from the
|
||||
* ground up. It still has remnants of the old code lying about, but it is
|
||||
* very different now (i.e., cleaner, less global variables, etc.)
|
||||
*
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* Based in part in the tar implementation in sash
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
* Permission to distribute sash derived code under the GPL has been granted.
|
||||
*
|
||||
* Based in part on the tar implementation from busybox-0.28
|
||||
* Copyright (C) 1995 Bruce Perens
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
/* Tar file constants */
|
||||
|
||||
#define TAR_BLOCK_SIZE 512
|
||||
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
#define NAME_SIZE 100
|
||||
#define NAME_SIZE_STR "100"
|
||||
typedef struct TarHeader TarHeader;
|
||||
struct TarHeader { /* byte offset */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[NAME_SIZE]; /* 157-256 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
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 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 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 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 TarFileType {
|
||||
REGTYPE = '0', /* regular file */
|
||||
REGTYPE0 = '\0', /* regular file (ancient bug compat) */
|
||||
LNKTYPE = '1', /* hard link */
|
||||
SYMTYPE = '2', /* symbolic link */
|
||||
CHRTYPE = '3', /* character special */
|
||||
BLKTYPE = '4', /* block special */
|
||||
DIRTYPE = '5', /* directory */
|
||||
FIFOTYPE = '6', /* FIFO special */
|
||||
CONTTYPE = '7', /* reserved */
|
||||
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,
|
||||
struct stat *statbuf,
|
||||
const char *fileName)
|
||||
{
|
||||
/* Note: hlInfoHeadPtr can never be NULL! */
|
||||
HardLinkInfo *hlInfo;
|
||||
|
||||
hlInfo = xmalloc(sizeof(HardLinkInfo) + strlen(fileName));
|
||||
hlInfo->next = *hlInfoHeadPtr;
|
||||
*hlInfoHeadPtr = hlInfo;
|
||||
hlInfo->dev = statbuf->st_dev;
|
||||
hlInfo->ino = statbuf->st_ino;
|
||||
hlInfo->linkCount = statbuf->st_nlink;
|
||||
strcpy(hlInfo->name, fileName);
|
||||
}
|
||||
|
||||
static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
|
||||
{
|
||||
HardLinkInfo *hlInfo;
|
||||
HardLinkInfo *hlInfoNext;
|
||||
|
||||
if (hlInfoHeadPtr) {
|
||||
hlInfo = *hlInfoHeadPtr;
|
||||
while (hlInfo) {
|
||||
hlInfoNext = hlInfo->next;
|
||||
free(hlInfo);
|
||||
hlInfo = hlInfoNext;
|
||||
}
|
||||
*hlInfoHeadPtr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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))
|
||||
break;
|
||||
hlInfo = hlInfo->next;
|
||||
}
|
||||
return hlInfo;
|
||||
}
|
||||
|
||||
/* Put an octal string into the specified buffer.
|
||||
* The number is zero padded and possibly null terminated.
|
||||
* 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 *tempString = tempBuffer;
|
||||
int width;
|
||||
|
||||
width = sprintf(tempBuffer, "%0*"OFF_FMT"o", len, value);
|
||||
tempString += (width - len);
|
||||
|
||||
/* If string has leading zeroes, we can drop one */
|
||||
/* and field will have trailing '\0' */
|
||||
/* (increases chances of compat with other tars) */
|
||||
if (tempString[0] == '0')
|
||||
tempString++;
|
||||
|
||||
/* Copy the string to the field */
|
||||
memcpy(cp, tempString, len);
|
||||
}
|
||||
#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b))
|
||||
|
||||
static void chksum_and_xwrite(int fd, struct TarHeader* hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
int chksum, size;
|
||||
|
||||
strcpy(hp->magic, "ustar ");
|
||||
|
||||
/* Calculate and store the checksum (i.e., the sum of all of the bytes of
|
||||
* the header). The checksum field must be filled with blanks for the
|
||||
* calculation. The checksum field is formatted differently from the
|
||||
* other fields: it has 6 digits, a null, then a space -- rather than
|
||||
* digits, followed by a null like the other fields... */
|
||||
memset(hp->chksum, ' ', sizeof(hp->chksum));
|
||||
cp = (const unsigned char *) hp;
|
||||
chksum = 0;
|
||||
size = sizeof(*hp);
|
||||
do { chksum += *cp++; } while (--size);
|
||||
putOctal(hp->chksum, sizeof(hp->chksum)-1, chksum);
|
||||
|
||||
/* Now write the header out to disk */
|
||||
xwrite(fd, hp, sizeof(*hp));
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static void writeLongname(int fd, int type, const char *name, int dir)
|
||||
{
|
||||
static const struct {
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
} prefilled = {
|
||||
"0000000",
|
||||
"0000000",
|
||||
"0000000",
|
||||
"00000000000",
|
||||
"00000000000",
|
||||
};
|
||||
struct TarHeader header;
|
||||
int size;
|
||||
|
||||
dir = !!dir; /* normalize: 0/1 */
|
||||
size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */
|
||||
/* + dir: account for possible '/' */
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
strcpy(header.name, "././@LongLink");
|
||||
memcpy(header.mode, prefilled.mode, sizeof(prefilled));
|
||||
PUT_OCTAL(header.size, size);
|
||||
header.typeflag = type;
|
||||
chksum_and_xwrite(fd, &header);
|
||||
|
||||
/* Write filename[/] and pad the block. */
|
||||
/* dir=0: writes 'name<NUL>', pads */
|
||||
/* dir=1: writes 'name', writes '/<NUL>', pads */
|
||||
dir *= 2;
|
||||
xwrite(fd, name, size - dir);
|
||||
xwrite(fd, "/", dir);
|
||||
size = (-size) & (TAR_BLOCK_SIZE-1);
|
||||
memset(&header, 0, size);
|
||||
xwrite(fd, &header, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write out a tar header for the specified file/directory/whatever */
|
||||
void BUG_tar_header_size(void);
|
||||
static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
const char *header_name, const char *fileName, struct stat *statbuf)
|
||||
{
|
||||
struct TarHeader header;
|
||||
|
||||
if (sizeof(header) != 512)
|
||||
BUG_tar_header_size();
|
||||
|
||||
memset(&header, 0, sizeof(struct TarHeader));
|
||||
|
||||
strncpy(header.name, header_name, sizeof(header.name));
|
||||
|
||||
/* POSIX says to mask mode with 07777. */
|
||||
PUT_OCTAL(header.mode, statbuf->st_mode & 07777);
|
||||
PUT_OCTAL(header.uid, statbuf->st_uid);
|
||||
PUT_OCTAL(header.gid, statbuf->st_gid);
|
||||
memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */
|
||||
PUT_OCTAL(header.mtime, statbuf->st_mtime);
|
||||
|
||||
/* Enter the user and group names */
|
||||
safe_strncpy(header.uname, get_cached_username(statbuf->st_uid), sizeof(header.uname));
|
||||
safe_strncpy(header.gname, get_cached_groupname(statbuf->st_gid), sizeof(header.gname));
|
||||
|
||||
if (tbInfo->hlInfo) {
|
||||
/* This is a hard link */
|
||||
header.typeflag = LNKTYPE;
|
||||
strncpy(header.linkname, tbInfo->hlInfo->name,
|
||||
sizeof(header.linkname));
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* Write out long linkname if needed */
|
||||
if (header.linkname[sizeof(header.linkname)-1])
|
||||
writeLongname(tbInfo->tarFd, GNULONGLINK,
|
||||
tbInfo->hlInfo->name, 0);
|
||||
#endif
|
||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(fileName);
|
||||
if (!lpath)
|
||||
return FALSE;
|
||||
header.typeflag = SYMTYPE;
|
||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* Write out long linkname if needed */
|
||||
if (header.linkname[sizeof(header.linkname)-1])
|
||||
writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0);
|
||||
#else
|
||||
/* If it is larger than 100 bytes, bail out */
|
||||
if (header.linkname[sizeof(header.linkname)-1]) {
|
||||
free(lpath);
|
||||
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
free(lpath);
|
||||
} else if (S_ISDIR(statbuf->st_mode)) {
|
||||
header.typeflag = DIRTYPE;
|
||||
/* Append '/' only if there is a space for it */
|
||||
if (!header.name[sizeof(header.name)-1])
|
||||
header.name[strlen(header.name)] = '/';
|
||||
} else if (S_ISCHR(statbuf->st_mode)) {
|
||||
header.typeflag = CHRTYPE;
|
||||
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
|
||||
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
|
||||
} else if (S_ISBLK(statbuf->st_mode)) {
|
||||
header.typeflag = BLKTYPE;
|
||||
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
|
||||
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
|
||||
} else if (S_ISFIFO(statbuf->st_mode)) {
|
||||
header.typeflag = FIFOTYPE;
|
||||
} else if (S_ISREG(statbuf->st_mode)) {
|
||||
if (sizeof(statbuf->st_size) > 4
|
||||
&& statbuf->st_size > (off_t)0777777777777LL
|
||||
) {
|
||||
bb_error_msg_and_die("cannot store file '%s' "
|
||||
"of size %"OFF_FMT"d, aborting",
|
||||
fileName, statbuf->st_size);
|
||||
}
|
||||
header.typeflag = REGTYPE;
|
||||
PUT_OCTAL(header.size, statbuf->st_size);
|
||||
} else {
|
||||
bb_error_msg("%s: unknown file type", fileName);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* Write out long name if needed */
|
||||
/* (we, like GNU tar, output long linkname *before* long name) */
|
||||
if (header.name[sizeof(header.name)-1])
|
||||
writeLongname(tbInfo->tarFd, GNULONGNAME,
|
||||
header_name, S_ISDIR(statbuf->st_mode));
|
||||
#endif
|
||||
|
||||
/* Now write the header out to disk */
|
||||
chksum_and_xwrite(tbInfo->tarFd, &header);
|
||||
|
||||
/* Now do the verbose thing (or not) */
|
||||
if (tbInfo->verboseFlag) {
|
||||
FILE *vbFd = stdout;
|
||||
|
||||
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" */
|
||||
/* '/' is probably a GNUism */
|
||||
fprintf(vbFd, "%s%s\n", header_name,
|
||||
S_ISDIR(statbuf->st_mode) ? "/" : "");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
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)
|
||||
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)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
excluded_files = excluded_files->link;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#define exclude_file(excluded_files, file) 0
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
/* Strip leading '/' (must be before memorizing hardlink's name) */
|
||||
header_name = fileName;
|
||||
while (header_name[0] == '/') {
|
||||
static smallint warned;
|
||||
|
||||
if (!warned) {
|
||||
bb_error_msg("removing leading '/' from member names");
|
||||
warned = 1;
|
||||
}
|
||||
header_name++;
|
||||
}
|
||||
|
||||
if (header_name[0] == '\0')
|
||||
return TRUE;
|
||||
|
||||
/* It is against the rules to archive a socket */
|
||||
if (S_ISSOCK(statbuf->st_mode)) {
|
||||
bb_error_msg("%s: socket ignored", fileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if we are dealing with a hard link.
|
||||
* If so -
|
||||
* Treat the first occurance of a given dev/inode as a file while
|
||||
* treating any additional occurances as hard links. This is done
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
if (statbuf->st_nlink > 1) {
|
||||
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
|
||||
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->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;
|
||||
}
|
||||
|
||||
if (exclude_file(tbInfo->excludeList, header_name))
|
||||
return SKIP;
|
||||
|
||||
#if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (strlen(header_name) >= NAME_SIZE) {
|
||||
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Is this a regular file? */
|
||||
if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
inputFileFd = open_or_warn(fileName, O_RDONLY);
|
||||
if (inputFileFd < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add an entry to the tarball */
|
||||
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If it was a regular file, write out the body */
|
||||
if (inputFileFd >= 0) {
|
||||
size_t readSize;
|
||||
/* Write the file to the archive. */
|
||||
/* We record size into header first, */
|
||||
/* and then write out file. If file shrinks in between, */
|
||||
/* tar will be corrupted. So we don't allow for that. */
|
||||
/* NB: GNU tar 1.16 warns and pads with zeroes */
|
||||
/* or even seeks back and updates header */
|
||||
bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////off_t readSize;
|
||||
////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////if (readSize != statbuf->st_size && readSize >= 0) {
|
||||
//// bb_error_msg_and_die("short read from %s, aborting", fileName);
|
||||
////}
|
||||
|
||||
/* Check that file did not grow in between? */
|
||||
/* if (safe_read(inputFileFd, 1) == 1) warn but continue? */
|
||||
|
||||
close(inputFileFd);
|
||||
|
||||
/* Pad the file up to the tar block size */
|
||||
/* (a few tricks here in the name of code size) */
|
||||
readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1);
|
||||
memset(block_buf, 0, readSize);
|
||||
xwrite(tbInfo->tarFd, block_buf, readSize);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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.statBuf) < 0)
|
||||
bb_perror_msg_and_die("cannot stat tar file");
|
||||
|
||||
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;
|
||||
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, ACTION_RECURSE |
|
||||
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0))
|
||||
{
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
include = include->link;
|
||||
}
|
||||
/* Write two empty blocks to the end of the archive */
|
||||
memset(block_buf, 0, 2*TAR_BLOCK_SIZE);
|
||||
xwrite(tbInfo.tarFd, block_buf, 2*TAR_BLOCK_SIZE);
|
||||
|
||||
/* To be pedantically correct, we would check if the tarball
|
||||
* is smaller than 20 tar blocks, and pad it if it was smaller,
|
||||
* but that isn't necessary for GNU tar interoperability, and
|
||||
* so is considered a waste of space */
|
||||
|
||||
/* Close so the child process (if any) will exit */
|
||||
close(tbInfo.tarFd);
|
||||
|
||||
/* Hang up the tools, close up shop, head home */
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
||||
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
if (gzipPid) {
|
||||
int status;
|
||||
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;
|
||||
}
|
||||
return errorFlag;
|
||||
}
|
||||
#else
|
||||
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 (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)
|
||||
*cp = '\0';
|
||||
llist_add_to(&newlist, line);
|
||||
}
|
||||
fclose(src_stream);
|
||||
}
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
#define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
#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;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(archive_handle->src_fd) != 0x1f
|
||||
|| xread_char(archive_handle->src_fd) != 0x9d
|
||||
) {
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
#define get_header_tar_Z NULL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* Looks like it isn't needed - tar detects malformed (truncated)
|
||||
* archive if e.g. bunzip2 fails */
|
||||
static int child_error;
|
||||
|
||||
static void handle_SIGCHLD(int status)
|
||||
{
|
||||
/* Actually, 'status' is a signo. We reuse it for other needs */
|
||||
|
||||
/* Wait for any child without blocking */
|
||||
if (waitpid(-1, &status, WNOHANG) < 0)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
||||
/* child exited with 0 */
|
||||
return;
|
||||
/* Cannot happen?
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
|
||||
child_error = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum {
|
||||
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,
|
||||
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_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 =
|
||||
"list\0" No_argument "t"
|
||||
"extract\0" No_argument "x"
|
||||
"directory\0" Required_argument "C"
|
||||
"file\0" Required_argument "f"
|
||||
"to-stdout\0" No_argument "O"
|
||||
"same-permissions\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
"keep-old\0" No_argument "k"
|
||||
# if ENABLE_FEATURE_TAR_CREATE
|
||||
"create\0" No_argument "c"
|
||||
"dereference\0" No_argument "h"
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_BZIP2
|
||||
"bzip2\0" No_argument "j"
|
||||
# endif
|
||||
# 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_TAR_GZIP
|
||||
"gzip\0" No_argument "z"
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_COMPRESS
|
||||
"compress\0" No_argument "Z"
|
||||
# endif
|
||||
"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 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
|
||||
;
|
||||
#endif
|
||||
|
||||
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int tar_main(int argc, char **argv)
|
||||
{
|
||||
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
|
||||
archive_handle_t *tar_handle;
|
||||
char *base_dir = NULL;
|
||||
const char *tar_filename = "-";
|
||||
unsigned opt;
|
||||
int verboseFlag = 0;
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
llist_t *excludes = NULL;
|
||||
#endif
|
||||
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
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
|
||||
"tt:vv:" // count -t,-v
|
||||
"?:" // bail out with usage instead of error return
|
||||
"X::T::" // cumulative lists
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
"\xff::" // cumulative lists for --exclude
|
||||
#endif
|
||||
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
|
||||
opt = getopt32(argv,
|
||||
"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
|
||||
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
|
||||
);
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
if (verboseFlag == 1) tar_handle->action_header = header_list;
|
||||
|
||||
if (opt & OPT_EXTRACT)
|
||||
tar_handle->action_data = data_extract_all;
|
||||
|
||||
if (opt & OPT_2STDOUT)
|
||||
tar_handle->action_data = data_extract_to_stdout;
|
||||
|
||||
if (opt & OPT_KEEP_OLD)
|
||||
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_OWN)
|
||||
tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_PERM)
|
||||
tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM;
|
||||
|
||||
if (opt & OPT_GZIP)
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
|
||||
if (opt & OPT_BZIP2)
|
||||
get_header_ptr = get_header_tar_bz2;
|
||||
|
||||
if (opt & OPT_LZMA)
|
||||
get_header_ptr = get_header_tar_lzma;
|
||||
|
||||
if (opt & OPT_COMPRESS)
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
}
|
||||
#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, separate function ? */
|
||||
while (optind < argc) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
char *cp = last_char_is(argv[optind], '/');
|
||||
if (cp > argv[optind])
|
||||
*cp = '\0';
|
||||
llist_add_to_end(&tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
if (tar_handle->accept || tar_handle->reject)
|
||||
tar_handle->filter = filter_accept_reject_list;
|
||||
|
||||
/* Open the tar file */
|
||||
{
|
||||
FILE *tar_stream;
|
||||
int flags;
|
||||
|
||||
if (opt & OPT_CREATE) {
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
if (tar_handle->accept == NULL)
|
||||
bb_error_msg_and_die("empty archive");
|
||||
|
||||
tar_stream = stdout;
|
||||
/* Mimicking GNU tar 1.15.1: */
|
||||
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 = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
tar_handle->src_fd = xopen(tar_filename, flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
signal(SIGCHLD, handle_SIGCHLD);
|
||||
#endif
|
||||
|
||||
/* create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_TAR_GZIP && get_header_ptr == get_header_tar_gz)
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
|
||||
zipMode = 2;
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
}
|
||||
|
||||
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
|
||||
/* nothing */;
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
|
||||
&& !find_list_entry(tar_handle->passed, tar_handle->accept->data)
|
||||
) {
|
||||
bb_error_msg_and_die("%s: not found in archive",
|
||||
tar_handle->accept->data);
|
||||
}
|
||||
tar_handle->accept = tar_handle->accept->link;
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */)
|
||||
close(tar_handle->src_fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,408 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini unzip implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2004 by Ed Clark
|
||||
*
|
||||
* Loosely based on original busybox unzip applet by Laurence Anderson.
|
||||
* All options and features should work in this version.
|
||||
*
|
||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
/* For reference see
|
||||
* http://www.pkware.com/company/standards/appnote/
|
||||
* http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
|
||||
*/
|
||||
|
||||
/* 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"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDS_MAGIC = 0x504b0102,
|
||||
ZIP_CDS_END_MAGIC = 0x504b0506,
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
ZIP_CDS_MAGIC = 0x02014b50,
|
||||
ZIP_CDS_END_MAGIC = 0x06054b50,
|
||||
ZIP_DD_MAGIC = 0x08074b50,
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ZIP_HEADER_LEN 26
|
||||
|
||||
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 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,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
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];
|
||||
};
|
||||
|
||||
#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 ); \
|
||||
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
|
||||
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
|
||||
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
|
||||
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
|
||||
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
|
||||
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
|
||||
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
|
||||
} while (0)
|
||||
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
|
||||
static void unzip_create_leading_dirs(const char *fn)
|
||||
{
|
||||
/* Create all leading directories */
|
||||
char *name = xstrdup(fn);
|
||||
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
|
||||
bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
|
||||
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(src_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_unzip_result res;
|
||||
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)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != res.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
smallint verbose = 1;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
unsigned total_size;
|
||||
unsigned total_entries;
|
||||
int src_fd = -1;
|
||||
int dst_fd = -1;
|
||||
char *src_fn = NULL;
|
||||
char *dst_fn = NULL;
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
int i, opt;
|
||||
int opt_range = 0;
|
||||
char key_buf[80];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
case 'l': /* List */
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
case 'n': /* Never overwrite existing files */
|
||||
overwrite = O_NEVER;
|
||||
break;
|
||||
|
||||
case 'o': /* Always overwrite existing files */
|
||||
overwrite = O_ALWAYS;
|
||||
break;
|
||||
|
||||
case 'p': /* Extract files to stdout and fall through to set verbosity */
|
||||
dst_fd = STDOUT_FILENO;
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
verbose = 0;
|
||||
break;
|
||||
|
||||
case 1: /* The zip file */
|
||||
/* +5: space for ".zip" and NUL */
|
||||
src_fn = xmalloc(strlen(optarg) + 5);
|
||||
strcpy(src_fn, optarg);
|
||||
opt_range++;
|
||||
break;
|
||||
|
||||
default:
|
||||
bb_show_usage();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* Include files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zaccept, optarg);
|
||||
break;
|
||||
}
|
||||
if (opt == 'd') {
|
||||
base_dir = optarg;
|
||||
opt_range += 2;
|
||||
break;
|
||||
}
|
||||
if (opt == 'x') {
|
||||
opt_range++;
|
||||
break;
|
||||
}
|
||||
bb_show_usage();
|
||||
|
||||
case 2 : /* Exclude files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zreject, optarg);
|
||||
break;
|
||||
}
|
||||
if (opt == 'd') { /* Extract to base directory */
|
||||
base_dir = optarg;
|
||||
opt_range++;
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (src_fn == NULL) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* Open input file */
|
||||
if (LONE_DASH(src_fn)) {
|
||||
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);
|
||||
|
||||
for (i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
strcpy(src_fn + orig_src_fn_len, extn[i]);
|
||||
src_fd = open(src_fn, O_RDONLY);
|
||||
}
|
||||
if (src_fd == -1) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Change dir if necessary */
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
if (verbose) {
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
}
|
||||
}
|
||||
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
while (1) {
|
||||
uint32_t magic;
|
||||
|
||||
/* Check magic number */
|
||||
xread(src_fd, &magic, 4);
|
||||
if (magic == ZIP_CDS_MAGIC)
|
||||
break;
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", magic);
|
||||
|
||||
/* Read the file 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);
|
||||
}
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
|
||||
xread(src_fd, dst_fn, zip_header.formatted.filename_len);
|
||||
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
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 {
|
||||
/* short listing -- filenames only */
|
||||
puts(dst_fn);
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
|
||||
}
|
||||
if (verbose) {
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
if (bb_make_directory(dst_fn, 0777, 0)) {
|
||||
bb_error_msg_and_die("exiting");
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
|
||||
}
|
||||
}
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract file */
|
||||
_check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
} else { /* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} 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("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (i) {
|
||||
case 'A':
|
||||
overwrite = O_ALWAYS;
|
||||
case 'y': /* Open file and fall into unzip */
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
case -1: /* Unzip */
|
||||
if (verbose) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_extract(&zip_header, src_fd, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
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("cannot read input");
|
||||
}
|
||||
free(dst_fn);
|
||||
dst_fn = xstrdup(key_buf);
|
||||
chomp(dst_fn);
|
||||
goto _check_file;
|
||||
|
||||
default:
|
||||
printf("error: invalid response [%c]\n",(char)i);
|
||||
goto _check_file;
|
||||
}
|
||||
|
||||
/* 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 && verbose) {
|
||||
printf(" -------- -------\n"
|
||||
"%9d %d files\n",
|
||||
total_size, total_entries);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
File renamed without changes.
@@ -8,9 +8,6 @@ incorrect, _please_ let me know.
|
||||
|
||||
-----------
|
||||
|
||||
Peter Willis <psyphreak@phreaker.net>
|
||||
eject
|
||||
|
||||
Emanuele Aina <emanuele.aina@tiscali.it>
|
||||
run-parts
|
||||
|
||||
@@ -26,9 +23,6 @@ Laurence Anderson <l.d.anderson@warwick.ac.uk>
|
||||
Jeff Angielski <jeff@theptrgroup.com>
|
||||
ftpput, ftpget
|
||||
|
||||
Enrik Berkhan <Enrik.Berkhan@inka.de>
|
||||
setconsole
|
||||
|
||||
Jim Bauer <jfbauer@nfr.com>
|
||||
modprobe shell dependency
|
||||
|
||||
@@ -38,9 +32,6 @@ Edward Betts <edward@debian.org>
|
||||
John Beppu <beppu@codepoet.org>
|
||||
du, nslookup, sort
|
||||
|
||||
David Brownell <dbrownell@users.sourceforge.net>
|
||||
zcip
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
|
||||
@@ -82,12 +73,9 @@ Matt Kraai <kraai@alumni.cmu.edu>
|
||||
documentation, bugfixes, test suite
|
||||
|
||||
Rob Landley <rob@landley.net>
|
||||
Became busybox maintainer in 2006.
|
||||
|
||||
sed (major rewrite in 2003, and I now maintain the thing)
|
||||
bunzip2 (complete from-scratch rewrite, then mjn3 optimized the result)
|
||||
sort (more or less from scratch rewrite in 2004, I now maintain it)
|
||||
mount (rewrite in 2005, I maintain the new one)
|
||||
sed (major rewrite in 2003, and I now maintain the thing).
|
||||
bunzip2 (complete from-scratch rewrite, then mjn3 optimized the result.)
|
||||
I've patched lots of other applets, but don't maintain 'em.
|
||||
|
||||
Stephan Linz <linz@li-pro.net>
|
||||
ipcalc, Red Hat equivalence
|
||||
@@ -95,15 +83,14 @@ Stephan Linz <linz@li-pro.net>
|
||||
John Lombardo <john@deltanet.com>
|
||||
tr
|
||||
|
||||
Glenn McGrath <glenn.l.mcgrath@gmail.com>
|
||||
Glenn McGrath <bug1@iinet.net.au>
|
||||
Common unarchiving code and unarchiving applets, ifupdown, ftpgetput,
|
||||
nameif, sed, patch, fold, install, uudecode.
|
||||
Various bugfixes, review and apply numerous patches.
|
||||
|
||||
Manuel Novoa III <mjn3@codepoet.org>
|
||||
cat, head, mkfifo, mknod, rmdir, sleep, tee, tty, uniq, usleep, wc, yes,
|
||||
mesg, vconfig, nice, renice,
|
||||
make_directory, parse_mode, dirname, mode_string,
|
||||
mesg, vconfig, make_directory, parse_mode, dirname, mode_string,
|
||||
get_last_path_component, simplify_path, and a number trivial libbb routines
|
||||
|
||||
also bug fixes, partial rewrites, and size optimizations in
|
||||
@@ -112,9 +99,8 @@ Manuel Novoa III <mjn3@codepoet.org>
|
||||
interface, dutmp, ifconfig, route
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
cmdedit; bb_mkdep, xargs(current), httpd(current);
|
||||
ports: ash, crond, fdisk (initial, unmaintained now), inetd, stty, traceroute,
|
||||
top;
|
||||
cmdedit; xargs(current), httpd(current);
|
||||
ports: ash, crond, fdisk, inetd, stty, traceroute, top;
|
||||
locale, various fixes
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
@@ -122,9 +108,6 @@ Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox in 1995, 1996. Some of his code can
|
||||
still be found hiding here and there...
|
||||
|
||||
Rodney Radford <rradford@mindspring.com>
|
||||
ipcs, ipcrm
|
||||
|
||||
Tim Riker <Tim@Rikers.org>
|
||||
bug fixes, member of fan club
|
||||
|
||||
@@ -140,10 +123,7 @@ Pavel Roskin <proski@gnu.org>
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
Remote logging feature for syslogd
|
||||
|
||||
Rob Sullivan <cogito.ergo.cogito@gmail.com>
|
||||
comm
|
||||
|
||||
Linus Torvalds
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Mark Whitley <markw@codepoet.org>
|
||||
@@ -157,17 +137,5 @@ Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
Tito Ragusa <farmatito@tiscali.it>
|
||||
devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm,
|
||||
fdformat, lsattr, chattr, id and eject.
|
||||
devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm and fdformat.
|
||||
|
||||
Paul Fox <pgf@foxharp.boston.ma.us>
|
||||
vi editing mode for ash, various other patches/fixes
|
||||
|
||||
Roberto A. Foglietta <me@roberto.foglietta.name>
|
||||
port: dnsd
|
||||
|
||||
Bernhard Fischer <rep.nop@aon.at>
|
||||
misc
|
||||
|
||||
Mike Frysinger <vapier@gentoo.org>
|
||||
initial e2fsprogs, printenv, setarch, sum, misc
|
||||
@@ -0,0 +1,20 @@
|
||||
1) Run 'make config' or 'make menuconfig' and select the
|
||||
functionality that you wish to enable.
|
||||
|
||||
2) Run 'make dep'
|
||||
|
||||
3) Check the Makefile for any Makefile setting you wish
|
||||
to adjust for your system (things like like setting
|
||||
your cross compiler, adjusting optimizations, etc)
|
||||
|
||||
4) Run 'make'
|
||||
|
||||
5) Go get a drink of water, drink a soda, visit the bathroom,
|
||||
or whatever while it compiles. It doesn't take very
|
||||
long to compile, so you don't really need to waste too
|
||||
much time waiting...
|
||||
|
||||
6) Run 'make install' or 'make PREFIX=/target install' to
|
||||
install busybox and all the needed links. Some people
|
||||
will prefer to install using hardlinks and will instead
|
||||
want to run 'make install-hardlinks'....
|
||||
@@ -1,11 +1,3 @@
|
||||
--- A note on GPL versions
|
||||
|
||||
BusyBox is distributed under version 2 of the General Public License (included
|
||||
in its entirety, below). Version 2 is the only version of this license which
|
||||
this version of BusyBox (or modified versions derived from this one) may be
|
||||
distributed under.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# You shouldn't need to mess with anything beyond this point...
|
||||
#--------------------------------------------------------------
|
||||
noconfig_targets := menuconfig config oldconfig randconfig \
|
||||
defconfig allyesconfig allnoconfig clean distclean \
|
||||
release tags
|
||||
|
||||
ifndef TOPDIR
|
||||
TOPDIR=$(CURDIR)/
|
||||
endif
|
||||
ifndef top_srcdir
|
||||
top_srcdir=$(CURDIR)
|
||||
endif
|
||||
ifndef top_builddir
|
||||
top_builddir=$(CURDIR)
|
||||
endif
|
||||
|
||||
export srctree=$(top_srcdir)
|
||||
vpath %/Config.in $(srctree)
|
||||
|
||||
include $(top_builddir)/Rules.mak
|
||||
|
||||
DIRS:=applets archival archival/libunarchive coreutils console-tools \
|
||||
debianutils editors findutils init miscutils modutils networking \
|
||||
networking/libiproute networking/udhcp procps loginutils shell \
|
||||
sysklogd util-linux libpwdgrp coreutils/libcoreutils libbb
|
||||
|
||||
SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS))
|
||||
|
||||
ifeq ($(strip $(CONFIG_SELINUX)),y)
|
||||
CFLAGS += -I/usr/include/selinux
|
||||
LIBRARIES += -lsecure
|
||||
endif
|
||||
|
||||
CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in
|
||||
CONFIG_DEFCONFIG = $(top_srcdir)/sysdeps/$(TARGET_OS)/defconfig
|
||||
|
||||
ALL_DIRS:= $(DIRS) scripts/config
|
||||
ALL_MAKEFILES:=$(patsubst %,%/Makefile,$(ALL_DIRS))
|
||||
|
||||
ifeq ($(KBUILD_SRC),)
|
||||
|
||||
ifdef O
|
||||
ifeq ("$(origin O)", "command line")
|
||||
KBUILD_OUTPUT := $(O)
|
||||
endif
|
||||
endif
|
||||
|
||||
# That's our default target when none is given on the command line
|
||||
.PHONY: _all
|
||||
_all:
|
||||
|
||||
ifneq ($(KBUILD_OUTPUT),)
|
||||
# Invoke a second make in the output directory, passing relevant variables
|
||||
# check that the output directory actually exists
|
||||
saved-output := $(KBUILD_OUTPUT)
|
||||
KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
|
||||
$(if $(wildcard $(KBUILD_OUTPUT)),, \
|
||||
$(error output directory "$(saved-output)" does not exist))
|
||||
|
||||
.PHONY: $(MAKECMDGOALS)
|
||||
|
||||
$(filter-out _all,$(MAKECMDGOALS)) _all: $(KBUILD_OUTPUT)/Rules.mak $(KBUILD_OUTPUT)/Makefile
|
||||
$(MAKE) -C $(KBUILD_OUTPUT) \
|
||||
top_srcdir=$(CURDIR) \
|
||||
top_builddir=$(KBUILD_OUTPUT) \
|
||||
TOPDIR=$(KBUILD_OUTPUT) \
|
||||
KBUILD_SRC=$(CURDIR) \
|
||||
-f $(CURDIR)/Makefile $@
|
||||
|
||||
$(KBUILD_OUTPUT)/Rules.mak:
|
||||
@echo > $@
|
||||
@echo top_srcdir=$(CURDIR) >> $@
|
||||
@echo top_builddir=$(KBUILD_OUTPUT) >> $@
|
||||
@echo include $(top_srcdir)/Rules.mak >> $@
|
||||
|
||||
$(KBUILD_OUTPUT)/Makefile:
|
||||
@echo > $@
|
||||
@echo top_srcdir=$(CURDIR) >> $@
|
||||
@echo top_builddir=$(KBUILD_OUTPUT) >> $@
|
||||
@echo KBUILD_SRC='$$(top_srcdir)' >> $@
|
||||
@echo include '$$(KBUILD_SRC)'/Makefile >> $@
|
||||
|
||||
# Leave processing to above invocation of make
|
||||
skip-makefile := 1
|
||||
endif # ifneq ($(KBUILD_OUTPUT),)
|
||||
endif # ifeq ($(KBUILD_SRC),)
|
||||
|
||||
ifeq ($(skip-makefile),)
|
||||
|
||||
_all: all
|
||||
|
||||
ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
all: busybox busybox.links doc
|
||||
|
||||
all_tree: $(ALL_MAKEFILES)
|
||||
|
||||
$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
|
||||
d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
|
||||
|
||||
# In this section, we need .config
|
||||
-include $(top_builddir)/.config.cmd
|
||||
include $(patsubst %,%/Makefile.in, $(SRC_DIRS))
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
busybox: $(ALL_MAKEFILES) .depend include/config.h $(libraries-y)
|
||||
$(CC) $(LDFLAGS) -o $@ -Wl,--start-group $(libraries-y) $(LIBRARIES) -Wl,--end-group
|
||||
$(STRIPCMD) $@
|
||||
|
||||
busybox.links: $(top_srcdir)/applets/busybox.mkll include/config.h $(top_srcdir)/include/applets.h
|
||||
- $(SHELL) $^ >$@
|
||||
|
||||
install: applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX)
|
||||
ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
|
||||
@echo
|
||||
@echo
|
||||
@echo --------------------------------------------------
|
||||
@echo You will probably need to make your busybox binary
|
||||
@echo setuid root to ensure all configured applets will
|
||||
@echo work properly.
|
||||
@echo --------------------------------------------------
|
||||
@echo
|
||||
endif
|
||||
|
||||
uninstall: busybox.links
|
||||
rm -f $(PREFIX)/bin/busybox
|
||||
for i in `cat busybox.links` ; do rm -f $(PREFIX)$$i; done
|
||||
|
||||
install-hardlinks: $(top_srcdir)/applets/install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX) --hardlinks
|
||||
|
||||
check: busybox
|
||||
bindir=$(top_builddir) srcdir=$(top_srcdir)/testsuite \
|
||||
$(top_srcdir)/testsuite/runtest
|
||||
|
||||
# Documentation Targets
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/busybox.pod : $(top_srcdir)/docs/busybox_header.pod $(top_srcdir)/include/usage.h $(top_srcdir)/docs/busybox_footer.pod
|
||||
-mkdir -p docs
|
||||
- ( cat $(top_srcdir)/docs/busybox_header.pod; \
|
||||
$(top_srcdir)/docs/autodocifier.pl $(top_srcdir)/include/usage.h; \
|
||||
cat $(top_srcdir)/docs/busybox_footer.pod ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
$(SECHO)
|
||||
$(SECHO) BusyBox Documentation
|
||||
$(SECHO)
|
||||
-mkdir -p docs
|
||||
-pod2text $< > $@
|
||||
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
- mkdir -p docs
|
||||
- pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
- mkdir -p docs
|
||||
-@ rm -f docs/BusyBox.html
|
||||
-@ cp docs/busybox.net/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
-@ mkdir -p docs/busybox.net
|
||||
- pod2html --noindex $< > \
|
||||
docs/busybox.net/BusyBox.html
|
||||
-@ rm -f pod2htm*
|
||||
|
||||
# The nifty new buildsystem stuff
|
||||
scripts/mkdep: $(top_srcdir)/scripts/mkdep.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
|
||||
|
||||
scripts/split-include: $(top_srcdir)/scripts/split-include.c
|
||||
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
|
||||
|
||||
.depend: scripts/mkdep include/config.h
|
||||
rm -f .depend .hdepend;
|
||||
mkdir -p include/config;
|
||||
scripts/mkdep -I include -- \
|
||||
`find $(top_srcdir) -name \*.c -print | sed -e "s,^./,,"` >> .depend;
|
||||
scripts/mkdep -I include -- \
|
||||
`find $(top_srcdir) -name \*.h -print | sed -e "s,^./,,"` >> .hdepend;
|
||||
|
||||
depend dep: .depend
|
||||
|
||||
include/config/MARKER: depend scripts/split-include
|
||||
scripts/split-include include/config.h include/config
|
||||
@ touch include/config/MARKER
|
||||
|
||||
include/config.h: .config
|
||||
@if [ ! -x $(top_builddir)/scripts/config/conf ] ; then \
|
||||
$(MAKE) -C scripts/config conf; \
|
||||
fi;
|
||||
@$(top_builddir)/scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
finished2:
|
||||
$(SECHO)
|
||||
$(SECHO) Finished installing...
|
||||
$(SECHO)
|
||||
|
||||
else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
all: menuconfig
|
||||
|
||||
# configuration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
$(ALL_MAKEFILES): %/Makefile: $(top_srcdir)/%/Makefile
|
||||
d=`dirname $@`; [ -d "$$d" ] || mkdir -p "$$d"; cp $< $@
|
||||
|
||||
scripts/config/conf: scripts/config/Makefile Rules.mak
|
||||
$(MAKE) -C scripts/config conf
|
||||
-@if [ ! -f .config ] ; then \
|
||||
cp $(CONFIG_DEFCONFIG) .config; \
|
||||
fi
|
||||
|
||||
scripts/config/mconf: scripts/config/Makefile Rules.mak
|
||||
$(MAKE) -C scripts/config ncurses conf mconf
|
||||
-@if [ ! -f .config ] ; then \
|
||||
cp $(CONFIG_DEFCONFIG) .config; \
|
||||
fi
|
||||
|
||||
menuconfig: scripts/config/mconf
|
||||
@./scripts/config/mconf $(CONFIG_CONFIG_IN)
|
||||
|
||||
config: scripts/config/conf
|
||||
@./scripts/config/conf $(CONFIG_CONFIG_IN)
|
||||
|
||||
oldconfig: scripts/config/conf
|
||||
@./scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
randconfig: scripts/config/conf
|
||||
@./scripts/config/conf -r $(CONFIG_CONFIG_IN)
|
||||
|
||||
allyesconfig: scripts/config/conf
|
||||
@./scripts/config/conf -y $(CONFIG_CONFIG_IN)
|
||||
sed -i -e "s/^CONFIG_DEBUG.*/# CONFIG_DEBUG is not set/" .config
|
||||
sed -i -e "s/^USING_CROSS_COMPILER.*/# USING_CROSS_COMPILER is not set/" .config
|
||||
sed -i -e "s/^CONFIG_STATIC.*/# CONFIG_STATIC is not set/" .config
|
||||
sed -i -e "s/^CONFIG_SELINUX.*/# CONFIG_SELINUX is not set/" .config
|
||||
@./scripts/config/conf -o $(CONFIG_CONFIG_IN)
|
||||
|
||||
allnoconfig: scripts/config/conf
|
||||
@./scripts/config/conf -n $(CONFIG_CONFIG_IN)
|
||||
|
||||
defconfig: scripts/config/conf
|
||||
@./scripts/config/conf -d $(CONFIG_CONFIG_IN)
|
||||
|
||||
clean:
|
||||
- rm -f docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pod docs/busybox.net/busybox.html \
|
||||
docs/busybox pod2htm* *.gdb *.elf *~ core .*config.log \
|
||||
docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.net/BusyBox.html busybox.links libbb/loop.h \
|
||||
.config.old .hdepend busybox
|
||||
- rm -rf _install
|
||||
- find . -name .\*.flags -exec rm -f {} \;
|
||||
- find . -name \*.o -exec rm -f {} \;
|
||||
- find . -name \*.a -exec rm -f {} \;
|
||||
|
||||
distclean: clean
|
||||
- rm -f scripts/split-include scripts/mkdep
|
||||
- rm -rf include/config include/config.h
|
||||
- find . -name .depend -exec rm -f {} \;
|
||||
rm -f .config .config.old .config.cmd
|
||||
- $(MAKE) -C scripts/config clean
|
||||
|
||||
release: distclean #doc
|
||||
cd ..; \
|
||||
rm -rf $(PROG)-$(VERSION); \
|
||||
cp -a busybox $(PROG)-$(VERSION); \
|
||||
\
|
||||
find $(PROG)-$(VERSION)/ -type d \
|
||||
-name .svn \
|
||||
-print \
|
||||
-exec rm -rf {} \; ; \
|
||||
\
|
||||
find $(PROG)-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
\
|
||||
tar -cvzf $(PROG)-$(VERSION).tar.gz $(PROG)-$(VERSION)/;
|
||||
|
||||
tags:
|
||||
ctags -R .
|
||||
|
||||
|
||||
endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
|
||||
|
||||
endif # ifeq ($(skip-makefile),)
|
||||
|
||||
.PHONY: dummy subdirs release distclean clean config oldconfig \
|
||||
menuconfig tags check test depend buildtree
|
||||
+35
-37
@@ -1,16 +1,15 @@
|
||||
Please see the LICENSE file for details on copying and usage.
|
||||
Please refer to the INSTALL file for instructions on how to build.
|
||||
|
||||
What is busybox:
|
||||
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the
|
||||
utilities you usually find in bzip2, coreutils, dhcp, diffutils, e2fsprogs,
|
||||
file, findutils, gawk, grep, inetutils, less, modutils, net-tools, procps,
|
||||
sed, shadow, sysklogd, sysvinit, tar, util-linux, and vim. The utilities
|
||||
in BusyBox often have fewer options than their full-featured cousins;
|
||||
however, the options that are included provide the expected functionality
|
||||
and behave very much like their larger counterparts.
|
||||
utilities you usually find in bzip2, coreutils, file, findutils, gawk, grep,
|
||||
inetutils, modutils, net-tools, procps, sed, shadow, sysklogd, sysvinit, tar,
|
||||
util-linux, and vim. The utilities in BusyBox often have fewer options than
|
||||
their full-featured cousins; however, the options that are included provide
|
||||
the expected functionality and behave very much like their larger
|
||||
counterparts.
|
||||
|
||||
BusyBox has been written with size-optimization and limited resources in
|
||||
mind, both to produce small binaries and to reduce run-time memory usage.
|
||||
@@ -36,12 +35,12 @@ Using busybox:
|
||||
BusyBox is extremely configurable. This allows you to include only the
|
||||
components and options you need, thereby reducing binary size. Run 'make
|
||||
config' or 'make menuconfig' to select the functionality that you wish to
|
||||
enable. (See 'make help' for more commands.)
|
||||
enable.
|
||||
|
||||
The behavior of busybox is determined by the name it's called under: as
|
||||
"cp" it behaves like cp, as "sed" it behaves like sed, and so on. Called
|
||||
as "busybox" it takes the second argument as the name of the applet to
|
||||
run (I.E. "./busybox ls -l /proc").
|
||||
run (I.E. "./busybox ls -l /proc").
|
||||
|
||||
The "standalone shell" mode is an easy way to try out busybox; this is a
|
||||
command shell that calls the builtin applets without needing them to be
|
||||
@@ -50,10 +49,9 @@ Using busybox:
|
||||
|
||||
The build automatically generates a file "busybox.links", which is used by
|
||||
'make install' to create symlinks to the BusyBox binary for all compiled in
|
||||
commands. This uses the CONFIG_PREFIX environment variable to specify
|
||||
where to install, and installs hardlinks or symlinks depending
|
||||
on the configuration preferences. (You can also manually run
|
||||
the install script at "applets/install.sh").
|
||||
commands. Use the PREFIX environment variable to specify where to install
|
||||
the busybox binary and symlink forest. (i.e., 'make PREFIX=/tmp/foo install',
|
||||
or 'make PREFIX=/tmp/foo install-hardlinks' if you prefer hard links.)
|
||||
|
||||
----------------
|
||||
|
||||
@@ -64,9 +62,10 @@ Downloading the current source code:
|
||||
|
||||
http://busybox.net/downloads/
|
||||
|
||||
You can browse the up to the minute source code and change history online.
|
||||
You can browse the up to the minute source code and change history online
|
||||
at:
|
||||
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_00_stable/busybox/
|
||||
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
|
||||
@@ -100,7 +99,7 @@ bugs:
|
||||
anyone else to duplicate the bug on their own machine. the following is such
|
||||
an example:
|
||||
|
||||
to: busybox@busybox.net
|
||||
to: busybox@mail.busybox.net
|
||||
from: diligent@testing.linux.org
|
||||
subject: /bin/date doesn't work
|
||||
|
||||
@@ -132,28 +131,27 @@ bugs:
|
||||
|
||||
Portability:
|
||||
|
||||
Busybox is developed and tested on Linux 2.4 and 2.6 kernels, compiled
|
||||
with gcc (the unit-at-a-time optimizations in version 3.4 and later are
|
||||
worth upgrading to get, but older versions should work), and linked against
|
||||
uClibc (0.9.27 or greater) or glibc (2.2 or greater). In such an
|
||||
environment, the full set of busybox features should work, and if
|
||||
anything doesn't we want to know about it so we can fix it.
|
||||
Busybox is developed and tested on Linux 2.4 and 2.6 kernels, linked
|
||||
against uClibc (0.9.27 or greater) and glibc (2.2 or greater). In such
|
||||
an environment, the full set of busybox features should work (and if
|
||||
anything doesn't we want to know about it so we can fix it). Note that
|
||||
the 2.6 kernel can be trimmed down considerably with the aid of Matt
|
||||
Mackall's -tiny work (http://www.selenic.com/tiny-about/).
|
||||
|
||||
There are many other environments out there, in which busybox may build
|
||||
and run just fine. We just don't test them. Since busybox consists of a
|
||||
large number of more or less independent applets, portability is a question
|
||||
of which features work where. Some busybox applets (such as cat and rm) are
|
||||
highly portable and likely to work just about anywhere, while others (such as
|
||||
insmod and losetup) require recent Linux kernels with recent C libraries.
|
||||
Since busybox consists of a large number of more or less independent
|
||||
applets, portability is a question of which features work where. Some
|
||||
busybox applets (such as cat and rm) are highly portable and likely to work
|
||||
just about anywhere, while others (such as insmod and losetup) are only
|
||||
likely to work under fairly recent Linux kernels with recent C libraries.
|
||||
|
||||
Earlier versions of Linux and glibc may or may not work, for any given
|
||||
configuration. Linux 2.2 or earlier should mostly work (there's still
|
||||
some support code in things like mount.c) but this is no longer regularly
|
||||
tested, and inherently won't support certain features (such as long files
|
||||
and --bind mounts). The same is true for glibc 2.0 and 2.1: expect a higher
|
||||
testing and debugging burden using such old infrastructure. (The busybox
|
||||
developers are not very interested in supporting these older versions, but
|
||||
will probably accept small self-contained patches to fix simple problems.)
|
||||
configuration. Linux 2.2 or earlier should mostly work, but this is no
|
||||
longer regularly tested and inherently won't support certain features (such
|
||||
as long files and --bind mounts). The same is true for glibc 2.0 and 2.1,
|
||||
expect a higher testing and debugging burden using such old infrastructure.
|
||||
(The busybox developers are not very interested in supporting these older
|
||||
versions, but can probably be talked into accepting small patches to fix
|
||||
simple problems.)
|
||||
|
||||
Some environments are not recommended. Early versions of uClibc were buggy
|
||||
and missing many features: upgrade. Linking against libc5 or dietlibc is
|
||||
@@ -194,5 +192,5 @@ Supported hardware:
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to the busybox
|
||||
maintainer:
|
||||
Denis Vlasenko
|
||||
<vda.linux@googlemail.com>
|
||||
Erik Andersen
|
||||
<andersen@codepoet.org>
|
||||
@@ -0,0 +1,200 @@
|
||||
# Rules.make for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
#--------------------------------------------------------
|
||||
PROG := busybox
|
||||
VERSION := 1.01
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
|
||||
|
||||
#--------------------------------------------------------
|
||||
# With a modern GNU make(1) (highly recommended, that's what all the
|
||||
# developers use), all of the following configuration values can be
|
||||
# overridden at the command line. For example:
|
||||
# make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
|
||||
#--------------------------------------------------------
|
||||
|
||||
# If you are running a cross compiler, you will want to set 'CROSS'
|
||||
# to something more interesting... Target architecture is determined
|
||||
# by asking the CC compiler what arch it compiles things for, so unless
|
||||
# your compiler is broken, you should not need to specify TARGET_ARCH
|
||||
CROSS =$(subst ",, $(strip $(CROSS_COMPILER_PREFIX)))
|
||||
CC = $(CROSS)gcc
|
||||
AR = $(CROSS)ar
|
||||
AS = $(CROSS)as
|
||||
LD = $(CROSS)ld
|
||||
NM = $(CROSS)nm
|
||||
STRIP = $(CROSS)strip
|
||||
CPP = $(CC) -E
|
||||
# MAKEFILES = $(top_builddir)/.config
|
||||
|
||||
# What OS are you compiling busybox for? This allows you to include
|
||||
# OS specific things, syscall overrides, etc.
|
||||
TARGET_OS=linux
|
||||
|
||||
# Select the compiler needed to build binaries for your development system
|
||||
HOSTCC = gcc
|
||||
HOSTCFLAGS= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
|
||||
|
||||
# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
|
||||
LC_ALL:= C
|
||||
|
||||
# If you want to add some simple compiler switches (like -march=i686),
|
||||
# especially from the command line, use this instead of CFLAGS directly.
|
||||
# For optimization overrides, it's better still to set OPTIMIZATION.
|
||||
CFLAGS_EXTRA=$(subst ",, $(strip $(EXTRA_CFLAGS_OPTIONS)))
|
||||
|
||||
# If you have a "pristine" source directory, point BB_SRC_DIR to it.
|
||||
# Experimental and incomplete; tell the mailing list
|
||||
# <busybox@busybox.net> if you do or don't like it so far.
|
||||
BB_SRC_DIR=
|
||||
|
||||
# To compile vs some other alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs...
|
||||
#
|
||||
# If you are using Red Hat 6.x with the compatible RPMs (for developing under
|
||||
# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
|
||||
# using the compatible RPMs (compat-*) at http://www.redhat.com !
|
||||
#LIBCDIR:=/usr/i386-glibc20-linux
|
||||
#
|
||||
# For other libraries, you are on your own. But these may (or may not) help...
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES:=$(LIBCDIR)/lib/libc.a -lgcc
|
||||
#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
|
||||
#GCCINCDIR:=$(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
|
||||
WARNINGS=-Wall -Wstrict-prototypes -Wshadow
|
||||
CFLAGS=-I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)
|
||||
ARFLAGS=cru
|
||||
|
||||
#--------------------------------------------------------
|
||||
export VERSION BUILDTIME TOPDIR HOSTCC HOSTCFLAGS CROSS CC AR AS LD NM STRIP CPP
|
||||
ifeq ($(strip $(TARGET_ARCH)),)
|
||||
TARGET_ARCH:=$(shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
-e 's/i.86/i386/' \
|
||||
-e 's/sparc.*/sparc/' \
|
||||
-e 's/arm.*/arm/g' \
|
||||
-e 's/m68k.*/m68k/' \
|
||||
-e 's/ppc/powerpc/g' \
|
||||
-e 's/v850.*/v850/g' \
|
||||
-e 's/sh[234]/sh/' \
|
||||
-e 's/mips-.*/mips/' \
|
||||
-e 's/mipsel-.*/mipsel/' \
|
||||
-e 's/cris.*/cris/' \
|
||||
)
|
||||
endif
|
||||
|
||||
# Pull in the user's busybox configuration
|
||||
ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
|
||||
-include $(top_builddir)/.config
|
||||
endif
|
||||
|
||||
# A nifty macro to make testing gcc features easier
|
||||
check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \
|
||||
then echo "$(1)"; else echo "$(2)"; fi)
|
||||
|
||||
# Setup some shortcuts so that silent mode is silent like it should be
|
||||
ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS))
|
||||
export MAKE_IS_SILENT=n
|
||||
SECHO=@echo
|
||||
else
|
||||
export MAKE_IS_SILENT=y
|
||||
SECHO=-@false
|
||||
endif
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Arch specific compiler optimization stuff should go here.
|
||||
# Unless you want to override the defaults, do not set anything
|
||||
# for OPTIMIZATION...
|
||||
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION:=${call check_gcc,-Os,-O2}
|
||||
|
||||
# Some nice architecture specific optimizations
|
||||
ifeq ($(strip $(TARGET_ARCH)),arm)
|
||||
OPTIMIZATION+=-fstrict-aliasing
|
||||
endif
|
||||
ifeq ($(strip $(TARGET_ARCH)),i386)
|
||||
OPTIMIZATION+=$(call check_gcc,-march=i386,)
|
||||
OPTIMIZATION+=$(call check_gcc,-mpreferred-stack-boundary=2,)
|
||||
OPTIMIZATION+=$(call check_gcc,-falign-functions=0 -falign-jumps=0 -falign-loops=0,\
|
||||
-malign-functions=0 -malign-jumps=0 -malign-loops=0)
|
||||
endif
|
||||
OPTIMIZATIONS=$(OPTIMIZATION) -fomit-frame-pointer
|
||||
|
||||
#
|
||||
#--------------------------------------------------------
|
||||
# If you're going to do a lot of builds with a non-vanilla configuration,
|
||||
# it makes sense to adjust parameters above, so you can type "make"
|
||||
# by itself, instead of following it by the same half-dozen overrides
|
||||
# every time. The stuff below, on the other hand, is probably less
|
||||
# prone to casual user adjustment.
|
||||
#
|
||||
|
||||
ifeq ($(strip $(CONFIG_LFS)),y)
|
||||
# For large file summit support
|
||||
CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
endif
|
||||
ifeq ($(strip $(CONFIG_DMALLOC)),y)
|
||||
# For testing mem leaks with dmalloc
|
||||
CFLAGS+=-DDMALLOC
|
||||
LIBRARIES:=-ldmalloc
|
||||
else
|
||||
ifeq ($(strip $(CONFIG_EFENCE)),y)
|
||||
LIBRARIES:=-lefence
|
||||
endif
|
||||
endif
|
||||
ifeq ($(strip $(CONFIG_DEBUG)),y)
|
||||
CFLAGS +=$(WARNINGS) -g -D_GNU_SOURCE
|
||||
LDFLAGS +=-Wl,-warn-common
|
||||
STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
|
||||
else
|
||||
CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
|
||||
LDFLAGS += -Wl,-warn-common
|
||||
STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
|
||||
endif
|
||||
ifeq ($(strip $(CONFIG_STATIC)),y)
|
||||
LDFLAGS += --static
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(PREFIX)),)
|
||||
PREFIX:=`pwd`/_install
|
||||
endif
|
||||
|
||||
# Additional complications due to support for pristine source dir.
|
||||
# Include files in the build directory should take precedence over
|
||||
# the copy in BB_SRC_DIR, both during the compilation phase and the
|
||||
# shell script that finds the list of object files.
|
||||
# Work in progress by <ldoolitt@recycle.lbl.gov>.
|
||||
#
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
VPATH:=$(BB_SRC_DIR)
|
||||
endif
|
||||
|
||||
OBJECTS:=$(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
|
||||
CFLAGS += $(CROSS_CFLAGS)
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
# Put user-supplied flags at the end, where they
|
||||
# have a chance of winning.
|
||||
CFLAGS += $(CFLAGS_EXTRA)
|
||||
|
||||
.PHONY: dummy
|
||||
@@ -0,0 +1,11 @@
|
||||
Busybox TODO
|
||||
|
||||
Stuff that needs to be done
|
||||
|
||||
----
|
||||
tr - missing SuS3 features in busybox 1.0pre10
|
||||
|
||||
tr doesnt support [:blank:], [:digit:] or other predefined classes, [=equiv=]
|
||||
support is also missing.
|
||||
----
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
srcdir=$(top_srcdir)/applets
|
||||
APPLETS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(top_builddir).depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
APPLETS_AR:=applets.a
|
||||
ifndef $(APPLETS_DIR)
|
||||
APPLETS_DIR:=$(top_builddir)/applets/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/applets
|
||||
|
||||
APPLET_SRC:=applets.c busybox.c
|
||||
APPLET_OBJ:= $(patsubst %.c,$(APPLETS_DIR)%.o, $(APPLET_SRC))
|
||||
|
||||
libraries-y+=$(APPLETS_DIR)$(APPLETS_AR)
|
||||
|
||||
$(APPLETS_DIR)$(APPLETS_AR): $(APPLET_OBJ)
|
||||
$(AR) $(ARFLAGS) $@ $(APPLET_OBJ)
|
||||
|
||||
$(APPLET_OBJ): $(top_builddir)/.config
|
||||
$(APPLET_OBJ): $(APPLETS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -0,0 +1,512 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Utility routines.
|
||||
*
|
||||
* Copyright (C) tons of folks. Tracking down who wrote what
|
||||
* isn't something I'm going to worry about... If you wrote something
|
||||
* here, please feel free to acknowledge your work.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
||||
* Permission has been granted to redistribute this code under the GPL.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
const char usage_messages[] =
|
||||
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
|
||||
#include "applets.h"
|
||||
|
||||
;
|
||||
|
||||
#undef MAKE_USAGE
|
||||
#undef APPLET
|
||||
#undef APPLET_NOUSAGE
|
||||
#undef PROTOTYPES
|
||||
#include "applets.h"
|
||||
|
||||
|
||||
static struct BB_applet *applet_using;
|
||||
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
|
||||
static void check_suid (struct BB_applet *app);
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include "pwd_.h"
|
||||
#include "grp_.h"
|
||||
|
||||
static void parse_config_file (void);
|
||||
|
||||
#define CONFIG_FILE "/etc/busybox.conf"
|
||||
|
||||
/* applets [] is const, so we have to define this "override" structure */
|
||||
struct BB_suid_config
|
||||
{
|
||||
struct BB_applet *m_applet;
|
||||
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
|
||||
struct BB_suid_config *m_next;
|
||||
};
|
||||
|
||||
static struct BB_suid_config *suid_config;
|
||||
static int suid_cfg_readable;
|
||||
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
#endif /* CONFIG_FEATURE_SUID */
|
||||
|
||||
|
||||
|
||||
extern void
|
||||
bb_show_usage (void)
|
||||
{
|
||||
const char *format_string;
|
||||
const char *usage_string = usage_messages;
|
||||
int i;
|
||||
|
||||
for (i = applet_using - applets; i > 0;) {
|
||||
if (!*usage_string++) {
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
format_string = "%s\n\nUsage: %s %s\n\n";
|
||||
if (*usage_string == '\b')
|
||||
format_string = "%s\n\nNo help available.\n\n";
|
||||
fprintf (stderr, format_string, bb_msg_full_version, applet_using->name,
|
||||
usage_string);
|
||||
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int
|
||||
applet_name_compare (const void *x, const void *y)
|
||||
{
|
||||
const char *name = x;
|
||||
const struct BB_applet *applet = y;
|
||||
|
||||
return strcmp (name, applet->name);
|
||||
}
|
||||
|
||||
extern const size_t NUM_APPLETS;
|
||||
|
||||
struct BB_applet *
|
||||
find_applet_by_name (const char *name)
|
||||
{
|
||||
return bsearch (name, applets, NUM_APPLETS, sizeof (struct BB_applet),
|
||||
applet_name_compare);
|
||||
}
|
||||
|
||||
void
|
||||
run_applet_by_name (const char *name, int argc, char **argv)
|
||||
{
|
||||
static int recurse_level = 0;
|
||||
extern int been_there_done_that; /* From busybox.c */
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if (recurse_level == 0)
|
||||
parse_config_file ();
|
||||
#endif
|
||||
|
||||
recurse_level++;
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
if ((applet_using = find_applet_by_name (name)) != NULL) {
|
||||
bb_applet_name = applet_using->name;
|
||||
if (argv[1] && strcmp (argv[1], "--help") == 0) {
|
||||
if (strcmp (applet_using->name, "busybox") == 0) {
|
||||
if (argv[2])
|
||||
applet_using = find_applet_by_name (argv[2]);
|
||||
else
|
||||
applet_using = NULL;
|
||||
}
|
||||
if (applet_using)
|
||||
bb_show_usage ();
|
||||
been_there_done_that = 1;
|
||||
busybox_main (0, NULL);
|
||||
}
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
check_suid (applet_using);
|
||||
#endif
|
||||
|
||||
exit ((*(applet_using->main)) (argc, argv));
|
||||
}
|
||||
/* Just in case they have renamed busybox - Check argv[1] */
|
||||
if (recurse_level == 1) {
|
||||
run_applet_by_name ("busybox", argc, argv);
|
||||
}
|
||||
recurse_level--;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
/* check if u is member of group g */
|
||||
static int
|
||||
ingroup (uid_t u, gid_t g)
|
||||
{
|
||||
struct group *grp = getgrgid (g);
|
||||
|
||||
if (grp) {
|
||||
char **mem;
|
||||
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam (*mem);
|
||||
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
check_suid (struct BB_applet *applet)
|
||||
{
|
||||
uid_t ruid = getuid (); /* real [ug]id */
|
||||
uid_t rgid = getgid ();
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if (suid_cfg_readable) {
|
||||
struct BB_suid_config *sct;
|
||||
|
||||
for (sct = suid_config; sct; sct = sct->m_next) {
|
||||
if (sct->m_applet == applet)
|
||||
break;
|
||||
}
|
||||
if (sct) {
|
||||
mode_t m = sct->m_mode;
|
||||
|
||||
if (sct->m_uid == ruid) /* same uid */
|
||||
m >>= 6;
|
||||
else if ((sct->m_gid == rgid) || ingroup (ruid, sct->m_gid)) /* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!(m & S_IXOTH)) /* is x bit not set ? */
|
||||
bb_error_msg_and_die ("You have no permission to run this applet!");
|
||||
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
|
||||
if (setegid (sct->m_gid))
|
||||
bb_error_msg_and_die
|
||||
("BusyBox binary has insufficient rights to set proper GID for applet!");
|
||||
} else
|
||||
setgid (rgid); /* no sgid -> drop */
|
||||
|
||||
if (sct->m_mode & S_ISUID) {
|
||||
if (seteuid (sct->m_uid))
|
||||
bb_error_msg_and_die
|
||||
("BusyBox binary has insufficient rights to set proper UID for applet!");
|
||||
} else
|
||||
setuid (ruid); /* no suid -> drop */
|
||||
} else {
|
||||
/* default: drop all priviledges */
|
||||
setgid (rgid);
|
||||
setuid (ruid);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET
|
||||
static int onetime = 0;
|
||||
|
||||
if (!onetime) {
|
||||
onetime = 1;
|
||||
fprintf (stderr, "Using fallback suid method\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (applet->need_suid == _BB_SUID_ALWAYS) {
|
||||
if (geteuid () != 0)
|
||||
bb_error_msg_and_die ("This applet requires root priviledges!");
|
||||
} else if (applet->need_suid == _BB_SUID_NEVER) {
|
||||
setgid (rgid); /* drop all priviledges */
|
||||
setuid (ruid);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
/* This should probably be a libbb routine. In that case,
|
||||
* I'd probably rename it to something like bb_trimmed_slice.
|
||||
*/
|
||||
static char *get_trimmed_slice(char *s, char *e)
|
||||
{
|
||||
/* First, consider the value at e to be nul and back up until we
|
||||
* reach a non-space char. Set the char after that (possibly at
|
||||
* the original e) to nul. */
|
||||
while (e-- > s) {
|
||||
if (!isspace(*e)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
e[1] = 0;
|
||||
|
||||
/* Next, advance past all leading space and return a ptr to the
|
||||
* first non-space char; possibly the terminating nul. */
|
||||
return (char *) bb_skip_whitespace(s);
|
||||
}
|
||||
|
||||
|
||||
#define parse_error(x) { err=x; goto pe_label; }
|
||||
|
||||
/* Don't depend on the tools to combine strings. */
|
||||
static const char config_file[] = CONFIG_FILE;
|
||||
|
||||
/* There are 4 chars + 1 nul for each of user/group/other. */
|
||||
static const char mode_chars[] = "Ssx-\0Ssx-\0Ttx-";
|
||||
|
||||
/* We don't supply a value for the nul, so an index adjustment is
|
||||
* necessary below. Also, we use unsigned short here to save some
|
||||
* space even though these are really mode_t values. */
|
||||
static const unsigned short mode_mask[] = {
|
||||
/* SST sst xxx --- */
|
||||
S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */
|
||||
S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */
|
||||
0, S_IXOTH, S_IXOTH, 0 /* other */
|
||||
};
|
||||
|
||||
static void parse_config_file(void)
|
||||
{
|
||||
struct BB_suid_config *sct_head;
|
||||
struct BB_suid_config *sct;
|
||||
struct BB_applet *applet;
|
||||
FILE *f;
|
||||
char *err;
|
||||
char *s;
|
||||
char *e;
|
||||
int i, lc, section;
|
||||
char buffer[256];
|
||||
struct stat st;
|
||||
|
||||
assert(!suid_config); /* Should be set to NULL by bss init. */
|
||||
|
||||
if ((stat(config_file, &st) != 0) /* No config file? */
|
||||
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|
||||
|| (st.st_uid != 0) /* Not owned by root? */
|
||||
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|
||||
|| !(f = fopen(config_file, "r")) /* Can not open? */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
suid_cfg_readable = 1;
|
||||
sct_head = NULL;
|
||||
section = lc = 0;
|
||||
|
||||
do {
|
||||
s = buffer;
|
||||
|
||||
if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */
|
||||
if (ferror(f)) { /* Make sure it wasn't a read error. */
|
||||
parse_error("reading");
|
||||
}
|
||||
fclose(f);
|
||||
suid_config = sct_head; /* Success, so set the pointer. */
|
||||
return;
|
||||
}
|
||||
|
||||
lc++; /* Got a (partial) line. */
|
||||
|
||||
/* If a line is too long for our buffer, we consider it an error.
|
||||
* The following test does mistreat one corner case though.
|
||||
* If the final line of the file does not end with a newline and
|
||||
* yet exactly fills the buffer, it will be treated as too long
|
||||
* even though there isn't really a problem. But it isn't really
|
||||
* worth adding code to deal with such an unlikely situation, and
|
||||
* we do err on the side of caution. Besides, the line would be
|
||||
* too long if it did end with a newline. */
|
||||
if (!strchr(s, '\n') && !feof(f)) {
|
||||
parse_error("line too long");
|
||||
}
|
||||
|
||||
/* Trim leading and trailing whitespace, ignoring comments, and
|
||||
* check if the resulting string is empty. */
|
||||
if (!*(s = get_trimmed_slice(s, strchrnul(s, '#')))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for a section header. */
|
||||
|
||||
if (*s == '[') {
|
||||
/* Unlike the old code, we ignore leading and trailing
|
||||
* whitespace for the section name. We also require that
|
||||
* there are no stray characters after the closing bracket. */
|
||||
if (!(e = strchr(s, ']')) /* Missing right bracket? */
|
||||
|| e[1] /* Trailing characters? */
|
||||
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
|
||||
) {
|
||||
parse_error("section header");
|
||||
}
|
||||
/* Right now we only have one section so just check it.
|
||||
* If more sections are added in the future, please don't
|
||||
* resort to cascading ifs with multiple strcasecmp calls.
|
||||
* That kind of bloated code is all too common. A loop
|
||||
* and a string table would be a better choice unless the
|
||||
* number of sections is very small. */
|
||||
if (strcasecmp(s, "SUID") == 0) {
|
||||
section = 1;
|
||||
continue;
|
||||
}
|
||||
section = -1; /* Unknown section so set to skip. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process sections. */
|
||||
|
||||
if (section == 1) { /* SUID */
|
||||
/* Since we trimmed leading and trailing space above, we're
|
||||
* now looking for strings of the form
|
||||
* <key>[::space::]*=[::space::]*<value>
|
||||
* where both key and value could contain inner whitespace. */
|
||||
|
||||
/* First get the key (an applet name in our case). */
|
||||
if (!!(e = strchr(s, '='))) {
|
||||
s = get_trimmed_slice(s, e);
|
||||
}
|
||||
if (!e || !*s) { /* Missing '=' or empty key. */
|
||||
parse_error("keyword");
|
||||
}
|
||||
|
||||
/* Ok, we have an applet name. Process the rhs if this
|
||||
* applet is currently built in and ignore it otherwise.
|
||||
* Note: This can hide config file bugs which only pop
|
||||
* up when the busybox configuration is changed. */
|
||||
if ((applet = find_applet_by_name(s))) {
|
||||
/* Note: We currently don't check for duplicates!
|
||||
* The last config line for each applet will be the
|
||||
* one used since we insert at the head of the list.
|
||||
* I suppose this could be considered a feature. */
|
||||
sct = xmalloc(sizeof(struct BB_suid_config));
|
||||
sct->m_applet = applet;
|
||||
sct->m_mode = 0;
|
||||
sct->m_next = sct_head;
|
||||
sct_head = sct;
|
||||
|
||||
/* Get the specified mode. */
|
||||
|
||||
e = (char *) bb_skip_whitespace(e+1);
|
||||
|
||||
for (i=0 ; i < 3 ; i++) {
|
||||
const char *q;
|
||||
if (!*(q = strchrnul(mode_chars + 5*i, *e++))) {
|
||||
parse_error("mode");
|
||||
}
|
||||
/* Adjust by -i to account for nul. */
|
||||
sct->m_mode |= mode_mask[(q - mode_chars) - i];
|
||||
}
|
||||
|
||||
/* Now get the the user/group info. */
|
||||
|
||||
s = (char *) bb_skip_whitespace(e);
|
||||
|
||||
/* Note: We require whitespace between the mode and the
|
||||
* user/group info. */
|
||||
if ((s == e) || !(e = strchr(s, '.'))) {
|
||||
parse_error("<uid>.<gid>");
|
||||
}
|
||||
*e++ = 0;
|
||||
|
||||
/* We can't use get_ug_id here since it would exit()
|
||||
* if a uid or gid was not found. Oh well... */
|
||||
{
|
||||
char *e2;
|
||||
|
||||
sct->m_uid = strtoul(s, &e2, 10);
|
||||
if (*e2 || (s == e2)) {
|
||||
struct passwd *pwd;
|
||||
if (!(pwd = getpwnam(s))) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
}
|
||||
|
||||
sct->m_gid = strtoul(e, &e2, 10);
|
||||
if (*e2 || (e == e2)) {
|
||||
struct group *grp;
|
||||
if (!(grp = getgrnam(e))) {
|
||||
parse_error("group");
|
||||
}
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Unknown sections are ignored. */
|
||||
|
||||
/* Encountering configuration lines prior to seeing a
|
||||
* section header is treated as an error. This is how
|
||||
* the old code worked, but it may not be desirable.
|
||||
* We may want to simply ignore such lines in case they
|
||||
* are used in some future version of busybox. */
|
||||
if (!section) {
|
||||
parse_error("keyword outside section");
|
||||
}
|
||||
|
||||
} while (1);
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, err);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
while (sct_head) {
|
||||
sct = sct_head->m_next;
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,193 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
int been_there_done_that = 0; /* Also used in applets.c */
|
||||
const char *bb_applet_name;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static const char usr_bin [] ="/usr/bin";
|
||||
static const char usr_sbin[] ="/usr/sbin";
|
||||
|
||||
static const char* const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static inline char *busybox_fullpath(void)
|
||||
{
|
||||
return xreadlink("/proc/self/exe");
|
||||
}
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].location], applets[i].name);
|
||||
rc = Link(busybox, fpc);
|
||||
if (rc!=0 && errno!=EEXIST) {
|
||||
bb_perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FEATURE_INSTALLER */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
bb_applet_name = argv[0];
|
||||
|
||||
if (bb_applet_name[0] == '-')
|
||||
bb_applet_name++;
|
||||
|
||||
for (s = bb_applet_name; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
bb_applet_name = s;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#ifdef CONFIG_INIT
|
||||
if(getpid()!=1) /* Do not set locale for `init' */
|
||||
#endif
|
||||
{
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
run_applet_by_name(bb_applet_name, argc, argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col = 0, len, i;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* CONFIG_FEATURE_INSTALLER */
|
||||
|
||||
argc--;
|
||||
|
||||
/* If we've already been here once, exit now */
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct BB_applet *a = applets;
|
||||
int output_width = 60;
|
||||
|
||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= 20;
|
||||
#endif
|
||||
|
||||
printf("%s\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n", bb_msg_full_version);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
printf("%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > output_width && a->name != 0) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Flag that we've been here already */
|
||||
been_there_done_that = 1;
|
||||
|
||||
/* Move the command line down a notch */
|
||||
/* Preserve pointers so setproctitle() works consistently */
|
||||
len = argv[argc] + strlen(argv[argc]) - argv[1];
|
||||
memmove(argv[0], argv[1], len);
|
||||
memset(argv[0] + len, 0, argv[1] - argv[0]);
|
||||
|
||||
/* Fix up the argv pointers */
|
||||
len = argv[1] - argv[0];
|
||||
memmove(argv, argv + 1, sizeof(char *) * (argc + 1));
|
||||
for (i = 0; i < argc; i++)
|
||||
argv[i] -= len;
|
||||
|
||||
return (main(argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -10,9 +10,9 @@
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
CONFIG_H=${1:-include/config.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
$HOSTCC -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
gcc -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*LINK/{
|
||||
dir=substr($2,8)
|
||||
gsub("_","/",dir)
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
if [ "$prefix" = "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
linkopts="-f"
|
||||
else
|
||||
linkopts="-fs"
|
||||
fi
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
|
||||
for i in $h ; do
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
config AR
|
||||
config CONFIG_AR
|
||||
bool "ar"
|
||||
default n
|
||||
help
|
||||
@@ -28,17 +28,17 @@ config AR
|
||||
Unless you have a specific application which requires ar, you should
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Enable support for long filenames (not need for debs)"
|
||||
config CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
bool " Enable support for long filenames (not need for debs)"
|
||||
default n
|
||||
depends on AR
|
||||
depends on CONFIG_AR
|
||||
help
|
||||
By default the ar format can only store the first 15 characters of the
|
||||
filename, this option removes that limitation.
|
||||
It supports the GNU ar long filename method which moves multiple long
|
||||
filenames into a the data section of a new ar entry.
|
||||
|
||||
config BUNZIP2
|
||||
config CONFIG_BUNZIP2
|
||||
bool "bunzip2"
|
||||
default n
|
||||
help
|
||||
@@ -47,24 +47,14 @@ config BUNZIP2
|
||||
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.
|
||||
|
||||
|
||||
The BusyBox bunzip2 applet is limited to de-compression only.
|
||||
On an x86 system, this applet adds about 11K.
|
||||
|
||||
Unless you have a specific application which requires bunzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config BZIP2
|
||||
bool "bzip2"
|
||||
default n
|
||||
help
|
||||
bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
sorting text compression algorithm, and Huffman coding. Compression
|
||||
is generally considerably better than that achieved by more
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
Unless you have a specific application which requires bzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config CPIO
|
||||
config CONFIG_CPIO
|
||||
bool "cpio"
|
||||
default n
|
||||
help
|
||||
@@ -78,36 +68,36 @@ config CPIO
|
||||
Unless you have a specific application which requires cpio, you should
|
||||
probably say N here.
|
||||
|
||||
config DPKG
|
||||
config CONFIG_DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
help
|
||||
dpkg is a medium-level tool to install, build, remove and manage Debian packages.
|
||||
|
||||
|
||||
This implementation of dpkg has a number of limitations, you should use the
|
||||
official dpkg if possible.
|
||||
|
||||
config DPKG_DEB
|
||||
config CONFIG_DPKG_DEB
|
||||
bool "dpkg_deb"
|
||||
default n
|
||||
help
|
||||
dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||
|
||||
|
||||
This implementation of dpkg-deb cannot pack archives.
|
||||
|
||||
|
||||
Unless you have a specific application which requires dpkg-deb, you should
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool "extract only (-x)"
|
||||
config CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool " extract only (-x)"
|
||||
default n
|
||||
depends on DPKG_DEB
|
||||
depends on CONFIG_DPKG_DEB
|
||||
help
|
||||
This reduces dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
|
||||
However it saves space as none of the extra dpkg-deb, ar or tar options are
|
||||
needed, they are linked to internally.
|
||||
|
||||
config GUNZIP
|
||||
config CONFIG_GUNZIP
|
||||
bool "gunzip"
|
||||
default n
|
||||
help
|
||||
@@ -115,42 +105,35 @@ 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"
|
||||
config CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
bool " Uncompress support"
|
||||
default n
|
||||
depends on GUNZIP
|
||||
depends on CONFIG_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
|
||||
config CONFIG_GZIP
|
||||
bool "gzip"
|
||||
default n
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config RPM2CPIO
|
||||
config CONFIG_RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default n
|
||||
help
|
||||
Converts an RPM file into a CPIO archive.
|
||||
|
||||
config RPM
|
||||
config CONFIG_RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
Mini RPM applet - queries and extracts
|
||||
|
||||
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
|
||||
config CONFIG_TAR
|
||||
bool "tar"
|
||||
default n
|
||||
help
|
||||
@@ -158,118 +141,78 @@ config TAR
|
||||
create compressed archives. It's probably the most widely used
|
||||
UNIX archive program.
|
||||
|
||||
config FEATURE_TAR_CREATE
|
||||
bool "Enable archive creation"
|
||||
config CONFIG_FEATURE_TAR_CREATE
|
||||
bool " Enable archive creation"
|
||||
default y
|
||||
depends on TAR
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
If you enable this option you'll be able to create
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config FEATURE_TAR_BZIP2
|
||||
bool "Enable -j option to handle .tar.bz2 files"
|
||||
config CONFIG_FEATURE_TAR_BZIP2
|
||||
bool " Enable -j option to handle .tar.bz2 files"
|
||||
default n
|
||||
depends on TAR
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with bzip2.
|
||||
|
||||
config FEATURE_TAR_LZMA
|
||||
bool "Enable -a option to handle .tar.lzma files"
|
||||
config CONFIG_FEATURE_TAR_FROM
|
||||
bool " Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with lzma.
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
depends on TAR
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config FEATURE_TAR_GZIP
|
||||
bool "Enable -z option"
|
||||
config CONFIG_FEATURE_TAR_GZIP
|
||||
bool " Enable -z option"
|
||||
default y
|
||||
depends on TAR
|
||||
depends on CONFIG_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"
|
||||
config CONFIG_FEATURE_TAR_COMPRESS
|
||||
bool " Enable -Z option"
|
||||
default n
|
||||
depends on TAR
|
||||
depends on CONFIG_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 "Enable support for old tar header format"
|
||||
config CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
bool " Enable support for old tar header format"
|
||||
default N
|
||||
depends on TAR
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
This option is required to unpack archives created in
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
default N
|
||||
depends on TAR
|
||||
help
|
||||
This option is required to unpack archives created by some old
|
||||
version of Sun's tar (it was calculating checksum using signed arithmetic).
|
||||
It is said to be fixed in newer Sun tar, but "old" tarballs still exist.
|
||||
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Enable support for some GNU tar extensions"
|
||||
config CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool " Enable support for some GNU tar extensions"
|
||||
default y
|
||||
depends on TAR
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
config CONFIG_FEATURE_TAR_LONG_OPTIONS
|
||||
bool " Enable long options"
|
||||
default n
|
||||
depends on TAR && GETOPT_LONG
|
||||
depends on CONFIG_TAR
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config UNCOMPRESS
|
||||
config CONFIG_UNCOMPRESS
|
||||
bool "uncompress"
|
||||
default n
|
||||
help
|
||||
uncompress is used to decompress archives created by compress.
|
||||
Not much used anymore, replaced by gzip/gunzip.
|
||||
|
||||
config UNLZMA
|
||||
bool "unlzma"
|
||||
default n
|
||||
help
|
||||
unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
compression algorithm, and range coding. Compression
|
||||
is generally considerably better than that achieved by the bzip2
|
||||
compressors.
|
||||
|
||||
The BusyBox unlzma applet is limited to de-compression only.
|
||||
On an x86 system, this applet adds about 4K.
|
||||
|
||||
Unless you have a specific application which requires unlzma, you
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimze unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 33% at the cost of
|
||||
a 2K bigger binary.
|
||||
|
||||
config UNZIP
|
||||
config CONFIG_UNZIP
|
||||
bool "unzip"
|
||||
default n
|
||||
help
|
||||
@@ -280,47 +223,36 @@ config UNZIP
|
||||
directory of your choice.
|
||||
|
||||
comment "Common options for cpio and tar"
|
||||
depends on CPIO || TAR
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
|
||||
config FEATURE_UNARCHIVE_TAPE
|
||||
bool "Enable tape drive support"
|
||||
config CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
bool " Enable tape drive support"
|
||||
default n
|
||||
depends on CPIO || TAR
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
help
|
||||
I don't think this is needed anymore.
|
||||
|
||||
comment "Common options for dpkg and dpkg_deb"
|
||||
depends on DPKG || DPKG_DEB
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
|
||||
config FEATURE_DEB_TAR_GZ
|
||||
bool "gzip debian packages (normal)"
|
||||
default y if DPKG || DPKG_DEB
|
||||
depends on DPKG || DPKG_DEB
|
||||
config CONFIG_FEATURE_DEB_TAR_GZ
|
||||
bool " gzip debian packages (normal)"
|
||||
default y if CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
depends on CONFIG_DPKG || CONFIG_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"
|
||||
config CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
bool " bzip2 debian packages"
|
||||
default n
|
||||
depends on DPKG || DPKG_DEB
|
||||
depends on CONFIG_DPKG || CONFIG_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
|
||||
@@ -0,0 +1,32 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
top_srcdir=..
|
||||
top_builddir=..
|
||||
ARCHIVAL_DIR:=./
|
||||
srcdir=$(top_srcdir)/archival
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
ARCHIVAL_AR:=archival.a
|
||||
ifndef $(ARCHIVAL_DIR)
|
||||
ARCHIVAL_DIR:=$(top_builddir)/archival/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/archival
|
||||
|
||||
ARCHIVAL-y:=
|
||||
ARCHIVAL-$(CONFIG_APT_GET) +=
|
||||
ARCHIVAL-$(CONFIG_AR) += ar.o
|
||||
ARCHIVAL-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
ARCHIVAL-$(CONFIG_CPIO) += cpio.o
|
||||
ARCHIVAL-$(CONFIG_DPKG) += dpkg.o
|
||||
ARCHIVAL-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o
|
||||
ARCHIVAL-$(CONFIG_GZIP) += gzip.o
|
||||
ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
ARCHIVAL-$(CONFIG_RPM) += rpm.o
|
||||
ARCHIVAL-$(CONFIG_TAR) += tar.o
|
||||
ARCHIVAL-$(CONFIG_UNCOMPRESS) += uncompress.o
|
||||
ARCHIVAL-$(CONFIG_UNZIP) += unzip.o
|
||||
|
||||
libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR)
|
||||
|
||||
$(ARCHIVAL_DIR)$(ARCHIVAL_AR): $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
|
||||
$(ARCHIVAL_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@iinet.net.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* There is no single standard to adhere to so ar may not portable
|
||||
* between different systems
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
const char *mode = bb_mode_string(file_header->mode);
|
||||
char *mtime;
|
||||
|
||||
mtime = ctime(&file_header->mtime);
|
||||
mtime[16] = ' ';
|
||||
memmove(&mtime[17], &mtime[20], 4);
|
||||
mtime[21] = '\0';
|
||||
printf("%s %d/%d%7d %s %s\n", &mode[1], file_header->uid, file_header->gid, (int) file_header->size, &mtime[4], file_header->name);
|
||||
}
|
||||
|
||||
#define AR_CTX_PRINT 0x01
|
||||
#define AR_CTX_LIST 0x02
|
||||
#define AR_CTX_EXTRACT 0x04
|
||||
#define AR_OPT_PRESERVE_DATE 0x08
|
||||
#define AR_OPT_VERBOSE 0x10
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned long opt;
|
||||
char *msg_unsupported_err = "Archive %s not supported. Install binutils 'ar'.";
|
||||
char magic[8];
|
||||
|
||||
archive_handle = init_handle();
|
||||
|
||||
bb_opt_complementaly = "p~tx:t~px:x~pt";
|
||||
opt = bb_getopt_ulflags(argc, argv, "ptxovcr");
|
||||
|
||||
if ((opt & BB_GETOPT_ERROR) || (opt == 0) || (optind == argc)) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & AR_CTX_LIST) {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & AR_CTX_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
}
|
||||
if (opt & AR_OPT_CREATE) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "creation");
|
||||
}
|
||||
if (opt & AR_OPT_INSERT) {
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind++]);
|
||||
}
|
||||
|
||||
archive_xread_all(archive_handle, 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);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define BUNZIP2_OPT_STDOUT 1
|
||||
#define BUNZIP2_OPT_FORCE 2
|
||||
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
char *compressed_name;
|
||||
/* Note: Ignore the warning about save_name being used uninitialized.
|
||||
* That is not the case, but gcc has trouble working that out... */
|
||||
char *save_name;
|
||||
unsigned long opt;
|
||||
int status;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "cf");
|
||||
|
||||
/* if called as bzcat force the stdout flag */
|
||||
if (bb_applet_name[2] == 'c') {
|
||||
opt |= BUNZIP2_OPT_STDOUT;
|
||||
}
|
||||
|
||||
/* Set input filename and number */
|
||||
compressed_name = argv[optind];
|
||||
if ((compressed_name) && (compressed_name[0] != '-') && (compressed_name[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = bb_xopen(compressed_name, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= BUNZIP2_OPT_STDOUT;
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
|
||||
}
|
||||
|
||||
if (opt & BUNZIP2_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
int len = strlen(compressed_name) - 4;
|
||||
if (strcmp(compressed_name + len, ".bz2") != 0) {
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
}
|
||||
save_name = bb_xstrndup(compressed_name, len);
|
||||
dst_fd = bb_xopen(save_name, O_WRONLY | O_CREAT);
|
||||
}
|
||||
|
||||
status = uncompressStream(src_fd, dst_fd);
|
||||
if(!(opt & BUNZIP2_OPT_STDOUT)) {
|
||||
char *delete_name;
|
||||
if (status) {
|
||||
delete_name = save_name;
|
||||
} else {
|
||||
delete_name = compressed_name;
|
||||
}
|
||||
if (unlink(delete_name) < 0) {
|
||||
bb_error_msg_and_die("Couldn't remove %s", delete_name);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#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
|
||||
|
||||
extern int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename = NULL;
|
||||
unsigned long opt;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename);
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test option are given, ignore extract option */
|
||||
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_UNCONDITIONAL) {
|
||||
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
if (archive_handle->action_header == header_list) {
|
||||
archive_handle->action_header = header_verbose_list;
|
||||
} else {
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (cpio_filename) { /* CPIO_OPT_FILE */
|
||||
archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 Library General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
#define DPKG_DEB_OPT_FIELD 4
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
extern int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned long opt;
|
||||
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->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
|
||||
control_tar_llist = llist_add_to(NULL, "control.tar.gz");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2");
|
||||
control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2");
|
||||
#endif
|
||||
|
||||
bb_opt_complementaly = "c~efXx:e~cfXx:f~ceXx:X~cefx:x~cefX";
|
||||
opt = bb_getopt_ulflags(argc, argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_CONTROL) {
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->action_data = data_extract_all;
|
||||
if (optind + 1 == argc) {
|
||||
extract_dir = "./DEBIAN";
|
||||
} else {
|
||||
argcount++;
|
||||
}
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_FIELD) {
|
||||
/* Print the entire control file
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
tar_archive->accept = llist_add_to(NULL, "./control");;
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & DPKG_DEB_OPT_EXTRACT) {
|
||||
tar_archive->action_header = header_list;
|
||||
}
|
||||
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
|
||||
tar_archive->action_data = data_extract_all;
|
||||
argcount = 2;
|
||||
}
|
||||
|
||||
if ((optind + argcount != argc) || (opt & BB_GETOPT_ERROR)) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
/* Workout where to extract the files */
|
||||
/* 2nd argument is a dir name */
|
||||
if (argv[optind]) {
|
||||
extract_dir = argv[optind];
|
||||
}
|
||||
if (extract_dir) {
|
||||
mkdir(extract_dir, 0777);
|
||||
chdir(extract_dir);
|
||||
}
|
||||
unpack_ar_archive(ar_archive);
|
||||
|
||||
/* Cleanup */
|
||||
close (ar_archive->src_fd);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char *license_msg[] = {
|
||||
" Copyright (C) 1992-1993 Jean-loup Gailly",
|
||||
" This program 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, or (at your option)",
|
||||
" any later version.",
|
||||
"",
|
||||
" This program 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 this program; if not, write to the Free Software",
|
||||
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.",
|
||||
0
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_OPT_STDOUT 1
|
||||
#define GUNZIP_OPT_FORCE 2
|
||||
#define GUNZIP_OPT_TEST 4
|
||||
#define GUNZIP_OPT_DECOMPRESS 8
|
||||
|
||||
extern int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
char status = EXIT_SUCCESS;
|
||||
unsigned long opt;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "cftd");
|
||||
/* if called as zcat */
|
||||
if (strcmp(bb_applet_name, "zcat") == 0) {
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
}
|
||||
|
||||
do {
|
||||
struct stat stat_buf;
|
||||
const char *old_path = argv[optind];
|
||||
const char *delete_path = NULL;
|
||||
char *new_path = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
optind++;
|
||||
|
||||
if (old_path == NULL || strcmp(old_path, "-") == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
} else {
|
||||
src_fd = bb_xopen(old_path, O_RDONLY);
|
||||
|
||||
/* Get the time stamp on the input file. */
|
||||
if (stat(old_path, &stat_buf) < 0) {
|
||||
bb_error_msg_and_die("Couldn't stat file %s", old_path);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((opt & GUNZIP_OPT_FORCE) == 0)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal. Use -f to force it.");
|
||||
}
|
||||
|
||||
/* Set output filename and number */
|
||||
if (opt & GUNZIP_OPT_TEST) {
|
||||
dst_fd = bb_xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
|
||||
} else if (opt & GUNZIP_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
char *extension;
|
||||
|
||||
new_path = bb_xstrdup(old_path);
|
||||
|
||||
extension = strrchr(new_path, '.');
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (extension && (strcmp(extension, ".Z") == 0)) {
|
||||
*extension = '\0';
|
||||
} else
|
||||
#endif
|
||||
if (extension && (strcmp(extension, ".gz") == 0)) {
|
||||
*extension = '\0';
|
||||
} else if (extension && (strcmp(extension, ".tgz") == 0)) {
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
}
|
||||
|
||||
/* Open output file */
|
||||
dst_fd = bb_xopen(new_path, O_WRONLY | O_CREAT);
|
||||
|
||||
/* Set permissions on the file */
|
||||
chmod(new_path, stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = old_path;
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (bb_xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = bb_xread_char(src_fd);
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (magic2 == 0x9d) {
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
} else
|
||||
#endif
|
||||
if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd);
|
||||
status = inflate_gunzip(src_fd, dst_fd);
|
||||
if (status != 0) {
|
||||
bb_error_msg_and_die("Error inflating");
|
||||
}
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
}
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
}
|
||||
|
||||
if ((status != EXIT_SUCCESS) && (new_path)) {
|
||||
/* Unzip failed, remove new path instead of old path */
|
||||
delete_path = new_path;
|
||||
}
|
||||
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
bb_error_msg_and_die("Couldn't remove %s", delete_path);
|
||||
}
|
||||
|
||||
free(new_path);
|
||||
|
||||
} while (optind < argc);
|
||||
|
||||
return status;
|
||||
}
|
||||
+1604
-1157
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,32 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
top_srcdir=../..
|
||||
top_builddir=../..
|
||||
srcdir=$(top_srcdir)/archival/libunarchive
|
||||
LIBUNARCHIVE_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program 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.
|
||||
#
|
||||
# This program 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 this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
LIBUNARCHIVE_AR:=libunarchive.a
|
||||
ifndef $(LIBUNARCHIVE_DIR)
|
||||
LIBUNARCHIVE_DIR:=$(top_builddir)/archival/libunarchive/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/archvial/libunarchive
|
||||
|
||||
LIBUNARCHIVE-y:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
filter_accept_reject_list.o \
|
||||
\
|
||||
header_skip.o \
|
||||
header_list.o \
|
||||
header_verbose_list.o \
|
||||
\
|
||||
archive_xread_all.o \
|
||||
archive_xread_all_eof.o \
|
||||
\
|
||||
seek_by_char.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
open_transformer.o \
|
||||
init_handle.o
|
||||
|
||||
GUNZIP_FILES:= check_header_gzip.o decompress_unzip.o
|
||||
DPKG_FILES:= \
|
||||
get_header_ar.o \
|
||||
unpack_ar_archive.o \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
LIBUNARCHIVE-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
LIBUNARCHIVE-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
LIBUNARCHIVE-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
LIBUNARCHIVE-$(CONFIG_TAR) += get_header_tar.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
LIBUNARCHIVE-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
LIBUNARCHIVE-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
|
||||
libraries-y+=$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR)
|
||||
|
||||
$(LIBUNARCHIVE_DIR)$(LIBUNARCHIVE_AR): $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
$(AR) $(ARFLAGS) $@ $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
|
||||
$(LIBUNARCHIVA_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 Library General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count)
|
||||
{
|
||||
ssize_t size;
|
||||
|
||||
size = bb_full_read(archive_handle->src_fd, buf, count);
|
||||
if (size != count) {
|
||||
bb_error_msg_and_die("Short read");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 Library General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count)
|
||||
{
|
||||
ssize_t size;
|
||||
|
||||
size = bb_full_read(archive_handle->src_fd, buf, count);
|
||||
if ((size != 0) && (size != count)) {
|
||||
bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count);
|
||||
}
|
||||
return(size);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
|
||||
extern void check_header_gzip(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
struct {
|
||||
unsigned char method;
|
||||
unsigned char flags;
|
||||
unsigned int mtime;
|
||||
unsigned char xtra_flags;
|
||||
unsigned char os_flags;
|
||||
} formated;
|
||||
} header;
|
||||
|
||||
bb_xread_all(src_fd, header.raw, 8);
|
||||
|
||||
/* Check the compression method */
|
||||
if (header.formated.method != 8) {
|
||||
bb_error_msg_and_die("Unknown compression method %d",
|
||||
header.formated.method);
|
||||
}
|
||||
|
||||
if (header.formated.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned char extra_short;
|
||||
|
||||
extra_short = bb_xread_char(src_fd) + (bb_xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
/* Ignore extra field */
|
||||
bb_xread_char(src_fd);
|
||||
extra_short--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discard original name if any */
|
||||
if (header.formated.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
while(bb_xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formated.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
while(bb_xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formated.flags & 0x02) {
|
||||
bb_xread_char(src_fd);
|
||||
bb_xread_char(src_fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
{
|
||||
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = bb_xstrdup(file_header->name);
|
||||
bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the existing entry if it exists */
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR) && (unlink(file_header->name) == -1) && (errno != ENOENT)) {
|
||||
bb_perror_msg_and_die("Couldnt remove old file");
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("Couldnt stat old file");
|
||||
}
|
||||
}
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or same age file exists", file_header->name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("Couldnt 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_name) && (file_header->size == 0)) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Couldnt create hard link");
|
||||
}
|
||||
} else {
|
||||
/* Create the filesystem entry */
|
||||
switch(file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
|
||||
bb_copyfd_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 ((errno != EISDIR) && (res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("extract_archive: %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create symlink from %s to '%s'", file_header->name, file_header->link_name);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("Cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bb_error_msg_and_die("Unrecognised file type");
|
||||
}
|
||||
}
|
||||
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
|
||||
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,28 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
const unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xmalloc(size + 1);
|
||||
|
||||
archive_xread_all(archive_handle, archive_handle->buffer, size);
|
||||
archive_handle->buffer[size] = '\0';
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
extern void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
}
|
||||
+277
-434
File diff suppressed because it is too large.
Load diff
+89
-101
@@ -1,4 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "config.h"
|
||||
#include "libbb.h"
|
||||
|
||||
/* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
@@ -7,6 +7,7 @@
|
||||
* (see disclaimer below)
|
||||
*/
|
||||
|
||||
|
||||
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
|
||||
*
|
||||
* Authors:
|
||||
@@ -25,6 +26,9 @@
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Default input buffer size */
|
||||
#define IBUFSIZ 2048
|
||||
@@ -33,101 +37,102 @@
|
||||
#define OBUFSIZ 2048
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compression if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
#define MAGIC_1 (char_type)'\037' /* First byte of compressed file */
|
||||
#define MAGIC_2 (char_type)'\235' /* Second byte of compressed file */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1) /* unused */
|
||||
#define HPRIME 9941 /* unused */
|
||||
#define BITS 16
|
||||
#define BITS_STR "16"
|
||||
#undef MAXSEG_64K /* unused */
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
#define FAST
|
||||
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1)
|
||||
#define HPRIME 9941
|
||||
#define BITS 16
|
||||
#undef MAXSEG_64K
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
/* Block compress mode -C compatible with 2.0 */
|
||||
int block_mode = BLOCK_MODE;
|
||||
|
||||
/* user settable max # bits/code */
|
||||
int maxbits = BITS;
|
||||
|
||||
/* Exitcode of compress (-1 no file compressed) */
|
||||
int exit_code = -1;
|
||||
|
||||
/* Input buffer */
|
||||
unsigned char inbuf[IBUFSIZ + 64];
|
||||
|
||||
/* Output buffer */
|
||||
unsigned char outbuf[OBUFSIZ + 2048];
|
||||
|
||||
|
||||
long int htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
||||
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
||||
#define clear_htab() memset(htab, -1, sizeof(htab))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
||||
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256)
|
||||
|
||||
/*
|
||||
* Decompress stdin to stdout. This routine adapts to the codes in the
|
||||
* file building the "string" table on-the-fly; requiring no table to
|
||||
* be stored in the compressed file.
|
||||
* be stored in the compressed file. The tables used herein are shared
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
uncompress(int fd_in, int fd_out)
|
||||
extern int uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
USE_DESKTOP(long long) int retval = -1;
|
||||
unsigned char *stackp;
|
||||
long code;
|
||||
long int code;
|
||||
int finchar;
|
||||
long oldcode;
|
||||
long incode;
|
||||
long int oldcode;
|
||||
long int incode;
|
||||
int inbits;
|
||||
int posbits;
|
||||
int outpos;
|
||||
int insize;
|
||||
int bitmask;
|
||||
long free_ent;
|
||||
long maxcode;
|
||||
long maxmaxcode;
|
||||
long int free_ent;
|
||||
long int maxcode;
|
||||
long int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
unsigned char *inbuf; /* were eating insane amounts of stack - */
|
||||
unsigned char *outbuf; /* bad for some embedded targets */
|
||||
unsigned char *htab;
|
||||
unsigned short *codetab;
|
||||
|
||||
/* Hmm, these were statics - why?! */
|
||||
/* user settable max # bits/code */
|
||||
int maxbits; /* = BITS; */
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
outbuf = xzalloc(OBUFSIZ + 2048);
|
||||
htab = xzalloc(HSIZE); /* wsn't zeroed out before, maybe can xmalloc? */
|
||||
codetab = xzalloc(HSIZE * sizeof(codetab[0]));
|
||||
|
||||
insize = 0;
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(fd_in, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
inbuf[0] = bb_xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
maxmaxcode = MAXCODE(maxbits);
|
||||
|
||||
if (maxbits > BITS) {
|
||||
bb_error_msg("compressed with %d bits, can only handle "
|
||||
BITS_STR" bits", maxbits);
|
||||
goto err;
|
||||
bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits,
|
||||
BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
@@ -136,21 +141,20 @@ uncompress(int fd_in, int fd_out)
|
||||
free_ent = ((block_mode) ? FIRST : 256);
|
||||
|
||||
/* As above, initialize the first 256 entries in the table. */
|
||||
/*clear_tab_prefixof(); - done by xzalloc */
|
||||
clear_tab_prefixof();
|
||||
|
||||
for (code = 255; code >= 0; --code) {
|
||||
tab_suffixof(code) = (unsigned char) code;
|
||||
}
|
||||
|
||||
do {
|
||||
resetbuf:
|
||||
resetbuf:;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
o = posbits >> 3;
|
||||
e = insize - o;
|
||||
e = insize - (o = (posbits >> 3));
|
||||
|
||||
for (i = 0; i < e; ++i)
|
||||
inbuf[i] = inbuf[i + o];
|
||||
@@ -159,9 +163,8 @@ uncompress(int fd_in, int fd_out)
|
||||
posbits = 0;
|
||||
}
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
if (insize < (int) sizeof(inbuf) - IBUFSIZ) {
|
||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
//error check??
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
@@ -186,16 +189,16 @@ uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
unsigned char *p = &inbuf[posbits >> 3];
|
||||
|
||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
code =
|
||||
((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
|
||||
if (oldcode == -1) {
|
||||
oldcode = code;
|
||||
finchar = (int) oldcode;
|
||||
outbuf[outpos++] = (unsigned char) finchar;
|
||||
outbuf[outpos++] = (unsigned char) (finchar =
|
||||
(int) (oldcode = code));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -206,9 +209,8 @@ uncompress(int fd_in, int fd_out)
|
||||
((posbits - 1) +
|
||||
((n_bits << 3) -
|
||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
@@ -228,7 +230,7 @@ uncompress(int fd_in, int fd_out)
|
||||
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
|
||||
(posbits & 07));
|
||||
bb_error_msg("uncompress: corrupt input");
|
||||
goto err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*--stackp = (unsigned char) finchar;
|
||||
@@ -236,20 +238,18 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
/* Generate output characters in reverse order */
|
||||
while ((long) code >= (long) 256) {
|
||||
while ((long int) code >= (long int) 256) {
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
finchar = tab_suffixof(code);
|
||||
*--stackp = (unsigned char) finchar;
|
||||
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
{
|
||||
int i;
|
||||
|
||||
i = de_stack - stackp;
|
||||
if (outpos + i >= OBUFSIZ) {
|
||||
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
|
||||
do {
|
||||
if (i > OBUFSIZ - outpos) {
|
||||
i = OBUFSIZ - outpos;
|
||||
@@ -261,14 +261,11 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
write(fd_out, outbuf, outpos);
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
i = de_stack - stackp;
|
||||
} while (i > 0);
|
||||
} while ((i = (de_stack - stackp)) > 0);
|
||||
} else {
|
||||
memcpy(outbuf + outpos, stackp, i);
|
||||
outpos += i;
|
||||
@@ -276,8 +273,7 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
/* Generate the new entry. */
|
||||
code = free_ent;
|
||||
if (code < maxmaxcode) {
|
||||
if ((code = free_ent) < maxmaxcode) {
|
||||
tab_prefixof(code) = (unsigned short) oldcode;
|
||||
tab_suffixof(code) = (unsigned char) finchar;
|
||||
free_ent = code + 1;
|
||||
@@ -290,16 +286,8 @@ uncompress(int fd_in, int fd_out)
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
write(fd_out, outbuf, outpos);
|
||||
}
|
||||
|
||||
retval = USE_DESKTOP(total_written) + 0;
|
||||
err:
|
||||
free(inbuf);
|
||||
free(outbuf);
|
||||
free(htab);
|
||||
free(codetab);
|
||||
return retval;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,985 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* gunzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support
|
||||
* files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* read_gz interface + associated hacking by Laurence Anderson
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char *license_msg[] = {
|
||||
" Copyright (C) 1992-1993 Jean-loup Gailly",
|
||||
" This program 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, or (at your option)",
|
||||
" any later version.",
|
||||
"",
|
||||
" This program 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 this program; if not, write to the Free Software",
|
||||
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.",
|
||||
0
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "config.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
typedef struct huft_s {
|
||||
unsigned char e; /* number of extra bits or operation */
|
||||
unsigned char b; /* number of bits in this code or subcode */
|
||||
union {
|
||||
unsigned short n; /* literal, length base, or distance base */
|
||||
struct huft_s *t; /* pointer to next level of table */
|
||||
} v;
|
||||
} huft_t;
|
||||
|
||||
static int gunzip_src_fd;
|
||||
unsigned int gunzip_bytes_out; /* number of output bytes */
|
||||
static unsigned int gunzip_outbuf_count; /* bytes in output buffer */
|
||||
|
||||
/* gunzip_window size--must be a power of two, and
|
||||
* at least 32K for zip's deflate method */
|
||||
static const int gunzip_wsize = 0x8000;
|
||||
static unsigned char *gunzip_window;
|
||||
|
||||
static unsigned int *gunzip_crc_table;
|
||||
unsigned int gunzip_crc;
|
||||
|
||||
/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
|
||||
#define BMAX 16 /* maximum bit length of any code (16 for explode) */
|
||||
#define N_MAX 288 /* maximum number of codes in any set */
|
||||
|
||||
/* bitbuffer */
|
||||
static unsigned int gunzip_bb; /* bit buffer */
|
||||
static unsigned char gunzip_bk; /* bits in bit buffer */
|
||||
|
||||
/* These control the size of the bytebuffer */
|
||||
static unsigned int bytebuffer_max = 0x8000;
|
||||
static unsigned char *bytebuffer = NULL;
|
||||
static unsigned int bytebuffer_offset = 0;
|
||||
static unsigned int bytebuffer_size = 0;
|
||||
|
||||
static const unsigned short mask_bits[] = {
|
||||
0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
};
|
||||
|
||||
/* Copy lengths for literal codes 257..285 */
|
||||
static const unsigned short cplens[] = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
|
||||
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
||||
};
|
||||
|
||||
/* note: see note #13 above about the 258 in this list. */
|
||||
/* Extra bits for literal codes 257..285 */
|
||||
static const unsigned char cplext[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
|
||||
5, 5, 5, 0, 99, 99
|
||||
}; /* 99==invalid */
|
||||
|
||||
/* Copy offsets for distance codes 0..29 */
|
||||
static const unsigned short cpdist[] = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
|
||||
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
/* Extra bits for distance codes */
|
||||
static const unsigned char cpdext[] = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
/* Order of the bit length code lengths */
|
||||
static const unsigned char border[] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
|
||||
static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current, const unsigned int required)
|
||||
{
|
||||
while (*current < required) {
|
||||
if (bytebuffer_offset >= bytebuffer_size) {
|
||||
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
|
||||
* to the front of the bytebuffer, leave 4 bytes free at end of tail
|
||||
* so we can easily top up buffer in check_trailer_gzip() */
|
||||
if (!(bytebuffer_size = bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8))) {
|
||||
bb_error_msg_and_die("unexpected end of file");
|
||||
}
|
||||
bytebuffer_size += 4;
|
||||
bytebuffer_offset = 4;
|
||||
}
|
||||
bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current;
|
||||
bytebuffer_offset++;
|
||||
*current += 8;
|
||||
}
|
||||
return(bitbuffer);
|
||||
}
|
||||
|
||||
static void make_gunzip_crc_table(void)
|
||||
{
|
||||
const unsigned int poly = 0xedb88320; /* polynomial exclusive-or pattern */
|
||||
unsigned short i; /* counter for all possible eight bit values */
|
||||
|
||||
/* initial shift register value */
|
||||
gunzip_crc = 0xffffffffL;
|
||||
gunzip_crc_table = (unsigned int *) malloc(256 * sizeof(unsigned int));
|
||||
|
||||
/* Compute and print table of CRC's, five per line */
|
||||
for (i = 0; i < 256; i++) {
|
||||
unsigned int table_entry; /* crc shift register */
|
||||
unsigned char k; /* byte being shifted into crc apparatus */
|
||||
|
||||
table_entry = i;
|
||||
/* The idea to initialize the register with the byte instead of
|
||||
* zero was stolen from Haruhiko Okumura's ar002
|
||||
*/
|
||||
for (k = 8; k; k--) {
|
||||
if (table_entry & 1) {
|
||||
table_entry = (table_entry >> 1) ^ poly;
|
||||
} else {
|
||||
table_entry >>= 1;
|
||||
}
|
||||
}
|
||||
gunzip_crc_table[i] = table_entry;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the malloc'ed tables built by huft_build(), which makes a linked
|
||||
* list of the tables it made, with the links in a dummy first entry of
|
||||
* each table.
|
||||
* t: table to free
|
||||
*/
|
||||
static int huft_free(huft_t * t)
|
||||
{
|
||||
huft_t *p;
|
||||
huft_t *q;
|
||||
|
||||
/* Go through linked list, freeing from the malloced (t[-1]) address. */
|
||||
p = t;
|
||||
while (p != (huft_t *) NULL) {
|
||||
q = (--p)->v.t;
|
||||
free((char *) p);
|
||||
p = q;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
* tables to decode that set of codes. Return zero on success, one if
|
||||
* the given code set is incomplete (the tables are still built in this
|
||||
* case), two if the input is invalid (all zero length codes or an
|
||||
* oversubscribed set of lengths), and three if not enough memory.
|
||||
*
|
||||
* b: code lengths in bits (all assumed <= BMAX)
|
||||
* n: number of codes (assumed <= N_MAX)
|
||||
* s: number of simple-valued codes (0..s-1)
|
||||
* d: list of base values for non-simple codes
|
||||
* e: list of extra bits for non-simple codes
|
||||
* t: result: starting table
|
||||
* m: maximum lookup bits, returns actual
|
||||
*/
|
||||
static int huft_build(unsigned int *b, const unsigned int n,
|
||||
const unsigned int s, const unsigned short *d,
|
||||
const unsigned char *e, huft_t ** t, int *m)
|
||||
{
|
||||
unsigned a; /* counter for codes of length k */
|
||||
unsigned c[BMAX + 1]; /* bit length count table */
|
||||
unsigned f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int h; /* table level */
|
||||
register unsigned i; /* counter, current code */
|
||||
register unsigned j; /* counter */
|
||||
register int k; /* number of bits in current code */
|
||||
int l; /* bits per table (returned in m) */
|
||||
register unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
register huft_t *q; /* points to current table */
|
||||
huft_t r; /* table entry for structure assignment */
|
||||
huft_t *u[BMAX]; /* table stack */
|
||||
unsigned v[N_MAX]; /* values in order of bit length */
|
||||
register int w; /* bits before this table == (l * h) */
|
||||
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
|
||||
unsigned *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
unsigned z; /* number of entries in current table */
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset((void *) (c), 0, sizeof(c));
|
||||
p = b;
|
||||
i = n;
|
||||
do {
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
p++; /* Can't combine with above line (Solaris bug) */
|
||||
} while (--i);
|
||||
if (c[0] == n) { /* null input--all zero length codes */
|
||||
*t = (huft_t *) NULL;
|
||||
*m = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
l = *m;
|
||||
for (j = 1; j <= BMAX; j++) {
|
||||
if (c[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
k = j; /* minimum code length */
|
||||
if ((unsigned) l < j) {
|
||||
l = j;
|
||||
}
|
||||
for (i = BMAX; i; i--) {
|
||||
if (c[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
g = i; /* maximum code length */
|
||||
if ((unsigned) l > i) {
|
||||
l = i;
|
||||
}
|
||||
*m = l;
|
||||
|
||||
/* Adjust last length count to fill out codes, if needed */
|
||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||
if ((y -= c[j]) < 0) {
|
||||
return 2; /* bad input: more codes than bits */
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0) {
|
||||
return 2;
|
||||
}
|
||||
c[i] += y;
|
||||
|
||||
/* Generate starting offsets into the value table for each length */
|
||||
x[1] = j = 0;
|
||||
p = c + 1;
|
||||
xp = x + 2;
|
||||
while (--i) { /* note that i == g from above */
|
||||
*xp++ = (j += *p++);
|
||||
}
|
||||
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = b;
|
||||
i = 0;
|
||||
do {
|
||||
if ((j = *p++) != 0) {
|
||||
v[x[j]++] = i;
|
||||
}
|
||||
} while (++i < n);
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
h = -1; /* no tables yet--level -1 */
|
||||
w = -l; /* bits decoded == (l * h) */
|
||||
u[0] = (huft_t *) NULL; /* just to keep compilers happy */
|
||||
q = (huft_t *) NULL; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
|
||||
/* go through the bit lengths (k already is bits in shortest code) */
|
||||
for (; k <= g; k++) {
|
||||
a = c[k];
|
||||
while (a--) {
|
||||
/* here i is the Huffman code of length k bits for value *p */
|
||||
/* make tables up to required level */
|
||||
while (k > w + l) {
|
||||
h++;
|
||||
w += l; /* previous table always l bits */
|
||||
|
||||
/* compute minimum size table less than or equal to l bits */
|
||||
z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */
|
||||
if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table *//* too few codes for k-w bit table */
|
||||
f -= a + 1; /* deduct codes from patterns left */
|
||||
xp = c + k;
|
||||
while (++j < z) { /* try smaller tables up to z bits */
|
||||
if ((f <<= 1) <= *++xp) {
|
||||
break; /* enough codes to use up j bits */
|
||||
}
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
|
||||
/* allocate and link in new table */
|
||||
q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t));
|
||||
|
||||
*t = q + 1; /* link to list for huft_free() */
|
||||
*(t = &(q->v.t)) = NULL;
|
||||
u[h] = ++q; /* table starts after link */
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h) {
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.b = (unsigned char) l; /* bits to dump before this table */
|
||||
r.e = (unsigned char) (16 + j); /* bits in this table */
|
||||
r.v.t = q; /* pointer to this table */
|
||||
j = i >> (w - l); /* (get around Turbo C bug) */
|
||||
u[h - 1][j] = r; /* connect to last table */
|
||||
}
|
||||
}
|
||||
|
||||
/* set up table entry in r */
|
||||
r.b = (unsigned char) (k - w);
|
||||
if (p >= v + n) {
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
} else if (*p < s) {
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */
|
||||
r.v.n = (unsigned short) (*p); /* simple code is just the value */
|
||||
p++; /* one compiler does not like *p++ */
|
||||
} else {
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.v.n = d[*p++ - s];
|
||||
}
|
||||
|
||||
/* fill code-like entries with r */
|
||||
f = 1 << (k - w);
|
||||
for (j = i >> w; j < z; j += f) {
|
||||
q[j] = r;
|
||||
}
|
||||
|
||||
/* backwards increment the k-bit code i */
|
||||
for (j = 1 << (k - 1); i & j; j >>= 1) {
|
||||
i ^= j;
|
||||
}
|
||||
i ^= j;
|
||||
|
||||
/* backup over finished tables */
|
||||
while ((i & ((1 << w) - 1)) != x[h]) {
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Return true (1) if we were given an incomplete table */
|
||||
return y != 0 && g != 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* inflate (decompress) the codes in a deflated (compressed) block.
|
||||
* Return an error code or zero if it all goes ok.
|
||||
*
|
||||
* tl, td: literal/length and distance decoder tables
|
||||
* bl, bd: number of bits decoded by tl[] and td[]
|
||||
*/
|
||||
static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned int my_bl, const unsigned int my_bd, int setup)
|
||||
{
|
||||
static unsigned int e; /* table entry flag/number of extra bits */
|
||||
static unsigned int n, d; /* length and index for copy */
|
||||
static unsigned int w; /* current gunzip_window position */
|
||||
static huft_t *t; /* pointer to table entry */
|
||||
static unsigned int ml, md; /* masks for bl and bd bits */
|
||||
static unsigned int b; /* bit buffer */
|
||||
static unsigned int k; /* number of bits in bit buffer */
|
||||
static huft_t *tl, *td;
|
||||
static unsigned int bl, bd;
|
||||
static int resumeCopy = 0;
|
||||
|
||||
if (setup) { // 1st time we are called, copy in variables
|
||||
tl = my_tl;
|
||||
td = my_td;
|
||||
bl = my_bl;
|
||||
bd = my_bd;
|
||||
/* make local copies of globals */
|
||||
b = gunzip_bb; /* initialize bit buffer */
|
||||
k = gunzip_bk;
|
||||
w = gunzip_outbuf_count; /* initialize gunzip_window position */
|
||||
|
||||
/* inflate the coded data */
|
||||
ml = mask_bits[bl]; /* precompute masks for speed */
|
||||
md = mask_bits[bd];
|
||||
return 0; // Don't actually do anything the first time
|
||||
}
|
||||
|
||||
if (resumeCopy) goto do_copy;
|
||||
|
||||
while (1) { /* do until end of block */
|
||||
b = fill_bitbuffer(b, &k, bl);
|
||||
if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
bb_error_msg_and_die("inflate_codes error 1");;
|
||||
}
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
b = fill_bitbuffer(b, &k, e);
|
||||
} while ((e =
|
||||
(t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
if (e == 16) { /* then it's a literal */
|
||||
gunzip_window[w++] = (unsigned char) t->v.n;
|
||||
if (w == gunzip_wsize) {
|
||||
gunzip_outbuf_count = (w);
|
||||
//flush_gunzip_window();
|
||||
w = 0;
|
||||
return 1; // We have a block to read
|
||||
}
|
||||
} else { /* it's an EOB or a length */
|
||||
|
||||
/* exit if end of block */
|
||||
if (e == 15) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* get length of block to copy */
|
||||
b = fill_bitbuffer(b, &k, e);
|
||||
n = t->v.n + ((unsigned) b & mask_bits[e]);
|
||||
b >>= e;
|
||||
k -= e;
|
||||
|
||||
/* decode distance of block to copy */
|
||||
b = fill_bitbuffer(b, &k, bd);
|
||||
if ((e = (t = td + ((unsigned) b & md))->e) > 16)
|
||||
do {
|
||||
if (e == 99)
|
||||
bb_error_msg_and_die("inflate_codes error 2");;
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
b = fill_bitbuffer(b, &k, e);
|
||||
} while ((e =
|
||||
(t =
|
||||
t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
b = fill_bitbuffer(b, &k, e);
|
||||
d = w - t->v.n - ((unsigned) b & mask_bits[e]);
|
||||
b >>= e;
|
||||
k -= e;
|
||||
|
||||
/* do the copy */
|
||||
do_copy: do {
|
||||
n -= (e =
|
||||
(e =
|
||||
gunzip_wsize - ((d &= gunzip_wsize - 1) > w ? d : w)) > n ? n : e);
|
||||
/* copy to new buffer to prevent possible overwrite */
|
||||
if (w - d >= e) { /* (this test assumes unsigned comparison) */
|
||||
memcpy(gunzip_window + w, gunzip_window + d, e);
|
||||
w += e;
|
||||
d += e;
|
||||
} else {
|
||||
/* do it slow to avoid memcpy() overlap */
|
||||
/* !NOMEMCPY */
|
||||
do {
|
||||
gunzip_window[w++] = gunzip_window[d++];
|
||||
} while (--e);
|
||||
}
|
||||
if (w == gunzip_wsize) {
|
||||
gunzip_outbuf_count = (w);
|
||||
if (n) resumeCopy = 1;
|
||||
else resumeCopy = 0;
|
||||
//flush_gunzip_window();
|
||||
w = 0;
|
||||
return 1;
|
||||
}
|
||||
} while (n);
|
||||
resumeCopy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* restore the globals from the locals */
|
||||
gunzip_outbuf_count = w; /* restore global gunzip_window pointer */
|
||||
gunzip_bb = b; /* restore global bit buffer */
|
||||
gunzip_bk = k;
|
||||
|
||||
/* normally just after call to inflate_codes, but save code by putting it here */
|
||||
/* free the decoding tables, return */
|
||||
huft_free(tl);
|
||||
huft_free(td);
|
||||
|
||||
/* done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
||||
{
|
||||
static int n, b_stored, k_stored, w;
|
||||
if (setup) {
|
||||
n = my_n;
|
||||
b_stored = my_b_stored;
|
||||
k_stored = my_k_stored;
|
||||
w = gunzip_outbuf_count; /* initialize gunzip_window position */
|
||||
return 0; // Don't do anything first time
|
||||
}
|
||||
|
||||
/* read and output the compressed data */
|
||||
while (n--) {
|
||||
b_stored = fill_bitbuffer(b_stored, &k_stored, 8);
|
||||
gunzip_window[w++] = (unsigned char) b_stored;
|
||||
if (w == (unsigned int) gunzip_wsize) {
|
||||
gunzip_outbuf_count = (w);
|
||||
//flush_gunzip_window();
|
||||
w = 0;
|
||||
b_stored >>= 8;
|
||||
k_stored -= 8;
|
||||
return 1; // We have a block
|
||||
}
|
||||
b_stored >>= 8;
|
||||
k_stored -= 8;
|
||||
}
|
||||
|
||||
/* restore the globals from the locals */
|
||||
gunzip_outbuf_count = w; /* restore global gunzip_window pointer */
|
||||
gunzip_bb = b_stored; /* restore global bit buffer */
|
||||
gunzip_bk = k_stored;
|
||||
return 0; // Finished
|
||||
}
|
||||
|
||||
/*
|
||||
* decompress an inflated block
|
||||
* e: last block flag
|
||||
*
|
||||
* GLOBAL VARIABLES: bb, kk,
|
||||
*/
|
||||
// Return values: -1 = inflate_stored, -2 = inflate_codes
|
||||
static int inflate_block(int *e)
|
||||
{
|
||||
unsigned t; /* block type */
|
||||
register unsigned int b; /* bit buffer */
|
||||
unsigned int k; /* number of bits in bit buffer */
|
||||
|
||||
/* make local bit buffer */
|
||||
|
||||
b = gunzip_bb;
|
||||
k = gunzip_bk;
|
||||
|
||||
/* read in last block bit */
|
||||
b = fill_bitbuffer(b, &k, 1);
|
||||
*e = (int) b & 1;
|
||||
b >>= 1;
|
||||
k -= 1;
|
||||
|
||||
/* read in block type */
|
||||
b = fill_bitbuffer(b, &k, 2);
|
||||
t = (unsigned) b & 3;
|
||||
b >>= 2;
|
||||
k -= 2;
|
||||
|
||||
/* restore the global bit buffer */
|
||||
gunzip_bb = b;
|
||||
gunzip_bk = k;
|
||||
|
||||
/* inflate that block type */
|
||||
switch (t) {
|
||||
case 0: /* Inflate stored */
|
||||
{
|
||||
unsigned int n; /* number of bytes in block */
|
||||
unsigned int b_stored; /* bit buffer */
|
||||
unsigned int k_stored; /* number of bits in bit buffer */
|
||||
|
||||
/* make local copies of globals */
|
||||
b_stored = gunzip_bb; /* initialize bit buffer */
|
||||
k_stored = gunzip_bk;
|
||||
|
||||
/* go to byte boundary */
|
||||
n = k_stored & 7;
|
||||
b_stored >>= n;
|
||||
k_stored -= n;
|
||||
|
||||
/* get the length and its complement */
|
||||
b_stored = fill_bitbuffer(b_stored, &k_stored, 16);
|
||||
n = ((unsigned) b_stored & 0xffff);
|
||||
b_stored >>= 16;
|
||||
k_stored -= 16;
|
||||
|
||||
b_stored = fill_bitbuffer(b_stored, &k_stored, 16);
|
||||
if (n != (unsigned) ((~b_stored) & 0xffff)) {
|
||||
return 1; /* error in compressed data */
|
||||
}
|
||||
b_stored >>= 16;
|
||||
k_stored -= 16;
|
||||
|
||||
inflate_stored(n, b_stored, k_stored, 1); // Setup inflate_stored
|
||||
return -1;
|
||||
}
|
||||
case 1: /* Inflate fixed
|
||||
* decompress an inflated type 1 (fixed Huffman codes) block. We should
|
||||
* either replace this with a custom decoder, or at least precompute the
|
||||
* Huffman tables.
|
||||
*/
|
||||
{
|
||||
int i; /* temporary variable */
|
||||
huft_t *tl; /* literal/length code table */
|
||||
huft_t *td; /* distance code table */
|
||||
unsigned int bl; /* lookup bits for tl */
|
||||
unsigned int bd; /* lookup bits for td */
|
||||
unsigned int l[288]; /* length list for huft_build */
|
||||
|
||||
/* set up literal table */
|
||||
for (i = 0; i < 144; i++) {
|
||||
l[i] = 8;
|
||||
}
|
||||
for (; i < 256; i++) {
|
||||
l[i] = 9;
|
||||
}
|
||||
for (; i < 280; i++) {
|
||||
l[i] = 7;
|
||||
}
|
||||
for (; i < 288; i++) { /* make a complete, but wrong code set */
|
||||
l[i] = 8;
|
||||
}
|
||||
bl = 7;
|
||||
if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) {
|
||||
return i;
|
||||
}
|
||||
|
||||
/* set up distance table */
|
||||
for (i = 0; i < 30; i++) { /* make an incomplete code set */
|
||||
l[i] = 5;
|
||||
}
|
||||
bd = 5;
|
||||
if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
|
||||
huft_free(tl);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* decompress until an end-of-block code */
|
||||
inflate_codes(tl, td, bl, bd, 1); // Setup inflate_codes
|
||||
|
||||
/* huft_free code moved into inflate_codes */
|
||||
|
||||
return -2;
|
||||
}
|
||||
case 2: /* Inflate dynamic */
|
||||
{
|
||||
const int dbits = 6; /* bits in base distance lookup table */
|
||||
const int lbits = 9; /* bits in base literal/length lookup table */
|
||||
|
||||
huft_t *tl; /* literal/length code table */
|
||||
huft_t *td; /* distance code table */
|
||||
unsigned int i; /* temporary variables */
|
||||
unsigned int j;
|
||||
unsigned int l; /* last length */
|
||||
unsigned int m; /* mask for bit lengths table */
|
||||
unsigned int n; /* number of lengths to get */
|
||||
unsigned int bl; /* lookup bits for tl */
|
||||
unsigned int bd; /* lookup bits for td */
|
||||
unsigned int nb; /* number of bit length codes */
|
||||
unsigned int nl; /* number of literal/length codes */
|
||||
unsigned int nd; /* number of distance codes */
|
||||
|
||||
unsigned int ll[286 + 30]; /* literal/length and distance code lengths */
|
||||
unsigned int b_dynamic; /* bit buffer */
|
||||
unsigned int k_dynamic; /* number of bits in bit buffer */
|
||||
|
||||
/* make local bit buffer */
|
||||
b_dynamic = gunzip_bb;
|
||||
k_dynamic = gunzip_bk;
|
||||
|
||||
/* read in table lengths */
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5);
|
||||
nl = 257 + ((unsigned int) b_dynamic & 0x1f); /* number of literal/length codes */
|
||||
|
||||
b_dynamic >>= 5;
|
||||
k_dynamic -= 5;
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5);
|
||||
nd = 1 + ((unsigned int) b_dynamic & 0x1f); /* number of distance codes */
|
||||
|
||||
b_dynamic >>= 5;
|
||||
k_dynamic -= 5;
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 4);
|
||||
nb = 4 + ((unsigned int) b_dynamic & 0xf); /* number of bit length codes */
|
||||
|
||||
b_dynamic >>= 4;
|
||||
k_dynamic -= 4;
|
||||
if (nl > 286 || nd > 30) {
|
||||
return 1; /* bad lengths */
|
||||
}
|
||||
|
||||
/* read in bit-length-code lengths */
|
||||
for (j = 0; j < nb; j++) {
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3);
|
||||
ll[border[j]] = (unsigned int) b_dynamic & 7;
|
||||
b_dynamic >>= 3;
|
||||
k_dynamic -= 3;
|
||||
}
|
||||
for (; j < 19; j++) {
|
||||
ll[border[j]] = 0;
|
||||
}
|
||||
|
||||
/* build decoding table for trees--single level, 7 bit lookup */
|
||||
bl = 7;
|
||||
i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl);
|
||||
if (i != 0) {
|
||||
if (i == 1) {
|
||||
huft_free(tl);
|
||||
}
|
||||
return i; /* incomplete code set */
|
||||
}
|
||||
|
||||
/* read in literal and distance code lengths */
|
||||
n = nl + nd;
|
||||
m = mask_bits[bl];
|
||||
i = l = 0;
|
||||
while ((unsigned int) i < n) {
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, (unsigned int)bl);
|
||||
j = (td = tl + ((unsigned int) b_dynamic & m))->b;
|
||||
b_dynamic >>= j;
|
||||
k_dynamic -= j;
|
||||
j = td->v.n;
|
||||
if (j < 16) { /* length of code in bits (0..15) */
|
||||
ll[i++] = l = j; /* save last length in l */
|
||||
} else if (j == 16) { /* repeat last length 3 to 6 times */
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 2);
|
||||
j = 3 + ((unsigned int) b_dynamic & 3);
|
||||
b_dynamic >>= 2;
|
||||
k_dynamic -= 2;
|
||||
if ((unsigned int) i + j > n) {
|
||||
return 1;
|
||||
}
|
||||
while (j--) {
|
||||
ll[i++] = l;
|
||||
}
|
||||
} else if (j == 17) { /* 3 to 10 zero length codes */
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3);
|
||||
j = 3 + ((unsigned int) b_dynamic & 7);
|
||||
b_dynamic >>= 3;
|
||||
k_dynamic -= 3;
|
||||
if ((unsigned int) i + j > n) {
|
||||
return 1;
|
||||
}
|
||||
while (j--) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
} else { /* j == 18: 11 to 138 zero length codes */
|
||||
b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 7);
|
||||
j = 11 + ((unsigned int) b_dynamic & 0x7f);
|
||||
b_dynamic >>= 7;
|
||||
k_dynamic -= 7;
|
||||
if ((unsigned int) i + j > n) {
|
||||
return 1;
|
||||
}
|
||||
while (j--) {
|
||||
ll[i++] = 0;
|
||||
}
|
||||
l = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* free decoding table for trees */
|
||||
huft_free(tl);
|
||||
|
||||
/* restore the global bit buffer */
|
||||
gunzip_bb = b_dynamic;
|
||||
gunzip_bk = k_dynamic;
|
||||
|
||||
/* build the decoding tables for literal/length and distance codes */
|
||||
bl = lbits;
|
||||
|
||||
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
|
||||
if (i == 1) {
|
||||
bb_error_msg_and_die("Incomplete literal tree");
|
||||
huft_free(tl);
|
||||
}
|
||||
return i; /* incomplete code set */
|
||||
}
|
||||
|
||||
bd = dbits;
|
||||
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
|
||||
if (i == 1) {
|
||||
bb_error_msg_and_die("incomplete distance tree");
|
||||
huft_free(td);
|
||||
}
|
||||
huft_free(tl);
|
||||
return i; /* incomplete code set */
|
||||
}
|
||||
|
||||
/* decompress until an end-of-block code */
|
||||
inflate_codes(tl, td, bl, bd, 1); // Setup inflate_codes
|
||||
|
||||
/* huft_free code moved into inflate_codes */
|
||||
|
||||
return -2;
|
||||
}
|
||||
default:
|
||||
/* bad block type */
|
||||
bb_error_msg_and_die("bad block type %d\n", t);
|
||||
}
|
||||
}
|
||||
|
||||
static void calculate_gunzip_crc(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
gunzip_bytes_out += gunzip_outbuf_count;
|
||||
}
|
||||
|
||||
static int inflate_get_next_window(void)
|
||||
{
|
||||
static int method = -1; // Method == -1 for stored, -2 for codes
|
||||
static int e = 0;
|
||||
static int needAnotherBlock = 1;
|
||||
|
||||
gunzip_outbuf_count = 0;
|
||||
|
||||
while(1) {
|
||||
int ret;
|
||||
|
||||
if (needAnotherBlock) {
|
||||
if(e) {
|
||||
calculate_gunzip_crc();
|
||||
e = 0;
|
||||
needAnotherBlock = 1;
|
||||
return 0;
|
||||
} // Last block
|
||||
method = inflate_block(&e);
|
||||
needAnotherBlock = 0;
|
||||
}
|
||||
|
||||
switch (method) {
|
||||
case -1: ret = inflate_stored(0,0,0,0);
|
||||
break;
|
||||
case -2: ret = inflate_codes(0,0,0,0,0);
|
||||
break;
|
||||
default: bb_error_msg_and_die("inflate error %d", method);
|
||||
}
|
||||
|
||||
if (ret == 1) {
|
||||
calculate_gunzip_crc();
|
||||
return 1; // More data left
|
||||
} else needAnotherBlock = 1; // End of that block
|
||||
}
|
||||
/* Doesnt get here */
|
||||
}
|
||||
|
||||
/* Initialise bytebuffer, be careful not to overfill the buffer */
|
||||
extern void inflate_init(unsigned int bufsize)
|
||||
{
|
||||
/* Set the bytebuffer size, default is same as gunzip_wsize */
|
||||
bytebuffer_max = bufsize + 8;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer_size = 0;
|
||||
}
|
||||
|
||||
extern int inflate_unzip(int in, int out)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
typedef void (*sig_type) (int);
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
gunzip_window = xmalloc(gunzip_wsize);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = in;
|
||||
|
||||
/* initialize gunzip_window, bit buffer */
|
||||
gunzip_bk = 0;
|
||||
gunzip_bb = 0;
|
||||
|
||||
/* Create the crc table */
|
||||
make_gunzip_crc_table();
|
||||
|
||||
/* Allocate space for buffer */
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
|
||||
while(1) {
|
||||
int ret = inflate_get_next_window();
|
||||
nwrote = bb_full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == -1) {
|
||||
bb_perror_msg("write");
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0) break;
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
free(gunzip_window);
|
||||
free(gunzip_crc_table);
|
||||
|
||||
/* Store unused bytes in a global buffer so calling applets can access it */
|
||||
if (gunzip_bk >= 8) {
|
||||
/* Undo too much lookahead. The next read will be byte aligned
|
||||
* so we can discard unused bits in the last meaningful byte. */
|
||||
bytebuffer_offset--;
|
||||
bytebuffer[bytebuffer_offset] = gunzip_bb & 0xff;
|
||||
gunzip_bb >>= 8;
|
||||
gunzip_bk -= 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int inflate_gunzip(int in, int out)
|
||||
{
|
||||
unsigned int stored_crc = 0;
|
||||
unsigned char count;
|
||||
|
||||
inflate_unzip(in, out);
|
||||
|
||||
/* top up the input buffer with the rest of the trailer */
|
||||
count = bytebuffer_size - bytebuffer_offset;
|
||||
if (count < 8) {
|
||||
bb_xread_all(in, &bytebuffer[bytebuffer_size], 8 - count);
|
||||
bytebuffer_size += 8 - count;
|
||||
}
|
||||
for (count = 0; count != 4; count++) {
|
||||
stored_crc |= (bytebuffer[bytebuffer_offset] << (count * 8));
|
||||
bytebuffer_offset++;
|
||||
}
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("crc error");
|
||||
}
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (gunzip_bytes_out !=
|
||||
(bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) |
|
||||
(bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))) {
|
||||
bb_error_msg("Incorrect length");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 1505 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user