Compare commits

..
Author SHA1 Message Date
Denis Vlasenko c71db663de backport htons(ntransmitted++) fix 2007-02-01 23:11:04 +00:00
Denis Vlasenko 8b7f6928c6 releasing busybox 1.3.2 2007-01-20 20:20:32 +00:00
Denis Vlasenko a2af67a8c5 busybox 1.3.1 'Christmas Tree' 2006-12-27 04:58:43 +00:00
Denis Vlasenko d0119d15f9 Simple fixes accumulated after 1.3.0.
busybox-1.3.0.ash.patch
busybox-1.3.0.bb_strtou.patch
busybox-1.3.0.CONFIG_FEATURE_TAR_GNU_EXTENSIONS.patch
busybox-1.3.0.dhcprelay.patch
busybox-1.3.0.dpkg_ar.patch
busybox-1.3.0.find.patch
busybox-1.3.0.mount.patch
busybox-1.3.0.perror.patch
busybox-1.3.0.sed.patch
busybox-1.3.0.shadow.patch
busybox-1.3.0.xregcomp.patch
2006-12-27 04:44:51 +00:00
Denis Vlasenko 8d42f86b14 Correcting branch name to be like previous ones 2006-12-27 04:35:04 +00:00
401 changed files with 11932 additions and 15396 deletions

No files matched your search

+6 -6
View File
@@ -397,14 +397,14 @@ config EFENCE
endchoice
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3?"
config DEBUG_YANK_SUSv2
bool "Disable obsolete features removed before SUSv3?"
default y
help
This option will enable backwards compatibility with SuSv2,
This option will disable backwards compatibility with SuSv2,
specifically, old-style numeric options ('command -1 <file>')
will be supported in head, tail, and fold. (Note: should
affect renice too.)
will not be supported in head, tail, and fold. (Note: should
yank from renice too.)
endmenu
@@ -441,7 +441,7 @@ config INSTALL_APPLET_DONT
prompt "not installed"
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL
help
Do not install applet links. Useful when using the -install feature
Do not install applets links. Usefull when using the -install feature
or a standalone shell for rescue pruposes.
endchoice
+28 -18
View File
@@ -1,5 +1,5 @@
VERSION = 1
PATCHLEVEL = 4
PATCHLEVEL = 3
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
@@ -71,7 +71,7 @@ endif
# In both cases the working directory must be the root of the kernel src.
# 1) O=
# Use "make O=dir/to/store/output/files/"
#
#
# 2) Set KBUILD_OUTPUT
# Set the environment variable KBUILD_OUTPUT to point to the directory
# where the output files shall be placed.
@@ -145,7 +145,7 @@ export srctree objtree VPATH TOPDIR
# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
@@ -229,7 +229,7 @@ export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
#
# If $(quiet) is empty, the whole command will be printed.
# If it is set to "quiet_", only the short version will be printed.
# If it is set to "quiet_", only the short version will be printed.
# If it is set to "silent_", nothing wil be printed at all, since
# the variable $(silent_cmd_cc_o_c) doesn't exist.
#
@@ -273,8 +273,8 @@ MAKEFLAGS += -rR
# Make variables (CC, etc...)
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
LD = $(CC) -nostdlib
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
@@ -313,7 +313,7 @@ export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
# When compiling out-of-tree modules, put MODVERDIR in the module
@@ -351,7 +351,7 @@ endif
# catch them early, and hand them over to scripts/kconfig/Makefile
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'.
# For example 'make oldconfig all'.
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).
@@ -429,6 +429,10 @@ libs-y := \
coreutils/libcoreutils/ \
debianutils/ \
e2fsprogs/ \
e2fsprogs/blkid/ \
e2fsprogs/e2p/ \
e2fsprogs/ext2fs/ \
e2fsprogs/uuid/ \
editors/ \
findutils/ \
init/ \
@@ -529,6 +533,7 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y := $(libs-y1) $(libs-y2)
# Build busybox
# ---------------------------------------------------------------------------
# busybox is build from the objects selected by $(busybox-init) and
@@ -561,13 +566,20 @@ busybox-all := $(core-y) $(libs-y)
# Rule to link busybox - also used during CONFIG_KALLSYMS
# May be overridden by arch/$(ARCH)/Makefile
quiet_cmd_busybox__ ?= LINK $@
ifdef CONFIG_STATIC
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
-static \
-o $@ \
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
-Wl,--start-group $(busybox-all) -Wl,--end-group
else
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) -o $@ $(LDFLAGS) \
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
-Wl,--start-group $(busybox-all) -Wl,--end-group
endif
# Generate System.map
quiet_cmd_sysmap = SYSMAP
quiet_cmd_sysmap = SYSMAP
cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
# Link of busybox
@@ -623,7 +635,7 @@ endef
# First command is ':' to allow us to use + in front of this rule
cmd_ksym_ld = $(cmd_busybox__)
define rule_ksym_ld
:
:
+$(call cmd,busybox_version)
$(call cmd,busybox__)
$(Q)echo 'cmd_$@ := $(cmd_busybox__)' > $(@D)/.$(@F).cmd
@@ -674,7 +686,7 @@ busybox: busybox_unstripped
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
busybox_unstripped -o $@
# The actual objects are generated when descending,
# The actual objects are generated when descending,
# make sure no implicit rule kicks in
$(sort $(busybox-all)): $(busybox-dirs) ;
@@ -707,7 +719,7 @@ _localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f)))
localver = $(subst $(space),, \
$(shell cat /dev/null $(_localver)) \
$(patsubst "%",%,$(CONFIG_LOCALVERSION)))
# If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
# and if the SCM is know a tag from the SCM is appended.
# The appended tag is determinded by the SCM used.
@@ -790,14 +802,12 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
#bbox# @ln -fsn asm-$(ARCH) $@
# Split autoconf.h into include/linux/config/*
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs > include/bbconfigopts.h
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
#bbox# piggybacked generation of few .h files
include/config/MARKER: scripts/basic/split-include include/autoconf.h
$(call cmd,split_autoconf)
$(call cmd,gen_bbconfigopts)
@echo ' SPLIT include/autoconf.h -> include/config/*'
@scripts/basic/split-include include/autoconf.h include/config
@echo ' GEN include/bbconfigopts.h'
@$(srctree)/scripts/mkconfigs >include/bbconfigopts.h
@touch $@
# Generate some files
@@ -1235,7 +1245,7 @@ endif
$(build)=$(build-dir) $(@:.ko=.o)
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
# FIXME Should go into a make.lib or something
# FIXME Should go into a make.lib or something
# ===========================================================================
quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
+2 -2
View File
@@ -38,9 +38,9 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
done
endif
check test: busybox busybox.links
check test: busybox
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:1=),-v)
.PHONY: release
release: distclean
+1 -4
View File
@@ -23,9 +23,6 @@ CFLAGS += \
ifeq ($(CONFIG_DEBUG),y)
CFLAGS += -g
LDFLAGS += -g
endif
ifeq ($(CONFIG_STATIC),y)
LDFLAGS += -static
endif
#LDFLAGS += -nostdlib
+1 -5
View File
@@ -164,11 +164,7 @@ man
---
ar
Write support?
----
stty / catv
stty's visible() function and catv's guts are identical. Merge them into
an appropriate libbb function.
----
---
Architectural issues:
+2 -3
View File
@@ -16,7 +16,6 @@ hostprogs-y += usage
always := $(hostprogs-y)
HOSTCFLAGS_usage.o = -I$(srctree)/include
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
include/usage_compressed.h: $(srctree)/include/usage.h applets/usage
$(call cmd,gen_usage_compressed)
@echo ' GEN include/usage_compressed.h'
@$(srctree)/applets/usage_compressed include/usage_compressed.h applets
+20 -28
View File
@@ -13,6 +13,8 @@
*/
#include "busybox.h"
#include <unistd.h>
#include <string.h>
#include <assert.h>
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
@@ -20,9 +22,7 @@
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#warning Note that glibc is utterly unsuitable for static linking anyway.
#endif
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
@@ -44,7 +44,7 @@ static const char usage_messages[] =
static struct BB_applet *applet_using;
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
const unsigned short NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
#ifdef CONFIG_FEATURE_SUID_CONFIG
@@ -320,7 +320,7 @@ static void parse_config_file(void)
}
#else
#define parse_config_file() ((void)0)
#define parse_config_file()
#endif /* CONFIG_FEATURE_SUID_CONFIG */
#ifdef CONFIG_FEATURE_SUID
@@ -340,26 +340,20 @@ static void check_suid(struct BB_applet *applet)
if (sct) {
mode_t m = sct->m_mode;
if (sct->m_uid == ruid)
/* same uid */
if (sct->m_uid == ruid) /* same uid */
m >>= 6;
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
/* same group / in group */
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid)) /* same group / in group */
m >>= 3;
if (!(m & S_IXOTH)) /* is x bit not set ? */
bb_error_msg_and_die("you have no permission to run this applet!");
if (sct->m_gid != 0) {
/* _both_ have to be set for sgid */
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
xsetgid(sct->m_gid);
} else xsetgid(rgid); /* no sgid -> drop */
}
if (sct->m_uid != 0) {
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
else xsetuid(ruid); /* no suid -> drop */
}
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
xsetgid(sct->m_gid);
} else xsetgid(rgid); /* no sgid -> drop */
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
else xsetuid(ruid); /* no suid -> drop */
} else {
/* default: drop all privileges */
xsetgid(rgid);
@@ -465,6 +459,8 @@ static int applet_name_compare(const void *name, const void *vapplet)
return strcmp(name, applet->name);
}
extern const size_t NUM_APPLETS;
struct BB_applet *find_applet_by_name(const char *name)
{
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
@@ -473,19 +469,15 @@ struct BB_applet *find_applet_by_name(const char *name)
void run_applet_by_name(const char *name, int argc, char **argv)
{
if (ENABLE_FEATURE_SUID_CONFIG)
parse_config_file();
if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file();
if (!strncmp(name, "busybox", 7))
exit(busybox_main(argc, argv));
if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv);
/* Do a binary search to find the applet entry given the name. */
applet_using = find_applet_by_name(name);
if (applet_using) {
applet_name = applet_using->name;
if (argc == 2 && !strcmp(argv[1], "--help"))
bb_show_usage();
if (ENABLE_FEATURE_SUID)
check_suid(applet_using);
exit(applet_using->main(argc, argv));
if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage();
if(ENABLE_FEATURE_SUID) check_suid(applet_using);
exit((*(applet_using->main))(argc, argv));
}
}
+35 -33
View File
@@ -14,8 +14,8 @@ const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
* this should be consistent w/ the enum, busybox.h::Location,
* or else...
*/
static const char usr_bin [] = "/usr/bin";
static const char usr_sbin[] = "/usr/sbin";
static const char usr_bin [] ="/usr/bin";
static const char usr_sbin[] ="/usr/sbin";
static const char* const install_dir[] = {
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
@@ -26,25 +26,25 @@ static const char* const install_dir[] = {
};
/* abstract link() */
typedef int (*link_func)(const char *, const char *);
typedef int (*__link_f)(const char *, const char *);
/* create (sym)links for each applet */
static void install_links(const char *busybox, int use_symbolic_links)
{
link_func lf = link;
__link_f Link = link;
char *fpc;
int i;
int rc;
if (use_symbolic_links)
lf = symlink;
Link = symlink;
for (i = 0; applets[i].name != NULL; i++) {
fpc = concat_path_file(
install_dir[applets[i].location],
applets[i].name);
rc = lf(busybox, fpc);
if (rc != 0 && errno != EEXIST) {
install_dir[applets[i].location], applets[i].name);
rc = Link(busybox, fpc);
if (rc!=0 && errno!=EEXIST) {
bb_perror_msg("%s", fpc);
}
free(fpc);
@@ -59,11 +59,10 @@ int main(int argc, char **argv)
{
const char *s;
applet_name = argv[0];
if (*applet_name == '-')
applet_name++;
while ((s = strchr(applet_name, '/')))
applet_name = s + 1;
applet_name=argv[0];
if (*applet_name == '-') applet_name++;
for (s = applet_name; *s ;)
if (*(s++) == '/') applet_name = s;
/* Set locale for everybody except 'init' */
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
@@ -82,41 +81,44 @@ int busybox_main(int argc, char **argv)
*/
if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
int use_symbolic_links = 0;
int rc = 0;
char *busybox;
/* to use symlinks, or not to use symlinks... */
if (argc > 2)
if (strcmp(argv[2], "-s") == 0)
if (argc > 2) {
if ((strcmp(argv[2], "-s") == 0)) {
use_symbolic_links = 1;
}
}
/* link */
// XXX: FIXME: this is broken. Why not just use argv[0] ?
busybox = xreadlink("/proc/self/exe");
if (!busybox)
return 1;
install_links(busybox, use_symbolic_links);
if (ENABLE_FEATURE_CLEAN_UP)
if (busybox) {
install_links(busybox, use_symbolic_links);
free(busybox);
return 0;
} else {
rc = 1;
}
return rc;
}
/* Deal with --help. (Also print help when called with no arguments) */
if (argc == 1 || !strcmp(argv[1], "--help") ) {
if (argc > 2) {
if (argc==1 || !strcmp(argv[1],"--help") ) {
if (argc>2) {
applet_name = argv[2];
run_applet_by_name(applet_name, 2, argv);
} else {
const struct BB_applet *a;
int col, output_width;
output_width = 80 - sizeof("start-stop-daemon, ") - 8;
if (ENABLE_FEATURE_AUTOWIDTH) {
/* Obtain the terminal width. */
get_terminal_width_height(0, &output_width, NULL);
/* leading tab and room to wrap */
output_width -= sizeof("start-stop-daemon, ") + 8;
}
} else output_width = 80 - sizeof("start-stop-daemon, ") - 8;
printf("%s\n"
"Copyright (C) 1998-2006  Erik Andersen, Rob Landley, and others.\n"
@@ -128,19 +130,19 @@ int busybox_main(int argc, char **argv)
"\tlink to busybox for each function they wish to use and BusyBox\n"
"\twill act like whatever it was invoked as!\n"
"\nCurrently defined functions:\n", bb_msg_full_version);
col = 0;
for (a = applets; a->name;) {
col += printf("%s%s", (col ? ", " : "\t"), a->name);
a++;
col=0;
for(a = applets; a->name;) {
col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
if (col > output_width && a->name) {
puts(",");
printf(",\n");
col = 0;
}
}
puts("\n");
return 0;
printf("\n\n");
exit(0);
}
} else run_applet_by_name(argv[1], argc - 1, argv + 1);
} else run_applet_by_name(argv[1], argc-1, argv+1);
bb_error_msg_and_die("applet not found");
}
+1 -1
View File
@@ -4,7 +4,7 @@
#include "../include/autoconf.h"
#include "../include/busybox.h"
static const char usage_messages[] = ""
static const char usage_messages[] =
#define MAKE_USAGE
#include "usage.h"
#include "applets.h"
+1 -1
View File
@@ -131,7 +131,7 @@ config RPM
bool "rpm"
default n
help
Mini RPM applet - queries and extracts RPM packages.
Mini RPM applet - queries and extracts
config TAR
bool "tar"
+1 -1
View File
@@ -87,7 +87,7 @@ int ar_main(int argc, char **argv)
}
archive_handle->offset += 7;
while (get_header_ar(archive_handle) == EXIT_SUCCESS) /* repeat */;
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -23,7 +23,7 @@ int bunzip2_main(int argc, char **argv)
/* Set input filename and number */
filename = argv[optind];
if (filename && NOT_LONE_DASH(filename)) {
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
src_fd = xopen(filename, O_RDONLY);
} else {
+228 -175
View File
@@ -34,7 +34,7 @@
* 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
* for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
* 4) if you go bigger than 15 bits you may get into trouble (untested) as its
* sometimes cast to an unsigned, if you go to 16 bit you will overlap
* sometimes cast to an unsigned int, if you go to 16 bit you will overlap
* int's and chaos is assured, 16381 is the max prime for 14 bit field
*/
@@ -53,16 +53,16 @@
* and available file */
#define PACKAGE_HASH_PRIME 10007
typedef struct edge_s {
unsigned operator:3;
unsigned type:4;
unsigned name:14;
unsigned version:14;
unsigned int operator:3;
unsigned int type:4;
unsigned int name:14;
unsigned int version:14;
} edge_t;
typedef struct common_node_s {
unsigned name:14;
unsigned version:14;
unsigned num_of_edges:14;
unsigned int name:14;
unsigned int version:14;
unsigned int num_of_edges:14;
edge_t **edge;
} common_node_t;
@@ -71,8 +71,8 @@ typedef struct common_node_s {
* likely to be installed at any one time, so there is a bit of leeway here */
#define STATUS_HASH_PRIME 8191
typedef struct status_node_s {
unsigned package:14; /* has to fit PACKAGE_HASH_PRIME */
unsigned status:14; /* has to fit STATUS_HASH_PRIME */
unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */
unsigned int status:14; /* has to fit STATUS_HASH_PRIME */
} status_node_t;
/* Were statically declared here, but such a big bss is nommu-unfriendly */
@@ -104,14 +104,26 @@ enum operator_e {
VER_ANY = 6
};
enum dpkg_opt_e {
dpkg_opt_purge = 1,
dpkg_opt_remove = 2,
dpkg_opt_unpack = 4,
dpkg_opt_configure = 8,
dpkg_opt_install = 16,
dpkg_opt_package_name = 32,
dpkg_opt_filename = 64,
dpkg_opt_list_installed = 128,
dpkg_opt_force_ignore_depends = 256
};
typedef struct deb_file_s {
char *control_file;
char *filename;
unsigned package:14;
unsigned int package:14;
} deb_file_t;
static void make_hash(const char *key, unsigned *start, unsigned *decrement, const int hash_prime)
static void make_hash(const char *key, unsigned int *start, unsigned int *decrement, const int hash_prime)
{
unsigned long int hash_num = key[0];
int len = strlen(key);
@@ -126,24 +138,26 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
* no effect*/
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
}
*start = (unsigned) hash_num % hash_prime;
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
*start = (unsigned int) hash_num % hash_prime;
*decrement = (unsigned int) 1 + (hash_num % (hash_prime - 1));
}
/* this adds the key to the hash table */
static int search_name_hashtable(const char *key)
{
unsigned probe_address = 0;
unsigned probe_decrement = 0;
unsigned int probe_address = 0;
unsigned int probe_decrement = 0;
// char *temp;
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
while (name_hashtable[probe_address] != NULL) {
if (strcmp(name_hashtable[probe_address], key) == 0) {
return probe_address;
}
probe_address -= probe_decrement;
if ((int)probe_address < 0) {
probe_address += NAME_HASH_PRIME;
} else {
probe_address -= probe_decrement;
if ((int)probe_address < 0) {
probe_address += NAME_HASH_PRIME;
}
}
}
name_hashtable[probe_address] = xstrdup(key);
@@ -153,19 +167,20 @@ static int search_name_hashtable(const char *key)
/* this DOESNT add the key to the hashtable
* TODO make it consistent with search_name_hashtable
*/
static unsigned search_status_hashtable(const char *key)
static unsigned int search_status_hashtable(const char *key)
{
unsigned probe_address = 0;
unsigned probe_decrement = 0;
unsigned int probe_address = 0;
unsigned int probe_decrement = 0;
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
while (status_hashtable[probe_address] != NULL) {
if (strcmp(key, name_hashtable[package_hashtable[status_hashtable[probe_address]->package]->name]) == 0) {
break;
}
probe_address -= probe_decrement;
if ((int)probe_address < 0) {
probe_address += STATUS_HASH_PRIME;
} else {
probe_address -= probe_decrement;
if ((int)probe_address < 0) {
probe_address += STATUS_HASH_PRIME;
}
}
}
return probe_address;
@@ -183,6 +198,7 @@ static int version_compare_part(const char *version1, const char *version2)
int tmp_int;
int ver_num1;
int ver_num2;
int ret;
if (version1 == NULL) {
version1 = xstrdup("");
@@ -205,7 +221,8 @@ static int version_compare_part(const char *version1, const char *version2)
free(name1_char);
free(name2_char);
if (tmp_int != 0) {
return tmp_int;
ret = tmp_int;
goto cleanup_version_compare_part;
}
/* Compare digits */
@@ -220,20 +237,24 @@ static int version_compare_part(const char *version1, const char *version2)
free(name1_char);
free(name2_char);
if (ver_num1 < ver_num2) {
return -1;
ret = -1;
goto cleanup_version_compare_part;
}
if (ver_num1 > ver_num2) {
return 1;
else if (ver_num1 > ver_num2) {
ret = 1;
goto cleanup_version_compare_part;
}
}
return 0;
ret = 0;
cleanup_version_compare_part:
return ret;
}
/* if ver1 < ver2 return -1,
* if ver1 = ver2 return 0,
* if ver1 > ver2 return 1,
*/
static int version_compare(const unsigned ver1, const unsigned ver2)
static int version_compare(const unsigned int ver1, const unsigned int ver2)
{
char *ch_ver1 = name_hashtable[ver1];
char *ch_ver2 = name_hashtable[ver2];
@@ -292,31 +313,46 @@ static int version_compare(const unsigned ver1, const unsigned ver2)
return result;
}
static int test_version(const unsigned version1, const unsigned version2, const unsigned operator)
static int test_version(const unsigned int version1, const unsigned int version2, const unsigned int operator)
{
const int version_result = version_compare(version1, version2);
switch (operator) {
case VER_ANY:
return TRUE;
case VER_EQUAL:
return (version_result == 0);
case VER_LESS:
return (version_result < 0);
case VER_LESS_EQUAL:
return (version_result <= 0);
case VER_MORE:
return (version_result > 0);
case VER_MORE_EQUAL:
return (version_result >= 0);
case VER_ANY:
return TRUE;
case VER_EQUAL:
if (version_result == 0) {
return TRUE;
}
break;
case VER_LESS:
if (version_result < 0) {
return TRUE;
}
break;
case VER_LESS_EQUAL:
if (version_result <= 0) {
return TRUE;
}
break;
case VER_MORE:
if (version_result > 0) {
return TRUE;
}
break;
case VER_MORE_EQUAL:
if (version_result >= 0) {
return TRUE;
}
break;
}
return FALSE;
}
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
static int search_package_hashtable(const unsigned int name, const unsigned int version, const unsigned int operator)
{
unsigned probe_address = 0;
unsigned probe_decrement = 0;
unsigned int probe_address = 0;
unsigned int probe_decrement = 0;
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
while (package_hashtable[probe_address] != NULL) {
@@ -357,8 +393,7 @@ static int search_for_provides(int needle, int start_at) {
common_node_t *p;
for (i = start_at + 1; i < PACKAGE_HASH_PRIME; i++) {
p = package_hashtable[i];
if (p == NULL)
continue;
if (p == NULL) continue;
for (j = 0; j < p->num_of_edges; j++)
if (p->edge[j]->type == EDGE_PROVIDES && p->edge[j]->name == needle)
return i;
@@ -386,7 +421,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
* field contains the number of EDGE nodes which follow as part of
* this alternative.
*/
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned edge_type)
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
{
char *line = xstrdup(whole_line);
char *line2;
@@ -405,19 +440,23 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
field += strspn(field, " ");
line2 = xstrdup(field);
field2 = strtok_r(line2, "|", &line_ptr2);
or_edge = NULL;
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS)
&& (strcmp(field, field2) != 0)
) {
or_edge = xmalloc(sizeof(edge_t));
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
(strcmp(field, field2) != 0)) {
or_edge = (edge_t *)xmalloc(sizeof(edge_t));
or_edge->type = edge_type + 1;
} else {
or_edge = NULL;
}
if (or_edge) {
or_edge->name = search_name_hashtable(field);
or_edge->version = 0; // tracks the number of altenatives
add_edge_to_node(parent_node, or_edge);
}
do {
edge = xmalloc(sizeof(edge_t));
edge = (edge_t *) xmalloc(sizeof(edge_t));
edge->type = edge_type;
/* Skip any extra leading spaces */
@@ -431,7 +470,8 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
edge->version = search_name_hashtable("ANY");
} else {
/* Skip leading ' ' or '(' */
version += strspn(field2, " (");
version += strspn(field2, " ");
version += strspn(version, "(");
/* Calculate length of any operator characters */
offset_ch = strspn(version, "<=>");
/* Determine operator */
@@ -476,6 +516,8 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
free(line2);
} while ((field = strtok_r(NULL, ",", &line_ptr1)) != NULL);
free(line);
return;
}
static void free_package(common_node_t *node)
@@ -564,25 +606,27 @@ static int read_package_field(const char *package_buffer, char **field_name, cha
}
offset++;
}
*field_name = NULL;
if (name_length) {
if (name_length == 0) {
*field_name = NULL;
} else {
*field_name = xstrndup(&package_buffer[offset_name_start], name_length);
}
*field_value = NULL;
if (value_length > 0) {
*field_value = xstrndup(&package_buffer[offset_value_start], value_length);
} else {
*field_value = NULL;
}
return next_offset;
}
static unsigned fill_package_struct(char *control_buffer)
static unsigned int fill_package_struct(char *control_buffer)
{
static const char *const field_names[] = { "Package", "Version",
"Pre-Depends", "Depends","Replaces", "Provides",
"Conflicts", "Suggests", "Recommends", "Enhances", 0
};
common_node_t *new_node = xzalloc(sizeof(common_node_t));
common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
char *field_name;
char *field_value;
int field_start = 0;
@@ -602,38 +646,38 @@ static unsigned fill_package_struct(char *control_buffer)
field_num = index_in_str_array(field_names, field_name);
switch (field_num) {
case 0: /* Package */
new_node->name = search_name_hashtable(field_value);
break;
case 1: /* Version */
new_node->version = search_name_hashtable(field_value);
break;
case 2: /* Pre-Depends */
add_split_dependencies(new_node, field_value, EDGE_PRE_DEPENDS);
break;
case 3: /* Depends */
add_split_dependencies(new_node, field_value, EDGE_DEPENDS);
break;
case 4: /* Replaces */
add_split_dependencies(new_node, field_value, EDGE_REPLACES);
break;
case 5: /* Provides */
add_split_dependencies(new_node, field_value, EDGE_PROVIDES);
break;
case 6: /* Conflicts */
add_split_dependencies(new_node, field_value, EDGE_CONFLICTS);
break;
case 7: /* Suggests */
add_split_dependencies(new_node, field_value, EDGE_SUGGESTS);
break;
case 8: /* Recommends */
add_split_dependencies(new_node, field_value, EDGE_RECOMMENDS);
break;
case 9: /* Enhances */
add_split_dependencies(new_node, field_value, EDGE_ENHANCES);
break;
case 0: /* Package */
new_node->name = search_name_hashtable(field_value);
break;
case 1: /* Version */
new_node->version = search_name_hashtable(field_value);
break;
case 2: /* Pre-Depends */
add_split_dependencies(new_node, field_value, EDGE_PRE_DEPENDS);
break;
case 3: /* Depends */
add_split_dependencies(new_node, field_value, EDGE_DEPENDS);
break;
case 4: /* Replaces */
add_split_dependencies(new_node, field_value, EDGE_REPLACES);
break;
case 5: /* Provides */
add_split_dependencies(new_node, field_value, EDGE_PROVIDES);
break;
case 6: /* Conflicts */
add_split_dependencies(new_node, field_value, EDGE_CONFLICTS);
break;
case 7: /* Suggests */
add_split_dependencies(new_node, field_value, EDGE_SUGGESTS);
break;
case 8: /* Recommends */
add_split_dependencies(new_node, field_value, EDGE_RECOMMENDS);
break;
case 9: /* Enhances */
add_split_dependencies(new_node, field_value, EDGE_ENHANCES);
break;
}
fill_package_struct_cleanup:
fill_package_struct_cleanup:
free(field_name);
free(field_value);
}
@@ -652,11 +696,11 @@ static unsigned fill_package_struct(char *control_buffer)
}
/* if num = 1, it returns the want status, 2 returns flag, 3 returns status */
static unsigned get_status(const unsigned status_node, const int num)
static unsigned int get_status(const unsigned int status_node, const int num)
{
char *status_string = name_hashtable[status_hashtable[status_node]->status];
char *state_sub_string;
unsigned state_sub_num;
unsigned int state_sub_num;
int len;
int i;
@@ -674,13 +718,13 @@ static unsigned get_status(const unsigned status_node, const int num)
return state_sub_num;
}
static void set_status(const unsigned status_node_num, const char *new_value, const int position)
static void set_status(const unsigned int status_node_num, const char *new_value, const int position)
{
const unsigned new_value_len = strlen(new_value);
const unsigned new_value_num = search_name_hashtable(new_value);
unsigned want = get_status(status_node_num, 1);
unsigned flag = get_status(status_node_num, 2);
unsigned status = get_status(status_node_num, 3);
const unsigned int new_value_len = strlen(new_value);
const unsigned int new_value_num = search_name_hashtable(new_value);
unsigned int want = get_status(status_node_num, 1);
unsigned int flag = get_status(status_node_num, 2);
unsigned int status = get_status(status_node_num, 3);
int want_len = strlen(name_hashtable[want]);
int flag_len = strlen(name_hashtable[flag]);
int status_len = strlen(name_hashtable[status]);
@@ -740,11 +784,11 @@ static void index_status_file(const char *filename)
char *control_buffer;
char *status_line;
status_node_t *status_node = NULL;
unsigned status_num;
unsigned int status_num;
status_file = xfopen(filename, "r");
while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) {
const unsigned package_num = fill_package_struct(control_buffer);
const unsigned int package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
status_node = xmalloc(sizeof(status_node_t));
/* fill_package_struct doesnt handle the status field */
@@ -968,7 +1012,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
/* Create array of package numbers to check against
* installed package for conflicts*/
while (deb_file[i] != NULL) {
const unsigned package_num = deb_file[i]->package;
const unsigned int package_num = deb_file[i]->package;
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
conflicts[conflicts_num] = package_num;
conflicts_num++;
@@ -981,7 +1025,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
package_hashtable[package_num]->edge[j]->operator);
if (package_hashtable[conflicts_package_num] == NULL) {
/* create a new package */
common_node_t *new_node = xzalloc(sizeof(common_node_t));
common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
new_node->name = package_hashtable[package_num]->edge[j]->name;
new_node->version = package_hashtable[package_num]->edge[j]->version;
package_hashtable[conflicts_package_num] = new_node;
@@ -1010,7 +1054,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
const edge_t *package_edge = package_node->edge[j];
if (package_edge->type == EDGE_CONFLICTS) {
const unsigned package_num =
const unsigned int package_num =
search_package_hashtable(package_edge->name,
package_edge->version,
package_edge->operator);
@@ -1069,7 +1113,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
*/
for (j = 0; j < package_node->num_of_edges; j++) {
const edge_t *package_edge = package_node->edge[j];
unsigned package_num;
unsigned int package_num;
if (package_edge->type == EDGE_OR_PRE_DEPENDS ||
package_edge->type == EDGE_OR_DEPENDS) { /* start an EDGE_OR_ list */
@@ -1302,11 +1346,11 @@ static void list_packages(void)
}
}
static void remove_package(const unsigned package_num, int noisy)
static void remove_package(const unsigned int package_num, int noisy)
{
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
const unsigned status_num = search_status_hashtable(package_name);
const unsigned int status_num = search_status_hashtable(package_name);
const int package_name_length = strlen(package_name);
char **remove_files;
char **exclude_files;
@@ -1354,11 +1398,11 @@ static void remove_package(const unsigned package_num, int noisy)
set_status(status_num, "config-files", 3);
}
static void purge_package(const unsigned package_num)
static void purge_package(const unsigned int package_num)
{
const char *package_name = name_hashtable[package_hashtable[package_num]->name];
const char *package_version = name_hashtable[package_hashtable[package_num]->version];
const unsigned status_num = search_status_hashtable(package_name);
const unsigned int status_num = search_status_hashtable(package_name);
char **remove_files;
char **exclude_files;
char list_name[strlen(package_name) + 25];
@@ -1478,8 +1522,8 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
static void unpack_package(deb_file_t *deb_file)
{
const char *package_name = name_hashtable[package_hashtable[deb_file->package]->name];
const unsigned status_num = search_status_hashtable(package_name);
const unsigned status_package_num = status_hashtable[status_num]->package;
const unsigned int status_num = search_status_hashtable(package_name);
const unsigned int status_package_num = status_hashtable[status_num]->package;
char *info_prefix;
char *list_filename;
archive_handle_t *archive_handle;
@@ -1570,91 +1614,101 @@ int dpkg_main(int argc, char **argv)
{
deb_file_t **deb_file = NULL;
status_node_t *status_node;
char *str_f;
int opt;
int package_num;
int dpkg_opt = 0;
int deb_count = 0;
int state_status;
int status_num;
int i;
enum {
OPT_configure = 0x1,
OPT_force_ignore_depends = 0x2,
OPT_install = 0x4,
OPT_list_installed = 0x8,
OPT_purge = 0x10,
OPT_remove = 0x20,
OPT_unpack = 0x40,
REQ_package_name = 0x8000,
REQ_filename = 0x4000,
};
opt = getopt32(argc, argv, "CF:ilPru", &str_f);
if (opt & OPT_configure) opt |= REQ_package_name; // -C
if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
if (strcmp(str_f, "depends"))
opt &= ~OPT_force_ignore_depends;
}
if (opt & OPT_install) opt |= REQ_filename; // -i
//if (opt & OPT_list_installed) ... // -l
if (opt & OPT_purge) opt |= REQ_package_name; // -P
if (opt & OPT_remove) opt |= REQ_package_name; // -r
if (opt & OPT_unpack) opt |= REQ_filename; // -u (--unpack in official dpkg)
argc -= optind;
argv += optind;
/* check for non-option argument if expected */
if (!opt || (!argc && !(opt && OPT_list_installed)))
bb_show_usage();
name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) {
switch (opt) {
case 'C': // equivalent to --configure in official dpkg
dpkg_opt |= dpkg_opt_configure;
dpkg_opt |= dpkg_opt_package_name;
break;
case 'F': // equivalent to --force in official dpkg
if (strcmp(optarg, "depends") == 0) {
dpkg_opt |= dpkg_opt_force_ignore_depends;
}
break;
case 'i':
dpkg_opt |= dpkg_opt_install;
dpkg_opt |= dpkg_opt_filename;
break;
case 'l':
dpkg_opt |= dpkg_opt_list_installed;
break;
case 'P':
dpkg_opt |= dpkg_opt_purge;
dpkg_opt |= dpkg_opt_package_name;
break;
case 'r':
dpkg_opt |= dpkg_opt_remove;
dpkg_opt |= dpkg_opt_package_name;
break;
case 'u': /* Equivalent to --unpack in official dpkg */
dpkg_opt |= dpkg_opt_unpack;
dpkg_opt |= dpkg_opt_filename;
break;
default:
bb_show_usage();
}
}
/* check for non-option argument if expected */
if ((dpkg_opt == 0) || ((argc == optind) && !(dpkg_opt && dpkg_opt_list_installed))) {
bb_show_usage();
}
/* puts("(Reading database ... xxxxx files and directories installed.)"); */
index_status_file("/var/lib/dpkg/status");
/* if the list action was given print the installed packages and exit */
if (opt & OPT_list_installed) {
if (dpkg_opt & dpkg_opt_list_installed) {
list_packages();
return EXIT_SUCCESS;
}
/* Read arguments and store relevant info in structs */
while (*argv) {
while (optind < argc) {
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
deb_file[deb_count] = xzalloc(sizeof(deb_file_t));
if (opt & REQ_filename) {
deb_file[deb_count] = (deb_file_t *) xzalloc(sizeof(deb_file_t));
if (dpkg_opt & dpkg_opt_filename) {
archive_handle_t *archive_handle;
llist_t *control_list = NULL;
/* Extract the control file */
llist_add_to(&control_list, "./control");
archive_handle = init_archive_deb_ar(argv[0]);
archive_handle = init_archive_deb_ar(argv[optind]);
init_archive_deb_control(archive_handle);
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
if (deb_file[deb_count]->control_file == NULL) {
bb_error_msg_and_die("cannot extract control file");
}
deb_file[deb_count]->filename = xstrdup(argv[0]);
deb_file[deb_count]->filename = xstrdup(argv[optind]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
if (package_num == -1) {
bb_error_msg("invalid control file in %s", argv[0]);
argv++;
bb_error_msg("invalid control file in %s", argv[optind]);
optind++;
continue;
}
deb_file[deb_count]->package = (unsigned) package_num;
deb_file[deb_count]->package = (unsigned int) package_num;
/* Add the package to the status hashtable */
if (opt & (OPT_unpack|OPT_install)) {
if ((dpkg_opt & dpkg_opt_unpack) || (dpkg_opt & dpkg_opt_install)) {
/* Try and find a currently installed version of this package */
status_num = search_status_hashtable(name_hashtable[package_hashtable[deb_file[deb_count]->package]->name]);
/* If no previous entry was found initialise a new entry */
if (status_hashtable[status_num] == NULL
|| status_hashtable[status_num]->status == 0
) {
status_node = xmalloc(sizeof(status_node_t));
if ((status_hashtable[status_num] == NULL) ||
(status_hashtable[status_num]->status == 0)) {
status_node = (status_node_t *) xmalloc(sizeof(status_node_t));
status_node->package = deb_file[deb_count]->package;
/* reinstreq isnt changed to "ok" until the package control info
* is written to the status file*/
@@ -1666,27 +1720,26 @@ int dpkg_main(int argc, char **argv)
}
}
}
else if (opt & REQ_package_name) {
else if (dpkg_opt & dpkg_opt_package_name) {
deb_file[deb_count]->package = search_package_hashtable(
search_name_hashtable(argv[0]),
search_name_hashtable("ANY"), VER_ANY);
search_name_hashtable(argv[optind]),
search_name_hashtable("ANY"), VER_ANY);
if (package_hashtable[deb_file[deb_count]->package] == NULL) {
bb_error_msg_and_die("package %s is uninstalled or unknown", argv[0]);
bb_error_msg_and_die("package %s is uninstalled or unknown", argv[optind]);
}
package_num = deb_file[deb_count]->package;
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
state_status = get_status(status_num, 3);
/* check package status is "installed" */
if (opt & OPT_remove) {
if (strcmp(name_hashtable[state_status], "not-installed") == 0
|| strcmp(name_hashtable[state_status], "config-files") == 0
) {
if (dpkg_opt & dpkg_opt_remove) {
if ((strcmp(name_hashtable[state_status], "not-installed") == 0) ||
(strcmp(name_hashtable[state_status], "config-files") == 0)) {
bb_error_msg_and_die("%s is already removed", name_hashtable[package_hashtable[package_num]->name]);
}
set_status(status_num, "deinstall", 1);
}
else if (opt & OPT_purge) {
else if (dpkg_opt & dpkg_opt_purge) {
/* if package status is "conf-files" then its ok */
if (strcmp(name_hashtable[state_status], "not-installed") == 0) {
bb_error_msg_and_die("%s is already purged", name_hashtable[package_hashtable[package_num]->name]);
@@ -1695,12 +1748,12 @@ int dpkg_main(int argc, char **argv)
}
}
deb_count++;
argv++;
optind++;
}
deb_file[deb_count] = NULL;
/* Check that the deb file arguments are installable */
if (!(opt & OPT_force_ignore_depends)) {
if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) {
if (!check_deps(deb_file, 0, deb_count)) {
bb_error_msg_and_die("dependency check failed");
}
@@ -1709,25 +1762,25 @@ int dpkg_main(int argc, char **argv)
/* TODO: install or remove packages in the correct dependency order */
for (i = 0; i < deb_count; i++) {
/* Remove or purge packages */
if (opt & OPT_remove) {
if (dpkg_opt & dpkg_opt_remove) {
remove_package(deb_file[i]->package, 1);
}
else if (opt & OPT_purge) {
else if (dpkg_opt & dpkg_opt_purge) {
purge_package(deb_file[i]->package);
}
else if (opt & OPT_unpack) {
else if (dpkg_opt & dpkg_opt_unpack) {
unpack_package(deb_file[i]);
}
else if (opt & OPT_install) {
else if (dpkg_opt & dpkg_opt_install) {
unpack_package(deb_file[i]);
/* package is configured in second pass below */
}
else if (opt & OPT_configure) {
else if (dpkg_opt & dpkg_opt_configure) {
configure_package(deb_file[i]);
}
}
/* configure installed packages */
if (opt & OPT_install) {
if (dpkg_opt & dpkg_opt_install) {
for (i = 0; i < deb_count; i++)
configure_package(deb_file[i]);
}
+1 -1
View File
@@ -58,7 +58,7 @@ int gunzip_main(int argc, char **argv)
optind++;
if (old_path == NULL || LONE_DASH(old_path)) {
if (old_path == NULL || strcmp(old_path, "-") == 0) {
src_fd = STDIN_FILENO;
opt |= GUNZIP_OPT_STDOUT;
USE_DESKTOP(opt &= ~GUNZIP_OPT_VERBOSE;)
+1336 -1085
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -43,13 +43,13 @@ void check_header_gzip(int src_fd)
/* Discard original name if any */
if (header.formatted.flags & 0x08) {
/* bit 3 set: original file name present */
while (xread_char(src_fd) != 0);
while(xread_char(src_fd) != 0);
}
/* Discard file comment if any */
if (header.formatted.flags & 0x10) {
/* bit 4 set: file comment present */
while (xread_char(src_fd) != 0);
while(xread_char(src_fd) != 0);
}
/* Read the header checksum */
+2 -2
View File
@@ -67,10 +67,10 @@ void data_extract_all(archive_handle_t *archive_handle)
/* Regular file */
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
file_header->mode);
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
break;
}
}
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
if ((errno != EISDIR) && (res == -1)
@@ -10,8 +10,9 @@
void data_extract_to_buffer(archive_handle_t *archive_handle)
{
unsigned int size = archive_handle->file_header->size;
const unsigned int size = archive_handle->file_header->size;
archive_handle->buffer = xzalloc(size + 1);
xread(archive_handle->src_fd, archive_handle->buffer, size);
}
@@ -4,10 +4,9 @@
*/
#include "unarchive.h"
#include <unistd.h>
void data_extract_to_stdout(archive_handle_t *archive_handle)
{
bb_copyfd_exact_size(archive_handle->src_fd,
STDOUT_FILENO,
archive_handle->file_header->size);
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
}
+34 -34
View File
@@ -32,25 +32,25 @@
#include "unarchive.h"
/* Constants for Huffman coding */
#define MAX_GROUPS 6
#define GROUP_SIZE 50 /* 64 would have been more efficient */
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
#define SYMBOL_RUNA 0
#define SYMBOL_RUNB 1
#define MAX_GROUPS 6
#define GROUP_SIZE 50 /* 64 would have been more efficient */
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
#define SYMBOL_RUNA 0
#define SYMBOL_RUNB 1
/* Status return values */
#define RETVAL_OK 0
#define RETVAL_LAST_BLOCK (-1)
#define RETVAL_NOT_BZIP_DATA (-2)
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
#define RETVAL_DATA_ERROR (-5)
#define RETVAL_OUT_OF_MEMORY (-6)
#define RETVAL_OBSOLETE_INPUT (-7)
#define RETVAL_OK 0
#define RETVAL_LAST_BLOCK (-1)
#define RETVAL_NOT_BZIP_DATA (-2)
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
#define RETVAL_DATA_ERROR (-5)
#define RETVAL_OUT_OF_MEMORY (-6)
#define RETVAL_OBSOLETE_INPUT (-7)
/* Other housekeeping constants */
#define IOBUF_SIZE 4096
#define IOBUF_SIZE 4096
/* This is what we know about each Huffman coding group */
struct group_data {
@@ -151,7 +151,7 @@ static int get_next_block(bunzip_data *bd)
/* Reset longjmp I/O error handling */
i=setjmp(bd->jmpbuf);
if (i) return i;
if(i) return i;
/* Read in header signature and CRC, then validate signature.
(last block signature means CRC is for whole file, return now) */
@@ -166,8 +166,8 @@ static int get_next_block(bunzip_data *bd)
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
it didn't actually work. */
if (get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
if ((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
/* mapping table: if some byte values are never used (encoding things
like ascii text), the compression code removes the gaps to have fewer
@@ -180,7 +180,7 @@ static int get_next_block(bunzip_data *bd)
for (i=0;i<16;i++) {
if(t&(1<<(15-i))) {
k=get_bits(bd,16);
for (j=0;j<16;j++)
for(j=0;j<16;j++)
if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j;
}
}
@@ -196,17 +196,17 @@ static int get_next_block(bunzip_data *bd)
start of the list.) */
if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR;
for (i=0; i<groupCount; i++) mtfSymbol[i] = i;
for (i=0; i<nSelectors; i++) {
for(i=0; i<groupCount; i++) mtfSymbol[i] = i;
for(i=0; i<nSelectors; i++) {
/* Get next value */
for (j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
/* Decode MTF to get the next selector */
uc = mtfSymbol[j];
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
mtfSymbol[0]=selectors[i]=uc;
}
@@ -227,7 +227,7 @@ static int get_next_block(bunzip_data *bd)
t=get_bits(bd, 5)-1;
for (i = 0; i < symCount; i++) {
for (;;) {
for(;;) {
if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
return RETVAL_DATA_ERROR;
@@ -254,7 +254,7 @@ static int get_next_block(bunzip_data *bd)
/* Find largest and smallest lengths in this group */
minLen=maxLen=length[0];
for (i = 1; i < symCount; i++) {
for(i = 1; i < symCount; i++) {
if(length[i] > maxLen) maxLen = length[i];
else if(length[i] < minLen) minLen = length[i];
}
@@ -284,9 +284,9 @@ static int get_next_block(bunzip_data *bd)
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
pp=0;
for (i=minLen;i<=maxLen;i++) {
for(i=minLen;i<=maxLen;i++) {
temp[i]=limit[i]=0;
for (t=0;t<symCount;t++)
for(t=0;t<symCount;t++)
if(length[t]==i) hufGroup->permute[pp++] = t;
}
@@ -325,7 +325,7 @@ static int get_next_block(bunzip_data *bd)
/* Initialize symbol occurrence counters and symbol Move To Front table */
for (i=0;i<256;i++) {
for(i=0;i<256;i++) {
byteCount[i] = 0;
mtfSymbol[i]=(unsigned char)i;
}
@@ -333,7 +333,7 @@ static int get_next_block(bunzip_data *bd)
/* Loop through compressed symbols. */
runPos=dbufCount=selector=0;
for (;;) {
for(;;) {
/* fetch next Huffman coding group from list. */
@@ -372,7 +372,7 @@ got_huff_bits:
/* Figure how how many bits are in next symbol and unget extras */
i=hufGroup->minLen;
while (j>limit[i]) ++i;
while(j>limit[i]) ++i;
bd->inbufBitCount += (hufGroup->maxLen - i);
/* Huffman decode value to get nextSym (with bounds checking) */
@@ -421,7 +421,7 @@ got_huff_bits:
uc = symToByte[mtfSymbol[0]];
byteCount[uc] += t;
while (t--) dbuf[dbufCount++]=uc;
while(t--) dbuf[dbufCount++]=uc;
}
/* Is this the terminating symbol? */
@@ -473,7 +473,7 @@ end_of_huffman_loop:
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
j=0;
for (i=0;i<256;i++) {
for(i=0;i<256;i++) {
k=j+byteCount[i];
byteCount[i] = j;
j=k;
@@ -535,7 +535,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Loop outputting bytes */
for (;;) {
for(;;) {
/* If the output buffer is full, snapshot state and return */
@@ -682,7 +682,7 @@ uncompressStream(int src_fd, int dst_fd)
outbuf=xmalloc(IOBUF_SIZE);
i=start_bunzip(&bd,src_fd,0,0);
if(!i) {
for (;;) {
for(;;) {
if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break;
if(i!=write(dst_fd,outbuf,i)) {
i=RETVAL_UNEXPECTED_OUTPUT_EOF;
+23 -39
View File
@@ -64,6 +64,12 @@
#undef MAXSEG_64K
#define MAXCODE(n) (1L << (n))
/* Block compress mode -C compatible with 2.0 */
static int block_mode = BLOCK_MODE;
/* user settable max # bits/code */
static int maxbits = BITS;
#define htabof(i) htab[i]
#define codetabof(i) codetab[i]
#define tab_prefixof(i) codetabof(i)
@@ -103,38 +109,25 @@ uncompress(int fd_in, int fd_out)
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
unsigned char htab[HSIZE];
unsigned short codetab[HSIZE];
/* Hmm, these were statics - why?! */
/* user settable max # bits/code */
int maxbits; /* = BITS; */
/* block compress mode -C compatible with 2.0 */
int block_mode; /* = BLOCK_MODE; */
memset(inbuf, 0, IBUFSIZ + 64);
memset(outbuf, 0, OBUFSIZ + 2048);
insize = 0;
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(fd_in, inbuf, 1) != 1) {
bb_error_msg("short read");
return -1;
}
inbuf[0] = xread_char(fd_in);
maxbits = inbuf[0] & BIT_MASK;
block_mode = inbuf[0] & BLOCK_MODE;
maxmaxcode = MAXCODE(maxbits);
if (maxbits > BITS) {
bb_error_msg("compressed with %d bits, can only handle "
"%d bits", maxbits, BITS);
bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits,
BITS);
return -1;
}
n_bits = INIT_BITS;
maxcode = MAXCODE(INIT_BITS) - 1;
bitmask = (1 << INIT_BITS) - 1;
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
bitmask = (1 << n_bits) - 1;
oldcode = -1;
finchar = 0;
outpos = 0;
@@ -150,14 +143,13 @@ uncompress(int fd_in, int fd_out)
}
do {
resetbuf:
resetbuf:;
{
int i;
int e;
int o;
o = posbits >> 3;
e = insize - o;
e = insize - (o = (posbits >> 3));
for (i = 0; i < e; ++i)
inbuf[i] = inbuf[i + o];
@@ -168,7 +160,6 @@ uncompress(int fd_in, int fd_out)
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
//error check??
insize += rsize;
}
@@ -193,8 +184,8 @@ uncompress(int fd_in, int fd_out)
{
unsigned char *p = &inbuf[posbits >> 3];
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
}
posbits += n_bits;
@@ -213,9 +204,8 @@ uncompress(int fd_in, int fd_out)
((posbits - 1) +
((n_bits << 3) -
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
n_bits = INIT_BITS;
maxcode = MAXCODE(INIT_BITS) - 1;
bitmask = (1 << INIT_BITS) - 1;
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
bitmask = (1 << n_bits) - 1;
goto resetbuf;
}
@@ -248,15 +238,13 @@ uncompress(int fd_in, int fd_out)
code = tab_prefixof(code);
}
finchar = tab_suffixof(code);
*--stackp = (unsigned char) finchar;
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
/* And put them out in forward order */
{
int i;
i = de_stack - stackp;
if (outpos + i >= OBUFSIZ) {
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
do {
if (i > OBUFSIZ - outpos) {
i = OBUFSIZ - outpos;
@@ -268,14 +256,12 @@ uncompress(int fd_in, int fd_out)
}
if (outpos >= OBUFSIZ) {
full_write(fd_out, outbuf, outpos);
//error check??
write(fd_out, outbuf, outpos);
USE_DESKTOP(total_written += outpos;)
outpos = 0;
}
stackp += i;
i = de_stack - stackp;
} while (i > 0);
} while ((i = (de_stack - stackp)) > 0);
} else {
memcpy(outbuf + outpos, stackp, i);
outpos += i;
@@ -283,8 +269,7 @@ uncompress(int fd_in, int fd_out)
}
/* Generate the new entry. */
code = free_ent;
if (code < maxmaxcode) {
if ((code = free_ent) < maxmaxcode) {
tab_prefixof(code) = (unsigned short) oldcode;
tab_suffixof(code) = (unsigned char) finchar;
free_ent = code + 1;
@@ -297,8 +282,7 @@ uncompress(int fd_in, int fd_out)
} while (rsize > 0);
if (outpos > 0) {
full_write(fd_out, outbuf, outpos);
//error check??
write(fd_out, outbuf, outpos);
USE_DESKTOP(total_written += outpos;)
}
+94 -113
View File
@@ -22,23 +22,15 @@
typedef struct {
int fd;
uint8_t *ptr;
/* Was keeping rc on stack in unlzma and separately allocating buffer,
* but with "buffer 'attached to' allocated rc" code is smaller: */
/* uint8_t *buffer; */
#define RC_BUFFER ((uint8_t*)(rc+1))
uint8_t *buffer;
uint8_t *buffer_end;
/* Had provisions for variable buffer, but we don't need it here */
/* int buffer_size; */
#define RC_BUFFER_SIZE 0x10000
int buffer_size;
uint32_t code;
uint32_t range;
uint32_t bound;
} rc_t;
#define RC_TOP_BITS 24
#define RC_MOVE_BITS 5
#define RC_MODEL_TOTAL_BITS 11
@@ -47,24 +39,22 @@ typedef struct {
/* Called twice: once at startup and once in rc_normalize() */
static void rc_read(rc_t * rc)
{
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
if (buffer_size <= 0)
rc->buffer_size = read(rc->fd, rc->buffer, rc->buffer_size);
if (rc->buffer_size <= 0)
bb_error_msg_and_die("unexpected EOF");
rc->ptr = RC_BUFFER;
rc->buffer_end = RC_BUFFER + buffer_size;
rc->ptr = rc->buffer;
rc->buffer_end = rc->buffer + rc->buffer_size;
}
/* Called once */
static rc_t* rc_init(int fd) /*, int buffer_size) */
static void rc_init(rc_t * rc, int fd, int buffer_size)
{
int i;
rc_t* rc;
rc = xmalloc(sizeof(rc_t) + RC_BUFFER_SIZE);
rc->fd = fd;
/* rc->buffer_size = buffer_size; */
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
rc->buffer = xmalloc(buffer_size);
rc->buffer_size = buffer_size;
rc->buffer_end = rc->buffer + rc->buffer_size;
rc->ptr = rc->buffer_end;
rc->code = 0;
@@ -74,14 +64,13 @@ static rc_t* rc_init(int fd) /*, int buffer_size) */
rc_read(rc);
rc->code = (rc->code << 8) | *rc->ptr++;
}
return rc;
}
/* Called once */
/* Called once. TODO: bb_maybe_free() */
static ATTRIBUTE_ALWAYS_INLINE void rc_free(rc_t * rc)
{
if (ENABLE_FEATURE_CLEAN_UP)
free(rc);
free(rc->buffer);
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
@@ -174,58 +163,53 @@ typedef struct {
} __attribute__ ((packed)) lzma_header_t;
/* #defines will force compiler to compute/optimize each one with each usage.
* Have heart and use enum instead. */
enum {
LZMA_BASE_SIZE = 1846,
LZMA_LIT_SIZE = 768,
#define LZMA_BASE_SIZE 1846
#define LZMA_LIT_SIZE 768
LZMA_NUM_POS_BITS_MAX = 4,
#define LZMA_NUM_POS_BITS_MAX 4
LZMA_LEN_NUM_LOW_BITS = 3,
LZMA_LEN_NUM_MID_BITS = 3,
LZMA_LEN_NUM_HIGH_BITS = 8,
#define LZMA_LEN_NUM_LOW_BITS 3
#define LZMA_LEN_NUM_MID_BITS 3
#define LZMA_LEN_NUM_HIGH_BITS 8
LZMA_LEN_CHOICE = 0,
LZMA_LEN_CHOICE_2 = (LZMA_LEN_CHOICE + 1),
LZMA_LEN_LOW = (LZMA_LEN_CHOICE_2 + 1),
LZMA_LEN_MID = (LZMA_LEN_LOW \
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS))),
LZMA_LEN_HIGH = (LZMA_LEN_MID \
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS))),
LZMA_NUM_LEN_PROBS = (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS)),
#define LZMA_LEN_CHOICE 0
#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
#define LZMA_LEN_MID (LZMA_LEN_LOW \
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
#define LZMA_LEN_HIGH (LZMA_LEN_MID \
+(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
LZMA_NUM_STATES = 12,
LZMA_NUM_LIT_STATES = 7,
#define LZMA_NUM_STATES 12
#define LZMA_NUM_LIT_STATES 7
LZMA_START_POS_MODEL_INDEX = 4,
LZMA_END_POS_MODEL_INDEX = 14,
LZMA_NUM_FULL_DISTANCES = (1 << (LZMA_END_POS_MODEL_INDEX >> 1)),
#define LZMA_START_POS_MODEL_INDEX 4
#define LZMA_END_POS_MODEL_INDEX 14
#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
LZMA_NUM_POS_SLOT_BITS = 6,
LZMA_NUM_LEN_TO_POS_STATES = 4,
#define LZMA_NUM_POS_SLOT_BITS 6
#define LZMA_NUM_LEN_TO_POS_STATES 4
LZMA_NUM_ALIGN_BITS = 4,
#define LZMA_NUM_ALIGN_BITS 4
LZMA_MATCH_MIN_LEN = 2,
LZMA_IS_MATCH = 0,
LZMA_IS_REP = (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
LZMA_IS_REP_G0 = (LZMA_IS_REP + LZMA_NUM_STATES),
LZMA_IS_REP_G1 = (LZMA_IS_REP_G0 + LZMA_NUM_STATES),
LZMA_IS_REP_G2 = (LZMA_IS_REP_G1 + LZMA_NUM_STATES),
LZMA_IS_REP_0_LONG = (LZMA_IS_REP_G2 + LZMA_NUM_STATES),
LZMA_POS_SLOT = (LZMA_IS_REP_0_LONG \
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
LZMA_SPEC_POS = (LZMA_POS_SLOT \
+ (LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS)),
LZMA_ALIGN = (LZMA_SPEC_POS \
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX),
LZMA_LEN_CODER = (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS)),
LZMA_REP_LEN_CODER = (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS),
LZMA_LITERAL = (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS),
};
#define LZMA_MATCH_MIN_LEN 2
#define LZMA_IS_MATCH 0
#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX))
#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
#define LZMA_SPEC_POS (LZMA_POS_SLOT \
+(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
#define LZMA_ALIGN (LZMA_SPEC_POS \
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
USE_DESKTOP(long long) int
unlzma(int src_fd, int dst_fd)
@@ -241,7 +225,7 @@ unlzma(int src_fd, int dst_fd)
uint16_t *prob_lit;
int num_bits;
int num_probs;
rc_t *rc;
rc_t rc;
int i, mi;
uint8_t *buffer;
uint8_t previous_byte = 0;
@@ -250,7 +234,8 @@ unlzma(int src_fd, int dst_fd)
int state = 0;
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
xread(src_fd, &header, sizeof(header));
if (read(src_fd, &header, sizeof(header)) != sizeof(header))
bb_error_msg_and_die("can't read header");
if (header.pos >= (9 * 5 * 5))
bb_error_msg_and_die("bad header");
@@ -275,16 +260,16 @@ unlzma(int src_fd, int dst_fd)
for (i = 0; i < num_probs; i++)
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
rc_init(&rc, src_fd, 0x10000);
while (global_pos + buffer_pos < header.dst_size) {
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
prob =
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
if (rc_is_bit_0(rc, prob)) {
if (rc_is_bit_0(&rc, prob)) {
mi = 1;
rc_update_bit_0(rc, prob);
rc_update_bit_0(&rc, prob);
prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE
* ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
+ (previous_byte >> (8 - lc)))));
@@ -302,7 +287,7 @@ unlzma(int src_fd, int dst_fd)
match_byte <<= 1;
bit = match_byte & 0x100;
prob_lit = prob + 0x100 + bit + mi;
if (rc_get_bit(rc, prob_lit, &mi)) {
if (rc_get_bit(&rc, prob_lit, &mi)) {
if (!bit)
break;
} else {
@@ -313,7 +298,7 @@ unlzma(int src_fd, int dst_fd)
}
while (mi < 0x100) {
prob_lit = prob + mi;
rc_get_bit(rc, prob_lit, &mi);
rc_get_bit(&rc, prob_lit, &mi);
}
previous_byte = (uint8_t) mi;
@@ -321,8 +306,8 @@ unlzma(int src_fd, int dst_fd)
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
// FIXME: error check
write(dst_fd, buffer, header.dict_size);
USE_DESKTOP(total_written += header.dict_size;)
}
if (state < 4)
@@ -335,24 +320,24 @@ unlzma(int src_fd, int dst_fd)
int offset;
uint16_t *prob_len;
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
prob = p + LZMA_IS_REP + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
if (rc_is_bit_0(&rc, prob)) {
rc_update_bit_0(&rc, prob);
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
prob = p + LZMA_LEN_CODER;
} else {
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
prob = p + LZMA_IS_REP_G0 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
if (rc_is_bit_0(&rc, prob)) {
rc_update_bit_0(&rc, prob);
prob = (p + LZMA_IS_REP_0_LONG
+ (state << LZMA_NUM_POS_BITS_MAX) + pos_state);
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
if (rc_is_bit_0(&rc, prob)) {
rc_update_bit_0(&rc, prob);
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
pos = buffer_pos - rep0;
@@ -363,30 +348,30 @@ unlzma(int src_fd, int dst_fd)
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
// FIXME: error check
write(dst_fd, buffer, header.dict_size);
USE_DESKTOP(total_written += header.dict_size;)
}
continue;
} else {
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
}
} else {
uint32_t distance;
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
prob = p + LZMA_IS_REP_G1 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
if (rc_is_bit_0(&rc, prob)) {
rc_update_bit_0(&rc, prob);
distance = rep1;
} else {
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
prob = p + LZMA_IS_REP_G2 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
if (rc_is_bit_0(&rc, prob)) {
rc_update_bit_0(&rc, prob);
distance = rep2;
} else {
rc_update_bit_1(rc, prob);
rc_update_bit_1(&rc, prob);
distance = rep3;
rep3 = rep2;
}
@@ -400,30 +385,30 @@ unlzma(int src_fd, int dst_fd)
}
prob_len = prob + LZMA_LEN_CHOICE;
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
if (rc_is_bit_0(&rc, prob_len)) {
rc_update_bit_0(&rc, prob_len);
prob_len = (prob + LZMA_LEN_LOW
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
offset = 0;
num_bits = LZMA_LEN_NUM_LOW_BITS;
} else {
rc_update_bit_1(rc, prob_len);
rc_update_bit_1(&rc, prob_len);
prob_len = prob + LZMA_LEN_CHOICE_2;
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
if (rc_is_bit_0(&rc, prob_len)) {
rc_update_bit_0(&rc, prob_len);
prob_len = (prob + LZMA_LEN_MID
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
num_bits = LZMA_LEN_NUM_MID_BITS;
} else {
rc_update_bit_1(rc, prob_len);
rc_update_bit_1(&rc, prob_len);
prob_len = prob + LZMA_LEN_HIGH;
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
+ (1 << LZMA_LEN_NUM_MID_BITS));
num_bits = LZMA_LEN_NUM_HIGH_BITS;
}
}
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
rc_bit_tree_decode(&rc, prob_len, num_bits, &len);
len += offset;
if (state < 4) {
@@ -436,7 +421,7 @@ unlzma(int src_fd, int dst_fd)
LZMA_NUM_LEN_TO_POS_STATES ? len :
LZMA_NUM_LEN_TO_POS_STATES - 1)
<< LZMA_NUM_POS_SLOT_BITS);
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
rc_bit_tree_decode(&rc, prob, LZMA_NUM_POS_SLOT_BITS,
&pos_slot);
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
num_bits = (pos_slot >> 1) - 1;
@@ -447,7 +432,7 @@ unlzma(int src_fd, int dst_fd)
} else {
num_bits -= LZMA_NUM_ALIGN_BITS;
while (num_bits--)
rep0 = (rep0 << 1) | rc_direct_bit(rc);
rep0 = (rep0 << 1) | rc_direct_bit(&rc);
prob = p + LZMA_ALIGN;
rep0 <<= LZMA_NUM_ALIGN_BITS;
num_bits = LZMA_NUM_ALIGN_BITS;
@@ -455,7 +440,7 @@ unlzma(int src_fd, int dst_fd)
i = 1;
mi = 1;
while (num_bits--) {
if (rc_get_bit(rc, prob + mi, &mi))
if (rc_get_bit(&rc, prob + mi, &mi))
rep0 |= i;
i <<= 1;
}
@@ -476,8 +461,8 @@ unlzma(int src_fd, int dst_fd)
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
goto bad;
// FIXME: error check
write(dst_fd, buffer, header.dict_size);
USE_DESKTOP(total_written += header.dict_size;)
}
len--;
@@ -485,13 +470,9 @@ unlzma(int src_fd, int dst_fd)
}
}
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
bad:
rc_free(rc);
return -1;
}
rc_free(rc);
// FIXME: error check
write(dst_fd, buffer, buffer_pos);
USE_DESKTOP(total_written += buffer_pos;)
rc_free(&rc);
return USE_DESKTOP(total_written) + 0;
}
File diff suppressed because it is too large. Load diff
@@ -5,13 +5,17 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libbb.h"
#include "unarchive.h"
/*
* Reassign the subarchive metadata parser based on the filename extension
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
* Reassign the subarchive metadata parser based on the filename extension
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
*/
char filter_accept_list_reassign(archive_handle_t *archive_handle)
{
+1 -2
View File
@@ -105,8 +105,7 @@ char get_header_ar(archive_handle_t *archive_handle)
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(typed);
if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
/* repeat */;
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
} else {
archive_handle->action_data(archive_handle);
}
+1 -1
View File
@@ -103,7 +103,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
/* Always round up */
printf("%d blocks\n", (int) (archive_handle->offset % 512 ?
archive_handle->offset / 512 + 1 :
archive_handle->offset / 512
archive_handle->offset / 512
));
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
hardlinks_t *tmp = saved_hardlinks;
+1 -1
View File
@@ -253,7 +253,7 @@ char get_header_tar(archive_handle_t *archive_handle)
}
/* Strip trailing '/' in directories */
/* Must be done after mode is set as '/' is used to check if it's a directory */
/* Must be done after mode is set as '/' is used to check if its a directory */
cp = last_char_is(file_header->name, '/');
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
@@ -3,6 +3,13 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libbb.h"
#include "unarchive.h"
+3 -2
View File
@@ -13,6 +13,7 @@
*/
void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
{
if (jump_size)
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
if (jump_size) {
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
}
}
+121 -168
View File
@@ -10,44 +10,44 @@
#include "busybox.h"
#include "unarchive.h"
#define RPM_HEADER_MAGIC "\216\255\350"
#define RPM_CHAR_TYPE 1
#define RPM_INT8_TYPE 2
#define RPM_INT16_TYPE 3
#define RPM_INT32_TYPE 4
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
#define RPM_STRING_TYPE 6
#define RPM_BIN_TYPE 7
#define RPM_STRING_ARRAY_TYPE 8
#define RPM_I18NSTRING_TYPE 9
#define RPM_HEADER_MAGIC "\216\255\350"
#define RPM_CHAR_TYPE 1
#define RPM_INT8_TYPE 2
#define RPM_INT16_TYPE 3
#define RPM_INT32_TYPE 4
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
#define RPM_STRING_TYPE 6
#define RPM_BIN_TYPE 7
#define RPM_STRING_ARRAY_TYPE 8
#define RPM_I18NSTRING_TYPE 9
#define TAG_NAME 1000
#define TAG_VERSION 1001
#define TAG_RELEASE 1002
#define TAG_SUMMARY 1004
#define TAG_DESCRIPTION 1005
#define TAG_BUILDTIME 1006
#define TAG_BUILDHOST 1007
#define TAG_SIZE 1009
#define TAG_VENDOR 1011
#define TAG_LICENSE 1014
#define TAG_PACKAGER 1015
#define TAG_GROUP 1016
#define TAG_URL 1020
#define TAG_PREIN 1023
#define TAG_POSTIN 1024
#define TAG_FILEFLAGS 1037
#define TAG_FILEUSERNAME 1039
#define TAG_FILEGROUPNAME 1040
#define TAG_SOURCERPM 1044
#define TAG_PREINPROG 1085
#define TAG_POSTINPROG 1086
#define TAG_PREFIXS 1098
#define TAG_DIRINDEXES 1116
#define TAG_BASENAMES 1117
#define TAG_DIRNAMES 1118
#define RPMFILE_CONFIG (1 << 0)
#define RPMFILE_DOC (1 << 1)
#define RPMTAG_NAME 1000
#define RPMTAG_VERSION 1001
#define RPMTAG_RELEASE 1002
#define RPMTAG_SUMMARY 1004
#define RPMTAG_DESCRIPTION 1005
#define RPMTAG_BUILDTIME 1006
#define RPMTAG_BUILDHOST 1007
#define RPMTAG_SIZE 1009
#define RPMTAG_VENDOR 1011
#define RPMTAG_LICENSE 1014
#define RPMTAG_PACKAGER 1015
#define RPMTAG_GROUP 1016
#define RPMTAG_URL 1020
#define RPMTAG_PREIN 1023
#define RPMTAG_POSTIN 1024
#define RPMTAG_FILEFLAGS 1037
#define RPMTAG_FILEUSERNAME 1039
#define RPMTAG_FILEGROUPNAME 1040
#define RPMTAG_SOURCERPM 1044
#define RPMTAG_PREINPROG 1085
#define RPMTAG_POSTINPROG 1086
#define RPMTAG_PREFIXS 1098
#define RPMTAG_DIRINDEXES 1116
#define RPMTAG_BASENAMES 1117
#define RPMTAG_DIRNAMES 1118
#define RPMFILE_CONFIG (1 << 0)
#define RPMFILE_DOC (1 << 1)
enum rpm_functions_e {
rpm_query = 1,
@@ -73,7 +73,7 @@ static int tagcount;
static void extract_cpio_gz(int fd);
static rpm_index **rpm_gettags(int fd, int *num_tags);
static int bsearch_rpmtag(const void *key, const void *item);
static char *rpm_getstr(int tag, int itemindex);
static char *rpm_getstring(int tag, int itemindex);
static int rpm_getint(int tag, int itemindex);
static int rpm_getcount(int tag);
static void fileaction_dobackup(char *filename, int fileref);
@@ -83,29 +83,28 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i
int rpm_main(int argc, char **argv)
{
int opt = 0, func = 0, rpm_fd, offset;
const int pagesize = getpagesize();
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
switch (opt) {
case 'i': /* First arg: Install mode, with q: Information */
if (!func) func = rpm_install;
case 'i': // First arg: Install mode, with q: Information
if (!func) func |= rpm_install;
else func |= rpm_query_info;
break;
case 'q': /* First arg: Query mode */
if (func) bb_show_usage();
func = rpm_query;
case 'q': // First arg: Query mode
if (!func) func |= rpm_query;
else bb_show_usage();
break;
case 'p': /* Query a package */
case 'p': // Query a package
func |= rpm_query_package;
break;
case 'l': /* List files in a package */
case 'l': // List files in a package
func |= rpm_query_list;
break;
case 'd': /* List doc files in a package (implies list) */
case 'd': // List doc files in a package (implies list)
func |= rpm_query_list;
func |= rpm_query_list_doc;
break;
case 'c': /* List config files in a package (implies list) */
case 'c': // List config files in a package (implies list)
func |= rpm_query_list;
func |= rpm_query_list_config;
break;
@@ -113,73 +112,57 @@ int rpm_main(int argc, char **argv)
bb_show_usage();
}
}
argv += optind;
argc -= optind;
if (!argc) bb_show_usage();
while (*argv) {
rpm_fd = xopen(*argv++, O_RDONLY);
mytags = rpm_gettags(rpm_fd, &tagcount);
if (!mytags)
bb_error_msg_and_die("error reading rpm header");
offset = xlseek(rpm_fd, 0, SEEK_CUR);
/* Mimimum is one page */
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
if (optind == argc) bb_show_usage();
while (optind < argc) {
rpm_fd = xopen(argv[optind], O_RDONLY);
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
offset = lseek(rpm_fd, 0, SEEK_CUR);
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_PRIVATE, rpm_fd, 0); // Mimimum is one page
if (func & rpm_install) {
/* Backup any config files */
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
/* Extact the archive */
extract_cpio_gz(rpm_fd);
/* Set the correct file uid/gid's */
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
}
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
if (!(func & (rpm_query_info|rpm_query_list))) {
/* If just a straight query, just give package name */
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
loop_through_files(RPMTAG_BASENAMES, fileaction_dobackup); /* Backup any config files */
extract_cpio_gz(rpm_fd); // Extact the archive
loop_through_files(RPMTAG_BASENAMES, fileaction_setowngrp); /* Set the correct file uid/gid's */
} else if (func & rpm_query && func & rpm_query_package) {
if (!((func & rpm_query_info) || (func & rpm_query_list))) { // If just a straight query, just give package name
printf("%s-%s-%s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_RELEASE, 0));
}
if (func & rpm_query_info) {
/* Do the nice printout */
time_t bdate_time;
struct tm *bdate;
char bdatestring[50];
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)");
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)");
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
printf("Name : %-29sRelocations: %s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_PREFIXS, 0) ? rpm_getstring(RPMTAG_PREFIXS, 0) : "(not relocateable)");
printf("Version : %-34sVendor: %s\n", rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_VENDOR, 0) ? rpm_getstring(RPMTAG_VENDOR, 0) : "(none)");
bdate_time = rpm_getint(RPMTAG_BUILDTIME, 0);
bdate = localtime((time_t *) &bdate_time);
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate);
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0));
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
printf("Release : %-30sBuild Date: %s\n", rpm_getstring(RPMTAG_RELEASE, 0), bdatestring);
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstring(RPMTAG_BUILDHOST, 0));
printf("Group : %-30sSource RPM: %s\n", rpm_getstring(RPMTAG_GROUP, 0), rpm_getstring(RPMTAG_SOURCERPM, 0));
printf("Size : %-33dLicense: %s\n", rpm_getint(RPMTAG_SIZE, 0), rpm_getstring(RPMTAG_LICENSE, 0));
printf("URL : %s\n", rpm_getstring(RPMTAG_URL, 0));
printf("Summary : %s\n", rpm_getstring(RPMTAG_SUMMARY, 0));
printf("Description :\n%s\n", rpm_getstring(RPMTAG_DESCRIPTION, 0));
}
if (func & rpm_query_list) {
int count, it, flags;
count = rpm_getcount(TAG_BASENAMES);
count = rpm_getcount(RPMTAG_BASENAMES);
for (it = 0; it < count; it++) {
flags = rpm_getint(TAG_FILEFLAGS, it);
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
case rpm_query_list_doc:
if (!(flags & RPMFILE_DOC)) continue;
break;
case rpm_query_list_config:
if (!(flags & RPMFILE_CONFIG)) continue;
break;
case rpm_query_list_doc|rpm_query_list_config:
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
break;
flags = rpm_getint(RPMTAG_FILEFLAGS, it);
switch ((func & rpm_query_list_doc) + (func & rpm_query_list_config))
{
case rpm_query_list_doc: if (!(flags & RPMFILE_DOC)) continue; break;
case rpm_query_list_config: if (!(flags & RPMFILE_CONFIG)) continue; break;
case rpm_query_list_doc + rpm_query_list_config: if (!((flags & RPMFILE_CONFIG) || (flags & RPMFILE_DOC))) continue; break;
}
printf("%s%s\n",
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
rpm_getstr(TAG_BASENAMES, it));
printf("%s%s\n", rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, it)), rpm_getstring(RPMTAG_BASENAMES, it));
}
}
}
free(mytags);
optind++;
free (mytags);
}
return 0;
}
@@ -203,25 +186,21 @@ static void extract_cpio_gz(int fd) {
bb_error_msg_and_die("invalid gzip magic");
}
check_header_gzip(archive_handle->src_fd);
xchdir("/"); /* Install RPM's to root */
xchdir("/"); // Install RPM's to root
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
archive_handle->offset = 0;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
/* loop */;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
}
static rpm_index **rpm_gettags(int fd, int *num_tags)
{
/* We should never need mode than 200, and realloc later */
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *));
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
int pass, tagindex = 0;
lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
/* 1st pass is the signature headers, 2nd is the main stuff */
for (pass = 0; pass < 2; pass++) {
for (pass = 0; pass < 2; pass++) { /* 1st pass is the signature headers, 2nd is the main stuff */
struct {
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
uint8_t version; /* 1 byte version number */
@@ -232,31 +211,24 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
rpm_index *tmpindex;
int storepos;
xread(fd, &header, sizeof(header));
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0)
return NULL; /* Invalid magic */
if (header.version != 1)
return NULL; /* This program only supports v1 headers */
read(fd, &header, sizeof(header));
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) return NULL; /* Invalid magic */
if (header.version != 1) return NULL; /* This program only supports v1 headers */
header.size = ntohl(header.size);
header.entries = ntohl(header.entries);
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
storepos = lseek(fd,0,SEEK_CUR) + header.entries * 16;
while (header.entries--) {
tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index));
xread(fd, tmpindex, sizeof(rpm_index));
tmpindex->tag = ntohl(tmpindex->tag);
tmpindex->type = ntohl(tmpindex->type);
tmpindex->count = ntohl(tmpindex->count);
read(fd, tmpindex, sizeof(rpm_index));
tmpindex->tag = ntohl(tmpindex->tag); tmpindex->type = ntohl(tmpindex->type); tmpindex->count = ntohl(tmpindex->count);
tmpindex->offset = storepos + ntohl(tmpindex->offset);
if (pass==0)
tmpindex->tag -= 743;
if (pass==0) tmpindex->tag -= 743;
}
xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
/* Skip padding to 8 byte boundary after reading signature headers */
if (pass==0)
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
lseek(fd, header.size, SEEK_CUR); /* Seek past store */
if (pass==0) lseek(fd, (8 - (lseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); /* Skip padding to 8 byte boundary after reading signature headers */
}
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
tags = realloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
*num_tags = tagindex;
return tags; /* All done, leave the file at the start of the gzipped cpio archive */
}
@@ -272,59 +244,42 @@ static int rpm_getcount(int tag)
{
rpm_index **found;
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found)
return 0;
return found[0]->count;
if (!found) return 0;
else return found[0]->count;
}
static char *rpm_getstr(int tag, int itemindex)
static char *rpm_getstring(int tag, int itemindex)
{
rpm_index **found;
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found || itemindex >= found[0]->count)
return NULL;
if (!found || itemindex >= found[0]->count) return NULL;
if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) {
int n;
char *tmpstr = (char *) (map + found[0]->offset);
for (n=0; n < itemindex; n++)
tmpstr = tmpstr + strlen(tmpstr) + 1;
for (n=0; n < itemindex; n++) tmpstr = tmpstr + strlen(tmpstr) + 1;
return tmpstr;
}
return NULL;
} else return NULL;
}
static int rpm_getint(int tag, int itemindex)
{
rpm_index **found;
int *tmpint; /* NB: using int8_t* would be easier to code */
int n, *tmpint;
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
* it's ok to ignore it because tag won't be used as a pointer */
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
if (!found || itemindex >= found[0]->count)
return -1;
if (!found || itemindex >= found[0]->count) return -1;
tmpint = (int *) (map + found[0]->offset);
if (found[0]->type == RPM_INT32_TYPE) {
tmpint = (int *) ((char *) tmpint + itemindex*4);
/*return ntohl(*tmpint);*/
/* int can be != int32_t */
return ntohl(*(int32_t*)tmpint);
}
if (found[0]->type == RPM_INT16_TYPE) {
tmpint = (int *) ((char *) tmpint + itemindex*2);
/* ??? read int, and THEN ntohs() it?? */
/*return ntohs(*tmpint);*/
return ntohs(*(int16_t*)tmpint);
}
if (found[0]->type == RPM_INT8_TYPE) {
tmpint = (int *) ((char *) tmpint + itemindex);
/* ??? why we don't read byte here??? */
/*return ntohs(*tmpint);*/
return *(int8_t*)tmpint;
}
return -1;
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 4);
return ntohl(*tmpint);
} else if (found[0]->type == RPM_INT16_TYPE) {
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 2);
return ntohs(*tmpint);
} else if (found[0]->type == RPM_INT8_TYPE) {
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 1);
return ntohs(*tmpint);
} else return -1;
}
static void fileaction_dobackup(char *filename, int fileref)
@@ -332,11 +287,9 @@ static void fileaction_dobackup(char *filename, int fileref)
struct stat oldfile;
int stat_res;
char *newname;
if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) {
/* Only need to backup config files */
stat_res = lstat(filename, &oldfile);
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) {
/* File already exists - really should check MD5's etc to see if different */
if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
stat_res = lstat (filename, &oldfile);
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
newname = xasprintf("%s.rpmorig", filename);
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
@@ -348,18 +301,18 @@ static void fileaction_dobackup(char *filename, int fileref)
static void fileaction_setowngrp(char *filename, int fileref)
{
int uid, gid;
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
chown(filename, uid, gid);
}
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
{
int count = 0;
while (rpm_getstr(filetag, count)) {
char* filename = xasprintf("%s%s",
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)),
rpm_getstr(TAG_BASENAMES, count));
while (rpm_getstring(filetag, count)) {
char * filename = xasprintf("%s%s",
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
count)), rpm_getstring(RPMTAG_BASENAMES, count));
fileaction(filename, count++);
free(filename);
}
+55 -95
View File
@@ -23,10 +23,10 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <fnmatch.h>
#include <getopt.h>
#include "busybox.h"
#include "unarchive.h"
#include <fnmatch.h>
#include <getopt.h>
#if ENABLE_FEATURE_TAR_CREATE
@@ -37,7 +37,6 @@
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
#define NAME_SIZE 100
#define NAME_SIZE_STR "100"
typedef struct TarHeader TarHeader;
struct TarHeader { /* byte offset */
char name[NAME_SIZE]; /* 0-99 */
char mode[8]; /* 100-107 */
@@ -57,6 +56,7 @@ struct TarHeader { /* byte offset */
char prefix[155]; /* 345-499 */
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
};
typedef struct TarHeader TarHeader;
/*
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
@@ -73,7 +73,6 @@ struct HardLinkInfo {
};
/* Some info to be carried along when creating a new tarball */
typedef struct TarBallInfo TarBallInfo;
struct TarBallInfo {
int tarFd; /* Open-for-write file descriptor
for the tarball */
@@ -86,6 +85,7 @@ struct TarBallInfo {
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
};
typedef struct TarBallInfo TarBallInfo;
/* A nice enum with all the possible tar file content types */
enum TarFileType {
@@ -348,7 +348,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
return TRUE;
}
#if ENABLE_FEATURE_TAR_FROM
# if ENABLE_FEATURE_TAR_FROM
static int exclude_file(const llist_t *excluded_files, const char *file)
{
while (excluded_files) {
@@ -371,12 +371,12 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
return 0;
}
#else
# else
#define exclude_file(excluded_files, file) 0
#endif
# endif
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth ATTRIBUTE_UNUSED)
void *userData, int depth)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
@@ -452,28 +452,26 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
/* If it was a regular file, write out the body */
if (inputFileFd >= 0) {
size_t readSize;
/* Wwrite the file to the archive. */
/* We record size into header first, */
/* and then write out file. If file shrinks in between, */
/* tar will be corrupted. So we don't allow for that. */
/* NB: GNU tar 1.16 warns and pads with zeroes */
/* or even seeks back and updates header */
bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
////off_t readSize;
////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
////if (readSize != statbuf->st_size && readSize >= 0) {
//// bb_error_msg_and_die("short read from %s, aborting", fileName);
////}
off_t readSize = 0;
/* write the file to the archive */
readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
/* readSize < 0 means that error was already reported */
if (readSize != statbuf->st_size && readSize >= 0) {
/* Deadly. We record size into header first, */
/* and then write out file. If file shrinks in between, */
/* tar will be corrupted. So bail out. */
/* NB: GNU tar 1.16 warns and pads with zeroes */
/* or even seeks back and updates header */
bb_error_msg_and_die("short read from %s, aborting", fileName);
}
/* Check that file did not grow in between? */
/* if (safe_read(inputFileFd, 1) == 1) warn but continue? */
/* if (safe_read(inputFileFd,1) == 1) warn but continue? */
close(inputFileFd);
/* Pad the file up to the tar block size */
/* (a few tricks here in the name of code size) */
readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1);
readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1);
memset(bb_common_bufsiz1, 0, readSize);
xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize);
}
@@ -506,17 +504,18 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
volatile int vfork_exec_errno = 0;
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
bb_perror_msg_and_die("pipe");
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
#if defined(__GNUC__) && __GNUC__
# if __GNUC__
/* Avoid vfork clobbering */
(void) &include;
(void) &errorFlag;
(void) &zip_exec;
#endif
# endif
gzipPid = vfork();
@@ -586,21 +585,16 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
if (gzipPid) {
int status;
if (waitpid(gzipPid, &status, 0) == -1)
bb_perror_msg("waitpid");
else if (!WIFEXITED(status) || WEXITSTATUS(status))
/* gzip was killed or has exited with nonzero! */
errorFlag = TRUE;
}
return errorFlag;
if (gzipPid && waitpid(gzipPid, NULL, 0) == -1)
bb_error_msg("waitpid failed");
return !errorFlag;
}
#else
int writeTarFile(const int tar_fd, const int verboseFlag,
const unsigned long dereferenceFlag, const llist_t *include,
const llist_t *exclude, const int gzip);
#endif /* FEATURE_TAR_CREATE */
#endif /* tar_create */
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
@@ -628,7 +622,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
return newlist;
}
#else
#define append_file_list_to_list(x) 0
#define append_file_list_to_list(x) 0
#endif
#if ENABLE_FEATURE_TAR_COMPRESS
@@ -653,30 +647,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
return EXIT_FAILURE;
}
#else
#define get_header_tar_Z NULL
#endif
#ifdef CHECK_FOR_CHILD_EXITCODE
/* Looks like it isn't needed - tar detects malformed (truncated)
* archive if e.g. bunzip2 fails */
static int child_error;
static void handle_SIGCHLD(int status)
{
/* Actually, 'status' is a signo. We reuse it for other needs */
/* Wait for any child without blocking */
if (waitpid(-1, &status, WNOHANG) < 0)
/* wait failed?! I'm confused... */
return;
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
/* child exited with 0 */
return;
/* Cannot happen?
if(!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
child_error = 1;
}
#define get_header_tar_Z 0
#endif
enum {
@@ -760,9 +731,7 @@ int tar_main(int argc, char **argv)
const char *tar_filename = "-";
unsigned opt;
int verboseFlag = 0;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
llist_t *excludes = NULL;
#endif
/* Initialise default values */
tar_handle = init_handle();
@@ -775,9 +744,7 @@ int tar_main(int argc, char **argv)
"tt:vv:" // count -t,-v
"?:" // bail out with usage instead of error return
"X::T::" // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // cumulative lists for --exclude
#endif
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
@@ -792,15 +759,14 @@ int tar_main(int argc, char **argv)
USE_FEATURE_TAR_FROM( "T:X:")
USE_FEATURE_TAR_GZIP( "z" )
USE_FEATURE_TAR_COMPRESS("Z" )
, &base_dir // -C dir
, &tar_filename // -f filename
USE_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
USE_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
, &excludes // --exclude
#endif
, &verboseFlag // combined count for -t and -v
, &verboseFlag // combined count for -t and -v
,
&base_dir, // -C dir
&tar_filename, // -f filename
USE_FEATURE_TAR_FROM(&(tar_handle->accept),) // T
USE_FEATURE_TAR_FROM(&(tar_handle->reject),) // X
USE_FEATURE_TAR_FROM(&excludes ,) // --exclude
&verboseFlag, // combined count for -t and -v
&verboseFlag // combined count for -t and -v
);
if (verboseFlag) tar_handle->action_header = header_verbose_list;
@@ -833,19 +799,17 @@ int tar_main(int argc, char **argv)
if (opt & OPT_COMPRESS)
get_header_ptr = get_header_tar_Z;
#if ENABLE_FEATURE_TAR_FROM
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
/* Append excludes to reject */
while (excludes) {
llist_t *next = excludes->link;
excludes->link = tar_handle->reject;
tar_handle->reject = excludes;
excludes = next;
if (ENABLE_FEATURE_TAR_FROM) {
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
/* Append excludes to reject */
while (excludes) {
llist_t *temp = excludes->link;
excludes->link = tar_handle->reject;
tar_handle->reject = excludes;
excludes = temp;
}
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
}
#endif
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
#endif
/* Check if we are reading from stdin */
if (argv[optind] && *argv[optind] == '-') {
@@ -887,7 +851,7 @@ int tar_main(int argc, char **argv)
flags = O_RDONLY;
}
if (LONE_DASH(tar_filename)) {
if (tar_filename[0] == '-' && !tar_filename[1]) {
tar_handle->src_fd = fileno(tar_stream);
tar_handle->seek = seek_by_read;
} else {
@@ -898,11 +862,6 @@ int tar_main(int argc, char **argv)
if (base_dir)
xchdir(base_dir);
#ifdef CHECK_FOR_CHILD_EXITCODE
/* We need to know whether child (gzip/bzip/etc) exits abnormally */
signal(SIGCHLD, handle_SIGCHLD);
#endif
/* create an archive */
if (opt & OPT_CREATE) {
int zipMode = 0;
@@ -910,10 +869,11 @@ int tar_main(int argc, char **argv)
zipMode = 1;
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
zipMode = 2;
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
tar_handle->accept,
tar_handle->reject, zipMode);
/* NB: writeTarFile() closes tar_handle->src_fd */
return EXIT_SUCCESS;
}
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
+1 -1
View File
@@ -25,7 +25,7 @@ int uncompress_main(int argc, char **argv)
int src_fd;
int dst_fd;
if (LONE_DASH(compressed_file)) {
if (strcmp(compressed_file, "-") == 0) {
src_fd = STDIN_FILENO;
flags |= GUNZIP_TO_STDOUT;
} else {
+1 -1
View File
@@ -26,7 +26,7 @@ int unlzma_main(int argc, char **argv)
/* Set input filename and number */
filename = argv[optind];
if (filename && NOT_LONE_DASH(filename)) {
if (filename && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
src_fd = xopen(filename, O_RDONLY);
} else {
+27 -16
View File
@@ -32,6 +32,9 @@
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
extern unsigned int gunzip_crc;
extern unsigned int gunzip_bytes_out;
typedef union {
unsigned char raw[26];
struct {
@@ -51,9 +54,9 @@ typedef union {
static void unzip_skip(int fd, off_t skip)
{
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
if (errno != ESPIPE)
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
bb_error_msg_and_die("seek failure");
bb_copyfd_exact_size(fd, -1, skip);
}
}
}
@@ -72,20 +75,22 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
if (zip_header->formatted.method == 0) {
/* Method 0 - stored (not compressed) */
off_t size = zip_header->formatted.ucmpsize;
if (size)
bb_copyfd_exact_size(src_fd, dst_fd, size);
if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
bb_error_msg_and_die("cannot complete extraction");
}
} else {
/* Method 8 - inflate */
inflate_unzip_result res;
/* err = */ inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd);
// we should check for -1 error return
inflate_init(zip_header->formatted.cmpsize);
inflate_unzip(src_fd, dst_fd);
inflate_cleanup();
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
bb_error_msg("invalid compressed data--%s error", "crc");
return 1;
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != res.bytes_out) {
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
bb_error_msg("invalid compressed data--%s error", "length");
return 1;
}
@@ -109,7 +114,7 @@ int unzip_main(int argc, char **argv)
char key_buf[512];
struct stat stat_buf;
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
while((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
switch (opt_range) {
case 0: /* Options */
switch (opt) {
@@ -182,14 +187,15 @@ int unzip_main(int argc, char **argv)
}
/* Open input file */
if (LONE_DASH(src_fn)) {
if (strcmp("-", src_fn) == 0) {
src_fd = STDIN_FILENO;
/* Cannot use prompt mode since zip data is arriving on STDIN */
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
} else {
static const char *const extn[] = {"", ".zip", ".ZIP"};
int orig_src_fn_len = strlen(src_fn);
for (i = 0; (i < 3) && (src_fd == -1); i++) {
for(i = 0; (i < 3) && (src_fd == -1); i++) {
strcpy(src_fn + orig_src_fn_len, extn[i]);
src_fd = open(src_fn, O_RDONLY);
}
@@ -244,8 +250,8 @@ int unzip_main(int argc, char **argv)
unzip_skip(src_fd, zip_header.formatted.extra_len);
if ((verbosity == v_list) && !list_header_done){
puts(" Length Date Time Name\n"
" -------- ---- ---- ----");
printf(" Length Date Time Name\n"
" -------- ---- ---- ----\n");
list_header_done = 1;
}
@@ -269,8 +275,10 @@ int unzip_main(int argc, char **argv)
dst_fn);
total_entries++;
i = 'n';
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
i = -1;
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
@@ -291,15 +299,17 @@ int unzip_main(int argc, char **argv)
i = 'n';
} else { /* Extract file */
_check_file:
_check_file:
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
i = 'y';
} else { /* File already exists */
if (overwrite == o_never) {
i = 'n';
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
if (overwrite == o_always) {
i = 'y';
@@ -310,6 +320,7 @@ int unzip_main(int argc, char **argv)
}
i = key_buf[0];
}
} else { /* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
}
@@ -328,7 +339,7 @@ int unzip_main(int argc, char **argv)
printf(" inflating: %s\n", dst_fn);
}
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
failed = 1;
failed = 1;
}
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
+3 -3
View File
@@ -81,14 +81,14 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
struct unipair *up;
int ct = 0, maxct;
int glyph;
uint16_t unicode;
u_short unicode;
maxct = tailsz; /* more than enough */
up = xmalloc(maxct * sizeof(struct unipair));
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
+2 -2
View File
@@ -29,7 +29,7 @@ int loadkmap_main(int argc, char **argv)
{
struct kbentry ke;
int i, j, fd;
uint16_t ibuff[NR_KEYS];
u_short ibuff[NR_KEYS];
char flags[MAX_NR_KEYMAPS];
char buff[7];
@@ -46,7 +46,7 @@ int loadkmap_main(int argc, char **argv)
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
xread(0, ibuff, NR_KEYS * sizeof(u_short));
for (j = 0; j < NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
+9 -6
View File
@@ -17,6 +17,7 @@ int openvt_main(int argc, char **argv)
int fd;
char vtname[sizeof(VC_FORMAT) + 2];
if (argc < 3) {
bb_show_usage();
}
@@ -24,16 +25,18 @@ int openvt_main(int argc, char **argv)
sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63));
if (fork() == 0) {
/* child */
/* leave current vt (controlling tty) */
setsid();
/* leave current vt */
if (setsid() < 0) {
bb_perror_msg_and_die("setsid");
}
close(0); /* so that new vt becomes stdin */
/* and grab new one */
fd = xopen(vtname, O_RDWR);
/* Reassign stdin, stdout and sterr */
dup2(fd, STDIN_FILENO);
/* Reassign stdout and sterr */
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
while (fd > 2) close(fd--);
execvp(argv[2], &argv[2]);
_exit(1);
-3
View File
@@ -10,7 +10,6 @@ lib-y:=
lib-$(CONFIG_BASENAME) += basename.o
lib-$(CONFIG_CAL) += cal.o
lib-$(CONFIG_CAT) += cat.o
lib-$(CONFIG_LESS) += cat.o # less uses it if stdout isn't a tty
lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
@@ -29,7 +28,6 @@ lib-$(CONFIG_DIRNAME) += dirname.o
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
lib-$(CONFIG_DU) += du.o
lib-$(CONFIG_ECHO) += echo.o
lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_ENV) += env.o
lib-$(CONFIG_EXPR) += expr.o
lib-$(CONFIG_FALSE) += false.o
@@ -67,7 +65,6 @@ lib-$(CONFIG_SYNC) += sync.o
lib-$(CONFIG_TAIL) += tail.o
lib-$(CONFIG_TEE) += tee.o
lib-$(CONFIG_TEST) += test.o
lib-$(CONFIG_ASH) += test.o # used by ash
lib-$(CONFIG_TOUCH) += touch.o
lib-$(CONFIG_TR) += tr.o
lib-$(CONFIG_TRUE) += true.o
+5
View File
@@ -87,6 +87,11 @@ int cal_main(int argc, char **argv)
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
char buf[40];
// Done in busybox.c, ok to remove?
//#ifdef CONFIG_LOCALE_SUPPORT
// setlocale(LC_TIME, "");
//#endif
flags = getopt32(argc, argv, "jy");
julian = flags & 1;
+10 -11
View File
@@ -11,32 +11,31 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
#include "busybox.h"
#include <unistd.h>
int bb_cat(char **argv)
int cat_main(int argc, char **argv)
{
static char *const argv_dash[] = { "-", NULL };
FILE *f;
int retval = EXIT_SUCCESS;
if (!*argv) argv = (char**) &argv_dash;
getopt32(argc, argv, "u");
argv += optind;
if (!*argv) {
*--argv = "-";
}
do {
f = fopen_or_warn_stdin(*argv);
if (f) {
off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
fclose_if_not_stdin(f);
if (r >= 0)
if (r >= 0) {
continue;
}
}
retval = EXIT_FAILURE;
} while (*++argv);
return retval;
}
int cat_main(int argc, char **argv)
{
getopt32(argc, argv, "u");
argv += optind;
return bb_cat(argv);
}
-3
View File
@@ -13,9 +13,6 @@
#include "busybox.h"
/* FIXME - move to .h */
extern int chown_main(int argc, char **argv);
int chgrp_main(int argc, char **argv)
{
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
+22 -27
View File
@@ -13,7 +13,8 @@
#include "busybox.h"
static struct bb_uidgid_t ugid = { -1, -1 };
static uid_t uid = -1;
static gid_t gid = -1;
static int (*chown_func)(const char *, uid_t, gid_t) = chown;
@@ -37,14 +38,12 @@ static int fileAction(const char *fileName, struct stat *statbuf,
// if (depth ... && S_ISLNK(statbuf->st_mode)) ....
if (!chown_func(fileName,
(ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid,
(ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid)
) {
(uid == (uid_t)-1) ? statbuf->st_uid : uid,
(gid == (gid_t)-1) ? statbuf->st_gid : gid)) {
if (OPT_VERBOSE
|| (OPT_CHANGED && (statbuf->st_uid != ugid.uid || statbuf->st_gid != ugid.gid))
|| (OPT_CHANGED && (statbuf->st_uid != uid || statbuf->st_gid != gid))
) {
printf("changed ownership of '%s' to %u:%u\n",
fileName, ugid.uid, ugid.gid);
printf("changed ownership of '%s' to %u:%u\n", fileName, uid, gid);
}
return TRUE;
}
@@ -55,36 +54,32 @@ static int fileAction(const char *fileName, struct stat *statbuf,
int chown_main(int argc, char **argv)
{
char *groupName;
int retval = EXIT_SUCCESS;
char *groupName;
opt_complementary = "-2";
getopt32(argc, argv, OPT_STR);
argv += optind;
if (OPT_NODEREF) chown_func = lchown;
/* First, check if there is a group name here */
groupName = strchr(*argv, '.'); /* deprecated? */
if (!groupName)
groupName = strchr(*argv, ':');
else
*groupName = ':'; /* replace '.' with ':' */
argv += optind;
/* First, try parsing "user[:[group]]" */
if (!groupName) { /* "user" */
ugid.uid = get_ug_id(*argv, xuname2uid);
} else if (groupName == *argv) { /* ":group" */
ugid.gid = get_ug_id(groupName + 1, xgroup2gid);
} else {
if (!groupName[1]) /* "user:" */
*groupName = '\0';
if (!get_uidgid(&ugid, *argv, 1))
bb_error_msg_and_die("unknown user/group %s", *argv);
/* First, check if there is a group name here */
groupName = strchr(*argv, '.');
if (!groupName) {
groupName = strchr(*argv, ':');
}
/* Check for the username and groupname */
if (groupName) {
*groupName++ = '\0';
gid = get_ug_id(groupName, bb_xgetgrnam);
}
if (--groupName != *argv)
uid = get_ug_id(*argv, bb_xgetpwnam);
++argv;
/* Ok, ready to do the deed now */
argv++;
do {
if (!recursive_action(*argv,
OPT_RECURSE, // recurse
@@ -93,7 +88,7 @@ int chown_main(int argc, char **argv)
fileAction, // file action
fileAction, // dir action
NULL, // user data
0) // depth
0) // depth
) {
retval = EXIT_FAILURE;
}
+6 -7
View File
@@ -168,8 +168,6 @@ int cut_main(int argc, char **argv)
opt_complementary = "b--bcf:c--bcf:f--bcf";
getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, &ltok);
// argc -= optind;
argv += optind;
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
if (option_mask32 & BB_GETOPT_ERROR)
@@ -264,21 +262,22 @@ int cut_main(int argc, char **argv)
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
}
/* argv[0..argc-1] should be names of file to process. If no
/* argv[(optind)..(argc-1)] should be names of file to process. If no
* files were specified or '-' was specified, take input from stdin.
* Otherwise, we process all the files specified. */
if (argv[0] == NULL || LONE_DASH(argv[0])) {
if (argv[optind] == NULL
|| (argv[optind][0] == '-' && argv[optind][1] == '\0')) {
cut_file(stdin);
} else {
FILE *file;
do {
file = fopen_or_warn(argv[0], "r");
for (; optind < argc; optind++) {
file = fopen_or_warn(argv[optind], "r");
if (file) {
cut_file(file);
fclose(file);
}
} while (*++argv);
}
}
if (ENABLE_FEATURE_CLEAN_UP)
free(cut_lists);
+1 -2
View File
@@ -212,8 +212,7 @@ format_utc:
}
} else if (opt & DATE_OPT_RFC2822) {
/* Undo busybox.c for date -R */
if (ENABLE_LOCALE_SUPPORT)
setlocale(LC_TIME, "C");
setlocale(LC_TIME, "C");
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
i = 22;
goto format_utc;
+1 -1
View File
@@ -93,7 +93,7 @@ int df_main(int argc, char **argv)
mount_entry = find_mount_point(mount_point, bb_path_mtab_file);
if (!mount_entry) {
bb_error_msg("%s: can't find mount point", mount_point);
SET_ERROR:
SET_ERROR:
status = EXIT_FAILURE;
continue;
}
+168 -169
View File
@@ -50,6 +50,8 @@
#define D_SKIPPED2 (1<<8)
/* Command line options */
static unsigned long cmd_flags;
#define FLAG_a (1<<0)
#define FLAG_b (1<<1)
#define FLAG_d (1<<2)
@@ -66,17 +68,12 @@
#define FLAG_w (1<<13)
/* XXX: FIXME: the following variables should be static, but gcc currently
* creates a much bigger object if we do this. [which version of gcc? --vda] */
/* 4.x, IIRC also 3.x --bernhard */
/* This is the default number of lines of context. */
int context = 3;
int status;
char *start;
const char *label1;
const char *label2;
* creates a much bigger object if we do this. */
int context, status;
char *start, *label[2];
struct stat stb1, stb2;
char **dl;
USE_FEATURE_DIFF_DIR(int dl_count;)
static int dl_count = 0;
struct cand {
int x;
@@ -109,7 +106,7 @@ static int clen;
static int len[2];
static int pref, suff; /* length of prefix and suffix */
static int slen[2];
static smallint anychange;
static int anychange;
static long *ixnew; /* will be overlaid on file[1] */
static long *ixold; /* will be overlaid on klist */
static struct cand *clist; /* merely a free storage pot for candidates */
@@ -119,7 +116,6 @@ static struct context_vec *context_vec_start;
static struct context_vec *context_vec_end;
static struct context_vec *context_vec_ptr;
static void print_only(const char *path, size_t dirlen, const char *entry)
{
if (dirlen > 1)
@@ -127,12 +123,11 @@ static void print_only(const char *path, size_t dirlen, const char *entry)
printf("Only in %.*s: %s\n", (int) dirlen, path, entry);
}
static void print_status(int val, char *path1, char *path2, char *entry)
{
const char * const _entry = entry ? entry : "";
char * const _path1 = entry ? concat_path_file(path1, _entry) : path1;
char * const _path2 = entry ? concat_path_file(path2, _entry) : path2;
const char *const _entry = entry ? entry : "";
char *_path1 = entry ? concat_path_file(path1, _entry) : path1;
char *_path2 = entry ? concat_path_file(path2, _entry) : path2;
switch (val) {
case D_ONLY:
@@ -145,20 +140,20 @@ static void print_status(int val, char *path1, char *path2, char *entry)
printf("Binary files %s and %s differ\n", _path1, _path2);
break;
case D_DIFFER:
if (option_mask32 & FLAG_q)
if (cmd_flags & FLAG_q)
printf("Files %s and %s differ\n", _path1, _path2);
break;
case D_SAME:
if (option_mask32 & FLAG_s)
if (cmd_flags & FLAG_s)
printf("Files %s and %s are identical\n", _path1, _path2);
break;
case D_MISMATCH1:
printf("File %s is a %s while file %s is a %s\n",
_path1, "directory", _path2, "regular file");
printf("File %s is a directory while file %s is a regular file\n",
_path1, _path2);
break;
case D_MISMATCH2:
printf("File %s is a %s while file %s is a %s\n",
_path1, "regular file", _path2, "directory");
printf("File %s is a regular file while file %s is a directory\n",
_path1, _path2);
break;
case D_SKIPPED1:
printf("File %s is not a regular file or directory and was skipped\n",
@@ -174,10 +169,7 @@ static void print_status(int val, char *path1, char *path2, char *entry)
free(_path2);
}
}
static void fiddle_sum(int *sum, int t)
{
*sum = (int)(*sum * 127 + t);
}
/*
* Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578.
*/
@@ -188,15 +180,24 @@ static int readhash(FILE * f)
sum = 1;
space = 0;
if (!(option_mask32 & FLAG_b) && !(option_mask32 & FLAG_w)) {
for (i = 0; (t = getc(f)) != '\n'; i++) {
if (t == EOF) {
if (i == 0)
return 0;
break;
if (!(cmd_flags & FLAG_b) && !(cmd_flags & FLAG_w)) {
if (FLAG_i)
for (i = 0; (t = getc(f)) != '\n'; i++) {
if (t == EOF) {
if (i == 0)
return 0;
break;
}
sum = sum * 127 + t;
} else
for (i = 0; (t = getc(f)) != '\n'; i++) {
if (t == EOF) {
if (i == 0)
return 0;
break;
}
sum = sum * 127 + t;
}
fiddle_sum(&sum, t);
}
} else {
for (i = 0;;) {
switch (t = getc(f)) {
@@ -208,11 +209,11 @@ static int readhash(FILE * f)
space++;
continue;
default:
if (space && !(option_mask32 & FLAG_w)) {
if (space && !(cmd_flags & FLAG_w)) {
i++;
space = 0;
}
fiddle_sum(&sum, t);
sum = sum * 127 + t;
i++;
continue;
case EOF:
@@ -233,20 +234,22 @@ static int readhash(FILE * f)
}
/*
* Check to see if the given files differ.
* Returns 0 if they are the same, 1 if different, and -1 on error.
*/
static int files_differ(FILE * f1, FILE * f2, int flags)
{
char buf1[BUFSIZ], buf2[BUFSIZ];
size_t i, j;
if ((flags & (D_EMPTY1 | D_EMPTY2)) || stb1.st_size != stb2.st_size ||
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
return 1;
while (1) {
i = fread(bb_common_bufsiz1, 1, BUFSIZ/2, f1);
j = fread(bb_common_bufsiz1 + BUFSIZ/2, 1, BUFSIZ/2, f2);
i = fread(buf1, 1, sizeof(buf1), f1);
j = fread(buf2, 1, sizeof(buf2), f2);
if (i != j)
return 1;
if (i == 0 && j == 0) {
@@ -254,13 +257,11 @@ static int files_differ(FILE * f1, FILE * f2, int flags)
return 1;
return 0;
}
if (memcmp(bb_common_bufsiz1,
bb_common_bufsiz1 + BUFSIZ/2, i) != 0)
if (memcmp(buf1, buf2, i) != 0)
return 1;
}
}
static void prepare(int i, FILE * fd, off_t filesize)
{
struct line *p;
@@ -274,8 +275,7 @@ static void prepare(int i, FILE * fd, off_t filesize)
sz = 100;
p = xmalloc((sz + 3) * sizeof(struct line));
j = 0;
while ((h = readhash(fd))) {
for (j = 0; (h = readhash(fd));) {
if (j == sz) {
sz = sz * 3 / 2;
p = xrealloc(p, (sz + 3) * sizeof(struct line));
@@ -286,18 +286,15 @@ static void prepare(int i, FILE * fd, off_t filesize)
file[i] = p;
}
static void prune(void)
{
int i, j;
for (pref = 0; pref < len[0] && pref < len[1] &&
file[0][pref + 1].value == file[1][pref + 1].value; pref++)
;
file[0][pref + 1].value == file[1][pref + 1].value; pref++);
for (suff = 0; suff < len[0] - pref && suff < len[1] - pref &&
file[0][len[0] - suff].value == file[1][len[1] - suff].value;
suff++)
;
suff++);
for (j = 0; j < 2; j++) {
sfile[j] = file[j] + pref;
slen[j] = len[j] - pref - suff;
@@ -306,7 +303,6 @@ static void prune(void)
}
}
static void equiv(struct line *a, int n, struct line *b, int m, int *c)
{
int i, j;
@@ -334,7 +330,6 @@ static void equiv(struct line *a, int n, struct line *b, int m, int *c)
c[j] = -1;
}
static int isqrt(int n)
{
int y, x = 1;
@@ -352,7 +347,6 @@ static int isqrt(int n)
return x;
}
static int newcand(int x, int y, int pred)
{
struct cand *q;
@@ -401,7 +395,7 @@ static int stone(int *a, int n, int *b, int *c)
#if ENABLE_FEATURE_DIFF_MINIMAL
const unsigned int bound =
(option_mask32 & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
(cmd_flags & FLAG_d) ? UINT_MAX : MAX(256, isqrt(n));
#else
const unsigned int bound = MAX(256, isqrt(n));
#endif
@@ -439,7 +433,6 @@ static int stone(int *a, int n, int *b, int *c)
return k;
}
static void unravel(int p)
{
struct cand *q;
@@ -464,7 +457,6 @@ static void unsort(struct line *f, int l, int *b)
free(a);
}
static int skipline(FILE * f)
{
int i, c;
@@ -501,8 +493,8 @@ static void check(FILE * f1, FILE * f2)
ixnew[j] = ctnew += skipline(f2);
j++;
}
if ((option_mask32 & FLAG_b) || (option_mask32 & FLAG_w)
|| (option_mask32 & FLAG_i)) {
if ((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)
|| (cmd_flags & FLAG_i)) {
while (1) {
c = getc(f1);
d = getc(f2);
@@ -510,13 +502,13 @@ static void check(FILE * f1, FILE * f2)
* GNU diff ignores a missing newline
* in one file if bflag || wflag.
*/
if (((option_mask32 & FLAG_b) || (option_mask32 & FLAG_w)) &&
if (((cmd_flags & FLAG_b) || (cmd_flags & FLAG_w)) &&
((c == EOF && d == '\n') || (c == '\n' && d == EOF))) {
break;
}
ctold++;
ctnew++;
if ((option_mask32 & FLAG_b) && isspace(c) && isspace(d)) {
if ((cmd_flags & FLAG_b) && isspace(c) && isspace(d)) {
do {
if (c == '\n')
break;
@@ -527,7 +519,7 @@ static void check(FILE * f1, FILE * f2)
break;
ctnew++;
} while (isspace(d = getc(f2)));
} else if (option_mask32 & FLAG_w) {
} else if (cmd_flags & FLAG_w) {
while (isspace(c) && c != '\n') {
c = getc(f1);
ctold++;
@@ -573,7 +565,6 @@ static void check(FILE * f1, FILE * f2)
ixnew[j] = ctnew += skipline(f2);
}
/* shellsort CACM #201 */
static void sort(struct line *a, int n)
{
@@ -616,28 +607,27 @@ static void uni_range(int a, int b)
printf("%d,0", b);
}
static void fetch(long *f, int a, int b, FILE * lb, int ch)
static int fetch(long *f, int a, int b, FILE * lb, int ch)
{
int i, j, c, lastc, col, nc;
if (a > b)
return;
return 0;
for (i = a; i <= b; i++) {
fseek(lb, f[i - 1], SEEK_SET);
nc = f[i] - f[i - 1];
if (ch != '\0') {
putchar(ch);
if (option_mask32 & FLAG_T)
if (cmd_flags & FLAG_T)
putchar('\t');
}
col = 0;
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
if ((c = getc(lb)) == EOF) {
printf("\n\\ No newline at end of file\n");
return;
puts("\n\\ No newline at end of file");
return 0;
}
if (c == '\t' && (option_mask32 & FLAG_t)) {
if (c == '\t' && (cmd_flags & FLAG_t)) {
do {
putchar(' ');
} while (++col & 7);
@@ -647,25 +637,24 @@ static void fetch(long *f, int a, int b, FILE * lb, int ch)
}
}
}
return;
return 0;
}
static int asciifile(FILE * f)
{
#if ENABLE_FEATURE_DIFF_BINARY
unsigned char buf[BUFSIZ];
int i, cnt;
#endif
if ((option_mask32 & FLAG_a) || f == NULL)
if ((cmd_flags & FLAG_a) || f == NULL)
return 1;
#if ENABLE_FEATURE_DIFF_BINARY
rewind(f);
cnt = fread(bb_common_bufsiz1, 1, BUFSIZ, f);
cnt = fread(buf, 1, sizeof(buf), f);
for (i = 0; i < cnt; i++) {
if (!isprint(bb_common_bufsiz1[i])
&& !isspace(bb_common_bufsiz1[i])) {
if (!isprint(buf[i]) && !isspace(buf[i])) {
return 0;
}
}
@@ -673,7 +662,6 @@ static int asciifile(FILE * f)
return 1;
}
/* dump accumulated "unified" diff changes */
static void dump_unified_vec(FILE * f1, FILE * f2)
{
@@ -691,11 +679,12 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
lowc = MAX(1, cvp->c - context);
upd = MIN(len[1], context_vec_ptr->d + context);
printf("@@ -");
fputs("@@ -", stdout);
uni_range(lowa, upb);
printf(" +");
fputs(" +", stdout);
uni_range(lowc, upd);
printf(" @@\n");
fputs(" @@", stdout);
putchar('\n');
/*
* Output changes in "unified" diff format--the old and new lines
@@ -735,20 +724,21 @@ static void dump_unified_vec(FILE * f1, FILE * f2)
static void print_header(const char *file1, const char *file2)
{
if (label1)
printf("--- %s\n", label1);
if (label[0] != NULL)
printf("%s %s\n", "---", label[0]);
else
printf("--- %s\t%s", file1, ctime(&stb1.st_mtime));
if (label2)
printf("+++ %s\n", label2);
printf("%s %s\t%s", "---", file1, ctime(&stb1.st_mtime));
if (label[1] != NULL)
printf("%s %s\n", "+++", label[1]);
else
printf("+++ %s\t%s", file2, ctime(&stb2.st_mtime));
printf("%s %s\t%s", "+++", file2, ctime(&stb2.st_mtime));
}
/*
* Indicate that there is a difference between lines a and b of the from file
* to get to lines c to d of the to file. If a is greater than b then there
* to get to lines c to d of the to file. If a is greater then b then there
* are no lines in the from file involved and this means that there were
* lines appended (beginning at b). If c is greater than d then there are
* lines missing from the to file.
@@ -758,10 +748,10 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
{
static size_t max_context = 64;
if ((a > b && c > d) || (option_mask32 & FLAG_q)) {
anychange = 1;
if (a > b && c > d)
return;
if (cmd_flags & FLAG_q)
return;
}
/*
* Allocate change records as needed.
@@ -771,7 +761,8 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
max_context <<= 1;
context_vec_start = xrealloc(context_vec_start,
max_context * sizeof(struct context_vec));
max_context *
sizeof(struct context_vec));
context_vec_end = context_vec_start + max_context;
context_vec_ptr = context_vec_start + offset;
}
@@ -780,6 +771,7 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
* Print the context/unidiff header first time through.
*/
print_header(file1, file2);
anychange = 1;
} else if (a > context_vec_ptr->b + (2 * context) + 1 &&
c > context_vec_ptr->d + (2 * context) + 1) {
/*
@@ -793,12 +785,14 @@ static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
context_vec_ptr->b = b;
context_vec_ptr->c = c;
context_vec_ptr->d = d;
anychange = 1;
return;
}
static void output(char *file1, FILE * f1, char *file2, FILE * f2)
{
/* Note that j0 and j1 can't be used as they are defined in math.h.
* This also allows the rather amusing variable 'j00'... */
int m, i0, i1, j00, j01;
@@ -822,7 +816,7 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
if (m == 0) {
change(file1, f1, file2, f2, 1, 0, 1, len[1]);
}
if (anychange != 0 && !(option_mask32 & FLAG_q)) {
if (anychange != 0) {
dump_unified_vec(f1, f2);
}
}
@@ -889,12 +883,14 @@ static void output(char *file1, FILE * f1, char *file2, FILE * f2)
* 3*(number of k-candidates installed), typically about
* 6n words for files of length n.
*/
static unsigned diffreg(char * ofile1, char * ofile2, int flags)
static int diffreg(char *ofile1, char *ofile2, int flags)
{
char *file1 = ofile1;
char *file2 = ofile2;
FILE *f1 = stdin, *f2 = stdin;
unsigned rval;
FILE *f1 = NULL;
FILE *f2 = NULL;
int rval = D_SAME;
int i;
anychange = 0;
@@ -902,30 +898,28 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode))
return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2);
rval = D_SAME;
if (LONE_DASH(file1) && LONE_DASH(file2))
if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0)
goto closem;
if (flags & D_EMPTY1)
f1 = xfopen(bb_dev_null, "r");
else if (NOT_LONE_DASH(file1))
f1 = xfopen(file1, "r");
else {
if (strcmp(file1, "-") == 0)
f1 = stdin;
else
f1 = xfopen(file1, "r");
}
if (flags & D_EMPTY2)
f2 = xfopen(bb_dev_null, "r");
else if (NOT_LONE_DASH(file2))
f2 = xfopen(file2, "r");
else {
if (strcmp(file2, "-") == 0)
f2 = stdin;
else
f2 = xfopen(file2, "r");
}
/* We can't diff non-seekable stream - we use rewind(), fseek().
* This can be fixed (volunteers?).
* Meanwhile we should check it here by stat'ing input fds,
* but I am lazy and check that in main() instead.
* Check in main won't catch "diffing fifos buried in subdirectories"
* failure scenario - not very likely in real life... */
i = files_differ(f1, f2, flags);
if (i == 0)
if ((i = files_differ(f1, f2, flags)) == 0)
goto closem;
else if (i != 1) { /* 1 == ok */
/* error */
@@ -971,14 +965,16 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
check(f1, f2);
output(file1, f1, file2, f2);
closem:
closem:
if (anychange) {
status |= 1;
if (rval == D_SAME)
rval = D_DIFFER;
}
fclose_if_not_stdin(f1);
fclose_if_not_stdin(f2);
if (f1 != NULL)
fclose(f1);
if (f2 != NULL)
fclose(f2);
if (file1 != ofile1)
free(file1);
if (file2 != ofile2)
@@ -986,30 +982,26 @@ static unsigned diffreg(char * ofile1, char * ofile2, int flags)
return rval;
}
#if ENABLE_FEATURE_DIFF_DIR
static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
{
int flags = D_HEADER;
int val;
char *fullpath1 = concat_path_file(dir1, path1);
char *fullpath2 = concat_path_file(dir2, path2);
char *fullpath1 = xasprintf("%s/%s", dir1, path1);
char *fullpath2 = xasprintf("%s/%s", dir2, path2);
if (stat(fullpath1, &stb1) != 0) {
flags |= D_EMPTY1;
memset(&stb1, 0, sizeof(stb1));
if (ENABLE_FEATURE_CLEAN_UP)
free(fullpath1);
fullpath1 = concat_path_file(dir1, path2);
fullpath1 = xasprintf("%s/%s", dir1, path2);
}
if (stat(fullpath2, &stb2) != 0) {
flags |= D_EMPTY2;
memset(&stb2, 0, sizeof(stb2));
stb2.st_mode = stb1.st_mode;
if (ENABLE_FEATURE_CLEAN_UP)
free(fullpath2);
fullpath2 = concat_path_file(dir2, path1);
fullpath2 = xasprintf("%s/%s", dir2, path1);
}
if (stb1.st_mode == 0)
@@ -1031,15 +1023,14 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
}
#endif
#if ENABLE_FEATURE_DIFF_DIR
static int dir_strcmp(const void *p1, const void *p2)
{
return strcmp(*(char *const *) p1, *(char *const *) p2);
}
/* This function adds a filename to dl, the directory listing. */
static int add_to_dirlist(const char *filename,
struct stat ATTRIBUTE_UNUSED * sb, void *userdata,
int depth ATTRIBUTE_UNUSED)
@@ -1047,7 +1038,7 @@ static int add_to_dirlist(const char *filename,
dl_count++;
dl = xrealloc(dl, dl_count * sizeof(char *));
dl[dl_count - 1] = xstrdup(filename);
if (option_mask32 & FLAG_r) {
if (cmd_flags & FLAG_r) {
int *pp = (int *) userdata;
int path_len = *pp + 1;
@@ -1056,10 +1047,10 @@ static int add_to_dirlist(const char *filename,
return TRUE;
}
/* This returns a sorted directory listing. */
static char **get_dir(char *path)
{
int i;
char **retval;
@@ -1077,7 +1068,7 @@ static char **get_dir(char *path)
dl_count = 0;
/* Now fill dl with a listing. */
if (option_mask32 & FLAG_r)
if (cmd_flags & FLAG_r)
recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL,
userdata, 0);
else {
@@ -1086,7 +1077,7 @@ static char **get_dir(char *path)
dp = warn_opendir(path);
while ((ep = readdir(dp))) {
if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
continue;
add_to_dirlist(ep->d_name, NULL, NULL, 0);
}
@@ -1104,9 +1095,9 @@ static char **get_dir(char *path)
return retval;
}
static void diffdir(char *p1, char *p2)
{
char **dirlist1, **dirlist2;
char *dp1, *dp2;
int dirlist1_count, dirlist2_count;
@@ -1153,13 +1144,13 @@ static void diffdir(char *p1, char *p2)
dirlist1++;
dirlist2++;
} else if (pos < 0) {
if (option_mask32 & FLAG_N)
if (cmd_flags & FLAG_N)
do_diff(p1, dp1, p2, NULL);
else
print_only(p1, strlen(p1) + 1, dp1);
dirlist1++;
} else {
if (option_mask32 & FLAG_N)
if (cmd_flags & FLAG_N)
do_diff(p1, NULL, p2, dp2);
else
print_only(p2, strlen(p2) + 1, dp2);
@@ -1170,75 +1161,83 @@ static void diffdir(char *p1, char *p2)
#endif
int diff_main(int argc, char **argv)
{
smallint gotstdin = 0;
int gotstdin = 0;
char *U_opt;
char *f1, *f2;
llist_t *L_arg = NULL;
/* exactly 2 params; collect multiple -L <label> */
opt_complementary = "=2:L::";
getopt32(argc, argv, "abdiL:NqrsS:tTU:wu"
"p" /* ignored (for compatibility) */,
opt_complementary = "L::";
cmd_flags = getopt32(argc, argv, "abdiL:NqrsS:tTU:wu",
&L_arg, &start, &U_opt);
/*argc -= optind;*/
argv += optind;
while (L_arg) {
if (label1 && label2)
bb_show_usage();
if (!label1)
label1 = L_arg->data;
else { /* then label2 is NULL */
label2 = label1;
label1 = L_arg->data;
if (cmd_flags & FLAG_L) {
while (L_arg) {
if (label[0] == NULL)
label[0] = L_arg->data;
else if (label[1] == NULL)
label[1] = L_arg->data;
else
bb_show_usage();
L_arg = L_arg->link;
}
/* If both label[0] and label[1] were set, they need to be swapped. */
if (label[0] && label[1]) {
char *tmp;
tmp = label[1];
label[1] = label[0];
label[0] = tmp;
}
/* we leak L_arg here... */
L_arg = L_arg->link;
}
if (option_mask32 & FLAG_U)
context = xatou_range(U_opt, 1, INT_MAX);
context = 3; /* This is the default number of lines of context. */
if (cmd_flags & FLAG_U) {
context = xatoul_range(U_opt, 1, INT_MAX);
}
argc -= optind;
argv += optind;
/*
* Do sanity checks, fill in stb1 and stb2 and call the appropriate
* driver routine. Both drivers use the contents of stb1 and stb2.
*/
f1 = argv[0];
f2 = argv[1];
if (LONE_DASH(f1)) {
if (argc < 2) {
bb_error_msg("missing filename");
bb_show_usage();
}
if (strcmp(argv[0], "-") == 0) {
fstat(STDIN_FILENO, &stb1);
gotstdin = 1;
} else
xstat(f1, &stb1);
if (LONE_DASH(f2)) {
xstat(argv[0], &stb1);
if (strcmp(argv[1], "-") == 0) {
fstat(STDIN_FILENO, &stb2);
gotstdin = 1;
} else
xstat(f2, &stb2);
xstat(argv[1], &stb2);
if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode)))
bb_error_msg_and_die("can't compare - to a directory");
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
#if ENABLE_FEATURE_DIFF_DIR
diffdir(f1, f2);
diffdir(argv[0], argv[1]);
#else
bb_error_msg_and_die("directory comparison not supported");
#endif
} else {
if (S_ISDIR(stb1.st_mode)) {
f1 = concat_path_file(f1, f2);
xstat(f1, &stb1);
argv[0] = concat_path_file(argv[0], argv[1]);
xstat(argv[0], &stb1);
}
if (S_ISDIR(stb2.st_mode)) {
f2 = concat_path_file(f2, f1);
xstat(f2, &stb2);
argv[1] = concat_path_file(argv[1], argv[0]);
xstat(argv[1], &stb2);
}
/* XXX: FIXME: */
/* We can't diff e.g. stdin supplied by a pipe - we use rewind(), fseek().
* This can be fixed (volunteers?) */
if (!S_ISREG(stb1.st_mode) || !S_ISREG(stb2.st_mode))
bb_error_msg_and_die("can't diff non-seekable stream");
print_status(diffreg(f1, f2, 0), f1, f2, NULL);
print_status(diffreg(argv[0], argv[1], 0), argv[0], argv[1], NULL);
}
return status;
exit(status);
}
+35 -31
View File
@@ -25,22 +25,26 @@
#include "busybox.h"
#if ENABLE_FEATURE_HUMAN_READABLE
# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
#ifdef CONFIG_FEATURE_HUMAN_READABLE
# ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned long disp_hr = 1024;
# else
static unsigned long disp_hr = 512;
# endif
#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned disp_k = 1;
#elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
static unsigned int disp_k = 1;
#else
static unsigned disp_k; /* bss inits to 0 */
static unsigned int disp_k; /* bss inits to 0 */
#endif
static int max_print_depth = INT_MAX;
static nlink_t count_hardlinks = 1;
static int status;
static int status
#if EXIT_SUCCESS == 0
= EXIT_SUCCESS
#endif
;
static int print_files;
static int slink_depth;
static int du_depth;
@@ -51,9 +55,9 @@ static dev_t dir_dev;
static void print(long size, const char * const filename)
{
/* TODO - May not want to defer error checking here. */
#if ENABLE_FEATURE_HUMAN_READABLE
#ifdef CONFIG_FEATURE_HUMAN_READABLE
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
filename);
filename);
#else
if (disp_k) {
size++;
@@ -69,7 +73,7 @@ static long du(const char * const filename)
struct stat statbuf;
long sum;
if (lstat(filename, &statbuf) != 0) {
if ((lstat(filename, &statbuf)) != 0) {
bb_perror_msg("%s", filename);
status = EXIT_FAILURE;
return 0;
@@ -87,7 +91,7 @@ static long du(const char * const filename)
if (S_ISLNK(statbuf.st_mode)) {
if (slink_depth > du_depth) { /* -H or -L */
if (stat(filename, &statbuf) != 0) {
if ((stat(filename, &statbuf)) != 0) {
bb_perror_msg("%s", filename);
status = EXIT_FAILURE;
return 0;
@@ -126,7 +130,7 @@ static long du(const char * const filename)
char *name = entry->d_name;
newfile = concat_subpath_file(filename, name);
if (newfile == NULL)
if(newfile == NULL)
continue;
++du_depth;
sum += du(newfile);
@@ -151,9 +155,9 @@ int du_main(int argc, char **argv)
char *smax_print_depth;
unsigned opt;
#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
#if ENABLE_FEATURE_HUMAN_READABLE
#ifdef CONFIG_FEATURE_HUMAN_READABLE
disp_hr = 512;
#else
disp_k = 0;
@@ -167,55 +171,55 @@ int du_main(int argc, char **argv)
* gnu du exits with an error code in this case. We choose to simply
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
#if ENABLE_FEATURE_HUMAN_READABLE
#ifdef CONFIG_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
if (opt & (1 << 9)) {
if((opt & (1 << 9))) {
/* -h opt */
disp_hr = 0;
}
if (opt & (1 << 10)) {
if((opt & (1 << 10))) {
/* -m opt */
disp_hr = 1024*1024;
}
if (opt & (1 << 2)) {
if((opt & (1 << 2))) {
/* -k opt */
disp_hr = 1024;
}
#else
opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & (1 << 2)) {
#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if((opt & (1 << 2))) {
/* -k opt */
disp_k = 1;
disp_k = 1;
}
#endif
#endif
if (opt & (1 << 0)) {
if((opt & (1 << 0))) {
/* -a opt */
print_files = INT_MAX;
}
if (opt & (1 << 1)) {
if((opt & (1 << 1))) {
/* -H opt */
slink_depth = 1;
}
if (opt & (1 << 3)) {
if((opt & (1 << 3))) {
/* -L opt */
slink_depth = INT_MAX;
slink_depth = INT_MAX;
}
if (opt & (1 << 4)) {
if((opt & (1 << 4))) {
/* -s opt */
max_print_depth = 0;
}
max_print_depth = 0;
}
one_file_system = opt & (1 << 5); /* -x opt */
if (opt & (1 << 6)) {
if((opt & (1 << 6))) {
/* -d opt */
max_print_depth = xatoi_u(smax_print_depth);
}
if (opt & (1 << 7)) {
if((opt & (1 << 7))) {
/* -l opt */
count_hardlinks = MAXINT(nlink_t);
count_hardlinks = INT_MAX;
}
print_final_total = opt & (1 << 8); /* -c opt */
@@ -234,7 +238,7 @@ int du_main(int argc, char **argv)
total += du(*argv);
slink_depth = slink_depth_save;
} while (*++argv);
#if ENABLE_FEATURE_CLEAN_UP
#ifdef CONFIG_FEATURE_CLEAN_UP
reset_ino_dev_hashtable();
#endif
+2 -2
View File
@@ -29,7 +29,7 @@
#include <stdlib.h>
#include "busybox.h"
int bb_echo(char **argv)
int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv)
{
#ifndef CONFIG_FEATURE_FANCY_ECHO
#define eflag '\\'
@@ -114,7 +114,7 @@ just_echo:
int echo_main(int argc, char** argv)
{
(void)bb_echo(argv);
(void)bb_echo(argc, argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
+1 -1
View File
@@ -58,7 +58,7 @@ int env_main(int argc, char** argv)
opt = getopt32(argc, argv, "+iu:", &unset_env);
argv += optind;
if (*argv && LONE_DASH(argv[0])) {
if (*argv && (argv[0][0] == '-') && !argv[0][1]) {
opt |= 1;
++argv;
}
+1 -1
View File
@@ -136,7 +136,7 @@ static int null(VALUE * v)
if (v->type == integer)
return v->u.i == 0;
else /* string: */
return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0;
}
/* Coerce V to a string value (can't fail). */
+1 -1
View File
@@ -45,7 +45,7 @@ int fold_main(int argc, char **argv)
int i;
int errs = 0;
if (ENABLE_INCLUDE_SUSv2) {
if(!ENABLE_DEBUG_YANK_SUSv2) {
/* Turn any numeric options into -w options. */
for (i = 1; i < argc; i++) {
char const *a = argv[i];
+3 -3
View File
@@ -47,7 +47,7 @@ int head_main(int argc, char **argv)
int c;
int retval = EXIT_SUCCESS;
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
/* Allow legacy syntax of an initial numeric option without -n. */
if (argc > 1 && argv[1][0] == '-'
&& isdigit(argv[1][1])
@@ -75,8 +75,8 @@ int head_main(int argc, char **argv)
#endif
case 'n':
p = optarg;
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
GET_COUNT:
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
GET_COUNT:
#endif
#if !ENABLE_FEATURE_FANCY_HEAD
+14 -11
View File
@@ -62,8 +62,8 @@ int id_main(int argc, char **argv)
if (argv[optind]) {
p = getpwnam(argv[optind]);
/* xuname2uid is needed because it exits on failure */
uid = xuname2uid(argv[optind]);
/* bb_xgetpwnam is needed because it exits on failure */
uid = bb_xgetpwnam(argv[optind]);
gid = p->pw_gid;
/* in this case PRINT_REAL is the same */
}
@@ -89,16 +89,19 @@ int id_main(int argc, char **argv)
#ifdef CONFIG_SELINUX
if (is_selinux_enabled()) {
security_context_t mysid;
const char *context;
security_context_t mysid;
char context[80];
int len = sizeof(context);
context = "unknown";
getcon(&mysid);
if (mysid) {
context = alloca(strlen(mysid) + 1);
strcpy((char*)context, mysid);
freecon(mysid);
}
getcon(&mysid);
context[0] = '\0';
if (mysid) {
len = strlen(mysid)+1;
safe_strncpy(context, mysid, len);
freecon(mysid);
} else {
safe_strncpy(context, "unknown", 8);
}
printf(" context=%s", context);
}
#endif
+38 -44
View File
@@ -13,62 +13,58 @@
#include <libgen.h>
#include <getopt.h> /* struct option */
#define INSTALL_OPT_CMD 1
#define INSTALL_OPT_DIRECTORY 2
#define INSTALL_OPT_PRESERVE_TIME 4
#define INSTALL_OPT_STRIP 8
#define INSTALL_OPT_GROUP 16
#define INSTALL_OPT_MODE 32
#define INSTALL_OPT_OWNER 64
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
static const struct option install_long_options[] = {
{ "directory", 0, NULL, 'd' },
{ "preserve-timestamps", 0, NULL, 'p' },
{ "strip", 0, NULL, 's' },
{ "group", 0, NULL, 'g' },
{ "mode", 0, NULL, 'm' },
{ "owner", 0, NULL, 'o' },
{ 0, 0, 0, 0 }
{ "directory", 0, NULL, 'd' },
{ "preserve-timestamps", 0, NULL, 'p' },
{ "strip", 0, NULL, 's' },
{ "group", 0, NULL, 'g' },
{ "mode", 0, NULL, 'm' },
{ "owner", 0, NULL, 'o' },
{ 0, 0, 0, 0 }
};
#endif
int install_main(int argc, char **argv)
{
struct stat statbuf;
mode_t mode;
uid_t uid;
gid_t gid;
const char *gid_str;
const char *uid_str;
const char *mode_str;
char *gid_str = "-1";
char *uid_str = "-1";
char *mode_str = "0755";
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
int ret = EXIT_SUCCESS, flags, i, isdir;
enum {
OPT_CMD = 0x1,
OPT_DIRECTORY = 0x2,
OPT_PRESERVE_TIME = 0x4,
OPT_STRIP = 0x8,
OPT_GROUP = 0x10,
OPT_MODE = 0x20,
OPT_OWNER = 0x40,
};
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
applet_long_options = install_long_options;
#endif
opt_complementary = "?:s--d:d--s";
/* -c exists for backwards compatibility, its needed */
flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str);
flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
if (flags & OPT_PRESERVE_TIME) {
if (flags & INSTALL_OPT_PRESERVE_TIME) {
copy_flags |= FILEUTILS_PRESERVE_STATUS;
}
mode = 0666;
if (flags & OPT_MODE) bb_parse_mode(mode_str, &mode);
uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
if (flags & (OPT_OWNER|OPT_GROUP)) umask(0);
bb_parse_mode(mode_str, &mode);
gid = get_ug_id(gid_str, bb_xgetgrnam);
uid = get_ug_id(uid_str, bb_xgetpwnam);
umask(0);
/* Create directories
* don't use bb_make_directory() as it can't change uid or gid
* perhaps bb_make_directory() should be improved.
*/
if (flags & OPT_DIRECTORY) {
if (flags & INSTALL_OPT_DIRECTORY) {
for (argv += optind; *argv; argv++) {
char *old_argv_ptr = *argv + 1;
char *argv_ptr;
@@ -79,16 +75,14 @@ int install_main(int argc, char **argv)
*argv_ptr = '\0';
old_argv_ptr++;
}
if (mkdir(*argv, mode | 0111) == -1) {
if (mkdir(*argv, mode) == -1) {
if (errno != EEXIST) {
bb_perror_msg("cannot create %s", *argv);
ret = EXIT_FAILURE;
break;
}
}
if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(*argv, uid, gid) == -1
) {
else if (lchown(*argv, uid, gid) == -1) {
bb_perror_msg("cannot change ownership of %s", *argv);
ret = EXIT_FAILURE;
break;
@@ -101,36 +95,36 @@ int install_main(int argc, char **argv)
return ret;
}
isdir = lstat(argv[argc - 1], &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
{
struct stat statbuf;
isdir = lstat(argv[argc - 1], &statbuf)<0
? 0 : S_ISDIR(statbuf.st_mode);
}
for (i = optind; i < argc - 1; i++) {
char *dest;
dest = argv[argc - 1];
if (isdir)
dest = concat_path_file(argv[argc - 1], basename(argv[i]));
if (isdir) dest = concat_path_file(argv[argc - 1], basename(argv[i]));
ret |= copy_file(argv[i], dest, copy_flags);
/* Set the file mode */
if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
if (chmod(dest, mode) == -1) {
bb_perror_msg("cannot change permissions of %s", dest);
ret = EXIT_FAILURE;
}
/* Set the user and group id */
if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
if (lchown(dest, uid, gid) == -1) {
bb_perror_msg("cannot change ownership of %s", dest);
ret = EXIT_FAILURE;
}
if (flags & OPT_STRIP) {
if (flags & INSTALL_OPT_STRIP) {
if (execlp("strip", "strip", dest, NULL) == -1) {
bb_perror_msg("strip");
bb_error_msg("strip failed");
ret = EXIT_FAILURE;
}
}
if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
if(ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
}
return ret;
+10 -19
View File
@@ -291,7 +291,7 @@ static void dfree(struct dnode **dnp, int nfiles)
free(dnp); /* free the array holding the dnode pointers */
}
#else
#define dfree(...) ((void)0)
#define dfree(...) do {} while(0)
#endif
static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
@@ -375,7 +375,7 @@ static void dnsort(struct dnode **dn, int size)
qsort(dn, size, sizeof(*dn), sortcmp);
}
#else
#define dnsort(dn, size) ((void)0)
#define dnsort(dn, size) do {} while(0)
#endif
@@ -537,16 +537,13 @@ static struct dnode **list_dir(const char *path)
}
#if ENABLE_FEATURE_LS_TIMESTAMPS
/* Do time() just once. Saves one syscall per file for "ls -l" */
/* Initialized in main() */
static time_t current_time_t;
#endif
static int list_single(struct dnode *dn)
{
int i, column = 0;
#if ENABLE_FEATURE_LS_USERNAME
char scratch[16];
#endif
#if ENABLE_FEATURE_LS_TIMESTAMPS
char *filetime;
time_t ttime, age;
@@ -587,9 +584,10 @@ static int list_single(struct dnode *dn)
break;
case LIST_ID_NAME:
#if ENABLE_FEATURE_LS_USERNAME
printf("%-8.8s %-8.8s",
get_cached_username(dn->dstat.st_uid),
get_cached_groupname(dn->dstat.st_gid));
bb_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
printf("%-8.8s ", scratch);
bb_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
printf("%-8.8s", scratch);
column += 17;
break;
#endif
@@ -617,8 +615,7 @@ static int list_single(struct dnode *dn)
break;
case LIST_DATE_TIME:
if ((all_fmt & LIST_FULLTIME) == 0) {
/* current_time_t ~== time(NULL) */
age = current_time_t - ttime;
age = time(NULL) - ttime;
printf("%6.6s ", filetime + 4);
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
/* hh:mm if less than 6 months old */
@@ -792,12 +789,6 @@ int ls_main(int argc, char **argv)
USE_FEATURE_AUTOWIDTH(char *terminal_width_str = NULL;)
USE_FEATURE_LS_COLOR(char *color_opt;)
setvbuf(stdout, bb_common_bufsiz1, _IOFBF, BUFSIZ);
#if ENABLE_FEATURE_LS_TIMESTAMPS
time(&current_time_t);
#endif
all_fmt = LIST_SHORT |
(ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD));
+7 -5
View File
@@ -18,9 +18,11 @@ typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
unsigned hash_length)
{
/* xzalloc zero-terminates */
char *hex_value = xzalloc((hash_length * 2) + 1);
bin2hex(hex_value, (char*)hash_value, hash_length);
int len = 0;
char *hex_value = xmalloc((hash_length * 2) + 2);
while (hash_length--) {
len += sprintf(hex_value + len, "%02x", *hash_value++);
}
return hex_value;
}
@@ -37,7 +39,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
void (*final)(void*, void*);
src_fd = STDIN_FILENO;
if (NOT_LONE_DASH(filename)) {
if (filename[0] != '-' || filename[1]) { /* not "-" */
src_fd = open(filename, O_RDONLY);
if (src_fd < 0) {
bb_perror_msg("%s", filename);
@@ -118,7 +120,7 @@ int md5_sha1_sum_main(int argc, char **argv)
}
pre_computed_stream = stdin;
if (NOT_LONE_DASH(file_ptr)) {
if (file_ptr[0] != '-' || file_ptr[1]) { /* not "-" */
pre_computed_stream = xfopen(file_ptr, "r");
}
+4 -3
View File
@@ -490,7 +490,7 @@ print_ascii(size_t n_bytes, const char *block,
static void
open_next_file(void)
{
while (1) {
while(1) {
input_filename = *file_list;
if (!input_filename)
return;
@@ -866,7 +866,8 @@ format_address_paren(off_t address, char c)
{
putchar('(');
format_address_std(address, ')');
if (c) putchar(c);
/* BUG in coreutils 5.2.1! must be "if (c) putchar(c);" */
putchar(c);
}
static void
@@ -1436,7 +1437,7 @@ od_main(int argc, char **argv)
if (str_w)
bytes_per_block = xatou(str_w);
if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
bb_error_msg("warning: invalid width %zu; using %d instead",
bb_error_msg("warning: invalid width %u; using %d instead",
bytes_per_block, l_c_m);
bytes_per_block = l_c_m;
}
+2
View File
@@ -10,6 +10,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <limits.h>
#include <stdlib.h>
#include "busybox.h"
int realpath_main(int argc, char **argv)
+94 -131
View File
@@ -14,44 +14,38 @@
#include "busybox.h"
static int global_flags;
/*
sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...]
sort -c [-bdfinru][-t char][-k keydef][file]
*/
/* These are sort types */
static const char OPT_STR[] = "ngMucszbrdfimS:T:o:k:t:";
enum {
FLAG_n = 1, /* Numeric sort */
FLAG_g = 2, /* Sort using strtod() */
FLAG_M = 4, /* Sort date */
#define FLAG_n 1 /* Numeric sort */
#define FLAG_g 2 /* Sort using strtod() */
#define FLAG_M 4 /* Sort date */
/* ucsz apply to root level only, not keys. b at root level implies bb */
FLAG_u = 8, /* Unique */
FLAG_c = 0x10, /* Check: no output, exit(!ordered) */
FLAG_s = 0x20, /* Stable sort, no ascii fallback at end */
FLAG_z = 0x40, /* Input is null terminated, not \n */
#define FLAG_u 8 /* Unique */
#define FLAG_c 16 /* Check: no output, exit(!ordered) */
#define FLAG_s 32 /* Stable sort, no ascii fallback at end */
#define FLAG_z 64 /* Input is null terminated, not \n */
/* These can be applied to search keys, the previous four can't */
FLAG_b = 0x80, /* Ignore leading blanks */
FLAG_r = 0x100, /* Reverse */
FLAG_d = 0x200, /* Ignore !(isalnum()|isspace()) */
FLAG_f = 0x400, /* Force uppercase */
FLAG_i = 0x800, /* Ignore !isprint() */
FLAG_m = 0x1000, /* ignored: merge already sorted files; do not sort */
FLAG_S = 0x2000, /* ignored: -S, --buffer-size=SIZE */
FLAG_T = 0x4000, /* ignored: -T, --temporary-directory=DIR */
FLAG_o = 0x8000,
FLAG_k = 0x10000,
FLAG_t = 0x20000,
FLAG_bb = 0x80000000, /* Ignore trailing blanks */
};
#define FLAG_b 128 /* Ignore leading blanks */
#define FLAG_r 256 /* Reverse */
#define FLAG_d 512 /* Ignore !(isalnum()|isspace()) */
#define FLAG_f 1024 /* Force uppercase */
#define FLAG_i 2048 /* Ignore !isprint() */
#define FLAG_bb 32768 /* Ignore trailing blanks */
#if ENABLE_FEATURE_SORT_BIG
static char key_separator;
static struct sort_key {
struct sort_key *next_key; /* linked list */
unsigned range[4]; /* start word, start char, end word, end char */
unsigned flags;
unsigned short range[4]; /* start word, start char, end word, end char */
int flags;
} *key_list;
static char *get_key(char *str, struct sort_key *key, int flags)
@@ -65,7 +59,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
return str;
}
/* Find start of key on first pass, end on second pass */
/* Find start of key on first pass, end on second pass*/
len = strlen(str);
for (j = 0; j < 2; j++) {
if (!key->range[2*j])
@@ -74,27 +68,28 @@ static char *get_key(char *str, struct sort_key *key, int flags)
else {
end = 0;
for (i = 1; i < key->range[2*j] + j; i++) {
if (key_separator) {
/* Skip body of key and separator */
while (str[end]) {
if (str[end++] == key_separator)
/* Skip leading blanks or first separator */
if (str[end]) {
if (!key_separator)
while (isspace(str[end])) end++;
}
/* Skip body of key */
for (; str[end]; end++) {
if (key_separator) {
if (str[end] == key_separator)
break;
}
} else {
/* Skip leading blanks */
while (isspace(str[end]))
end++;
/* Skip body of key */
while (str[end]) {
} else {
if (isspace(str[end]))
break;
end++;
}
}
}
}
if (!j) start = end;
}
/* Key with explicit separator starts after separator */
if (key_separator && str[start] == key_separator)
start++;
/* Strip leading whitespace if necessary */
//XXX: skip_whitespace()
if (flags & FLAG_b)
@@ -145,7 +140,7 @@ static struct sort_key *add_key(void)
}
#define GET_LINE(fp) \
((option_mask32 & FLAG_z) \
((global_flags & FLAG_z) \
? bb_get_chunk_from_file(fp, NULL) \
: xmalloc_getline(fp))
#else
@@ -155,20 +150,20 @@ static struct sort_key *add_key(void)
/* Iterate through keys list and perform comparisons */
static int compare_keys(const void *xarg, const void *yarg)
{
int flags = option_mask32, retval = 0;
int flags = global_flags, retval = 0;
char *x, *y;
#if ENABLE_FEATURE_SORT_BIG
struct sort_key *key;
for (key = key_list; !retval && key; key = key->next_key) {
flags = key->flags ? key->flags : option_mask32;
flags = key->flags ? key->flags : global_flags;
/* Chop out and modify key chunks, handling -dfib */
x = get_key(*(char **)xarg, key, flags);
y = get_key(*(char **)yarg, key, flags);
#else
/* This curly bracket serves no purpose but to match the nesting
level of the for () loop we're not using */
level of the for() loop we're not using */
{
x = *(char **)xarg;
y = *(char **)yarg;
@@ -180,11 +175,7 @@ static int compare_keys(const void *xarg, const void *yarg)
break;
/* Ascii sort */
case 0:
#if ENABLE_LOCALE_SUPPORT
retval = strcoll(x, y);
#else
retval = strcmp(x, y);
#endif
break;
#if ENABLE_FEATURE_SORT_BIG
case FLAG_g: {
@@ -240,7 +231,7 @@ static int compare_keys(const void *xarg, const void *yarg)
/* Free key copies. */
if (x != *(char **)xarg) free(x);
if (y != *(char **)yarg) free(y);
/* if (retval) break; - done by for () anyway */
/* if (retval) break; - done by for() anyway */
#else
/* Integer version of -n for tiny systems */
case FLAG_n:
@@ -248,103 +239,78 @@ static int compare_keys(const void *xarg, const void *yarg)
break;
} /* switch */
#endif
} /* for */
}
/* Perform fallback sort if necessary */
if (!retval && !(option_mask32 & FLAG_s))
if (!retval && !(global_flags & FLAG_s))
retval = strcmp(*(char **)xarg, *(char **)yarg);
if (flags & FLAG_r) return -retval;
return retval;
}
#if ENABLE_FEATURE_SORT_BIG
static unsigned str2u(char **str)
{
unsigned long lu;
if (!isdigit((*str)[0]))
bb_error_msg_and_die("bad field specification");
lu = strtoul(*str, str, 10);
if ((sizeof(long) > sizeof(int) && lu > INT_MAX) || !lu)
bb_error_msg_and_die("bad field specification");
return lu;
}
#endif
int sort_main(int argc, char **argv)
{
FILE *fp, *outfile = stdout;
char *line, **lines = NULL;
char *str_ignored, *str_o, *str_k, *str_t;
int i, flag;
int linecount = 0;
FILE *fp, *outfile = NULL;
int linecount = 0, i, flag;
char *line, **lines = NULL, *optlist = "ngMucszbrdfimS:T:o:k:t:";
int c;
xfunc_error_retval = 2;
/* Parse command line options */
/* -o and -t can be given at most once */
opt_complementary = "?:o--o:t--t";
getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &str_k, &str_t);
while ((c = getopt(argc, argv, optlist)) > 0) {
line = strchr(optlist, c);
if (!line) bb_show_usage();
switch (*line) {
#if ENABLE_FEATURE_SORT_BIG
if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w");
if (option_mask32 & FLAG_t) {
if (!str_t[0] || str_t[1])
bb_error_msg_and_die("bad -t parameter");
key_separator = str_t[0];
}
/* parse sort key */
if (option_mask32 & FLAG_k) {
enum {
FLAG_allowed_for_k =
FLAG_n | /* Numeric sort */
FLAG_g | /* Sort using strtod() */
FLAG_M | /* Sort date */
FLAG_b | /* Ignore leading blanks */
FLAG_r | /* Reverse */
FLAG_d | /* Ignore !(isalnum()|isspace()) */
FLAG_f | /* Force uppercase */
FLAG_i | /* Ignore !isprint() */
0
};
struct sort_key *key = add_key();
const char *temp2;
case 'o':
if (outfile) bb_error_msg_and_die("too many -o");
outfile = xfopen(optarg, "w");
break;
case 't':
if (key_separator || optarg[1])
bb_error_msg_and_die("too many -t");
key_separator = *optarg;
break;
/* parse sort key */
case 'k': {
struct sort_key *key = add_key();
char *temp, *temp2;
i = 0; /* i==0 before comma, 1 after (-k3,6) */
while (*str_k) {
/* Start of range */
/* Cannot use bb_strtou - suffix can be a letter */
key->range[2*i] = str2u(&str_k);
if (*str_k == '.') {
str_k++;
key->range[2*i+1] = str2u(&str_k);
}
while (*str_k) {
if (*str_k == ',' && !i++) {
str_k++;
break;
} /* no else needed: fall through to syntax error
because comma isn't in OPT_STR */
temp2 = strchr(OPT_STR, *str_k);
if (!temp2)
bb_error_msg_and_die("unknown key option");
flag = 1 << (temp2 - OPT_STR);
if (flag & ~FLAG_allowed_for_k)
bb_error_msg_and_die("unknown sort type");
/* b after ',' means strip _trailing_ space */
if (i && flag == FLAG_b) flag = FLAG_bb;
key->flags |= flag;
str_k++;
temp = optarg;
for (i = 0; *temp;) {
/* Start of range */
key->range[2*i] = (unsigned short)strtol(temp, &temp, 10);
if (*temp == '.')
key->range[(2*i)+1] = (unsigned short)strtol(temp+1, &temp, 10);
for (; *temp; temp++) {
if (*temp == ',' && !i++) {
temp++;
break;
} /* no else needed: fall through to syntax error
because comma isn't in optlist */
temp2 = strchr(optlist, *temp);
flag = (1 << (temp2 - optlist));
if (!temp2 || (flag > FLAG_M && flag < FLAG_b))
bb_error_msg_and_die("unknown key option");
/* b after ',' means strip _trailing_ space */
if (i && flag == FLAG_b) flag = FLAG_bb;
key->flags |= flag;
}
}
break;
}
#endif
default:
global_flags |= (1 << (line - optlist));
/* global b strips leading and trailing spaces */
if (global_flags & FLAG_b) global_flags |= FLAG_bb;
break;
}
}
#endif
/* global b strips leading and trailing spaces */
if (option_mask32 & FLAG_b) option_mask32 |= FLAG_bb;
/* Open input files and read data */
for (i = argv[optind] ? optind : optind-1; argv[i]; i++) {
fp = stdin;
if (i >= optind && NOT_LONE_DASH(argv[i]))
if (i >= optind && (argv[i][0] != '-' || argv[i][1]))
fp = xfopen(argv[i], "r");
for (;;) {
line = GET_LINE(fp);
@@ -360,8 +326,8 @@ int sort_main(int argc, char **argv)
if (!key_list)
add_key()->range[0] = 1;
/* handle -c */
if (option_mask32 & FLAG_c) {
int j = (option_mask32 & FLAG_u) ? -1 : 0;
if (global_flags & FLAG_c) {
int j = (global_flags & FLAG_u) ? -1 : 0;
for (i = 1; i < linecount; i++)
if (compare_keys(&lines[i-1], &lines[i]) > j) {
fprintf(stderr, "Check line %d\n", i);
@@ -373,12 +339,8 @@ int sort_main(int argc, char **argv)
/* Perform the actual sort */
qsort(lines, linecount, sizeof(char *), compare_keys);
/* handle -u */
if (option_mask32 & FLAG_u) {
flag = 0;
/* coreutils 6.3 drop lines for which only key is the same */
/* -- disabling last-resort compare... */
option_mask32 |= FLAG_s;
for (i = 1; i < linecount; i++) {
if (global_flags & FLAG_u) {
for (flag = 0, i = 1; i < linecount; i++) {
if (!compare_keys(&lines[flag], &lines[i]))
free(lines[i]);
else
@@ -387,6 +349,7 @@ int sort_main(int argc, char **argv)
if (linecount) linecount = flag+1;
}
/* Print it */
if (!outfile) outfile = stdout;
for (i = 0; i < linecount; i++)
fprintf(outfile, "%s\n", lines[i]);
+565 -451
View File
File diff suppressed because it is too large. Load diff
+109 -47
View File
@@ -15,80 +15,142 @@
#include "busybox.h"
enum { sysv_sum, bsd_sum };
/* 1 if any of the files read were the standard input */
static int have_read_stdin;
/* BSD: calculate and print the rotated checksum and the size in 1K blocks
The checksum varies depending on sizeof (int). */
/* SYSV: calculate and print the checksum and the size in 512-byte blocks */
/* Return 1 if successful. */
static int sum_file(const char *file, int type, int print_name)
/* make a little more readable and avoid using strcmp for just 2 bytes */
#define IS_STDIN(s) (s[0] == '-' && s[1] == '\0')
/* Calculate and print the rotated checksum and the size in 1K blocks
of file FILE, or of the standard input if FILE is "-".
If PRINT_NAME is >1, print FILE next to the checksum and size.
The checksum varies depending on sizeof (int).
Return 1 if successful. */
static int bsd_sum_file(const char *file, int print_name)
{
#define buf bb_common_bufsiz1
int r, fd;
FILE *fp;
int checksum = 0; /* The checksum mod 2^16. */
uintmax_t total_bytes = 0; /* The number of bytes. */
int ch; /* Each character read. */
int ret = 0;
if (IS_STDIN(file)) {
fp = stdin;
have_read_stdin++;
} else {
fp = fopen_or_warn(file, "r");
if (fp == NULL)
goto out;
}
while ((ch = getc(fp)) != EOF) {
++total_bytes;
checksum = (checksum >> 1) + ((checksum & 1) << 15);
checksum += ch;
checksum &= 0xffff; /* Keep it within bounds. */
}
if (ferror(fp)) {
bb_perror_msg(file);
fclose_if_not_stdin(fp);
goto out;
}
if (fclose_if_not_stdin(fp) == EOF) {
bb_perror_msg(file);
goto out;
}
ret++;
printf("%05d %5ju ", checksum, (total_bytes+1023)/1024);
if (print_name > 1)
puts(file);
else
puts("");
out:
return ret;
}
/* Calculate and print the checksum and the size in 512-byte blocks
of file FILE, or of the standard input if FILE is "-".
If PRINT_NAME is >0, print FILE next to the checksum and size.
Return 1 if successful. */
#define MY_BUF_SIZE 8192
static int sysv_sum_file(const char *file, int print_name)
{
RESERVE_CONFIG_BUFFER(buf, MY_BUF_SIZE);
int fd;
uintmax_t total_bytes = 0;
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
unsigned s = 0;
unsigned int s = 0;
fd = 0;
if (NOT_LONE_DASH(file)) {
if (IS_STDIN(file)) {
fd = 0;
have_read_stdin = 1;
} else {
fd = open(file, O_RDONLY);
if (fd == -1)
goto ret_bad;
goto release_and_ret;
}
while (1) {
size_t bytes_read = safe_read(fd, buf, BUFSIZ);
size_t bytes_read = safe_read(fd, buf, MY_BUF_SIZE);
if ((ssize_t)bytes_read <= 0) {
r = (fd && close(fd) != 0);
if (!bytes_read && !r)
/* no error */
break;
ret_bad:
if (bytes_read == 0)
break;
if (bytes_read == -1) {
release_and_ret:
bb_perror_msg(file);
RELEASE_CONFIG_BUFFER(buf);
if (!IS_STDIN(file))
close(fd);
return 0;
}
total_bytes += bytes_read;
if (type == sysv_sum) {
do s += buf[--bytes_read]; while (bytes_read);
} else {
r = 0;
do {
s = (s >> 1) + ((s & 1) << 15);
s += buf[r++];
s &= 0xffff; /* Keep it within bounds. */
} while (--bytes_read);
}
while (bytes_read--)
s += buf[bytes_read];
}
if (!print_name) file = "";
if (type == sysv_sum) {
r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
if (!IS_STDIN(file) && close(fd) == -1)
goto release_and_ret;
else
RELEASE_CONFIG_BUFFER(buf);
{
int r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
s = (r & 0xffff) + (r >> 16);
printf("%d %ju %s\n", s, (total_bytes+511)/512, file);
} else
printf("%05d %5ju %s\n", s, (total_bytes+1023)/1024, file);
printf("%d %ju ", s, (total_bytes+511)/512);
}
puts(print_name ? file : "");
return 1;
#undef buf
}
int sum_main(int argc, char **argv)
{
int n;
int type = bsd_sum;
int flags;
int ok;
int (*sum_func)(const char *, int) = bsd_sum_file;
n = getopt32(argc, argv, "sr");
if (n & 1) type = sysv_sum;
/* give the bsd priority over sysv func */
if (n & 2) type = bsd_sum;
/* give the bsd func priority over sysv func */
flags = getopt32(argc, argv, "sr");
if (flags & 1)
sum_func = sysv_sum_file;
if (flags & 2)
sum_func = bsd_sum_file;
if (argc == optind)
n = sum_file("-", type, 0);
have_read_stdin = 0;
if ((argc - optind) == 0)
ok = sum_func("-", 0);
else
for (n = 1; optind < argc; optind++)
n &= sum_file(argv[optind], type, 1);
for (ok = 1; optind < argc; optind++)
ok &= sum_func(argv[optind], 1);
return !n;
if (have_read_stdin && fclose(stdin) == EOF)
bb_perror_msg_and_die("-");
exit(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
+103 -54
View File
@@ -24,35 +24,56 @@
* 7) lseek attempted when count==0 even if arg was +0 (from top)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "busybox.h"
static const struct suffix_mult tail_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
{ "m", 1048576 },
{ NULL, 0 }
};
static int status;
static void tail_xbb_full_write(const char *buf, size_t len)
{
/* If we get a write error, there is really no sense in continuing. */
if (full_write(STDOUT_FILENO, buf, len) < 0)
bb_perror_nomsg_and_die();
}
static void tail_xprint_header(const char *fmt, const char *filename)
{
if (fdprintf(STDOUT_FILENO, fmt, filename) < 0)
#if defined __GLIBC__
if (dprintf(STDOUT_FILENO, fmt, filename) < 0) {
bb_perror_nomsg_and_die();
}
#else
int hdr_len = strlen(fmt) + strlen(filename);
char *hdr = xzalloc(hdr_len);
sprintf(hdr, filename, filename);
tail_xbb_full_write(hdr, hdr_len);
#endif
}
static ssize_t tail_read(int fd, char *buf, size_t count)
{
ssize_t r;
off_t current, end;
off_t current,end;
struct stat sbuf;
end = current = lseek(fd, 0, SEEK_CUR);
if (!fstat(fd, &sbuf))
end = sbuf.st_size;
lseek(fd, end < current ? 0 : current, SEEK_SET);
r = safe_read(fd, buf, count);
if (r < 0) {
if ((r = safe_read(fd, buf, count)) < 0) {
bb_perror_msg(bb_msg_read_error);
status = EXIT_FAILURE;
}
@@ -60,94 +81,122 @@ static ssize_t tail_read(int fd, char *buf, size_t count)
return r;
}
static const char tail_opts[] =
"fn:c:"
#if ENABLE_FEATURE_FANCY_TAIL
"qs:v"
#endif
;
static const char header_fmt[] = "\n==> %s <==\n";
int tail_main(int argc, char **argv)
{
unsigned count = 10;
long count = 10;
unsigned sleep_period = 1;
int from_top = 0;
int follow = 0;
int header_threshhold = 1;
const char *str_c, *str_n, *str_s;
int count_bytes = 0;
char *tailbuf;
size_t tailbufsize;
int taillen = 0;
int newline = 0;
int nfiles, nread, nwrite, seen, i, opt;
int *fds;
int *fds, nfiles, nread, nwrite, seen, i, opt;
char *s, *buf;
const char *fmt;
void eat_num(const char *p) {
if (*p == '-') p++;
else if (*p == '+') { p++; from_top = 1; }
count = xatou_sfx(p, tail_suffixes);
}
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
/* Allow legacy syntax of an initial numeric option without -n. */
if (argc >= 2 && (argv[1][0] == '+' || argv[1][0] == '-')
&& isdigit(argv[1][1])
) {
argv[0] = "-n";
argv--;
argc++;
optind = 2;
optarg = argv[1];
goto GET_COUNT;
}
#endif
opt = getopt32(argc, argv, "fc:n:" USE_FEATURE_FANCY_TAIL("qs:v"), &str_c, &str_n, &str_s);
#define FOLLOW (opt & 0x1)
#define COUNT_BYTES (opt & 0x2)
//if (opt & 0x1) // -f
if (opt & 0x2) eat_num(str_c); // -c
if (opt & 0x4) eat_num(str_n); // -n
#if ENABLE_FEATURE_FANCY_TAIL
if (opt & 0x8) header_threshhold = INT_MAX; // -q
if (opt & 0x10) sleep_period = xatou(str_s); // -s
if (opt & 0x20) header_threshhold = 0; // -v
while ((opt = getopt(argc, argv, tail_opts)) > 0) {
switch (opt) {
case 'f':
follow = 1;
break;
case 'c':
count_bytes = 1;
/* FALLS THROUGH */
case 'n':
#if !ENABLE_DEBUG_YANK_SUSv2 || ENABLE_FEATURE_FANCY_TAIL
GET_COUNT:
#endif
argc -= optind;
argv += optind;
count = xatol_sfx(optarg, tail_suffixes);
/* Note: Leading whitespace is an error trapped above. */
if (*optarg == '+') {
from_top = 1;
} else {
from_top = 0;
}
if (count < 0) {
count = -count;
}
break;
#if ENABLE_FEATURE_FANCY_TAIL
case 'q':
header_threshhold = INT_MAX;
break;
case 's':
sleep_period = xatou(optarg);
break;
case 'v':
header_threshhold = 0;
break;
#endif
default:
bb_show_usage();
}
}
/* open all the files */
fds = xmalloc(sizeof(int) * (argc + 1));
fds = (int *)xmalloc(sizeof(int) * (argc - optind + 1));
argv += optind;
nfiles = i = 0;
if (argc == 0) {
if ((argc -= optind) == 0) {
struct stat statbuf;
if (!fstat(STDIN_FILENO, &statbuf) && S_ISFIFO(statbuf.st_mode)) {
opt &= ~1; /* clear FOLLOW */
follow = 0;
}
/* --argv; */
*argv = (char *) bb_msg_standard_input;
goto DO_STDIN;
}
do {
if (NOT_LONE_DASH(argv[i])) {
fds[nfiles] = open(argv[i], O_RDONLY);
if (fds[nfiles] < 0) {
bb_perror_msg("%s", argv[i]);
status = EXIT_FAILURE;
continue;
}
} else {
DO_STDIN: /* "-" */
if ((argv[i][0] == '-') && !argv[i][1]) {
DO_STDIN:
fds[nfiles] = STDIN_FILENO;
} else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) {
bb_perror_msg("%s", argv[i]);
status = EXIT_FAILURE;
continue;
}
argv[nfiles] = argv[i];
++nfiles;
} while (++i < argc);
if (!nfiles)
if (!nfiles) {
bb_error_msg_and_die("no files");
}
tailbufsize = BUFSIZ;
/* tail the files */
if (!from_top && COUNT_BYTES) {
if (from_top < count_bytes) { /* Each is 0 or 1, so true iff 0 < 1. */
/* Hence, !from_top && count_bytes */
if (tailbufsize < count) {
tailbufsize = count + BUFSIZ;
}
@@ -163,7 +212,7 @@ int tail_main(int argc, char **argv)
* starting file position may not be the beginning of the file.
* Beware of backing up too far. See example in wc.c.
*/
if (!(count | from_top) && lseek(fds[i], 0, SEEK_END) >= 0) {
if ((!(count|from_top)) && (lseek(fds[i], 0, SEEK_END) >= 0)) {
continue;
}
@@ -181,22 +230,22 @@ int tail_main(int argc, char **argv)
if (from_top) {
nwrite = nread;
if (seen < count) {
if (COUNT_BYTES) {
if (count_bytes) {
nwrite -= (count - seen);
seen = count;
} else {
s = buf;
do {
--nwrite;
if (*s++ == '\n' && ++seen == count) {
if ((*s++ == '\n') && (++seen == count)) {
break;
}
} while (nwrite);
}
}
xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite);
tail_xbb_full_write(buf + nread - nwrite, nwrite);
} else if (count) {
if (COUNT_BYTES) {
if (count_bytes) {
taillen += nread;
if (taillen > count) {
memmove(tailbuf, tailbuf + taillen - count, count);
@@ -246,7 +295,7 @@ int tail_main(int argc, char **argv)
}
if (!from_top) {
xwrite(STDOUT_FILENO, tailbuf, taillen);
tail_xbb_full_write(tailbuf, taillen);
}
taillen = 0;
@@ -256,7 +305,7 @@ int tail_main(int argc, char **argv)
fmt = NULL;
if (FOLLOW) while (1) {
while (follow) {
sleep(sleep_period);
i = 0;
do {
@@ -268,7 +317,7 @@ int tail_main(int argc, char **argv)
tail_xprint_header(fmt, argv[i]);
fmt = NULL;
}
xwrite(STDOUT_FILENO, buf, nread);
tail_xbb_full_write(buf, nread);
}
} while (++i < nfiles);
}
+4 -6
View File
@@ -175,16 +175,14 @@ int bb_test(int argc, char **argv)
{
int res;
if (LONE_CHAR(argv[0], '[')) {
--argc;
if (NOT_LONE_CHAR(argv[argc], ']')) {
if (strcmp(argv[0], "[") == 0) {
if (strcmp(argv[--argc], "]")) {
bb_error_msg("missing ]");
return 2;
}
argv[argc] = NULL;
} else if (strcmp(argv[0], "[[") == 0) {
--argc;
if (strcmp(argv[argc], "]]")) {
if (strcmp(argv[--argc], "]]")) {
bb_error_msg("missing ]]");
return 2;
}
@@ -580,6 +578,6 @@ static int is_a_group_member(gid_t gid)
int test_main(int argc, char **argv)
{
return bb_test(argc, argv);
exit(bb_test(argc, argv));
}
+2 -2
View File
@@ -146,7 +146,7 @@ int uudecode_main(int argc, char **argv)
FILE *dst_stream;
int mode;
int ret;
if (strncmp(line, "begin-base64 ", 13) == 0) {
line_ptr = line + 13;
decode_fn_ptr = read_base64;
@@ -166,7 +166,7 @@ int uudecode_main(int argc, char **argv)
}
outname++;
}
if (LONE_DASH(outname)) {
if (strcmp(outname, "-") == 0) {
dst_stream = stdout;
} else {
dst_stream = xfopen(outname, "w");
+52 -55
View File
@@ -26,7 +26,7 @@ struct pid_list {
pid_t pid;
};
static struct pid_list *found;
static struct pid_list *found = NULL;
static inline void push(pid_t pid)
{
@@ -42,16 +42,13 @@ static int pid_is_exec(pid_t pid, const char *name)
{
char buf[sizeof("/proc//exe") + sizeof(int)*3];
char *execbuf;
int sz;
int equal;
sprintf(buf, "/proc/%d/exe", pid);
sz = strlen(name) + 1;
execbuf = xzalloc(sz);
readlink(buf, execbuf, sz);
execbuf = xstrdup(name);
readlink(buf, execbuf, strlen(name)+1);
/* if readlink fails, execbuf still contains "" */
equal = !strcmp(execbuf, name);
equal = ! strcmp(execbuf, name);
if (ENABLE_FEATURE_CLEAN_UP)
free(execbuf);
return equal;
@@ -62,7 +59,7 @@ static int pid_is_user(int pid, int uid)
struct stat sb;
char buf[sizeof("/proc/") + sizeof(int)*3];
sprintf(buf, "/proc/%u", pid);
sprintf(buf, "/proc/%d", pid);
if (stat(buf, &sb) != 0)
return 0;
return (sb.st_uid == uid);
@@ -70,24 +67,25 @@ static int pid_is_user(int pid, int uid)
static int pid_is_cmd(pid_t pid, const char *name)
{
char fname[sizeof("/proc//stat") + sizeof(int)*3];
char *buf;
int r = 0;
char buf[sizeof("/proc//stat") + sizeof(int)*3];
FILE *f;
int c;
sprintf(fname, "/proc/%u/stat", pid);
buf = xmalloc_open_read_close(fname, NULL);
if (buf) {
char *p = strchr(buf, '(');
if (p) {
char *pe = strrchr(++p, ')');
if (pe) {
*pe = '\0';
r = !strcmp(p, name);
}
}
free(buf);
sprintf(buf, "/proc/%d/stat", pid);
f = fopen(buf, "r");
if (!f)
return 0;
while ((c = getc(f)) != EOF && c != '(')
;
if (c != '(') {
fclose(f);
return 0;
}
return r;
/* this hopefully handles command names containing ')' */
while ((c = getc(f)) != EOF && c == *name)
name++;
fclose(f);
return (c == ')' && *name == '\0');
}
@@ -113,7 +111,7 @@ static void do_pidfile(void)
f = fopen(pidfile, "r");
if (f) {
if (fscanf(f, "%u", &pid) == 1)
if (fscanf(f, "%d", &pid) == 1)
check(pid);
fclose(f);
} else if (errno != ENOENT)
@@ -135,8 +133,7 @@ static void do_procinit(void)
foundany = 0;
while ((entry = readdir(procdir)) != NULL) {
pid = bb_strtou(entry->d_name, NULL, 10);
if (errno)
if (sscanf(entry->d_name, "%d", &pid) != 1)
continue;
foundany++;
check(pid);
@@ -194,7 +191,7 @@ static int do_stop(void)
}
#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
static const struct option long_options[] = {
static const struct option ssd_long_options[] = {
{ "stop", 0, NULL, 'K' },
{ "start", 0, NULL, 'S' },
{ "background", 0, NULL, 'b' },
@@ -219,16 +216,16 @@ static const struct option long_options[] = {
};
#endif
enum {
CTX_STOP = 0x1,
CTX_START = 0x2,
OPT_BACKGROUND = 0x4,
OPT_QUIET = 0x8,
OPT_MAKEPID = 0x10,
OPT_OKNODO = 0x20 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY,
OPT_VERBOSE = 0x40 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY,
OPT_NICELEVEL = 0x80 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY,
};
#define SSD_CTX_STOP 0x1
#define SSD_CTX_START 0x2
#define SSD_OPT_BACKGROUND 0x4
#define SSD_OPT_QUIET 0x8
#define SSD_OPT_MAKEPID 0x10
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
#define SSD_OPT_OKNODO 0x20
#define SSD_OPT_VERBOSE 0x40
#define SSD_OPT_NICELEVEL 0x80
#endif
int start_stop_daemon_main(int argc, char **argv)
{
@@ -241,7 +238,7 @@ int start_stop_daemon_main(int argc, char **argv)
char *opt_N;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
applet_long_options = long_options;
applet_long_options = ssd_long_options;
#endif
/* Check required one context option was given */
@@ -254,7 +251,8 @@ int start_stop_daemon_main(int argc, char **argv)
// USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
,&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile);
quiet = (opt & OPT_QUIET) && !(opt & OPT_VERBOSE);
quiet = (opt & SSD_OPT_QUIET)
USE_FEATURE_START_STOP_DAEMON_FANCY(&& !(opt & SSD_OPT_VERBOSE));
if (signame) {
signal_nr = get_signum(signame);
@@ -271,15 +269,14 @@ int start_stop_daemon_main(int argc, char **argv)
argc -= optind;
argv += optind;
if (userspec) {
user_id = bb_strtou(userspec, NULL, 10);
if (errno)
user_id = xuname2uid(userspec);
}
if (userspec && sscanf(userspec, "%d", &user_id) != 1)
user_id = bb_xgetpwnam(userspec);
if (opt & CTX_STOP) {
if (opt & SSD_CTX_STOP) {
int i = do_stop();
return (opt & OPT_OKNODO) ? 0 : (i<=0);
return
USE_FEATURE_START_STOP_DAEMON_FANCY((opt & SSD_OPT_OKNODO)
? 0 :) !!(i<=0);
}
do_procinit();
@@ -287,14 +284,15 @@ int start_stop_daemon_main(int argc, char **argv)
if (found) {
if (!quiet)
printf("%s already running\n%d\n", execname, found->pid);
return !(opt & OPT_OKNODO);
USE_FEATURE_START_STOP_DAEMON_FANCY(return !(opt & SSD_OPT_OKNODO);)
SKIP_FEATURE_START_STOP_DAEMON_FANCY(return EXIT_FAILURE;)
}
*--argv = startas;
if (opt & OPT_BACKGROUND) {
if (opt & SSD_OPT_BACKGROUND) {
xdaemon(0, 0);
setsid();
bb_daemonize();
}
if (opt & OPT_MAKEPID) {
if (opt & SSD_OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
FILE *pidf = xfopen(pidfile, "w");
@@ -303,13 +301,12 @@ int start_stop_daemon_main(int argc, char **argv)
fclose(pidf);
}
if (chuid) {
user_id = bb_strtou(chuid, NULL, 10);
if (errno)
user_id = xuname2uid(chuid);
if (sscanf(chuid, "%d", &user_id) != 1)
user_id = bb_xgetpwnam(chuid);
xsetuid(user_id);
}
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
if (opt & OPT_NICELEVEL) {
if (opt & SSD_OPT_NICELEVEL) {
/* Set process priority */
int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, INT_MIN/2, INT_MAX/2);
if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
+4 -4
View File
@@ -82,7 +82,7 @@ have additions to this FAQ document, we would love to add them,
to determine which applet to run, as shown above.
</p>
<p>
BusyBox also has a feature called the
BusyBox also has a feature called the
<a name="standalone_shell">"standalone shell"</a>, where the busybox
shell runs any built-in applets before checking the command path. This
feature is also enabled by "make allyesconfig", and to try it out run
@@ -261,7 +261,7 @@ within each applet. More build coverage testing.</p></li>
<hr />
<p>
<h2><a name="external">where can i find other small utilities since busybox
<h2><a name="external">where can i find other small utilities since busybox
does not include the features i want?</a></h2>
<p>
we maintain such a <a href="tinyutils.html">list</a> on this site!
@@ -941,7 +941,7 @@ text console scrolling...)</p>
<p>So will data always be read from the far end of a pipe at the
same chunk sizes it was written in? Nope. Don't rely on that. For one
counterexample, see <a href="http://www.faqs.org/rfcs/rfc896.html">rfc 896
counterexample, see <a href="http://www.faqs.org/rfcs/rfc896.html">rfc 896
for Nagle's algorithm</a>, which waits a fraction of a second or so before
sending out small amounts of data through a TCP/IP connection in case more
data comes in that can be merged into the same packet. (In case you were
@@ -1089,7 +1089,7 @@ aaronl :Aaron Lehmann
beppu :John Beppu
dwhedon :David Whedon
erik :Erik Andersen
gfeldman :Gennady Feldman
gfeldman :Gennady Feldman
jimg :Jim Gleason
kraai :Matt Kraai
markw :Mark Whitley
+1 -2
View File
@@ -16,8 +16,7 @@ commands (or features) at compile time. This makes it easy to customize
your embedded systems. To create a working system, just add some device
nodes in /dev, a few configuration files in /etc, and a Linux kernel.</p>
<p>BusyBox is maintained by
<a href="mailto:vda.linux@googlemail.com">Denis Vlasenko</a>,
<p>BusyBox is maintained by <a href="http://www.landley.net/">Rob Landley</a>,
and licensed under the <a href="/license.html">GNU GENERAL PUBLIC LICENSE</a>
version 2 or later.</p>
+3 -12
View File
@@ -2,17 +2,8 @@
<ul>
<li><b>27 December, 2006 -- BusyBox 1.3.1 (stable)</b>
<p><a href=http://busybox.net/downloads/busybox-1.3.1.tar.bz2>BusyBox 1.3.1</a>.
(<a href=http://busybox.net/downloads/fixes-1.3.1/>patches</a>)</p>
<p>Closing 2006 with new release. It includes only trivial fixes accumulated since 1.3.0
</p>
</li>
<li><b>14 December, 2006 -- BusyBox 1.3.0 (stable)</b>
<p><a href=http://busybox.net/downloads/busybox-1.3.0.tar.bz2>BusyBox 1.3.0</a>.
(<a href=http://busybox.net/downloads/fixes-1.3.0/>patches</a>)</p>
<p><a href=http://busybox.net/downloads/busybox-1.3.0.tar.bz2>BusyBox 1.3.0</a>.</p>
<p>This release has CONFIG_DESKTOP option which enables features
needed for busybox usage on desktop machine. For example, find, chmod
@@ -28,8 +19,8 @@
<li>grep: added -r, fixed -h
<li>watch: make it exec child like standard one does (was totally
incompatible)
<li>tar: fix limitations which were preventing bbox tar usage
on big directories: long names and linknames, pax headers
<li>tar: fix limitations which were preventing bbox tar usage
on a big directories: long names and linknames, pax headers
(Linux kernel tarballs have that). Fixed a number of obscure bugs.
Raised max file limit (now 64Gb). Security fixes (/../ attacks).
<li>httpd: added -i (inetd), -f (foreground), support for
+7 -7
View File
@@ -40,7 +40,7 @@ scripts using <code>Control-C</code>. Or have interactive applications
that don't behave right when sending SIGINT. Examples are emacs'es
that die on Control-g or shellscript statements that sometimes are
executed and sometimes not, apparently not determined by the user's
intention.
intention.
</td></tr><tr><th valign=top align=left>Required knowledge: </th>
@@ -101,7 +101,7 @@ just exit.
<p>Now imagine the user hits C-c while a shellscript is executing its
first program. The following programs receive SIGINT: program1 and
also the shell executing the script. program1 exits.
also the shell executing the script. program1 exits.
<p>But what should the shell do? If we say that it is only the
innermost's programs business to react on SIGINT, the shell will do
@@ -351,7 +351,7 @@ that do not properly communicate the required information up to the
calling program.
<p>Unless a program messes with signal handling, the system does this
automatically.
automatically.
<p>There are programs that want to exit on SIGINT, but they don't let
the system do the automatic exit, because they want to do some
@@ -425,7 +425,7 @@ Notes:
special numeric value. People often assume this since the manuals for
shells often list some return value for exactly this. But this is just
a convention for your shell script. It does not work from one UNIX API
program to another.
program to another.
<P>All that happens is that the shell sets the "$?" variable to a
special numeric value for the convenience of your script, because your
@@ -571,7 +571,7 @@ comments the scripts echo.
<tr valign=top align=left>
<td>IUE</td>
<td>The shell executing a script exits immediately if it receives
SIGINT.</td>
SIGINT.</td>
<td>4.4BSD ash (ash), NetBSD, FreeBSD prior to 3.0/22.8</td>
<td>The editor session is lost and subsequent commands are not
executed.</td>
@@ -605,7 +605,7 @@ will further commands from the script be executed. </td>
signal (either it had the default handler for SIGINT or it killed
itself). </td>
<td>bash (Linux /bin/sh), most commercial /bin/sh, FreeBSD /bin/sh
from 3.0/2.2.8.</td>
from 3.0/2.2.8.</td>
<td>The editor continues as normal and subsequent commands are
executed. </td>
<td>The editor continues as normal and subsequent commands are
@@ -615,7 +615,7 @@ child exits, but only if the child exited with signal status. If
the child did a normal exit (even if it received SIGINT, but catches
it), the script will continue. </td>
<td>The child must be implemented right, or the user will not be able
to break shell scripts reliably.</td>
to break shell scripts reliably.</td>
</tr>
</table>
+116 -116
View File
@@ -4,197 +4,197 @@ for everything (filename, uid, filesize etc) which can overflow.
pax Header Block
The pax header block shall be identical to the ustar header block
described in ustar Interchange Format, except that two additional
The pax header block shall be identical to the ustar header block
described in ustar Interchange Format, except that two additional
typeflag values are defined:
x
Represents extended header records for the following file in
Represents extended header records for the following file in
the archive (which shall have its own ustar header block).
g
Represents global extended header records for the following
files in the archive. Each value shall affect all subsequent files
that do not override that value in their own extended header
record and until another global extended header record is reached
that provides another value for the same field. The typeflag g
global headers should not be used with interchange media that
Represents global extended header records for the following
files in the archive. Each value shall affect all subsequent files
that do not override that value in their own extended header
record and until another global extended header record is reached
that provides another value for the same field. The typeflag g
global headers should not be used with interchange media that
could suffer partial data loss in transporting the archive.
For both of these types, the size field shall be the size of the
extended header records in octets. The other fields in the header
block are not meaningful to this version of the pax utility.
However, if this archive is read by a pax utility conforming to
the ISO POSIX-2:1993 standard, the header block fields are used to
create a regular file that contains the extended header records as
data. Therefore, header block field values should be selected to
For both of these types, the size field shall be the size of the
extended header records in octets. The other fields in the header
block are not meaningful to this version of the pax utility.
However, if this archive is read by a pax utility conforming to
the ISO POSIX-2:1993 standard, the header block fields are used to
create a regular file that contains the extended header records as
data. Therefore, header block field values should be selected to
provide reasonable file access to this regular file.
A further difference from the ustar header block is that data
blocks for files of typeflag 1 (the digit one) (hard link) may be
included, which means that the size field may be greater than
A further difference from the ustar header block is that data
blocks for files of typeflag 1 (the digit one) (hard link) may be
included, which means that the size field may be greater than
zero.
pax Extended Header
An extended header shall consist of one or more records, each
An extended header shall consist of one or more records, each
constructed as follows:
"%d %s=%s\n", <length>, <keyword>, <value>
The <length> field shall be the decimal length of the extended
header record in octets, including length string itself and the
The <length> field shall be the decimal length of the extended
header record in octets, including length string itself and the
trailing <newline>.
[skip]
atime
The file access time for the following file(s), equivalent to
the value of the st_atime member of the stat structure for a file,
as described by the stat() function. The access time shall be
restored if the process has the appropriate privilege required to
do so. The format of the <value> shall be as described in pax
The file access time for the following file(s), equivalent to
the value of the st_atime member of the stat structure for a file,
as described by the stat() function. The access time shall be
restored if the process has the appropriate privilege required to
do so. The format of the <value> shall be as described in pax
Extended Header File Times.
charset
The name of the character set used to encode the data in the
The name of the character set used to encode the data in the
following file(s).
The encoding is included in an extended header for information
only; when pax is used as described in IEEE Std 1003.1-2001, it
shall not translate the file data into any other encoding. The
The encoding is included in an extended header for information
only; when pax is used as described in IEEE Std 1003.1-2001, it
shall not translate the file data into any other encoding. The
BINARY entry indicates unencoded binary data.
When used in write or copy mode, it is implementation-defined
When used in write or copy mode, it is implementation-defined
whether pax includes a charset extended header record for a file.
comment
A series of characters used as a comment. All characters in
A series of characters used as a comment. All characters in
the <value> field shall be ignored by pax.
gid
The group ID of the group that owns the file, expressed as a
decimal number using digits from the ISO/IEC 646:1991 standard.
This record shall override the gid field in the following header
block(s). When used in write or copy mode, pax shall include a gid
extended header record for each file whose group ID is greater
The group ID of the group that owns the file, expressed as a
decimal number using digits from the ISO/IEC 646:1991 standard.
This record shall override the gid field in the following header
block(s). When used in write or copy mode, pax shall include a gid
extended header record for each file whose group ID is greater
than 2097151 (octal 7777777).
gname
The group of the file(s), formatted as a group name in the
group database. This record shall override the gid and gname
fields in the following header block(s), and any gid extended
header record. When used in read, copy, or list mode, pax shall
translate the name from the UTF-8 encoding in the header record to
the character set appropriate for the group database on the
receiving system. If any of the UTF-8 characters cannot be
translated, and if the -o invalid= UTF-8 option is not specified,
the results are implementation-defined. When used in write or copy
mode, pax shall include a gname extended header record for each
file whose group name cannot be represented entirely with the
The group of the file(s), formatted as a group name in the
group database. This record shall override the gid and gname
fields in the following header block(s), and any gid extended
header record. When used in read, copy, or list mode, pax shall
translate the name from the UTF-8 encoding in the header record to
the character set appropriate for the group database on the
receiving system. If any of the UTF-8 characters cannot be
translated, and if the -o invalid= UTF-8 option is not specified,
the results are implementation-defined. When used in write or copy
mode, pax shall include a gname extended header record for each
file whose group name cannot be represented entirely with the
letters and digits of the portable character set.
linkpath
The pathname of a link being created to another file, of any
type, previously archived. This record shall override the linkname
field in the following ustar header block(s). The following ustar
header block shall determine the type of link created. If typeflag
of the following header block is 1, it shall be a hard link. If
typeflag is 2, it shall be a symbolic link and the linkpath value
shall be the contents of the symbolic link. The pax utility shall
translate the name of the link (contents of the symbolic link)
from the UTF-8 encoding to the character set appropriate for the
local file system. When used in write or copy mode, pax shall
include a linkpath extended header record for each link whose
pathname cannot be represented entirely with the members of the
The pathname of a link being created to another file, of any
type, previously archived. This record shall override the linkname
field in the following ustar header block(s). The following ustar
header block shall determine the type of link created. If typeflag
of the following header block is 1, it shall be a hard link. If
typeflag is 2, it shall be a symbolic link and the linkpath value
shall be the contents of the symbolic link. The pax utility shall
translate the name of the link (contents of the symbolic link)
from the UTF-8 encoding to the character set appropriate for the
local file system. When used in write or copy mode, pax shall
include a linkpath extended header record for each link whose
pathname cannot be represented entirely with the members of the
portable character set other than NUL.
mtime
The file modification time of the following file(s),
equivalent to the value of the st_mtime member of the stat
structure for a file, as described in the stat() function. This
record shall override the mtime field in the following header
block(s). The modification time shall be restored if the process
has the appropriate privilege required to do so. The format of the
The file modification time of the following file(s),
equivalent to the value of the st_mtime member of the stat
structure for a file, as described in the stat() function. This
record shall override the mtime field in the following header
block(s). The modification time shall be restored if the process
has the appropriate privilege required to do so. The format of the
<value> shall be as described in pax Extended Header File Times.
path
The pathname of the following file(s). This record shall
override the name and prefix fields in the following header
block(s). The pax utility shall translate the pathname of the file
from the UTF-8 encoding to the character set appropriate for the
The pathname of the following file(s). This record shall
override the name and prefix fields in the following header
block(s). The pax utility shall translate the pathname of the file
from the UTF-8 encoding to the character set appropriate for the
local file system.
When used in write or copy mode, pax shall include a path
extended header record for each file whose pathname cannot be
represented entirely with the members of the portable character
When used in write or copy mode, pax shall include a path
extended header record for each file whose pathname cannot be
represented entirely with the members of the portable character
set other than NUL.
realtime.any
The keywords prefixed by "realtime." are reserved for future
The keywords prefixed by "realtime." are reserved for future
standardization.
security.any
The keywords prefixed by "security." are reserved for future
The keywords prefixed by "security." are reserved for future
standardization.
size
The size of the file in octets, expressed as a decimal number
using digits from the ISO/IEC 646:1991 standard. This record shall
override the size field in the following header block(s). When
used in write or copy mode, pax shall include a size extended
header record for each file with a size value greater than
The size of the file in octets, expressed as a decimal number
using digits from the ISO/IEC 646:1991 standard. This record shall
override the size field in the following header block(s). When
used in write or copy mode, pax shall include a size extended
header record for each file with a size value greater than
8589934591 (octal 77777777777).
uid
The user ID of the file owner, expressed as a decimal number
using digits from the ISO/IEC 646:1991 standard. This record shall
override the uid field in the following header block(s). When used
in write or copy mode, pax shall include a uid extended header
record for each file whose owner ID is greater than 2097151 (octal
The user ID of the file owner, expressed as a decimal number
using digits from the ISO/IEC 646:1991 standard. This record shall
override the uid field in the following header block(s). When used
in write or copy mode, pax shall include a uid extended header
record for each file whose owner ID is greater than 2097151 (octal
7777777).
uname
The owner of the following file(s), formatted as a user name
in the user database. This record shall override the uid and uname
fields in the following header block(s), and any uid extended
header record. When used in read, copy, or list mode, pax shall
translate the name from the UTF-8 encoding in the header record to
the character set appropriate for the user database on the
receiving system. If any of the UTF-8 characters cannot be
translated, and if the -o invalid= UTF-8 option is not specified,
the results are implementation-defined. When used in write or copy
mode, pax shall include a uname extended header record for each
file whose user name cannot be represented entirely with the
The owner of the following file(s), formatted as a user name
in the user database. This record shall override the uid and uname
fields in the following header block(s), and any uid extended
header record. When used in read, copy, or list mode, pax shall
translate the name from the UTF-8 encoding in the header record to
the character set appropriate for the user database on the
receiving system. If any of the UTF-8 characters cannot be
translated, and if the -o invalid= UTF-8 option is not specified,
the results are implementation-defined. When used in write or copy
mode, pax shall include a uname extended header record for each
file whose user name cannot be represented entirely with the
letters and digits of the portable character set.
If the <value> field is zero length, it shall delete any header
block field, previously entered extended header value, or global
If the <value> field is zero length, it shall delete any header
block field, previously entered extended header value, or global
extended header value of the same name.
If a keyword in an extended header record (or in a -o
option-argument) overrides or deletes a corresponding field in the
ustar header block, pax shall ignore the contents of that header
If a keyword in an extended header record (or in a -o
option-argument) overrides or deletes a corresponding field in the
ustar header block, pax shall ignore the contents of that header
block field.
Unlike the ustar header block fields, NULs shall not delimit
<value>s; all characters within the <value> field shall be
considered data for the field. None of the length limitations of
the ustar header block fields in ustar Header Block shall apply to
Unlike the ustar header block fields, NULs shall not delimit
<value>s; all characters within the <value> field shall be
considered data for the field. None of the length limitations of
the ustar header block fields in ustar Header Block shall apply to
the extended header records.
pax Extended Header File Times
Time records shall be formatted as a decimal representation of the
time in seconds since the Epoch. If a period ( '.' ) decimal point
character is present, the digits to the right of the point shall
represent the units of a subsecond timing granularity. In read or
copy mode, the pax utility shall truncate the time of a file to
the greatest value that is not greater than the input header
file time. In write or copy mode, the pax utility shall output a
time exactly if it can be represented exactly as a decimal number,
and otherwise shall generate only enough digits so that the same
time shall be recovered if the file is extracted on a system whose
Time records shall be formatted as a decimal representation of the
time in seconds since the Epoch. If a period ( '.' ) decimal point
character is present, the digits to the right of the point shall
represent the units of a subsecond timing granularity. In read or
copy mode, the pax utility shall truncate the time of a file to
the greatest value that is not greater than the input header
file time. In write or copy mode, the pax utility shall output a
time exactly if it can be represented exactly as a decimal number,
and otherwise shall generate only enough digits so that the same
time shall be recovered if the file is extracted on a system whose
underlying implementation supports the same time granularity.
Example from Linux kernel archive tarball:
+34 -34
View File
@@ -11,14 +11,14 @@ config CHATTR
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 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"
@@ -34,34 +34,34 @@ config LSATTR
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 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 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 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.
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
+7 -3
View File
@@ -6,7 +6,11 @@
lib-y:=
lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
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
lib-$(CONFIG_FSCK) += fsck.o
CFLAGS += -include $(srctree)/e2fsprogs/e2fsbb.h
+2 -11
View File
@@ -1,12 +1,3 @@
Authors and contributors of original e2fsprogs:
This is a pretty straight rip from the e2fsprogs pkg.
Remy Card <card@masi.ibp.fr>
Theodore Ts'o <tytso@mit.edu>
Stephen C. Tweedie <sct@redhat.com>
Andreas Gruenbacher, <a.gruenbacher@computer.org>
Kaz Kylheku <kaz@ashi.footprints.net>
F.W. ten Wolde <franky@duteca.et.tudelft.nl>
Jeremy Fitzhardinge <jeremy@zip.com.au>
M.J.E. Mol <marcel@duteca.et.tudelft.nl>
Miquel van Smoorenburg <miquels@drinkel.ow.org>
Uwe Ohse <uwe@tirka.gun.de>
See README's in subdirs for specific info.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -189,7 +189,7 @@ static void lvm_probe_all(blkid_cache cache)
struct dirent *lv_iter;
vg_name = vg_iter->d_name;
if (LONE_CHAR(vg_name, '.') || !strcmp(vg_name, ".."))
if (!strcmp(vg_name, ".") || !strcmp(vg_name, ".."))
continue;
vdirname = xmalloc(vg_len + strlen(vg_name) + 8);
sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
@@ -203,7 +203,7 @@ static void lvm_probe_all(blkid_cache cache)
char *lv_name, *lvm_device;
lv_name = lv_iter->d_name;
if (LONE_CHAR(lv_name, '.') || !strcmp(lv_name, ".."))
if (!strcmp(lv_name, ".") || !strcmp(lv_name, ".."))
continue;
lvm_device = xmalloc(vg_len + strlen(vg_name) +
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -349,7 +349,7 @@ static int probe_swap1(int fd,
* pagesize).
*/
if (lseek(fd, 1024, SEEK_SET) < 0) return 1;
sws = xmalloc(1024);
sws = (struct swap_id_block *)xmalloc(1024);
if (read(fd, sws, 1024) != 1024) {
free(sws);
return 1;
@@ -620,7 +620,7 @@ try_again:
if (lseek(fd, idx << 10, SEEK_SET) < 0)
continue;
buf = xmalloc(1024);
buf = (unsigned char *)xmalloc(1024);
if (read(fd, buf, 1024) != 1024) {
free(buf);
@@ -238,7 +238,7 @@ struct ocfs_volume_header {
struct ocfs_volume_label {
unsigned char disk_lock[48];
char label[64];
char label[64];
unsigned char label_len[2];
unsigned char vol_id[16];
unsigned char vol_id_len[2];
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+68 -39
View File
@@ -19,8 +19,26 @@
* 98/12/29 - Display version info only when -V specified (G M Sipe)
*/
#include "busybox.h"
#include "e2fs_lib.h"
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/stat.h>
#include "ext2fs/ext2_fs.h"
#ifdef __GNUC__
# define EXT2FS_ATTR(x) __attribute__(x)
#else
# define EXT2FS_ATTR(x)
#endif
#include "e2fsbb.h"
#include "e2p/e2p.h"
#define OPT_ADD 1
#define OPT_REM 2
@@ -59,13 +77,14 @@ static const struct flags_char flags_array[] = {
static unsigned long get_flag(char c)
{
const struct flags_char *fp;
for (fp = flags_array; fp->optchar; fp++)
for (fp = flags_array; fp->flag; fp++)
if (fp->optchar == c)
return fp->flag;
bb_show_usage();
return 0;
}
static int decode_arg(const char *arg)
static int decode_arg(char *arg)
{
unsigned long *fl;
char opt = *arg++;
@@ -80,35 +99,23 @@ static int decode_arg(const char *arg)
flags |= OPT_SET;
fl = &sf;
} else
return 0;
return EOF;
while (*arg)
*fl |= get_flag(*arg++);
for (; *arg ; ++arg)
(*fl) |= get_flag(*arg);
return 1;
}
static void change_attributes(const char *name);
static int chattr_dir_proc(const char *, struct dirent *, void *);
static int chattr_dir_proc(const char *dir_name, struct dirent *de,
void *private ATTRIBUTE_UNUSED)
{
char *path = concat_subpath_file(dir_name, de->d_name);
/* path is NULL if de->d_name is "." or "..", else... */
if (path) {
change_attributes(path);
free(path);
}
return 0;
}
static void change_attributes(const char *name)
static void change_attributes(const char * name)
{
unsigned long fsflags;
struct stat st;
if (lstat(name, &st) == -1) {
bb_perror_msg("stat %s", name);
bb_error_msg("stat %s failed", name);
return;
}
if (S_ISLNK(st.st_mode) && recursive)
@@ -123,13 +130,13 @@ static void change_attributes(const char *name)
if (flags & OPT_SET_VER)
if (fsetversion(name, version) == -1)
bb_perror_msg("setting version on %s", name);
bb_error_msg("setting version on %s", name);
if (flags & OPT_SET) {
fsflags = sf;
} else {
if (fgetflags(name, &fsflags) == -1) {
bb_perror_msg("reading flags on %s", name);
bb_error_msg("reading flags on %s", name);
goto skip_setflags;
}
if (flags & OPT_REM)
@@ -140,50 +147,72 @@ static void change_attributes(const char *name)
fsflags &= ~EXT2_DIRSYNC_FL;
}
if (fsetflags(name, fsflags) == -1)
bb_perror_msg("setting flags on %s", name);
bb_error_msg("setting flags on %s", name);
skip_setflags:
if (recursive && S_ISDIR(st.st_mode))
skip_setflags:
if (S_ISDIR(st.st_mode) && recursive)
iterate_on_dir(name, chattr_dir_proc, NULL);
}
static int chattr_dir_proc(const char *dir_name, struct dirent *de,
void *private EXT2FS_ATTR((unused)))
{
/*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/
if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \
(de->d_name[1] == '.' && de->d_name[2] == '\0'))) {
char *path = concat_subpath_file(dir_name, de->d_name);
if (path) {
change_attributes(path);
free(path);
}
}
return 0;
}
int chattr_main(int argc, char **argv)
{
int i;
char *arg;
/* parse the args */
while ((arg = *++argv)) {
for (i = 1; i < argc; ++i) {
arg = argv[i];
/* take care of -R and -v <version> */
if (arg[0] == '-') {
if (arg[1] == 'R' && arg[2] == '\0') {
recursive = 1;
continue;
}
if (arg[1] == 'v' && arg[2] == '\0') {
if (!*++argv)
} else if (arg[1] == 'v' && arg[2] == '\0') {
char *tmp;
++i;
if (i >= argc)
bb_show_usage();
version = xatoul(*argv);
version = strtol(argv[i], &tmp, 0);
if (*tmp)
bb_error_msg_and_die("bad version '%s'", arg);
flags |= OPT_SET_VER;
continue;
}
}
if (!decode_arg(arg))
if (decode_arg(arg) == EOF)
break;
}
/* run sanity checks on all the arguments given us */
if (!*argv)
if (i >= argc)
bb_show_usage();
if ((flags & OPT_SET) && (flags & (OPT_ADD|OPT_REM)))
if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM)))
bb_error_msg_and_die("= is incompatible with - and +");
if (rf & af)
bb_error_msg_and_die("can't set and unset a flag");
if ((rf & af) != 0)
bb_error_msg_and_die("Can't set and unset a flag");
if (!flags)
bb_error_msg_and_die("must use '-v', =, - or +");
bb_error_msg_and_die("Must use '-v', =, - or +");
/* now run chattr on all the files passed to us */
do change_attributes(*argv); while (*++argv);
while (i < argc)
change_attributes(argv[i++]);
return EXIT_SUCCESS;
}
-561
View File
@@ -1,561 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* linux/include/linux/ext2_fs.h
*
* Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr)
* Laboratoire MASI - Institut Blaise Pascal
* Universite Pierre et Marie Curie (Paris VI)
*
* Copyright (C) 1991, 1992 Linus Torvalds
*/
#ifndef _LINUX_EXT2_FS_H
#define _LINUX_EXT2_FS_H
/*
* Special inode numbers
*/
#define EXT2_BAD_INO 1 /* Bad blocks inode */
#define EXT2_ROOT_INO 2 /* Root inode */
#define EXT2_ACL_IDX_INO 3 /* ACL inode */
#define EXT2_ACL_DATA_INO 4 /* ACL inode */
#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
#define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */
#define EXT2_JOURNAL_INO 8 /* Journal inode */
/* First non-reserved inode for old ext2 filesystems */
#define EXT2_GOOD_OLD_FIRST_INO 11
/*
* The second extended file system magic number
*/
#define EXT2_SUPER_MAGIC 0xEF53
/* Assume that user mode programs are passing in an ext2fs superblock, not
* a kernel struct super_block. This will allow us to call the feature-test
* macros from user land. */
#define EXT2_SB(sb) (sb)
/*
* Maximal count of links to a file
*/
#define EXT2_LINK_MAX 32000
/*
* Macro-instructions used to manage several block sizes
*/
#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */
#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t))
/*
* Macro-instructions used to manage fragments
*/
#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE
#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE
#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE
#define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
/*
* ACL structures
*/
struct ext2_acl_header { /* Header of Access Control Lists */
uint32_t aclh_size;
uint32_t aclh_file_count;
uint32_t aclh_acle_count;
uint32_t aclh_first_acle;
};
struct ext2_acl_entry { /* Access Control List Entry */
uint32_t acle_size;
uint16_t acle_perms; /* Access permissions */
uint16_t acle_type; /* Type of entry */
uint16_t acle_tag; /* User or group identity */
uint16_t acle_pad1;
uint32_t acle_next; /* Pointer on next entry for the */
/* same inode or on next free entry */
};
/*
* Structure of a blocks group descriptor
*/
struct ext2_group_desc {
uint32_t bg_block_bitmap; /* Blocks bitmap block */
uint32_t bg_inode_bitmap; /* Inodes bitmap block */
uint32_t bg_inode_table; /* Inodes table block */
uint16_t bg_free_blocks_count; /* Free blocks count */
uint16_t bg_free_inodes_count; /* Free inodes count */
uint16_t bg_used_dirs_count; /* Directories count */
uint16_t bg_pad;
uint32_t bg_reserved[3];
};
/*
* Data structures used by the directory indexing feature
*
* Note: all of the multibyte integer fields are little endian.
*/
/*
* Note: dx_root_info is laid out so that if it should somehow get
* overlaid by a dirent the two low bits of the hash version will be
* zero. Therefore, the hash version mod 4 should never be 0.
* Sincerely, the paranoia department.
*/
struct ext2_dx_root_info {
uint32_t reserved_zero;
uint8_t hash_version; /* 0 now, 1 at release */
uint8_t info_length; /* 8 */
uint8_t indirect_levels;
uint8_t unused_flags;
};
#define EXT2_HASH_LEGACY 0
#define EXT2_HASH_HALF_MD4 1
#define EXT2_HASH_TEA 2
#define EXT2_HASH_FLAG_INCOMPAT 0x1
struct ext2_dx_entry {
uint32_t hash;
uint32_t block;
};
struct ext2_dx_countlimit {
uint16_t limit;
uint16_t count;
};
/*
* Macro-instructions used to manage group descriptors
*/
#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
/*
* Constants relative to the data blocks
*/
#define EXT2_NDIR_BLOCKS 12
#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
/*
* Inode flags
*/
#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
#define EXT2_UNRM_FL 0x00000002 /* Undelete */
#define EXT2_COMPR_FL 0x00000004 /* Compress file */
#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
/* Reserved for compression usage... */
#define EXT2_DIRTY_FL 0x00000100
#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
#define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */
#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
/* End compression flags --- maybe not all used */
#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
#define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */
#define EXT2_IMAGIC_FL 0x00002000
#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
#define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */
#define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */
#define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
#define EXT3_EXTENTS_FL 0x00080000 /* Inode uses extents */
#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
#define EXT2_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
#define EXT2_FL_USER_MODIFIABLE 0x000080FF /* User modifiable flags */
/*
* ioctl commands
*/
#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
/*
* Structure of an inode on the disk
*/
struct ext2_inode {
uint16_t i_mode; /* File mode */
uint16_t i_uid; /* Low 16 bits of Owner Uid */
uint32_t i_size; /* Size in bytes */
uint32_t i_atime; /* Access time */
uint32_t i_ctime; /* Creation time */
uint32_t i_mtime; /* Modification time */
uint32_t i_dtime; /* Deletion Time */
uint16_t i_gid; /* Low 16 bits of Group Id */
uint16_t i_links_count; /* Links count */
uint32_t i_blocks; /* Blocks count */
uint32_t i_flags; /* File flags */
union {
struct {
uint32_t l_i_reserved1;
} linux1;
struct {
uint32_t h_i_translator;
} hurd1;
struct {
uint32_t m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
uint32_t i_generation; /* File version (for NFS) */
uint32_t i_file_acl; /* File ACL */
uint32_t i_dir_acl; /* Directory ACL */
uint32_t i_faddr; /* Fragment address */
union {
struct {
uint8_t l_i_frag; /* Fragment number */
uint8_t l_i_fsize; /* Fragment size */
uint16_t i_pad1;
uint16_t l_i_uid_high; /* these 2 fields */
uint16_t l_i_gid_high; /* were reserved2[0] */
uint32_t l_i_reserved2;
} linux2;
struct {
uint8_t h_i_frag; /* Fragment number */
uint8_t h_i_fsize; /* Fragment size */
uint16_t h_i_mode_high;
uint16_t h_i_uid_high;
uint16_t h_i_gid_high;
uint32_t h_i_author;
} hurd2;
struct {
uint8_t m_i_frag; /* Fragment number */
uint8_t m_i_fsize; /* Fragment size */
uint16_t m_pad1;
uint32_t m_i_reserved2[2];
} masix2;
} osd2; /* OS dependent 2 */
};
/*
* Permanent part of an large inode on the disk
*/
struct ext2_inode_large {
uint16_t i_mode; /* File mode */
uint16_t i_uid; /* Low 16 bits of Owner Uid */
uint32_t i_size; /* Size in bytes */
uint32_t i_atime; /* Access time */
uint32_t i_ctime; /* Creation time */
uint32_t i_mtime; /* Modification time */
uint32_t i_dtime; /* Deletion Time */
uint16_t i_gid; /* Low 16 bits of Group Id */
uint16_t i_links_count; /* Links count */
uint32_t i_blocks; /* Blocks count */
uint32_t i_flags; /* File flags */
union {
struct {
uint32_t l_i_reserved1;
} linux1;
struct {
uint32_t h_i_translator;
} hurd1;
struct {
uint32_t m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
uint32_t i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
uint32_t i_generation; /* File version (for NFS) */
uint32_t i_file_acl; /* File ACL */
uint32_t i_dir_acl; /* Directory ACL */
uint32_t i_faddr; /* Fragment address */
union {
struct {
uint8_t l_i_frag; /* Fragment number */
uint8_t l_i_fsize; /* Fragment size */
uint16_t i_pad1;
uint16_t l_i_uid_high; /* these 2 fields */
uint16_t l_i_gid_high; /* were reserved2[0] */
uint32_t l_i_reserved2;
} linux2;
struct {
uint8_t h_i_frag; /* Fragment number */
uint8_t h_i_fsize; /* Fragment size */
uint16_t h_i_mode_high;
uint16_t h_i_uid_high;
uint16_t h_i_gid_high;
uint32_t h_i_author;
} hurd2;
struct {
uint8_t m_i_frag; /* Fragment number */
uint8_t m_i_fsize; /* Fragment size */
uint16_t m_pad1;
uint32_t m_i_reserved2[2];
} masix2;
} osd2; /* OS dependent 2 */
uint16_t i_extra_isize;
uint16_t i_pad1;
};
#define i_size_high i_dir_acl
/*
* File system states
*/
#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
#define EXT2_ERROR_FS 0x0002 /* Errors detected */
/*
* Mount flags
*/
#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */
#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
EXT2_MOUNT_##opt)
/*
* Maximal mount counts between two filesystem checks
*/
#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
/*
* Behaviour when detecting errors
*/
#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
#define EXT2_ERRORS_PANIC 3 /* Panic */
#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
/*
* Structure of the super block
*/
struct ext2_super_block {
uint32_t s_inodes_count; /* Inodes count */
uint32_t s_blocks_count; /* Blocks count */
uint32_t s_r_blocks_count; /* Reserved blocks count */
uint32_t s_free_blocks_count; /* Free blocks count */
uint32_t s_free_inodes_count; /* Free inodes count */
uint32_t s_first_data_block; /* First Data Block */
uint32_t s_log_block_size; /* Block size */
int32_t s_log_frag_size; /* Fragment size */
uint32_t s_blocks_per_group; /* # Blocks per group */
uint32_t s_frags_per_group; /* # Fragments per group */
uint32_t s_inodes_per_group; /* # Inodes per group */
uint32_t s_mtime; /* Mount time */
uint32_t s_wtime; /* Write time */
uint16_t s_mnt_count; /* Mount count */
int16_t s_max_mnt_count; /* Maximal mount count */
uint16_t s_magic; /* Magic signature */
uint16_t s_state; /* File system state */
uint16_t s_errors; /* Behaviour when detecting errors */
uint16_t s_minor_rev_level; /* minor revision level */
uint32_t s_lastcheck; /* time of last check */
uint32_t s_checkinterval; /* max. time between checks */
uint32_t s_creator_os; /* OS */
uint32_t s_rev_level; /* Revision level */
uint16_t s_def_resuid; /* Default uid for reserved blocks */
uint16_t s_def_resgid; /* Default gid for reserved blocks */
/*
* These fields are for EXT2_DYNAMIC_REV superblocks only.
*
* Note: the difference between the compatible feature set and
* the incompatible feature set is that if there is a bit set
* in the incompatible feature set that the kernel doesn't
* know about, it should refuse to mount the filesystem.
*
* e2fsck's requirements are more strict; if it doesn't know
* about a feature in either the compatible or incompatible
* feature set, it must abort and not try to meddle with
* things it doesn't understand...
*/
uint32_t s_first_ino; /* First non-reserved inode */
uint16_t s_inode_size; /* size of inode structure */
uint16_t s_block_group_nr; /* block group # of this superblock */
uint32_t s_feature_compat; /* compatible feature set */
uint32_t s_feature_incompat; /* incompatible feature set */
uint32_t s_feature_ro_compat; /* readonly-compatible feature set */
uint8_t s_uuid[16]; /* 128-bit uuid for volume */
char s_volume_name[16]; /* volume name */
char s_last_mounted[64]; /* directory where last mounted */
uint32_t s_algorithm_usage_bitmap; /* For compression */
/*
* Performance hints. Directory preallocation should only
* happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on.
*/
uint8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
uint8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
uint16_t s_reserved_gdt_blocks; /* Per group table for online growth */
/*
* Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set.
*/
uint8_t s_journal_uuid[16]; /* uuid of journal superblock */
uint32_t s_journal_inum; /* inode number of journal file */
uint32_t s_journal_dev; /* device number of journal file */
uint32_t s_last_orphan; /* start of list of inodes to delete */
uint32_t s_hash_seed[4]; /* HTREE hash seed */
uint8_t s_def_hash_version; /* Default hash version to use */
uint8_t s_jnl_backup_type; /* Default type of journal backup */
uint16_t s_reserved_word_pad;
uint32_t s_default_mount_opts;
uint32_t s_first_meta_bg; /* First metablock group */
uint32_t s_mkfs_time; /* When the filesystem was created */
uint32_t s_jnl_blocks[17]; /* Backup of the journal inode */
uint32_t s_reserved[172]; /* Padding to the end of the block */
};
/*
* Codes for operating systems
*/
#define EXT2_OS_LINUX 0
#define EXT2_OS_HURD 1
#define EXT2_OS_MASIX 2
#define EXT2_OS_FREEBSD 3
#define EXT2_OS_LITES 4
/*
* Revision levels
*/
#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
#define EXT2_GOOD_OLD_INODE_SIZE 128
/*
* Journal inode backup types
*/
#define EXT3_JNL_BACKUP_BLOCKS 1
/*
* Feature set definitions
*/
#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_compat & (mask) )
#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_ro_compat & (mask) )
#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
( EXT2_SB(sb)->s_feature_incompat & (mask) )
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
#define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010
#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
/* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */
#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
#define EXT2_FEATURE_COMPAT_SUPP 0
#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
/*
* Default values for user and/or group using reserved blocks
*/
#define EXT2_DEF_RESUID 0
#define EXT2_DEF_RESGID 0
/*
* Default mount options
*/
#define EXT2_DEFM_DEBUG 0x0001
#define EXT2_DEFM_BSDGROUPS 0x0002
#define EXT2_DEFM_XATTR_USER 0x0004
#define EXT2_DEFM_ACL 0x0008
#define EXT2_DEFM_UID16 0x0010
#define EXT3_DEFM_JMODE 0x0060
#define EXT3_DEFM_JMODE_DATA 0x0020
#define EXT3_DEFM_JMODE_ORDERED 0x0040
#define EXT3_DEFM_JMODE_WBACK 0x0060
/*
* Structure of a directory entry
*/
#define EXT2_NAME_LEN 255
struct ext2_dir_entry {
uint32_t inode; /* Inode number */
uint16_t rec_len; /* Directory entry length */
uint16_t name_len; /* Name length */
char name[EXT2_NAME_LEN]; /* File name */
};
/*
* The new version of the directory entry. Since EXT2 structures are
* stored in intel byte order, and the name_len field could never be
* bigger than 255 chars, it's safe to reclaim the extra byte for the
* file_type field.
*/
struct ext2_dir_entry_2 {
uint32_t inode; /* Inode number */
uint16_t rec_len; /* Directory entry length */
uint8_t name_len; /* Name length */
uint8_t file_type;
char name[EXT2_NAME_LEN]; /* File name */
};
/*
* Ext2 directory file types. Only the low 3 bits are used. The
* other bits are reserved for now.
*/
#define EXT2_FT_UNKNOWN 0
#define EXT2_FT_REG_FILE 1
#define EXT2_FT_DIR 2
#define EXT2_FT_CHRDEV 3
#define EXT2_FT_BLKDEV 4
#define EXT2_FT_FIFO 5
#define EXT2_FT_SOCK 6
#define EXT2_FT_SYMLINK 7
#define EXT2_FT_MAX 8
/*
* EXT2_DIR_PAD defines the directory entries boundaries
*
* NOTE: It must be a multiple of 4
*/
#define EXT2_DIR_PAD 4
#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
~EXT2_DIR_ROUND)
#endif /* _LINUX_EXT2_FS_H */
-197
View File
@@ -1,197 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* See README for additional information
*
* This file can be redistributed under the terms of the GNU Library General
* Public License
*/
#include "libbb.h"
#include "e2fs_lib.h"
#define HAVE_EXT2_IOCTLS 1
#if INT_MAX == LONG_MAX
#define IF_LONG_IS_SAME(x) x
#define IF_LONG_IS_WIDER(x)
#else
#define IF_LONG_IS_SAME(x)
#define IF_LONG_IS_WIDER(x) x
#endif
static void close_silently(int fd)
{
int e = errno;
close(fd);
errno = e;
}
/* Iterate a function on each entry of a directory */
int iterate_on_dir(const char *dir_name,
int (*func)(const char *, struct dirent *, void *),
void * private)
{
DIR *dir;
struct dirent *de, *dep;
int max_len, len;
max_len = PATH_MAX + sizeof(struct dirent);
de = xmalloc(max_len+1);
memset(de, 0, max_len+1);
dir = opendir(dir_name);
if (dir == NULL) {
free(de);
return -1;
}
while ((dep = readdir(dir))) {
len = sizeof(struct dirent);
if (len < dep->d_reclen)
len = dep->d_reclen;
if (len > max_len)
len = max_len;
memcpy(de, dep, len);
func(dir_name, de, private);
}
closedir(dir);
free(de);
return 0;
}
/* Get/set a file version on an ext2 file system */
int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version)
{
#if HAVE_EXT2_IOCTLS
int fd, r;
IF_LONG_IS_WIDER(int ver;)
fd = open(name, O_NONBLOCK);
if (fd == -1)
return -1;
if (!get_version) {
IF_LONG_IS_WIDER(
ver = (int) set_version;
r = ioctl(fd, EXT2_IOC_SETVERSION, &ver);
)
IF_LONG_IS_SAME(
r = ioctl(fd, EXT2_IOC_SETVERSION, (void*)&set_version);
)
} else {
IF_LONG_IS_WIDER(
r = ioctl(fd, EXT2_IOC_GETVERSION, &ver);
*get_version = ver;
)
IF_LONG_IS_SAME(
r = ioctl(fd, EXT2_IOC_GETVERSION, (void*)get_version);
)
}
close_silently(fd);
return r;
#else /* ! HAVE_EXT2_IOCTLS */
errno = EOPNOTSUPP;
return -1;
#endif /* ! HAVE_EXT2_IOCTLS */
}
/* Get/set a file flags on an ext2 file system */
int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags)
{
#if HAVE_EXT2_IOCTLS
struct stat buf;
int fd, r;
IF_LONG_IS_WIDER(int f;)
if (stat(name, &buf) == 0 /* stat is ok */
&& !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)
) {
goto notsupp;
}
fd = open(name, O_NONBLOCK); /* neither read nor write asked for */
if (fd == -1)
return -1;
if (!get_flags) {
IF_LONG_IS_WIDER(
f = (int) set_flags;
r = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
)
IF_LONG_IS_SAME(
r = ioctl(fd, EXT2_IOC_SETFLAGS, (void*)&set_flags);
)
} else {
IF_LONG_IS_WIDER(
r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);
*get_flags = f;
)
IF_LONG_IS_SAME(
r = ioctl(fd, EXT2_IOC_GETFLAGS, (void*)get_flags);
)
}
close_silently(fd);
return r;
notsupp:
#endif /* HAVE_EXT2_IOCTLS */
errno = EOPNOTSUPP;
return -1;
}
/* Print file attributes on an ext2 file system */
struct flags_name {
unsigned long flag;
char short_name;
const char *long_name;
};
static const struct flags_name flags_array[] = {
{ EXT2_SECRM_FL, 's', "Secure_Deletion" },
{ EXT2_UNRM_FL, 'u' , "Undelete" },
{ EXT2_SYNC_FL, 'S', "Synchronous_Updates" },
{ EXT2_DIRSYNC_FL, 'D', "Synchronous_Directory_Updates" },
{ EXT2_IMMUTABLE_FL, 'i', "Immutable" },
{ EXT2_APPEND_FL, 'a', "Append_Only" },
{ EXT2_NODUMP_FL, 'd', "No_Dump" },
{ EXT2_NOATIME_FL, 'A', "No_Atime" },
{ EXT2_COMPR_FL, 'c', "Compression_Requested" },
#ifdef ENABLE_COMPRESSION
{ EXT2_COMPRBLK_FL, 'B', "Compressed_File" },
{ EXT2_DIRTY_FL, 'Z', "Compressed_Dirty_File" },
{ EXT2_NOCOMPR_FL, 'X', "Compression_Raw_Access" },
{ EXT2_ECOMPR_FL, 'E', "Compression_Error" },
#endif
{ EXT3_JOURNAL_DATA_FL, 'j', "Journaled_Data" },
{ EXT2_INDEX_FL, 'I', "Indexed_directory" },
{ EXT2_NOTAIL_FL, 't', "No_Tailmerging" },
{ EXT2_TOPDIR_FL, 'T', "Top_of_Directory_Hierarchies" },
{ 0, '\0', NULL }
};
void print_flags(FILE *f, unsigned long flags, unsigned options)
{
const struct flags_name *fp;
if (options & PFOPT_LONG) {
int first = 1;
for (fp = flags_array; fp->short_name; fp++) {
if (flags & fp->flag) {
if (!first)
fputs(", ", f);
fputs(fp->long_name, f);
first = 0;
}
}
if (first)
fputs("---", f);
} else {
for (fp = flags_array; fp->short_name; fp++) {
char c = '-';
if (flags & fp->flag)
c = fp->short_name;
fputc(c, f);
}
}
}
-30
View File
@@ -1,30 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* See README for additional information
*
* This file can be redistributed under the terms of the GNU Library General
* Public License
*/
/* Constants and structures */
#include "e2fs_defs.h"
/* Iterate a function on each entry of a directory */
int iterate_on_dir(const char *dir_name,
int (*func)(const char *, struct dirent *, void *),
void *private);
/* Get/set a file version on an ext2 file system */
int fgetsetversion(const char *name, unsigned long *get_version, unsigned long set_version);
#define fgetversion(name, version) fgetsetversion(name, version, 0)
#define fsetversion(name, version) fgetsetversion(name, NULL, version)
/* Get/set a file flags on an ext2 file system */
int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_flags);
#define fgetflags(name, flags) fgetsetflags(name, flags, 0)
#define fsetflags(name, flags) fgetsetflags(name, NULL, flags)
/* Must be 1 for compatibility with `int long_format'. */
#define PFOPT_LONG 1
/* Print file attributes on an ext2 file system */
void print_flags(FILE *f, unsigned long flags, unsigned options);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 401 files, more files were not shown because too many files have changed in this diff. Show more