Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b7f6928c6 | ||
|
|
a2af67a8c5 | ||
|
|
d0119d15f9 | ||
|
|
8d42f86b14 |
No files matched your search
@@ -1,7 +0,0 @@
|
||||
busybox
|
||||
busybox.links
|
||||
_install
|
||||
.config
|
||||
.menuconfig.log
|
||||
.config.cmd
|
||||
.config.old
|
||||
@@ -2,12 +2,15 @@ List of the authors of code contained in BusyBox.
|
||||
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
incorrect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Peter Willis <psyphreak@phreaker.net>
|
||||
eject
|
||||
|
||||
Emanuele Aina <emanuele.aina@tiscali.it>
|
||||
run-parts
|
||||
|
||||
@@ -23,12 +26,21 @@ 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
|
||||
|
||||
Edward Betts <edward@debian.org>
|
||||
expr, hostid, logname, whoami
|
||||
|
||||
John Beppu <beppu@codepoet.org>
|
||||
du, nslookup, sort
|
||||
|
||||
David Brownell <dbrownell@users.sourceforge.net>
|
||||
zcip
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
|
||||
@@ -69,6 +81,14 @@ Daniel Jacobowitz <dan@debian.org>
|
||||
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)
|
||||
|
||||
Stephan Linz <linz@li-pro.net>
|
||||
ipcalc, Red Hat equivalence
|
||||
|
||||
@@ -76,13 +96,14 @@ John Lombardo <john@deltanet.com>
|
||||
tr
|
||||
|
||||
Glenn McGrath <bug1@iinet.net.au>
|
||||
Common unarchving code and unarchiving applets, ifupdown, ftpgetput,
|
||||
nameif, sed, patch, fold, install, uudecode.
|
||||
Various bugfixes, review and apply numerous patches.
|
||||
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, make_directory, parse_mode, dirname, mode_string,
|
||||
mesg, vconfig, nice, renice,
|
||||
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
|
||||
@@ -91,8 +112,9 @@ Manuel Novoa III <mjn3@codepoet.org>
|
||||
interface, dutmp, ifconfig, route
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
cmdedit; xargs(current), httpd(current);
|
||||
ports: ash, crond, fdisk, inetd, stty, traceroute, top;
|
||||
cmdedit; bb_mkdep, xargs(current), httpd(current);
|
||||
ports: ash, crond, fdisk (initial, unmaintained now), inetd, stty, traceroute,
|
||||
top;
|
||||
locale, various fixes
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
@@ -100,6 +122,9 @@ 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
|
||||
|
||||
@@ -115,7 +140,10 @@ Pavel Roskin <proski@gnu.org>
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
Remote logging feature for syslogd
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
Rob Sullivan <cogito.ergo.cogito@gmail.com>
|
||||
comm
|
||||
|
||||
Linus Torvalds
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Mark Whitley <markw@codepoet.org>
|
||||
@@ -129,5 +157,17 @@ 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 and fdformat.
|
||||
devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm,
|
||||
fdformat, lsattr, chattr, id and eject.
|
||||
|
||||
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,479 @@
|
||||
#
|
||||
# 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. This feature requires the
|
||||
/proc filesystem.
|
||||
|
||||
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_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_SYSLOG
|
||||
bool "Support for 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_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 FEATURE_HAVE_RPC
|
||||
bool "RPC support"
|
||||
default y
|
||||
help
|
||||
Select this if you have rpc support.
|
||||
This automatically turns off all configuration options that rely
|
||||
on RPC.
|
||||
|
||||
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 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.
|
||||
|
||||
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
|
||||
help
|
||||
Build a shared library libbusybox.so which contains all
|
||||
libraries used inside busybox.
|
||||
|
||||
This is an experimental feature intended to support the upcoming
|
||||
"make standalone" mode. Enabling it against the one big busybox
|
||||
binary serves no purpose (and increases the size). You should
|
||||
almost certainly say "no" to this right now.
|
||||
|
||||
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_SHARED_BUSYBOX
|
||||
bool "Use shared libbusybox for busybox"
|
||||
default y if BUILD_LIBBUSYBOX
|
||||
depends on !STATIC && BUILD_LIBBUSYBOX
|
||||
help
|
||||
Use libbusybox.so also for busybox itself.
|
||||
You need to have a working dynamic linker to use this variant.
|
||||
|
||||
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'.
|
||||
|
||||
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.
|
||||
|
||||
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 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
|
||||
depends on DEBUG
|
||||
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 DEBUG_YANK_SUSv2
|
||||
bool "Disable obsolete features removed before SUSv3?"
|
||||
default y
|
||||
help
|
||||
This option will disable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will not be supported in head, tail, and fold. (Note: should
|
||||
yank from 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_DONT
|
||||
bool
|
||||
prompt "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL
|
||||
help
|
||||
Do not install applets links. Usefull when using the -install feature
|
||||
or a standalone shell for rescue pruposes.
|
||||
|
||||
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
|
||||
@@ -1,20 +1,125 @@
|
||||
1) Run 'make config' or 'make menuconfig' and select the
|
||||
functionality that you wish to enable.
|
||||
Building:
|
||||
=========
|
||||
|
||||
2) Run 'make dep'
|
||||
The BusyBox build process is similar to the Linux kernel build:
|
||||
|
||||
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)
|
||||
make menuconfig # This creates a file called ".config"
|
||||
make # This creates the "busybox" executable
|
||||
make install # or make PREFIX=/path/from/root install
|
||||
|
||||
4) Run 'make'
|
||||
The full list of configuration and install options is available by typing:
|
||||
|
||||
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...
|
||||
make help
|
||||
|
||||
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'....
|
||||
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 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.
|
||||
@@ -1,3 +1,11 @@
|
||||
--- 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
|
||||
|
||||
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
%.bflt: %_unstripped
|
||||
$(CROSS_COMPILE)elf2flt $(ELF2FLTFLAGS) $< -o $@
|
||||
|
||||
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
|
||||
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
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:1=),-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
|
||||
|
||||
.PHONY: baseline
|
||||
baseline: busybox_unstripped
|
||||
@mv busybox_unstripped busybox_old
|
||||
|
||||
.PHONY: objsizes
|
||||
objsizes: busybox_unstripped
|
||||
$(srctree)/scripts/objsizes
|
||||
|
||||
.PHONY: bigdata
|
||||
bigdata: busybox_unstripped
|
||||
nm --size-sort busybox_unstripped | grep -vi ' [tr] ' | tail -20
|
||||
|
||||
# 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 $@ $^
|
||||
@@ -0,0 +1,28 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
|
||||
CPPFLAGS += \
|
||||
-std=gnu99 \
|
||||
-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
|
||||
|
||||
CFLAGS += \
|
||||
-Wall -Wstrict-prototypes -Wshadow -Werror -Wundef \
|
||||
-funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \
|
||||
-Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += -g
|
||||
LDFLAGS += -g
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# ==========================================================================
|
||||
# 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 $(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
|
||||
@@ -1,127 +1,198 @@
|
||||
Please see the LICENSE file for details on copying and usage.
|
||||
Please refer to the INSTALL file for instructions on how to build.
|
||||
|
||||
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 GNU coreutils, util-linux, etc. The utilities in BusyBox
|
||||
generally have fewer options than their full-featured GNU cousins; however, the
|
||||
options that are included provide the expected functionality and behave very
|
||||
much like their GNU counterparts.
|
||||
What is busybox:
|
||||
|
||||
BusyBox has been written with size-optimization and limited resources in mind.
|
||||
It is also extremely modular so you can easily include or exclude commands (or
|
||||
features) at compile time. This makes it easy to customize your embedded
|
||||
systems. To create a working system, just add /dev, /etc, and a Linux kernel.
|
||||
BusyBox provides a fairly complete POSIX environment for any small or embedded
|
||||
system.
|
||||
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.
|
||||
|
||||
BusyBox is extremely configurable. This allows you to include only the
|
||||
components you need, thereby reducing binary size. Run 'make config' or
|
||||
'make menuconfig' to select the functionality that you wish to enable.
|
||||
BusyBox has been written with size-optimization and limited resources in
|
||||
mind, both to produce small binaries and to reduce run-time memory usage.
|
||||
Busybox is also extremely modular so you can easily include or exclude
|
||||
commands (or features) at compile time. This makes it easy to customize
|
||||
embedded systems; to create a working system, just add /dev, /etc, and a
|
||||
Linux kernel. Busybox (usually together with uClibc) has also been used as
|
||||
a component of "thin client" desktop systems, live-CD distributions, rescue
|
||||
disks, installers, and so on.
|
||||
|
||||
After the build is complete, a busybox.links file is generated. This is
|
||||
used by 'make install' to create symlinks to the BusyBox binary for all
|
||||
compiled in functions. By default, 'make install' will place the symlink
|
||||
forest into `pwd`/_install unless you have defined the PREFIX environment
|
||||
variable (i.e., 'make PREFIX=/tmp/foo install')
|
||||
|
||||
If you wish to install hard links, rather than symlinks, you can use
|
||||
'make PREFIX=/tmp/foo install-hardlinks' instead.
|
||||
BusyBox provides a fairly complete POSIX environment for any small system,
|
||||
both embedded environments and more full featured systems concerned about
|
||||
space. Busybox is slowly working towards implementing the full Single Unix
|
||||
Specification V3 (http://www.opengroup.org/onlinepubs/009695399/), but isn't
|
||||
there yet (and for size reasons will probably support at most UTF-8 for
|
||||
internationalization). We are also interested in passing the Linux Test
|
||||
Project (http://ltp.sourceforge.net).
|
||||
|
||||
----------------
|
||||
|
||||
Supported architectures:
|
||||
Using busybox:
|
||||
|
||||
BusyBox in general will build on any architecture supported by gcc.
|
||||
Kernel module loading for 2.2 and 2.4 Linux kernels is currently
|
||||
limited to ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC,
|
||||
S390, SH3/4/5, Sparc, v850e, and x86_64 for 2.4.x kernels. For 2.6.x
|
||||
kernels, kernel module loading support should work on all architectures.
|
||||
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.)
|
||||
|
||||
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").
|
||||
|
||||
Supported C Libraries:
|
||||
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
|
||||
installed in the path. (Note that this requires /proc to be mounted, if
|
||||
testing from a boot floppy or in a chroot environment.)
|
||||
|
||||
uClibc and glibc are supported. People have been looking at newlib and
|
||||
dietlibc, but they are currently considered unsupported, untested, or
|
||||
worse. Linux-libc5 is no longer supported -- you should probably use uClibc
|
||||
instead if you want a small C library.
|
||||
|
||||
Supported kernels:
|
||||
|
||||
Full functionality requires Linux 2.2.x or better. A large fraction of the
|
||||
code should run on just about anything. While the current code is fairly
|
||||
Linux specific, it should be fairly easy to port the majority of the code
|
||||
to support, say, FreeBSD or Solaris, or Mac OS X, or even Windows (if you
|
||||
are into that sort of thing).
|
||||
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 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").
|
||||
|
||||
----------------
|
||||
|
||||
Getting help:
|
||||
Downloading the current source code:
|
||||
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
Source for the latest released version, as well as daily snapshots, can always
|
||||
be downloaded from
|
||||
|
||||
http://busybox.net/downloads/
|
||||
|
||||
You can browse the up to the minute source code and change history online.
|
||||
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
|
||||
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
|
||||
http://busybox.net/subversion.html
|
||||
|
||||
For those that are actively contributing and would like to check files in,
|
||||
see:
|
||||
|
||||
http://busybox.net/developer.html
|
||||
|
||||
The developers also have a bug and patch tracking system
|
||||
(http://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
is generally a faster way of getting it fixed, and the complete archive of
|
||||
what happened is the subversion changelog.
|
||||
|
||||
----------------
|
||||
|
||||
Bugs:
|
||||
getting help:
|
||||
|
||||
If you find bugs, please submit a detailed bug report to the BusyBox mailing
|
||||
list at busybox@mail.busybox.net. A well-written bug report should include a
|
||||
transcript of a shell session that demonstrates the bad behavior and enables
|
||||
anyone else to duplicate the bug on their own machine. The following is such
|
||||
an example:
|
||||
when you find you need help, you can check out the busybox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
To: busybox@mail.busybox.net
|
||||
From: diligent@testing.linux.org
|
||||
Subject: /bin/date doesn't work
|
||||
----------------
|
||||
|
||||
Package: BusyBox
|
||||
Version: 1.00
|
||||
bugs:
|
||||
|
||||
When I execute BusyBox 'date' it produces unexpected results.
|
||||
With GNU date I get the following output:
|
||||
if you find bugs, please submit a detailed bug report to the busybox mailing
|
||||
list at busybox@busybox.net. a well-written bug report should include a
|
||||
transcript of a shell session that demonstrates the bad behavior and enables
|
||||
anyone else to duplicate the bug on their own machine. the following is such
|
||||
an example:
|
||||
|
||||
to: busybox@busybox.net
|
||||
from: diligent@testing.linux.org
|
||||
subject: /bin/date doesn't work
|
||||
|
||||
package: busybox
|
||||
version: 1.00
|
||||
|
||||
when i execute busybox 'date' it produces unexpected results.
|
||||
with gnu date i get the following output:
|
||||
|
||||
$ date
|
||||
Fri Oct 8 14:19:41 MDT 2004
|
||||
fri oct 8 14:19:41 mdt 2004
|
||||
|
||||
But when I use BusyBox date I get this instead:
|
||||
but when i use busybox date i get this instead:
|
||||
|
||||
$ date
|
||||
illegal instruction
|
||||
|
||||
I am using Debian unstable, kernel version 2.4.25-vrs2 on a Netwinder,
|
||||
and the latest uClibc from CVS. Thanks for the wonderful program!
|
||||
i am using debian unstable, kernel version 2.4.25-vrs2 on a netwinder,
|
||||
and the latest uclibc from cvs. thanks for the wonderful program!
|
||||
|
||||
-Diligent
|
||||
-diligent
|
||||
|
||||
Note the careful description and use of examples showing not only what BusyBox
|
||||
does, but also a counter example showing what an equivalent GNU app does. Bug
|
||||
reports lacking such detail may never be fixed... Thanks for understanding.
|
||||
note the careful description and use of examples showing not only what
|
||||
busybox does, but also a counter example showing what an equivalent app
|
||||
does (or pointing to the text of a relevant standard). Bug reports lacking
|
||||
such detail may never be fixed... Thanks for understanding.
|
||||
|
||||
----------------
|
||||
|
||||
Downloads:
|
||||
Portability:
|
||||
|
||||
Source for the latest released version, as well as daily snapshots, can always
|
||||
be downloaded from
|
||||
http://busybox.net/downloads/
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.)
|
||||
|
||||
Some environments are not recommended. Early versions of uClibc were buggy
|
||||
and missing many features: upgrade. Linking against libc5 or dietlibc is
|
||||
not supported and not interesting to the busybox developers. (The first is
|
||||
obsolete and has no known size or feature advantages over uClibc, the second
|
||||
has known bugs that its developers have actively refused to fix.) Ancient
|
||||
Linux kernels (2.0.x and earlier) are similarly uninteresting.
|
||||
|
||||
In theory it's possible to use Busybox under other operating systems (such as
|
||||
MacOS X, Solaris, Cygwin, or the BSD Fork Du Jour). This generally involves
|
||||
a different kernel and a different C library at the same time. While it
|
||||
should be possible to port the majority of the code to work in one of
|
||||
these environments, don't be suprised if it doesn't work out of the box. If
|
||||
you're into that sort of thing, start small (selecting just a few applets)
|
||||
and work your way up.
|
||||
|
||||
Shaun Jackman has recently (2005) ported busybox to a combination of newlib
|
||||
and libgloss, and some of his patches have been integrated. This platform
|
||||
may join glibc/uclibc and Linux as a supported combination with the 1.1
|
||||
release, but is not supported in 1.0.
|
||||
|
||||
Supported hardware:
|
||||
|
||||
BusyBox in general will build on any architecture supported by gcc. We
|
||||
support both 32 and 64 bit platforms, and both big and little endian
|
||||
systems.
|
||||
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
architectures supported by the kernel.
|
||||
|
||||
----------------
|
||||
|
||||
CVS:
|
||||
|
||||
BusyBox now has its own publicly browsable CVS tree at:
|
||||
http://busybox.net/cgi-bin/cvsweb/busybox/
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://busybox.net/cvs_anon.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://busybox.net/cvs_write.html
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@codepoet.org>
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to the busybox
|
||||
maintainer:
|
||||
Denis Vlasenko
|
||||
<vda.linux@googlemail.com>
|
||||
@@ -1,196 +0,0 @@
|
||||
# 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.00
|
||||
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=-r
|
||||
|
||||
#--------------------------------------------------------
|
||||
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)
|
||||
|
||||
#--------------------------------------------------------
|
||||
# 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=
|
||||
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 += -s -Wl,-warn-common
|
||||
STRIPCMD:=$(STRIP) --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
|
||||
|
||||
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
|
||||
@@ -1,11 +1,309 @@
|
||||
Busybox TODO
|
||||
|
||||
Stuff that needs to be done
|
||||
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.
|
||||
There's base64 encoding and decoding going on in:
|
||||
networking/wget.c:base64enc()
|
||||
coreutils/uudecode.c:read_base64()
|
||||
coreutils/uuencode.c:tbl_base64[]
|
||||
networking/httpd.c:decodeBase64()
|
||||
And probably elsewhere. That needs to be unified into libbb functions.
|
||||
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!
|
||||
Add chrt applet. Please CC Bernhard if you suggest a patch.
|
||||
|
||||
As yet unclaimed:
|
||||
|
||||
----
|
||||
tr - missing SuS3 features in busybox 1.0pre10
|
||||
|
||||
tr doesnt support [:blank:], [:digit:] or other predefined classes, [=equiv=]
|
||||
support is also missing.
|
||||
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
|
||||
---
|
||||
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?
|
||||
---
|
||||
|
||||
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
|
||||
---
|
||||
@@ -0,0 +1,21 @@
|
||||
# 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
|
||||
obj-y += busybox.o
|
||||
|
||||
# Generated file needs additional love
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
|
||||
hostprogs-y += usage
|
||||
always := $(hostprogs-y)
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
include/usage_compressed.h: $(srctree)/include/usage.h applets/usage
|
||||
@echo ' GEN include/usage_compressed.h'
|
||||
@$(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
@@ -1,32 +0,0 @@
|
||||
# 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)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# 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) -ro $@ $(APPLET_OBJ)
|
||||
|
||||
$(APPLET_OBJ): $(top_builddir)/.config
|
||||
$(APPLET_OBJ): $(APPLETS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+198
-227
@@ -6,264 +6,85 @@
|
||||
* 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.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
const char usage_messages[] =
|
||||
/* 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 utterly unsuitable for static linking anyway.
|
||||
#endif
|
||||
|
||||
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
|
||||
static const char usage_messages[] =
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
|
||||
#include "applets.h"
|
||||
|
||||
;
|
||||
|
||||
#undef MAKE_USAGE
|
||||
#else
|
||||
#define usage_messages 0
|
||||
#endif /* ENABLE_SHOW_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
|
||||
static struct BB_suid_config
|
||||
{
|
||||
struct BB_applet *m_applet;
|
||||
struct BB_applet *m_applet;
|
||||
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
|
||||
struct BB_suid_config *m_next;
|
||||
};
|
||||
struct BB_suid_config *m_next;
|
||||
} *suid_config;
|
||||
|
||||
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)
|
||||
static int ingroup(uid_t u, gid_t g)
|
||||
{
|
||||
struct group *grp = getgrgid (g);
|
||||
struct group *grp = getgrgid(g);
|
||||
|
||||
if (grp) {
|
||||
char **mem;
|
||||
if (grp) {
|
||||
char **mem;
|
||||
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam (*mem);
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam(*mem);
|
||||
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
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.
|
||||
*/
|
||||
@@ -281,7 +102,7 @@ static char *get_trimmed_slice(char *s, char *e)
|
||||
|
||||
/* 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);
|
||||
return skip_whitespace(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -322,7 +143,7 @@ static void parse_config_file(void)
|
||||
|| !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? */
|
||||
|| !(f = fopen(config_file, "r")) /* Cannot open? */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -422,7 +243,7 @@ static void parse_config_file(void)
|
||||
|
||||
/* Get the specified mode. */
|
||||
|
||||
e = (char *) bb_skip_whitespace(e+1);
|
||||
e = skip_whitespace(e+1);
|
||||
|
||||
for (i=0 ; i < 3 ; i++) {
|
||||
const char *q;
|
||||
@@ -434,8 +255,8 @@ static void parse_config_file(void)
|
||||
}
|
||||
|
||||
/* Now get the the user/group info. */
|
||||
|
||||
s = (char *) bb_skip_whitespace(e);
|
||||
|
||||
s = skip_whitespace(e);
|
||||
|
||||
/* Note: We require whitespace between the mode and the
|
||||
* user/group info. */
|
||||
@@ -451,8 +272,8 @@ static void parse_config_file(void)
|
||||
|
||||
sct->m_uid = strtoul(s, &e2, 10);
|
||||
if (*e2 || (s == e2)) {
|
||||
struct passwd *pwd;
|
||||
if (!(pwd = getpwnam(s))) {
|
||||
struct passwd *pwd = getpwnam(s);
|
||||
if (!pwd) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
@@ -498,15 +319,165 @@ static void parse_config_file(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
#define parse_config_file()
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
static 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 */
|
||||
xsetgid(sct->m_gid);
|
||||
} else xsetgid(rgid); /* no sgid -> drop */
|
||||
|
||||
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
|
||||
else xsetuid(ruid); /* no suid -> drop */
|
||||
} else {
|
||||
/* default: drop all privileges */
|
||||
xsetgid(rgid);
|
||||
xsetuid(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
|
||||
|
||||
#endif
|
||||
if (applet->need_suid == _BB_SUID_ALWAYS) {
|
||||
if (geteuid()) bb_error_msg_and_die("applet requires root privileges!");
|
||||
} else if (applet->need_suid == _BB_SUID_NEVER) {
|
||||
xsetgid(rgid); /* drop all privileges */
|
||||
xsetuid(ruid);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define check_suid(x)
|
||||
#endif /* CONFIG_FEATURE_SUID */
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
|
||||
|
||||
#ifdef CONFIG_FEATURE_COMPRESS_USAGE
|
||||
|
||||
#include "usage_compressed.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static const char *unpack_usage_messages(void)
|
||||
{
|
||||
int input[2], output[2], pid;
|
||||
char *buf;
|
||||
|
||||
if(pipe(input) < 0 || pipe(output) < 0)
|
||||
exit(1);
|
||||
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case -1: /* error */
|
||||
exit(1);
|
||||
case 0: /* child */
|
||||
close(input[1]);
|
||||
close(output[0]);
|
||||
uncompressStream(input[0], output[1]);
|
||||
exit(0);
|
||||
}
|
||||
/* parent */
|
||||
|
||||
close(input[0]);
|
||||
close(output[1]);
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case -1: /* error */
|
||||
exit(1);
|
||||
case 0: /* child */
|
||||
full_write(input[1], packed_usage, sizeof(packed_usage));
|
||||
exit(0);
|
||||
}
|
||||
/* parent */
|
||||
close(input[1]);
|
||||
|
||||
buf = xmalloc(SIZEOF_usage_messages);
|
||||
full_read(output[0], buf, SIZEOF_usage_messages);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#else
|
||||
#define unpack_usage_messages() usage_messages
|
||||
#endif /* ENABLE_FEATURE_COMPRESS_USAGE */
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
if (ENABLE_SHOW_USAGE) {
|
||||
const char *format_string;
|
||||
const char *usage_string = unpack_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(xfunc_error_retval);
|
||||
}
|
||||
|
||||
static int applet_name_compare(const void *name, const void *vapplet)
|
||||
{
|
||||
const struct BB_applet *applet = vapplet;
|
||||
|
||||
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)
|
||||
{
|
||||
if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file();
|
||||
|
||||
if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv);
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
applet_using = find_applet_by_name(name);
|
||||
if (applet_using) {
|
||||
applet_name = applet_using->name;
|
||||
if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage();
|
||||
if(ENABLE_FEATURE_SUID) check_suid(applet_using);
|
||||
exit((*(applet_using->main))(argc, argv));
|
||||
}
|
||||
}
|
||||
+53
-98
@@ -1,16 +1,12 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
* BusyBox' main applet dispatcher.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#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;
|
||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
@@ -32,17 +28,6 @@ static const char* const install_dir[] = {
|
||||
/* 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)
|
||||
{
|
||||
@@ -66,47 +51,35 @@ static void install_links(const char *busybox, int use_symbolic_links)
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define install_links(x,y)
|
||||
#endif /* CONFIG_FEATURE_INSTALLER */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
bb_applet_name = argv[0];
|
||||
applet_name=argv[0];
|
||||
if (*applet_name == '-') applet_name++;
|
||||
for (s = applet_name; *s ;)
|
||||
if (*(s++) == '/') applet_name = s;
|
||||
|
||||
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
|
||||
{
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
run_applet_by_name(bb_applet_name, argc, argv);
|
||||
run_applet_by_name(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)) {
|
||||
if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
@@ -119,7 +92,8 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
// XXX: FIXME: this is broken. Why not just use argv[0] ?
|
||||
busybox = xreadlink("/proc/self/exe");
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
@@ -128,66 +102,47 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* CONFIG_FEATURE_INSTALLER */
|
||||
|
||||
argc--;
|
||||
/* Deal with --help. (Also print help when called with no arguments) */
|
||||
|
||||
/* 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;
|
||||
if (argc==1 || !strcmp(argv[1],"--help") ) {
|
||||
if (argc>2) {
|
||||
applet_name = argv[2];
|
||||
run_applet_by_name(applet_name, 2, argv);
|
||||
} else {
|
||||
const struct BB_applet *a;
|
||||
int col, output_width;
|
||||
|
||||
#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
|
||||
if (ENABLE_FEATURE_AUTOWIDTH) {
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
} else output_width = 80 - sizeof("start-stop-daemon, ") - 8;
|
||||
|
||||
fprintf(stderr, "%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);
|
||||
printf("%s\n"
|
||||
"Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
"Licensed under GPLv2. See source distribution for full notice.\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 +=
|
||||
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > output_width && a->name != 0) {
|
||||
fprintf(stderr, ",\n");
|
||||
col = 0;
|
||||
col=0;
|
||||
for(a = applets; a->name;) {
|
||||
col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
|
||||
if (col > output_width && a->name) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
exit(0);
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(0);
|
||||
}
|
||||
} else run_applet_by_name(argv[1], argc-1, argv+1);
|
||||
|
||||
/* 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));
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
/*
|
||||
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/config.h}
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
gcc -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
$HOSTCC -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*LINK/{
|
||||
dir=substr($2,8)
|
||||
gsub("_","/",dir)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/* 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>
|
||||
//Ok to remove? #include "bb_config.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);
|
||||
}
|
||||
+60
-18
@@ -3,18 +3,56 @@
|
||||
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"
|
||||
prefix=${1}
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks]"
|
||||
exit 1;
|
||||
fi
|
||||
h=`sort busybox.links | uniq`
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) 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
|
||||
`
|
||||
fi
|
||||
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
@@ -24,29 +62,33 @@ for i in $h ; do
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
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
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,17 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/busybox.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;
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/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[] = '
|
||||
"$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`
|
||||
@@ -0,0 +1,5 @@
|
||||
# ==========================================================================
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
CFLAGS += -march=i386 -mpreferred-stack-boundary=2
|
||||
+106
-64
@@ -5,7 +5,7 @@
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
config CONFIG_AR
|
||||
config AR
|
||||
bool "ar"
|
||||
default n
|
||||
help
|
||||
@@ -28,17 +28,17 @@ config CONFIG_AR
|
||||
Unless you have a specific application which requires ar, you should
|
||||
probably say N here.
|
||||
|
||||
config CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
bool " Enable support for long filenames (not need for debs)"
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Enable support for long filenames (not need for debs)"
|
||||
default n
|
||||
depends on CONFIG_AR
|
||||
depends on AR
|
||||
help
|
||||
By default the ar format can only store the first 15 characters of the
|
||||
filename, this option removes that limitation.
|
||||
It supports the GNU ar long filename method which moves multiple long
|
||||
filenames into a the data section of a new ar entry.
|
||||
|
||||
config CONFIG_BUNZIP2
|
||||
config BUNZIP2
|
||||
bool "bunzip2"
|
||||
default n
|
||||
help
|
||||
@@ -47,14 +47,14 @@ config 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 CONFIG_CPIO
|
||||
config CPIO
|
||||
bool "cpio"
|
||||
default n
|
||||
help
|
||||
@@ -68,36 +68,36 @@ config CONFIG_CPIO
|
||||
Unless you have a specific application which requires cpio, you should
|
||||
probably say N here.
|
||||
|
||||
config CONFIG_DPKG
|
||||
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 CONFIG_DPKG_DEB
|
||||
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 CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool " extract only (-x)"
|
||||
config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool "extract only (-x)"
|
||||
default n
|
||||
depends on CONFIG_DPKG_DEB
|
||||
depends on DPKG_DEB
|
||||
help
|
||||
This reduces dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
|
||||
However it saves space as none of the extra dpkg-deb, ar or tar options are
|
||||
needed, they are linked to internally.
|
||||
|
||||
config CONFIG_GUNZIP
|
||||
config GUNZIP
|
||||
bool "gunzip"
|
||||
default n
|
||||
help
|
||||
@@ -105,35 +105,35 @@ config CONFIG_GUNZIP
|
||||
You can use the `-t' option to test the integrity of
|
||||
an archive, without decompressing it.
|
||||
|
||||
config CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
bool " Uncompress support"
|
||||
config FEATURE_GUNZIP_UNCOMPRESS
|
||||
bool "Uncompress support"
|
||||
default n
|
||||
depends on CONFIG_GUNZIP
|
||||
depends on GUNZIP
|
||||
help
|
||||
Enable if you want gunzip to have the ability to decompress
|
||||
archives created by the program compress (not much
|
||||
used anymore).
|
||||
|
||||
config CONFIG_GZIP
|
||||
config GZIP
|
||||
bool "gzip"
|
||||
default n
|
||||
help
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config CONFIG_RPM2CPIO
|
||||
config RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default n
|
||||
help
|
||||
Converts an RPM file into a CPIO archive.
|
||||
|
||||
config CONFIG_RPM
|
||||
config RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - queries and extracts
|
||||
|
||||
config CONFIG_TAR
|
||||
config TAR
|
||||
bool "tar"
|
||||
default n
|
||||
help
|
||||
@@ -141,78 +141,109 @@ config CONFIG_TAR
|
||||
create compressed archives. It's probably the most widely used
|
||||
UNIX archive program.
|
||||
|
||||
config CONFIG_FEATURE_TAR_CREATE
|
||||
bool " Enable archive creation"
|
||||
config FEATURE_TAR_CREATE
|
||||
bool "Enable archive creation"
|
||||
default y
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to create
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config CONFIG_FEATURE_TAR_BZIP2
|
||||
bool " Enable -j option to handle .tar.bz2 files"
|
||||
config FEATURE_TAR_BZIP2
|
||||
bool "Enable -j option to handle .tar.bz2 files"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with bzip2.
|
||||
|
||||
config CONFIG_FEATURE_TAR_FROM
|
||||
bool " Enable -X (exclude from) and -T (include from) options)"
|
||||
config FEATURE_TAR_LZMA
|
||||
bool "Enable -a option to handle .tar.lzma files"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
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
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config CONFIG_FEATURE_TAR_GZIP
|
||||
bool " Enable -z option"
|
||||
config FEATURE_TAR_GZIP
|
||||
bool "Enable -z option"
|
||||
default y
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call gzip,
|
||||
when creating or extracting tar gziped archives.
|
||||
|
||||
config CONFIG_FEATURE_TAR_COMPRESS
|
||||
bool " Enable -Z option"
|
||||
config FEATURE_TAR_COMPRESS
|
||||
bool "Enable -Z option"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call uncompress,
|
||||
when extracting .tar.Z archives.
|
||||
|
||||
config CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
bool " Enable support for old tar header format"
|
||||
config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
bool "Enable support for old tar header format"
|
||||
default N
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
This option is required to unpack archives created in
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool " Enable support for some GNU tar extensions"
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Enable support for some GNU tar extensions"
|
||||
default y
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR
|
||||
help
|
||||
With this option busybox supports GNU long filenames and
|
||||
linknames.
|
||||
|
||||
config CONFIG_FEATURE_TAR_LONG_OPTIONS
|
||||
bool " Enable long options"
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on CONFIG_TAR
|
||||
depends on TAR && GETOPT_LONG
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config CONFIG_UNCOMPRESS
|
||||
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 CONFIG_UNZIP
|
||||
config UNLZMA
|
||||
bool "unlzma"
|
||||
default n
|
||||
help
|
||||
unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
compression algorithm, and range coding. Compression
|
||||
is generally considerably better than that achieved by the bzip2
|
||||
compressors.
|
||||
|
||||
The BusyBox unlzma applet is limited to de-compression only.
|
||||
On an x86 system, this applet adds about 4K.
|
||||
|
||||
Unless you have a specific application which requires unlzma, you
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimze unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 33% at the cost of
|
||||
a 2K bigger binary.
|
||||
|
||||
config UNZIP
|
||||
bool "unzip"
|
||||
default n
|
||||
help
|
||||
@@ -223,36 +254,47 @@ config CONFIG_UNZIP
|
||||
directory of your choice.
|
||||
|
||||
comment "Common options for cpio and tar"
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
depends on CPIO || TAR
|
||||
|
||||
config CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
bool " Enable tape drive support"
|
||||
config FEATURE_UNARCHIVE_TAPE
|
||||
bool "Enable tape drive support"
|
||||
default n
|
||||
depends on CONFIG_CPIO || CONFIG_TAR
|
||||
depends on CPIO || TAR
|
||||
help
|
||||
I don't think this is needed anymore.
|
||||
|
||||
comment "Common options for dpkg and dpkg_deb"
|
||||
depends on CONFIG_DPKG || CONFIG_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
|
||||
config FEATURE_DEB_TAR_GZ
|
||||
bool "gzip debian packages (normal)"
|
||||
default y if DPKG || DPKG_DEB
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This is the default compression method inside the debian ar file.
|
||||
|
||||
|
||||
If you want compatibility with standard .deb's you should say yes here.
|
||||
|
||||
config CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
bool " bzip2 debian packages"
|
||||
config FEATURE_DEB_TAR_BZ2
|
||||
bool "bzip2 debian packages"
|
||||
default n
|
||||
depends on CONFIG_DPKG || CONFIG_DPKG_DEB
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
|
||||
with bzip2 instead of gzip.
|
||||
|
||||
|
||||
You only want this if you are creating your own custom debian packages that
|
||||
use an internal control.tar.bz2 or data.tar.bz2.
|
||||
|
||||
config FEATURE_DEB_TAR_LZMA
|
||||
bool "lzma debian packages"
|
||||
default n
|
||||
depends on DPKG || DPKG_DEB
|
||||
help
|
||||
This allows dpkg and dpkg-deb to extract deb's that are compressed
|
||||
internally with lzma instead of gzip.
|
||||
|
||||
You only want this if you are creating your own custom debian
|
||||
packages that use an internal control.tar.lzma or data.tar.lzma.
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,22 @@
|
||||
# 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) += bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += unlzma.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += gunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
@@ -1,32 +0,0 @@
|
||||
# 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)
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
# 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) -ro $@ $(patsubst %,$(ARCHIVAL_DIR)%, $(ARCHIVAL-y))
|
||||
|
||||
$(ARCHIVAL_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+25
-42
@@ -7,36 +7,15 @@
|
||||
*
|
||||
* 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
|
||||
* 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 <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"
|
||||
#include "unarchive.h"
|
||||
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
{
|
||||
@@ -47,30 +26,31 @@ static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
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);
|
||||
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_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_VERBOSE 0x10
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned long opt;
|
||||
unsigned opt;
|
||||
static const 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, "ptxovc");
|
||||
|
||||
if ((opt & 0x80000000UL) || (optind == argc)) {
|
||||
bb_show_usage();
|
||||
}
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:p:t:x:-1:?:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argc, argv, "ptxovcr");
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
@@ -88,19 +68,22 @@ extern int ar_main(int argc, char **argv)
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
}
|
||||
if (opt & AR_OPT_CREATE) {
|
||||
bb_error_msg_and_die("Archive creation not supported. Install binutils 'ar'.");
|
||||
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);
|
||||
archive_handle->src_fd = 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++]);
|
||||
llist_add_to(&(archive_handle->accept), argv[optind++]);
|
||||
}
|
||||
|
||||
archive_xread_all(archive_handle, magic, 7);
|
||||
xread(archive_handle->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("Invalid ar magic");
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
|
||||
+33
-58
@@ -1,29 +1,11 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -32,58 +14,51 @@
|
||||
|
||||
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;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, 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;
|
||||
}
|
||||
opt = getopt32(argc, argv, "cf");
|
||||
|
||||
/* Set input filename and number */
|
||||
compressed_name = argv[optind];
|
||||
if ((compressed_name) && (compressed_name[0] != '-') && (compressed_name[1] != '\0')) {
|
||||
filename = argv[optind];
|
||||
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = bb_xopen(compressed_name, O_RDONLY);
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= BUNZIP2_OPT_STDOUT;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as bzcat force the stdout flag */
|
||||
if ((opt & BUNZIP2_OPT_STDOUT) || applet_name[2] == 'c')
|
||||
filename = 0;
|
||||
|
||||
/* 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.");
|
||||
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");
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* extension = filename+strlen(filename)-4 is buggy:
|
||||
* strlen may be less than 4 */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".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);
|
||||
}
|
||||
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else dst_fd = STDOUT_FILENO;
|
||||
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);
|
||||
if (filename) {
|
||||
if (status >= 0) filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-29
@@ -4,19 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
@@ -24,34 +12,33 @@
|
||||
*
|
||||
*/
|
||||
#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_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
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
|
||||
extern int cpio_main(int argc, char **argv)
|
||||
int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename = NULL;
|
||||
unsigned long opt;
|
||||
unsigned opt;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename);
|
||||
opt = getopt32(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) {
|
||||
@@ -59,7 +46,7 @@ extern int cpio_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test option are given, ignore extract option */
|
||||
/* if both extract and test options are given, ignore extract option */
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
opt &= ~CPIO_OPT_EXTRACT;
|
||||
}
|
||||
@@ -79,8 +66,8 @@ extern int cpio_main(int argc, char **argv)
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (cpio_filename) { /* CPIO_OPT_FILE */
|
||||
archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY);
|
||||
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) {
|
||||
@@ -89,11 +76,11 @@ extern int cpio_main(int argc, char **argv)
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
|
||||
llist_add_to(&(archive_handle->accept), argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+354
-368
File diff suppressed because it is too large.
Load diff
+19
-35
@@ -1,27 +1,11 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* dpkg-deb packs, unpacks and provides information about Debian archives.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
#define DPKG_DEB_OPT_CONTROL 2
|
||||
@@ -29,12 +13,12 @@
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
extern int dpkg_deb_main(int argc, char **argv)
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned long opt;
|
||||
unsigned opt;
|
||||
char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
@@ -47,17 +31,17 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
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");
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, "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");
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.bz2");
|
||||
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");
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argc, argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
@@ -76,7 +60,7 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
* 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");;
|
||||
llist_add_to(&(tar_archive->accept), "./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
@@ -88,11 +72,11 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
argcount = 2;
|
||||
}
|
||||
|
||||
if ((optind + argcount != argc) || (opt & 0x80000000UL)) {
|
||||
if ((optind + argcount) != argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
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 */
|
||||
@@ -100,13 +84,13 @@ extern int dpkg_deb_main(int argc, char **argv)
|
||||
extract_dir = argv[optind];
|
||||
}
|
||||
if (extract_dir) {
|
||||
mkdir(extract_dir, 0777);
|
||||
chdir(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);
|
||||
close(ar_archive->src_fd);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+48
-84
@@ -14,20 +14,7 @@
|
||||
* 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
|
||||
*
|
||||
* 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
|
||||
@@ -40,34 +27,6 @@
|
||||
* 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"
|
||||
|
||||
@@ -75,22 +34,24 @@ static char *license_msg[] = {
|
||||
#define GUNZIP_OPT_FORCE 2
|
||||
#define GUNZIP_OPT_TEST 4
|
||||
#define GUNZIP_OPT_DECOMPRESS 8
|
||||
#define GUNZIP_OPT_VERBOSE 0x10
|
||||
|
||||
extern int gunzip_main(int argc, char **argv)
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
char status = EXIT_SUCCESS;
|
||||
unsigned long opt;
|
||||
USE_DESKTOP(long long) int status;
|
||||
int exitcode = 0;
|
||||
unsigned opt;
|
||||
|
||||
opt = bb_getopt_ulflags(argc, argv, "cftd");
|
||||
opt = getopt32(argc, argv, "cftdv");
|
||||
/* if called as zcat */
|
||||
if (strcmp(bb_applet_name, "zcat") == 0) {
|
||||
if (strcmp(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 *old_path = argv[optind];
|
||||
char *delete_path = NULL;
|
||||
char *new_path = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
@@ -100,30 +61,29 @@ extern int gunzip_main(int argc, char **argv)
|
||||
if (old_path == NULL || strcmp(old_path, "-") == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
USE_DESKTOP(opt &= ~GUNZIP_OPT_VERBOSE;)
|
||||
optind = argc; /* we don't handle "gunzip - a.gz b.gz" */
|
||||
} else {
|
||||
src_fd = bb_xopen(old_path, O_RDONLY);
|
||||
|
||||
src_fd = 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);
|
||||
}
|
||||
fstat(src_fd, &stat_buf);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((opt & GUNZIP_OPT_FORCE) == 0)) {
|
||||
if (isatty(src_fd) && !(opt & GUNZIP_OPT_FORCE)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal. Use -f to force it.");
|
||||
("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 ? */
|
||||
dst_fd = xopen(bb_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);
|
||||
new_path = xstrdup(old_path);
|
||||
|
||||
extension = strrchr(new_path, '.');
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
@@ -137,43 +97,46 @@ extern int gunzip_main(int argc, char **argv)
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
// FIXME: should we die or just skip to next?
|
||||
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);
|
||||
/* Open output file (with correct permissions) */
|
||||
dst_fd = xopen3(new_path, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = old_path;
|
||||
}
|
||||
|
||||
status = -1;
|
||||
/* do the decompression, and cleanup */
|
||||
if (bb_xread_char(src_fd) == 0x1f) {
|
||||
if (xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = bb_xread_char(src_fd);
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (magic2 == 0x9d) {
|
||||
magic2 = xread_char(src_fd);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && 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 if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd); // FIXME: xfunc? _or_die?
|
||||
status = inflate_gunzip(src_fd, dst_fd);
|
||||
} else {
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
exitcode = 1;
|
||||
}
|
||||
else if (ENABLE_DESKTOP && (opt & GUNZIP_OPT_VERBOSE)) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
old_path, (unsigned)(stat_buf.st_size*100 / (status+1)), new_path);
|
||||
}
|
||||
} else {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
|
||||
if ((status != EXIT_SUCCESS) && (new_path)) {
|
||||
if (status < 0 && new_path) {
|
||||
/* Unzip failed, remove new path instead of old path */
|
||||
delete_path = new_path;
|
||||
}
|
||||
@@ -187,12 +150,13 @@ extern int gunzip_main(int argc, char **argv)
|
||||
|
||||
/* 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);
|
||||
bb_error_msg("cannot remove %s", delete_path);
|
||||
exitcode = 1;
|
||||
}
|
||||
|
||||
free(new_path);
|
||||
|
||||
} while (optind < argc);
|
||||
|
||||
return status;
|
||||
return exitcode;
|
||||
}
|
||||
+89
-164
@@ -13,27 +13,17 @@
|
||||
* files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
/* TODO: full support for -v for DESKTOP
|
||||
/usr/bin/gzip -v a bogus aa
|
||||
a: 85.1% -- replaced with a.gz
|
||||
gzip: bogus: No such file or directory
|
||||
aa: 85.1% -- replaced with aa.gz
|
||||
*/
|
||||
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -51,12 +41,6 @@
|
||||
#include <time.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
#endif
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
@@ -106,17 +90,11 @@ typedef unsigned long ulg;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef DYN_ALLOC
|
||||
# define DECLARE(type, array, size) static type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
array = (type*)xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)); \
|
||||
}
|
||||
# define FREE(array) {free(array), array=NULL;}
|
||||
#else
|
||||
# define DECLARE(type, array, size) static type array[size]
|
||||
# define ALLOC(type, array, size)
|
||||
# define FREE(array)
|
||||
#endif
|
||||
|
||||
#define tab_suffix window
|
||||
#define tab_prefix prev /* hash link (see deflate.c) */
|
||||
@@ -152,8 +130,8 @@ typedef int file_t; /* Do not use stdio */
|
||||
#define ASCII 1
|
||||
|
||||
#ifndef WSIZE
|
||||
# define WSIZE 0x8000 /* window size--must be a power of two, and */
|
||||
#endif /* at least 32K for zip's deflate method */
|
||||
# define WSIZE 0x8000 /* window size--must be a power of two, and */
|
||||
#endif /* at least 32K for zip's deflate method */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
@@ -173,15 +151,6 @@ typedef int file_t; /* Do not use stdio */
|
||||
#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
|
||||
flush_outbuf();}
|
||||
|
||||
|
||||
/* Output a 32 bit value to the bit stream, lsb first */
|
||||
#if 0
|
||||
#define put_long(n) { \
|
||||
put_short((n) & 0xffff); \
|
||||
put_short(((ulg)(n)) >> 16); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define seekable() 0 /* force sequential output */
|
||||
#define translate_eol 0 /* no option -a yet */
|
||||
|
||||
@@ -214,9 +183,6 @@ typedef int file_t; /* Do not use stdio */
|
||||
static int zip(int in, int out);
|
||||
static int file_read(char *buf, unsigned size);
|
||||
|
||||
/* from gzip.c */
|
||||
static RETSIGTYPE abort_gzip(void);
|
||||
|
||||
/* from deflate.c */
|
||||
static void lm_init(ush * flags);
|
||||
static ulg deflate(void);
|
||||
@@ -243,10 +209,6 @@ static void flush_outbuf(void);
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if !defined(OF) && defined(lint)
|
||||
# include "gzip.h"
|
||||
#endif
|
||||
|
||||
#ifndef BITS
|
||||
# define BITS 16
|
||||
#endif
|
||||
@@ -308,17 +270,17 @@ DECLARE(ush, tab_prefix, 1L << BITS);
|
||||
static int foreground; /* set if program run in foreground */
|
||||
static int method = DEFLATED; /* compression method */
|
||||
static int exit_code = OK; /* program exit code */
|
||||
static int part_nb; /* number of parts in .gz file */
|
||||
static long time_stamp; /* original time stamp (modification time) */
|
||||
static long ifile_size; /* input file size, -1 for devices (debug only) */
|
||||
static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
|
||||
static int z_len; /* strlen(z_suffix) */
|
||||
|
||||
static int ifd; /* input file descriptor */
|
||||
static int ofd; /* output file descriptor */
|
||||
#ifdef DEBUG
|
||||
static unsigned insize; /* valid bytes in inbuf */
|
||||
#endif
|
||||
static unsigned outcnt; /* bytes in output buffer */
|
||||
|
||||
static uint32_t *crc_32_tab;
|
||||
|
||||
/* Output a 16 bit value, lsb first */
|
||||
static void put_short(ush w)
|
||||
@@ -335,7 +297,7 @@ static void put_short(ush w)
|
||||
/* ========================================================================
|
||||
* Signal and error handler.
|
||||
*/
|
||||
static void abort_gzip()
|
||||
static void abort_gzip(int ATTRIBUTE_UNUSED ignored)
|
||||
{
|
||||
exit(ERROR);
|
||||
}
|
||||
@@ -346,17 +308,12 @@ static void abort_gzip()
|
||||
static void clear_bufs(void)
|
||||
{
|
||||
outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
insize = 0;
|
||||
#endif
|
||||
bytes_in = 0L;
|
||||
}
|
||||
|
||||
static void write_bb_error_msg(void)
|
||||
{
|
||||
fputc('\n', stderr);
|
||||
bb_perror_nomsg();
|
||||
abort_gzip();
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Does the same as write(), but also handles partial pipe writes and checks
|
||||
* for error return.
|
||||
@@ -366,9 +323,7 @@ static void write_buf(int fd, void *buf, unsigned cnt)
|
||||
unsigned n;
|
||||
|
||||
while ((n = write(fd, buf, cnt)) != cnt) {
|
||||
if (n == (unsigned) (-1)) {
|
||||
write_bb_error_msg();
|
||||
}
|
||||
if (n == (unsigned) (-1)) bb_error_msg_and_die(bb_msg_write_error);
|
||||
cnt -= n;
|
||||
buf = (void *) ((char *) buf + n);
|
||||
}
|
||||
@@ -379,32 +334,13 @@ static void write_buf(int fd, void *buf, unsigned cnt)
|
||||
* pointer, then initialize the crc shift register contents instead.
|
||||
* Return the current crc in either case.
|
||||
*/
|
||||
static ulg updcrc(uch * s, unsigned n)
|
||||
static uint32_t updcrc(uch * s, unsigned n)
|
||||
{
|
||||
static ulg crc = (ulg) 0xffffffffL; /* shift register contents */
|
||||
register ulg c; /* temporary variable */
|
||||
static unsigned long crc_32_tab[256];
|
||||
|
||||
if (crc_32_tab[1] == 0x00000000L) {
|
||||
unsigned long csr; /* crc shift register */
|
||||
const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */
|
||||
int i; /* counter for all possible eight bit values */
|
||||
int k; /* byte being shifted into crc apparatus */
|
||||
|
||||
/* Compute table of CRC's. */
|
||||
for (i = 1; i < 256; i++) {
|
||||
csr = 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--)
|
||||
csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1;
|
||||
crc_32_tab[i] = csr;
|
||||
}
|
||||
}
|
||||
static uint32_t crc = ~0; /* shift register contents */
|
||||
uint32_t c; /* temporary variable */
|
||||
|
||||
if (s == NULL) {
|
||||
c = 0xffffffffL;
|
||||
c = ~0;
|
||||
} else {
|
||||
c = crc;
|
||||
if (n)
|
||||
@@ -413,7 +349,7 @@ static ulg updcrc(uch * s, unsigned n)
|
||||
} while (--n);
|
||||
}
|
||||
crc = c;
|
||||
return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
|
||||
return ~c;
|
||||
}
|
||||
|
||||
/* bits.c -- output variable-length bit strings
|
||||
@@ -547,7 +483,7 @@ static void send_bits(int value, int length)
|
||||
*/
|
||||
static unsigned bi_reverse(unsigned code, int len)
|
||||
{
|
||||
register unsigned res = 0;
|
||||
unsigned res = 0;
|
||||
|
||||
do {
|
||||
res |= code & 1;
|
||||
@@ -559,7 +495,7 @@ static unsigned bi_reverse(unsigned code, int len)
|
||||
/* ===========================================================================
|
||||
* Write out any remaining bits in an incomplete byte.
|
||||
*/
|
||||
static void bi_windup()
|
||||
static void bi_windup(void)
|
||||
{
|
||||
if (bi_valid > 8) {
|
||||
put_short(bi_buf);
|
||||
@@ -767,25 +703,26 @@ static unsigned match_start; /* start of matching string */
|
||||
static int eofile; /* flag set at end of input file */
|
||||
static unsigned lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
static const unsigned max_chain_length = 4096;
|
||||
enum {
|
||||
max_chain_length = 4096,
|
||||
|
||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||
* A higher limit improves compression ratio but degrades the speed.
|
||||
*/
|
||||
|
||||
static const unsigned int max_lazy_match = 258;
|
||||
max_lazy_match = 258,
|
||||
|
||||
/* Attempt to find a better match only when the current match is strictly
|
||||
* smaller than this value. This mechanism is used only for compression
|
||||
* levels >= 4.
|
||||
*/
|
||||
#define max_insert_length max_lazy_match
|
||||
max_insert_length = max_lazy_match,
|
||||
/* Insert new strings in the hash table only if the match length
|
||||
* is not greater than this length. This saves time but degrades compression.
|
||||
* max_insert_length is used only for compression levels <= 3.
|
||||
*/
|
||||
|
||||
static const unsigned good_match = 32;
|
||||
good_match = 32,
|
||||
|
||||
/* Use a faster search when the previous match is longer than this */
|
||||
|
||||
@@ -796,12 +733,13 @@ static const unsigned good_match = 32;
|
||||
* found for specific files.
|
||||
*/
|
||||
|
||||
static const int nice_match = 258; /* Stop searching when current match exceeds this */
|
||||
nice_match = 258 /* Stop searching when current match exceeds this */
|
||||
|
||||
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
|
||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||
* meaning.
|
||||
*/
|
||||
};
|
||||
|
||||
#define EQUAL 0
|
||||
/* result of memcmp for equal strings */
|
||||
@@ -843,10 +781,10 @@ static void check_match(IPos start, IPos match, int length);
|
||||
*/
|
||||
static void lm_init(ush * flags)
|
||||
{
|
||||
register unsigned j;
|
||||
unsigned j;
|
||||
|
||||
/* Initialize the hash table. */
|
||||
memzero((char *) head, HASH_SIZE * sizeof(*head));
|
||||
memset(head, 0, HASH_SIZE * sizeof(*head));
|
||||
/* prev will be initialized on the fly */
|
||||
|
||||
*flags |= SLOW;
|
||||
@@ -893,9 +831,9 @@ static void lm_init(ush * flags)
|
||||
static int longest_match(IPos cur_match)
|
||||
{
|
||||
unsigned chain_length = max_chain_length; /* max hash chain length */
|
||||
register uch *scan = window + strstart; /* current string */
|
||||
register uch *match; /* matched string */
|
||||
register int len; /* length of current match */
|
||||
uch *scan = window + strstart; /* current string */
|
||||
uch *match; /* matched string */
|
||||
int len; /* length of current match */
|
||||
int best_len = prev_length; /* best match length so far */
|
||||
IPos limit =
|
||||
strstart > (IPos) MAX_DIST ? strstart - (IPos) MAX_DIST : NIL;
|
||||
@@ -909,9 +847,9 @@ static int longest_match(IPos cur_match)
|
||||
#if HASH_BITS < 8 || MAX_MATCH != 258
|
||||
# error Code too clever
|
||||
#endif
|
||||
register uch *strend = window + strstart + MAX_MATCH;
|
||||
register uch scan_end1 = scan[best_len - 1];
|
||||
register uch scan_end = scan[best_len];
|
||||
uch *strend = window + strstart + MAX_MATCH;
|
||||
uch scan_end1 = scan[best_len - 1];
|
||||
uch scan_end = scan[best_len];
|
||||
|
||||
/* Do not waste too much time if we already have a good match: */
|
||||
if (prev_length >= good_match) {
|
||||
@@ -996,9 +934,9 @@ static void check_match(IPos start, IPos match, int length)
|
||||
* file reads are performed for at least two bytes (required for the
|
||||
* translate_eol option).
|
||||
*/
|
||||
static void fill_window()
|
||||
static void fill_window(void)
|
||||
{
|
||||
register unsigned n, m;
|
||||
unsigned n, m;
|
||||
unsigned more =
|
||||
(unsigned) (window_size - (ulg) lookahead - (ulg) strstart);
|
||||
/* Amount of free space at the end of the window. */
|
||||
@@ -1053,20 +991,20 @@ static void fill_window()
|
||||
*/
|
||||
#define FLUSH_BLOCK(eof) \
|
||||
flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \
|
||||
(char*)NULL, (long)strstart - block_start, (eof))
|
||||
(char*)NULL, (long)strstart - block_start, (eof))
|
||||
|
||||
/* ===========================================================================
|
||||
* Same as above, but achieves better compression. We use a lazy
|
||||
* evaluation for matches: a match is finally adopted only if there is
|
||||
* no better match at the next window position.
|
||||
*/
|
||||
static ulg deflate()
|
||||
static ulg deflate(void)
|
||||
{
|
||||
IPos hash_head; /* head of hash chain */
|
||||
IPos prev_match; /* previous match */
|
||||
int flush; /* set if current block must be flushed */
|
||||
int match_available = 0; /* set if previous match exists */
|
||||
register unsigned match_length = MIN_MATCH - 1; /* length of best match */
|
||||
unsigned match_length = MIN_MATCH - 1; /* length of best match */
|
||||
|
||||
/* Process the input block. */
|
||||
while (lookahead != 0) {
|
||||
@@ -1188,68 +1126,58 @@ static ulg deflate()
|
||||
|
||||
typedef struct dirent dir_type;
|
||||
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
/* ======================================================================== */
|
||||
int gzip_main(int argc, char **argv)
|
||||
{
|
||||
enum {
|
||||
OPT_tostdout = 0x1,
|
||||
OPT_force = 0x2,
|
||||
};
|
||||
|
||||
unsigned opt;
|
||||
int result;
|
||||
int inFileNum;
|
||||
int outFileNum;
|
||||
struct stat statBuf;
|
||||
char *delFileName;
|
||||
int tostdout = 0;
|
||||
int force = 0;
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "cf123456789dq")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
tostdout = 1;
|
||||
break;
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
/* Ignore 1-9 (compression level) options */
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
break;
|
||||
case 'q':
|
||||
break;
|
||||
#ifdef CONFIG_GUNZIP
|
||||
case 'd':
|
||||
optind = 1;
|
||||
return gunzip_main(argc, argv);
|
||||
#endif
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
opt = getopt32(argc, argv, "cf123456789qv" USE_GUNZIP("d"));
|
||||
//if (opt & 0x1) // -c
|
||||
//if (opt & 0x2) // -f
|
||||
/* Ignore 1-9 (compression level) options */
|
||||
//if (opt & 0x4) // -1
|
||||
//if (opt & 0x8) // -2
|
||||
//if (opt & 0x10) // -3
|
||||
//if (opt & 0x20) // -4
|
||||
//if (opt & 0x40) // -5
|
||||
//if (opt & 0x80) // -6
|
||||
//if (opt & 0x100) // -7
|
||||
//if (opt & 0x200) // -8
|
||||
//if (opt & 0x400) // -9
|
||||
//if (opt & 0x800) // -q
|
||||
//if (opt & 0x1000) // -v
|
||||
if (ENABLE_GUNZIP && (opt & 0x2000)) { // -d
|
||||
/* FIXME: getopt32 should not depend on optind */
|
||||
optind = 1;
|
||||
return gunzip_main(argc, argv);
|
||||
}
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
(void) signal(SIGINT, (sig_type) abort_gzip);
|
||||
(void) signal(SIGINT, abort_gzip);
|
||||
}
|
||||
#ifdef SIGTERM
|
||||
if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
|
||||
(void) signal(SIGTERM, (sig_type) abort_gzip);
|
||||
(void) signal(SIGTERM, abort_gzip);
|
||||
}
|
||||
#endif
|
||||
#ifdef SIGHUP
|
||||
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
|
||||
(void) signal(SIGHUP, (sig_type) abort_gzip);
|
||||
(void) signal(SIGHUP, abort_gzip);
|
||||
}
|
||||
#endif
|
||||
|
||||
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1);
|
||||
z_len = strlen(z_suffix);
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA);
|
||||
@@ -1258,12 +1186,13 @@ int gzip_main(int argc, char **argv)
|
||||
ALLOC(uch, window, 2L * WSIZE);
|
||||
ALLOC(ush, tab_prefix, 1L << BITS);
|
||||
|
||||
/* Initialise the CRC32 table */
|
||||
crc_32_tab = crc32_filltable(0);
|
||||
|
||||
clear_bufs();
|
||||
part_nb = 0;
|
||||
|
||||
if (optind == argc) {
|
||||
time_stamp = 0;
|
||||
ifile_size = -1L;
|
||||
zip(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
int i;
|
||||
@@ -1271,25 +1200,22 @@ int gzip_main(int argc, char **argv)
|
||||
for (i = optind; i < argc; i++) {
|
||||
char *path = NULL;
|
||||
|
||||
clear_bufs();
|
||||
if (strcmp(argv[i], "-") == 0) {
|
||||
time_stamp = 0;
|
||||
ifile_size = -1L;
|
||||
inFileNum = STDIN_FILENO;
|
||||
outFileNum = STDOUT_FILENO;
|
||||
} else {
|
||||
inFileNum = open(argv[i], O_RDONLY);
|
||||
if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0)
|
||||
inFileNum = xopen(argv[i], O_RDONLY);
|
||||
if (fstat(inFileNum, &statBuf) < 0)
|
||||
bb_perror_msg_and_die("%s", argv[i]);
|
||||
time_stamp = statBuf.st_ctime;
|
||||
ifile_size = statBuf.st_size;
|
||||
|
||||
if (!tostdout) {
|
||||
path = xmalloc(strlen(argv[i]) + 4);
|
||||
strcpy(path, argv[i]);
|
||||
strcat(path, ".gz");
|
||||
if (!(opt & OPT_tostdout)) {
|
||||
path = xasprintf("%s.gz", argv[i]);
|
||||
|
||||
/* Open output file */
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) && defined O_NOFOLLOW
|
||||
outFileNum =
|
||||
open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW);
|
||||
#else
|
||||
@@ -1307,7 +1233,7 @@ int gzip_main(int argc, char **argv)
|
||||
outFileNum = STDOUT_FILENO;
|
||||
}
|
||||
|
||||
if (path == NULL && isatty(outFileNum) && force == 0) {
|
||||
if (path == NULL && isatty(outFileNum) && !(opt & OPT_force)) {
|
||||
bb_error_msg
|
||||
("compressed data not written to a terminal. Use -f to force compression.");
|
||||
free(path);
|
||||
@@ -1334,7 +1260,7 @@ int gzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
return (exit_code);
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
/* trees.c -- output deflated data using Huffman coding
|
||||
@@ -1749,7 +1675,7 @@ static void ct_init(ush * attr, int *methodp)
|
||||
/* ===========================================================================
|
||||
* Initialize a new block.
|
||||
*/
|
||||
static void init_block()
|
||||
static void init_block(void)
|
||||
{
|
||||
int n; /* iterates over tree elements */
|
||||
|
||||
@@ -2162,7 +2088,7 @@ static void send_tree(ct_data * tree, int max_code)
|
||||
* Construct the Huffman tree for the bit lengths and return the index in
|
||||
* bl_order of the last bit length code to send.
|
||||
*/
|
||||
static const int build_bl_tree()
|
||||
static int build_bl_tree(void)
|
||||
{
|
||||
int max_blindex; /* index of last bit length code of non zero freq */
|
||||
|
||||
@@ -2425,7 +2351,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||
* IN assertion: the fields freq of dyn_ltree are set and the total of all
|
||||
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
|
||||
*/
|
||||
static void set_file_type()
|
||||
static void set_file_type(void)
|
||||
{
|
||||
int n = 0;
|
||||
unsigned ascii_freq = 0;
|
||||
@@ -2450,7 +2376,7 @@ static void set_file_type()
|
||||
*/
|
||||
|
||||
|
||||
static ulg crc; /* crc on uncompressed file data */
|
||||
static uint32_t crc; /* crc on uncompressed file data */
|
||||
static long header_bytes; /* number of bytes in gzip header */
|
||||
|
||||
static void put_long(ulg n)
|
||||
@@ -2481,7 +2407,6 @@ static int zip(int in, int out)
|
||||
|
||||
/* Write the header to the gzip file. See algorithm.doc for the format */
|
||||
|
||||
|
||||
method = DEFLATED;
|
||||
put_header_byte(GZIP_MAGIC[0]); /* magic header */
|
||||
put_header_byte(GZIP_MAGIC[1]);
|
||||
@@ -2538,7 +2463,7 @@ static int file_read(char *buf, unsigned size)
|
||||
* Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
|
||||
* (used for the compressed data only)
|
||||
*/
|
||||
static void flush_outbuf()
|
||||
static void flush_outbuf(void)
|
||||
{
|
||||
if (outcnt == 0)
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# 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 \
|
||||
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
|
||||
|
||||
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) += $(GUNZIP_FILES) 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) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.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) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
@@ -1,32 +0,0 @@
|
||||
# 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)
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
# 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) -ro $@ $(patsubst %,$(LIBUNARCHIVE_DIR)%, $(LIBUNARCHIVE-y))
|
||||
|
||||
$(LIBUNARCHIVA_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -1,32 +1,20 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#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 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 %d of %d", size, count);
|
||||
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);
|
||||
return size;
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip */
|
||||
|
||||
extern void check_header_gzip(int src_fd)
|
||||
void check_header_gzip(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -12,45 +17,45 @@ extern void check_header_gzip(int src_fd)
|
||||
unsigned int mtime;
|
||||
unsigned char xtra_flags;
|
||||
unsigned char os_flags;
|
||||
} formated;
|
||||
} formatted;
|
||||
} header;
|
||||
|
||||
bb_xread_all(src_fd, header.raw, 8);
|
||||
xread(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.formatted.method != 8) {
|
||||
bb_error_msg_and_die("unknown compression method %d",
|
||||
header.formatted.method);
|
||||
}
|
||||
|
||||
if (header.formated.flags & 0x04) {
|
||||
if (header.formatted.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);
|
||||
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
/* Ignore extra field */
|
||||
bb_xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
extra_short--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discard original name if any */
|
||||
if (header.formated.flags & 0x08) {
|
||||
if (header.formatted.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
while(bb_xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formated.flags & 0x10) {
|
||||
if (header.formatted.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
while(bb_xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formated.flags & 0x02) {
|
||||
bb_xread_char(src_fd);
|
||||
bb_xread_char(src_fd);
|
||||
if (header.formatted.flags & 0x02) {
|
||||
xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -22,7 +11,7 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
{
|
||||
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
|
||||
@@ -1,49 +1,31 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#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)
|
||||
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);
|
||||
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("Couldnt remove old file");
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("cannot remove old file");
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
@@ -51,69 +33,82 @@ extern void data_extract_all(archive_handle_t *archive_handle)
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("Couldnt stat old file");
|
||||
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);
|
||||
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);
|
||||
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_name) && (file_header->size == 0)) {
|
||||
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");
|
||||
bb_perror_msg("cannot 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");
|
||||
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_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("unrecognized 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_NOPRESERVE_OWN)) {
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2002 Glenn McGrath
|
||||
*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
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_handle->buffer = xzalloc(size + 1);
|
||||
|
||||
archive_xread_all(archive_handle, archive_handle->buffer, size);
|
||||
archive_handle->buffer[size] = '\0';
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -1,23 +1,12 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
extern void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -21,7 +10,7 @@
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void data_skip(archive_handle_t *archive_handle)
|
||||
void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
|
||||
/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net).
|
||||
|
||||
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
|
||||
which also acknowledges contributions by Mike Burrows, David Wheeler,
|
||||
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
|
||||
Robert Sedgewick, and Jon L. Bentley.
|
||||
Based on bzip2 decompression code by Julian R Seward (jseward@acm.org),
|
||||
which also acknowledges contributions by Mike Burrows, David Wheeler,
|
||||
Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten,
|
||||
Robert Sedgewick, and Jon L. Bentley.
|
||||
|
||||
This code is licensed under the LGPLv2:
|
||||
LGPL (http://www.gnu.org/copyleft/lgpl.html
|
||||
Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -23,37 +22,20 @@
|
||||
|
||||
I would ask that anyone benefiting from this work, especially those
|
||||
using it in commercial products, consider making a donation to my local
|
||||
non-profit hospice organization in the name of the woman I loved, who
|
||||
passed away Feb. 12, 2003.
|
||||
|
||||
In memory of Toni W. Hagan
|
||||
|
||||
Hospice of Acadiana, Inc.
|
||||
2600 Johnston St., Suite 200
|
||||
Lafayette, LA 70503-3240
|
||||
|
||||
Phone (337) 232-1234 or 1-800-738-2226
|
||||
Fax (337) 232-1297
|
||||
|
||||
http://www.hospiceacadiana.com/
|
||||
non-profit hospice organization (www.hospiceacadiana.com) in the name of
|
||||
the woman I loved, Toni W. Hagan, who passed away Feb. 12, 2003.
|
||||
|
||||
Manuel
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Constants for Huffman coding */
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define SYMBOL_RUNA 0
|
||||
#define SYMBOL_RUNB 1
|
||||
|
||||
@@ -79,51 +61,73 @@ struct group_data {
|
||||
|
||||
/* Structure holding all the housekeeping data, including IO buffers and
|
||||
memory that persists between calls to bunzip */
|
||||
|
||||
typedef struct {
|
||||
/* State for interrupting output loop */
|
||||
|
||||
int writeCopies,writePos,writeRunCountdown,writeCount,writeCurrent;
|
||||
|
||||
/* I/O tracking data (file handles, buffers, positions, etc.) */
|
||||
|
||||
int in_fd,out_fd,inbufCount,inbufPos /*,outbufPos*/;
|
||||
unsigned char *inbuf /*,*outbuf*/;
|
||||
unsigned int inbufBitCount, inbufBits;
|
||||
|
||||
/* The CRC values stored in the block header and calculated from the data */
|
||||
unsigned int crc32Table[256],headerCRC, totalCRC, writeCRC;
|
||||
|
||||
uint32_t headerCRC, totalCRC, writeCRC;
|
||||
uint32_t *crc32Table;
|
||||
/* Intermediate buffer and its size (in bytes) */
|
||||
|
||||
unsigned int *dbuf, dbufSize;
|
||||
|
||||
/* These things are a bit too big to go on the stack */
|
||||
|
||||
unsigned char selectors[32768]; /* nSelectors=15 bits */
|
||||
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
||||
|
||||
/* For I/O error handling */
|
||||
|
||||
jmp_buf jmpbuf;
|
||||
} bunzip_data;
|
||||
|
||||
/* Return the next nnn bits of input. All reads from the compressed input
|
||||
are done through this function. All reads are big endian */
|
||||
|
||||
static unsigned int get_bits(bunzip_data *bd, char bits_wanted)
|
||||
{
|
||||
unsigned int bits=0;
|
||||
|
||||
/* If we need to get more data from the byte buffer, do so. (Loop getting
|
||||
one byte at a time to enforce endianness and avoid unaligned access.) */
|
||||
|
||||
while (bd->inbufBitCount<bits_wanted) {
|
||||
|
||||
/* If we need to read more data from file into byte buffer, do so */
|
||||
|
||||
if(bd->inbufPos==bd->inbufCount) {
|
||||
if((bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE)) <= 0)
|
||||
longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
bd->inbufPos=0;
|
||||
}
|
||||
|
||||
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
|
||||
|
||||
if(bd->inbufBitCount>=24) {
|
||||
bits=bd->inbufBits&((1<<bd->inbufBitCount)-1);
|
||||
bits_wanted-=bd->inbufBitCount;
|
||||
bits<<=bits_wanted;
|
||||
bd->inbufBitCount=0;
|
||||
}
|
||||
|
||||
/* Grab next 8 bits of input from buffer. */
|
||||
|
||||
bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount+=8;
|
||||
}
|
||||
|
||||
/* Calculate result */
|
||||
|
||||
bd->inbufBitCount-=bits_wanted;
|
||||
bits|=(bd->inbufBits>>bd->inbufBitCount)&((1<<bits_wanted)-1);
|
||||
|
||||
@@ -134,8 +138,6 @@ static unsigned int get_bits(bunzip_data *bd, char bits_wanted)
|
||||
|
||||
static int get_next_block(bunzip_data *bd)
|
||||
{
|
||||
/* Note: Ignore the warning about hufGroup, base and limit being used uninitialized.
|
||||
* They will be initialized on the fist pass of the loop. */
|
||||
struct group_data *hufGroup;
|
||||
int dbufCount,nextSym,dbufSize,groupCount,*base,*limit,selector,
|
||||
i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256];
|
||||
@@ -145,26 +147,34 @@ static int get_next_block(bunzip_data *bd)
|
||||
dbuf=bd->dbuf;
|
||||
dbufSize=bd->dbufSize;
|
||||
selectors=bd->selectors;
|
||||
|
||||
/* Reset longjmp I/O error handling */
|
||||
|
||||
i=setjmp(bd->jmpbuf);
|
||||
if(i) return i;
|
||||
|
||||
/* Read in header signature and CRC, then validate signature.
|
||||
(last block signature means CRC is for whole file, return now) */
|
||||
|
||||
i = get_bits(bd,24);
|
||||
j = get_bits(bd,24);
|
||||
bd->headerCRC=get_bits(bd,32);
|
||||
if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* We can add support for blockRandomised if anybody complains. There was
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
|
||||
if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
|
||||
if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
symbols to deal with, and writes a sparse bitfield indicating which
|
||||
values were present. We make a translation table to convert the symbols
|
||||
back to the corresponding bytes. */
|
||||
|
||||
t=get_bits(bd, 16);
|
||||
symTotal=0;
|
||||
for (i=0;i<16;i++) {
|
||||
@@ -174,60 +184,81 @@ static int get_next_block(bunzip_data *bd)
|
||||
if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j;
|
||||
}
|
||||
}
|
||||
|
||||
/* How many different Huffman coding groups does this block use? */
|
||||
|
||||
groupCount=get_bits(bd,3);
|
||||
if (groupCount<2 || groupCount>MAX_GROUPS) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* nSelectors: Every GROUP_SIZE many symbols we select a new Huffman coding
|
||||
group. Read in the group selector list, which is stored as MTF encoded
|
||||
bit runs. (MTF=Move To Front, as each value is used it's moved to the
|
||||
start of the list.) */
|
||||
|
||||
if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR;
|
||||
for(i=0; i<groupCount; i++) mtfSymbol[i] = i;
|
||||
for(i=0; i<nSelectors; i++) {
|
||||
|
||||
/* Get next value */
|
||||
|
||||
for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* Decode MTF to get the next selector */
|
||||
|
||||
uc = mtfSymbol[j];
|
||||
for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
mtfSymbol[0]=selectors[i]=uc;
|
||||
}
|
||||
|
||||
/* Read the Huffman coding tables for each group, which code for symTotal
|
||||
literal symbols, plus two run symbols (RUNA, RUNB) */
|
||||
|
||||
symCount=symTotal+2;
|
||||
for (j=0; j<groupCount; j++) {
|
||||
unsigned char length[MAX_SYMBOLS],temp[MAX_HUFCODE_BITS+1];
|
||||
int minLen, maxLen, pp;
|
||||
|
||||
/* Read Huffman code lengths for each symbol. They're stored in
|
||||
a way similar to mtf; record a starting value for the first symbol,
|
||||
and an offset from the previous value for everys symbol after that.
|
||||
(Subtracting 1 before the loop and then adding it back at the end is
|
||||
an optimization that makes the test inside the loop simpler: symbol
|
||||
length 0 becomes negative, so an unsigned inequality catches it.) */
|
||||
|
||||
t=get_bits(bd, 5)-1;
|
||||
for (i = 0; i < symCount; i++) {
|
||||
for(;;) {
|
||||
if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
|
||||
return RETVAL_DATA_ERROR;
|
||||
|
||||
/* If first bit is 0, stop. Else second bit indicates whether
|
||||
to increment or decrement the value. Optimization: grab 2
|
||||
bits and unget the second if the first was 0. */
|
||||
|
||||
k = get_bits(bd,2);
|
||||
if (k < 2) {
|
||||
bd->inbufBitCount++;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Add one if second bit 1, else subtract 1. Avoids if/else */
|
||||
|
||||
t+=(((k+1)&2)-1);
|
||||
}
|
||||
|
||||
/* Correct for the initial -1, to get the final symbol length */
|
||||
|
||||
length[i]=t+1;
|
||||
}
|
||||
|
||||
/* Find largest and smallest lengths in this group */
|
||||
|
||||
minLen=maxLen=length[0];
|
||||
for(i = 1; i < symCount; i++) {
|
||||
if(length[i] > maxLen) maxLen = length[i];
|
||||
else if(length[i] < minLen) minLen = length[i];
|
||||
}
|
||||
|
||||
/* Calculate permute[], base[], and limit[] tables from length[].
|
||||
*
|
||||
* permute[] is the lookup table for converting Huffman coded symbols
|
||||
@@ -238,36 +269,47 @@ static int get_next_block(bunzip_data *bd)
|
||||
* number of bits can have. This is how the Huffman codes can vary in
|
||||
* length: each code with a value>limit[length] needs another bit.
|
||||
*/
|
||||
|
||||
hufGroup=bd->groups+j;
|
||||
hufGroup->minLen = minLen;
|
||||
hufGroup->maxLen = maxLen;
|
||||
|
||||
/* Note that minLen can't be smaller than 1, so we adjust the base
|
||||
and limit array pointers so we're not always wasting the first
|
||||
entry. We do this again when using them (during symbol decoding).*/
|
||||
|
||||
base=hufGroup->base-1;
|
||||
limit=hufGroup->limit-1;
|
||||
|
||||
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
|
||||
|
||||
pp=0;
|
||||
for(i=minLen;i<=maxLen;i++) {
|
||||
temp[i]=limit[i]=0;
|
||||
for(t=0;t<symCount;t++)
|
||||
if(length[t]==i) hufGroup->permute[pp++] = t;
|
||||
}
|
||||
|
||||
/* Count symbols coded for at each bit length */
|
||||
|
||||
for (i=0;i<symCount;i++) temp[length[i]]++;
|
||||
|
||||
/* Calculate limit[] (the largest symbol-coding value at each bit
|
||||
* length, which is (previous limit<<1)+symbols at this level), and
|
||||
* base[] (number of symbols to ignore at each bit length, which is
|
||||
* limit minus the cumulative count of symbols coded for already). */
|
||||
|
||||
pp=t=0;
|
||||
for (i=minLen; i<maxLen; i++) {
|
||||
pp+=temp[i];
|
||||
|
||||
/* We read the largest possible symbol size and then unget bits
|
||||
after determining how many we need, and those extra bits could
|
||||
be set to anything. (They're noise from future symbols.) At
|
||||
each level we're really only interested in the first few bits,
|
||||
so here we set all the trailing to-be-ignored bits to 1 so they
|
||||
don't affect the value>limit[length] comparison. */
|
||||
|
||||
limit[i]= (pp << (maxLen - i)) - 1;
|
||||
pp<<=1;
|
||||
base[i+1]=pp-(t+=temp[i]);
|
||||
@@ -276,27 +318,34 @@ static int get_next_block(bunzip_data *bd)
|
||||
limit[maxLen]=pp+temp[maxLen]-1;
|
||||
base[minLen]=0;
|
||||
}
|
||||
|
||||
/* We've finished reading and digesting the block header. Now read this
|
||||
block's Huffman coded symbols from the file and undo the Huffman coding
|
||||
and run length encoding, saving the result into dbuf[dbufCount++]=uc */
|
||||
|
||||
/* Initialize symbol occurrence counters and symbol Move To Front table */
|
||||
|
||||
for(i=0;i<256;i++) {
|
||||
byteCount[i] = 0;
|
||||
mtfSymbol[i]=(unsigned char)i;
|
||||
}
|
||||
|
||||
/* Loop through compressed symbols. */
|
||||
runPos=dbufCount=symCount=selector=0;
|
||||
|
||||
runPos=dbufCount=selector=0;
|
||||
for(;;) {
|
||||
/* Determine which Huffman coding group to use. */
|
||||
if(!(symCount--)) {
|
||||
symCount=GROUP_SIZE-1;
|
||||
if(selector>=nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup=bd->groups+selectors[selector++];
|
||||
base=hufGroup->base-1;
|
||||
limit=hufGroup->limit-1;
|
||||
}
|
||||
|
||||
/* fetch next Huffman coding group from list. */
|
||||
|
||||
symCount=GROUP_SIZE-1;
|
||||
if(selector>=nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup=bd->groups+selectors[selector++];
|
||||
base=hufGroup->base-1;
|
||||
limit=hufGroup->limit-1;
|
||||
continue_this_group:
|
||||
|
||||
/* Read next Huffman-coded symbol. */
|
||||
|
||||
/* Note: It is far cheaper to read maxLen bits and back up than it is
|
||||
to read minLen bits and then an additional bit at a time, testing
|
||||
as we go. Because there is a trailing last block (with file CRC),
|
||||
@@ -306,6 +355,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
dry). The following (up to got_huff_bits:) is equivalent to
|
||||
j=get_bits(bd,hufGroup->maxLen);
|
||||
*/
|
||||
|
||||
while (bd->inbufBitCount<hufGroup->maxLen) {
|
||||
if(bd->inbufPos==bd->inbufCount) {
|
||||
j = get_bits(bd,hufGroup->maxLen);
|
||||
@@ -316,27 +366,37 @@ static int get_next_block(bunzip_data *bd)
|
||||
};
|
||||
bd->inbufBitCount-=hufGroup->maxLen;
|
||||
j = (bd->inbufBits>>bd->inbufBitCount)&((1<<hufGroup->maxLen)-1);
|
||||
|
||||
got_huff_bits:
|
||||
|
||||
/* Figure how how many bits are in next symbol and unget extras */
|
||||
|
||||
i=hufGroup->minLen;
|
||||
while(j>limit[i]) ++i;
|
||||
bd->inbufBitCount += (hufGroup->maxLen - i);
|
||||
|
||||
/* Huffman decode value to get nextSym (with bounds checking) */
|
||||
|
||||
if ((i > hufGroup->maxLen)
|
||||
|| (((unsigned)(j=(j>>(hufGroup->maxLen-i))-base[i]))
|
||||
>= MAX_SYMBOLS))
|
||||
return RETVAL_DATA_ERROR;
|
||||
nextSym = hufGroup->permute[j];
|
||||
|
||||
/* We have now decoded the symbol, which indicates either a new literal
|
||||
byte, or a repeated run of the most recent literal byte. First,
|
||||
check if nextSym indicates a repeated run, and if so loop collecting
|
||||
how many times to repeat the last literal. */
|
||||
|
||||
if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
|
||||
|
||||
/* If this is the start of a new run, zero out counter */
|
||||
|
||||
if(!runPos) {
|
||||
runPos = 1;
|
||||
t = 0;
|
||||
}
|
||||
|
||||
/* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at
|
||||
each bit position, add 1 or 2 instead. For example,
|
||||
1011 is 1<<0 + 1<<1 + 2<<2. 1010 is 2<<0 + 2<<1 + 1<<2.
|
||||
@@ -344,14 +404,17 @@ got_huff_bits:
|
||||
the basic or 0/1 method (except all bits 0, which would use no
|
||||
symbols, but a run of length 0 doesn't mean anything in this
|
||||
context). Thus space is saved. */
|
||||
|
||||
t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
|
||||
runPos <<= 1;
|
||||
continue;
|
||||
if(runPos < dbufSize) runPos <<= 1;
|
||||
goto end_of_huffman_loop;
|
||||
}
|
||||
|
||||
/* When we hit the first non-run symbol after a run, we now know
|
||||
how many times to repeat the last literal, so append that many
|
||||
copies to our buffer of decoded symbols (dbuf) now. (The last
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
|
||||
if(runPos) {
|
||||
runPos=0;
|
||||
if(dbufCount+t>=dbufSize) return RETVAL_DATA_ERROR;
|
||||
@@ -360,8 +423,11 @@ got_huff_bits:
|
||||
byteCount[uc] += t;
|
||||
while(t--) dbuf[dbufCount++]=uc;
|
||||
}
|
||||
|
||||
/* Is this the terminating symbol? */
|
||||
|
||||
if(nextSym>symTotal) break;
|
||||
|
||||
/* At this point, nextSym indicates a new literal character. Subtract
|
||||
one to get the position in the MTF array at which this literal is
|
||||
currently to be found. (Note that the result can't be -1 or 0,
|
||||
@@ -369,44 +435,62 @@ got_huff_bits:
|
||||
first symbol in the mtf array, position 0, would have been handled
|
||||
as part of a run above. Therefore 1 unused mtf position minus
|
||||
2 non-literal nextSym values equals -1.) */
|
||||
|
||||
if(dbufCount>=dbufSize) return RETVAL_DATA_ERROR;
|
||||
i = nextSym - 1;
|
||||
uc = mtfSymbol[i];
|
||||
|
||||
/* Adjust the MTF array. Since we typically expect to move only a
|
||||
* small number of symbols, and are bound by 256 in any case, using
|
||||
* memmove here would typically be bigger and slower due to function
|
||||
* call overhead and other assorted setup costs. */
|
||||
|
||||
do {
|
||||
mtfSymbol[i] = mtfSymbol[i-1];
|
||||
} while (--i);
|
||||
mtfSymbol[0] = uc;
|
||||
uc=symToByte[uc];
|
||||
|
||||
/* We have our literal byte. Save it into dbuf. */
|
||||
|
||||
byteCount[uc]++;
|
||||
dbuf[dbufCount++] = (unsigned int)uc;
|
||||
|
||||
/* Skip group initialization if we're not done with this group. Done
|
||||
* this way to avoid compiler warning. */
|
||||
|
||||
end_of_huffman_loop:
|
||||
if(symCount--) goto continue_this_group;
|
||||
}
|
||||
|
||||
/* At this point, we've read all the Huffman-coded symbols (and repeated
|
||||
runs) for this block from the input stream, and decoded them into the
|
||||
intermediate buffer. There are dbufCount many decoded bytes in dbuf[].
|
||||
Now undo the Burrows-Wheeler transform on dbuf.
|
||||
See http://dogma.net/markn/articles/bwt/bwt.htm
|
||||
*/
|
||||
|
||||
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
|
||||
|
||||
j=0;
|
||||
for(i=0;i<256;i++) {
|
||||
k=j+byteCount[i];
|
||||
byteCount[i] = j;
|
||||
j=k;
|
||||
}
|
||||
|
||||
/* Figure out what order dbuf would be in if we sorted it. */
|
||||
|
||||
for (i=0;i<dbufCount;i++) {
|
||||
uc=(unsigned char)(dbuf[i] & 0xff);
|
||||
dbuf[byteCount[uc]] |= (i << 8);
|
||||
byteCount[uc]++;
|
||||
}
|
||||
|
||||
/* Decode first byte by hand to initialize "previous" byte. Note that it
|
||||
doesn't get output, and if the first three characters are identical
|
||||
it doesn't qualify as a run (hence writeRunCountdown=5). */
|
||||
|
||||
if(dbufCount) {
|
||||
if(origPtr>=dbufCount) return RETVAL_DATA_ERROR;
|
||||
bd->writePos=dbuf[origPtr];
|
||||
@@ -444,22 +528,32 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
Huffman-decoded a block into the intermediate buffer yet). */
|
||||
|
||||
if (bd->writeCopies) {
|
||||
|
||||
/* Inside the loop, writeCopies means extra copies (beyond 1) */
|
||||
|
||||
--bd->writeCopies;
|
||||
|
||||
/* Loop outputting bytes */
|
||||
|
||||
for(;;) {
|
||||
|
||||
/* If the output buffer is full, snapshot state and return */
|
||||
|
||||
if(gotcount >= len) {
|
||||
bd->writePos=pos;
|
||||
bd->writeCurrent=current;
|
||||
bd->writeCopies++;
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Write next byte into output buffer, updating CRC */
|
||||
|
||||
outbuf[gotcount++] = current;
|
||||
bd->writeCRC=(((bd->writeCRC)<<8)
|
||||
^bd->crc32Table[((bd->writeCRC)>>24)^current]);
|
||||
|
||||
/* Loop now if we're outputting multiple copies of this byte */
|
||||
|
||||
if (bd->writeCopies) {
|
||||
--bd->writeCopies;
|
||||
continue;
|
||||
@@ -471,26 +565,38 @@ decode_next_byte:
|
||||
pos=dbuf[pos];
|
||||
current=pos&0xff;
|
||||
pos>>=8;
|
||||
|
||||
/* After 3 consecutive copies of the same byte, the 4th is a repeat
|
||||
count. We count down from 4 instead
|
||||
* of counting up because testing for non-zero is faster */
|
||||
|
||||
if(--bd->writeRunCountdown) {
|
||||
if(current!=previous) bd->writeRunCountdown=4;
|
||||
} else {
|
||||
|
||||
/* We have a repeated run, this byte indicates the count */
|
||||
|
||||
bd->writeCopies=current;
|
||||
current=previous;
|
||||
bd->writeRunCountdown=5;
|
||||
|
||||
/* Sometimes there are just 3 bytes (run length 0) */
|
||||
|
||||
if(!bd->writeCopies) goto decode_next_byte;
|
||||
|
||||
/* Subtract the 1 copy we'd output anyway to get extras */
|
||||
|
||||
--bd->writeCopies;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decompression of this block completed successfully */
|
||||
|
||||
bd->writeCRC=~bd->writeCRC;
|
||||
bd->totalCRC=((bd->totalCRC<<1) | (bd->totalCRC>>31)) ^ bd->writeCRC;
|
||||
|
||||
/* If this block had a CRC error, force file level CRC error. */
|
||||
|
||||
if(bd->writeCRC!=bd->headerCRC) {
|
||||
bd->totalCRC=bd->headerCRC+1;
|
||||
return RETVAL_LAST_BLOCK;
|
||||
@@ -499,12 +605,13 @@ decode_next_byte:
|
||||
|
||||
/* Refill the intermediate buffer by Huffman-decoding next block of input */
|
||||
/* (previous is just a convenient unused temp variable here) */
|
||||
|
||||
previous=get_next_block(bd);
|
||||
if(previous) {
|
||||
bd->writeCount=previous;
|
||||
return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount;
|
||||
}
|
||||
bd->writeCRC=0xffffffffUL;
|
||||
bd->writeCRC=~0;
|
||||
pos=bd->writePos;
|
||||
current=bd->writeCurrent;
|
||||
goto decode_next_byte;
|
||||
@@ -513,41 +620,48 @@ decode_next_byte:
|
||||
/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
|
||||
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
|
||||
ignored, and data is read from file handle into temporary buffer. */
|
||||
static int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len)
|
||||
|
||||
static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
|
||||
int len)
|
||||
{
|
||||
bunzip_data *bd;
|
||||
unsigned int i,j,c;
|
||||
unsigned int i;
|
||||
const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16)
|
||||
+(((unsigned int)'h')<<8)+(unsigned int)'0';
|
||||
|
||||
/* Figure out how much data to allocate */
|
||||
|
||||
i=sizeof(bunzip_data);
|
||||
if(in_fd!=-1) i+=IOBUF_SIZE;
|
||||
|
||||
/* Allocate bunzip_data. Most fields initialize to zero. */
|
||||
bd=*bdp=xmalloc(i);
|
||||
memset(bd,0,sizeof(bunzip_data));
|
||||
|
||||
bd=*bdp=xzalloc(i);
|
||||
|
||||
/* Setup input buffer */
|
||||
|
||||
if(-1==(bd->in_fd=in_fd)) {
|
||||
bd->inbuf=inbuf;
|
||||
bd->inbufCount=len;
|
||||
} else bd->inbuf=(unsigned char *)(bd+1);
|
||||
|
||||
/* Init the CRC32 table (big endian) */
|
||||
for(i=0;i<256;i++) {
|
||||
c=i<<24;
|
||||
for(j=8;j;j--)
|
||||
c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
|
||||
bd->crc32Table[i]=c;
|
||||
}
|
||||
|
||||
bd->crc32Table = crc32_filltable(1);
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
|
||||
i=setjmp(bd->jmpbuf);
|
||||
if(i) return i;
|
||||
|
||||
/* Ensure that file starts with "BZh['1'-'9']." */
|
||||
|
||||
i = get_bits(bd,32);
|
||||
if (((unsigned int)(i-BZh0-1)) >= 9) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
|
||||
uncompressed data. Allocate intermediate buffer for block. */
|
||||
|
||||
bd->dbufSize=100000*(i-BZh0);
|
||||
|
||||
bd->dbuf=xmalloc(bd->dbufSize * sizeof(int));
|
||||
@@ -556,47 +670,53 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, char *inbuf, int len)
|
||||
|
||||
/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data,
|
||||
not end of file.) */
|
||||
extern int uncompressStream(int src_fd, int dst_fd)
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
uncompressStream(int src_fd, int dst_fd)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
char *outbuf;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
|
||||
outbuf=xmalloc(IOBUF_SIZE);
|
||||
if(!(i=start_bunzip(&bd,src_fd,0,0))) {
|
||||
i=start_bunzip(&bd,src_fd,0,0);
|
||||
if(!i) {
|
||||
for(;;) {
|
||||
if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break;
|
||||
if(i!=write(dst_fd,outbuf,i)) {
|
||||
i=RETVAL_UNEXPECTED_OUTPUT_EOF;
|
||||
break;
|
||||
}
|
||||
USE_DESKTOP(total_written += i;)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check CRC and release memory */
|
||||
|
||||
if(i==RETVAL_LAST_BLOCK) {
|
||||
if (bd->headerCRC!=bd->totalCRC) {
|
||||
bb_error_msg("Data integrity error when decompressing.");
|
||||
bb_error_msg("data integrity error when decompressing");
|
||||
} else {
|
||||
i=RETVAL_OK;
|
||||
}
|
||||
}
|
||||
else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
||||
bb_error_msg("Compressed file ends unexpectedly");
|
||||
} else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
||||
bb_error_msg("compressed file ends unexpectedly");
|
||||
} else {
|
||||
bb_error_msg("Decompression failed");
|
||||
bb_error_msg("decompression failed");
|
||||
}
|
||||
if(bd->dbuf) free(bd->dbuf);
|
||||
free(bd->dbuf);
|
||||
free(bd);
|
||||
free(outbuf);
|
||||
|
||||
return i;
|
||||
return i ? i : USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static char * const bunzip_errors[]={NULL,"Bad file checksum","Not bzip data",
|
||||
"Unexpected input EOF","Unexpected output EOF","Data error",
|
||||
"Out of memory","Obsolete (pre 0.9.5) bzip format not supported."};
|
||||
"Out of memory","Obsolete (pre 0.9.5) bzip format not supported."};
|
||||
|
||||
/* Dumb little test thing, decompress stdin to stdout */
|
||||
int main(int argc, char *argv[])
|
||||
@@ -604,8 +724,8 @@ int main(int argc, char *argv[])
|
||||
int i=uncompressStream(0,1);
|
||||
char c;
|
||||
|
||||
if(i) fprintf(stderr,"%s\n", bunzip_errors[-i]);
|
||||
else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n");
|
||||
if(i<0) fprintf(stderr,"%s\n", bunzip_errors[-i]);
|
||||
else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n");
|
||||
return -i;
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "config.h"
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "libbb.h"
|
||||
|
||||
/* uncompress for busybox -- (c) 2002 Robert Griebl
|
||||
@@ -65,30 +65,17 @@
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
/* Block compress mode -C compatible with 2.0 */
|
||||
int block_mode = BLOCK_MODE;
|
||||
static 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];
|
||||
static int maxbits = BITS;
|
||||
|
||||
#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_htab() memset(htab, -1, HSIZE)
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
|
||||
@@ -99,8 +86,10 @@ unsigned short codetab[HSIZE];
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
extern int uncompress(int fd_in, int fd_out)
|
||||
USE_DESKTOP(long long) int
|
||||
uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
unsigned char *stackp;
|
||||
long int code;
|
||||
int finchar;
|
||||
@@ -116,10 +105,16 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
long int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
RESERVE_CONFIG_UBUFFER(inbuf, IBUFSIZ + 64);
|
||||
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
|
||||
unsigned char htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
memset(inbuf, 0, IBUFSIZ + 64);
|
||||
memset(outbuf, 0, OBUFSIZ + 2048);
|
||||
|
||||
insize = 0;
|
||||
|
||||
inbuf[0] = bb_xread_char(fd_in);
|
||||
inbuf[0] = xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
@@ -163,7 +158,7 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
posbits = 0;
|
||||
}
|
||||
|
||||
if (insize < (int) sizeof(inbuf) - IBUFSIZ) {
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
insize += rsize;
|
||||
}
|
||||
@@ -189,16 +184,16 @@ extern int 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) {
|
||||
outbuf[outpos++] = (unsigned char) (finchar =
|
||||
(int) (oldcode = code));
|
||||
oldcode = code;
|
||||
finchar = (int) oldcode;
|
||||
outbuf[outpos++] = (unsigned char) finchar;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -262,6 +257,7 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
@@ -287,7 +283,10 @@ extern int uncompress(int fd_in, int fd_out)
|
||||
|
||||
if (outpos > 0) {
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
return 0;
|
||||
RELEASE_CONFIG_BUFFER(inbuf);
|
||||
RELEASE_CONFIG_BUFFER(outbuf);
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
/* 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"
|
||||
|
||||
#ifdef CONFIG_FEATURE_LZMA_FAST
|
||||
# define speed_inline ATTRIBUTE_ALWAYS_INLINE
|
||||
#else
|
||||
# define speed_inline
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
uint8_t *ptr;
|
||||
uint8_t *buffer;
|
||||
uint8_t *buffer_end;
|
||||
int buffer_size;
|
||||
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)
|
||||
{
|
||||
rc->buffer_size = read(rc->fd, rc->buffer, rc->buffer_size);
|
||||
if (rc->buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = rc->buffer;
|
||||
rc->buffer_end = rc->buffer + rc->buffer_size;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static void rc_init(rc_t * rc, int fd, int buffer_size)
|
||||
{
|
||||
int i;
|
||||
|
||||
rc->fd = fd;
|
||||
rc->buffer = xmalloc(buffer_size);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Called once. TODO: bb_maybe_free() */
|
||||
static ATTRIBUTE_ALWAYS_INLINE void rc_free(rc_t * rc)
|
||||
{
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(rc->buffer);
|
||||
}
|
||||
|
||||
/* 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 ATTRIBUTE_ALWAYS_INLINE void rc_normalize(rc_t * rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called 9 times */
|
||||
/* Why rc_is_bit_0_helper exists?
|
||||
* Because we want to always expose (rc->code < rc->bound) to optimizer
|
||||
*/
|
||||
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 ATTRIBUTE_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 ATTRIBUTE_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;
|
||||
|
||||
|
||||
#define LZMA_BASE_SIZE 1846
|
||||
#define LZMA_LIT_SIZE 768
|
||||
|
||||
#define LZMA_NUM_POS_BITS_MAX 4
|
||||
|
||||
#define LZMA_LEN_NUM_LOW_BITS 3
|
||||
#define LZMA_LEN_NUM_MID_BITS 3
|
||||
#define LZMA_LEN_NUM_HIGH_BITS 8
|
||||
|
||||
#define LZMA_LEN_CHOICE 0
|
||||
#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
|
||||
#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
|
||||
#define LZMA_LEN_MID (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
|
||||
#define LZMA_LEN_HIGH (LZMA_LEN_MID \
|
||||
+(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
|
||||
#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
|
||||
|
||||
#define LZMA_NUM_STATES 12
|
||||
#define LZMA_NUM_LIT_STATES 7
|
||||
|
||||
#define LZMA_START_POS_MODEL_INDEX 4
|
||||
#define LZMA_END_POS_MODEL_INDEX 14
|
||||
#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
|
||||
|
||||
#define LZMA_NUM_POS_SLOT_BITS 6
|
||||
#define LZMA_NUM_LEN_TO_POS_STATES 4
|
||||
|
||||
#define LZMA_NUM_ALIGN_BITS 4
|
||||
|
||||
#define LZMA_MATCH_MIN_LEN 2
|
||||
|
||||
#define LZMA_IS_MATCH 0
|
||||
#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
|
||||
#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_SPEC_POS (LZMA_POS_SLOT \
|
||||
+(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
|
||||
#define LZMA_ALIGN (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
|
||||
#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
|
||||
#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unlzma(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;
|
||||
|
||||
if (read(src_fd, &header, sizeof(header)) != sizeof(header))
|
||||
bb_error_msg_and_die("can't read 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_init(&rc, src_fd, 0x10000);
|
||||
|
||||
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;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
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;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
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;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, buffer_pos);
|
||||
USE_DESKTOP(total_written += buffer_pos;)
|
||||
rc_free(&rc);
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
@@ -16,20 +16,10 @@
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Fixed huft_build() so decoding end-of-block code does not grab more bits
|
||||
* than necessary (this is required by unzip applet), added inflate_cleanup()
|
||||
* to free leaked bytebuffer memory (used in unzip.c), and some minor style
|
||||
* guide cleanups by Ed Clark
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -38,39 +28,12 @@
|
||||
* 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.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#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 "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
typedef struct huft_s {
|
||||
@@ -88,11 +51,11 @@ 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;
|
||||
enum { gunzip_wsize = 0x8000 };
|
||||
static unsigned char *gunzip_window;
|
||||
|
||||
static unsigned int *gunzip_crc_table;
|
||||
unsigned int gunzip_crc;
|
||||
static uint32_t *gunzip_crc_table;
|
||||
uint32_t 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) */
|
||||
@@ -116,26 +79,26 @@ static const unsigned short mask_bits[] = {
|
||||
/* 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
|
||||
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
|
||||
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
|
||||
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
|
||||
11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
@@ -151,43 +114,16 @@ static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current
|
||||
/* 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() */
|
||||
bytebuffer_size = 4 + bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8);
|
||||
if (1 > (bytebuffer_size = safe_read(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;
|
||||
}
|
||||
return bitbuffer;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -225,70 +161,60 @@ static int huft_free(huft_t * t)
|
||||
* 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)
|
||||
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, unsigned int *m)
|
||||
{
|
||||
unsigned a; /* counter for codes of length k */
|
||||
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 eob_len; /* length of end-of-block code (value 256) */
|
||||
unsigned f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int htl; /* table level */
|
||||
unsigned i; /* counter, current code */
|
||||
unsigned j; /* counter */
|
||||
int k; /* number of bits in current code */
|
||||
unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
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 */
|
||||
int ws[BMAX+1]; /* bits decoded stack */
|
||||
int w; /* bits decoded */
|
||||
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 */
|
||||
unsigned *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
unsigned z; /* number of entries in current table */
|
||||
|
||||
/* Length of EOB code, if any */
|
||||
eob_len = n > 256 ? b[256] : BMAX;
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset((void *) (c), 0, sizeof(c));
|
||||
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) */
|
||||
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 */
|
||||
if (c[0] == n) { /* null input--all zero length codes */
|
||||
*t = (huft_t *) NULL;
|
||||
*m = 0;
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
for (j = 1; (c[j] == 0) && (j <= BMAX); j++);
|
||||
k = j; /* minimum code length */
|
||||
for (i = BMAX; (c[i] == 0) && i; i--);
|
||||
g = i; /* maximum code length */
|
||||
*m = (*m < j) ? j : ((*m > i) ? i : *m);
|
||||
|
||||
/* 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 */
|
||||
return 2; /* bad input: more codes than bits */
|
||||
}
|
||||
}
|
||||
if ((y -= c[i]) < 0) {
|
||||
@@ -300,7 +226,7 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
x[1] = j = 0;
|
||||
p = c + 1;
|
||||
xp = x + 2;
|
||||
while (--i) { /* note that i == g from above */
|
||||
while (--i) { /* note that i == g from above */
|
||||
*xp++ = (j += *p++);
|
||||
}
|
||||
|
||||
@@ -314,13 +240,13 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
} 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) */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
htl = -1; /* no tables yet--level -1 */
|
||||
w = ws[0] = 0; /* bits decoded */
|
||||
u[0] = (huft_t *) NULL; /* just to keep compilers happy */
|
||||
q = (huft_t *) NULL; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
|
||||
/* go through the bit lengths (k already is bits in shortest code) */
|
||||
for (; k <= g; k++) {
|
||||
@@ -328,52 +254,52 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
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 */
|
||||
while (k > ws[htl + 1]) {
|
||||
w = ws[++htl];
|
||||
|
||||
/* 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 */
|
||||
/* compute minimum size table less than or equal to *m bits */
|
||||
z = (z = g - w) > *m ? *m : 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 */
|
||||
while (++j < z) { /* try smaller tables up to z bits */
|
||||
if ((f <<= 1) <= *++xp) {
|
||||
break; /* enough codes to use up j bits */
|
||||
break; /* enough codes to use up j bits */
|
||||
}
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
j = (w + j > eob_len && w < eob_len) ? eob_len - w : j; /* make EOB code end at table */
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
ws[htl+1] = w + j; /* set bits decoded in stack */
|
||||
|
||||
/* allocate and link in new table */
|
||||
q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t));
|
||||
|
||||
q = (huft_t *) xzalloc((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 */
|
||||
t = &(q->v.t);
|
||||
u[htl] = ++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 */
|
||||
if (htl) {
|
||||
x[htl] = i; /* save pattern for backing up */
|
||||
r.b = (unsigned char) (w - ws[htl - 1]); /* 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 & ((1 << w) - 1)) >> ws[htl - 1];
|
||||
u[htl - 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 */
|
||||
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++ */
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
|
||||
} else {
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
||||
r.v.n = d[*p++ - s];
|
||||
}
|
||||
|
||||
@@ -390,12 +316,15 @@ static int huft_build(unsigned int *b, const unsigned int n,
|
||||
i ^= j;
|
||||
|
||||
/* backup over finished tables */
|
||||
while ((i & ((1 << w) - 1)) != x[h]) {
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
while ((i & ((1 << w) - 1)) != x[htl]) {
|
||||
w = ws[--htl];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* return actual size of base table */
|
||||
*m = ws[1];
|
||||
|
||||
/* Return true (1) if we were given an incomplete table */
|
||||
return y != 0 && g != 1;
|
||||
}
|
||||
@@ -443,7 +372,7 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned int my_b
|
||||
if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
bb_error_msg_and_die("inflate_codes error 1");;
|
||||
bb_error_msg_and_die("inflate_codes error 1");
|
||||
}
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
@@ -479,7 +408,7 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned int my_b
|
||||
if ((e = (t = td + ((unsigned) b & md))->e) > 16)
|
||||
do {
|
||||
if (e == 99)
|
||||
bb_error_msg_and_die("inflate_codes error 2");;
|
||||
bb_error_msg_and_die("inflate_codes error 2");
|
||||
b >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -540,7 +469,7 @@ do_copy: do {
|
||||
|
||||
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;
|
||||
static unsigned int n, b_stored, k_stored, w;
|
||||
if (setup) {
|
||||
n = my_n;
|
||||
b_stored = my_b_stored;
|
||||
@@ -553,7 +482,7 @@ static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
||||
while (n--) {
|
||||
b_stored = fill_bitbuffer(b_stored, &k_stored, 8);
|
||||
gunzip_window[w++] = (unsigned char) b_stored;
|
||||
if (w == (unsigned int) gunzip_wsize) {
|
||||
if (w == gunzip_wsize) {
|
||||
gunzip_outbuf_count = (w);
|
||||
//flush_gunzip_window();
|
||||
w = 0;
|
||||
@@ -582,7 +511,7 @@ static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
||||
static int inflate_block(int *e)
|
||||
{
|
||||
unsigned t; /* block type */
|
||||
register unsigned int b; /* bit buffer */
|
||||
unsigned int b; /* bit buffer */
|
||||
unsigned int k; /* number of bits in bit buffer */
|
||||
|
||||
/* make local bit buffer */
|
||||
@@ -816,7 +745,7 @@ static int inflate_block(int *e)
|
||||
|
||||
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
|
||||
if (i == 1) {
|
||||
bb_error_msg_and_die("Incomplete literal tree");
|
||||
bb_error_msg_and_die("incomplete literal tree");
|
||||
huft_free(tl);
|
||||
}
|
||||
return i; /* incomplete code set */
|
||||
@@ -841,7 +770,7 @@ static int inflate_block(int *e)
|
||||
}
|
||||
default:
|
||||
/* bad block type */
|
||||
bb_error_msg_and_die("bad block type %d\n", t);
|
||||
bb_error_msg_and_die("bad block type %d", t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -877,11 +806,11 @@ static int inflate_get_next_window(void)
|
||||
}
|
||||
|
||||
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);
|
||||
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) {
|
||||
@@ -893,7 +822,7 @@ static int inflate_get_next_window(void)
|
||||
}
|
||||
|
||||
/* Initialise bytebuffer, be careful not to overfill the buffer */
|
||||
extern void inflate_init(unsigned int bufsize)
|
||||
void inflate_init(unsigned int bufsize)
|
||||
{
|
||||
/* Set the bytebuffer size, default is same as gunzip_wsize */
|
||||
bytebuffer_max = bufsize + 8;
|
||||
@@ -901,8 +830,15 @@ extern void inflate_init(unsigned int bufsize)
|
||||
bytebuffer_size = 0;
|
||||
}
|
||||
|
||||
extern int inflate_unzip(int in, int out)
|
||||
void inflate_cleanup(void)
|
||||
{
|
||||
free(bytebuffer);
|
||||
}
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
inflate_unzip(int in, int out)
|
||||
{
|
||||
USE_DESKTOP(long long total = 0;)
|
||||
ssize_t nwrote;
|
||||
typedef void (*sig_type) (int);
|
||||
|
||||
@@ -917,18 +853,20 @@ extern int inflate_unzip(int in, int out)
|
||||
gunzip_bb = 0;
|
||||
|
||||
/* Create the crc table */
|
||||
make_gunzip_crc_table();
|
||||
gunzip_crc_table = crc32_filltable(0);
|
||||
gunzip_crc = ~0;
|
||||
|
||||
/* 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);
|
||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == -1) {
|
||||
bb_perror_msg("write");
|
||||
return -1;
|
||||
}
|
||||
USE_DESKTOP(total += nwrote;)
|
||||
if (ret == 0) break;
|
||||
}
|
||||
|
||||
@@ -945,20 +883,22 @@ extern int inflate_unzip(int in, int out)
|
||||
gunzip_bb >>= 8;
|
||||
gunzip_bk -= 8;
|
||||
}
|
||||
return 0;
|
||||
return USE_DESKTOP(total) + 0;
|
||||
}
|
||||
|
||||
extern int inflate_gunzip(int in, int out)
|
||||
USE_DESKTOP(long long) int
|
||||
inflate_gunzip(int in, int out)
|
||||
{
|
||||
unsigned int stored_crc = 0;
|
||||
unsigned char count;
|
||||
uint32_t stored_crc = 0;
|
||||
unsigned int count;
|
||||
USE_DESKTOP(long long total = )inflate_unzip(in, out);
|
||||
|
||||
inflate_unzip(in, out);
|
||||
USE_DESKTOP(if (total < 0) return total;)
|
||||
|
||||
/* 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);
|
||||
xread(in, &bytebuffer[bytebuffer_size], 8 - count);
|
||||
bytebuffer_size += 8 - count;
|
||||
}
|
||||
for (count = 0; count != 4; count++) {
|
||||
@@ -967,16 +907,18 @@ extern int inflate_gunzip(int in, int out)
|
||||
}
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (stored_crc != (gunzip_crc ^ 0xffffffffL)) {
|
||||
if (stored_crc != (~gunzip_crc)) {
|
||||
bb_error_msg("crc error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 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");
|
||||
bb_error_msg("incorrect length");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return USE_DESKTOP(total) + 0;
|
||||
}
|
||||
@@ -1,32 +1,17 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
* Copyright (C) 2002 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Accept any non-null name, its not really a filter at all */
|
||||
extern char filter_accept_all(archive_handle_t *archive_handle)
|
||||
char filter_accept_all(archive_handle_t *archive_handle)
|
||||
{
|
||||
if (archive_handle->file_header->name) {
|
||||
return(EXIT_SUCCESS);
|
||||
} else {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
if (archive_handle->file_header->name)
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,34 +1,19 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
* Copyright (C) 2002 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list, ignoring reject list.
|
||||
*/
|
||||
extern char filter_accept_list(archive_handle_t *archive_handle)
|
||||
char filter_accept_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
|
||||
return(EXIT_SUCCESS);
|
||||
} else {
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name))
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,19 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -28,7 +17,7 @@
|
||||
* 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
|
||||
*/
|
||||
extern char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Check the file entry is in the accept list */
|
||||
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
|
||||
@@ -41,15 +30,19 @@ extern char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
if (strcmp(name_ptr, ".gz") == 0) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
if (strcmp(name_ptr, ".bz2") == 0) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_bz2;
|
||||
return(EXIT_SUCCESS);
|
||||
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);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,45 +1,33 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
* Copyright (C) 2002 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Accept names that are in the accept list and not in the reject list
|
||||
*/
|
||||
extern char filter_accept_reject_list(archive_handle_t *archive_handle)
|
||||
char filter_accept_reject_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
const char *key = archive_handle->file_header->name;
|
||||
const llist_t *accept_entry = find_list_entry(archive_handle->accept, key);
|
||||
const llist_t *reject_entry = find_list_entry(archive_handle->reject, key);
|
||||
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);
|
||||
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 (archive_handle->accept && (accept_entry == NULL)) {
|
||||
return(EXIT_FAILURE);
|
||||
if ((accept_entry == NULL) && archive_handle->accept) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Accepted */
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,30 +1,54 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Copyright (C) 2002 by Glenn McGrath
|
||||
*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern const llist_t *find_list_entry(const llist_t *list, const char *filename)
|
||||
/* 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);
|
||||
return list;
|
||||
}
|
||||
list = list->link;
|
||||
}
|
||||
return(NULL);
|
||||
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,50 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Copyright 2001 Glenn McGrath.
|
||||
*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
char get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
int err;
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
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];
|
||||
} formated;
|
||||
struct {
|
||||
char name[16];
|
||||
char date[12];
|
||||
char uid[6];
|
||||
char gid[6];
|
||||
char mode[8];
|
||||
char size[10];
|
||||
char magic[2];
|
||||
} formatted;
|
||||
} ar;
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned int ar_long_name_size;
|
||||
#endif
|
||||
|
||||
/* dont use bb_xread as we want to handle the error ourself */
|
||||
/* 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);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* ar header starts on an even byte (2 byte aligned)
|
||||
@@ -53,56 +40,64 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
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] = bb_xread_char(archive_handle->src_fd);
|
||||
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.formated.magic[0] != '`') || (ar.formated.magic[1] != '\n')) {
|
||||
bb_error_msg_and_die("Invalid ar header");
|
||||
}
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
typed->mode = strtol(ar.formated.mode, NULL, 8);
|
||||
typed->mtime = atoi(ar.formated.date);
|
||||
typed->uid = atoi(ar.formated.uid);
|
||||
typed->gid = atoi(ar.formated.gid);
|
||||
typed->size = atoi(ar.formated.size);
|
||||
/* 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.formated.name[0] == '/') {
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formated.name[1] == '/') {
|
||||
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);
|
||||
bb_xread_all(archive_handle->src_fd, ar_long_names, ar_long_name_size);
|
||||
xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
|
||||
archive_handle->offset += ar_long_name_size;
|
||||
/* This ar entries data section only contained filenames for other records
|
||||
* they are stored in the static ar_long_names for future reference */
|
||||
return (get_header_ar(archive_handle)); /* Return next header */
|
||||
} else if (ar.formated.name[1] == ' ') {
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
} else 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 */
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
} else {
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
(saved in variable long_name) that conatains the real filename */
|
||||
const unsigned int long_offset = atoi(&ar.formated.name[1]);
|
||||
const unsigned int long_offset = atoi(&ar.formatted.name[1]);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("Cant resolve long filename");
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = bb_xstrdup(ar_long_names + long_offset);
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
}
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
} else {
|
||||
/* short filenames */
|
||||
typed->name = bb_xstrndup(ar.formated.name, 16);
|
||||
typed->name = xstrndup(ar.formatted.name, 16);
|
||||
}
|
||||
|
||||
typed->name[strcspn(typed->name, " /")] = '\0';
|
||||
@@ -122,5 +117,5 @@ extern char get_header_ar(archive_handle_t *archive_handle)
|
||||
/* 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);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,121 +1,129 @@
|
||||
/*
|
||||
* 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.
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* Copyright 2002 Laurence Anderson
|
||||
*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysmacros.h> /* major() and minor() */
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
typedef struct hardlinks_s {
|
||||
file_header_t *entry;
|
||||
char *name;
|
||||
int inode;
|
||||
struct hardlinks_s *next;
|
||||
} hardlinks_t;
|
||||
|
||||
extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
char get_header_cpio(archive_handle_t *archive_handle)
|
||||
{
|
||||
static hardlinks_t *saved_hardlinks = NULL;
|
||||
static unsigned short 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, inode;
|
||||
int major, minor, nlink;
|
||||
|
||||
if (pending_hardlinks) { /* Deal with any pending hardlinks */
|
||||
hardlinks_t *tmp;
|
||||
hardlinks_t *oldtmp;
|
||||
hardlinks_t *tmp, *oldtmp;
|
||||
|
||||
tmp = saved_hardlinks;
|
||||
oldtmp = NULL;
|
||||
|
||||
file_header->link_name = file_header->name;
|
||||
file_header->size = 0;
|
||||
|
||||
while (tmp) {
|
||||
bb_error_msg_and_die("need to fix this\n");
|
||||
if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
|
||||
file_header = tmp->entry;
|
||||
if (oldtmp) {
|
||||
oldtmp->next = tmp->next; /* Remove item from linked list */
|
||||
} else {
|
||||
saved_hardlinks = tmp->next;
|
||||
}
|
||||
free(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;
|
||||
}
|
||||
pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
|
||||
|
||||
file_header->name = file_header->link_name;
|
||||
|
||||
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, cpio_header, 110) == 0) {
|
||||
return(EXIT_FAILURE);
|
||||
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");
|
||||
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",
|
||||
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;
|
||||
file_header->size = tmpsize;
|
||||
}
|
||||
|
||||
file_header->name = (char *) xmalloc(namesize + 1);
|
||||
archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */
|
||||
file_header->name[namesize] = '\0';
|
||||
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) {
|
||||
printf("%d blocks\n", (int) (archive_handle->offset % 512 ? (archive_handle->offset / 512) + 1 : archive_handle->offset / 512)); /* Always round up */
|
||||
/* 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->entry->name);
|
||||
bb_error_msg("%s not created: cannot resolve hardlink", tmp->name);
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free (oldtmp->entry->name);
|
||||
free (oldtmp->entry);
|
||||
free (oldtmp);
|
||||
free(oldtmp->name);
|
||||
free(oldtmp);
|
||||
}
|
||||
saved_hardlinks = NULL;
|
||||
pending_hardlinks = 0;
|
||||
}
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
file_header->link_name = (char *) xmalloc(file_header->size + 1);
|
||||
archive_xread_all(archive_handle, file_header->link_name, file_header->size);
|
||||
file_header->link_name[file_header->size] = '\0';
|
||||
file_header->link_name = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, file_header->link_name, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
file_header->size = 0; /* Stop possible seeks in future */
|
||||
} else {
|
||||
@@ -126,23 +134,14 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
hardlinks_t *new = xmalloc(sizeof(hardlinks_t));
|
||||
new->next = saved_hardlinks;
|
||||
new->inode = inode;
|
||||
new->entry = file_header;
|
||||
/* name current allocated, freed later */
|
||||
new->name = file_header->name;
|
||||
file_header->name = NULL;
|
||||
saved_hardlinks = new;
|
||||
return(EXIT_SUCCESS); // Skip this one
|
||||
} else { /* Found the file with data in */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
pending_hardlinks = 1;
|
||||
while (tmp) {
|
||||
if (tmp->inode == inode) {
|
||||
tmp->entry->link_name = bb_xstrdup(file_header->name);
|
||||
nlink--;
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (nlink > 1) {
|
||||
bb_error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
|
||||
}
|
||||
return EXIT_SUCCESS; /* Skip this one */
|
||||
}
|
||||
/* Found the file with data in */
|
||||
pending_hardlinks = nlink;
|
||||
}
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
@@ -157,5 +156,5 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
|
||||
|
||||
free(file_header->link_name);
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
/* 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
|
||||
@@ -20,133 +8,175 @@
|
||||
* References:
|
||||
* GNU tar and star man pages,
|
||||
* Opengroup's ustar interchange format,
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static char *longname = NULL;
|
||||
static char *linkname = NULL;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
static char *longname;
|
||||
static char *linkname;
|
||||
#else
|
||||
enum {
|
||||
longname = 0,
|
||||
linkname = 0,
|
||||
};
|
||||
#endif
|
||||
|
||||
extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
union {
|
||||
/* ustar header, Posix 1003.1 */
|
||||
unsigned char raw[512];
|
||||
struct {
|
||||
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 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-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 */
|
||||
} formated;
|
||||
} tar;
|
||||
long sum = 0;
|
||||
long i;
|
||||
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)
|
||||
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 int 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 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-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 sum, i;
|
||||
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);
|
||||
|
||||
if (bb_full_read(archive_handle->src_fd, tar.raw, 512) != 512) {
|
||||
/* Assume end of file */
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
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.formated.name[0] == 0) {
|
||||
return(EXIT_SUCCESS);
|
||||
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.formated.magic, "ustar", 5) != 0) {
|
||||
#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
if (strncmp(tar.formated.magic, "\0\0\0\0\0", 5) != 0)
|
||||
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");
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
/* Do checksum on headers */
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum += tar.raw[i];
|
||||
sum = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
sum += ' ' * 8;
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum += tar.raw[i];
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
if (sum != strtol(tar.formated.chksum, NULL, 8)) {
|
||||
bb_error_msg("Invalid tar header checksum");
|
||||
return(EXIT_FAILURE);
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
if (sum != xstrtoul(tar.chksum, 8)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (longname) {
|
||||
file_header->name = longname;
|
||||
longname = NULL;
|
||||
}
|
||||
else if (linkname) {
|
||||
file_header->name = linkname;
|
||||
linkname = NULL;
|
||||
} else
|
||||
#endif
|
||||
if (tar.formated.prefix[0] == 0) {
|
||||
file_header->name = strdup(tar.formated.name);
|
||||
} else {
|
||||
file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name);
|
||||
}
|
||||
|
||||
file_header->uid = strtol(tar.formated.uid, NULL, 8);
|
||||
file_header->gid = strtol(tar.formated.gid, NULL, 8);
|
||||
file_header->size = strtol(tar.formated.size, NULL, 8);
|
||||
file_header->mtime = strtol(tar.formated.mtime, NULL, 8);
|
||||
file_header->link_name = (tar.formated.linkname[0] != '\0') ?
|
||||
bb_xstrdup(tar.formated.linkname) : NULL;
|
||||
file_header->device = makedev(strtol(tar.formated.devmajor, NULL, 8),
|
||||
strtol(tar.formated.devminor, NULL, 8));
|
||||
/* 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_name = 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_name = xstrdup(tar.linkname);
|
||||
/* FIXME: what if we have non-link object with link_name? */
|
||||
/* Will link_name 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 & strtol(tar.formated.mode, NULL, 8);
|
||||
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 */
|
||||
switch (tar.formated.typeflag) {
|
||||
/* (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 'x':
|
||||
case 'g':
|
||||
bb_error_msg_and_die("pax is not tar");
|
||||
break;
|
||||
case '7':
|
||||
/* Reserved for high performance files, treat as normal file */
|
||||
case 0:
|
||||
/* case 0: */
|
||||
case '0':
|
||||
#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATABILITY
|
||||
#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;
|
||||
file_header->mode |= S_IFREG;
|
||||
break;
|
||||
case '2':
|
||||
file_header->mode |= S_IFLNK;
|
||||
@@ -163,53 +193,85 @@ extern char get_header_tar(archive_handle_t *archive_handle)
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
break;
|
||||
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
case 'L': {
|
||||
longname = xmalloc(file_header->size + 1);
|
||||
archive_xread_all(archive_handle, longname, file_header->size);
|
||||
longname[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
return(get_header_tar(archive_handle));
|
||||
}
|
||||
case 'K': {
|
||||
linkname = xmalloc(file_header->size + 1);
|
||||
archive_xread_all(archive_handle, linkname, file_header->size);
|
||||
linkname[file_header->size] = '\0';
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
file_header->name = linkname;
|
||||
return(get_header_tar(archive_handle));
|
||||
}
|
||||
#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 'M': /* Continuation of multi volume archive */
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
bb_error_msg("Ignoring GNU extension type %c", tar.formated.typeflag);
|
||||
#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("Unknown typeflag: 0x%x", tar.formated.typeflag);
|
||||
bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
|
||||
}
|
||||
{ /* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if its a directory */
|
||||
char *tmp = last_char_is(file_header->name, '/');
|
||||
if (tmp) {
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (longname) {
|
||||
file_header->name = longname;
|
||||
longname = NULL;
|
||||
}
|
||||
if (linkname) {
|
||||
file_header->link_name = 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 its 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);
|
||||
archive_handle->passed = llist_add_to(archive_handle->passed, file_header->name);
|
||||
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_name);
|
||||
/* Do not free(file_header->name)! */
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -24,15 +13,15 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -19,24 +8,24 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned char magic[2];
|
||||
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_xread_all(archive_handle, &magic, 2);
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/* 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 "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, unlzma);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void header_list(const file_header_t *file_header)
|
||||
void header_list(const file_header_t *file_header)
|
||||
{
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void header_skip(const file_header_t *file_header)
|
||||
void header_skip(const file_header_t *file_header ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
/* 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"
|
||||
|
||||
extern void header_verbose_list(const file_header_t *file_header)
|
||||
void header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm *mtime = localtime(&file_header->mtime);
|
||||
struct tm *mtime = localtime(&(file_header->mtime));
|
||||
|
||||
printf("%s %d/%d%10u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
file_header->uid,
|
||||
file_header->gid,
|
||||
(unsigned int) file_header->size,
|
||||
file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
|
||||
@@ -1,21 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -23,14 +10,13 @@ archive_handle_t *init_handle(void)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
|
||||
/* Initialise default values */
|
||||
archive_handle = xmalloc(sizeof(archive_handle_t));
|
||||
memset(archive_handle, 0, sizeof(archive_handle_t));
|
||||
archive_handle->file_header = xmalloc(sizeof(file_header_t));
|
||||
/* 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);
|
||||
return archive_handle;
|
||||
}
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -19,33 +8,37 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#include "unarchive.h"
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
extern int open_transformer(int src_fd, int (*transformer)(int src_fd, int dst_fd))
|
||||
int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
|
||||
{
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
|
||||
if (pipe(fd_pipe) != 0) {
|
||||
bb_perror_msg_and_die("Can't create pipe");
|
||||
bb_perror_msg_and_die("can't create pipe");
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
bb_perror_msg_and_die("Fork failed");
|
||||
bb_perror_msg_and_die("fork failed");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
// FIXME: error check?
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
exit(0);
|
||||
/* notreached */
|
||||
exit(0);
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
/* parent process */
|
||||
close(fd_pipe[1]); /* Don't want to write to the child */
|
||||
|
||||
return(fd_pipe[0]);
|
||||
return fd_pipe[0];
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* If we are reading through a pipe(), or from stdin then we cant lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*
|
||||
* TODO: rename to seek_by_read
|
||||
*/
|
||||
extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
if (jump_size) {
|
||||
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -22,14 +11,14 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
extern void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount)
|
||||
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) {
|
||||
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
if (errno == ESPIPE) {
|
||||
seek_by_char(archive_handle, amount);
|
||||
seek_by_read(archive_handle, amount);
|
||||
} else
|
||||
#endif
|
||||
bb_perror_msg_and_die("Seek failure");
|
||||
bb_perror_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "libbb.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_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,20 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
#include "libbb.h"
|
||||
|
||||
extern void unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
void unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
char magic[7];
|
||||
|
||||
archive_xread_all(ar_archive, magic, 7);
|
||||
xread(ar_archive->src_fd, magic, 7);
|
||||
if (strncmp(magic, "!<arch>", 7) != 0) {
|
||||
bb_error_msg_and_die("Invalid ar magic");
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += 7;
|
||||
|
||||
|
||||
+42
-72
@@ -4,31 +4,9 @@
|
||||
*
|
||||
* Copyright (C) 2001,2002 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h> /* For ntohl & htonl function */
|
||||
#include <string.h> /* For strncmp */
|
||||
#include <sys/mman.h> /* For mmap */
|
||||
#include <time.h> /* For ctime */
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -43,7 +21,7 @@
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
|
||||
#define RPMTAG_NAME 1000
|
||||
#define RPMTAG_NAME 1000
|
||||
#define RPMTAG_VERSION 1001
|
||||
#define RPMTAG_RELEASE 1002
|
||||
#define RPMTAG_SUMMARY 1004
|
||||
@@ -92,17 +70,15 @@ static void *map;
|
||||
static rpm_index **mytags;
|
||||
static int tagcount;
|
||||
|
||||
void extract_cpio_gz(int fd);
|
||||
rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
int bsearch_rpmtag(const void *key, const void *item);
|
||||
char *rpm_getstring(int tag, int itemindex);
|
||||
int rpm_getint(int tag, int itemindex);
|
||||
int rpm_getcount(int tag);
|
||||
void exec_script(int progtag, int datatag, char *prefix);
|
||||
void fileaction_dobackup(char *filename, int fileref);
|
||||
void fileaction_setowngrp(char *filename, int fileref);
|
||||
void fileaction_list(char *filename, int itemno);
|
||||
void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
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_getstring(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)
|
||||
{
|
||||
@@ -139,11 +115,11 @@ int rpm_main(int argc, char **argv)
|
||||
|
||||
if (optind == argc) bb_show_usage();
|
||||
while (optind < argc) {
|
||||
rpm_fd = bb_xopen(argv[optind], O_RDONLY);
|
||||
rpm_fd = xopen(argv[optind], O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
|
||||
offset = lseek(rpm_fd, 0, SEEK_CUR);
|
||||
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
|
||||
map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_SHARED, rpm_fd, 0); // Mimimum is one page
|
||||
map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_PRIVATE, rpm_fd, 0); // Mimimum is one page
|
||||
if (func & rpm_install) {
|
||||
loop_through_files(RPMTAG_BASENAMES, fileaction_dobackup); /* Backup any config files */
|
||||
extract_cpio_gz(rpm_fd); // Extact the archive
|
||||
@@ -191,13 +167,13 @@ int rpm_main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void extract_cpio_gz(int fd) {
|
||||
static void extract_cpio_gz(int fd) {
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned char magic[2];
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_char;
|
||||
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;
|
||||
@@ -205,12 +181,12 @@ void extract_cpio_gz(int fd) {
|
||||
archive_handle->src_fd = fd;
|
||||
archive_handle->offset = 0;
|
||||
|
||||
bb_xread_all(archive_handle->src_fd, &magic, 2);
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
chdir("/"); // Install RPM's to root
|
||||
xchdir("/"); // Install RPM's to root
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
@@ -218,9 +194,9 @@ void extract_cpio_gz(int fd) {
|
||||
}
|
||||
|
||||
|
||||
rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
{
|
||||
rpm_index **tags = calloc(200, sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
|
||||
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
|
||||
int pass, tagindex = 0;
|
||||
lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
@@ -243,7 +219,7 @@ rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
storepos = lseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
|
||||
while (header.entries--) {
|
||||
tmpindex = tags[tagindex++] = malloc(sizeof(rpm_index));
|
||||
tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index));
|
||||
read(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);
|
||||
@@ -257,24 +233,25 @@ rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
return tags; /* All done, leave the file at the start of the gzipped cpio archive */
|
||||
}
|
||||
|
||||
int bsearch_rpmtag(const void *key, const void *item)
|
||||
static int bsearch_rpmtag(const void *key, const void *item)
|
||||
{
|
||||
int *tag = (int *)key;
|
||||
rpm_index **tmp = (rpm_index **) item;
|
||||
return ((int) key - tmp[0]->tag);
|
||||
return (*tag - tmp[0]->tag);
|
||||
}
|
||||
|
||||
int rpm_getcount(int tag)
|
||||
static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch((void *) tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found) return 0;
|
||||
else return found[0]->count;
|
||||
}
|
||||
|
||||
char *rpm_getstring(int tag, int itemindex)
|
||||
static char *rpm_getstring(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch((void *) tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count) return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) {
|
||||
int n;
|
||||
@@ -284,11 +261,13 @@ char *rpm_getstring(int tag, int itemindex)
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
int rpm_getint(int tag, int itemindex)
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
int n, *tmpint;
|
||||
found = bsearch((void *) tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
/* 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) {
|
||||
@@ -303,7 +282,7 @@ int rpm_getint(int tag, int itemindex)
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
void fileaction_dobackup(char *filename, int fileref)
|
||||
static void fileaction_dobackup(char *filename, int fileref)
|
||||
{
|
||||
struct stat oldfile;
|
||||
int stat_res;
|
||||
@@ -311,8 +290,7 @@ void fileaction_dobackup(char *filename, int fileref)
|
||||
if (rpm_getint(RPMTAG_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 = bb_xstrdup(filename);
|
||||
newname = strcat(newname, ".rpmorig");
|
||||
newname = xasprintf("%s.rpmorig", filename);
|
||||
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
|
||||
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
|
||||
free(newname);
|
||||
@@ -320,29 +298,21 @@ void fileaction_dobackup(char *filename, int fileref)
|
||||
}
|
||||
}
|
||||
|
||||
void fileaction_setowngrp(char *filename, int fileref)
|
||||
static void fileaction_setowngrp(char *filename, int fileref)
|
||||
{
|
||||
int uid, gid;
|
||||
uid = my_getpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
|
||||
gid = my_getgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
|
||||
chown (filename, uid, gid);
|
||||
uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
|
||||
gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
|
||||
chown(filename, uid, gid);
|
||||
}
|
||||
|
||||
void fileaction_list(char *filename, int fileref)
|
||||
{
|
||||
printf("%s\n", filename);
|
||||
}
|
||||
|
||||
void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
|
||||
{
|
||||
int count = 0;
|
||||
char *filename, *tmp_dirname, *tmp_basename;
|
||||
while (rpm_getstring(filetag, count)) {
|
||||
tmp_dirname = rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, count)); /* 1st put on the directory */
|
||||
tmp_basename = rpm_getstring(RPMTAG_BASENAMES, count);
|
||||
filename = xmalloc(strlen(tmp_basename) + strlen(tmp_dirname) + 1);
|
||||
strcpy(filename, tmp_dirname); /* First the directory name */
|
||||
strcat(filename, tmp_basename); /* then the filename */
|
||||
char * filename = xasprintf("%s%s",
|
||||
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
|
||||
count)), rpm_getstring(RPMTAG_BASENAMES, count));
|
||||
fileaction(filename, count++);
|
||||
free(filename);
|
||||
}
|
||||
|
||||
+13
-30
@@ -4,25 +4,8 @@
|
||||
*
|
||||
* Copyright (C) 2001 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h> /* For ntohl & htonl function */
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -48,16 +31,16 @@ struct rpm_header {
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
};
|
||||
|
||||
void skip_header(int rpm_fd)
|
||||
static void skip_header(int rpm_fd)
|
||||
{
|
||||
struct rpm_header header;
|
||||
|
||||
bb_xread_all(rpm_fd, &header, sizeof(struct rpm_header));
|
||||
xread(rpm_fd, &header, sizeof(struct rpm_header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
|
||||
bb_error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
|
||||
bb_error_msg_and_die("invalid RPM header magic"); /* Invalid magic */
|
||||
}
|
||||
if (header.version != 1) {
|
||||
bb_error_msg_and_die("Unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
}
|
||||
header.entries = ntohl(header.entries);
|
||||
header.size = ntohl(header.size);
|
||||
@@ -66,7 +49,7 @@ void skip_header(int rpm_fd)
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
extern int rpm2cpio_main(int argc, char **argv)
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
int rpm_fd;
|
||||
@@ -75,12 +58,12 @@ extern int rpm2cpio_main(int argc, char **argv)
|
||||
if (argc == 1) {
|
||||
rpm_fd = STDIN_FILENO;
|
||||
} else {
|
||||
rpm_fd = bb_xopen(argv[1], O_RDONLY);
|
||||
rpm_fd = xopen(argv[1], O_RDONLY);
|
||||
}
|
||||
|
||||
bb_xread_all(rpm_fd, &lead, sizeof(struct rpm_lead));
|
||||
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
|
||||
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
|
||||
bb_error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
}
|
||||
|
||||
/* Skip the signature header */
|
||||
@@ -90,14 +73,14 @@ extern int rpm2cpio_main(int argc, char **argv)
|
||||
/* Skip the main header */
|
||||
skip_header(rpm_fd);
|
||||
|
||||
bb_xread_all(rpm_fd, &magic, 2);
|
||||
xread(rpm_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("Invalid gzip magic");
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip(rpm_fd);
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) != 0) {
|
||||
bb_error_msg("Error inflating");
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
close(rpm_fd);
|
||||
|
||||
+477
-472
File diff suppressed because it is too large.
Load diff
+16
-37
@@ -2,45 +2,25 @@
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_TO_STDOUT 1
|
||||
#define GUNZIP_FORCE 2
|
||||
|
||||
extern int uncompress_main(int argc, char **argv)
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned long flags;
|
||||
|
||||
flags = bb_getopt_ulflags(argc, argv, "cf");
|
||||
flags = getopt32(argc, argv, "cf");
|
||||
|
||||
while (optind < argc) {
|
||||
const char *compressed_file = argv[optind++];
|
||||
const char *delete_path = NULL;
|
||||
char *compressed_file = argv[optind++];
|
||||
char *delete_path = NULL;
|
||||
char *uncompressed_file = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
@@ -49,7 +29,7 @@ extern int uncompress_main(int argc, char **argv)
|
||||
src_fd = STDIN_FILENO;
|
||||
flags |= GUNZIP_TO_STDOUT;
|
||||
} else {
|
||||
src_fd = bb_xopen(compressed_file, O_RDONLY);
|
||||
src_fd = xopen(compressed_file, O_RDONLY);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
@@ -65,28 +45,27 @@ extern int uncompress_main(int argc, char **argv)
|
||||
struct stat stat_buf;
|
||||
char *extension;
|
||||
|
||||
uncompressed_file = bb_xstrdup(compressed_file);
|
||||
uncompressed_file = xstrdup(compressed_file);
|
||||
|
||||
extension = strrchr(uncompressed_file, '.');
|
||||
if (!extension || (strcmp(extension, ".Z") != 0)) {
|
||||
bb_error_msg_and_die("Invalid extension");
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
*extension = '\0';
|
||||
|
||||
/* Open output file */
|
||||
dst_fd = bb_xopen(uncompressed_file, O_WRONLY | O_CREAT);
|
||||
|
||||
/* Set permissions on the file */
|
||||
stat(compressed_file, &stat_buf);
|
||||
chmod(uncompressed_file, stat_buf.st_mode);
|
||||
xstat(compressed_file, &stat_buf);
|
||||
dst_fd = xopen3(uncompressed_file,
|
||||
O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = compressed_file;
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if ((bb_xread_char(src_fd) != 0x1f) || (bb_xread_char(src_fd) != 0x9d)) {
|
||||
bb_error_msg_and_die("Invalid magic");
|
||||
if ((xread_char(src_fd) != 0x1f) || (xread_char(src_fd) != 0x9d)) {
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
@@ -105,7 +84,7 @@ extern int uncompress_main(int argc, char **argv)
|
||||
|
||||
/* 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);
|
||||
bb_error_msg_and_die("cannot remove %s", delete_path);
|
||||
}
|
||||
|
||||
free(uncompressed_file);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Why our g[un]zip/bunzip2 are so ugly compared to this beauty? */
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define UNLZMA_OPT_STDOUT 1
|
||||
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, dst_fd;
|
||||
|
||||
opt = getopt32(argc, argv, "c");
|
||||
|
||||
/* Set input filename and number */
|
||||
filename = argv[optind];
|
||||
if (filename && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as lzmacat force the stdout flag */
|
||||
if ((opt & UNLZMA_OPT_STDOUT) || applet_name[4] == 'c')
|
||||
filename = 0;
|
||||
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* bug: char *extension = filename + strlen(filename) - 5; */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".lzma") != 0) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else
|
||||
dst_fd = STDOUT_FILENO;
|
||||
status = unlzma(src_fd, dst_fd);
|
||||
if (filename) {
|
||||
if (status >= 0) /* if success delete src, else delete dst */
|
||||
filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
return (status < 0);
|
||||
}
|
||||
+307
-168
@@ -2,246 +2,385 @@
|
||||
/*
|
||||
* Mini unzip implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Laurence Anderson
|
||||
* Copyright (C) 2004 by Ed Clark
|
||||
*
|
||||
* 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
|
||||
* 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/products/enterprise/white_papers/appnote.txt
|
||||
* http://www.pkware.com/company/standards/appnote/
|
||||
* http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
|
||||
*/
|
||||
|
||||
/* TODO Endian issues, exclude, should we accept input from stdin ? */
|
||||
/* 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 <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define ZIP_FILEHEADER_MAGIC 0x04034b50
|
||||
#define ZIP_CDS_MAGIC 0x02014b50
|
||||
#define ZIP_CDS_END_MAGIC 0x06054b50
|
||||
#define ZIP_DD_MAGIC 0x08074b50
|
||||
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
|
||||
#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
|
||||
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
|
||||
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
|
||||
|
||||
extern unsigned int gunzip_crc;
|
||||
extern unsigned int gunzip_bytes_out;
|
||||
|
||||
static void header_list_unzip(const file_header_t *file_header)
|
||||
{
|
||||
printf(" inflating: %s\n", file_header->name);
|
||||
}
|
||||
typedef union {
|
||||
unsigned char raw[26];
|
||||
struct {
|
||||
unsigned short version; /* 0-1 */
|
||||
unsigned short flags; /* 2-3 */
|
||||
unsigned short method; /* 4-5 */
|
||||
unsigned short modtime; /* 6-7 */
|
||||
unsigned short moddate; /* 8-9 */
|
||||
unsigned int crc32 ATTRIBUTE_PACKED; /* 10-13 */
|
||||
unsigned int cmpsize ATTRIBUTE_PACKED; /* 14-17 */
|
||||
unsigned int ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
|
||||
unsigned short filename_len; /* 22-23 */
|
||||
unsigned short extra_len; /* 24-25 */
|
||||
} formatted ATTRIBUTE_PACKED;
|
||||
} zip_header_t;
|
||||
|
||||
static void header_verbose_list_unzip(const file_header_t *file_header)
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
unsigned int dostime = (unsigned int) file_header->mtime;
|
||||
|
||||
/* can printf arguments cut of the decade component ? */
|
||||
unsigned short year = 1980 + ((dostime & 0xfe000000) >> 25);
|
||||
while (year >= 100) {
|
||||
year -= 100;
|
||||
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
|
||||
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
|
||||
bb_error_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
(unsigned int) file_header->size,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
year,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
file_header->name);
|
||||
}
|
||||
|
||||
extern int unzip_main(int argc, char **argv)
|
||||
static void unzip_create_leading_dirs(char *fn)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[26];
|
||||
struct {
|
||||
unsigned short version; /* 0-1 */
|
||||
unsigned short flags; /* 2-3 */
|
||||
unsigned short method; /* 4-5 */
|
||||
unsigned short modtime; /* 6-7 */
|
||||
unsigned short moddate; /* 8-9 */
|
||||
unsigned int crc32 __attribute__ ((packed)); /* 10-13 */
|
||||
unsigned int cmpsize __attribute__ ((packed));; /* 14-17 */
|
||||
unsigned int ucmpsize __attribute__ ((packed));; /* 18-21 */
|
||||
unsigned short filename_len; /* 22-23 */
|
||||
unsigned short extra_len; /* 24-25 */
|
||||
} formated __attribute__ ((packed));
|
||||
} zip_header;
|
||||
/* 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);
|
||||
}
|
||||
|
||||
archive_handle_t *archive_handle;
|
||||
static int 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_size(src_fd, dst_fd, size) != size)) {
|
||||
bb_error_msg_and_die("cannot complete extraction");
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_init(zip_header->formatted.cmpsize);
|
||||
inflate_unzip(src_fd, dst_fd);
|
||||
inflate_cleanup();
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("invalid compressed data--%s error", "crc");
|
||||
return 1;
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
|
||||
bb_error_msg("invalid compressed data--%s error", "length");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
zip_header_t zip_header;
|
||||
enum {v_silent, v_normal, v_list} verbosity = v_normal;
|
||||
enum {o_prompt, o_never, o_always} overwrite = o_prompt;
|
||||
unsigned int total_size = 0;
|
||||
unsigned int total_entries = 0;
|
||||
int src_fd = -1, dst_fd = -1;
|
||||
char *src_fn = NULL, *dst_fn = NULL;
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
int opt = 0;
|
||||
int failed, i, opt, opt_range = 0, list_header_done = 0;
|
||||
char key_buf[512];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->action_data = NULL;
|
||||
archive_handle->action_header = header_list_unzip;
|
||||
while((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
case 'l': /* List */
|
||||
verbosity = v_list;
|
||||
break;
|
||||
|
||||
while ((opt = getopt(argc, argv, "lnopqd:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'l': /* list */
|
||||
archive_handle->action_header = header_verbose_list_unzip;
|
||||
archive_handle->action_data = data_skip;
|
||||
case 'n': /* Never overwrite existing files */
|
||||
overwrite = o_never;
|
||||
break;
|
||||
case 'n': /* never overwright existing files */
|
||||
|
||||
case 'o': /* Always overwrite existing files */
|
||||
overwrite = o_always;
|
||||
break;
|
||||
case 'o':
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
case 'p': /* Extract files to stdout and fall through to set verbosity */
|
||||
dst_fd = STDOUT_FILENO;
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
verbosity = (verbosity == v_normal) ? v_silent : verbosity;
|
||||
break;
|
||||
case 'p': /* extract files to stdout */
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
|
||||
case 1 : /* The zip file */
|
||||
src_fn = xstrndup(optarg, strlen(optarg)+4);
|
||||
opt_range++;
|
||||
break;
|
||||
case 'q': /* Extract files quietly */
|
||||
archive_handle->action_header = header_skip;
|
||||
break;
|
||||
case 'd': /* Extract files to specified base directory*/
|
||||
base_dir = optarg;
|
||||
break;
|
||||
#if 0
|
||||
case 'x': /* Exclude the specified files */
|
||||
archive_handle->filter = filter_accept_reject_list;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
bb_show_usage();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: /* Include files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zaccept, optarg);
|
||||
|
||||
} else if (opt == 'd') {
|
||||
base_dir = optarg;
|
||||
opt_range += 2;
|
||||
|
||||
} else if (opt == 'x') {
|
||||
opt_range++;
|
||||
|
||||
} else {
|
||||
bb_show_usage();
|
||||
}
|
||||
break;
|
||||
|
||||
case 2 : /* Exclude files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zreject, optarg);
|
||||
|
||||
} else if (opt == 'd') { /* Extract to base directory */
|
||||
base_dir = optarg;
|
||||
opt_range++;
|
||||
|
||||
} else {
|
||||
bb_show_usage();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == optind) {
|
||||
if (src_fn == NULL) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
printf("Archive: %s\n", argv[optind]);
|
||||
if (archive_handle->action_header == header_verbose_list_unzip) {
|
||||
printf(" Length Date Time Name\n");
|
||||
printf(" -------- ---- ---- ----\n");
|
||||
}
|
||||
/* Open input file */
|
||||
if (strcmp("-", src_fn) == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
/* Cannot use prompt mode since zip data is arriving on STDIN */
|
||||
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
|
||||
|
||||
if (*argv[optind] == '-') {
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
} else {
|
||||
archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
|
||||
static const char *const extn[] = {"", ".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("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
|
||||
}
|
||||
}
|
||||
|
||||
if ((base_dir) && (chdir(base_dir))) {
|
||||
bb_perror_msg_and_die("Couldnt chdir");
|
||||
}
|
||||
/* Change dir if necessary */
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
if (verbosity != v_silent)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
|
||||
failed = 0;
|
||||
|
||||
while (1) {
|
||||
unsigned int magic;
|
||||
int dst_fd;
|
||||
|
||||
/* TODO Endian issues */
|
||||
archive_xread_all(archive_handle, &magic, 4);
|
||||
archive_handle->offset += 4;
|
||||
|
||||
/* Check magic number */
|
||||
xread(src_fd, &magic, 4);
|
||||
if (magic == ZIP_CDS_MAGIC) {
|
||||
break;
|
||||
}
|
||||
else if (magic != ZIP_FILEHEADER_MAGIC) {
|
||||
bb_error_msg_and_die("Invlaide zip magic");
|
||||
} else if (magic != ZIP_FILEHEADER_MAGIC) {
|
||||
bb_error_msg_and_die("invalid zip magic %08X", magic);
|
||||
}
|
||||
|
||||
/* Read the file header */
|
||||
archive_xread_all(archive_handle, zip_header.raw, 26);
|
||||
archive_handle->offset += 26;
|
||||
archive_handle->file_header->mode = S_IFREG | 0777;
|
||||
|
||||
if (zip_header.formated.method != 8) {
|
||||
bb_error_msg_and_die("Unsupported compression method %d\n", zip_header.formated.method);
|
||||
xread(src_fd, zip_header.raw, 26);
|
||||
zip_header.formatted.version = SWAP_LE32(zip_header.formatted.version);
|
||||
zip_header.formatted.flags = SWAP_LE32(zip_header.formatted.flags);
|
||||
zip_header.formatted.method = SWAP_LE32(zip_header.formatted.method);
|
||||
zip_header.formatted.modtime = SWAP_LE32(zip_header.formatted.modtime);
|
||||
zip_header.formatted.moddate = SWAP_LE32(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_LE32(zip_header.formatted.filename_len);
|
||||
zip_header.formatted.extra_len = SWAP_LE32(zip_header.formatted.extra_len);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported compression method %d", zip_header.formatted.method);
|
||||
}
|
||||
|
||||
/* Read filename */
|
||||
archive_handle->file_header->name = xmalloc(zip_header.formated.filename_len + 1);
|
||||
archive_xread_all(archive_handle, archive_handle->file_header->name, zip_header.formated.filename_len);
|
||||
archive_handle->offset += zip_header.formated.filename_len;
|
||||
archive_handle->file_header->name[zip_header.formated.filename_len] = '\0';
|
||||
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 bits */
|
||||
archive_handle->file_header->size = zip_header.formated.extra_len;
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += zip_header.formated.extra_len;
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
/* Handle directories */
|
||||
archive_handle->file_header->mode = S_IFREG | 0777;
|
||||
if (last_char_is(archive_handle->file_header->name, '/')) {
|
||||
archive_handle->file_header->mode ^= S_IFREG;
|
||||
archive_handle->file_header->mode |= S_IFDIR;
|
||||
if ((verbosity == v_list) && !list_header_done){
|
||||
printf(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----\n");
|
||||
list_header_done = 1;
|
||||
}
|
||||
|
||||
/* Data section */
|
||||
archive_handle->file_header->size = zip_header.formated.cmpsize;
|
||||
if (archive_handle->action_data) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
} else {
|
||||
dst_fd = bb_xopen(archive_handle->file_header->name, O_WRONLY | O_CREAT);
|
||||
inflate_init(zip_header.formated.cmpsize);
|
||||
inflate_unzip(archive_handle->src_fd, dst_fd);
|
||||
close(dst_fd);
|
||||
chmod(archive_handle->file_header->name, archive_handle->file_header->mode);
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn) ||
|
||||
(zaccept && !find_list_entry(zaccept, dst_fn))) { /* Skip entry */
|
||||
i = 'n';
|
||||
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header.formated.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("Invalid compressed data--crc error");
|
||||
}
|
||||
} else { /* Extract entry */
|
||||
total_size += zip_header.formatted.ucmpsize;
|
||||
|
||||
/* Validate decompression - size */
|
||||
if (gunzip_bytes_out != zip_header.formated.ucmpsize) {
|
||||
bb_error_msg("Invalid compressed data--length error");
|
||||
if (verbosity == v_list) { /* List entry */
|
||||
unsigned int 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_entries++;
|
||||
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 (verbosity == v_normal) {
|
||||
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, 512, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* local file descriptor section */
|
||||
archive_handle->offset += zip_header.formated.cmpsize;
|
||||
/* This ISNT unix time */
|
||||
archive_handle->file_header->mtime = zip_header.formated.modtime | (zip_header.formated.moddate << 16);
|
||||
archive_handle->file_header->size = zip_header.formated.ucmpsize;
|
||||
total_size += archive_handle->file_header->size;
|
||||
total_entries++;
|
||||
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 (verbosity == v_normal) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
|
||||
failed = 1;
|
||||
}
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
}
|
||||
break;
|
||||
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
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, 512, 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.formated.flags & 4) {
|
||||
if (zip_header.formatted.flags & 4) {
|
||||
/* skip over duplicate crc, compressed size and uncompressed size */
|
||||
unsigned char data_description[12];
|
||||
archive_xread_all(archive_handle, data_description, 12);
|
||||
archive_handle->offset += 12;
|
||||
unzip_skip(src_fd, 12);
|
||||
}
|
||||
}
|
||||
/* Central directory section */
|
||||
|
||||
if (archive_handle->action_header == header_verbose_list_unzip) {
|
||||
printf(" -------- -------\n");
|
||||
printf("%9d %d files\n", total_size, total_entries);
|
||||
if (verbosity == v_list) {
|
||||
printf(" -------- -------\n"
|
||||
"%9d %d files\n", total_size, total_entries);
|
||||
}
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
return failed;
|
||||
}
|
||||
+46
-9
@@ -5,64 +5,101 @@
|
||||
|
||||
menu "Console Utilities"
|
||||
|
||||
config CONFIG_CHVT
|
||||
config CHVT
|
||||
bool "chvt"
|
||||
default n
|
||||
help
|
||||
This program is used to change to another terminal.
|
||||
Example: chvt 4 (change to terminal /dev/tty4)
|
||||
|
||||
config CONFIG_CLEAR
|
||||
config CLEAR
|
||||
bool "clear"
|
||||
default n
|
||||
help
|
||||
This program clears the terminal screen.
|
||||
|
||||
config CONFIG_DEALLOCVT
|
||||
config DEALLOCVT
|
||||
bool "deallocvt"
|
||||
default n
|
||||
help
|
||||
This program deallocates unused virtual consoles.
|
||||
|
||||
config CONFIG_DUMPKMAP
|
||||
config DUMPKMAP
|
||||
bool "dumpkmap"
|
||||
default n
|
||||
help
|
||||
This program dumps the kernel's keyboard translation table to
|
||||
stdout, in binary format. You can then use loadkmap to load it.
|
||||
|
||||
config CONFIG_LOADFONT
|
||||
config LOADFONT
|
||||
bool "loadfont"
|
||||
default n
|
||||
help
|
||||
This program loads a console font from standard input.
|
||||
|
||||
config CONFIG_LOADKMAP
|
||||
config LOADKMAP
|
||||
bool "loadkmap"
|
||||
default n
|
||||
help
|
||||
This program loads a keyboard translation table from
|
||||
standard input.
|
||||
|
||||
config CONFIG_OPENVT
|
||||
config OPENVT
|
||||
bool "openvt"
|
||||
default n
|
||||
help
|
||||
This program is used to start a command on an unused
|
||||
virtual terminal.
|
||||
|
||||
config CONFIG_RESET
|
||||
config RESET
|
||||
bool "reset"
|
||||
default n
|
||||
help
|
||||
This program is used to reset the terminal screen, if it
|
||||
gets messed up.
|
||||
|
||||
config CONFIG_SETKEYCODES
|
||||
config RESIZE
|
||||
bool "resize"
|
||||
default n
|
||||
help
|
||||
This program is used to (re)set the width and height of your current
|
||||
terminal.
|
||||
|
||||
config FEATURE_RESIZE_PRINT
|
||||
bool "print environment variables"
|
||||
default n
|
||||
depends on RESIZE
|
||||
help
|
||||
Prints the newly set size (number of columns and rows) of
|
||||
the terminal.
|
||||
E.g.:
|
||||
COLUMNS=80;LINES=44;export COLUMNS LINES;
|
||||
|
||||
config SETCONSOLE
|
||||
bool "setconsole"
|
||||
default n
|
||||
help
|
||||
This program redirects the system console to another device,
|
||||
like the current tty while logged in via telnet.
|
||||
|
||||
config FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on SET_CONSOLE && GETOPT_LONG
|
||||
help
|
||||
Support long options for the setconsole applet.
|
||||
|
||||
config SETKEYCODES
|
||||
bool "setkeycodes"
|
||||
default n
|
||||
help
|
||||
This program loads entries into the kernel's scancode-to-keycode
|
||||
map, allowing unusual keyboards to generate usable keycodes.
|
||||
|
||||
config SETLOGCONS
|
||||
bool "setlogcons"
|
||||
default n
|
||||
help
|
||||
This program redirects the output console of kernel messages.
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,19 @@
|
||||
# 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.
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_CHVT) += chvt.o
|
||||
lib-$(CONFIG_CLEAR) += clear.o
|
||||
lib-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
lib-$(CONFIG_SETCONSOLE) += setconsole.o
|
||||
lib-$(CONFIG_LOADFONT) += loadfont.o
|
||||
lib-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
lib-$(CONFIG_OPENVT) += openvt.o
|
||||
lib-$(CONFIG_RESET) += reset.o
|
||||
lib-$(CONFIG_RESIZE) += resize.o
|
||||
lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
|
||||
lib-$(CONFIG_SETLOGCONS) += setlogcons.o
|
||||
@@ -1,32 +0,0 @@
|
||||
# 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)/console/tools
|
||||
CONSOLETOOLS_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)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# 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
|
||||
#
|
||||
|
||||
CONSOLETOOLS_AR:=console-tools.a
|
||||
ifndef $(CONSOLETOOLS_DIR)
|
||||
CONSOLETOOLS_DIR:=$(top_builddir)/console-tools/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/console-tools
|
||||
|
||||
CONSOLETOOLS_DIR-y:=
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CHVT) += chvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_CLEAR) += clear.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_OPENVT) += openvt.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_RESET) += reset.o
|
||||
CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o
|
||||
|
||||
libraries-y+=$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR)
|
||||
|
||||
$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR): $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y))
|
||||
|
||||
$(CONSOLETOOLS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+9
-37
@@ -4,33 +4,16 @@
|
||||
*
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
static const int VT_ACTIVATE = 0x5606; /* make vt active */
|
||||
static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */
|
||||
enum {
|
||||
VT_ACTIVATE = 0x5606, /* make vt active */
|
||||
VT_WAITACTIVE = 0x5607 /* wait for vt active */
|
||||
};
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
@@ -41,21 +24,10 @@ int chvt_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
fd = get_console_fd();
|
||||
num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
bb_perror_msg_and_die("VT_ACTIVATE");
|
||||
}
|
||||
if (ioctl(fd, VT_WAITACTIVE, num)) {
|
||||
bb_perror_msg_and_die("VT_WAITACTIVE");
|
||||
num = xatoul_range(argv[1], 1, 63);
|
||||
if ((-1 == ioctl(fd, VT_ACTIVATE, num))
|
||||
|| (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
|
||||
bb_perror_msg_and_die("ioctl");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+3
-16
@@ -4,19 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -27,8 +15,7 @@
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
extern int clear_main(int argc, char **argv)
|
||||
int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
return EXIT_SUCCESS;
|
||||
return printf("\033[H\033[J") != 6;
|
||||
}
|
||||
+11
-30
@@ -5,51 +5,32 @@
|
||||
* Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it>
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */
|
||||
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
/* num = 0 deallocate all unused consoles */
|
||||
int num = 0;
|
||||
|
||||
switch(argc)
|
||||
{
|
||||
case 2:
|
||||
if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0)
|
||||
bb_error_msg_and_die("0: illegal VT number");
|
||||
/* Falltrough */
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
switch (argc) {
|
||||
case 2:
|
||||
num = xatoul_range(argv[1], 1, 63);
|
||||
/* Fallthrough */
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (ioctl( get_console_fd(), VT_DISALLOCATE, num )) {
|
||||
if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) {
|
||||
bb_perror_msg_and_die("VT_DISALLOCATE");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
+19
-45
@@ -4,29 +4,10 @@
|
||||
*
|
||||
* Copyright (C) Arne Bernin <arne@matrix.loopback.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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
@@ -35,11 +16,11 @@ struct kbentry {
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
static const int KDGKBENT = 0x4B46; /* gets one entry in translation table */
|
||||
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
static const int NR_KEYS = 128;
|
||||
static const int MAX_NR_KEYMAPS = 256;
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
@@ -47,28 +28,21 @@ int dumpkmap_main(int argc, char **argv)
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
if (argc >= 2 && *argv[1] == '-')
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
fd=bb_xopen(CURRENT_VC, O_RDWR);
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, magic, 7);
|
||||
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
|
||||
flags[0]=1;
|
||||
flags[1]=1;
|
||||
flags[2]=1;
|
||||
flags[4]=1;
|
||||
flags[5]=1;
|
||||
flags[6]=1;
|
||||
flags[8]=1;
|
||||
flags[9]=1;
|
||||
flags[10]=1;
|
||||
flags[12]=1;
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
||||
memset(flags, 0x01, 13);
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
|
||||
/* dump flags */
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
|
||||
write(1, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
@@ -76,13 +50,13 @@ int dumpkmap_main(int argc, char **argv)
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
bb_error_msg("ioctl returned: %m, %s, %s, %xqq", (char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,(void*)&ke.kb_value,2);
|
||||
}
|
||||
|
||||
bb_perror_msg("ioctl failed with %s, %s, %p",
|
||||
(char *)&ke.kb_index,
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value);
|
||||
} else {
|
||||
write(1, (void*)&ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-36
@@ -7,27 +7,18 @@
|
||||
* Loads the console font, and possibly the corresponding screen map(s).
|
||||
* (Adapted for busybox by Matej Vela.)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
#include <endian.h>
|
||||
#include "busybox.h"
|
||||
#include <sys/kd.h>
|
||||
|
||||
static const int PSF_MAGIC1 = 0x36;
|
||||
static const int PSF_MAGIC2 = 0x04;
|
||||
enum {
|
||||
PSF_MAGIC1 = 0x36,
|
||||
PSF_MAGIC2 = 0x04,
|
||||
|
||||
static const int PSF_MODE512 = 0x01;
|
||||
static const int PSF_MODEHASTAB = 0x02;
|
||||
static const int PSF_MAXMODE = 0x03;
|
||||
static const int PSF_SEPARATOR = 0xFFFF;
|
||||
PSF_MODE512 = 0x01,
|
||||
PSF_MODEHASTAB = 0x02,
|
||||
PSF_MAXMODE = 0x03,
|
||||
PSF_SEPARATOR = 0xFFFF
|
||||
};
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
@@ -39,20 +30,20 @@ struct psf_header {
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
extern int loadfont_main(int argc, char **argv)
|
||||
int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = bb_xopen(CURRENT_VC, O_RDWR);
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
loadnewfont(fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
|
||||
{
|
||||
char buf[16384];
|
||||
int i;
|
||||
@@ -60,7 +51,7 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (unit < 1 || unit > 32)
|
||||
bb_error_msg_and_die("Bad character size %d", unit);
|
||||
bb_error_msg_and_die("bad character size %d", unit);
|
||||
|
||||
for (i = 0; i < fontsize; i++)
|
||||
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
|
||||
@@ -117,8 +108,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
#ifdef ENOIOCTLCMD
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
bb_error_msg("It seems this kernel is older than 1.1.92");
|
||||
bb_error_msg_and_die("No Unicode mapping table loaded.");
|
||||
bb_error_msg("it seems this kernel is older than 1.1.92");
|
||||
bb_error_msg_and_die("no Unicode mapping table loaded");
|
||||
} else
|
||||
#endif
|
||||
bb_perror_msg_and_die("PIO_UNIMAPCLR");
|
||||
@@ -126,11 +117,6 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
ud.entry_ct = ct;
|
||||
ud.entries = up;
|
||||
if (ioctl(fd, PIO_UNIMAP, &ud)) {
|
||||
#if 0
|
||||
if (errno == ENOMEM) {
|
||||
/* change advice parameters */
|
||||
}
|
||||
#endif
|
||||
bb_perror_msg_and_die("PIO_UNIMAP");
|
||||
}
|
||||
}
|
||||
@@ -138,7 +124,7 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
static void loadnewfont(int fd)
|
||||
{
|
||||
int unit;
|
||||
char inbuf[32768]; /* primitive */
|
||||
unsigned char inbuf[32768]; /* primitive */
|
||||
unsigned int inputlth, offset;
|
||||
|
||||
/*
|
||||
@@ -148,13 +134,13 @@ static void loadnewfont(int fd)
|
||||
*/
|
||||
inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
|
||||
if (ferror(stdin))
|
||||
bb_perror_msg_and_die("Error reading input font");
|
||||
bb_perror_msg_and_die("error reading input font");
|
||||
/* use malloc/realloc in case of giant files;
|
||||
maybe these do not occur: 16kB for the font,
|
||||
and 16kB for the map leaves 32 unicode values
|
||||
for each font position */
|
||||
if (!feof(stdin))
|
||||
bb_perror_msg_and_die("Font too large");
|
||||
bb_perror_msg_and_die("font too large");
|
||||
|
||||
/* test for psf first */
|
||||
{
|
||||
@@ -172,11 +158,11 @@ static void loadnewfont(int fd)
|
||||
goto no_psf;
|
||||
|
||||
if (psfhdr.mode > PSF_MAXMODE)
|
||||
bb_error_msg_and_die("Unsupported psf file mode");
|
||||
bb_error_msg_and_die("unsupported psf file mode");
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
#if !defined( PIO_FONTX ) || defined( __sparc__ )
|
||||
if (fontsize != 256)
|
||||
bb_error_msg_and_die("Only fontsize 256 supported");
|
||||
bb_error_msg_and_die("only fontsize 256 supported");
|
||||
#endif
|
||||
hastable = (psfhdr.mode & PSF_MODEHASTAB);
|
||||
unit = psfhdr.charsize;
|
||||
@@ -184,7 +170,7 @@ static void loadnewfont(int fd)
|
||||
|
||||
head = head0 + fontsize * unit;
|
||||
if (head > inputlth || (!hastable && head != inputlth))
|
||||
bb_error_msg_and_die("Input file: bad length");
|
||||
bb_error_msg_and_die("input file: bad length");
|
||||
do_loadfont(fd, inbuf + head0, unit, fontsize);
|
||||
if (hastable)
|
||||
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
|
||||
@@ -199,7 +185,7 @@ static void loadnewfont(int fd)
|
||||
} else {
|
||||
/* bare font */
|
||||
if (inputlth & 0377)
|
||||
bb_error_msg_and_die("Bad input file size");
|
||||
bb_error_msg_and_die("bad input file size");
|
||||
offset = 0;
|
||||
unit = inputlth / 256;
|
||||
}
|
||||
|
||||
@@ -4,29 +4,10 @@
|
||||
*
|
||||
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
|
||||
*
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
||||
@@ -55,17 +36,17 @@ int loadkmap_main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = bb_xopen(CURRENT_VC, O_RDWR);
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
if ((bb_full_read(0, buff, 7) != 7) || (strncmp(buff, BINARY_KEYMAP_MAGIC, 7) != 0))
|
||||
bb_error_msg_and_die("This is not a valid binary keymap.");
|
||||
xread(0, buff, 7);
|
||||
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
||||
bb_error_msg_and_die("this is not a valid binary keymap");
|
||||
|
||||
if (bb_full_read(0, flags, MAX_NR_KEYMAPS) != MAX_NR_KEYMAPS)
|
||||
bb_perror_msg_and_die("Error reading keymap flags");
|
||||
xread(0, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
bb_full_read(0, ibuff, NR_KEYS * sizeof(u_short));
|
||||
xread(0, ibuff, NR_KEYS * sizeof(u_short));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
@@ -75,8 +56,6 @@ int loadkmap_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
return EXIT_SUCCESS;
|
||||
if (ENABLE_FEATURE_CLEAN_UP) close(fd);
|
||||
return 0;
|
||||
}
|
||||
+13
-52
@@ -5,80 +5,41 @@
|
||||
* busyboxed by Quy Tonthat <quy@signal3.com>
|
||||
* hacked by Tito <farmatito@tiscali.it>
|
||||
*
|
||||
* 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.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
char vtname[sizeof VC_FORMAT + 2];
|
||||
char vtname[sizeof(VC_FORMAT) + 2];
|
||||
|
||||
|
||||
if (argc < 3)
|
||||
bb_show_usage();
|
||||
if (argc < 3) {
|
||||
bb_show_usage();
|
||||
}
|
||||
/* check for illegal vt number: < 1 or > 63 */
|
||||
sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63));
|
||||
|
||||
/* check for Illegal vt number: < 1 or > 12 */
|
||||
sprintf(vtname, VC_FORMAT,(int)bb_xgetlarg(argv[1], 10, 1, 12));
|
||||
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
|
||||
if(fork() == 0) {
|
||||
if (fork() == 0) {
|
||||
/* leave current vt */
|
||||
|
||||
#ifdef ESIX_5_3_2_D
|
||||
if (setpgrp() < 0) {
|
||||
#else
|
||||
if (setsid() < 0) {
|
||||
#endif
|
||||
|
||||
bb_perror_msg_and_die("Unable to set new session");
|
||||
bb_perror_msg_and_die("setsid");
|
||||
}
|
||||
close(0); /* so that new vt becomes stdin */
|
||||
|
||||
/* and grab new one */
|
||||
fd = bb_xopen(vtname, O_RDWR);
|
||||
fd = xopen(vtname, O_RDWR);
|
||||
|
||||
/* Reassign stdout and sterr */
|
||||
close(1);
|
||||
close(2);
|
||||
dup(fd);
|
||||
dup(fd);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
|
||||
execvp(argv[0], argv);
|
||||
execvp(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+4
-17
@@ -5,20 +5,7 @@
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
@@ -28,14 +15,14 @@
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int reset_main(int argc, char **argv)
|
||||
int reset_main(int argc, char **argv)
|
||||
{
|
||||
if (isatty(0) || isatty(0) || isatty(0)) {
|
||||
if (isatty(1)) {
|
||||
/* See 'man 4 console_codes' for details:
|
||||
* "ESC c" -- Reset
|
||||
* "ESC ( K" -- Select user mapping
|
||||
* "ESC [ J" -- Erase display
|
||||
* "ESC [ 0 m" -- Reset all Graphics Rendition display attributes
|
||||
* "ESC [ 0 m" -- Reset all display attributes
|
||||
* "ESC [ ? 25 h" -- Make cursor visible.
|
||||
*/
|
||||
printf("\033c\033(K\033[J\033[0m\033[?25h");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* resize - set terminal width and height.
|
||||
*
|
||||
* Copyright 2006 Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
/* no options, no getopt */
|
||||
#include "busybox.h"
|
||||
|
||||
int resize_main(int argc, char **argv)
|
||||
{
|
||||
struct termios old, new;
|
||||
struct winsize w = {0,0,0,0};
|
||||
int ret;
|
||||
|
||||
tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */
|
||||
new = old;
|
||||
new.c_cflag |= (CLOCAL | CREAD);
|
||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &new);
|
||||
/* save_cursor_pos 7
|
||||
* scroll_whole_screen [r
|
||||
* put_cursor_waaaay_off [$x;$yH
|
||||
* get_cursor_pos [6n
|
||||
* restore_cursor_pos 8
|
||||
*/
|
||||
printf("\0337\033[r\033[999;999H\033[6n");
|
||||
scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col);
|
||||
ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);
|
||||
printf("\0338");
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &old);
|
||||
if (ENABLE_FEATURE_RESIZE_PRINT)
|
||||
printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
|
||||
w.ws_col, w.ws_row);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* setconsole.c - redirect system console output
|
||||
*
|
||||
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
static const struct option setconsole_long_options[] = {
|
||||
{ "reset", 0, NULL, 'r' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
#define OPT_SETCONS_RESET 1
|
||||
|
||||
int setconsole_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
const char *device = CURRENT_TTY;
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
applet_long_options = setconsole_long_options;
|
||||
#endif
|
||||
flags = getopt32(argc, argv, "r");
|
||||
|
||||
if (argc - optind > 1)
|
||||
bb_show_usage();
|
||||
|
||||
if (argc - optind == 1) {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
bb_show_usage();
|
||||
device = argv[optind];
|
||||
} else {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
device = CONSOLE_DEV;
|
||||
}
|
||||
|
||||
if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
|
||||
bb_perror_msg_and_die("TIOCCONS");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+21
-40
@@ -6,20 +6,7 @@
|
||||
*
|
||||
* Adjusted for BusyBox 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
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -33,40 +20,34 @@
|
||||
struct kbkeycode {
|
||||
unsigned int scancode, keycode;
|
||||
};
|
||||
static const int KDSETKEYCODE = 0x4B4D; /* write kernel keycode table entry */
|
||||
enum {
|
||||
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
|
||||
};
|
||||
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
char *ep;
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
|
||||
if (argc % 2 != 1 || argc < 2) {
|
||||
bb_show_usage();
|
||||
if (argc % 2 != 1 || argc < 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
|
||||
fd = get_console_fd();
|
||||
|
||||
while (argc > 2) {
|
||||
a.keycode = atoi(argv[2]);
|
||||
a.scancode = sc = strtol(argv[1], &ep, 16);
|
||||
if (*ep) {
|
||||
bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]);
|
||||
while (argc > 2) {
|
||||
a.keycode = xatoul_range(argv[2], 0, 127);
|
||||
a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
|
||||
if (a.scancode > 127) {
|
||||
a.scancode -= 0xe000;
|
||||
a.scancode += 128;
|
||||
}
|
||||
if (ioctl(fd, KDSETKEYCODE, &a)) {
|
||||
bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
if (a.scancode > 127) {
|
||||
a.scancode -= 0xe000;
|
||||
a.scancode += 128;
|
||||
}
|
||||
if (a.scancode > 255 || a.keycode > 127) {
|
||||
bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds");
|
||||
}
|
||||
if (ioctl(fd,KDSETKEYCODE,&a)) {
|
||||
perror("KDSETKEYCODE");
|
||||
bb_error_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* setlogcons: Send kernel messages to the current console or to console N
|
||||
*
|
||||
* Copyright (C) 2006 by Jan Kiszka <jan.kiszka@web.de>
|
||||
*
|
||||
* Based on setlogcons (kbd-1.12) by Andries E. Brouwer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
extern int setlogcons_main(int argc, char **argv)
|
||||
{
|
||||
struct {
|
||||
char fn;
|
||||
char subarg;
|
||||
} arg;
|
||||
|
||||
arg.fn = 11; /* redirect kernel messages */
|
||||
arg.subarg = 0; /* to specified console (current as default) */
|
||||
|
||||
if (argc == 2)
|
||||
arg.subarg = xatoul_range(argv[1], 0, 63);
|
||||
|
||||
if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
|
||||
bb_perror_msg_and_die("TIOCLINUX");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+354
-185
@@ -5,7 +5,7 @@
|
||||
|
||||
menu "Coreutils"
|
||||
|
||||
config CONFIG_BASENAME
|
||||
config BASENAME
|
||||
bool "basename"
|
||||
default n
|
||||
help
|
||||
@@ -13,89 +13,101 @@ config CONFIG_BASENAME
|
||||
leaving just the filename itself. Enable this option if you wish
|
||||
to enable the 'basename' utility.
|
||||
|
||||
config CONFIG_CAL
|
||||
config CAL
|
||||
bool "cal"
|
||||
default n
|
||||
help
|
||||
cal is used to display a monthly calender.
|
||||
|
||||
config CONFIG_CAT
|
||||
config CAT
|
||||
bool "cat"
|
||||
default n
|
||||
help
|
||||
cat is used to concatenate files and print them to the standard
|
||||
output. Enable this option if you wish to enable the 'cat' utility.
|
||||
|
||||
config CONFIG_CHGRP
|
||||
config CATV
|
||||
bool "catv"
|
||||
default n
|
||||
help
|
||||
Display nonprinting characters as escape sequences (like some
|
||||
implementations' cat -v option).
|
||||
|
||||
config CHGRP
|
||||
bool "chgrp"
|
||||
default n
|
||||
help
|
||||
chgrp is used to change the group ownership of files.
|
||||
|
||||
config CONFIG_CHMOD
|
||||
config CHMOD
|
||||
bool "chmod"
|
||||
default n
|
||||
help
|
||||
chmod is used to change the access permission of files.
|
||||
|
||||
config CONFIG_CHOWN
|
||||
config CHOWN
|
||||
bool "chown"
|
||||
default n
|
||||
help
|
||||
chown is used to change the user and/or group ownership
|
||||
of files.
|
||||
|
||||
config CONFIG_CHROOT
|
||||
config CHROOT
|
||||
bool "chroot"
|
||||
default n
|
||||
help
|
||||
chroot is used to change the root directory and run a command.
|
||||
The default command is `/bin/sh'.
|
||||
|
||||
config CONFIG_CMP
|
||||
config CKSUM
|
||||
bool "cksum"
|
||||
default n
|
||||
help
|
||||
cksum is used to calculate the CRC32 checksum of a file.
|
||||
|
||||
config CMP
|
||||
bool "cmp"
|
||||
default n
|
||||
help
|
||||
cmp is used to compare two files and returns the result
|
||||
to standard output.
|
||||
|
||||
config CONFIG_CP
|
||||
config COMM
|
||||
bool "comm"
|
||||
default n
|
||||
help
|
||||
comm is used to compare two files line by line and return
|
||||
a three-column output.
|
||||
|
||||
config CP
|
||||
bool "cp"
|
||||
default n
|
||||
help
|
||||
cp is used to copy files and directories.
|
||||
|
||||
config CONFIG_CUT
|
||||
config CUT
|
||||
bool "cut"
|
||||
default n
|
||||
help
|
||||
cut is used to print selected parts of lines from
|
||||
each file to stdout.
|
||||
|
||||
if CONFIG_WATCH
|
||||
config CONFIG_DATE
|
||||
default y
|
||||
comment "date (forced enabled for use with watch)"
|
||||
endif
|
||||
config DATE
|
||||
bool "date"
|
||||
default n
|
||||
help
|
||||
date is used to set the system date or display the
|
||||
current time in the given format.
|
||||
|
||||
if !CONFIG_WATCH
|
||||
config CONFIG_DATE
|
||||
bool "date"
|
||||
default n
|
||||
help
|
||||
date is used to set the system date or display the
|
||||
current time in the given format.
|
||||
endif
|
||||
|
||||
config CONFIG_FEATURE_DATE_ISOFMT
|
||||
bool " Enable ISO date format output (-I)"
|
||||
config FEATURE_DATE_ISOFMT
|
||||
bool "Enable ISO date format output (-I)"
|
||||
default y
|
||||
depends on CONFIG_DATE
|
||||
depends on DATE
|
||||
help
|
||||
Enable option (-I) to output an ISO-8601 compliant
|
||||
date/time string.
|
||||
|
||||
config CONFIG_DD
|
||||
config DD
|
||||
bool "dd"
|
||||
default n
|
||||
help
|
||||
@@ -103,60 +115,116 @@ config CONFIG_DD
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
|
||||
config CONFIG_DF
|
||||
config FEATURE_DD_SIGNAL_HANDLING
|
||||
bool "Enable DD signal handling for status reporting"
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null& pid=$! $ kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in 10899206+0 records out
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
default n
|
||||
depends on DD
|
||||
help
|
||||
Enables support for writing a certain number of bytes in and out,
|
||||
at a time, and performing conversions on the data stream.
|
||||
|
||||
config DF
|
||||
bool "df"
|
||||
default n
|
||||
help
|
||||
df reports the amount of disk space used and available
|
||||
on filesystems.
|
||||
|
||||
config CONFIG_DIRNAME
|
||||
config DIFF
|
||||
bool "diff"
|
||||
default n
|
||||
help
|
||||
diff compares two files or directories and outputs the
|
||||
differences between them in a form that can be given to
|
||||
the patch command.
|
||||
|
||||
config FEATURE_DIFF_BINARY
|
||||
bool "Enable checks for binary files"
|
||||
default y
|
||||
depends on DIFF
|
||||
help
|
||||
This option enables support for checking for binary files
|
||||
before a comparison is carried out.
|
||||
|
||||
config FEATURE_DIFF_DIR
|
||||
bool "Enable directory support"
|
||||
default y
|
||||
depends on DIFF
|
||||
help
|
||||
This option enables support for directory and subdirectory
|
||||
comparison.
|
||||
|
||||
config FEATURE_DIFF_MINIMAL
|
||||
bool "Enable -d option to find smaller sets of changes"
|
||||
default n
|
||||
depends on DIFF
|
||||
help
|
||||
Enabling this option allows the use of -d to make diff
|
||||
try hard to find the smallest possible set of changes.
|
||||
|
||||
config DIRNAME
|
||||
bool "dirname"
|
||||
default n
|
||||
help
|
||||
dirname is used to strip a non-directory suffix from
|
||||
a file name.
|
||||
|
||||
config CONFIG_DOS2UNIX
|
||||
config DOS2UNIX
|
||||
bool "dos2unix/unix2dos"
|
||||
default n
|
||||
help
|
||||
dos2unix is used to convert a text file from DOS format to
|
||||
UNIX format, and vice versa.
|
||||
|
||||
config CONFIG_UNIX2DOS
|
||||
config UNIX2DOS
|
||||
bool
|
||||
default y
|
||||
depends on CONFIG_DOS2UNIX
|
||||
depends on DOS2UNIX
|
||||
help
|
||||
unix2dos is used to convert a text file from UNIX format to
|
||||
DOS format, and vice versa.
|
||||
|
||||
config CONFIG_DU
|
||||
config DU
|
||||
bool "du (default blocksize of 512 bytes)"
|
||||
default n
|
||||
help
|
||||
du is used to report the amount of disk space used
|
||||
for specified files.
|
||||
|
||||
config CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
|
||||
bool " Use a default blocksize of 1024 bytes (1K)"
|
||||
config FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
bool "Use a default blocksize of 1024 bytes (1K)"
|
||||
default y
|
||||
depends on CONFIG_DU
|
||||
depends on DU
|
||||
help
|
||||
Use a blocksize of (1K) instead of the default 512b.
|
||||
|
||||
config CONFIG_ECHO
|
||||
bool "echo (basic SUSv3 version taking no options)"
|
||||
config ECHO
|
||||
bool "echo (basic SuSv3 version taking no options)"
|
||||
default n
|
||||
help
|
||||
echo is used to print a specified string to stdout.
|
||||
|
||||
config CONFIG_FEATURE_FANCY_ECHO
|
||||
bool " Enable echo options (-n and -e)"
|
||||
# this entry also appears in shell/Config.in, next to the echo builtin
|
||||
config FEATURE_FANCY_ECHO
|
||||
bool "Enable echo options (-n and -e)"
|
||||
default y
|
||||
depends on CONFIG_ECHO
|
||||
depends on ECHO
|
||||
help
|
||||
This adds options (-n and -e) to echo.
|
||||
|
||||
config CONFIG_ENV
|
||||
config ENV
|
||||
bool "env"
|
||||
default n
|
||||
help
|
||||
@@ -164,399 +232,500 @@ config CONFIG_ENV
|
||||
a command; without options it displays the current
|
||||
environment.
|
||||
|
||||
config CONFIG_EXPR
|
||||
config FEATURE_ENV_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on ENV && GETOPT_LONG
|
||||
help
|
||||
Support long options for the env applet.
|
||||
|
||||
config EXPR
|
||||
bool "expr"
|
||||
default n
|
||||
help
|
||||
expr is used to calculate numbers and print the result
|
||||
to standard output.
|
||||
|
||||
if CONFIG_HUSH || CONFIG_LASH || CONFIG_MSH
|
||||
config CONFIG_FALSE
|
||||
default y
|
||||
comment "false (forced enabled for use with shell)"
|
||||
endif
|
||||
config EXPR_MATH_SUPPORT_64
|
||||
bool "Extend Posix numbers support to 64 bit"
|
||||
default n
|
||||
depends on EXPR
|
||||
help
|
||||
Enable 64-bit math support in the expr applet. This will make
|
||||
the applet slightly larger, but will allow computation with very
|
||||
large numbers.
|
||||
|
||||
if !CONFIG_HUSH && !CONFIG_LASH && !CONFIG_MSH
|
||||
config CONFIG_FALSE
|
||||
bool "false"
|
||||
default n
|
||||
help
|
||||
false returns an exit code of FALSE (1).
|
||||
endif
|
||||
config FALSE
|
||||
bool "false"
|
||||
default n
|
||||
help
|
||||
false returns an exit code of FALSE (1).
|
||||
|
||||
config CONFIG_FOLD
|
||||
config FOLD
|
||||
bool "fold"
|
||||
default n
|
||||
help
|
||||
Wrap text to fit a specific width.
|
||||
|
||||
config CONFIG_HEAD
|
||||
config HEAD
|
||||
bool "head"
|
||||
default n
|
||||
help
|
||||
head is used to print the first specified number of lines
|
||||
from files.
|
||||
|
||||
config CONFIG_FEATURE_FANCY_HEAD
|
||||
bool " Enable head options (-c, -q, and -v)"
|
||||
config FEATURE_FANCY_HEAD
|
||||
bool "Enable head options (-c, -q, and -v)"
|
||||
default n
|
||||
depends on CONFIG_HEAD
|
||||
depends on HEAD
|
||||
help
|
||||
This enables the head options (-c, -q, and -v).
|
||||
|
||||
config CONFIG_HOSTID
|
||||
config HOSTID
|
||||
bool "hostid"
|
||||
default n
|
||||
help
|
||||
hostid prints the numeric identifier (in hexadecimal) for
|
||||
the current host.
|
||||
|
||||
config CONFIG_ID
|
||||
config ID
|
||||
bool "id"
|
||||
default n
|
||||
help
|
||||
id displays the current user and group ID names.
|
||||
|
||||
config CONFIG_INSTALL
|
||||
config INSTALL
|
||||
bool "install"
|
||||
default n
|
||||
help
|
||||
Copy files and set attributes.
|
||||
|
||||
config CONFIG_LENGTH
|
||||
config FEATURE_INSTALL_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on INSTALL && GETOPT_LONG
|
||||
help
|
||||
Support long options for the install applet.
|
||||
|
||||
config LENGTH
|
||||
bool "length"
|
||||
default n
|
||||
help
|
||||
length is used to print out the length of a specified string.
|
||||
|
||||
config CONFIG_LN
|
||||
config LN
|
||||
bool "ln"
|
||||
default n
|
||||
help
|
||||
ln is used to create hard or soft links between files.
|
||||
|
||||
config CONFIG_LOGNAME
|
||||
config LOGNAME
|
||||
bool "logname"
|
||||
default n
|
||||
help
|
||||
logname is used to print the current user's login name.
|
||||
|
||||
config CONFIG_LS
|
||||
config LS
|
||||
bool "ls"
|
||||
default n
|
||||
help
|
||||
ls is used to list the contents of directories.
|
||||
|
||||
config CONFIG_FEATURE_LS_FILETYPES
|
||||
bool " Enable filetyping options (-p and -F)"
|
||||
config FEATURE_LS_FILETYPES
|
||||
bool "Enable filetyping options (-p and -F)"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Enable the ls options (-p and -F).
|
||||
|
||||
config CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||
bool " Enable symlinks dereferencing (-L)"
|
||||
config FEATURE_LS_FOLLOWLINKS
|
||||
bool "Enable symlinks dereferencing (-L)"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Enable the ls option (-L).
|
||||
|
||||
config CONFIG_FEATURE_LS_RECURSIVE
|
||||
bool " Enable recursion (-R)"
|
||||
config FEATURE_LS_RECURSIVE
|
||||
bool "Enable recursion (-R)"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Enable the ls option (-R).
|
||||
|
||||
config CONFIG_FEATURE_LS_SORTFILES
|
||||
bool " Sort the file names"
|
||||
config FEATURE_LS_SORTFILES
|
||||
bool "Sort the file names"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Allow ls to sort file names alphabetically.
|
||||
|
||||
config CONFIG_FEATURE_LS_TIMESTAMPS
|
||||
bool " Show file timestamps"
|
||||
config FEATURE_LS_TIMESTAMPS
|
||||
bool "Show file timestamps"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Allow ls to display timestamps for files.
|
||||
|
||||
config CONFIG_FEATURE_LS_USERNAME
|
||||
bool " Show username/groupnames"
|
||||
config FEATURE_LS_USERNAME
|
||||
bool "Show username/groupnames"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS
|
||||
help
|
||||
Allow ls to display username/groupname for files.
|
||||
|
||||
config CONFIG_FEATURE_LS_COLOR
|
||||
bool " Use color to identify file types"
|
||||
config FEATURE_LS_COLOR
|
||||
bool "Allow use of color to identify file types"
|
||||
default y
|
||||
depends on CONFIG_LS
|
||||
depends on LS && GETOPT_LONG
|
||||
help
|
||||
Allow ls to use color when displaying files.
|
||||
This enables the --color option to ls.
|
||||
|
||||
config CONFIG_MD5SUM
|
||||
config FEATURE_LS_COLOR_IS_DEFAULT
|
||||
bool "Produce colored ls output by default"
|
||||
default n
|
||||
depends on FEATURE_LS_COLOR
|
||||
help
|
||||
Saying yes here will turn coloring on by default,
|
||||
even if no "--color" option is given to the ls command.
|
||||
This is not recommended, since the colors are not
|
||||
configurable, and the output may not be legible on
|
||||
many output screens.
|
||||
|
||||
config MD5SUM
|
||||
bool "md5sum"
|
||||
default n
|
||||
help
|
||||
md5sum is used to print or check MD5 checksums.
|
||||
|
||||
config CONFIG_MKDIR
|
||||
config MKDIR
|
||||
bool "mkdir"
|
||||
default n
|
||||
help
|
||||
mkdir is used to create directories with the specified names.
|
||||
|
||||
config CONFIG_MKFIFO
|
||||
config FEATURE_MKDIR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on MKDIR && GETOPT_LONG
|
||||
help
|
||||
Support long options for the mkdir applet.
|
||||
|
||||
config MKFIFO
|
||||
bool "mkfifo"
|
||||
default n
|
||||
help
|
||||
mkfifo is used to create FIFOs (named pipes).
|
||||
The `mknod' program can also create FIFOs.
|
||||
|
||||
config CONFIG_MKNOD
|
||||
config MKNOD
|
||||
bool "mknod"
|
||||
default n
|
||||
help
|
||||
mknod is used to create FIFOs or block/character special
|
||||
files with the specified names.
|
||||
|
||||
config CONFIG_MV
|
||||
config MV
|
||||
bool "mv"
|
||||
default n
|
||||
help
|
||||
mv is used to move or rename files or directories.
|
||||
|
||||
config CONFIG_OD
|
||||
config FEATURE_MV_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on MV && GETOPT_LONG
|
||||
help
|
||||
Support long options for the mv applet.
|
||||
|
||||
config NICE
|
||||
bool "nice"
|
||||
default n
|
||||
help
|
||||
nice runs a program with modified scheduling priority.
|
||||
|
||||
config NOHUP
|
||||
bool "nohup"
|
||||
default n
|
||||
help
|
||||
run a command immune to hangups, with output to a non-tty.
|
||||
|
||||
config OD
|
||||
bool "od"
|
||||
default n
|
||||
help
|
||||
od is used to dump binary files in octal and other formats.
|
||||
|
||||
config CONFIG_PRINTF
|
||||
config PRINTENV
|
||||
bool "printenv"
|
||||
default n
|
||||
help
|
||||
printenv is used to print all or part of environment.
|
||||
|
||||
config PRINTF
|
||||
bool "printf"
|
||||
default n
|
||||
help
|
||||
printf is used to format and print specified strings.
|
||||
It's similar to `echo' except it has more options.
|
||||
|
||||
config CONFIG_PWD
|
||||
config PWD
|
||||
bool "pwd"
|
||||
default n
|
||||
help
|
||||
pwd is used to print the current directory.
|
||||
|
||||
config CONFIG_REALPATH
|
||||
config REALPATH
|
||||
bool "realpath"
|
||||
default n
|
||||
help
|
||||
Return the canonicalized absolute pathname.
|
||||
This isn't provided by GNU shellutils, but where else does it belong.
|
||||
|
||||
config CONFIG_RM
|
||||
config RM
|
||||
bool "rm"
|
||||
default n
|
||||
help
|
||||
rm is used to remove files or directories.
|
||||
|
||||
config CONFIG_RMDIR
|
||||
config RMDIR
|
||||
bool "rmdir"
|
||||
default n
|
||||
help
|
||||
rmdir is used to remove empty directories.
|
||||
|
||||
config CONFIG_SEQ
|
||||
config SEQ
|
||||
bool "seq"
|
||||
default n
|
||||
help
|
||||
print a sequence of numbers
|
||||
|
||||
config CONFIG_SHA1SUM
|
||||
config SHA1SUM
|
||||
bool "sha1sum"
|
||||
default n
|
||||
help
|
||||
Compute and check SHA1 message digest
|
||||
|
||||
config CONFIG_SLEEP
|
||||
config SLEEP
|
||||
bool "sleep (single integer arg with no suffix)"
|
||||
default n
|
||||
help
|
||||
sleep is used to pause for a specified number of seconds,
|
||||
|
||||
config CONFIG_FEATURE_FANCY_SLEEP
|
||||
bool " Enable multiple integer args and optional time suffixes"
|
||||
config FEATURE_FANCY_SLEEP
|
||||
bool "Enable multiple integer args and optional time suffixes"
|
||||
default n
|
||||
depends on CONFIG_SLEEP
|
||||
depends on SLEEP
|
||||
help
|
||||
Allow sleep to pause for specified minutes, hours, and days.
|
||||
|
||||
config CONFIG_SORT
|
||||
config SORT
|
||||
bool "sort"
|
||||
default n
|
||||
help
|
||||
sort is used to sort lines of text in specified files.
|
||||
|
||||
config CONFIG_STTY
|
||||
config FEATURE_SORT_BIG
|
||||
bool "full SuSv3 compliant sort (Support -ktcsbdfiozgM)"
|
||||
default y
|
||||
depends on SORT
|
||||
help
|
||||
Without this, sort only supports -r, -u, and an integer version
|
||||
of -n. Selecting this adds sort keys, floating point support, and
|
||||
more. This adds a little over 3k to a nonstatic build on x86.
|
||||
|
||||
The SuSv3 sort standard is available at:
|
||||
http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
|
||||
|
||||
config STAT
|
||||
bool "stat"
|
||||
default n
|
||||
help
|
||||
display file or filesystem status.
|
||||
|
||||
config FEATURE_STAT_FORMAT
|
||||
bool "Enable custom formats (-c)"
|
||||
default n
|
||||
depends on STAT
|
||||
help
|
||||
Without this, stat will not support the '-c format' option where
|
||||
users can pass a custom format string for output. This adds about
|
||||
7k to a nonstatic build on amd64.
|
||||
|
||||
config STTY
|
||||
bool "stty"
|
||||
default n
|
||||
help
|
||||
stty is used to change and print terminal line settings.
|
||||
|
||||
config CONFIG_SYNC
|
||||
config SUM
|
||||
bool "sum"
|
||||
default n
|
||||
help
|
||||
checksum and count the blocks in a file
|
||||
|
||||
config SYNC
|
||||
bool "sync"
|
||||
default n
|
||||
help
|
||||
sync is used to flush filesystem buffers.
|
||||
|
||||
config CONFIG_TAIL
|
||||
config TAIL
|
||||
bool "tail"
|
||||
default n
|
||||
help
|
||||
tail is used to print the last specified number of lines
|
||||
from files.
|
||||
|
||||
config CONFIG_FEATURE_FANCY_TAIL
|
||||
bool " Enable extra tail options (-q, -s, and -v)"
|
||||
config FEATURE_FANCY_TAIL
|
||||
bool "Enable extra tail options (-q, -s, and -v)"
|
||||
default y
|
||||
depends on CONFIG_TAIL
|
||||
depends on TAIL
|
||||
help
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
config CONFIG_TEE
|
||||
config TEE
|
||||
bool "tee"
|
||||
default n
|
||||
help
|
||||
tee is used to read from standard input and write
|
||||
to standard output and files.
|
||||
|
||||
config CONFIG_FEATURE_TEE_USE_BLOCK_IO
|
||||
bool " Enable block i/o (larger/faster) instead of byte i/o."
|
||||
config FEATURE_TEE_USE_BLOCK_IO
|
||||
bool "Enable block i/o (larger/faster) instead of byte i/o."
|
||||
default n
|
||||
depends on CONFIG_TEE
|
||||
depends on TEE
|
||||
help
|
||||
Enable this option for a faster tee, at expense of size.
|
||||
|
||||
if CONFIG_ASH || CONFIG_HUSH || CONFIG_LASH || CONFIG_MSH
|
||||
config CONFIG_TEST
|
||||
default y
|
||||
comment "test (forced enabled for use with shell)"
|
||||
endif
|
||||
|
||||
if !CONFIG_ASH && !CONFIG_HUSH && !CONFIG_LASH && !CONFIG_MSH
|
||||
config CONFIG_TEST
|
||||
bool "test"
|
||||
default n
|
||||
help
|
||||
test is used to check file types and compare values,
|
||||
returning an appropriate exit code. The shells (ash
|
||||
and bash) have test builtin.
|
||||
endif
|
||||
|
||||
config CONFIG_FEATURE_TEST_64
|
||||
bool " Extend test to 64 bit"
|
||||
config TEST
|
||||
bool "test"
|
||||
default n
|
||||
depends on CONFIG_TEST
|
||||
help
|
||||
test is used to check file types and compare values,
|
||||
returning an appropriate exit code. The bash shell
|
||||
has test built in, ash can build it in optionally.
|
||||
|
||||
config FEATURE_TEST_64
|
||||
bool "Extend test to 64 bit"
|
||||
default n
|
||||
depends on TEST
|
||||
help
|
||||
Enable 64-bit support in test.
|
||||
|
||||
config CONFIG_TOUCH
|
||||
config TOUCH
|
||||
bool "touch"
|
||||
default n
|
||||
help
|
||||
touch is used to create or change the access and/or
|
||||
modification timestamp of specified files.
|
||||
|
||||
config CONFIG_TR
|
||||
config TR
|
||||
bool "tr"
|
||||
default n
|
||||
help
|
||||
tr is used to squeeze, and/or delete characters from standard
|
||||
input, writing to standard output.
|
||||
|
||||
if CONFIG_HUSH || CONFIG_LASH || CONFIG_MSH
|
||||
config CONFIG_TRUE
|
||||
default y
|
||||
comment "true (forced enabled for use with shell)"
|
||||
endif
|
||||
config FEATURE_TR_CLASSES
|
||||
bool "Enable character classes (such as [:upper:])"
|
||||
default n
|
||||
depends on TR
|
||||
help
|
||||
Enable character classes, enabling commands such as:
|
||||
tr [:upper:] [:lower:] to convert input into lowercase.
|
||||
|
||||
if !CONFIG_HUSH && !CONFIG_LASH && !CONFIG_MSH
|
||||
config CONFIG_TRUE
|
||||
bool "true"
|
||||
default n
|
||||
help
|
||||
true returns an exit code of TRUE (0).
|
||||
config FEATURE_TR_EQUIV
|
||||
bool "Enable equivalence classes"
|
||||
default n
|
||||
depends on TR
|
||||
help
|
||||
Enable equivalence classes, which essentially add the enclosed
|
||||
character to the current set. For instance, tr [=a=] xyz would
|
||||
replace all instances of 'a' with 'xyz'. This option is mainly
|
||||
useful for cases when no other way of expressing a character
|
||||
is possible.
|
||||
|
||||
endif
|
||||
config TRUE
|
||||
bool "true"
|
||||
default n
|
||||
help
|
||||
true returns an exit code of TRUE (0).
|
||||
|
||||
config CONFIG_TTY
|
||||
config TTY
|
||||
bool "tty"
|
||||
default n
|
||||
help
|
||||
tty is used to print the name of the current terminal to
|
||||
standard output.
|
||||
|
||||
config CONFIG_UNAME
|
||||
config UNAME
|
||||
bool "uname"
|
||||
default n
|
||||
help
|
||||
uname is used to print system information.
|
||||
|
||||
config CONFIG_UNIQ
|
||||
config UNIQ
|
||||
bool "uniq"
|
||||
default n
|
||||
help
|
||||
uniq is used to remove duplicate lines from a sorted file.
|
||||
|
||||
config CONFIG_USLEEP
|
||||
config USLEEP
|
||||
bool "usleep"
|
||||
default n
|
||||
help
|
||||
usleep is used to pause for a specified number of microseconds.
|
||||
|
||||
config CONFIG_UUDECODE
|
||||
config UUDECODE
|
||||
bool "uudecode"
|
||||
default n
|
||||
help
|
||||
uudecode is used to decode a uuencoded file.
|
||||
|
||||
config CONFIG_UUENCODE
|
||||
config UUENCODE
|
||||
bool "uuencode"
|
||||
default n
|
||||
help
|
||||
uuencode is used to uuencode a file.
|
||||
|
||||
config CONFIG_WATCH
|
||||
config WATCH
|
||||
bool "watch"
|
||||
default n
|
||||
select DATE
|
||||
help
|
||||
watch is used to execute a program periodically, showing
|
||||
output to the screen.
|
||||
|
||||
config CONFIG_WC
|
||||
config WC
|
||||
bool "wc"
|
||||
default n
|
||||
help
|
||||
wc is used to print the number of bytes, words, and lines,
|
||||
in specified files.
|
||||
|
||||
config CONFIG_WHO
|
||||
config FEATURE_WC_LARGE
|
||||
bool "Support very large files in wc"
|
||||
default n
|
||||
depends on WC
|
||||
help
|
||||
Use "unsigned long long" in wc for count variables
|
||||
|
||||
config WHO
|
||||
bool "who"
|
||||
default n
|
||||
select CONFIG_FEATURE_U_W_TMP
|
||||
select FEATURE_UTMP
|
||||
help
|
||||
who is used to show who is logged on.
|
||||
|
||||
config CONFIG_WHOAMI
|
||||
config WHOAMI
|
||||
bool "whoami"
|
||||
default n
|
||||
help
|
||||
whoami is used to print the username of the current
|
||||
user id (same as id -un).
|
||||
|
||||
config CONFIG_YES
|
||||
config YES
|
||||
bool "yes"
|
||||
default n
|
||||
help
|
||||
@@ -564,46 +733,46 @@ config CONFIG_YES
|
||||
the default string `y'.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CONFIG_CP || CONFIG_MV
|
||||
depends on CP || MV
|
||||
|
||||
config CONFIG_FEATURE_PRESERVE_HARDLINKS
|
||||
bool " Preserve hard links"
|
||||
config FEATURE_PRESERVE_HARDLINKS
|
||||
bool "Preserve hard links"
|
||||
default n
|
||||
depends on CONFIG_CP || CONFIG_MV
|
||||
depends on CP || MV
|
||||
help
|
||||
Allow cp and mv to preserve hard links.
|
||||
|
||||
comment "Common options for ls and more"
|
||||
depends on CONFIG_LS || CONFIG_MORE
|
||||
comment "Common options for ls, more and telnet"
|
||||
depends on LS || MORE || TELNET
|
||||
|
||||
config CONFIG_FEATURE_AUTOWIDTH
|
||||
bool " Calculate terminal & column widths"
|
||||
config FEATURE_AUTOWIDTH
|
||||
bool "Calculate terminal & column widths"
|
||||
default y
|
||||
depends on CONFIG_LS || CONFIG_MORE
|
||||
depends on LS || MORE || TELNET
|
||||
help
|
||||
This option allows utilities such as 'ls' and 'more' to determine the
|
||||
width of the screen, which can allow them to display additional text
|
||||
or avoid wrapping text onto the next line. If you leave this
|
||||
disabled, your utilities will be especially primitive and will be
|
||||
unable to determine the current screen width.
|
||||
This option allows utilities such as 'ls', 'more' and 'telnet'
|
||||
to determine the width of the screen, which can allow them to
|
||||
display additional text or avoid wrapping text onto the next line.
|
||||
If you leave this disabled, your utilities will be especially
|
||||
primitive and will be unable to determine the current screen width.
|
||||
|
||||
comment "Common options for df, du, ls"
|
||||
depends on CONFIG_DF || CONFIG_DU || CONFIG_LS
|
||||
depends on DF || DU || LS
|
||||
|
||||
config CONFIG_FEATURE_HUMAN_READABLE
|
||||
bool " Support for human readable output (example 13k, 23M, 235G)"
|
||||
config FEATURE_HUMAN_READABLE
|
||||
bool "Support for human readable output (example 13k, 23M, 235G)"
|
||||
default n
|
||||
depends on CONFIG_DF || CONFIG_DU || CONFIG_LS
|
||||
depends on DF || DU || LS
|
||||
help
|
||||
Allow df, du, and ls to have human readable output.
|
||||
|
||||
comment "Common options for md5sum, sha1sum"
|
||||
depends on CONFIG_MD5SUM || CONFIG_SHA1SUM
|
||||
depends on MD5SUM || SHA1SUM
|
||||
|
||||
config CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
|
||||
bool " Enable -c, -s and -w options"
|
||||
config FEATURE_MD5_SHA1_SUM_CHECK
|
||||
bool "Enable -c, -s and -w options"
|
||||
default n
|
||||
depends on CONFIG_MD5SUM || CONFIG_SHA1SUM
|
||||
depends on MD5SUM || SHA1SUM
|
||||
help
|
||||
Enabling the -c options allows files to be checked
|
||||
against pre-calculated hash values.
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# 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 += libcoreutils/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_BASENAME) += basename.o
|
||||
lib-$(CONFIG_CAL) += cal.o
|
||||
lib-$(CONFIG_CAT) += cat.o
|
||||
lib-$(CONFIG_CATV) += catv.o
|
||||
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
|
||||
lib-$(CONFIG_CHMOD) += chmod.o
|
||||
lib-$(CONFIG_CHOWN) += chown.o
|
||||
lib-$(CONFIG_CHROOT) += chroot.o
|
||||
lib-$(CONFIG_CKSUM) += cksum.o
|
||||
lib-$(CONFIG_CMP) += cmp.o
|
||||
lib-$(CONFIG_COMM) += comm.o
|
||||
lib-$(CONFIG_CP) += cp.o
|
||||
lib-$(CONFIG_CUT) += cut.o
|
||||
lib-$(CONFIG_DATE) += date.o
|
||||
lib-$(CONFIG_DD) += dd.o
|
||||
lib-$(CONFIG_DF) += df.o
|
||||
lib-$(CONFIG_DIFF) += diff.o
|
||||
lib-$(CONFIG_DIRNAME) += dirname.o
|
||||
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
lib-$(CONFIG_DU) += du.o
|
||||
lib-$(CONFIG_ECHO) += echo.o
|
||||
lib-$(CONFIG_ENV) += env.o
|
||||
lib-$(CONFIG_EXPR) += expr.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
lib-$(CONFIG_FOLD) += fold.o
|
||||
lib-$(CONFIG_HEAD) += head.o
|
||||
lib-$(CONFIG_HOSTID) += hostid.o
|
||||
lib-$(CONFIG_ID) += id.o
|
||||
lib-$(CONFIG_INSTALL) += install.o
|
||||
lib-$(CONFIG_LENGTH) += length.o
|
||||
lib-$(CONFIG_LN) += ln.o
|
||||
lib-$(CONFIG_LOGNAME) += logname.o
|
||||
lib-$(CONFIG_LS) += ls.o
|
||||
lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_MKDIR) += mkdir.o
|
||||
lib-$(CONFIG_MKFIFO) += mkfifo.o
|
||||
lib-$(CONFIG_MKNOD) += mknod.o
|
||||
lib-$(CONFIG_MV) += mv.o
|
||||
lib-$(CONFIG_NICE) += nice.o
|
||||
lib-$(CONFIG_NOHUP) += nohup.o
|
||||
lib-$(CONFIG_OD) += od.o
|
||||
lib-$(CONFIG_PRINTENV) += printenv.o
|
||||
lib-$(CONFIG_PRINTF) += printf.o
|
||||
lib-$(CONFIG_PWD) += pwd.o
|
||||
lib-$(CONFIG_REALPATH) += realpath.o
|
||||
lib-$(CONFIG_RM) += rm.o
|
||||
lib-$(CONFIG_RMDIR) += rmdir.o
|
||||
lib-$(CONFIG_SEQ) += seq.o
|
||||
lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_SLEEP) += sleep.o
|
||||
lib-$(CONFIG_SORT) += sort.o
|
||||
lib-$(CONFIG_STAT) += stat.o
|
||||
lib-$(CONFIG_STTY) += stty.o
|
||||
lib-$(CONFIG_SUM) += sum.o
|
||||
lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TEST) += test.o
|
||||
lib-$(CONFIG_TOUCH) += touch.o
|
||||
lib-$(CONFIG_TR) += tr.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
lib-$(CONFIG_TTY) += tty.o
|
||||
lib-$(CONFIG_UNAME) += uname.o
|
||||
lib-$(CONFIG_UNIQ) += uniq.o
|
||||
lib-$(CONFIG_USLEEP) += usleep.o
|
||||
lib-$(CONFIG_UUDECODE) += uudecode.o
|
||||
lib-$(CONFIG_UUENCODE) += uuencode.o
|
||||
lib-$(CONFIG_WATCH) += watch.o
|
||||
lib-$(CONFIG_WC) += wc.o
|
||||
lib-$(CONFIG_WHO) += who.o
|
||||
lib-$(CONFIG_WHOAMI) += whoami.o
|
||||
lib-$(CONFIG_YES) += yes.o
|
||||
@@ -1,32 +0,0 @@
|
||||
# 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)/coreutils
|
||||
SHELLUTILS_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)
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
# 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
|
||||
#
|
||||
|
||||
COREUTILS_AR:=coreutils.a
|
||||
ifndef $(COREUTILS_DIR)
|
||||
COREUTILS_DIR:=$(top_builddir)/coreutils/
|
||||
endif
|
||||
srcdir=$(top_srcdir)/coreutils
|
||||
|
||||
COREUTILS-y:=
|
||||
COREUTILS-$(CONFIG_BASENAME) += basename.o
|
||||
COREUTILS-$(CONFIG_CAL) += cal.o
|
||||
COREUTILS-$(CONFIG_CAT) += cat.o
|
||||
COREUTILS-$(CONFIG_CHGRP) += chgrp.o
|
||||
COREUTILS-$(CONFIG_CHMOD) += chmod.o
|
||||
COREUTILS-$(CONFIG_CHOWN) += chown.o
|
||||
COREUTILS-$(CONFIG_CHROOT) += chroot.o
|
||||
COREUTILS-$(CONFIG_CMP) += cmp.o
|
||||
COREUTILS-$(CONFIG_CP) += cp.o
|
||||
COREUTILS-$(CONFIG_CUT) += cut.o
|
||||
COREUTILS-$(CONFIG_DATE) += date.o
|
||||
COREUTILS-$(CONFIG_DD) += dd.o
|
||||
COREUTILS-$(CONFIG_DF) += df.o
|
||||
COREUTILS-$(CONFIG_DIRNAME) += dirname.o
|
||||
COREUTILS-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
COREUTILS-$(CONFIG_DU) += du.o
|
||||
COREUTILS-$(CONFIG_ECHO) += echo.o
|
||||
COREUTILS-$(CONFIG_ENV) += env.o
|
||||
COREUTILS-$(CONFIG_EXPR) += expr.o
|
||||
COREUTILS-$(CONFIG_FALSE) += false.o
|
||||
COREUTILS-$(CONFIG_FOLD) += fold.o
|
||||
COREUTILS-$(CONFIG_HEAD) += head.o
|
||||
COREUTILS-$(CONFIG_HOSTID) += hostid.o
|
||||
COREUTILS-$(CONFIG_ID) += id.o
|
||||
COREUTILS-$(CONFIG_INSTALL) += install.o
|
||||
COREUTILS-$(CONFIG_LENGTH) += length.o
|
||||
COREUTILS-$(CONFIG_LN) += ln.o
|
||||
COREUTILS-$(CONFIG_LOGNAME) += logname.o
|
||||
COREUTILS-$(CONFIG_LS) += ls.o
|
||||
COREUTILS-$(CONFIG_MD5SUM) += md5_sha1_sum.o
|
||||
COREUTILS-$(CONFIG_MKDIR) += mkdir.o
|
||||
COREUTILS-$(CONFIG_MKFIFO) += mkfifo.o
|
||||
COREUTILS-$(CONFIG_MKNOD) += mknod.o
|
||||
COREUTILS-$(CONFIG_MV) += mv.o
|
||||
COREUTILS-$(CONFIG_OD) += od.o
|
||||
COREUTILS-$(CONFIG_PRINTF) += printf.o
|
||||
COREUTILS-$(CONFIG_PWD) += pwd.o
|
||||
COREUTILS-$(CONFIG_REALPATH) += realpath.o
|
||||
COREUTILS-$(CONFIG_RM) += rm.o
|
||||
COREUTILS-$(CONFIG_RMDIR) += rmdir.o
|
||||
COREUTILS-$(CONFIG_SEQ) += seq.o
|
||||
COREUTILS-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
|
||||
COREUTILS-$(CONFIG_SLEEP) += sleep.o
|
||||
COREUTILS-$(CONFIG_SORT) += sort.o
|
||||
COREUTILS-$(CONFIG_STTY) += stty.o
|
||||
COREUTILS-$(CONFIG_SYNC) += sync.o
|
||||
COREUTILS-$(CONFIG_TAIL) += tail.o
|
||||
COREUTILS-$(CONFIG_TEE) += tee.o
|
||||
COREUTILS-$(CONFIG_TEST) += test.o
|
||||
COREUTILS-$(CONFIG_TOUCH) += touch.o
|
||||
COREUTILS-$(CONFIG_TR) += tr.o
|
||||
COREUTILS-$(CONFIG_TRUE) += true.o
|
||||
COREUTILS-$(CONFIG_TTY) += tty.o
|
||||
COREUTILS-$(CONFIG_UNAME) += uname.o
|
||||
COREUTILS-$(CONFIG_UNIQ) += uniq.o
|
||||
COREUTILS-$(CONFIG_USLEEP) += usleep.o
|
||||
COREUTILS-$(CONFIG_UUDECODE) += uudecode.o
|
||||
COREUTILS-$(CONFIG_UUENCODE) += uuencode.o
|
||||
COREUTILS-$(CONFIG_WATCH) += watch.o
|
||||
COREUTILS-$(CONFIG_WC) += wc.o
|
||||
COREUTILS-$(CONFIG_WHO) += who.o
|
||||
COREUTILS-$(CONFIG_WHOAMI) += whoami.o
|
||||
COREUTILS-$(CONFIG_YES) += yes.o
|
||||
|
||||
libraries-y+=$(COREUTILS_DIR)$(COREUTILS_AR)
|
||||
|
||||
$(COREUTILS_DIR)$(COREUTILS_AR): $(patsubst %,$(COREUTILS_DIR)%, $(COREUTILS-y))
|
||||
$(AR) -ro $@ $(patsubst %,$(COREUTILS_DIR)%, $(COREUTILS-y))
|
||||
|
||||
$(COREUTILS_DIR)%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
|
||||
|
||||
+3
-15
@@ -4,19 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -37,7 +25,7 @@
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
int basename_main(int argc, char **argv)
|
||||
{
|
||||
size_t m, n;
|
||||
char *s;
|
||||
@@ -58,5 +46,5 @@ extern int basename_main(int argc, char **argv)
|
||||
|
||||
puts(s);
|
||||
|
||||
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+27
-50
@@ -1,23 +1,11 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Calendar implementation for busybox
|
||||
*
|
||||
* See original copyright at the end of this file
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 compliant with -j and -y extensions (from util-linux). */
|
||||
/* BB_AUDIT BUG: The output of 'cal -j 1752' is incorrect. The upstream
|
||||
@@ -29,26 +17,13 @@
|
||||
* Major size reduction... over 50% (>1.5k) on i386.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#define THURSDAY 4 /* for reformation */
|
||||
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
|
||||
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
|
||||
|
||||
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
|
||||
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
|
||||
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
|
||||
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
|
||||
|
||||
#define MAXDAYS 42 /* max slots in a month array */
|
||||
#define SPACE -1 /* used in day array */
|
||||
@@ -58,7 +33,7 @@ static const char days_in_month[] = {
|
||||
};
|
||||
|
||||
static const char sep1752[] = {
|
||||
1, 2, 14, 15, 16,
|
||||
1, 2, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30
|
||||
};
|
||||
@@ -89,9 +64,9 @@ static int is_leap_year(int year)
|
||||
#define leap_years_since_year_1(yr) \
|
||||
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
|
||||
|
||||
static void center __P((char *, int, int));
|
||||
static void day_array __P((int, int, int *));
|
||||
static void trim_trailing_spaces_and_print __P((char *));
|
||||
static void center (char *, int, int);
|
||||
static void day_array (int, int, int *);
|
||||
static void trim_trailing_spaces_and_print (char *);
|
||||
|
||||
static void blank_string(char *buf, size_t buflen);
|
||||
static char *build_row(char *p, int *dp);
|
||||
@@ -112,11 +87,12 @@ int cal_main(int argc, char **argv)
|
||||
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
|
||||
char buf[40];
|
||||
|
||||
#ifdef CONFIG_LOCALE_SUPPORT
|
||||
setlocale(LC_TIME, "");
|
||||
#endif
|
||||
// Done in busybox.c, ok to remove?
|
||||
//#ifdef CONFIG_LOCALE_SUPPORT
|
||||
// setlocale(LC_TIME, "");
|
||||
//#endif
|
||||
|
||||
flags = bb_getopt_ulflags(argc, argv, "jy");
|
||||
flags = getopt32(argc, argv, "jy");
|
||||
|
||||
julian = flags & 1;
|
||||
|
||||
@@ -137,9 +113,9 @@ int cal_main(int argc, char **argv)
|
||||
}
|
||||
} else {
|
||||
if (argc == 2) {
|
||||
month = bb_xgetularg10_bnd(*argv++, 1, 12);
|
||||
month = xatoul_range(*argv++, 1, 12);
|
||||
}
|
||||
year = bb_xgetularg10_bnd(*argv, 1, 9999);
|
||||
year = xatoul_range(*argv, 1, 9999);
|
||||
}
|
||||
|
||||
blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian);
|
||||
@@ -148,7 +124,7 @@ int cal_main(int argc, char **argv)
|
||||
do {
|
||||
zero_tm.tm_mon = i;
|
||||
strftime(buf, sizeof(buf), "%B", &zero_tm);
|
||||
month_names[i] = bb_xstrdup(buf);
|
||||
month_names[i] = xstrdup(buf);
|
||||
|
||||
if (i < 7) {
|
||||
zero_tm.tm_wday = i;
|
||||
@@ -164,7 +140,7 @@ int cal_main(int argc, char **argv)
|
||||
|
||||
day_array(month, year, dp);
|
||||
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
|
||||
bb_printf("%*s%s\n%s\n",
|
||||
printf("%*s%s\n%s\n",
|
||||
((7*julian + WEEK_LEN) - len) / 2, "",
|
||||
lineout, day_headings);
|
||||
for (row = 0; row < 6; row++) {
|
||||
@@ -195,9 +171,9 @@ int cal_main(int argc, char **argv)
|
||||
center(month_names[month + 1], week_len, HEAD_SEP);
|
||||
}
|
||||
center(month_names[month + 2 - julian], week_len, 0);
|
||||
bb_printf("\n%s%*s%s", day_headings, HEAD_SEP, "", day_headings);
|
||||
printf("\n%s%*s%s", day_headings, HEAD_SEP, "", day_headings);
|
||||
if (!julian) {
|
||||
bb_printf("%*s%s", HEAD_SEP, "", day_headings);
|
||||
printf("%*s%s", HEAD_SEP, "", day_headings);
|
||||
}
|
||||
putchar('\n');
|
||||
for (row = 0; row < (6*7); row += 7) {
|
||||
@@ -211,7 +187,7 @@ int cal_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
bb_fflush_stdout_and_exit(0);
|
||||
fflush_stdout_and_exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -231,11 +207,12 @@ static void day_array(int month, int year, int *days)
|
||||
memset(days, SPACE, MAXDAYS * sizeof(int));
|
||||
|
||||
if ((month == 9) && (year == 1752)) {
|
||||
size_t oday = 0;
|
||||
|
||||
j_offset = julian * 244;
|
||||
i = 0;
|
||||
do {
|
||||
days[i+2] = sep1752[i] + j_offset;
|
||||
} while (++i < sizeof(sep1752));
|
||||
days[oday+2] = sep1752[oday] + j_offset;
|
||||
} while (++oday < sizeof(sep1752));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -305,7 +282,7 @@ static void center(char *str, int len, int separate)
|
||||
{
|
||||
int n = strlen(str);
|
||||
len -= n;
|
||||
bb_printf("%*s%*s", (len/2) + n, str, (len/2) + (len % 2) + separate, "");
|
||||
printf("%*s%*s", (len/2) + n, str, (len/2) + (len % 2) + separate, "");
|
||||
}
|
||||
|
||||
static void blank_string(char *buf, size_t buflen)
|
||||
|
||||
+8
-34
@@ -4,48 +4,21 @@
|
||||
*
|
||||
* Copyright (C) 2003 Manuel Novoa III <mjn3@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
|
||||
*
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
|
||||
|
||||
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
||||
*
|
||||
* This is a new implementation of 'cat' which aims to be SUSv3 compliant.
|
||||
*
|
||||
* Changes from the previous implementation include:
|
||||
* 1) Multiple '-' args are accepted as required by SUSv3. The previous
|
||||
* implementation would close stdin and segfault on a subsequent '-'.
|
||||
* 2) The '-u' options is required by SUSv3. Note that the specified
|
||||
* behavior for '-u' is done by default, so all we need do is accept
|
||||
* the option.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
bb_getopt_ulflags(argc, argv, "u");
|
||||
getopt32(argc, argv, "u");
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
@@ -53,9 +26,10 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
do {
|
||||
if ((f = bb_wfopen_input(*argv)) != NULL) {
|
||||
int r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
|
||||
bb_fclose_nonstdin(f);
|
||||
f = fopen_or_warn_stdin(*argv);
|
||||
if (f) {
|
||||
off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
|
||||
fclose_if_not_stdin(f);
|
||||
if (r >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cat -v implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2006 Rob Landley <rob@landley.net>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* See "Cat -v considered harmful" at
|
||||
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int catv_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS, fd;
|
||||
unsigned flags;
|
||||
|
||||
flags = getopt32(argc, argv, "etv");
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
flags ^= CATV_OPT_v;
|
||||
|
||||
argv += optind;
|
||||
do {
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
fd = 0;
|
||||
if (*argv && 0 > (fd = xopen(*argv, O_RDONLY)))
|
||||
retval = EXIT_FAILURE;
|
||||
else for (;;) {
|
||||
int i, res;
|
||||
|
||||
res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
|
||||
if (res < 0)
|
||||
retval = EXIT_FAILURE;
|
||||
if (res < 1)
|
||||
break;
|
||||
for (i = 0; i < res; i++) {
|
||||
char c = bb_common_bufsiz1[i];
|
||||
|
||||
if (c > 126 && (flags & CATV_OPT_v)) {
|
||||
if (c == 127) {
|
||||
printf("^?");
|
||||
continue;
|
||||
} else {
|
||||
printf("M-");
|
||||
c -= 128;
|
||||
}
|
||||
}
|
||||
if (c < 32) {
|
||||
if (c == 10) {
|
||||
if (flags & CATV_OPT_e)
|
||||
putchar('$');
|
||||
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
|
||||
printf("^%c", c+'@');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && fd)
|
||||
close(fd);
|
||||
} while (*++argv);
|
||||
|
||||
fflush_stdout_and_exit(retval);
|
||||
}
|
||||
Loaded 100 of 922 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user