Compare commits

...
272 Commits
Author SHA1 Message Date
Denys Vlasenko b03007455c httpd: fix handling of range requests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 14:08:04 +02:00
Denys Vlasenko ca26f1c238 hush: fix a bug with "stdio rewind on exit". Closes 9186
With FEATURE_SH_STANDALONE=y, run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

`cmd` and arithmetic also need the fix for this, even without
FEATURE_SH_STANDALONE.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 20:24:49 +02:00
Mike Frysinger 8191abd146 ash_test: ignore generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit b9b7aa1910)
2016-03-22 18:22:51 -04:00
Ron Yorston c1565a04f2 ash: simplify EOF/newline handling in list parser
Processing of here documents in ash has had a couple of breakages
which are now the subject of tests.  This commit should fix both.

It is based on the following commit in dash git by Herbert Xu:

   <7c245aa> [PARSER] Simplify EOF/newline handling in list parser

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit c0e007663d)
2016-03-22 18:21:45 -04:00
Ron Yorston acad7392ee Revert "ash: fix a SEGV case in an invalid heredoc" xxx
This reverts commit 7e66102f76 but
leaves the test in place as it's still valid.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 6bd2fabc52)
2016-03-22 18:21:28 -04:00
Ron Yorston 4c07ad9130 ash: add test for issue with here document
This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 9121510dc6)
2016-03-22 18:21:06 -04:00
Ron Yorston 856af4e3dc ash: fix corruption of ${#var} if $var contains UTF-8 characters
As reported in bug 8506:

   $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
   $ echo ${#X}
   abcd26

The result should be 26.

This regression was introduced by:

   <d68d1fb> 2015-05-18 [Ron Yorston]  ash: code shrink around varvalue

The length in characters was being used to discard the contents of
the variable instead of the length in bytes.

URL: https://bugs.busybox.net/8506
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 3e3bfb896e)
2016-03-22 18:20:04 -04:00
Ron Yorston 4194c28753 ash: fix error during recursive processing of here document
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 713f07d906)
2016-03-21 14:28:06 -04:00
Denys Vlasenko 3a76bb5136 udhcp: fix a SEGV on malformed RFC1035-encoded domain name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit d474ffc682)
2016-03-21 14:23:12 -04:00
Denys Vlasenko 3c4de6e36c udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit 352f79acbd)
2016-03-21 14:23:05 -04:00
Denys Vlasenko e50f74da70 Bump version to 1.24.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:38:03 +01:00
Denys Vlasenko 9de318d63e scripts/trylink: fix static build with glibc again. Closes 8471
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:37:12 +01:00
Ari Sundholm be729c1d3b truncate: always set mode when opening file to avoid fortify errors
Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit e111a16404)
2016-01-13 13:33:38 -05:00
Denys Vlasenko 092fabcf1d [g]unzip: fix recent breakage.
Also, do emit error message we so painstakingly pass from gzip internals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 6bd3fff51a)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-02 00:03:42 -05:00
Denys Vlasenko 6767af17f1 unzip: test for bad archive SEGVing
function                                             old     new   delta
huft_build                                          1296    1300      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 1de25a6e87)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-01 11:05:07 -05:00
Denys Vlasenko 5c23f2566c Apply post-1.24.0 patches, bump version to 1.24.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 02:29:00 +02:00
Denys Vlasenko 7ab00a0de9 Bump version to 1.24.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 14:33:03 +02:00
Denys Vlasenko 5de450237c libpwdgrp: do not require that /etc/passwd entries have nonempty home and shell
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 04:06:18 +02:00
Denys Vlasenko 57aeb62f83 randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 03:15:36 +02:00
Denys Vlasenko c8e5ead03a build system: remove special-casing for extra libs
It is not reliable (tried on three systems, multiple problems).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 03:12:17 +02:00
Denys Vlasenko 2dbbf823ef randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 23:48:28 +02:00
Denys Vlasenko 85378cded7 hush: code shrink
function                                             old     new   delta
builtin_wait                                         347     328     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 21:47:11 +02:00
Denys Vlasenko 932302666b randconfig fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 16:58:18 +02:00
Denys Vlasenko 69c8c699aa randconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11 16:27:55 +02:00
Denys Vlasenko 005c492c40 ash: shrink umask code
function                                             old     new   delta
umaskcmd                                             258     248     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-10 20:17:12 +02:00
Denys Vlasenko 02859aaeb2 use auto_string() where appropriate to kill a few statics
Custom linker script 'busybox_ldscript' found, using it
function                                             old     new   delta
static.str                                             4       -      -4
static.passwd                                          4       0      -4
bb_ask                                               322     311     -11
ether_print                                           63      47     -16
UNSPEC_print                                          82      66     -16
INET_sprint                                           59      38     -21
INET6_sprint                                          54      30     -24
make_human_readable_str                              292     235     -57
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/7 up/down: 0/-153)           Total: -153 bytes
   text	   data	    bss	    dec	    hex	filename
 939880	    992	  17480	 958352	  e9f90	busybox_old
 939736	    992	  17456	 958184	  e9ee8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 18:16:40 +02:00
Denys Vlasenko e52da5570e libbb: auto_string() for efficient handling of temporary malloced stirngs
Use it in libiproute: get rid of one static string buffer.

function                                             old     new   delta
auto_string                                            -      51     +51
ll_index_to_name                                      10      49     +39
buffer_fill_and_print                                169     178      +9
scan_recursive                                       378     380      +2
decode_one_format                                    732     734      +2
cmdputs                                              334     332      -2
static.cur_saved                                       4       1      -3
static.nbuf                                           16       -     -16
printable_string                                      94      57     -37
ll_idx_n2a                                            53       -     -53
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 4/3 up/down: 103/-111)           Total: -8 bytes
   text	   data	    bss	    dec	    hex	filename
 939880	    992	  17496	 958368	  e9fa0	busybox_old
 939880	    992	  17480	 958352	  e9f90	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 17:59:56 +02:00
Denys Vlasenko 550bf5b4a4 remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS builds
function                                             old     new   delta
xfunc_has_died                                         -      21     +21
sleep_much                                             -      12     +12
sleep10                                                -       9      +9
die_func                                               -       4      +4
fflush_stdout_and_exit                                35      36      +1
builtin_type                                         121     119      -2
die_sleep                                              4       -      -4
xfunc_die                                             60      24     -36
hush_main                                           1128    1011    -117
die_jmp                                              156       -    -156
------------------------------------------------------------------------------
(add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315)          Total: -268 bytes
   text	   data	    bss	    dec	    hex	filename
 939992	    992	  17652	 958636	  ea0ac	busybox_old
 939880	    992	  17496	 958368	  e9fa0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:42:57 +02:00
Denys Vlasenko 4cd99e7c6c ash: "you have mail" should ignore first change in mtime
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:02:53 +02:00
Denys Vlasenko 2384162f64 ash: simplify "you have mail" code
function                                             old     new   delta
mailtime_hash                                          -       4      +4
redirect                                            1282    1280      -2
mailtime                                              40       -     -40
cmdloop                                              429     378     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-93)             Total: -89 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 15:52:03 +02:00
Denys Vlasenko 4700fb5bea ash: make dowait() a bit more readable. Logic is unchanged
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 15:40:13 +02:00
Denys Vlasenko e1603156ff updated android_ndk_defconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 18:17:31 +02:00
Denys Vlasenko f2bf20f5d5 udhcpc: fix for some Android toolchain breakage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 18:13:57 +02:00
Denys Vlasenko 8403b01217 iproute: more string reuse
text	   data	    bss	    dec	    hex	filename
 936892	    932	  17676	 955500	  e946c	busybox_old
 936843	    932	  17676	 955451	  e943b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 17:15:08 +02:00
Christoph J. Thompson d1eea8db92 iproute: don't hardcode the path to config files
Allows using an alternate path for config files.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Christoph J. Thompson <cjsthompson@gmail.com>
Signed-off-by: Michael Bestas <mikeioannina@gmail.com>
2015-10-08 17:06:06 +02:00
Denys Vlasenko 413feca279 ip: increased max ID for /etc/iproute2/rt_tables to 1023
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 15:10:10 +02:00
Denys Vlasenko 3d8d5e8ad4 libiproute: use itoa() where appropriate
function                                             old     new   delta
rtnl_rtprot_a2n                                       31      88     +57
print_tunnel                                         647     640      -7
print_route                                         1865    1858      -7
print_linkinfo                                       820     812      -8
print_addrinfo                                      1241    1227     -14
rtnl_rttable_n2a                                      53      38     -15
rtnl_rtscope_n2a                                      53      38     -15
rtnl_rtrealm_n2a                                      53      38     -15
rtnl_dsfield_n2a                                      61      38     -23
rtnl_rtntype_n2a                                     118      89     -29
print_rule                                           724     689     -35
ipaddr_list_or_flush                                1293    1253     -40
rtnl_rtprot_n2a                                       53       -     -53
rtnl_rtprot_initialize                                63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/11 up/down: 57/-324)         Total: -267 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 13:02:28 +02:00
Denys Vlasenko 7f3a2a2256 join some common strings, -400 bytes
function                                             old     new   delta
print_intel_cstates                                  499     511     +12
file_insert                                          355     364      +9
dpkg_main                                           2944    2940      -4
ifenslave_main                                       645     640      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 21/-9)              Total: 12 bytes
   text	   data	    bss	    dec	    hex	filename
 937564	    932	  17676	 956172	  e970c	busybox_old
 937164	    932	  17676	 955772	  e957c	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-08 11:24:44 +02:00
Denys Vlasenko d60752f8c9 build system: -fno-builtin-printf
Benefits are: drops reference to out-of-line putchar(), fixes a few cases
of failed string merge.

function                                             old     new   delta
i2cdump_main                                        1488    1502     +14
sha256_process_block64                               423     433     +10
sendmail_main                                       1183    1185      +2
list_table                                          1114    1116      +2
i2cdetect_main                                      1235    1237      +2
fdisk_main                                          2852    2854      +2
builtin_type                                         119     121      +2
unicode_conv_to_printable2                           325     324      -1
scan_recursive                                       380     378      -2
mkfs_minix_main                                     2687    2684      -3
buffer_fill_and_print                                178     169      -9
putchar                                              152       -    -152
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 7/4 up/down: 34/-167)          Total: -133 bytes
   text    data     bss     dec     hex filename
 937788     932   17676  956396   e97ec busybox_old
 937564     932   17676  956172   e970c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 22:42:45 +02:00
Denys Vlasenko 8c0708a329 find: support "find . -delete" idiom - do not try rmdir(".")
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 21:01:47 +02:00
Denys Vlasenko 305958dbd4 md5sum: code shrink
For CONFIG_MD5_SMALL=1:
function                                             old     new   delta
md5_process_block64                                  925     881     -44

For CONFIG_MD5_SMALL=0:
function                                             old     new   delta
md5_process_block64                                 1603    1586     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 19:17:01 +02:00
Denys Vlasenko ec046f74a3 ash: use a more typical form of "print four octal digits" format
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:57:53 +02:00
Denys Vlasenko 5711a2a4ad libbb: more compact API for bb_parse_mode()
function                                             old     new   delta
make_device                                         2182    2188      +6
parse_command                                       1440    1443      +3
parse_params                                        1497    1499      +2
install_main                                         773     769      -4
mkdir_main                                           168     160      -8
getoptscmd                                           641     632      -9
builtin_umask                                        158     147     -11
bb_parse_mode                                        431     410     -21
umaskcmd                                             286     258     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81)            Total: -70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:55:33 +02:00
Denys Vlasenko c1e2e005b4 ash: shrink "umask -S" code
function                                             old     new   delta
umaskcmd                                             279     286      +7
static.permmode                                        3       -      -3
static.permmask                                       18       -     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:32:56 +02:00
Denys Vlasenko 6283f98283 hush: fix umask: umask(022) was setting umask(755)
Based on the patch by Rich Felker <dalias@libc.org>

function                                             old     new   delta
builtin_umask                                        121     161     +40
umaskcmd                                             318     279     -39

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 16:56:20 +02:00
Denys Vlasenko 9c5410023a ash: a bunch of trivial simplifications
Also, in a few places made code more reliable wrt large sizeof(int)
and sizeof(arith_t)..

function                                             old     new   delta
sprint_status48                                        -     143    +143
newline_and_flush                                      -      56     +56
showjob                                              365     382     +17
parse_command                                       1440    1443      +3
cmdputs                                              334     332      -2
cmdloop                                              434     429      -5
showjobs                                              70      64      -6
fg_bgcmd                                             296     290      -6
ash_vmsg                                             159     153      -6
ash_main                                            1487    1481      -6
jobscmd                                               94      82     -12
getoptscmd                                           687     632     -55
outcslow                                              56       -     -56
sprint_status                                        156       -    -156
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/8 up/down: 219/-310)          Total: -91 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 15:44:36 +02:00
Denys Vlasenko 2007ef5c3c wget: make it possible to have both SSL helpers configured
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:40:53 +02:00
Denys Vlasenko 4271698fea ifplugd: discovered why it needed net/ethernet.h: just for ETH_ALEN
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:02:56 +02:00
Denys Vlasenko 78fb6ea63a ssl_helper: tweaks discovered while building 32-bit version
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 02:00:11 +02:00
Denys Vlasenko 1c6c670ed4 wget: make openssl/ssl_helper choice configurable
I got sick of not being able to wget a https file...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 01:39:40 +02:00
Denys Vlasenko 3b650c1e7b qemu testing: extract_od_binary.sh: support huge files (and broken od)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 16:46:29 +02:00
Denys Vlasenko 2b48c38be6 uudecode: tolerate text input with CR+LF line ends
function                                             old     new   delta
read_stduu                                           265     308     +43
uudecode_main                                        313     317      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 15:10:44 +02:00
Denys Vlasenko e6b578761a qemu testing: Do build brctl and ifplugd; force mips32 dialect
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 12:43:04 +02:00
Denys Vlasenko a779c6d63b qemu testing: fix hexdumping of binary
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 12:34:24 +02:00
Denys Vlasenko 5fa6d1a632 Aboriginal linux/musl build fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 11:15:43 +02:00
Denys Vlasenko 12efcf3285 Add qemu_multiarch_testing/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-05 09:04:04 +02:00
Denys Vlasenko 28b00ce6ff awk: support "length" form of "length()". Closes 8371
function                                             old     new   delta
parse_expr                                           805     848     +43
tokenlist                                            447     448      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-02 02:41:39 +02:00
Denys Vlasenko c919d561ad umount: always use umount2 syscall with specified flags
Make umount -f more compatible with util-linux 2.22.2.

Before:
  * 'umount -f': calls umount syscall,
        if it fails calls umount2 with 'MNT_FORCE'
  * 'mount -f -l': calls umount syscall,
        if it fails calls umount2 with 'MNT_LAZY'. 'MNT_FORCE' dropped
After:
  * 'umount -f': calls umount2 syscall with 'MNT_FORCE'
  * 'mount -f -l': calls umount2 syscall with 'MNT_LAZY' and 'MNT_FORCE'

function                                             old     new   delta
umount                                                45       -     -45
umount_main                                          610     555     -55

Signed-off-by: Anton Bondarenko <anton.bondarenko@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-01 18:50:06 +02:00
Denys Vlasenko c65a7596df adduser: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 21:11:12 +02:00
Bernhard Reutner-Fischer 65db14ec50 adduser: Add -k /path/to/skel
function                                             old     new   delta
.rodata                                           157069  157133     +64
adduser_main                                         921     936     +15
adduser_longopts                                     103     110      +7
packed_usage                                       30230   30236      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 92/0)               Total: 92 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 21:09:18 +02:00
Bartosz Golaszewski 2beb52499e i2c-tools: rename remaining defines
Rename the defines not present in linux UAPI headers to better reflect
their purpose.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 13:15:01 +02:00
Bartosz Golaszewski d9892fa0c3 i2c-tools: remove duplicate definitions
Most applets include linux' user API headers instead of duplicating
the definitions. Make it the case for i2c-tools as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-21 13:15:00 +02:00
Denys Vlasenko 8aa7cf305b sort: fix -kN,M handling (was including last separator into the comparison)
Testcase:

$ printf '%s\n' a/a:a a:b | sort -t: -k1,1
a:b
a/a:a

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-19 22:06:40 +02:00
Tito Ragusa f085344d5c libbb: another unit test for is_suffixed_with
Suggested by Bartosz Golaszewski.

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-15 23:38:01 +02:00
Peter Korsgaard 875297378c modprobe: handle module arguments containing spaces
Modprobe wasn't correctly parsing module arguments containing spaces from
/proc/cmdline - E.G. module.property="some text".

Extend the parsing to correctly handle quoted text.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-09 14:55:07 +02:00
Ron Yorston ca25af9b06 ash: fix slash treatment in expmeta
Commit 549deab caused this sequence of commands:

   mkdir foo
   cd foo
   touch a b
   echo "./"*

to return './*' instead of the expected './a ./b'.  The problem
was caused by the backport of commit 880d952 from dash.  In dash
the issue was fixed by two further commits by Herbert Xu:

<d6d06ff> [EXPAND] Fixed non-leading slash treatment in expmeta
<36f0fa8> [EXPAND] Fix slash treatment in expmeta

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Apply these fixes to BusyBox ash, thus causing the new test
glob3.tests to succeed.

function                                             old     new   delta
expmeta                                              469     528     +59

Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 22:23:54 +02:00
Denys Vlasenko b5be13ccd9 hush: fix a nommu bug where a part of function body is lost if run in a pipe
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 06:22:10 +02:00
Denys Vlasenko 2156e22853 Makefile.flags: survive a build system which has no pthread
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 04:20:51 +02:00
Denys Vlasenko 26c423d9a8 ash,hush: add a test which fails for ash since commit 549deab
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 03:33:02 +02:00
Denys Vlasenko 66a781acb9 ash: add tests adapted from hush glob tests. glob2.tests currently fails
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 03:27:08 +02:00
Denys Vlasenko 68acc0f835 libbb: make is_suffixed_with() return pointer inside string, not key.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 21:47:33 +02:00
Bartosz Golaszewski 7448b513c8 libbb: add is_suffixed_with() function
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 16:36:43 +02:00
Denys Vlasenko 5b865deb3f ping: fix recently introduced build breakage for non-optimizing builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 16:26:31 +02:00
Bartosz Golaszewski 0a4d0e8fbf libbb: add a comment describing the way is_prefixed_with() works
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 15:04:16 +02:00
Bartosz Golaszewski b432923e29 libbb: add unit tests for is_prefixed_with()
Test corner cases too like looking for an empty prefix etc.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 15:00:24 +02:00
Sören Tempel d862717328 login: don't print motd if .hushlogin exists in users home
function                                             old     new   delta
login_main                                           978     996     +18

Signed-off-by: Sören Tempel <soeren@soeren-tempel.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 22:16:48 +02:00
Peter Korsgaard 864d1b7a15 dmesg: add -r option to print raw format even when FEATURE_DMESG_PRETTY is enabled
Similar to the "big" util-linux version. For !DMESG_PRETTY, the option is accepted
(but ignored) as well, for compatibility reasons.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 21:08:02 +02:00
Alex Dowad 65c501a093 ifupdown: 'prio' should have been 'metric' in static_up and static_up6
When a static interface with explicit gateway and metric in /etc/network/interfaces
is enabled using 'ifup', and further, the BusyBox 'ip' applet is enabled, the
following error message appears at the console (and no default route is added):

ip: either "to" is duplicate, or "prio" is garbage

Tracing ifup reveals that it is attempting to run the following shell command:

ip route add default via <GW> dev <DEVICE> prio <METRIC>

'ip' does not understand the 'prio' argument, causing this error. With 'metric',
it works fine.

Signed-off-by: Alex Dowad <alexinbeijing@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:18:36 +02:00
Denys Vlasenko c52cbea2bb libbb: add setsockopt_foo helpers
function                                             old     new   delta
setsockopt_int                                         -      23     +23
do_load                                              918     934     +16
setsockopt_SOL_SOCKET_int                              -      14     +14
setsockopt_keepalive                                   -      10     +10
setsockopt_SOL_SOCKET_1                                -      10     +10
buffer_fill_and_print                                169     178      +9
setsockopt_1                                           -       8      +8
nfsmount                                            3560    3566      +6
redirect                                            1277    1282      +5
tcpudpsvd_main                                      1782    1786      +4
d6_send_kernel_packet                                272     275      +3
i2cget_main                                          380     382      +2
ed_main                                             2544    2545      +1
scan_recursive                                       380     378      -2
nbdclient_main                                       492     490      -2
hash_find                                            235     233      -2
cmdputs                                              334     332      -2
parse_command                                       1443    1440      -3
static.two                                             4       -      -4
ntpd_main                                           1039    1035      -4
const_int_1                                            4       -      -4
const_IPTOS_LOWDELAY                                   4       -      -4
RCVBUF                                                 4       -      -4
ntp_init                                             474     469      -5
change_listen_mode                                   316     310      -6
uevent_main                                          416     409      -7
arping_main                                         1697    1690      -7
telnet_main                                         1612    1603      -9
socket_want_pktinfo                                   42      33      -9
setsockopt_reuseaddr                                  21      10     -11
setsockopt_broadcast                                  21      10     -11
httpd_main                                           772     757     -15
get_remote_transfer_fd                               109      94     -15
make_new_session                                     503     487     -16
ftpd_main                                           2177    2160     -17
read_bunzip                                         1896    1866     -30
common_traceroute_main                              4099    4058     -41
common_ping_main                                    1836    1783     -53
------------------------------------------------------------------------------
(add/remove: 5/4 grow/shrink: 8/21 up/down: 111/-283)        Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Denys Vlasenko 2db782bc7b Merge setsockopt error messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Denys Vlasenko 729b70646c traceroute: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Bartosz Golaszewski bb2fd67d0b Makefile: add missing libraries to LDLIBS
Static build with CONFIG_PAM fails on Debian Jessie due to undefined
references to libdl and libaudit.

Static build without pam, but with libcrypt required fails as well due
to undefined references to libpthread.

Fix these two cases by adding the missing libraries to LDLIBS when
appropriate.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:05:55 +02:00
Bartosz Golaszewski 718e228adc unit-tests: remove code depending on WANT_TIMING
Since there is no interest in merging a config option for WANT_TIMING,
remove the parts of code depending on it altogether.

While we're at it: add some newlines to improve readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:01:49 +02:00
Bartosz Golaszewski d077565bb2 unit-tests: remove unnecesary field from struct bbunit_listelem
In the initial submission struct bbunit_listelem was manipulated by
custom list functions implemented in bbunit.c. Since the tests are now
added to the list by llist_add_to_end(), which allocates the llist_t
objects behind the scenes, there's no need for the *next field.

function                                             old     new   delta
unit_main                                            142     141      -1
bbunit_strrstr_elem                                   24      16      -8
bbunit_obscure_weak_pass_elem                         24      16      -8
bbunit_obscure_strong_pass_elem                       24      16      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:00:10 +02:00
Denys Vlasenko fb52769f4a arping: make help text clearer
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-16 19:56:16 +02:00
Ron Yorston 26ccd3d062 less: fix botched attempt to use last column
Commit 1ecb996 attempted to make read_lines() use the last column of
the terminal (as re_wrap() did).  There were two problems with this:

- The size of the buffer allocated for lines wasn't increased to allow
  for the extra character.

- The test for width overflow was moved after the point where the
  next character was added to the buffer.  This caused a buffer overflow
  in certain circumstances.

  For example, if the line beyond the end of the display was wider than
  the display read_lines() would initially read the partial line into a
  buffer.  When the user moved down read_lines() would be called again
  to ensure the rest of the line was read.  This would place the next
  character in the partial line before checking for overflow.

  This can be fixed by moving the test for overflow back to where it was
  before commit 1ecb996 and changing the comparison to `>` rather than
  `>=`.

There are two other places where buffers are created without allowing
for width+1 characters.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-16 18:54:49 +02:00
Ron Yorston 72dcbe4df7 ipcalc: fix trivial usage message
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-15 21:15:27 +02:00
Denys Vlasenko a83e3ae172 zcip: tweak comments and make unsigned division more obvious
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 15:06:38 +02:00
Denys Vlasenko e347583835 zcip: another code shrink
function                                             old     new   delta
send_arp_request                                       -     185    +185
zcip_main                                           1273    1272      -1
pick_nip                                              40       -     -40
arp                                                  185       -    -185
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 0/1 up/down: 185/-226)          Total: -41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 14:30:31 +02:00
Denys Vlasenko 99e30be38b zcip: code shrink
function                                             old     new   delta
zcip_main                                           1263    1230     -33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 12:28:21 +02:00
Denys Vlasenko 16aa7a73c4 zcip: simplify code
function                                             old     new   delta
zcip_main                                           1411    1263    -148

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-04 03:27:56 +02:00
Ron Yorston 64ed5f0d3c uname: make OS name configurable
A mailing list thread in September 2013 discussed changing the string
returned by the non-POSIX 'uname -o' option.  Nothing ever came of this
because there was no agreement as to what the string should be.

Make the string configurable so that people can decide for themselves.

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-03 18:09:18 +02:00
Ron Yorston b27cf31003 less: further tweaks to regular file detection
Test explicitly for REOPEN flags:  update_num_lines is called
unconditionally so (num_lines != NOT_REGULAR_FILE) is also true when
num_lines contains a valid number of lines.

The call to fstat doesn't need to be in #if ENABLE_FEATURE_LESS_FLAGS:
the whole function is already in such a test.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-03 16:41:19 +02:00
Aaro Koskinen ad27a6d326 diff.tests: add testcases for -B and single line changes
Add testcases for -B and single line changes.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:51:15 +02:00
Aaro Koskinen a47fccaa63 diff: fix -B with single line changes
Fix -B with single line changes. They were always ignored regardless
if they were blank or not.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:50:49 +02:00
Denys Vlasenko 9dc526d0f9 less: improve regular file detection in line counting code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:42:20 +02:00
Ron Yorston 1ecb996fd2 less: allow use of last column of terminal
When read_lines tests whether a character will fit on the current
line it checks the *next* character but in case of overflow doesn't
display the *current* one.  This results in the last column of the
terminal never being used.

The test in re_wrap (used when the terminal width changes or line
numbers are enabled/disabled) is different:  it does allow the use
of the final column.

function                                             old     new   delta
read_lines                                           764     770      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 6/0)                 Total: 6 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:09 +02:00
Ron Yorston d542d183e1 less: fix line number confusion
Much of the code refers to lines using indices into the flines
array (which splits lines into portions that fit on the terminal).
In some cases this is wrong and actual line numbers should be
used:

- when lines are being truncated rather than wrapped (-S flag)
- when line numbers have been entered by the user

Also fix a bug in numeric input and improve the display at EOF.

function                                             old     new   delta
goto_lineno                                            -     111    +111
cap_cur_fline                                          -     101    +101
buffer_to_line                                         -      56     +56
buffer_up                                             35      66     +31
less_main                                           2606    2615      +9
goto_match                                           125     127      +2
buffer_down                                           81      56     -25
buffer_line                                           64       -     -64
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 3/1 up/down: 310/-89)           Total: 221 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:08 +02:00
Ron Yorston ad1b4d5882 less: add a function to detect when display is at end of file
Add a function to package the test that detects whether enough has
been read from the file to allow a screenful to be displayed.

Also use this to determine when to display '(END)' in the status
line.  The previous code was incomplete and didn't handle truncated
lines (-S flag) properly.

function                                             old     new   delta
at_end                                                 -      63     +63
status_print                                         111     109      -2
read_lines                                           819     764     -55
getch_nowait                                         319     264     -55
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/3 up/down: 63/-112)           Total: -49 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:08 +02:00
Ron Yorston 70b84be9e8 less: rearrange detection of non-regular files
Move the code to detect non-regular files to the point where the
file is being opened.  If num_lines == READING_FILE guarantees
that the file is regular.

Detect when a file becomes unreadable between it first being opened
and the call to update_num_lines.  Mark the file as being non-regular
so we don't try that again.

function                                             old     new   delta
reinitialize                                         197     245     +48
update_num_lines                                     159     127     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-32)             Total: 16 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:07 +02:00
Ron Yorston 159e032bf4 less: move code to count lines into a separate function
function                                             old     new   delta
update_num_lines                                       -     159    +159
m_status_print                                       409     266    -143
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 159/-143)           Total: 16 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 16:22:07 +02:00
Ron Yorston ae1a9e899e less: fix numeric input
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 15:33:53 +02:00
Mike Frysinger 670c3f7822 echo: make escape sequences depend on fancy mode
Currently when you disable fancy echo, escape sequences are hardcoded
enabled (e.g. as if you used `echo -e` all the time).  The opposite
behavior is more desirable (always disable -e support) because:
* This seems to contradict the spirit of the kconfig help text (where
  it says enable support for -n/-e flags), although you could say that
  we aren't supporting the -e flag directly as `echo -e` will show the
  -e flag.
* POSIX makes escape sequences optional, and even says they are there
  only on XSI-conformant systems.
* It saves space (~100 bytes on x86_64).
* It makes things faster!
* It makes it behave more like bash where you need an explicit -e flag
  in order for escape sequences to be interpreted.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-31 03:47:49 +02:00
Linus Walleij 52f2f37477 fbset: fix rgba parsing
In commit b5c7220e7b
"fbset: respect rgba configuration lines in fb.modes"
I somehow managed to swap the offset/length markers around.
The man page for fb.modes says it should be offset/length
not length/offset as I was accidentally parsing it.

As my fb.modes file was also reversed I didn't notice
until I tried someone elses fb.modes file. Mea culpa.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-30 03:05:46 +02:00
Arthur Gautier c29021e2a5 udhcpc: dns labels can actually start with a number
While RFC1035 recommends a label not to start with a number, there is
actually no such limitation in dns. One may buy a domain name like
0x1.net and use it.

This commit remove this check and allow a user to use such domains.

Signed-off-by: Arthur Gautier <baloo@gandi.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-30 03:03:58 +02:00
Ron Yorston 193ba408a4 less: improvements to verbose status messages
Make verbose status messages (-m/-M flags) behave more like the
real `less` command:

- fix display of line numbers so they're correct whether lines are
  being truncated (-S flag) or wrapped.
- don't display total lines or percentage when lines are read from
  stdin:  we don't have that information until we reach EOF.  When
  we do reach EOF the additional information is displayed.
- when lines are read from a file count the total number of lines
  so that we can display percentages.  Counting lines is avoided
  until the information is actually needed.  If the user pages to
  EOF the separate read pass can be avoided entirely.

Fixes Bug 7586

function                                             old     new   delta
m_status_print                                       195     382    +187
safe_lineno                                            -      35     +35
reinitialize                                         172     182     +10
read_lines                                           675     685     +10
buffer_fill_and_print                                178     169      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 242/-9)            Total: 233 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-21 22:28:09 +02:00
Denys Vlasenko 35ae2ccb40 sync: add support for -d -f FILE
Based on the patch by Ari Sundholm <ari@tuxera.com>

function                                             old     new   delta
sync_main                                             20     163    +143
packed_usage                                       30653   30673     +20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 163/0)             Total: 163 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-21 19:50:48 +02:00
Denys Vlasenko ce193f809b Remove old_e2fsprogs/*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 23:12:51 +02:00
Ron Yorston d840c5d139 libbb: add a function to make a copy of a region of memory
Introduce a library routine to package the idiom:

    p = xmalloc(b, n);
    memcpy(p, b, n);

and use it where possible.  The example in traceroute used xzalloc
but it didn't need to.

function                                             old     new   delta
xmemdup                                                -      32     +32
last_main                                            834     826      -8
make_device                                         2321    2311     -10
common_traceroute_main                              3698    3685     -13
readtoken1                                          3182    3168     -14
procps_scan                                         1222    1206     -16
forkchild                                            655     638     -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/6 up/down: 32/-78)            Total: -46 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 23:05:20 +02:00
Ron Yorston 78cfa00154 less: correctly account for tabs when rewrapping lines
Lines are rewrapped when the terminal width changes or line numbers
are enabled/disabled.  The current calculation always adds eight to
the line length for a tab whereas it should only add enough to move
to the next tab stop.

This doesn't affect the display of lines, which is handled elsewhere
and gets tab stops right, but it does cause lines to be wrapped at
the wrong position.

Signed-off-by:  Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:50:25 +02:00
Ron Yorston f06386ad4f less: fix display of line numbers
Line numbers are displayed incorrectly on lines that have a search
pattern highlighted.  The problem can be fixed by moving the call to
lineno_str in print_found above the while loop that alters the value
of the line pointer.  However, a more substantial rewrite results in
savings.

function                                             old     new   delta
buffer_print                                         688     697      +9
.rodata                                           156077  156045     -32
lineno_str                                            85       -     -85
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 9/-117)           Total: -108 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:48:05 +02:00
Ron Yorston 51aa861843 less: document -S flag and make it independently configurable
The -S flag, to cause long lines to be truncated, was enabled by
FEATURE_LESS_DASHCMD.  This is non-obvious and -S is useful even
if the '-' command isn't enabled.

function                                             old     new   delta
.rodata                                           156045  156077     +32
packed_usage                                       30223   30244     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 53/0)               Total: 53 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 22:34:13 +02:00
Ron Yorston 072fc60f29 ash: use alloca to get rid of setjmp
Now that the only thing protected by setjmp/longjmp is the saved string,
we can allocate it on the stack to get rid of the jump.

Based on commit bd35d8e from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken1                                          3182    3116     -66
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-66)             Total: -66 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 04:02:45 +02:00
Denys Vlasenko f54a487bb4 fix file mode
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:52:32 +02:00
Ron Yorston 0e056f7e9e ash: remove parsebackquote flag
Commit 503a0b8 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu says:

  >The parsebackquote flag is only used in a test where it always has the
  >value zero.  So we can remove it altogether.

The first statement is incorrect:  parsebackquote is non-zero when
backquotes (as opposed to $(...)) are used for command substitution.
It is possible for the test to be executed with parsebackquote != 0 in
that case.

The test is question checks whether quotes have been closed, raising
the error "unterminated quoted string" if they haven't.  There seems
to be no good reason to allow unclosed quotes within backquotes.  Bash,
hush and dash (after commit 503a0b8) all treat the following as an error:

   XX=`"pwd`

whereas BusyBox ash doesn't.  It just ignores the unclosed quote and
executes pwd.

So, parsebackquote should be removed but not for the reason stated.

function                                             old     new   delta
parsebackquote                                         1       -      -1
readtoken1                                          3222    3182     -40
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-41)             Total: -41 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:50:27 +02:00
Maninder Singh 97f2f7ca7f Removes stray empty line from code
This patch removes stray empty line from busybox code
reported by script find_stray_empty_lines

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-13 03:25:46 +02:00
Clayton Shotwell b7ee7e1e13 applets: Add installation of individual binaries
Adding support to install individual binaries if the option is
enabled. This also installs the shared libbusybox.so.* library.

Signed-off-by: Clayton Shotwell <clshotwe@rockwellcollins.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 19:10:03 +02:00
Denys Vlasenko c9091d8947 ps: fix SEGV on narrow screens. closes 8176
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 19:07:24 +02:00
Denys Vlasenko db31c637fa ipaddress: better formatting, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 18:36:06 +02:00
Michael Tokarev 6a7cd3d4ab ip addr: support change and replace commands
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-01 18:26:41 +02:00
Maninder Singh 7db312ad26 fix whitespaces
reported by script :- scripts/fix_ws.sh

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:19:47 +02:00
Maninder Singh 0fabedf085 fix if(p)/free(p) construct
No need of explicit NULL check before free.

Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:19:43 +02:00
Bartosz Golaszewski d90899206d i2cdetect: use break instead of goto in list_i2c_busses_and_exit()
Since there are now more statements in the if block after the while loop
in list_i2c_busses_and_exit(), there's no need for a label.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski aeb11a9496 i2cdump: code rework
Split i2cdump_main() into shorter functions. Simplify the code a bit.
Make block an array of ints so that we can store negative results of
read functions (fixes a bug found by Denys Vlasenko).

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski 2204472497 i2cdetect: add a check for (mode == DETECT_MODE_AUTO)
We should only warn the user about addresses to be skipped if
(mode == DETECT_MODE_AUTO).

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:47 +02:00
Bartosz Golaszewski e545bf6723 i2cdetect: don't scan non-regular addresses without the '-a' option
Addresses 0x00-0x02 shouldn't be scanned by default. This patch makes
'first' default to 0x03 and only enables lower addresses if '-a' option
is passed

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:46 +02:00
Bartosz Golaszewski 314742747d i2cdetect: don't die on addresses already in use by drivers
We can't use i2c_set_slave_addr() in i2cdetect, as we have to check for
EBUSY after calling ioctl(I2C_SLAVE) and print 'UU' on busy addresses
instead of bailing-out.

While we're at it: reorder definitions of local vars in i2cdetect_main().

function                                             old     new   delta
i2cdetect_main                                       703     744     +41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0)               Total: 41 bytes
   text	   data	    bss	    dec	    hex	filename
 826097	   4164	   9584	 839845	  cd0a5	busybox_old
 826145	   4164	   9584	 839893	  cd0d5	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 18:05:34 +02:00
Junling Zheng d291c2fdd5 chown: fix help text
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-06-07 02:32:23 +02:00
Ari Sundholm fc3e40ee81 truncate: do not die when a file doesn't exist and no-create flag is on
Additionally, open(2) failures do not make the program die immediately.
This makes the behavior of the program match coreutils more closely.

function                                             old     new   delta
truncate_main                                        161     221     +60

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 15:17:03 +02:00
Denys Vlasenko 7f4a49a96c Print one less newline at the end of bb_show_usage()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 14:30:52 +02:00
Maninder Singh 97c6491b4e typo fixes
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:46:36 +02:00
Denys Vlasenko c4603fb09a dc: fix "dc p" prinitng bogus data
function                                             old     new   delta
check_under                                            -      20     +20
print_no_pop                                          27      32      +5
pop                                                   33      24      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 25/-9)              Total: 16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-25 13:31:25 +02:00
Denys Vlasenko b878121e76 tc: fix print_rate
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-24 18:01:53 +02:00
Denys Vlasenko 9a595bb36d hush: add recent ash tests to hush testsuite too (they all pass for hush)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 10:23:16 +02:00
Ron Yorston 523006798c testsuite: add some tests for ash
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 10:13:21 +02:00
Ron Yorston 417622cc2e ash: fix breakage of ${v/pat/str}
The commit

   ash: move parse-time quote flag detection to run-time

breaks pattern substitution in parameter expansion.  Fix this and
revise the code so that the different handling of the pattern and
the replacement string takes place in rmescapes rather than the
separate function parse_sub_pattern.

function                                             old     new   delta
rmescapes                                            227     273     +46
static.qchars                                          3       4      +1
subevalvar                                          1177    1157     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 47/-20)             Total: 27 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:59:14 +02:00
Ron Yorston 549deab5ab ash: move parse-time quote flag detection to run-time
Because the parser does not recursively parse parameter expansion
with respect to quotes, we can't accurately determine quote status at
parse time.  This patch works around this by moving the quote detection
to run-time where we do interpret it recursively.

Test case:
   foo=\\ echo "<${foo#[\\]}>"
Old result:
   <\>
New result:
   <>

Do not quote back slashes in parameter expansions outside quotes.

Test case:
   a=/b/c/*
   b=\\
   echo ${a%$b*}
Old result:
   /b/c/*
New result:
   /b/c/

Based on commits 880d952, 7cfd8be, 0d7d660 and a7c21a6 from
git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu

function                                             old     new   delta
argstr                                              1164    1193     +29
memtodest                                            147     174     +27
subevalvar                                          1153    1177     +24
redirect                                            1279    1282      +3
dolatstr                                               5       7      +2
static.spclchars                                      10       9      -1
expandarg                                            962     960      -2
evalcase                                             273     271      -2
evalcommand                                         1204    1197      -7
rmescapes                                            236     227      -9
preglob                                               27       8     -19
evalvar                                              604     582     -22
cmdputs                                              389     334     -55
readtoken1                                          3163    3061    -102
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/9 up/down: 85/-219)          Total: -134 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:57:51 +02:00
Ron Yorston ad88bdee0c ash: remove arithmetic expansion collapsing at parse time
Collapsing arithmetic expansion is incorrect when the inner arithmetic
expansion is a part of a parameter expansion.

Test case:
   unset a
   echo $((3 + ${a:=$((4 + 5))}))
   echo $a
Old result:
   12
   (4 + 5)
New result:
   12
   9

Based on commit bb777a6 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
readtoken1                                          3180    3163     -17

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:56:16 +02:00
Ron Yorston 7e4ed267b6 ash: remove superfluous code in arithmetic mode
Based on commits 1a74845, cfc3d6a and ff13779 from
git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu

function                                             old     new   delta
evalcommand                                         1197    1204      +7
localcmd                                             327     325      -2
readtoken1                                          3200    3180     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 7/-22)             Total: -15 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:54:43 +02:00
Ron Yorston 3df47f9cbb ash: do not expand tilde in parameter expansion within quotes
Test case:
   unset a
   echo "${a:-~root}"
Old result:
   /root
New result:
   ~root

Based on commit 170f44d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
evalvar                                              598     604      +6
parse_command                                       1440    1443      +3
localcmd                                             325     327      +2
readtoken1                                          3199    3200      +1
argstr                                              1180    1164     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 12/-16)             Total: -4 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:53:26 +02:00
Ron Yorston eb6b48ba74 ash: perform tilde expansion in all parameter expansion words
Previously tilde expansion was not carried out for =?#% expansion words.

Test case:
   a=~root:~root
   echo ${a#~root}
Old result:
   /root:/root
New result:
   :/root

Based on commit dd721f71 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
subevalvar                                          1152    1153      +1

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:51:35 +02:00
Ron Yorston d68d1fbd6c ash: code shrink around varvalue
Based on commit c989d72 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu

function                                             old     new   delta
strtodest                                              -      40     +40
memtodest                                            123     147     +24
parse_command                                       1443    1440      -3
readtoken1                                          3205    3199      -6
argstr                                              1203    1180     -23
varvalue                                             788     660    -128
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 64/-160)           Total: -96 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-18 09:49:28 +02:00
Denys Vlasenko e0a4e107aa ash: explain what "local -" does
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-13 02:20:14 +02:00
Eugene Rudoy 1285aa62f9 ash: consider "local -" case while iterating over local variables in mklocal.
fixes segfault introduced in 0a0acb55db with functions using "local -".
test-case: f() { local -; local x; }; f

note: with this change applied multiple 'local -'s still cause multiple entries to be added to the localvars list.
this problem will be addressed in a separate commit.

Signed-off-by: Eugene Rudoy <gene.devel@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-13 02:09:53 +02:00
Daniel Thompson a818777d42 libbb: Enable support for !CONFIG_MULTIUSER
Linux recently gained a new config option, CONFIG_MULTIUSER, that makes
support for non-root users optional. This results in a number of syscalls
being disabled: setuid, setregid, setgid, setreuid, setresuid, getresuid,
setresgid, getresgid, setgroups, getgroups, setfsuid, setfsgid, capget,
capset.

Currently a number of busybox applets, including login, struggle to run
when CONFIG_MULTIUSER is disabled. Even the root user is unable to login:
  login: can't set groups: Functi

This patch adds code to make change_identity() a nop on single user
systems. It works by recognising the signature errno value (ENOSYS, due
to the system calls being disabled) and, to avoid security risks, only
deploys when the current uid and target uid is the same.

After the patch is applied any attempt to switch to a non-root user will
fail. Thus a badly configured userspace (for example, one that tries to
start a daemon as a non-root user when the kernel cannot support this)
will report errors as one would expect.

Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-12 23:59:57 +02:00
Bartosz Golaszewski 7ca5c51cc8 i2c-tools: only try /dev/i2c/* if opening /dev/i2c-* fails with ENOENT
Trying to access /dev/i2c/* on every error after opening /dev/i2c-* can
mislead users who e.g. don't have root access. Instead of bailing-out
with "permission denied" we currently print "no such file or directory".

Fix it by trying open("/dev/i2c/%d") only if we got ENOENT.

Upstream i2cdetect tries to get any info it can from /sys and /proc even
when invoked by an unprivileged user, but we don't want to add unnecessary
bloat.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:26:27 +02:00
Bartosz Golaszewski b2cca32a37 i2c-tools: fix 'i2cdetect -l'
Calling 'i2cdetect -l' only displays usage and exits. Fix it by
correctly parsing command-line arguments.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:24:03 +02:00
Thiago Jung Bauermann 17b16223f3 bzcat.tests: Run both .gz and .bz2 tests, and add .Z tests
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 17:19:22 +02:00
Denys Vlasenko bdb540e04f tar: do not try to decode GNU extended headers as pax headers
function                                             old     new   delta
get_header_tar                                      1736    1692     -44

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-11 16:55:16 +02:00
Matt Whitlock 778efe37ee Conditionalize Bionic workarounds on __ANDROID_API__
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 19:33:32 +02:00
Matt Whitlock f23e3ec529 Bionic lacks mempcpy; enable existing workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:57:44 +02:00
Thiago Jung Bauermann b4059f6309 libarchive: auto-detect .Z files as well
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:40:12 +02:00
Denys Vlasenko c77a58fb2d typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:24:33 +02:00
Andrew Fuller 4d8ddb810d vi: basic undo feature shouldn't depend on yankmark
Currently basic undo functionality with the 'u' key depends on
FEATURE_VI_YANKMARK. These two features are separate, so we can remove this
dependency.

Signed-off-by: Andrew Fuller <abf@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-03 18:18:25 +02:00
Aaro Koskinen bbd53216f8 gzip: add support for compression levels 4-9
function                                             old     new   delta
gzip_main                                            192     282     +90
static.gzip_level_config                               -      24     +24
packed_usage                                       30439   30459     +20
fill_window                                          216     220      +4
pack_gzip                                           1789    1729     -60
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 138/-60)            Total: 78 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-26 14:22:37 +02:00
Matt Whitlock 93b98ff572 Bionic lacks tcdrain; provide a workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-26 13:14:50 +02:00
Matt Whitlock cee59053dc Bionic lacks ttyname_r; provide a workaround
Signed-off-by: Matt Whitlock <busybox@mattwhitlock.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-25 21:32:48 +02:00
Denys Vlasenko de5edadee2 special-case {true,false,test} --help
This also removes their help texts.

function                                             old     new   delta
run_applet_no_and_exit                               442     452     +10
packed_usage                                       30713   30625     -88

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-21 16:00:41 +02:00
Bernhard Reutner-Fischer 7d86384b24 include: Fallback to UTMP unless there is UTMPX support
Fixes compilation against uClibc-0.9.30 for instance

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-20 15:24:30 +02:00
Ron Yorston 61d6ae244a libbb: remove unnecessary argument to nonblock_immune_read
The loop_on_EINTR argument to nonblock_immune_read is always set to 1.

function                                             old     new   delta
xmalloc_reads                                        200     195      -5
pgetc                                                488     483      -5
argstr                                              1313    1308      -5
nonblock_immune_read                                 123      86     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-52)             Total: -52 bytes

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-20 13:41:32 +02:00
Denys Vlasenko ad795510d9 mdev: if a "future" mdev.seq is seen, do not overwrite it with ours
This was seen to happen if two mdevs are run in parallel,
mdev.seq is empty, and the "newer" one manages to write it first.

function                                             old     new   delta
mdev_main                                           1366    1388     +22
atoll                                                  -      20     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-19 18:55:12 +02:00
Denys Vlasenko bd77e9d609 mdev: improve logging
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-19 18:54:49 +02:00
Denys Vlasenko 73327a048b hush: document buggy handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:38:13 +02:00
Denys Vlasenko 0a0acb55db ash: fix handling of duplicate "local"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-18 19:36:38 +02:00
Denys Vlasenko 63f4d32c98 sed: implement ",+N" range end
function                                             old     new   delta
add_cmd                                             1115    1173     +58
process_files                                       2226    2253     +27
sed_main                                             696     702      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 91/0)               Total: 91 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-17 14:24:55 +02:00
Denys Vlasenko 71a5b67ba0 uevent: new applet
This applet listens on netlink socket with kernel's uevent messages.
Run-tested.

function                                             old     new   delta
uevent_main                                            -     416    +416
packed_usage                                       30671   30713     +42
applet_names                                        2531    2538      +7
applet_main                                         1468    1472      +4
RCVBUF                                                 -       4      +4
applet_nameofs                                       734     736      +2
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 4/0 up/down: 475/0)             Total: 475 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-16 12:44:02 +02:00
Felix Fietkau f7466e4776 find: fix regression in status processing for path arguments
Regression added in commit 14158b4127
"find: add optional support for '-exec ... {} +'"

This commit causes find to exit on the first path argument that was not
found, which breaks existing scripts and is incompatible to other
implementations.

Instead of exiting on the first failure, return EXIT_FAILURE at the end
if any error occurred.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 16:45:23 +02:00
Alfonso Ranieri a90490fb69 volume_id: fix a buglet introduced by is_prefixed_with() conversion
Signed-off-by: Alfonso Ranieri <alforan@tin.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 14:32:39 +02:00
Denys Vlasenko e0ddb65cb2 build system: make CONFIG_EXTRA_LDFLAGS go to LDFLAGS, not EXTRA_LDFLAGS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-14 14:15:15 +02:00
Aaro Koskinen 7b729edd33 update copyright years
Copyright years seem to be out of date, e.g. coreutils/truncate.c
has Copyright (C) 2015.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-02 23:03:56 +02:00
Bernhard Reutner-Fischer 86a7f18f21 *: Switch to POSIX utmpx API
UTMP is SVID legacy, UTMPX is mandated by POSIX.

Glibc and uClibc have identical layout of UTMP and UTMPX, both of these
libc treat _PATH_UTMPX as _PATH_UTMP so from a user-perspective nothing
changes except the names of the API entrypoints.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-02 23:03:46 +02:00
Denys Vlasenko 1186894f77 update example ntp.script
Handle an interesting corner case when NTP server is reachable...
but on a different IP now.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-31 22:00:55 +02:00
Denys Vlasenko 9472e8a86f ftpd: change_identity() must be after chroot()
Otherwise chroot() doesn't work for non-root

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-31 21:46:26 +02:00
Denys Vlasenko 379e8e81af typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-26 10:49:02 +01:00
Denys Vlasenko 1850d5ec0e truncate: new applet
Add the actual new source file :(

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 18:00:32 +01:00
Vladislav Grishenko 4d15068d83 zcip: fix wrong comparison of source IP with our IP
Commit "zcip: fix link-local IP conflict detection" has introduced
wrong comparsion of source IP with our IP. This leads to a new IP
being picked unnecessarily on every incoming ARP packet.

Signed-off-by: Vladislav Grishenko <themiron@mail.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:59:34 +01:00
Ari Sundholm 911db16229 truncate: new applet
function                                             old     new   delta
truncate_main                                          -     161    +161
cwbkMG_suffixes                                        -     128    +128
packed_usage                                       30443   30459     +16
applet_names                                        2512    2521      +9
applet_main                                         1456    1460      +4
parse_command                                       1460    1463      +3
applet_nameofs                                       728     730      +2
applet_install_loc                                   182     183      +1
dd_suffixes                                          112       -    -112
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 10/3 up/down: 337/-133)         Total: 204 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:56:38 +01:00
Ari Sundholm 8893023ba2 dd: move suffix struct to xatonum.c
This way it can be used by other applets without duplication.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:41:04 +01:00
Phil Sutter 92edab1aa6 logread: implement dumpfollow mode of operation
This is basically a combination of the default (dump mode) and -f
(follow mode). Specifying -F makes logread first dump the log buffer and
then immediately start following it.

function                                             old     new   delta
packed_usage                                       30412   30443     +31
logread_main                                         491     497      +6

Signed-off-by: Phil Sutter <phil.sutter@viprinet.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:37:20 +01:00
Denys Vlasenko 6d8ea1d50e ifupdown: shrink a message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:08:51 +01:00
Frank Bergmann 6ca03f2dd8 ifupdown: correct ifstate update during 'ifup -a'. Closes 6212
When 'if -a' runs into an failure on an interface all further
interfaces won't be correctly updated in ifstate. This patch
inserts a new variable that only tracks the current interfaces
failure so that the write to ifstate can rely on this and not
the one for the functions return value.

Fixes https://bugs.busybox.net/show_bug.cgi?id=6212

Signed-off-by: Frank Bergmann <frank.frajasalo@googlemail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:04:27 +01:00
Ron Yorston 75a76269ba ash: do not split the result of tilde expansion
A tilde expansion generates a valid pathname. Splitting it using IFS
either leaves it unchanged or changes it to something unintended.

Example:
   IFS=m HOME=/tmp; printf "%s\n" ~

Based on this commit authored by Jilles Tjoelker:

   http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=834629283f6c629a4da05ef60bae9445c954a19a

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 16:55:44 +01:00
Mike Frysinger 6798564b9e trylink: respect compiler settings when probing features
The CPPFLAGS/CFLAGS settings might have features that matter, so make
sure we utilize them when testing the compiler.

URL: https://bugs.gentoo.org/471118
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-03-16 17:47:01 -04:00
Mike Frysinger 4a08e82d44 trylink: use mktemp instead of hardcoding paths
This way we respect standard tempdir env vars and are guaranteed to
be unique.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-03-16 17:46:17 -04:00
Denys Vlasenko 49acc1a761 vi: make BACKSPACE and DELETE join lines at start/end of line
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 21:15:34 +01:00
Ron Yorston 8ec1ff350c Use chomp to remove newlines
function                                             old     new   delta
unix_do_one                                          548     540      -8
process_timer_stats                                  508     500      -8
process_irq_counts                                   532     524      -8
lpd_main                                             839     831      -8
hwclock_main                                         502     494      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-50)             Total: -40 bytes

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 20:18:51 +01:00
Ron Yorston 53e9c51ade od: fix printing of high-bit chars
Example: echo £ | od -c

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 20:11:48 +01:00
Denys Vlasenko 8dff01d06a libbb: introduce and use is_prefixed_with()
function                                             old     new   delta
is_prefixed_with                                       -      18     +18
complete_username                                     78      77      -1
man_main                                             737     735      -2
fsck_device                                          429     427      -2
unpack_ar_archive                                     80      76      -4
strip_unsafe_prefix                                  105     101      -4
singlemount                                         1054    1050      -4
rtc_adjtime_is_utc                                    90      86      -4
resolve_mount_spec                                    88      84      -4
parse_one_line                                      1029    1025      -4
parse_conf                                          1460    1456      -4
may_wakeup                                            83      79      -4
loadkmap_main                                        219     215      -4
get_irqs_from_stat                                   103      99      -4
get_header_cpio                                      913     909      -4
findfs_main                                           79      75      -4
fbsplash_main                                       1230    1226      -4
load_crontab                                         776     771      -5
expand_vars_to_list                                 1151    1146      -5
date_main                                            881     876      -5
skip_dev_pfx                                          30      24      -6
make_device                                         2199    2193      -6
complete_cmd_dir_file                                773     767      -6
run_applet_and_exit                                  715     708      -7
uudecode_main                                        321     313      -8
pwdx_main                                            197     189      -8
execute                                              568     560      -8
i2cdetect_main                                      1186    1176     -10
procps_scan                                         1242    1230     -12
procps_read_smaps                                   1017    1005     -12
process_module                                       746     734     -12
patch_main                                          1903    1891     -12
nfsmount                                            3572    3560     -12
stack_machine                                        126     112     -14
process_timer_stats                                  449     435     -14
match_fstype                                         111      97     -14
do_ipaddr                                           1344    1330     -14
open_list_and_close                                  359     343     -16
get_header_tar                                      1795    1779     -16
prepend_new_eth_table                                340     323     -17
fsck_main                                           1811    1794     -17
find_iface_state                                      56      38     -18
dnsd_main                                           1321    1303     -18
base_device                                          179     158     -21
find_keyword                                         104      82     -22
handle_incoming_and_exit                            2785    2762     -23
parse_and_put_prompt                                 774     746     -28
modinfo                                              347     317     -30
find_action                                          204     171     -33
update_passwd                                       1470    1436     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540)         Total: -522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 17:48:34 +01:00
Denys Vlasenko 936c8809ca deluser: also remove user from /etc/group
function                                             old     new   delta
update_passwd                                       1270    1470    +200
deluser_main                                         310     332     +22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 15:30:46 +01:00
Alexander Korolkov 748fb60f27 arping: fix iface name in error messages
arping: interface eth0 not found: No such device
                  ^^^^

This is because error template is formed before parsing command line arguments,
so it always uses default interface name "eth0".

Signed-off-by: Alexander Korolkov <alexander.korolkov@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 13:05:33 +01:00
Denys Vlasenko fe8b5802ba patch: segfault fix. Closes 7916
Fix segfault on this case (malformed --- line):

    -- dwarves.orig 2015-02-25 01:45:27.753000000 +0000
    +++ dwarves     2015-02-25 01:46:08.199000000 +0000
    @@ -1,7 +1,7 @@
     Bashful
     Doc
     Dopey
    -Grouchy
    +Grumpy
     Happy
     Sleepy
     Sneezy

function                                             old     new   delta
patch_main                                          1903    1957     +54

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-11 18:01:34 +01:00
Isaac Dunham 7b434a67dc mount: -T OTHERTAB support
function                                             old     new   delta
mount_main                                          1221    1241     +20
packed_usage                                       30616   30610      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
2015-03-11 16:07:24 +01:00
Denys Vlasenko 3c31b092ac ntpd: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-05 14:04:44 +01:00
Denys Vlasenko 2ec4f44225 inetd: fix order of array index check and array access
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-03 13:10:30 +01:00
Denys Vlasenko 3aef814c0b ntpd: chnage help text about -l to say that it doesn't disable client code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 20:59:13 +01:00
Denys Vlasenko 7db2a7c20e runsvdir: if pid==1, also intercept SIGINT for -s SCRIPT
function                                             old     new   delta
runsvdir_main                                       1057    1064      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:39:13 +01:00
Denys Vlasenko dac8d80f77 runsvdir: do not block SIGCHLD around poll/sleep
There is no reason to do so. We do not even have SIGCHLD handler.

function                                             old     new   delta
runsvdir_main                                       1077    1057     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:38:55 +01:00
Denys Vlasenko fa535f3e48 runsvdir: (almost) close a signal race
We could lose a signal while processing previous one

function                                             old     new   delta
runsvdir_main                                       1088    1077     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-02 17:37:31 +01:00
Serj Kalichev 1eafd44947 acpid: fix logging
Without this patch acpid can't log the events at all. Moreover it tries
to truncate log file every time.

Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-23 15:26:47 +01:00
Denys Vlasenko c5beaa08eb ls: heed compiler warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-23 15:25:58 +01:00
Denys Vlasenko a88db5c1a9 modinfo: fix fallout from basename removal
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-21 17:08:35 +01:00
Tito Ragusa cb6a112f09 libpwdgrp: fix thinko in getpwnam
function                                             old     new   delta
parse_file                                             -      64     +64
getXXnam_r                                           162     138     -24
getXXnam                                              90      50     -40
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 64/-64)              Total: 0 bytes

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-19 22:03:56 +01:00
Bernhard Reutner-Fischer d7bfee1edb wget: fix --header to not append duplicate headers
function                                             old     new   delta
wget_main                                           2551    2715    +164
wget_user_headers                                      -      62     +62
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 226/0)             Total: 226 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 20:41:02 +01:00
Denys Vlasenko 54e9585e10 trivial code shrink
function                                             old     new   delta
rdate_main                                           246     251      +5
show_entry                                           291     287      -4
daytime_stream                                        44      39      -5
packed_usage                                       30176   30168      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-17)             Total: -12 bytes
   text	   data	    bss	    dec	    hex	filename
 929453	    932	  17684	 948069	  e7765	busybox_old
 929411	    932	  17684	 948027	  e773b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 13:47:46 +01:00
Denys Vlasenko 0cb981c5e2 ls: trivial code shrink
function                                             old     new   delta
display_single                                       914     893     -21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-18 11:29:07 +01:00
Bernhard Reutner-Fischer 70e30e8eec dc: tweak parsing
https://bugs.debian.org/538685
dc requires whitespace between language elements.

We were requiring
1 2 + p
instead of the abbreviated
1 2+p
(for example).

function                                             old     new   delta
stack_machine                                         97     126     +29
dc_main                                              117      79     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 29/-38)             Total: -9 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-16 17:12:04 +01:00
Denys Vlasenko 8e92df15b5 ls: fix year 9999 bug :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-16 15:36:25 +01:00
Denys Vlasenko 402afe1cc6 modprobe-small: fix thinko in previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-13 11:53:33 +01:00
Denys Vlasenko 1fd844267c modprobe-small: if concurrent module load did not succeed, wait
usecase:
two sd cards are being mounted in parallel at same time on dual core. example
modules which are getting loaded is  nls_cp437. While one module is being
loaded , it makes state in /proc/modules as 'coming' and then starts doing its
module init function (in our case - registering nls). meanwhile on other core,
if modprobe returns that is has already been loaded, then it will continue
and search for the nls list which is not yet finished from first module init.
This fails resulting in not mounting sd card.

function                                             old     new   delta
process_module                                       667     746     +79

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-12 17:05:14 +01:00
Bartosz Golaszewski 622a7aab2c i2cget, i2cset, i2cdetect, i2cdump: new applets
Add a minimal implementation of i2cget, i2cset, i2cdump and i2cdetect
tools. Supports most features of upstream i2c-tools.

function                                             old     new   delta
i2cdump_main                                           -    1444   +1444
i2cset_main                                            -    1239   +1239
i2cdetect_main                                         -     611    +611
list_i2c_busses_and_exit                               -     532    +532
packed_usage                                       29975   30438    +463
i2cget_main                                            -     380    +380
check_read_funcs                                       -     140    +140
i2c_funcs_tab                                          -     128    +128
confirm_action                                         -     100    +100
i2c_dev_open                                           -      57     +57
i2c_smbus_access                                       -      44     +44
confirm_or_abort                                       -      43     +43
check_funcs_test_end                                   -      39     +39
i2c_smbus_read_word_data                               -      38     +38
i2c_smbus_read_byte_data                               -      38     +38
i2c_smbus_read_byte                                    -      37     +37
i2c_set_slave_addr                                     -      32     +32
applet_names                                        2480    2512     +32
adap_descs                                             -      32     +32
i2c_set_pec                                            -      29     +29
get_funcs_matrix                                       -      21     +21
i2c_parse_data_addr                                    -      18     +18
i2c_parse_bus_addr                                     -      18     +18
i2c_bus_lookup                                         -      18     +18
i2c_smbus_write_byte                                   -      17     +17
applet_main                                         1440    1456     +16
will_skip                                              -      14     +14
no_support                                             -      11     +11
applet_nameofs                                       720     728      +8
applet_install_loc                                   180     182      +2
------------------------------------------------------------------------------
(add/remove: 26/0 grow/shrink: 5/0 up/down: 5601/0)          Total: 5601 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-10 03:16:25 +01:00
Denys Vlasenko 8c06bc6ba1 unzip: prevent attacks via malicious filenames
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-10 01:30:43 +01:00
Denys Vlasenko 23cfaab47d libpwdgrp: use getpwent() instead of getpwent_r()
function                                             old     new   delta
massage_data_for_non_r_func                            -      90     +90
bb_internal_getpwent                                   -      69     +69
getXXnam_r                                            94     162     +68
fill_bounds                                          131     128      -3
deluser_main                                         355     310     -45
complete_username                                    123      78     -45
getXXnam                                             163      90     -73
massage_data_for_r_func                              103       -    -103
bb_internal_getpwent_r                               121       -    -121
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/5 up/down: 227/-407)         Total: -163 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 21:21:02 +01:00
Denys Vlasenko 68c048fb23 modprobe-small: fix and simplify rmmod
"rmmod OUT_OF_TREE_MODULE" was not working, because module is not in depmod file.

In general, rmmod doesn't need scanning, it simply unloads every argv[i].

function                                             old     new   delta
rmmod                                                  -      63     +63
modprobe_main                                        449     465     +16
process_module                                       705     667     -38
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 79/-38)             Total: 41 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 20:44:46 +01:00
Kevin Wallace 782ee2aa0e libbb/loop: don't try to re-use existing loop device
loopinfo.lo_file_name is not enough to uniquely identify a file on a system with
multiple mount namespaces.  We could conceivably change this to dedup on
(lo_rdevice, lo_inode), but, as the comment above the deleted code notes, this
whole approach of reusing devices is racy anyway, so it seems better to stop
doing it entirely.

Signed-off-by: Kevin Wallace <k@igneous.io>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 19:13:57 +01:00
Denys Vlasenko a03195941b examples/mdev_fat.conf: document that newer mdev exposes path
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 18:14:39 +01:00
Ari Sundholm f22a838aed dd: add optional support for status=noxfer/none
While at it, added 'B' number suffixes, upstream compat

function                                             old     new   delta
dd_main                                             1469    1543     +74
dd_suffixes                                           88     112     +24
packed_usage                                       30156   30176     +20
dd_output_status                                     372     388     +16
static.status_words                                    -      13     +13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 147/0)             Total: 147 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-07 01:41:22 +01:00
Denys Vlasenko 7e66102f76 ash: fix a SEGV case in an invalid heredoc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-05 21:00:17 +01:00
Denys Vlasenko a14fa79592 deluser: implement --remove-home
function                                             old     new   delta
deluser_main                                         308     355     +47
packed_usage                                       30149   30156      +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0)               Total: 54 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-05 18:35:52 +01:00
Denys Vlasenko 3c5d133c7d fstrim: fix help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-04 15:19:38 +01:00
Denys Vlasenko a75dcd4353 route: fix bogus read error when route table is empty
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-04 10:40:10 +01:00
Denys Vlasenko 09020b1aa8 route: improve -A inet6
Upstream route command shows non-up routes, it shows reject and nonexthop flags.
And we had "ref" and "use" values mixed up...

function                                             old     new   delta
flagvals                                              32      44     +12
flagchars                                              9      12      +3
INET_setroute                                        767     768      +1
INET6_setroute                                       495     496      +1
set_flags                                             43      39      -4
flags_ipvx                                            16       8      -8
route_main                                           632     623      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/3 up/down: 17/-21)             Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 19:32:44 +01:00
Denys Vlasenko b62d4d9d57 gzip: trivial code shrink -5 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 15:25:17 +01:00
Denys Vlasenko a977778893 ifconfig: fix double free fatal error in INET_sprint
Based on the patch by Zheng Junling <zhengjunling@huawei.com>
and Chen Gang <cg.chen@huawei.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 12:11:30 +01:00
Denys Vlasenko 8e74adab01 libbb: make INET[6]_rresolve use sockaddr2{host,dotted}_noport
function                                             old     new   delta
INET_rresolve                                        274     214     -60
INET6_rresolve                                       168      85     -83

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-03 12:07:40 +01:00
Denys Vlasenko f7f70bf1b3 gzip: speed up and shrink put_16bit()
function                                             old     new   delta
put_16bit                                            104      98      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 16:07:07 +01:00
Rich Felker 7f7ade1964 gzip: do not store timestamp in gzip header
Storing the original file's modification time in the output file is
harmful (precludes deterministic results) and unlike official gzip,
the busybox version provides no way to suppress this behavior; the -n
option is silently ignored. Rather than trying to make -n work, this
patch just removes the timestamp-storing functionality. It should be
considered deprecated anyway; it's not Y2038-safe and gunzip ignores
it by default.

Per RFC 1952, 0 is the correct value to store to indicate that there
is no timestamp.

Signed-off-by: Rich Felker <dalias@libc.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 16:01:16 +01:00
Denys Vlasenko 5104645cf8 platform.h: enable mempcpy for FreeBSD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-02-02 03:51:47 +01:00
Micke Prag 07fa09a952 ubiattach: add option -O
Some images do not have the default VID offset. The option -O must
be used to attach such images.

Signed-off-by: Micke Prag <micke.prag@telldus.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 18:33:24 +01:00
Martin Kaiser 1cbe93cf4e telnetd: we only need CONFIG_UNIX98_PTYS from the Linux kernel
(re-sending this as it got ignored completey and the format of the
previous mail was probably not correct - please let me know if there's
anything else I can do to get this trivial fix applied)

for telnetd to work, we only need CONFIG_UNIX98_PTYS to be enabled
in the Linux kernel - DEVPTS_FS has been obsolete for some time

Signed-off-by: Martin Kaiser <lists@kaiser.cx>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 17:12:38 +01:00
Denys Vlasenko 08f9ffc3f7 dpkg: update supported compression methods
Based on a patch by Ron Yorston <rmy@tigress.co.uk>

function                                             old     new   delta
get_header_tar_xz                                      -      60     +60
filter_accept_list_reassign                          128     188     +60
unpack_package                                       585     621     +36
init_archive_deb_control                              52      76     +24
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 180/0)             Total: 180 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-30 15:15:38 +01:00
Denys Vlasenko 8c05a74f7e platform.h: mempcpy needs <string.h>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-29 16:41:48 +01:00
Denys Vlasenko ff3f3accc6 ntpd: get rid of G.initial_poll_complete
This speeds up syncing - now happens only just
two replies from a peer. Especially useful for "ntpd -q".
Shouldn't have ill effects: if we chose a bad peer,
we will discover it later and switch to another one.

The code is even smaller this way.

Suggested by Miroslav Lichvar <mlichvar@redhat.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-29 16:31:36 +01:00
Denys Vlasenko 936c401077 dhcpd: fix an improper widening conversion
We wanted to detect when tv_sec = unsigned1 - unsigned2
underflows by looking at tv_sec's sign. But if tv_sec
is long and it is wider than unsigned, we get unsigned -> long
conversion which is in this case never negative.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-27 21:59:40 +01:00
Denys Vlasenko 64b744997e ftpd: prevent zombies. closes 7832
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-26 15:45:48 +01:00
Denys Vlasenko 50a6d86520 platform.h: add compat mempcpy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-25 22:08:46 +01:00
Denys Vlasenko cc70b6f8b6 depmod: simple memory optimization
function                                             old     new   delta
filename2modname                                      67      86     +19
parse_module                                         374     351     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-24 22:30:30 +01:00
Denys Vlasenko 86031a5ffd trim extra newlines in help texts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-24 19:46:45 +01:00
Natanael Copa 9de69c024c modprobe: fix modprobe -r and parsing of /etc/modprobe.d
This fixes a regression introduced with commit 78854520 (modprobe:
revert checking for /, stop doing basename() on modprobe args,
2015-01-01) that broke modprobe options stored in /etc/modprobe.conf and
/etc/modprobe.d/*.conf.

This also fixes modprobe -r

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-19 19:15:24 +01:00
Denys Vlasenko 76b2262b9b modprobe: fix "modprobe devname:snd/timer" case (alias with a slash)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-15 03:04:23 +01:00
Denys Vlasenko e998b08f11 modprobe: fix recent breakage: modules.dep reading code needs to strip dirname
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-15 02:49:59 +01:00
Denys Vlasenko 1b6715345f modprobe-small: code shrink
function                                             old     new   delta
pathname_matches_modname                              80      42     -38

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 17:46:56 +01:00
Denys Vlasenko 3c75b1c34e modprobe-small: fix recent breakage: modprobe -r was using full path
"modprobe -r MODNAME", after it found the full module pathname,
should strip dirpath before trying to remove the module.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 17:40:30 +01:00
Denys Vlasenko 39f017293a diff: fix a bug in diffing against stdin. Closes 7784
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-11 16:41:54 +01:00
Ron Yorston 70f4320b40 vi: fix reading of file after last line
If the :r command is used to read a file after the last line of the
buffer the last line of the buffer and the first line of the file
are joined.  An extra blank line appears at the end of the buffer.

   file 1
   file 1
   file 1file 2
   file 2
   file 2

	~
	~

The insertion point is normally at the start of the line following the
specified line.  When the specified line is the last one the next_line
function baulks at moving to the non-existent following line.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 18:23:29 +01:00
Ron Yorston e5213cee38 vi: failure to open file is not an error when initialising buffer
Commit 32afd3a introduced these regressions on the master branch:

Starting vi with no filename on the command line gives the status message
"'(null)' Bad address" instead of "- No file 1/1 100%".

Starting vi with a non-existent file on the command line gives the status
message "'new.txt' No such file or directory" instead of "- new.txt 1/1 100%"

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 17:00:48 +01:00
Denys Vlasenko 08364dab75 depmod: fix recent breakage in modules.dep generation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-07 14:39:01 +01:00
Tito Ragusa e5cae08f12 libpwdgrp: line counting in error meesages is broken, remove it
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-06 01:22:36 +01:00
René Rhéaume e76957708b swaponoff: add support for -e
Signed-off-by: René Rhéaume <rene.rheaume@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 20:35:00 +01:00
Denys Vlasenko 1ec49732e2 mpstat: code shrink
function                                             old     new   delta
get_uptime                                           134     129      -5
get_irqs_from_stat                                   110     103      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 18:39:23 +01:00
Guillermo Rodriguez 75a1403f26 free: handle "cached" value too
function                                             old     new   delta
free_main                                            356     481    +125

Signed-off-by: Guillermo Rodriguez <guille.rodriguez@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 18:34:53 +01:00
Denys Vlasenko da9212667c libbb: code shrink by factoring out common update_utmp_DEAD_PROCESS
function                                             old     new   delta
update_utmp_DEAD_PROCESS                               -      17     +17
telnetd_main                                        1685    1674     -11
mark_terminated                                       56      45     -11
handle_sigchld                                        74      63     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:37:58 +01:00
Denys Vlasenko 08b90a9d10 deleting unused ntpd_simple.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:12:37 +01:00
Denys Vlasenko c5d4a04e45 libpwdgrp: fixes suggested by Tito, comment tweaks
function                                             old     new   delta
bb_internal_getpwent_r                               100     121     +21
parse_common                                         202     203      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:09:04 +01:00
Adam Tkac 4bf88d9094 ntpd: relicense ntpd applet to ISC-style license
OpenNTPd is licensed under ISC-style license so it's good idea to keep
ntpd applet under same license to avoid mess, instead of having
our changes to be under GPL.

Names of original code's authors are added.

Signed-off-by: Adam Tkac <vonsch@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 17:46:08 +01:00
Denys Vlasenko db4d1051ca libpwdgrp: another code shrink
function                                             old     new   delta
massage_data_for_r_func                                -     110    +110
bb_internal_getpwent_r                               173     100     -73
getXXnam_r                                           176      95     -81
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 110/-154)          Total: -44 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 02:34:52 +01:00
Denys Vlasenko 5acf1346b4 libpwdgrp: code shrink
function                                             old     new   delta
parse_common                                         206     205      -1
getgrouplist_internal                                229     225      -4
bb_internal_getpwent_r                               182     173      -9
getXXnam                                             232     222     -10
getXXnam_r                                           216     176     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-64)             Total: -64 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-04 02:02:39 +01:00
Denys Vlasenko 12fc869560 libpwdgrp: getgrXXX: empty string is not a member name, do not store it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:16:18 +01:00
Denys Vlasenko 402451aa19 fix a SEGV in previous commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:11:27 +01:00
Denys Vlasenko f9936676bb libpwdgrp: fix counting of commas in group list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 21:03:39 +01:00
Denys Vlasenko 134c53098b libpwdgrp: store getXXnam result in a single malloc block
This saves a bit of memory but more importantly, allows to create
xmalloc_getpwnam() API where result can be deleted simply using free().

function                                             old     new   delta
getXXnam                                             134     173     +39
parse_common                                         188     212     +24
convert_to_struct                                    277     290     +13
get_S                                                 90      88      -2
tokenize                                             129     126      -3
bb_internal_getpwent_r                               175     172      -3
getXXnam_r                                           208     198     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 76/-18)             Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 20:47:47 +01:00
Denys Vlasenko 20c0a16334 libpwdgrp: make db->def[] one byte shorter
In the future I will need another uint8_t, want to fit it
w/o using another word on 32 bits.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 19:12:49 +01:00
Denys Vlasenko 5e62a3d016 libpwdgrp: use a better estimate of max struct size
Previous code's trick with bitwise OR was giving this on 32-bit x86:

sizeof(struct passwd):28
sizeof(struct group):16
sizeof(struct spwd):36
sizeof(struct_result):60

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 17:53:49 +01:00
Denys Vlasenko 9dca6acaac libpwdgrp: reinstate Tito's optional atexit freeing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 16:09:05 +01:00
Denys Vlasenko 8d547aca75 libpwdgrp: fix a memory leak in getXXnam (we did not save address of string buf)
function                                             old     new   delta
convert_to_struct                                    261     269      +8
const_sp_db                                           20      24      +4
const_pw_db                                           20      24      +4
const_gr_db                                           20      24      +4
tokenize                                             144     147      +3
parse_common                                         185     188      +3
get_S                                                 82      85      +3
bb_internal_getpwent_r                               188     185      -3
gr_off                                                 4       -      -4
getXXnam                                             171     165      -6
pw_off                                                 7       -      -7
getgrouplist_internal                                237     229      -8
getXXnam_r                                           215     207      -8
sp_off                                                 9       -      -9
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 7/4 up/down: 29/-45)            Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 15:54:04 +01:00
Denys Vlasenko 31d6734457 libpwdgrp: tweak comments, replace one xmalloc with xzalloc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-03 15:15:47 +01:00
Denys Vlasenko 908b6e5dfd libpwdgrp: use FAST_FUNC to make "matching ABI" optimization more likely to succeed
See bb_internal_get*nam_r size reduction:

function                                             old     new   delta
bb_internal_getpwent_r                               167     176      +9
getXXnam_r                                           204     206      +2
sulogin_main                                         326     325      -1
su_main                                              471     470      -1
read_line_input                                     3832    3831      -1
print_stat                                           865     864      -1
prepare_socket_fd                                    283     282      -1
load_crontab                                         777     776      -1
fork_job                                             456     455      -1
do_shm                                               884     883      -1
do_sem                                               637     636      -1
do_msg                                               783     782      -1
complete_username                                    124     123      -1
bb_internal_getgrouplist                              71      70      -1
xgetpwuid                                             27      25      -2
xgetpwnam                                             27      25      -2
xgetgrnam                                             27      25      -2
xgetgrgid                                             27      25      -2
uid2uname                                             18      16      -2
login_main                                           980     978      -2
gid2group                                             18      16      -2
get_shell_name                                        54      52      -2
change_identity                                       50      48      -2
bb_internal_initgroups                                50      48      -2
argstr                                              1261    1259      -2
print_perms                                          177     174      -3
inetd_main                                          2077    2074      -3
run_applet_no_and_exit                               446     442      -4
fileaction_setowngrp                                  89      85      -4
deluser_main                                         312     308      -4
bb_internal_getpwuid                                  19      15      -4
bb_internal_getpwnam                                  11       7      -4
bb_internal_getgrnam                                  14      10      -4
bb_internal_getgrgid                                  19      15      -4
adduser_main                                         865     861      -4
passwd_main                                          989     984      -5
get_passwd                                            97      92      -5
data_extract_all                                     887     882      -5
check_user_passwd                                    490     485      -5
get_groups                                            81      75      -6
ftpd_main                                           2178    2171      -7
bb_internal_getspnam_r                                42      18     -24
bb_internal_getpwnam_r                                39      15     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/41 up/down: 11/-153)         Total: -142 bytes
   text	   data	    bss	    dec	    hex	filename
 923167	    928	  17676	 941771	  e5ecb	busybox_old
 923023	    928	  17676	 941627	  e5e3b	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-02 22:31:07 +01:00
Tito Ragusa 1da09cfacf libpwdgrp: rewritten to use malloced implementation
This removed buffer size limitations.

function                                             old     new   delta
convert_to_struct                                      -     269    +269
getXXnam_r                                             -     204    +204
parse_common                                           -     185    +185
getXXnam                                               -     164    +164
tokenize                                               -     126    +126
bb_internal_getpwent_r                               102     167     +65
get_S                                                 30      88     +58
getgrouplist_internal                                195     240     +45
const_sp_db                                            -      20     +20
const_pw_db                                            -      20     +20
const_gr_db                                            -      20     +20
bb_internal_endpwent                                  27      36      +9
bb_internal_endgrent                                  27      36      +9
decode_one_format                                    726     734      +8
bb_internal_setpwent                                  17      24      +7
volume_id_probe_iso9660                              319     322      +3
scriptreplay_main                                    204     207      +3
mkfs_minix_main                                     2684    2687      +3
id_main                                              478     480      +2
hash_find                                            233     235      +2
pstree_main                                          321     322      +1
gr_off                                                 3       4      +1
expand_one_var                                      1579    1578      -1
pwf                                                    4       -      -4
grf                                                    4       -      -4
pack_gzip                                           1787    1780      -7
addattr32                                             67      56     -11
buffer_fill_and_print                                191     178     -13
dpkg_main                                           2944    2927     -17
bb_internal_setgrent                                  17       -     -17
bb_internal_getpwuid                                  38      19     -19
bb_internal_getgrgid                                  44      19     -25
bb_internal_getpwnam                                  38      11     -27
bb_internal_getgrnam                                  44      14     -30
bb_internal_fgetpwent_r                               51       -     -51
bb_internal_fgetgrent_r                               51       -     -51
bb_internal_getspnam_r                               121      42     -79
bb_internal_getpwnam_r                               121      39     -82
bb_internal_getgrent_r                               102       -    -102
bb__parsepwent                                       110       -    -110
bb_internal_getpwuid_r                               113       -    -113
bb_internal_getgrgid_r                               113       -    -113
bb__parsespent                                       120       -    -120
bb_internal_getgrnam_r                               121       -    -121
bb__pgsreader                                        213       -    -213
bb__parsegrent                                       226       -    -226
------------------------------------------------------------------------------
(add/remove: 8/13 grow/shrink: 14/11 up/down: 1224/-1556)    Total: -332 bytes
   text	   data	    bss	    dec	    hex	filename
 923471	    928	  17684	 942083	  e6003	busybox_old
 923167	    928	  17676	 941771	  e5ecb	busybox_unstripped

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-02 21:37:59 +01:00
Denys Vlasenko 78854520eb modprobe: revert checking for /, stop doing basename() on modprobe args
function                                             old     new   delta
process_module                                       726     719      -7
filename2modname                                      81      67     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-21)             Total: -21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-01 19:02:40 +01:00
Bartosz Golaszewski 6c19d35f68 Makefile: fix cscope target
This target doesn't work with current directory layout. Just make cscope
index all .c and .h files.

While we're at it: add cscope output files to .gitignore.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-31 21:29:05 +01:00
Denys Vlasenko c76236fd7d ash: fix a SEGV in ${#1}
function                                             old     new   delta
varvalue                                             760     805     +45
evalvar                                              648     603     -45

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-29 00:04:18 +01:00
John Schroeder 8074a6ca4d udhcpd: account for script delay in lease
Prevent nasty surprises if script runs longer than lease time / 2.

Signed-off-by: John Schroeder <jschroed@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-25 21:12:51 +01:00
Denys Vlasenko b9965077e5 Start 1.24.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-24 02:06:02 +01:00
456 changed files with 7039 additions and 44994 deletions

No files matched your search

+8
View File
@@ -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
+4 -21
View File
@@ -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
+4
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -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
View File
@@ -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"
+9
View File
@@ -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' \
-1
View File
@@ -257,7 +257,6 @@ static NOINLINE int cpio_o(void)
free(line);
continue;
}
} else { /* line == NULL: EOF */
next_link:
if (links) {
+15 -4
View File
@@ -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;
+6
View File
@@ -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
View File
@@ -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");
}
+4 -2
View File
@@ -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
-1
View File
@@ -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) {
+24 -12
View File
@@ -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;
}
+1 -1
View File
@@ -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");
+20 -44
View File
@@ -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:
{
+21
View File
@@ -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;
}
-1
View File
@@ -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))
+7
View File
@@ -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
) {
+1 -1
View File
@@ -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;
+36
View File
@@ -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;
}
-3
View File
@@ -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
-2
View File
@@ -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
View File
@@ -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
View File
@@ -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
+4 -3
View File
@@ -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);
-1
View File
@@ -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
View File
@@ -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
-1
View File
@@ -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
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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();
+3 -1
View File
@@ -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);
}
-1
View File
@@ -134,7 +134,6 @@ int ln_main(int argc, char **argv)
}
free(src_name);
} while ((++argv)[1]);
return status;
+13 -10
View File
@@ -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
View File
@@ -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;
+6 -8
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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"
+87
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;
}
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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;
-69
View File
@@ -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
-18
View File
@@ -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
-3
View File
@@ -1,3 +0,0 @@
This is a pretty straight rip from the e2fsprogs pkg.
See README's in subdirs for specific info.
-26
View File
@@ -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
-104
View File
@@ -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
-182
View File
@@ -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
-125
View File
@@ -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
-213
View File
@@ -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
-367
View File
@@ -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
-222
View File
@@ -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
-110
View File
@@ -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;
}
}
-73
View File
@@ -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
-726
View File
@@ -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
-374
View File
@@ -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 */
-459
View File
@@ -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
-139
View File
@@ -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
-189
View File
@@ -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
-431
View File
@@ -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
-220
View File
@@ -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 = &af;
} 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;
}
-43
View File
@@ -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
-638
View File
@@ -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);
}
-18
View File
@@ -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
-64
View File
@@ -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);
-187
View File
@@ -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 */
}
-70
View File
@@ -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;
}
-52
View File
@@ -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;
}
-273
View File
@@ -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);
}
}
-134
View File
@@ -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;
}
-72
View File
@@ -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
-65
View File
@@ -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
-32
View File
@@ -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);
}
-74
View File
@@ -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);
}
-27
View File
@@ -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");
}
-78
View File
@@ -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;
}
-26
View File
@@ -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
-173
View File
@@ -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;
}
-58
View File
@@ -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 456 files, more files were not shown because too many files have changed in this diff. Show more