Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e50f74da70 | ||
|
|
9de318d63e | ||
|
|
be729c1d3b | ||
|
|
092fabcf1d | ||
|
|
6767af17f1 | ||
|
|
5c23f2566c | ||
|
|
7ab00a0de9 | ||
|
|
5de450237c | ||
|
|
57aeb62f83 | ||
|
|
c8e5ead03a | ||
|
|
2dbbf823ef | ||
|
|
85378cded7 | ||
|
|
932302666b | ||
|
|
69c8c699aa | ||
|
|
005c492c40 | ||
|
|
02859aaeb2 | ||
|
|
e52da5570e | ||
|
|
550bf5b4a4 | ||
|
|
4cd99e7c6c | ||
|
|
2384162f64 | ||
|
|
4700fb5bea | ||
|
|
e1603156ff | ||
|
|
f2bf20f5d5 | ||
|
|
8403b01217 | ||
|
|
d1eea8db92 | ||
|
|
413feca279 | ||
|
|
3d8d5e8ad4 | ||
|
|
7f3a2a2256 | ||
|
|
d60752f8c9 | ||
|
|
8c0708a329 | ||
|
|
305958dbd4 | ||
|
|
ec046f74a3 | ||
|
|
5711a2a4ad | ||
|
|
c1e2e005b4 | ||
|
|
6283f98283 | ||
|
|
9c5410023a | ||
|
|
2007ef5c3c | ||
|
|
4271698fea | ||
|
|
78fb6ea63a | ||
|
|
1c6c670ed4 | ||
|
|
3b650c1e7b | ||
|
|
2b48c38be6 | ||
|
|
e6b578761a | ||
|
|
a779c6d63b | ||
|
|
5fa6d1a632 | ||
|
|
12efcf3285 | ||
|
|
28b00ce6ff | ||
|
|
c919d561ad | ||
|
|
c65a7596df | ||
|
|
65db14ec50 | ||
|
|
2beb52499e | ||
|
|
d9892fa0c3 | ||
|
|
8aa7cf305b | ||
|
|
f085344d5c | ||
|
|
875297378c | ||
|
|
ca25af9b06 | ||
|
|
b5be13ccd9 | ||
|
|
2156e22853 | ||
|
|
26c423d9a8 | ||
|
|
66a781acb9 | ||
|
|
68acc0f835 | ||
|
|
7448b513c8 | ||
|
|
5b865deb3f | ||
|
|
0a4d0e8fbf | ||
|
|
b432923e29 | ||
|
|
d862717328 | ||
|
|
864d1b7a15 | ||
|
|
65c501a093 | ||
|
|
c52cbea2bb | ||
|
|
2db782bc7b | ||
|
|
729b70646c | ||
|
|
bb2fd67d0b | ||
|
|
718e228adc | ||
|
|
d077565bb2 | ||
|
|
fb52769f4a | ||
|
|
26ccd3d062 | ||
|
|
72dcbe4df7 | ||
|
|
a83e3ae172 | ||
|
|
e347583835 | ||
|
|
99e30be38b | ||
|
|
16aa7a73c4 | ||
|
|
64ed5f0d3c | ||
|
|
b27cf31003 | ||
|
|
ad27a6d326 | ||
|
|
a47fccaa63 | ||
|
|
9dc526d0f9 | ||
|
|
1ecb996fd2 | ||
|
|
d542d183e1 | ||
|
|
ad1b4d5882 | ||
|
|
70b84be9e8 | ||
|
|
159e032bf4 | ||
|
|
ae1a9e899e | ||
|
|
670c3f7822 | ||
|
|
52f2f37477 | ||
|
|
c29021e2a5 | ||
|
|
193ba408a4 | ||
|
|
35ae2ccb40 | ||
|
|
ce193f809b | ||
|
|
d840c5d139 | ||
|
|
78cfa00154 | ||
|
|
f06386ad4f | ||
|
|
51aa861843 | ||
|
|
072fc60f29 | ||
|
|
f54a487bb4 | ||
|
|
0e056f7e9e | ||
|
|
97f2f7ca7f | ||
|
|
b7ee7e1e13 | ||
|
|
c9091d8947 | ||
|
|
db31c637fa | ||
|
|
6a7cd3d4ab | ||
|
|
7db312ad26 | ||
|
|
0fabedf085 | ||
|
|
d90899206d | ||
|
|
aeb11a9496 | ||
|
|
2204472497 | ||
|
|
e545bf6723 | ||
|
|
314742747d | ||
|
|
d291c2fdd5 | ||
|
|
fc3e40ee81 | ||
|
|
7f4a49a96c | ||
|
|
97c6491b4e | ||
|
|
c4603fb09a | ||
|
|
b878121e76 | ||
|
|
9a595bb36d | ||
|
|
523006798c | ||
|
|
417622cc2e | ||
|
|
549deab5ab | ||
|
|
ad88bdee0c | ||
|
|
7e4ed267b6 | ||
|
|
3df47f9cbb | ||
|
|
eb6b48ba74 | ||
|
|
d68d1fbd6c | ||
|
|
e0a4e107aa | ||
|
|
1285aa62f9 | ||
|
|
a818777d42 | ||
|
|
7ca5c51cc8 | ||
|
|
b2cca32a37 | ||
|
|
17b16223f3 | ||
|
|
bdb540e04f | ||
|
|
778efe37ee | ||
|
|
f23e3ec529 | ||
|
|
b4059f6309 | ||
|
|
c77a58fb2d | ||
|
|
4d8ddb810d | ||
|
|
bbd53216f8 | ||
|
|
93b98ff572 | ||
|
|
cee59053dc | ||
|
|
de5edadee2 | ||
|
|
7d86384b24 | ||
|
|
61d6ae244a | ||
|
|
ad795510d9 | ||
|
|
bd77e9d609 | ||
|
|
73327a048b | ||
|
|
0a0acb55db | ||
|
|
63f4d32c98 | ||
|
|
71a5b67ba0 | ||
|
|
f7466e4776 | ||
|
|
a90490fb69 | ||
|
|
e0ddb65cb2 | ||
|
|
7b729edd33 | ||
|
|
86a7f18f21 | ||
|
|
1186894f77 | ||
|
|
9472e8a86f | ||
|
|
379e8e81af | ||
|
|
1850d5ec0e | ||
|
|
4d15068d83 | ||
|
|
911db16229 | ||
|
|
8893023ba2 | ||
|
|
92edab1aa6 | ||
|
|
6d8ea1d50e | ||
|
|
6ca03f2dd8 | ||
|
|
75a76269ba | ||
|
|
6798564b9e | ||
|
|
4a08e82d44 | ||
|
|
49acc1a761 | ||
|
|
8ec1ff350c | ||
|
|
53e9c51ade | ||
|
|
8dff01d06a | ||
|
|
936c8809ca | ||
|
|
748fb60f27 | ||
|
|
fe8b5802ba | ||
|
|
7b434a67dc | ||
|
|
3c31b092ac | ||
|
|
2ec4f44225 | ||
|
|
3aef814c0b | ||
|
|
7db2a7c20e | ||
|
|
dac8d80f77 | ||
|
|
fa535f3e48 | ||
|
|
1eafd44947 | ||
|
|
c5beaa08eb | ||
|
|
a88db5c1a9 | ||
|
|
cb6a112f09 | ||
|
|
d7bfee1edb | ||
|
|
54e9585e10 | ||
|
|
0cb981c5e2 | ||
|
|
70e30e8eec | ||
|
|
8e92df15b5 | ||
|
|
402afe1cc6 | ||
|
|
1fd844267c | ||
|
|
622a7aab2c | ||
|
|
8c06bc6ba1 | ||
|
|
23cfaab47d | ||
|
|
68c048fb23 | ||
|
|
782ee2aa0e | ||
|
|
a03195941b | ||
|
|
f22a838aed | ||
|
|
7e66102f76 | ||
|
|
a14fa79592 | ||
|
|
3c5d133c7d | ||
|
|
a75dcd4353 | ||
|
|
09020b1aa8 | ||
|
|
b62d4d9d57 | ||
|
|
a977778893 | ||
|
|
8e74adab01 | ||
|
|
f7f70bf1b3 | ||
|
|
7f7ade1964 | ||
|
|
5104645cf8 | ||
|
|
07fa09a952 | ||
|
|
1cbe93cf4e | ||
|
|
08f9ffc3f7 | ||
|
|
8c05a74f7e | ||
|
|
ff3f3accc6 | ||
|
|
936c401077 | ||
|
|
64b744997e | ||
|
|
50a6d86520 | ||
|
|
cc70b6f8b6 | ||
|
|
86031a5ffd | ||
|
|
9de69c024c | ||
|
|
76b2262b9b | ||
|
|
e998b08f11 | ||
|
|
1b6715345f | ||
|
|
3c75b1c34e | ||
|
|
39f017293a | ||
|
|
70f4320b40 | ||
|
|
e5213cee38 | ||
|
|
08364dab75 | ||
|
|
e5cae08f12 | ||
|
|
e76957708b | ||
|
|
1ec49732e2 | ||
|
|
75a1403f26 | ||
|
|
da9212667c | ||
|
|
08b90a9d10 | ||
|
|
c5d4a04e45 | ||
|
|
4bf88d9094 | ||
|
|
db4d1051ca | ||
|
|
5acf1346b4 | ||
|
|
12fc869560 | ||
|
|
402451aa19 | ||
|
|
f9936676bb | ||
|
|
134c53098b | ||
|
|
20c0a16334 | ||
|
|
5e62a3d016 | ||
|
|
9dca6acaac | ||
|
|
8d547aca75 | ||
|
|
31d6734457 | ||
|
|
908b6e5dfd | ||
|
|
1da09cfacf | ||
|
|
78854520eb | ||
|
|
6c19d35f68 | ||
|
|
c76236fd7d | ||
|
|
8074a6ca4d | ||
|
|
b9965077e5 |
No files matched your search
@@ -42,3 +42,11 @@ core
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
|
||||
#
|
||||
# cscope output
|
||||
#
|
||||
cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 23
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 24
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -552,7 +552,7 @@ export INSTALL_PATH ?= /boot
|
||||
#
|
||||
# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
|
||||
# relocations required by build roots. This is not defined in the
|
||||
# makefile but the arguement can be passed to make if needed.
|
||||
# makefile but the argument can be passed to make if needed.
|
||||
#
|
||||
|
||||
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
|
||||
@@ -1165,24 +1165,7 @@ endif
|
||||
ALLSOURCE_ARCHS := $(ARCH)
|
||||
|
||||
define all-sources
|
||||
( find $(__srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name include -o -name arch \) -prune -o \
|
||||
-name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLSOURCE_ARCHS) ; do \
|
||||
find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
find $(__srctree)include $(RCS_FIND_IGNORE) \
|
||||
\( -name config -o -name 'asm-*' \) -prune \
|
||||
-o -name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLINCLUDE_ARCHS) ; do \
|
||||
find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print )
|
||||
( find -regex '.*\.[ch]$$' )
|
||||
endef
|
||||
|
||||
quiet_cmd_cscope-file = FILELST cscope.files
|
||||
|
||||
@@ -28,6 +28,10 @@ ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_FEATURE_INDIVIDUAL),y)
|
||||
INSTALL_OPTS:= --binaries
|
||||
LIBBUSYBOX_SONAME:= 0_lib/libbusybox.so.$(BB_VER)
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
|
||||
+16
-9
@@ -56,6 +56,9 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
|
||||
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
|
||||
CFLAGS += $(call cc-option,-fno-unwind-tables,)
|
||||
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
|
||||
# No automatic printf->puts,putchar conversions
|
||||
# (try disabling this and comparing assembly, it's instructive)
|
||||
CFLAGS += $(call cc-option,-fno-builtin-printf,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
@@ -126,15 +129,19 @@ else
|
||||
LDLIBS += m
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
# However, on *other platforms* it fails when some of those flags
|
||||
# given needlessly. On some systems, crypt needs pthread.
|
||||
#
|
||||
# I even had a system where a runtime test for pthread
|
||||
# (similar to CRYPT_AVAILABLE test above) was not reliable.
|
||||
#
|
||||
# Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
|
||||
# Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
# libpam uses libpthread, so for static builds busybox must be linked to
|
||||
# libpthread. On some platforms that requires an explicit -lpthread, so
|
||||
# it should be in LDLIBS. For non-static builds, scripts/trylink will
|
||||
# take care of removing -lpthread if possible. (Not bothering to check
|
||||
# CONFIG_STATIC because even in a non-static build it could be that the
|
||||
# only libpam available is libpam.a, so -lpthread could still be
|
||||
# needed.)
|
||||
LDLIBS += pam pam_misc pthread
|
||||
LDLIBS += pam pam_misc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
@@ -163,7 +170,7 @@ SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDFLAGS),)
|
||||
EXTRA_LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ Supported hardware:
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
SH3/4/5, Sparc, and v850e. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
|
||||
+24
-2
@@ -5,19 +5,26 @@ export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
sharedlib_dir="0_lib"
|
||||
|
||||
linkopts=""
|
||||
scriptwrapper="n"
|
||||
binaries="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--binaries) binaries="y";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
@@ -40,8 +47,9 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
for i in $DO_INSTALL_LIBS; do
|
||||
rm -f "$prefix/$libdir/$i" || exit 1
|
||||
if [ -f "$i" ]; then
|
||||
echo " Installing $i to the target at $prefix/$libdir/"
|
||||
cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/$i" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -68,6 +76,7 @@ install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
||||
|
||||
for i in $h; do
|
||||
appdir=`dirname "$i"`
|
||||
app=`basename "$i"`
|
||||
mkdir -p "$prefix/$appdir" || exit 1
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
@@ -78,6 +87,19 @@ for i in $h; do
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ "$binaries" = "y" ]; then
|
||||
# Copy the binary over rather
|
||||
if [ -e $sharedlib_dir/$app ]; then
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
|
||||
else
|
||||
echo " $prefix/$i already exists"
|
||||
fi
|
||||
else
|
||||
echo "Error: Could not find $sharedlib_dir/$app"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
|
||||
@@ -20,6 +20,7 @@ exec >"$target.$$"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
@@ -27,6 +28,13 @@ echo '#define UNPACKED_USAGE "" \'
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
# "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
|
||||
#0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
|
||||
# 000010 000010 026533 063144 020135 026533 020143 047503
|
||||
#0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
|
||||
# 043116 044504 056522 055440 066055 046040 043517 044506
|
||||
#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
|
||||
# 042514 020135 026533 020141 041501 044524 047117 044506
|
||||
|
||||
echo '#define PACKED_USAGE \'
|
||||
## Breaks on big-endian systems!
|
||||
@@ -40,6 +48,7 @@ echo '#define PACKED_USAGE \'
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/$/ \\/'
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
|
||||
@@ -257,7 +257,6 @@ static NOINLINE int cpio_o(void)
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
|
||||
+15
-4
@@ -1151,13 +1151,13 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
if (result && number_of_alternatives == 0) {
|
||||
if (root_of_alternatives)
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, "
|
||||
"which cannot be satisfied",
|
||||
"package %s %sdepends on %s, which %s",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[root_of_alternatives->name]);
|
||||
name_hashtable[root_of_alternatives->name],
|
||||
"cannot be satisfied");
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, which %s\n",
|
||||
"package %s %sdepends on %s, which %s",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[package_edge->name],
|
||||
@@ -1472,12 +1472,16 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
@@ -1492,12 +1496,19 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
|
||||
@@ -70,6 +70,8 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
@@ -82,6 +84,10 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
+112
-24
@@ -62,14 +62,27 @@ aa: 85.1% -- replaced with aa.gz
|
||||
//config: 1: larger buffers, larger hash-tables
|
||||
//config: 2: larger buffers, largest hash-tables
|
||||
//config: Larger models may give slightly better compression
|
||||
//config:
|
||||
//config:config FEATURE_GZIP_LEVELS
|
||||
//config: bool "Enable compression levels"
|
||||
//config: default n
|
||||
//config: depends on GZIP
|
||||
//config: help
|
||||
//config: Enable support for compression levels 4-9. The default level
|
||||
//config: is 6. If levels 1-3 are specified, 4 is used.
|
||||
//config: If this option is not selected, -N options are ignored and -9
|
||||
//config: is used.
|
||||
|
||||
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
|
||||
|
||||
//usage:#define gzip_trivial_usage
|
||||
//usage: "[-cfd] [FILE]..."
|
||||
//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
|
||||
//usage:#define gzip_full_usage "\n\n"
|
||||
//usage: "Compress FILEs (or stdin)\n"
|
||||
//usage: IF_FEATURE_GZIP_LEVELS(
|
||||
//usage: "\n -1..9 Compression level"
|
||||
//usage: )
|
||||
//usage: "\n -d Decompress"
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
@@ -252,6 +265,8 @@ enum {
|
||||
* input file length plus MIN_LOOKAHEAD.
|
||||
*/
|
||||
|
||||
#ifndef ENABLE_FEATURE_GZIP_LEVELS
|
||||
|
||||
max_chain_length = 4096,
|
||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||
* A higher limit improves compression ratio but degrades the speed.
|
||||
@@ -283,11 +298,23 @@ enum {
|
||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||
* meaning.
|
||||
*/
|
||||
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
|
||||
};
|
||||
|
||||
|
||||
struct globals {
|
||||
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
unsigned max_chain_length;
|
||||
unsigned max_lazy_match;
|
||||
unsigned good_match;
|
||||
unsigned nice_match;
|
||||
#define max_chain_length (G1.max_chain_length)
|
||||
#define max_lazy_match (G1.max_lazy_match)
|
||||
#define good_match (G1.good_match)
|
||||
#define nice_match (G1.nice_match)
|
||||
#endif
|
||||
|
||||
lng block_start;
|
||||
|
||||
/* window position at the beginning of the current output block. Gets
|
||||
@@ -417,19 +444,46 @@ static void flush_outbuf(void)
|
||||
#define put_8bit(c) \
|
||||
do { \
|
||||
G1.outbuf[G1.outcnt++] = (c); \
|
||||
if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \
|
||||
if (G1.outcnt == OUTBUFSIZ) \
|
||||
flush_outbuf(); \
|
||||
} while (0)
|
||||
|
||||
/* Output a 16 bit value, lsb first */
|
||||
static void put_16bit(ush w)
|
||||
{
|
||||
if (G1.outcnt < OUTBUFSIZ - 2) {
|
||||
G1.outbuf[G1.outcnt++] = w;
|
||||
G1.outbuf[G1.outcnt++] = w >> 8;
|
||||
} else {
|
||||
put_8bit(w);
|
||||
put_8bit(w >> 8);
|
||||
/* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
|
||||
* (probably because of fear of aliasing with G1.outbuf[]
|
||||
* stores), do it explicitly:
|
||||
*/
|
||||
unsigned outcnt = G1.outcnt;
|
||||
uch *dst = &G1.outbuf[outcnt];
|
||||
|
||||
#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
ush *dst16 = (void*) dst;
|
||||
*dst16 = w; /* unalinged LSB 16-bit store */
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
#else
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
dst[1] = w;
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Slowpath: we will need to do flush_outbuf() */
|
||||
G1.outcnt = ++outcnt;
|
||||
if (outcnt == OUTBUFSIZ)
|
||||
flush_outbuf();
|
||||
put_8bit(w);
|
||||
}
|
||||
|
||||
static void put_32bit(ulg n)
|
||||
@@ -1318,7 +1372,6 @@ static void build_tree(tree_desc * desc)
|
||||
/* and insert the new node in the heap */
|
||||
G2.heap[SMALLEST] = node++;
|
||||
pqdownheap(tree, SMALLEST);
|
||||
|
||||
} while (G2.heap_len >= 2);
|
||||
|
||||
G2.heap[--G2.heap_max] = G2.heap[SMALLEST];
|
||||
@@ -1666,7 +1719,6 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 0); /* without header */
|
||||
G2.compressed_len = stored_len << 3;
|
||||
|
||||
} else if (stored_len + 4 <= opt_lenb && buf != NULL) {
|
||||
/* 4: two words for the lengths */
|
||||
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
|
||||
@@ -1680,7 +1732,6 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
G2.compressed_len += (stored_len + 4) << 3;
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 1); /* with header */
|
||||
|
||||
} else if (static_lenb == opt_lenb) {
|
||||
send_bits((STATIC_TREES << 1) + eof, 3);
|
||||
compress_block((ct_data *) G2.static_ltree, (ct_data *) G2.static_dtree);
|
||||
@@ -2007,7 +2058,7 @@ static void ct_init(void)
|
||||
* IN assertions: the input and output buffers are cleared.
|
||||
*/
|
||||
|
||||
static void zip(ulg time_stamp)
|
||||
static void zip(void)
|
||||
{
|
||||
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
|
||||
|
||||
@@ -2018,7 +2069,7 @@ static void zip(ulg time_stamp)
|
||||
/* compression method: 8 (DEFLATED) */
|
||||
/* general flags: 0 */
|
||||
put_32bit(0x00088b1f);
|
||||
put_32bit(time_stamp);
|
||||
put_32bit(0); /* Unix timestamp */
|
||||
|
||||
/* Write deflated file to zip file */
|
||||
G1.crc = ~0;
|
||||
@@ -2044,8 +2095,6 @@ static void zip(ulg time_stamp)
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
/* Clear input and output buffers */
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
@@ -2077,9 +2126,23 @@ IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED
|
||||
G2.bl_desc.max_length = MAX_BL_BITS;
|
||||
//G2.bl_desc.max_code = 0;
|
||||
|
||||
#if 0
|
||||
/* Saving of timestamp is disabled. Why?
|
||||
* - it is not Y2038-safe.
|
||||
* - some people want deterministic results
|
||||
* (normally they'd use -n, but our -n is a nop).
|
||||
* - it's bloat.
|
||||
* Per RFC 1952, gzfile.time=0 is "no timestamp".
|
||||
* If users will demand this to be reinstated,
|
||||
* implement -n "don't save timestamp".
|
||||
*/
|
||||
struct stat s;
|
||||
s.st_ctime = 0;
|
||||
fstat(STDIN_FILENO, &s);
|
||||
zip(s.st_ctime);
|
||||
#else
|
||||
zip();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2122,24 +2185,48 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
{
|
||||
unsigned opt;
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
static const struct {
|
||||
uint8_t good;
|
||||
uint8_t chain_shift;
|
||||
uint8_t lazy2;
|
||||
uint8_t nice2;
|
||||
} gzip_level_config[6] = {
|
||||
{4, 4, 4/2, 16/2}, /* Level 4 */
|
||||
{8, 5, 16/2, 32/2}, /* Level 5 */
|
||||
{8, 7, 16/2, 128/2}, /* Level 6 */
|
||||
{8, 8, 32/2, 128/2}, /* Level 7 */
|
||||
{32, 10, 128/2, 258/2}, /* Level 8 */
|
||||
{32, 12, 258/2, 258/2}, /* Level 9 */
|
||||
};
|
||||
#endif
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
applet_long_options = gzip_longopts;
|
||||
#endif
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
return gunzip_main(argc, argv);
|
||||
#endif
|
||||
option_mask32 &= 0x7; /* ignore -q, -0..9 */
|
||||
//if (opt & 0x1) // -c
|
||||
//if (opt & 0x2) // -f
|
||||
//if (opt & 0x4) // -v
|
||||
argv += optind;
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
|
||||
if (opt == 0)
|
||||
opt = 1 << 6; /* default: 6 */
|
||||
/* Map 1..3 to 4 */
|
||||
if (opt & 0x7)
|
||||
opt |= 1 << 4;
|
||||
opt = ffs(opt >> 3);
|
||||
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
|
||||
good_match = gzip_level_config[opt].good;
|
||||
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
|
||||
nice_match = gzip_level_config[opt].nice2 * 2;
|
||||
#endif
|
||||
option_mask32 &= 0x7; /* retain only -cfv */
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
@@ -2151,5 +2238,6 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Initialize the CRC32 table */
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, pack_gzip, append_ext, "gz");
|
||||
}
|
||||
@@ -30,11 +30,13 @@ COMMON_FILES:= \
|
||||
DPKG_FILES:= \
|
||||
unpack_ar_archive.o \
|
||||
filter_accept_list_reassign.o \
|
||||
unsafe_prefix.o \
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
get_header_tar_bz2.o \
|
||||
get_header_tar_lzma.o \
|
||||
get_header_tar_xz.o \
|
||||
|
||||
INSERT
|
||||
|
||||
@@ -43,7 +45,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
@@ -52,7 +54,7 @@ lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
|
||||
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
|
||||
@@ -385,7 +385,6 @@ void sendMTFValues(EState* s)
|
||||
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("'%s' returned status %d",
|
||||
archive_handle->tar__to_command, WEXITSTATUS(status));
|
||||
if (WIFSIGNALED(status))
|
||||
bb_error_msg_and_die("'%s' terminated on signal %d",
|
||||
bb_error_msg_and_die("'%s' terminated by signal %d",
|
||||
archive_handle->tar__to_command, WTERMSIG(status));
|
||||
|
||||
if (!BB_MMU) {
|
||||
|
||||
@@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
unsigned i; /* counter, current code */
|
||||
unsigned j; /* counter */
|
||||
int k; /* number of bits in current code */
|
||||
unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
const unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
huft_t *q; /* points to current table */
|
||||
huft_t r; /* table entry for structure assignment */
|
||||
huft_t *u[BMAX]; /* table stack */
|
||||
unsigned v[N_MAX]; /* values in order of bit length */
|
||||
unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */
|
||||
int ws[BMAX + 1]; /* bits decoded stack */
|
||||
int w; /* bits decoded */
|
||||
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
|
||||
@@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset(c, 0, sizeof(c));
|
||||
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
|
||||
p = b;
|
||||
i = n;
|
||||
do {
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
@@ -364,8 +364,12 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
*xp++ = j;
|
||||
}
|
||||
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = (unsigned *) b;
|
||||
/* Make a table of values in order of bit lengths.
|
||||
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
|
||||
* In particular, last v[i] is never filled and must not be accessed.
|
||||
*/
|
||||
memset(v, 0xff, sizeof(v));
|
||||
p = b;
|
||||
i = 0;
|
||||
do {
|
||||
j = *p++;
|
||||
@@ -432,7 +436,9 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* set up table entry in r */
|
||||
r.b = (unsigned char) (k - w);
|
||||
if (p >= v + n) {
|
||||
if (/*p >= v + n || -- redundant, caught by the second check: */
|
||||
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
|
||||
) {
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
} else if (*p < s) {
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
@@ -517,8 +523,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99)
|
||||
abort_unzip(PASS_STATE_ONLY);;
|
||||
if (e == 99) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -554,8 +561,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99)
|
||||
if (e == 99) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -821,8 +829,9 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
|
||||
b_dynamic >>= 4;
|
||||
k_dynamic -= 4;
|
||||
if (nl > 286 || nd > 30)
|
||||
if (nl > 286 || nd > 30) {
|
||||
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
|
||||
}
|
||||
|
||||
/* read in bit-length-code lengths */
|
||||
for (j = 0; j < nb; j++) {
|
||||
@@ -903,12 +912,14 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
bl = lbits;
|
||||
|
||||
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
|
||||
if (i != 0)
|
||||
if (i != 0) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bd = dbits;
|
||||
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
|
||||
if (i != 0)
|
||||
if (i != 0) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
|
||||
/* set up data for inflate_codes() */
|
||||
inflate_codes_setup(PASS_STATE bl, bd);
|
||||
@@ -996,6 +1007,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
error_msg = "corrupted data";
|
||||
if (setjmp(error_jmp)) {
|
||||
/* Error from deep inside zip machinery */
|
||||
bb_error_msg(error_msg);
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
@@ -297,7 +297,6 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* Remember previous code. */
|
||||
oldcode = incode;
|
||||
}
|
||||
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
|
||||
@@ -28,6 +28,10 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
name_ptr++;
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
if (strcmp(name_ptr, "tar") == 0) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
@@ -46,6 +50,12 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& strcmp(name_ptr, "xz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (strncmp(&cpio_header[0], "07070", 5) != 0
|
||||
if (!is_prefixed_with(&cpio_header[0], "07070")
|
||||
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
|
||||
) {
|
||||
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
|
||||
|
||||
@@ -17,36 +17,6 @@
|
||||
typedef uint32_t aliased_uint32_t FIX_ALIASING;
|
||||
typedef off_t aliased_off_t FIX_ALIASING;
|
||||
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (strncmp(cp, "/../"+1, 3) == 0) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
@@ -135,7 +105,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
value = end + 1;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
|
||||
if (!global && is_prefixed_with(value, "path=")) {
|
||||
value += sizeof("path=") - 1;
|
||||
free(archive_handle->tar__longname);
|
||||
archive_handle->tar__longname = xstrdup(value);
|
||||
@@ -148,7 +118,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
* This is what Red Hat's patched version of tar uses.
|
||||
*/
|
||||
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
|
||||
if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
|
||||
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
|
||||
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
|
||||
free(archive_handle->tar__sctx[global]);
|
||||
archive_handle->tar__sctx[global] = xstrdup(value);
|
||||
@@ -232,7 +202,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
if (strncmp(tar.magic, "ustar", 5) != 0
|
||||
if (!is_prefixed_with(tar.magic, "ustar")
|
||||
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
) {
|
||||
@@ -380,7 +350,14 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
goto size0;
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
|
||||
case 'L':
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(p_longname);
|
||||
@@ -400,18 +377,17 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += file_header->size;
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again;
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive */
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
/*
|
||||
* case 'S': // Sparse file
|
||||
* Was seen in the wild. Not supported (yet?).
|
||||
* See https://www.gnu.org/software/tar/manual/html_section/tar_92.html
|
||||
* for the format. (An "Old GNU Format" was seen, not PAX formats).
|
||||
*/
|
||||
// case 'D': /* GNU dump dir */
|
||||
// case 'M': /* Continuation of multi volume archive */
|
||||
// case 'N': /* Old GNU for names > 100 characters */
|
||||
// case 'V': /* Volume header */
|
||||
#endif
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
}
|
||||
skip_ext_hdr:
|
||||
{
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -71,7 +71,6 @@ typedef struct {
|
||||
uint8_t *out;
|
||||
|
||||
unsigned r1_lit;
|
||||
|
||||
} lzo1x_999_t;
|
||||
|
||||
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
|
||||
|
||||
@@ -185,6 +185,13 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_Z
|
||||
&& magic.b16[0] == COMPRESS_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_Z_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
|
||||
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
char magic[7];
|
||||
|
||||
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
|
||||
if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {
|
||||
if (!is_prefixed_with(magic, AR_MAGIC)) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += AR_MAGIC_LEN;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (is_prefixed_with(cp, "/../"+1)) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
@@ -995,10 +995,8 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
s->lzma2.need_props = false;
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_PROPERTIES;
|
||||
|
||||
} else if (s->lzma2.need_props) {
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
} else {
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_LZMA_PREPARE;
|
||||
@@ -1080,7 +1078,6 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
|
||||
rc_reset(&s->rc);
|
||||
s->lzma2.sequence = SEQ_CONTROL;
|
||||
|
||||
} else if (b->out_pos == b->out_size
|
||||
|| (b->in_pos == b->in_size
|
||||
&& s->temp.size
|
||||
|
||||
@@ -353,7 +353,6 @@ static enum xz_ret XZ_FUNC crc32_validate(struct xz_dec *s, struct xz_buf *b)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->pos += 8;
|
||||
|
||||
} while (s->pos < 32);
|
||||
|
||||
s->crc32 = 0;
|
||||
@@ -753,7 +752,6 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_run(struct xz_dec *s, struct xz_buf *b)
|
||||
b->in_pos = in_start;
|
||||
b->out_pos = out_start;
|
||||
}
|
||||
|
||||
} else if (ret == XZ_OK && in_start == b->in_pos
|
||||
&& out_start == b->out_pos) {
|
||||
if (s->allow_buf_error)
|
||||
|
||||
+24
-13
@@ -596,14 +596,17 @@ int unzip_main(int argc, char **argv)
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
} else {
|
||||
if (listing) {
|
||||
/* List entry */
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
@@ -639,9 +642,11 @@ int unzip_main(int argc, char **argv)
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
} else if (dst_fd == STDOUT_FILENO) {
|
||||
/* Extracting to STDOUT */
|
||||
i = -1;
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
} else if (last_char_is(dst_fn, '/')) {
|
||||
/* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
@@ -655,22 +660,26 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "directory");
|
||||
}
|
||||
}
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract file */
|
||||
} else {
|
||||
/* Extract file */
|
||||
check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
/* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
} else { /* File already exists */
|
||||
} else {
|
||||
/* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
} else if (S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is regular file */
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} else {
|
||||
@@ -678,8 +687,10 @@ int unzip_main(int argc, char **argv)
|
||||
my_fgets80(key_buf);
|
||||
i = key_buf[0];
|
||||
}
|
||||
} else { /* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn);
|
||||
} else {
|
||||
/* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "regular file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+114
-71
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.21.0.git
|
||||
# Mon May 28 21:51:18 2012
|
||||
# Busybox version: 1.24.0.git
|
||||
# Fri Sep 18 20:39:29 2015
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -36,12 +36,15 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
|
||||
# CONFIG_UNICODE_BIDI_SUPPORT is not set
|
||||
# CONFIG_UNICODE_NEUTRAL_TABLE is not set
|
||||
# CONFIG_UNICODE_PRESERVE_BROKEN is not set
|
||||
# CONFIG_PAM is not set
|
||||
CONFIG_FEATURE_USE_SENDFILE=y
|
||||
CONFIG_LONG_OPTS=y
|
||||
# CONFIG_FEATURE_DEVPTS is not set
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
# CONFIG_FEATURE_UTMP is not set
|
||||
# CONFIG_FEATURE_WTMP is not set
|
||||
# CONFIG_FEATURE_PIDFILE is not set
|
||||
CONFIG_PID_FILE_PATH=""
|
||||
# CONFIG_FEATURE_SUID is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
@@ -63,7 +66,7 @@ CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_LFS is not set
|
||||
CONFIG_CROSS_COMPILER_PREFIX="arm-linux-androideabi-"
|
||||
CONFIG_SYSROOT="/opt/android-ndk/platforms/android-9/arch-arm"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers -fuse-ld=bfd"
|
||||
CONFIG_EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o"
|
||||
CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
|
||||
@@ -72,6 +75,7 @@ CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
# CONFIG_DEBUG_PESSIMIZE is not set
|
||||
# CONFIG_UNIT_TEST is not set
|
||||
# CONFIG_WERROR is not set
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
@@ -96,6 +100,7 @@ CONFIG_PREFIX="./_install"
|
||||
# CONFIG_FEATURE_RTMINMAX is not set
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
CONFIG_SHA3_SMALL=1
|
||||
# CONFIG_FEATURE_FAST_TOP is not set
|
||||
# CONFIG_FEATURE_ETC_NETWORKS is not set
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
@@ -133,7 +138,14 @@ CONFIG_FEATURE_SEAMLESS_Z=y
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_FEATURE_AR_CREATE=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
@@ -141,14 +153,14 @@ CONFIG_FEATURE_CPIO_P=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_GZIP=y
|
||||
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
|
||||
CONFIG_GZIP_FAST=0
|
||||
# CONFIG_FEATURE_GZIP_LEVELS is not set
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
CONFIG_FEATURE_TAR_AUTODETECT=y
|
||||
@@ -161,12 +173,6 @@ CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
# CONFIG_FEATURE_TAR_SELINUX is not set
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_UNZIP=y
|
||||
|
||||
#
|
||||
@@ -178,16 +184,27 @@ CONFIG_CAT=y
|
||||
# CONFIG_FEATURE_DATE_ISOFMT is not set
|
||||
# CONFIG_FEATURE_DATE_NANO is not set
|
||||
# CONFIG_FEATURE_DATE_COMPAT is not set
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_FEATURE_DD_STATUS=y
|
||||
# CONFIG_HOSTID is not set
|
||||
# CONFIG_ID is not set
|
||||
# CONFIG_GROUPS is not set
|
||||
CONFIG_SHUF=y
|
||||
CONFIG_SYNC=y
|
||||
# CONFIG_FEATURE_SYNC_FANCY is not set
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_UNLINK=y
|
||||
CONFIG_BASE64=y
|
||||
# CONFIG_WHO is not set
|
||||
# CONFIG_USERS is not set
|
||||
@@ -203,10 +220,6 @@ CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
# CONFIG_FEATURE_CP_LONG_OPTIONS is not set
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
# CONFIG_DF is not set
|
||||
# CONFIG_FEATURE_DF_FANCY is not set
|
||||
CONFIG_DIRNAME=y
|
||||
@@ -263,6 +276,7 @@ CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SHA3SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_FEATURE_FLOAT_SLEEP=y
|
||||
@@ -274,7 +288,6 @@ CONFIG_FEATURE_SPLIT_FANCY=y
|
||||
# CONFIG_FEATURE_STAT_FORMAT is not set
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
@@ -283,6 +296,7 @@ CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
|
||||
CONFIG_TRUE=y
|
||||
# CONFIG_TTY is not set
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNAME_OSNAME="GNU/Linux"
|
||||
CONFIG_UNEXPAND=y
|
||||
# CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS is not set
|
||||
CONFIG_UNIQ=y
|
||||
@@ -294,6 +308,11 @@ CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_YES=y
|
||||
|
||||
#
|
||||
# Common options
|
||||
#
|
||||
CONFIG_FEATURE_VERBOSE=y
|
||||
|
||||
#
|
||||
# Common options for cp and mv
|
||||
#
|
||||
@@ -310,7 +329,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -356,7 +375,16 @@ CONFIG_WHICH=y
|
||||
#
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_FEATURE_AWK_GNU_EXTENSIONS=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_MAX_LEN=4096
|
||||
CONFIG_FEATURE_VI_8BIT=y
|
||||
@@ -371,14 +399,9 @@ CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_ASK_TERMINAL=y
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_FEATURE_VI_UNDO=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
@@ -395,6 +418,7 @@ CONFIG_FEATURE_FIND_MAXDEPTH=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
CONFIG_FEATURE_FIND_EXEC_PLUS=y
|
||||
CONFIG_FEATURE_FIND_USER=y
|
||||
CONFIG_FEATURE_FIND_GROUP=y
|
||||
CONFIG_FEATURE_FIND_NOT=y
|
||||
@@ -416,6 +440,7 @@ CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y
|
||||
|
||||
#
|
||||
# Init Utilities
|
||||
@@ -447,11 +472,12 @@ CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
# CONFIG_FEATURE_SHADOWPASSWDS is not set
|
||||
# CONFIG_USE_BB_PWD_GRP is not set
|
||||
# CONFIG_USE_BB_SHADOW is not set
|
||||
# CONFIG_USE_BB_CRYPT is not set
|
||||
# CONFIG_USE_BB_CRYPT_SHA is not set
|
||||
CONFIG_USE_BB_CRYPT=y
|
||||
CONFIG_USE_BB_CRYPT_SHA=y
|
||||
# CONFIG_ADDUSER is not set
|
||||
# CONFIG_FEATURE_ADDUSER_LONG_OPTIONS is not set
|
||||
# CONFIG_FEATURE_CHECK_NAMES is not set
|
||||
CONFIG_LAST_ID=0
|
||||
CONFIG_FIRST_SYSTEM_ID=0
|
||||
CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_ADDGROUP is not set
|
||||
@@ -463,7 +489,6 @@ CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_GETTY is not set
|
||||
# CONFIG_LOGIN is not set
|
||||
# CONFIG_LOGIN_SESSION_AS_CHILD is not set
|
||||
# CONFIG_PAM is not set
|
||||
# CONFIG_LOGIN_SCRIPTS is not set
|
||||
# CONFIG_FEATURE_NOLOGIN is not set
|
||||
# CONFIG_FEATURE_SECURETTY is not set
|
||||
@@ -521,13 +546,26 @@ CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
|
||||
# Linux System Utilities
|
||||
#
|
||||
CONFIG_BLOCKDEV=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_FATATTR=y
|
||||
CONFIG_FSTRIM=y
|
||||
# CONFIG_MDEV is not set
|
||||
# CONFIG_FEATURE_MDEV_CONF is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
|
||||
# CONFIG_FEATURE_MDEV_EXEC is not set
|
||||
# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_FEATURE_MOUNT_OTHERTAB is not set
|
||||
CONFIG_REV=y
|
||||
CONFIG_UEVENT=y
|
||||
# CONFIG_ACPID is not set
|
||||
# CONFIG_FEATURE_ACPID_COMPAT is not set
|
||||
CONFIG_BLKID=y
|
||||
@@ -573,15 +611,6 @@ CONFIG_LSUSB=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_UUID=y
|
||||
CONFIG_MORE=y
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_PIVOT_ROOT is not set
|
||||
# CONFIG_RDATE is not set
|
||||
CONFIG_RDEV=y
|
||||
@@ -591,6 +620,7 @@ CONFIG_SCRIPT=y
|
||||
CONFIG_SCRIPTREPLAY=y
|
||||
# CONFIG_SETARCH is not set
|
||||
# CONFIG_SWAPONOFF is not set
|
||||
# CONFIG_FEATURE_SWAPON_DISCARD is not set
|
||||
# CONFIG_FEATURE_SWAPON_PRI is not set
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
# CONFIG_UMOUNT is not set
|
||||
@@ -603,32 +633,45 @@ CONFIG_VOLUMEID=y
|
||||
#
|
||||
# Filesystem/Volume identification
|
||||
#
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXFAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_F2FS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_JFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_XFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ISO9660=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_JFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NILFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SQUASHFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_XFS=y
|
||||
|
||||
#
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
# CONFIG_CONSPY is not set
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_I2CGET=y
|
||||
CONFIG_I2CSET=y
|
||||
CONFIG_I2CDUMP=y
|
||||
CONFIG_I2CDETECT=y
|
||||
CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
CONFIG_FEATURE_LESS_BRACKETS=y
|
||||
CONFIG_FEATURE_LESS_FLAGS=y
|
||||
CONFIG_FEATURE_LESS_TRUNCATE=y
|
||||
CONFIG_FEATURE_LESS_MARKS=y
|
||||
CONFIG_FEATURE_LESS_REGEXP=y
|
||||
CONFIG_FEATURE_LESS_WINCH=y
|
||||
@@ -637,13 +680,17 @@ CONFIG_FEATURE_LESS_DASHCMD=y
|
||||
CONFIG_FEATURE_LESS_LINENUMS=y
|
||||
# CONFIG_NANDWRITE is not set
|
||||
CONFIG_NANDDUMP=y
|
||||
# CONFIG_RFKILL is not set
|
||||
CONFIG_SETSERIAL=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
# CONFIG_UBIATTACH is not set
|
||||
# CONFIG_UBIDETACH is not set
|
||||
# CONFIG_UBIMKVOL is not set
|
||||
# CONFIG_UBIRMVOL is not set
|
||||
# CONFIG_UBIRSVOL is not set
|
||||
# CONFIG_UBIUPDATEVOL is not set
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_ADJTIMEX is not set
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_FEATURE_COMPRESS_BBCONFIG=y
|
||||
@@ -659,10 +706,6 @@ CONFIG_FEATURE_CHAT_SEND_ESCAPES=y
|
||||
CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
CONFIG_FEATURE_DC_LIBM=y
|
||||
@@ -700,18 +743,14 @@ CONFIG_MAN=y
|
||||
# CONFIG_MT is not set
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
# CONFIG_READAHEAD is not set
|
||||
# CONFIG_RFKILL is not set
|
||||
# CONFIG_RUNLEVEL is not set
|
||||
CONFIG_RX=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_STRINGS=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_WATCHDOG is not set
|
||||
|
||||
#
|
||||
@@ -743,13 +782,13 @@ CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FEATURE_FTP_AUTHENTICATION=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
# CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
|
||||
# CONFIG_HOSTNAME is not set
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
@@ -806,6 +845,7 @@ CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
# CONFIG_NSLOOKUP is not set
|
||||
# CONFIG_NTPD is not set
|
||||
# CONFIG_FEATURE_NTPD_SERVER is not set
|
||||
# CONFIG_FEATURE_NTPD_CONF is not set
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
# CONFIG_SLATTACH is not set
|
||||
@@ -843,6 +883,7 @@ CONFIG_FEATURE_TUNCTL_UG=y
|
||||
CONFIG_DHCPD_LEASES_FILE=""
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
CONFIG_FEATURE_UDHCP_RFC3397=y
|
||||
@@ -889,6 +930,13 @@ CONFIG_POWERTOP=y
|
||||
CONFIG_PSTREE=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_SMEMCAP=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_UPTIME=y
|
||||
# CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set
|
||||
CONFIG_FREE=y
|
||||
@@ -909,13 +957,6 @@ CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
|
||||
# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
@@ -961,6 +1002,7 @@ CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_HELP is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
@@ -1010,6 +1052,7 @@ CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
|
||||
# CONFIG_LOGREAD is not set
|
||||
# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
|
||||
# CONFIG_FEATURE_KMSG_SYSLOG is not set
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_FEATURE_KLOGD_KLOGCTL=y
|
||||
# CONFIG_LOGGER is not set
|
||||
@@ -10,8 +10,9 @@
|
||||
//usage:#define loadkmap_trivial_usage
|
||||
//usage: "< keymap"
|
||||
//usage:#define loadkmap_full_usage "\n\n"
|
||||
//usage: "Load a binary keyboard translation table from stdin\n"
|
||||
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
||||
//usage: "Load a binary keyboard translation table from stdin"
|
||||
////usage: "\n"
|
||||
////usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
//usage:
|
||||
//usage:#define loadkmap_example_usage
|
||||
//usage: "$ loadkmap < /etc/i18n/lang-keymap\n"
|
||||
@@ -56,7 +57,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
|
||||
if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
|
||||
bb_error_msg_and_die("not a valid binary keymap");
|
||||
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
@@ -83,7 +83,6 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (04 /*CTRL-D*/ == c)
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// we assume a PC keyboard
|
||||
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
|
||||
|
||||
+9
-45
@@ -11,7 +11,7 @@ config CAL
|
||||
bool "cal"
|
||||
default y
|
||||
help
|
||||
cal is used to display a monthly calender.
|
||||
cal is used to display a monthly calendar.
|
||||
|
||||
config CATV
|
||||
bool "catv"
|
||||
@@ -87,44 +87,6 @@ config CUT
|
||||
cut is used to print selected parts of lines from
|
||||
each file to stdout.
|
||||
|
||||
config DD
|
||||
bool "dd"
|
||||
default y
|
||||
help
|
||||
dd copies a file (from standard input to standard output,
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
|
||||
config FEATURE_DD_SIGNAL_HANDLING
|
||||
bool "Enable DD signal handling for status reporting"
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null&
|
||||
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in
|
||||
10899206+0 records out
|
||||
|
||||
config FEATURE_DD_THIRD_STATUS_LINE
|
||||
bool "Enable the third status line upon signal"
|
||||
default y
|
||||
depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
help
|
||||
Displays a coreutils-like third status line with transferred bytes,
|
||||
elapsed time and speed.
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
Enables support for writing a certain number of bytes in and out,
|
||||
at a time, and performing conversions on the data stream.
|
||||
|
||||
config DF
|
||||
bool "df"
|
||||
default y
|
||||
@@ -609,12 +571,6 @@ config SUM
|
||||
help
|
||||
checksum and count the blocks in a file
|
||||
|
||||
config SYNC
|
||||
bool "sync"
|
||||
default y
|
||||
help
|
||||
sync is used to flush filesystem buffers.
|
||||
|
||||
config TAC
|
||||
bool "tac"
|
||||
default y
|
||||
@@ -674,6 +630,14 @@ config UNAME
|
||||
help
|
||||
uname is used to print system information.
|
||||
|
||||
config UNAME_OSNAME
|
||||
string "Operating system name"
|
||||
default "GNU/Linux"
|
||||
depends on UNAME
|
||||
help
|
||||
Sets the operating system name reported by uname -o. The
|
||||
default is "GNU/Linux".
|
||||
|
||||
config UNEXPAND
|
||||
bool "unexpand"
|
||||
default y
|
||||
|
||||
@@ -68,7 +68,6 @@ lib-$(CONFIG_SORT) += sort.o
|
||||
lib-$(CONFIG_STAT) += stat.o
|
||||
lib-$(CONFIG_STTY) += stty.o
|
||||
lib-$(CONFIG_SUM) += sum.o
|
||||
lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAC) += tac.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
//usage:#define basename_trivial_usage
|
||||
//usage: "FILE [SUFFIX]"
|
||||
//usage:#define basename_full_usage "\n\n"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE\n"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE"
|
||||
//usage:
|
||||
//usage:#define basename_example_usage
|
||||
//usage: "$ basename /usr/local/bin/foo\n"
|
||||
|
||||
+2
-2
@@ -69,9 +69,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
|
||||
if (S_ISLNK(statbuf->st_mode))
|
||||
return TRUE;
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
newmode = bb_parse_mode((char *)param, statbuf->st_mode);
|
||||
if (newmode == (mode_t)-1)
|
||||
bb_error_msg_and_die("invalid mode '%s'", (char *)param);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
//usage:#define chown_trivial_usage
|
||||
//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... OWNER[<.|:>[GROUP]] FILE..."
|
||||
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... OWNER[<.|:>[GROUP]] FILE..."
|
||||
//usage:#define chown_full_usage "\n\n"
|
||||
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
|
||||
//usage: "\n -R Recurse"
|
||||
|
||||
+1
-1
@@ -373,7 +373,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
date_buf[0] = '\0';
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
if (is_prefixed_with(fmt_dt2str, "%f")) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
/* Generate output string */
|
||||
|
||||
+109
-49
@@ -8,6 +8,51 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DD
|
||||
//config: bool "dd"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dd copies a file (from standard input to standard output,
|
||||
//config: by default) using specific input and output blocksizes,
|
||||
//config: while optionally performing conversions on it.
|
||||
//config:
|
||||
//config:config FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: bool "Enable signal handling for status reporting"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
//config: print to standard error the number of records read and written
|
||||
//config: so far, then to resume copying.
|
||||
//config:
|
||||
//config: $ dd if=/dev/zero of=/dev/null &
|
||||
//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
|
||||
//config: 10899206+0 records in
|
||||
//config: 10899206+0 records out
|
||||
//config:
|
||||
//config:config FEATURE_DD_THIRD_STATUS_LINE
|
||||
//config: bool "Enable the third status line upon signal"
|
||||
//config: default y
|
||||
//config: depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: help
|
||||
//config: Displays a coreutils-like third status line with transferred bytes,
|
||||
//config: elapsed time and speed.
|
||||
//config:
|
||||
//config:config FEATURE_DD_IBS_OBS
|
||||
//config: bool "Enable ibs, obs and conv options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for writing a certain number of bytes in and out,
|
||||
//config: at a time, and performing conversions on the data stream.
|
||||
//config:
|
||||
//config:config FEATURE_DD_STATUS
|
||||
//config: bool "Enable status display options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for status=noxfer/none option.
|
||||
|
||||
//usage:#define dd_trivial_usage
|
||||
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
|
||||
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]")
|
||||
@@ -32,8 +77,12 @@
|
||||
//usage: "\n conv=fsync Physically write data out before finishing"
|
||||
//usage: "\n conv=swab Swap every pair of bytes"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_DD_STATUS(
|
||||
//usage: "\n status=noxfer Suppress rate output"
|
||||
//usage: "\n status=none Suppress all output"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kD (1000), k (1024), MD, M, GD, G"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G"
|
||||
//usage:
|
||||
//usage:#define dd_example_usage
|
||||
//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
|
||||
@@ -50,26 +99,13 @@ enum {
|
||||
ofd = STDOUT_FILENO,
|
||||
};
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
{ "b", 512 },
|
||||
{ "kD", 1000 },
|
||||
{ "k", 1024 },
|
||||
{ "K", 1024 }, /* compat with coreutils dd */
|
||||
{ "MD", 1000000 },
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
unsigned long long total_bytes;
|
||||
unsigned long long begin_time_us;
|
||||
#endif
|
||||
int flags;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
@@ -77,6 +113,21 @@ struct globals {
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
} while (0)
|
||||
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
FLAG_STATUS = 1 << 7,
|
||||
FLAG_STATUS_NONE = 1 << 7,
|
||||
FLAG_STATUS_NOXFER = 1 << 8,
|
||||
};
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
{
|
||||
@@ -93,6 +144,13 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
G.out_full, G.out_part);
|
||||
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
# if ENABLE_FEATURE_DD_STATUS
|
||||
if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */
|
||||
return;
|
||||
//TODO: should status=none make dd stop reacting to USR1 entirely?
|
||||
//So far we react to it (we print the stats),
|
||||
//status=none only suppresses final, non-USR1 generated status message.
|
||||
# endif
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
@@ -148,20 +206,8 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs\0""obs\0""conv\0"
|
||||
#endif
|
||||
@@ -169,6 +215,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
static const char status_words[] ALIGN1 =
|
||||
"none\0""noxfer\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 0,
|
||||
@@ -177,6 +227,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_skip,
|
||||
OP_if,
|
||||
OP_of,
|
||||
IF_FEATURE_DD_STATUS(OP_status,)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
OP_ibs,
|
||||
OP_obs,
|
||||
@@ -215,14 +266,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
size_t oc;
|
||||
ssize_t prev_read_size; /* for detecting swab failure */
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
@@ -258,11 +307,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (what == OP_ibs) {
|
||||
/* Must fit into positive ssize_t */
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
@@ -278,7 +327,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
n = index_in_strings(conv_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
flags |= (1 << n);
|
||||
G.flags |= (1 << n);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
@@ -288,22 +337,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
obs = ibs;
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
if (what == OP_count) {
|
||||
flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, dd_suffixes);
|
||||
G.flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_seek) {
|
||||
seek = XATOU_SFX(val, dd_suffixes);
|
||||
seek = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_skip) {
|
||||
skip = XATOU_SFX(val, dd_suffixes);
|
||||
skip = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_if) {
|
||||
@@ -314,6 +363,16 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
if (what == OP_status) {
|
||||
int n;
|
||||
n = index_in_strings(status_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "status");
|
||||
G.flags |= FLAG_STATUS << n;
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
} /* end of "for (argv[i])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
@@ -321,7 +380,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
obuf = ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (ibs != obs) {
|
||||
flags |= FLAG_TWOBUFS;
|
||||
G.flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
#endif
|
||||
@@ -341,12 +400,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (outfile) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
if (!seek && !(G.flags & FLAG_NOTRUNC))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (seek && !(G.flags & FLAG_NOTRUNC)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
@@ -377,7 +436,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
@@ -385,7 +444,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
break;
|
||||
if (n < 0) {
|
||||
/* "Bad block" */
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
if (!(G.flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
bb_simple_perror_msg(infile);
|
||||
/* GNU dd with conv=noerror skips over bad blocks */
|
||||
@@ -394,7 +453,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if (flags & FLAG_SWAB) {
|
||||
if (G.flags & FLAG_SWAB) {
|
||||
uint16_t *p16;
|
||||
ssize_t n2;
|
||||
|
||||
@@ -419,12 +478,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (flags & FLAG_SYNC) {
|
||||
if (G.flags & FLAG_SYNC) {
|
||||
memset(ibuf + n, 0, ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
if (flags & FLAG_TWOBUFS) {
|
||||
if (G.flags & FLAG_TWOBUFS) {
|
||||
char *tmp = ibuf;
|
||||
while (n) {
|
||||
size_t d = obs - oc;
|
||||
@@ -446,7 +505,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto out_status;
|
||||
}
|
||||
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (G.flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
@@ -468,11 +527,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
out_status:
|
||||
dd_output_status(0);
|
||||
if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
|
||||
dd_output_status(0);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
free(obuf);
|
||||
if (flags & FLAG_TWOBUFS)
|
||||
if (G.flags & FLAG_TWOBUFS)
|
||||
free(ibuf);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned buflen;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = '\\',
|
||||
eflag = 0, /* 0 -- disable escape sequences */
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
|
||||
|
||||
+3
-5
@@ -10,11 +10,9 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */
|
||||
|
||||
//usage:#define false_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define false_full_usage "\n\n"
|
||||
//usage: "Return an exit code of FALSE (1)"
|
||||
//usage:
|
||||
/* "false --help" is special-cased to ignore --help */
|
||||
//usage:#define false_trivial_usage NOUSAGE_STR
|
||||
//usage:#define false_full_usage ""
|
||||
//usage:#define false_example_usage
|
||||
//usage: "$ false\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
mode = 0755; /* GNU coreutils 6.10 compat */
|
||||
if (opts & OPT_MODE)
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
mode = bb_parse_mode(mode_str, mode);
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
|
||||
int opt;
|
||||
opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
mode = bb_parse_mode(smode, mode);
|
||||
if (mode != (mode_t)-1) /* if mode is valid */
|
||||
/* make future mknod/mkfifo set mode bits exactly */
|
||||
umask(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,6 @@ int ln_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
free(src_name);
|
||||
|
||||
} while ((++argv)[1]);
|
||||
|
||||
return status;
|
||||
|
||||
+13
-10
@@ -566,12 +566,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
|
||||
char *filetime;
|
||||
time_t ttime = dn->dn_mtime;
|
||||
const time_t *ttime = &dn->dn_mtime;
|
||||
if (G.all_fmt & TIME_ACCESS)
|
||||
ttime = dn->dn_atime;
|
||||
ttime = &dn->dn_atime;
|
||||
if (G.all_fmt & TIME_CHANGE)
|
||||
ttime = dn->dn_ctime;
|
||||
filetime = ctime(&ttime);
|
||||
ttime = &dn->dn_ctime;
|
||||
filetime = ctime(ttime);
|
||||
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
|
||||
if (G.all_fmt & LIST_FULLTIME) { /* -e */
|
||||
/* Note: coreutils 8.4 ls --full-time prints:
|
||||
@@ -580,13 +580,16 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
column += printf("%.24s ", filetime);
|
||||
} else { /* LIST_DATE_TIME */
|
||||
/* G.current_time_t ~== time(NULL) */
|
||||
time_t age = G.current_time_t - ttime;
|
||||
printf("%.6s ", filetime + 4); /* "Jun 30" */
|
||||
time_t age = G.current_time_t - *ttime;
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* hh:mm if less than 6 months old */
|
||||
printf("%.5s ", filetime + 11);
|
||||
} else { /* year. buggy if year > 9999 ;) */
|
||||
printf(" %.4s ", filetime + 20);
|
||||
/* less than 6 months old */
|
||||
/* "mmm dd hh:mm " */
|
||||
printf("%.12s ", filetime + 4);
|
||||
} else {
|
||||
/* "mmm dd yyyy " */
|
||||
/* "mmm dd yyyyy " after year 9999 :) */
|
||||
strchr(filetime + 20, '\n')[0] = ' ';
|
||||
printf("%.7s%6s", filetime + 4, filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
|
||||
+2
-2
@@ -71,8 +71,8 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode_t mmode = 0777;
|
||||
if (!bb_parse_mode(smode, &mmode)) {
|
||||
mode_t mmode = bb_parse_mode(smode, 0777);
|
||||
if (mmode == (mode_t)-1) {
|
||||
bb_error_msg_and_die("invalid mode '%s'", smode);
|
||||
}
|
||||
mode = mmode;
|
||||
|
||||
@@ -387,11 +387,11 @@ print_named_ascii(size_t n_bytes, const char *block,
|
||||
" sp"
|
||||
};
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
// actually " x\0 xxx\0", but want to share string with print_ascii.
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
// [12] because we take three 32bit stack slots anyway, and
|
||||
// gcc is too dumb to initialize with constant stores,
|
||||
// it copies initializer from rodata. Oh well.
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410
|
||||
|
||||
while (n_bytes--) {
|
||||
unsigned masked_c = *(unsigned char *) block++;
|
||||
@@ -419,7 +419,7 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
const char *unused_fmt_string UNUSED_PARAM)
|
||||
{
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
|
||||
while (n_bytes--) {
|
||||
const char *s;
|
||||
@@ -455,11 +455,9 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
case '\v':
|
||||
s = " \\v";
|
||||
break;
|
||||
case '\x7f':
|
||||
s = " 177";
|
||||
break;
|
||||
default: /* c is never larger than 040 */
|
||||
buf[7] = (c >> 3) + '0';
|
||||
default:
|
||||
buf[6] = (c >> 6 & 3) + '0';
|
||||
buf[7] = (c >> 3 & 7) + '0';
|
||||
buf[8] = (c & 7) + '0';
|
||||
s = buf + 5;
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ int shuf_main(int argc, char **argv)
|
||||
*dash = '\0';
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
*dash = '-';
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
+22
-8
@@ -25,14 +25,14 @@
|
||||
//usage: "\n -f Ignore case"
|
||||
//usage: "\n -g General numerical sort"
|
||||
//usage: "\n -i Ignore unprintable characters"
|
||||
//usage: "\n -k Sort key"
|
||||
//usage: "\n -M Sort month"
|
||||
//usage: )
|
||||
//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
|
||||
//usage: "\n -n Sort numbers"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
//usage: "\n -o Output to file"
|
||||
//usage: "\n -k Sort by key"
|
||||
//usage: "\n -t CHAR Key separator"
|
||||
//usage: "\n -t CHAR Field separator"
|
||||
//usage: "\n -k N[,M] Sort by Nth field"
|
||||
//usage: )
|
||||
//usage: "\n -r Reverse sort order"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
@@ -106,7 +106,9 @@ static struct sort_key {
|
||||
|
||||
static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
{
|
||||
int start = 0, end = 0, len, j;
|
||||
int start = start; /* for compiler */
|
||||
int end;
|
||||
int len, j;
|
||||
unsigned i;
|
||||
|
||||
/* Special case whole string, so we don't have to make a copy */
|
||||
@@ -123,12 +125,15 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
end = len;
|
||||
/* Loop through fields */
|
||||
else {
|
||||
unsigned char ch = 0;
|
||||
|
||||
end = 0;
|
||||
for (i = 1; i < key->range[2*j] + j; i++) {
|
||||
if (key_separator) {
|
||||
/* Skip body of key and separator */
|
||||
while (str[end]) {
|
||||
if (str[end++] == key_separator)
|
||||
while ((ch = str[end]) != '\0') {
|
||||
end++;
|
||||
if (ch == key_separator)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -136,13 +141,21 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
while (isspace(str[end]))
|
||||
end++;
|
||||
/* Skip body of key */
|
||||
while (str[end]) {
|
||||
while (str[end] != '\0') {
|
||||
if (isspace(str[end]))
|
||||
break;
|
||||
end++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Remove last delim: "abc:def:" => "abc:def" */
|
||||
if (j && ch) {
|
||||
//if (str[end-1] != key_separator)
|
||||
// bb_error_msg(_and_die("BUG! "
|
||||
// "str[start:%d,end:%d]:'%.*s'",
|
||||
// start, end, (int)(end-start), &str[start]);
|
||||
end--;
|
||||
}
|
||||
}
|
||||
if (!j) start = end;
|
||||
}
|
||||
@@ -163,7 +176,8 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
if (start > len) start = len;
|
||||
}
|
||||
/* Make the copy */
|
||||
if (end < start) end = start;
|
||||
if (end < start)
|
||||
end = start;
|
||||
str = xstrndup(str+start, end-start);
|
||||
/* Handle -d */
|
||||
if (flags & FLAG_d) {
|
||||
|
||||
+1
-1
@@ -374,7 +374,7 @@ static void print_it(const char *masterformat,
|
||||
{
|
||||
/* Create a working copy of the format string */
|
||||
char *format = xstrdup(masterformat);
|
||||
/* Add 2 to accomodate our conversion of the stat '%s' format string
|
||||
/* Add 2 to accommodate our conversion of the stat '%s' format string
|
||||
* to the printf '%llu' one. */
|
||||
char *dest = xmalloc(strlen(format) + 2 + 1);
|
||||
char *b;
|
||||
|
||||
+75
-3
@@ -3,16 +3,39 @@
|
||||
* Mini sync implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
* Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||
//config:config SYNC
|
||||
//config: bool "sync"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: sync is used to flush filesystem buffers.
|
||||
//config:config FEATURE_SYNC_FANCY
|
||||
//config: bool "Enable -d and -f flags (requres syncfs(2) in libc)"
|
||||
//config: default y
|
||||
//config: depends on SYNC
|
||||
//config: help
|
||||
//config: sync -d FILE... executes fdatasync() on each FILE.
|
||||
//config: sync -f FILE... executes syncfs() on each FILE.
|
||||
|
||||
//kbuild:lib-$(CONFIG_SYNC) += sync.o
|
||||
//applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync))
|
||||
|
||||
//usage:#define sync_trivial_usage
|
||||
//usage: ""
|
||||
//usage: ""IF_FEATURE_SYNC_FANCY("[-df] [FILE]...")
|
||||
//usage:#define sync_full_usage "\n\n"
|
||||
//usage: IF_NOT_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks to disk"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks (in FILEs) to disk"
|
||||
//usage: "\n -d Avoid syncing metadata"
|
||||
//usage: "\n -f Sync filesystems underlying FILEs"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -21,10 +44,59 @@
|
||||
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
||||
{
|
||||
#if !ENABLE_FEATURE_SYNC_FANCY
|
||||
/* coreutils-6.9 compat */
|
||||
bb_warn_ignoring_args(argv[1]);
|
||||
|
||||
sync();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
#else
|
||||
unsigned opts;
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
enum {
|
||||
OPT_DATASYNC = (1 << 0),
|
||||
OPT_SYNCFS = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "d--f:f--d";
|
||||
opts = getopt32(argv, "df");
|
||||
argv += optind;
|
||||
|
||||
/* Handle the no-argument case. */
|
||||
if (!argv[0])
|
||||
sync();
|
||||
|
||||
while (*argv) {
|
||||
int fd = open_or_warn(*argv, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
if (opts & OPT_DATASYNC) {
|
||||
if (fdatasync(fd))
|
||||
goto err;
|
||||
goto do_close;
|
||||
}
|
||||
if (opts & OPT_SYNCFS) {
|
||||
/*
|
||||
* syncfs is documented to only fail with EBADF,
|
||||
* which can't happen here. So, no error checks.
|
||||
*/
|
||||
syncfs(fd);
|
||||
goto do_close;
|
||||
}
|
||||
if (fsync(fd)) {
|
||||
err:
|
||||
bb_simple_perror_msg(*argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
do_close:
|
||||
close(fd);
|
||||
next:
|
||||
++argv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
+3
-8
@@ -39,14 +39,9 @@
|
||||
//config: help
|
||||
//config: Enable 64-bit support in test.
|
||||
|
||||
/* "test --help" does not print help (POSIX compat), only "[ --help" does.
|
||||
* We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION")
|
||||
* Unfortunately, it screws up generated BusyBox.html. TODO. */
|
||||
//usage:#define test_trivial_usage
|
||||
//usage: "EXPRESSION ]"
|
||||
//usage:#define test_full_usage "\n\n"
|
||||
//usage: "Check file types, compare values etc. Return a 0/1 exit code\n"
|
||||
//usage: "depending on logical value of EXPRESSION"
|
||||
/* "test --help" is special-cased to ignore --help */
|
||||
//usage:#define test_trivial_usage NOUSAGE_STR
|
||||
//usage:#define test_full_usage ""
|
||||
//usage:
|
||||
//usage:#define test_example_usage
|
||||
//usage: "$ test 1 -eq 2\n"
|
||||
|
||||
+3
-5
@@ -10,11 +10,9 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */
|
||||
|
||||
//usage:#define true_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define true_full_usage "\n\n"
|
||||
//usage: "Return an exit code of TRUE (0)"
|
||||
//usage:
|
||||
/* "true --help" is special-cased to ignore --help */
|
||||
//usage:#define true_trivial_usage NOUSAGE_STR
|
||||
//usage:#define true_full_usage ""
|
||||
//usage:#define true_example_usage
|
||||
//usage: "$ true\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Mini truncate implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config TRUNCATE
|
||||
//config: bool "truncate"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: truncate truncates files to a given size. If a file does
|
||||
//config: not exist, it is created unless told otherwise.
|
||||
|
||||
//kbuild:lib-$(CONFIG_TRUNCATE) += truncate.o
|
||||
//applet:IF_TRUNCATE(APPLET_NOFORK(truncate, truncate, BB_DIR_USR_BIN, BB_SUID_DROP, truncate))
|
||||
|
||||
//usage:#define truncate_trivial_usage
|
||||
//usage: "[-c] -s SIZE FILE..."
|
||||
//usage:#define truncate_full_usage "\n\n"
|
||||
//usage: "Truncate FILEs to the given size\n"
|
||||
//usage: "\n -c Do not create files"
|
||||
//usage: "\n -s SIZE Truncate to SIZE"
|
||||
//usage:
|
||||
//usage:#define truncate_example_usage
|
||||
//usage: "$ truncate -s 1G foo"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_LFS
|
||||
# define XATOU_SFX xatoull_sfx
|
||||
#else
|
||||
# define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int truncate_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
int flags = O_RDWR;
|
||||
int ret = EXIT_SUCCESS;
|
||||
char *size_str;
|
||||
off_t size;
|
||||
|
||||
enum {
|
||||
OPT_NOCREATE = (1 << 0),
|
||||
OPT_SIZE = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "s:-1";
|
||||
opts = getopt32(argv, "cs:", &size_str);
|
||||
|
||||
if (!(opts & OPT_NOCREATE))
|
||||
flags |= O_CREAT;
|
||||
|
||||
// TODO: coreutils 8.17 also support "m" (lowercase) suffix
|
||||
// with truncate, but not with dd!
|
||||
// We share kMG_suffixes[], so we can't make both tools
|
||||
// compatible at once...
|
||||
size = XATOU_SFX(size_str, kMG_suffixes);
|
||||
|
||||
argv += optind;
|
||||
while (*argv) {
|
||||
int fd = open(*argv, flags, 0666);
|
||||
if (fd < 0) {
|
||||
if (errno != ENOENT || !(opts & OPT_NOCREATE)) {
|
||||
bb_perror_msg("%s: open", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
/* else: ENOENT && OPT_NOCREATE:
|
||||
* do not report error, exitcode is also 0.
|
||||
*/
|
||||
} else {
|
||||
if (ftruncate(fd, size) == -1) {
|
||||
bb_perror_msg("%s: truncate", *argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
xclose(fd);
|
||||
}
|
||||
++argv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
+2
-2
@@ -74,7 +74,7 @@ typedef struct {
|
||||
struct utsname name;
|
||||
char processor[sizeof(((struct utsname*)NULL)->machine)];
|
||||
char platform[sizeof(((struct utsname*)NULL)->machine)];
|
||||
char os[sizeof("GNU/Linux")];
|
||||
char os[sizeof(CONFIG_UNAME_OSNAME)];
|
||||
} uname_info_t;
|
||||
|
||||
static const char options[] ALIGN1 = "snrvmpioa";
|
||||
@@ -141,7 +141,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
strcpy(uname_info.processor, unknown_str);
|
||||
strcpy(uname_info.platform, unknown_str);
|
||||
strcpy(uname_info.os, "GNU/Linux");
|
||||
strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
|
||||
#if 0
|
||||
/* Fedora does something like this */
|
||||
strcpy(uname_info.processor, uname_info.name.machine);
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* %7lu matches GNU coreutils 6.9 */
|
||||
printf("%7lu ", dups + 1);
|
||||
}
|
||||
printf("%s\n", old_line);
|
||||
puts(old_line);
|
||||
}
|
||||
free(old_line);
|
||||
}
|
||||
|
||||
+15
-4
@@ -29,9 +29,19 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
|
||||
{
|
||||
char *line;
|
||||
|
||||
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
|
||||
for (;;) {
|
||||
int encoded_len, str_len;
|
||||
char *line_ptr, *dst;
|
||||
size_t line_len;
|
||||
|
||||
line_len = 64 * 1024;
|
||||
line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
|
||||
if (!line)
|
||||
break;
|
||||
/* Handle both Unix and MSDOS text, and stray trailing spaces */
|
||||
str_len = line_len;
|
||||
while (--str_len >= 0 && isspace(line[str_len]))
|
||||
line[str_len] = '\0';
|
||||
|
||||
if (strcmp(line, "end") == 0) {
|
||||
return; /* the only non-error exit */
|
||||
@@ -46,7 +56,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
|
||||
|
||||
encoded_len = line[0] * 4 / 3;
|
||||
/* Check that line is not too short. (we tolerate
|
||||
* overly _long_ line to accomodate possible extra '`').
|
||||
* overly _long_ line to accommodate possible extra '`').
|
||||
* Empty line case is also caught here. */
|
||||
if (str_len <= encoded_len) {
|
||||
break; /* go to bb_error_msg_and_die("short file"); */
|
||||
@@ -110,10 +120,10 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
|
||||
FILE *dst_stream;
|
||||
int mode;
|
||||
|
||||
if (strncmp(line, "begin-base64 ", 13) == 0) {
|
||||
if (is_prefixed_with(line, "begin-base64 ")) {
|
||||
line_ptr = line + 13;
|
||||
decode_fn_ptr = read_base64;
|
||||
} else if (strncmp(line, "begin ", 6) == 0) {
|
||||
} else if (is_prefixed_with(line, "begin ")) {
|
||||
line_ptr = line + 6;
|
||||
decode_fn_ptr = read_stduu;
|
||||
} else {
|
||||
@@ -128,6 +138,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!outname)
|
||||
break;
|
||||
outname++;
|
||||
trim(outname); /* remove trailing space (and '\r' for DOS text) */
|
||||
if (!outname[0])
|
||||
break;
|
||||
}
|
||||
|
||||
+5
-5
@@ -73,7 +73,7 @@ static void idle_string(char *str6, time_t t)
|
||||
int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct utmp *ut;
|
||||
struct utmpx *ut;
|
||||
unsigned opt;
|
||||
int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
|
||||
const char *fmt = "%s";
|
||||
@@ -81,10 +81,10 @@ int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, do_users ? "" : "aH");
|
||||
if (opt & 2) // -H
|
||||
printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
|
||||
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
|
||||
|
||||
setutent();
|
||||
while ((ut = getutent()) != NULL) {
|
||||
setutxent();
|
||||
while ((ut = getutxent()) != NULL) {
|
||||
if (ut->ut_user[0]
|
||||
&& ((opt & 1) || ut->ut_type == USER_PROCESS)
|
||||
) {
|
||||
@@ -126,6 +126,6 @@ int who_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (do_users)
|
||||
bb_putchar('\n');
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
endutent();
|
||||
endutxent();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (ret < 0)
|
||||
bb_perror_msg("can't execute '%s'", name);
|
||||
else /* ret > 0 */
|
||||
bb_error_msg("%s exited with code %d", name, ret & 0xff);
|
||||
bb_error_msg("%s: exit status %u", name, ret & 0xff);
|
||||
|
||||
if (option_mask32 & OPT_e)
|
||||
xfunc_die();
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ fulfilled by the gateway program: <p>
|
||||
|
||||
</p><ul>
|
||||
<li> <a name="protocol"><code>SERVER_PROTOCOL</code></a> <p>
|
||||
The name and revision of the information protcol this request came
|
||||
The name and revision of the information protocol this request came
|
||||
in with. Format: protocol/revision </p><p>
|
||||
|
||||
</p></li><li> <code>SERVER_PORT</code> <p>
|
||||
|
||||
+20
-20
@@ -199,7 +199,7 @@ static char *base_device(const char *device)
|
||||
}
|
||||
|
||||
/* Handle DAC 960 devices */
|
||||
if (strncmp(cp, "rd/", 3) == 0) {
|
||||
if (is_prefixed_with(cp, "rd/")) {
|
||||
cp += 3;
|
||||
if (cp[0] != 'c' || !isdigit(cp[1])
|
||||
|| cp[2] != 'd' || !isdigit(cp[3]))
|
||||
@@ -224,9 +224,9 @@ static char *base_device(const char *device)
|
||||
#if ENABLE_FEATURE_DEVFS
|
||||
/* Now let's handle devfs (ugh) names */
|
||||
len = 0;
|
||||
if (strncmp(cp, "ide/", 4) == 0)
|
||||
if (is_prefixed_with(cp, "ide/"))
|
||||
len = 4;
|
||||
if (strncmp(cp, "scsi/", 5) == 0)
|
||||
if (is_prefixed_with(cp, "scsi/"))
|
||||
len = 5;
|
||||
if (len) {
|
||||
cp += len;
|
||||
@@ -237,38 +237,38 @@ static char *base_device(const char *device)
|
||||
* some number of digits at each level, abort.
|
||||
*/
|
||||
for (hier = devfs_hier; *hier; hier++) {
|
||||
len = strlen(*hier);
|
||||
if (strncmp(cp, *hier, len) != 0)
|
||||
cp = is_prefixed_with(cp, *hier);
|
||||
if (!cp)
|
||||
goto errout;
|
||||
cp += len;
|
||||
while (*cp != '/' && *cp != 0) {
|
||||
while (*cp != '/' && *cp != '\0') {
|
||||
if (!isdigit(*cp))
|
||||
goto errout;
|
||||
cp++;
|
||||
}
|
||||
//FIXME: what if *cp = '\0' now? cp++ moves past it!!!
|
||||
cp++;
|
||||
}
|
||||
cp[-1] = 0;
|
||||
cp[-1] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Now handle devfs /dev/disc or /dev/disk names */
|
||||
disk = 0;
|
||||
if (strncmp(cp, "discs/", 6) == 0)
|
||||
disk = NULL;
|
||||
if (is_prefixed_with(cp, "discs/"))
|
||||
disk = "disc";
|
||||
else if (strncmp(cp, "disks/", 6) == 0)
|
||||
else if (is_prefixed_with(cp, "disks/"))
|
||||
disk = "disk";
|
||||
if (disk) {
|
||||
cp += 6;
|
||||
if (strncmp(cp, disk, 4) != 0)
|
||||
cp = is_prefixed_with(cp, disk);
|
||||
if (!cp)
|
||||
goto errout;
|
||||
cp += 4;
|
||||
while (*cp != '/' && *cp != 0) {
|
||||
while (*cp != '/' && *cp != '\0') {
|
||||
if (!isdigit(*cp))
|
||||
goto errout;
|
||||
cp++;
|
||||
}
|
||||
*cp = 0;
|
||||
*cp = '\0';
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
@@ -593,8 +593,8 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
|
||||
type, "from fstab");
|
||||
} else if (fstype
|
||||
&& (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
|
||||
&& strncmp(fstype, "opts=", 5) != 0
|
||||
&& strncmp(fstype, "loop", 4) != 0
|
||||
&& !is_prefixed_with(fstype, "opts=")
|
||||
&& !is_prefixed_with(fstype, "loop")
|
||||
&& !strchr(fstype, ',')
|
||||
) {
|
||||
type = fstype;
|
||||
@@ -627,8 +627,8 @@ static int device_already_active(char *device)
|
||||
#ifdef BASE_MD
|
||||
/* Don't check a soft raid disk with any other disk */
|
||||
if (instance_list
|
||||
&& (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1)
|
||||
|| !strncmp(device, BASE_MD, sizeof(BASE_MD)-1))
|
||||
&& (is_prefixed_with(instance_list->device, BASE_MD)
|
||||
|| is_prefixed_with(device, BASE_MD))
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
@@ -895,7 +895,7 @@ static void compile_fs_type(char *fs_type)
|
||||
if (strcmp(s, "loop") == 0)
|
||||
/* loop is really short-hand for opts=loop */
|
||||
goto loop_special_case;
|
||||
if (strncmp(s, "opts=", 5) == 0) {
|
||||
if (is_prefixed_with(s, "opts=")) {
|
||||
s += 5;
|
||||
loop_special_case:
|
||||
fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Linux Ext2 FS Progs"
|
||||
|
||||
INSERT
|
||||
|
||||
config CHATTR
|
||||
bool "chattr"
|
||||
default n
|
||||
help
|
||||
chattr changes the file attributes on a second extended file system.
|
||||
|
||||
config E2FSCK
|
||||
bool "e2fsck"
|
||||
default n
|
||||
help
|
||||
e2fsck is used to check Linux second extended file systems (ext2fs).
|
||||
e2fsck also supports ext2 filesystems countaining a journal (ext3).
|
||||
The normal compat symlinks 'fsck.ext2' and 'fsck.ext3' are also
|
||||
provided.
|
||||
|
||||
config FSCK
|
||||
bool "fsck"
|
||||
default n
|
||||
help
|
||||
fsck is used to check and optionally repair one or more filesystems.
|
||||
In actuality, fsck is simply a front-end for the various file system
|
||||
checkers (fsck.fstype) available under Linux.
|
||||
|
||||
config LSATTR
|
||||
bool "lsattr"
|
||||
default n
|
||||
help
|
||||
lsattr lists the file attributes on a second extended file system.
|
||||
|
||||
config MKE2FS
|
||||
bool "mke2fs"
|
||||
default n
|
||||
help
|
||||
mke2fs is used to create an ext2/ext3 filesystem. The normal compat
|
||||
symlinks 'mkfs.ext2' and 'mkfs.ext3' are also provided.
|
||||
|
||||
config TUNE2FS
|
||||
bool "tune2fs"
|
||||
default n
|
||||
help
|
||||
tune2fs allows the system administrator to adjust various tunable
|
||||
filesystem parameters on Linux ext2/ext3 filesystems.
|
||||
|
||||
config E2LABEL
|
||||
bool "e2label"
|
||||
default n
|
||||
depends on TUNE2FS
|
||||
help
|
||||
e2label will display or change the filesystem label on the ext2
|
||||
filesystem located on device.
|
||||
|
||||
config FINDFS
|
||||
bool "findfs"
|
||||
default n
|
||||
depends on TUNE2FS
|
||||
help
|
||||
findfs will search the disks in the system looking for a filesystem
|
||||
which has a label matching label or a UUID equal to uuid.
|
||||
|
||||
endmenu
|
||||
@@ -1,18 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(CONFIG_CHATTR) += chattr.o
|
||||
lib-$(CONFIG_E2FSCK) += e2fsck.o util.o
|
||||
lib-$(CONFIG_FSCK) += fsck.o util.o
|
||||
lib-$(CONFIG_LSATTR) += lsattr.o
|
||||
lib-$(CONFIG_MKE2FS) += mke2fs.o util.o
|
||||
lib-$(CONFIG_TUNE2FS) += tune2fs.o util.o
|
||||
|
||||
CFLAGS += -include $(srctree)/e2fsprogs/e2fsbb.h
|
||||
@@ -1,3 +0,0 @@
|
||||
This is a pretty straight rip from the e2fsprogs pkg.
|
||||
|
||||
See README's in subdirs for specific info.
|
||||
@@ -1,26 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
NEEDED-$(CONFIG_E2FSCK) = y
|
||||
NEEDED-$(CONFIG_FSCK) = y
|
||||
NEEDED-$(CONFIG_MKE2FS) = y
|
||||
NEEDED-$(CONFIG_TUNE2FS) = y
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(NEEDED-y) += cache.o dev.o devname.o devno.o blkid_getsize.o \
|
||||
probe.o read.o resolve.o save.o tag.o list.o
|
||||
|
||||
CFLAGS_dev.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_devname.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_devno.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_blkid_getsize.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_probe.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_save.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_tag.o := -include $(srctree)/include/busybox.h
|
||||
CFLAGS_list.o := -include $(srctree)/include/busybox.h
|
||||
@@ -1,104 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* blkid.h - Interface for libblkid, a library to identify block devices
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
#ifndef BLKID_BLKID_H
|
||||
#define BLKID_BLKID_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BLKID_VERSION "1.0.0"
|
||||
#define BLKID_DATE "12-Feb-2003"
|
||||
|
||||
typedef struct blkid_struct_dev *blkid_dev;
|
||||
typedef struct blkid_struct_cache *blkid_cache;
|
||||
typedef __s64 blkid_loff_t;
|
||||
|
||||
typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
|
||||
typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
|
||||
|
||||
/*
|
||||
* Flags for blkid_get_dev
|
||||
*
|
||||
* BLKID_DEV_CREATE Create an empty device structure if not found
|
||||
* in the cache.
|
||||
* BLKID_DEV_VERIFY Make sure the device structure corresponds
|
||||
* with reality.
|
||||
* BLKID_DEV_FIND Just look up a device entry, and return NULL
|
||||
* if it is not found.
|
||||
* BLKID_DEV_NORMAL Get a valid device structure, either from the
|
||||
* cache or by probing the device.
|
||||
*/
|
||||
#define BLKID_DEV_FIND 0x0000
|
||||
#define BLKID_DEV_CREATE 0x0001
|
||||
#define BLKID_DEV_VERIFY 0x0002
|
||||
#define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
|
||||
|
||||
/* cache.c */
|
||||
extern void blkid_put_cache(blkid_cache cache);
|
||||
extern int blkid_get_cache(blkid_cache *cache, const char *filename);
|
||||
|
||||
/* dev.c */
|
||||
extern const char *blkid_dev_devname(blkid_dev dev);
|
||||
|
||||
extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
|
||||
extern int blkid_dev_set_search(blkid_dev_iterate iter,
|
||||
char *search_type, char *search_value);
|
||||
extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
|
||||
extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
|
||||
|
||||
/* devno.c */
|
||||
extern char *blkid_devno_to_devname(dev_t devno);
|
||||
|
||||
/* devname.c */
|
||||
extern int blkid_probe_all(blkid_cache cache);
|
||||
extern int blkid_probe_all_new(blkid_cache cache);
|
||||
extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname,
|
||||
int flags);
|
||||
|
||||
/* getsize.c */
|
||||
extern blkid_loff_t blkid_get_dev_size(int fd);
|
||||
|
||||
/* probe.c */
|
||||
int blkid_known_fstype(const char *fstype);
|
||||
extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
|
||||
|
||||
/* read.c */
|
||||
|
||||
/* resolve.c */
|
||||
extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
|
||||
const char *devname);
|
||||
extern char *blkid_get_devname(blkid_cache cache, const char *token,
|
||||
const char *value);
|
||||
|
||||
/* tag.c */
|
||||
extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
|
||||
extern int blkid_tag_next(blkid_tag_iterate iterate,
|
||||
const char **type, const char **value);
|
||||
extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
|
||||
extern int blkid_dev_has_tag(blkid_dev dev, const char *type,
|
||||
const char *value);
|
||||
extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
|
||||
const char *type,
|
||||
const char *value);
|
||||
extern int blkid_parse_tag_string(const char *token, char **ret_type,
|
||||
char **ret_val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,182 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* blkidP.h - Internal interfaces for libblkid
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
#ifndef BLKID_BLKIDP_H
|
||||
#define BLKID_BLKIDP_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "blkid.h"
|
||||
#include "list.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define __BLKID_ATTR(x) __attribute__(x)
|
||||
#else
|
||||
#define __BLKID_ATTR(x)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This describes the attributes of a specific device.
|
||||
* We can traverse all of the tags by bid_tags (linking to the tag bit_names).
|
||||
* The bid_label and bid_uuid fields are shortcuts to the LABEL and UUID tag
|
||||
* values, if they exist.
|
||||
*/
|
||||
struct blkid_struct_dev
|
||||
{
|
||||
struct list_head bid_devs; /* All devices in the cache */
|
||||
struct list_head bid_tags; /* All tags for this device */
|
||||
blkid_cache bid_cache; /* Dev belongs to this cache */
|
||||
char *bid_name; /* Device inode pathname */
|
||||
char *bid_type; /* Preferred device TYPE */
|
||||
int bid_pri; /* Device priority */
|
||||
dev_t bid_devno; /* Device major/minor number */
|
||||
time_t bid_time; /* Last update time of device */
|
||||
unsigned int bid_flags; /* Device status bitflags */
|
||||
char *bid_label; /* Shortcut to device LABEL */
|
||||
char *bid_uuid; /* Shortcut to binary UUID */
|
||||
};
|
||||
|
||||
#define BLKID_BID_FL_VERIFIED 0x0001 /* Device data validated from disk */
|
||||
#define BLKID_BID_FL_INVALID 0x0004 /* Device is invalid */
|
||||
|
||||
/*
|
||||
* Each tag defines a NAME=value pair for a particular device. The tags
|
||||
* are linked via bit_names for a single device, so that traversing the
|
||||
* names list will get you a list of all tags associated with a device.
|
||||
* They are also linked via bit_values for all devices, so one can easily
|
||||
* search all tags with a given NAME for a specific value.
|
||||
*/
|
||||
struct blkid_struct_tag
|
||||
{
|
||||
struct list_head bit_tags; /* All tags for this device */
|
||||
struct list_head bit_names; /* All tags with given NAME */
|
||||
char *bit_name; /* NAME of tag (shared) */
|
||||
char *bit_val; /* value of tag */
|
||||
blkid_dev bit_dev; /* pointer to device */
|
||||
};
|
||||
typedef struct blkid_struct_tag *blkid_tag;
|
||||
|
||||
/*
|
||||
* Minimum number of seconds between device probes, even when reading
|
||||
* from the cache. This is to avoid re-probing all devices which were
|
||||
* just probed by another program that does not share the cache.
|
||||
*/
|
||||
#define BLKID_PROBE_MIN 2
|
||||
|
||||
/*
|
||||
* Time in seconds an entry remains verified in the in-memory cache
|
||||
* before being reverified (in case of long-running processes that
|
||||
* keep a cache in memory and continue to use it for a long time).
|
||||
*/
|
||||
#define BLKID_PROBE_INTERVAL 200
|
||||
|
||||
/* This describes an entire blkid cache file and probed devices.
|
||||
* We can traverse all of the found devices via bic_list.
|
||||
* We can traverse all of the tag types by bic_tags, which hold empty tags
|
||||
* for each tag type. Those tags can be used as list_heads for iterating
|
||||
* through all devices with a specific tag type (e.g. LABEL).
|
||||
*/
|
||||
struct blkid_struct_cache
|
||||
{
|
||||
struct list_head bic_devs; /* List head of all devices */
|
||||
struct list_head bic_tags; /* List head of all tag types */
|
||||
time_t bic_time; /* Last probe time */
|
||||
time_t bic_ftime; /* Mod time of the cachefile */
|
||||
unsigned int bic_flags; /* Status flags of the cache */
|
||||
char *bic_filename; /* filename of cache */
|
||||
};
|
||||
|
||||
#define BLKID_BIC_FL_PROBED 0x0002 /* We probed /proc/partition devices */
|
||||
#define BLKID_BIC_FL_CHANGED 0x0004 /* Cache has changed from disk */
|
||||
|
||||
extern char *blkid_strdup(const char *s);
|
||||
extern char *blkid_strndup(const char *s, const int length);
|
||||
|
||||
#define BLKID_CACHE_FILE "/etc/blkid.tab"
|
||||
extern const char *blkid_devdirs[];
|
||||
|
||||
#define BLKID_ERR_IO 5
|
||||
#define BLKID_ERR_PROC 9
|
||||
#define BLKID_ERR_MEM 12
|
||||
#define BLKID_ERR_CACHE 14
|
||||
#define BLKID_ERR_DEV 19
|
||||
#define BLKID_ERR_PARAM 22
|
||||
#define BLKID_ERR_BIG 27
|
||||
|
||||
/*
|
||||
* Priority settings for different types of devices
|
||||
*/
|
||||
#define BLKID_PRI_EVMS 30
|
||||
#define BLKID_PRI_LVM 20
|
||||
#define BLKID_PRI_MD 10
|
||||
|
||||
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
|
||||
#define CONFIG_BLKID_DEBUG
|
||||
#endif
|
||||
|
||||
#define DEBUG_CACHE 0x0001
|
||||
#define DEBUG_DUMP 0x0002
|
||||
#define DEBUG_DEV 0x0004
|
||||
#define DEBUG_DEVNAME 0x0008
|
||||
#define DEBUG_DEVNO 0x0010
|
||||
#define DEBUG_PROBE 0x0020
|
||||
#define DEBUG_READ 0x0040
|
||||
#define DEBUG_RESOLVE 0x0080
|
||||
#define DEBUG_SAVE 0x0100
|
||||
#define DEBUG_TAG 0x0200
|
||||
#define DEBUG_INIT 0x8000
|
||||
#define DEBUG_ALL 0xFFFF
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
#include <stdio.h>
|
||||
extern int blkid_debug_mask;
|
||||
#define DBG(m,x) if ((m) & blkid_debug_mask) x;
|
||||
#else
|
||||
#define DBG(m,x)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
extern void blkid_debug_dump_dev(blkid_dev dev);
|
||||
extern void blkid_debug_dump_tag(blkid_tag tag);
|
||||
#endif
|
||||
|
||||
/* lseek.c */
|
||||
/* extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence); */
|
||||
#ifdef CONFIG_LFS
|
||||
# define blkid_llseek lseek64
|
||||
#else
|
||||
# define blkid_llseek lseek
|
||||
#endif
|
||||
|
||||
/* read.c */
|
||||
extern void blkid_read_cache(blkid_cache cache);
|
||||
|
||||
/* save.c */
|
||||
extern int blkid_flush_cache(blkid_cache cache);
|
||||
|
||||
/*
|
||||
* Functions to create and find a specific tag type: tag.c
|
||||
*/
|
||||
extern void blkid_free_tag(blkid_tag tag);
|
||||
extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
|
||||
extern int blkid_set_tag(blkid_dev dev, const char *name,
|
||||
const char *value, const int vlength);
|
||||
|
||||
/*
|
||||
* Functions to create and find a specific tag type: dev.c
|
||||
*/
|
||||
extern blkid_dev blkid_new_dev(void);
|
||||
extern void blkid_free_dev(blkid_dev dev);
|
||||
|
||||
#endif
|
||||
@@ -1,179 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* getsize.c --- get the size of a partition.
|
||||
*
|
||||
* Copyright (C) 1995, 1995 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
/* include this before sys/queues.h! */
|
||||
#include "blkidP.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_LINUX_FD_H
|
||||
#include <linux/fd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISK_H
|
||||
#ifdef HAVE_SYS_QUEUE_H
|
||||
#include <sys/queue.h> /* for LIST_HEAD */
|
||||
#endif
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
|
||||
#define BLKGETSIZE _IO(0x12,96) /* return device size */
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
|
||||
#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
|
||||
#endif
|
||||
|
||||
#ifdef APPLE_DARWIN
|
||||
#define BLKGETSIZE DKIOCGETBLOCKCOUNT32
|
||||
#endif /* APPLE_DARWIN */
|
||||
|
||||
static int valid_offset(int fd, blkid_loff_t offset)
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (blkid_llseek(fd, offset, 0) < 0)
|
||||
return 0;
|
||||
if (read(fd, &ch, 1) < 1)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the number of blocks in a partition
|
||||
*/
|
||||
blkid_loff_t blkid_get_dev_size(int fd)
|
||||
{
|
||||
int valid_blkgetsize64 = 1;
|
||||
#ifdef __linux__
|
||||
struct utsname ut;
|
||||
#endif
|
||||
unsigned long long size64;
|
||||
unsigned long size;
|
||||
blkid_loff_t high, low;
|
||||
#ifdef FDGETPRM
|
||||
struct floppy_struct this_floppy;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
int part = -1;
|
||||
struct disklabel lab;
|
||||
struct partition *pp;
|
||||
char ch;
|
||||
struct stat st;
|
||||
#endif /* HAVE_SYS_DISKLABEL_H */
|
||||
|
||||
#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
|
||||
if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
|
||||
if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
|
||||
&& (size64 << 9 > 0xFFFFFFFF))
|
||||
return 0; /* EFBIG */
|
||||
return (blkid_loff_t) size64 << 9;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BLKGETSIZE64
|
||||
#ifdef __linux__
|
||||
uname(&ut);
|
||||
if ((ut.release[0] == '2') && (ut.release[1] == '.') &&
|
||||
(ut.release[2] < '6') && (ut.release[3] == '.'))
|
||||
valid_blkgetsize64 = 0;
|
||||
#endif
|
||||
if (valid_blkgetsize64 &&
|
||||
ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
|
||||
if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
|
||||
&& ((size64) > 0xFFFFFFFF))
|
||||
return 0; /* EFBIG */
|
||||
return size64;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BLKGETSIZE
|
||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0)
|
||||
return (blkid_loff_t)size << 9;
|
||||
#endif
|
||||
|
||||
#ifdef FDGETPRM
|
||||
if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
|
||||
return (blkid_loff_t)this_floppy.size << 9;
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISKLABEL_H
|
||||
#if 0
|
||||
/*
|
||||
* This should work in theory but I haven't tested it. Anyone
|
||||
* on a BSD system want to test this for me? In the meantime,
|
||||
* binary search mechanism should work just fine.
|
||||
*/
|
||||
if ((fstat(fd, &st) >= 0) && S_ISBLK(st.st_mode))
|
||||
part = st.st_rdev & 7;
|
||||
if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) {
|
||||
pp = &lab.d_partitions[part];
|
||||
if (pp->p_size)
|
||||
return pp->p_size << 9;
|
||||
}
|
||||
#endif
|
||||
#endif /* HAVE_SYS_DISKLABEL_H */
|
||||
|
||||
/*
|
||||
* OK, we couldn't figure it out by using a specialized ioctl,
|
||||
* which is generally the best way. So do binary search to
|
||||
* find the size of the partition.
|
||||
*/
|
||||
low = 0;
|
||||
for (high = 1024; valid_offset(fd, high); high *= 2)
|
||||
low = high;
|
||||
while (low < high - 1)
|
||||
{
|
||||
const blkid_loff_t mid = (low + high) / 2;
|
||||
|
||||
if (valid_offset(fd, mid))
|
||||
low = mid;
|
||||
else
|
||||
high = mid;
|
||||
}
|
||||
return low + 1;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_loff_t bytes;
|
||||
int fd;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s device\n"
|
||||
"Determine the size of a device\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((fd = open(argv[1], O_RDONLY)) < 0)
|
||||
perror(argv[0]);
|
||||
|
||||
bytes = blkid_get_dev_size(fd);
|
||||
printf("Device %s has %lld 1k blocks.\n", argv[1], bytes >> 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cache.c - allocation/initialization/free routines for cache
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "blkidP.h"
|
||||
|
||||
int blkid_debug_mask = 0;
|
||||
|
||||
int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
|
||||
{
|
||||
blkid_cache cache;
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
if (!(blkid_debug_mask & DEBUG_INIT)) {
|
||||
char *dstr = getenv("BLKID_DEBUG");
|
||||
|
||||
if (dstr)
|
||||
blkid_debug_mask = strtoul(dstr, 0, 0);
|
||||
blkid_debug_mask |= DEBUG_INIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
DBG(DEBUG_CACHE, printf("creating blkid cache (using %s)\n",
|
||||
filename ? filename : "default cache"));
|
||||
|
||||
cache = xzalloc(sizeof(struct blkid_struct_cache));
|
||||
|
||||
INIT_LIST_HEAD(&cache->bic_devs);
|
||||
INIT_LIST_HEAD(&cache->bic_tags);
|
||||
|
||||
if (filename && !strlen(filename))
|
||||
filename = 0;
|
||||
if (!filename && (getuid() == geteuid()))
|
||||
filename = getenv("BLKID_FILE");
|
||||
if (!filename)
|
||||
filename = BLKID_CACHE_FILE;
|
||||
cache->bic_filename = blkid_strdup(filename);
|
||||
|
||||
blkid_read_cache(cache);
|
||||
|
||||
*ret_cache = cache;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blkid_put_cache(blkid_cache cache)
|
||||
{
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
(void) blkid_flush_cache(cache);
|
||||
|
||||
DBG(DEBUG_CACHE, printf("freeing cache struct\n"));
|
||||
|
||||
/* DBG(DEBUG_CACHE, blkid_debug_dump_cache(cache)); */
|
||||
|
||||
while (!list_empty(&cache->bic_devs)) {
|
||||
blkid_dev dev = list_entry(cache->bic_devs.next,
|
||||
struct blkid_struct_dev,
|
||||
bid_devs);
|
||||
blkid_free_dev(dev);
|
||||
}
|
||||
|
||||
while (!list_empty(&cache->bic_tags)) {
|
||||
blkid_tag tag = list_entry(cache->bic_tags.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_tags);
|
||||
|
||||
while (!list_empty(&tag->bit_names)) {
|
||||
blkid_tag bad = list_entry(tag->bit_names.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_names);
|
||||
|
||||
DBG(DEBUG_CACHE, printf("warning: unfreed tag %s=%s\n",
|
||||
bad->bit_name, bad->bit_val));
|
||||
blkid_free_tag(bad);
|
||||
}
|
||||
blkid_free_tag(tag);
|
||||
}
|
||||
free(cache->bic_filename);
|
||||
|
||||
free(cache);
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if ((argc > 2)) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, argv[1])) < 0) {
|
||||
fprintf(stderr, "error %d parsing cache file %s\n", ret,
|
||||
argv[1] ? argv[1] : BLKID_CACHE_FILE);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_probe_all(cache)) < 0)
|
||||
fprintf(stderr, "error probing devices\n");
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -1,213 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* dev.c - allocation/initialization/free routines for dev
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
blkid_dev blkid_new_dev(void)
|
||||
{
|
||||
blkid_dev dev;
|
||||
|
||||
dev = xzalloc(sizeof(struct blkid_struct_dev));
|
||||
|
||||
INIT_LIST_HEAD(&dev->bid_devs);
|
||||
INIT_LIST_HEAD(&dev->bid_tags);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void blkid_free_dev(blkid_dev dev)
|
||||
{
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
DBG(DEBUG_DEV,
|
||||
printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
|
||||
DBG(DEBUG_DEV, blkid_debug_dump_dev(dev));
|
||||
|
||||
list_del(&dev->bid_devs);
|
||||
while (!list_empty(&dev->bid_tags)) {
|
||||
blkid_tag tag = list_entry(dev->bid_tags.next,
|
||||
struct blkid_struct_tag,
|
||||
bit_tags);
|
||||
blkid_free_tag(tag);
|
||||
}
|
||||
if (dev->bid_name)
|
||||
free(dev->bid_name);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a blkid device, return its name
|
||||
*/
|
||||
const char *blkid_dev_devname(blkid_dev dev)
|
||||
{
|
||||
return dev->bid_name;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
void blkid_debug_dump_dev(blkid_dev dev)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!dev) {
|
||||
printf(" dev: NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" dev: name = %s\n", dev->bid_name);
|
||||
printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
|
||||
printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
|
||||
printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
|
||||
printf(" dev: flags = 0x%08X\n", dev->bid_flags);
|
||||
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
if (tag)
|
||||
printf(" tag: %s=\"%s\"\n", tag->bit_name,
|
||||
tag->bit_val);
|
||||
else
|
||||
printf(" tag: NULL\n");
|
||||
}
|
||||
bb_putchar('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* dev iteration routines for the public libblkid interface.
|
||||
*
|
||||
* These routines do not expose the list.h implementation, which are a
|
||||
* contamination of the namespace, and which force us to reveal far, far
|
||||
* too much of our internal implemenation. I'm not convinced I want
|
||||
* to keep list.h in the long term, anyway. It's fine for kernel
|
||||
* programming, but performance is not the #1 priority for this
|
||||
* library, and I really don't like the tradeoff of type-safety for
|
||||
* performance for this application. [tytso:20030125.2007EST]
|
||||
*/
|
||||
|
||||
/*
|
||||
* This series of functions iterate over all devices in a blkid cache
|
||||
*/
|
||||
#define DEV_ITERATE_MAGIC 0x01a5284c
|
||||
|
||||
struct blkid_struct_dev_iterate {
|
||||
int magic;
|
||||
blkid_cache cache;
|
||||
struct list_head *p;
|
||||
};
|
||||
|
||||
blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
|
||||
{
|
||||
blkid_dev_iterate iter;
|
||||
|
||||
iter = xmalloc(sizeof(struct blkid_struct_dev_iterate));
|
||||
iter->magic = DEV_ITERATE_MAGIC;
|
||||
iter->cache = cache;
|
||||
iter->p = cache->bic_devs.next;
|
||||
return iter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 0 on success, -1 on error
|
||||
*/
|
||||
extern int blkid_dev_next(blkid_dev_iterate iter,
|
||||
blkid_dev *dev)
|
||||
{
|
||||
*dev = 0;
|
||||
if (!iter || iter->magic != DEV_ITERATE_MAGIC ||
|
||||
iter->p == &iter->cache->bic_devs)
|
||||
return -1;
|
||||
*dev = list_entry(iter->p, struct blkid_struct_dev, bid_devs);
|
||||
iter->p = iter->p->next;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blkid_dev_iterate_end(blkid_dev_iterate iter)
|
||||
{
|
||||
if (!iter || iter->magic != DEV_ITERATE_MAGIC)
|
||||
return;
|
||||
iter->magic = 0;
|
||||
free(iter);
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
#endif
|
||||
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog);
|
||||
fprintf(stderr, "\tList all devices and exit\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_dev_iterate iter;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev;
|
||||
int c, ret;
|
||||
char *tmp;
|
||||
char *file = NULL;
|
||||
char *search_type = NULL;
|
||||
char *search_value = NULL;
|
||||
|
||||
while ((c = getopt (argc, argv, "m:f:")) != EOF)
|
||||
switch (c) {
|
||||
case 'f':
|
||||
file = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
usage(argv[0]);
|
||||
}
|
||||
if (argc >= optind+2) {
|
||||
search_type = argv[optind];
|
||||
search_value = argv[optind+1];
|
||||
optind += 2;
|
||||
}
|
||||
if (argc != optind)
|
||||
usage(argv[0]);
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, file)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
iter = blkid_dev_iterate_begin(cache);
|
||||
if (search_type)
|
||||
blkid_dev_set_search(iter, search_type, search_value);
|
||||
while (blkid_dev_next(iter, &dev) == 0) {
|
||||
printf("Device: %s\n", blkid_dev_devname(dev));
|
||||
}
|
||||
blkid_dev_iterate_end(iter);
|
||||
|
||||
|
||||
blkid_put_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,367 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* devname.c - get a dev by its device inode name
|
||||
*
|
||||
* Copyright (C) Andries Brouwer
|
||||
* Copyright (C) 1999, 2000, 2001, 2002, 2003 Theodore Ts'o
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
/*
|
||||
* Find a dev struct in the cache by device name, if available.
|
||||
*
|
||||
* If there is no entry with the specified device name, and the create
|
||||
* flag is set, then create an empty device entry.
|
||||
*/
|
||||
blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
||||
{
|
||||
blkid_dev dev = NULL, tmp;
|
||||
struct list_head *p;
|
||||
|
||||
if (!cache || !devname)
|
||||
return NULL;
|
||||
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
|
||||
if (strcmp(tmp->bid_name, devname))
|
||||
continue;
|
||||
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("found devname %s in cache\n", tmp->bid_name));
|
||||
dev = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!dev && (flags & BLKID_DEV_CREATE)) {
|
||||
dev = blkid_new_dev();
|
||||
if (!dev)
|
||||
return NULL;
|
||||
dev->bid_name = blkid_strdup(devname);
|
||||
dev->bid_cache = cache;
|
||||
list_add_tail(&dev->bid_devs, &cache->bic_devs);
|
||||
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
||||
}
|
||||
|
||||
if (flags & BLKID_DEV_VERIFY)
|
||||
dev = blkid_verify(cache, dev);
|
||||
return dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Probe a single block device to add to the device cache.
|
||||
*/
|
||||
static void probe_one(blkid_cache cache, const char *ptname,
|
||||
dev_t devno, int pri)
|
||||
{
|
||||
blkid_dev dev = NULL;
|
||||
struct list_head *p;
|
||||
const char **dir;
|
||||
char *devname = NULL;
|
||||
|
||||
/* See if we already have this device number in the cache. */
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
|
||||
bid_devs);
|
||||
if (tmp->bid_devno == devno) {
|
||||
dev = blkid_verify(cache, tmp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dev && dev->bid_devno == devno)
|
||||
goto set_pri;
|
||||
|
||||
/*
|
||||
* Take a quick look at /dev/ptname for the device number. We check
|
||||
* all of the likely device directories. If we don't find it, or if
|
||||
* the stat information doesn't check out, use blkid_devno_to_devname()
|
||||
* to find it via an exhaustive search for the device major/minor.
|
||||
*/
|
||||
for (dir = blkid_devdirs; *dir; dir++) {
|
||||
struct stat st;
|
||||
char device[256];
|
||||
|
||||
sprintf(device, "%s/%s", *dir, ptname);
|
||||
if ((dev = blkid_get_dev(cache, device, BLKID_DEV_FIND)) &&
|
||||
dev->bid_devno == devno)
|
||||
goto set_pri;
|
||||
|
||||
if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
|
||||
st.st_rdev == devno) {
|
||||
devname = blkid_strdup(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!devname) {
|
||||
devname = blkid_devno_to_devname(devno);
|
||||
if (!devname)
|
||||
return;
|
||||
}
|
||||
dev = blkid_get_dev(cache, devname, BLKID_DEV_NORMAL);
|
||||
free(devname);
|
||||
|
||||
set_pri:
|
||||
if (!pri && !strncmp(ptname, "md", 2))
|
||||
pri = BLKID_PRI_MD;
|
||||
if (dev)
|
||||
dev->bid_pri = pri;
|
||||
}
|
||||
|
||||
#define PROC_PARTITIONS "/proc/partitions"
|
||||
#define VG_DIR "/proc/lvm/VGs"
|
||||
|
||||
/*
|
||||
* This function initializes the UUID cache with devices from the LVM
|
||||
* proc hierarchy. We currently depend on the names of the LVM
|
||||
* hierarchy giving us the device structure in /dev. (XXX is this a
|
||||
* safe thing to do?)
|
||||
*/
|
||||
#ifdef VG_DIR
|
||||
#include <dirent.h>
|
||||
static dev_t lvm_get_devno(const char *lvm_device)
|
||||
{
|
||||
FILE *lvf;
|
||||
char buf[1024];
|
||||
int ma, mi;
|
||||
dev_t ret = 0;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
|
||||
if ((lvf = fopen_for_read(lvm_device)) == NULL) {
|
||||
DBG(DEBUG_DEVNAME, printf("%s: (%d) %s\n", lvm_device, errno,
|
||||
strerror(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(buf, sizeof(buf), lvf)) {
|
||||
if (sscanf(buf, "device: %d:%d", &ma, &mi) == 2) {
|
||||
ret = makedev(ma, mi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(lvf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void lvm_probe_all(blkid_cache cache)
|
||||
{
|
||||
DIR *vg_list;
|
||||
struct dirent *vg_iter;
|
||||
int vg_len = strlen(VG_DIR);
|
||||
dev_t dev;
|
||||
|
||||
if ((vg_list = opendir(VG_DIR)) == NULL)
|
||||
return;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("probing LVM devices under %s\n", VG_DIR));
|
||||
|
||||
while ((vg_iter = readdir(vg_list)) != NULL) {
|
||||
DIR *lv_list;
|
||||
char *vdirname;
|
||||
char *vg_name;
|
||||
struct dirent *lv_iter;
|
||||
|
||||
vg_name = vg_iter->d_name;
|
||||
if (LONE_CHAR(vg_name, '.') || !strcmp(vg_name, ".."))
|
||||
continue;
|
||||
vdirname = xmalloc(vg_len + strlen(vg_name) + 8);
|
||||
sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
|
||||
|
||||
lv_list = opendir(vdirname);
|
||||
free(vdirname);
|
||||
if (lv_list == NULL)
|
||||
continue;
|
||||
|
||||
while ((lv_iter = readdir(lv_list)) != NULL) {
|
||||
char *lv_name, *lvm_device;
|
||||
|
||||
lv_name = lv_iter->d_name;
|
||||
if (LONE_CHAR(lv_name, '.') || !strcmp(lv_name, ".."))
|
||||
continue;
|
||||
|
||||
lvm_device = xmalloc(vg_len + strlen(vg_name) +
|
||||
strlen(lv_name) + 8);
|
||||
sprintf(lvm_device, "%s/%s/LVs/%s", VG_DIR, vg_name,
|
||||
lv_name);
|
||||
dev = lvm_get_devno(lvm_device);
|
||||
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
|
||||
DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
|
||||
lvm_device,
|
||||
(unsigned int) dev));
|
||||
probe_one(cache, lvm_device, dev, BLKID_PRI_LVM);
|
||||
free(lvm_device);
|
||||
}
|
||||
closedir(lv_list);
|
||||
}
|
||||
closedir(vg_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
|
||||
|
||||
static int
|
||||
evms_probe_all(blkid_cache cache)
|
||||
{
|
||||
char line[100];
|
||||
int ma, mi, sz, num = 0;
|
||||
FILE *procpt;
|
||||
char device[110];
|
||||
|
||||
procpt = fopen_for_read(PROC_EVMS_VOLUMES);
|
||||
if (!procpt)
|
||||
return 0;
|
||||
while (fgets(line, sizeof(line), procpt)) {
|
||||
if (sscanf(line, " %d %d %d %*s %*s %[^\n ]",
|
||||
&ma, &mi, &sz, device) != 4)
|
||||
continue;
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
|
||||
device, ma, mi));
|
||||
|
||||
probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS);
|
||||
num++;
|
||||
}
|
||||
fclose(procpt);
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the device data for all available block devices in the system.
|
||||
*/
|
||||
int blkid_probe_all(blkid_cache cache)
|
||||
{
|
||||
FILE *proc;
|
||||
char line[1024];
|
||||
char ptname0[128], ptname1[128], *ptname = NULL;
|
||||
char *ptnames[2];
|
||||
dev_t devs[2];
|
||||
int ma, mi;
|
||||
unsigned long long sz;
|
||||
int lens[2] = { 0, 0 };
|
||||
int which = 0, last = 0;
|
||||
|
||||
ptnames[0] = ptname0;
|
||||
ptnames[1] = ptname1;
|
||||
|
||||
if (!cache)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (cache->bic_flags & BLKID_BIC_FL_PROBED &&
|
||||
time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL)
|
||||
return 0;
|
||||
|
||||
blkid_read_cache(cache);
|
||||
evms_probe_all(cache);
|
||||
#ifdef VG_DIR
|
||||
lvm_probe_all(cache);
|
||||
#endif
|
||||
|
||||
proc = fopen_for_read(PROC_PARTITIONS);
|
||||
if (!proc)
|
||||
return -BLKID_ERR_PROC;
|
||||
|
||||
while (fgets(line, sizeof(line), proc)) {
|
||||
last = which;
|
||||
which ^= 1;
|
||||
ptname = ptnames[which];
|
||||
|
||||
if (sscanf(line, " %d %d %llu %128[^\n ]",
|
||||
&ma, &mi, &sz, ptname) != 4)
|
||||
continue;
|
||||
devs[which] = makedev(ma, mi);
|
||||
|
||||
DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname));
|
||||
|
||||
/* Skip whole disk devs unless they have no partitions
|
||||
* If we don't have a partition on this dev, also
|
||||
* check previous dev to see if it didn't have a partn.
|
||||
* heuristic: partition name ends in a digit.
|
||||
*
|
||||
* Skip extended partitions.
|
||||
* heuristic: size is 1
|
||||
*
|
||||
* FIXME: skip /dev/{ida,cciss,rd} whole-disk devs
|
||||
*/
|
||||
|
||||
lens[which] = strlen(ptname);
|
||||
if (isdigit(ptname[lens[which] - 1])) {
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("partition dev %s, devno 0x%04X\n",
|
||||
ptname, (unsigned int) devs[which]));
|
||||
|
||||
if (sz > 1)
|
||||
probe_one(cache, ptname, devs[which], 0);
|
||||
lens[which] = 0;
|
||||
lens[last] = 0;
|
||||
} else if (lens[last] && strncmp(ptnames[last], ptname,
|
||||
lens[last])) {
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("whole dev %s, devno 0x%04X\n",
|
||||
ptnames[last], (unsigned int) devs[last]));
|
||||
probe_one(cache, ptnames[last], devs[last], 0);
|
||||
lens[last] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the last device if it wasn't partitioned */
|
||||
if (lens[which])
|
||||
probe_one(cache, ptname, devs[which], 0);
|
||||
|
||||
fclose(proc);
|
||||
|
||||
cache->bic_time = time(NULL);
|
||||
cache->bic_flags |= BLKID_BIC_FL_PROBED;
|
||||
blkid_flush_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Usage: %s\n"
|
||||
"Probe all devices and exit\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if (blkid_probe_all(cache) < 0)
|
||||
printf("%s: error probing devices\n", argv[0]);
|
||||
|
||||
blkid_put_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,222 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* devno.c - find a particular device by its device number (major/minor)
|
||||
*
|
||||
* Copyright (C) 2000, 2001, 2003 Theodore Ts'o
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
struct dir_list {
|
||||
char *name;
|
||||
struct dir_list *next;
|
||||
};
|
||||
|
||||
char *blkid_strndup(const char *s, int length)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
if (!length)
|
||||
length = strlen(s);
|
||||
|
||||
ret = xmalloc(length + 1);
|
||||
strncpy(ret, s, length);
|
||||
ret[length] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *blkid_strdup(const char *s)
|
||||
{
|
||||
return blkid_strndup(s, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function adds an entry to the directory list
|
||||
*/
|
||||
static void add_to_dirlist(const char *name, struct dir_list **list)
|
||||
{
|
||||
struct dir_list *dp;
|
||||
|
||||
dp = xmalloc(sizeof(struct dir_list));
|
||||
dp->name = blkid_strdup(name);
|
||||
dp->next = *list;
|
||||
*list = dp;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function frees a directory list
|
||||
*/
|
||||
static void free_dirlist(struct dir_list **list)
|
||||
{
|
||||
struct dir_list *dp, *next;
|
||||
|
||||
for (dp = *list; dp; dp = next) {
|
||||
next = dp->next;
|
||||
free(dp->name);
|
||||
free(dp);
|
||||
}
|
||||
*list = NULL;
|
||||
}
|
||||
|
||||
static void scan_dir(char *dir_name, dev_t devno, struct dir_list **list,
|
||||
char **devname)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *dp;
|
||||
char path[1024];
|
||||
int dirlen;
|
||||
struct stat st;
|
||||
|
||||
if ((dir = opendir(dir_name)) == NULL)
|
||||
return;
|
||||
dirlen = strlen(dir_name) + 2;
|
||||
while ((dp = readdir(dir)) != 0) {
|
||||
if (dirlen + strlen(dp->d_name) >= sizeof(path))
|
||||
continue;
|
||||
|
||||
if (dp->d_name[0] == '.' &&
|
||||
((dp->d_name[1] == 0) ||
|
||||
((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
|
||||
continue;
|
||||
|
||||
sprintf(path, "%s/%s", dir_name, dp->d_name);
|
||||
if (stat(path, &st) < 0)
|
||||
continue;
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
add_to_dirlist(path, list);
|
||||
else if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
|
||||
*devname = blkid_strdup(path);
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found 0x%llx at %s (%p)\n", devno,
|
||||
path, *devname));
|
||||
break;
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
/* Directories where we will try to search for device numbers */
|
||||
const char *blkid_devdirs[] = { "/devices", "/devfs", "/dev", NULL };
|
||||
|
||||
/*
|
||||
* This function finds the pathname to a block device with a given
|
||||
* device number. It returns a pointer to allocated memory to the
|
||||
* pathname on success, and NULL on failure.
|
||||
*/
|
||||
char *blkid_devno_to_devname(dev_t devno)
|
||||
{
|
||||
struct dir_list *list = NULL, *new_list = NULL;
|
||||
char *devname = NULL;
|
||||
const char **dir;
|
||||
|
||||
/*
|
||||
* Add the starting directories to search in reverse order of
|
||||
* importance, since we are using a stack...
|
||||
*/
|
||||
for (dir = blkid_devdirs; *dir; dir++)
|
||||
add_to_dirlist(*dir, &list);
|
||||
|
||||
while (list) {
|
||||
struct dir_list *current = list;
|
||||
|
||||
list = list->next;
|
||||
DBG(DEBUG_DEVNO, printf("directory %s\n", current->name));
|
||||
scan_dir(current->name, devno, &new_list, &devname);
|
||||
free(current->name);
|
||||
free(current);
|
||||
if (devname)
|
||||
break;
|
||||
/*
|
||||
* If we're done checking at this level, descend to
|
||||
* the next level of subdirectories. (breadth-first)
|
||||
*/
|
||||
if (list == NULL) {
|
||||
list = new_list;
|
||||
new_list = NULL;
|
||||
}
|
||||
}
|
||||
free_dirlist(&list);
|
||||
free_dirlist(&new_list);
|
||||
|
||||
if (!devname) {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("blkid: cannot find devno 0x%04lx\n",
|
||||
(unsigned long) devno));
|
||||
} else {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found devno 0x%04llx as %s\n", devno, devname));
|
||||
}
|
||||
|
||||
|
||||
return devname;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char *devname, *tmp;
|
||||
int major, minor;
|
||||
dev_t devno;
|
||||
const char *errmsg = "Cannot parse %s: %s\n";
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if ((argc != 2) && (argc != 3)) {
|
||||
fprintf(stderr, "Usage:\t%s device_number\n\t%s major minor\n"
|
||||
"Resolve a device number to a device name\n",
|
||||
argv[0], argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (argc == 2) {
|
||||
devno = strtoul(argv[1], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "device number", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
major = strtoul(argv[1], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "major number", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
minor = strtoul(argv[2], &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, errmsg, "minor number", argv[2]);
|
||||
exit(1);
|
||||
}
|
||||
devno = makedev(major, minor);
|
||||
}
|
||||
printf("Looking for device 0x%04Lx\n", devno);
|
||||
devname = blkid_devno_to_devname(devno);
|
||||
free(devname);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
|
||||
#include "list.h"
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
void __list_add(struct list_head * add,
|
||||
struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = add;
|
||||
add->next = next;
|
||||
add->prev = prev;
|
||||
prev->next = add;
|
||||
}
|
||||
|
||||
/*
|
||||
* list_add - add a new entry
|
||||
* @add: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
void list_add(struct list_head *add, struct list_head *head)
|
||||
{
|
||||
__list_add(add, head, head->next);
|
||||
}
|
||||
|
||||
/*
|
||||
* list_add_tail - add a new entry
|
||||
* @add: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
void list_add_tail(struct list_head *add, struct list_head *head)
|
||||
{
|
||||
__list_add(add, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
void __list_del(struct list_head * prev, struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/*
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
*
|
||||
* list_empty() on @entry does not return true after this, @entry is
|
||||
* in an undefined state.
|
||||
*/
|
||||
void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/*
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/*
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/*
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
|
||||
if (first != list) {
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#if !defined(_BLKID_LIST_H) && !defined(LIST_HEAD)
|
||||
#define BLKID_LIST_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
void __list_add(struct list_head * add, struct list_head * prev, struct list_head * next);
|
||||
void list_add(struct list_head *add, struct list_head *head);
|
||||
void list_add_tail(struct list_head *add, struct list_head *head);
|
||||
void __list_del(struct list_head * prev, struct list_head * next);
|
||||
void list_del(struct list_head *entry);
|
||||
void list_del_init(struct list_head *entry);
|
||||
int list_empty(struct list_head *head);
|
||||
void list_splice(struct list_head *list, struct list_head *head);
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over elements in a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over elements in a list, but don't dereference
|
||||
* pos after the body is done (in case it is freed)
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @pnext: the &struct list_head to use as a pointer to the next item.
|
||||
* @head: the head for your list (not included in iteration).
|
||||
*/
|
||||
#define list_for_each_safe(pos, pnext, head) \
|
||||
for (pos = (head)->next, pnext = pos->next; pos != (head); \
|
||||
pos = pnext, pnext = pos->next)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,726 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* probe.c - identify a block device by its contents, and return a dev
|
||||
* struct with the details
|
||||
*
|
||||
* Copyright (C) 1999 by Andries Brouwer
|
||||
* Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
|
||||
* Copyright (C) 2001 by Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include "blkidP.h"
|
||||
#include "../uuid/uuid.h"
|
||||
#include "probe.h"
|
||||
|
||||
/*
|
||||
* This is a special case code to check for an MDRAID device. We do
|
||||
* this special since it requires checking for a superblock at the end
|
||||
* of the device.
|
||||
*/
|
||||
static int check_mdraid(int fd, unsigned char *ret_uuid)
|
||||
{
|
||||
struct mdp_superblock_s *md;
|
||||
blkid_loff_t offset;
|
||||
char buf[4096];
|
||||
|
||||
if (fd < 0)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
offset = (blkid_get_dev_size(fd) & ~((blkid_loff_t)65535)) - 65536;
|
||||
|
||||
if (blkid_llseek(fd, offset, 0) < 0 ||
|
||||
read(fd, buf, 4096) != 4096)
|
||||
return -BLKID_ERR_IO;
|
||||
|
||||
/* Check for magic number */
|
||||
if (memcmp("\251+N\374", buf, 4))
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (!ret_uuid)
|
||||
return 0;
|
||||
*ret_uuid = 0;
|
||||
|
||||
/* The MD UUID is not contiguous in the superblock, make it so */
|
||||
md = (struct mdp_superblock_s *)buf;
|
||||
if (md->set_uuid0 || md->set_uuid1 || md->set_uuid2 || md->set_uuid3) {
|
||||
memcpy(ret_uuid, &md->set_uuid0, 4);
|
||||
memcpy(ret_uuid, &md->set_uuid1, 12);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void set_uuid(blkid_dev dev, uuid_t uuid)
|
||||
{
|
||||
char str[37];
|
||||
|
||||
if (!uuid_is_null(uuid)) {
|
||||
uuid_unparse(uuid, str);
|
||||
blkid_set_tag(dev, "UUID", str, sizeof(str));
|
||||
}
|
||||
}
|
||||
|
||||
static void get_ext2_info(blkid_dev dev, unsigned char *buf)
|
||||
{
|
||||
struct ext2_super_block *es = (struct ext2_super_block *) buf;
|
||||
const char *label = NULL;
|
||||
|
||||
DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
|
||||
blkid_le32(es->s_feature_compat),
|
||||
blkid_le32(es->s_feature_incompat),
|
||||
blkid_le32(es->s_feature_ro_compat)));
|
||||
|
||||
if (strlen(es->s_volume_name))
|
||||
label = es->s_volume_name;
|
||||
blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
|
||||
|
||||
set_uuid(dev, es->s_uuid);
|
||||
}
|
||||
|
||||
static int probe_ext3(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct ext2_super_block *es;
|
||||
|
||||
es = (struct ext2_super_block *)buf;
|
||||
|
||||
/* Distinguish between jbd and ext2/3 fs */
|
||||
if (blkid_le32(es->s_feature_incompat) &
|
||||
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
/* Distinguish between ext3 and ext2 */
|
||||
if (!(blkid_le32(es->s_feature_compat) &
|
||||
EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
get_ext2_info(dev, buf);
|
||||
|
||||
blkid_set_tag(dev, "SEC_TYPE", "ext2", sizeof("ext2"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_ext2(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct ext2_super_block *es;
|
||||
|
||||
es = (struct ext2_super_block *)buf;
|
||||
|
||||
/* Distinguish between jbd and ext2/3 fs */
|
||||
if (blkid_le32(es->s_feature_incompat) &
|
||||
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
get_ext2_info(dev, buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_jbd(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct ext2_super_block *es = (struct ext2_super_block *) buf;
|
||||
|
||||
if (!(blkid_le32(es->s_feature_incompat) &
|
||||
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
get_ext2_info(dev, buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_vfat(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct vfat_super_block *vs;
|
||||
char serno[10];
|
||||
const char *label = NULL;
|
||||
int label_len = 0;
|
||||
|
||||
vs = (struct vfat_super_block *)buf;
|
||||
|
||||
if (strncmp(vs->vs_label, "NO NAME", 7)) {
|
||||
char *end = vs->vs_label + sizeof(vs->vs_label) - 1;
|
||||
|
||||
while (*end == ' ' && end >= vs->vs_label)
|
||||
--end;
|
||||
if (end >= vs->vs_label) {
|
||||
label = vs->vs_label;
|
||||
label_len = end - vs->vs_label + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We can't just print them as %04X, because they are unaligned */
|
||||
sprintf(serno, "%02X%02X-%02X%02X", vs->vs_serno[3], vs->vs_serno[2],
|
||||
vs->vs_serno[1], vs->vs_serno[0]);
|
||||
blkid_set_tag(dev, "LABEL", label, label_len);
|
||||
blkid_set_tag(dev, "UUID", serno, sizeof(serno));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_msdos(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct msdos_super_block *ms = (struct msdos_super_block *) buf;
|
||||
char serno[10];
|
||||
const char *label = NULL;
|
||||
int label_len = 0;
|
||||
|
||||
if (strncmp(ms->ms_label, "NO NAME", 7)) {
|
||||
char *end = ms->ms_label + sizeof(ms->ms_label) - 1;
|
||||
|
||||
while (*end == ' ' && end >= ms->ms_label)
|
||||
--end;
|
||||
if (end >= ms->ms_label) {
|
||||
label = ms->ms_label;
|
||||
label_len = end - ms->ms_label + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We can't just print them as %04X, because they are unaligned */
|
||||
sprintf(serno, "%02X%02X-%02X%02X", ms->ms_serno[3], ms->ms_serno[2],
|
||||
ms->ms_serno[1], ms->ms_serno[0]);
|
||||
blkid_set_tag(dev, "UUID", serno, 0);
|
||||
blkid_set_tag(dev, "LABEL", label, label_len);
|
||||
blkid_set_tag(dev, "SEC_TYPE", "msdos", sizeof("msdos"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_xfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct xfs_super_block *xs;
|
||||
const char *label = NULL;
|
||||
|
||||
xs = (struct xfs_super_block *)buf;
|
||||
|
||||
if (strlen(xs->xs_fname))
|
||||
label = xs->xs_fname;
|
||||
blkid_set_tag(dev, "LABEL", label, sizeof(xs->xs_fname));
|
||||
set_uuid(dev, xs->xs_uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_reiserfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id, unsigned char *buf)
|
||||
{
|
||||
struct reiserfs_super_block *rs = (struct reiserfs_super_block *) buf;
|
||||
unsigned int blocksize;
|
||||
const char *label = NULL;
|
||||
|
||||
blocksize = blkid_le16(rs->rs_blocksize);
|
||||
|
||||
/* If the superblock is inside the journal, we have the wrong one */
|
||||
if (id->bim_kboff/(blocksize>>10) > blkid_le32(rs->rs_journal_block))
|
||||
return -BLKID_ERR_BIG;
|
||||
|
||||
/* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
|
||||
if (!strcmp(id->bim_magic, "ReIsEr2Fs") ||
|
||||
!strcmp(id->bim_magic, "ReIsEr3Fs")) {
|
||||
if (strlen(rs->rs_label))
|
||||
label = rs->rs_label;
|
||||
set_uuid(dev, rs->rs_uuid);
|
||||
}
|
||||
blkid_set_tag(dev, "LABEL", label, sizeof(rs->rs_label));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_jfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct jfs_super_block *js;
|
||||
const char *label = NULL;
|
||||
|
||||
js = (struct jfs_super_block *)buf;
|
||||
|
||||
if (strlen((char *) js->js_label))
|
||||
label = (char *) js->js_label;
|
||||
blkid_set_tag(dev, "LABEL", label, sizeof(js->js_label));
|
||||
set_uuid(dev, js->js_uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_romfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct romfs_super_block *ros;
|
||||
const char *label = NULL;
|
||||
|
||||
ros = (struct romfs_super_block *)buf;
|
||||
|
||||
if (strlen((char *) ros->ros_volume))
|
||||
label = (char *) ros->ros_volume;
|
||||
blkid_set_tag(dev, "LABEL", label, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_cramfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct cramfs_super_block *csb;
|
||||
const char *label = NULL;
|
||||
|
||||
csb = (struct cramfs_super_block *)buf;
|
||||
|
||||
if (strlen((char *) csb->name))
|
||||
label = (char *) csb->name;
|
||||
blkid_set_tag(dev, "LABEL", label, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_swap0(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf __BLKID_ATTR((unused)))
|
||||
{
|
||||
blkid_set_tag(dev, "UUID", 0, 0);
|
||||
blkid_set_tag(dev, "LABEL", 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_swap1(int fd,
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf __BLKID_ATTR((unused)))
|
||||
{
|
||||
struct swap_id_block *sws;
|
||||
|
||||
probe_swap0(fd, cache, dev, id, buf);
|
||||
/*
|
||||
* Version 1 swap headers are always located at offset of 1024
|
||||
* bytes, although the swap signature itself is located at the
|
||||
* end of the page (which may vary depending on hardware
|
||||
* pagesize).
|
||||
*/
|
||||
if (lseek(fd, 1024, SEEK_SET) < 0) return 1;
|
||||
sws = xmalloc(1024);
|
||||
if (read(fd, sws, 1024) != 1024) {
|
||||
free(sws);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* arbitrary sanity check.. is there any garbage down there? */
|
||||
if (sws->sws_pad[32] == 0 && sws->sws_pad[33] == 0) {
|
||||
if (sws->sws_volume[0])
|
||||
blkid_set_tag(dev, "LABEL", (const char*)sws->sws_volume,
|
||||
sizeof(sws->sws_volume));
|
||||
if (sws->sws_uuid[0])
|
||||
set_uuid(dev, sws->sws_uuid);
|
||||
}
|
||||
free(sws);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char
|
||||
* const udf_magic[] = { "BEA01", "BOOT2", "CD001", "CDW02", "NSR02",
|
||||
"NSR03", "TEA01", 0 };
|
||||
|
||||
static int probe_udf(int fd, blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev __BLKID_ATTR((unused)),
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf __BLKID_ATTR((unused)))
|
||||
{
|
||||
int j, bs;
|
||||
struct iso_volume_descriptor isosb;
|
||||
const char *const *m;
|
||||
|
||||
/* determine the block size by scanning in 2K increments
|
||||
(block sizes larger than 2K will be null padded) */
|
||||
for (bs = 1; bs < 16; bs++) {
|
||||
lseek(fd, bs*2048+32768, SEEK_SET);
|
||||
if (read(fd, (char *)&isosb, sizeof(isosb)) != sizeof(isosb))
|
||||
return 1;
|
||||
if (isosb.id[0])
|
||||
break;
|
||||
}
|
||||
|
||||
/* Scan up to another 64 blocks looking for additional VSD's */
|
||||
for (j = 1; j < 64; j++) {
|
||||
if (j > 1) {
|
||||
lseek(fd, j*bs*2048+32768, SEEK_SET);
|
||||
if (read(fd, (char *)&isosb, sizeof(isosb))
|
||||
!= sizeof(isosb))
|
||||
return 1;
|
||||
}
|
||||
/* If we find NSR0x then call it udf:
|
||||
NSR01 for UDF 1.00
|
||||
NSR02 for UDF 1.50
|
||||
NSR03 for UDF 2.00 */
|
||||
if (!strncmp(isosb.id, "NSR0", 4))
|
||||
return 0;
|
||||
for (m = udf_magic; *m; m++)
|
||||
if (!strncmp(*m, isosb.id, 5))
|
||||
break;
|
||||
if (*m == 0)
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int probe_ocfs(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct ocfs_volume_header ovh;
|
||||
struct ocfs_volume_label ovl;
|
||||
__u32 major;
|
||||
|
||||
memcpy(&ovh, buf, sizeof(ovh));
|
||||
memcpy(&ovl, buf+512, sizeof(ovl));
|
||||
|
||||
major = ocfsmajor(ovh);
|
||||
if (major == 1)
|
||||
blkid_set_tag(dev, "SEC_TYPE", "ocfs1", sizeof("ocfs1"));
|
||||
else if (major >= 9)
|
||||
blkid_set_tag(dev, "SEC_TYPE", "ntocfs", sizeof("ntocfs"));
|
||||
|
||||
blkid_set_tag(dev, "LABEL", (const char*)ovl.label, ocfslabellen(ovl));
|
||||
blkid_set_tag(dev, "MOUNT", (const char*)ovh.mount, ocfsmountlen(ovh));
|
||||
set_uuid(dev, ovl.vol_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_ocfs2(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct ocfs2_super_block *osb;
|
||||
|
||||
osb = (struct ocfs2_super_block *)buf;
|
||||
|
||||
blkid_set_tag(dev, "LABEL", (const char*)osb->s_label, sizeof(osb->s_label));
|
||||
set_uuid(dev, osb->s_uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int probe_oracleasm(int fd __BLKID_ATTR((unused)),
|
||||
blkid_cache cache __BLKID_ATTR((unused)),
|
||||
blkid_dev dev,
|
||||
const struct blkid_magic *id __BLKID_ATTR((unused)),
|
||||
unsigned char *buf)
|
||||
{
|
||||
struct oracle_asm_disk_label *dl;
|
||||
|
||||
dl = (struct oracle_asm_disk_label *)buf;
|
||||
|
||||
blkid_set_tag(dev, "LABEL", dl->dl_id, sizeof(dl->dl_id));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* BLKID_BLK_OFFS is at least as large as the highest bim_kboff defined
|
||||
* in the type_array table below + bim_kbalign.
|
||||
*
|
||||
* When probing for a lot of magics, we handle everything in 1kB buffers so
|
||||
* that we don't have to worry about reading each combination of block sizes.
|
||||
*/
|
||||
#define BLKID_BLK_OFFS 64 /* currently reiserfs */
|
||||
|
||||
/*
|
||||
* Various filesystem magics that we can check for. Note that kboff and
|
||||
* sboff are in kilobytes and bytes respectively. All magics are in
|
||||
* byte strings so we don't worry about endian issues.
|
||||
*/
|
||||
static const struct blkid_magic type_array[] = {
|
||||
/* type kboff sboff len magic probe */
|
||||
{ "oracleasm", 0, 32, 8, "ORCLDISK", probe_oracleasm },
|
||||
{ "ntfs", 0, 3, 8, "NTFS ", 0 },
|
||||
{ "jbd", 1, 0x38, 2, "\123\357", probe_jbd },
|
||||
{ "ext3", 1, 0x38, 2, "\123\357", probe_ext3 },
|
||||
{ "ext2", 1, 0x38, 2, "\123\357", probe_ext2 },
|
||||
{ "reiserfs", 8, 0x34, 8, "ReIsErFs", probe_reiserfs },
|
||||
{ "reiserfs", 64, 0x34, 9, "ReIsEr2Fs", probe_reiserfs },
|
||||
{ "reiserfs", 64, 0x34, 9, "ReIsEr3Fs", probe_reiserfs },
|
||||
{ "reiserfs", 64, 0x34, 8, "ReIsErFs", probe_reiserfs },
|
||||
{ "reiserfs", 8, 20, 8, "ReIsErFs", probe_reiserfs },
|
||||
{ "vfat", 0, 0x52, 5, "MSWIN", probe_vfat },
|
||||
{ "vfat", 0, 0x52, 8, "FAT32 ", probe_vfat },
|
||||
{ "vfat", 0, 0x36, 5, "MSDOS", probe_msdos },
|
||||
{ "vfat", 0, 0x36, 8, "FAT16 ", probe_msdos },
|
||||
{ "vfat", 0, 0x36, 8, "FAT12 ", probe_msdos },
|
||||
{ "minix", 1, 0x10, 2, "\177\023", 0 },
|
||||
{ "minix", 1, 0x10, 2, "\217\023", 0 },
|
||||
{ "minix", 1, 0x10, 2, "\150\044", 0 },
|
||||
{ "minix", 1, 0x10, 2, "\170\044", 0 },
|
||||
{ "vxfs", 1, 0, 4, "\365\374\001\245", 0 },
|
||||
{ "xfs", 0, 0, 4, "XFSB", probe_xfs },
|
||||
{ "romfs", 0, 0, 8, "-rom1fs-", probe_romfs },
|
||||
{ "bfs", 0, 0, 4, "\316\372\173\033", 0 },
|
||||
{ "cramfs", 0, 0, 4, "E=\315\050", probe_cramfs },
|
||||
{ "qnx4", 0, 4, 6, "QNX4FS", 0 },
|
||||
{ "udf", 32, 1, 5, "BEA01", probe_udf },
|
||||
{ "udf", 32, 1, 5, "BOOT2", probe_udf },
|
||||
{ "udf", 32, 1, 5, "CD001", probe_udf },
|
||||
{ "udf", 32, 1, 5, "CDW02", probe_udf },
|
||||
{ "udf", 32, 1, 5, "NSR02", probe_udf },
|
||||
{ "udf", 32, 1, 5, "NSR03", probe_udf },
|
||||
{ "udf", 32, 1, 5, "TEA01", probe_udf },
|
||||
{ "iso9660", 32, 1, 5, "CD001", 0 },
|
||||
{ "iso9660", 32, 9, 5, "CDROM", 0 },
|
||||
{ "jfs", 32, 0, 4, "JFS1", probe_jfs },
|
||||
{ "hfs", 1, 0, 2, "BD", 0 },
|
||||
{ "ufs", 8, 0x55c, 4, "T\031\001\000", 0 },
|
||||
{ "hpfs", 8, 0, 4, "I\350\225\371", 0 },
|
||||
{ "sysv", 0, 0x3f8, 4, "\020~\030\375", 0 },
|
||||
{ "swap", 0, 0xff6, 10, "SWAP-SPACE", probe_swap0 },
|
||||
{ "swap", 0, 0xff6, 10, "SWAPSPACE2", probe_swap1 },
|
||||
{ "swap", 0, 0x1ff6, 10, "SWAP-SPACE", probe_swap0 },
|
||||
{ "swap", 0, 0x1ff6, 10, "SWAPSPACE2", probe_swap1 },
|
||||
{ "swap", 0, 0x3ff6, 10, "SWAP-SPACE", probe_swap0 },
|
||||
{ "swap", 0, 0x3ff6, 10, "SWAPSPACE2", probe_swap1 },
|
||||
{ "swap", 0, 0x7ff6, 10, "SWAP-SPACE", probe_swap0 },
|
||||
{ "swap", 0, 0x7ff6, 10, "SWAPSPACE2", probe_swap1 },
|
||||
{ "swap", 0, 0xfff6, 10, "SWAP-SPACE", probe_swap0 },
|
||||
{ "swap", 0, 0xfff6, 10, "SWAPSPACE2", probe_swap1 },
|
||||
{ "ocfs", 0, 8, 9, "OracleCFS", probe_ocfs },
|
||||
{ "ocfs2", 1, 0, 6, "OCFSV2", probe_ocfs2 },
|
||||
{ "ocfs2", 2, 0, 6, "OCFSV2", probe_ocfs2 },
|
||||
{ "ocfs2", 4, 0, 6, "OCFSV2", probe_ocfs2 },
|
||||
{ "ocfs2", 8, 0, 6, "OCFSV2", probe_ocfs2 },
|
||||
{ NULL, 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* Verify that the data in dev is consistent with what is on the actual
|
||||
* block device (using the devname field only). Normally this will be
|
||||
* called when finding items in the cache, but for long running processes
|
||||
* is also desirable to revalidate an item before use.
|
||||
*
|
||||
* If we are unable to revalidate the data, we return the old data and
|
||||
* do not set the BLKID_BID_FL_VERIFIED flag on it.
|
||||
*/
|
||||
blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
|
||||
{
|
||||
const struct blkid_magic *id;
|
||||
unsigned char *bufs[BLKID_BLK_OFFS + 1], *buf;
|
||||
const char *type;
|
||||
struct stat st;
|
||||
time_t diff, now;
|
||||
int fd, idx;
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
now = time(NULL);
|
||||
diff = now - dev->bid_time;
|
||||
|
||||
if ((now < dev->bid_time) ||
|
||||
(diff < BLKID_PROBE_MIN) ||
|
||||
(dev->bid_flags & BLKID_BID_FL_VERIFIED &&
|
||||
diff < BLKID_PROBE_INTERVAL))
|
||||
return dev;
|
||||
|
||||
DBG(DEBUG_PROBE,
|
||||
printf("need to revalidate %s (time since last check %lu)\n",
|
||||
dev->bid_name, diff));
|
||||
|
||||
fd = open(dev->bid_name, O_RDONLY);
|
||||
if (fd < 0
|
||||
|| fstat(fd, &st) < 0
|
||||
) {
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
if (errno == ENXIO || errno == ENODEV || errno == ENOENT) {
|
||||
blkid_free_dev(dev);
|
||||
return NULL;
|
||||
}
|
||||
/* We don't have read permission, just return cache data. */
|
||||
DBG(DEBUG_PROBE,
|
||||
printf("returning unverified data for %s\n",
|
||||
dev->bid_name));
|
||||
return dev;
|
||||
}
|
||||
|
||||
memset(bufs, 0, sizeof(bufs));
|
||||
|
||||
/*
|
||||
* Iterate over the type array. If we already know the type,
|
||||
* then try that first. If it doesn't work, then blow away
|
||||
* the type information, and try again.
|
||||
*
|
||||
*/
|
||||
try_again:
|
||||
type = 0;
|
||||
if (!dev->bid_type || !strcmp(dev->bid_type, "mdraid")) {
|
||||
uuid_t uuid;
|
||||
|
||||
if (check_mdraid(fd, uuid) == 0) {
|
||||
set_uuid(dev, uuid);
|
||||
type = "mdraid";
|
||||
goto found_type;
|
||||
}
|
||||
}
|
||||
for (id = type_array; id->bim_type; id++) {
|
||||
if (dev->bid_type &&
|
||||
strcmp(id->bim_type, dev->bid_type))
|
||||
continue;
|
||||
|
||||
idx = id->bim_kboff + (id->bim_sboff >> 10);
|
||||
if (idx > BLKID_BLK_OFFS || idx < 0)
|
||||
continue;
|
||||
buf = bufs[idx];
|
||||
if (!buf) {
|
||||
if (lseek(fd, idx << 10, SEEK_SET) < 0)
|
||||
continue;
|
||||
|
||||
buf = xmalloc(1024);
|
||||
|
||||
if (read(fd, buf, 1024) != 1024) {
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
bufs[idx] = buf;
|
||||
}
|
||||
|
||||
if (memcmp(id->bim_magic, buf + (id->bim_sboff&0x3ff),
|
||||
id->bim_len))
|
||||
continue;
|
||||
|
||||
if ((id->bim_probe == NULL) ||
|
||||
(id->bim_probe(fd, cache, dev, id, buf) == 0)) {
|
||||
type = id->bim_type;
|
||||
goto found_type;
|
||||
}
|
||||
}
|
||||
|
||||
if (!id->bim_type && dev->bid_type) {
|
||||
/*
|
||||
* Zap the device filesystem type and try again
|
||||
*/
|
||||
blkid_set_tag(dev, "TYPE", 0, 0);
|
||||
blkid_set_tag(dev, "SEC_TYPE", 0, 0);
|
||||
blkid_set_tag(dev, "LABEL", 0, 0);
|
||||
blkid_set_tag(dev, "UUID", 0, 0);
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
if (!dev->bid_type) {
|
||||
blkid_free_dev(dev);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
found_type:
|
||||
if (dev && type) {
|
||||
dev->bid_devno = st.st_rdev;
|
||||
dev->bid_time = time(NULL);
|
||||
dev->bid_flags |= BLKID_BID_FL_VERIFIED;
|
||||
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
||||
|
||||
blkid_set_tag(dev, "TYPE", type, 0);
|
||||
|
||||
DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
|
||||
dev->bid_name, st.st_rdev, type));
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
int blkid_known_fstype(const char *fstype)
|
||||
{
|
||||
const struct blkid_magic *id;
|
||||
|
||||
for (id = type_array; id->bim_type; id++) {
|
||||
if (strcmp(fstype, id->bim_type) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_dev dev;
|
||||
blkid_cache cache;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s device\n"
|
||||
"Probe a single device to determine type\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
dev = blkid_get_dev(cache, argv[1], BLKID_DEV_NORMAL);
|
||||
if (!dev) {
|
||||
printf("%s: %s has an unsupported type\n", argv[0], argv[1]);
|
||||
return 1;
|
||||
}
|
||||
printf("%s is type %s\n", argv[1], dev->bid_type ?
|
||||
dev->bid_type : "(null)");
|
||||
if (dev->bid_label)
|
||||
printf("\tlabel is '%s'\n", dev->bid_label);
|
||||
if (dev->bid_uuid)
|
||||
printf("\tuuid is %s\n", dev->bid_uuid);
|
||||
|
||||
blkid_free_dev(dev);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,374 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* probe.h - constants and on-disk structures for extracting device data
|
||||
*
|
||||
* Copyright (C) 1999 by Andries Brouwer
|
||||
* Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
|
||||
* Copyright (C) 2001 by Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
#ifndef BLKID_PROBE_H
|
||||
#define BLKID_PROBE_H 1
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
struct blkid_magic;
|
||||
|
||||
typedef int (*blkid_probe_t)(int fd, blkid_cache cache, blkid_dev dev,
|
||||
const struct blkid_magic *id, unsigned char *buf);
|
||||
|
||||
struct blkid_magic {
|
||||
const char *bim_type; /* type name for this magic */
|
||||
long bim_kboff; /* kilobyte offset of superblock */
|
||||
unsigned bim_sboff; /* byte offset within superblock */
|
||||
unsigned bim_len; /* length of magic */
|
||||
const char *bim_magic; /* magic string */
|
||||
blkid_probe_t bim_probe; /* probe function */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structures for each of the content types we want to extract information
|
||||
* from. We do not necessarily need the magic field here, because we have
|
||||
* already identified the content type before we get this far. It may still
|
||||
* be useful if there are probe functions which handle multiple content types.
|
||||
*/
|
||||
struct ext2_super_block {
|
||||
__u32 s_inodes_count;
|
||||
__u32 s_blocks_count;
|
||||
__u32 s_r_blocks_count;
|
||||
__u32 s_free_blocks_count;
|
||||
__u32 s_free_inodes_count;
|
||||
__u32 s_first_data_block;
|
||||
__u32 s_log_block_size;
|
||||
__u32 s_dummy3[7];
|
||||
unsigned char s_magic[2];
|
||||
__u16 s_state;
|
||||
__u32 s_dummy5[8];
|
||||
__u32 s_feature_compat;
|
||||
__u32 s_feature_incompat;
|
||||
__u32 s_feature_ro_compat;
|
||||
unsigned char s_uuid[16];
|
||||
char s_volume_name[16];
|
||||
};
|
||||
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004
|
||||
#define EXT3_FEATURE_INCOMPAT_RECOVER 0x00000004
|
||||
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x00000008
|
||||
|
||||
struct xfs_super_block {
|
||||
unsigned char xs_magic[4];
|
||||
__u32 xs_blocksize;
|
||||
__u64 xs_dblocks;
|
||||
__u64 xs_rblocks;
|
||||
__u32 xs_dummy1[2];
|
||||
unsigned char xs_uuid[16];
|
||||
__u32 xs_dummy2[15];
|
||||
char xs_fname[12];
|
||||
__u32 xs_dummy3[2];
|
||||
__u64 xs_icount;
|
||||
__u64 xs_ifree;
|
||||
__u64 xs_fdblocks;
|
||||
};
|
||||
|
||||
struct reiserfs_super_block {
|
||||
__u32 rs_blocks_count;
|
||||
__u32 rs_free_blocks;
|
||||
__u32 rs_root_block;
|
||||
__u32 rs_journal_block;
|
||||
__u32 rs_journal_dev;
|
||||
__u32 rs_orig_journal_size;
|
||||
__u32 rs_dummy2[5];
|
||||
__u16 rs_blocksize;
|
||||
__u16 rs_dummy3[3];
|
||||
unsigned char rs_magic[12];
|
||||
__u32 rs_dummy4[5];
|
||||
unsigned char rs_uuid[16];
|
||||
char rs_label[16];
|
||||
};
|
||||
|
||||
struct jfs_super_block {
|
||||
unsigned char js_magic[4];
|
||||
__u32 js_version;
|
||||
__u64 js_size;
|
||||
__u32 js_bsize;
|
||||
__u32 js_dummy1;
|
||||
__u32 js_pbsize;
|
||||
__u32 js_dummy2[27];
|
||||
unsigned char js_uuid[16];
|
||||
unsigned char js_label[16];
|
||||
unsigned char js_loguuid[16];
|
||||
};
|
||||
|
||||
struct romfs_super_block {
|
||||
unsigned char ros_magic[8];
|
||||
__u32 ros_dummy1[2];
|
||||
unsigned char ros_volume[16];
|
||||
};
|
||||
|
||||
struct cramfs_super_block {
|
||||
__u8 magic[4];
|
||||
__u32 size;
|
||||
__u32 flags;
|
||||
__u32 future;
|
||||
__u8 signature[16];
|
||||
struct cramfs_info {
|
||||
__u32 crc;
|
||||
__u32 edition;
|
||||
__u32 blocks;
|
||||
__u32 files;
|
||||
} info;
|
||||
__u8 name[16];
|
||||
};
|
||||
|
||||
struct swap_id_block {
|
||||
/* unsigned char sws_boot[1024]; */
|
||||
__u32 sws_version;
|
||||
__u32 sws_lastpage;
|
||||
__u32 sws_nrbad;
|
||||
unsigned char sws_uuid[16];
|
||||
char sws_volume[16];
|
||||
unsigned char sws_pad[117];
|
||||
__u32 sws_badpg;
|
||||
};
|
||||
|
||||
/* Yucky misaligned values */
|
||||
struct vfat_super_block {
|
||||
/* 00*/ unsigned char vs_ignored[3];
|
||||
/* 03*/ unsigned char vs_sysid[8];
|
||||
/* 0b*/ unsigned char vs_sector_size[2];
|
||||
/* 0d*/ __u8 vs_cluster_size;
|
||||
/* 0e*/ __u16 vs_reserved;
|
||||
/* 10*/ __u8 vs_fats;
|
||||
/* 11*/ unsigned char vs_dir_entries[2];
|
||||
/* 13*/ unsigned char vs_sectors[2];
|
||||
/* 15*/ unsigned char vs_media;
|
||||
/* 16*/ __u16 vs_fat_length;
|
||||
/* 18*/ __u16 vs_secs_track;
|
||||
/* 1a*/ __u16 vs_heads;
|
||||
/* 1c*/ __u32 vs_hidden;
|
||||
/* 20*/ __u32 vs_total_sect;
|
||||
/* 24*/ __u32 vs_fat32_length;
|
||||
/* 28*/ __u16 vs_flags;
|
||||
/* 2a*/ __u8 vs_version[2];
|
||||
/* 2c*/ __u32 vs_root_cluster;
|
||||
/* 30*/ __u16 vs_insfo_sector;
|
||||
/* 32*/ __u16 vs_backup_boot;
|
||||
/* 34*/ __u16 vs_reserved2[6];
|
||||
/* 40*/ unsigned char vs_unknown[3];
|
||||
/* 43*/ unsigned char vs_serno[4];
|
||||
/* 47*/ char vs_label[11];
|
||||
/* 52*/ unsigned char vs_magic[8];
|
||||
/* 5a*/ unsigned char vs_dummy2[164];
|
||||
/*1fe*/ unsigned char vs_pmagic[2];
|
||||
};
|
||||
|
||||
/* Yucky misaligned values */
|
||||
struct msdos_super_block {
|
||||
/* 00*/ unsigned char ms_ignored[3];
|
||||
/* 03*/ unsigned char ms_sysid[8];
|
||||
/* 0b*/ unsigned char ms_sector_size[2];
|
||||
/* 0d*/ __u8 ms_cluster_size;
|
||||
/* 0e*/ __u16 ms_reserved;
|
||||
/* 10*/ __u8 ms_fats;
|
||||
/* 11*/ unsigned char ms_dir_entries[2];
|
||||
/* 13*/ unsigned char ms_sectors[2];
|
||||
/* 15*/ unsigned char ms_media;
|
||||
/* 16*/ __u16 ms_fat_length;
|
||||
/* 18*/ __u16 ms_secs_track;
|
||||
/* 1a*/ __u16 ms_heads;
|
||||
/* 1c*/ __u32 ms_hidden;
|
||||
/* 20*/ __u32 ms_total_sect;
|
||||
/* 24*/ unsigned char ms_unknown[3];
|
||||
/* 27*/ unsigned char ms_serno[4];
|
||||
/* 2b*/ char ms_label[11];
|
||||
/* 36*/ unsigned char ms_magic[8];
|
||||
/* 3d*/ unsigned char ms_dummy2[192];
|
||||
/*1fe*/ unsigned char ms_pmagic[2];
|
||||
};
|
||||
|
||||
struct minix_super_block {
|
||||
__u16 ms_ninodes;
|
||||
__u16 ms_nzones;
|
||||
__u16 ms_imap_blocks;
|
||||
__u16 ms_zmap_blocks;
|
||||
__u16 ms_firstdatazone;
|
||||
__u16 ms_log_zone_size;
|
||||
__u32 ms_max_size;
|
||||
unsigned char ms_magic[2];
|
||||
__u16 ms_state;
|
||||
__u32 ms_zones;
|
||||
};
|
||||
|
||||
struct mdp_superblock_s {
|
||||
__u32 md_magic;
|
||||
__u32 major_version;
|
||||
__u32 minor_version;
|
||||
__u32 patch_version;
|
||||
__u32 gvalid_words;
|
||||
__u32 set_uuid0;
|
||||
__u32 ctime;
|
||||
__u32 level;
|
||||
__u32 size;
|
||||
__u32 nr_disks;
|
||||
__u32 raid_disks;
|
||||
__u32 md_minor;
|
||||
__u32 not_persistent;
|
||||
__u32 set_uuid1;
|
||||
__u32 set_uuid2;
|
||||
__u32 set_uuid3;
|
||||
};
|
||||
|
||||
struct hfs_super_block {
|
||||
char h_magic[2];
|
||||
char h_dummy[18];
|
||||
__u32 h_blksize;
|
||||
};
|
||||
|
||||
struct ocfs_volume_header {
|
||||
unsigned char minor_version[4];
|
||||
unsigned char major_version[4];
|
||||
unsigned char signature[128];
|
||||
char mount[128];
|
||||
unsigned char mount_len[2];
|
||||
};
|
||||
|
||||
struct ocfs_volume_label {
|
||||
unsigned char disk_lock[48];
|
||||
char label[64];
|
||||
unsigned char label_len[2];
|
||||
unsigned char vol_id[16];
|
||||
unsigned char vol_id_len[2];
|
||||
};
|
||||
|
||||
#define ocfsmajor(o) ((__u32)o.major_version[0] \
|
||||
+ (((__u32) o.major_version[1]) << 8) \
|
||||
+ (((__u32) o.major_version[2]) << 16) \
|
||||
+ (((__u32) o.major_version[3]) << 24))
|
||||
#define ocfslabellen(o) ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
|
||||
#define ocfsmountlen(o) ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
|
||||
|
||||
#define OCFS_MAGIC "OracleCFS"
|
||||
|
||||
struct ocfs2_super_block {
|
||||
unsigned char signature[8];
|
||||
unsigned char s_dummy1[184];
|
||||
unsigned char s_dummy2[80];
|
||||
char s_label[64];
|
||||
unsigned char s_uuid[16];
|
||||
};
|
||||
|
||||
#define OCFS2_MIN_BLOCKSIZE 512
|
||||
#define OCFS2_MAX_BLOCKSIZE 4096
|
||||
|
||||
#define OCFS2_SUPER_BLOCK_BLKNO 2
|
||||
|
||||
#define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
|
||||
|
||||
struct oracle_asm_disk_label {
|
||||
char dummy[32];
|
||||
char dl_tag[8];
|
||||
char dl_id[24];
|
||||
};
|
||||
|
||||
#define ORACLE_ASM_DISK_LABEL_MARKED "ORCLDISK"
|
||||
#define ORACLE_ASM_DISK_LABEL_OFFSET 32
|
||||
|
||||
#define ISODCL(from, to) (to - from + 1)
|
||||
struct iso_volume_descriptor {
|
||||
char type[ISODCL(1,1)]; /* 711 */
|
||||
char id[ISODCL(2,6)];
|
||||
char version[ISODCL(7,7)];
|
||||
char data[ISODCL(8,2048)];
|
||||
};
|
||||
|
||||
/*
|
||||
* Byte swap functions
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define _INLINE_ static __inline__
|
||||
#else /* For Watcom C */
|
||||
#define _INLINE_ static inline
|
||||
#endif
|
||||
|
||||
static __u16 blkid_swab16(__u16 val);
|
||||
static __u32 blkid_swab32(__u32 val);
|
||||
static __u64 blkid_swab64(__u64 val);
|
||||
|
||||
#if ((defined __GNUC__) && \
|
||||
(defined(__i386__) || defined(__i486__) || defined(__i586__)))
|
||||
|
||||
#define _BLKID_HAVE_ASM_BITOPS_
|
||||
|
||||
_INLINE_ __u32 blkid_swab32(__u32 val)
|
||||
{
|
||||
#ifdef EXT2FS_REQUIRE_486
|
||||
__asm__("bswap %0" : "=r" (val) : "0" (val));
|
||||
#else
|
||||
__asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
|
||||
"rorl $16,%0\n\t" /* swap words */
|
||||
"xchgb %b0,%h0" /* swap higher bytes */
|
||||
:"=q" (val)
|
||||
: "0" (val));
|
||||
#endif
|
||||
return val;
|
||||
}
|
||||
|
||||
_INLINE_ __u16 blkid_swab16(__u16 val)
|
||||
{
|
||||
__asm__("xchgb %b0,%h0" /* swap bytes */
|
||||
: "=q" (val)
|
||||
: "0" (val));
|
||||
return val;
|
||||
}
|
||||
|
||||
_INLINE_ __u64 blkid_swab64(__u64 val)
|
||||
{
|
||||
return blkid_swab32(val >> 32) |
|
||||
( ((__u64)blkid_swab32((__u32)val)) << 32 );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_BLKID_HAVE_ASM_BITOPS_)
|
||||
|
||||
_INLINE_ __u16 blkid_swab16(__u16 val)
|
||||
{
|
||||
return (val >> 8) | (val << 8);
|
||||
}
|
||||
|
||||
_INLINE_ __u32 blkid_swab32(__u32 val)
|
||||
{
|
||||
return (val>>24) | ((val>>8) & 0xFF00) |
|
||||
((val<<8) & 0xFF0000) | (val<<24);
|
||||
}
|
||||
|
||||
_INLINE_ __u64 blkid_swab64(__u64 val)
|
||||
{
|
||||
return blkid_swab32(val >> 32) |
|
||||
( ((__u64)blkid_swab32((__u32)val)) << 32 );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define blkid_le16(x) blkid_swab16(x)
|
||||
#define blkid_le32(x) blkid_swab32(x)
|
||||
#define blkid_le64(x) blkid_swab64(x)
|
||||
#define blkid_be16(x) (x)
|
||||
#define blkid_be32(x) (x)
|
||||
#define blkid_be64(x) (x)
|
||||
#else
|
||||
#define blkid_le16(x) (x)
|
||||
#define blkid_le32(x) (x)
|
||||
#define blkid_le64(x) (x)
|
||||
#define blkid_be16(x) blkid_swab16(x)
|
||||
#define blkid_be32(x) blkid_swab32(x)
|
||||
#define blkid_be64(x) blkid_swab64(x)
|
||||
#endif
|
||||
|
||||
#undef _INLINE_
|
||||
|
||||
#endif /* _BLKID_PROBE_H */
|
||||
@@ -1,459 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* read.c - read the blkid cache from disk, to avoid scanning all devices
|
||||
*
|
||||
* Copyright (C) 2001, 2003 Theodore Y. Ts'o
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
#include "../uuid/uuid.h"
|
||||
|
||||
#ifdef HAVE_STRTOULL
|
||||
#define __USE_ISOC9X
|
||||
#define STRTOULL strtoull /* defined in stdlib.h if you try hard enough */
|
||||
#else
|
||||
/* FIXME: need to support real strtoull here */
|
||||
#define STRTOULL strtoul
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
#define blkid_debug_dump_dev(dev) (debug_dump_dev(dev))
|
||||
static void debug_dump_dev(blkid_dev dev);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* File format:
|
||||
*
|
||||
* <device [<NAME="value"> ...]>device_name</device>
|
||||
*
|
||||
* The following tags are required for each entry:
|
||||
* <ID="id"> unique (within this file) ID number of this device
|
||||
* <TIME="time"> (ascii time_t) time this entry was last read from disk
|
||||
* <TYPE="type"> (detected) type of filesystem/data for this partition
|
||||
*
|
||||
* The following tags may be present, depending on the device contents
|
||||
* <LABEL="label"> (user supplied) label (volume name, etc)
|
||||
* <UUID="uuid"> (generated) universally unique identifier (serial no)
|
||||
*/
|
||||
|
||||
static char *skip_over_blank(char *cp)
|
||||
{
|
||||
while (*cp && isspace(*cp))
|
||||
cp++;
|
||||
return cp;
|
||||
}
|
||||
|
||||
static char *skip_over_word(char *cp)
|
||||
{
|
||||
char ch;
|
||||
|
||||
while ((ch = *cp)) {
|
||||
/* If we see a backslash, skip the next character */
|
||||
if (ch == '\\') {
|
||||
cp++;
|
||||
if (*cp == '\0')
|
||||
break;
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (isspace(ch) || ch == '<' || ch == '>')
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
static char *strip_line(char *line)
|
||||
{
|
||||
char *p;
|
||||
|
||||
line = skip_over_blank(line);
|
||||
|
||||
p = line + strlen(line) - 1;
|
||||
|
||||
while (*line) {
|
||||
if (isspace(*p))
|
||||
*p-- = '\0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start parsing a new line from the cache.
|
||||
*
|
||||
* line starts with "<device" return 1 -> continue parsing line
|
||||
* line starts with "<foo", empty, or # return 0 -> skip line
|
||||
* line starts with other, return -BLKID_ERR_CACHE -> error
|
||||
*/
|
||||
static int parse_start(char **cp)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strip_line(*cp);
|
||||
|
||||
/* Skip comment or blank lines. We can't just NUL the first '#' char,
|
||||
* in case it is inside quotes, or escaped.
|
||||
*/
|
||||
if (*p == '\0' || *p == '#')
|
||||
return 0;
|
||||
|
||||
if (!strncmp(p, "<device", 7)) {
|
||||
DBG(DEBUG_READ, printf("found device header: %8s\n", p));
|
||||
p += 7;
|
||||
|
||||
*cp = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*p == '<')
|
||||
return 0;
|
||||
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
|
||||
/* Consume the remaining XML on the line (cosmetic only) */
|
||||
static int parse_end(char **cp)
|
||||
{
|
||||
*cp = skip_over_blank(*cp);
|
||||
|
||||
if (!strncmp(*cp, "</device>", 9)) {
|
||||
DBG(DEBUG_READ, printf("found device trailer %9s\n", *cp));
|
||||
*cp += 9;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new device struct with device name filled in. Will handle
|
||||
* finding the device on lines of the form:
|
||||
* <device foo=bar>devname</device>
|
||||
* <device>devname<foo>bar</foo></device>
|
||||
*/
|
||||
static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
|
||||
{
|
||||
char *start, *tmp, *end, *name;
|
||||
int ret;
|
||||
|
||||
if ((ret = parse_start(cp)) <= 0)
|
||||
return ret;
|
||||
|
||||
start = tmp = strchr(*cp, '>');
|
||||
if (!start) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: short line parsing dev: %s\n", *cp));
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
start = skip_over_blank(start + 1);
|
||||
end = skip_over_word(start);
|
||||
|
||||
DBG(DEBUG_READ, printf("device should be %*s\n", end - start, start));
|
||||
|
||||
if (**cp == '>')
|
||||
*cp = end;
|
||||
else
|
||||
(*cp)++;
|
||||
|
||||
*tmp = '\0';
|
||||
|
||||
if (!(tmp = strrchr(end, '<')) || parse_end(&tmp) < 0) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: missing </device> ending: %s\n", end));
|
||||
} else if (tmp)
|
||||
*tmp = '\0';
|
||||
|
||||
if (end - start <= 1) {
|
||||
DBG(DEBUG_READ, printf("blkid: empty device name: %s\n", *cp));
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
|
||||
name = blkid_strndup(start, end-start);
|
||||
if (name == NULL)
|
||||
return -BLKID_ERR_MEM;
|
||||
|
||||
DBG(DEBUG_READ, printf("found dev %s\n", name));
|
||||
|
||||
if (!(*dev = blkid_get_dev(cache, name, BLKID_DEV_CREATE)))
|
||||
return -BLKID_ERR_MEM;
|
||||
|
||||
free(name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract a tag of the form NAME="value" from the line.
|
||||
*/
|
||||
static int parse_token(char **name, char **value, char **cp)
|
||||
{
|
||||
char *end;
|
||||
|
||||
if (!name || !value || !cp)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (!(*value = strchr(*cp, '=')))
|
||||
return 0;
|
||||
|
||||
**value = '\0';
|
||||
*name = strip_line(*cp);
|
||||
*value = skip_over_blank(*value + 1);
|
||||
|
||||
if (**value == '"') {
|
||||
end = strchr(*value + 1, '"');
|
||||
if (!end) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("unbalanced quotes at: %s\n", *value));
|
||||
*cp = *value;
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
(*value)++;
|
||||
*end = '\0';
|
||||
end++;
|
||||
} else {
|
||||
end = skip_over_word(*value);
|
||||
if (*end) {
|
||||
*end = '\0';
|
||||
end++;
|
||||
}
|
||||
}
|
||||
*cp = end;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract a tag of the form <NAME>value</NAME> from the line.
|
||||
*/
|
||||
/*
|
||||
static int parse_xml(char **name, char **value, char **cp)
|
||||
{
|
||||
char *end;
|
||||
|
||||
if (!name || !value || !cp)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
*name = strip_line(*cp);
|
||||
|
||||
if ((*name)[0] != '<' || (*name)[1] == '/')
|
||||
return 0;
|
||||
|
||||
FIXME: finish this.
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Extract a tag from the line.
|
||||
*
|
||||
* Return 1 if a valid tag was found.
|
||||
* Return 0 if no tag found.
|
||||
* Return -ve error code.
|
||||
*/
|
||||
static int parse_tag(blkid_cache cache, blkid_dev dev, char **cp)
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
int ret;
|
||||
|
||||
if (!cache || !dev)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if ((ret = parse_token(&name, &value, cp)) <= 0 /* &&
|
||||
(ret = parse_xml(&name, &value, cp)) <= 0 */)
|
||||
return ret;
|
||||
|
||||
/* Some tags are stored directly in the device struct */
|
||||
if (!strcmp(name, "DEVNO"))
|
||||
dev->bid_devno = STRTOULL(value, 0, 0);
|
||||
else if (!strcmp(name, "PRI"))
|
||||
dev->bid_pri = strtol(value, 0, 0);
|
||||
else if (!strcmp(name, "TIME"))
|
||||
/* FIXME: need to parse a long long eventually */
|
||||
dev->bid_time = strtol(value, 0, 0);
|
||||
else
|
||||
ret = blkid_set_tag(dev, name, value, strlen(value));
|
||||
|
||||
DBG(DEBUG_READ, printf(" tag: %s=\"%s\"\n", name, value));
|
||||
|
||||
return ret < 0 ? ret : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a single line of data, and return a newly allocated dev struct.
|
||||
* Add the new device to the cache struct, if one was read.
|
||||
*
|
||||
* Lines are of the form <device [TAG="value" ...]>/dev/foo</device>
|
||||
*
|
||||
* Returns -ve value on error.
|
||||
* Returns 0 otherwise.
|
||||
* If a valid device was read, *dev_p is non-NULL, otherwise it is NULL
|
||||
* (e.g. comment lines, unknown XML content, etc).
|
||||
*/
|
||||
static int blkid_parse_line(blkid_cache cache, blkid_dev *dev_p, char *cp)
|
||||
{
|
||||
blkid_dev dev;
|
||||
int ret;
|
||||
|
||||
if (!cache || !dev_p)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
*dev_p = NULL;
|
||||
|
||||
DBG(DEBUG_READ, printf("line: %s\n", cp));
|
||||
|
||||
if ((ret = parse_dev(cache, dev_p, &cp)) <= 0)
|
||||
return ret;
|
||||
|
||||
dev = *dev_p;
|
||||
|
||||
while ((ret = parse_tag(cache, dev, &cp)) > 0) {
|
||||
;
|
||||
}
|
||||
|
||||
if (dev->bid_type == NULL) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: device %s has no TYPE\n",dev->bid_name));
|
||||
blkid_free_dev(dev);
|
||||
}
|
||||
|
||||
DBG(DEBUG_READ, blkid_debug_dump_dev(dev));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the specified filename, and return the data in the supplied or
|
||||
* a newly allocated cache struct. If the file doesn't exist, return a
|
||||
* new empty cache struct.
|
||||
*/
|
||||
void blkid_read_cache(blkid_cache cache)
|
||||
{
|
||||
FILE *file;
|
||||
char buf[4096];
|
||||
int fd, lineno = 0;
|
||||
struct stat st;
|
||||
|
||||
if (!cache)
|
||||
return;
|
||||
|
||||
/*
|
||||
* If the file doesn't exist, then we just return an empty
|
||||
* struct so that the cache can be populated.
|
||||
*/
|
||||
if ((fd = open(cache->bic_filename, O_RDONLY)) < 0)
|
||||
return;
|
||||
if (fstat(fd, &st) < 0)
|
||||
goto errout;
|
||||
if ((st.st_mtime == cache->bic_ftime) ||
|
||||
(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
|
||||
DBG(DEBUG_CACHE, printf("skipping re-read of %s\n",
|
||||
cache->bic_filename));
|
||||
goto errout;
|
||||
}
|
||||
|
||||
DBG(DEBUG_CACHE, printf("reading cache file %s\n",
|
||||
cache->bic_filename));
|
||||
|
||||
file = xfdopen_for_read(fd);
|
||||
|
||||
while (fgets(buf, sizeof(buf), file)) {
|
||||
blkid_dev dev;
|
||||
unsigned int end;
|
||||
|
||||
lineno++;
|
||||
if (buf[0] == 0)
|
||||
continue;
|
||||
end = strlen(buf) - 1;
|
||||
/* Continue reading next line if it ends with a backslash */
|
||||
while (end < sizeof(buf) - 2 && buf[end] == '\\' &&
|
||||
fgets(buf + end, sizeof(buf) - end, file)) {
|
||||
end = strlen(buf) - 1;
|
||||
lineno++;
|
||||
}
|
||||
|
||||
if (blkid_parse_line(cache, &dev, buf) < 0) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: bad format on line %d\n", lineno));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
/*
|
||||
* Initially we do not need to write out the cache file.
|
||||
*/
|
||||
cache->bic_flags &= ~BLKID_BIC_FL_CHANGED;
|
||||
cache->bic_ftime = st.st_mtime;
|
||||
|
||||
return;
|
||||
errout:
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
static void debug_dump_dev(blkid_dev dev)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!dev) {
|
||||
printf(" dev: NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" dev: name = %s\n", dev->bid_name);
|
||||
printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
|
||||
printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
|
||||
printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
|
||||
printf(" dev: flags = 0x%08X\n", dev->bid_flags);
|
||||
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
if (tag)
|
||||
printf(" tag: %s=\"%s\"\n", tag->bit_name,
|
||||
tag->bit_val);
|
||||
else
|
||||
printf(" tag: NULL\n");
|
||||
}
|
||||
bb_putchar('\n');
|
||||
}
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n"
|
||||
"Test parsing of the cache (filename)\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_get_cache(&cache, argv[1])) < 0)
|
||||
fprintf(stderr, "error %d reading cache file %s\n", ret,
|
||||
argv[1] ? argv[1] : BLKID_CACHE_FILE);
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -1,139 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* resolve.c - resolve names and tags into specific devices
|
||||
*
|
||||
* Copyright (C) 2001, 2003 Theodore Ts'o.
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "blkidP.h"
|
||||
#include "probe.h"
|
||||
|
||||
/*
|
||||
* Find a tagname (e.g. LABEL or UUID) on a specific device.
|
||||
*/
|
||||
char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
|
||||
const char *devname)
|
||||
{
|
||||
blkid_tag found;
|
||||
blkid_dev dev;
|
||||
blkid_cache c = cache;
|
||||
char *ret = NULL;
|
||||
|
||||
DBG(DEBUG_RESOLVE, printf("looking for %s on %s\n", tagname, devname));
|
||||
|
||||
if (!devname)
|
||||
return NULL;
|
||||
|
||||
if (!cache) {
|
||||
if (blkid_get_cache(&c, NULL) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((dev = blkid_get_dev(c, devname, BLKID_DEV_NORMAL)) &&
|
||||
(found = blkid_find_tag_dev(dev, tagname)))
|
||||
ret = blkid_strdup(found->bit_val);
|
||||
|
||||
if (!cache)
|
||||
blkid_put_cache(c);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate a device name from a token (NAME=value string), or (name, value)
|
||||
* pair. In the case of a token, value is ignored. If the "token" is not
|
||||
* of the form "NAME=value" and there is no value given, then it is assumed
|
||||
* to be the actual devname and a copy is returned.
|
||||
*/
|
||||
char *blkid_get_devname(blkid_cache cache, const char *token,
|
||||
const char *value)
|
||||
{
|
||||
blkid_dev dev;
|
||||
blkid_cache c = cache;
|
||||
char *t = NULL, *v = NULL;
|
||||
char *ret = NULL;
|
||||
|
||||
if (!token)
|
||||
return NULL;
|
||||
|
||||
if (!cache) {
|
||||
if (blkid_get_cache(&c, NULL) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBG(DEBUG_RESOLVE,
|
||||
printf("looking for %s%s%s %s\n", token, value ? "=" : "",
|
||||
value ? value : "", cache ? "in cache" : "from disk"));
|
||||
|
||||
if (!value) {
|
||||
if (!strchr(token, '='))
|
||||
return blkid_strdup(token);
|
||||
blkid_parse_tag_string(token, &t, &v);
|
||||
if (!t || !v)
|
||||
goto errout;
|
||||
token = t;
|
||||
value = v;
|
||||
}
|
||||
|
||||
dev = blkid_find_dev_with_tag(c, token, value);
|
||||
if (!dev)
|
||||
goto errout;
|
||||
|
||||
ret = blkid_strdup(blkid_dev_devname(dev));
|
||||
|
||||
errout:
|
||||
free(t);
|
||||
free(v);
|
||||
if (!cache) {
|
||||
blkid_put_cache(c);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *value;
|
||||
blkid_cache cache;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 2 && argc != 3) {
|
||||
fprintf(stderr, "Usage:\t%s tagname=value\n"
|
||||
"\t%s tagname devname\n"
|
||||
"Find which device holds a given token or\n"
|
||||
"Find what the value of a tag is in a device\n",
|
||||
argv[0], argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
if (blkid_get_cache(&cache, bb_dev_null) < 0) {
|
||||
fprintf(stderr, "Can't get blkid cache\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argv[2]) {
|
||||
value = blkid_get_tag_value(cache, argv[1], argv[2]);
|
||||
printf("%s has tag %s=%s\n", argv[2], argv[1],
|
||||
value ? value : "<missing>");
|
||||
} else {
|
||||
value = blkid_get_devname(cache, argv[1], NULL);
|
||||
printf("%s has tag %s\n", value ? value : "<none>", argv[1]);
|
||||
}
|
||||
blkid_put_cache(cache);
|
||||
return value ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
@@ -1,189 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* save.c - write the cache struct to disk
|
||||
*
|
||||
* Copyright (C) 2001 by Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
#include <sys/mkdev.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include "blkidP.h"
|
||||
|
||||
static int save_dev(blkid_dev dev, FILE *file)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!dev || dev->bid_name[0] != '/')
|
||||
return 0;
|
||||
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("device %s, type %s\n", dev->bid_name, dev->bid_type));
|
||||
|
||||
fprintf(file,
|
||||
"<device DEVNO=\"0x%04lx\" TIME=\"%lu\"",
|
||||
(unsigned long) dev->bid_devno, dev->bid_time);
|
||||
if (dev->bid_pri)
|
||||
fprintf(file, " PRI=\"%d\"", dev->bid_pri);
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
fprintf(file, " %s=\"%s\"", tag->bit_name,tag->bit_val);
|
||||
}
|
||||
fprintf(file, ">%s</device>\n", dev->bid_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write out the cache struct to the cache file on disk.
|
||||
*/
|
||||
int blkid_flush_cache(blkid_cache cache)
|
||||
{
|
||||
struct list_head *p;
|
||||
char *tmp = NULL;
|
||||
const char *opened = NULL;
|
||||
const char *filename;
|
||||
FILE *file = NULL;
|
||||
int fd, ret = 0;
|
||||
struct stat st;
|
||||
|
||||
if (!cache)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (list_empty(&cache->bic_devs) ||
|
||||
!(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
|
||||
DBG(DEBUG_SAVE, printf("skipping cache file write\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
filename = cache->bic_filename ? cache->bic_filename: BLKID_CACHE_FILE;
|
||||
|
||||
/* If we can't write to the cache file, then don't even try */
|
||||
if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) ||
|
||||
(ret == 0 && access(filename, W_OK) < 0)) {
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("can't write to cache file %s\n", filename));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try and create a temporary file in the same directory so
|
||||
* that in case of error we don't overwrite the cache file.
|
||||
* If the cache file doesn't yet exist, it isn't a regular
|
||||
* file (e.g. /dev/null or a socket), or we couldn't create
|
||||
* a temporary file then we open it directly.
|
||||
*/
|
||||
if (ret == 0 && S_ISREG(st.st_mode)) {
|
||||
tmp = xmalloc(strlen(filename) + 8);
|
||||
sprintf(tmp, "%s-XXXXXX", filename);
|
||||
fd = mkstemp(tmp);
|
||||
if (fd >= 0) {
|
||||
file = xfdopen_for_write(fd);
|
||||
opened = tmp;
|
||||
}
|
||||
fchmod(fd, 0644);
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
file = fopen_for_write(filename);
|
||||
opened = filename;
|
||||
}
|
||||
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("writing cache file %s (really %s)\n",
|
||||
filename, opened));
|
||||
|
||||
if (!file) {
|
||||
ret = errno;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
|
||||
if (!dev->bid_type)
|
||||
continue;
|
||||
if ((ret = save_dev(dev, file)) < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret >= 0) {
|
||||
cache->bic_flags &= ~BLKID_BIC_FL_CHANGED;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
if (opened != filename) {
|
||||
if (ret < 0) {
|
||||
unlink(opened);
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("unlinked temp cache %s\n", opened));
|
||||
} else {
|
||||
char *backup;
|
||||
|
||||
backup = xmalloc(strlen(filename) + 5);
|
||||
sprintf(backup, "%s.old", filename);
|
||||
unlink(backup);
|
||||
link(filename, backup);
|
||||
free(backup);
|
||||
rename(opened, filename);
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("moved temp cache %s\n", opened));
|
||||
}
|
||||
}
|
||||
|
||||
errout:
|
||||
free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n"
|
||||
"Test loading/saving a cache (filename)\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, bb_dev_null)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
if ((ret = blkid_probe_all(cache)) < 0) {
|
||||
fprintf(stderr, "error (%d) probing devices\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
cache->bic_filename = blkid_strdup(argv[1]);
|
||||
|
||||
if ((ret = blkid_flush_cache(cache)) < 0) {
|
||||
fprintf(stderr, "error (%d) saving cache\n", ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -1,431 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* tag.c - allocation/initialization/free routines for tag structs
|
||||
*
|
||||
* Copyright (C) 2001 Andreas Dilger
|
||||
* Copyright (C) 2003 Theodore Ts'o
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the
|
||||
* GNU Lesser General Public License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "blkidP.h"
|
||||
|
||||
static blkid_tag blkid_new_tag(void)
|
||||
{
|
||||
blkid_tag tag;
|
||||
|
||||
tag = xzalloc(sizeof(struct blkid_struct_tag));
|
||||
|
||||
INIT_LIST_HEAD(&tag->bit_tags);
|
||||
INIT_LIST_HEAD(&tag->bit_names);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
void blkid_debug_dump_tag(blkid_tag tag)
|
||||
{
|
||||
if (!tag) {
|
||||
printf(" tag: NULL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
|
||||
}
|
||||
#endif
|
||||
|
||||
void blkid_free_tag(blkid_tag tag)
|
||||
{
|
||||
if (!tag)
|
||||
return;
|
||||
|
||||
DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name,
|
||||
tag->bit_val ? tag->bit_val : "(NULL)"));
|
||||
DBG(DEBUG_TAG, blkid_debug_dump_tag(tag));
|
||||
|
||||
list_del(&tag->bit_tags); /* list of tags for this device */
|
||||
list_del(&tag->bit_names); /* list of tags with this type */
|
||||
|
||||
free(tag->bit_name);
|
||||
free(tag->bit_val);
|
||||
free(tag);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the desired tag on a device. If value is NULL, then the
|
||||
* first such tag is returned, otherwise return only exact tag if found.
|
||||
*/
|
||||
blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!dev || !type)
|
||||
return NULL;
|
||||
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tmp = list_entry(p, struct blkid_struct_tag,
|
||||
bit_tags);
|
||||
|
||||
if (!strcmp(tmp->bit_name, type))
|
||||
return tmp;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the desired tag type in the cache.
|
||||
* We return the head tag for this tag type.
|
||||
*/
|
||||
static blkid_tag blkid_find_head_cache(blkid_cache cache, const char *type)
|
||||
{
|
||||
blkid_tag head = NULL, tmp;
|
||||
struct list_head *p;
|
||||
|
||||
if (!cache || !type)
|
||||
return NULL;
|
||||
|
||||
list_for_each(p, &cache->bic_tags) {
|
||||
tmp = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
if (!strcmp(tmp->bit_name, type)) {
|
||||
DBG(DEBUG_TAG,
|
||||
printf(" found cache tag head %s\n", type));
|
||||
head = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a tag on an existing device.
|
||||
*
|
||||
* If value is NULL, then delete the tagsfrom the device.
|
||||
*/
|
||||
int blkid_set_tag(blkid_dev dev, const char *name,
|
||||
const char *value, const int vlength)
|
||||
{
|
||||
blkid_tag t = 0, head = 0;
|
||||
char *val = NULL;
|
||||
|
||||
if (!dev || !name)
|
||||
return -BLKID_ERR_PARAM;
|
||||
|
||||
if (!(val = blkid_strndup(value, vlength)) && value)
|
||||
return -BLKID_ERR_MEM;
|
||||
t = blkid_find_tag_dev(dev, name);
|
||||
if (!value) {
|
||||
blkid_free_tag(t);
|
||||
} else if (t) {
|
||||
if (!strcmp(t->bit_val, val)) {
|
||||
/* Same thing, exit */
|
||||
free(val);
|
||||
return 0;
|
||||
}
|
||||
free(t->bit_val);
|
||||
t->bit_val = val;
|
||||
} else {
|
||||
/* Existing tag not present, add to device */
|
||||
if (!(t = blkid_new_tag()))
|
||||
goto errout;
|
||||
t->bit_name = blkid_strdup(name);
|
||||
t->bit_val = val;
|
||||
t->bit_dev = dev;
|
||||
|
||||
list_add_tail(&t->bit_tags, &dev->bid_tags);
|
||||
|
||||
if (dev->bid_cache) {
|
||||
head = blkid_find_head_cache(dev->bid_cache,
|
||||
t->bit_name);
|
||||
if (!head) {
|
||||
head = blkid_new_tag();
|
||||
if (!head)
|
||||
goto errout;
|
||||
|
||||
DBG(DEBUG_TAG,
|
||||
printf(" creating new cache tag head %s\n", name));
|
||||
head->bit_name = blkid_strdup(name);
|
||||
if (!head->bit_name)
|
||||
goto errout;
|
||||
list_add_tail(&head->bit_tags,
|
||||
&dev->bid_cache->bic_tags);
|
||||
}
|
||||
list_add_tail(&t->bit_names, &head->bit_names);
|
||||
}
|
||||
}
|
||||
|
||||
/* Link common tags directly to the device struct */
|
||||
if (!strcmp(name, "TYPE"))
|
||||
dev->bid_type = val;
|
||||
else if (!strcmp(name, "LABEL"))
|
||||
dev->bid_label = val;
|
||||
else if (!strcmp(name, "UUID"))
|
||||
dev->bid_uuid = val;
|
||||
|
||||
if (dev->bid_cache)
|
||||
dev->bid_cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
blkid_free_tag(t);
|
||||
if (!t)
|
||||
free(val);
|
||||
blkid_free_tag(head);
|
||||
return -BLKID_ERR_MEM;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse a "NAME=value" string. This is slightly different than
|
||||
* parse_token, because that will end an unquoted value at a space, while
|
||||
* this will assume that an unquoted value is the rest of the token (e.g.
|
||||
* if we are passed an already quoted string from the command-line we don't
|
||||
* have to both quote and escape quote so that the quotes make it to
|
||||
* us).
|
||||
*
|
||||
* Returns 0 on success, and -1 on failure.
|
||||
*/
|
||||
int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val)
|
||||
{
|
||||
char *name, *value, *cp;
|
||||
|
||||
DBG(DEBUG_TAG, printf("trying to parse '%s' as a tag\n", token));
|
||||
|
||||
if (!token || !(cp = strchr(token, '=')))
|
||||
return -1;
|
||||
|
||||
name = blkid_strdup(token);
|
||||
if (!name)
|
||||
return -1;
|
||||
value = name + (cp - token);
|
||||
*value++ = '\0';
|
||||
if (*value == '"' || *value == '\'') {
|
||||
char c = *value++;
|
||||
if (!(cp = strrchr(value, c)))
|
||||
goto errout; /* missing closing quote */
|
||||
*cp = '\0';
|
||||
}
|
||||
value = blkid_strdup(value);
|
||||
if (!value)
|
||||
goto errout;
|
||||
|
||||
*ret_type = name;
|
||||
*ret_val = value;
|
||||
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
free(name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tag iteration routines for the public libblkid interface.
|
||||
*
|
||||
* These routines do not expose the list.h implementation, which are a
|
||||
* contamination of the namespace, and which force us to reveal far, far
|
||||
* too much of our internal implemenation. I'm not convinced I want
|
||||
* to keep list.h in the long term, anyway. It's fine for kernel
|
||||
* programming, but performance is not the #1 priority for this
|
||||
* library, and I really don't like the tradeoff of type-safety for
|
||||
* performance for this application. [tytso:20030125.2007EST]
|
||||
*/
|
||||
|
||||
/*
|
||||
* This series of functions iterate over all tags in a device
|
||||
*/
|
||||
#define TAG_ITERATE_MAGIC 0x01a5284c
|
||||
|
||||
struct blkid_struct_tag_iterate {
|
||||
int magic;
|
||||
blkid_dev dev;
|
||||
struct list_head *p;
|
||||
};
|
||||
|
||||
blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev)
|
||||
{
|
||||
blkid_tag_iterate iter;
|
||||
|
||||
iter = xmalloc(sizeof(struct blkid_struct_tag_iterate));
|
||||
iter->magic = TAG_ITERATE_MAGIC;
|
||||
iter->dev = dev;
|
||||
iter->p = dev->bid_tags.next;
|
||||
return iter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 0 on success, -1 on error
|
||||
*/
|
||||
extern int blkid_tag_next(blkid_tag_iterate iter,
|
||||
const char **type, const char **value)
|
||||
{
|
||||
blkid_tag tag;
|
||||
|
||||
*type = 0;
|
||||
*value = 0;
|
||||
if (!iter || iter->magic != TAG_ITERATE_MAGIC ||
|
||||
iter->p == &iter->dev->bid_tags)
|
||||
return -1;
|
||||
tag = list_entry(iter->p, struct blkid_struct_tag, bit_tags);
|
||||
*type = tag->bit_name;
|
||||
*value = tag->bit_val;
|
||||
iter->p = iter->p->next;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void blkid_tag_iterate_end(blkid_tag_iterate iter)
|
||||
{
|
||||
if (!iter || iter->magic != TAG_ITERATE_MAGIC)
|
||||
return;
|
||||
iter->magic = 0;
|
||||
free(iter);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function returns a device which matches a particular
|
||||
* type/value pair. If there is more than one device that matches the
|
||||
* search specification, it returns the one with the highest priority
|
||||
* value. This allows us to give preference to EVMS or LVM devices.
|
||||
*
|
||||
* XXX there should also be an interface which uses an iterator so we
|
||||
* can get all of the devices which match a type/value search parameter.
|
||||
*/
|
||||
extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
|
||||
const char *type,
|
||||
const char *value)
|
||||
{
|
||||
blkid_tag head;
|
||||
blkid_dev dev;
|
||||
int pri;
|
||||
struct list_head *p;
|
||||
|
||||
if (!cache || !type || !value)
|
||||
return NULL;
|
||||
|
||||
blkid_read_cache(cache);
|
||||
|
||||
DBG(DEBUG_TAG, printf("looking for %s=%s in cache\n", type, value));
|
||||
|
||||
try_again:
|
||||
pri = -1;
|
||||
dev = 0;
|
||||
head = blkid_find_head_cache(cache, type);
|
||||
|
||||
if (head) {
|
||||
list_for_each(p, &head->bit_names) {
|
||||
blkid_tag tmp = list_entry(p, struct blkid_struct_tag,
|
||||
bit_names);
|
||||
|
||||
if (!strcmp(tmp->bit_val, value) &&
|
||||
tmp->bit_dev->bid_pri > pri) {
|
||||
dev = tmp->bit_dev;
|
||||
pri = dev->bid_pri;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dev && !(dev->bid_flags & BLKID_BID_FL_VERIFIED)) {
|
||||
dev = blkid_verify(cache, dev);
|
||||
if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED))
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
if (!dev && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
|
||||
if (blkid_probe_all(cache) < 0)
|
||||
return NULL;
|
||||
goto try_again;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
#endif
|
||||
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device "
|
||||
"[type value]\n",
|
||||
prog);
|
||||
fprintf(stderr, "\tList all tags for a device and exit\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
blkid_tag_iterate iter;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev;
|
||||
int c, ret, found;
|
||||
int flags = BLKID_DEV_FIND;
|
||||
char *tmp;
|
||||
char *file = NULL;
|
||||
char *devname = NULL;
|
||||
char *search_type = NULL;
|
||||
char *search_value = NULL;
|
||||
const char *type, *value;
|
||||
|
||||
while ((c = getopt (argc, argv, "m:f:")) != EOF)
|
||||
switch (c) {
|
||||
case 'f':
|
||||
file = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
blkid_debug_mask = strtoul (optarg, &tmp, 0);
|
||||
if (*tmp) {
|
||||
fprintf(stderr, "Invalid debug mask: %s\n",
|
||||
optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
usage(argv[0]);
|
||||
}
|
||||
if (argc > optind)
|
||||
devname = argv[optind++];
|
||||
if (argc > optind)
|
||||
search_type = argv[optind++];
|
||||
if (argc > optind)
|
||||
search_value = argv[optind++];
|
||||
if (!devname || (argc != optind))
|
||||
usage(argv[0]);
|
||||
|
||||
if ((ret = blkid_get_cache(&cache, file)) != 0) {
|
||||
fprintf(stderr, "%s: error creating cache (%d)\n",
|
||||
argv[0], ret);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dev = blkid_get_dev(cache, devname, flags);
|
||||
if (!dev) {
|
||||
fprintf(stderr, "%s: cannot find device in blkid cache\n", devname);
|
||||
exit(1);
|
||||
}
|
||||
if (search_type) {
|
||||
found = blkid_dev_has_tag(dev, search_type, search_value);
|
||||
printf("Device %s: (%s, %s) %s\n", blkid_dev_devname(dev),
|
||||
search_type, search_value ? search_value : "NULL",
|
||||
found ? "FOUND" : "NOT FOUND");
|
||||
return !found;
|
||||
}
|
||||
printf("Device %s...\n", blkid_dev_devname(dev));
|
||||
|
||||
iter = blkid_tag_iterate_begin(dev);
|
||||
while (blkid_tag_next(iter, &type, &value) == 0) {
|
||||
printf("\tTag %s has value %s\n", type, value);
|
||||
}
|
||||
blkid_tag_iterate_end(iter);
|
||||
|
||||
blkid_put_cache(cache);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,220 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* chattr.c - Change file attributes on an ext2 file system
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/10/30 - Creation
|
||||
* 93/11/13 - Replace stat() calls by lstat() to avoid loops
|
||||
* 94/02/27 - Integrated in Ted's distribution
|
||||
* 98/12/29 - Ignore symlinks when working recursively (G M Sipe)
|
||||
* 98/12/29 - Display version info only when -V specified (G M Sipe)
|
||||
*/
|
||||
|
||||
#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
|
||||
#define OPT_SET 4
|
||||
#define OPT_SET_VER 8
|
||||
static int flags;
|
||||
static int recursive;
|
||||
|
||||
static unsigned long version;
|
||||
|
||||
static unsigned long af;
|
||||
static unsigned long rf;
|
||||
static unsigned long sf;
|
||||
|
||||
struct flags_char {
|
||||
unsigned long flag;
|
||||
char optchar;
|
||||
};
|
||||
|
||||
static const struct flags_char flags_array[] = {
|
||||
{ EXT2_NOATIME_FL, 'A' },
|
||||
{ EXT2_SYNC_FL, 'S' },
|
||||
{ EXT2_DIRSYNC_FL, 'D' },
|
||||
{ EXT2_APPEND_FL, 'a' },
|
||||
{ EXT2_COMPR_FL, 'c' },
|
||||
{ EXT2_NODUMP_FL, 'd' },
|
||||
{ EXT2_IMMUTABLE_FL, 'i' },
|
||||
{ EXT3_JOURNAL_DATA_FL, 'j' },
|
||||
{ EXT2_SECRM_FL, 's' },
|
||||
{ EXT2_UNRM_FL, 'u' },
|
||||
{ EXT2_NOTAIL_FL, 't' },
|
||||
{ EXT2_TOPDIR_FL, 'T' },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static unsigned long get_flag(char c)
|
||||
{
|
||||
const struct flags_char *fp;
|
||||
for (fp = flags_array; fp->flag; fp++)
|
||||
if (fp->optchar == c)
|
||||
return fp->flag;
|
||||
bb_show_usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decode_arg(char *arg)
|
||||
{
|
||||
unsigned long *fl;
|
||||
char opt = *arg++;
|
||||
|
||||
if (opt == '-') {
|
||||
flags |= OPT_REM;
|
||||
fl = &rf;
|
||||
} else if (opt == '+') {
|
||||
flags |= OPT_ADD;
|
||||
fl = ⁡
|
||||
} else if (opt == '=') {
|
||||
flags |= OPT_SET;
|
||||
fl = &sf;
|
||||
} else
|
||||
return EOF;
|
||||
|
||||
for (; *arg; ++arg)
|
||||
(*fl) |= get_flag(*arg);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int chattr_dir_proc(const char *, struct dirent *, void *);
|
||||
|
||||
static void change_attributes(const char * name)
|
||||
{
|
||||
unsigned long fsflags;
|
||||
struct stat st;
|
||||
|
||||
if (lstat(name, &st) == -1) {
|
||||
bb_error_msg("stat %s failed", name);
|
||||
return;
|
||||
}
|
||||
if (S_ISLNK(st.st_mode) && recursive)
|
||||
return;
|
||||
|
||||
/* Don't try to open device files, fifos etc. We probably
|
||||
* ought to display an error if the file was explicitly given
|
||||
* on the command line (whether or not recursive was
|
||||
* requested). */
|
||||
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode))
|
||||
return;
|
||||
|
||||
if (flags & OPT_SET_VER)
|
||||
if (fsetversion(name, version) == -1)
|
||||
bb_error_msg("setting version on %s", name);
|
||||
|
||||
if (flags & OPT_SET) {
|
||||
fsflags = sf;
|
||||
} else {
|
||||
if (fgetflags(name, &fsflags) == -1) {
|
||||
bb_error_msg("reading flags on %s", name);
|
||||
goto skip_setflags;
|
||||
}
|
||||
if (flags & OPT_REM)
|
||||
fsflags &= ~rf;
|
||||
if (flags & OPT_ADD)
|
||||
fsflags |= af;
|
||||
if (!S_ISDIR(st.st_mode))
|
||||
fsflags &= ~EXT2_DIRSYNC_FL;
|
||||
}
|
||||
if (fsetflags(name, fsflags) == -1)
|
||||
bb_error_msg("setting flags on %s", name);
|
||||
|
||||
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] || (de->d_name[1] == '.' && !de->d_name[2]))
|
||||
) {
|
||||
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) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chattr_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *arg;
|
||||
|
||||
/* parse the args */
|
||||
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;
|
||||
} else if (arg[1] == 'v' && arg[2] == '\0') {
|
||||
char *tmp;
|
||||
++i;
|
||||
if (i >= argc)
|
||||
bb_show_usage();
|
||||
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) == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
/* run sanity checks on all the arguments given us */
|
||||
if (i >= argc)
|
||||
bb_show_usage();
|
||||
if ((flags & OPT_SET) && ((flags & OPT_ADD) || (flags & OPT_REM)))
|
||||
bb_error_msg_and_die("= is incompatible with - and +");
|
||||
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 +");
|
||||
|
||||
/* now run chattr on all the files passed to us */
|
||||
while (i < argc)
|
||||
change_attributes(argv[i++]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* File: e2fsbb.h
|
||||
*
|
||||
* Redefine a bunch of e2fsprogs stuff to use busybox routines
|
||||
* instead. This makes upgrade between e2fsprogs versions easy.
|
||||
*/
|
||||
|
||||
#ifndef E2FSBB_H
|
||||
#define E2FSBB_H 1
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* version we've last synced against */
|
||||
#define E2FSPROGS_VERSION "1.38"
|
||||
#define E2FSPROGS_DATE "30-Jun-2005"
|
||||
|
||||
typedef long errcode_t;
|
||||
#define ERRCODE_RANGE 8
|
||||
#define error_message(code) strerror((int) (code & ((1<<ERRCODE_RANGE)-1)))
|
||||
|
||||
/* header defines */
|
||||
#define ENABLE_HTREE 1
|
||||
#define HAVE_ERRNO_H 1
|
||||
#define HAVE_EXT2_IOCTLS 1
|
||||
#define HAVE_LINUX_FD_H 1
|
||||
#define HAVE_MNTENT_H 1
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
#define HAVE_NET_IF_H 1
|
||||
#define HAVE_SYS_IOCTL_H 1
|
||||
#define HAVE_SYS_MOUNT_H 1
|
||||
#define HAVE_SYS_QUEUE_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Endianness */
|
||||
#if BB_BIG_ENDIAN
|
||||
#define ENABLE_SWAPFS 1
|
||||
#define WORDS_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,638 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <setjmp.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <mntent.h>
|
||||
#include <dirent.h>
|
||||
#include "ext2fs/kernel-list.h"
|
||||
#include <sys/types.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
/*
|
||||
* Now pull in the real linux/jfs.h definitions.
|
||||
*/
|
||||
#include "ext2fs/kernel-jbd.h"
|
||||
|
||||
|
||||
|
||||
#include "fsck.h"
|
||||
|
||||
#include "ext2fs/ext2_fs.h"
|
||||
#include "blkid/blkid.h"
|
||||
#include "ext2fs/ext2_ext_attr.h"
|
||||
#include "uuid/uuid.h"
|
||||
#include "libbb.h"
|
||||
|
||||
#ifdef HAVE_CONIO_H
|
||||
#undef HAVE_TERMIOS_H
|
||||
#include <conio.h>
|
||||
#define read_a_char() getch()
|
||||
#else
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* The last ext2fs revision level that this version of e2fsck is able to
|
||||
* support
|
||||
*/
|
||||
#define E2FSCK_CURRENT_REV 1
|
||||
|
||||
/* Used by the region allocation code */
|
||||
typedef __u32 region_addr_t;
|
||||
typedef struct region_struct *region_t;
|
||||
|
||||
struct dx_dirblock_info {
|
||||
int type;
|
||||
blk_t phys;
|
||||
int flags;
|
||||
blk_t parent;
|
||||
ext2_dirhash_t min_hash;
|
||||
ext2_dirhash_t max_hash;
|
||||
ext2_dirhash_t node_min_hash;
|
||||
ext2_dirhash_t node_max_hash;
|
||||
};
|
||||
|
||||
/*
|
||||
These defines are used in the type field of dx_dirblock_info
|
||||
*/
|
||||
|
||||
#define DX_DIRBLOCK_ROOT 1
|
||||
#define DX_DIRBLOCK_LEAF 2
|
||||
#define DX_DIRBLOCK_NODE 3
|
||||
|
||||
|
||||
/*
|
||||
The following defines are used in the 'flags' field of a dx_dirblock_info
|
||||
*/
|
||||
#define DX_FLAG_REFERENCED 1
|
||||
#define DX_FLAG_DUP_REF 2
|
||||
#define DX_FLAG_FIRST 4
|
||||
#define DX_FLAG_LAST 8
|
||||
|
||||
/*
|
||||
* E2fsck options
|
||||
*/
|
||||
#define E2F_OPT_READONLY 0x0001
|
||||
#define E2F_OPT_PREEN 0x0002
|
||||
#define E2F_OPT_YES 0x0004
|
||||
#define E2F_OPT_NO 0x0008
|
||||
#define E2F_OPT_TIME 0x0010
|
||||
#define E2F_OPT_CHECKBLOCKS 0x0040
|
||||
#define E2F_OPT_DEBUG 0x0080
|
||||
#define E2F_OPT_FORCE 0x0100
|
||||
#define E2F_OPT_WRITECHECK 0x0200
|
||||
#define E2F_OPT_COMPRESS_DIRS 0x0400
|
||||
|
||||
/*
|
||||
* E2fsck flags
|
||||
*/
|
||||
#define E2F_FLAG_ABORT 0x0001 /* Abort signaled */
|
||||
#define E2F_FLAG_CANCEL 0x0002 /* Cancel signaled */
|
||||
#define E2F_FLAG_SIGNAL_MASK 0x0003
|
||||
#define E2F_FLAG_RESTART 0x0004 /* Restart signaled */
|
||||
|
||||
#define E2F_FLAG_SETJMP_OK 0x0010 /* Setjmp valid for abort */
|
||||
|
||||
#define E2F_FLAG_PROG_BAR 0x0020 /* Progress bar on screen */
|
||||
#define E2F_FLAG_PROG_SUPPRESS 0x0040 /* Progress suspended */
|
||||
#define E2F_FLAG_JOURNAL_INODE 0x0080 /* Create a new ext3 journal inode */
|
||||
#define E2F_FLAG_SB_SPECIFIED 0x0100 /* The superblock was explicitly
|
||||
* specified by the user */
|
||||
#define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */
|
||||
#define E2F_FLAG_RESIZE_INODE 0x0400 /* Request to recreate resize inode */
|
||||
|
||||
|
||||
/*Don't know where these come from*/
|
||||
#define READ 0
|
||||
#define WRITE 1
|
||||
#define cpu_to_be32(n) htonl(n)
|
||||
#define be32_to_cpu(n) ntohl(n)
|
||||
|
||||
/*
|
||||
* We define a set of "latch groups"; these are problems which are
|
||||
* handled as a set. The user answers once for a particular latch
|
||||
* group.
|
||||
*/
|
||||
#define PR_LATCH_MASK 0x0ff0 /* Latch mask */
|
||||
#define PR_LATCH_BLOCK 0x0010 /* Latch for illegal blocks (pass 1) */
|
||||
#define PR_LATCH_BBLOCK 0x0020 /* Latch for bad block inode blocks (pass 1) */
|
||||
#define PR_LATCH_IBITMAP 0x0030 /* Latch for pass 5 inode bitmap proc. */
|
||||
#define PR_LATCH_BBITMAP 0x0040 /* Latch for pass 5 inode bitmap proc. */
|
||||
#define PR_LATCH_RELOC 0x0050 /* Latch for superblock relocate hint */
|
||||
#define PR_LATCH_DBLOCK 0x0060 /* Latch for pass 1b dup block headers */
|
||||
#define PR_LATCH_LOW_DTIME 0x0070 /* Latch for pass1 orphaned list refugees */
|
||||
#define PR_LATCH_TOOBIG 0x0080 /* Latch for file to big errors */
|
||||
#define PR_LATCH_OPTIMIZE_DIR 0x0090 /* Latch for optimize directories */
|
||||
|
||||
#define PR_LATCH(x) ((((x) & PR_LATCH_MASK) >> 4) - 1)
|
||||
|
||||
/*
|
||||
* Latch group descriptor flags
|
||||
*/
|
||||
#define PRL_YES 0x0001 /* Answer yes */
|
||||
#define PRL_NO 0x0002 /* Answer no */
|
||||
#define PRL_LATCHED 0x0004 /* The latch group is latched */
|
||||
#define PRL_SUPPRESS 0x0008 /* Suppress all latch group questions */
|
||||
|
||||
#define PRL_VARIABLE 0x000f /* All the flags that need to be reset */
|
||||
|
||||
/*
|
||||
* Pre-Pass 1 errors
|
||||
*/
|
||||
|
||||
#define PR_0_BB_NOT_GROUP 0x000001 /* Block bitmap not in group */
|
||||
#define PR_0_IB_NOT_GROUP 0x000002 /* Inode bitmap not in group */
|
||||
#define PR_0_ITABLE_NOT_GROUP 0x000003 /* Inode table not in group */
|
||||
#define PR_0_SB_CORRUPT 0x000004 /* Superblock corrupt */
|
||||
#define PR_0_FS_SIZE_WRONG 0x000005 /* Filesystem size is wrong */
|
||||
#define PR_0_NO_FRAGMENTS 0x000006 /* Fragments not supported */
|
||||
#define PR_0_BLOCKS_PER_GROUP 0x000007 /* Bad blocks_per_group */
|
||||
#define PR_0_FIRST_DATA_BLOCK 0x000008 /* Bad first_data_block */
|
||||
#define PR_0_ADD_UUID 0x000009 /* Adding UUID to filesystem */
|
||||
#define PR_0_RELOCATE_HINT 0x00000A /* Relocate hint */
|
||||
#define PR_0_MISC_CORRUPT_SUPER 0x00000B /* Miscellaneous superblock corruption */
|
||||
#define PR_0_GETSIZE_ERROR 0x00000C /* Error determing physical device size of filesystem */
|
||||
#define PR_0_INODE_COUNT_WRONG 0x00000D /* Inode count in the superblock incorrect */
|
||||
#define PR_0_HURD_CLEAR_FILETYPE 0x00000E /* The Hurd does not support the filetype feature */
|
||||
#define PR_0_JOURNAL_BAD_INODE 0x00000F /* The Hurd does not support the filetype feature */
|
||||
#define PR_0_JOURNAL_UNSUPP_MULTIFS 0x000010 /* The external journal has multiple filesystems (which we can't handle yet) */
|
||||
#define PR_0_CANT_FIND_JOURNAL 0x000011 /* Can't find external journal */
|
||||
#define PR_0_EXT_JOURNAL_BAD_SUPER 0x000012/* External journal has bad superblock */
|
||||
#define PR_0_JOURNAL_BAD_UUID 0x000013 /* Superblock has a bad journal UUID */
|
||||
#define PR_0_JOURNAL_UNSUPP_SUPER 0x000014 /* Journal has an unknown superblock type */
|
||||
#define PR_0_JOURNAL_BAD_SUPER 0x000015 /* Journal superblock is corrupt */
|
||||
#define PR_0_JOURNAL_HAS_JOURNAL 0x000016 /* Journal superblock is corrupt */
|
||||
#define PR_0_JOURNAL_RECOVER_SET 0x000017 /* Superblock has recovery flag set but no journal */
|
||||
#define PR_0_JOURNAL_RECOVERY_CLEAR 0x000018 /* Journal has data, but recovery flag is clear */
|
||||
#define PR_0_JOURNAL_RESET_JOURNAL 0x000019 /* Ask if we should clear the journal */
|
||||
#define PR_0_FS_REV_LEVEL 0x00001A /* Filesystem revision is 0, but feature flags are set */
|
||||
#define PR_0_ORPHAN_CLEAR_INODE 0x000020 /* Clearing orphan inode */
|
||||
#define PR_0_ORPHAN_ILLEGAL_BLOCK_NUM 0x000021 /* Illegal block found in orphaned inode */
|
||||
#define PR_0_ORPHAN_ALREADY_CLEARED_BLOCK 0x000022 /* Already cleared block found in orphaned inode */
|
||||
#define PR_0_ORPHAN_ILLEGAL_HEAD_INODE 0x000023 /* Illegal orphan inode in superblock */
|
||||
#define PR_0_ORPHAN_ILLEGAL_INODE 0x000024 /* Illegal inode in orphaned inode list */
|
||||
#define PR_0_JOURNAL_UNSUPP_ROCOMPAT 0x000025 /* Journal has unsupported read-only feature - abort */
|
||||
#define PR_0_JOURNAL_UNSUPP_INCOMPAT 0x000026 /* Journal has unsupported incompatible feature - abort */
|
||||
#define PR_0_JOURNAL_UNSUPP_VERSION 0x000027 /* Journal has unsupported version number */
|
||||
#define PR_0_MOVE_JOURNAL 0x000028 /* Moving journal to hidden file */
|
||||
#define PR_0_ERR_MOVE_JOURNAL 0x000029 /* Error moving journal */
|
||||
#define PR_0_CLEAR_V2_JOURNAL 0x00002A /* Clearing V2 journal superblock */
|
||||
#define PR_0_JOURNAL_RUN 0x00002B /* Run journal anyway */
|
||||
#define PR_0_JOURNAL_RUN_DEFAULT 0x00002C /* Run journal anyway by default */
|
||||
#define PR_0_BACKUP_JNL 0x00002D /* Backup journal inode blocks */
|
||||
#define PR_0_NONZERO_RESERVED_GDT_BLOCKS 0x00002E /* Reserved blocks w/o resize_inode */
|
||||
#define PR_0_CLEAR_RESIZE_INODE 0x00002F /* Resize_inode not enabled, but resize inode is non-zero */
|
||||
#define PR_0_RESIZE_INODE_INVALID 0x000030 /* Resize inode invalid */
|
||||
|
||||
/*
|
||||
* Pass 1 errors
|
||||
*/
|
||||
|
||||
#define PR_1_PASS_HEADER 0x010000 /* Pass 1: Checking inodes, blocks, and sizes */
|
||||
#define PR_1_ROOT_NO_DIR 0x010001 /* Root directory is not an inode */
|
||||
#define PR_1_ROOT_DTIME 0x010002 /* Root directory has dtime set */
|
||||
#define PR_1_RESERVED_BAD_MODE 0x010003 /* Reserved inode has bad mode */
|
||||
#define PR_1_ZERO_DTIME 0x010004 /* Deleted inode has zero dtime */
|
||||
#define PR_1_SET_DTIME 0x010005 /* Inode in use, but dtime set */
|
||||
#define PR_1_ZERO_LENGTH_DIR 0x010006 /* Zero-length directory */
|
||||
#define PR_1_BB_CONFLICT 0x010007 /* Block bitmap conflicts with some other fs block */
|
||||
#define PR_1_IB_CONFLICT 0x010008 /* Inode bitmap conflicts with some other fs block */
|
||||
#define PR_1_ITABLE_CONFLICT 0x010009 /* Inode table conflicts with some other fs block */
|
||||
#define PR_1_BB_BAD_BLOCK 0x01000A /* Block bitmap is on a bad block */
|
||||
#define PR_1_IB_BAD_BLOCK 0x01000B /* Inode bitmap is on a bad block */
|
||||
#define PR_1_BAD_I_SIZE 0x01000C /* Inode has incorrect i_size */
|
||||
#define PR_1_BAD_I_BLOCKS 0x01000D /* Inode has incorrect i_blocks */
|
||||
#define PR_1_ILLEGAL_BLOCK_NUM 0x01000E /* Illegal block number in inode */
|
||||
#define PR_1_BLOCK_OVERLAPS_METADATA 0x01000F /* Block number overlaps fs metadata */
|
||||
#define PR_1_INODE_BLOCK_LATCH 0x010010 /* Inode has illegal blocks (latch question) */
|
||||
#define PR_1_TOO_MANY_BAD_BLOCKS 0x010011 /* Too many bad blocks in inode */
|
||||
#define PR_1_BB_ILLEGAL_BLOCK_NUM 0x010012 /* Illegal block number in bad block inode */
|
||||
#define PR_1_INODE_BBLOCK_LATCH 0x010013 /* Bad block inode has illegal blocks (latch question) */
|
||||
#define PR_1_DUP_BLOCKS_PREENSTOP 0x010014 /* Duplicate or bad blocks in use! */
|
||||
#define PR_1_BBINODE_BAD_METABLOCK 0x010015 /* Bad block used as bad block indirect block */
|
||||
#define PR_1_BBINODE_BAD_METABLOCK_PROMPT 0x010016 /* Inconsistency can't be fixed prompt */
|
||||
#define PR_1_BAD_PRIMARY_BLOCK 0x010017 /* Bad primary block */
|
||||
#define PR_1_BAD_PRIMARY_BLOCK_PROMPT 0x010018 /* Bad primary block prompt */
|
||||
#define PR_1_BAD_PRIMARY_SUPERBLOCK 0x010019 /* Bad primary superblock */
|
||||
#define PR_1_BAD_PRIMARY_GROUP_DESCRIPTOR 0x01001A /* Bad primary block group descriptors */
|
||||
#define PR_1_BAD_SUPERBLOCK 0x01001B /* Bad superblock in group */
|
||||
#define PR_1_BAD_GROUP_DESCRIPTORS 0x01001C /* Bad block group descriptors in group */
|
||||
#define PR_1_PROGERR_CLAIMED_BLOCK 0x01001D /* Block claimed for no reason */
|
||||
#define PR_1_RELOC_BLOCK_ALLOCATE 0x01001E /* Error allocating blocks for relocating metadata */
|
||||
#define PR_1_RELOC_MEMORY_ALLOCATE 0x01001F /* Error allocating block buffer during relocation process */
|
||||
#define PR_1_RELOC_FROM_TO 0x010020 /* Relocating metadata group information from X to Y */
|
||||
#define PR_1_RELOC_TO 0x010021 /* Relocating metatdata group information to X */
|
||||
#define PR_1_RELOC_READ_ERR 0x010022 /* Block read error during relocation process */
|
||||
#define PR_1_RELOC_WRITE_ERR 0x010023 /* Block write error during relocation process */
|
||||
#define PR_1_ALLOCATE_IBITMAP_ERROR 0x010024 /* Error allocating inode bitmap */
|
||||
#define PR_1_ALLOCATE_BBITMAP_ERROR 0x010025 /* Error allocating block bitmap */
|
||||
#define PR_1_ALLOCATE_ICOUNT 0x010026 /* Error allocating icount structure */
|
||||
#define PR_1_ALLOCATE_DBCOUNT 0x010027 /* Error allocating dbcount */
|
||||
#define PR_1_ISCAN_ERROR 0x010028 /* Error while scanning inodes */
|
||||
#define PR_1_BLOCK_ITERATE 0x010029 /* Error while iterating over blocks */
|
||||
#define PR_1_ICOUNT_STORE 0x01002A /* Error while storing inode count information */
|
||||
#define PR_1_ADD_DBLOCK 0x01002B /* Error while storing directory block information */
|
||||
#define PR_1_READ_INODE 0x01002C /* Error while reading inode (for clearing) */
|
||||
#define PR_1_SUPPRESS_MESSAGES 0x01002D /* Suppress messages prompt */
|
||||
#define PR_1_SET_IMAGIC 0x01002F /* Imagic flag set on an inode when filesystem doesn't support it */
|
||||
#define PR_1_SET_IMMUTABLE 0x010030 /* Immutable flag set on a device or socket inode */
|
||||
#define PR_1_COMPR_SET 0x010031 /* Compression flag set on a non-compressed filesystem */
|
||||
#define PR_1_SET_NONZSIZE 0x010032 /* Non-zero size on device, fifo or socket inode */
|
||||
#define PR_1_FS_REV_LEVEL 0x010033 /* Filesystem revision is 0, but feature flags are set */
|
||||
#define PR_1_JOURNAL_INODE_NOT_CLEAR 0x010034 /* Journal inode not in use, needs clearing */
|
||||
#define PR_1_JOURNAL_BAD_MODE 0x010035 /* Journal inode has wrong mode */
|
||||
#define PR_1_LOW_DTIME 0x010036 /* Inode that was part of orphan linked list */
|
||||
#define PR_1_ORPHAN_LIST_REFUGEES 0x010037 /* Latch question which asks how to deal with low dtime inodes */
|
||||
#define PR_1_ALLOCATE_REFCOUNT 0x010038 /* Error allocating refcount structure */
|
||||
#define PR_1_READ_EA_BLOCK 0x010039 /* Error reading Extended Attribute block */
|
||||
#define PR_1_BAD_EA_BLOCK 0x01003A /* Invalid Extended Attribute block */
|
||||
#define PR_1_EXTATTR_READ_ABORT 0x01003B /* Error reading Extended Attribute block while fixing refcount -- abort */
|
||||
#define PR_1_EXTATTR_REFCOUNT 0x01003C /* Extended attribute reference count incorrect */
|
||||
#define PR_1_EXTATTR_WRITE 0x01003D /* Error writing Extended Attribute block while fixing refcount */
|
||||
#define PR_1_EA_MULTI_BLOCK 0x01003E /* Multiple EA blocks not supported */
|
||||
#define PR_1_EA_ALLOC_REGION 0x01003F /* Error allocating EA region allocation structure */
|
||||
#define PR_1_EA_ALLOC_COLLISION 0x010040 /* Error EA allocation collision */
|
||||
#define PR_1_EA_BAD_NAME 0x010041 /* Bad extended attribute name */
|
||||
#define PR_1_EA_BAD_VALUE 0x010042 /* Bad extended attribute value */
|
||||
#define PR_1_INODE_TOOBIG 0x010043 /* Inode too big (latch question) */
|
||||
#define PR_1_TOOBIG_DIR 0x010044 /* Directory too big */
|
||||
#define PR_1_TOOBIG_REG 0x010045 /* Regular file too big */
|
||||
#define PR_1_TOOBIG_SYMLINK 0x010046 /* Symlink too big */
|
||||
#define PR_1_HTREE_SET 0x010047 /* INDEX_FL flag set on a non-HTREE filesystem */
|
||||
#define PR_1_HTREE_NODIR 0x010048 /* INDEX_FL flag set on a non-directory */
|
||||
#define PR_1_HTREE_BADROOT 0x010049 /* Invalid root node in HTREE directory */
|
||||
#define PR_1_HTREE_HASHV 0x01004A /* Unsupported hash version in HTREE directory */
|
||||
#define PR_1_HTREE_INCOMPAT 0x01004B /* Incompatible flag in HTREE root node */
|
||||
#define PR_1_HTREE_DEPTH 0x01004C /* HTREE too deep */
|
||||
#define PR_1_BB_FS_BLOCK 0x01004D /* Bad block has indirect block that conflicts with filesystem block */
|
||||
#define PR_1_RESIZE_INODE_CREATE 0x01004E /* Resize inode failed */
|
||||
#define PR_1_EXTRA_ISIZE 0x01004F /* inode->i_size is too long */
|
||||
#define PR_1_ATTR_NAME_LEN 0x010050 /* attribute name is too long */
|
||||
#define PR_1_ATTR_VALUE_OFFSET 0x010051 /* wrong EA value offset */
|
||||
#define PR_1_ATTR_VALUE_BLOCK 0x010052 /* wrong EA blocknumber */
|
||||
#define PR_1_ATTR_VALUE_SIZE 0x010053 /* wrong EA value size */
|
||||
#define PR_1_ATTR_HASH 0x010054 /* wrong EA hash value */
|
||||
|
||||
/*
|
||||
* Pass 1b errors
|
||||
*/
|
||||
|
||||
#define PR_1B_PASS_HEADER 0x011000 /* Pass 1B: Rescan for duplicate/bad blocks */
|
||||
#define PR_1B_DUP_BLOCK_HEADER 0x011001 /* Duplicate/bad block(s) header */
|
||||
#define PR_1B_DUP_BLOCK 0x011002 /* Duplicate/bad block(s) in inode */
|
||||
#define PR_1B_DUP_BLOCK_END 0x011003 /* Duplicate/bad block(s) end */
|
||||
#define PR_1B_ISCAN_ERROR 0x011004 /* Error while scanning inodes */
|
||||
#define PR_1B_ALLOCATE_IBITMAP_ERROR 0x011005 /* Error allocating inode bitmap */
|
||||
#define PR_1B_BLOCK_ITERATE 0x0110006 /* Error while iterating over blocks */
|
||||
#define PR_1B_ADJ_EA_REFCOUNT 0x0110007 /* Error adjusting EA refcount */
|
||||
#define PR_1C_PASS_HEADER 0x012000 /* Pass 1C: Scan directories for inodes with dup blocks. */
|
||||
#define PR_1D_PASS_HEADER 0x013000 /* Pass 1D: Reconciling duplicate blocks */
|
||||
#define PR_1D_DUP_FILE 0x013001 /* File has duplicate blocks */
|
||||
#define PR_1D_DUP_FILE_LIST 0x013002 /* List of files sharing duplicate blocks */
|
||||
#define PR_1D_SHARE_METADATA 0x013003 /* File sharing blocks with filesystem metadata */
|
||||
#define PR_1D_NUM_DUP_INODES 0x013004 /* Report of how many duplicate/bad inodes */
|
||||
#define PR_1D_DUP_BLOCKS_DEALT 0x013005 /* Duplicated blocks already reassigned or cloned. */
|
||||
#define PR_1D_CLONE_QUESTION 0x013006 /* Clone duplicate/bad blocks? */
|
||||
#define PR_1D_DELETE_QUESTION 0x013007 /* Delete file? */
|
||||
#define PR_1D_CLONE_ERROR 0x013008 /* Couldn't clone file (error) */
|
||||
|
||||
/*
|
||||
* Pass 2 errors
|
||||
*/
|
||||
|
||||
#define PR_2_PASS_HEADER 0x020000 /* Pass 2: Checking directory structure */
|
||||
#define PR_2_BAD_INODE_DOT 0x020001 /* Bad inode number for '.' */
|
||||
#define PR_2_BAD_INO 0x020002 /* Directory entry has bad inode number */
|
||||
#define PR_2_UNUSED_INODE 0x020003 /* Directory entry has deleted or unused inode */
|
||||
#define PR_2_LINK_DOT 0x020004 /* Directry entry is link to '.' */
|
||||
#define PR_2_BB_INODE 0x020005 /* Directory entry points to inode now located in a bad block */
|
||||
#define PR_2_LINK_DIR 0x020006 /* Directory entry contains a link to a directory */
|
||||
#define PR_2_LINK_ROOT 0x020007 /* Directory entry contains a link to the root directry */
|
||||
#define PR_2_BAD_NAME 0x020008 /* Directory entry has illegal characters in its name */
|
||||
#define PR_2_MISSING_DOT 0x020009 /* Missing '.' in directory inode */
|
||||
#define PR_2_MISSING_DOT_DOT 0x02000A /* Missing '..' in directory inode */
|
||||
#define PR_2_1ST_NOT_DOT 0x02000B /* First entry in directory inode doesn't contain '.' */
|
||||
#define PR_2_2ND_NOT_DOT_DOT 0x02000C /* Second entry in directory inode doesn't contain '..' */
|
||||
#define PR_2_FADDR_ZERO 0x02000D /* i_faddr should be zero */
|
||||
#define PR_2_FILE_ACL_ZERO 0x02000E /* i_file_acl should be zero */
|
||||
#define PR_2_DIR_ACL_ZERO 0x02000F /* i_dir_acl should be zero */
|
||||
#define PR_2_FRAG_ZERO 0x020010 /* i_frag should be zero */
|
||||
#define PR_2_FSIZE_ZERO 0x020011 /* i_fsize should be zero */
|
||||
#define PR_2_BAD_MODE 0x020012 /* inode has bad mode */
|
||||
#define PR_2_DIR_CORRUPTED 0x020013 /* directory corrupted */
|
||||
#define PR_2_FILENAME_LONG 0x020014 /* filename too long */
|
||||
#define PR_2_DIRECTORY_HOLE 0x020015 /* Directory inode has a missing block (hole) */
|
||||
#define PR_2_DOT_NULL_TERM 0x020016 /* '.' is not NULL terminated */
|
||||
#define PR_2_DOT_DOT_NULL_TERM 0x020017 /* '..' is not NULL terminated */
|
||||
#define PR_2_BAD_CHAR_DEV 0x020018 /* Illegal character device in inode */
|
||||
#define PR_2_BAD_BLOCK_DEV 0x020019 /* Illegal block device in inode */
|
||||
#define PR_2_DUP_DOT 0x02001A /* Duplicate '.' entry */
|
||||
#define PR_2_DUP_DOT_DOT 0x02001B /* Duplicate '..' entry */
|
||||
#define PR_2_NO_DIRINFO 0x02001C /* Internal error: couldn't find dir_info */
|
||||
#define PR_2_FINAL_RECLEN 0x02001D /* Final rec_len is wrong */
|
||||
#define PR_2_ALLOCATE_ICOUNT 0x02001E /* Error allocating icount structure */
|
||||
#define PR_2_DBLIST_ITERATE 0x02001F /* Error iterating over directory blocks */
|
||||
#define PR_2_READ_DIRBLOCK 0x020020 /* Error reading directory block */
|
||||
#define PR_2_WRITE_DIRBLOCK 0x020021 /* Error writing directory block */
|
||||
#define PR_2_ALLOC_DIRBOCK 0x020022 /* Error allocating new directory block */
|
||||
#define PR_2_DEALLOC_INODE 0x020023 /* Error deallocating inode */
|
||||
#define PR_2_SPLIT_DOT 0x020024 /* Directory entry for '.' is big. Split? */
|
||||
#define PR_2_BAD_FIFO 0x020025 /* Illegal FIFO */
|
||||
#define PR_2_BAD_SOCKET 0x020026 /* Illegal socket */
|
||||
#define PR_2_SET_FILETYPE 0x020027 /* Directory filetype not set */
|
||||
#define PR_2_BAD_FILETYPE 0x020028 /* Directory filetype incorrect */
|
||||
#define PR_2_CLEAR_FILETYPE 0x020029 /* Directory filetype set when it shouldn't be */
|
||||
#define PR_2_NULL_NAME 0x020030 /* Directory filename can't be zero-length */
|
||||
#define PR_2_INVALID_SYMLINK 0x020031 /* Invalid symlink */
|
||||
#define PR_2_FILE_ACL_BAD 0x020032 /* i_file_acl (extended attribute) is bad */
|
||||
#define PR_2_FEATURE_LARGE_FILES 0x020033 /* Filesystem contains large files, but has no such flag in sb */
|
||||
#define PR_2_HTREE_NOTREF 0x020034 /* Node in HTREE directory not referenced */
|
||||
#define PR_2_HTREE_DUPREF 0x020035 /* Node in HTREE directory referenced twice */
|
||||
#define PR_2_HTREE_MIN_HASH 0x020036 /* Node in HTREE directory has bad min hash */
|
||||
#define PR_2_HTREE_MAX_HASH 0x020037 /* Node in HTREE directory has bad max hash */
|
||||
#define PR_2_HTREE_CLEAR 0x020038 /* Clear invalid HTREE directory */
|
||||
#define PR_2_HTREE_BADBLK 0x02003A /* Bad block in htree interior node */
|
||||
#define PR_2_ADJ_EA_REFCOUNT 0x02003B /* Error adjusting EA refcount */
|
||||
#define PR_2_HTREE_BAD_ROOT 0x02003C /* Invalid HTREE root node */
|
||||
#define PR_2_HTREE_BAD_LIMIT 0x02003D /* Invalid HTREE limit */
|
||||
#define PR_2_HTREE_BAD_COUNT 0x02003E /* Invalid HTREE count */
|
||||
#define PR_2_HTREE_HASH_ORDER 0x02003F /* HTREE interior node has out-of-order hashes in table */
|
||||
#define PR_2_HTREE_BAD_DEPTH 0x020040 /* Node in HTREE directory has bad depth */
|
||||
#define PR_2_DUPLICATE_DIRENT 0x020041 /* Duplicate directory entry found */
|
||||
#define PR_2_NON_UNIQUE_FILE 0x020042 /* Non-unique filename found */
|
||||
#define PR_2_REPORT_DUP_DIRENT 0x020043 /* Duplicate directory entry found */
|
||||
|
||||
/*
|
||||
* Pass 3 errors
|
||||
*/
|
||||
|
||||
#define PR_3_PASS_HEADER 0x030000 /* Pass 3: Checking directory connectivity */
|
||||
#define PR_3_NO_ROOT_INODE 0x030001 /* Root inode not allocated */
|
||||
#define PR_3_EXPAND_LF_DIR 0x030002 /* No room in lost+found */
|
||||
#define PR_3_UNCONNECTED_DIR 0x030003 /* Unconnected directory inode */
|
||||
#define PR_3_NO_LF_DIR 0x030004 /* /lost+found not found */
|
||||
#define PR_3_BAD_DOT_DOT 0x030005 /* .. entry is incorrect */
|
||||
#define PR_3_NO_LPF 0x030006 /* Bad or non-existent /lost+found. Cannot reconnect */
|
||||
#define PR_3_CANT_EXPAND_LPF 0x030007 /* Could not expand /lost+found */
|
||||
#define PR_3_CANT_RECONNECT 0x030008 /* Could not reconnect inode */
|
||||
#define PR_3_ERR_FIND_LPF 0x030009 /* Error while trying to find /lost+found */
|
||||
#define PR_3_ERR_LPF_NEW_BLOCK 0x03000A /* Error in ext2fs_new_block while creating /lost+found */
|
||||
#define PR_3_ERR_LPF_NEW_INODE 0x03000B /* Error in ext2fs_new_inode while creating /lost+found */
|
||||
#define PR_3_ERR_LPF_NEW_DIR_BLOCK 0x03000C /* Error in ext2fs_new_dir_block while creating /lost+found */
|
||||
#define PR_3_ERR_LPF_WRITE_BLOCK 0x03000D /* Error while writing directory block for /lost+found */
|
||||
#define PR_3_ADJUST_INODE 0x03000E /* Error while adjusting inode count */
|
||||
#define PR_3_FIX_PARENT_ERR 0x03000F /* Couldn't fix parent directory -- error */
|
||||
#define PR_3_FIX_PARENT_NOFIND 0x030010 /* Couldn't fix parent directory -- couldn't find it */
|
||||
#define PR_3_ALLOCATE_IBITMAP_ERROR 0x030011 /* Error allocating inode bitmap */
|
||||
#define PR_3_CREATE_ROOT_ERROR 0x030012 /* Error creating root directory */
|
||||
#define PR_3_CREATE_LPF_ERROR 0x030013 /* Error creating lost and found directory */
|
||||
#define PR_3_ROOT_NOT_DIR_ABORT 0x030014 /* Root inode is not directory; aborting */
|
||||
#define PR_3_NO_ROOT_INODE_ABORT 0x030015 /* Cannot proceed without a root inode. */
|
||||
#define PR_3_NO_DIRINFO 0x030016 /* Internal error: couldn't find dir_info */
|
||||
#define PR_3_LPF_NOTDIR 0x030017 /* Lost+found is not a directory */
|
||||
|
||||
/*
|
||||
* Pass 3a --- rehashing diretories
|
||||
*/
|
||||
#define PR_3A_PASS_HEADER 0x031000 /* Pass 3a: Reindexing directories */
|
||||
#define PR_3A_OPTIMIZE_ITER 0x031001 /* Error iterating over directories */
|
||||
#define PR_3A_OPTIMIZE_DIR_ERR 0x031002 /* Error rehash directory */
|
||||
#define PR_3A_OPTIMIZE_DIR_HEADER 0x031003 /* Rehashing dir header */
|
||||
#define PR_3A_OPTIMIZE_DIR 0x031004 /* Rehashing directory %d */
|
||||
#define PR_3A_OPTIMIZE_DIR_END 0x031005 /* Rehashing dir end */
|
||||
|
||||
/*
|
||||
* Pass 4 errors
|
||||
*/
|
||||
|
||||
#define PR_4_PASS_HEADER 0x040000 /* Pass 4: Checking reference counts */
|
||||
#define PR_4_ZERO_LEN_INODE 0x040001 /* Unattached zero-length inode */
|
||||
#define PR_4_UNATTACHED_INODE 0x040002 /* Unattached inode */
|
||||
#define PR_4_BAD_REF_COUNT 0x040003 /* Inode ref count wrong */
|
||||
#define PR_4_INCONSISTENT_COUNT 0x040004 /* Inconsistent inode count information cached */
|
||||
|
||||
/*
|
||||
* Pass 5 errors
|
||||
*/
|
||||
|
||||
#define PR_5_PASS_HEADER 0x050000 /* Pass 5: Checking group summary information */
|
||||
#define PR_5_INODE_BMAP_PADDING 0x050001 /* Padding at end of inode bitmap is not set. */
|
||||
#define PR_5_BLOCK_BMAP_PADDING 0x050002 /* Padding at end of block bitmap is not set. */
|
||||
#define PR_5_BLOCK_BITMAP_HEADER 0x050003 /* Block bitmap differences header */
|
||||
#define PR_5_BLOCK_UNUSED 0x050004 /* Block not used, but marked in bitmap */
|
||||
#define PR_5_BLOCK_USED 0x050005 /* Block used, but not marked used in bitmap */
|
||||
#define PR_5_BLOCK_BITMAP_END 0x050006 /* Block bitmap differences end */
|
||||
#define PR_5_INODE_BITMAP_HEADER 0x050007 /* Inode bitmap differences header */
|
||||
#define PR_5_INODE_UNUSED 0x050008 /* Inode not used, but marked in bitmap */
|
||||
#define PR_5_INODE_USED 0x050009 /* Inode used, but not marked used in bitmap */
|
||||
#define PR_5_INODE_BITMAP_END 0x05000A /* Inode bitmap differences end */
|
||||
#define PR_5_FREE_INODE_COUNT_GROUP 0x05000B /* Free inodes count for group wrong */
|
||||
#define PR_5_FREE_DIR_COUNT_GROUP 0x05000C /* Directories count for group wrong */
|
||||
#define PR_5_FREE_INODE_COUNT 0x05000D /* Free inodes count wrong */
|
||||
#define PR_5_FREE_BLOCK_COUNT_GROUP 0x05000E /* Free blocks count for group wrong */
|
||||
#define PR_5_FREE_BLOCK_COUNT 0x05000F /* Free blocks count wrong */
|
||||
#define PR_5_BMAP_ENDPOINTS 0x050010 /* Programming error: bitmap endpoints don't match */
|
||||
#define PR_5_FUDGE_BITMAP_ERROR 0x050011 /* Internal error: fudging end of bitmap */
|
||||
#define PR_5_COPY_IBITMAP_ERROR 0x050012 /* Error copying in replacement inode bitmap */
|
||||
#define PR_5_COPY_BBITMAP_ERROR 0x050013 /* Error copying in replacement block bitmap */
|
||||
#define PR_5_BLOCK_RANGE_UNUSED 0x050014 /* Block range not used, but marked in bitmap */
|
||||
#define PR_5_BLOCK_RANGE_USED 0x050015 /* Block range used, but not marked used in bitmap */
|
||||
#define PR_5_INODE_RANGE_UNUSED 0x050016 /* Inode range not used, but marked in bitmap */
|
||||
#define PR_5_INODE_RANGE_USED 0x050017 /* Inode rangeused, but not marked used in bitmap */
|
||||
|
||||
|
||||
/*
|
||||
* The directory information structure; stores directory information
|
||||
* collected in earlier passes, to avoid disk i/o in fetching the
|
||||
* directory information.
|
||||
*/
|
||||
struct dir_info {
|
||||
ext2_ino_t ino; /* Inode number */
|
||||
ext2_ino_t dotdot; /* Parent according to '..' */
|
||||
ext2_ino_t parent; /* Parent according to treewalk */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The indexed directory information structure; stores information for
|
||||
* directories which contain a hash tree index.
|
||||
*/
|
||||
struct dx_dir_info {
|
||||
ext2_ino_t ino; /* Inode number */
|
||||
int numblocks; /* number of blocks */
|
||||
int hashversion;
|
||||
short depth; /* depth of tree */
|
||||
struct dx_dirblock_info *dx_block; /* Array of size numblocks */
|
||||
};
|
||||
|
||||
/*
|
||||
* Define the extended attribute refcount structure
|
||||
*/
|
||||
typedef struct ea_refcount *ext2_refcount_t;
|
||||
|
||||
struct e2fsck_struct {
|
||||
ext2_filsys fs;
|
||||
const char *program_name;
|
||||
char *filesystem_name;
|
||||
char *device_name;
|
||||
char *io_options;
|
||||
int flags; /* E2fsck internal flags */
|
||||
int options;
|
||||
blk_t use_superblock; /* sb requested by user */
|
||||
blk_t superblock; /* sb used to open fs */
|
||||
int blocksize; /* blocksize */
|
||||
blk_t num_blocks; /* Total number of blocks */
|
||||
int mount_flags;
|
||||
blkid_cache blkid; /* blkid cache */
|
||||
|
||||
jmp_buf abort_loc;
|
||||
|
||||
unsigned long abort_code;
|
||||
|
||||
int (*progress)(e2fsck_t ctx, int pass, unsigned long cur,
|
||||
unsigned long max);
|
||||
|
||||
ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
|
||||
ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
|
||||
ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
|
||||
ext2fs_inode_bitmap inode_imagic_map; /* AFS inodes */
|
||||
ext2fs_inode_bitmap inode_reg_map; /* Inodes which are regular files*/
|
||||
|
||||
ext2fs_block_bitmap block_found_map; /* Blocks which are in use */
|
||||
ext2fs_block_bitmap block_dup_map; /* Blks referenced more than once */
|
||||
ext2fs_block_bitmap block_ea_map; /* Blocks which are used by EA's */
|
||||
|
||||
/*
|
||||
* Inode count arrays
|
||||
*/
|
||||
ext2_icount_t inode_count;
|
||||
ext2_icount_t inode_link_info;
|
||||
|
||||
ext2_refcount_t refcount;
|
||||
ext2_refcount_t refcount_extra;
|
||||
|
||||
/*
|
||||
* Array of flags indicating whether an inode bitmap, block
|
||||
* bitmap, or inode table is invalid
|
||||
*/
|
||||
int *invalid_inode_bitmap_flag;
|
||||
int *invalid_block_bitmap_flag;
|
||||
int *invalid_inode_table_flag;
|
||||
int invalid_bitmaps; /* There are invalid bitmaps/itable */
|
||||
|
||||
/*
|
||||
* Block buffer
|
||||
*/
|
||||
char *block_buf;
|
||||
|
||||
/*
|
||||
* For pass1_check_directory and pass1_get_blocks
|
||||
*/
|
||||
ext2_ino_t stashed_ino;
|
||||
struct ext2_inode *stashed_inode;
|
||||
|
||||
/*
|
||||
* Location of the lost and found directory
|
||||
*/
|
||||
ext2_ino_t lost_and_found;
|
||||
int bad_lost_and_found;
|
||||
|
||||
/*
|
||||
* Directory information
|
||||
*/
|
||||
int dir_info_count;
|
||||
int dir_info_size;
|
||||
struct dir_info *dir_info;
|
||||
|
||||
/*
|
||||
* Indexed directory information
|
||||
*/
|
||||
int dx_dir_info_count;
|
||||
int dx_dir_info_size;
|
||||
struct dx_dir_info *dx_dir_info;
|
||||
|
||||
/*
|
||||
* Directories to hash
|
||||
*/
|
||||
ext2_u32_list dirs_to_hash;
|
||||
|
||||
/*
|
||||
* Tuning parameters
|
||||
*/
|
||||
int process_inode_size;
|
||||
int inode_buffer_blocks;
|
||||
|
||||
/*
|
||||
* ext3 journal support
|
||||
*/
|
||||
io_channel journal_io;
|
||||
char *journal_name;
|
||||
|
||||
/*
|
||||
* How we display the progress update (for unix)
|
||||
*/
|
||||
int progress_fd;
|
||||
int progress_pos;
|
||||
int progress_last_percent;
|
||||
unsigned int progress_last_time;
|
||||
int interactive; /* Are we connected directly to a tty? */
|
||||
char start_meta[2], stop_meta[2];
|
||||
|
||||
/* File counts */
|
||||
int fs_directory_count;
|
||||
int fs_regular_count;
|
||||
int fs_blockdev_count;
|
||||
int fs_chardev_count;
|
||||
int fs_links_count;
|
||||
int fs_symlinks_count;
|
||||
int fs_fast_symlinks_count;
|
||||
int fs_fifo_count;
|
||||
int fs_total_count;
|
||||
int fs_sockets_count;
|
||||
int fs_ind_count;
|
||||
int fs_dind_count;
|
||||
int fs_tind_count;
|
||||
int fs_fragmented;
|
||||
int large_files;
|
||||
int fs_ext_attr_inodes;
|
||||
int fs_ext_attr_blocks;
|
||||
|
||||
int ext_attr_ver;
|
||||
|
||||
/*
|
||||
* For the use of callers of the e2fsck functions; not used by
|
||||
* e2fsck functions themselves.
|
||||
*/
|
||||
void *priv_data;
|
||||
};
|
||||
|
||||
|
||||
#define tid_gt(x, y) ((x - y) > 0)
|
||||
|
||||
static inline int tid_geq(tid_t x, tid_t y)
|
||||
{
|
||||
int difference = (x - y);
|
||||
return (difference >= 0);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
NEEDED-$(CONFIG_CHATTR) = y
|
||||
NEEDED-$(CONFIG_LSATTR) = y
|
||||
NEEDED-$(CONFIG_MKE2FS) = y
|
||||
NEEDED-$(CONFIG_TUNE2FS) = y
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(NEEDED-y) += fgetsetflags.o fgetsetversion.o pf.o iod.o mntopts.o \
|
||||
feature.o ls.o uuid.o pe.o ostype.o ps.o hashstr.o \
|
||||
parse_num.o
|
||||
@@ -1,64 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "libbb.h"
|
||||
#include <sys/types.h> /* Needed by dirent.h on netbsd */
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "../ext2fs/ext2_fs.h"
|
||||
|
||||
#define E2P_FEATURE_COMPAT 0
|
||||
#define E2P_FEATURE_INCOMPAT 1
|
||||
#define E2P_FEATURE_RO_INCOMPAT 2
|
||||
#ifndef EXT3_FEATURE_INCOMPAT_EXTENTS
|
||||
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
|
||||
#endif
|
||||
|
||||
/* `options' for print_e2flags() */
|
||||
|
||||
#define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */
|
||||
|
||||
/*int fgetversion (const char * name, unsigned long * version);*/
|
||||
/*int fsetversion (const char * name, unsigned long version);*/
|
||||
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)
|
||||
|
||||
/*int fgetflags (const char * name, unsigned long * flags);*/
|
||||
/*int fsetflags (const char * name, unsigned long flags);*/
|
||||
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)
|
||||
|
||||
int getflags (int fd, unsigned long * flags);
|
||||
int getversion (int fd, unsigned long * version);
|
||||
int iterate_on_dir (const char * dir_name,
|
||||
int (*func) (const char *, struct dirent *, void *),
|
||||
void * private);
|
||||
/*void list_super(struct ext2_super_block * s);*/
|
||||
void list_super2(struct ext2_super_block * s, FILE *f);
|
||||
#define list_super(s) list_super2(s, stdout)
|
||||
void print_fs_errors (FILE *f, unsigned short errors);
|
||||
void print_flags (FILE *f, unsigned long flags, unsigned options);
|
||||
void print_fs_state (FILE *f, unsigned short state);
|
||||
int setflags (int fd, unsigned long flags);
|
||||
int setversion (int fd, unsigned long version);
|
||||
|
||||
const char *e2p_feature2string(int compat, unsigned int mask);
|
||||
int e2p_string2feature(char *string, int *compat, unsigned int *mask);
|
||||
int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array);
|
||||
|
||||
int e2p_is_null_uuid(void *uu);
|
||||
void e2p_uuid_to_str(void *uu, char *out);
|
||||
const char *e2p_uuid2str(void *uu);
|
||||
|
||||
const char *e2p_hash2string(int num);
|
||||
int e2p_string2hash(char *string);
|
||||
|
||||
const char *e2p_mntopt2string(unsigned int mask);
|
||||
int e2p_string2mntopt(char *string, unsigned int *mask);
|
||||
int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok);
|
||||
|
||||
unsigned long parse_num_blocks(const char *arg, int log_block_size);
|
||||
|
||||
char *e2p_os2string(int os_type);
|
||||
int e2p_string2os(char *str);
|
||||
@@ -1,187 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* feature.c --- convert between features and strings
|
||||
*
|
||||
* Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
struct feature {
|
||||
int compat;
|
||||
unsigned int mask;
|
||||
const char *string;
|
||||
};
|
||||
|
||||
static const struct feature feature_list[] = {
|
||||
{ E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC,
|
||||
"dir_prealloc" },
|
||||
{ E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL,
|
||||
"has_journal" },
|
||||
{ E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES,
|
||||
"imagic_inodes" },
|
||||
{ E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR,
|
||||
"ext_attr" },
|
||||
{ E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX,
|
||||
"dir_index" },
|
||||
{ E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INO,
|
||||
"resize_inode" },
|
||||
{ E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER,
|
||||
"sparse_super" },
|
||||
{ E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE,
|
||||
"large_file" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION,
|
||||
"compression" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE,
|
||||
"filetype" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER,
|
||||
"needs_recovery" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV,
|
||||
"journal_dev" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS,
|
||||
"extents" },
|
||||
{ E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG,
|
||||
"meta_bg" },
|
||||
{ 0, 0, 0 },
|
||||
};
|
||||
|
||||
const char *e2p_feature2string(int compat, unsigned int mask)
|
||||
{
|
||||
const struct feature *f;
|
||||
static char buf[20];
|
||||
char fchar;
|
||||
int fnum;
|
||||
|
||||
for (f = feature_list; f->string; f++) {
|
||||
if ((compat == f->compat) &&
|
||||
(mask == f->mask))
|
||||
return f->string;
|
||||
}
|
||||
switch (compat) {
|
||||
case E2P_FEATURE_COMPAT:
|
||||
fchar = 'C';
|
||||
break;
|
||||
case E2P_FEATURE_INCOMPAT:
|
||||
fchar = 'I';
|
||||
break;
|
||||
case E2P_FEATURE_RO_INCOMPAT:
|
||||
fchar = 'R';
|
||||
break;
|
||||
default:
|
||||
fchar = '?';
|
||||
break;
|
||||
}
|
||||
for (fnum = 0; mask >>= 1; fnum++);
|
||||
sprintf(buf, "FEATURE_%c%d", fchar, fnum);
|
||||
return buf;
|
||||
}
|
||||
|
||||
int e2p_string2feature(char *string, int *compat_type, unsigned int *mask)
|
||||
{
|
||||
const struct feature *f;
|
||||
char *eptr;
|
||||
int num;
|
||||
|
||||
for (f = feature_list; f->string; f++) {
|
||||
if (!strcasecmp(string, f->string)) {
|
||||
*compat_type = f->compat;
|
||||
*mask = f->mask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (strncasecmp(string, "FEATURE_", 8))
|
||||
return 1;
|
||||
|
||||
switch (string[8]) {
|
||||
case 'c':
|
||||
case 'C':
|
||||
*compat_type = E2P_FEATURE_COMPAT;
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
*compat_type = E2P_FEATURE_INCOMPAT;
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
*compat_type = E2P_FEATURE_RO_INCOMPAT;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
if (string[9] == 0)
|
||||
return 1;
|
||||
num = strtol(string+9, &eptr, 10);
|
||||
if (num > 32 || num < 0)
|
||||
return 1;
|
||||
if (*eptr)
|
||||
return 1;
|
||||
*mask = 1 << num;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline char *skip_over_blanks(char *cp)
|
||||
{
|
||||
while (*cp && isspace(*cp))
|
||||
cp++;
|
||||
return cp;
|
||||
}
|
||||
|
||||
static inline char *skip_over_word(char *cp)
|
||||
{
|
||||
while (*cp && !isspace(*cp) && *cp != ',')
|
||||
cp++;
|
||||
return cp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Edit a feature set array as requested by the user. The ok_array,
|
||||
* if set, allows the application to limit what features the user is
|
||||
* allowed to set or clear using this function.
|
||||
*/
|
||||
int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
|
||||
{
|
||||
char *cp, *buf, *next;
|
||||
int neg;
|
||||
unsigned int mask;
|
||||
int compat_type;
|
||||
|
||||
buf = xstrdup(str);
|
||||
cp = buf;
|
||||
while (cp && *cp) {
|
||||
neg = 0;
|
||||
cp = skip_over_blanks(cp);
|
||||
next = skip_over_word(cp);
|
||||
if (*next == 0)
|
||||
next = 0;
|
||||
else
|
||||
*next = 0;
|
||||
switch (*cp) {
|
||||
case '-':
|
||||
case '^':
|
||||
neg++;
|
||||
case '+':
|
||||
cp++;
|
||||
break;
|
||||
}
|
||||
if (e2p_string2feature(cp, &compat_type, &mask))
|
||||
return 1;
|
||||
if (ok_array && !(ok_array[compat_type] & mask))
|
||||
return 1;
|
||||
if (neg)
|
||||
compat_array[compat_type] &= ~mask;
|
||||
else
|
||||
compat_array[compat_type] |= mask;
|
||||
cp = next ? next+1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* fgetflags.c - Get a file flags on an ext2 file system
|
||||
* fsetflags.c - Set a file flags on an ext2 file system
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/10/30 - Creation
|
||||
*/
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_EXT2_IOCTLS
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
#ifdef O_LARGEFILE
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
|
||||
#else
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags)
|
||||
{
|
||||
#ifdef HAVE_EXT2_IOCTLS
|
||||
struct stat buf;
|
||||
int fd, r, f, save_errno = 0;
|
||||
|
||||
if (!stat(name, &buf) &&
|
||||
!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
|
||||
goto notsupp;
|
||||
}
|
||||
fd = open (name, OPEN_FLAGS);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
if (!get_flags) {
|
||||
f = (int) set_flags;
|
||||
r = ioctl (fd, EXT2_IOC_SETFLAGS, &f);
|
||||
} else {
|
||||
r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
|
||||
*get_flags = f;
|
||||
}
|
||||
if (r == -1)
|
||||
save_errno = errno;
|
||||
close (fd);
|
||||
if (save_errno)
|
||||
errno = save_errno;
|
||||
return r;
|
||||
notsupp:
|
||||
#endif /* HAVE_EXT2_IOCTLS */
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* fgetversion.c - Get a file version on an ext2 file system
|
||||
* fsetversion.c - Set a file version on an ext2 file system
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/10/30 - Creation
|
||||
*/
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
#ifdef O_LARGEFILE
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
|
||||
#else
|
||||
#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
/*
|
||||
To do fsetversion: unsigned long *ptr_version must be set to NULL.
|
||||
and unsigned long version must be set to a value
|
||||
To do fgetversion: unsigned long *ptr_version must NOT be set to NULL
|
||||
and unsigned long version is ignored.
|
||||
TITO.
|
||||
*/
|
||||
|
||||
int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version)
|
||||
{
|
||||
#ifdef HAVE_EXT2_IOCTLS
|
||||
int fd, r, ver, save_errno = 0;
|
||||
|
||||
fd = open (name, OPEN_FLAGS);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
if (!get_version) {
|
||||
ver = (int) set_version;
|
||||
r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
|
||||
} else {
|
||||
r = ioctl (fd, EXT2_IOC_GETVERSION, &ver);
|
||||
*get_version = ver;
|
||||
}
|
||||
if (r == -1)
|
||||
save_errno = errno;
|
||||
close (fd);
|
||||
if (save_errno)
|
||||
errno = save_errno;
|
||||
return r;
|
||||
#else /* ! HAVE_EXT2_IOCTLS */
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
#endif /* ! HAVE_EXT2_IOCTLS */
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* feature.c --- convert between features and strings
|
||||
*
|
||||
* Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
struct hash {
|
||||
int num;
|
||||
const char *string;
|
||||
};
|
||||
|
||||
static const struct hash hash_list[] = {
|
||||
{ EXT2_HASH_LEGACY, "legacy" },
|
||||
{ EXT2_HASH_HALF_MD4, "half_md4" },
|
||||
{ EXT2_HASH_TEA, "tea" },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
const char *e2p_hash2string(int num)
|
||||
{
|
||||
const struct hash *p;
|
||||
static char buf[20];
|
||||
|
||||
for (p = hash_list; p->string; p++) {
|
||||
if (num == p->num)
|
||||
return p->string;
|
||||
}
|
||||
sprintf(buf, "HASHALG_%d", num);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the hash algorithm, or -1 on error
|
||||
*/
|
||||
int e2p_string2hash(char *string)
|
||||
{
|
||||
const struct hash *p;
|
||||
char *eptr;
|
||||
int num;
|
||||
|
||||
for (p = hash_list; p->string; p++) {
|
||||
if (!strcasecmp(string, p->string)) {
|
||||
return p->num;
|
||||
}
|
||||
}
|
||||
if (strncasecmp(string, "HASHALG_", 8))
|
||||
return -1;
|
||||
|
||||
if (string[8] == 0)
|
||||
return -1;
|
||||
num = strtol(string+8, &eptr, 10);
|
||||
if (num > 255 || num < 0)
|
||||
return -1;
|
||||
if (*eptr)
|
||||
return -1;
|
||||
return num;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* iod.c - Iterate a function on each entry of a directory
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/10/30 - Creation
|
||||
*/
|
||||
|
||||
#include "e2p.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
||||
free(de);
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,273 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* ls.c - List the contents of an ext2fs superblock
|
||||
*
|
||||
* Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* Copyright (C) 1995, 1996, 1997 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
static void print_user(unsigned short uid, FILE *f)
|
||||
{
|
||||
struct passwd *pw = getpwuid(uid);
|
||||
fprintf(f, "%u (user %s)\n", uid,
|
||||
(pw == NULL ? "unknown" : pw->pw_name));
|
||||
}
|
||||
|
||||
static void print_group(unsigned short gid, FILE *f)
|
||||
{
|
||||
struct group *gr = getgrgid(gid);
|
||||
fprintf(f, "%u (group %s)\n", gid,
|
||||
(gr == NULL ? "unknown" : gr->gr_name));
|
||||
}
|
||||
|
||||
#define MONTH_INT (86400 * 30)
|
||||
#define WEEK_INT (86400 * 7)
|
||||
#define DAY_INT (86400)
|
||||
#define HOUR_INT (60 * 60)
|
||||
#define MINUTE_INT (60)
|
||||
|
||||
static const char *interval_string(unsigned int secs)
|
||||
{
|
||||
static char buf[256], tmp[80];
|
||||
int hr, min, num;
|
||||
|
||||
buf[0] = 0;
|
||||
|
||||
if (secs == 0)
|
||||
return "<none>";
|
||||
|
||||
if (secs >= MONTH_INT) {
|
||||
num = secs / MONTH_INT;
|
||||
secs -= num*MONTH_INT;
|
||||
sprintf(buf, "%d month%s", num, (num>1) ? "s" : "");
|
||||
}
|
||||
if (secs >= WEEK_INT) {
|
||||
num = secs / WEEK_INT;
|
||||
secs -= num*WEEK_INT;
|
||||
sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "",
|
||||
num, (num>1) ? "s" : "");
|
||||
strcat(buf, tmp);
|
||||
}
|
||||
if (secs >= DAY_INT) {
|
||||
num = secs / DAY_INT;
|
||||
secs -= num*DAY_INT;
|
||||
sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "",
|
||||
num, (num>1) ? "s" : "");
|
||||
strcat(buf, tmp);
|
||||
}
|
||||
if (secs > 0) {
|
||||
hr = secs / HOUR_INT;
|
||||
secs -= hr*HOUR_INT;
|
||||
min = secs / MINUTE_INT;
|
||||
secs -= min*MINUTE_INT;
|
||||
sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "",
|
||||
hr, min, secs);
|
||||
strcat(buf, tmp);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void print_features(struct ext2_super_block * s, FILE *f)
|
||||
{
|
||||
#ifdef EXT2_DYNAMIC_REV
|
||||
int i, j, printed=0;
|
||||
__u32 *mask = &s->s_feature_compat, m;
|
||||
|
||||
fprintf(f, "Filesystem features: ");
|
||||
for (i=0; i <3; i++,mask++) {
|
||||
for (j=0,m=1; j < 32; j++, m<<=1) {
|
||||
if (*mask & m) {
|
||||
fprintf(f, " %s", e2p_feature2string(i, m));
|
||||
printed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (printed == 0)
|
||||
fprintf(f, " (none)");
|
||||
fprintf(f, "\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static void print_mntopts(struct ext2_super_block * s, FILE *f)
|
||||
{
|
||||
#ifdef EXT2_DYNAMIC_REV
|
||||
int i, printed=0;
|
||||
__u32 mask = s->s_default_mount_opts, m;
|
||||
|
||||
fprintf(f, "Default mount options: ");
|
||||
if (mask & EXT3_DEFM_JMODE) {
|
||||
fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE));
|
||||
printed++;
|
||||
}
|
||||
for (i=0,m=1; i < 32; i++, m<<=1) {
|
||||
if (m & EXT3_DEFM_JMODE)
|
||||
continue;
|
||||
if (mask & m) {
|
||||
fprintf(f, " %s", e2p_mntopt2string(m));
|
||||
printed++;
|
||||
}
|
||||
}
|
||||
if (printed == 0)
|
||||
fprintf(f, " (none)");
|
||||
fprintf(f, "\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef EXT2_INODE_SIZE
|
||||
#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
|
||||
#endif
|
||||
|
||||
#ifndef EXT2_GOOD_OLD_REV
|
||||
#define EXT2_GOOD_OLD_REV 0
|
||||
#endif
|
||||
|
||||
void list_super2(struct ext2_super_block * sb, FILE *f)
|
||||
{
|
||||
int inode_blocks_per_group;
|
||||
char buf[80], *str;
|
||||
time_t tm;
|
||||
|
||||
inode_blocks_per_group = (((sb->s_inodes_per_group *
|
||||
EXT2_INODE_SIZE(sb)) +
|
||||
EXT2_BLOCK_SIZE(sb) - 1) /
|
||||
EXT2_BLOCK_SIZE(sb));
|
||||
if (sb->s_volume_name[0]) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name));
|
||||
} else
|
||||
strcpy(buf, "<none>");
|
||||
fprintf(f, "Filesystem volume name: %s\n", buf);
|
||||
if (sb->s_last_mounted[0]) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted));
|
||||
} else
|
||||
strcpy(buf, "<not available>");
|
||||
fprintf(f,
|
||||
"Last mounted on: %s\n"
|
||||
"Filesystem UUID: %s\n"
|
||||
"Filesystem magic number: 0x%04X\n"
|
||||
"Filesystem revision #: %d",
|
||||
buf, e2p_uuid2str(sb->s_uuid), sb->s_magic, sb->s_rev_level);
|
||||
if (sb->s_rev_level == EXT2_GOOD_OLD_REV) {
|
||||
fprintf(f, " (original)\n");
|
||||
#ifdef EXT2_DYNAMIC_REV
|
||||
} else if (sb->s_rev_level == EXT2_DYNAMIC_REV) {
|
||||
fprintf(f, " (dynamic)\n");
|
||||
#endif
|
||||
} else
|
||||
fprintf(f, " (unknown)\n");
|
||||
print_features(sb, f);
|
||||
print_mntopts(sb, f);
|
||||
fprintf(f, "Filesystem state: ");
|
||||
print_fs_state (f, sb->s_state);
|
||||
fprintf(f, "\nErrors behavior: ");
|
||||
print_fs_errors(f, sb->s_errors);
|
||||
str = e2p_os2string(sb->s_creator_os);
|
||||
fprintf(f,
|
||||
"\n"
|
||||
"Filesystem OS type: %s\n"
|
||||
"Inode count: %u\n"
|
||||
"Block count: %u\n"
|
||||
"Reserved block count: %u\n"
|
||||
"Free blocks: %u\n"
|
||||
"Free inodes: %u\n"
|
||||
"First block: %u\n"
|
||||
"Block size: %u\n"
|
||||
"Fragment size: %u\n",
|
||||
str, sb->s_inodes_count, sb->s_blocks_count, sb->s_r_blocks_count,
|
||||
sb->s_free_blocks_count, sb->s_free_inodes_count,
|
||||
sb->s_first_data_block, EXT2_BLOCK_SIZE(sb), EXT2_FRAG_SIZE(sb));
|
||||
free(str);
|
||||
if (sb->s_reserved_gdt_blocks)
|
||||
fprintf(f, "Reserved GDT blocks: %u\n",
|
||||
sb->s_reserved_gdt_blocks);
|
||||
fprintf(f,
|
||||
"Blocks per group: %u\n"
|
||||
"Fragments per group: %u\n"
|
||||
"Inodes per group: %u\n"
|
||||
"Inode blocks per group: %u\n",
|
||||
sb->s_blocks_per_group, sb->s_frags_per_group,
|
||||
sb->s_inodes_per_group, inode_blocks_per_group);
|
||||
if (sb->s_first_meta_bg)
|
||||
fprintf(f, "First meta block group: %u\n",
|
||||
sb->s_first_meta_bg);
|
||||
if (sb->s_mkfs_time) {
|
||||
tm = sb->s_mkfs_time;
|
||||
fprintf(f, "Filesystem created: %s", ctime(&tm));
|
||||
}
|
||||
tm = sb->s_mtime;
|
||||
fprintf(f, "Last mount time: %s",
|
||||
sb->s_mtime ? ctime(&tm) : "n/a\n");
|
||||
tm = sb->s_wtime;
|
||||
fprintf(f,
|
||||
"Last write time: %s"
|
||||
"Mount count: %u\n"
|
||||
"Maximum mount count: %d\n",
|
||||
ctime(&tm), sb->s_mnt_count, sb->s_max_mnt_count);
|
||||
tm = sb->s_lastcheck;
|
||||
fprintf(f,
|
||||
"Last checked: %s"
|
||||
"Check interval: %u (%s)\n",
|
||||
ctime(&tm),
|
||||
sb->s_checkinterval, interval_string(sb->s_checkinterval));
|
||||
if (sb->s_checkinterval)
|
||||
{
|
||||
time_t next;
|
||||
|
||||
next = sb->s_lastcheck + sb->s_checkinterval;
|
||||
fprintf(f, "Next check after: %s", ctime(&next));
|
||||
}
|
||||
fprintf(f, "Reserved blocks uid: ");
|
||||
print_user(sb->s_def_resuid, f);
|
||||
fprintf(f, "Reserved blocks gid: ");
|
||||
print_group(sb->s_def_resgid, f);
|
||||
if (sb->s_rev_level >= EXT2_DYNAMIC_REV) {
|
||||
fprintf(f,
|
||||
"First inode: %d\n"
|
||||
"Inode size: %d\n",
|
||||
sb->s_first_ino, sb->s_inode_size);
|
||||
}
|
||||
if (!e2p_is_null_uuid(sb->s_journal_uuid))
|
||||
fprintf(f, "Journal UUID: %s\n",
|
||||
e2p_uuid2str(sb->s_journal_uuid));
|
||||
if (sb->s_journal_inum)
|
||||
fprintf(f, "Journal inode: %u\n",
|
||||
sb->s_journal_inum);
|
||||
if (sb->s_journal_dev)
|
||||
fprintf(f, "Journal device: 0x%04x\n",
|
||||
sb->s_journal_dev);
|
||||
if (sb->s_last_orphan)
|
||||
fprintf(f, "First orphan inode: %u\n",
|
||||
sb->s_last_orphan);
|
||||
if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) ||
|
||||
sb->s_def_hash_version)
|
||||
fprintf(f, "Default directory hash: %s\n",
|
||||
e2p_hash2string(sb->s_def_hash_version));
|
||||
if (!e2p_is_null_uuid(sb->s_hash_seed))
|
||||
fprintf(f, "Directory Hash Seed: %s\n",
|
||||
e2p_uuid2str(sb->s_hash_seed));
|
||||
if (sb->s_jnl_backup_type) {
|
||||
fprintf(f, "Journal backup: ");
|
||||
if (sb->s_jnl_backup_type == 1)
|
||||
fprintf(f, "inode blocks\n");
|
||||
else
|
||||
fprintf(f, "type %u\n", sb->s_jnl_backup_type);
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* mountopts.c --- convert between default mount options and strings
|
||||
*
|
||||
* Copyright (C) 2002 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
struct mntopt {
|
||||
unsigned int mask;
|
||||
const char *string;
|
||||
};
|
||||
|
||||
static const struct mntopt mntopt_list[] = {
|
||||
{ EXT2_DEFM_DEBUG, "debug" },
|
||||
{ EXT2_DEFM_BSDGROUPS, "bsdgroups" },
|
||||
{ EXT2_DEFM_XATTR_USER, "user_xattr" },
|
||||
{ EXT2_DEFM_ACL, "acl" },
|
||||
{ EXT2_DEFM_UID16, "uid16" },
|
||||
{ EXT3_DEFM_JMODE_DATA, "journal_data" },
|
||||
{ EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" },
|
||||
{ EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
const char *e2p_mntopt2string(unsigned int mask)
|
||||
{
|
||||
const struct mntopt *f;
|
||||
static char buf[20];
|
||||
int fnum;
|
||||
|
||||
for (f = mntopt_list; f->string; f++) {
|
||||
if (mask == f->mask)
|
||||
return f->string;
|
||||
}
|
||||
for (fnum = 0; mask >>= 1; fnum++);
|
||||
sprintf(buf, "MNTOPT_%d", fnum);
|
||||
return buf;
|
||||
}
|
||||
|
||||
int e2p_string2mntopt(char *string, unsigned int *mask)
|
||||
{
|
||||
const struct mntopt *f;
|
||||
char *eptr;
|
||||
int num;
|
||||
|
||||
for (f = mntopt_list; f->string; f++) {
|
||||
if (!strcasecmp(string, f->string)) {
|
||||
*mask = f->mask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (strncasecmp(string, "MNTOPT_", 8))
|
||||
return 1;
|
||||
|
||||
if (string[8] == 0)
|
||||
return 1;
|
||||
num = strtol(string+8, &eptr, 10);
|
||||
if (num > 32 || num < 0)
|
||||
return 1;
|
||||
if (*eptr)
|
||||
return 1;
|
||||
*mask = 1 << num;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *skip_over_blanks(char *cp)
|
||||
{
|
||||
while (*cp && isspace(*cp))
|
||||
cp++;
|
||||
return cp;
|
||||
}
|
||||
|
||||
static char *skip_over_word(char *cp)
|
||||
{
|
||||
while (*cp && !isspace(*cp) && *cp != ',')
|
||||
cp++;
|
||||
return cp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Edit a mntopt set array as requested by the user. The ok
|
||||
* parameter, if non-zero, allows the application to limit what
|
||||
* mntopts the user is allowed to set or clear using this function.
|
||||
*/
|
||||
int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
|
||||
{
|
||||
char *cp, *buf, *next;
|
||||
int neg;
|
||||
unsigned int mask;
|
||||
|
||||
buf = xstrdup(str);
|
||||
cp = buf;
|
||||
while (cp && *cp) {
|
||||
neg = 0;
|
||||
cp = skip_over_blanks(cp);
|
||||
next = skip_over_word(cp);
|
||||
if (*next == 0)
|
||||
next = 0;
|
||||
else
|
||||
*next = 0;
|
||||
switch (*cp) {
|
||||
case '-':
|
||||
case '^':
|
||||
neg++;
|
||||
case '+':
|
||||
cp++;
|
||||
break;
|
||||
}
|
||||
if (e2p_string2mntopt(cp, &mask))
|
||||
return 1;
|
||||
if (ok && !(ok & mask))
|
||||
return 1;
|
||||
if (mask & EXT3_DEFM_JMODE)
|
||||
*mntopts &= ~EXT3_DEFM_JMODE;
|
||||
if (neg)
|
||||
*mntopts &= ~mask;
|
||||
else
|
||||
*mntopts |= mask;
|
||||
cp = next ? next+1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* getostype.c - Get the Filesystem OS type
|
||||
*
|
||||
* Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
#include "e2p.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char *const os_tab[] =
|
||||
{ "Linux",
|
||||
"Hurd",
|
||||
"Masix",
|
||||
"FreeBSD",
|
||||
"Lites",
|
||||
0 };
|
||||
|
||||
/*
|
||||
* Convert an os_type to a string
|
||||
*/
|
||||
char *e2p_os2string(int os_type)
|
||||
{
|
||||
const char *os;
|
||||
char *ret;
|
||||
|
||||
if (os_type <= EXT2_OS_LITES)
|
||||
os = os_tab[os_type];
|
||||
else
|
||||
os = "(unknown os)";
|
||||
|
||||
ret = xstrdup(os);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an os_type to a string
|
||||
*/
|
||||
int e2p_string2os(char *str)
|
||||
{
|
||||
const char *const *cpp;
|
||||
int i = 0;
|
||||
|
||||
for (cpp = os_tab; *cpp; cpp++, i++) {
|
||||
if (!strcasecmp(str, *cpp))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef TEST_PROGRAM
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s;
|
||||
int i, os;
|
||||
|
||||
for (i=0; i <= EXT2_OS_LITES; i++) {
|
||||
s = e2p_os2string(i);
|
||||
os = e2p_string2os(s);
|
||||
printf("%d: %s (%d)\n", i, s, os);
|
||||
if (i != os) {
|
||||
fprintf(stderr, "Failure!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* parse_num.c - Parse the number of blocks
|
||||
*
|
||||
* Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned long parse_num_blocks(const char *arg, int log_block_size)
|
||||
{
|
||||
char *p;
|
||||
unsigned long long num;
|
||||
|
||||
num = strtoull(arg, &p, 0);
|
||||
|
||||
if (p[0] && p[1])
|
||||
return 0;
|
||||
|
||||
switch (*p) { /* Using fall-through logic */
|
||||
case 'T': case 't':
|
||||
num <<= 10;
|
||||
case 'G': case 'g':
|
||||
num <<= 10;
|
||||
case 'M': case 'm':
|
||||
num <<= 10;
|
||||
case 'K': case 'k':
|
||||
num >>= log_block_size;
|
||||
break;
|
||||
case 's':
|
||||
num >>= 1;
|
||||
break;
|
||||
case '\0':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
unsigned long num;
|
||||
int log_block_size = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s arg\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
num = parse_num_blocks(argv[1], log_block_size);
|
||||
|
||||
printf("Parsed number: %lu\n", num);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* pe.c - Print a second extended filesystem errors behavior
|
||||
*
|
||||
* Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 94/01/09 - Creation
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
void print_fs_errors(FILE *f, unsigned short errors)
|
||||
{
|
||||
char *disp = NULL;
|
||||
switch (errors) {
|
||||
case EXT2_ERRORS_CONTINUE: disp = "Continue"; break;
|
||||
case EXT2_ERRORS_RO: disp = "Remount read-only"; break;
|
||||
case EXT2_ERRORS_PANIC: disp = "Panic"; break;
|
||||
default: disp = "Unknown (continue)";
|
||||
}
|
||||
fprintf(f, disp);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* pf.c - Print file attributes on an ext2 file system
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/10/30 - Creation
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
struct flags_name {
|
||||
unsigned long flag;
|
||||
const 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_direcctory" },
|
||||
{ EXT2_NOTAIL_FL, "t", "No_Tailmerging" },
|
||||
{ EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
void print_flags (FILE *f, unsigned long flags, unsigned options)
|
||||
{
|
||||
int long_opt = (options & PFOPT_LONG);
|
||||
const struct flags_name *fp;
|
||||
int first = 1;
|
||||
|
||||
for (fp = flags_array; fp->flag != 0; fp++) {
|
||||
if (flags & fp->flag) {
|
||||
if (long_opt) {
|
||||
if (first)
|
||||
first = 0;
|
||||
else
|
||||
fputs(", ", f);
|
||||
fputs(fp->long_name, f);
|
||||
} else
|
||||
fputs(fp->short_name, f);
|
||||
} else {
|
||||
if (!long_opt)
|
||||
fputs("-", f);
|
||||
}
|
||||
}
|
||||
if (long_opt && first)
|
||||
fputs("---", f);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* ps.c - Print filesystem state
|
||||
*
|
||||
* Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
|
||||
* Laboratoire MASI, Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* This file can be redistributed under the terms of the GNU Library General
|
||||
* Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
* History:
|
||||
* 93/12/22 - Creation
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
void print_fs_state(FILE *f, unsigned short state)
|
||||
{
|
||||
fprintf(f, (state & EXT2_VALID_FS ? " clean" : " not clean"));
|
||||
if (state & EXT2_ERROR_FS)
|
||||
fprintf(f, " with errors");
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* uuid.c -- utility routines for manipulating UUID's.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../ext2fs/ext2_types.h"
|
||||
|
||||
#include "e2p.h"
|
||||
|
||||
struct uuid {
|
||||
__u32 time_low;
|
||||
__u16 time_mid;
|
||||
__u16 time_hi_and_version;
|
||||
__u16 clock_seq;
|
||||
__u8 node[6];
|
||||
};
|
||||
|
||||
/* Returns 1 if the uuid is the NULL uuid */
|
||||
int e2p_is_null_uuid(void *uu)
|
||||
{
|
||||
__u8 *cp;
|
||||
int i;
|
||||
|
||||
for (i=0, cp = uu; i < 16; i++)
|
||||
if (*cp)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void e2p_unpack_uuid(void *in, struct uuid *uu)
|
||||
{
|
||||
__u8 *ptr = in;
|
||||
__u32 tmp;
|
||||
|
||||
tmp = *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
uu->time_low = tmp;
|
||||
|
||||
tmp = *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
uu->time_mid = tmp;
|
||||
|
||||
tmp = *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
uu->time_hi_and_version = tmp;
|
||||
|
||||
tmp = *ptr++;
|
||||
tmp = (tmp << 8) | *ptr++;
|
||||
uu->clock_seq = tmp;
|
||||
|
||||
memcpy(uu->node, ptr, 6);
|
||||
}
|
||||
|
||||
void e2p_uuid_to_str(void *uu, char *out)
|
||||
{
|
||||
struct uuid uuid;
|
||||
|
||||
e2p_unpack_uuid(uu, &uuid);
|
||||
sprintf(out,
|
||||
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
|
||||
uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
|
||||
uuid.node[0], uuid.node[1], uuid.node[2],
|
||||
uuid.node[3], uuid.node[4], uuid.node[5]);
|
||||
}
|
||||
|
||||
const char *e2p_uuid2str(void *uu)
|
||||
{
|
||||
static char buf[80];
|
||||
if (e2p_is_null_uuid(uu))
|
||||
return "<none>";
|
||||
e2p_uuid_to_str(uu, buf);
|
||||
return buf;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
NEEDED-$(CONFIG_E2FSCK) = y
|
||||
NEEDED-$(CONFIG_FSCK) = y
|
||||
NEEDED-$(CONFIG_MKE2FS) = y
|
||||
NEEDED-$(CONFIG_TUNE2FS) = y
|
||||
|
||||
lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
lib-$(NEEDED-y) += gen_bitmap.o bitops.o ismounted.o mkjournal.o unix_io.o \
|
||||
rw_bitmaps.o initialize.o bitmaps.o block.o \
|
||||
ind_block.o inode.o freefs.o alloc_stats.o closefs.o \
|
||||
openfs.o io_manager.o finddev.o read_bb.o alloc.o badblocks.o \
|
||||
getsize.o getsectsize.o alloc_tables.o read_bb_file.o mkdir.o \
|
||||
bb_inode.o newdir.o alloc_sb.o lookup.o dirblock.o expanddir.o \
|
||||
dir_iterate.o link.o res_gdt.o icount.o get_pathname.o dblist.o \
|
||||
dirhash.o version.o flushb.o unlink.o check_desc.o valid_blk.o \
|
||||
ext_attr.o bmap.o dblist_dir.o ext2fs_inline.o swapfs.o
|
||||
|
||||
CFLAGS += -include $(srctree)/e2fsprogs/e2fsbb.h
|
||||
@@ -1,173 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* alloc.c --- allocate new inodes, blocks for ext2fs
|
||||
*
|
||||
* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Public
|
||||
* License.
|
||||
* %End-Header%
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#if HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
/*
|
||||
* Right now, just search forward from the parent directory's block
|
||||
* group to find the next free inode.
|
||||
*
|
||||
* Should have a special policy for directories.
|
||||
*/
|
||||
errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,
|
||||
int mode EXT2FS_ATTR((unused)),
|
||||
ext2fs_inode_bitmap map, ext2_ino_t *ret)
|
||||
{
|
||||
ext2_ino_t dir_group = 0;
|
||||
ext2_ino_t i;
|
||||
ext2_ino_t start_inode;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
if (!map)
|
||||
map = fs->inode_map;
|
||||
if (!map)
|
||||
return EXT2_ET_NO_INODE_BITMAP;
|
||||
|
||||
if (dir > 0)
|
||||
dir_group = (dir - 1) / EXT2_INODES_PER_GROUP(fs->super);
|
||||
|
||||
start_inode = (dir_group * EXT2_INODES_PER_GROUP(fs->super)) + 1;
|
||||
if (start_inode < EXT2_FIRST_INODE(fs->super))
|
||||
start_inode = EXT2_FIRST_INODE(fs->super);
|
||||
i = start_inode;
|
||||
|
||||
do {
|
||||
if (!ext2fs_fast_test_inode_bitmap(map, i))
|
||||
break;
|
||||
i++;
|
||||
if (i > fs->super->s_inodes_count)
|
||||
i = EXT2_FIRST_INODE(fs->super);
|
||||
} while (i != start_inode);
|
||||
|
||||
if (ext2fs_test_inode_bitmap(map, i))
|
||||
return EXT2_ET_INODE_ALLOC_FAIL;
|
||||
*ret = i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stupid algorithm --- we now just search forward starting from the
|
||||
* goal. Should put in a smarter one someday....
|
||||
*/
|
||||
errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
|
||||
ext2fs_block_bitmap map, blk_t *ret)
|
||||
{
|
||||
blk_t i;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
if (!map)
|
||||
map = fs->block_map;
|
||||
if (!map)
|
||||
return EXT2_ET_NO_BLOCK_BITMAP;
|
||||
if (!goal || (goal >= fs->super->s_blocks_count))
|
||||
goal = fs->super->s_first_data_block;
|
||||
i = goal;
|
||||
do {
|
||||
if (!ext2fs_fast_test_block_bitmap(map, i)) {
|
||||
*ret = i;
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
if (i >= fs->super->s_blocks_count)
|
||||
i = fs->super->s_first_data_block;
|
||||
} while (i != goal);
|
||||
return EXT2_ET_BLOCK_ALLOC_FAIL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function zeros out the allocated block, and updates all of the
|
||||
* appropriate filesystem records.
|
||||
*/
|
||||
errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
|
||||
char *block_buf, blk_t *ret)
|
||||
{
|
||||
errcode_t retval;
|
||||
blk_t block;
|
||||
char *buf = NULL;
|
||||
|
||||
if (!block_buf) {
|
||||
retval = ext2fs_get_mem(fs->blocksize, &buf);
|
||||
if (retval)
|
||||
return retval;
|
||||
block_buf = buf;
|
||||
}
|
||||
memset(block_buf, 0, fs->blocksize);
|
||||
|
||||
if (!fs->block_map) {
|
||||
retval = ext2fs_read_block_bitmap(fs);
|
||||
if (retval)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
retval = ext2fs_new_block(fs, goal, 0, &block);
|
||||
if (retval)
|
||||
goto fail;
|
||||
|
||||
retval = io_channel_write_blk(fs->io, block, 1, block_buf);
|
||||
if (retval)
|
||||
goto fail;
|
||||
|
||||
ext2fs_block_alloc_stats(fs, block, +1);
|
||||
*ret = block;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (buf)
|
||||
ext2fs_free_mem(&buf);
|
||||
return retval;
|
||||
}
|
||||
|
||||
errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
|
||||
int num, ext2fs_block_bitmap map, blk_t *ret)
|
||||
{
|
||||
blk_t b = start;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
if (!map)
|
||||
map = fs->block_map;
|
||||
if (!map)
|
||||
return EXT2_ET_NO_BLOCK_BITMAP;
|
||||
if (!b)
|
||||
b = fs->super->s_first_data_block;
|
||||
if (!finish)
|
||||
finish = start;
|
||||
if (!num)
|
||||
num = 1;
|
||||
do {
|
||||
if (b+num-1 > fs->super->s_blocks_count)
|
||||
b = fs->super->s_first_data_block;
|
||||
if (ext2fs_fast_test_block_bitmap_range(map, b, num)) {
|
||||
*ret = b;
|
||||
return 0;
|
||||
}
|
||||
b++;
|
||||
} while (b != finish);
|
||||
return EXT2_ET_BLOCK_ALLOC_FAIL;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* alloc_sb.c --- Allocate the superblock and block group descriptors for a
|
||||
* newly initialized filesystem. Used by mke2fs when initializing a filesystem
|
||||
*
|
||||
* Copyright (C) 1994, 1995, 1996, 2003 Theodore Ts'o.
|
||||
*
|
||||
* %Begin-Header%
|
||||
* This file may be redistributed under the terms of the GNU Public
|
||||
* License.
|
||||
* %End-Header%
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#if HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "ext2_fs.h"
|
||||
#include "ext2fs.h"
|
||||
|
||||
int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
|
||||
dgrp_t group,
|
||||
ext2fs_block_bitmap bmap)
|
||||
{
|
||||
blk_t super_blk, old_desc_blk, new_desc_blk;
|
||||
int j, old_desc_blocks, num_blocks;
|
||||
|
||||
num_blocks = ext2fs_super_and_bgd_loc(fs, group, &super_blk,
|
||||
&old_desc_blk, &new_desc_blk, 0);
|
||||
|
||||
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
|
||||
old_desc_blocks = fs->super->s_first_meta_bg;
|
||||
else
|
||||
old_desc_blocks =
|
||||
fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
|
||||
|
||||
if (super_blk || (group == 0))
|
||||
ext2fs_mark_block_bitmap(bmap, super_blk);
|
||||
|
||||
if (old_desc_blk) {
|
||||
for (j=0; j < old_desc_blocks; j++)
|
||||
ext2fs_mark_block_bitmap(bmap, old_desc_blk + j);
|
||||
}
|
||||
if (new_desc_blk)
|
||||
ext2fs_mark_block_bitmap(bmap, new_desc_blk);
|
||||
|
||||
return num_blocks;
|
||||
}
|
||||
Loaded 100 of 446 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user