Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28dd64a0e1 | ||
|
|
5698ff9323 | ||
|
|
d9e0c438e1 |
No files matched your search
-15
@@ -35,18 +35,3 @@ Config.in
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
#
|
||||
# testing output
|
||||
#
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
|
||||
#
|
||||
# cscope output
|
||||
#
|
||||
cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
@@ -257,26 +257,6 @@ config UNICODE_PRESERVE_BROKEN
|
||||
at shell prompt will list file named 0xff (single char name
|
||||
with char value 255), not file named '?'.
|
||||
|
||||
config PAM
|
||||
bool "Support for PAM (Pluggable Authentication Modules)"
|
||||
default n
|
||||
help
|
||||
Use PAM in some busybox applets (currently login and httpd) instead
|
||||
of direct access to password database.
|
||||
|
||||
config FEATURE_USE_SENDFILE
|
||||
bool "Use sendfile system call"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
When enabled, busybox will use the kernel sendfile() function
|
||||
instead of read/write loops to copy data between file descriptors
|
||||
(for example, cp command does this a lot).
|
||||
If sendfile() doesn't work, copying code falls back to read/write
|
||||
loop. sendfile() was originally implemented for faster I/O
|
||||
from files to sockets, but since Linux 2.6.33 it was extended
|
||||
to work for many more file types.
|
||||
|
||||
config LONG_OPTS
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
@@ -436,7 +416,10 @@ config SELINUX
|
||||
the option of compiling in SELinux applets.
|
||||
|
||||
If you do not have a complete SELinux userland installed, this stuff
|
||||
will not compile. Specifially, libselinux 1.28 or better is
|
||||
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> \
|
||||
@@ -688,14 +671,6 @@ config DEBUG_PESSIMIZE
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
config UNIT_TEST
|
||||
bool "Build unit tests"
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to build unit tests (both the framework and
|
||||
test cases) as a Busybox applet. This results in bigger code, so you
|
||||
probably don't want this option in production builds.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 24
|
||||
SUBLEVEL = 2
|
||||
PATCHLEVEL = 22
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -552,7 +552,7 @@ export INSTALL_PATH ?= /boot
|
||||
#
|
||||
# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
|
||||
# relocations required by build roots. This is not defined in the
|
||||
# makefile but the argument can be passed to make if needed.
|
||||
# makefile but the arguement can be passed to make if needed.
|
||||
#
|
||||
|
||||
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
|
||||
@@ -1165,7 +1165,24 @@ endif
|
||||
ALLSOURCE_ARCHS := $(ARCH)
|
||||
|
||||
define all-sources
|
||||
( find -regex '.*\.[ch]$$' )
|
||||
( find $(__srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name include -o -name arch \) -prune -o \
|
||||
-name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLSOURCE_ARCHS) ; do \
|
||||
find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
find $(__srctree)include $(RCS_FIND_IGNORE) \
|
||||
\( -name config -o -name 'asm-*' \) -prune \
|
||||
-o -name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLINCLUDE_ARCHS) ; do \
|
||||
find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print )
|
||||
endef
|
||||
|
||||
quiet_cmd_cscope-file = FILELST cscope.files
|
||||
|
||||
@@ -28,10 +28,6 @@ ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_FEATURE_INDIVIDUAL),y)
|
||||
INSTALL_OPTS:= --binaries
|
||||
LIBBUSYBOX_SONAME:= 0_lib/libbusybox.so.$(BB_VER)
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
@@ -59,11 +55,7 @@ endif
|
||||
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
|
||||
.PHONY: check
|
||||
.PHONY: test
|
||||
ifeq ($(CONFIG_UNIT_TEST),y)
|
||||
UNIT_CMD = ./busybox unit
|
||||
endif
|
||||
check test: busybox busybox.links
|
||||
$(UNIT_CMD)
|
||||
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite \
|
||||
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
|
||||
|
||||
+9
-16
@@ -56,9 +56,6 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
|
||||
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
|
||||
CFLAGS += $(call cc-option,-fno-unwind-tables,)
|
||||
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
|
||||
# No automatic printf->puts,putchar conversions
|
||||
# (try disabling this and comparing assembly, it's instructive)
|
||||
CFLAGS += $(call cc-option,-fno-builtin-printf,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
@@ -129,19 +126,15 @@ else
|
||||
LDLIBS += m
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
# However, on *other platforms* it fails when some of those flags
|
||||
# given needlessly. On some systems, crypt needs pthread.
|
||||
#
|
||||
# I even had a system where a runtime test for pthread
|
||||
# (similar to CRYPT_AVAILABLE test above) was not reliable.
|
||||
#
|
||||
# Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
|
||||
# Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
LDLIBS += pam pam_misc
|
||||
# libpam uses libpthread, so for static builds busybox must be linked to
|
||||
# libpthread. On some platforms that requires an explicit -lpthread, so
|
||||
# it should be in LDLIBS. For non-static builds, scripts/trylink will
|
||||
# take care of removing -lpthread if possible. (Not bothering to check
|
||||
# CONFIG_STATIC because even in a non-static build it could be that the
|
||||
# only libpam available is libpam.a, so -lpthread could still be
|
||||
# needed.)
|
||||
LDLIBS += pam pam_misc pthread
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
@@ -170,7 +163,7 @@ SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDFLAGS),)
|
||||
LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
EXTRA_LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ help:
|
||||
@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"'
|
||||
@$(if $(boards), \
|
||||
$(foreach b, $(boards), \
|
||||
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
|
||||
|
||||
@@ -185,7 +185,7 @@ Supported hardware:
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, and v850e. Anything else probably won't work.
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#undef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||
@@ -50,16 +49,6 @@ static int cmp_name(const void *a, const void *b)
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
@@ -105,12 +94,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
printf(";\n\n");
|
||||
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
if (str_isalnum_(applets[i].name))
|
||||
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
|
||||
+2
-24
@@ -5,26 +5,19 @@ export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
sharedlib_dir="0_lib"
|
||||
|
||||
linkopts=""
|
||||
scriptwrapper="n"
|
||||
binaries="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--binaries) binaries="y";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
@@ -47,9 +40,8 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
for i in $DO_INSTALL_LIBS; do
|
||||
rm -f "$prefix/$libdir/$i" || exit 1
|
||||
if [ -f "$i" ]; then
|
||||
echo " Installing $i to the target at $prefix/$libdir/"
|
||||
cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/$i" || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -76,7 +68,6 @@ install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
||||
|
||||
for i in $h; do
|
||||
appdir=`dirname "$i"`
|
||||
app=`basename "$i"`
|
||||
mkdir -p "$prefix/$appdir" || exit 1
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
@@ -87,19 +78,6 @@ for i in $h; do
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ "$binaries" = "y" ]; then
|
||||
# Copy the binary over rather
|
||||
if [ -e $sharedlib_dir/$app ]; then
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
|
||||
else
|
||||
echo " $prefix/$i already exists"
|
||||
fi
|
||||
else
|
||||
echo "Error: Could not find $sharedlib_dir/$app"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
|
||||
@@ -20,7 +20,6 @@ exec >"$target.$$"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
@@ -28,13 +27,6 @@ echo '#define UNPACKED_USAGE "" \'
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
# "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
|
||||
#0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
|
||||
# 000010 000010 026533 063144 020135 026533 020143 047503
|
||||
#0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
|
||||
# 043116 044504 056522 055440 066055 046040 043517 044506
|
||||
#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
|
||||
# 042514 020135 026533 020141 041501 044524 047117 044506
|
||||
|
||||
echo '#define PACKED_USAGE \'
|
||||
## Breaks on big-endian systems!
|
||||
@@ -48,7 +40,6 @@ echo '#define PACKED_USAGE \'
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/$/ \\/'
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
|
||||
+39
-17
@@ -39,7 +39,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
||||
}
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
)
|
||||
@@ -48,7 +48,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_state_t xstate;
|
||||
transformer_aux_data_t aux;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -72,8 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
goto err;
|
||||
} else {
|
||||
/* "clever zcat" with FILE */
|
||||
/* fail_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
|
||||
int fd = open_zipped(filename);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
@@ -81,7 +80,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
} else
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -120,11 +119,9 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = 1;
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
xstate.dst_fd = STDOUT_FILENO;
|
||||
status = unpacker(&xstate);
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
} else {
|
||||
@@ -143,10 +140,10 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (xstate.mtime != 0) {
|
||||
if (aux.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
|
||||
times[1].tv_sec = times[0].tv_sec = aux.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
@@ -228,13 +225,18 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
|
||||
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -321,6 +323,11 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -347,7 +354,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -387,6 +394,11 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -395,7 +407,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -481,6 +493,11 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -495,7 +512,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -519,6 +536,11 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -533,6 +555,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -127,7 +127,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
|
||||
+1
-1
@@ -65,7 +65,6 @@
|
||||
//usage: IF_FEATURE_CPIO_P(
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: "\n -d Make leading directories"
|
||||
//usage: "\n -m Preserve mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
@@ -257,6 +256,7 @@ static NOINLINE int cpio_o(void)
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
|
||||
+4
-15
@@ -1151,13 +1151,13 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
if (result && number_of_alternatives == 0) {
|
||||
if (root_of_alternatives)
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, which %s",
|
||||
"package %s %sdepends on %s, "
|
||||
"which cannot be satisfied",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[root_of_alternatives->name],
|
||||
"cannot be satisfied");
|
||||
name_hashtable[root_of_alternatives->name]);
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, which %s",
|
||||
"package %s %sdepends on %s, which %s\n",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[package_edge->name],
|
||||
@@ -1472,16 +1472,12 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
@@ -1496,19 +1492,12 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
|
||||
@@ -70,8 +70,6 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
@@ -84,10 +82,6 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
+25
-113
@@ -62,27 +62,14 @@ aa: 85.1% -- replaced with aa.gz
|
||||
//config: 1: larger buffers, larger hash-tables
|
||||
//config: 2: larger buffers, largest hash-tables
|
||||
//config: Larger models may give slightly better compression
|
||||
//config:
|
||||
//config:config FEATURE_GZIP_LEVELS
|
||||
//config: bool "Enable compression levels"
|
||||
//config: default n
|
||||
//config: depends on GZIP
|
||||
//config: help
|
||||
//config: Enable support for compression levels 4-9. The default level
|
||||
//config: is 6. If levels 1-3 are specified, 4 is used.
|
||||
//config: If this option is not selected, -N options are ignored and -9
|
||||
//config: is used.
|
||||
|
||||
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
|
||||
|
||||
//usage:#define gzip_trivial_usage
|
||||
//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
|
||||
//usage: "[-cfd] [FILE]..."
|
||||
//usage:#define gzip_full_usage "\n\n"
|
||||
//usage: "Compress FILEs (or stdin)\n"
|
||||
//usage: IF_FEATURE_GZIP_LEVELS(
|
||||
//usage: "\n -1..9 Compression level"
|
||||
//usage: )
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
@@ -265,8 +252,6 @@ enum {
|
||||
* input file length plus MIN_LOOKAHEAD.
|
||||
*/
|
||||
|
||||
#ifndef ENABLE_FEATURE_GZIP_LEVELS
|
||||
|
||||
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.
|
||||
@@ -298,23 +283,11 @@ enum {
|
||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||
* meaning.
|
||||
*/
|
||||
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
|
||||
};
|
||||
|
||||
|
||||
struct globals {
|
||||
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
unsigned max_chain_length;
|
||||
unsigned max_lazy_match;
|
||||
unsigned good_match;
|
||||
unsigned nice_match;
|
||||
#define max_chain_length (G1.max_chain_length)
|
||||
#define max_lazy_match (G1.max_lazy_match)
|
||||
#define good_match (G1.good_match)
|
||||
#define nice_match (G1.nice_match)
|
||||
#endif
|
||||
|
||||
lng block_start;
|
||||
|
||||
/* window position at the beginning of the current output block. Gets
|
||||
@@ -444,46 +417,19 @@ static void flush_outbuf(void)
|
||||
#define put_8bit(c) \
|
||||
do { \
|
||||
G1.outbuf[G1.outcnt++] = (c); \
|
||||
if (G1.outcnt == OUTBUFSIZ) \
|
||||
flush_outbuf(); \
|
||||
if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \
|
||||
} while (0)
|
||||
|
||||
/* Output a 16 bit value, lsb first */
|
||||
static void put_16bit(ush w)
|
||||
{
|
||||
/* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
|
||||
* (probably because of fear of aliasing with G1.outbuf[]
|
||||
* stores), do it explicitly:
|
||||
*/
|
||||
unsigned outcnt = G1.outcnt;
|
||||
uch *dst = &G1.outbuf[outcnt];
|
||||
|
||||
#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
ush *dst16 = (void*) dst;
|
||||
*dst16 = w; /* unalinged LSB 16-bit store */
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
if (G1.outcnt < OUTBUFSIZ - 2) {
|
||||
G1.outbuf[G1.outcnt++] = w;
|
||||
G1.outbuf[G1.outcnt++] = w >> 8;
|
||||
} else {
|
||||
put_8bit(w);
|
||||
put_8bit(w >> 8);
|
||||
}
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
#else
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
dst[1] = w;
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Slowpath: we will need to do flush_outbuf() */
|
||||
G1.outcnt = ++outcnt;
|
||||
if (outcnt == OUTBUFSIZ)
|
||||
flush_outbuf();
|
||||
put_8bit(w);
|
||||
}
|
||||
|
||||
static void put_32bit(ulg n)
|
||||
@@ -1372,6 +1318,7 @@ static void build_tree(tree_desc * desc)
|
||||
/* and insert the new node in the heap */
|
||||
G2.heap[SMALLEST] = node++;
|
||||
pqdownheap(tree, SMALLEST);
|
||||
|
||||
} while (G2.heap_len >= 2);
|
||||
|
||||
G2.heap[--G2.heap_max] = G2.heap[SMALLEST];
|
||||
@@ -1719,6 +1666,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 0); /* without header */
|
||||
G2.compressed_len = stored_len << 3;
|
||||
|
||||
} else if (stored_len + 4 <= opt_lenb && buf != NULL) {
|
||||
/* 4: two words for the lengths */
|
||||
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
|
||||
@@ -1732,6 +1680,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
G2.compressed_len += (stored_len + 4) << 3;
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 1); /* with header */
|
||||
|
||||
} else if (static_lenb == opt_lenb) {
|
||||
send_bits((STATIC_TREES << 1) + eof, 3);
|
||||
compress_block((ct_data *) G2.static_ltree, (ct_data *) G2.static_dtree);
|
||||
@@ -2058,7 +2007,7 @@ static void ct_init(void)
|
||||
* IN assertions: the input and output buffers are cleared.
|
||||
*/
|
||||
|
||||
static void zip(void)
|
||||
static void zip(ulg time_stamp)
|
||||
{
|
||||
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
|
||||
|
||||
@@ -2069,7 +2018,7 @@ static void zip(void)
|
||||
/* compression method: 8 (DEFLATED) */
|
||||
/* general flags: 0 */
|
||||
put_32bit(0x00088b1f);
|
||||
put_32bit(0); /* Unix timestamp */
|
||||
put_32bit(time_stamp);
|
||||
|
||||
/* Write deflated file to zip file */
|
||||
G1.crc = ~0;
|
||||
@@ -2093,8 +2042,10 @@ static void zip(void)
|
||||
|
||||
/* ======================================================================== */
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
/* Clear input and output buffers */
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
@@ -2126,23 +2077,9 @@ IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED
|
||||
G2.bl_desc.max_length = MAX_BL_BITS;
|
||||
//G2.bl_desc.max_code = 0;
|
||||
|
||||
#if 0
|
||||
/* Saving of timestamp is disabled. Why?
|
||||
* - it is not Y2038-safe.
|
||||
* - some people want deterministic results
|
||||
* (normally they'd use -n, but our -n is a nop).
|
||||
* - it's bloat.
|
||||
* Per RFC 1952, gzfile.time=0 is "no timestamp".
|
||||
* If users will demand this to be reinstated,
|
||||
* implement -n "don't save timestamp".
|
||||
*/
|
||||
struct stat s;
|
||||
s.st_ctime = 0;
|
||||
fstat(STDIN_FILENO, &s);
|
||||
zip(s.st_ctime);
|
||||
#else
|
||||
zip();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2185,48 +2122,24 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
{
|
||||
unsigned opt;
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
static const struct {
|
||||
uint8_t good;
|
||||
uint8_t chain_shift;
|
||||
uint8_t lazy2;
|
||||
uint8_t nice2;
|
||||
} gzip_level_config[6] = {
|
||||
{4, 4, 4/2, 16/2}, /* Level 4 */
|
||||
{8, 5, 16/2, 32/2}, /* Level 5 */
|
||||
{8, 7, 16/2, 128/2}, /* Level 6 */
|
||||
{8, 8, 32/2, 128/2}, /* Level 7 */
|
||||
{32, 10, 128/2, 258/2}, /* Level 8 */
|
||||
{32, 12, 258/2, 258/2}, /* Level 9 */
|
||||
};
|
||||
#endif
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
applet_long_options = gzip_longopts;
|
||||
#endif
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
return gunzip_main(argc, argv);
|
||||
#endif
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
|
||||
if (opt == 0)
|
||||
opt = 1 << 6; /* default: 6 */
|
||||
/* Map 1..3 to 4 */
|
||||
if (opt & 0x7)
|
||||
opt |= 1 << 4;
|
||||
opt = ffs(opt >> 3);
|
||||
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
|
||||
good_match = gzip_level_config[opt].good;
|
||||
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
|
||||
nice_match = gzip_level_config[opt].nice2 * 2;
|
||||
#endif
|
||||
option_mask32 &= 0x7; /* retain only -cfv */
|
||||
option_mask32 &= 0x7; /* ignore -q, -0..9 */
|
||||
//if (opt & 0x1) // -c
|
||||
//if (opt & 0x2) // -f
|
||||
//if (opt & 0x4) // -v
|
||||
argv += optind;
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
@@ -2238,6 +2151,5 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Initialize the CRC32 table */
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, pack_gzip, append_ext, "gz");
|
||||
}
|
||||
@@ -30,13 +30,11 @@ COMMON_FILES:= \
|
||||
DPKG_FILES:= \
|
||||
unpack_ar_archive.o \
|
||||
filter_accept_list_reassign.o \
|
||||
unsafe_prefix.o \
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
get_header_tar_bz2.o \
|
||||
get_header_tar_lzma.o \
|
||||
get_header_tar_xz.o \
|
||||
|
||||
INSERT
|
||||
|
||||
@@ -45,7 +43,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
@@ -54,7 +52,7 @@ lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
|
||||
@@ -385,6 +385,7 @@ void sendMTFValues(EState* s)
|
||||
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("'%s' returned status %d",
|
||||
archive_handle->tar__to_command, WEXITSTATUS(status));
|
||||
if (WIFSIGNALED(status))
|
||||
bb_error_msg_and_die("'%s' terminated by signal %d",
|
||||
bb_error_msg_and_die("'%s' terminated on signal %d",
|
||||
archive_handle->tar__to_command, WTERMSIG(status));
|
||||
|
||||
if (!BB_MMU) {
|
||||
|
||||
@@ -731,7 +731,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream(transformer_state_t *xstate)
|
||||
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
bunzip_data *bd;
|
||||
@@ -739,14 +739,14 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
int i;
|
||||
unsigned len;
|
||||
|
||||
if (check_signature16(xstate, BZIP2_MAGIC))
|
||||
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
|
||||
return -1;
|
||||
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -756,7 +756,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
i = IOBUF_SIZE - i; /* number of bytes produced */
|
||||
if (i == 0) /* EOF? */
|
||||
break;
|
||||
if (i != transformer_write(xstate, outbuf, i)) {
|
||||
if (i != full_write(dst_fd, outbuf, i)) {
|
||||
bb_error_msg("short write");
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
goto release_mem;
|
||||
}
|
||||
@@ -789,7 +790,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
len = bd->inbufCount - bd->inbufPos;
|
||||
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
|
||||
if (len < 2) {
|
||||
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
break;
|
||||
len = 2;
|
||||
}
|
||||
|
||||
@@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
unsigned i; /* counter, current code */
|
||||
unsigned j; /* counter */
|
||||
int k; /* number of bits in current code */
|
||||
const unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
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 + 1]; /* values in order of bit length. last v[] is never used */
|
||||
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 */
|
||||
@@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset(c, 0, sizeof(c));
|
||||
p = b;
|
||||
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
|
||||
i = n;
|
||||
do {
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
@@ -364,12 +364,8 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
*xp++ = j;
|
||||
}
|
||||
|
||||
/* Make a table of values in order of bit lengths.
|
||||
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
|
||||
* In particular, last v[i] is never filled and must not be accessed.
|
||||
*/
|
||||
memset(v, 0xff, sizeof(v));
|
||||
p = b;
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = (unsigned *) b;
|
||||
i = 0;
|
||||
do {
|
||||
j = *p++;
|
||||
@@ -436,9 +432,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* set up table entry in r */
|
||||
r.b = (unsigned char) (k - w);
|
||||
if (/*p >= v + n || -- redundant, caught by the second check: */
|
||||
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
|
||||
) {
|
||||
if (p >= v + n) {
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
} else if (*p < s) {
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
@@ -523,9 +517,8 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
if (e == 99)
|
||||
abort_unzip(PASS_STATE_ONLY);;
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -561,9 +554,8 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
if (e == 99)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -829,9 +821,8 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
|
||||
b_dynamic >>= 4;
|
||||
k_dynamic -= 4;
|
||||
if (nl > 286 || nd > 30) {
|
||||
if (nl > 286 || nd > 30)
|
||||
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
|
||||
}
|
||||
|
||||
/* read in bit-length-code lengths */
|
||||
for (j = 0; j < nb; j++) {
|
||||
@@ -912,14 +903,12 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
bl = lbits;
|
||||
|
||||
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bd = dbits;
|
||||
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
|
||||
/* set up data for inflate_codes() */
|
||||
inflate_codes_setup(PASS_STATE bl, bd);
|
||||
@@ -982,7 +971,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
|
||||
|
||||
/* Called from unpack_gz_stream() and inflate_unzip() */
|
||||
static IF_DESKTOP(long long) int
|
||||
inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n = 0;
|
||||
ssize_t nwrote;
|
||||
@@ -991,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
gunzip_window = xmalloc(GUNZIP_WSIZE);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = in;
|
||||
|
||||
/* (re) initialize state */
|
||||
method = -1;
|
||||
@@ -1007,15 +996,15 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
error_msg = "corrupted data";
|
||||
if (setjmp(error_jmp)) {
|
||||
/* Error from deep inside zip machinery */
|
||||
bb_error_msg(error_msg);
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int r = inflate_get_next_window(PASS_STATE_ONLY);
|
||||
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == (ssize_t)-1) {
|
||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote != (ssize_t)gunzip_outbuf_count) {
|
||||
bb_perror_msg("write");
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1045,22 +1034,22 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
/* For unzip */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
inflate_unzip(transformer_state_t *xstate)
|
||||
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
ALLOC_STATE;
|
||||
|
||||
to_read = xstate->bytes_in;
|
||||
to_read = aux->bytes_in;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE in, out);
|
||||
free(bytebuffer);
|
||||
|
||||
xstate->crc32 = gunzip_crc;
|
||||
xstate->bytes_out = gunzip_bytes_out;
|
||||
aux->crc32 = gunzip_crc;
|
||||
aux->bytes_out = gunzip_bytes_out;
|
||||
DEALLOC_STATE;
|
||||
return n;
|
||||
}
|
||||
@@ -1118,7 +1107,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -1180,7 +1169,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
}
|
||||
|
||||
xstate->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
if (aux)
|
||||
aux->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
@@ -1192,27 +1182,27 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(transformer_state_t *xstate)
|
||||
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
uint32_t v32;
|
||||
IF_DESKTOP(long long) int total, n;
|
||||
DECLARE_STATE;
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_Z
|
||||
if (check_signature16(xstate, GZIP_MAGIC))
|
||||
if (check_signature16(aux, src_fd, GZIP_MAGIC))
|
||||
return -1;
|
||||
#else
|
||||
if (xstate->check_signature) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2) {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
if (magic2 == COMPRESS_MAGIC) {
|
||||
xstate->check_signature = 0;
|
||||
return unpack_Z_stream(xstate);
|
||||
aux->check_signature = 0;
|
||||
return unpack_Z_stream(aux, src_fd, dst_fd);
|
||||
}
|
||||
if (magic2 != GZIP_MAGIC)
|
||||
goto bad_magic;
|
||||
@@ -1225,16 +1215,16 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
to_read = -1;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = src_fd;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE xstate)) {
|
||||
if (!check_header_gzip(PASS_STATE aux)) {
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
|
||||
if (n < 0) {
|
||||
total = -1;
|
||||
goto ret;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_Z_stream(transformer_state_t *xstate)
|
||||
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
IF_DESKTOP(long long) int retval = -1;
|
||||
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
if (check_signature16(xstate, COMPRESS_MAGIC))
|
||||
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
|
||||
return -1;
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
||||
if (full_read(src_fd, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
||||
rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
|
||||
if (rsize < 0)
|
||||
bb_error_msg_and_die(bb_msg_read_error);
|
||||
insize += rsize;
|
||||
@@ -274,7 +274,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
@@ -297,10 +297,11 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* Remember previous code. */
|
||||
oldcode = incode;
|
||||
}
|
||||
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ enum {
|
||||
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_lzma_stream(transformer_state_t *xstate)
|
||||
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
@@ -214,6 +214,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint16_t *p;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
@@ -223,7 +225,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
@@ -237,9 +239,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
/* Example values from linux-3.3.4.tar.lzma:
|
||||
* dict_size: 64M, dst_size: 2^64-1
|
||||
*/
|
||||
header.dict_size = SWAP_LE32(header.dict_size);
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
@@ -248,17 +247,13 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
{
|
||||
int num_probs;
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
}
|
||||
|
||||
rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
@@ -306,7 +301,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
@@ -315,7 +310,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
goto one_byte2;
|
||||
#endif
|
||||
} else {
|
||||
int num_bits;
|
||||
int offset;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
@@ -440,22 +434,19 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
/* FIXME: ...........^^^^^
|
||||
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
IF_NOT_DESKTOP(int total_written = 0; /* success */)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
#include "unxz/xz_dec_stream.c"
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_state_t *xstate)
|
||||
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
iobuf.out = membuf + BUFSIZ;
|
||||
iobuf.out_size = BUFSIZ;
|
||||
|
||||
if (!xstate || xstate->check_signature == 0) {
|
||||
if (!aux || aux->check_signature == 0) {
|
||||
/* Preload XZ file signature */
|
||||
strcpy((char*)membuf, HEADER_MAGIC);
|
||||
iobuf.in_size = HEADER_MAGIC_SIZE;
|
||||
@@ -67,7 +67,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
|
||||
int rd = safe_read(src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
||||
if (iobuf.out_pos) {
|
||||
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
|
||||
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
name_ptr++;
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
if (strcmp(name_ptr, "tar") == 0) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
@@ -50,12 +46,6 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& strcmp(name_ptr, "xz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (!is_prefixed_with(&cpio_header[0], "07070")
|
||||
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");
|
||||
|
||||
@@ -17,6 +17,36 @@
|
||||
typedef uint32_t aliased_uint32_t FIX_ALIASING;
|
||||
typedef off_t aliased_off_t FIX_ALIASING;
|
||||
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (strncmp(cp, "/../"+1, 3) == 0) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
@@ -85,9 +115,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
*/
|
||||
p += len;
|
||||
sz -= len;
|
||||
if (
|
||||
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
|
||||
(int)(sz|len) < 0 /* this works */
|
||||
if ((int)sz < 0
|
||||
|| len == 0
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
@@ -105,7 +133,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
value = end + 1;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (!global && is_prefixed_with(value, "path=")) {
|
||||
if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
|
||||
value += sizeof("path=") - 1;
|
||||
free(archive_handle->tar__longname);
|
||||
archive_handle->tar__longname = xstrdup(value);
|
||||
@@ -118,7 +146,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
* This is what Red Hat's patched version of tar uses.
|
||||
*/
|
||||
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
|
||||
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
|
||||
if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
|
||||
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
|
||||
free(archive_handle->tar__sctx[global]);
|
||||
archive_handle->tar__sctx[global] = xstrdup(value);
|
||||
@@ -202,7 +230,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
if (!is_prefixed_with(tar.magic, "ustar")
|
||||
if (strncmp(tar.magic, "ustar", 5) != 0
|
||||
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
) {
|
||||
@@ -213,7 +241,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* or not first block (false positive, it's not .gz/.bz2!) */
|
||||
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
|
||||
err:
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
archive_handle->offset = 0;
|
||||
@@ -350,14 +378,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
goto size0;
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
|
||||
case 'L':
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(p_longname);
|
||||
@@ -377,17 +398,18 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += file_header->size;
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again;
|
||||
/*
|
||||
* case 'S': // Sparse file
|
||||
* Was seen in the wild. Not supported (yet?).
|
||||
* See https://www.gnu.org/software/tar/manual/html_section/tar_92.html
|
||||
* for the format. (An "Old GNU Format" was seen, not PAX formats).
|
||||
*/
|
||||
// case 'D': /* GNU dump dir */
|
||||
// case 'M': /* Continuation of multi volume archive */
|
||||
// case 'N': /* Old GNU for names > 100 characters */
|
||||
// case 'V': /* Volume header */
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive */
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
#endif
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
}
|
||||
skip_ext_hdr:
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,7 @@ char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -71,6 +71,7 @@ typedef struct {
|
||||
uint8_t *out;
|
||||
|
||||
unsigned r1_lit;
|
||||
|
||||
} lzo1x_999_t;
|
||||
|
||||
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
|
||||
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
|
||||
{
|
||||
memset(xstate, 0, sizeof(*xstate));
|
||||
memset(aux, 0, sizeof(*aux));
|
||||
}
|
||||
|
||||
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
|
||||
{
|
||||
if (xstate->check_signature) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
bb_error_msg("invalid magic");
|
||||
#if 0 /* possible future extension */
|
||||
if (xstate->check_signature > 1)
|
||||
if (aux->check_signature > 1)
|
||||
xfunc_die();
|
||||
#endif
|
||||
return -1;
|
||||
@@ -27,47 +27,6 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
|
||||
if (xstate->mem_output_size_max != 0) {
|
||||
size_t pos = xstate->mem_output_size;
|
||||
size_t size;
|
||||
|
||||
size = (xstate->mem_output_size += bufsize);
|
||||
if (size > xstate->mem_output_size_max) {
|
||||
free(xstate->mem_output_buf);
|
||||
xstate->mem_output_buf = NULL;
|
||||
bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
|
||||
memcpy(xstate->mem_output_buf + pos, buf, bufsize);
|
||||
xstate->mem_output_buf[size] = '\0';
|
||||
nwrote = bufsize;
|
||||
} else {
|
||||
nwrote = full_write(xstate->dst_fd, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
bb_perror_msg("write");
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
ret:
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote = transformer_write(xstate, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
xfunc_die();
|
||||
}
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
void check_errors_in_children(int signo)
|
||||
{
|
||||
int status;
|
||||
@@ -101,12 +60,12 @@ void check_errors_in_children(int signo)
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
#if BB_MMU
|
||||
void FAST_FUNC fork_transformer(int fd,
|
||||
void FAST_FUNC open_transformer(int fd,
|
||||
int check_signature,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
)
|
||||
#else
|
||||
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
#endif
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
@@ -121,12 +80,10 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = check_signature;
|
||||
xstate.src_fd = fd;
|
||||
xstate.dst_fd = fd_pipe.wr;
|
||||
r = transformer(&xstate);
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = check_signature;
|
||||
r = transformer(&aux, fd, fd_pipe.wr);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* send EOF */
|
||||
close(fd);
|
||||
@@ -161,19 +118,16 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
{
|
||||
union {
|
||||
uint8_t b[4];
|
||||
uint16_t b16[2];
|
||||
uint32_t b32[1];
|
||||
} magic;
|
||||
int offset;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
offset = -2;
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
int offset = -2;
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
/* .gz and .bz2 both have 2-byte signature, and their
|
||||
* unpack_XXX_stream wants this header skipped. */
|
||||
@@ -181,22 +135,15 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& magic.b16[0] == GZIP_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_gz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_Z
|
||||
&& magic.b16[0] == COMPRESS_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_Z_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
|
||||
USE_FOR_MMU(xformer = unpack_gz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_bz2_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
|
||||
USE_FOR_MMU(xformer = unpack_bz2_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
@@ -205,146 +152,68 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
offset = -6;
|
||||
xread(fd, magic.b32, sizeof(magic.b32[0]));
|
||||
if (magic.b32[0] == XZ_MAGIC2) {
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
}
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (fail_if_not_compressed)
|
||||
if (fail_if_not_detected)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
IF_FEATURE_SEAMLESS_XZ("/xz")
|
||||
" magic");
|
||||
|
||||
/* Some callers expect this function to "consume" fd
|
||||
* even if data is not compressed. In this case,
|
||||
* we return a state with trivial transformer.
|
||||
*/
|
||||
// USE_FOR_MMU(xstate->xformer = copy_stream;)
|
||||
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
|
||||
/* fall through to seeking bck over bytes we read earlier */
|
||||
|
||||
USE_FOR_NOMMU(found_magic:)
|
||||
/* NOMMU version of fork_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
return 1;
|
||||
|
||||
USE_FOR_MMU(found_magic:)
|
||||
/* In MMU case, if magic was found, seeking back is not necessary */
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
if (!xstate || !xstate->xformer) {
|
||||
free(xstate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
found_magic:
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
open_transformer_with_no_sig(fd, xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
/* NOMMU version of open_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file */
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
open_transformer_with_sig(fd, xformer, xformer_prog);
|
||||
# endif
|
||||
free(xstate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
|
||||
int FAST_FUNC open_zipped(const char *fname)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
return fd;
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
return xstate;
|
||||
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, fail_if_not_compressed);
|
||||
if (!xstate)
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
if (xstate->xformer) {
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
# endif
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
}
|
||||
/* else: the file is not compressed */
|
||||
|
||||
free(xstate);
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
|
||||
void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
|
||||
{
|
||||
# if 1
|
||||
transformer_state_t *xstate;
|
||||
char *image;
|
||||
|
||||
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (!xstate) /* file open error */
|
||||
return NULL;
|
||||
|
||||
image = NULL;
|
||||
if (xstate->xformer) {
|
||||
/* In-memory decompression */
|
||||
xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
|
||||
xstate->xformer(xstate);
|
||||
if (xstate->mem_output_buf) {
|
||||
image = xstate->mem_output_buf;
|
||||
if (maxsz_p)
|
||||
*maxsz_p = xstate->mem_output_size;
|
||||
}
|
||||
} else {
|
||||
/* File is not compressed */
|
||||
image = xmalloc_read(xstate->src_fd, maxsz_p);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(xstate->src_fd);
|
||||
free(xstate);
|
||||
return image;
|
||||
# else
|
||||
/* This version forks a subprocess - much more expensive */
|
||||
int fd;
|
||||
char *image;
|
||||
|
||||
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
|
||||
fd = open_zipped(fname);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -352,8 +221,6 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(fd);
|
||||
return image;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
return image;
|
||||
}
|
||||
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
char magic[7];
|
||||
|
||||
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
|
||||
if (!is_prefixed_with(magic, AR_MAGIC)) {
|
||||
if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += AR_MAGIC_LEN;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (is_prefixed_with(cp, "/../"+1)) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
@@ -995,8 +995,10 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
s->lzma2.need_props = false;
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_PROPERTIES;
|
||||
|
||||
} else if (s->lzma2.need_props) {
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
} else {
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_LZMA_PREPARE;
|
||||
@@ -1078,6 +1080,7 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
|
||||
rc_reset(&s->rc);
|
||||
s->lzma2.sequence = SEQ_CONTROL;
|
||||
|
||||
} else if (b->out_pos == b->out_size
|
||||
|| (b->in_pos == b->in_size
|
||||
&& s->temp.size
|
||||
|
||||
@@ -353,6 +353,7 @@ static enum xz_ret XZ_FUNC crc32_validate(struct xz_dec *s, struct xz_buf *b)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->pos += 8;
|
||||
|
||||
} while (s->pos < 32);
|
||||
|
||||
s->crc32 = 0;
|
||||
@@ -752,6 +753,7 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_run(struct xz_dec *s, struct xz_buf *b)
|
||||
b->in_pos = in_start;
|
||||
b->out_pos = out_start;
|
||||
}
|
||||
|
||||
} else if (ret == XZ_OK && in_start == b->in_pos
|
||||
&& out_start == b->out_pos) {
|
||||
if (s->allow_buf_error)
|
||||
|
||||
+1
-1
@@ -1099,7 +1099,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
|
||||
return xasprintf("%s.lzo", filename);
|
||||
}
|
||||
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM)
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
if (option_mask32 & OPT_DECOMPRESS)
|
||||
return do_lzo_decompress();
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* This works, but doesn't report uncompress errors (they happen in child) */
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
|
||||
|
||||
+45
-33
@@ -160,6 +160,13 @@
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
/*
|
||||
@@ -614,12 +621,21 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
# endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
# define WAIT_FOR_CHILD 0
|
||||
@@ -633,6 +649,11 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
# endif
|
||||
|
||||
gzipPid = xvfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
@@ -648,7 +669,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(gzip, gzip, "-f", (char *)0);
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -671,21 +692,16 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", gzip);
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
}
|
||||
}
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
|
||||
|
||||
#if !SEAMLESS_COMPRESSION
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
/* gcc 4.2.1 inlines it, making code bigger */
|
||||
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, const char *gzip)
|
||||
const llist_t *exclude, int gzip)
|
||||
{
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
@@ -698,7 +714,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
* can avoid including the tarball into itself.... */
|
||||
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
#endif
|
||||
@@ -733,7 +749,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip) {
|
||||
int status;
|
||||
if (safe_waitpid(-1, &status, 0) == -1)
|
||||
@@ -745,9 +761,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
#endif
|
||||
return errorFlag;
|
||||
}
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
# define writeTarFile(...) 0
|
||||
#endif
|
||||
#else
|
||||
int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -1119,7 +1137,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
tar_handle->src_fd = open_zipped(tar_filename);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
@@ -1131,24 +1149,18 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if SEAMLESS_COMPRESSION
|
||||
const char *zipMode = NULL;
|
||||
if (opt & OPT_COMPRESS)
|
||||
zipMode = "compress";
|
||||
if (opt & OPT_GZIP)
|
||||
zipMode = "gzip";
|
||||
if (opt & OPT_BZIP2)
|
||||
zipMode = "bzip2";
|
||||
if (opt & OPT_LZMA)
|
||||
zipMode = "lzma";
|
||||
if (opt & OPT_XZ)
|
||||
zipMode = "xz";
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
|
||||
zipMode = 2;
|
||||
#endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag,
|
||||
@@ -1159,7 +1171,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (opt & OPT_ANY_COMPRESS) {
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
if (opt & OPT_COMPRESS)
|
||||
@@ -1178,7 +1190,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
|
||||
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
/* Can't lseek over pipes */
|
||||
tar_handle->seek = seek_by_read;
|
||||
/*tar_handle->offset = 0; - already is */
|
||||
|
||||
+19
-32
@@ -280,19 +280,17 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.bytes_in = zip_header->formatted.cmpsize;
|
||||
xstate.src_fd = zip_fd;
|
||||
xstate.dst_fd = dst_fd;
|
||||
if (inflate_unzip(&xstate) < 0)
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.bytes_in = zip_header->formatted.cmpsize;
|
||||
if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
@@ -596,17 +594,14 @@ int unzip_main(int argc, char **argv)
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
} else {
|
||||
if (listing) {
|
||||
/* List entry */
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
@@ -642,11 +637,9 @@ int unzip_main(int argc, char **argv)
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) {
|
||||
/* Extracting to STDOUT */
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
} else if (last_char_is(dst_fn, '/')) {
|
||||
/* Extract directory */
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
@@ -660,26 +653,22 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "directory");
|
||||
bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
|
||||
}
|
||||
}
|
||||
i = 'n';
|
||||
} else {
|
||||
/* Extract file */
|
||||
|
||||
} else { /* Extract file */
|
||||
check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
/* File does not exist */
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
} else {
|
||||
/* File already exists */
|
||||
} else { /* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is regular file */
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} else {
|
||||
@@ -687,10 +676,8 @@ int unzip_main(int argc, char **argv)
|
||||
my_fgets80(key_buf);
|
||||
i = key_buf[0];
|
||||
}
|
||||
} else {
|
||||
/* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "regular file");
|
||||
} else { /* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+71
-114
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.24.0.git
|
||||
# Fri Sep 18 20:39:29 2015
|
||||
# Busybox version: 1.21.0.git
|
||||
# Mon May 28 21:51:18 2012
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -36,15 +36,12 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
|
||||
# CONFIG_UNICODE_BIDI_SUPPORT is not set
|
||||
# CONFIG_UNICODE_NEUTRAL_TABLE is not set
|
||||
# CONFIG_UNICODE_PRESERVE_BROKEN is not set
|
||||
# CONFIG_PAM is not set
|
||||
CONFIG_FEATURE_USE_SENDFILE=y
|
||||
CONFIG_LONG_OPTS=y
|
||||
# CONFIG_FEATURE_DEVPTS is not set
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
# CONFIG_FEATURE_UTMP is not set
|
||||
# CONFIG_FEATURE_WTMP is not set
|
||||
# CONFIG_FEATURE_PIDFILE is not set
|
||||
CONFIG_PID_FILE_PATH=""
|
||||
# CONFIG_FEATURE_SUID is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
@@ -66,7 +63,7 @@ CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_LFS is not set
|
||||
CONFIG_CROSS_COMPILER_PREFIX="arm-linux-androideabi-"
|
||||
CONFIG_SYSROOT="/opt/android-ndk/platforms/android-9/arch-arm"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers -fuse-ld=bfd"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers"
|
||||
CONFIG_EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o"
|
||||
CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
|
||||
@@ -75,7 +72,6 @@ CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
# CONFIG_DEBUG_PESSIMIZE is not set
|
||||
# CONFIG_UNIT_TEST is not set
|
||||
# CONFIG_WERROR is not set
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
@@ -100,7 +96,6 @@ CONFIG_PREFIX="./_install"
|
||||
# CONFIG_FEATURE_RTMINMAX is not set
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
CONFIG_SHA3_SMALL=1
|
||||
# CONFIG_FEATURE_FAST_TOP is not set
|
||||
# CONFIG_FEATURE_ETC_NETWORKS is not set
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
@@ -138,14 +133,7 @@ CONFIG_FEATURE_SEAMLESS_Z=y
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_FEATURE_AR_CREATE=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
@@ -153,14 +141,14 @@ CONFIG_FEATURE_CPIO_P=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_GZIP=y
|
||||
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
|
||||
CONFIG_GZIP_FAST=0
|
||||
# CONFIG_FEATURE_GZIP_LEVELS is not set
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
CONFIG_FEATURE_TAR_AUTODETECT=y
|
||||
@@ -173,6 +161,12 @@ CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
# CONFIG_FEATURE_TAR_SELINUX is not set
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_UNZIP=y
|
||||
|
||||
#
|
||||
@@ -184,27 +178,16 @@ CONFIG_CAT=y
|
||||
# CONFIG_FEATURE_DATE_ISOFMT is not set
|
||||
# CONFIG_FEATURE_DATE_NANO is not set
|
||||
# CONFIG_FEATURE_DATE_COMPAT is not set
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_FEATURE_DD_STATUS=y
|
||||
# CONFIG_HOSTID is not set
|
||||
# CONFIG_ID is not set
|
||||
# CONFIG_GROUPS is not set
|
||||
CONFIG_SHUF=y
|
||||
CONFIG_SYNC=y
|
||||
# CONFIG_FEATURE_SYNC_FANCY is not set
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_UNLINK=y
|
||||
CONFIG_BASE64=y
|
||||
# CONFIG_WHO is not set
|
||||
# CONFIG_USERS is not set
|
||||
@@ -220,6 +203,10 @@ CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
# CONFIG_FEATURE_CP_LONG_OPTIONS is not set
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
# CONFIG_DF is not set
|
||||
# CONFIG_FEATURE_DF_FANCY is not set
|
||||
CONFIG_DIRNAME=y
|
||||
@@ -276,7 +263,6 @@ CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SHA3SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_FEATURE_FLOAT_SLEEP=y
|
||||
@@ -288,6 +274,7 @@ CONFIG_FEATURE_SPLIT_FANCY=y
|
||||
# CONFIG_FEATURE_STAT_FORMAT is not set
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
@@ -296,7 +283,6 @@ CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
|
||||
CONFIG_TRUE=y
|
||||
# CONFIG_TTY is not set
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNAME_OSNAME="GNU/Linux"
|
||||
CONFIG_UNEXPAND=y
|
||||
# CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS is not set
|
||||
CONFIG_UNIQ=y
|
||||
@@ -308,11 +294,6 @@ CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_YES=y
|
||||
|
||||
#
|
||||
# Common options
|
||||
#
|
||||
CONFIG_FEATURE_VERBOSE=y
|
||||
|
||||
#
|
||||
# Common options for cp and mv
|
||||
#
|
||||
@@ -329,7 +310,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -375,16 +356,7 @@ CONFIG_WHICH=y
|
||||
#
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_FEATURE_AWK_GNU_EXTENSIONS=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_MAX_LEN=4096
|
||||
CONFIG_FEATURE_VI_8BIT=y
|
||||
@@ -399,9 +371,14 @@ CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_ASK_TERMINAL=y
|
||||
CONFIG_FEATURE_VI_UNDO=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
@@ -418,7 +395,6 @@ CONFIG_FEATURE_FIND_MAXDEPTH=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
CONFIG_FEATURE_FIND_EXEC_PLUS=y
|
||||
CONFIG_FEATURE_FIND_USER=y
|
||||
CONFIG_FEATURE_FIND_GROUP=y
|
||||
CONFIG_FEATURE_FIND_NOT=y
|
||||
@@ -440,7 +416,6 @@ CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y
|
||||
|
||||
#
|
||||
# Init Utilities
|
||||
@@ -472,12 +447,11 @@ CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
# CONFIG_FEATURE_SHADOWPASSWDS is not set
|
||||
# CONFIG_USE_BB_PWD_GRP is not set
|
||||
# CONFIG_USE_BB_SHADOW is not set
|
||||
CONFIG_USE_BB_CRYPT=y
|
||||
CONFIG_USE_BB_CRYPT_SHA=y
|
||||
# CONFIG_USE_BB_CRYPT is not set
|
||||
# CONFIG_USE_BB_CRYPT_SHA is not set
|
||||
# CONFIG_ADDUSER is not set
|
||||
# CONFIG_FEATURE_ADDUSER_LONG_OPTIONS is not set
|
||||
# CONFIG_FEATURE_CHECK_NAMES is not set
|
||||
CONFIG_LAST_ID=0
|
||||
CONFIG_FIRST_SYSTEM_ID=0
|
||||
CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_ADDGROUP is not set
|
||||
@@ -489,6 +463,7 @@ CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_GETTY is not set
|
||||
# CONFIG_LOGIN is not set
|
||||
# CONFIG_LOGIN_SESSION_AS_CHILD is not set
|
||||
# CONFIG_PAM is not set
|
||||
# CONFIG_LOGIN_SCRIPTS is not set
|
||||
# CONFIG_FEATURE_NOLOGIN is not set
|
||||
# CONFIG_FEATURE_SECURETTY is not set
|
||||
@@ -546,26 +521,13 @@ CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
|
||||
# Linux System Utilities
|
||||
#
|
||||
CONFIG_BLOCKDEV=y
|
||||
CONFIG_FATATTR=y
|
||||
CONFIG_FSTRIM=y
|
||||
# CONFIG_MDEV is not set
|
||||
# CONFIG_FEATURE_MDEV_CONF is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
|
||||
# CONFIG_FEATURE_MDEV_EXEC is not set
|
||||
# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_FEATURE_MOUNT_OTHERTAB is not set
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_REV=y
|
||||
CONFIG_UEVENT=y
|
||||
# CONFIG_ACPID is not set
|
||||
# CONFIG_FEATURE_ACPID_COMPAT is not set
|
||||
CONFIG_BLKID=y
|
||||
@@ -611,6 +573,15 @@ CONFIG_LSUSB=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_UUID=y
|
||||
CONFIG_MORE=y
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_PIVOT_ROOT is not set
|
||||
# CONFIG_RDATE is not set
|
||||
CONFIG_RDEV=y
|
||||
@@ -620,7 +591,6 @@ CONFIG_SCRIPT=y
|
||||
CONFIG_SCRIPTREPLAY=y
|
||||
# CONFIG_SETARCH is not set
|
||||
# CONFIG_SWAPONOFF is not set
|
||||
# CONFIG_FEATURE_SWAPON_DISCARD is not set
|
||||
# CONFIG_FEATURE_SWAPON_PRI is not set
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
# CONFIG_UMOUNT is not set
|
||||
@@ -633,45 +603,32 @@ CONFIG_VOLUMEID=y
|
||||
#
|
||||
# Filesystem/Volume identification
|
||||
#
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXFAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_F2FS=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ISO9660=y
|
||||
CONFIG_FEATURE_VOLUMEID_JFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NILFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SQUASHFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_XFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ISO9660=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
|
||||
|
||||
#
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
# CONFIG_CONSPY is not set
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_I2CGET=y
|
||||
CONFIG_I2CSET=y
|
||||
CONFIG_I2CDUMP=y
|
||||
CONFIG_I2CDETECT=y
|
||||
CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
CONFIG_FEATURE_LESS_BRACKETS=y
|
||||
CONFIG_FEATURE_LESS_FLAGS=y
|
||||
CONFIG_FEATURE_LESS_TRUNCATE=y
|
||||
CONFIG_FEATURE_LESS_MARKS=y
|
||||
CONFIG_FEATURE_LESS_REGEXP=y
|
||||
CONFIG_FEATURE_LESS_WINCH=y
|
||||
@@ -680,17 +637,13 @@ CONFIG_FEATURE_LESS_DASHCMD=y
|
||||
CONFIG_FEATURE_LESS_LINENUMS=y
|
||||
# CONFIG_NANDWRITE is not set
|
||||
CONFIG_NANDDUMP=y
|
||||
# CONFIG_RFKILL is not set
|
||||
CONFIG_SETSERIAL=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
# CONFIG_UBIATTACH is not set
|
||||
# CONFIG_UBIDETACH is not set
|
||||
# CONFIG_UBIMKVOL is not set
|
||||
# CONFIG_UBIRMVOL is not set
|
||||
# CONFIG_UBIRSVOL is not set
|
||||
# CONFIG_UBIUPDATEVOL is not set
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_ADJTIMEX is not set
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_FEATURE_COMPRESS_BBCONFIG=y
|
||||
@@ -706,6 +659,10 @@ CONFIG_FEATURE_CHAT_SEND_ESCAPES=y
|
||||
CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
CONFIG_FEATURE_DC_LIBM=y
|
||||
@@ -743,14 +700,18 @@ CONFIG_MAN=y
|
||||
# CONFIG_MT is not set
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
# CONFIG_READAHEAD is not set
|
||||
# CONFIG_RFKILL is not set
|
||||
# CONFIG_RUNLEVEL is not set
|
||||
CONFIG_RX=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_STRINGS=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_WATCHDOG is not set
|
||||
|
||||
#
|
||||
@@ -782,13 +743,13 @@ CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FEATURE_FTP_AUTHENTICATION=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
# CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
|
||||
# CONFIG_HOSTNAME is not set
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
@@ -845,7 +806,6 @@ CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
# CONFIG_NSLOOKUP is not set
|
||||
# CONFIG_NTPD is not set
|
||||
# CONFIG_FEATURE_NTPD_SERVER is not set
|
||||
# CONFIG_FEATURE_NTPD_CONF is not set
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
# CONFIG_SLATTACH is not set
|
||||
@@ -883,7 +843,6 @@ CONFIG_FEATURE_TUNCTL_UG=y
|
||||
CONFIG_DHCPD_LEASES_FILE=""
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
CONFIG_FEATURE_UDHCP_RFC3397=y
|
||||
@@ -930,13 +889,6 @@ CONFIG_POWERTOP=y
|
||||
CONFIG_PSTREE=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_SMEMCAP=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_UPTIME=y
|
||||
# CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set
|
||||
CONFIG_FREE=y
|
||||
@@ -957,6 +909,13 @@ CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
|
||||
# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
@@ -1002,7 +961,6 @@ CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_HELP is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
@@ -1052,7 +1010,6 @@ CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
|
||||
# CONFIG_LOGREAD is not set
|
||||
# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
|
||||
# CONFIG_FEATURE_KMSG_SYSLOG is not set
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_FEATURE_KLOGD_KLOGCTL=y
|
||||
# CONFIG_LOGGER is not set
|
||||
@@ -10,9 +10,8 @@
|
||||
//usage:#define loadkmap_trivial_usage
|
||||
//usage: "< keymap"
|
||||
//usage:#define loadkmap_full_usage "\n\n"
|
||||
//usage: "Load a binary keyboard translation table from stdin"
|
||||
////usage: "\n"
|
||||
////usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
//usage: "Load a binary keyboard translation table from stdin\n"
|
||||
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
||||
//usage:
|
||||
//usage:#define loadkmap_example_usage
|
||||
//usage: "$ loadkmap < /etc/i18n/lang-keymap\n"
|
||||
@@ -57,7 +56,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
|
||||
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
|
||||
bb_error_msg_and_die("not a valid binary keymap");
|
||||
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
//usage:#define setlogcons_trivial_usage
|
||||
//usage: "[N]"
|
||||
//usage: "N"
|
||||
//usage:#define setlogcons_full_usage "\n\n"
|
||||
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
|
||||
//usage: "Redirect the kernel output to console N (0 for current)"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (04 /*CTRL-D*/ == c)
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// we assume a PC keyboard
|
||||
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
|
||||
|
||||
+46
-21
@@ -11,7 +11,7 @@ config CAL
|
||||
bool "cal"
|
||||
default y
|
||||
help
|
||||
cal is used to display a monthly calendar.
|
||||
cal is used to display a monthly calender.
|
||||
|
||||
config CATV
|
||||
bool "catv"
|
||||
@@ -87,6 +87,44 @@ config CUT
|
||||
cut is used to print selected parts of lines from
|
||||
each file to stdout.
|
||||
|
||||
config DD
|
||||
bool "dd"
|
||||
default y
|
||||
help
|
||||
dd copies a file (from standard input to standard output,
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
|
||||
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_THIRD_STATUS_LINE
|
||||
bool "Enable the third status line upon signal"
|
||||
default y
|
||||
depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
help
|
||||
Displays a coreutils-like third status line with transferred bytes,
|
||||
elapsed time and speed.
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
default y
|
||||
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 y
|
||||
@@ -571,6 +609,12 @@ config SUM
|
||||
help
|
||||
checksum and count the blocks in a file
|
||||
|
||||
config SYNC
|
||||
bool "sync"
|
||||
default y
|
||||
help
|
||||
sync is used to flush filesystem buffers.
|
||||
|
||||
config TAC
|
||||
bool "tac"
|
||||
default y
|
||||
@@ -589,13 +633,12 @@ config FEATURE_FANCY_TAIL
|
||||
default y
|
||||
depends on TAIL
|
||||
help
|
||||
The options (-q, -s, -v and -F) are provided by GNU tail, but
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
-q Never output headers giving file names
|
||||
-s SEC Wait SEC seconds between reads with -f
|
||||
-v Always output headers giving file names
|
||||
-F Same as -f, but keep retrying
|
||||
|
||||
config TEE
|
||||
bool "tee"
|
||||
@@ -630,14 +673,6 @@ config UNAME
|
||||
help
|
||||
uname is used to print system information.
|
||||
|
||||
config UNAME_OSNAME
|
||||
string "Operating system name"
|
||||
default "GNU/Linux"
|
||||
depends on UNAME
|
||||
help
|
||||
Sets the operating system name reported by uname -o. The
|
||||
default is "GNU/Linux".
|
||||
|
||||
config UNEXPAND
|
||||
bool "unexpand"
|
||||
default y
|
||||
@@ -703,16 +738,6 @@ config YES
|
||||
yes is used to repeatedly output a specific string, or
|
||||
the default string `y'.
|
||||
|
||||
comment "Common options"
|
||||
|
||||
config FEATURE_VERBOSE
|
||||
bool "Support verbose options (usually -v) for various applets"
|
||||
default y
|
||||
help
|
||||
Enable cp -v, rm -v and similar messages.
|
||||
Also enables long option (--verbose) if it exists.
|
||||
Without this option, -v is accepted but ignored.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CP || MV
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ 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_TAC) += tac.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
//usage:#define basename_trivial_usage
|
||||
//usage: "FILE [SUFFIX]"
|
||||
//usage:#define basename_full_usage "\n\n"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE\n"
|
||||
//usage:
|
||||
//usage:#define basename_example_usage
|
||||
//usage: "$ basename /usr/local/bin/foo\n"
|
||||
|
||||
+8
-10
@@ -20,22 +20,20 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
struct BUG_const_mismatch {
|
||||
char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
};
|
||||
|
||||
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
unsigned opts;
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
typedef char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
|
||||
opts = getopt32(argv, "etv");
|
||||
argv += optind;
|
||||
#if 0 /* These consts match, we can just pass "opts" to visible() */
|
||||
|
||||
+2
-2
@@ -69,9 +69,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
|
||||
if (S_ISLNK(statbuf->st_mode))
|
||||
return TRUE;
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
newmode = bb_parse_mode((char *)param, statbuf->st_mode);
|
||||
if (newmode == (mode_t)-1)
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
bb_error_msg_and_die("invalid mode '%s'", (char *)param);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
|
||||
+2
-2
@@ -11,15 +11,15 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
//usage:#define chown_trivial_usage
|
||||
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... OWNER[<.|:>[GROUP]] FILE..."
|
||||
//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... OWNER[<.|:>[GROUP]] FILE..."
|
||||
//usage:#define chown_full_usage "\n\n"
|
||||
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: "\n -h Affect symlinks instead of symlink targets"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -L Traverse all symlinks to directories"
|
||||
//usage: "\n -H Traverse symlinks on command line only"
|
||||
//usage: "\n -P Don't traverse symlinks (default)"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
|
||||
@@ -79,6 +79,7 @@ int cp_main(int argc, char **argv)
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
|
||||
+1
-1
@@ -373,7 +373,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
date_buf[0] = '\0';
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
if (is_prefixed_with(fmt_dt2str, "%f")) {
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
/* Generate output string */
|
||||
|
||||
+49
-109
@@ -8,51 +8,6 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DD
|
||||
//config: bool "dd"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dd copies a file (from standard input to standard output,
|
||||
//config: by default) using specific input and output blocksizes,
|
||||
//config: while optionally performing conversions on it.
|
||||
//config:
|
||||
//config:config FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: bool "Enable signal handling for status reporting"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
//config: print to standard error the number of records read and written
|
||||
//config: so far, then to resume copying.
|
||||
//config:
|
||||
//config: $ dd if=/dev/zero of=/dev/null &
|
||||
//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
|
||||
//config: 10899206+0 records in
|
||||
//config: 10899206+0 records out
|
||||
//config:
|
||||
//config:config FEATURE_DD_THIRD_STATUS_LINE
|
||||
//config: bool "Enable the third status line upon signal"
|
||||
//config: default y
|
||||
//config: depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: help
|
||||
//config: Displays a coreutils-like third status line with transferred bytes,
|
||||
//config: elapsed time and speed.
|
||||
//config:
|
||||
//config:config FEATURE_DD_IBS_OBS
|
||||
//config: bool "Enable ibs, obs and conv options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for writing a certain number of bytes in and out,
|
||||
//config: at a time, and performing conversions on the data stream.
|
||||
//config:
|
||||
//config:config FEATURE_DD_STATUS
|
||||
//config: bool "Enable status display options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for status=noxfer/none option.
|
||||
|
||||
//usage:#define dd_trivial_usage
|
||||
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
|
||||
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]")
|
||||
@@ -77,12 +32,8 @@
|
||||
//usage: "\n conv=fsync Physically write data out before finishing"
|
||||
//usage: "\n conv=swab Swap every pair of bytes"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_DD_STATUS(
|
||||
//usage: "\n status=noxfer Suppress rate output"
|
||||
//usage: "\n status=none Suppress all output"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kD (1000), k (1024), MD, M, GD, G"
|
||||
//usage:
|
||||
//usage:#define dd_example_usage
|
||||
//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
|
||||
@@ -99,13 +50,26 @@ enum {
|
||||
ofd = STDOUT_FILENO,
|
||||
};
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
{ "b", 512 },
|
||||
{ "kD", 1000 },
|
||||
{ "k", 1024 },
|
||||
{ "K", 1024 }, /* compat with coreutils dd */
|
||||
{ "MD", 1000000 },
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
unsigned long long total_bytes;
|
||||
unsigned long long begin_time_us;
|
||||
#endif
|
||||
int flags;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
@@ -113,21 +77,6 @@ struct globals {
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
} while (0)
|
||||
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
FLAG_STATUS = 1 << 7,
|
||||
FLAG_STATUS_NONE = 1 << 7,
|
||||
FLAG_STATUS_NOXFER = 1 << 8,
|
||||
};
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
{
|
||||
@@ -144,13 +93,6 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
G.out_full, G.out_part);
|
||||
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
# if ENABLE_FEATURE_DD_STATUS
|
||||
if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */
|
||||
return;
|
||||
//TODO: should status=none make dd stop reacting to USR1 entirely?
|
||||
//So far we react to it (we print the stats),
|
||||
//status=none only suppresses final, non-USR1 generated status message.
|
||||
# endif
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
@@ -206,8 +148,20 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs\0""obs\0""conv\0"
|
||||
#endif
|
||||
@@ -215,10 +169,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
static const char status_words[] ALIGN1 =
|
||||
"none\0""noxfer\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 0,
|
||||
@@ -227,7 +177,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_skip,
|
||||
OP_if,
|
||||
OP_of,
|
||||
IF_FEATURE_DD_STATUS(OP_status,)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
OP_ibs,
|
||||
OP_obs,
|
||||
@@ -266,12 +215,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
size_t oc;
|
||||
ssize_t prev_read_size; /* for detecting swab failure */
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
@@ -307,11 +258,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (what == OP_ibs) {
|
||||
/* Must fit into positive ssize_t */
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
@@ -327,7 +278,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
n = index_in_strings(conv_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
G.flags |= (1 << n);
|
||||
flags |= (1 << n);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
@@ -337,22 +288,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
obs = ibs;
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
if (what == OP_count) {
|
||||
G.flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_seek) {
|
||||
seek = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
seek = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_skip) {
|
||||
skip = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
skip = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_if) {
|
||||
@@ -363,16 +314,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
if (what == OP_status) {
|
||||
int n;
|
||||
n = index_in_strings(status_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "status");
|
||||
G.flags |= FLAG_STATUS << n;
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
} /* end of "for (argv[i])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
@@ -380,7 +321,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
obuf = ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (ibs != obs) {
|
||||
G.flags |= FLAG_TWOBUFS;
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
#endif
|
||||
@@ -400,12 +341,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (outfile) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(G.flags & FLAG_NOTRUNC))
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(G.flags & FLAG_NOTRUNC)) {
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
@@ -436,7 +377,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
@@ -444,7 +385,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
break;
|
||||
if (n < 0) {
|
||||
/* "Bad block" */
|
||||
if (!(G.flags & FLAG_NOERROR))
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
bb_simple_perror_msg(infile);
|
||||
/* GNU dd with conv=noerror skips over bad blocks */
|
||||
@@ -453,7 +394,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if (G.flags & FLAG_SWAB) {
|
||||
if (flags & FLAG_SWAB) {
|
||||
uint16_t *p16;
|
||||
ssize_t n2;
|
||||
|
||||
@@ -478,12 +419,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (G.flags & FLAG_SYNC) {
|
||||
if (flags & FLAG_SYNC) {
|
||||
memset(ibuf + n, 0, ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
if (G.flags & FLAG_TWOBUFS) {
|
||||
if (flags & FLAG_TWOBUFS) {
|
||||
char *tmp = ibuf;
|
||||
while (n) {
|
||||
size_t d = obs - oc;
|
||||
@@ -505,7 +446,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto out_status;
|
||||
}
|
||||
|
||||
if (G.flags & FLAG_FSYNC) {
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
@@ -527,12 +468,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
out_status:
|
||||
if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
|
||||
dd_output_status(0);
|
||||
dd_output_status(0);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
free(obuf);
|
||||
if (G.flags & FLAG_TWOBUFS)
|
||||
if (flags & FLAG_TWOBUFS)
|
||||
free(ibuf);
|
||||
}
|
||||
|
||||
|
||||
+8
-28
@@ -25,7 +25,6 @@
|
||||
//usage:#define df_trivial_usage
|
||||
//usage: "[-Pk"
|
||||
//usage: IF_FEATURE_HUMAN_READABLE("mh")
|
||||
//usage: "T"
|
||||
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
|
||||
//usage: "] [FILESYSTEM]..."
|
||||
//usage:#define df_full_usage "\n\n"
|
||||
@@ -36,7 +35,6 @@
|
||||
//usage: "\n -m 1M-byte blocks"
|
||||
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: "\n -T Print filesystem type"
|
||||
//usage: IF_FEATURE_DF_FANCY(
|
||||
//usage: "\n -a Show all filesystems"
|
||||
//usage: "\n -i Inodes"
|
||||
@@ -85,12 +83,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
@@ -102,7 +99,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kPT"
|
||||
opt = getopt32(argv, "kP"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
IF_FEATURE_DF_FANCY(, &chp));
|
||||
@@ -137,11 +134,8 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
|
||||
(opt & OPT_FSTYPE) ? "Type " : "",
|
||||
disp_units_hdr,
|
||||
(opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
printf("Filesystem %-15sUsed Available %s Mounted on\n",
|
||||
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -154,7 +148,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
const char *fs_type;
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -177,7 +170,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
device = mount_entry->mnt_fsname;
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
@@ -226,22 +218,10 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
|
||||
}
|
||||
free(uni_dev);
|
||||
if (opt & OPT_FSTYPE) {
|
||||
char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
|
||||
if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
|
||||
printf(" %s\n%31s", uni_type, "");
|
||||
else
|
||||
printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
|
||||
free(uni_type);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
|
||||
printf("\n%-20s", "");
|
||||
if (opt & OPT_FSTYPE) {
|
||||
if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
|
||||
printf("\n%-30s", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned buflen;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = 0, /* 0 -- disable escape sequences */
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
|
||||
|
||||
+5
-3
@@ -10,9 +10,11 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */
|
||||
|
||||
/* "false --help" is special-cased to ignore --help */
|
||||
//usage:#define false_trivial_usage NOUSAGE_STR
|
||||
//usage:#define false_full_usage ""
|
||||
//usage:#define false_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define false_full_usage "\n\n"
|
||||
//usage: "Return an exit code of FALSE (1)"
|
||||
//usage:
|
||||
//usage:#define false_example_usage
|
||||
//usage: "$ false\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
+19
-34
@@ -8,7 +8,7 @@
|
||||
|
||||
/* -v, -b, -c are ignored */
|
||||
//usage:#define install_trivial_usage
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
|
||||
//usage:#define install_full_usage "\n\n"
|
||||
//usage: "Copy files and set attributes\n"
|
||||
//usage: "\n -c Just copy (default)"
|
||||
@@ -19,7 +19,6 @@
|
||||
//usage: "\n -o USER Set ownership"
|
||||
//usage: "\n -g GRP Set group ownership"
|
||||
//usage: "\n -m MODE Set permissions"
|
||||
//usage: "\n -t DIR Install to DIR"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -Z Set security context"
|
||||
//usage: )
|
||||
@@ -29,16 +28,12 @@
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
static const char install_longopts[] ALIGN1 =
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
"directory\0" No_argument "d"
|
||||
"preserve-timestamps\0" No_argument "p"
|
||||
"strip\0" No_argument "s"
|
||||
"group\0" Required_argument "g"
|
||||
"mode\0" Required_argument "m"
|
||||
"owner\0" Required_argument "o"
|
||||
"target-directory\0" Required_argument "t"
|
||||
/* autofs build insists of using -b --suffix=.orig */
|
||||
/* TODO? (short option for --suffix is -S) */
|
||||
#if ENABLE_SELINUX
|
||||
@@ -94,11 +89,11 @@ int install_main(int argc, char **argv)
|
||||
const char *gid_str;
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
int mkdir_flags = FILEUTILS_RECUR;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int opts;
|
||||
int min_args = 1;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int isdir;
|
||||
int isdir = 0;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
bool use_default_selinux_context = 1;
|
||||
@@ -114,22 +109,21 @@ int install_main(int argc, char **argv)
|
||||
OPT_GROUP = 1 << 7,
|
||||
OPT_MODE = 1 << 8,
|
||||
OPT_OWNER = 1 << 9,
|
||||
OPT_TARGET = 1 << 10,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str, &last
|
||||
IF_SELINUX(, &scontext));
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@@ -147,11 +141,6 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
|
||||
mkdir_flags |= FILEUTILS_VERBOSE;
|
||||
copy_flags |= FILEUTILS_VERBOSE;
|
||||
}
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour,
|
||||
* BSD only preserves modification time */
|
||||
if (opts & OPT_PRESERVE_TIME) {
|
||||
@@ -159,41 +148,37 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
mode = 0755; /* GNU coreutils 6.10 compat */
|
||||
if (opts & OPT_MODE)
|
||||
mode = bb_parse_mode(mode_str, mode);
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
/* If -t DIR is in use, then isdir=true, last="DIR" */
|
||||
isdir = (opts & OPT_TARGET);
|
||||
if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
|
||||
/* Neither -t DIR nor -d is in use */
|
||||
argc--;
|
||||
last = argv[argc];
|
||||
argv[argc] = NULL;
|
||||
last = argv[argc - 1];
|
||||
if (!(opts & OPT_DIRECTORY)) {
|
||||
argv[argc - 1] = NULL;
|
||||
min_args++;
|
||||
|
||||
/* coreutils install resolves link in this case, don't use lstat */
|
||||
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
if (argc < min_args)
|
||||
bb_show_usage();
|
||||
|
||||
while ((arg = *argv++) != NULL) {
|
||||
char *dest;
|
||||
|
||||
char *dest = last;
|
||||
if (opts & OPT_DIRECTORY) {
|
||||
dest = arg;
|
||||
/* GNU coreutils 6.9 does not set uid:gid
|
||||
* on intermediate created directories
|
||||
* (only on last one) */
|
||||
if (bb_make_directory(dest, 0755, mkdir_flags)) {
|
||||
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
} else {
|
||||
dest = last;
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
|
||||
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created. */
|
||||
free(ddir);
|
||||
|
||||
@@ -33,9 +33,7 @@ mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
|
||||
int opt;
|
||||
opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode = bb_parse_mode(smode, mode);
|
||||
if (mode != (mode_t)-1) /* if mode is valid */
|
||||
/* make future mknod/mkfifo set mode bits exactly */
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
umask(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ int ln_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
free(src_name);
|
||||
|
||||
} while ((++argv)[1]);
|
||||
|
||||
return status;
|
||||
|
||||
+11
-14
@@ -566,12 +566,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
|
||||
char *filetime;
|
||||
const time_t *ttime = &dn->dn_mtime;
|
||||
time_t ttime = dn->dn_mtime;
|
||||
if (G.all_fmt & TIME_ACCESS)
|
||||
ttime = &dn->dn_atime;
|
||||
ttime = dn->dn_atime;
|
||||
if (G.all_fmt & TIME_CHANGE)
|
||||
ttime = &dn->dn_ctime;
|
||||
filetime = ctime(ttime);
|
||||
ttime = dn->dn_ctime;
|
||||
filetime = ctime(&ttime);
|
||||
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
|
||||
if (G.all_fmt & LIST_FULLTIME) { /* -e */
|
||||
/* Note: coreutils 8.4 ls --full-time prints:
|
||||
@@ -580,16 +580,13 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
column += printf("%.24s ", filetime);
|
||||
} else { /* LIST_DATE_TIME */
|
||||
/* G.current_time_t ~== time(NULL) */
|
||||
time_t age = G.current_time_t - *ttime;
|
||||
time_t age = G.current_time_t - ttime;
|
||||
printf("%.6s ", filetime + 4); /* "Jun 30" */
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* less than 6 months old */
|
||||
/* "mmm dd hh:mm " */
|
||||
printf("%.12s ", filetime + 4);
|
||||
} else {
|
||||
/* "mmm dd yyyy " */
|
||||
/* "mmm dd yyyyy " after year 9999 :) */
|
||||
strchr(filetime + 20, '\n')[0] = ' ';
|
||||
printf("%.7s%6s", filetime + 4, filetime + 20);
|
||||
/* hh:mm if less than 6 months old */
|
||||
printf("%.5s ", filetime + 11);
|
||||
} else { /* year. buggy if year > 9999 ;) */
|
||||
printf(" %.4s ", filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
@@ -1035,7 +1032,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
}
|
||||
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
|
||||
+4
-8
@@ -48,9 +48,7 @@ static const char mkdir_longopts[] ALIGN1 =
|
||||
#if ENABLE_SELINUX
|
||||
"context\0" Required_argument "Z"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_VERBOSE
|
||||
"verbose\0" No_argument "v"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -69,20 +67,18 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
||||
applet_long_options = mkdir_longopts;
|
||||
#endif
|
||||
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode_t mmode = bb_parse_mode(smode, 0777);
|
||||
if (mmode == (mode_t)-1) {
|
||||
mode_t mmode = 0777;
|
||||
if (!bb_parse_mode(smode, &mmode)) {
|
||||
bb_error_msg_and_die("invalid mode '%s'", smode);
|
||||
}
|
||||
mode = mmode;
|
||||
}
|
||||
if (opt & 2)
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 4) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 8) {
|
||||
if (opt & 4) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
|
||||
+1
-7
@@ -33,17 +33,13 @@ static const char mv_longopts[] ALIGN1 =
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
#endif
|
||||
|
||||
#define OPT_FORCE (1 << 0)
|
||||
#define OPT_INTERACTIVE (1 << 1)
|
||||
#define OPT_NOCLOBBER (1 << 2)
|
||||
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
|
||||
|
||||
|
||||
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mv_main(int argc, char **argv)
|
||||
@@ -62,6 +58,7 @@ int mv_main(int argc, char **argv)
|
||||
/* Need at least two arguments.
|
||||
* If more than one of -f, -i, -n is specified , only the final one
|
||||
* takes effect (it unsets previous options).
|
||||
* -v is accepted but ignored.
|
||||
*/
|
||||
opt_complementary = "-2:f-in:i-fn:n-fi";
|
||||
flags = getopt32(argv, "finv");
|
||||
@@ -151,9 +148,6 @@ int mv_main(int argc, char **argv)
|
||||
status = 1;
|
||||
}
|
||||
RET_0:
|
||||
if (flags & OPT_VERBOSE) {
|
||||
printf("'%s' -> '%s'\n", *argv, dest);
|
||||
}
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
|
||||
@@ -387,11 +387,11 @@ print_named_ascii(size_t n_bytes, const char *block,
|
||||
" sp"
|
||||
};
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
// actually " x\0 xxx\0", but want to share string with print_ascii.
|
||||
// [12] because we take three 32bit stack slots anyway, and
|
||||
// gcc is too dumb to initialize with constant stores,
|
||||
// it copies initializer from rodata. Oh well.
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410
|
||||
|
||||
while (n_bytes--) {
|
||||
unsigned masked_c = *(unsigned char *) block++;
|
||||
@@ -419,7 +419,7 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
const char *unused_fmt_string UNUSED_PARAM)
|
||||
{
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
|
||||
while (n_bytes--) {
|
||||
const char *s;
|
||||
@@ -455,9 +455,11 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
case '\v':
|
||||
s = " \\v";
|
||||
break;
|
||||
default:
|
||||
buf[6] = (c >> 6 & 3) + '0';
|
||||
buf[7] = (c >> 3 & 7) + '0';
|
||||
case '\x7f':
|
||||
s = " 177";
|
||||
break;
|
||||
default: /* c is never larger than 040 */
|
||||
buf[7] = (c >> 3) + '0';
|
||||
buf[8] = (c & 7) + '0';
|
||||
s = buf + 5;
|
||||
}
|
||||
|
||||
+1
-2
@@ -38,6 +38,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "f-i:i-f";
|
||||
/* -v (verbose) is ignored */
|
||||
opt = getopt32(argv, "fiRrv");
|
||||
argv += optind;
|
||||
if (opt & 1)
|
||||
@@ -46,8 +47,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FILEUTILS_INTERACTIVE;
|
||||
if (opt & (8|4))
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 16) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
|
||||
if (*argv != NULL) {
|
||||
do {
|
||||
|
||||
+2
-8
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#define PARENTS (1 << 0)
|
||||
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
|
||||
//efine VERBOSE (1 << 1) //accepted but ignored
|
||||
#define IGNORE_NON_EMPTY (1 << 2)
|
||||
|
||||
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -44,12 +44,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
static const char rmdir_longopts[] ALIGN1 =
|
||||
"parents\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
/* Debian etch: many packages fail to be purged or installed
|
||||
* because they desperately want this option: */
|
||||
"ignore-fail-on-non-empty\0" No_argument "\xff"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
applet_long_options = rmdir_longopts;
|
||||
#endif
|
||||
@@ -64,10 +62,6 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
path = *argv;
|
||||
|
||||
while (1) {
|
||||
if (flags & VERBOSE) {
|
||||
printf("rmdir: removing directory, '%s'\n", path);
|
||||
}
|
||||
|
||||
if (rmdir(path) < 0) {
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* shuf: Write a random permutation of the input lines to standard output.
|
||||
*
|
||||
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config SHUF
|
||||
//config: bool "shuf"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Generate random permutations
|
||||
|
||||
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
|
||||
//applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf))
|
||||
|
||||
//usage:#define shuf_trivial_usage
|
||||
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
|
||||
//usage:#define shuf_full_usage "\n\n"
|
||||
//usage: "Randomly permute lines\n"
|
||||
//usage: "\n -e Treat ARGs as lines"
|
||||
//usage: "\n -i L-H Treat numbers L-H as lines"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z End lines with zero byte, not newline"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#define OPT_e (1 << 0)
|
||||
#define OPT_i (1 << 1)
|
||||
#define OPT_n (1 << 2)
|
||||
#define OPT_o (1 << 3)
|
||||
#define OPT_z (1 << 4)
|
||||
#define OPT_STR "ei:n:o:z"
|
||||
|
||||
/*
|
||||
* Use the Fisher-Yates shuffle algorithm on an array of lines.
|
||||
*/
|
||||
static void shuffle_lines(char **lines, unsigned numlines)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned r;
|
||||
char *tmp;
|
||||
|
||||
srand(monotonic_us());
|
||||
|
||||
for (i = numlines-1; i > 0; i--) {
|
||||
r = rand();
|
||||
/* RAND_MAX can be as small as 32767 */
|
||||
if (i > RAND_MAX)
|
||||
r ^= rand() << 15;
|
||||
r %= i;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int shuf_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
char *opt_i_str, *opt_n_str, *opt_o_str;
|
||||
unsigned i;
|
||||
char **lines;
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opt_complementary = "e--i:i--e"; /* mutually exclusive */
|
||||
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Prepare lines for shuffling - either: */
|
||||
if (opts & OPT_e) {
|
||||
/* make lines from command-line arguments */
|
||||
numlines = argc;
|
||||
lines = argv;
|
||||
} else
|
||||
if (opts & OPT_i) {
|
||||
/* create a range of numbers */
|
||||
char *dash;
|
||||
unsigned lo, hi;
|
||||
|
||||
dash = strchr(opt_i_str, '-');
|
||||
if (!dash) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
*dash = '\0';
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
numlines = (hi+1) - lo;
|
||||
lines = xmalloc(numlines * sizeof(lines[0]));
|
||||
for (i = 0; i < numlines; i++) {
|
||||
lines[i] = (char*)(uintptr_t)lo;
|
||||
lo++;
|
||||
}
|
||||
} else {
|
||||
/* default - read lines from stdin or the input file */
|
||||
FILE *fp;
|
||||
|
||||
if (argc > 1)
|
||||
bb_show_usage();
|
||||
|
||||
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
|
||||
lines = NULL;
|
||||
numlines = 0;
|
||||
for (;;) {
|
||||
char *line = xmalloc_fgetline(fp);
|
||||
if (!line)
|
||||
break;
|
||||
lines = xrealloc_vector(lines, 6, numlines);
|
||||
lines[numlines++] = line;
|
||||
}
|
||||
fclose_if_not_stdin(fp);
|
||||
}
|
||||
|
||||
if (numlines != 0)
|
||||
shuffle_lines(lines, numlines);
|
||||
|
||||
if (opts & OPT_o)
|
||||
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
|
||||
if (opts & OPT_n) {
|
||||
unsigned maxlines;
|
||||
maxlines = xatou(opt_n_str);
|
||||
if (numlines > maxlines)
|
||||
numlines = maxlines;
|
||||
}
|
||||
|
||||
eol = '\n';
|
||||
if (opts & OPT_z)
|
||||
eol = '\0';
|
||||
|
||||
for (i = 0; i < numlines; i++) {
|
||||
if (opts & OPT_i)
|
||||
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
|
||||
else
|
||||
printf("%s%c", lines[i], eol);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+11
-29
@@ -25,14 +25,14 @@
|
||||
//usage: "\n -f Ignore case"
|
||||
//usage: "\n -g General numerical sort"
|
||||
//usage: "\n -i Ignore unprintable characters"
|
||||
//usage: "\n -k Sort key"
|
||||
//usage: "\n -M Sort month"
|
||||
//usage: )
|
||||
//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
|
||||
//usage: "\n -n Sort numbers"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
//usage: "\n -o Output to file"
|
||||
//usage: "\n -t CHAR Field separator"
|
||||
//usage: "\n -k N[,M] Sort by Nth field"
|
||||
//usage: "\n -k Sort by key"
|
||||
//usage: "\n -t CHAR Key separator"
|
||||
//usage: )
|
||||
//usage: "\n -r Reverse sort order"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
@@ -106,9 +106,7 @@ static struct sort_key {
|
||||
|
||||
static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
{
|
||||
int start = start; /* for compiler */
|
||||
int end;
|
||||
int len, j;
|
||||
int start = 0, end = 0, len, j;
|
||||
unsigned i;
|
||||
|
||||
/* Special case whole string, so we don't have to make a copy */
|
||||
@@ -125,15 +123,12 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
end = len;
|
||||
/* Loop through fields */
|
||||
else {
|
||||
unsigned char ch = 0;
|
||||
|
||||
end = 0;
|
||||
for (i = 1; i < key->range[2*j] + j; i++) {
|
||||
if (key_separator) {
|
||||
/* Skip body of key and separator */
|
||||
while ((ch = str[end]) != '\0') {
|
||||
end++;
|
||||
if (ch == key_separator)
|
||||
while (str[end]) {
|
||||
if (str[end++] == key_separator)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -141,21 +136,13 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
while (isspace(str[end]))
|
||||
end++;
|
||||
/* Skip body of key */
|
||||
while (str[end] != '\0') {
|
||||
while (str[end]) {
|
||||
if (isspace(str[end]))
|
||||
break;
|
||||
end++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Remove last delim: "abc:def:" => "abc:def" */
|
||||
if (j && ch) {
|
||||
//if (str[end-1] != key_separator)
|
||||
// bb_error_msg(_and_die("BUG! "
|
||||
// "str[start:%d,end:%d]:'%.*s'",
|
||||
// start, end, (int)(end-start), &str[start]);
|
||||
end--;
|
||||
}
|
||||
}
|
||||
if (!j) start = end;
|
||||
}
|
||||
@@ -176,8 +163,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
if (start > len) start = len;
|
||||
}
|
||||
/* Make the copy */
|
||||
if (end < start)
|
||||
end = start;
|
||||
if (end < start) end = start;
|
||||
str = xstrndup(str+start, end-start);
|
||||
/* Handle -d */
|
||||
if (flags & FLAG_d) {
|
||||
@@ -239,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
y = *(char **)yarg;
|
||||
#endif
|
||||
/* Perform actual comparison */
|
||||
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
|
||||
switch (flags & 7) {
|
||||
default:
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
break;
|
||||
@@ -316,14 +302,10 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
} /* for */
|
||||
|
||||
/* Perform fallback sort if necessary */
|
||||
if (!retval && !(option_mask32 & FLAG_s)) {
|
||||
if (!retval && !(option_mask32 & FLAG_s))
|
||||
retval = strcmp(*(char **)xarg, *(char **)yarg);
|
||||
flags = option_mask32;
|
||||
}
|
||||
|
||||
if (flags & FLAG_r)
|
||||
return -retval;
|
||||
|
||||
if (flags & FLAG_r) return -retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -374,7 +374,7 @@ static void print_it(const char *masterformat,
|
||||
{
|
||||
/* Create a working copy of the format string */
|
||||
char *format = xstrdup(masterformat);
|
||||
/* Add 2 to accommodate our conversion of the stat '%s' format string
|
||||
/* Add 2 to accomodate our conversion of the stat '%s' format string
|
||||
* to the printf '%llu' one. */
|
||||
char *dest = xmalloc(strlen(format) + 2 + 1);
|
||||
char *b;
|
||||
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
);
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" %s\n", scontext);
|
||||
printf(" %lc\n", *scontext);
|
||||
else
|
||||
bb_putchar('\n');
|
||||
# endif
|
||||
@@ -700,8 +700,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
(unsigned long) statbuf.st_gid,
|
||||
(gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" S_Context: %s\n", scontext);
|
||||
printf(" S_Context: %lc\n", *scontext);
|
||||
# endif
|
||||
printf("Access: %s\n", human_time(statbuf.st_atime));
|
||||
printf("Modify: %s\n", human_time(statbuf.st_mtime));
|
||||
|
||||
+3
-75
@@ -3,39 +3,16 @@
|
||||
* Mini sync implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
* Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||
//config:config SYNC
|
||||
//config: bool "sync"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: sync is used to flush filesystem buffers.
|
||||
//config:config FEATURE_SYNC_FANCY
|
||||
//config: bool "Enable -d and -f flags (requres syncfs(2) in libc)"
|
||||
//config: default y
|
||||
//config: depends on SYNC
|
||||
//config: help
|
||||
//config: sync -d FILE... executes fdatasync() on each FILE.
|
||||
//config: sync -f FILE... executes syncfs() on each FILE.
|
||||
|
||||
//kbuild:lib-$(CONFIG_SYNC) += sync.o
|
||||
//applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync))
|
||||
|
||||
//usage:#define sync_trivial_usage
|
||||
//usage: ""IF_FEATURE_SYNC_FANCY("[-df] [FILE]...")
|
||||
//usage: ""
|
||||
//usage:#define sync_full_usage "\n\n"
|
||||
//usage: IF_NOT_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks to disk"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks (in FILEs) to disk"
|
||||
//usage: "\n -d Avoid syncing metadata"
|
||||
//usage: "\n -f Sync filesystems underlying FILEs"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -44,59 +21,10 @@
|
||||
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
||||
{
|
||||
#if !ENABLE_FEATURE_SYNC_FANCY
|
||||
/* coreutils-6.9 compat */
|
||||
bb_warn_ignoring_args(argv[1]);
|
||||
|
||||
sync();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
#else
|
||||
unsigned opts;
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
enum {
|
||||
OPT_DATASYNC = (1 << 0),
|
||||
OPT_SYNCFS = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "d--f:f--d";
|
||||
opts = getopt32(argv, "df");
|
||||
argv += optind;
|
||||
|
||||
/* Handle the no-argument case. */
|
||||
if (!argv[0])
|
||||
sync();
|
||||
|
||||
while (*argv) {
|
||||
int fd = open_or_warn(*argv, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
if (opts & OPT_DATASYNC) {
|
||||
if (fdatasync(fd))
|
||||
goto err;
|
||||
goto do_close;
|
||||
}
|
||||
if (opts & OPT_SYNCFS) {
|
||||
/*
|
||||
* syncfs is documented to only fail with EBADF,
|
||||
* which can't happen here. So, no error checks.
|
||||
*/
|
||||
syncfs(fd);
|
||||
goto do_close;
|
||||
}
|
||||
if (fsync(fd)) {
|
||||
err:
|
||||
bb_simple_perror_msg(*argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
do_close:
|
||||
close(fd);
|
||||
next:
|
||||
++argv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
+4
-3
@@ -32,14 +32,15 @@
|
||||
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: )
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: )
|
||||
|
||||
+42
-38
@@ -39,9 +39,14 @@
|
||||
//config: help
|
||||
//config: Enable 64-bit support in test.
|
||||
|
||||
/* "test --help" is special-cased to ignore --help */
|
||||
//usage:#define test_trivial_usage NOUSAGE_STR
|
||||
//usage:#define test_full_usage ""
|
||||
/* "test --help" does not print help (POSIX compat), only "[ --help" does.
|
||||
* We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION")
|
||||
* Unfortunately, it screws up generated BusyBox.html. TODO. */
|
||||
//usage:#define test_trivial_usage
|
||||
//usage: "EXPRESSION ]"
|
||||
//usage:#define test_full_usage "\n\n"
|
||||
//usage: "Check file types, compare values etc. Return a 0/1 exit code\n"
|
||||
//usage: "depending on logical value of EXPRESSION"
|
||||
//usage:
|
||||
//usage:#define test_example_usage
|
||||
//usage: "$ test 1 -eq 2\n"
|
||||
@@ -821,6 +826,7 @@ int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
// bool negate = 0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
@@ -838,7 +844,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
/* argc is unused after this point */
|
||||
|
||||
/* We must do DEINIT_S() prior to returning */
|
||||
INIT_S();
|
||||
@@ -857,45 +862,43 @@ int test_main(int argc, char **argv)
|
||||
*/
|
||||
/*ngroups = 0; - done by INIT_S() */
|
||||
|
||||
//argc--;
|
||||
argv++;
|
||||
args = argv;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4.
|
||||
* Testcase: "test '(' = '('"
|
||||
* The general parser would misinterpret '(' as group start.
|
||||
*/
|
||||
if (1) {
|
||||
int negate = 0;
|
||||
again:
|
||||
if (!argv[0]) {
|
||||
/* "test" */
|
||||
res = 1;
|
||||
goto ret_special;
|
||||
}
|
||||
if (!argv[1]) {
|
||||
/* "test [!] arg" */
|
||||
res = (argv[0][0] == '\0');
|
||||
goto ret_special;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
ret_special:
|
||||
/* If there was leading "!" op... */
|
||||
res ^= negate;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
if (LONE_CHAR(argv[0], '!')) {
|
||||
argv++;
|
||||
negate ^= 1;
|
||||
goto again;
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (!argv[0]) { /* "test" */
|
||||
res = 1;
|
||||
goto ret;
|
||||
}
|
||||
#if 0
|
||||
// Now it's fixed in the parser and should not be needed
|
||||
if (LONE_CHAR(argv[0], '!') && argv[1]) {
|
||||
negate = 1;
|
||||
//argc--;
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1]) { /* "test [!] arg" */
|
||||
res = (*argv[0] == '\0');
|
||||
goto ret;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Some complex expression. Undo '!' removal */
|
||||
if (negate) {
|
||||
negate = 0;
|
||||
//argc++;
|
||||
argv--;
|
||||
}
|
||||
#endif
|
||||
args = argv;
|
||||
res = !oexpr(check_operator(*args));
|
||||
|
||||
if (*args != NULL && *++args != NULL) {
|
||||
@@ -908,5 +911,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
ret:
|
||||
DEINIT_S();
|
||||
// return negate ? !res : res;
|
||||
return res;
|
||||
}
|
||||
+5
-3
@@ -10,9 +10,11 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */
|
||||
|
||||
/* "true --help" is special-cased to ignore --help */
|
||||
//usage:#define true_trivial_usage NOUSAGE_STR
|
||||
//usage:#define true_full_usage ""
|
||||
//usage:#define true_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define true_full_usage "\n\n"
|
||||
//usage: "Return an exit code of TRUE (0)"
|
||||
//usage:
|
||||
//usage:#define true_example_usage
|
||||
//usage: "$ true\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Mini truncate implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config TRUNCATE
|
||||
//config: bool "truncate"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: truncate truncates files to a given size. If a file does
|
||||
//config: not exist, it is created unless told otherwise.
|
||||
|
||||
//kbuild:lib-$(CONFIG_TRUNCATE) += truncate.o
|
||||
//applet:IF_TRUNCATE(APPLET_NOFORK(truncate, truncate, BB_DIR_USR_BIN, BB_SUID_DROP, truncate))
|
||||
|
||||
//usage:#define truncate_trivial_usage
|
||||
//usage: "[-c] -s SIZE FILE..."
|
||||
//usage:#define truncate_full_usage "\n\n"
|
||||
//usage: "Truncate FILEs to the given size\n"
|
||||
//usage: "\n -c Do not create files"
|
||||
//usage: "\n -s SIZE Truncate to SIZE"
|
||||
//usage:
|
||||
//usage:#define truncate_example_usage
|
||||
//usage: "$ truncate -s 1G foo"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_LFS
|
||||
# define XATOU_SFX xatoull_sfx
|
||||
#else
|
||||
# define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int truncate_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
int flags = O_RDWR;
|
||||
int ret = EXIT_SUCCESS;
|
||||
char *size_str;
|
||||
off_t size;
|
||||
|
||||
enum {
|
||||
OPT_NOCREATE = (1 << 0),
|
||||
OPT_SIZE = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "s:-1";
|
||||
opts = getopt32(argv, "cs:", &size_str);
|
||||
|
||||
if (!(opts & OPT_NOCREATE))
|
||||
flags |= O_CREAT;
|
||||
|
||||
// TODO: coreutils 8.17 also support "m" (lowercase) suffix
|
||||
// with truncate, but not with dd!
|
||||
// We share kMG_suffixes[], so we can't make both tools
|
||||
// compatible at once...
|
||||
size = XATOU_SFX(size_str, kMG_suffixes);
|
||||
|
||||
argv += optind;
|
||||
while (*argv) {
|
||||
int fd = open(*argv, flags, 0666);
|
||||
if (fd < 0) {
|
||||
if (errno != ENOENT || !(opts & OPT_NOCREATE)) {
|
||||
bb_perror_msg("%s: open", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
/* else: ENOENT && OPT_NOCREATE:
|
||||
* do not report error, exitcode is also 0.
|
||||
*/
|
||||
} else {
|
||||
if (ftruncate(fd, size) == -1) {
|
||||
bb_perror_msg("%s: truncate", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
xclose(fd);
|
||||
}
|
||||
++argv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
+6
-8
@@ -49,18 +49,16 @@
|
||||
*/
|
||||
|
||||
//usage:#define uname_trivial_usage
|
||||
//usage: "[-amnrspvio]"
|
||||
//usage: "[-amnrspv]"
|
||||
//usage:#define uname_full_usage "\n\n"
|
||||
//usage: "Print system information\n"
|
||||
//usage: "\n -a Print all"
|
||||
//usage: "\n -m The machine (hardware) type"
|
||||
//usage: "\n -n Hostname"
|
||||
//usage: "\n -r Kernel release"
|
||||
//usage: "\n -s Kernel name (default)"
|
||||
//usage: "\n -r OS release"
|
||||
//usage: "\n -s OS name (default)"
|
||||
//usage: "\n -p Processor type"
|
||||
//usage: "\n -v Kernel version"
|
||||
//usage: "\n -i The hardware platform"
|
||||
//usage: "\n -o OS name"
|
||||
//usage: "\n -v OS version"
|
||||
//usage:
|
||||
//usage:#define uname_example_usage
|
||||
//usage: "$ uname -a\n"
|
||||
@@ -74,7 +72,7 @@ typedef struct {
|
||||
struct utsname name;
|
||||
char processor[sizeof(((struct utsname*)NULL)->machine)];
|
||||
char platform[sizeof(((struct utsname*)NULL)->machine)];
|
||||
char os[sizeof(CONFIG_UNAME_OSNAME)];
|
||||
char os[sizeof("GNU/Linux")];
|
||||
} uname_info_t;
|
||||
|
||||
static const char options[] ALIGN1 = "snrvmpioa";
|
||||
@@ -141,7 +139,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
strcpy(uname_info.processor, unknown_str);
|
||||
strcpy(uname_info.platform, unknown_str);
|
||||
strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
|
||||
strcpy(uname_info.os, "GNU/Linux");
|
||||
#if 0
|
||||
/* Fedora does something like this */
|
||||
strcpy(uname_info.processor, uname_info.name.machine);
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* %7lu matches GNU coreutils 6.9 */
|
||||
printf("%7lu ", dups + 1);
|
||||
}
|
||||
puts(old_line);
|
||||
printf("%s\n", old_line);
|
||||
}
|
||||
free(old_line);
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* unlink for busybox
|
||||
*
|
||||
* Copyright (C) 2014 Isaac Dunham <ibid.ag@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see LICENSE in this source tree
|
||||
*/
|
||||
|
||||
//config:config UNLINK
|
||||
//config: bool "unlink"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlink deletes a file by calling unlink()
|
||||
|
||||
//kbuild:lib-$(CONFIG_UNLINK) += unlink.o
|
||||
|
||||
//applet:IF_UNLINK(APPLET(unlink, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define unlink_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage:#define unlink_full_usage "\n\n"
|
||||
//usage: "Delete FILE by calling unlink()"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlink_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
opt_complementary = "=1"; /* must have exactly 1 param */
|
||||
getopt32(argv, "");
|
||||
argv += optind;
|
||||
xunlink(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
+4
-15
@@ -29,19 +29,9 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
|
||||
{
|
||||
char *line;
|
||||
|
||||
for (;;) {
|
||||
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
|
||||
int encoded_len, str_len;
|
||||
char *line_ptr, *dst;
|
||||
size_t line_len;
|
||||
|
||||
line_len = 64 * 1024;
|
||||
line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
|
||||
if (!line)
|
||||
break;
|
||||
/* Handle both Unix and MSDOS text, and stray trailing spaces */
|
||||
str_len = line_len;
|
||||
while (--str_len >= 0 && isspace(line[str_len]))
|
||||
line[str_len] = '\0';
|
||||
|
||||
if (strcmp(line, "end") == 0) {
|
||||
return; /* the only non-error exit */
|
||||
@@ -56,7 +46,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
|
||||
|
||||
encoded_len = line[0] * 4 / 3;
|
||||
/* Check that line is not too short. (we tolerate
|
||||
* overly _long_ line to accommodate possible extra '`').
|
||||
* overly _long_ line to accomodate possible extra '`').
|
||||
* Empty line case is also caught here. */
|
||||
if (str_len <= encoded_len) {
|
||||
break; /* go to bb_error_msg_and_die("short file"); */
|
||||
@@ -120,10 +110,10 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
|
||||
FILE *dst_stream;
|
||||
int mode;
|
||||
|
||||
if (is_prefixed_with(line, "begin-base64 ")) {
|
||||
if (strncmp(line, "begin-base64 ", 13) == 0) {
|
||||
line_ptr = line + 13;
|
||||
decode_fn_ptr = read_base64;
|
||||
} else if (is_prefixed_with(line, "begin ")) {
|
||||
} else if (strncmp(line, "begin ", 6) == 0) {
|
||||
line_ptr = line + 6;
|
||||
decode_fn_ptr = read_stduu;
|
||||
} else {
|
||||
@@ -138,7 +128,6 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!outname)
|
||||
break;
|
||||
outname++;
|
||||
trim(outname); /* remove trailing space (and '\r' for DOS text) */
|
||||
if (!outname[0])
|
||||
break;
|
||||
}
|
||||
|
||||
+5
-5
@@ -73,7 +73,7 @@ static void idle_string(char *str6, time_t t)
|
||||
int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct utmpx *ut;
|
||||
struct utmp *ut;
|
||||
unsigned opt;
|
||||
int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
|
||||
const char *fmt = "%s";
|
||||
@@ -81,10 +81,10 @@ int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, do_users ? "" : "aH");
|
||||
if (opt & 2) // -H
|
||||
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
|
||||
printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
|
||||
|
||||
setutxent();
|
||||
while ((ut = getutxent()) != NULL) {
|
||||
setutent();
|
||||
while ((ut = getutent()) != NULL) {
|
||||
if (ut->ut_user[0]
|
||||
&& ((opt & 1) || ut->ut_type == USER_PROCESS)
|
||||
) {
|
||||
@@ -126,6 +126,6 @@ int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (do_users)
|
||||
bb_putchar('\n');
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
endutxent();
|
||||
endutent();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (ret < 0)
|
||||
bb_perror_msg("can't execute '%s'", name);
|
||||
else /* ret > 0 */
|
||||
bb_error_msg("%s: exit status %u", name, ret & 0xff);
|
||||
bb_error_msg("%s exited with code %d", name, ret & 0xff);
|
||||
|
||||
if (option_mask32 & OPT_e)
|
||||
xfunc_die();
|
||||
|
||||
+61
-24
@@ -1,9 +1,13 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Which implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
* Based on which from debianutils
|
||||
*/
|
||||
|
||||
//usage:#define which_trivial_usage
|
||||
@@ -20,43 +24,76 @@
|
||||
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int which_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
const char *env_path;
|
||||
int status = 0;
|
||||
|
||||
env_path = getenv("PATH");
|
||||
if (!env_path)
|
||||
env_path = bb_default_root_path;
|
||||
IF_DESKTOP(int opt;)
|
||||
int status = EXIT_SUCCESS;
|
||||
char *path;
|
||||
char *p;
|
||||
|
||||
opt_complementary = "-1"; /* at least one argument */
|
||||
getopt32(argv, "a");
|
||||
IF_DESKTOP(opt =) getopt32(argv, "a");
|
||||
argv += optind;
|
||||
|
||||
/* This matches what is seen on e.g. ubuntu.
|
||||
* "which" there is a shell script. */
|
||||
path = getenv("PATH");
|
||||
if (!path) {
|
||||
path = (char*)bb_PATH_root_path;
|
||||
putenv(path);
|
||||
path += 5; /* skip "PATH=" */
|
||||
}
|
||||
|
||||
do {
|
||||
int missing = 1;
|
||||
|
||||
/* If file contains a slash don't use PATH */
|
||||
#if ENABLE_DESKTOP
|
||||
/* Much bloat just to support -a */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (file_is_executable(*argv)) {
|
||||
missing = 0;
|
||||
if (execable_file(*argv)) {
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
} else {
|
||||
char *path;
|
||||
char *tmp;
|
||||
char *p;
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
|
||||
path = tmp = xstrdup(env_path);
|
||||
while ((p = find_executable(*argv, &tmp)) != NULL) {
|
||||
missing = 0;
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (!p)
|
||||
status = EXIT_FAILURE;
|
||||
else {
|
||||
print:
|
||||
puts(p);
|
||||
free(p);
|
||||
if (!option_mask32) /* -a not set */
|
||||
break;
|
||||
if (opt) {
|
||||
/* -a: show matches in all PATH components */
|
||||
if (tmp) {
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (p)
|
||||
goto print;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
free(path2);
|
||||
}
|
||||
status |= missing;
|
||||
} while (*++argv);
|
||||
#else
|
||||
/* Just ignoring -a */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (execable_file(*argv)) {
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
p = find_execable(*argv, &tmp);
|
||||
free(path2);
|
||||
if (p) {
|
||||
puts(p);
|
||||
free(p);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
#endif
|
||||
} while (*(++argv) != NULL);
|
||||
|
||||
return status;
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ fulfilled by the gateway program: <p>
|
||||
|
||||
</p><ul>
|
||||
<li> <a name="protocol"><code>SERVER_PROTOCOL</code></a> <p>
|
||||
The name and revision of the information protocol this request came
|
||||
The name and revision of the information protcol this request came
|
||||
in with. Format: protocol/revision </p><p>
|
||||
|
||||
</p></li><li> <code>SERVER_PORT</code> <p>
|
||||
|
||||
@@ -21,7 +21,7 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
||||
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
||||
int i ;
|
||||
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||
if (executable_exists(ext_dhcp_clients[i].name))
|
||||
if (exists_execable(ext_dhcp_clients[i].name))
|
||||
return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
||||
}
|
||||
bb_error_msg("no dhcp clients found, using static interface shutdown");
|
||||
|
||||
@@ -103,15 +103,7 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro:
|
||||
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
|
||||
Typically it is done in <applet>_main(). Another variation is
|
||||
to use stack:
|
||||
|
||||
int <applet>_main(...)
|
||||
{
|
||||
#undef G
|
||||
struct globals G;
|
||||
memset(&G, 0, sizeof(G));
|
||||
SET_PTR_TO_GLOBALS(&G);
|
||||
Typically it is done in <applet>_main().
|
||||
|
||||
Now you can reference "globals" by G.a, G.buf and so on, in any function.
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ udhcpc - auto-backgrounds unless -f after lease is obtained,
|
||||
udhcpd - auto-backgrounds and do not log to stderr unless -f,
|
||||
otherwise logs to stderr, but option -S makes it log *also* to syslog
|
||||
zcip - auto-backgrounds and logs *also* to syslog unless -f
|
||||
behaviour can be overridden with experimental LOGGING env.var
|
||||
(can be set to either "none" or "syslog")
|
||||
|
||||
Total: 13 applets (+1 obsolete),
|
||||
4 log to syslog by default (crond fakeidentd inetd zcip),
|
||||
|
||||
+40
-64
@@ -6,7 +6,7 @@ This document details the steps you must take to add a new applet to BusyBox.
|
||||
Credits:
|
||||
Matt Kraai - initial writeup
|
||||
Mark Whitley - the remix
|
||||
Thomas Lundquist - trying to keep it updated
|
||||
Thomas Lundquist - Trying to keep it updated.
|
||||
|
||||
When doing this you should consider using the latest git HEAD.
|
||||
This is a good thing if you plan to getting it committed into mainline.
|
||||
@@ -16,14 +16,14 @@ Initial Write
|
||||
|
||||
First, write your applet. Be sure to include copyright information at the top,
|
||||
such as who you stole the code from and so forth. Also include the mini-GPL
|
||||
boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
|
||||
in this document). Be sure to name the main function <applet>_main instead
|
||||
of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
|
||||
as the first include file in your applet.
|
||||
boilerplate. Be sure to name the main function <applet>_main instead of main.
|
||||
And be sure to put it in <applet>.c. Usage does not have to be taken care of by
|
||||
your applet.
|
||||
Make sure to #include "libbb.h" as the first include file in your applet.
|
||||
|
||||
For a new applet mu, here is the code that would go in mu.c:
|
||||
|
||||
(libbb.h already includes most usual header files. You do not need
|
||||
(busybox.h already includes most usual header files. You do not need
|
||||
#include <stdio.h> etc...)
|
||||
|
||||
|
||||
@@ -41,22 +41,6 @@ For a new applet mu, here is the code that would go in mu.c:
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
|
||||
int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mu_main(int argc, char **argv)
|
||||
{
|
||||
@@ -106,8 +90,6 @@ Make a new file named <function_name>.c
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//kbuild:lib-y += function.o
|
||||
|
||||
int function(char *a)
|
||||
{
|
||||
return *a;
|
||||
@@ -115,7 +97,9 @@ int function(char *a)
|
||||
|
||||
----end example code------
|
||||
|
||||
Remember about the kbuild snippet.
|
||||
Add <function_name>.o in the right alphabetically sorted place
|
||||
in libbb/Kbuild.src. You should look at the conditional part of
|
||||
libbb/Kbuild.src as well.
|
||||
|
||||
You should also try to find a suitable place in include/libbb.h for
|
||||
the function declaration. If not, add it somewhere anyway, with or without
|
||||
@@ -125,68 +109,60 @@ You can look at libbb/Config.src and try to find out if the function is
|
||||
tunable and add it there if it is.
|
||||
|
||||
|
||||
Kbuild/Config.in/usage/applets.h snippets in .c files
|
||||
-----------------------------------------------------
|
||||
|
||||
The old way of adding new applets was to put all the information needed by the
|
||||
configuration and build system into appropriate files (namely: Kbuild.src and
|
||||
Config.src in new applet's directory) and to add the applet declaration and
|
||||
usage info text to include/applets.src.h and include/usage.src.h respectively.
|
||||
|
||||
Since the scripts/gen_build_files.sh script had been introduced, the preferred
|
||||
way is to have all these declarations contained within the applet .c files.
|
||||
|
||||
Every line intended to be processed by gen_build_files.sh should start as a
|
||||
comment without any preceding whitespaces and be followed by an appropriate
|
||||
keyword - kbuild, config, usage or applet - and a colon, just like shown in the
|
||||
first example above.
|
||||
|
||||
|
||||
Placement / Directory
|
||||
---------------------
|
||||
|
||||
Find the appropriate directory for your new applet.
|
||||
|
||||
Add the kbuild snippet to the .c file:
|
||||
Make sure you find the appropriate places in the files, the applets are
|
||||
sorted alphabetically.
|
||||
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
Add the applet to Kbuild.src in the chosen directory:
|
||||
|
||||
Add the config snippet to the .c file:
|
||||
lib-$(CONFIG_MU) += mu.o
|
||||
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
Add the applet to Config.src in the chosen directory:
|
||||
|
||||
config MU
|
||||
bool "MU"
|
||||
default n
|
||||
help
|
||||
Returns an indeterminate value.
|
||||
|
||||
|
||||
Usage String(s)
|
||||
---------------
|
||||
|
||||
Next, add usage information for your applet to the .c file.
|
||||
Next, add usage information for you applet to include/usage.src.h.
|
||||
This should look like the following:
|
||||
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
//usage: ...
|
||||
#define mu_trivial_usage \
|
||||
"-[abcde] FILES"
|
||||
#define mu_full_usage \
|
||||
"Returns an indeterminate value.\n\n" \
|
||||
"Options:\n" \
|
||||
"\t-a\t\tfirst function\n" \
|
||||
"\t-b\t\tsecond function\n" \
|
||||
...
|
||||
|
||||
If your program supports flags, the flags should be mentioned on the first
|
||||
line ([-abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line.
|
||||
line (-[abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line. (Numerous examples of this
|
||||
currently exist in usage.src.h.)
|
||||
|
||||
|
||||
Header Files
|
||||
------------
|
||||
|
||||
Finally add the applet declaration snippet. Be sure to read the top of
|
||||
applets.src.h before adding your applet - it contains important info
|
||||
on applet macros and conventions.
|
||||
Next, add an entry to include/applets.src.h. Be *sure* to keep the list
|
||||
in alphabetical order, or else it will break the binary-search lookup
|
||||
algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
|
||||
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
Be sure to read the top of applets.src.h before adding your applet.
|
||||
|
||||
/* all programs above here are alphabetically "less than" 'mu' */
|
||||
IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* all programs below here are alphabetically "greater than" 'mu' */
|
||||
|
||||
|
||||
The Grand Announcement
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
Busybox unit test framework
|
||||
===========================
|
||||
|
||||
This document describes what you need to do to write test cases using the
|
||||
Busybox unit test framework.
|
||||
|
||||
|
||||
Building unit tests
|
||||
-------------------
|
||||
|
||||
The framework and all tests are built as a regular Busybox applet if option
|
||||
CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
|
||||
|
||||
|
||||
Writing test cases
|
||||
------------------
|
||||
|
||||
Unit testing interface can be found in include/bbunit.h.
|
||||
|
||||
Tests can be placed in any .c file in Busybox tree - preferably right next to
|
||||
the functions they test. Test cases should be enclosed within an #if, and
|
||||
should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
|
||||
the test curly brackets. If an assertion fails the test ends immediately, ie.
|
||||
the following assertions will not be reached. Any code placed after
|
||||
BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
|
||||
|
||||
#if ENABLE_UNIT_TEST
|
||||
|
||||
BBUNIT_DEFINE_TEST(test_name)
|
||||
{
|
||||
int *i;
|
||||
|
||||
i = malloc(sizeof(int));
|
||||
BBUNIT_ASSERT_NOTNULL(i);
|
||||
*i = 2;
|
||||
BBUNIT_ASSERT_EQ((*i)*(*i), 4);
|
||||
|
||||
BBUNIT_ENDTEST;
|
||||
|
||||
free(i);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_UNIT_TEST */
|
||||
|
||||
|
||||
Running the unit test suite
|
||||
---------------------------
|
||||
|
||||
To run the tests you can either directly run 'busybox unit' or use 'make test'
|
||||
to run both the unit tests (if compiled) and regular test suite.
|
||||
+20
-20
@@ -199,7 +199,7 @@ static char *base_device(const char *device)
|
||||
}
|
||||
|
||||
/* Handle DAC 960 devices */
|
||||
if (is_prefixed_with(cp, "rd/")) {
|
||||
if (strncmp(cp, "rd/", 3) == 0) {
|
||||
cp += 3;
|
||||
if (cp[0] != 'c' || !isdigit(cp[1])
|
||||
|| cp[2] != 'd' || !isdigit(cp[3]))
|
||||
@@ -224,9 +224,9 @@ static char *base_device(const char *device)
|
||||
#if ENABLE_FEATURE_DEVFS
|
||||
/* Now let's handle devfs (ugh) names */
|
||||
len = 0;
|
||||
if (is_prefixed_with(cp, "ide/"))
|
||||
if (strncmp(cp, "ide/", 4) == 0)
|
||||
len = 4;
|
||||
if (is_prefixed_with(cp, "scsi/"))
|
||||
if (strncmp(cp, "scsi/", 5) == 0)
|
||||
len = 5;
|
||||
if (len) {
|
||||
cp += len;
|
||||
@@ -237,38 +237,38 @@ static char *base_device(const char *device)
|
||||
* some number of digits at each level, abort.
|
||||
*/
|
||||
for (hier = devfs_hier; *hier; hier++) {
|
||||
cp = is_prefixed_with(cp, *hier);
|
||||
if (!cp)
|
||||
len = strlen(*hier);
|
||||
if (strncmp(cp, *hier, len) != 0)
|
||||
goto errout;
|
||||
while (*cp != '/' && *cp != '\0') {
|
||||
cp += len;
|
||||
while (*cp != '/' && *cp != 0) {
|
||||
if (!isdigit(*cp))
|
||||
goto errout;
|
||||
cp++;
|
||||
}
|
||||
//FIXME: what if *cp = '\0' now? cp++ moves past it!!!
|
||||
cp++;
|
||||
}
|
||||
cp[-1] = '\0';
|
||||
cp[-1] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Now handle devfs /dev/disc or /dev/disk names */
|
||||
disk = NULL;
|
||||
if (is_prefixed_with(cp, "discs/"))
|
||||
disk = 0;
|
||||
if (strncmp(cp, "discs/", 6) == 0)
|
||||
disk = "disc";
|
||||
else if (is_prefixed_with(cp, "disks/"))
|
||||
else if (strncmp(cp, "disks/", 6) == 0)
|
||||
disk = "disk";
|
||||
if (disk) {
|
||||
cp += 6;
|
||||
cp = is_prefixed_with(cp, disk);
|
||||
if (!cp)
|
||||
if (strncmp(cp, disk, 4) != 0)
|
||||
goto errout;
|
||||
while (*cp != '/' && *cp != '\0') {
|
||||
cp += 4;
|
||||
while (*cp != '/' && *cp != 0) {
|
||||
if (!isdigit(*cp))
|
||||
goto errout;
|
||||
cp++;
|
||||
}
|
||||
*cp = '\0';
|
||||
*cp = 0;
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
@@ -593,8 +593,8 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
|
||||
type, "from fstab");
|
||||
} else if (fstype
|
||||
&& (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
|
||||
&& !is_prefixed_with(fstype, "opts=")
|
||||
&& !is_prefixed_with(fstype, "loop")
|
||||
&& strncmp(fstype, "opts=", 5) != 0
|
||||
&& strncmp(fstype, "loop", 4) != 0
|
||||
&& !strchr(fstype, ',')
|
||||
) {
|
||||
type = fstype;
|
||||
@@ -627,8 +627,8 @@ static int device_already_active(char *device)
|
||||
#ifdef BASE_MD
|
||||
/* Don't check a soft raid disk with any other disk */
|
||||
if (instance_list
|
||||
&& (is_prefixed_with(instance_list->device, BASE_MD)
|
||||
|| is_prefixed_with(device, BASE_MD))
|
||||
&& (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1)
|
||||
|| !strncmp(device, BASE_MD, sizeof(BASE_MD)-1))
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
@@ -895,7 +895,7 @@ static void compile_fs_type(char *fs_type)
|
||||
if (strcmp(s, "loop") == 0)
|
||||
/* loop is really short-hand for opts=loop */
|
||||
goto loop_special_case;
|
||||
if (is_prefixed_with(s, "opts=")) {
|
||||
if (strncmp(s, "opts=", 5) == 0) {
|
||||
s += 5;
|
||||
loop_special_case:
|
||||
fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Linux Ext2 FS Progs"
|
||||
|
||||
INSERT
|
||||
|
||||
config CHATTR
|
||||
bool "chattr"
|
||||
default n
|
||||
help
|
||||
chattr changes the file attributes on a second extended file system.
|
||||
|
||||
config E2FSCK
|
||||
bool "e2fsck"
|
||||
default n
|
||||
help
|
||||
e2fsck is used to check Linux second extended file systems (ext2fs).
|
||||
e2fsck also supports ext2 filesystems countaining a journal (ext3).
|
||||
The normal compat symlinks 'fsck.ext2' and 'fsck.ext3' are also
|
||||
provided.
|
||||
|
||||
config FSCK
|
||||
bool "fsck"
|
||||
default n
|
||||
help
|
||||
fsck is used to check and optionally repair one or more filesystems.
|
||||
In actuality, fsck is simply a front-end for the various file system
|
||||
checkers (fsck.fstype) available under Linux.
|
||||
|
||||
config LSATTR
|
||||
bool "lsattr"
|
||||
default n
|
||||
help
|
||||
lsattr lists the file attributes on a second extended file system.
|
||||
|
||||
config MKE2FS
|
||||
bool "mke2fs"
|
||||
default n
|
||||
help
|
||||
mke2fs is used to create an ext2/ext3 filesystem. The normal compat
|
||||
symlinks 'mkfs.ext2' and 'mkfs.ext3' are also provided.
|
||||
|
||||
config TUNE2FS
|
||||
bool "tune2fs"
|
||||
default n
|
||||
help
|
||||
tune2fs allows the system administrator to adjust various tunable
|
||||
filesystem parameters on Linux ext2/ext3 filesystems.
|
||||
|
||||
config E2LABEL
|
||||
bool "e2label"
|
||||
default n
|
||||
depends on TUNE2FS
|
||||
help
|
||||
e2label will display or change the filesystem label on the ext2
|
||||
filesystem located on device.
|
||||
|
||||
config FINDFS
|
||||
bool "findfs"
|
||||
default n
|
||||
depends on TUNE2FS
|
||||
help
|
||||
findfs will search the disks in the system looking for a filesystem
|
||||
which has a label matching label or a UUID equal to uuid.
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,18 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_CHATTR) += chattr.o
|
||||
lib-$(CONFIG_E2FSCK) += e2fsck.o util.o
|
||||
lib-$(CONFIG_FSCK) += fsck.o util.o
|
||||
lib-$(CONFIG_LSATTR) += lsattr.o
|
||||
lib-$(CONFIG_MKE2FS) += mke2fs.o util.o
|
||||
lib-$(CONFIG_TUNE2FS) += tune2fs.o util.o
|
||||
|
||||
CFLAGS += -include $(srctree)/e2fsprogs/e2fsbb.h
|
||||
@@ -0,0 +1,3 @@
|
||||
This is a pretty straight rip from the e2fsprogs pkg.
|
||||
|
||||
See README's in subdirs for specific info.
|
||||
@@ -0,0 +1,26 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
NEEDED-$(CONFIG_E2FSCK) = y
|
||||
NEEDED-$(CONFIG_FSCK) = y
|
||||
NEEDED-$(CONFIG_MKE2FS) = y
|
||||
NEEDED-$(CONFIG_TUNE2FS) = y
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(NEEDED-y) += cache.o dev.o devname.o devno.o blkid_getsize.o \
|
||||
probe.o read.o resolve.o save.o tag.o list.o
|
||||
|
||||
CFLAGS_dev.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_devname.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_devno.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_blkid_getsize.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_probe.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_save.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_tag.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_list.o := -include $(srctree)/include/busybox.h
|
||||
@@ -0,0 +1,104 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* blkid.h - Interface for libblkid, a library to identify block devices
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
#ifndef BLKID_BLKID_H
|
||||
#define BLKID_BLKID_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BLKID_VERSION "1.0.0"
|
||||
#define BLKID_DATE "12-Feb-2003"
|
||||
|
||||
typedef struct blkid_struct_dev *blkid_dev;
|
||||
typedef struct blkid_struct_cache *blkid_cache;
|
||||
typedef __s64 blkid_loff_t;
|
||||
|
||||
typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
|
||||
typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
|
||||
|
||||
/*
|
||||
* Flags for blkid_get_dev
|
||||
*
|
||||
* BLKID_DEV_CREATE Create an empty device structure if not found
|
||||
* in the cache.
|
||||
* BLKID_DEV_VERIFY Make sure the device structure corresponds
|
||||
* with reality.
|
||||
* BLKID_DEV_FIND Just look up a device entry, and return NULL
|
||||
* if it is not found.
|
||||
* BLKID_DEV_NORMAL Get a valid device structure, either from the
|
||||
* cache or by probing the device.
|
||||
*/
|
||||
#define BLKID_DEV_FIND 0x0000
|
||||
#define BLKID_DEV_CREATE 0x0001
|
||||
#define BLKID_DEV_VERIFY 0x0002
|
||||
#define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
|
||||
|
||||
/* cache.c */
|
||||
extern void blkid_put_cache(blkid_cache cache);
|
||||
extern int blkid_get_cache(blkid_cache *cache, const char *filename);
|
||||
|
||||
/* dev.c */
|
||||
extern const char *blkid_dev_devname(blkid_dev dev);
|
||||
|
||||
extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
|
||||
extern int blkid_dev_set_search(blkid_dev_iterate iter,
|
||||
char *search_type, char *search_value);
|
||||
extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
|
||||
extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
|
||||
|
||||
/* devno.c */
|
||||
extern char *blkid_devno_to_devname(dev_t devno);
|
||||
|
||||
/* devname.c */
|
||||
extern int blkid_probe_all(blkid_cache cache);
|
||||
extern int blkid_probe_all_new(blkid_cache cache);
|
||||
extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname,
|
||||
int flags);
|
||||
|
||||
/* getsize.c */
|
||||
extern blkid_loff_t blkid_get_dev_size(int fd);
|
||||
|
||||
/* probe.c */
|
||||
int blkid_known_fstype(const char *fstype);
|
||||
extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
|
||||
|
||||
/* read.c */
|
||||
|
||||
/* resolve.c */
|
||||
extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
|
||||
const char *devname);
|
||||
extern char *blkid_get_devname(blkid_cache cache, const char *token,
|
||||
const char *value);
|
||||
|
||||
/* tag.c */
|
||||
extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
|
||||
extern int blkid_tag_next(blkid_tag_iterate iterate,
|
||||
const char **type, const char **value);
|
||||
extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
|
||||
extern int blkid_dev_has_tag(blkid_dev dev, const char *type,
|
||||
const char *value);
|
||||
extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
|
||||
const char *type,
|
||||
const char *value);
|
||||
extern int blkid_parse_tag_string(const char *token, char **ret_type,
|
||||
char **ret_val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,182 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* blkidP.h - Internal interfaces for libblkid
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
#ifndef BLKID_BLKIDP_H
|
||||
#define BLKID_BLKIDP_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "blkid.h"
|
||||
#include "list.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define __BLKID_ATTR(x) __attribute__(x)
|
||||
#else
|
||||
#define __BLKID_ATTR(x)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This describes the attributes of a specific device.
|
||||
* We can traverse all of the tags by bid_tags (linking to the tag bit_names).
|
||||
* The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
|
||||
* values, if they exist.
|
||||
*/
|
||||
struct blkid_struct_dev
|
||||
{
|
||||
struct list_head bid_devs; /* All devices in the cache */
|
||||
struct list_head bid_tags; /* All tags for this device */
|
||||
blkid_cache bid_cache; /* Dev belongs to this cache */
|
||||
char *bid_name; /* Device inode pathname */
|
||||
char *bid_type; /* Preferred device TYPE */
|
||||
int bid_pri; /* Device priority */
|
||||
dev_t bid_devno; /* Device major/minor number */
|
||||
time_t bid_time; /* Last update time of device */
|
||||
unsigned int bid_flags; /* Device status bitflags */
|
||||
char *bid_label; /* Shortcut to device LABEL */
|
||||
char *bid_uuid; /* Shortcut to binary UUID */
|
||||
};
|
||||
|
||||
#define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
|
||||
#define BLKID_BID_FL_INVALID 0x0004 /* Device is invalid */
|
||||
|
||||
/*
|
||||
* Each tag defines a NAME=value pair for a particular device. The tags
|
||||
* are linked via bit_names for a single device, so that traversing the
|
||||
* names list will get you a list of all tags associated with a device.
|
||||
* They are also linked via bit_values for all devices, so one can easily
|
||||
* search all tags with a given NAME for a specific value.
|
||||
*/
|
||||
struct blkid_struct_tag
|
||||
{
|
||||
struct list_head bit_tags; /* All tags for this device */
|
||||
struct list_head bit_names; /* All tags with given NAME */
|
||||
char *bit_name; /* NAME of tag (shared) */
|
||||
char *bit_val; /* value of tag */
|
||||
blkid_dev bit_dev; /* pointer to device */
|
||||
};
|
||||
typedef struct blkid_struct_tag *blkid_tag;
|
||||
|
||||
/*
|
||||
* Minimum number of seconds between device probes, even when reading
|
||||
* from the cache. This is to avoid re-probing all devices which were
|
||||
* just probed by another program that does not share the cache.
|
||||
*/
|
||||
#define BLKID_PROBE_MIN 2
|
||||
|
||||
/*
|
||||
* Time in seconds an entry remains verified in the in-memory cache
|
||||
* before being reverified (in case of long-running processes that
|
||||
* keep a cache in memory and continue to use it for a long time).
|
||||
*/
|
||||
#define BLKID_PROBE_INTERVAL 200
|
||||
|
||||
/* This describes an entire blkid cache file and probed devices.
|
||||
* We can traverse all of the found devices via bic_list.
|
||||
* We can traverse all of the tag types by bic_tags, which hold empty tags
|
||||
* for each tag type. Those tags can be used as list_heads for iterating
|
||||
* through all devices with a specific tag type (e.g. LABEL).
|
||||
*/
|
||||
struct blkid_struct_cache
|
||||
{
|
||||
struct list_head bic_devs; /* List head of all devices */
|
||||
struct list_head bic_tags; /* List head of all tag types */
|
||||
time_t bic_time; /* Last probe time */
|
||||
time_t bic_ftime; /* Mod time of the cachefile */
|
||||
unsigned int bic_flags; /* Status flags of the cache */
|
||||
char *bic_filename; /* filename of cache */
|
||||
};
|
||||
|
||||
#define BLKID_BIC_FL_PROBED 0x0002 /* We probed /proc/partition devices */
|
||||
#define BLKID_BIC_FL_CHANGED 0x0004 /* Cache has changed from disk */
|
||||
|
||||
extern char *blkid_strdup(const char *s);
|
||||
extern char *blkid_strndup(const char *s, const int length);
|
||||
|
||||
#define BLKID_CACHE_FILE "/etc/blkid.tab"
|
||||
extern const char *blkid_devdirs[];
|
||||
|
||||
#define BLKID_ERR_IO 5
|
||||
#define BLKID_ERR_PROC 9
|
||||
#define BLKID_ERR_MEM 12
|
||||
#define BLKID_ERR_CACHE 14
|
||||
#define BLKID_ERR_DEV 19
|
||||
#define BLKID_ERR_PARAM 22
|
||||
#define BLKID_ERR_BIG 27
|
||||
|
||||
/*
|
||||
* Priority settings for different types of devices
|
||||
*/
|
||||
#define BLKID_PRI_EVMS 30
|
||||
#define BLKID_PRI_LVM 20
|
||||
#define BLKID_PRI_MD 10
|
||||
|
||||
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
|
||||
#define CONFIG_BLKID_DEBUG
|
||||
#endif
|
||||
|
||||
#define DEBUG_CACHE 0x0001
|
||||
#define DEBUG_DUMP 0x0002
|
||||
#define DEBUG_DEV 0x0004
|
||||
#define DEBUG_DEVNAME 0x0008
|
||||
#define DEBUG_DEVNO 0x0010
|
||||
#define DEBUG_PROBE 0x0020
|
||||
#define DEBUG_READ 0x0040
|
||||
#define DEBUG_RESOLVE 0x0080
|
||||
#define DEBUG_SAVE 0x0100
|
||||
#define DEBUG_TAG 0x0200
|
||||
#define DEBUG_INIT 0x8000
|
||||
#define DEBUG_ALL 0xFFFF
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
#include <stdio.h>
|
||||
extern int blkid_debug_mask;
|
||||
#define DBG(m,x) if ((m) & blkid_debug_mask) x;
|
||||
#else
|
||||
#define DBG(m,x)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
extern void blkid_debug_dump_dev(blkid_dev dev);
|
||||
extern void blkid_debug_dump_tag(blkid_tag tag);
|
||||
#endif
|
||||
|
||||
/* lseek.c */
|
||||
/* extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence); */
|
||||
#ifdef CONFIG_LFS
|
||||
# define blkid_llseek lseek64
|
||||
#else
|
||||
# define blkid_llseek lseek
|
||||
#endif
|
||||
|
||||
/* read.c */
|
||||
extern void blkid_read_cache(blkid_cache cache);
|
||||
|
||||
/* save.c */
|
||||
extern int blkid_flush_cache(blkid_cache cache);
|
||||
|
||||
/*
|
||||
* Functions to create and find a specific tag type: tag.c
|
||||
*/
|
||||
extern void blkid_free_tag(blkid_tag tag);
|
||||
extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
|
||||
extern int blkid_set_tag(blkid_dev dev, const char *name,
|
||||
const char *value, const int vlength);
|
||||
|
||||
/*
|
||||
* Functions to create and find a specific tag type: dev.c
|
||||
*/
|
||||
extern blkid_dev blkid_new_dev(void);
|
||||
extern void blkid_free_dev(blkid_dev dev);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,179 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* getsize.c --- get the size of a partition.
|
||||
*
|
||||
* Copyright (C) 1995, 1995 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
/* include this before sys/queues.h! */
|
||||
#include "blkidP.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_LINUX_FD_H
|
||||
#include <linux/fd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISK_H
|
||||
#ifdef HAVE_SYS_QUEUE_H
|
||||
#include <sys/queue.h> /* for LIST_HEAD */
|
||||
#endif
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
|
||||
#define BLKGETSIZE _IO(0x12,96) /* return device size */
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
|
||||
#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
|
||||
#endif
|
||||
|
||||
#ifdef APPLE_DARWIN
|
||||
#define BLKGETSIZE DKIOCGETBLOCKCOUNT32
|
||||
#endif /* APPLE_DARWIN */
|
||||
|
||||
static int valid_offset(int fd, blkid_loff_t offset)
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (blkid_llseek(fd, offset, 0) < 0)
|
||||
return 0;
|
||||
if (read(fd, &ch, 1) < 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the number of blocks in a partition
|
||||
*/
|
||||
blkid_loff_t blkid_get_dev_size(int fd)
|
||||
{
|
||||
int valid_blkgetsize64 = 1;
|
||||
#ifdef __linux__
|
||||
struct utsname ut;
|
||||
#endif
|
||||
unsigned long long size64;
|
||||
unsigned long size;
|
||||
blkid_loff_t high, low;
|
||||
#ifdef FDGETPRM
|
||||
struct floppy_struct this_floppy;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
int part = -1;
|
||||
struct disklabel lab;
|
||||
struct partition *pp;
|
||||
char ch;
|
||||
struct stat st;
|
||||
#endif /* HAVE_SYS_DISKLABEL_H */
|
||||
|
||||
#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
|
||||
if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
|
||||
if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
|
||||
&& (size64 << 9 > 0xFFFFFFFF))
|
||||
return 0; /* EFBIG */
|
||||
return (blkid_loff_t) size64 << 9;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BLKGETSIZE64
|
||||
#ifdef __linux__
|
||||
uname(&ut);
|
||||
if ((ut.release[0] == '2') && (ut.release[1] == '.') &&
|
||||
(ut.release[2] < '6') && (ut.release[3] == '.'))
|
||||
valid_blkgetsize64 = 0;
|
||||
#endif
|
||||
if (valid_blkgetsize64 &&
|
||||
ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
|
||||
if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
|
||||
&& ((size64) > 0xFFFFFFFF))
|
||||
return 0; /* EFBIG */
|
||||
return size64;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BLKGETSIZE
|
||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0)
|
||||
return (blkid_loff_t)size << 9;
|
||||
#endif
|
||||
|
||||
#ifdef FDGETPRM
|
||||
if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
|
||||
return (blkid_loff_t)this_floppy.size << 9;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
#if 0
|
||||
/*
|
||||
* This should work in theory but I haven't tested it. Anyone
|
||||
* on a BSD system want to test this for me? In the meantime,
|
||||
* binary search mechanism should work just fine.
|
||||
*/
|
||||
if ((fstat(fd, &st) >= 0) && S_ISBLK(st.st_mode))
|
||||
part = st.st_rdev & 7;
|
||||
if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) {
|
||||
pp = &lab.d_partitions[part];
|
||||
if (pp->p_size)
|
||||
return pp->p_size << 9;
|
||||
}
|
||||
#endif
|
||||
#endif /* HAVE_SYS_DISKLABEL_H */
|
||||
|
||||
/*
|
||||
* OK, we couldn't figure it out by using a specialized ioctl,
|
||||
* which is generally the best way. So do binary search to
|
||||
* find the size of the partition.
|
||||
*/
|
||||
low = 0;
|
||||
for (high = 1024; valid_offset(fd, high); high *= 2)
|
||||
low = high;
|
||||
while (low < high - 1)
|
||||
{
|
||||
const blkid_loff_t mid = (low + high) / 2;
|
||||
|
||||
if (valid_offset(fd, mid))
|
||||
low = mid;
|
||||
else
|
||||
high = mid;
|
||||
}
|
||||
return low + 1;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_loff_t bytes;
|
||||
int fd;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s device\n"
|
||||
"Determine the size of a device\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((fd = open(argv[1], O_RDONLY)) < 0)
|
||||
perror(argv[0]);
|
||||
|
||||
bytes = blkid_get_dev_size(fd);
|
||||
printf("Device %s has %lld 1k blocks.\n", argv[1], bytes >> 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cache.c - allocation/initialization/free routines for cache
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "blkidP.h"
|
||||
|
||||
int blkid_debug_mask = 0;
|
||||
|
||||
int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
|
||||
{
|
||||
blkid_cache cache;
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
if (!(blkid_debug_mask & DEBUG_INIT)) {
|
||||
char *dstr = getenv("BLKID_DEBUG");
|
||||
|
||||
if (dstr)
|
||||
blkid_debug_mask = strtoul(dstr, 0, 0);
|
||||
blkid_debug_mask |= DEBUG_INIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
DBG(DEBUG_CACHE, printf("creating blkid cache (using %s)\n",
|
||||
filename ? filename : "default cache"));
|
||||
|
||||
cache = xzalloc(sizeof(struct blkid_struct_cache));
|
||||
|
||||
INIT_LIST_HEAD(&cache->bic_devs);
|
||||
INIT_LIST_HEAD(&cache->bic_tags);
|
||||
|
||||
if (filename && !strlen(filename))
|
||||
filename = 0;
|
||||
if (!filename && (getuid() == geteuid()))
|
||||
filename = getenv("BLKID_FILE");
|
||||
if (!filename)
|
||||
filename = BLKID_CACHE_FILE;
|
||||
cache->bic_filename = blkid_strdup(filename);
|
||||
|
||||
blkid_read_cache(cache);
|
||||
|
||||
*ret_cache = cache;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blkid_put_cache(blkid_cache cache)
|
||||
{
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
(void) blkid_flush_cache(cache);
|
||||
|
||||
DBG(DEBUG_CACHE, printf("freeing cache struct\n"));
|
||||
|
||||
/* DBG(DEBUG_CACHE, blkid_debug_dump_cache(cache)); */
|
||||
|
||||
while (!list_empty(&cache->bic_devs)) {
|
||||
blkid_dev dev = list_entry(cache->bic_devs.next,
|
||||
struct blkid_struct_dev,
|
||||
bid_devs);
|
||||
blkid_free_dev(dev);
|
||||
}
|
||||
|
||||
while (!list_empty(&cache->bic_tags)) {
|
||||
blkid_tag tag = list_entry(cache->bic_tags.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_tags);
|
||||
|
||||
while (!list_empty(&tag->bit_names)) {
|
||||
blkid_tag bad = list_entry(tag->bit_names.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_names);
|
||||
|
||||
DBG(DEBUG_CACHE, printf("warning: unfreed tag %s=%s\n",
|
||||
bad->bit_name, bad->bit_val));
|
||||
blkid_free_tag(bad);
|
||||
}
|
||||
blkid_free_tag(tag);
|
||||
}
|
||||
free(cache->bic_filename);
|
||||
|
||||
free(cache);
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if ((argc > 2)) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, argv[1])) < 0) {
|
||||
fprintf(stderr, "error %d parsing cache file %s\n", ret,
|
||||
argv[1] ? argv[1] : BLKID_CACHE_FILE);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_probe_all(cache)) < 0)
|
||||
fprintf(stderr, "error probing devices\n");
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,213 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* dev.c - allocation/initialization/free routines for dev
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
blkid_dev blkid_new_dev(void)
|
||||
{
|
||||
blkid_dev dev;
|
||||
|
||||
dev = xzalloc(sizeof(struct blkid_struct_dev));
|
||||
|
||||
INIT_LIST_HEAD(&dev->bid_devs);
|
||||
INIT_LIST_HEAD(&dev->bid_tags);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void blkid_free_dev(blkid_dev dev)
|
||||
{
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
DBG(DEBUG_DEV,
|
||||
printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
|
||||
DBG(DEBUG_DEV, blkid_debug_dump_dev(dev));
|
||||
|
||||
list_del(&dev->bid_devs);
|
||||
while (!list_empty(&dev->bid_tags)) {
|
||||
blkid_tag tag = list_entry(dev->bid_tags.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_tags);
|
||||
blkid_free_tag(tag);
|
||||
}
|
||||
if (dev->bid_name)
|
||||
free(dev->bid_name);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a blkid device, return its name
|
||||
*/
|
||||
const char *blkid_dev_devname(blkid_dev dev)
|
||||
{
|
||||
return dev->bid_name;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
void blkid_debug_dump_dev(blkid_dev dev)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!dev) {
|
||||
printf(" dev: NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" dev: name = %s\n", dev->bid_name);
|
||||
printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
|
||||
printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
|
||||
printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
|
||||
printf(" dev: flags = 0x%08X\n", dev->bid_flags);
|
||||
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
if (tag)
|
||||
printf(" tag: %s=\"%s\"\n", tag->bit_name,
|
||||
tag->bit_val);
|
||||
else
|
||||
printf(" tag: NULL\n");
|
||||
}
|
||||
bb_putchar('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* dev iteration routines for the public libblkid interface.
|
||||
*
|
||||
* These routines do not expose the list.h implementation, which are a
|
||||
* contamination of the namespace, and which force us to reveal far, far
|
||||
* too much of our internal implemenation. I'm not convinced I want
|
||||
* to keep list.h in the long term, anyway. It's fine for kernel
|
||||
* programming, but performance is not the #1 priority for this
|
||||
* library, and I really don't like the tradeoff of type-safety for
|
||||
* performance for this application. [tytso:20030125.2007EST]
|
||||
*/
|
||||
|
||||
/*
|
||||
* This series of functions iterate over all devices in a blkid cache
|
||||
*/
|
||||
#define DEV_ITERATE_MAGIC 0x01a5284c
|
||||
|
||||
struct blkid_struct_dev_iterate {
|
||||
int magic;
|
||||
blkid_cache cache;
|
||||
struct list_head *p;
|
||||
};
|
||||
|
||||
blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
|
||||
{
|
||||
blkid_dev_iterate iter;
|
||||
|
||||
iter = xmalloc(sizeof(struct blkid_struct_dev_iterate));
|
||||
iter->magic = DEV_ITERATE_MAGIC;
|
||||
iter->cache = cache;
|
||||
iter->p = cache->bic_devs.next;
|
||||
return iter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 0 on success, -1 on error
|
||||
*/
|
||||
extern int blkid_dev_next(blkid_dev_iterate iter,
|
||||
blkid_dev *dev)
|
||||
{
|
||||
*dev = 0;
|
||||
if (!iter || iter->magic != DEV_ITERATE_MAGIC ||
|
||||
iter->p == &iter->cache->bic_devs)
|
||||
return -1;
|
||||
*dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs);
|
||||
iter->p = iter->p->next;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blkid_dev_iterate_end(blkid_dev_iterate iter)
|
||||
{
|
||||
if (!iter || iter->magic != DEV_ITERATE_MAGIC)
|
||||
return;
|
||||
iter->magic = 0;
|
||||
free(iter);
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
#endif
|
||||
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog);
|
||||
fprintf(stderr, "\tList all devices and exit\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_dev_iterate iter;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev;
|
||||
int c, ret;
|
||||
char *tmp;
|
||||
char *file = NULL;
|
||||
char *search_type = NULL;
|
||||
char *search_value = NULL;
|
||||
|
||||
while ((c = getopt (argc, argv, "m:f:")) != EOF)
|
||||
switch (c) {
|
||||
case 'f':
|
||||
file = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
usage(argv[0]);
|
||||
}
|
||||
if (argc >= optind+2) {
|
||||
search_type = argv[optind];
|
||||
search_value = argv[optind+1];
|
||||
optind += 2;
|
||||
}
|
||||
if (argc != optind)
|
||||
usage(argv[0]);
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, file)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
iter = blkid_dev_iterate_begin(cache);
|
||||
if (search_type)
|
||||
blkid_dev_set_search(iter, search_type, search_value);
|
||||
while (blkid_dev_next(iter, &dev) == 0) {
|
||||
printf("Device: %s\n", blkid_dev_devname(dev));
|
||||
}
|
||||
blkid_dev_iterate_end(iter);
|
||||
|
||||
|
||||
blkid_put_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,367 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* devname.c - get a dev by its device inode name
|
||||
*
|
||||
* Copyright (C) Andries Brouwer
|
||||
* Copyright (C) 1999, 2000, 2001, 2002, 2003 Theodore Ts'o
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
/*
|
||||
* Find a dev struct in the cache by device name, if available.
|
||||
*
|
||||
* If there is no entry with the specified device name, and the create
|
||||
* flag is set, then create an empty device entry.
|
||||
*/
|
||||
blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
||||
{
|
||||
blkid_dev dev = NULL, tmp;
|
||||
struct list_head *p;
|
||||
|
||||
if (!cache || !devname)
|
||||
return NULL;
|
||||
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
|
||||
if (strcmp(tmp->bid_name, devname))
|
||||
continue;
|
||||
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("found devname %s in cache\n", tmp->bid_name));
|
||||
dev = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!dev && (flags & BLKID_DEV_CREATE)) {
|
||||
dev = blkid_new_dev();
|
||||
if (!dev)
|
||||
return NULL;
|
||||
dev->bid_name = blkid_strdup(devname);
|
||||
dev->bid_cache = cache;
|
||||
list_add_tail(&dev->bid_devs, &cache->bic_devs);
|
||||
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
||||
}
|
||||
|
||||
if (flags & BLKID_DEV_VERIFY)
|
||||
dev = blkid_verify(cache, dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Probe a single block device to add to the device cache.
|
||||
*/
|
||||
static void probe_one(blkid_cache cache, const char *ptname,
|
||||
dev_t devno, int pri)
|
||||
{
|
||||
blkid_dev dev = NULL;
|
||||
struct list_head *p;
|
||||
const char **dir;
|
||||
char *devname = NULL;
|
||||
|
||||
/* See if we already have this device number in the cache. */
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
|
||||
bid_devs);
|
||||
if (tmp->bid_devno == devno) {
|
||||
dev = blkid_verify(cache, tmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dev && dev->bid_devno == devno)
|
||||
goto set_pri;
|
||||
|
||||
/*
|
||||
* Take a quick look at /dev/ptname for the device number. We check
|
||||
* all of the likely device directories. If we don't find it, or if
|
||||
* the stat information doesn't check out, use blkid_devno_to_devname()
|
||||
* to find it via an exhaustive search for the device major/minor.
|
||||
*/
|
||||
for (dir = blkid_devdirs; *dir; dir++) {
|
||||
struct stat st;
|
||||
char device[256];
|
||||
|
||||
sprintf(device, "%s/%s", *dir, ptname);
|
||||
if ((dev = blkid_get_dev(cache, device, BLKID_DEV_FIND)) &&
|
||||
dev->bid_devno == devno)
|
||||
goto set_pri;
|
||||
|
||||
if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
|
||||
st.st_rdev == devno) {
|
||||
devname = blkid_strdup(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!devname) {
|
||||
devname = blkid_devno_to_devname(devno);
|
||||
if (!devname)
|
||||
return;
|
||||
}
|
||||
dev = blkid_get_dev(cache, devname, BLKID_DEV_NORMAL);
|
||||
free(devname);
|
||||
|
||||
set_pri:
|
||||
if (!pri && !strncmp(ptname, "md", 2))
|
||||
pri = BLKID_PRI_MD;
|
||||
if (dev)
|
||||
dev->bid_pri = pri;
|
||||
}
|
||||
|
||||
#define PROC_PARTITIONS "/proc/partitions"
|
||||
#define VG_DIR "/proc/lvm/VGs"
|
||||
|
||||
/*
|
||||
* This function initializes the UUID cache with devices from the LVM
|
||||
* proc hierarchy. We currently depend on the names of the LVM
|
||||
* hierarchy giving us the device structure in /dev. (XXX is this a
|
||||
* safe thing to do?)
|
||||
*/
|
||||
#ifdef VG_DIR
|
||||
#include <dirent.h>
|
||||
static dev_t lvm_get_devno(const char *lvm_device)
|
||||
{
|
||||
FILE *lvf;
|
||||
char buf[1024];
|
||||
int ma, mi;
|
||||
dev_t ret = 0;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
|
||||
if ((lvf = fopen_for_read(lvm_device)) == NULL) {
|
||||
DBG(DEBUG_DEVNAME, printf("%s: (%d) %s\n", lvm_device, errno,
|
||||
strerror(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(buf, sizeof(buf), lvf)) {
|
||||
if (sscanf(buf, "device: %d:%d", &ma, &mi) == 2) {
|
||||
ret = makedev(ma, mi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(lvf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void lvm_probe_all(blkid_cache cache)
|
||||
{
|
||||
DIR *vg_list;
|
||||
struct dirent *vg_iter;
|
||||
int vg_len = strlen(VG_DIR);
|
||||
dev_t dev;
|
||||
|
||||
if ((vg_list = opendir(VG_DIR)) == NULL)
|
||||
return;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("probing LVM devices under %s\n", VG_DIR));
|
||||
|
||||
while ((vg_iter = readdir(vg_list)) != NULL) {
|
||||
DIR *lv_list;
|
||||
char *vdirname;
|
||||
char *vg_name;
|
||||
struct dirent *lv_iter;
|
||||
|
||||
vg_name = vg_iter->d_name;
|
||||
if (LONE_CHAR(vg_name, '.') || !strcmp(vg_name, ".."))
|
||||
continue;
|
||||
vdirname = xmalloc(vg_len + strlen(vg_name) + 8);
|
||||
sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
|
||||
|
||||
lv_list = opendir(vdirname);
|
||||
free(vdirname);
|
||||
if (lv_list == NULL)
|
||||
continue;
|
||||
|
||||
while ((lv_iter = readdir(lv_list)) != NULL) {
|
||||
char *lv_name, *lvm_device;
|
||||
|
||||
lv_name = lv_iter->d_name;
|
||||
if (LONE_CHAR(lv_name, '.') || !strcmp(lv_name, ".."))
|
||||
continue;
|
||||
|
||||
lvm_device = xmalloc(vg_len + strlen(vg_name) +
|
||||
strlen(lv_name) + 8);
|
||||
sprintf(lvm_device, "%s/%s/LVs/%s", VG_DIR, vg_name,
|
||||
lv_name);
|
||||
dev = lvm_get_devno(lvm_device);
|
||||
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
|
||||
DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
|
||||
lvm_device,
|
||||
(unsigned int) dev));
|
||||
probe_one(cache, lvm_device, dev, BLKID_PRI_LVM);
|
||||
free(lvm_device);
|
||||
}
|
||||
closedir(lv_list);
|
||||
}
|
||||
closedir(vg_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
|
||||
|
||||
static int
|
||||
evms_probe_all(blkid_cache cache)
|
||||
{
|
||||
char line[100];
|
||||
int ma, mi, sz, num = 0;
|
||||
FILE *procpt;
|
||||
char device[110];
|
||||
|
||||
procpt = fopen_for_read(PROC_EVMS_VOLUMES);
|
||||
if (!procpt)
|
||||
return 0;
|
||||
while (fgets(line, sizeof(line), procpt)) {
|
||||
if (sscanf(line, " %d %d %d %*s %*s %[^\n ]",
|
||||
&ma, &mi, &sz, device) != 4)
|
||||
continue;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
|
||||
device, ma, mi));
|
||||
|
||||
probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS);
|
||||
num++;
|
||||
}
|
||||
fclose(procpt);
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the device data for all available block devices in the system.
|
||||
*/
|
||||
int blkid_probe_all(blkid_cache cache)
|
||||
{
|
||||
FILE *proc;
|
||||
char line[1024];
|
||||
char ptname0[128], ptname1[128], *ptname = NULL;
|
||||
char *ptnames[2];
|
||||
dev_t devs[2];
|
||||
int ma, mi;
|
||||
unsigned long long sz;
|
||||
int lens[2] = { 0, 0 };
|
||||
int which = 0, last = 0;
|
||||
|
||||
ptnames[0] = ptname0;
|
||||
ptnames[1] = ptname1;
|
||||
|
||||
if (!cache)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (cache->bic_flags & BLKID_BIC_FL_PROBED &&
|
||||
time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL)
|
||||
return 0;
|
||||
|
||||
blkid_read_cache(cache);
|
||||
evms_probe_all(cache);
|
||||
#ifdef VG_DIR
|
||||
lvm_probe_all(cache);
|
||||
#endif
|
||||
|
||||
proc = fopen_for_read(PROC_PARTITIONS);
|
||||
if (!proc)
|
||||
return -BLKID_ERR_PROC;
|
||||
|
||||
while (fgets(line, sizeof(line), proc)) {
|
||||
last = which;
|
||||
which ^= 1;
|
||||
ptname = ptnames[which];
|
||||
|
||||
if (sscanf(line, " %d %d %llu %128[^\n ]",
|
||||
&ma, &mi, &sz, ptname) != 4)
|
||||
continue;
|
||||
devs[which] = makedev(ma, mi);
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname));
|
||||
|
||||
/* Skip whole disk devs unless they have no partitions
|
||||
* If we don't have a partition on this dev, also
|
||||
* check previous dev to see if it didn't have a partn.
|
||||
* heuristic: partition name ends in a digit.
|
||||
*
|
||||
* Skip extended partitions.
|
||||
* heuristic: size is 1
|
||||
*
|
||||
* FIXME: skip /dev/{ida,cciss,rd} whole-disk devs
|
||||
*/
|
||||
|
||||
lens[which] = strlen(ptname);
|
||||
if (isdigit(ptname[lens[which] - 1])) {
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("partition dev %s, devno 0x%04X\n",
|
||||
ptname, (unsigned int) devs[which]));
|
||||
|
||||
if (sz > 1)
|
||||
probe_one(cache, ptname, devs[which], 0);
|
||||
lens[which] = 0;
|
||||
lens[last] = 0;
|
||||
} else if (lens[last] && strncmp(ptnames[last], ptname,
|
||||
lens[last])) {
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("whole dev %s, devno 0x%04X\n",
|
||||
ptnames[last], (unsigned int) devs[last]));
|
||||
probe_one(cache, ptnames[last], devs[last], 0);
|
||||
lens[last] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the last device if it wasn't partitioned */
|
||||
if (lens[which])
|
||||
probe_one(cache, ptname, devs[which], 0);
|
||||
|
||||
fclose(proc);
|
||||
|
||||
cache->bic_time = time(NULL);
|
||||
cache->bic_flags |= BLKID_BIC_FL_PROBED;
|
||||
blkid_flush_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Usage: %s\n"
|
||||
"Probe all devices and exit\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if (blkid_probe_all(cache) < 0)
|
||||
printf("%s: error probing devices\n", argv[0]);
|
||||
|
||||
blkid_put_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,222 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* devno.c - find a particular device by its device number (major/minor)
|
||||
*
|
||||
* Copyright (C) 2000, 2001, 2003 Theodore Ts'o
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
struct dir_list {
|
||||
char *name;
|
||||
struct dir_list *next;
|
||||
};
|
||||
|
||||
char *blkid_strndup(const char *s, int length)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
if (!length)
|
||||
length = strlen(s);
|
||||
|
||||
ret = xmalloc(length + 1);
|
||||
strncpy(ret, s, length);
|
||||
ret[length] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *blkid_strdup(const char *s)
|
||||
{
|
||||
return blkid_strndup(s, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function adds an entry to the directory list
|
||||
*/
|
||||
static void add_to_dirlist(const char *name, struct dir_list **list)
|
||||
{
|
||||
struct dir_list *dp;
|
||||
|
||||
dp = xmalloc(sizeof(struct dir_list));
|
||||
dp->name = blkid_strdup(name);
|
||||
dp->next = *list;
|
||||
*list = dp;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function frees a directory list
|
||||
*/
|
||||
static void free_dirlist(struct dir_list **list)
|
||||
{
|
||||
struct dir_list *dp, *next;
|
||||
|
||||
for (dp = *list; dp; dp = next) {
|
||||
next = dp->next;
|
||||
free(dp->name);
|
||||
free(dp);
|
||||
}
|
||||
*list = NULL;
|
||||
}
|
||||
|
||||
static void scan_dir(char *dir_name, dev_t devno, struct dir_list **list,
|
||||
char **devname)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *dp;
|
||||
char path[1024];
|
||||
int dirlen;
|
||||
struct stat st;
|
||||
|
||||
if ((dir = opendir(dir_name)) == NULL)
|
||||
return;
|
||||
dirlen = strlen(dir_name) + 2;
|
||||
while ((dp = readdir(dir)) != 0) {
|
||||
if (dirlen + strlen(dp->d_name) >= sizeof(path))
|
||||
continue;
|
||||
|
||||
if (dp->d_name[0] == '.' &&
|
||||
((dp->d_name[1] == 0) ||
|
||||
((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
|
||||
continue;
|
||||
|
||||
sprintf(path, "%s/%s", dir_name, dp->d_name);
|
||||
if (stat(path, &st) < 0)
|
||||
continue;
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
add_to_dirlist(path, list);
|
||||
else if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
|
||||
*devname = blkid_strdup(path);
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found 0x%llx at %s (%p)\n", devno,
|
||||
path, *devname));
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
/* Directories where we will try to search for device numbers */
|
||||
const char *blkid_devdirs[] = { "/devices", "/devfs", "/dev", NULL };
|
||||
|
||||
/*
|
||||
* This function finds the pathname to a block device with a given
|
||||
* device number. It returns a pointer to allocated memory to the
|
||||
* pathname on success, and NULL on failure.
|
||||
*/
|
||||
char *blkid_devno_to_devname(dev_t devno)
|
||||
{
|
||||
struct dir_list *list = NULL, *new_list = NULL;
|
||||
char *devname = NULL;
|
||||
const char **dir;
|
||||
|
||||
/*
|
||||
* Add the starting directories to search in reverse order of
|
||||
* importance, since we are using a stack...
|
||||
*/
|
||||
for (dir = blkid_devdirs; *dir; dir++)
|
||||
add_to_dirlist(*dir, &list);
|
||||
|
||||
while (list) {
|
||||
struct dir_list *current = list;
|
||||
|
||||
list = list->next;
|
||||
DBG(DEBUG_DEVNO, printf("directory %s\n", current->name));
|
||||
scan_dir(current->name, devno, &new_list, &devname);
|
||||
free(current->name);
|
||||
free(current);
|
||||
if (devname)
|
||||
break;
|
||||
/*
|
||||
* If we're done checking at this level, descend to
|
||||
* the next level of subdirectories. (breadth-first)
|
||||
*/
|
||||
if (list == NULL) {
|
||||
list = new_list;
|
||||
new_list = NULL;
|
||||
}
|
||||
}
|
||||
free_dirlist(&list);
|
||||
free_dirlist(&new_list);
|
||||
|
||||
if (!devname) {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("blkid: cannot find devno 0x%04lx\n",
|
||||
(unsigned long) devno));
|
||||
} else {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found devno 0x%04llx as %s\n", devno, devname));
|
||||
}
|
||||
|
||||
|
||||
return devname;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char *devname, *tmp;
|
||||
int major, minor;
|
||||
dev_t devno;
|
||||
const char *errmsg = "Cannot parse %s: %s\n";
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if ((argc != 2) && (argc != 3)) {
|
||||
fprintf(stderr, "Usage:\t%s device_number\n\t%s major minor\n"
|
||||
"Resolve a device number to a device name\n",
|
||||
argv[0], argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc == 2) {
|
||||
devno = strtoul(argv[1], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "device number", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
major = strtoul(argv[1], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "major number", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
minor = strtoul(argv[2], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "minor number", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
devno = makedev(major, minor);
|
||||
}
|
||||
printf("Looking for device 0x%04Lx\n", devno);
|
||||
devname = blkid_devno_to_devname(devno);
|
||||
free(devname);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Loaded 100 of 553 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user