Compare commits
1152
Commits
1_7_2
...
1_11_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a81fe4173 | ||
|
|
3e7eca97b9 | ||
|
|
9e6fe061d4 | ||
|
|
a959a858a3 | ||
|
|
2957fc6992 | ||
|
|
6857e4e2f3 | ||
|
|
9a22b56d36 | ||
|
|
a4d0cd0a31 | ||
|
|
f2b846e277 | ||
|
|
fa1649e9ac | ||
|
|
dee8587d92 | ||
|
|
f941306199 | ||
|
|
dabe36e4a0 | ||
|
|
e06f61d273 | ||
|
|
7049ff8696 | ||
|
|
f26e3d2e41 | ||
|
|
d0cc3f4ade | ||
|
|
fe733a9744 | ||
|
|
70685bd022 | ||
|
|
5ec6132c98 | ||
|
|
003f9fb213 | ||
|
|
cc3f20b9bd | ||
|
|
211b59be43 | ||
|
|
2f5d0cd511 | ||
|
|
2b75a94118 | ||
|
|
ef527f50e6 | ||
|
|
a80d0e4bf7 | ||
|
|
8124a96c34 | ||
|
|
e3eae0d445 | ||
|
|
50b5cac59f | ||
|
|
2a210e5df2 | ||
|
|
b07a496229 | ||
|
|
c87339d584 | ||
|
|
d235f58ac2 | ||
|
|
20273138fc | ||
|
|
3387538bbe | ||
|
|
b175946ba4 | ||
|
|
b67004b2ae | ||
|
|
dd9c072846 | ||
|
|
1363f0df15 | ||
|
|
d5736c5607 | ||
|
|
9cd4c76b50 | ||
|
|
1ba323e5b6 | ||
|
|
324a3fdf87 | ||
|
|
4a689e9b49 | ||
|
|
55789c6646 | ||
|
|
ab876cd107 | ||
|
|
985de15bf3 | ||
|
|
c1c63b622d | ||
|
|
4954d47ab0 | ||
|
|
619b87dfa5 | ||
|
|
16c2fea280 | ||
|
|
13436ea0dd | ||
|
|
6eaf8deddd | ||
|
|
b6926109b7 | ||
|
|
988339259f | ||
|
|
30c9cc5b17 | ||
|
|
c7985b76c5 | ||
|
|
b61e13d247 | ||
|
|
ccce59d562 | ||
|
|
32d8423e63 | ||
|
|
82dfec3e4e | ||
|
|
31e1286365 | ||
|
|
8474cd38f3 | ||
|
|
f45c4f41b7 | ||
|
|
57c899e4c2 | ||
|
|
1dba30f2de | ||
|
|
f54a088429 | ||
|
|
b4c5bf615e | ||
|
|
5703c22a51 | ||
|
|
ff7cd6f925 | ||
|
|
f716a6da9a | ||
|
|
5cdc247ba4 | ||
|
|
04087c6bbd | ||
|
|
d50dda8c35 | ||
|
|
873b895d50 | ||
|
|
e235285c3a | ||
|
|
7a762f9dbf | ||
|
|
f8d01d3f66 | ||
|
|
dd316dd283 | ||
|
|
a84420062a | ||
|
|
6108dc4df6 | ||
|
|
29038c06d6 | ||
|
|
2659c63213 | ||
|
|
a1767a1f5d | ||
|
|
21765fa063 | ||
|
|
76f812803b | ||
|
|
aa9cd89c67 | ||
|
|
7504f2f5d2 | ||
|
|
e773be0428 | ||
|
|
eee4f55a65 | ||
|
|
c7497ea31b | ||
|
|
25b463079d | ||
|
|
0eb406caa8 | ||
|
|
bd8390a872 | ||
|
|
fdddab0c61 | ||
|
|
4ea83bf562 | ||
|
|
9de4622055 | ||
|
|
7e3d33b6ce | ||
|
|
76db5adbf7 | ||
|
|
bd1aeeb850 | ||
|
|
87f40bac14 | ||
|
|
43360e5178 | ||
|
|
2e76c3f901 | ||
|
|
895bea2303 | ||
|
|
46ccdcb96e | ||
|
|
7b4f3f13d3 | ||
|
|
76d50418b3 | ||
|
|
3fe4f986a0 | ||
|
|
98a6f56d49 | ||
|
|
598bb732e8 | ||
|
|
2d0529c9bc | ||
|
|
ed9d621cf4 | ||
|
|
f2cccbce37 | ||
|
|
b8c9354114 | ||
|
|
048897c971 | ||
|
|
52a8d975da | ||
|
|
b597564e4c | ||
|
|
09c0a749a1 | ||
|
|
c8fa04f9b1 | ||
|
|
0876822ded | ||
|
|
dd6f570fa3 | ||
|
|
53354ac47d | ||
|
|
f0d6c25586 | ||
|
|
c0cd9f29d2 | ||
|
|
a05c0716c2 | ||
|
|
401de648a7 | ||
|
|
7bdf0c82da | ||
|
|
797c96d8ce | ||
|
|
593f8baeb0 | ||
|
|
9b6f4aa8e8 | ||
|
|
f592aa36f3 | ||
|
|
f0d6068086 | ||
|
|
c05b1684a0 | ||
|
|
66d56c565e | ||
|
|
50120dab4e | ||
|
|
7d60fc1c0a | ||
|
|
bedfabd500 | ||
|
|
b6fe10091d | ||
|
|
e7860e358e | ||
|
|
1a9bbfb96f | ||
|
|
1da86d2f40 | ||
|
|
1e93f3c585 | ||
|
|
3b162ecdf6 | ||
|
|
630a7f75e8 | ||
|
|
85571d8d01 | ||
|
|
6075b2aee0 | ||
|
|
c2741e1f72 | ||
|
|
ef729dd90c | ||
|
|
d42816763f | ||
|
|
beac1bd58e | ||
|
|
9af7aba579 | ||
|
|
b8e653bfbf | ||
|
|
cd2663f15e | ||
|
|
d78920675f | ||
|
|
62d8503589 | ||
|
|
e0fd13e901 | ||
|
|
a76669c595 | ||
|
|
f4e6bd0bf3 | ||
|
|
1d1bba4e99 | ||
|
|
d12fcc20da | ||
|
|
3e57adb731 | ||
|
|
8f74094548 | ||
|
|
447bd66837 | ||
|
|
f9a0784144 | ||
|
|
db508e3b82 | ||
|
|
cd9d4c85a4 | ||
|
|
634b022108 | ||
|
|
17282292c2 | ||
|
|
5de8a13b08 | ||
|
|
ea9f7a6a7f | ||
|
|
417e240abb | ||
|
|
10be1a787f | ||
|
|
c21d9c7290 | ||
|
|
1510216a55 | ||
|
|
55fb9da5b8 | ||
|
|
b85fb693c1 | ||
|
|
4fec346966 | ||
|
|
9cf0f62b15 | ||
|
|
9474830006 | ||
|
|
1ea2568469 | ||
|
|
7a5f494cab | ||
|
|
c47e8978fe | ||
|
|
fc9e108032 | ||
|
|
6bb55cfb99 | ||
|
|
cf18010ca9 | ||
|
|
dc5d7fec35 | ||
|
|
423465cd5e | ||
|
|
55e547eb6f | ||
|
|
a0e17f7df6 | ||
|
|
b267ed95bc | ||
|
|
4830fc565a | ||
|
|
af6cca50af | ||
|
|
30f892a0ee | ||
|
|
69dc325397 | ||
|
|
bd23fbbd0a | ||
|
|
8e2c9e1518 | ||
|
|
e94a87134d | ||
|
|
ff9234948e | ||
|
|
cf575ca856 | ||
|
|
61082ec1cc | ||
|
|
69d5ba2f95 | ||
|
|
a959a2abdd | ||
|
|
4801441e9a | ||
|
|
e9b76e1f1e | ||
|
|
ae84b11467 | ||
|
|
dfd8282464 | ||
|
|
7b3863986d | ||
|
|
b22a8059cb | ||
|
|
869d3d318f | ||
|
|
7bd8d8fd26 | ||
|
|
49bdf28c32 | ||
|
|
6de8994440 | ||
|
|
19903f0d44 | ||
|
|
b23429198e | ||
|
|
54b90b5988 | ||
|
|
38100a4ebe | ||
|
|
0953336951 | ||
|
|
eaad910655 | ||
|
|
f02efd11c9 | ||
|
|
5e25ddb7d3 | ||
|
|
636a1f85e8 | ||
|
|
cb83abd7b6 | ||
|
|
3576bed2f9 | ||
|
|
ae4342ca3e | ||
|
|
ee56e013cf | ||
|
|
5599502a55 | ||
|
|
e125a683a7 | ||
|
|
faf334aeb8 | ||
|
|
9ddc8d54d1 | ||
|
|
b6c4855f1d | ||
|
|
29eb3599e4 | ||
|
|
d04e1fc309 | ||
|
|
2794c9bb93 | ||
|
|
85e015c7c8 | ||
|
|
29952d79fc | ||
|
|
51a06c07da | ||
|
|
b8635e28b5 | ||
|
|
dff6190112 | ||
|
|
f3b778a4dc | ||
|
|
825968f92c | ||
|
|
1b23773e26 | ||
|
|
9c3052aab6 | ||
|
|
81e97a1380 | ||
|
|
e251337a4d | ||
|
|
6b06cb80be | ||
|
|
43d5d429fd | ||
|
|
b81f97bbd2 | ||
|
|
9305cdddbf | ||
|
|
77ad97f199 | ||
|
|
c4f12f59cc | ||
|
|
023dc6798e | ||
|
|
98636eb08c | ||
|
|
50dbed95fb | ||
|
|
b89e2027d9 | ||
|
|
f3aa4a8ec5 | ||
|
|
4579e9c1c8 | ||
|
|
4b04f543a1 | ||
|
|
35d1683ce9 | ||
|
|
2af860464e | ||
|
|
6253880450 | ||
|
|
6e38d52120 | ||
|
|
647c20cfc2 | ||
|
|
6bf05cf1ff | ||
|
|
b153ace939 | ||
|
|
06ebc16461 | ||
|
|
dddfaff363 | ||
|
|
380bcfc9f7 | ||
|
|
c8f7a97f89 | ||
|
|
8abae88410 | ||
|
|
96b99b860c | ||
|
|
687a26fe0d | ||
|
|
4e79049e10 | ||
|
|
32dcc53b71 | ||
|
|
6da9b00f4f | ||
|
|
2dea01ca11 | ||
|
|
57be4abcf8 | ||
|
|
e061226668 | ||
|
|
812870a2e7 | ||
|
|
dcbd350ccf | ||
|
|
a2dcb50175 | ||
|
|
3c07e4b877 | ||
|
|
b34266b42b | ||
|
|
a0c103a30a | ||
|
|
05efca90d2 | ||
|
|
d93400bffb | ||
|
|
c450379ff0 | ||
|
|
10f6fb1d46 | ||
|
|
e4ed64067e | ||
|
|
e6520f0532 | ||
|
|
c0431ed455 | ||
|
|
4809a9f78e | ||
|
|
7dff4333d6 | ||
|
|
5d0f4aaa99 | ||
|
|
92a6f878e9 | ||
|
|
64d5bfda1a | ||
|
|
16afa38a7b | ||
|
|
b140eddc41 | ||
|
|
2c84495184 | ||
|
|
44f0821259 | ||
|
|
95842fbc16 | ||
|
|
a6b3a1f0bf | ||
|
|
4d89a8bd1d | ||
|
|
ad6cab1834 | ||
|
|
c6191e9a0a | ||
|
|
15ce7f5b58 | ||
|
|
019d299f01 | ||
|
|
b520271f65 | ||
|
|
a50a9b0fdf | ||
|
|
765c1c3c31 | ||
|
|
71e3ab327a | ||
|
|
58dc274a7a | ||
|
|
fa5b05ab07 | ||
|
|
ffdcb41fd2 | ||
|
|
9d4a17e0b6 | ||
|
|
be002adb2f | ||
|
|
1f228985b2 | ||
|
|
5d89fbaa2e | ||
|
|
9137341851 | ||
|
|
5a07a1d255 | ||
|
|
a4a93fdf18 | ||
|
|
2d94992235 | ||
|
|
376003bbbe | ||
|
|
5bb2fc2dc1 | ||
|
|
01eaee9309 | ||
|
|
0a1446275d | ||
|
|
fe493479e2 | ||
|
|
25cfe4996e | ||
|
|
5b3adae7e8 | ||
|
|
85d788e491 | ||
|
|
daeddee442 | ||
|
|
f3745ea489 | ||
|
|
d9c51e9fa7 | ||
|
|
6c10657c4a | ||
|
|
5a96c3eab6 | ||
|
|
a4e55ab840 | ||
|
|
33b92f2fdb | ||
|
|
9a7af9fc17 | ||
|
|
d2095fd903 | ||
|
|
1b2d0b2821 | ||
|
|
50d068cb76 | ||
|
|
e96dcb4dcf | ||
|
|
250aa5bb01 | ||
|
|
c033d5196d | ||
|
|
4437d19fb4 | ||
|
|
aca10f852a | ||
|
|
bc1918a7a2 | ||
|
|
3cfebe44c7 | ||
|
|
7089c31d57 | ||
|
|
c7131c3e58 | ||
|
|
b15ebe46fc | ||
|
|
4f98e19382 | ||
|
|
6d1ebecf65 | ||
|
|
24f824edb3 | ||
|
|
ffa4499c9f | ||
|
|
867bd37c7f | ||
|
|
7465dbcf2a | ||
|
|
f78a656f7c | ||
|
|
033424a213 | ||
|
|
9bc80d7062 | ||
|
|
4a9ca13fe7 | ||
|
|
55e06c1edf | ||
|
|
eecd588c53 | ||
|
|
1d690db720 | ||
|
|
3bc7d7df3d | ||
|
|
0f5dfd6b9a | ||
|
|
93b8263652 | ||
|
|
80f647c21c | ||
|
|
119f87be2a | ||
|
|
da616dbfa8 | ||
|
|
37bb6ada96 | ||
|
|
b75a1c3c2a | ||
|
|
fcc6347976 | ||
|
|
b3f39f0cfa | ||
|
|
858ebf130a | ||
|
|
b12b1c87b5 | ||
|
|
79cedcb2c0 | ||
|
|
643dcf00e3 | ||
|
|
ed23adce72 | ||
|
|
6fa1ba3972 | ||
|
|
90c31b3d4b | ||
|
|
278a1c2264 | ||
|
|
ad4da989e3 | ||
|
|
0a38bcf570 | ||
|
|
1af00eda92 | ||
|
|
1a95e3960c | ||
|
|
261f237024 | ||
|
|
7f8f0fafdb | ||
|
|
7b6d9d687d | ||
|
|
a7f4e4bbd8 | ||
|
|
2e4c3c4cc3 | ||
|
|
0edbdd8ac8 | ||
|
|
c59d802a5a | ||
|
|
9895dfdb9a | ||
|
|
9dedf72e71 | ||
|
|
468aea2d88 | ||
|
|
165f5b394f | ||
|
|
d943af058b | ||
|
|
5297809c03 | ||
|
|
1b2058fe98 | ||
|
|
f2f3868e0d | ||
|
|
aa8a601084 | ||
|
|
02f12f53e8 | ||
|
|
cae11b51aa | ||
|
|
4461564c77 | ||
|
|
7cb808e1c5 | ||
|
|
0e7940ae90 | ||
|
|
6c615a6c07 | ||
|
|
b9ad75fa60 | ||
|
|
a38ba59cc3 | ||
|
|
c4523c2b3d | ||
|
|
2570b2e575 | ||
|
|
cf26ab70c1 | ||
|
|
e1caabbb75 | ||
|
|
95891fc016 | ||
|
|
72b3442aeb | ||
|
|
11b9f26610 | ||
|
|
8ee649a02e | ||
|
|
ce7eb4443c | ||
|
|
25a9c17f55 | ||
|
|
c6dbb85c9e | ||
|
|
08ec67bc62 | ||
|
|
cc2965fd23 | ||
|
|
80591b0a00 | ||
|
|
b02cea1212 | ||
|
|
a1acfc8f37 | ||
|
|
0c3b0d501e | ||
|
|
f7d5665969 | ||
|
|
68e5e2b1c7 | ||
|
|
fa076d491f | ||
|
|
9ce4ae8142 | ||
|
|
92e13c2a11 | ||
|
|
59f351ccda | ||
|
|
f39653e306 | ||
|
|
cee01cfb2e | ||
|
|
dccfe05e17 | ||
|
|
64a76d7b44 | ||
|
|
c4c2cd44d2 | ||
|
|
e9d67a81c8 | ||
|
|
7fe0ebac5f | ||
|
|
73132b9c12 | ||
|
|
04211fd204 | ||
|
|
dc1cbf839d | ||
|
|
c693840fe8 | ||
|
|
42cc304e90 | ||
|
|
39c77c3738 | ||
|
|
0b6c6a9c9f | ||
|
|
a79428998d | ||
|
|
c93b162248 | ||
|
|
324d26f9aa | ||
|
|
715c16ab0a | ||
|
|
69ca5a70fd | ||
|
|
c8bac033f3 | ||
|
|
45ecfc2f5c | ||
|
|
b9d0f0c762 | ||
|
|
74f8208f18 | ||
|
|
ffa5d76602 | ||
|
|
45911a60c3 | ||
|
|
31567c1c70 | ||
|
|
68d09697c9 | ||
|
|
4824ccae8e | ||
|
|
0dc490bda2 | ||
|
|
f90ab183d6 | ||
|
|
275b929e01 | ||
|
|
9e1f92d0bb | ||
|
|
9230582315 | ||
|
|
c52248e41c | ||
|
|
3c96d0258c | ||
|
|
0f3a580c4f | ||
|
|
027271e5a9 | ||
|
|
0a0180cdc5 | ||
|
|
104d544fd7 | ||
|
|
dd5702d696 | ||
|
|
a7d6c8bab9 | ||
|
|
cf7cf62204 | ||
|
|
0764a7f72d | ||
|
|
7a60133c6c | ||
|
|
403a5a298e | ||
|
|
71c9f015e9 | ||
|
|
dd9228b861 | ||
|
|
c0183e6e0d | ||
|
|
6aa7696e28 | ||
|
|
2a7a451391 | ||
|
|
d7e6af2dda | ||
|
|
78c5656530 | ||
|
|
e421b5ebf6 | ||
|
|
2724fa9d8a | ||
|
|
fb274df079 | ||
|
|
9c8c038981 | ||
|
|
d1277c6052 | ||
|
|
d0a071a528 | ||
|
|
b44c790e41 | ||
|
|
d25c33f186 | ||
|
|
c5b737231d | ||
|
|
592d4fe772 | ||
|
|
4866e905d7 | ||
|
|
4ee7cd4f6f | ||
|
|
aa9b1828b9 | ||
|
|
1d42665b6b | ||
|
|
62a90cdd74 | ||
|
|
d02db89244 | ||
|
|
85c247161b | ||
|
|
081eb71ebd | ||
|
|
68404f13d4 | ||
|
|
a55bd05f3c | ||
|
|
397de617f3 | ||
|
|
a4522c5a66 | ||
|
|
afc4113ed7 | ||
|
|
cdf62770af | ||
|
|
107fe7c081 | ||
|
|
aefed941c2 | ||
|
|
9f153f610f | ||
|
|
3f165fa5b3 | ||
|
|
8e2cfec1cd | ||
|
|
4cf1d08fc2 | ||
|
|
4e6d5117b8 | ||
|
|
4e6c8120a5 | ||
|
|
35e9c5d83a | ||
|
|
c51fc7bed6 | ||
|
|
b4a5087ee0 | ||
|
|
4917c11432 | ||
|
|
a43dba76ea | ||
|
|
444639cc21 | ||
|
|
c3fff877e1 | ||
|
|
4aafd5f4e3 | ||
|
|
d18f52bd18 | ||
|
|
fb29038b59 | ||
|
|
509697f00d | ||
|
|
da8ae75340 | ||
|
|
fe2188378c | ||
|
|
8a2e421f26 | ||
|
|
19fb67eee4 | ||
|
|
b29028e351 | ||
|
|
f39c7c0c86 | ||
|
|
cd174d1f31 | ||
|
|
32fd76c1d5 | ||
|
|
93e1a215af | ||
|
|
3444bd4fc2 | ||
|
|
51f421a55c | ||
|
|
1acb4ef87e | ||
|
|
574f2f4394 | ||
|
|
fe66a0eca1 | ||
|
|
c8f2f74ddd | ||
|
|
5014dada3f | ||
|
|
8195d20e36 | ||
|
|
17db1a9ac1 | ||
|
|
7be1030dcc | ||
|
|
be048f21e6 | ||
|
|
06aed4316e | ||
|
|
04bb2d2d06 | ||
|
|
d4f0b9476a | ||
|
|
d686482d05 | ||
|
|
6f1713f216 | ||
|
|
394eebed66 | ||
|
|
38b8831b32 | ||
|
|
f99afb5dff | ||
|
|
a2f47358eb | ||
|
|
6d8112cc24 | ||
|
|
8f8a420f12 | ||
|
|
b78d1c045f | ||
|
|
4f82bdb050 | ||
|
|
52feee9b1f | ||
|
|
28b29916cb | ||
|
|
400d8bb45e | ||
|
|
d553faf5a5 | ||
|
|
a7259b64e8 | ||
|
|
d2172c04e6 | ||
|
|
33196372be | ||
|
|
86620756d2 | ||
|
|
32b2a9fd6a | ||
|
|
68444b9f0c | ||
|
|
6aa74fcf5b | ||
|
|
838ffd5be2 | ||
|
|
2f518b078b | ||
|
|
081efd1232 | ||
|
|
a523e2efad | ||
|
|
84da0bf475 | ||
|
|
e376d454bb | ||
|
|
ae86a338b8 | ||
|
|
597906c436 | ||
|
|
e7b43cf59f | ||
|
|
c12d51e94e | ||
|
|
624188aec0 | ||
|
|
671ca33aa1 | ||
|
|
a58a637bed | ||
|
|
99a61842df | ||
|
|
8617454027 | ||
|
|
e93550866b | ||
|
|
53ce7f0d71 | ||
|
|
431a7c9c53 | ||
|
|
a37e7134f7 | ||
|
|
92657d484f | ||
|
|
e8419c90f1 | ||
|
|
5233cd3800 | ||
|
|
6f04391cec | ||
|
|
de7684a309 | ||
|
|
27dd495b98 | ||
|
|
b4133683a4 | ||
|
|
f732e96757 | ||
|
|
c9ca0a3274 | ||
|
|
56244736ec | ||
|
|
542963685c | ||
|
|
03b4c14bd4 | ||
|
|
b3b0753593 | ||
|
|
cb448fe01b | ||
|
|
ffae845cfd | ||
|
|
b1d8e7db0f | ||
|
|
25591c322c | ||
|
|
7fc294cdfe | ||
|
|
3718832a15 | ||
|
|
1e18f1bab3 | ||
|
|
284d0faed6 | ||
|
|
069e347863 | ||
|
|
cd5c61cd3b | ||
|
|
753f42ab8d | ||
|
|
0e6f661e23 | ||
|
|
977bc6a137 | ||
|
|
ea915363e7 | ||
|
|
6b160e490d | ||
|
|
be7d2a8ded | ||
|
|
25cd7fd702 | ||
|
|
1e47c429bf | ||
|
|
e00e5025ec | ||
|
|
39487e2d6a | ||
|
|
94e87bc83d | ||
|
|
28bf671d6d | ||
|
|
f1d93ec420 | ||
|
|
b2e578a1f2 | ||
|
|
773f6710c1 | ||
|
|
12c0622231 | ||
|
|
b5ee8db9b5 | ||
|
|
65eb550024 | ||
|
|
81887e2342 | ||
|
|
23ffb6a4a2 | ||
|
|
6dd03f04ea | ||
|
|
87cf2ee8ab | ||
|
|
d5fe880a57 | ||
|
|
9d96af2e83 | ||
|
|
3b92eaac53 | ||
|
|
75cddd8eb5 | ||
|
|
0a4624aece | ||
|
|
59bb4a4f50 | ||
|
|
7c5258b1c4 | ||
|
|
3d3d698594 | ||
|
|
fee2d0c256 | ||
|
|
7e497527ea | ||
|
|
e26b2783a5 | ||
|
|
648b44fd78 | ||
|
|
a5f2cd30c9 | ||
|
|
fc21305892 | ||
|
|
f536b99d26 | ||
|
|
a985d306a1 | ||
|
|
83177991c8 | ||
|
|
08126f665d | ||
|
|
459a5ad410 | ||
|
|
4ecfcdcced | ||
|
|
c04163a289 | ||
|
|
04e11c9209 | ||
|
|
9304d6ea92 | ||
|
|
991a1da148 | ||
|
|
0ef240d979 | ||
|
|
05743d7949 | ||
|
|
68e8e96d7f | ||
|
|
d56e3ccf96 | ||
|
|
937b10f35d | ||
|
|
761e1d1462 | ||
|
|
65581f3ed1 | ||
|
|
1e2a7e4ed1 | ||
|
|
6d52c1ee24 | ||
|
|
dc1c45795b | ||
|
|
97bd0e05cc | ||
|
|
7dbf1b4d9e | ||
|
|
afdad653ac | ||
|
|
534b8d0483 | ||
|
|
9412ec7555 | ||
|
|
22876c797c | ||
|
|
b386c1c614 | ||
|
|
d55fe3e595 | ||
|
|
e8ef7ec7de | ||
|
|
f3f33ebb0b | ||
|
|
f8157cafcb | ||
|
|
32d49bc70f | ||
|
|
c85bfcad52 | ||
|
|
5c3d2b334a | ||
|
|
95dc672326 | ||
|
|
30eb319103 | ||
|
|
6e602c4931 | ||
|
|
80667e30fb | ||
|
|
a2980c6249 | ||
|
|
5de754a395 | ||
|
|
7cff01ec2d | ||
|
|
0b2b5842a1 | ||
|
|
f0044c480c | ||
|
|
c348e0bc7b | ||
|
|
8c69afd992 | ||
|
|
c882f341ce | ||
|
|
8c638cbf09 | ||
|
|
c96d37050f | ||
|
|
36fc3cd8bc | ||
|
|
ddd42cb064 | ||
|
|
9772816570 | ||
|
|
73032ca04b | ||
|
|
847fa779af | ||
|
|
0effc2410b | ||
|
|
b5c60fc787 | ||
|
|
da42bd5bbe | ||
|
|
ef67c5758a | ||
|
|
c4e4be9414 | ||
|
|
f470196a41 | ||
|
|
61160dd0a1 | ||
|
|
b76b9a4328 | ||
|
|
893988182a | ||
|
|
ca9635b19d | ||
|
|
a5549c9617 | ||
|
|
680b86afbb | ||
|
|
1d290d1e24 | ||
|
|
9e58921e7e | ||
|
|
314820e595 | ||
|
|
8e8200a772 | ||
|
|
46ef46aefb | ||
|
|
46904bfbcc | ||
|
|
518d8dd979 | ||
|
|
52432f2b06 | ||
|
|
2b11fb483e | ||
|
|
c2f0de5eef | ||
|
|
1aac3ab49f | ||
|
|
78e1d58d3a | ||
|
|
c44c21060e | ||
|
|
ce34cccf28 | ||
|
|
d27d925a6d | ||
|
|
481ce92bdf | ||
|
|
84bbac5a09 | ||
|
|
ee8e3ee919 | ||
|
|
de24bd960f | ||
|
|
d2c450ce81 | ||
|
|
474d1c57c8 | ||
|
|
9b4c072a04 | ||
|
|
766f65919b | ||
|
|
482f2b31e7 | ||
|
|
6b404431aa | ||
|
|
4e9ca75281 | ||
|
|
bcd5fc12ec | ||
|
|
56ea65ca5f | ||
|
|
5fee2e1a79 | ||
|
|
9cd30d30a0 | ||
|
|
83c44229d2 | ||
|
|
21e20cb4ad | ||
|
|
4dada747e5 | ||
|
|
4f2e8bc765 | ||
|
|
fb0eba706c | ||
|
|
27963980db | ||
|
|
d3c042fc60 | ||
|
|
fcd878efcd | ||
|
|
3f9c848576 | ||
|
|
ddc865fb0d | ||
|
|
c03e872112 | ||
|
|
abee3d0e0d | ||
|
|
d55268d0d4 | ||
|
|
5adfa44101 | ||
|
|
1d61416b5a | ||
|
|
08137c28c4 | ||
|
|
bb50fdfe07 | ||
|
|
ec5631b6d6 | ||
|
|
7b55c7f97d | ||
|
|
8e5b6f58a2 | ||
|
|
299c5c379e | ||
|
|
3b4921674e | ||
|
|
f7be20e70c | ||
|
|
fcfb5c04bb | ||
|
|
e4bc603f0b | ||
|
|
ef36c04ccf | ||
|
|
f882f08627 | ||
|
|
528a8b9769 | ||
|
|
4baed3a080 | ||
|
|
e3cbfb91d2 | ||
|
|
94e3365b8f | ||
|
|
88adfcd178 | ||
|
|
ee87ebf381 | ||
|
|
26b6fba9d3 | ||
|
|
619879246d | ||
|
|
fff145dba3 | ||
|
|
f77f369ce8 | ||
|
|
c794c51a1a | ||
|
|
0163111325 | ||
|
|
9ad2cb3f1a | ||
|
|
4ca2965b99 | ||
|
|
2cd4a747e5 | ||
|
|
d7e2e127a9 | ||
|
|
2afabe8b83 | ||
|
|
191836845e | ||
|
|
75aa615bef | ||
|
|
9cb220be9d | ||
|
|
a96425fe82 | ||
|
|
b851c42a14 | ||
|
|
f3fca91e9f | ||
|
|
c689fcfdb0 | ||
|
|
5f934b0785 | ||
|
|
d0bbbdcd6e | ||
|
|
7221c8c22d | ||
|
|
2bec513996 | ||
|
|
7ab3699b58 | ||
|
|
ab801874f8 | ||
|
|
8003e266ed | ||
|
|
8723a94c25 | ||
|
|
5cb40bbbd3 | ||
|
|
4c13922961 | ||
|
|
e2532ab5f2 | ||
|
|
1796e2c495 | ||
|
|
6672c8e480 | ||
|
|
b539c8452f | ||
|
|
64309f8669 | ||
|
|
745cd17926 | ||
|
|
c253778de9 | ||
|
|
35ff74676b | ||
|
|
41f5add965 | ||
|
|
1aa7e477b1 | ||
|
|
79c6904faf | ||
|
|
186c2b3d0e | ||
|
|
30297a5b83 | ||
|
|
bd9a48bc9c | ||
|
|
4e1e720523 | ||
|
|
ed270a5f32 | ||
|
|
b1bac0dab2 | ||
|
|
a09300a88c | ||
|
|
7c9d533a85 | ||
|
|
6446c2d4ab | ||
|
|
72e76044cf | ||
|
|
a8875efa85 | ||
|
|
dd8bbfd084 | ||
|
|
fe5e23bf75 | ||
|
|
c3c6659f12 | ||
|
|
d2023283ac | ||
|
|
1da0ad13fb | ||
|
|
96702ca945 | ||
|
|
8ec6ee47f1 | ||
|
|
5bc593ccb8 | ||
|
|
cccdc4e01a | ||
|
|
835068637e | ||
|
|
f962a0354e | ||
|
|
f23c3f95e8 | ||
|
|
fff9b699f1 | ||
|
|
3831c91c95 | ||
|
|
e85dbae389 | ||
|
|
ff2b6d2185 | ||
|
|
6884f665bd | ||
|
|
68af8e7a08 | ||
|
|
b559105cfb | ||
|
|
7d75a96b15 | ||
|
|
705eaf8b40 | ||
|
|
9cdfd14223 | ||
|
|
223bc97f61 | ||
|
|
c881c733bb | ||
|
|
ed6a49c657 | ||
|
|
2a587df80a | ||
|
|
49d15890e0 | ||
|
|
e13bd362e3 | ||
|
|
dbd18f639c | ||
|
|
70ab28f907 | ||
|
|
fbe5f39f0f | ||
|
|
16aec39ebe | ||
|
|
8512862163 | ||
|
|
7e3a5f58bc | ||
|
|
7c2db5c198 | ||
|
|
a702457eac | ||
|
|
e8979889b4 | ||
|
|
01cd9570c7 | ||
|
|
a6899c3587 | ||
|
|
6d38dc3af4 | ||
|
|
f430cdbf2e | ||
|
|
1fe4e9e573 | ||
|
|
ae6bf96659 | ||
|
|
9d6c46955f | ||
|
|
8d0a734d91 | ||
|
|
3d461676a9 | ||
|
|
a89d50fb9a | ||
|
|
130f559f4d | ||
|
|
05c8c4f745 | ||
|
|
72cc9641f8 | ||
|
|
40276648ab | ||
|
|
6df9e3c9a3 | ||
|
|
059c91711f | ||
|
|
4bfb84db4e | ||
|
|
e5569cb52e | ||
|
|
40702dac93 | ||
|
|
f6ccc62c70 | ||
|
|
5cc6459c46 | ||
|
|
73cb1fdfea | ||
|
|
e7fca5125a | ||
|
|
b4f608d8e0 | ||
|
|
d031b203c7 | ||
|
|
9bd8d0c23e | ||
|
|
599bbfbd9b | ||
|
|
abbd363261 | ||
|
|
53bd4015aa | ||
|
|
459a2ba1ef | ||
|
|
49cce2b838 | ||
|
|
6e1b62b18c | ||
|
|
a29a5e40ae | ||
|
|
cb12cb2407 | ||
|
|
5281630229 | ||
|
|
6bef3d1d22 | ||
|
|
1bec1b980e | ||
|
|
cd0fbb5e77 | ||
|
|
ef66d75704 | ||
|
|
018b155ad9 | ||
|
|
cb981638f5 | ||
|
|
f8b21d0933 | ||
|
|
15c3885688 | ||
|
|
9fcd799b98 | ||
|
|
3a3e50e3db | ||
|
|
6cee58e9cf | ||
|
|
360362dc57 | ||
|
|
06200348be | ||
|
|
bfc3d82256 | ||
|
|
681023650e | ||
|
|
b68979aefa | ||
|
|
9d1afdb571 | ||
|
|
9130340adf | ||
|
|
d059ddc1bb | ||
|
|
1641d614fa | ||
|
|
968dbf9685 | ||
|
|
dfc0740b04 | ||
|
|
15ca51e3e2 | ||
|
|
5a28a25b9d | ||
|
|
63430ae35a | ||
|
|
a59f435b5f | ||
|
|
7ab5e3dfcd | ||
|
|
78ee7c853a | ||
|
|
6fa3ab3cf1 | ||
|
|
e5387a0574 | ||
|
|
037576d77b | ||
|
|
99014e8965 | ||
|
|
a03945aa84 | ||
|
|
2edbc2ab85 | ||
|
|
aa7a888e42 | ||
|
|
85ff862753 | ||
|
|
1a7afb48da | ||
|
|
fcc569637b | ||
|
|
bc7c5d082e | ||
|
|
34cd7afc49 | ||
|
|
f74194e942 | ||
|
|
0363078437 | ||
|
|
73e5ed2206 | ||
|
|
740eae0585 | ||
|
|
e87b8689d2 | ||
|
|
9e23767ef5 | ||
|
|
0de37e10ed | ||
|
|
31acd1ba0a | ||
|
|
16e74b7464 | ||
|
|
aff3a306b8 | ||
|
|
5576136563 | ||
|
|
23c8128916 | ||
|
|
f472b237a1 | ||
|
|
686b0ef7d8 | ||
|
|
008eda2c54 | ||
|
|
2450c450ab | ||
|
|
10916c5c6b | ||
|
|
59d7c43dbe | ||
|
|
d898b8600c | ||
|
|
b6ccd32e3f | ||
|
|
6a9154b6f6 | ||
|
|
3f5fdc7572 | ||
|
|
be039374f3 | ||
|
|
4a4575686e | ||
|
|
9435993b01 | ||
|
|
be5a7b9655 | ||
|
|
ef3aabe906 | ||
|
|
77f1ec1b9b | ||
|
|
11c23d7b99 | ||
|
|
8add068573 | ||
|
|
2ea8c40e8f | ||
|
|
4f95e5aab8 | ||
|
|
f9566d8c29 | ||
|
|
15cb4a4272 | ||
|
|
9b49a5ed85 | ||
|
|
8d82cf72c9 | ||
|
|
52a4388d95 | ||
|
|
db60bcf1b7 | ||
|
|
724d196c75 | ||
|
|
82d38dab91 | ||
|
|
141750e388 | ||
|
|
88ce2748e4 | ||
|
|
42e418292d | ||
|
|
01f3b2c91a | ||
|
|
d19b87ece4 | ||
|
|
8d755adc1a | ||
|
|
e9fd69c8e8 | ||
|
|
d419a9f830 | ||
|
|
ac7d0e375e | ||
|
|
642a52d65e | ||
|
|
d62fd84d4b | ||
|
|
7930bcf736 | ||
|
|
5037b21478 | ||
|
|
41770226bb | ||
|
|
f545be083d | ||
|
|
def8898596 | ||
|
|
76a6b236a9 | ||
|
|
3240474c23 | ||
|
|
e747f62ed6 | ||
|
|
339936be00 | ||
|
|
23e3e25df6 | ||
|
|
91e5203205 | ||
|
|
91e80c2be7 | ||
|
|
226002ea74 | ||
|
|
d21f596ddb | ||
|
|
5dd8a03665 | ||
|
|
368a12efc2 | ||
|
|
ebeaea04dc | ||
|
|
d24d5c84c2 | ||
|
|
feb7ae7f01 | ||
|
|
0c97c9d437 | ||
|
|
d65ea39ffc | ||
|
|
ff0976248a | ||
|
|
8412d7959a | ||
|
|
a0898170d8 | ||
|
|
96e1b38586 | ||
|
|
deabacdf91 | ||
|
|
d7b3350eb3 | ||
|
|
5fb09656ca | ||
|
|
a4f4de9b7e | ||
|
|
605b20e277 | ||
|
|
1eecaf26b0 | ||
|
|
e03c77fe15 | ||
|
|
f60d62638b | ||
|
|
64e619c0c8 | ||
|
|
304a97a1ec | ||
|
|
72e1c89d97 | ||
|
|
2450e4ba44 | ||
|
|
1ebd0a6d91 | ||
|
|
66bbfbd581 | ||
|
|
3d2a9217a7 | ||
|
|
ab8c9378c9 | ||
|
|
6081868ee3 | ||
|
|
e918e155ed | ||
|
|
0afdfdf649 | ||
|
|
920c52a5c8 | ||
|
|
a0ad43b80b | ||
|
|
a7bc9ac8f8 | ||
|
|
b925605441 | ||
|
|
c3122bca53 | ||
|
|
0d3c6afc93 | ||
|
|
8607677529 | ||
|
|
1d31f0f380 | ||
|
|
78e2d4e361 | ||
|
|
a36535b067 | ||
|
|
6124c37135 | ||
|
|
7c654ae9df | ||
|
|
892536f019 | ||
|
|
4daad9004d | ||
|
|
1acdc89e99 | ||
|
|
86b29ea9e8 | ||
|
|
33b900f984 | ||
|
|
5d61e71c3a | ||
|
|
c9dc2ac578 | ||
|
|
a619b85ef5 | ||
|
|
b042bd9514 | ||
|
|
dd5e11bb05 | ||
|
|
7ae209c019 | ||
|
|
137fbe495d | ||
|
|
3982407ba4 | ||
|
|
4dd4e6d6b9 | ||
|
|
6a5377ac14 | ||
|
|
ea7645bab6 | ||
|
|
35465a3f00 | ||
|
|
d9391b15f1 | ||
|
|
a545726d2b | ||
|
|
d9c6a001e3 | ||
|
|
e9b3321b9f | ||
|
|
86e0a22ec6 | ||
|
|
46a530626d | ||
|
|
818322b9b1 | ||
|
|
a7ce207bd8 | ||
|
|
47ddd01b3c | ||
|
|
7710563858 | ||
|
|
06783a5140 | ||
|
|
512a545f0d | ||
|
|
2a1d024333 | ||
|
|
06b3cc2811 | ||
|
|
32a471e4db | ||
|
|
9a4e08eaa8 | ||
|
|
73f56bb76d | ||
|
|
3a252b8c12 | ||
|
|
23856ab8e6 | ||
|
|
f588f70b91 | ||
|
|
f34e821572 | ||
|
|
7b70d78de8 | ||
|
|
f431017535 | ||
|
|
bcceb0c5a4 | ||
|
|
fc5d15912c | ||
|
|
707669501f | ||
|
|
efd3f38f8c | ||
|
|
0beaff8c19 | ||
|
|
9b0a439f02 | ||
|
|
27bd8d7146 | ||
|
|
2535f12cf2 | ||
|
|
32eb1f6cb9 | ||
|
|
a9335eafcf | ||
|
|
fa05074eee | ||
|
|
976690afe0 | ||
|
|
a2f61012b6 | ||
|
|
ac074b3f87 | ||
|
|
04ea11b033 | ||
|
|
476b070036 | ||
|
|
bf8fcaceb7 | ||
|
|
4d7605af86 | ||
|
|
4c1d88daff | ||
|
|
e7c1ad1540 | ||
|
|
ff6e8e2974 | ||
|
|
9382b3809b | ||
|
|
c8d4d2f11d | ||
|
|
d7ecd863c8 | ||
|
|
87f3b26b3a | ||
|
|
40f0bcf9d3 | ||
|
|
dcf9bba3b7 | ||
|
|
fdf9060aa3 | ||
|
|
cef23e0d8b | ||
|
|
3638cc4462 | ||
|
|
211f7f88ae | ||
|
|
beffd43d8e | ||
|
|
7e0fbf9c26 | ||
|
|
f0000653e9 | ||
|
|
21b83cfb27 | ||
|
|
82f3b16713 | ||
|
|
9862e6b056 | ||
|
|
fc202427d5 | ||
|
|
d2bb2d3918 | ||
|
|
8d91c13df5 | ||
|
|
7bc5360bba | ||
|
|
05241802a7 | ||
|
|
fc1e9951c6 | ||
|
|
8bdba4d011 | ||
|
|
fb48f6c982 | ||
|
|
76c476f817 | ||
|
|
b308d81e92 | ||
|
|
7d8de4d55d | ||
|
|
0f214ecef0 | ||
|
|
8a5fab6333 | ||
|
|
512499c8ca | ||
|
|
ec9781d5e4 | ||
|
|
614aca61e5 | ||
|
|
6dd333dfe6 | ||
|
|
30bab71f7b | ||
|
|
737d131e5e | ||
|
|
5222677176 | ||
|
|
6666ac42a5 | ||
|
|
2062fc4155 | ||
|
|
6a7b7ce23e | ||
|
|
3d829627fb | ||
|
|
cab774d6e5 | ||
|
|
46fc23b532 | ||
|
|
30f00a4286 | ||
|
|
66dc9068eb |
No files matched your search
@@ -95,7 +95,7 @@ Stephan Linz <linz@li-pro.net>
|
||||
John Lombardo <john@deltanet.com>
|
||||
tr
|
||||
|
||||
Glenn McGrath <bug1@iinet.net.au>
|
||||
Glenn McGrath <glenn.l.mcgrath@gmail.com>
|
||||
Common unarchiving code and unarchiving applets, ifupdown, ftpgetput,
|
||||
nameif, sed, patch, fold, install, uudecode.
|
||||
Various bugfixes, review and apply numerous patches.
|
||||
|
||||
@@ -13,22 +13,6 @@ menu "Busybox Settings"
|
||||
|
||||
menu "General Configuration"
|
||||
|
||||
config NITPICK
|
||||
bool "See lots more (probably unnecessary) configuration options."
|
||||
default n
|
||||
help
|
||||
Some BusyBox applets have more configuration options than anyone
|
||||
will ever care about. To avoid drowining people in complexity, most
|
||||
of the applet features that can be set to a sane default value are
|
||||
hidden, unless you hit the above switch.
|
||||
|
||||
This is better than to telling people to edit the busybox source
|
||||
code, but not by much.
|
||||
|
||||
See http://en.wikipedia.org/wiki/Fibber_McGee_and_Molly#The_Closet
|
||||
|
||||
You have been warned.
|
||||
|
||||
config DESKTOP
|
||||
bool "Enable options for full-blown desktop systems"
|
||||
default n
|
||||
@@ -37,10 +21,21 @@ config DESKTOP
|
||||
Select this only if you plan to use busybox on full-blown
|
||||
desktop machine with common Linux distro, not on an embedded box.
|
||||
|
||||
config FEATURE_ASSUME_UNICODE
|
||||
bool "Assume that 1:1 char/glyph correspondence is not true"
|
||||
default n
|
||||
help
|
||||
This makes various applets aware that one byte is not
|
||||
one character on screen.
|
||||
|
||||
Busybox aims to eventually work correctly with Unicode displays.
|
||||
Any older encodings are not guaranteed to work.
|
||||
Probably by the time when busybox will be fully Unicode-clean,
|
||||
other encodings will be mainly of historic interest.
|
||||
|
||||
choice
|
||||
prompt "Buffer allocation policy"
|
||||
default FEATURE_BUFFERS_USE_MALLOC
|
||||
depends on NITPICK
|
||||
help
|
||||
There are 3 ways BusyBox can handle buffer allocations:
|
||||
- Use malloc. This costs code size for the call to xmalloc.
|
||||
@@ -111,7 +106,7 @@ config LOCALE_SUPPORT
|
||||
busybox to support locale settings.
|
||||
|
||||
config GETOPT_LONG
|
||||
bool "Enable support for --long-options"
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
help
|
||||
Enable this if you want busybox applets to use the gnu --long-option
|
||||
@@ -130,7 +125,6 @@ config FEATURE_DEVPTS
|
||||
config FEATURE_CLEAN_UP
|
||||
bool "Clean up all memory before exiting (usually not needed)"
|
||||
default n
|
||||
depends on NITPICK
|
||||
help
|
||||
As a size optimization, busybox normally exits without explicitly
|
||||
freeing dynamically allocated memory or closing files. This saves
|
||||
@@ -186,10 +180,10 @@ config FEATURE_SUID_CONFIG
|
||||
|
||||
The file has to be owned by user root, group root and has to be
|
||||
writeable only by root:
|
||||
(chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
|
||||
(chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
|
||||
The busybox executable has to be owned by user root, group
|
||||
root and has to be setuid root for this to work:
|
||||
(chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)
|
||||
(chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)
|
||||
|
||||
Robert 'sandman' Griebl has more information here:
|
||||
<url: http://www.softforge.de/bb/suid.html >.
|
||||
@@ -280,44 +274,104 @@ config STATIC
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config PIE
|
||||
bool "Build BusyBox as a position independent executable"
|
||||
default n
|
||||
depends on !STATIC
|
||||
help
|
||||
(TODO: what is it and why/when is it useful?)
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config NOMMU
|
||||
bool "Force NOMMU build"
|
||||
default n
|
||||
help
|
||||
Busybox tries to detect whether architecture it is being
|
||||
built against supports MMU or not. If this detection fails,
|
||||
or if you want to build NOMMU version of busybox for testing,
|
||||
you may force NOMMU build here.
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
# PIE can be made to work with BUILD_LIBBUSYBOX, but currently
|
||||
# build system does not support that
|
||||
config BUILD_LIBBUSYBOX
|
||||
bool "Build shared libbusybox"
|
||||
default n
|
||||
depends on !FEATURE_PREFER_APPLETS && !PIE && !STATIC
|
||||
help
|
||||
Build a shared library libbusybox.so which contains all
|
||||
libraries used inside busybox.
|
||||
Build a shared library libbusybox.so.N.N.N which contains all
|
||||
busybox code.
|
||||
|
||||
This is an experimental feature intended to support the upcoming
|
||||
"make standalone" mode. Enabling it against the one big busybox
|
||||
binary serves no purpose (and increases the size). You should
|
||||
almost certainly say "no" to this right now.
|
||||
This feature allows every applet to be built as a tiny
|
||||
separate executable. Enabling it for "one big busybox binary"
|
||||
approach serves no purpose and increases code size.
|
||||
You should almost certainly say "no" to this.
|
||||
|
||||
config FEATURE_FULL_LIBBUSYBOX
|
||||
bool "Feature-complete libbusybox"
|
||||
default n if !FEATURE_SHARED_BUSYBOX
|
||||
depends on BUILD_LIBBUSYBOX
|
||||
help
|
||||
Build a libbusybox with the complete feature-set, disregarding
|
||||
the actually selected config.
|
||||
### config FEATURE_FULL_LIBBUSYBOX
|
||||
### bool "Feature-complete libbusybox"
|
||||
### default n if !FEATURE_SHARED_BUSYBOX
|
||||
### depends on BUILD_LIBBUSYBOX
|
||||
### help
|
||||
### Build a libbusybox with the complete feature-set, disregarding
|
||||
### the actually selected config.
|
||||
###
|
||||
### Normally, libbusybox will only contain the features which are
|
||||
### used by busybox itself. If you plan to write a separate
|
||||
### standalone application which uses libbusybox say 'Y'.
|
||||
###
|
||||
### Note: libbusybox is GPL, not LGPL, and exports no stable API that
|
||||
### might act as a copyright barrier. We can and will modify the
|
||||
### exported function set between releases (even minor version number
|
||||
### changes), and happily break out-of-tree features.
|
||||
###
|
||||
### Say 'N' if in doubt.
|
||||
|
||||
Normally, libbusybox will only contain the features which are
|
||||
used by busybox itself. If you plan to write a separate
|
||||
standalone application which uses libbusybox say 'Y'.
|
||||
|
||||
Note: libbusybox is GPL, not LGPL, and exports no stable API that
|
||||
might act as a copyright barrier. We can and will modify the
|
||||
exported function set between releases (even minor version number
|
||||
changes), and happily break out-of-tree features.
|
||||
|
||||
Say 'N' if in doubt.
|
||||
|
||||
config FEATURE_SHARED_BUSYBOX
|
||||
bool "Use shared libbusybox for busybox"
|
||||
default y if BUILD_LIBBUSYBOX
|
||||
config FEATURE_INDIVIDUAL
|
||||
bool "Produce a binary for each applet, linked against libbusybox"
|
||||
default y
|
||||
depends on !STATIC && BUILD_LIBBUSYBOX
|
||||
help
|
||||
Use libbusybox.so also for busybox itself.
|
||||
You need to have a working dynamic linker to use this variant.
|
||||
If your CPU architecture doesn't allow for sharing text/rodata
|
||||
sections of running binaries, but allows for runtime dynamic
|
||||
libraries, this option will allow you to reduce memory footprint
|
||||
when you have many different applets running at once.
|
||||
|
||||
If your CPU architecture allows for sharing text/rodata,
|
||||
having single binary is more optimal.
|
||||
|
||||
Each applet will be a tiny program, dynamically linked
|
||||
against libbusybox.so.N.N.N.
|
||||
|
||||
You need to have a working dynamic linker.
|
||||
|
||||
config FEATURE_SHARED_BUSYBOX
|
||||
bool "Produce additional busybox binary linked against libbusybox"
|
||||
default y
|
||||
depends on !STATIC && BUILD_LIBBUSYBOX
|
||||
help
|
||||
Build busybox, dynamically linked against libbusybox.so.N.N.N.
|
||||
|
||||
You need to have a working dynamic linker.
|
||||
|
||||
### config BUILD_AT_ONCE
|
||||
### bool "Compile all sources at once"
|
||||
### default n
|
||||
### help
|
||||
### Normally each source-file is compiled with one invocation of
|
||||
### the compiler.
|
||||
### If you set this option, all sources are compiled at once.
|
||||
### This gives the compiler more opportunities to optimize which can
|
||||
### result in smaller and/or faster binaries.
|
||||
###
|
||||
### Setting this option will consume alot of memory, e.g. if you
|
||||
### enable all applets with all features, gcc uses more than 300MB
|
||||
### RAM during compilation of busybox.
|
||||
###
|
||||
### This option is most likely only beneficial for newer compilers
|
||||
### such as gcc-4.1 and above.
|
||||
###
|
||||
### Say 'N' unless you know what you are doing.
|
||||
|
||||
config LFS
|
||||
bool "Build with Large File Support (for accessing files > 2 GB)"
|
||||
@@ -331,24 +385,15 @@ config LFS
|
||||
cp, mount, tar, and many others. If you want to access files larger
|
||||
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
|
||||
|
||||
config BUILD_AT_ONCE
|
||||
bool "Compile all sources at once"
|
||||
default n
|
||||
config CROSS_COMPILER_PREFIX
|
||||
string "Cross Compiler prefix"
|
||||
default ""
|
||||
help
|
||||
Normally each source-file is compiled with one invocation of
|
||||
the compiler.
|
||||
If you set this option, all sources are compiled at once.
|
||||
This gives the compiler more opportunities to optimize which can
|
||||
result in smaller and/or faster binaries.
|
||||
|
||||
Setting this option will consume alot of memory, e.g. if you
|
||||
enable all applets with all features, gcc uses more than 300MB
|
||||
RAM during compilation of busybox.
|
||||
|
||||
This option is most likely only beneficial for newer compilers
|
||||
such as gcc-4.1 and above.
|
||||
|
||||
Say 'N' unless you know what you are doing.
|
||||
If you want to build BusyBox with a cross compiler, then you
|
||||
will need to set this to the cross-compiler prefix, for example,
|
||||
"i386-uclibc-". Note that CROSS_COMPILE environment variable
|
||||
or "make CROSS_COMPILE=xxx ..." will override this selection.
|
||||
For native build leave it empty.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -365,6 +410,17 @@ config DEBUG
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
config DEBUG_PESSIMIZE
|
||||
bool "Disable compiler optimizations."
|
||||
default n
|
||||
depends on DEBUG
|
||||
help
|
||||
The compiler's optimization of source code can eliminate and reorder
|
||||
code, resulting in an executable that's hard to understand when
|
||||
stepping through it with a debugger. This switches it off, resulting
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
@@ -373,18 +429,6 @@ config WERROR
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
# Seems to be unused
|
||||
#config DEBUG_PESSIMIZE
|
||||
# bool "Disable compiler optimizations."
|
||||
# default n
|
||||
# depends on DEBUG
|
||||
# help
|
||||
# The compiler's optimization of source code can eliminate and reorder
|
||||
# code, resulting in an executable that's hard to understand when
|
||||
# stepping through it with a debugger. This switches it off, resulting
|
||||
# in a much bigger executable that more closely matches the source
|
||||
# code.
|
||||
|
||||
choice
|
||||
prompt "Additional debugging library"
|
||||
default NO_DEBUG_LIB
|
||||
@@ -465,6 +509,11 @@ config INSTALL_APPLET_HARDLINKS
|
||||
Install applets as hard-links to the busybox binary. This might count
|
||||
on a filesystem with few inodes.
|
||||
|
||||
config INSTALL_APPLET_SCRIPT_WRAPPERS
|
||||
bool "as script wrappers"
|
||||
help
|
||||
Install applets as script wrappers that call the busybox binary.
|
||||
|
||||
config INSTALL_APPLET_DONT
|
||||
bool "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
|
||||
@@ -474,6 +523,30 @@ config INSTALL_APPLET_DONT
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "/bin/sh applet link"
|
||||
default INSTALL_SH_APPLET_SYMLINK
|
||||
depends on INSTALL_APPLET_SCRIPT_WRAPPERS
|
||||
help
|
||||
Choose how you install /bin/sh applet link.
|
||||
|
||||
config INSTALL_SH_APPLET_SYMLINK
|
||||
bool "as soft-link"
|
||||
help
|
||||
Install /bin/sh applet as soft-link to the busybox binary.
|
||||
|
||||
config INSTALL_SH_APPLET_HARDLINK
|
||||
bool "as hard-link"
|
||||
help
|
||||
Install /bin/sh applet as hard-link to the busybox binary.
|
||||
|
||||
config INSTALL_SH_APPLET_SCRIPT_WRAPPER
|
||||
bool "as script wrapper"
|
||||
help
|
||||
Install /bin/sh applet as script wrapper that call the busybox binary.
|
||||
|
||||
endchoice
|
||||
|
||||
config PREFIX
|
||||
string "BusyBox installation prefix"
|
||||
default "./_install"
|
||||
@@ -506,4 +579,4 @@ source shell/Config.in
|
||||
source sysklogd/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
source ipsvd/Config.in
|
||||
source printutils/Config.in
|
||||
@@ -1,7 +1,7 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 7
|
||||
SUBLEVEL = 0
|
||||
EXTRAVERSION = .svn
|
||||
PATCHLEVEL = 11
|
||||
SUBLEVEL = 3
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
# *DOCUMENTATION*
|
||||
@@ -142,17 +142,6 @@ VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
|
||||
export srctree objtree VPATH TOPDIR
|
||||
|
||||
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
-e s/arm.*/arm/ -e s/sa110/arm/ \
|
||||
-e s/s390x/s390/ -e s/parisc64/parisc/ \
|
||||
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
|
||||
|
||||
# Cross compiling and selecting different set of gcc/bin-utils
|
||||
# ---------------------------------------------------------------------------
|
||||
#
|
||||
@@ -172,8 +161,32 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
# Default value for CROSS_COMPILE is not to prefix executables
|
||||
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
|
||||
|
||||
ARCH ?= $(SUBARCH)
|
||||
CROSS_COMPILE ?=
|
||||
CROSS_COMPILE ?=
|
||||
# bbox: we may have CONFIG_CROSS_COMPILER_PREFIX in .config,
|
||||
# and it has not been included yet... thus using an awkward syntax.
|
||||
ifeq ($(CROSS_COMPILE),)
|
||||
CROSS_COMPILE := $(shell grep ^CONFIG_CROSS_COMPILER_PREFIX .config 2>/dev/null)
|
||||
CROSS_COMPILE := $(subst CONFIG_CROSS_COMPILER_PREFIX=,,$(CROSS_COMPILE))
|
||||
CROSS_COMPILE := $(subst ",,$(CROSS_COMPILE))
|
||||
endif
|
||||
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
SUBARCH := $(shell echo $(CROSS_COMPILE) | cut -d- -f1)
|
||||
else
|
||||
SUBARCH := $(shell uname -m)
|
||||
endif
|
||||
SUBARCH := $(shell echo $(SUBARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
-e s/arm.*/arm/ -e s/sa110/arm/ \
|
||||
-e s/s390x/s390/ -e s/parisc64/parisc/ \
|
||||
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
|
||||
|
||||
ARCH ?= $(SUBARCH)
|
||||
|
||||
# Architecture as present in compile.h
|
||||
UTS_MACHINE := $(ARCH)
|
||||
@@ -302,6 +315,8 @@ AFLAGS_KERNEL =
|
||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
CFLAGS := $(CFLAGS)
|
||||
# Added only to final link stage of busybox binary
|
||||
CFLAGS_busybox := $(CFLAGS_busybox)
|
||||
CPPFLAGS := $(CPPFLAGS)
|
||||
AFLAGS := $(AFLAGS)
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
@@ -361,7 +376,8 @@ endif
|
||||
# of make so .config is not included in this case either (for *config).
|
||||
|
||||
no-dot-config-targets := clean mrproper distclean \
|
||||
cscope TAGS tags help %docs check%
|
||||
cscope TAGS tags help %docs
|
||||
#bbox# check% is removed from above
|
||||
|
||||
config-targets := 0
|
||||
mixed-targets := 0
|
||||
@@ -437,7 +453,6 @@ libs-y := \
|
||||
editors/ \
|
||||
findutils/ \
|
||||
init/ \
|
||||
ipsvd/ \
|
||||
libbb/ \
|
||||
libpwdgrp/ \
|
||||
loginutils/ \
|
||||
@@ -446,12 +461,14 @@ libs-y := \
|
||||
networking/ \
|
||||
networking/libiproute/ \
|
||||
networking/udhcp/ \
|
||||
printutils/ \
|
||||
procps/ \
|
||||
runit/ \
|
||||
selinux/ \
|
||||
shell/ \
|
||||
sysklogd/ \
|
||||
util-linux/ \
|
||||
util-linux/volume_id/ \
|
||||
|
||||
endif # KBUILD_EXTMOD
|
||||
|
||||
@@ -496,12 +513,6 @@ all: busybox
|
||||
#bbox# NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
|
||||
CHECKFLAGS += $(NOSTDINC_FLAGS)
|
||||
|
||||
# warn about C99 declaration after statement
|
||||
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
|
||||
# disable pointer signedness warnings in gcc 4.0
|
||||
CFLAGS += $(call cc-option,-Wno-pointer-sign,)
|
||||
|
||||
# Default kernel image to build when no specific target is given.
|
||||
# KBUILD_IMAGE may be overruled on the commandline or
|
||||
# set in the environment
|
||||
@@ -568,11 +579,14 @@ busybox-all := $(core-y) $(libs-y)
|
||||
# Rule to link busybox - also used during CONFIG_KALLSYMS
|
||||
# May be overridden by arch/$(ARCH)/Makefile
|
||||
quiet_cmd_busybox__ ?= LINK $@
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
|
||||
-o $@ -Wl,-Map -Wl,$@.map \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group \
|
||||
$(LDLIBS)
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink \
|
||||
"$@" \
|
||||
"$(CC)" \
|
||||
"$(CFLAGS) $(CFLAGS_busybox)" \
|
||||
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
|
||||
"$(core-y)" \
|
||||
"$(libs-y)" \
|
||||
"$(LDLIBS)"
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
@@ -684,6 +698,8 @@ ifeq ($(SKIP_STRIP),y)
|
||||
else
|
||||
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
|
||||
busybox_unstripped -o $@
|
||||
# strip is confused by PIE executable and does not set exec bits
|
||||
$(Q)chmod a+x $@
|
||||
endif
|
||||
|
||||
# The actual objects are generated when descending,
|
||||
@@ -727,7 +743,7 @@ localver = $(subst $(space),, \
|
||||
# Currently, only git is supported.
|
||||
# Other SCMs can edit scripts/setlocalversion and add the appropriate
|
||||
# checks as needed.
|
||||
ifdef CONFIG_LOCALVERSION_AUTO
|
||||
ifdef _BB_DISABLED_CONFIG_LOCALVERSION_AUTO
|
||||
_localver-auto = $(shell $(CONFIG_SHELL) \
|
||||
$(srctree)/scripts/setlocalversion $(srctree))
|
||||
localver-auto = $(LOCALVERSION)$(_localver-auto)
|
||||
@@ -840,7 +856,7 @@ depend dep:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Modules
|
||||
|
||||
ifdef CONFIG_MODULES
|
||||
ifdef _BB_DISABLED_CONFIG_MODULES
|
||||
|
||||
# By default, build modules as well
|
||||
|
||||
@@ -917,7 +933,7 @@ endif # CONFIG_MODULES
|
||||
|
||||
# Directories & files removed with 'make clean'
|
||||
CLEAN_DIRS += $(MODVERDIR)
|
||||
CLEAN_FILES += busybox* System.map .kernelrelease \
|
||||
CLEAN_FILES += busybox busybox_unstripped* System.map .kernelrelease \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
@@ -926,6 +942,8 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
include/autoconf.h \
|
||||
include/bbconfigopts.h \
|
||||
include/usage_compressed.h \
|
||||
include/applet_tables.h \
|
||||
applets/usage \
|
||||
.kernelrelease Module.symvers tags TAGS cscope*
|
||||
|
||||
# clean - Delete most, but leave enough to build external modules
|
||||
@@ -968,7 +986,7 @@ distclean: mrproper
|
||||
@find $(srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
|
||||
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
|
||||
-o -name '.*.rej' -o -size 0 \
|
||||
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
|
||||
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
|
||||
-type f -print | xargs rm -f
|
||||
|
||||
|
||||
+21
-5
@@ -12,6 +12,17 @@ endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_HARDLINKS),y)
|
||||
INSTALL_OPTS:= --hardlinks
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS),y)
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_SYMLINK),y)
|
||||
INSTALL_OPTS:= --sw-sh-sym
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_HARDLINK),y)
|
||||
INSTALL_OPTS:= --sw-sh-hard
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
@@ -35,15 +46,20 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
|
||||
done
|
||||
endif
|
||||
|
||||
# Not very elegant: copies testsuite to objdir...
|
||||
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
|
||||
.PHONY: check
|
||||
.PHONY: test
|
||||
check test: busybox busybox.links
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
|
||||
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite \
|
||||
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
|
||||
|
||||
.PHONY: release
|
||||
release: distclean
|
||||
cd ..; \
|
||||
rm -r -f busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION); \
|
||||
cp -a busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
|
||||
cp -pPR busybox busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) && { \
|
||||
find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type d \
|
||||
-name .svn \
|
||||
-print \
|
||||
@@ -79,11 +95,11 @@ objsizes: busybox_unstripped
|
||||
|
||||
.PHONY: stksizes
|
||||
stksizes: busybox_unstripped
|
||||
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH)
|
||||
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH) | uniq
|
||||
|
||||
.PHONY: bigdata
|
||||
bigdata: busybox_unstripped
|
||||
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [tr] '
|
||||
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [trw] '
|
||||
|
||||
# Documentation Targets
|
||||
.PHONY: doc
|
||||
|
||||
+57
-35
@@ -3,6 +3,7 @@
|
||||
# ==========================================================================
|
||||
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
export BB_VER
|
||||
SKIP_STRIP = n
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
@@ -10,37 +11,31 @@ CPPFLAGS += $(call cc-option,-std=gnu99,)
|
||||
|
||||
CPPFLAGS += \
|
||||
-Iinclude -Ilibbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include -I$(srctree)/libbb) \
|
||||
-include include/autoconf.h \
|
||||
-D_GNU_SOURCE -DNDEBUG \
|
||||
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
|
||||
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
|
||||
|
||||
# flag checks are grouped together to speed the checks up a bit..
|
||||
CFLAGS += $(call cc-option,-Wall -Wshadow -Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef -Wstrict-prototypes,)
|
||||
# If you want to add "-Wmissing-prototypes -Wmissing-declarations" above
|
||||
# (or anything else for that matter) make sure that it is still possible
|
||||
# to build bbox without warnings. Current offender: find.c:alloc_action().
|
||||
# Looks more like gcc bug: gcc will warn on it with or without prototype.
|
||||
# But still, warning-free compile is a must, or else we will drown
|
||||
# in warnings pretty soon.
|
||||
CFLAGS += $(call cc-option,-Wall,)
|
||||
CFLAGS += $(call cc-option,-Wshadow,)
|
||||
CFLAGS += $(call cc-option,-Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef,)
|
||||
CFLAGS += $(call cc-option,-Wstrict-prototypes,)
|
||||
CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
# warn about C99 declaration after statement
|
||||
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
# If you want to add more -Wsomething above, make sure that it is
|
||||
# still possible to build bbox without warnings.
|
||||
|
||||
ifeq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Werror,)
|
||||
else
|
||||
# for development, warn a little bit about unused results..
|
||||
CPPFLAGS += -D_FORTIFY_SOURCE=2
|
||||
endif
|
||||
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
|
||||
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
|
||||
|
||||
# gcc emits bogus "no prev proto" warning on find.c:alloc_action()
|
||||
ifneq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
# -fno-guess-branch-probability: prohibit pseudo-random guessing
|
||||
# of branch probabilities (hopefully makes bloatcheck more stable):
|
||||
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
|
||||
@@ -51,43 +46,70 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
|
||||
# be fixed..
|
||||
#CFLAGS+=$(call cc-option,-Wconversion,)
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
ifneq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-Os,)
|
||||
else
|
||||
CFLAGS += $(call cc-option,-g,)
|
||||
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
|
||||
CFLAGS += $(call cc-option,-O0,)
|
||||
else
|
||||
CFLAGS += $(call cc-option,-Os,)
|
||||
endif
|
||||
endif
|
||||
|
||||
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
|
||||
ARCH_FPIC ?= -fpic
|
||||
ARCH_FPIE ?= -fpie
|
||||
ARCH_PIE ?= -pie
|
||||
|
||||
ifeq ($(CONFIG_BUILD_LIBBUSYBOX),y)
|
||||
# on i386: 14% smaller libbusybox.so
|
||||
# (code itself is 9% bigger, we save on relocs/PLT/GOT)
|
||||
CFLAGS += $(ARCH_FPIC)
|
||||
# and another 4% reduction of libbusybox.so:
|
||||
# (external entry points must be marked EXTERNALLY_VISIBLE)
|
||||
CFLAGS += $(call cc-option,-fvisibility=hidden)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STATIC),y)
|
||||
LDFLAGS += -static
|
||||
CFLAGS_busybox += -static
|
||||
endif
|
||||
|
||||
BBOX_LIB_LIST = m crypt
|
||||
ifeq ($(CONFIG_PIE),y)
|
||||
CFLAGS_busybox += $(ARCH_PIE)
|
||||
CFLAGS += $(ARCH_FPIE)
|
||||
endif
|
||||
|
||||
LDLIBS += m crypt
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
BBOX_LIB_LIST += pam pam_misc
|
||||
LDLIBS += pam pam_misc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
BBOX_LIB_LIST += selinux sepol
|
||||
LDLIBS += selinux sepol
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
BBOX_LIB_LIST += efence
|
||||
LDLIBS += efence
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DMALLOC),y)
|
||||
BBOX_LIB_LIST += dmalloc
|
||||
LDLIBS += dmalloc
|
||||
endif
|
||||
|
||||
# For scripts/trylink
|
||||
export BBOX_LIB_LIST
|
||||
|
||||
#LDFLAGS += -nostdlib
|
||||
|
||||
LDFLAGS_ELF2FLT = -Wl,-elf2flt
|
||||
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
|
||||
# If a flat binary should be built, CFLAGS_busybox="-Wl,-elf2flt"
|
||||
# env var should be set for make invocation.
|
||||
# Here we check whether CFLAGS_busybox indeed contains that flag.
|
||||
# (For historical reasons, we also check LDFLAGS, which doesn't
|
||||
# seem to be entirely correct variable to put "-Wl,-elf2flt" into).
|
||||
W_ELF2FLT = -Wl,-elf2flt
|
||||
ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
|
||||
SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
# TODO: use "make stksizes" to find & fix big stack users
|
||||
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
|
||||
FLTFLAGS += -s 20000
|
||||
# Reduced from 20k to 16k in 1.9.0.
|
||||
FLTFLAGS += -s 16000
|
||||
+2
-3
@@ -16,7 +16,6 @@ help:
|
||||
@echo 'Configuration:'
|
||||
@echo ' allnoconfig - disable all symbols in .config'
|
||||
@echo ' allyesconfig - enable all symbols in .config (see defconfig)'
|
||||
@echo ' allbareconfig - enable all applets without any sub-features'
|
||||
@echo ' config - text based configurator (of last resort)'
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@@ -24,10 +23,10 @@ help:
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into $(CONFIG_PREFIX)'
|
||||
@echo ' install - install busybox into CONFIG_PREFIX'
|
||||
@echo ' uninstall'
|
||||
@echo
|
||||
@echo 'Development:'
|
||||
|
||||
@@ -82,6 +82,9 @@ Downloading the current source code:
|
||||
is generally a faster way of getting it fixed, and the complete archive of
|
||||
what happened is the subversion changelog.
|
||||
|
||||
Note: if you want to compile busybox in a busybox environment you must
|
||||
select ENABLE_DESKTOP.
|
||||
|
||||
----------------
|
||||
|
||||
getting help:
|
||||
|
||||
@@ -6,37 +6,24 @@ do one of these bounce an email off the person it's listed under to see if they
|
||||
have any suggestions how they plan to go about it, and to minimize conflicts
|
||||
between your work and theirs. But otherwise, all of these are fair game.
|
||||
|
||||
Rob Landley <rob@landley.net>:
|
||||
Add BB_NOMMU to platform.h and migrate __uClinux__ tests to that.
|
||||
#if defined __UCLIBC__ && !defined __ARCH_USE_MMU__
|
||||
Rob Landley suggested these:
|
||||
Add a libbb/platform.c
|
||||
Implement fdprintf() for platforms that haven't got one.
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Cleanup bb_asprintf()
|
||||
|
||||
Migrate calloc() and bb_calloc() occurrences to bb_xzalloc().
|
||||
Remove obsolete _() wrapper crud for internationalization we don't do.
|
||||
Figure out where we need utf8 support, and add it.
|
||||
|
||||
sh
|
||||
The command shell situation is a big mess. We have three or four different
|
||||
The command shell situation is a big mess. We have three different
|
||||
shells that don't really share any code, and the "standalone shell" doesn't
|
||||
work all that well (especially not in a chroot environment), due to apps not
|
||||
being reentrant. I'm writing a new shell (bbsh) to unify the various
|
||||
shells and configurably add the minimal set of bash features people
|
||||
actually use. The hardest part is it has to configure down as small as
|
||||
lash while providing lash's features. The rest is easy in comparison.
|
||||
bzip2
|
||||
Compression-side support.
|
||||
being reentrant.
|
||||
lash is phased out. hush can be configured down to be nearly as small,
|
||||
but less buggy :)
|
||||
init
|
||||
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
|
||||
depmod
|
||||
busybox lacks a way to update module deps when running from firmware without the
|
||||
use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
|
||||
modutils. The orig depmod is rather pointless to have to add to a firmware image
|
||||
in when we already have a insmod/rmmod and friends.
|
||||
Unify base64 handling.
|
||||
[done]
|
||||
Do a SUSv3 audit
|
||||
Look at the full Single Unix Specification version 3 (available online at
|
||||
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
|
||||
@@ -128,9 +115,6 @@ Bernhard Fischer <busybox@busybox.net> suggests to look at these:
|
||||
|
||||
As yet unclaimed:
|
||||
|
||||
----
|
||||
find
|
||||
doesn't understand (), lots of susv3 stuff.
|
||||
----
|
||||
diff
|
||||
Make sure we handle empty files properly:
|
||||
@@ -148,10 +132,6 @@ patch
|
||||
And while we're at it, a new patch filename quoting format is apparently
|
||||
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
|
||||
---
|
||||
ps / top
|
||||
Add support for both RSS and VSIZE rather than just one or the other.
|
||||
Or make it a build option.
|
||||
---
|
||||
man
|
||||
It would be nice to have a man command. Not one that handles troff or
|
||||
anything, just one that can handle preformatted ascii man pages, possibly
|
||||
@@ -161,7 +141,7 @@ man
|
||||
(How doclifter might work into this is anybody's guess.)
|
||||
---
|
||||
ar
|
||||
Write support?
|
||||
Write support!
|
||||
---
|
||||
stty / catv
|
||||
stty's visible() function and catv's guts are identical. Merge them into
|
||||
@@ -297,24 +277,22 @@ Minor stuff:
|
||||
---
|
||||
use bb_perror_msg where appropriate: See
|
||||
egrep "[^_]perror"
|
||||
---
|
||||
Remove superfluous fmt occurances: e.g.
|
||||
fprintf(stderr, "%s: %s not found\n", "unalias", *argptr);
|
||||
-> fprintf(stderr, "unalias: %s not found\n", *argptr);
|
||||
---
|
||||
possible code duplication ingroup() and is_a_group_member()
|
||||
---
|
||||
Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
|
||||
---
|
||||
See grep -r strtod
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
in_ether duplicated in network/{interface,ifconfig}.c
|
||||
---
|
||||
|
||||
|
||||
Code cleanup:
|
||||
|
||||
Replace deprecated functions.
|
||||
|
||||
bzero() -> memset()
|
||||
---
|
||||
sigblock(), siggetmask(), sigsetmask(), sigmask() -> sigprocmask et al
|
||||
---
|
||||
vdprintf() -> similar sized functionality
|
||||
---
|
||||
+247
-114
@@ -1,11 +1,7 @@
|
||||
# This .config compiles for NOMMU.
|
||||
# TODO:
|
||||
# Pick disabled applet, enable & try to make it compile & work on NOMMU
|
||||
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.6.0.svn
|
||||
# Wed Apr 11 01:29:04 2007
|
||||
# Busybox version: 1.11.0.svn
|
||||
# Mon Apr 21 23:20:35 2008
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -16,9 +12,8 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
#
|
||||
# General Configuration
|
||||
#
|
||||
# CONFIG_NITPICK is not set
|
||||
# CONFIG_DESKTOP is not set
|
||||
# CONFIG_FEATURE_BUFFERS_USE_MALLOC is not set
|
||||
CONFIG_DESKTOP=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
CONFIG_SHOW_USAGE=y
|
||||
@@ -31,29 +26,29 @@ CONFIG_FEATURE_DEVPTS=y
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
CONFIG_FEATURE_PIDFILE=y
|
||||
CONFIG_FEATURE_SUID=y
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
# CONFIG_SELINUX is not set
|
||||
CONFIG_FEATURE_SUID_CONFIG=y
|
||||
CONFIG_FEATURE_SUID_CONFIG_QUIET=y
|
||||
CONFIG_SELINUX=y
|
||||
CONFIG_FEATURE_PREFER_APPLETS=y
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
CONFIG_FEATURE_HAVE_RPC=y
|
||||
|
||||
#
|
||||
# Build Options
|
||||
#
|
||||
# CONFIG_STATIC is not set
|
||||
CONFIG_NOMMU=y
|
||||
# CONFIG_BUILD_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_INDIVIDUAL is not set
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
# CONFIG_BUILD_AT_ONCE is not set
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
CONFIG_WERROR=y
|
||||
# CONFIG_WERROR is not set
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
# CONFIG_EFENCE is not set
|
||||
@@ -65,7 +60,11 @@ CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_INSTALL_NO_USR is not set
|
||||
CONFIG_INSTALL_APPLET_SYMLINKS=y
|
||||
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
|
||||
# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
|
||||
# CONFIG_INSTALL_APPLET_DONT is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
|
||||
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
|
||||
CONFIG_PREFIX="./_install"
|
||||
|
||||
#
|
||||
@@ -73,14 +72,20 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SIZE_VS_SPEED=2
|
||||
CONFIG_FEATURE_FAST_TOP=y
|
||||
CONFIG_FEATURE_ETC_NETWORKS=y
|
||||
CONFIG_FEATURE_EDITING=y
|
||||
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
|
||||
# CONFIG_FEATURE_EDITING_VI is not set
|
||||
CONFIG_FEATURE_EDITING_MAX_LEN=1024
|
||||
CONFIG_FEATURE_EDITING_VI=y
|
||||
CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
|
||||
# CONFIG_FEATURE_TAB_COMPLETION is not set
|
||||
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
|
||||
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
|
||||
CONFIG_FEATURE_TAB_COMPLETION=y
|
||||
CONFIG_FEATURE_USERNAME_COMPLETION=y
|
||||
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
|
||||
CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y
|
||||
CONFIG_FEATURE_COPYBUF_KB=4
|
||||
CONFIG_MONOTONIC_SYSCALL=y
|
||||
CONFIG_IOCTL_HEX2STR_ERROR=y
|
||||
|
||||
#
|
||||
# Applets
|
||||
@@ -92,25 +97,31 @@ CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
# CONFIG_DPKG is not set
|
||||
# CONFIG_DPKG_DEB is not set
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
# CONFIG_RPM is not set
|
||||
CONFIG_RPM=y
|
||||
CONFIG_FEATURE_RPM_BZ2=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
# CONFIG_FEATURE_TAR_BZIP2 is not set
|
||||
# CONFIG_FEATURE_TAR_LZMA is not set
|
||||
CONFIG_FEATURE_TAR_GZIP=y
|
||||
CONFIG_FEATURE_TAR_BZIP2=y
|
||||
CONFIG_FEATURE_TAR_LZMA=y
|
||||
CONFIG_FEATURE_TAR_COMPRESS=y
|
||||
CONFIG_FEATURE_TAR_AUTODETECT=y
|
||||
CONFIG_FEATURE_TAR_FROM=y
|
||||
# CONFIG_FEATURE_TAR_GZIP is not set
|
||||
# CONFIG_FEATURE_TAR_COMPRESS is not set
|
||||
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
@@ -119,10 +130,13 @@ CONFIG_UNZIP=y
|
||||
#
|
||||
# Common options for cpio and tar
|
||||
#
|
||||
CONFIG_FEATURE_UNARCHIVE_TAPE=y
|
||||
# CONFIG_FEATURE_DEB_TAR_GZ is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_BZ2 is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_LZMA is not set
|
||||
|
||||
#
|
||||
# Common options for dpkg and dpkg_deb
|
||||
#
|
||||
CONFIG_FEATURE_DEB_TAR_GZ=y
|
||||
CONFIG_FEATURE_DEB_TAR_BZ2=y
|
||||
CONFIG_FEATURE_DEB_TAR_LZMA=y
|
||||
|
||||
#
|
||||
# Coreutils
|
||||
@@ -136,7 +150,6 @@ CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_CUT=y
|
||||
@@ -146,10 +159,7 @@ CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_FEATURE_DF_INODE=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
@@ -159,6 +169,8 @@ CONFIG_ECHO=y
|
||||
CONFIG_FEATURE_FANCY_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
|
||||
CONFIG_EXPAND=y
|
||||
CONFIG_FEATURE_EXPAND_LONG_OPTIONS=y
|
||||
CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
@@ -194,9 +206,12 @@ CONFIG_OD=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PRINTF=y
|
||||
CONFIG_PWD=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_FEATURE_READLINK_FOLLOW=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RM=y
|
||||
CONFIG_RMDIR=y
|
||||
CONFIG_FEATURE_RMDIR_LONG_OPTIONS=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
@@ -210,6 +225,7 @@ CONFIG_FEATURE_STAT_FORMAT=y
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
CONFIG_TEE=y
|
||||
@@ -223,11 +239,12 @@ CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNEXPAND=y
|
||||
CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS=y
|
||||
CONFIG_UNIQ=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUDECODE=y
|
||||
CONFIG_UUENCODE=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_WC=y
|
||||
CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHO=y
|
||||
@@ -261,6 +278,7 @@ CONFIG_CHVT=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_DEALLOCVT=y
|
||||
CONFIG_DUMPKMAP=y
|
||||
CONFIG_KBD_MODE=y
|
||||
CONFIG_LOADFONT=y
|
||||
CONFIG_LOADKMAP=y
|
||||
CONFIG_OPENVT=y
|
||||
@@ -277,14 +295,12 @@ CONFIG_SETLOGCONS=y
|
||||
#
|
||||
CONFIG_MKTEMP=y
|
||||
CONFIG_PIPE_PROGRESS=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_FEATURE_READLINK_FOLLOW=y
|
||||
CONFIG_RUN_PARTS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_FANCY=y
|
||||
# CONFIG_START_STOP_DAEMON is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
|
||||
CONFIG_START_STOP_DAEMON=y
|
||||
CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y
|
||||
CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y
|
||||
CONFIG_WHICH=y
|
||||
|
||||
#
|
||||
@@ -292,10 +308,17 @@ CONFIG_WHICH=y
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_MATH=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_MAX_LEN=4096
|
||||
CONFIG_FEATURE_VI_8BIT=y
|
||||
CONFIG_FEATURE_VI_COLON=y
|
||||
CONFIG_FEATURE_VI_YANKMARK=y
|
||||
CONFIG_FEATURE_VI_SEARCH=y
|
||||
@@ -318,6 +341,7 @@ CONFIG_FEATURE_FIND_MMIN=y
|
||||
CONFIG_FEATURE_FIND_PERM=y
|
||||
CONFIG_FEATURE_FIND_TYPE=y
|
||||
CONFIG_FEATURE_FIND_XDEV=y
|
||||
CONFIG_FEATURE_FIND_MAXDEPTH=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
@@ -328,6 +352,10 @@ CONFIG_FEATURE_FIND_DEPTH=y
|
||||
CONFIG_FEATURE_FIND_PAREN=y
|
||||
CONFIG_FEATURE_FIND_SIZE=y
|
||||
CONFIG_FEATURE_FIND_PRUNE=y
|
||||
CONFIG_FEATURE_FIND_DELETE=y
|
||||
CONFIG_FEATURE_FIND_PATH=y
|
||||
CONFIG_FEATURE_FIND_REGEX=y
|
||||
CONFIG_FEATURE_FIND_CONTEXT=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
@@ -341,14 +369,16 @@ CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
#
|
||||
# Init Utilities
|
||||
#
|
||||
# CONFIG_INIT is not set
|
||||
CONFIG_INIT=y
|
||||
# CONFIG_DEBUG_INIT is not set
|
||||
# CONFIG_FEATURE_USE_INITTAB is not set
|
||||
# CONFIG_FEATURE_INIT_SCTTY is not set
|
||||
# CONFIG_FEATURE_INIT_SYSLOG is not set
|
||||
# CONFIG_FEATURE_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_FEATURE_INITRD is not set
|
||||
CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_REMOVED=y
|
||||
CONFIG_FEATURE_KILL_DELAY=1
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_HALT=y
|
||||
CONFIG_MESG=y
|
||||
|
||||
@@ -361,16 +391,23 @@ CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
|
||||
CONFIG_FEATURE_CHECK_NAMES=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_FEATURE_ADDUSER_LONG_OPTIONS=y
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
CONFIG_FEATURE_WTMP=y
|
||||
CONFIG_LOGIN=y
|
||||
# CONFIG_PAM is not set
|
||||
CONFIG_LOGIN_SCRIPTS=y
|
||||
CONFIG_FEATURE_NOLOGIN=y
|
||||
CONFIG_FEATURE_SECURETTY=y
|
||||
CONFIG_PASSWD=y
|
||||
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
|
||||
CONFIG_CRYPTPW=y
|
||||
CONFIG_CHPASSWD=y
|
||||
CONFIG_SU=y
|
||||
CONFIG_FEATURE_SU_SYSLOG=y
|
||||
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
|
||||
@@ -426,6 +463,7 @@ CONFIG_FEATURE_SGI_LABEL=y
|
||||
CONFIG_FEATURE_SUN_LABEL=y
|
||||
CONFIG_FEATURE_OSF_LABEL=y
|
||||
CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FINDFS=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
@@ -436,6 +474,8 @@ CONFIG_MKFS_MINIX=y
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_HEXDUMP=y
|
||||
CONFIG_FEATURE_HEXDUMP_REVERSE=y
|
||||
CONFIG_HD=y
|
||||
CONFIG_HWCLOCK=y
|
||||
CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
@@ -444,19 +484,45 @@ CONFIG_IPCS=y
|
||||
CONFIG_LOSETUP=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_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_VOLUMEID=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=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_LINUXRAID=y
|
||||
CONFIG_MOUNT=y
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
CONFIG_FEATURE_MOUNT_FAKE=y
|
||||
CONFIG_FEATURE_MOUNT_VERBOSE=y
|
||||
CONFIG_FEATURE_MOUNT_HELPERS=y
|
||||
CONFIG_FEATURE_MOUNT_LABEL=y
|
||||
CONFIG_FEATURE_MOUNT_NFS=y
|
||||
CONFIG_FEATURE_MOUNT_CIFS=y
|
||||
CONFIG_FEATURE_MOUNT_FLAGS=y
|
||||
CONFIG_FEATURE_MOUNT_FSTAB=y
|
||||
CONFIG_PIVOT_ROOT=y
|
||||
CONFIG_RDATE=y
|
||||
CONFIG_READPROFILE=y
|
||||
CONFIG_RTCWAKE=y
|
||||
CONFIG_SCRIPT=y
|
||||
CONFIG_SETARCH=y
|
||||
CONFIG_SWAPONOFF=y
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
@@ -473,12 +539,20 @@ CONFIG_FEATURE_MOUNT_LOOP=y
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
CONFIG_ADJTIMEX=y
|
||||
# CONFIG_BBCONFIG is not set
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_CHAT=y
|
||||
CONFIG_FEATURE_CHAT_NOFAIL=y
|
||||
CONFIG_FEATURE_CHAT_TTY_HIFI=y
|
||||
CONFIG_FEATURE_CHAT_IMPLICIT_CR=y
|
||||
CONFIG_FEATURE_CHAT_SWALLOW_OPTS=y
|
||||
CONFIG_FEATURE_CHAT_SEND_ESCAPES=y
|
||||
CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
# CONFIG_CROND is not set
|
||||
# CONFIG_DEBUG_CROND_OPTION is not set
|
||||
# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
|
||||
# CONFIG_CRONTAB is not set
|
||||
CONFIG_CROND=y
|
||||
CONFIG_DEBUG_CROND_OPTION=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
# CONFIG_DEVFSD is not set
|
||||
# CONFIG_DEVFSD_MODLOAD is not set
|
||||
@@ -486,6 +560,8 @@ CONFIG_DC=y
|
||||
# CONFIG_DEVFSD_VERBOSE is not set
|
||||
# CONFIG_FEATURE_DEVFS is not set
|
||||
CONFIG_EJECT=y
|
||||
CONFIG_FEATURE_EJECT_SCSI=y
|
||||
CONFIG_FBSPLASH=y
|
||||
CONFIG_LAST=y
|
||||
CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
@@ -504,27 +580,34 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
|
||||
CONFIG_FEATURE_MAKEDEVS_TABLE=y
|
||||
CONFIG_MAN=y
|
||||
CONFIG_MICROCOM=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_MT=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
CONFIG_READAHEAD=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
CONFIG_RX=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SETSID=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SYMLINKS=y
|
||||
CONFIG_TASKSET=y
|
||||
CONFIG_FEATURE_TASKSET_FANCY=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
|
||||
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
|
||||
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
|
||||
CONFIG_ARP=y
|
||||
CONFIG_ARPING=y
|
||||
CONFIG_BRCTL=y
|
||||
CONFIG_FEATURE_BRCTL_FANCY=y
|
||||
CONFIG_FEATURE_BRCTL_SHOW=y
|
||||
CONFIG_DNSD=y
|
||||
CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
@@ -532,37 +615,43 @@ CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
CONFIG_HOSTNAME=y
|
||||
# CONFIG_HTTPD is not set
|
||||
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
|
||||
# CONFIG_FEATURE_HTTPD_SETUID is not set
|
||||
# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES is not set
|
||||
# CONFIG_FEATURE_HTTPD_CGI is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
|
||||
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
|
||||
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
|
||||
CONFIG_FEATURE_HTTPD_CGI=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
|
||||
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
|
||||
CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
|
||||
CONFIG_FEATURE_HTTPD_ERROR_PAGES=y
|
||||
CONFIG_FEATURE_HTTPD_PROXY=y
|
||||
CONFIG_IFCONFIG=y
|
||||
CONFIG_FEATURE_IFCONFIG_STATUS=y
|
||||
CONFIG_FEATURE_IFCONFIG_SLIP=y
|
||||
CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
|
||||
CONFIG_FEATURE_IFCONFIG_HW=y
|
||||
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
|
||||
# CONFIG_IFUPDOWN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
|
||||
CONFIG_IFENSLAVE=y
|
||||
CONFIG_IFUPDOWN=y
|
||||
CONFIG_IFUPDOWN_IFSTATE_PATH="/var/run/ifstate"
|
||||
CONFIG_FEATURE_IFUPDOWN_IP=y
|
||||
CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN=y
|
||||
# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPX is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
|
||||
# CONFIG_INETD is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
|
||||
# CONFIG_FEATURE_INETD_RPC is not set
|
||||
CONFIG_FEATURE_IFUPDOWN_IPV4=y
|
||||
CONFIG_FEATURE_IFUPDOWN_IPV6=y
|
||||
CONFIG_FEATURE_IFUPDOWN_MAPPING=y
|
||||
CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP=y
|
||||
CONFIG_INETD=y
|
||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO=y
|
||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD=y
|
||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME=y
|
||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME=y
|
||||
CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN=y
|
||||
CONFIG_FEATURE_INETD_RPC=y
|
||||
CONFIG_IP=y
|
||||
CONFIG_FEATURE_IP_ADDRESS=y
|
||||
CONFIG_FEATURE_IP_LINK=y
|
||||
@@ -570,6 +659,7 @@ CONFIG_FEATURE_IP_ROUTE=y
|
||||
CONFIG_FEATURE_IP_TUNNEL=y
|
||||
CONFIG_FEATURE_IP_RULE=y
|
||||
CONFIG_FEATURE_IP_SHORT_FORMS=y
|
||||
CONFIG_FEATURE_IP_RARE_PROTOCOLS=y
|
||||
CONFIG_IPADDR=y
|
||||
CONFIG_IPLINK=y
|
||||
CONFIG_IPROUTE=y
|
||||
@@ -579,41 +669,56 @@ CONFIG_IPCALC=y
|
||||
CONFIG_FEATURE_IPCALC_FANCY=y
|
||||
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
|
||||
CONFIG_NAMEIF=y
|
||||
CONFIG_FEATURE_NAMEIF_EXTENDED=y
|
||||
CONFIG_NC=y
|
||||
CONFIG_NC_SERVER=y
|
||||
CONFIG_NC_EXTRA=y
|
||||
CONFIG_NETSTAT=y
|
||||
CONFIG_FEATURE_NETSTAT_WIDE=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_SENDMAIL=y
|
||||
CONFIG_FETCHMAIL=y
|
||||
CONFIG_SLATTACH=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
# CONFIG_TELNETD is not set
|
||||
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
|
||||
CONFIG_TELNETD=y
|
||||
CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_TFTPD=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
# CONFIG_DEBUG_TFTP is not set
|
||||
CONFIG_DEBUG_TFTP=y
|
||||
CONFIG_TRACEROUTE=y
|
||||
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
|
||||
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
# CONFIG_APP_UDHCPC is not set
|
||||
# CONFIG_FEATURE_UDHCP_DEBUG is not set
|
||||
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
|
||||
CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
|
||||
CONFIG_APP_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_FEATURE_UDHCP_DEBUG=y
|
||||
CONFIG_FEATURE_RFC3397=y
|
||||
CONFIG_DHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
|
||||
CONFIG_VCONFIG=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_FEATURE_WGET_STATUSBAR=y
|
||||
CONFIG_FEATURE_WGET_AUTHENTICATION=y
|
||||
CONFIG_FEATURE_WGET_LONG_OPTIONS=y
|
||||
CONFIG_ZCIP=y
|
||||
CONFIG_TCPSVD=y
|
||||
CONFIG_UDPSVD=y
|
||||
|
||||
#
|
||||
# Process Utilities
|
||||
@@ -623,26 +728,35 @@ CONFIG_FUSER=y
|
||||
CONFIG_KILL=y
|
||||
CONFIG_KILLALL=y
|
||||
CONFIG_KILLALL5=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_PGREP=y
|
||||
CONFIG_PIDOF=y
|
||||
CONFIG_FEATURE_PIDOF_SINGLE=y
|
||||
CONFIG_FEATURE_PIDOF_OMIT=y
|
||||
CONFIG_PKILL=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_FEATURE_PS_TIME=y
|
||||
CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS=y
|
||||
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_DECIMALS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_UPTIME=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_LASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH is not set
|
||||
# CONFIG_ASH_BASH_COMPAT is not set
|
||||
# CONFIG_ASH_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_READ_NCHARS is not set
|
||||
# CONFIG_ASH_READ_TIMEOUT is not set
|
||||
@@ -657,8 +771,14 @@ CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
# CONFIG_HUSH is not set
|
||||
# CONFIG_LASH is not set
|
||||
CONFIG_HUSH=y
|
||||
CONFIG_HUSH_HELP=y
|
||||
CONFIG_HUSH_INTERACTIVE=y
|
||||
CONFIG_HUSH_JOB=y
|
||||
CONFIG_HUSH_TICK=y
|
||||
CONFIG_HUSH_IF=y
|
||||
CONFIG_HUSH_LOOPS=y
|
||||
CONFIG_LASH=y
|
||||
CONFIG_MSH=y
|
||||
|
||||
#
|
||||
@@ -666,6 +786,8 @@ CONFIG_MSH=y
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_FEATURE_SH_NOFORK=y
|
||||
CONFIG_CTTYHACK=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
@@ -673,6 +795,7 @@ CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_SYSLOGD=y
|
||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||
CONFIG_FEATURE_REMOTE_LOG=y
|
||||
CONFIG_FEATURE_SYSLOGD_DUP=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
|
||||
CONFIG_LOGREAD=y
|
||||
@@ -683,28 +806,38 @@ CONFIG_LOGGER=y
|
||||
#
|
||||
# Runit Utilities
|
||||
#
|
||||
# CONFIG_RUNSV is not set
|
||||
# CONFIG_RUNSVDIR is not set
|
||||
CONFIG_RUNSV=y
|
||||
CONFIG_RUNSVDIR=y
|
||||
CONFIG_SV=y
|
||||
# CONFIG_SVLOGD is not set
|
||||
CONFIG_SVLOGD=y
|
||||
CONFIG_CHPST=y
|
||||
CONFIG_SETUIDGID=y
|
||||
CONFIG_ENVUIDGID=y
|
||||
CONFIG_ENVDIR=y
|
||||
CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_CHCON is not set
|
||||
# CONFIG_FEATURE_CHCON_LONG_OPTIONS is not set
|
||||
# CONFIG_GETENFORCE is not set
|
||||
# CONFIG_GETSEBOOL is not set
|
||||
# CONFIG_LOAD_POLICY is not set
|
||||
# CONFIG_MATCHPATHCON is not set
|
||||
# CONFIG_RUNCON is not set
|
||||
# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
|
||||
# CONFIG_SELINUXENABLED is not set
|
||||
# CONFIG_SETENFORCE is not set
|
||||
|
||||
#
|
||||
# ipsvd utilities
|
||||
# Selinux Utilities
|
||||
#
|
||||
# CONFIG_TCPSVD is not set
|
||||
# CONFIG_UDPSVD is not set
|
||||
CONFIG_CHCON=y
|
||||
CONFIG_FEATURE_CHCON_LONG_OPTIONS=y
|
||||
CONFIG_GETENFORCE=y
|
||||
CONFIG_GETSEBOOL=y
|
||||
CONFIG_LOAD_POLICY=y
|
||||
CONFIG_MATCHPATHCON=y
|
||||
CONFIG_RESTORECON=y
|
||||
CONFIG_RUNCON=y
|
||||
CONFIG_FEATURE_RUNCON_LONG_OPTIONS=y
|
||||
CONFIG_SELINUXENABLED=y
|
||||
CONFIG_SETENFORCE=y
|
||||
CONFIG_SETFILES=y
|
||||
CONFIG_FEATURE_SETFILES_CHECK_OPTION=y
|
||||
CONFIG_SETSEBOOL=y
|
||||
CONFIG_SESTATUS=y
|
||||
|
||||
#
|
||||
# Print Utilities
|
||||
#
|
||||
CONFIG_LPD=y
|
||||
CONFIG_LPR=y
|
||||
CONFIG_LPQ=y
|
||||
+17
-8
@@ -4,22 +4,31 @@
|
||||
#
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
obj-y:=
|
||||
obj-y += applets.o
|
||||
obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage
|
||||
hostprogs-y += usage applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
applets/applet_tables: .config
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
|
||||
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
|
||||
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
|
||||
|
||||
include/applet_tables.h: applets/applet_tables
|
||||
$(call cmd,gen_applet_tables)
|
||||
@@ -0,0 +1,126 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Applet table generator.
|
||||
* Runs on host and produces include/applet_tables.h
|
||||
*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/busybox.h"
|
||||
|
||||
struct bb_applet {
|
||||
const char *name;
|
||||
const char *main;
|
||||
enum bb_install_loc_t install_loc;
|
||||
enum bb_suid_t need_suid;
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
|
||||
unsigned char noexec;
|
||||
/* Even nicer */
|
||||
/* true if instead of fork(); exec("applet"); waitpid();
|
||||
* one can simply call applet_main(argc,argv); */
|
||||
unsigned char nofork;
|
||||
};
|
||||
|
||||
/* Define struct bb_applet applets[] */
|
||||
#include "../include/applets.h"
|
||||
|
||||
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
|
||||
|
||||
static int offset[NUM_APPLETS];
|
||||
|
||||
static int cmp_name(const void *a, const void *b)
|
||||
{
|
||||
const struct bb_applet *aa = a;
|
||||
const struct bb_applet *bb = b;
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int ofs;
|
||||
unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
offset[i] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
/* We reuse 4 high-order bits of offset array for other purposes,
|
||||
* so if they are indeed needed, refuse to proceed */
|
||||
if (ofs > 0xfff)
|
||||
return 1;
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
dup2(i, 1);
|
||||
|
||||
/* Keep in sync with include/busybox.h! */
|
||||
|
||||
puts("/* This is a generated file, don't edit */\n");
|
||||
|
||||
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
|
||||
if (NUM_APPLETS == 1) {
|
||||
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
|
||||
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
|
||||
}
|
||||
|
||||
puts("\nconst char applet_names[] ALIGN1 = \"\"");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
}
|
||||
puts(";");
|
||||
|
||||
puts("\nint (*const applet_main[])(int argc, char **argv) = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("%s_main,\n", applets[i].main);
|
||||
}
|
||||
puts("};");
|
||||
|
||||
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
+ (applets[i].nofork << 12)
|
||||
+ (applets[i].noexec << 13)
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SUID
|
||||
+ (applets[i].need_suid << 14) /* 2 bits */
|
||||
#endif
|
||||
);
|
||||
}
|
||||
puts("};");
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].install_loc; /* 3 bits */
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].install_loc << 4; /* 3 bits */
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
puts("};\n");
|
||||
#endif
|
||||
|
||||
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+8
-659
@@ -1,669 +1,18 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Utility routines.
|
||||
* Stub for linking busybox binary against libbusybox.
|
||||
*
|
||||
* Copyright (C) tons of folks. Tracking down who wrote what
|
||||
* isn't something I'm going to worry about... If you wrote something
|
||||
* here, please feel free to acknowledge your work.
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
||||
* Permission has been granted to redistribute this code under the GPL.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
* Licensed under GPLv2, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
|
||||
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
#warning Static linking against glibc produces buggy executables
|
||||
#warning (glibc does not cope well with ld --gc-sections).
|
||||
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
|
||||
#warning Note that glibc is unsuitable for static linking anyway.
|
||||
#warning If you still want to do it, remove -Wl,--gc-sections
|
||||
#warning from top-level Makefile and remove this warning.
|
||||
#error Aborting compilation.
|
||||
#if ENABLE_BUILD_LIBBUSYBOX
|
||||
int main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
return lbb_main(argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Declare <applet>_main() */
|
||||
#define PROTOTYPES
|
||||
#include "applets.h"
|
||||
#undef PROTOTYPES
|
||||
|
||||
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
|
||||
/* Define usage_messages[] */
|
||||
static const char usage_messages[] ALIGN1 = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
;
|
||||
#undef MAKE_USAGE
|
||||
#else
|
||||
#define usage_messages 0
|
||||
#endif /* SHOW_USAGE */
|
||||
|
||||
/* Define struct bb_applet applets[] */
|
||||
#include "applets.h"
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry. */
|
||||
|
||||
#if ENABLE_FEATURE_SH_STANDALONE
|
||||
const unsigned short NUM_APPLETS = ARRAY_SIZE(applets);
|
||||
#endif
|
||||
const struct bb_applet *current_applet;
|
||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||
#if !BB_MMU
|
||||
bool re_execed;
|
||||
#endif
|
||||
|
||||
USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
|
||||
|
||||
#if ENABLE_FEATURE_SUID_CONFIG
|
||||
|
||||
/* applets[] is const, so we have to define this "override" structure */
|
||||
static struct BB_suid_config {
|
||||
const struct bb_applet *m_applet;
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
struct BB_suid_config *m_next;
|
||||
} *suid_config;
|
||||
|
||||
static bool suid_cfg_readable;
|
||||
|
||||
/* check if u is member of group g */
|
||||
static int ingroup(uid_t u, gid_t g)
|
||||
{
|
||||
struct group *grp = getgrgid(g);
|
||||
|
||||
if (grp) {
|
||||
char **mem;
|
||||
|
||||
for (mem = grp->gr_mem; *mem; mem++) {
|
||||
struct passwd *pwd = getpwnam(*mem);
|
||||
|
||||
if (pwd && (pwd->pw_uid == u))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This should probably be a libbb routine. In that case,
|
||||
* I'd probably rename it to something like bb_trimmed_slice.
|
||||
*/
|
||||
static char *get_trimmed_slice(char *s, char *e)
|
||||
{
|
||||
/* First, consider the value at e to be nul and back up until we
|
||||
* reach a non-space char. Set the char after that (possibly at
|
||||
* the original e) to nul. */
|
||||
while (e-- > s) {
|
||||
if (!isspace(*e)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
e[1] = '\0';
|
||||
|
||||
/* Next, advance past all leading space and return a ptr to the
|
||||
* first non-space char; possibly the terminating nul. */
|
||||
return skip_whitespace(s);
|
||||
}
|
||||
|
||||
/* Don't depend on the tools to combine strings. */
|
||||
static const char config_file[] ALIGN1 = "/etc/busybox.conf";
|
||||
|
||||
/* We don't supply a value for the nul, so an index adjustment is
|
||||
* necessary below. Also, we use unsigned short here to save some
|
||||
* space even though these are really mode_t values. */
|
||||
static const unsigned short mode_mask[] ALIGN2 = {
|
||||
/* SST sst xxx --- */
|
||||
S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */
|
||||
S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */
|
||||
0, S_IXOTH, S_IXOTH, 0 /* other */
|
||||
};
|
||||
|
||||
#define parse_error(x) do { errmsg = x; goto pe_label; } while (0)
|
||||
|
||||
static void parse_config_file(void)
|
||||
{
|
||||
struct BB_suid_config *sct_head;
|
||||
struct BB_suid_config *sct;
|
||||
const struct bb_applet *applet;
|
||||
FILE *f;
|
||||
const char *errmsg;
|
||||
char *s;
|
||||
char *e;
|
||||
int i;
|
||||
unsigned lc;
|
||||
smallint section;
|
||||
char buffer[256];
|
||||
struct stat st;
|
||||
|
||||
assert(!suid_config); /* Should be set to NULL by bss init. */
|
||||
|
||||
ruid = getuid();
|
||||
if (ruid == 0) /* run by root - don't need to even read config file */
|
||||
return;
|
||||
|
||||
if ((stat(config_file, &st) != 0) /* No config file? */
|
||||
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|
||||
|| (st.st_uid != 0) /* Not owned by root? */
|
||||
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|
||||
|| !(f = fopen(config_file, "r")) /* Cannot open? */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
suid_cfg_readable = 1;
|
||||
sct_head = NULL;
|
||||
section = lc = 0;
|
||||
|
||||
while (1) {
|
||||
s = buffer;
|
||||
|
||||
if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */
|
||||
if (ferror(f)) { /* Make sure it wasn't a read error. */
|
||||
parse_error("reading");
|
||||
}
|
||||
fclose(f);
|
||||
suid_config = sct_head; /* Success, so set the pointer. */
|
||||
return;
|
||||
}
|
||||
|
||||
lc++; /* Got a (partial) line. */
|
||||
|
||||
/* If a line is too long for our buffer, we consider it an error.
|
||||
* The following test does mistreat one corner case though.
|
||||
* If the final line of the file does not end with a newline and
|
||||
* yet exactly fills the buffer, it will be treated as too long
|
||||
* even though there isn't really a problem. But it isn't really
|
||||
* worth adding code to deal with such an unlikely situation, and
|
||||
* we do err on the side of caution. Besides, the line would be
|
||||
* too long if it did end with a newline. */
|
||||
if (!strchr(s, '\n') && !feof(f)) {
|
||||
parse_error("line too long");
|
||||
}
|
||||
|
||||
/* Trim leading and trailing whitespace, ignoring comments, and
|
||||
* check if the resulting string is empty. */
|
||||
s = get_trimmed_slice(s, strchrnul(s, '#'));
|
||||
if (!*s) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for a section header. */
|
||||
|
||||
if (*s == '[') {
|
||||
/* Unlike the old code, we ignore leading and trailing
|
||||
* whitespace for the section name. We also require that
|
||||
* there are no stray characters after the closing bracket. */
|
||||
e = strchr(s, ']');
|
||||
if (!e /* Missing right bracket? */
|
||||
|| e[1] /* Trailing characters? */
|
||||
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
|
||||
) {
|
||||
parse_error("section header");
|
||||
}
|
||||
/* Right now we only have one section so just check it.
|
||||
* If more sections are added in the future, please don't
|
||||
* resort to cascading ifs with multiple strcasecmp calls.
|
||||
* That kind of bloated code is all too common. A loop
|
||||
* and a string table would be a better choice unless the
|
||||
* number of sections is very small. */
|
||||
if (strcasecmp(s, "SUID") == 0) {
|
||||
section = 1;
|
||||
continue;
|
||||
}
|
||||
section = -1; /* Unknown section so set to skip. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process sections. */
|
||||
|
||||
if (section == 1) { /* SUID */
|
||||
/* Since we trimmed leading and trailing space above, we're
|
||||
* now looking for strings of the form
|
||||
* <key>[::space::]*=[::space::]*<value>
|
||||
* where both key and value could contain inner whitespace. */
|
||||
|
||||
/* First get the key (an applet name in our case). */
|
||||
e = strchr(s, '=');
|
||||
if (e) {
|
||||
s = get_trimmed_slice(s, e);
|
||||
}
|
||||
if (!e || !*s) { /* Missing '=' or empty key. */
|
||||
parse_error("keyword");
|
||||
}
|
||||
|
||||
/* Ok, we have an applet name. Process the rhs if this
|
||||
* applet is currently built in and ignore it otherwise.
|
||||
* Note: this can hide config file bugs which only pop
|
||||
* up when the busybox configuration is changed. */
|
||||
applet = find_applet_by_name(s);
|
||||
if (applet) {
|
||||
/* Note: We currently don't check for duplicates!
|
||||
* The last config line for each applet will be the
|
||||
* one used since we insert at the head of the list.
|
||||
* I suppose this could be considered a feature. */
|
||||
sct = xmalloc(sizeof(struct BB_suid_config));
|
||||
sct->m_applet = applet;
|
||||
sct->m_mode = 0;
|
||||
sct->m_next = sct_head;
|
||||
sct_head = sct;
|
||||
|
||||
/* Get the specified mode. */
|
||||
|
||||
e = skip_whitespace(e+1);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
/* There are 4 chars + 1 nul for each of user/group/other. */
|
||||
static const char mode_chars[] ALIGN1 = "Ssx-\0" "Ssx-\0" "Ttx-";
|
||||
|
||||
const char *q;
|
||||
q = strchrnul(mode_chars + 5*i, *e++);
|
||||
if (!*q) {
|
||||
parse_error("mode");
|
||||
}
|
||||
/* Adjust by -i to account for nul. */
|
||||
sct->m_mode |= mode_mask[(q - mode_chars) - i];
|
||||
}
|
||||
|
||||
/* Now get the the user/group info. */
|
||||
|
||||
s = skip_whitespace(e);
|
||||
|
||||
/* Note: we require whitespace between the mode and the
|
||||
* user/group info. */
|
||||
if ((s == e) || !(e = strchr(s, '.'))) {
|
||||
parse_error("<uid>.<gid>");
|
||||
}
|
||||
*e++ = '\0';
|
||||
|
||||
/* We can't use get_ug_id here since it would exit()
|
||||
* if a uid or gid was not found. Oh well... */
|
||||
sct->m_uid = bb_strtoul(s, NULL, 10);
|
||||
if (errno) {
|
||||
struct passwd *pwd = getpwnam(s);
|
||||
if (!pwd) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
}
|
||||
|
||||
sct->m_gid = bb_strtoul(e, NULL, 10);
|
||||
if (errno) {
|
||||
struct group *grp;
|
||||
grp = getgrnam(e);
|
||||
if (!grp) {
|
||||
parse_error("group");
|
||||
}
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Unknown sections are ignored. */
|
||||
|
||||
/* Encountering configuration lines prior to seeing a
|
||||
* section header is treated as an error. This is how
|
||||
* the old code worked, but it may not be desirable.
|
||||
* We may want to simply ignore such lines in case they
|
||||
* are used in some future version of busybox. */
|
||||
if (!section) {
|
||||
parse_error("keyword outside section");
|
||||
}
|
||||
|
||||
} /* while (1) */
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, errmsg);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
while (sct_head) {
|
||||
sct = sct_head->m_next;
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void parse_config_file(void)
|
||||
{
|
||||
USE_FEATURE_SUID(ruid = getuid();)
|
||||
}
|
||||
#endif /* FEATURE_SUID_CONFIG */
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
static void check_suid(const struct bb_applet *applet)
|
||||
{
|
||||
gid_t rgid; /* real gid */
|
||||
|
||||
if (ruid == 0) /* set by parse_config_file() */
|
||||
return; /* run by root - no need to check more */
|
||||
rgid = getgid();
|
||||
|
||||
#if ENABLE_FEATURE_SUID_CONFIG
|
||||
if (suid_cfg_readable) {
|
||||
uid_t uid;
|
||||
struct BB_suid_config *sct;
|
||||
mode_t m;
|
||||
|
||||
for (sct = suid_config; sct; sct = sct->m_next) {
|
||||
if (sct->m_applet == applet)
|
||||
goto found;
|
||||
}
|
||||
/* default: drop all privileges */
|
||||
xsetgid(rgid);
|
||||
xsetuid(ruid);
|
||||
return;
|
||||
found:
|
||||
m = sct->m_mode;
|
||||
if (sct->m_uid == ruid)
|
||||
/* same uid */
|
||||
m >>= 6;
|
||||
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
|
||||
/* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!(m & S_IXOTH)) /* is x bit not set ? */
|
||||
bb_error_msg_and_die("you have no permission to run this applet!");
|
||||
|
||||
/* _both_ sgid and group_exec have to be set for setegid */
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
|
||||
rgid = sct->m_gid;
|
||||
/* else (no setegid) we will set egid = rgid */
|
||||
|
||||
/* We set effective AND saved ids. If saved-id is not set
|
||||
* like we do below, seteiud(0) can still later succeed! */
|
||||
if (setresgid(-1, rgid, rgid))
|
||||
bb_perror_msg_and_die("setresgid");
|
||||
|
||||
/* do we have to set effective uid? */
|
||||
uid = ruid;
|
||||
if (sct->m_mode & S_ISUID)
|
||||
uid = sct->m_uid;
|
||||
/* else (no seteuid) we will set euid = ruid */
|
||||
|
||||
if (setresuid(-1, uid, uid))
|
||||
bb_perror_msg_and_die("setresuid");
|
||||
return;
|
||||
}
|
||||
#if !ENABLE_FEATURE_SUID_CONFIG_QUIET
|
||||
{
|
||||
static bool onetime = 0;
|
||||
|
||||
if (!onetime) {
|
||||
onetime = 1;
|
||||
fprintf(stderr, "Using fallback suid method\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (applet->need_suid == _BB_SUID_ALWAYS) {
|
||||
/* Real uid is not 0. If euid isn't 0 too, suid bit
|
||||
* is most probably not set on our executable */
|
||||
if (geteuid())
|
||||
bb_error_msg_and_die("applet requires root privileges!");
|
||||
} else if (applet->need_suid == _BB_SUID_NEVER) {
|
||||
xsetgid(rgid); /* drop all privileges */
|
||||
xsetuid(ruid);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define check_suid(x) ((void)0)
|
||||
#endif /* FEATURE_SUID */
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_COMPRESS_USAGE
|
||||
|
||||
#include "usage_compressed.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static const char *unpack_usage_messages(void)
|
||||
{
|
||||
char *outbuf = NULL;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
|
||||
i = start_bunzip(&bd,
|
||||
/* src_fd: */ -1,
|
||||
/* inbuf: */ packed_usage,
|
||||
/* len: */ sizeof(packed_usage));
|
||||
/* read_bunzip can longjmp to start_bunzip, and ultimately
|
||||
* end up here with i != 0 on read data errors! Not trivial */
|
||||
if (!i) {
|
||||
/* Cannot use xmalloc: will leak bd in NOFORK case! */
|
||||
outbuf = malloc_or_warn(SIZEOF_usage_messages);
|
||||
if (outbuf)
|
||||
read_bunzip(bd, outbuf, SIZEOF_usage_messages);
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
return outbuf;
|
||||
}
|
||||
#define dealloc_usage_messages(s) free(s)
|
||||
|
||||
#else
|
||||
|
||||
#define unpack_usage_messages() usage_messages
|
||||
#define dealloc_usage_messages(s) ((void)(s))
|
||||
|
||||
#endif /* FEATURE_COMPRESS_USAGE */
|
||||
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
if (ENABLE_SHOW_USAGE) {
|
||||
const char *format_string;
|
||||
const char *p;
|
||||
const char *usage_string = p = unpack_usage_messages();
|
||||
int i;
|
||||
|
||||
i = current_applet - applets;
|
||||
while (i) {
|
||||
while (*p++) continue;
|
||||
i--;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s multi-call binary\n", bb_banner);
|
||||
format_string = "\nUsage: %s %s\n\n";
|
||||
if (*p == '\b')
|
||||
format_string = "\nNo help available.\n\n";
|
||||
fprintf(stderr, format_string, applet_name, p);
|
||||
dealloc_usage_messages((char*)usage_string);
|
||||
}
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
|
||||
static int applet_name_compare(const void *name, const void *vapplet)
|
||||
{
|
||||
const struct bb_applet *applet = vapplet;
|
||||
|
||||
return strcmp(name, applet->name);
|
||||
}
|
||||
|
||||
const struct bb_applet *find_applet_by_name(const char *name)
|
||||
{
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
|
||||
applet_name_compare);
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
/* directory table
|
||||
* this should be consistent w/ the enum,
|
||||
* busybox.h::bb_install_loc_t, or else... */
|
||||
static const char usr_bin [] ALIGN1 = "/usr/bin";
|
||||
static const char usr_sbin[] ALIGN1 = "/usr/sbin";
|
||||
static const char *const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
int (*lf)(const char *, const char *) = link;
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
lf = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].install_loc],
|
||||
applets[i].name);
|
||||
rc = lf(busybox, fpc);
|
||||
if (rc != 0 && errno != EEXIST) {
|
||||
bb_perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define install_links(x,y) ((void)0)
|
||||
#endif /* FEATURE_INSTALLER */
|
||||
|
||||
|
||||
/* If we were called as "busybox..." */
|
||||
static int busybox_main(char **argv)
|
||||
{
|
||||
if (!argv[1]) {
|
||||
/* Called without arguments */
|
||||
const struct bb_applet *a;
|
||||
int col, output_width;
|
||||
help:
|
||||
output_width = 80;
|
||||
if (ENABLE_FEATURE_AUTOWIDTH) {
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
}
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
|
||||
printf("%s multi-call binary\n", bb_banner); /* reuse const string... */
|
||||
printf("Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
"Licensed under GPLv2. See source distribution for full notice.\n"
|
||||
"\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n"
|
||||
"\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n");
|
||||
col = 0;
|
||||
a = applets;
|
||||
while (a->name) {
|
||||
if (col > output_width) {
|
||||
puts(",");
|
||||
col = 0;
|
||||
}
|
||||
col += printf("%s%s", (col ? ", " : "\t"), a->name);
|
||||
a++;
|
||||
}
|
||||
puts("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
|
||||
const char *busybox;
|
||||
busybox = xmalloc_readlink_or_warn(bb_busybox_exec_path);
|
||||
if (!busybox)
|
||||
busybox = bb_busybox_exec_path;
|
||||
/* -s makes symlinks */
|
||||
install_links(busybox,
|
||||
argv[2] && strcmp(argv[2], "-s") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
/* "busybox --help [<applet>]" */
|
||||
if (!argv[2])
|
||||
goto help;
|
||||
/* convert to "<applet> --help" */
|
||||
argv[0] = argv[2];
|
||||
argv[2] = NULL;
|
||||
} else {
|
||||
/* "busybox <applet> arg1 arg2 ..." */
|
||||
argv++;
|
||||
}
|
||||
/* we want "<argv[0]>: applet not found", not "busybox: ..." */
|
||||
applet_name = argv[0];
|
||||
run_applet_and_exit(argv[0], argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
void run_current_applet_and_exit(char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
|
||||
while (argv[argc])
|
||||
argc++;
|
||||
|
||||
/* Reinit some shared global data */
|
||||
optind = 1;
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
|
||||
applet_name = current_applet->name;
|
||||
if (argc == 2 && !strcmp(argv[1], "--help"))
|
||||
bb_show_usage();
|
||||
if (ENABLE_FEATURE_SUID)
|
||||
check_suid(current_applet);
|
||||
exit(current_applet->main(argc, argv));
|
||||
}
|
||||
|
||||
void run_applet_and_exit(const char *name, char **argv)
|
||||
{
|
||||
current_applet = find_applet_by_name(name);
|
||||
if (current_applet)
|
||||
run_current_applet_and_exit(argv);
|
||||
if (!strncmp(name, "busybox", 7))
|
||||
exit(busybox_main(argv));
|
||||
}
|
||||
|
||||
|
||||
#ifdef __GLIBC__
|
||||
/* Make it reside in R/W memory: */
|
||||
int *const bb_errno __attribute__ ((section (".data")));
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
(*(int **)&bb_errno) = __errno_location();
|
||||
#endif
|
||||
|
||||
#if !BB_MMU
|
||||
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
||||
if (argv[0][0] & 0x80) {
|
||||
re_execed = 1;
|
||||
argv[0][0] &= 0x7f;
|
||||
}
|
||||
#endif
|
||||
applet_name = argv[0];
|
||||
if (applet_name[0] == '-')
|
||||
applet_name++;
|
||||
applet_name = bb_basename(applet_name);
|
||||
|
||||
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
|
||||
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
run_applet_and_exit(applet_name, argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
@@ -14,13 +14,11 @@ const char *applet_name;
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
applet_name = argv[0];
|
||||
|
||||
return APPLET_main(argc,argv);
|
||||
}
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
printf(APPLET_full_usage "\n");
|
||||
|
||||
exit(1);
|
||||
fputs(APPLET_full_usage "\n", stdout);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
+50
-34
@@ -5,19 +5,23 @@ export LC_CTYPE=POSIX
|
||||
|
||||
prefix=${1}
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks]"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
exit 1;
|
||||
fi
|
||||
h=`sort busybox.links | uniq`
|
||||
scriptwrapper="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
"") h="";;
|
||||
*) echo "Unknown install option: $2"; exit 1;;
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
"") h="";;
|
||||
*) echo "Unknown install option: $2"; exit 1;;
|
||||
esac
|
||||
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
@@ -33,7 +37,7 @@ 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
|
||||
cp -a $i $prefix/$libdir/ || exit 1
|
||||
cp -pPR $i $prefix/$libdir/ || exit 1
|
||||
chmod 0644 $prefix/$libdir/$i || exit 1
|
||||
fi
|
||||
done
|
||||
@@ -52,6 +56,7 @@ if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
cd "$pd"
|
||||
done
|
||||
`
|
||||
exit 0
|
||||
fi
|
||||
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
@@ -61,33 +66,44 @@ install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
for i in $h; do
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
ln $linkopts busybox $prefix$i || exit 1
|
||||
else
|
||||
rm -f $prefix$i
|
||||
echo "#!/bin/busybox" > $prefix$i
|
||||
chmod +x $prefix/$i
|
||||
fi
|
||||
echo " $prefix$i"
|
||||
else
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
else
|
||||
echo " $prefix$i already exists"
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
else
|
||||
echo " $prefix$i already exists"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
+12
-1
@@ -5,6 +5,17 @@
|
||||
* object directory */
|
||||
#include "../include/autoconf.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
#define BB_MMU 0
|
||||
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
#define USE_FOR_MMU(...)
|
||||
#else
|
||||
#define BB_MMU 1
|
||||
#define USE_FOR_NOMMU(...)
|
||||
#define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
@@ -13,6 +24,6 @@ static const char usage_messages[] = ""
|
||||
|
||||
int main(void)
|
||||
{
|
||||
write(1, usage_messages, sizeof(usage_messages));
|
||||
write(STDOUT_FILENO, usage_messages, sizeof(usage_messages));
|
||||
return 0;
|
||||
}
|
||||
@@ -12,8 +12,23 @@ sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
exec >"$target"
|
||||
|
||||
echo 'static const char packed_usage[] ALIGN1 = '
|
||||
echo 'static const char packed_usage[] ALIGN1 = {'
|
||||
|
||||
## Breaks on big-endian systems!
|
||||
## # Extra effort to avoid using "od -t x1": -t is not available
|
||||
## # in non-CONFIG_DESKTOPed busybox od
|
||||
##
|
||||
## "$loc/usage" | bzip2 -1 | od -v -x \
|
||||
## | $SED -e 's/^[^ ]*//' \
|
||||
## | $SED -e 's/ //g' \
|
||||
## | grep -v '^$' \
|
||||
## | $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
|
||||
"$loc/usage" | bzip2 -1 | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' -e 's/ *\(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
|
||||
echo ';'
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
| $SED -e 's/ //g' \
|
||||
| grep -v '^$' \
|
||||
| $SED -e 's/\(..\)/0x\1,/g'
|
||||
|
||||
echo '};'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
+60
-32
@@ -29,7 +29,7 @@ config AR
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Enable support for long filenames (not need for debs)"
|
||||
bool "Support for long filenames (not need for debs)"
|
||||
default n
|
||||
depends on AR
|
||||
help
|
||||
@@ -48,12 +48,22 @@ config BUNZIP2
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
The BusyBox bunzip2 applet is limited to de-compression only.
|
||||
On an x86 system, this applet adds about 11K.
|
||||
|
||||
Unless you have a specific application which requires bunzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config BZIP2
|
||||
bool "bzip2"
|
||||
default n
|
||||
help
|
||||
bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
sorting text compression algorithm, and Huffman coding. Compression
|
||||
is generally considerably better than that achieved by more
|
||||
conventional LZ77/LZ78-based compressors, and approaches the
|
||||
performance of the PPM family of statistical compressors.
|
||||
|
||||
Unless you have a specific application which requires bzip2, you
|
||||
should probably say N here.
|
||||
|
||||
config CPIO
|
||||
bool "cpio"
|
||||
default n
|
||||
@@ -68,6 +78,14 @@ config CPIO
|
||||
Unless you have a specific application which requires cpio, you should
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_CPIO_O
|
||||
bool "Support for archive creation"
|
||||
default n
|
||||
depends on CPIO
|
||||
help
|
||||
This implementation of cpio can create cpio archives in the "newc"
|
||||
format only.
|
||||
|
||||
config DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
@@ -89,7 +107,7 @@ config DPKG_DEB
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_DPKG_DEB_EXTRACT_ONLY
|
||||
bool "extract only (-x)"
|
||||
bool "Extract only (-x)"
|
||||
default n
|
||||
depends on DPKG_DEB
|
||||
help
|
||||
@@ -156,6 +174,14 @@ config FEATURE_TAR_CREATE
|
||||
If you enable this option you'll be able to create
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config FEATURE_TAR_GZIP
|
||||
bool "Enable -z option"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call gzip,
|
||||
when creating or extracting tar gziped archives.
|
||||
|
||||
config FEATURE_TAR_BZIP2
|
||||
bool "Enable -j option to handle .tar.bz2 files"
|
||||
default n
|
||||
@@ -172,22 +198,6 @@ config FEATURE_TAR_LZMA
|
||||
If you enable this option you'll be able to extract
|
||||
archives compressed with lzma.
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config FEATURE_TAR_GZIP
|
||||
bool "Enable -z option"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option tar will be able to call gzip,
|
||||
when creating or extracting tar gziped archives.
|
||||
|
||||
config FEATURE_TAR_COMPRESS
|
||||
bool "Enable -Z option"
|
||||
default n
|
||||
@@ -196,8 +206,24 @@ config FEATURE_TAR_COMPRESS
|
||||
If you enable this option tar will be able to call uncompress,
|
||||
when extracting .tar.Z archives.
|
||||
|
||||
config FEATURE_TAR_AUTODETECT
|
||||
bool "Let tar autodetect gz/bz2 compresses tarballs"
|
||||
default n
|
||||
depends on FEATURE_TAR_GZIP || FEATURE_TAR_BZIP2
|
||||
help
|
||||
With this option tar can automatically detect gzip/bzip2 compressed
|
||||
tarballs. Currently it works only on seekable streams.
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
If you enable this option you'll be able to specify
|
||||
a list of files to include or exclude from an archive.
|
||||
|
||||
config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
bool "Enable support for old tar header format"
|
||||
bool "Support for old tar header format"
|
||||
default N
|
||||
depends on TAR
|
||||
help
|
||||
@@ -215,7 +241,7 @@ config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
It is said to be fixed in newer Sun tar, but "old" tarballs still exist.
|
||||
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Enable support for some GNU tar extensions"
|
||||
bool "Support for GNU tar extensions (long filenames)"
|
||||
default y
|
||||
depends on TAR
|
||||
help
|
||||
@@ -227,7 +253,16 @@ config FEATURE_TAR_LONG_OPTIONS
|
||||
default n
|
||||
depends on TAR && GETOPT_LONG
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
config FEATURE_TAR_UNAME_GNAME
|
||||
bool "Enable use of user and group names"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
Enables use of user and group names in tar. This affects contents
|
||||
listings (-t) and preserving permissions when unpacking (-p).
|
||||
+200 bytes.
|
||||
|
||||
config UNCOMPRESS
|
||||
bool "uncompress"
|
||||
@@ -252,7 +287,7 @@ config UNLZMA
|
||||
should probably say N here.
|
||||
|
||||
config FEATURE_LZMA_FAST
|
||||
bool "Optimze unlzma for speed"
|
||||
bool "Optimize unlzma for speed"
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
@@ -272,13 +307,6 @@ config UNZIP
|
||||
comment "Common options for cpio and tar"
|
||||
depends on CPIO || TAR
|
||||
|
||||
config FEATURE_UNARCHIVE_TAPE
|
||||
bool "Enable tape drive support"
|
||||
default n
|
||||
depends on CPIO || TAR
|
||||
help
|
||||
I don't think this is needed anymore.
|
||||
|
||||
comment "Common options for dpkg and dpkg_deb"
|
||||
depends on DPKG || DPKG_DEB
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ libs-y += libunarchive/
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
lib-$(CONFIG_DPKG) += dpkg.o
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@iinet.net.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
@@ -38,7 +37,7 @@ static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv);
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
static const char msg_unsupported_err[] ALIGN1 =
|
||||
|
||||
+30
-17
@@ -11,7 +11,7 @@
|
||||
enum {
|
||||
OPT_STDOUT = 0x1,
|
||||
OPT_FORCE = 0x2,
|
||||
/* gunzip only: */
|
||||
/* gunzip and bunzip2 only: */
|
||||
OPT_VERBOSE = 0x4,
|
||||
OPT_DECOMPRESS = 0x8,
|
||||
OPT_TEST = 0x10,
|
||||
@@ -49,7 +49,7 @@ int bbunpack(char **argv,
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
bb_simple_perror_msg(filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
@@ -74,7 +74,7 @@ int bbunpack(char **argv,
|
||||
goto err;
|
||||
}
|
||||
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
|
||||
/* GNU gunzip goes not bail out, but goes to next file */
|
||||
/* GNU gunzip does not bail out, but goes to next file */
|
||||
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
stat_buf.st_mode))
|
||||
goto err;
|
||||
@@ -138,7 +138,7 @@ char* make_new_name_generic(char *filename, const char *expected_ext)
|
||||
|
||||
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Modified for busybox by Glenn McGrath
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
@@ -158,10 +158,10 @@ USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int bunzip2_main(int argc, char **argv);
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
@@ -185,7 +185,7 @@ int bunzip2_main(int argc, char **argv)
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
* busybox functions by Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
@@ -241,7 +241,6 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
check_header_gzip_or_die(STDIN_FILENO);
|
||||
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
@@ -257,10 +256,24 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
int gunzip_main(int argc, char **argv);
|
||||
int gunzip_main(int argc, char **argv)
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
* -n --no-name
|
||||
* gzip: do not save the original file name and time stamp.
|
||||
* (The original name is always saved if the name had to be truncated.)
|
||||
* gunzip: do not restore the original file name/time even if present
|
||||
* (remove only the gzip suffix from the compressed file name).
|
||||
* This option is the default when decompressing.
|
||||
* -N --name
|
||||
* gzip: always save the original file name and time stamp (this is the default)
|
||||
* gunzip: restore the original file name and time stamp if present.
|
||||
*/
|
||||
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
getopt32(argv, "cfvdtn");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
@@ -295,10 +308,10 @@ USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int unlzma_main(int argc, char **argv);
|
||||
int unlzma_main(int argc, char **argv)
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "c");
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
/* lzmacat? */
|
||||
if (applet_name[4] == 'c')
|
||||
@@ -337,8 +350,8 @@ USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
return status;
|
||||
}
|
||||
|
||||
int uncompress_main(int argc, char **argv);
|
||||
int uncompress_main(int argc, char **argv)
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/bin/sh
|
||||
# Test that concatenated gz files are unpacking correctly.
|
||||
# It also tests that unpacking in general is working right.
|
||||
# Since zip code has many corner cases, run it for a few hours
|
||||
# to get a decent coverage (200000 tests or more).
|
||||
|
||||
gzip="gzip"
|
||||
gunzip="../busybox gunzip"
|
||||
# Or the other way around:
|
||||
#gzip="../busybox gzip"
|
||||
#gunzip="gunzip"
|
||||
|
||||
c=0
|
||||
i=$PID
|
||||
while true; do
|
||||
c=$((c+1))
|
||||
|
||||
# RANDOM is not very random on some shells. Spice it up.
|
||||
# 100003 is prime
|
||||
len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
i=$((i * 1664525 + 1013904223))
|
||||
len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len1 count=1 >z1 2>/dev/null
|
||||
cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len2 count=1 >z2 2>/dev/null
|
||||
|
||||
$gzip <z1 >zz.gz
|
||||
$gzip <z2 >>zz.gz
|
||||
$gunzip -c zz.gz >z9 || {
|
||||
echo "Exitcode $?"
|
||||
exit
|
||||
}
|
||||
sum=`cat z1 z2 | md5sum`
|
||||
sum9=`md5sum <z9`
|
||||
test "$sum" == "$sum9" || {
|
||||
echo "md5sums don't match"
|
||||
exit
|
||||
}
|
||||
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum"
|
||||
|
||||
sum=`cat z1 z2 z1 z2 | md5sum`
|
||||
rm z1.gz z2.gz 2>/dev/null
|
||||
$gzip z1
|
||||
$gzip z2
|
||||
cat z1.gz z2.gz z1.gz z2.gz >zz.gz
|
||||
$gunzip -c zz.gz >z9 || {
|
||||
echo "Exitcode $? (2)"
|
||||
exit
|
||||
}
|
||||
sum9=`md5sum <z9`
|
||||
test "$sum" == "$sum9" || {
|
||||
echo "md5sums don't match (1)"
|
||||
exit
|
||||
}
|
||||
|
||||
echo "Test $c ok: len1=$len1 len2=$len2 sum=$sum (2)"
|
||||
done
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# Leak test for gunzip. Watch top for growing process size.
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
|
||||
cat /dev/urandom \
|
||||
| while true; do read junk; echo "junk $RANDOM $junk"; done \
|
||||
| ../busybox gzip \
|
||||
| ../busybox gunzip -c >/dev/null
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Leak test for gunzip. Watch top for growing process size.
|
||||
# In this case we look for leaks in "concatenated .gz" code -
|
||||
# we feed gunzip with a stream of .gz files.
|
||||
|
||||
i=$PID
|
||||
c=0
|
||||
while true; do
|
||||
c=$((c + 1))
|
||||
echo "Block# $c" >&2
|
||||
# RANDOM is not very random on some shells. Spice it up.
|
||||
i=$((i * 1664525 + 1013904223))
|
||||
# 100003 is prime
|
||||
len=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 ))
|
||||
|
||||
# Just using urandom will make gzip use method 0 (store) -
|
||||
# not good for test coverage!
|
||||
cat /dev/urandom \
|
||||
| while true; do read junk; echo "junk $c $i $junk"; done \
|
||||
| dd bs=$len count=1 2>/dev/null \
|
||||
| gzip >xxx.gz
|
||||
cat xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz
|
||||
done | ../busybox gunzip -c >/dev/null
|
||||
@@ -0,0 +1,44 @@
|
||||
bzip2 applet in busybox is based on lightly-modified source
|
||||
of bzip2 version 1.0.4. bzip2 source is distributed
|
||||
under the following conditions (copied verbatim from LICENSE file)
|
||||
===========================================================
|
||||
|
||||
|
||||
This program, "bzip2", the associated library "libbzip2", and all
|
||||
documentation, are copyright (C) 1996-2006 Julian R Seward. All
|
||||
rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
|
||||
3. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
|
||||
4. The name of the author may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Julian Seward, Cambridge, UK.
|
||||
jseward@bzip.org
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
@@ -0,0 +1,90 @@
|
||||
This file is an abridged version of README from bizp2 1.0.4
|
||||
Build instructions (which are not relevant to busyboxed bzip2)
|
||||
are removed.
|
||||
===========================================================
|
||||
|
||||
|
||||
This is the README for bzip2/libzip2.
|
||||
This version is fully compatible with the previous public releases.
|
||||
|
||||
------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------
|
||||
|
||||
Please read and be aware of the following:
|
||||
|
||||
|
||||
WARNING:
|
||||
|
||||
This program and library (attempts to) compress data by
|
||||
performing several non-trivial transformations on it.
|
||||
Unless you are 100% familiar with *all* the algorithms
|
||||
contained herein, and with the consequences of modifying them,
|
||||
you should NOT meddle with the compression or decompression
|
||||
machinery. Incorrect changes can and very likely *will*
|
||||
lead to disastrous loss of data.
|
||||
|
||||
|
||||
DISCLAIMER:
|
||||
|
||||
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
|
||||
USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
|
||||
|
||||
Every compression of a file implies an assumption that the
|
||||
compressed file can be decompressed to reproduce the original.
|
||||
Great efforts in design, coding and testing have been made to
|
||||
ensure that this program works correctly. However, the complexity
|
||||
of the algorithms, and, in particular, the presence of various
|
||||
special cases in the code which occur with very low but non-zero
|
||||
probability make it impossible to rule out the possibility of bugs
|
||||
remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
|
||||
PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
|
||||
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
|
||||
|
||||
That is not to say this program is inherently unreliable.
|
||||
Indeed, I very much hope the opposite is true. bzip2/libbzip2
|
||||
has been carefully constructed and extensively tested.
|
||||
|
||||
|
||||
PATENTS:
|
||||
|
||||
To the best of my knowledge, bzip2/libbzip2 does not use any
|
||||
patented algorithms. However, I do not have the resources
|
||||
to carry out a patent search. Therefore I cannot give any
|
||||
guarantee of the above statement.
|
||||
|
||||
|
||||
I hope you find bzip2 useful. Feel free to contact me at
|
||||
jseward@bzip.org
|
||||
if you have any suggestions or queries. Many people mailed me with
|
||||
comments, suggestions and patches after the releases of bzip-0.15,
|
||||
bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
|
||||
1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
|
||||
feedback. I thank you for your comments.
|
||||
|
||||
bzip2's "home" is http://www.bzip.org/
|
||||
|
||||
Julian Seward
|
||||
jseward@bzip.org
|
||||
Cambridge, UK.
|
||||
|
||||
18 July 1996 (version 0.15)
|
||||
25 August 1996 (version 0.21)
|
||||
7 August 1997 (bzip2, version 0.1)
|
||||
29 August 1997 (bzip2, version 0.1pl2)
|
||||
23 August 1998 (bzip2, version 0.9.0)
|
||||
8 June 1999 (bzip2, version 0.9.5)
|
||||
4 Sept 1999 (bzip2, version 0.9.5d)
|
||||
5 May 2000 (bzip2, version 1.0pre8)
|
||||
30 December 2001 (bzip2, version 1.0.2pre1)
|
||||
15 February 2005 (bzip2, version 1.0.3)
|
||||
20 December 2006 (bzip2, version 1.0.4)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Library top-level functions. ---*/
|
||||
/*--- bzlib.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* CHANGES
|
||||
* 0.9.0 -- original version.
|
||||
* 0.9.0a/b -- no changes in this file.
|
||||
* 0.9.0c -- made zero-length BZ_FLUSH work correctly in bzCompress().
|
||||
* fixed bzWrite/bzRead to ignore zero-length requests.
|
||||
* fixed bzread to correctly handle read requests after EOF.
|
||||
* wrong parameter order in call to bzDecompressInit in
|
||||
* bzBuffToBuffDecompress. Fixed.
|
||||
*/
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Compression stuff ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#if BZ_LIGHT_DEBUG
|
||||
static
|
||||
void bz_assert_fail(int errcode)
|
||||
{
|
||||
/* if (errcode == 1007) bb_error_msg_and_die("probably bad RAM"); */
|
||||
bb_error_msg_and_die("internal error %d", errcode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void prepare_new_block(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nblock = 0;
|
||||
s->numZ = 0;
|
||||
s->state_out_pos = 0;
|
||||
BZ_INITIALISE_CRC(s->blockCRC);
|
||||
/* inlined memset would be nice to have here */
|
||||
for (i = 0; i < 256; i++)
|
||||
s->inUse[i] = 0;
|
||||
s->blockNo++;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
ALWAYS_INLINE
|
||||
void init_RL(EState* s)
|
||||
{
|
||||
s->state_in_ch = 256;
|
||||
s->state_in_len = 0;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
int isempty_RL(EState* s)
|
||||
{
|
||||
return (s->state_in_ch >= 256 || s->state_in_len <= 0);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
{
|
||||
int32_t n;
|
||||
EState* s;
|
||||
|
||||
s = xzalloc(sizeof(EState));
|
||||
s->strm = strm;
|
||||
|
||||
n = 100000 * blockSize100k;
|
||||
s->arr1 = xmalloc(n * sizeof(uint32_t));
|
||||
s->mtfv = (uint16_t*)s->arr1;
|
||||
s->ptr = (uint32_t*)s->arr1;
|
||||
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
|
||||
s->block = (uint8_t*)s->arr2;
|
||||
s->ftab = xmalloc(65537 * sizeof(uint32_t));
|
||||
|
||||
s->crc32table = crc32_filltable(NULL, 1);
|
||||
|
||||
s->state = BZ_S_INPUT;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
s->blockSize100k = blockSize100k;
|
||||
s->nblockMAX = n - 19;
|
||||
|
||||
strm->state = s;
|
||||
/*strm->total_in = 0;*/
|
||||
strm->total_out = 0;
|
||||
init_RL(s);
|
||||
prepare_new_block(s);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void add_pair_to_block(EState* s)
|
||||
{
|
||||
int32_t i;
|
||||
uint8_t ch = (uint8_t)(s->state_in_ch);
|
||||
for (i = 0; i < s->state_in_len; i++) {
|
||||
BZ_UPDATE_CRC(s, s->blockCRC, ch);
|
||||
}
|
||||
s->inUse[s->state_in_ch] = 1;
|
||||
switch (s->state_in_len) {
|
||||
case 3:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
/* fall through */
|
||||
case 2:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
/* fall through */
|
||||
case 1:
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
break;
|
||||
default:
|
||||
s->inUse[s->state_in_len - 4] = 1;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)ch; s->nblock++;
|
||||
s->block[s->nblock] = (uint8_t)(s->state_in_len - 4);
|
||||
s->nblock++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void flush_RL(EState* s)
|
||||
{
|
||||
if (s->state_in_ch < 256) add_pair_to_block(s);
|
||||
init_RL(s);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define ADD_CHAR_TO_BLOCK(zs, zchh0) \
|
||||
{ \
|
||||
uint32_t zchh = (uint32_t)(zchh0); \
|
||||
/*-- fast track the common case --*/ \
|
||||
if (zchh != zs->state_in_ch && zs->state_in_len == 1) { \
|
||||
uint8_t ch = (uint8_t)(zs->state_in_ch); \
|
||||
BZ_UPDATE_CRC(zs, zs->blockCRC, ch); \
|
||||
zs->inUse[zs->state_in_ch] = 1; \
|
||||
zs->block[zs->nblock] = (uint8_t)ch; \
|
||||
zs->nblock++; \
|
||||
zs->state_in_ch = zchh; \
|
||||
} \
|
||||
else \
|
||||
/*-- general, uncommon cases --*/ \
|
||||
if (zchh != zs->state_in_ch || zs->state_in_len == 255) { \
|
||||
if (zs->state_in_ch < 256) \
|
||||
add_pair_to_block(zs); \
|
||||
zs->state_in_ch = zchh; \
|
||||
zs->state_in_len = 1; \
|
||||
} else { \
|
||||
zs->state_in_len++; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ copy_input_until_stop(EState* s)
|
||||
{
|
||||
/*Bool progress_in = False;*/
|
||||
|
||||
#ifdef SAME_CODE_AS_BELOW
|
||||
if (s->mode == BZ_M_RUNNING) {
|
||||
/*-- fast track the common case --*/
|
||||
while (1) {
|
||||
/*-- no input? --*/
|
||||
if (s->strm->avail_in == 0) break;
|
||||
/*-- block full? --*/
|
||||
if (s->nblock >= s->nblockMAX) break;
|
||||
/*progress_in = True;*/
|
||||
ADD_CHAR_TO_BLOCK(s, (uint32_t)(*(uint8_t*)(s->strm->next_in)));
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
/*s->strm->total_in++;*/
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*-- general, uncommon case --*/
|
||||
while (1) {
|
||||
/*-- no input? --*/
|
||||
if (s->strm->avail_in == 0) break;
|
||||
/*-- block full? --*/
|
||||
if (s->nblock >= s->nblockMAX) break;
|
||||
//# /*-- flush/finish end? --*/
|
||||
//# if (s->avail_in_expect == 0) break;
|
||||
/*progress_in = True;*/
|
||||
ADD_CHAR_TO_BLOCK(s, *(uint8_t*)(s->strm->next_in));
|
||||
s->strm->next_in++;
|
||||
s->strm->avail_in--;
|
||||
/*s->strm->total_in++;*/
|
||||
//# s->avail_in_expect--;
|
||||
}
|
||||
}
|
||||
/*return progress_in;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ copy_output_until_stop(EState* s)
|
||||
{
|
||||
/*Bool progress_out = False;*/
|
||||
|
||||
while (1) {
|
||||
/*-- no output space? --*/
|
||||
if (s->strm->avail_out == 0) break;
|
||||
|
||||
/*-- block done? --*/
|
||||
if (s->state_out_pos >= s->numZ) break;
|
||||
|
||||
/*progress_out = True;*/
|
||||
*(s->strm->next_out) = s->zbits[s->state_out_pos];
|
||||
s->state_out_pos++;
|
||||
s->strm->avail_out--;
|
||||
s->strm->next_out++;
|
||||
s->strm->total_out++;
|
||||
}
|
||||
/*return progress_out;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void /*Bool*/ handle_compress(bz_stream *strm)
|
||||
{
|
||||
/*Bool progress_in = False;*/
|
||||
/*Bool progress_out = False;*/
|
||||
EState* s = strm->state;
|
||||
|
||||
while (1) {
|
||||
if (s->state == BZ_S_OUTPUT) {
|
||||
/*progress_out |=*/ copy_output_until_stop(s);
|
||||
if (s->state_out_pos < s->numZ) break;
|
||||
if (s->mode == BZ_M_FINISHING
|
||||
//# && s->avail_in_expect == 0
|
||||
&& s->strm->avail_in == 0
|
||||
&& isempty_RL(s))
|
||||
break;
|
||||
prepare_new_block(s);
|
||||
s->state = BZ_S_INPUT;
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
if (s->mode == BZ_M_FLUSHING
|
||||
&& s->avail_in_expect == 0
|
||||
&& isempty_RL(s))
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (s->state == BZ_S_INPUT) {
|
||||
/*progress_in |=*/ copy_input_until_stop(s);
|
||||
//#if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) {
|
||||
if (s->mode != BZ_M_RUNNING && s->strm->avail_in == 0) {
|
||||
flush_RL(s);
|
||||
BZ2_compressBlock(s, (s->mode == BZ_M_FINISHING));
|
||||
s->state = BZ_S_OUTPUT;
|
||||
} else
|
||||
if (s->nblock >= s->nblockMAX) {
|
||||
BZ2_compressBlock(s, 0);
|
||||
s->state = BZ_S_OUTPUT;
|
||||
} else
|
||||
if (s->strm->avail_in == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*return progress_in || progress_out;*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
{
|
||||
/*Bool progress;*/
|
||||
EState* s;
|
||||
|
||||
s = strm->state;
|
||||
|
||||
switch (s->mode) {
|
||||
case BZ_M_RUNNING:
|
||||
if (action == BZ_RUN) {
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;*/
|
||||
return BZ_RUN_OK;
|
||||
}
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
else
|
||||
if (action == BZ_FLUSH) {
|
||||
//#s->avail_in_expect = strm->avail_in;
|
||||
s->mode = BZ_M_FLUSHING;
|
||||
goto case_BZ_M_FLUSHING;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
/*if (action == BZ_FINISH)*/ {
|
||||
//#s->avail_in_expect = strm->avail_in;
|
||||
s->mode = BZ_M_FINISHING;
|
||||
goto case_BZ_M_FINISHING;
|
||||
}
|
||||
|
||||
#ifdef FLUSH_IS_UNUSED
|
||||
case_BZ_M_FLUSHING:
|
||||
case BZ_M_FLUSHING:
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FLUSH_OK;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
return BZ_RUN_OK;
|
||||
#endif
|
||||
|
||||
case_BZ_M_FINISHING:
|
||||
/*case BZ_M_FINISHING:*/
|
||||
default:
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
//# return BZ_FINISH_OK;
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FINISH_OK;
|
||||
/*s->mode = BZ_M_IDLE;*/
|
||||
return BZ_STREAM_END;
|
||||
}
|
||||
/* return BZ_OK; --not reached--*/
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static
|
||||
void BZ2_bzCompressEnd(bz_stream *strm)
|
||||
{
|
||||
EState* s;
|
||||
|
||||
s = strm->state;
|
||||
free(s->arr1);
|
||||
free(s->arr2);
|
||||
free(s->ftab);
|
||||
free(s->crc32table);
|
||||
free(strm->state);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Misc convenience stuff ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#ifdef EXAMPLE_CODE_FOR_MEM_TO_MEM_COMPRESSION
|
||||
static
|
||||
int BZ2_bzBuffToBuffCompress(char* dest,
|
||||
unsigned int* destLen,
|
||||
char* source,
|
||||
unsigned int sourceLen,
|
||||
int blockSize100k)
|
||||
{
|
||||
bz_stream strm;
|
||||
int ret;
|
||||
|
||||
if (dest == NULL || destLen == NULL ||
|
||||
source == NULL ||
|
||||
blockSize100k < 1 || blockSize100k > 9)
|
||||
return BZ_PARAM_ERROR;
|
||||
|
||||
BZ2_bzCompressInit(&strm, blockSize100k);
|
||||
|
||||
strm.next_in = source;
|
||||
strm.next_out = dest;
|
||||
strm.avail_in = sourceLen;
|
||||
strm.avail_out = *destLen;
|
||||
|
||||
ret = BZ2_bzCompress(&strm, BZ_FINISH);
|
||||
if (ret == BZ_FINISH_OK) goto output_overflow;
|
||||
if (ret != BZ_STREAM_END) goto errhandler;
|
||||
|
||||
/* normal termination */
|
||||
*destLen -= strm.avail_out;
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return BZ_OK;
|
||||
|
||||
output_overflow:
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return BZ_OUTBUFF_FULL;
|
||||
|
||||
errhandler:
|
||||
BZ2_bzCompressEnd(&strm);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Public header file for the library. ---*/
|
||||
/*--- bzlib.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
#define BZ_RUN 0
|
||||
#define BZ_FLUSH 1
|
||||
#define BZ_FINISH 2
|
||||
|
||||
#define BZ_OK 0
|
||||
#define BZ_RUN_OK 1
|
||||
#define BZ_FLUSH_OK 2
|
||||
#define BZ_FINISH_OK 3
|
||||
#define BZ_STREAM_END 4
|
||||
#define BZ_SEQUENCE_ERROR (-1)
|
||||
#define BZ_PARAM_ERROR (-2)
|
||||
#define BZ_MEM_ERROR (-3)
|
||||
#define BZ_DATA_ERROR (-4)
|
||||
#define BZ_DATA_ERROR_MAGIC (-5)
|
||||
#define BZ_IO_ERROR (-6)
|
||||
#define BZ_UNEXPECTED_EOF (-7)
|
||||
#define BZ_OUTBUFF_FULL (-8)
|
||||
#define BZ_CONFIG_ERROR (-9)
|
||||
|
||||
typedef struct bz_stream {
|
||||
void *state;
|
||||
char *next_in;
|
||||
char *next_out;
|
||||
unsigned avail_in;
|
||||
unsigned avail_out;
|
||||
/*unsigned long long total_in;*/
|
||||
unsigned long long total_out;
|
||||
} bz_stream;
|
||||
|
||||
/*-- Core (low-level) library functions --*/
|
||||
|
||||
static void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k);
|
||||
static int BZ2_bzCompress(bz_stream *strm, int action);
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static void BZ2_bzCompressEnd(bz_stream *strm);
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Private header file for the library. ---*/
|
||||
/*--- bzlib_private.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* #include "bzlib.h" */
|
||||
|
||||
/*-- General stuff. --*/
|
||||
|
||||
typedef unsigned char Bool;
|
||||
|
||||
#define True ((Bool)1)
|
||||
#define False ((Bool)0)
|
||||
|
||||
#if BZ_LIGHT_DEBUG
|
||||
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
|
||||
#define AssertH(cond, errcode) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
bz_assert_fail(errcode); \
|
||||
} while (0)
|
||||
#else
|
||||
#define AssertH(cond, msg) do { } while (0)
|
||||
#endif
|
||||
|
||||
#if BZ_DEBUG
|
||||
#define AssertD(cond, msg) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
bb_error_msg_and_die("(debug build): internal error %s", msg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define AssertD(cond, msg) do { } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
/*-- Header bytes. --*/
|
||||
|
||||
#define BZ_HDR_B 0x42 /* 'B' */
|
||||
#define BZ_HDR_Z 0x5a /* 'Z' */
|
||||
#define BZ_HDR_h 0x68 /* 'h' */
|
||||
#define BZ_HDR_0 0x30 /* '0' */
|
||||
|
||||
#define BZ_HDR_BZh0 0x425a6830
|
||||
|
||||
/*-- Constants for the back end. --*/
|
||||
|
||||
#define BZ_MAX_ALPHA_SIZE 258
|
||||
#define BZ_MAX_CODE_LEN 23
|
||||
|
||||
#define BZ_RUNA 0
|
||||
#define BZ_RUNB 1
|
||||
|
||||
#define BZ_N_GROUPS 6
|
||||
#define BZ_G_SIZE 50
|
||||
#define BZ_N_ITERS 4
|
||||
|
||||
#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
|
||||
|
||||
|
||||
/*-- Stuff for doing CRCs. --*/
|
||||
|
||||
#define BZ_INITIALISE_CRC(crcVar) \
|
||||
{ \
|
||||
crcVar = 0xffffffffL; \
|
||||
}
|
||||
|
||||
#define BZ_FINALISE_CRC(crcVar) \
|
||||
{ \
|
||||
crcVar = ~(crcVar); \
|
||||
}
|
||||
|
||||
#define BZ_UPDATE_CRC(s, crcVar, cha) \
|
||||
{ \
|
||||
crcVar = (crcVar << 8) ^ s->crc32table[(crcVar >> 24) ^ ((uint8_t)cha)]; \
|
||||
}
|
||||
|
||||
|
||||
/*-- States and modes for compression. --*/
|
||||
|
||||
#define BZ_M_IDLE 1
|
||||
#define BZ_M_RUNNING 2
|
||||
#define BZ_M_FLUSHING 3
|
||||
#define BZ_M_FINISHING 4
|
||||
|
||||
#define BZ_S_OUTPUT 1
|
||||
#define BZ_S_INPUT 2
|
||||
|
||||
#define BZ_N_RADIX 2
|
||||
#define BZ_N_QSORT 12
|
||||
#define BZ_N_SHELL 18
|
||||
#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2)
|
||||
|
||||
|
||||
/*-- Structure holding all the compression-side stuff. --*/
|
||||
|
||||
typedef struct EState {
|
||||
/* pointer back to the struct bz_stream */
|
||||
bz_stream *strm;
|
||||
|
||||
/* mode this stream is in, and whether inputting */
|
||||
/* or outputting data */
|
||||
int32_t mode;
|
||||
int32_t state;
|
||||
|
||||
/* remembers avail_in when flush/finish requested */
|
||||
/* bbox: not needed, strm->avail_in always has the same value */
|
||||
/* commented out with '//#' throughout the code */
|
||||
/* uint32_t avail_in_expect; */
|
||||
|
||||
/* for doing the block sorting */
|
||||
int32_t origPtr;
|
||||
uint32_t *arr1;
|
||||
uint32_t *arr2;
|
||||
uint32_t *ftab;
|
||||
|
||||
/* aliases for arr1 and arr2 */
|
||||
uint32_t *ptr;
|
||||
uint8_t *block;
|
||||
uint16_t *mtfv;
|
||||
uint8_t *zbits;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* run-length-encoding of the input */
|
||||
uint32_t state_in_ch;
|
||||
int32_t state_in_len;
|
||||
|
||||
/* input and output limits and current posns */
|
||||
int32_t nblock;
|
||||
int32_t nblockMAX;
|
||||
int32_t numZ;
|
||||
int32_t state_out_pos;
|
||||
|
||||
/* the buffer for bit stream creation */
|
||||
uint32_t bsBuff;
|
||||
int32_t bsLive;
|
||||
|
||||
/* block and combined CRCs */
|
||||
uint32_t blockCRC;
|
||||
uint32_t combinedCRC;
|
||||
|
||||
/* misc administratium */
|
||||
int32_t blockNo;
|
||||
int32_t blockSize100k;
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t nMTF;
|
||||
|
||||
/* map of bytes used in block */
|
||||
int32_t nInUse;
|
||||
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
|
||||
uint8_t unseqToSeq[256];
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t mtfFreq [BZ_MAX_ALPHA_SIZE];
|
||||
uint8_t selector [BZ_MAX_SELECTORS];
|
||||
uint8_t selectorMtf[BZ_MAX_SELECTORS];
|
||||
|
||||
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
|
||||
/* stack-saving measures: these can be local, but they are too big */
|
||||
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/* second dimension: only 3 needed; 4 makes index calculations faster */
|
||||
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
#endif
|
||||
int32_t BZ2_hbMakeCodeLengths__heap [BZ_MAX_ALPHA_SIZE + 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
|
||||
int32_t mainSort__runningOrder[256];
|
||||
int32_t mainSort__copyStart[256];
|
||||
int32_t mainSort__copyEnd[256];
|
||||
} EState;
|
||||
|
||||
|
||||
/*-- compression. --*/
|
||||
|
||||
static void
|
||||
BZ2_blockSort(EState*);
|
||||
|
||||
static void
|
||||
BZ2_compressBlock(EState*, int);
|
||||
|
||||
static void
|
||||
BZ2_bsInitWrite(EState*);
|
||||
|
||||
static void
|
||||
BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
|
||||
|
||||
static void
|
||||
BZ2_hbMakeCodeLengths(EState*, uint8_t*, int32_t*, int32_t, int32_t);
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end bzlib_private.h ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -0,0 +1,687 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Compression machinery (not incl block sorting) ---*/
|
||||
/*--- compress.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* CHANGES
|
||||
* 0.9.0 -- original version.
|
||||
* 0.9.0a/b -- no changes in this file.
|
||||
* 0.9.0c -- changed setting of nGroups in sendMTFValues()
|
||||
* so as to do a bit better on small files
|
||||
*/
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Bit stream I/O ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_bsInitWrite(EState* s)
|
||||
{
|
||||
s->bsLive = 0;
|
||||
s->bsBuff = 0;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static NOINLINE
|
||||
void bsFinishWrite(EState* s)
|
||||
{
|
||||
while (s->bsLive > 0) {
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
/* Helps only on level 5, on other levels hurts. ? */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
ALWAYS_INLINE
|
||||
#endif
|
||||
void bsW(EState* s, int32_t n, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (32 - s->bsLive - n));
|
||||
s->bsLive += n;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU32(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 24) & 0xff);
|
||||
bsW(s, 8, (u >> 16) & 0xff);
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- The back end proper ---*/
|
||||
/*---------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void makeMaps_e(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nInUse = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (s->inUse[i]) {
|
||||
s->unseqToSeq[i] = s->nInUse;
|
||||
s->nInUse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static NOINLINE
|
||||
void generateMTFValues(EState* s)
|
||||
{
|
||||
uint8_t yy[256];
|
||||
int32_t i, j;
|
||||
int32_t zPend;
|
||||
int32_t wr;
|
||||
int32_t EOB;
|
||||
|
||||
/*
|
||||
* After sorting (eg, here),
|
||||
* s->arr1[0 .. s->nblock-1] holds sorted order,
|
||||
* and
|
||||
* ((uint8_t*)s->arr2)[0 .. s->nblock-1]
|
||||
* holds the original block data.
|
||||
*
|
||||
* The first thing to do is generate the MTF values,
|
||||
* and put them in
|
||||
* ((uint16_t*)s->arr1)[0 .. s->nblock-1].
|
||||
* Because there are strictly fewer or equal MTF values
|
||||
* than block values, ptr values in this area are overwritten
|
||||
* with MTF values only when they are no longer needed.
|
||||
*
|
||||
* The final compressed bitstream is generated into the
|
||||
* area starting at
|
||||
* &((uint8_t*)s->arr2)[s->nblock]
|
||||
*
|
||||
* These storage aliases are set up in bzCompressInit(),
|
||||
* except for the last one, which is arranged in
|
||||
* compressBlock().
|
||||
*/
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
makeMaps_e(s);
|
||||
EOB = s->nInUse+1;
|
||||
|
||||
for (i = 0; i <= EOB; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
wr = 0;
|
||||
zPend = 0;
|
||||
for (i = 0; i < s->nInUse; i++)
|
||||
yy[i] = (uint8_t) i;
|
||||
|
||||
for (i = 0; i < s->nblock; i++) {
|
||||
uint8_t ll_i;
|
||||
AssertD(wr <= i, "generateMTFValues(1)");
|
||||
j = ptr[i] - 1;
|
||||
if (j < 0)
|
||||
j += s->nblock;
|
||||
ll_i = s->unseqToSeq[block[j]];
|
||||
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
|
||||
|
||||
if (yy[0] == ll_i) {
|
||||
zPend++;
|
||||
} else {
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
register uint8_t rll_i;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
rll_i = ll_i;
|
||||
while (rll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
};
|
||||
yy[0] = rtmp;
|
||||
j = ryy_j - &(yy[0]);
|
||||
mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2)
|
||||
break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
|
||||
mtfv[wr] = EOB;
|
||||
wr++;
|
||||
s->mtfFreq[EOB]++;
|
||||
|
||||
s->nMTF = wr;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define BZ_LESSER_ICOST 0
|
||||
#define BZ_GREATER_ICOST 15
|
||||
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups, nBytes;
|
||||
|
||||
/*
|
||||
* uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* is a global since the decoder also needs it.
|
||||
*
|
||||
* int32_t code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
* are also globals only used in this proc.
|
||||
* Made global to keep stack frame size small.
|
||||
*/
|
||||
#define code sendMTFValues__code
|
||||
#define rfreq sendMTFValues__rfreq
|
||||
#define len_pack sendMTFValues__len_pack
|
||||
|
||||
uint16_t cost[BZ_N_GROUPS];
|
||||
int32_t fave[BZ_N_GROUPS];
|
||||
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
alphaSize = s->nInUse + 2;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->len[t][v] = BZ_GREATER_ICOST;
|
||||
|
||||
/*--- Decide how many coding tables to use ---*/
|
||||
AssertH(s->nMTF > 0, 3001);
|
||||
if (s->nMTF < 200) nGroups = 2; else
|
||||
if (s->nMTF < 600) nGroups = 3; else
|
||||
if (s->nMTF < 1200) nGroups = 4; else
|
||||
if (s->nMTF < 2400) nGroups = 5; else
|
||||
nGroups = 6;
|
||||
|
||||
/*--- Generate an initial set of coding tables ---*/
|
||||
{
|
||||
int32_t nPart, remF, tFreq, aFreq;
|
||||
|
||||
nPart = nGroups;
|
||||
remF = s->nMTF;
|
||||
gs = 0;
|
||||
while (nPart > 0) {
|
||||
tFreq = remF / nPart;
|
||||
ge = gs - 1;
|
||||
aFreq = 0;
|
||||
while (aFreq < tFreq && ge < alphaSize-1) {
|
||||
ge++;
|
||||
aFreq += s->mtfFreq[ge];
|
||||
}
|
||||
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
&& ((nGroups - nPart) % 2 == 1) /* bbox: can this be replaced by x & 1? */
|
||||
) {
|
||||
aFreq -= s->mtfFreq[ge];
|
||||
ge--;
|
||||
}
|
||||
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
if (v >= gs && v <= ge)
|
||||
s->len[nPart-1][v] = BZ_LESSER_ICOST;
|
||||
else
|
||||
s->len[nPart-1][v] = BZ_GREATER_ICOST;
|
||||
|
||||
nPart--;
|
||||
gs = ge + 1;
|
||||
remF -= aFreq;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate up to BZ_N_ITERS times to improve the tables.
|
||||
*/
|
||||
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||
for (t = 0; t < nGroups; t++)
|
||||
fave[t] = 0;
|
||||
|
||||
for (t = 0; t < nGroups; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->rfreq[t][v] = 0;
|
||||
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
/*
|
||||
* Set up an auxiliary length table which is used to fast-track
|
||||
* the common case (nGroups == 6).
|
||||
*/
|
||||
if (nGroups == 6) {
|
||||
for (v = 0; v < alphaSize; v++) {
|
||||
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
nSelectors = 0;
|
||||
totc = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF)
|
||||
ge = s->nMTF-1;
|
||||
|
||||
/*
|
||||
* Calculate the cost of this group as coded
|
||||
* by each of the coding tables.
|
||||
*/
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] = 0;
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 5
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
register uint32_t cost01, cost23, cost45;
|
||||
register uint16_t icv;
|
||||
cost01 = cost23 = cost45 = 0;
|
||||
#define BZ_ITER(nn) \
|
||||
icv = mtfv[gs+(nn)]; \
|
||||
cost01 += s->len_pack[icv][0]; \
|
||||
cost23 += s->len_pack[icv][1]; \
|
||||
cost45 += s->len_pack[icv][2];
|
||||
BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4);
|
||||
BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9);
|
||||
BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14);
|
||||
BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19);
|
||||
BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24);
|
||||
BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29);
|
||||
BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34);
|
||||
BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39);
|
||||
BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44);
|
||||
BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49);
|
||||
#undef BZ_ITER
|
||||
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
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
uint16_t icv = mtfv[i];
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] += s->len[t][icv];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Find the coding table which is best for this group,
|
||||
* and record its identity in the selector table.
|
||||
*/
|
||||
/*bc = 999999999;*/
|
||||
/*bt = -1;*/
|
||||
bc = cost[0];
|
||||
bt = 0;
|
||||
for (t = 1 /*0*/; t < nGroups; t++) {
|
||||
if (cost[t] < bc) {
|
||||
bc = cost[t];
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
totc += bc;
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
/*
|
||||
* Increment the symbol frequencies for the selected table.
|
||||
*/
|
||||
/* 1% faster compress. +800 bytes */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 4
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
|
||||
BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4);
|
||||
BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9);
|
||||
BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14);
|
||||
BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19);
|
||||
BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24);
|
||||
BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29);
|
||||
BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34);
|
||||
BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39);
|
||||
BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44);
|
||||
BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49);
|
||||
#undef BZ_ITUR
|
||||
gs = ge + 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
while (gs <= ge) {
|
||||
s->rfreq[bt][mtfv[gs]]++;
|
||||
gs++;
|
||||
}
|
||||
/* already is: gs = ge + 1; */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recompute the tables based on the accumulated frequencies.
|
||||
*/
|
||||
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
|
||||
* comment in huffman.c for details. */
|
||||
for (t = 0; t < nGroups; t++)
|
||||
BZ2_hbMakeCodeLengths(s, &(s->len[t][0]), &(s->rfreq[t][0]), alphaSize, 17 /*20*/);
|
||||
}
|
||||
|
||||
AssertH(nGroups < 8, 3002);
|
||||
AssertH(nSelectors < 32768 && nSelectors <= (2 + (900000 / BZ_G_SIZE)), 3003);
|
||||
|
||||
/*--- Compute MTF values for the selectors. ---*/
|
||||
{
|
||||
uint8_t pos[BZ_N_GROUPS], ll_i, tmp2, tmp;
|
||||
|
||||
for (i = 0; i < nGroups; i++)
|
||||
pos[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
ll_i = s->selector[i];
|
||||
j = 0;
|
||||
tmp = pos[j];
|
||||
while (ll_i != tmp) {
|
||||
j++;
|
||||
tmp2 = tmp;
|
||||
tmp = pos[j];
|
||||
pos[j] = tmp2;
|
||||
};
|
||||
pos[0] = tmp;
|
||||
s->selectorMtf[i] = j;
|
||||
}
|
||||
};
|
||||
|
||||
/*--- Assign actual codes for the tables. --*/
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
minLen = 32;
|
||||
maxLen = 0;
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||
}
|
||||
AssertH(!(maxLen > 17 /*20*/), 3004);
|
||||
AssertH(!(minLen < 1), 3005);
|
||||
BZ2_hbAssignCodes(&(s->code[t][0]), &(s->len[t][0]), minLen, maxLen, alphaSize);
|
||||
}
|
||||
|
||||
/*--- Transmit the mapping table. ---*/
|
||||
{
|
||||
/* bbox: optimized a bit more than in bzip2 */
|
||||
int inUse16 = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (sizeof(long) <= 4) {
|
||||
inUse16 = inUse16*2 +
|
||||
((*(uint32_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 4])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 8])
|
||||
| *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
|
||||
} else { /* Our CPU can do better */
|
||||
inUse16 = inUse16*2 +
|
||||
((*(uint64_t*)&(s->inUse[i * 16 + 0])
|
||||
| *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 16, inUse16);
|
||||
|
||||
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (inUse16 < 0) {
|
||||
unsigned v16 = 0;
|
||||
for (j = 0; j < 16; j++)
|
||||
v16 = v16*2 + s->inUse[i * 16 + j];
|
||||
bsW(s, 16, v16);
|
||||
}
|
||||
inUse16 <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*--- Now the selectors. ---*/
|
||||
nBytes = s->numZ;
|
||||
bsW(s, 3, nGroups);
|
||||
bsW(s, 15, nSelectors);
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
for (j = 0; j < s->selectorMtf[i]; j++)
|
||||
bsW(s, 1, 1);
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
|
||||
/*--- Now the coding tables. ---*/
|
||||
nBytes = s->numZ;
|
||||
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
int32_t curr = s->len[t][0];
|
||||
bsW(s, 5, curr);
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*--- And finally, the block data proper ---*/
|
||||
nBytes = s->numZ;
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
if (ge >= s->nMTF)
|
||||
ge = s->nMTF-1;
|
||||
AssertH(s->selector[selCtr] < nGroups, 3006);
|
||||
|
||||
/* Costs 1300 bytes and is _slower_ (on Intel Core 2) */
|
||||
#if 0
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
uint16_t mtfv_i;
|
||||
uint8_t* s_len_sel_selCtr = &(s->len[s->selector[selCtr]][0]);
|
||||
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
|
||||
#define BZ_ITAH(nn) \
|
||||
mtfv_i = mtfv[gs+(nn)]; \
|
||||
bsW(s, s_len_sel_selCtr[mtfv_i], s_code_sel_selCtr[mtfv_i])
|
||||
BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4);
|
||||
BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9);
|
||||
BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14);
|
||||
BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19);
|
||||
BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24);
|
||||
BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29);
|
||||
BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34);
|
||||
BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39);
|
||||
BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44);
|
||||
BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49);
|
||||
#undef BZ_ITAH
|
||||
gs = ge+1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
/* code is bit bigger, but moves multiply out of the loop */
|
||||
uint8_t* s_len_sel_selCtr = &(s->len [s->selector[selCtr]][0]);
|
||||
int32_t* s_code_sel_selCtr = &(s->code[s->selector[selCtr]][0]);
|
||||
while (gs <= ge) {
|
||||
bsW(s,
|
||||
s_len_sel_selCtr[mtfv[gs]],
|
||||
s_code_sel_selCtr[mtfv[gs]]
|
||||
);
|
||||
gs++;
|
||||
}
|
||||
/* already is: gs = ge+1; */
|
||||
}
|
||||
selCtr++;
|
||||
}
|
||||
AssertH(selCtr == nSelectors, 3007);
|
||||
#undef code
|
||||
#undef rfreq
|
||||
#undef len_pack
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
{
|
||||
if (s->nblock > 0) {
|
||||
BZ_FINALISE_CRC(s->blockCRC);
|
||||
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
|
||||
s->combinedCRC ^= s->blockCRC;
|
||||
if (s->blockNo > 1)
|
||||
s->numZ = 0;
|
||||
|
||||
BZ2_blockSort(s);
|
||||
}
|
||||
|
||||
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
|
||||
|
||||
/*-- If this is the first block, create the stream header. --*/
|
||||
if (s->blockNo == 1) {
|
||||
BZ2_bsInitWrite(s);
|
||||
/*bsPutU8(s, BZ_HDR_B);*/
|
||||
/*bsPutU8(s, BZ_HDR_Z);*/
|
||||
/*bsPutU8(s, BZ_HDR_h);*/
|
||||
/*bsPutU8(s, BZ_HDR_0 + s->blockSize100k);*/
|
||||
bsPutU32(s, BZ_HDR_BZh0 + s->blockSize100k);
|
||||
}
|
||||
|
||||
if (s->nblock > 0) {
|
||||
/*bsPutU8(s, 0x31);*/
|
||||
/*bsPutU8(s, 0x41);*/
|
||||
/*bsPutU8(s, 0x59);*/
|
||||
/*bsPutU8(s, 0x26);*/
|
||||
bsPutU32(s, 0x31415926);
|
||||
/*bsPutU8(s, 0x53);*/
|
||||
/*bsPutU8(s, 0x59);*/
|
||||
bsPutU16(s, 0x5359);
|
||||
|
||||
/*-- Now the block's CRC, so it is in a known place. --*/
|
||||
bsPutU32(s, s->blockCRC);
|
||||
|
||||
/*
|
||||
* Now a single bit indicating (non-)randomisation.
|
||||
* As of version 0.9.5, we use a better sorting algorithm
|
||||
* which makes randomisation unnecessary. So always set
|
||||
* the randomised bit to 'no'. Of course, the decoder
|
||||
* still needs to be able to handle randomised blocks
|
||||
* so as to maintain backwards compatibility with
|
||||
* older versions of bzip2.
|
||||
*/
|
||||
bsW(s, 1, 0);
|
||||
|
||||
bsW(s, 24, s->origPtr);
|
||||
generateMTFValues(s);
|
||||
sendMTFValues(s);
|
||||
}
|
||||
|
||||
/*-- If this is the last block, add the stream trailer. --*/
|
||||
if (is_last_block) {
|
||||
/*bsPutU8(s, 0x17);*/
|
||||
/*bsPutU8(s, 0x72);*/
|
||||
/*bsPutU8(s, 0x45);*/
|
||||
/*bsPutU8(s, 0x38);*/
|
||||
bsPutU32(s, 0x17724538);
|
||||
/*bsPutU8(s, 0x50);*/
|
||||
/*bsPutU8(s, 0x90);*/
|
||||
bsPutU16(s, 0x5090);
|
||||
bsPutU32(s, s->combinedCRC);
|
||||
bsFinishWrite(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end compress.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* bzip2 is written by Julian Seward <jseward@bzip.org>.
|
||||
* Adapted for busybox by Denys Vlasenko <vda.linux@googlemail.com>.
|
||||
* See README and LICENSE files in this directory for more information.
|
||||
*/
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- Huffman coding low-level stuff ---*/
|
||||
/*--- huffman.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
This file is part of bzip2/libbzip2, a program and library for
|
||||
lossless, block-sorting data compression.
|
||||
|
||||
bzip2/libbzip2 version 1.0.4 of 20 December 2006
|
||||
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
|
||||
|
||||
Please read the WARNING, DISCLAIMER and PATENTS sections in the
|
||||
README file.
|
||||
|
||||
This program is released under the terms of the license contained
|
||||
in the file LICENSE.
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
|
||||
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
|
||||
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
|
||||
|
||||
#define ADDWEIGHTS(zw1,zw2) \
|
||||
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
|
||||
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
|
||||
|
||||
#define UPHEAP(z) \
|
||||
{ \
|
||||
int32_t zz, tmp; \
|
||||
zz = z; \
|
||||
tmp = heap[zz]; \
|
||||
while (weight[tmp] < weight[heap[zz >> 1]]) { \
|
||||
heap[zz] = heap[zz >> 1]; \
|
||||
zz >>= 1; \
|
||||
} \
|
||||
heap[zz] = tmp; \
|
||||
}
|
||||
|
||||
|
||||
/* 90 bytes, 0.3% of overall compress speed */
|
||||
#if CONFIG_BZIP2_FEATURE_SPEED >= 1
|
||||
|
||||
/* macro works better than inline (gcc 4.2.1) */
|
||||
#define DOWNHEAP1(heap, weight, Heap) \
|
||||
{ \
|
||||
int32_t zz, yy, tmp; \
|
||||
zz = 1; \
|
||||
tmp = heap[zz]; \
|
||||
while (1) { \
|
||||
yy = zz << 1; \
|
||||
if (yy > nHeap) \
|
||||
break; \
|
||||
if (yy < nHeap \
|
||||
&& weight[heap[yy+1]] < weight[heap[yy]]) \
|
||||
yy++; \
|
||||
if (weight[tmp] < weight[heap[yy]]) \
|
||||
break; \
|
||||
heap[zz] = heap[yy]; \
|
||||
zz = yy; \
|
||||
} \
|
||||
heap[zz] = tmp; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static
|
||||
void DOWNHEAP1(int32_t *heap, int32_t *weight, int32_t nHeap)
|
||||
{
|
||||
int32_t zz, yy, tmp;
|
||||
zz = 1;
|
||||
tmp = heap[zz];
|
||||
while (1) {
|
||||
yy = zz << 1;
|
||||
if (yy > nHeap)
|
||||
break;
|
||||
if (yy < nHeap
|
||||
&& weight[heap[yy + 1]] < weight[heap[yy]])
|
||||
yy++;
|
||||
if (weight[tmp] < weight[heap[yy]])
|
||||
break;
|
||||
heap[zz] = heap[yy];
|
||||
zz = yy;
|
||||
}
|
||||
heap[zz] = tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_hbMakeCodeLengths(EState *s,
|
||||
uint8_t *len,
|
||||
int32_t *freq,
|
||||
int32_t alphaSize,
|
||||
int32_t maxLen)
|
||||
{
|
||||
/*
|
||||
* Nodes and heap entries run from 1. Entry 0
|
||||
* for both the heap and nodes is a sentinel.
|
||||
*/
|
||||
int32_t nNodes, nHeap, n1, n2, i, j, k;
|
||||
Bool tooLong;
|
||||
|
||||
/* bbox: moved to EState to save stack
|
||||
int32_t heap [BZ_MAX_ALPHA_SIZE + 2];
|
||||
int32_t weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
*/
|
||||
#define heap (s->BZ2_hbMakeCodeLengths__heap)
|
||||
#define weight (s->BZ2_hbMakeCodeLengths__weight)
|
||||
#define parent (s->BZ2_hbMakeCodeLengths__parent)
|
||||
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
|
||||
|
||||
while (1) {
|
||||
nNodes = alphaSize;
|
||||
nHeap = 0;
|
||||
|
||||
heap[0] = 0;
|
||||
weight[0] = 0;
|
||||
parent[0] = -2;
|
||||
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
parent[i] = -1;
|
||||
nHeap++;
|
||||
heap[nHeap] = i;
|
||||
UPHEAP(nHeap);
|
||||
}
|
||||
|
||||
AssertH(nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001);
|
||||
|
||||
while (nHeap > 1) {
|
||||
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
|
||||
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP1(heap, weight, nHeap);
|
||||
nNodes++;
|
||||
parent[n1] = parent[n2] = nNodes;
|
||||
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
|
||||
parent[nNodes] = -1;
|
||||
nHeap++;
|
||||
heap[nHeap] = nNodes;
|
||||
UPHEAP(nHeap);
|
||||
}
|
||||
|
||||
AssertH(nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002);
|
||||
|
||||
tooLong = False;
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
j = 0;
|
||||
k = i;
|
||||
while (parent[k] >= 0) {
|
||||
k = parent[k];
|
||||
j++;
|
||||
}
|
||||
len[i-1] = j;
|
||||
if (j > maxLen)
|
||||
tooLong = True;
|
||||
}
|
||||
|
||||
if (!tooLong)
|
||||
break;
|
||||
|
||||
/* 17 Oct 04: keep-going condition for the following loop used
|
||||
to be 'i < alphaSize', which missed the last element,
|
||||
theoretically leading to the possibility of the compressor
|
||||
looping. However, this count-scaling step is only needed if
|
||||
one of the generated Huffman code words is longer than
|
||||
maxLen, which up to and including version 1.0.2 was 20 bits,
|
||||
which is extremely unlikely. In version 1.0.3 maxLen was
|
||||
changed to 17 bits, which has minimal effect on compression
|
||||
ratio, but does mean this scaling step is used from time to
|
||||
time, enough to verify that it works.
|
||||
|
||||
This means that bzip2-1.0.3 and later will only produce
|
||||
Huffman codes with a maximum length of 17 bits. However, in
|
||||
order to preserve backwards compatibility with bitstreams
|
||||
produced by versions pre-1.0.3, the decompressor must still
|
||||
handle lengths of up to 20. */
|
||||
|
||||
for (i = 1; i <= alphaSize; i++) {
|
||||
j = weight[i] >> 8;
|
||||
/* bbox: yes, it is a signed division.
|
||||
* don't replace with shift! */
|
||||
j = 1 + (j / 2);
|
||||
weight[i] = j << 8;
|
||||
}
|
||||
}
|
||||
#undef heap
|
||||
#undef weight
|
||||
#undef parent
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void BZ2_hbAssignCodes(int32_t *code,
|
||||
uint8_t *length,
|
||||
int32_t minLen,
|
||||
int32_t maxLen,
|
||||
int32_t alphaSize)
|
||||
{
|
||||
int32_t n, vec, i;
|
||||
|
||||
vec = 0;
|
||||
for (n = minLen; n <= maxLen; n++) {
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (length[i] == n) {
|
||||
code[i] = vec;
|
||||
vec++;
|
||||
};
|
||||
}
|
||||
vec <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/*--- end huffman.c ---*/
|
||||
/*-------------------------------------------------------------*/
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
|
||||
*
|
||||
* This file uses bzip2 library code which is written
|
||||
* by Julian Seward <jseward@bzip.org>.
|
||||
* See README and LICENSE files in bz/ directory for more information
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define CONFIG_BZIP2_FEATURE_SPEED 1
|
||||
|
||||
/* Speed test:
|
||||
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
|
||||
* Stock bzip2 is 26.4% slower than bbox bzip2 at SPEED 1
|
||||
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
|
||||
* At SPEED 5 difference is 32.7%.
|
||||
*
|
||||
* Test run of all CONFIG_BZIP2_FEATURE_SPEED values on a 11Mb text file:
|
||||
* Size Time (3 runs)
|
||||
* 0: 10828 4.145 4.146 4.148
|
||||
* 1: 11097 3.845 3.860 3.861
|
||||
* 2: 11392 3.763 3.767 3.768
|
||||
* 3: 11892 3.722 3.724 3.727
|
||||
* 4: 12740 3.637 3.640 3.644
|
||||
* 5: 17273 3.497 3.509 3.509
|
||||
*/
|
||||
|
||||
|
||||
#define BZ_DEBUG 0
|
||||
/* Takes ~300 bytes, detects corruption caused by bad RAM etc */
|
||||
#define BZ_LIGHT_DEBUG 0
|
||||
|
||||
#include "bz/bzlib.h"
|
||||
|
||||
#include "bz/bzlib_private.h"
|
||||
|
||||
#include "bz/blocksort.c"
|
||||
#include "bz/bzlib.c"
|
||||
#include "bz/compress.c"
|
||||
#include "bz/huffman.c"
|
||||
|
||||
/* No point in being shy and having very small buffer here.
|
||||
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
|
||||
* If iobuf is several pages long, malloc() may use mmap,
|
||||
* making iobuf is page aligned and thus (maybe) have one memcpy less
|
||||
* if kernel is clever enough.
|
||||
*/
|
||||
enum {
|
||||
IOBUF_SIZE = 8 * 1024
|
||||
};
|
||||
|
||||
static uint8_t level;
|
||||
|
||||
/* NB: compressStream() has to return -1 on errors, not die.
|
||||
* bbunpack() will correctly clean up in this case
|
||||
* (delete incomplete .bz2 file)
|
||||
*/
|
||||
|
||||
/* Returns:
|
||||
* -1 on errors
|
||||
* total written bytes so far otherwise
|
||||
*/
|
||||
static
|
||||
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
{
|
||||
int n, n2, ret;
|
||||
|
||||
strm->avail_in = rlen;
|
||||
strm->next_in = rbuf;
|
||||
while (1) {
|
||||
strm->avail_out = IOBUF_SIZE;
|
||||
strm->next_out = wbuf;
|
||||
|
||||
ret = BZ2_bzCompress(strm, rlen ? BZ_RUN : BZ_FINISH);
|
||||
if (ret != BZ_RUN_OK /* BZ_RUNning */
|
||||
&& ret != BZ_FINISH_OK /* BZ_FINISHing, but not done yet */
|
||||
&& ret != BZ_STREAM_END /* BZ_FINISHed */
|
||||
) {
|
||||
bb_error_msg_and_die("internal error %d", ret);
|
||||
}
|
||||
|
||||
n = IOBUF_SIZE - strm->avail_out;
|
||||
if (n) {
|
||||
n2 = full_write(STDOUT_FILENO, wbuf, n);
|
||||
if (n2 != n) {
|
||||
if (n2 >= 0)
|
||||
errno = 0; /* prevent bogus error message */
|
||||
bb_perror_msg(n2 >= 0 ? "short write" : "write error");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == BZ_STREAM_END)
|
||||
break;
|
||||
if (rlen && strm->avail_in == 0)
|
||||
break;
|
||||
}
|
||||
return 0 USE_DESKTOP( + strm->total_out );
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int compressStream(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
char *iobuf;
|
||||
#define rbuf iobuf
|
||||
#define wbuf (iobuf + IOBUF_SIZE)
|
||||
|
||||
iobuf = xmalloc(2 * IOBUF_SIZE);
|
||||
BZ2_bzCompressInit(strm, level);
|
||||
|
||||
while (1) {
|
||||
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
|
||||
if (count < 0) {
|
||||
bb_perror_msg("read error");
|
||||
total = -1;
|
||||
break;
|
||||
}
|
||||
/* if count == 0, bz_write finalizes compression */
|
||||
total = bz_write(strm, rbuf, count, wbuf);
|
||||
if (count == 0 || total < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
BZ2_bzCompressEnd(strm);
|
||||
free(iobuf);
|
||||
#endif
|
||||
return total;
|
||||
}
|
||||
|
||||
static
|
||||
char* make_new_name_bzip2(char *filename)
|
||||
{
|
||||
return xasprintf("%s.bz2", filename);
|
||||
}
|
||||
|
||||
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
/* standard bzip2 flags
|
||||
* -d --decompress force decompression
|
||||
* -z --compress force compression
|
||||
* -k --keep keep (don't delete) input files
|
||||
* -f --force overwrite existing output files
|
||||
* -t --test test compressed file integrity
|
||||
* -c --stdout output to standard out
|
||||
* -q --quiet suppress noncritical error messages
|
||||
* -v --verbose be verbose (a 2nd -v gives more)
|
||||
* -s --small use less memory (at most 2500k)
|
||||
* -1 .. -9 set block size to 100k .. 900k
|
||||
* --fast alias for -1
|
||||
* --best alias for -9
|
||||
*/
|
||||
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
|
||||
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
|
||||
if (opt & 0x8) // -d
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 4;
|
||||
#else
|
||||
opt >>= 3;
|
||||
#endif
|
||||
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 1;
|
||||
while (!(opt & 1)) {
|
||||
level++;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
option_mask32 &= 0x7; /* ignore all except -cfv */
|
||||
return bbunpack(argv, make_new_name_bzip2, compressStream);
|
||||
}
|
||||
+288
-21
@@ -7,35 +7,298 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define CPIO_OPT_EXTRACT 0x01
|
||||
#define CPIO_OPT_TEST 0x02
|
||||
#define CPIO_OPT_UNCONDITIONAL 0x04
|
||||
#define CPIO_OPT_VERBOSE 0x08
|
||||
#define CPIO_OPT_FILE 0x10
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
static off_t cpio_pad4(off_t size)
|
||||
{
|
||||
int i;
|
||||
|
||||
int cpio_main(int argc, char **argv);
|
||||
int cpio_main(int argc, char **argv)
|
||||
i = (- size) & 3;
|
||||
size += i;
|
||||
while (--i >= 0)
|
||||
bb_putchar('\0');
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Return value will become exit code.
|
||||
* It's ok to exit instead of return. */
|
||||
static int cpio_o(void)
|
||||
{
|
||||
struct name_s {
|
||||
struct name_s *next;
|
||||
char name[1];
|
||||
};
|
||||
struct inodes_s {
|
||||
struct inodes_s *next;
|
||||
struct name_s *names;
|
||||
struct stat st;
|
||||
};
|
||||
|
||||
struct inodes_s *links = NULL;
|
||||
off_t bytes = 0; /* output bytes count */
|
||||
|
||||
while (1) {
|
||||
const char *name;
|
||||
char *line;
|
||||
struct stat st;
|
||||
|
||||
line = xmalloc_fgetline(stdin);
|
||||
|
||||
if (line) {
|
||||
/* Strip leading "./[./]..." from the filename */
|
||||
name = line;
|
||||
while (name[0] == '.' && name[1] == '/') {
|
||||
while (*++name == '/')
|
||||
continue;
|
||||
}
|
||||
if (!*name) { /* line is empty */
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
if (lstat(name, &st)) {
|
||||
abort_cpio_o:
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
|
||||
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
|
||||
st.st_size = 0; /* paranoia */
|
||||
|
||||
/* Store hardlinks for later processing, dont output them */
|
||||
if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
|
||||
struct name_s *n;
|
||||
struct inodes_s *l;
|
||||
|
||||
/* Do we have this hardlink remembered? */
|
||||
l = links;
|
||||
while (1) {
|
||||
if (l == NULL) {
|
||||
/* Not found: add new item to "links" list */
|
||||
l = xzalloc(sizeof(*l));
|
||||
l->st = st;
|
||||
l->next = links;
|
||||
links = l;
|
||||
break;
|
||||
}
|
||||
if (l->st.st_ino == st.st_ino) {
|
||||
/* found */
|
||||
break;
|
||||
}
|
||||
l = l->next;
|
||||
}
|
||||
/* Add new name to "l->names" list */
|
||||
n = xmalloc(sizeof(*n) + strlen(name));
|
||||
strcpy(n->name, name);
|
||||
n->next = l->names;
|
||||
l->names = n;
|
||||
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
/* Output hardlink's data */
|
||||
st = links->st;
|
||||
name = links->names->name;
|
||||
links->names = links->names->next;
|
||||
/* GNU cpio is reported to emit file data
|
||||
* only for the last instance. Mimic that. */
|
||||
if (links->names == NULL)
|
||||
links = links->next;
|
||||
else
|
||||
st.st_size = 0;
|
||||
/* NB: we leak links->names and/or links,
|
||||
* this is intended (we exit soon anyway) */
|
||||
} else {
|
||||
/* If no (more) hardlinks to output,
|
||||
* output "trailer" entry */
|
||||
name = "TRAILER!!!";
|
||||
/* st.st_size == 0 is a must, but for uniformity
|
||||
* in the output, we zero out everything */
|
||||
memset(&st, 0, sizeof(st));
|
||||
/* st.st_nlink = 1; - GNU cpio does this */
|
||||
}
|
||||
}
|
||||
|
||||
bytes += printf("070701"
|
||||
"%08X%08X%08X%08X%08X%08X%08X"
|
||||
"%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
|
||||
/* strlen+1: */ "%08X"
|
||||
/* chksum: */ "00000000" /* (only for "070702" files) */
|
||||
/* name,NUL: */ "%s%c",
|
||||
(unsigned)(uint32_t) st.st_ino,
|
||||
(unsigned)(uint32_t) st.st_mode,
|
||||
(unsigned)(uint32_t) st.st_uid,
|
||||
(unsigned)(uint32_t) st.st_gid,
|
||||
(unsigned)(uint32_t) st.st_nlink,
|
||||
(unsigned)(uint32_t) st.st_mtime,
|
||||
(unsigned)(uint32_t) st.st_size,
|
||||
(unsigned)(uint32_t) major(st.st_dev),
|
||||
(unsigned)(uint32_t) minor(st.st_dev),
|
||||
(unsigned)(uint32_t) major(st.st_rdev),
|
||||
(unsigned)(uint32_t) minor(st.st_rdev),
|
||||
(unsigned)(strlen(name) + 1),
|
||||
name, '\0');
|
||||
bytes = cpio_pad4(bytes);
|
||||
|
||||
if (st.st_size) {
|
||||
if (S_ISLNK(st.st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(name);
|
||||
if (!lpath)
|
||||
goto abort_cpio_o;
|
||||
bytes += printf("%s", lpath);
|
||||
free(lpath);
|
||||
} else { /* S_ISREG */
|
||||
int fd = xopen(name, O_RDONLY);
|
||||
fflush(stdout);
|
||||
/* We must abort if file got shorter too! */
|
||||
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
|
||||
bytes += st.st_size;
|
||||
close(fd);
|
||||
}
|
||||
bytes = cpio_pad4(bytes);
|
||||
}
|
||||
|
||||
if (!line) {
|
||||
if (links)
|
||||
goto next_link;
|
||||
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
free(line);
|
||||
} /* end of "while (1)" */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* GNU cpio (GNU cpio) 2.9 help (abridged):
|
||||
|
||||
Main operation mode:
|
||||
-i, --extract Extract files from an archive
|
||||
-o, --create Create the archive
|
||||
-p, --pass-through Copy-pass mode (was ist das?!)
|
||||
-t, --list List the archive
|
||||
|
||||
Operation modifiers valid in any mode:
|
||||
--block-size=SIZE I/O block size = SIZE * 512 bytes
|
||||
-B I/O block size = 5120 bytes
|
||||
-c Use the old portable (ASCII) archive format
|
||||
-C, --io-size=NUMBER I/O block size to the given NUMBER bytes
|
||||
-f, --nonmatching Only copy files that do not match given pattern
|
||||
-F, --file=FILE Use FILE instead of standard input or output
|
||||
-H, --format=FORMAT Use given archive FORMAT
|
||||
-M, --message=STRING Print STRING when the end of a volume of the
|
||||
backup media is reached
|
||||
-n, --numeric-uid-gid If -v, show numeric UID and GID
|
||||
--quiet Do not print the number of blocks copied
|
||||
--rsh-command=COMMAND Use remote COMMAND instead of rsh
|
||||
-v, --verbose Verbosely list the files processed
|
||||
-V, --dot Print a "." for each file processed
|
||||
-W, --warning=FLAG Control warning display: 'none','truncate','all';
|
||||
multiple options accumulate
|
||||
|
||||
Operation modifiers valid only in --extract mode:
|
||||
-b, --swap Swap both halfwords of words and bytes of
|
||||
halfwords in the data (equivalent to -sS)
|
||||
-r, --rename Interactively rename files
|
||||
-s, --swap-bytes Swap the bytes of each halfword in the files
|
||||
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
|
||||
--to-stdout Extract files to standard output
|
||||
-E, --pattern-file=FILE Read additional patterns specifying filenames to
|
||||
extract or list from FILE
|
||||
--only-verify-crc Verify CRC's, don't actually extract the files
|
||||
|
||||
Operation modifiers valid only in --create mode:
|
||||
-A, --append Append to an existing archive
|
||||
-O FILE File to use instead of standard output
|
||||
|
||||
Operation modifiers valid only in --pass-through mode:
|
||||
-l, --link Link files instead of copying them, when possible
|
||||
|
||||
Operation modifiers valid in --extract and --create modes:
|
||||
--absolute-filenames Do not strip file system prefix components from
|
||||
the file names
|
||||
--no-absolute-filenames Create all files relative to the current dir
|
||||
|
||||
Operation modifiers valid in --create and --pass-through modes:
|
||||
-0, --null A list of filenames is terminated by a NUL
|
||||
-a, --reset-access-time Reset the access times of files after reading them
|
||||
-I FILE File to use instead of standard input
|
||||
-L, --dereference Dereference symbolic links (copy the files
|
||||
that they point to instead of copying the links)
|
||||
-R, --owner=[USER][:.][GROUP] Set owner of created files
|
||||
|
||||
Operation modifiers valid in --extract and --pass-through modes:
|
||||
-d, --make-directories Create leading directories where needed
|
||||
-m, --preserve-modification-time
|
||||
Retain previous file modification times when
|
||||
creating files
|
||||
--no-preserve-owner Do not change the ownership of the files
|
||||
--sparse Write files with blocks of zeros as sparse files
|
||||
-u, --unconditional Replace all files unconditionally
|
||||
*/
|
||||
|
||||
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename = NULL;
|
||||
char *cpio_filename;
|
||||
USE_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
unsigned opt;
|
||||
enum {
|
||||
CPIO_OPT_EXTRACT = (1 << 0),
|
||||
CPIO_OPT_TEST = (1 << 1),
|
||||
CPIO_OPT_UNCONDITIONAL = (1 << 2),
|
||||
CPIO_OPT_VERBOSE = (1 << 3),
|
||||
CPIO_OPT_FILE = (1 << 4),
|
||||
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
|
||||
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
|
||||
CPIO_OPT_CREATE = (1 << 7),
|
||||
CPIO_OPT_FORMAT = (1 << 8),
|
||||
};
|
||||
|
||||
/* Initialise */
|
||||
#if ENABLE_GETOPT_LONG && ENABLE_DESKTOP
|
||||
applet_long_options =
|
||||
"extract\0" No_argument "i"
|
||||
"list\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
"create\0" No_argument "o"
|
||||
"format\0" Required_argument "H"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER;
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
|
||||
|
||||
if (opt & CPIO_OPT_CREATE) {
|
||||
if (*cpio_fmt != 'n')
|
||||
bb_show_usage();
|
||||
if (opt & CPIO_OPT_FILE) {
|
||||
fclose(stdout);
|
||||
stdout = fopen(cpio_filename, "w");
|
||||
/* Paranoia: I don't trust libc that much */
|
||||
xdup2(fileno(stdout), STDOUT_FILENO);
|
||||
}
|
||||
return cpio_o();
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "ituvF:dm", &cpio_filename);
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
@@ -63,21 +326,25 @@ int cpio_main(int argc, char **argv)
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (cpio_filename) { /* CPIO_OPT_FILE */
|
||||
if (opt & CPIO_OPT_FILE) { /* -F */
|
||||
archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind]);
|
||||
optind++;
|
||||
if (opt & CPIO_OPT_PRESERVE_MTIME) {
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
while (*argv) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), *argv);
|
||||
argv++;
|
||||
}
|
||||
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+115
-93
@@ -75,10 +75,21 @@ typedef struct status_node_s {
|
||||
unsigned status:16; /* was:14 */ /* has to fit STATUS_HASH_PRIME */
|
||||
} status_node_t;
|
||||
|
||||
/* Were statically declared here, but such a big bss is nommu-unfriendly */
|
||||
static char **name_hashtable; /* [NAME_HASH_PRIME + 1] */
|
||||
static common_node_t **package_hashtable; /* [PACKAGE_HASH_PRIME + 1] */
|
||||
static status_node_t **status_hashtable; /* [STATUS_HASH_PRIME + 1] */
|
||||
|
||||
/* Globals */
|
||||
struct globals {
|
||||
char *name_hashtable[NAME_HASH_PRIME + 1];
|
||||
common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1];
|
||||
status_node_t *status_hashtable[STATUS_HASH_PRIME + 1];
|
||||
};
|
||||
#define G (*ptr_to_globals)
|
||||
#define name_hashtable (G.name_hashtable )
|
||||
#define package_hashtable (G.package_hashtable)
|
||||
#define status_hashtable (G.status_hashtable )
|
||||
#define INIT_G() do { \
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Even numbers are for 'extras', like ored dependencies or null */
|
||||
enum edge_type_e {
|
||||
@@ -124,7 +135,7 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
|
||||
* shift amount is mod 24 because long int is 32 bit and data
|
||||
* to be shifted is 8, don't want to shift data to where it has
|
||||
* no effect*/
|
||||
hash_num += ((key[i] + key[i-1]) << ((key[i] * i) % 24));
|
||||
hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
|
||||
}
|
||||
*start = (unsigned) hash_num % hash_prime;
|
||||
*decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
|
||||
@@ -133,8 +144,8 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
|
||||
/* this adds the key to the hash table */
|
||||
static int search_name_hashtable(const char *key)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
make_hash(key, &probe_address, &probe_decrement, NAME_HASH_PRIME);
|
||||
while (name_hashtable[probe_address] != NULL) {
|
||||
@@ -155,8 +166,8 @@ static int search_name_hashtable(const char *key)
|
||||
*/
|
||||
static unsigned search_status_hashtable(const char *key)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
make_hash(key, &probe_address, &probe_decrement, STATUS_HASH_PRIME);
|
||||
while (status_hashtable[probe_address] != NULL) {
|
||||
@@ -312,11 +323,10 @@ static int test_version(const unsigned version1, const unsigned version2, const
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static int search_package_hashtable(const unsigned name, const unsigned version, const unsigned operator)
|
||||
{
|
||||
unsigned probe_address = 0;
|
||||
unsigned probe_decrement = 0;
|
||||
unsigned probe_address;
|
||||
unsigned probe_decrement;
|
||||
|
||||
make_hash(name_hashtable[name], &probe_address, &probe_decrement, PACKAGE_HASH_PRIME);
|
||||
while (package_hashtable[probe_address] != NULL) {
|
||||
@@ -410,10 +420,10 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
if ((edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS)
|
||||
&& (strcmp(field, field2) != 0)
|
||||
) {
|
||||
or_edge = xmalloc(sizeof(edge_t));
|
||||
or_edge = xzalloc(sizeof(edge_t));
|
||||
or_edge->type = edge_type + 1;
|
||||
or_edge->name = search_name_hashtable(field);
|
||||
or_edge->version = 0; // tracks the number of alternatives
|
||||
//or_edge->version = 0; // tracks the number of alternatives
|
||||
add_edge_to_node(parent_node, or_edge);
|
||||
}
|
||||
|
||||
@@ -439,17 +449,13 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
||||
if (offset_ch > 0) {
|
||||
if (strncmp(version, "=", offset_ch) == 0) {
|
||||
edge->operator = VER_EQUAL;
|
||||
}
|
||||
else if (strncmp(version, "<<", offset_ch) == 0) {
|
||||
} else if (strncmp(version, "<<", offset_ch) == 0) {
|
||||
edge->operator = VER_LESS;
|
||||
}
|
||||
else if (strncmp(version, "<=", offset_ch) == 0) {
|
||||
} else if (strncmp(version, "<=", offset_ch) == 0) {
|
||||
edge->operator = VER_LESS_EQUAL;
|
||||
}
|
||||
else if (strncmp(version, ">>", offset_ch) == 0) {
|
||||
} else if (strncmp(version, ">>", offset_ch) == 0) {
|
||||
edge->operator = VER_MORE;
|
||||
}
|
||||
else if (strncmp(version, ">=", offset_ch) == 0) {
|
||||
} else if (strncmp(version, ">=", offset_ch) == 0) {
|
||||
edge->operator = VER_MORE_EQUAL;
|
||||
} else {
|
||||
bb_error_msg_and_die("illegal operator");
|
||||
@@ -602,7 +608,7 @@ static unsigned fill_package_struct(char *control_buffer)
|
||||
&field_name, &field_value);
|
||||
|
||||
if (field_name == NULL) {
|
||||
goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement! */
|
||||
goto fill_package_struct_cleanup;
|
||||
}
|
||||
|
||||
field_num = index_in_strings(field_names, field_name);
|
||||
@@ -735,7 +741,6 @@ static const char *describe_status(int status_num)
|
||||
return "is not installed or flagged to be installed";
|
||||
}
|
||||
|
||||
|
||||
static void index_status_file(const char *filename)
|
||||
{
|
||||
FILE *status_file;
|
||||
@@ -745,7 +750,7 @@ static void index_status_file(const char *filename)
|
||||
unsigned status_num;
|
||||
|
||||
status_file = xfopen(filename, "r");
|
||||
while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) {
|
||||
while ((control_buffer = xmalloc_fgetline_str(status_file, "\n\n")) != NULL) {
|
||||
const unsigned package_num = fill_package_struct(control_buffer);
|
||||
if (package_num != -1) {
|
||||
status_node = xmalloc(sizeof(status_node_t));
|
||||
@@ -798,7 +803,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
int i = 0;
|
||||
|
||||
/* Update previously known packages */
|
||||
while ((control_buffer = xmalloc_fgets_str(old_status_file, "\n\n")) != NULL) {
|
||||
while ((control_buffer = xmalloc_fgetline_str(old_status_file, "\n\n")) != NULL) {
|
||||
tmp_string = strstr(control_buffer, "Package:");
|
||||
if (tmp_string == NULL) {
|
||||
continue;
|
||||
@@ -913,20 +918,16 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
fclose(old_status_file);
|
||||
fclose(new_status_file);
|
||||
|
||||
|
||||
/* Create a separate backfile to dpkg */
|
||||
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
|
||||
struct stat stat_buf;
|
||||
xstat("/var/lib/dpkg/status", &stat_buf);
|
||||
if (errno != ENOENT)
|
||||
bb_error_msg_and_die("cannot create backup status file");
|
||||
/* Its ok if renaming the status file fails because status
|
||||
* file doesnt exist, maybe we are starting from scratch */
|
||||
bb_error_msg("no status file found, creating new one");
|
||||
}
|
||||
|
||||
if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) {
|
||||
bb_error_msg_and_die("DANGER: cannot create status file, "
|
||||
"you need to manually repair your status file");
|
||||
}
|
||||
xrename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status");
|
||||
}
|
||||
|
||||
/* This function returns TRUE if the given package can satisfy a
|
||||
@@ -953,7 +954,7 @@ static int package_satisfies_dependency(int package, int depend_type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count - ?? */)
|
||||
{
|
||||
int *conflicts = NULL;
|
||||
int conflicts_num = 0;
|
||||
@@ -1156,9 +1157,9 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
||||
static char **create_list(const char *filename)
|
||||
{
|
||||
FILE *list_stream;
|
||||
char **file_list = NULL;
|
||||
char *line = NULL;
|
||||
int count = 0;
|
||||
char **file_list;
|
||||
char *line;
|
||||
int count;
|
||||
|
||||
/* don't use [xw]fopen here, handle error ourself */
|
||||
list_stream = fopen(filename, "r");
|
||||
@@ -1166,17 +1167,15 @@ static char **create_list(const char *filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((line = xmalloc_getline(list_stream)) != NULL) {
|
||||
file_list = NULL;
|
||||
count = 0;
|
||||
while ((line = xmalloc_fgetline(list_stream)) != NULL) {
|
||||
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
|
||||
file_list[count] = line;
|
||||
count++;
|
||||
file_list[count++] = line;
|
||||
file_list[count] = NULL;
|
||||
}
|
||||
fclose(list_stream);
|
||||
|
||||
if (count == 0) {
|
||||
return NULL;
|
||||
}
|
||||
file_list[count] = NULL;
|
||||
return file_list;
|
||||
}
|
||||
|
||||
@@ -1213,24 +1212,54 @@ static int remove_file_array(char **remove_names, char **exclude_names)
|
||||
return (remove_flag == 0);
|
||||
}
|
||||
|
||||
static int run_package_script(const char *package_name, const char *script_type)
|
||||
static void run_package_script_or_die(const char *package_name, const char *script_type)
|
||||
{
|
||||
struct stat path_stat;
|
||||
char *script_path;
|
||||
int result;
|
||||
|
||||
script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
|
||||
|
||||
/* If the file doesnt exist is isnt a fatal */
|
||||
result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
|
||||
/* If the file doesnt exist is isnt fatal */
|
||||
result = access(script_path, F_OK) ? EXIT_SUCCESS : system(script_path);
|
||||
free(script_path);
|
||||
return result;
|
||||
if (result)
|
||||
bb_error_msg_and_die("%s failed, exit code %d", script_type, result);
|
||||
}
|
||||
|
||||
/*
|
||||
The policy manual defines what scripts get called when and with
|
||||
what arguments. I realize that busybox does not support all of
|
||||
these scenarios, but it does support some of them; it does not,
|
||||
however, run them with any parameters in run_package_script_or_die().
|
||||
Here are the scripts:
|
||||
|
||||
preinst install
|
||||
preinst install <old_version>
|
||||
preinst upgrade <old_version>
|
||||
preinst abort_upgrade <new_version>
|
||||
postinst configure <most_recent_version>
|
||||
postinst abort-upgade <new_version>
|
||||
postinst abort-remove
|
||||
postinst abort-remove in-favour <package> <version>
|
||||
postinst abort-deconfigure in-favor <failed_install_package> removing <conflicting_package> <version>
|
||||
prerm remove
|
||||
prerm upgrade <new_version>
|
||||
prerm failed-upgrade <old_version>
|
||||
prerm remove in-favor <package> <new_version>
|
||||
prerm deconfigure in-favour <package> <version> removing <package> <version>
|
||||
postrm remove
|
||||
postrm purge
|
||||
postrm upgrade <new_version>
|
||||
postrm failed-upgrade <old_version>
|
||||
postrm abort-install
|
||||
postrm abort-install <old_version>
|
||||
postrm abort-upgrade <old_version>
|
||||
postrm disappear <overwriter> <version>
|
||||
*/
|
||||
static const char *const all_control_files[] = {
|
||||
"preinst", "postinst", "prerm", "postrm",
|
||||
"list", "md5sums", "shlibs", "conffiles",
|
||||
"config", "templates", NULL
|
||||
"config", "templates"
|
||||
};
|
||||
|
||||
static char **all_control_list(const char *package_name)
|
||||
@@ -1239,9 +1268,10 @@ static char **all_control_list(const char *package_name)
|
||||
char **remove_files;
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = xzalloc(sizeof(all_control_files));
|
||||
while (all_control_files[i]) {
|
||||
remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
|
||||
remove_files = xzalloc(sizeof(all_control_files) + sizeof(char*));
|
||||
while (i < ARRAY_SIZE(all_control_files)) {
|
||||
remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s",
|
||||
package_name, all_control_files[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -1314,27 +1344,26 @@ static void remove_package(const unsigned package_num, int noisy)
|
||||
if (noisy)
|
||||
printf("Removing %s (%s)...\n", package_name, package_version);
|
||||
|
||||
/* run prerm script */
|
||||
if (run_package_script(package_name, "prerm") != 0) {
|
||||
bb_error_msg_and_die("script failed, prerm failure");
|
||||
}
|
||||
/* Run prerm script */
|
||||
run_package_script_or_die(package_name, "prerm");
|
||||
|
||||
/* Create a list of files to remove, and a separate list of those to keep */
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
remove_files = create_list(list_name);
|
||||
|
||||
sprintf(conffile_name, "/var/lib/dpkg/info/%s.conffiles", package_name);
|
||||
sprintf(conffile_name, "/var/lib/dpkg/info/%s.%s", package_name, "conffiles");
|
||||
exclude_files = create_list(conffile_name);
|
||||
|
||||
/* Some directories can't be removed straight away, so do multiple passes */
|
||||
while (remove_file_array(remove_files, exclude_files)) /*repeat */;
|
||||
while (remove_file_array(remove_files, exclude_files))
|
||||
continue;
|
||||
free_array(exclude_files);
|
||||
free_array(remove_files);
|
||||
|
||||
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
|
||||
exclude_files = xzalloc(sizeof(char*) * 3);
|
||||
exclude_files[0] = xstrdup(conffile_name);
|
||||
exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
|
||||
exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = all_control_list(package_name);
|
||||
@@ -1343,7 +1372,9 @@ static void remove_package(const unsigned package_num, int noisy)
|
||||
free_array(remove_files);
|
||||
free_array(exclude_files);
|
||||
|
||||
/* rename <package>.conffile to <package>.list */
|
||||
/* rename <package>.conffiles to <package>.list
|
||||
* The conffiles control file isn't required in Debian packages, so don't
|
||||
* error out if it's missing. */
|
||||
rename(conffile_name, list_name);
|
||||
|
||||
/* Change package status */
|
||||
@@ -1361,13 +1392,11 @@ static void purge_package(const unsigned package_num)
|
||||
|
||||
printf("Purging %s (%s)...\n", package_name, package_version);
|
||||
|
||||
/* run prerm script */
|
||||
if (run_package_script(package_name, "prerm") != 0) {
|
||||
bb_error_msg_and_die("script failed, prerm failure");
|
||||
}
|
||||
/* Run prerm script */
|
||||
run_package_script_or_die(package_name, "prerm");
|
||||
|
||||
/* Create a list of files to remove */
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
remove_files = create_list(list_name);
|
||||
|
||||
exclude_files = xzalloc(sizeof(char*));
|
||||
@@ -1382,10 +1411,8 @@ static void purge_package(const unsigned package_num)
|
||||
free_array(remove_files);
|
||||
free(exclude_files);
|
||||
|
||||
/* run postrm script */
|
||||
if (run_package_script(package_name, "postrm") != 0) {
|
||||
bb_error_msg_and_die("postrm failure.. set status to what?");
|
||||
}
|
||||
/* Run postrm script */
|
||||
run_package_script_or_die(package_name, "postrm");
|
||||
|
||||
/* Change package status */
|
||||
set_status(status_num, "not-installed", 3);
|
||||
@@ -1475,8 +1502,8 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
char *list_filename;
|
||||
archive_handle_t *archive_handle;
|
||||
FILE *out_stream;
|
||||
llist_t *accept_list = NULL;
|
||||
int i = 0;
|
||||
llist_t *accept_list;
|
||||
int i;
|
||||
|
||||
/* If existing version, remove it first */
|
||||
if (strcmp(name_hashtable[get_status(status_num, 3)], "installed") == 0) {
|
||||
@@ -1490,11 +1517,13 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
}
|
||||
|
||||
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
|
||||
info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name);
|
||||
info_prefix = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "");
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_control(archive_handle);
|
||||
|
||||
while (all_control_files[i]) {
|
||||
accept_list = NULL;
|
||||
i = 0;
|
||||
while (i < ARRAY_SIZE(all_control_files)) {
|
||||
char *c = xasprintf("./%s", all_control_files[i]);
|
||||
llist_add_to(&accept_list, c);
|
||||
i++;
|
||||
@@ -1507,10 +1536,7 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Run the preinst prior to extracting */
|
||||
if (run_package_script(package_name, "preinst") != 0) {
|
||||
/* when preinst returns exit code != 0 then quit installation process */
|
||||
bb_error_msg_and_die("subprocess pre-installation script returned error");
|
||||
}
|
||||
run_package_script_or_die(package_name, "preinst");
|
||||
|
||||
/* Extract data.tar.gz to the root directory */
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
@@ -1521,7 +1547,7 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Create the list file */
|
||||
list_filename = xasprintf("/var/lib/dpkg/info/%s.list", package_name);
|
||||
list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
out_stream = xfopen(list_filename, "w");
|
||||
while (archive_handle->sub_archive->passed) {
|
||||
/* the leading . has been stripped by data_extract_all_prefix already */
|
||||
@@ -1548,17 +1574,16 @@ static void configure_package(deb_file_t *deb_file)
|
||||
printf("Setting up %s (%s)...\n", package_name, package_version);
|
||||
|
||||
/* Run the postinst script */
|
||||
if (run_package_script(package_name, "postinst") != 0) {
|
||||
/* TODO: handle failure gracefully */
|
||||
bb_error_msg_and_die("postinst failure.. set status to what?");
|
||||
}
|
||||
/* TODO: handle failure gracefully */
|
||||
run_package_script_or_die(package_name, "postinst");
|
||||
|
||||
/* Change status to reflect success */
|
||||
set_status(status_num, "install", 1);
|
||||
set_status(status_num, "installed", 3);
|
||||
}
|
||||
|
||||
int dpkg_main(int argc, char **argv);
|
||||
int dpkg_main(int argc, char **argv)
|
||||
int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dpkg_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
deb_file_t **deb_file = NULL;
|
||||
status_node_t *status_node;
|
||||
@@ -1579,6 +1604,8 @@ int dpkg_main(int argc, char **argv)
|
||||
OPT_unpack = 0x40,
|
||||
};
|
||||
|
||||
INIT_G();
|
||||
|
||||
opt = getopt32(argv, "CF:ilPru", &str_f);
|
||||
//if (opt & OPT_configure) ... // -C
|
||||
if (opt & OPT_force_ignore_depends) { // -F (--force in official dpkg)
|
||||
@@ -1590,16 +1617,11 @@ int dpkg_main(int argc, char **argv)
|
||||
//if (opt & OPT_purge) ... // -P
|
||||
//if (opt & OPT_remove) ... // -r
|
||||
//if (opt & OPT_unpack) ... // -u (--unpack in official dpkg)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* check for non-option argument if expected */
|
||||
if (!opt || (!argc && !(opt && OPT_list_installed)))
|
||||
if (!opt || (!argv[0] && !(opt && OPT_list_installed)))
|
||||
bb_show_usage();
|
||||
|
||||
name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
|
||||
package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
|
||||
status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
|
||||
|
||||
/* puts("(Reading database ... xxxxx files and directories installed.)"); */
|
||||
index_status_file("/var/lib/dpkg/status");
|
||||
|
||||
@@ -1693,7 +1715,7 @@ int dpkg_main(int argc, char **argv)
|
||||
|
||||
/* Check that the deb file arguments are installable */
|
||||
if (!(opt & OPT_force_ignore_depends)) {
|
||||
if (!check_deps(deb_file, 0, deb_count)) {
|
||||
if (!check_deps(deb_file, 0 /*, deb_count*/)) {
|
||||
bb_error_msg_and_die("dependency check failed");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
int dpkg_deb_main(int argc, char **argv);
|
||||
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
@@ -41,7 +41,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
#endif
|
||||
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
|
||||
+28
-11
@@ -686,7 +686,7 @@ static void check_match(IPos start, IPos match, int length)
|
||||
if (verbose > 1) {
|
||||
bb_error_msg("\\[%d,%d]", start - match, length);
|
||||
do {
|
||||
putc(G1.window[start++], stderr);
|
||||
fputc(G1.window[start++], stderr);
|
||||
} while (--length != 0);
|
||||
}
|
||||
}
|
||||
@@ -2025,26 +2025,43 @@ USE_DESKTOP(long long) int pack_gzip(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gzip_main(int argc, char **argv);
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
* -n --no-name
|
||||
* gzip: do not save the original file name and time stamp.
|
||||
* (The original name is always saved if the name had to be truncated.)
|
||||
* gunzip: do not restore the original file name/time even if present
|
||||
* (remove only the gzip suffix from the compressed file name).
|
||||
* This option is the default when decompressing.
|
||||
* -N --name
|
||||
* gzip: always save the original file name and time stamp (this is the default)
|
||||
* gunzip: restore the original file name and time stamp if present.
|
||||
*/
|
||||
|
||||
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
#if ENABLE_GUNZIP
|
||||
int gzip_main(int argc, char **argv)
|
||||
#else
|
||||
int gzip_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
#endif
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789" );
|
||||
option_mask32 &= 0x7; /* Clear -d, ignore -q, -0..9 */
|
||||
opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789n" );
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x8) // -d
|
||||
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
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x8) { // -d
|
||||
return gunzip_main(argc, argv);
|
||||
}
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
PTR_TO_GLOBALS = xzalloc(sizeof(struct globals) + sizeof(struct globals2))
|
||||
+ sizeof(struct globals);
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
G2.l_desc.dyn_tree = G2.dyn_ltree;
|
||||
G2.l_desc.static_tree = G2.static_ltree;
|
||||
G2.l_desc.extra_bits = extra_lbits;
|
||||
|
||||
@@ -28,43 +28,40 @@ lib-y:= \
|
||||
find_list_entry.o \
|
||||
init_handle.o
|
||||
|
||||
GUNZIP_FILES:= check_header_gzip.o decompress_unzip.o
|
||||
DPKG_FILES:= \
|
||||
get_header_ar.o \
|
||||
unpack_ar_archive.o \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
# open_transformer uses fork(). Compile it only if absolutely necessary
|
||||
lib-$(CONFIG_RPM) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += decompress_unzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += decompress_unzip.o get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
@@ -12,7 +12,7 @@ ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
|
||||
ssize_t size;
|
||||
|
||||
size = full_read(archive_handle->src_fd, buf, count);
|
||||
if (size != 0 && size != count) {
|
||||
if (size != 0 && size != (ssize_t)count) {
|
||||
bb_error_msg_and_die("short read: %u of %u",
|
||||
(unsigned)size, (unsigned)count);
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip_or_die */
|
||||
|
||||
void check_header_gzip_or_die(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
struct {
|
||||
unsigned char method;
|
||||
unsigned char flags;
|
||||
unsigned int mtime;
|
||||
unsigned char xtra_flags;
|
||||
unsigned char os_flags;
|
||||
} formatted;
|
||||
} header;
|
||||
|
||||
xread(src_fd, header.raw, 8);
|
||||
|
||||
/* Check the compression method */
|
||||
if (header.formatted.method != 8) {
|
||||
bb_error_msg_and_die("unknown compression method %d",
|
||||
header.formatted.method);
|
||||
}
|
||||
|
||||
if (header.formatted.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned extra_short;
|
||||
|
||||
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
/* Ignore extra field */
|
||||
xread_char(src_fd);
|
||||
extra_short--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discard original name if any */
|
||||
if (header.formatted.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formatted.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
//#include <sys/types.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
void data_align(archive_handle_t *archive_handle, unsigned boundary)
|
||||
{
|
||||
const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
|
||||
@@ -20,7 +20,7 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the existing entry if it exists */
|
||||
/* Remove the entry if it exists */
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
@@ -112,7 +112,22 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
|
||||
if (file_header->uname) {
|
||||
struct passwd *pwd = getpwnam(file_header->uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->gname) {
|
||||
struct group *grp = getgrnam(file_header->gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
lchown(file_header->name, uid, gid);
|
||||
#else
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
#endif
|
||||
}
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
||||
#define RETVAL_SHORT_WRITE (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
@@ -54,22 +54,26 @@
|
||||
|
||||
/* This is what we know about each Huffman coding group */
|
||||
struct group_data {
|
||||
/* We have an extra slot at the end of limit[] for a sentinal value. */
|
||||
/* We have an extra slot at the end of limit[] for a sentinel value. */
|
||||
int limit[MAX_HUFCODE_BITS+1], base[MAX_HUFCODE_BITS], permute[MAX_SYMBOLS];
|
||||
int minLen, maxLen;
|
||||
};
|
||||
|
||||
/* Structure holding all the housekeeping data, including IO buffers and
|
||||
memory that persists between calls to bunzip */
|
||||
|
||||
* memory that persists between calls to bunzip
|
||||
* Found the most used member:
|
||||
* cat this_file.c | sed -e 's/"/ /g' -e "s/'/ /g" | xargs -n1 \
|
||||
* | grep 'bd->' | sed 's/^.*bd->/bd->/' | sort | $PAGER
|
||||
* and moved it (inbufBitCount) to offset 0.
|
||||
*/
|
||||
struct bunzip_data {
|
||||
/* State for interrupting output loop */
|
||||
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
|
||||
|
||||
/* I/O tracking data (file handles, buffers, positions, etc.) */
|
||||
unsigned inbufBitCount, inbufBits;
|
||||
int in_fd, out_fd, inbufCount, inbufPos /*, outbufPos*/;
|
||||
unsigned char *inbuf /*,*outbuf*/;
|
||||
unsigned inbufBitCount, inbufBits;
|
||||
|
||||
/* State for interrupting output loop */
|
||||
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
|
||||
|
||||
/* The CRC values stored in the block header and calculated from the data */
|
||||
uint32_t headerCRC, totalCRC, writeCRC;
|
||||
@@ -80,7 +84,7 @@ struct bunzip_data {
|
||||
/* For I/O error handling */
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Big things go last (register-relative addressing can be larger for big offsets */
|
||||
/* Big things go last (register-relative addressing can be larger for big offsets) */
|
||||
uint32_t crc32Table[256];
|
||||
unsigned char selectors[32768]; /* nSelectors=15 bits */
|
||||
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
||||
@@ -91,17 +95,15 @@ struct bunzip_data {
|
||||
/* Return the next nnn bits of input. All reads from the compressed input
|
||||
are done through this function. All reads are big endian */
|
||||
|
||||
static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
static unsigned get_bits(bunzip_data *bd, int bits_wanted)
|
||||
{
|
||||
unsigned bits = 0;
|
||||
|
||||
/* If we need to get more data from the byte buffer, do so. (Loop getting
|
||||
one byte at a time to enforce endianness and avoid unaligned access.) */
|
||||
|
||||
while (bd->inbufBitCount < bits_wanted) {
|
||||
while ((int)(bd->inbufBitCount) < bits_wanted) {
|
||||
|
||||
/* If we need to read more data from file into byte buffer, do so */
|
||||
|
||||
if (bd->inbufPos == bd->inbufCount) {
|
||||
/* if "no input fd" case: in_fd == -1, read fails, we jump */
|
||||
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
|
||||
@@ -111,7 +113,6 @@ static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
}
|
||||
|
||||
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
|
||||
|
||||
if (bd->inbufBitCount >= 24) {
|
||||
bits = bd->inbufBits & ((1 << bd->inbufBitCount) - 1);
|
||||
bits_wanted -= bd->inbufBitCount;
|
||||
@@ -120,13 +121,11 @@ static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
}
|
||||
|
||||
/* Grab next 8 bits of input from buffer. */
|
||||
|
||||
bd->inbufBits = (bd->inbufBits<<8) | bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount += 8;
|
||||
}
|
||||
|
||||
/* Calculate result */
|
||||
|
||||
bd->inbufBitCount -= bits_wanted;
|
||||
bits |= (bd->inbufBits >> bd->inbufBitCount) & ((1 << bits_wanted) - 1);
|
||||
|
||||
@@ -134,7 +133,6 @@ static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
}
|
||||
|
||||
/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
|
||||
|
||||
static int get_next_block(bunzip_data *bd)
|
||||
{
|
||||
struct group_data *hufGroup;
|
||||
@@ -148,13 +146,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
selectors = bd->selectors;
|
||||
|
||||
/* Reset longjmp I/O error handling */
|
||||
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
|
||||
/* Read in header signature and CRC, then validate signature.
|
||||
(last block signature means CRC is for whole file, return now) */
|
||||
|
||||
i = get_bits(bd, 24);
|
||||
j = get_bits(bd, 24);
|
||||
bd->headerCRC = get_bits(bd, 32);
|
||||
@@ -164,17 +160,15 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* We can add support for blockRandomised if anybody complains. There was
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
|
||||
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
|
||||
origPtr = get_bits(bd, 24);
|
||||
if (origPtr > dbufSize) return RETVAL_DATA_ERROR;
|
||||
if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
symbols to deal with, and writes a sparse bitfield indicating which
|
||||
values were present. We make a translation table to convert the symbols
|
||||
back to the corresponding bytes. */
|
||||
|
||||
t = get_bits(bd, 16);
|
||||
symTotal = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
@@ -187,7 +181,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
|
||||
/* How many different Huffman coding groups does this block use? */
|
||||
|
||||
groupCount = get_bits(bd, 3);
|
||||
if (groupCount < 2 || groupCount > MAX_GROUPS)
|
||||
return RETVAL_DATA_ERROR;
|
||||
@@ -196,19 +189,16 @@ static int get_next_block(bunzip_data *bd)
|
||||
group. Read in the group selector list, which is stored as MTF encoded
|
||||
bit runs. (MTF=Move To Front, as each value is used it's moved to the
|
||||
start of the list.) */
|
||||
|
||||
nSelectors = get_bits(bd, 15);
|
||||
if (!nSelectors) return RETVAL_DATA_ERROR;
|
||||
for (i = 0; i < groupCount; i++) mtfSymbol[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
|
||||
/* Get next value */
|
||||
|
||||
for (j = 0; get_bits(bd, 1); j++)
|
||||
if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
if (j >= groupCount) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* Decode MTF to get the next selector */
|
||||
|
||||
uc = mtfSymbol[j];
|
||||
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
mtfSymbol[0] = selectors[i] = uc;
|
||||
@@ -216,10 +206,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
/* Read the Huffman coding tables for each group, which code for symTotal
|
||||
literal symbols, plus two run symbols (RUNA, RUNB) */
|
||||
|
||||
symCount = symTotal + 2;
|
||||
for (j = 0; j < groupCount; j++) {
|
||||
unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
|
||||
unsigned char length[MAX_SYMBOLS];
|
||||
/* 8 bits is ALMOST enough for temp[], see below */
|
||||
unsigned temp[MAX_HUFCODE_BITS+1];
|
||||
int minLen, maxLen, pp;
|
||||
|
||||
/* Read Huffman code lengths for each symbol. They're stored in
|
||||
@@ -228,7 +219,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
(Subtracting 1 before the loop and then adding it back at the end is
|
||||
an optimization that makes the test inside the loop simpler: symbol
|
||||
length 0 becomes negative, so an unsigned inequality catches it.) */
|
||||
|
||||
t = get_bits(bd, 5) - 1;
|
||||
for (i = 0; i < symCount; i++) {
|
||||
for (;;) {
|
||||
@@ -238,7 +228,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* If first bit is 0, stop. Else second bit indicates whether
|
||||
to increment or decrement the value. Optimization: grab 2
|
||||
bits and unget the second if the first was 0. */
|
||||
|
||||
k = get_bits(bd, 2);
|
||||
if (k < 2) {
|
||||
bd->inbufBitCount++;
|
||||
@@ -246,17 +235,14 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
|
||||
/* Add one if second bit 1, else subtract 1. Avoids if/else */
|
||||
|
||||
t += (((k+1) & 2) - 1);
|
||||
}
|
||||
|
||||
/* Correct for the initial -1, to get the final symbol length */
|
||||
|
||||
length[i] = t + 1;
|
||||
}
|
||||
|
||||
/* Find largest and smallest lengths in this group */
|
||||
|
||||
minLen = maxLen = length[0];
|
||||
for (i = 1; i < symCount; i++) {
|
||||
if (length[i] > maxLen) maxLen = length[i];
|
||||
@@ -273,7 +259,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
* number of bits can have. This is how the Huffman codes can vary in
|
||||
* length: each code with a value>limit[length] needs another bit.
|
||||
*/
|
||||
|
||||
hufGroup = bd->groups + j;
|
||||
hufGroup->minLen = minLen;
|
||||
hufGroup->maxLen = maxLen;
|
||||
@@ -281,12 +266,10 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Note that minLen can't be smaller than 1, so we adjust the base
|
||||
and limit array pointers so we're not always wasting the first
|
||||
entry. We do this again when using them (during symbol decoding).*/
|
||||
|
||||
base = hufGroup->base - 1;
|
||||
limit = hufGroup->limit - 1;
|
||||
|
||||
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
|
||||
|
||||
pp = 0;
|
||||
for (i = minLen; i <= maxLen; i++) {
|
||||
temp[i] = limit[i] = 0;
|
||||
@@ -296,14 +279,14 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
|
||||
/* Count symbols coded for at each bit length */
|
||||
|
||||
/* NB: in pathological cases, temp[8] can end ip being 256.
|
||||
* That's why uint8_t is too small for temp[]. */
|
||||
for (i = 0; i < symCount; i++) temp[length[i]]++;
|
||||
|
||||
/* Calculate limit[] (the largest symbol-coding value at each bit
|
||||
* length, which is (previous limit<<1)+symbols at this level), and
|
||||
* base[] (number of symbols to ignore at each bit length, which is
|
||||
* limit minus the cumulative count of symbols coded for already). */
|
||||
|
||||
pp = t = 0;
|
||||
for (i = minLen; i < maxLen; i++) {
|
||||
pp += temp[i];
|
||||
@@ -314,25 +297,24 @@ static int get_next_block(bunzip_data *bd)
|
||||
each level we're really only interested in the first few bits,
|
||||
so here we set all the trailing to-be-ignored bits to 1 so they
|
||||
don't affect the value>limit[length] comparison. */
|
||||
|
||||
limit[i] = (pp << (maxLen - i)) - 1;
|
||||
pp <<= 1;
|
||||
t += temp[i];
|
||||
base[i+1] = pp - t;
|
||||
}
|
||||
limit[maxLen+1] = INT_MAX; /* Sentinal value for reading next sym. */
|
||||
limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */
|
||||
limit[maxLen] = pp + temp[maxLen] - 1;
|
||||
base[minLen] = 0;
|
||||
}
|
||||
|
||||
/* We've finished reading and digesting the block header. Now read this
|
||||
block's Huffman coded symbols from the file and undo the Huffman coding
|
||||
and run length encoding, saving the result into dbuf[dbufCount++]=uc */
|
||||
and run length encoding, saving the result into dbuf[dbufCount++] = uc */
|
||||
|
||||
/* Initialize symbol occurrence counters and symbol Move To Front table */
|
||||
|
||||
memset(byteCount, 0, sizeof(byteCount)); /* smaller, maybe slower? */
|
||||
for (i = 0; i < 256; i++) {
|
||||
byteCount[i] = 0;
|
||||
//byteCount[i] = 0;
|
||||
mtfSymbol[i] = (unsigned char)i;
|
||||
}
|
||||
|
||||
@@ -341,8 +323,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
runPos = dbufCount = selector = 0;
|
||||
for (;;) {
|
||||
|
||||
/* fetch next Huffman coding group from list. */
|
||||
|
||||
/* Fetch next Huffman coding group from list. */
|
||||
symCount = GROUP_SIZE - 1;
|
||||
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup = bd->groups + selectors[selector++];
|
||||
@@ -361,8 +342,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
dry). The following (up to got_huff_bits:) is equivalent to
|
||||
j = get_bits(bd, hufGroup->maxLen);
|
||||
*/
|
||||
|
||||
while (bd->inbufBitCount < hufGroup->maxLen) {
|
||||
while ((int)(bd->inbufBitCount) < hufGroup->maxLen) {
|
||||
if (bd->inbufPos == bd->inbufCount) {
|
||||
j = get_bits(bd, hufGroup->maxLen);
|
||||
goto got_huff_bits;
|
||||
@@ -376,13 +356,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
got_huff_bits:
|
||||
|
||||
/* Figure how how many bits are in next symbol and unget extras */
|
||||
|
||||
i = hufGroup->minLen;
|
||||
while (j > limit[i]) ++i;
|
||||
bd->inbufBitCount += (hufGroup->maxLen - i);
|
||||
|
||||
/* Huffman decode value to get nextSym (with bounds checking) */
|
||||
|
||||
if (i > hufGroup->maxLen)
|
||||
return RETVAL_DATA_ERROR;
|
||||
j = (j >> (hufGroup->maxLen - i)) - base[i];
|
||||
@@ -394,11 +372,9 @@ static int get_next_block(bunzip_data *bd)
|
||||
byte, or a repeated run of the most recent literal byte. First,
|
||||
check if nextSym indicates a repeated run, and if so loop collecting
|
||||
how many times to repeat the last literal. */
|
||||
|
||||
if ((unsigned)nextSym <= SYMBOL_RUNB) { /* RUNA or RUNB */
|
||||
|
||||
/* If this is the start of a new run, zero out counter */
|
||||
|
||||
if (!runPos) {
|
||||
runPos = 1;
|
||||
t = 0;
|
||||
@@ -411,7 +387,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
the basic or 0/1 method (except all bits 0, which would use no
|
||||
symbols, but a run of length 0 doesn't mean anything in this
|
||||
context). Thus space is saved. */
|
||||
|
||||
t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
|
||||
if (runPos < dbufSize) runPos <<= 1;
|
||||
goto end_of_huffman_loop;
|
||||
@@ -421,7 +396,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
how many times to repeat the last literal, so append that many
|
||||
copies to our buffer of decoded symbols (dbuf) now. (The last
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
|
||||
if (runPos) {
|
||||
runPos = 0;
|
||||
if (dbufCount + t >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
@@ -432,7 +406,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
|
||||
/* Is this the terminating symbol? */
|
||||
|
||||
if (nextSym > symTotal) break;
|
||||
|
||||
/* At this point, nextSym indicates a new literal character. Subtract
|
||||
@@ -442,7 +415,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
first symbol in the mtf array, position 0, would have been handled
|
||||
as part of a run above. Therefore 1 unused mtf position minus
|
||||
2 non-literal nextSym values equals -1.) */
|
||||
|
||||
if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
i = nextSym - 1;
|
||||
uc = mtfSymbol[i];
|
||||
@@ -451,7 +423,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
* small number of symbols, and are bound by 256 in any case, using
|
||||
* memmove here would typically be bigger and slower due to function
|
||||
* call overhead and other assorted setup costs. */
|
||||
|
||||
do {
|
||||
mtfSymbol[i] = mtfSymbol[i-1];
|
||||
} while (--i);
|
||||
@@ -459,13 +430,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
uc = symToByte[uc];
|
||||
|
||||
/* We have our literal byte. Save it into dbuf. */
|
||||
|
||||
byteCount[uc]++;
|
||||
dbuf[dbufCount++] = (unsigned)uc;
|
||||
|
||||
/* Skip group initialization if we're not done with this group. Done
|
||||
* this way to avoid compiler warning. */
|
||||
|
||||
end_of_huffman_loop:
|
||||
if (symCount--) goto continue_this_group;
|
||||
}
|
||||
@@ -478,7 +447,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
*/
|
||||
|
||||
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
k = j + byteCount[i];
|
||||
@@ -487,7 +455,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
|
||||
/* Figure out what order dbuf would be in if we sorted it. */
|
||||
|
||||
for (i = 0; i < dbufCount; i++) {
|
||||
uc = (unsigned char)(dbuf[i] & 0xff);
|
||||
dbuf[byteCount[uc]] |= (i << 8);
|
||||
@@ -497,11 +464,10 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Decode first byte by hand to initialize "previous" byte. Note that it
|
||||
doesn't get output, and if the first three characters are identical
|
||||
it doesn't qualify as a run (hence writeRunCountdown=5). */
|
||||
|
||||
if (dbufCount) {
|
||||
if (origPtr >= dbufCount) return RETVAL_DATA_ERROR;
|
||||
if ((int)origPtr >= dbufCount) return RETVAL_DATA_ERROR;
|
||||
bd->writePos = dbuf[origPtr];
|
||||
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
|
||||
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
|
||||
bd->writePos >>= 8;
|
||||
bd->writeRunCountdown = 5;
|
||||
}
|
||||
@@ -516,7 +482,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
error (all errors are negative numbers). If out_fd!=-1, outbuf and len
|
||||
are ignored, data is written to out_fd and return is RETVAL_OK or error.
|
||||
*/
|
||||
|
||||
int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
{
|
||||
const unsigned *dbuf;
|
||||
@@ -533,34 +498,28 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* We will always have pending decoded data to write into the output
|
||||
buffer unless this is the very first call (in which case we haven't
|
||||
Huffman-decoded a block into the intermediate buffer yet). */
|
||||
|
||||
if (bd->writeCopies) {
|
||||
|
||||
/* Inside the loop, writeCopies means extra copies (beyond 1) */
|
||||
|
||||
--bd->writeCopies;
|
||||
|
||||
/* Loop outputting bytes */
|
||||
|
||||
for (;;) {
|
||||
|
||||
/* If the output buffer is full, snapshot state and return */
|
||||
|
||||
if (gotcount >= len) {
|
||||
bd->writePos =pos;
|
||||
bd->writePos = pos;
|
||||
bd->writeCurrent = current;
|
||||
bd->writeCopies++;
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Write next byte into output buffer, updating CRC */
|
||||
|
||||
outbuf[gotcount++] = current;
|
||||
bd->writeCRC = (bd->writeCRC << 8)
|
||||
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
|
||||
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
|
||||
|
||||
/* Loop now if we're outputting multiple copies of this byte */
|
||||
|
||||
if (bd->writeCopies) {
|
||||
--bd->writeCopies;
|
||||
continue;
|
||||
@@ -573,47 +532,40 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
current = pos & 0xff;
|
||||
pos >>= 8;
|
||||
|
||||
/* After 3 consecutive copies of the same byte, the 4th is a repeat
|
||||
count. We count down from 4 instead
|
||||
/* After 3 consecutive copies of the same byte, the 4th
|
||||
* is a repeat count. We count down from 4 instead
|
||||
* of counting up because testing for non-zero is faster */
|
||||
|
||||
if (--bd->writeRunCountdown) {
|
||||
if (current != previous)
|
||||
bd->writeRunCountdown = 4;
|
||||
} else {
|
||||
|
||||
/* We have a repeated run, this byte indicates the count */
|
||||
|
||||
bd->writeCopies = current;
|
||||
current = previous;
|
||||
bd->writeRunCountdown = 5;
|
||||
|
||||
/* Sometimes there are just 3 bytes (run length 0) */
|
||||
|
||||
if (!bd->writeCopies) goto decode_next_byte;
|
||||
|
||||
/* Subtract the 1 copy we'd output anyway to get extras */
|
||||
|
||||
--bd->writeCopies;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decompression of this block completed successfully */
|
||||
|
||||
bd->writeCRC = ~bd->writeCRC;
|
||||
bd->totalCRC = ((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ bd->writeCRC;
|
||||
|
||||
/* If this block had a CRC error, force file level CRC error. */
|
||||
|
||||
if (bd->writeCRC != bd->headerCRC) {
|
||||
bd->totalCRC = bd->headerCRC+1;
|
||||
bd->totalCRC = bd->headerCRC + 1;
|
||||
return RETVAL_LAST_BLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
/* Refill the intermediate buffer by Huffman-decoding next block of input */
|
||||
/* (previous is just a convenient unused temp variable here) */
|
||||
|
||||
previous = get_next_block(bd);
|
||||
if (previous) {
|
||||
bd->writeCount = previous;
|
||||
@@ -625,7 +577,6 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
goto decode_next_byte;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
|
||||
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
|
||||
ignored, and data is read from file handle into temporary buffer. */
|
||||
@@ -633,7 +584,6 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
|
||||
should work for NOFORK applets too, we must be extremely careful to not leak
|
||||
any allocations! */
|
||||
|
||||
int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
|
||||
int len)
|
||||
{
|
||||
@@ -644,16 +594,13 @@ int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
|
||||
};
|
||||
|
||||
/* Figure out how much data to allocate */
|
||||
|
||||
i = sizeof(bunzip_data);
|
||||
if (in_fd != -1) i += IOBUF_SIZE;
|
||||
|
||||
/* Allocate bunzip_data. Most fields initialize to zero. */
|
||||
|
||||
bd = *bdp = xzalloc(i);
|
||||
|
||||
/* Setup input buffer */
|
||||
|
||||
bd->in_fd = in_fd;
|
||||
if (-1 == in_fd) {
|
||||
/* in this case, bd->inbuf is read-only */
|
||||
@@ -663,22 +610,18 @@ int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
|
||||
bd->inbuf = (unsigned char *)(bd + 1);
|
||||
|
||||
/* Init the CRC32 table (big endian) */
|
||||
|
||||
crc32_filltable(bd->crc32Table, 1);
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
|
||||
/* Ensure that file starts with "BZh['1'-'9']." */
|
||||
|
||||
i = get_bits(bd, 32);
|
||||
if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
|
||||
/* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of
|
||||
uncompressed data. Allocate intermediate buffer for block. */
|
||||
|
||||
bd->dbufSize = 100000 * (i - BZh0);
|
||||
|
||||
/* Cannot use xmalloc - may leak bd in NOFORK case! */
|
||||
@@ -698,7 +641,6 @@ void dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
{
|
||||
@@ -713,8 +655,8 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
for (;;) {
|
||||
i = read_bunzip(bd, outbuf, IOBUF_SIZE);
|
||||
if (i <= 0) break;
|
||||
if (i != safe_write(dst_fd, outbuf, i)) {
|
||||
i = RETVAL_UNEXPECTED_OUTPUT_EOF;
|
||||
if (i != full_write(dst_fd, outbuf, i)) {
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
break;
|
||||
}
|
||||
USE_DESKTOP(total_written += i;)
|
||||
@@ -725,14 +667,14 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
|
||||
if (i == RETVAL_LAST_BLOCK) {
|
||||
if (bd->headerCRC != bd->totalCRC) {
|
||||
bb_error_msg("data integrity error when decompressing");
|
||||
bb_error_msg("CRC error");
|
||||
} else {
|
||||
i = RETVAL_OK;
|
||||
}
|
||||
} else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
||||
bb_error_msg("compressed file ends unexpectedly");
|
||||
} else if (i == RETVAL_SHORT_WRITE) {
|
||||
bb_error_msg("short write");
|
||||
} else {
|
||||
bb_error_msg("decompression failed");
|
||||
bb_error_msg("bunzip error %d", i);
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
free(outbuf);
|
||||
@@ -755,9 +697,9 @@ int main(int argc, char **argv)
|
||||
char c;
|
||||
|
||||
if (i < 0)
|
||||
fprintf(stderr,"%s\n", bunzip_errors[-i]);
|
||||
else if (read(0, &c, 1))
|
||||
fprintf(stderr,"Trailing garbage ignored\n");
|
||||
fprintf(stderr, "%s\n", bunzip_errors[-i]);
|
||||
else if (read(STDIN_FILENO, &c, 1))
|
||||
fprintf(stderr, "Trailing garbage ignored\n");
|
||||
return -i;
|
||||
}
|
||||
#endif
|
||||
@@ -282,14 +282,16 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
|
||||
prob =
|
||||
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
mi = 1;
|
||||
rc_update_bit_0(rc, prob);
|
||||
prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE
|
||||
* ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
||||
+ (previous_byte >> (8 - lc)))));
|
||||
prob = (p + LZMA_LITERAL
|
||||
+ (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
||||
+ (previous_byte >> (8 - lc))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (state >= LZMA_NUM_LIT_STATES) {
|
||||
int match_byte;
|
||||
@@ -304,35 +306,37 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
prob_lit = prob + 0x100 + bit + mi;
|
||||
if (rc_get_bit(rc, prob_lit, &mi)) {
|
||||
if (!bit)
|
||||
break;
|
||||
} else {
|
||||
if (bit)
|
||||
break;
|
||||
}
|
||||
bit ^= (rc_get_bit(rc, prob_lit, &mi) << 8); /* 0x100 or 0 */
|
||||
if (bit)
|
||||
break;
|
||||
} while (mi < 0x100);
|
||||
}
|
||||
while (mi < 0x100) {
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
}
|
||||
previous_byte = (uint8_t) mi;
|
||||
|
||||
state -= 3;
|
||||
if (state < 4-3)
|
||||
state = 0;
|
||||
if (state >= 10-3)
|
||||
state -= 6-3;
|
||||
|
||||
previous_byte = (uint8_t) mi;
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
one_byte1:
|
||||
buffer[buffer_pos++] = previous_byte;
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
if (state < 4)
|
||||
state = 0;
|
||||
else if (state < 10)
|
||||
state -= 3;
|
||||
else
|
||||
state -= 6;
|
||||
#else
|
||||
len = 1;
|
||||
goto one_byte2;
|
||||
#endif
|
||||
} else {
|
||||
int offset;
|
||||
uint16_t *prob_len;
|
||||
@@ -352,24 +356,23 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
prob = (p + LZMA_IS_REP_0_LONG
|
||||
+ (state << LZMA_NUM_POS_BITS_MAX) + pos_state);
|
||||
+ (state << LZMA_NUM_POS_BITS_MAX)
|
||||
+ pos_state
|
||||
);
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
buffer[buffer_pos++] = previous_byte;
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
continue;
|
||||
goto one_byte1;
|
||||
#else
|
||||
len = 1;
|
||||
goto string;
|
||||
#endif
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
}
|
||||
@@ -405,7 +408,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_LOW
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
|
||||
offset = 0;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
} else {
|
||||
@@ -414,14 +417,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_MID
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
|
||||
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits = LZMA_LEN_NUM_MID_BITS;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
prob_len = prob + LZMA_LEN_HIGH;
|
||||
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
||||
+ (1 << LZMA_LEN_NUM_MID_BITS));
|
||||
+ (1 << LZMA_LEN_NUM_MID_BITS));
|
||||
num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
||||
}
|
||||
}
|
||||
@@ -432,12 +435,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int pos_slot;
|
||||
|
||||
state += LZMA_NUM_LIT_STATES;
|
||||
prob =
|
||||
p + LZMA_POS_SLOT +
|
||||
((len <
|
||||
LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
prob = p + LZMA_POS_SLOT +
|
||||
((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
&pos_slot);
|
||||
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
||||
@@ -468,17 +469,18 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
len += LZMA_MATCH_MIN_LEN;
|
||||
|
||||
SKIP_FEATURE_LZMA_FAST(string:)
|
||||
do {
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
SKIP_FEATURE_LZMA_FAST(one_byte2:)
|
||||
buffer[buffer_pos++] = previous_byte;
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
@@ -487,8 +489,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
rc_free(rc);
|
||||
return -1;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,11 +13,14 @@
|
||||
*/
|
||||
char filter_accept_reject_list(archive_handle_t *archive_handle)
|
||||
{
|
||||
const char *key = archive_handle->file_header->name;
|
||||
const llist_t *reject_entry = find_list_entry2(archive_handle->reject, key);
|
||||
const char *key;
|
||||
const llist_t *reject_entry;
|
||||
const llist_t *accept_entry;
|
||||
|
||||
key = archive_handle->file_header->name;
|
||||
|
||||
/* If the key is in a reject list fail */
|
||||
reject_entry = find_list_entry2(archive_handle->reject, key);
|
||||
if (reject_entry) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ const llist_t *find_list_entry2(const llist_t *list, const char *filename)
|
||||
if (*c++ == '/') pattern_slash_cnt++;
|
||||
c = filename;
|
||||
d = buf;
|
||||
/* paranoia is better that buffer overflows */
|
||||
/* paranoia is better than buffer overflows */
|
||||
while (*c && d != buf + sizeof(buf)-1) {
|
||||
if (*c == '/' && --pattern_slash_cnt < 0)
|
||||
break;
|
||||
|
||||
@@ -7,71 +7,33 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
typedef struct hardlinks_s {
|
||||
char *name;
|
||||
int inode;
|
||||
struct hardlinks_s *next;
|
||||
typedef struct hardlinks_t {
|
||||
struct hardlinks_t *next;
|
||||
int inode; /* TODO: must match maj/min too! */
|
||||
int mode ;
|
||||
int mtime; /* These three are useful only in corner case */
|
||||
int uid ; /* of hardlinks with zero size body */
|
||||
int gid ;
|
||||
char name[1];
|
||||
} hardlinks_t;
|
||||
|
||||
char get_header_cpio(archive_handle_t *archive_handle)
|
||||
{
|
||||
static hardlinks_t *saved_hardlinks = NULL;
|
||||
static unsigned pending_hardlinks = 0;
|
||||
static int inode;
|
||||
static hardlinks_t *saved_hardlinks_created = NULL;
|
||||
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
char dummy[16];
|
||||
int major, minor, nlink;
|
||||
|
||||
if (pending_hardlinks) { /* Deal with any pending hardlinks */
|
||||
hardlinks_t *tmp, *oldtmp;
|
||||
|
||||
tmp = saved_hardlinks;
|
||||
oldtmp = NULL;
|
||||
|
||||
file_header->link_target = file_header->name;
|
||||
file_header->size = 0;
|
||||
|
||||
while (tmp) {
|
||||
if (tmp->inode != inode) {
|
||||
tmp = tmp->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
file_header->name = tmp->name;
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
}
|
||||
|
||||
pending_hardlinks--;
|
||||
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free(oldtmp->name);
|
||||
free(oldtmp);
|
||||
if (oldtmp == saved_hardlinks)
|
||||
saved_hardlinks = tmp;
|
||||
}
|
||||
|
||||
file_header->name = file_header->link_target;
|
||||
|
||||
if (pending_hardlinks > 1) {
|
||||
bb_error_msg("error resolving hardlink: archive made by GNU cpio 2.0-2.2?");
|
||||
}
|
||||
|
||||
/* No more pending hardlinks, read next file entry */
|
||||
pending_hardlinks = 0;
|
||||
}
|
||||
int namesize;
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
|
||||
/* There can be padding before archive header */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
if (archive_xread_all_eof(archive_handle, (unsigned char*)cpio_header, 110) == 0) {
|
||||
return EXIT_FAILURE;
|
||||
goto create_hardlinks;
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
@@ -81,17 +43,19 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
|
||||
}
|
||||
|
||||
{
|
||||
unsigned long tmpsize;
|
||||
sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
|
||||
dummy, &inode, (unsigned int*)&file_header->mode,
|
||||
(unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
|
||||
&nlink, &file_header->mtime, &tmpsize,
|
||||
dummy, &major, &minor, &namesize, dummy);
|
||||
file_header->size = tmpsize;
|
||||
}
|
||||
sscanf(cpio_header + 6,
|
||||
"%8x" "%8x" "%8x" "%8x"
|
||||
"%8x" "%8x" "%8x" /*maj,min:*/ "%16c"
|
||||
/*rmaj,rmin:*/"%8x" "%8x" "%8x" /*chksum:*/ "%8c",
|
||||
&inode, &mode, &uid, &gid,
|
||||
&nlink, &mtime, &size, dummy,
|
||||
&major, &minor, &namesize, dummy);
|
||||
file_header->mode = mode;
|
||||
file_header->uid = uid;
|
||||
file_header->gid = gid;
|
||||
file_header->mtime = mtime;
|
||||
file_header->size = size;
|
||||
|
||||
free(file_header->name);
|
||||
file_header->name = xzalloc(namesize + 1);
|
||||
/* Read in filename */
|
||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||
@@ -101,25 +65,9 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
|
||||
/* Always round up */
|
||||
printf("%d blocks\n", (int) (archive_handle->offset % 512 ?
|
||||
archive_handle->offset / 512 + 1 :
|
||||
archive_handle->offset / 512
|
||||
));
|
||||
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
hardlinks_t *oldtmp = NULL;
|
||||
while (tmp) {
|
||||
bb_error_msg("%s not created: cannot resolve hardlink", tmp->name);
|
||||
oldtmp = tmp;
|
||||
tmp = tmp->next;
|
||||
free(oldtmp->name);
|
||||
free(oldtmp);
|
||||
}
|
||||
saved_hardlinks = NULL;
|
||||
pending_hardlinks = 0;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
/* Always round up. ">> 9" divides by 512 */
|
||||
printf("%"OFF_FMT"u blocks\n", (archive_handle->offset + 511) >> 9);
|
||||
goto create_hardlinks;
|
||||
}
|
||||
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
@@ -130,25 +78,33 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
} else {
|
||||
file_header->link_target = NULL;
|
||||
}
|
||||
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
|
||||
if (file_header->size == 0) { /* Put file on a linked list for later */
|
||||
hardlinks_t *new = xmalloc(sizeof(hardlinks_t));
|
||||
|
||||
// TODO: data_extract_all can't deal with hardlinks to non-files...
|
||||
// (should be !S_ISDIR instead of S_ISREG here)
|
||||
|
||||
if (nlink > 1 && S_ISREG(file_header->mode)) {
|
||||
hardlinks_t *new = xmalloc(sizeof(*new) + namesize);
|
||||
new->inode = inode;
|
||||
new->mode = mode ;
|
||||
new->mtime = mtime;
|
||||
new->uid = uid ;
|
||||
new->gid = gid ;
|
||||
strcpy(new->name, file_header->name);
|
||||
/* Put file on a linked list for later */
|
||||
if (size == 0) {
|
||||
new->next = saved_hardlinks;
|
||||
new->inode = inode;
|
||||
/* name current allocated, freed later */
|
||||
new->name = file_header->name;
|
||||
file_header->name = NULL;
|
||||
saved_hardlinks = new;
|
||||
return EXIT_SUCCESS; /* Skip this one */
|
||||
/* TODO: this breaks cpio -t (it does not show hardlinks) */
|
||||
}
|
||||
/* Found the file with data in */
|
||||
pending_hardlinks = nlink;
|
||||
new->next = saved_hardlinks_created;
|
||||
saved_hardlinks_created = new;
|
||||
}
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
archive_handle->action_header(archive_handle->file_header);
|
||||
archive_handle->action_header(file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
}
|
||||
@@ -156,6 +112,58 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
file_header->link_target = NULL;
|
||||
file_header->name = NULL;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
create_hardlinks:
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
|
||||
while (saved_hardlinks) {
|
||||
hardlinks_t *cur;
|
||||
hardlinks_t *make_me = saved_hardlinks;
|
||||
saved_hardlinks = make_me->next;
|
||||
|
||||
memset(file_header, 0, sizeof(*file_header));
|
||||
file_header->name = make_me->name;
|
||||
file_header->mode = make_me->mode;
|
||||
/*file_header->size = 0;*/
|
||||
|
||||
/* Try to find a file we are hardlinked to */
|
||||
cur = saved_hardlinks_created;
|
||||
while (cur) {
|
||||
/* TODO: must match maj/min too! */
|
||||
if (cur->inode == make_me->inode) {
|
||||
file_header->link_target = cur->name;
|
||||
/* link_target != NULL, size = 0: "I am a hardlink" */
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
free(make_me);
|
||||
goto next_link;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
/* Oops... no file with such inode was created... do it now
|
||||
* (happens when hardlinked files are empty (zero length)) */
|
||||
file_header->mtime = make_me->mtime;
|
||||
file_header->uid = make_me->uid ;
|
||||
file_header->gid = make_me->gid ;
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
/* Move to the list of created hardlinked files */
|
||||
make_me->next = saved_hardlinks_created;
|
||||
saved_hardlinks_created = make_me;
|
||||
next_link: ;
|
||||
}
|
||||
|
||||
while (saved_hardlinks_created) {
|
||||
hardlinks_t *p = saved_hardlinks_created;
|
||||
saved_hardlinks_created = p->next;
|
||||
free(p);
|
||||
}
|
||||
|
||||
return EXIT_FAILURE; /* "No more files to process" */
|
||||
}
|
||||
@@ -46,6 +46,9 @@ void BUG_tar_header_size(void);
|
||||
char get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
static smallint end;
|
||||
#if ENABLE_FEATURE_TAR_AUTODETECT
|
||||
static smallint not_first;
|
||||
#endif
|
||||
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
struct {
|
||||
@@ -59,8 +62,12 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
/* Normally it's defined as magic[6] followed by
|
||||
* version[2], but we put them together to save code.
|
||||
*/
|
||||
char magic[8]; /* 257-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
@@ -86,17 +93,32 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
again_after_align:
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
i = full_read(archive_handle->src_fd, &tar, 512);
|
||||
/* if GNU tar sees EOF in above read, it says:
|
||||
* "tar: A lone zero block at N", where N = kilobyte
|
||||
* where EOF was met (not EOF block, actual EOF!),
|
||||
* and tar will exit with error code 0.
|
||||
* We will mimic exit(EXIT_SUCCESS), although we will not mimic
|
||||
* the message and we don't check whether we indeed
|
||||
* saw zero block directly before this. */
|
||||
if (i == 0)
|
||||
xfunc_error_retval = 0;
|
||||
if (i != 512)
|
||||
bb_error_msg_and_die("short read");
|
||||
#else
|
||||
xread(archive_handle->src_fd, &tar, 512);
|
||||
#endif
|
||||
archive_handle->offset += 512;
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.name[0] == 0) {
|
||||
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
|
||||
if (end) {
|
||||
/* This is the second consecutive empty header! End of archive!
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
|
||||
/* repeat */;
|
||||
continue;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
end = 1;
|
||||
@@ -104,16 +126,49 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
}
|
||||
end = 0;
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar
|
||||
* 0's are for the old tar format
|
||||
*/
|
||||
if (strncmp(tar.magic, "ustar", 5) != 0) {
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
if (memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
/* 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
|
||||
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
) {
|
||||
#if ENABLE_FEATURE_TAR_AUTODETECT
|
||||
char (*get_header_ptr)(archive_handle_t *);
|
||||
|
||||
/* tar gz/bz autodetect: check for gz/bz2 magic.
|
||||
* If it is the very first block, and we see the magic,
|
||||
* we can switch to get_header_tar_gz/bz2/lzma().
|
||||
* Needs seekable fd. I wish recv(MSG_PEEK) works
|
||||
* on any fd... */
|
||||
if (not_first)
|
||||
goto err;
|
||||
#if ENABLE_FEATURE_TAR_GZIP
|
||||
if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
} else
|
||||
#endif
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
#if ENABLE_FEATURE_TAR_BZIP2
|
||||
if (tar.name[0] == 'B' && tar.name[1] == 'Z'
|
||||
&& tar.name[2] == 'h' && isdigit(tar.name[3])
|
||||
) { /* bzip2 */
|
||||
get_header_ptr = get_header_tar_bz2;
|
||||
} else
|
||||
#endif
|
||||
goto err;
|
||||
if (lseek(archive_handle->src_fd, -512, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
return EXIT_FAILURE;
|
||||
err:
|
||||
#endif /* FEATURE_TAR_AUTODETECT */
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_AUTODETECT
|
||||
not_first = 1;
|
||||
#endif
|
||||
|
||||
/* Do checksum on headers.
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
@@ -156,18 +211,23 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
/* getOctal trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
char t = tar.prefix[0];
|
||||
/* we trash prefix[0] here, but we DO need it later! */
|
||||
unsigned minor = GET_OCTAL(tar.devminor);
|
||||
unsigned major = GET_OCTAL(tar.devmajor);
|
||||
file_header->device = makedev(major, minor);
|
||||
tar.prefix[0] = t;
|
||||
}
|
||||
file_header->link_target = NULL;
|
||||
if (!linkname && parse_names && tar.linkname[0]) {
|
||||
/* we trash magic[0] here, it's ok */
|
||||
tar.linkname[sizeof(tar.linkname)] = '\0';
|
||||
file_header->link_target = xstrdup(tar.linkname);
|
||||
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
|
||||
/* FIXME: what if we have non-link object with link_target? */
|
||||
/* Will link_target be free()ed? */
|
||||
}
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
file_header->uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
#endif
|
||||
file_header->mtime = GET_OCTAL(tar.mtime);
|
||||
file_header->size = GET_OCTAL(tar.size);
|
||||
file_header->gid = GET_OCTAL(tar.gid);
|
||||
@@ -178,10 +238,12 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->name = NULL;
|
||||
if (!longname && parse_names) {
|
||||
/* we trash mode[0] here, it's ok */
|
||||
tar.name[sizeof(tar.name)] = '\0';
|
||||
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.mode[0] = '\0';
|
||||
if (tar.prefix[0]) {
|
||||
/* and padding[0] */
|
||||
tar.prefix[sizeof(tar.prefix)] = '\0';
|
||||
//tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.padding[0] = '\0';
|
||||
file_header->name = concat_path_file(tar.prefix, tar.name);
|
||||
} else
|
||||
file_header->name = xstrdup(tar.name);
|
||||
@@ -298,6 +360,9 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
free(file_header->link_target);
|
||||
/* Do not free(file_header->name)! */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
free(file_header->uname);
|
||||
free(file_header->gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -11,9 +11,10 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -8,21 +8,27 @@
|
||||
|
||||
char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
#if BB_MMU
|
||||
unsigned char magic[2];
|
||||
#endif
|
||||
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
/* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
|
||||
* Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
|
||||
* need the header. */
|
||||
#if BB_MMU
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
#endif
|
||||
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -14,9 +14,10 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -10,6 +10,33 @@ void header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm *mtime = localtime(&(file_header->mtime));
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char *user = file_header->uname;
|
||||
char *group = file_header->gname;
|
||||
|
||||
if (user == NULL) {
|
||||
snprintf(uid, sizeof(uid), "%u", (unsigned)file_header->uid);
|
||||
user = uid;
|
||||
}
|
||||
if (group == NULL) {
|
||||
snprintf(gid, sizeof(gid), "%u", (unsigned)file_header->gid);
|
||||
group = gid;
|
||||
}
|
||||
printf("%s %s/%s %9u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
user,
|
||||
group,
|
||||
(unsigned int) file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
#else /* !FEATURE_TAR_UNAME_GNAME */
|
||||
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
file_header->uid,
|
||||
@@ -22,10 +49,10 @@ void header_verbose_list(const file_header_t *file_header)
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
#endif /* FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
if (file_header->link_target) {
|
||||
printf(" -> %s", file_header->link_target);
|
||||
}
|
||||
/* putchar isnt used anywhere else i dont think */
|
||||
puts("");
|
||||
bb_putchar('\n');
|
||||
}
|
||||
@@ -7,32 +7,58 @@
|
||||
#include "unarchive.h"
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
/*
|
||||
* On MMU machine, the transform_prog is removed by macro magic
|
||||
* in include/unarchive.h. On NOMMU, transformer is removed.
|
||||
*/
|
||||
int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
|
||||
const char *transform_prog)
|
||||
{
|
||||
int fd_pipe[2];
|
||||
struct fd_pair fd_pipe;
|
||||
int pid;
|
||||
|
||||
xpipe(fd_pipe);
|
||||
xpiped_pair(fd_pipe);
|
||||
|
||||
#if BB_MMU
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
bb_perror_msg_and_die("fork failed");
|
||||
}
|
||||
if (pid == -1)
|
||||
bb_perror_msg_and_die("can't fork");
|
||||
#else
|
||||
pid = vfork();
|
||||
if (pid == -1)
|
||||
bb_perror_msg_and_die("can't vfork");
|
||||
#endif
|
||||
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
close(fd_pipe.rd); /* We don't want to read from the parent */
|
||||
// FIXME: error check?
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
exit(0);
|
||||
#if BB_MMU
|
||||
transformer(src_fd, fd_pipe.wr);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* Send EOF */
|
||||
close(src_fd);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
#else
|
||||
{
|
||||
char *argv[4];
|
||||
xmove_fd(src_fd, 0);
|
||||
xmove_fd(fd_pipe.wr, 1);
|
||||
argv[0] = (char*)transform_prog;
|
||||
argv[1] = (char*)"-cf";
|
||||
argv[2] = (char*)"-";
|
||||
argv[3] = NULL;
|
||||
BB_EXECVP(transform_prog, argv);
|
||||
bb_perror_msg_and_die("can't exec %s", transform_prog);
|
||||
}
|
||||
#endif
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
/* parent process */
|
||||
close(fd_pipe[1]); /* Don't want to write to the child */
|
||||
close(fd_pipe.wr); /* Don't want to write to the child */
|
||||
|
||||
return fd_pipe[0];
|
||||
return fd_pipe.rd;
|
||||
}
|
||||
@@ -6,14 +6,12 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount)
|
||||
void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
|
||||
{
|
||||
if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
|
||||
#if ENABLE_FEATURE_UNARCHIVE_TAPE
|
||||
if (errno == ESPIPE) {
|
||||
if (errno == ESPIPE)
|
||||
seek_by_read(archive_handle, amount);
|
||||
} else
|
||||
#endif
|
||||
else
|
||||
bb_perror_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* If we are reading through a pipe(), or from stdin then we can't lseek,
|
||||
/* If we are reading through a pipe, or from stdin then we can't lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*/
|
||||
void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
void seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
|
||||
{
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
|
||||
+24
-5
@@ -80,7 +80,7 @@ static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv);
|
||||
int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
@@ -187,9 +187,15 @@ int rpm_main(int argc, char **argv)
|
||||
|
||||
static void extract_cpio_gz(int fd)
|
||||
{
|
||||
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned char magic[2];
|
||||
#if BB_MMU
|
||||
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
|
||||
enum { xformer_prog = 0 };
|
||||
#else
|
||||
enum { xformer = 0 };
|
||||
const char *xformer_prog;
|
||||
#endif
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
@@ -202,11 +208,19 @@ static void extract_cpio_gz(int fd)
|
||||
archive_handle->offset = 0;
|
||||
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
#if BB_MMU
|
||||
xformer = unpack_gz_stream;
|
||||
#else
|
||||
xformer_prog = "gunzip";
|
||||
#endif
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
if (ENABLE_FEATURE_RPM_BZ2
|
||||
&& (magic[0] == 0x42) && (magic[1] == 0x5a)) {
|
||||
#if BB_MMU
|
||||
xformer = unpack_bz2_stream;
|
||||
#else
|
||||
xformer_prog = "bunzip2";
|
||||
#endif
|
||||
/* We can do better, need modifying unpack_bz2_stream to not require
|
||||
* first 2 bytes. Not very hard to do... I mean, TODO :) */
|
||||
xlseek(archive_handle->src_fd, -2, SEEK_CUR);
|
||||
@@ -214,11 +228,16 @@ static void extract_cpio_gz(int fd)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
USE_FEATURE_RPM_BZ2("/bzip")
|
||||
" magic");
|
||||
} else
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
} else {
|
||||
#if !BB_MMU
|
||||
/* NOMMU version of open_transformer execs an external unzipper that should
|
||||
* have the file position at the start of the file */
|
||||
xlseek(archive_handle->src_fd, 0, SEEK_SET);
|
||||
#endif
|
||||
}
|
||||
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
+9
-10
@@ -13,14 +13,14 @@
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
|
||||
struct rpm_lead {
|
||||
unsigned char magic[4];
|
||||
uint8_t major, minor;
|
||||
uint16_t type;
|
||||
uint16_t archnum;
|
||||
char name[66];
|
||||
uint16_t osnum;
|
||||
uint16_t signature_type;
|
||||
char reserved[16];
|
||||
unsigned char magic[4];
|
||||
uint8_t major, minor;
|
||||
uint16_t type;
|
||||
uint16_t archnum;
|
||||
char name[66];
|
||||
uint16_t osnum;
|
||||
uint16_t signature_type;
|
||||
char reserved[16];
|
||||
};
|
||||
|
||||
struct rpm_header {
|
||||
@@ -49,7 +49,7 @@ static void skip_header(int rpm_fd)
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv);
|
||||
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
@@ -79,7 +79,6 @@ int rpm2cpio_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip_or_die(rpm_fd);
|
||||
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
+190
-149
@@ -3,7 +3,7 @@
|
||||
* Mini tar implementation for busybox
|
||||
*
|
||||
* Modified to use common extraction code used by ar, cpio, dpkg-deb, dpkg
|
||||
* Glenn McGrath <bug1@iinet.net.au>
|
||||
* by Glenn McGrath
|
||||
*
|
||||
* Note, that as of BusyBox-0.43, tar has been completely rewritten from the
|
||||
* ground up. It still has remnants of the old code lying about, but it is
|
||||
@@ -24,12 +24,25 @@
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* FIXME: Stop using this non-standard feature */
|
||||
#ifndef FNM_LEADING_DIR
|
||||
#define FNM_LEADING_DIR 0
|
||||
#endif
|
||||
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
#if !ENABLE_FEATURE_TAR_GZIP && !ENABLE_FEATURE_TAR_BZIP2
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
/* Tar file constants */
|
||||
@@ -50,14 +63,18 @@ struct TarHeader { /* byte offset */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[NAME_SIZE]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
/* POSIX: "ustar" NUL "00" */
|
||||
/* GNU tar: "ustar " NUL */
|
||||
/* Normally it's defined as magic[6] followed by
|
||||
* version[2], but we put them together to save code.
|
||||
*/
|
||||
char magic[8]; /* 257-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
|
||||
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -67,26 +84,26 @@ struct TarHeader { /* byte offset */
|
||||
*/
|
||||
typedef struct HardLinkInfo HardLinkInfo;
|
||||
struct HardLinkInfo {
|
||||
HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
};
|
||||
|
||||
/* Some info to be carried along when creating a new tarball */
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
for the tarball */
|
||||
struct stat statBuf; /* Stat info for the tarball, letting
|
||||
us know the inode and device that the
|
||||
tarball lives, so we can avoid trying
|
||||
to include the tarball into itself */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
* for the tarball */
|
||||
struct stat statBuf; /* Stat info for the tarball, letting
|
||||
* us know the inode and device that the
|
||||
* tarball lives, so we can avoid trying
|
||||
* to include the tarball into itself */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
};
|
||||
|
||||
/* A nice enum with all the possible tar file content types */
|
||||
@@ -106,7 +123,7 @@ enum TarFileType {
|
||||
typedef enum TarFileType TarFileType;
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
static void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr,
|
||||
static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
|
||||
struct stat *statbuf,
|
||||
const char *fileName)
|
||||
{
|
||||
@@ -122,7 +139,7 @@ static void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr,
|
||||
strcpy(hlInfo->name, fileName);
|
||||
}
|
||||
|
||||
static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
|
||||
static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
|
||||
{
|
||||
HardLinkInfo *hlInfo;
|
||||
HardLinkInfo *hlInfoNext;
|
||||
@@ -139,7 +156,7 @@ static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbuf)
|
||||
static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf)
|
||||
{
|
||||
while (hlInfo) {
|
||||
if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev))
|
||||
@@ -386,35 +403,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
const char *header_name;
|
||||
int inputFileFd = -1;
|
||||
|
||||
/*
|
||||
* Check to see if we are dealing with a hard link.
|
||||
* If so -
|
||||
* Treat the first occurance of a given dev/inode as a file while
|
||||
* treating any additional occurances as hard links. This is done
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
if (statbuf->st_nlink > 1) {
|
||||
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
|
||||
if (tbInfo->hlInfo == NULL)
|
||||
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, fileName);
|
||||
}
|
||||
|
||||
/* It is against the rules to archive a socket */
|
||||
if (S_ISSOCK(statbuf->st_mode)) {
|
||||
bb_error_msg("%s: socket ignored", fileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* It is a bad idea to store the archive we are in the process of creating,
|
||||
* so check the device and inode to be sure that this particular file isn't
|
||||
* the new tarball */
|
||||
if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
|
||||
tbInfo->statBuf.st_ino == statbuf->st_ino) {
|
||||
bb_error_msg("%s: file is the archive; skipping", fileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Strip leading '/' (must be before memorizing hardlink's name) */
|
||||
header_name = fileName;
|
||||
while (header_name[0] == '/') {
|
||||
static smallint warned;
|
||||
@@ -426,19 +415,49 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
header_name++;
|
||||
}
|
||||
|
||||
if (header_name[0] == '\0')
|
||||
return TRUE;
|
||||
|
||||
/* It is against the rules to archive a socket */
|
||||
if (S_ISSOCK(statbuf->st_mode)) {
|
||||
bb_error_msg("%s: socket ignored", fileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if we are dealing with a hard link.
|
||||
* If so -
|
||||
* Treat the first occurance of a given dev/inode as a file while
|
||||
* treating any additional occurances as hard links. This is done
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
if (statbuf->st_nlink > 1) {
|
||||
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
|
||||
if (tbInfo->hlInfo == NULL)
|
||||
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name);
|
||||
}
|
||||
|
||||
/* It is a bad idea to store the archive we are in the process of creating,
|
||||
* so check the device and inode to be sure that this particular file isn't
|
||||
* the new tarball */
|
||||
if (tbInfo->statBuf.st_dev == statbuf->st_dev
|
||||
&& tbInfo->statBuf.st_ino == statbuf->st_ino
|
||||
) {
|
||||
bb_error_msg("%s: file is the archive; skipping", fileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (exclude_file(tbInfo->excludeList, header_name))
|
||||
return SKIP;
|
||||
|
||||
#if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (strlen(fileName) >= NAME_SIZE) {
|
||||
if (strlen(header_name) >= NAME_SIZE) {
|
||||
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (header_name[0] == '\0')
|
||||
return TRUE;
|
||||
|
||||
if (exclude_file(tbInfo->excludeList, header_name))
|
||||
return SKIP;
|
||||
|
||||
/* Is this a regular file? */
|
||||
if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
@@ -484,11 +503,90 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
const unsigned long dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, const int gzip)
|
||||
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
|
||||
#if !(ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2)
|
||||
#define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
#endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
#if ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
#elif ENABLE_FEATURE_TAR_GZIP
|
||||
const char *zip_exec = "gzip";
|
||||
#else /* only ENABLE_FEATURE_TAR_BZIP2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
#endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
#define WAIT_FOR_CHILD 0
|
||||
volatile int vfork_exec_errno = 0;
|
||||
struct fd_pair gzipDataPipe;
|
||||
#if WAIT_FOR_CHILD
|
||||
struct fd_pair gzipStatusPipe;
|
||||
xpiped_pair(gzipStatusPipe);
|
||||
#endif
|
||||
xpiped_pair(gzipDataPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
#endif
|
||||
|
||||
gzipPid = vfork();
|
||||
if (gzipPid < 0)
|
||||
bb_perror_msg_and_die("can't vfork");
|
||||
|
||||
if (gzipPid == 0) {
|
||||
/* child */
|
||||
/* NB: close _first_, then move fds! */
|
||||
close(gzipDataPipe.wr);
|
||||
#if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.rd);
|
||||
/* gzipStatusPipe.wr will close only on exec -
|
||||
* parent waits for this close to happen */
|
||||
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
|
||||
#endif
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* parent */
|
||||
xmove_fd(gzipDataPipe.wr, tar_fd);
|
||||
close(gzipDataPipe.rd);
|
||||
#if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.wr);
|
||||
while (1) {
|
||||
char buf;
|
||||
int n;
|
||||
|
||||
/* Wait until child execs (or fails to) */
|
||||
n = full_read(gzipStatusPipe.rd, &buf, 1);
|
||||
if (n < 0 /* && errno == EAGAIN */)
|
||||
continue; /* try it again */
|
||||
}
|
||||
close(gzipStatusPipe.rd);
|
||||
#endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("cannot exec %s", zip_exec);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2 */
|
||||
|
||||
|
||||
/* gcc 4.2.1 inlines it, making code bigger */
|
||||
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, int gzip)
|
||||
{
|
||||
pid_t gzipPid = 0;
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
|
||||
@@ -503,62 +601,11 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
||||
bb_perror_msg_and_die("cannot stat tar file");
|
||||
|
||||
if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) {
|
||||
int gzipDataPipe[2] = { -1, -1 };
|
||||
int gzipStatusPipe[2] = { -1, -1 };
|
||||
volatile int vfork_exec_errno = 0;
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
|
||||
xpipe(gzipDataPipe);
|
||||
xpipe(gzipStatusPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &include;
|
||||
(void) &errorFlag;
|
||||
(void) &zip_exec;
|
||||
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
#endif
|
||||
|
||||
gzipPid = vfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
dup2(gzipDataPipe[0], 0);
|
||||
close(gzipDataPipe[1]);
|
||||
|
||||
dup2(tbInfo.tarFd, 1);
|
||||
|
||||
close(gzipStatusPipe[0]);
|
||||
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
|
||||
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
|
||||
close(gzipStatusPipe[1]);
|
||||
exit(-1);
|
||||
} else if (gzipPid > 0) {
|
||||
close(gzipDataPipe[0]);
|
||||
close(gzipStatusPipe[1]);
|
||||
|
||||
while (1) {
|
||||
char buf;
|
||||
|
||||
int n = full_read(gzipStatusPipe[0], &buf, 1);
|
||||
|
||||
if (n == 0 && vfork_exec_errno != 0) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("cannot exec %s", zip_exec);
|
||||
} else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
|
||||
continue; /* try it again */
|
||||
break;
|
||||
}
|
||||
close(gzipStatusPipe[0]);
|
||||
|
||||
tbInfo.tarFd = gzipDataPipe[1];
|
||||
} else bb_perror_msg_and_die("vfork gzip");
|
||||
}
|
||||
|
||||
tbInfo.excludeList = exclude;
|
||||
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
@@ -590,37 +637,34 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
if (gzipPid) {
|
||||
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
|
||||
if (gzip) {
|
||||
int status;
|
||||
if (waitpid(gzipPid, &status, 0) == -1)
|
||||
if (safe_waitpid(-1, &status, 0) == -1)
|
||||
bb_perror_msg("waitpid");
|
||||
else if (!WIFEXITED(status) || WEXITSTATUS(status))
|
||||
/* gzip was killed or has exited with nonzero! */
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
#endif
|
||||
return errorFlag;
|
||||
}
|
||||
#else
|
||||
int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
const unsigned long dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, const int gzip);
|
||||
int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
{
|
||||
FILE *src_stream;
|
||||
llist_t *cur = list;
|
||||
llist_t *tmp;
|
||||
char *line;
|
||||
llist_t *newlist = NULL;
|
||||
|
||||
while (cur) {
|
||||
src_stream = xfopen(cur->data, "r");
|
||||
tmp = cur;
|
||||
cur = cur->link;
|
||||
free(tmp);
|
||||
while ((line = xmalloc_getline(src_stream)) != NULL) {
|
||||
while (list) {
|
||||
src_stream = xfopen(llist_pop(&list), "r");
|
||||
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
char *cp = last_char_is(line, '/');
|
||||
if (cp > line)
|
||||
@@ -648,10 +692,10 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
/* nothing */;
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
@@ -670,7 +714,7 @@ static void handle_SIGCHLD(int status)
|
||||
/* Actually, 'status' is a signo. We reuse it for other needs */
|
||||
|
||||
/* Wait for any child without blocking */
|
||||
if (waitpid(-1, &status, WNOHANG) < 0)
|
||||
if (wait_any_nohang(&status) < 0)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
@@ -755,8 +799,8 @@ static const char tar_longopts[] ALIGN1 =
|
||||
;
|
||||
#endif
|
||||
|
||||
int tar_main(int argc, char **argv);
|
||||
int tar_main(int argc, char **argv)
|
||||
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int tar_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
|
||||
archive_handle_t *tar_handle;
|
||||
@@ -806,6 +850,7 @@ int tar_main(int argc, char **argv)
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
);
|
||||
argv += optind;
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
if (verboseFlag == 1) tar_handle->action_header = header_list;
|
||||
@@ -851,21 +896,15 @@ int tar_main(int argc, char **argv)
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
#endif
|
||||
|
||||
/* Check if we are reading from stdin */
|
||||
if (argv[optind] && *argv[optind] == '-') {
|
||||
/* Default is to read from stdin, so just skip to next arg */
|
||||
optind++;
|
||||
}
|
||||
|
||||
/* Setup an array of filenames to work with */
|
||||
/* TODO: This is the same as in ar, separate function ? */
|
||||
while (optind < argc) {
|
||||
while (*argv) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
char *cp = last_char_is(argv[optind], '/');
|
||||
if (cp > argv[optind])
|
||||
char *cp = last_char_is(*argv, '/');
|
||||
if (cp > *argv)
|
||||
*cp = '\0';
|
||||
llist_add_to_end(&tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
llist_add_to_end(&tar_handle->accept, *argv);
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (tar_handle->accept || tar_handle->reject)
|
||||
@@ -908,11 +947,13 @@ int tar_main(int argc, char **argv)
|
||||
|
||||
/* create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_TAR_GZIP && get_header_ptr == get_header_tar_gz)
|
||||
if (ENABLE_FEATURE_TAR_GZIP && (opt & OPT_GZIP))
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
|
||||
if (ENABLE_FEATURE_TAR_BZIP2 && (opt & OPT_BZIP2))
|
||||
zipMode = 2;
|
||||
#endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
tar_handle->accept,
|
||||
@@ -920,7 +961,7 @@ int tar_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
|
||||
/* nothing */;
|
||||
continue;
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
|
||||
+141
-110
@@ -27,37 +27,67 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
|
||||
#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
|
||||
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
|
||||
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
|
||||
enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDS_MAGIC = 0x504b0102,
|
||||
ZIP_CDS_END_MAGIC = 0x504b0506,
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
ZIP_CDS_MAGIC = 0x02014b50,
|
||||
ZIP_CDS_END_MAGIC = 0x06054b50,
|
||||
ZIP_DD_MAGIC = 0x08074b50,
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ZIP_HEADER_LEN 26
|
||||
|
||||
typedef union {
|
||||
unsigned char raw[26];
|
||||
uint8_t raw[ZIP_HEADER_LEN];
|
||||
struct {
|
||||
unsigned short version; /* 0-1 */
|
||||
unsigned short flags; /* 2-3 */
|
||||
unsigned short method; /* 4-5 */
|
||||
unsigned short modtime; /* 6-7 */
|
||||
unsigned short moddate; /* 8-9 */
|
||||
unsigned int crc32 ATTRIBUTE_PACKED; /* 10-13 */
|
||||
unsigned int cmpsize ATTRIBUTE_PACKED; /* 14-17 */
|
||||
unsigned int ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
|
||||
unsigned short filename_len; /* 22-23 */
|
||||
unsigned short extra_len; /* 24-25 */
|
||||
uint16_t version; /* 0-1 */
|
||||
uint16_t flags; /* 2-3 */
|
||||
uint16_t method; /* 4-5 */
|
||||
uint16_t modtime; /* 6-7 */
|
||||
uint16_t moddate; /* 8-9 */
|
||||
uint32_t crc32 ATTRIBUTE_PACKED; /* 10-13 */
|
||||
uint32_t cmpsize ATTRIBUTE_PACKED; /* 14-17 */
|
||||
uint32_t ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
} formatted ATTRIBUTE_PACKED;
|
||||
} zip_header_t;
|
||||
} zip_header_t; /* ATTRIBUTE_PACKED - gcc 4.2.1 doesn't like it (spews warning) */
|
||||
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
struct BUG_zip_header_must_be_26_bytes {
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2 ==
|
||||
ZIP_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS(zip_header) do { \
|
||||
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
|
||||
(zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \
|
||||
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
|
||||
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
|
||||
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
|
||||
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
|
||||
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
|
||||
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
|
||||
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
|
||||
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
|
||||
} while (0)
|
||||
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
|
||||
if (errno != ESPIPE)
|
||||
bb_error_msg_and_die("seek failure");
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
|
||||
static void unzip_create_leading_dirs(char *fn)
|
||||
static void unzip_create_leading_dirs(const char *fn)
|
||||
{
|
||||
/* Create all leading directories */
|
||||
char *name = xstrdup(fn);
|
||||
@@ -67,7 +97,7 @@ static void unzip_create_leading_dirs(char *fn)
|
||||
free(name);
|
||||
}
|
||||
|
||||
static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
{
|
||||
if (zip_header->formatted.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
@@ -77,64 +107,71 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_unzip_result res;
|
||||
/* err = */ inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd);
|
||||
// we should check for -1 error return
|
||||
if (inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("invalid compressed data--%s error", "crc");
|
||||
return 1;
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != res.bytes_out) {
|
||||
bb_error_msg("invalid compressed data--%s error", "length");
|
||||
return 1;
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv);
|
||||
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
enum {v_silent, v_normal, v_list} verbosity = v_normal;
|
||||
enum {o_prompt, o_never, o_always} overwrite = o_prompt;
|
||||
unsigned int total_size = 0;
|
||||
unsigned int total_entries = 0;
|
||||
int src_fd = -1, dst_fd = -1;
|
||||
char *src_fn = NULL, *dst_fn = NULL;
|
||||
smallint verbose = 1;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
unsigned total_size;
|
||||
unsigned total_entries;
|
||||
int src_fd = -1;
|
||||
int dst_fd = -1;
|
||||
char *src_fn = NULL;
|
||||
char *dst_fn = NULL;
|
||||
llist_t *zaccept = NULL;
|
||||
llist_t *zreject = NULL;
|
||||
char *base_dir = NULL;
|
||||
int failed, i, opt, opt_range = 0, list_header_done = 0;
|
||||
char key_buf[512];
|
||||
int i, opt;
|
||||
int opt_range = 0;
|
||||
char key_buf[80];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
case 'l': /* List */
|
||||
verbosity = v_list;
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
case 'n': /* Never overwrite existing files */
|
||||
overwrite = o_never;
|
||||
overwrite = O_NEVER;
|
||||
break;
|
||||
|
||||
case 'o': /* Always overwrite existing files */
|
||||
overwrite = o_always;
|
||||
overwrite = O_ALWAYS;
|
||||
break;
|
||||
|
||||
case 'p': /* Extract files to stdout and fall through to set verbosity */
|
||||
dst_fd = STDOUT_FILENO;
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
verbosity = (verbosity == v_normal) ? v_silent : verbosity;
|
||||
verbose = 0;
|
||||
break;
|
||||
|
||||
case 1 : /* The zip file */
|
||||
src_fn = xmalloc(strlen(optarg)+4);
|
||||
case 1: /* The zip file */
|
||||
/* +5: space for ".zip" and NUL */
|
||||
src_fn = xmalloc(strlen(optarg) + 5);
|
||||
strcpy(src_fn, optarg);
|
||||
opt_range++;
|
||||
break;
|
||||
@@ -148,31 +185,30 @@ int unzip_main(int argc, char **argv)
|
||||
case 1: /* Include files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zaccept, optarg);
|
||||
|
||||
} else if (opt == 'd') {
|
||||
break;
|
||||
}
|
||||
if (opt == 'd') {
|
||||
base_dir = optarg;
|
||||
opt_range += 2;
|
||||
|
||||
} else if (opt == 'x') {
|
||||
opt_range++;
|
||||
|
||||
} else {
|
||||
bb_show_usage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
if (opt == 'x') {
|
||||
opt_range++;
|
||||
break;
|
||||
}
|
||||
bb_show_usage();
|
||||
|
||||
case 2 : /* Exclude files */
|
||||
if (opt == 1) {
|
||||
llist_add_to(&zreject, optarg);
|
||||
|
||||
} else if (opt == 'd') { /* Extract to base directory */
|
||||
break;
|
||||
}
|
||||
if (opt == 'd') { /* Extract to base directory */
|
||||
base_dir = optarg;
|
||||
opt_range++;
|
||||
|
||||
} else {
|
||||
bb_show_usage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/* fall through */
|
||||
|
||||
default:
|
||||
bb_show_usage();
|
||||
@@ -187,17 +223,19 @@ int unzip_main(int argc, char **argv)
|
||||
if (LONE_DASH(src_fn)) {
|
||||
src_fd = STDIN_FILENO;
|
||||
/* Cannot use prompt mode since zip data is arriving on STDIN */
|
||||
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
|
||||
if (overwrite == O_PROMPT)
|
||||
overwrite = O_NEVER;
|
||||
} else {
|
||||
static const char *const extn[] = {"", ".zip", ".ZIP"};
|
||||
static const char extn[][5] = {"", ".zip", ".ZIP"};
|
||||
int orig_src_fn_len = strlen(src_fn);
|
||||
|
||||
for (i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
strcpy(src_fn + orig_src_fn_len, extn[i]);
|
||||
src_fd = open(src_fn, O_RDONLY);
|
||||
}
|
||||
if (src_fd == -1) {
|
||||
src_fn[orig_src_fn_len] = '\0';
|
||||
bb_error_msg_and_die("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
|
||||
bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,36 +243,31 @@ int unzip_main(int argc, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
if (verbosity != v_silent)
|
||||
if (verbose) {
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
}
|
||||
}
|
||||
|
||||
failed = 0;
|
||||
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
while (1) {
|
||||
unsigned int magic;
|
||||
uint32_t magic;
|
||||
|
||||
/* Check magic number */
|
||||
xread(src_fd, &magic, 4);
|
||||
if (magic == ZIP_CDS_MAGIC) {
|
||||
if (magic == ZIP_CDS_MAGIC)
|
||||
break;
|
||||
} else if (magic != ZIP_FILEHEADER_MAGIC) {
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", magic);
|
||||
}
|
||||
|
||||
/* Read the file header */
|
||||
xread(src_fd, zip_header.raw, 26);
|
||||
zip_header.formatted.version = SWAP_LE32(zip_header.formatted.version);
|
||||
zip_header.formatted.flags = SWAP_LE32(zip_header.formatted.flags);
|
||||
zip_header.formatted.method = SWAP_LE32(zip_header.formatted.method);
|
||||
zip_header.formatted.modtime = SWAP_LE32(zip_header.formatted.modtime);
|
||||
zip_header.formatted.moddate = SWAP_LE32(zip_header.formatted.moddate);
|
||||
zip_header.formatted.crc32 = SWAP_LE32(zip_header.formatted.crc32);
|
||||
zip_header.formatted.cmpsize = SWAP_LE32(zip_header.formatted.cmpsize);
|
||||
zip_header.formatted.ucmpsize = SWAP_LE32(zip_header.formatted.ucmpsize);
|
||||
zip_header.formatted.filename_len = SWAP_LE32(zip_header.formatted.filename_len);
|
||||
zip_header.formatted.extra_len = SWAP_LE32(zip_header.formatted.extra_len);
|
||||
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS(zip_header);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported compression method %d", zip_header.formatted.method);
|
||||
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
|
||||
}
|
||||
|
||||
/* Read filename */
|
||||
@@ -245,23 +278,17 @@ int unzip_main(int argc, char **argv)
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
if ((verbosity == v_list) && !list_header_done){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
list_header_done = 1;
|
||||
}
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn) ||
|
||||
(zaccept && !find_list_entry(zaccept, dst_fn))) { /* Skip entry */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract entry */
|
||||
total_size += zip_header.formatted.ucmpsize;
|
||||
|
||||
if (verbosity == v_list) { /* List entry */
|
||||
unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
if (listing) { /* List entry */
|
||||
if (verbose) {
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
zip_header.formatted.ucmpsize,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
@@ -269,7 +296,12 @@ int unzip_main(int argc, char **argv)
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_entries++;
|
||||
total_size += zip_header.formatted.ucmpsize;
|
||||
total_entries++;
|
||||
} else {
|
||||
/* short listing -- filenames only */
|
||||
puts(dst_fn);
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
@@ -278,7 +310,7 @@ int unzip_main(int argc, char **argv)
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
|
||||
}
|
||||
if (verbosity == v_normal) {
|
||||
if (verbose) {
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
@@ -300,14 +332,14 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
i = 'y';
|
||||
} else { /* File already exists */
|
||||
if (overwrite == o_never) {
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == o_always) {
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} else {
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
if (!fgets(key_buf, 512, stdin)) {
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("cannot read input");
|
||||
}
|
||||
i = key_buf[0];
|
||||
@@ -321,17 +353,15 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
switch (i) {
|
||||
case 'A':
|
||||
overwrite = o_always;
|
||||
overwrite = O_ALWAYS;
|
||||
case 'y': /* Open file and fall into unzip */
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
case -1: /* Unzip */
|
||||
if (verbosity == v_normal) {
|
||||
if (verbose) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
|
||||
failed = 1;
|
||||
}
|
||||
unzip_extract(&zip_header, src_fd, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
@@ -339,7 +369,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
overwrite = o_never;
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
unzip_skip(src_fd, zip_header.formatted.cmpsize);
|
||||
@@ -348,7 +378,7 @@ int unzip_main(int argc, char **argv)
|
||||
case 'r':
|
||||
/* Prompt for new name */
|
||||
printf("new name: ");
|
||||
if (!fgets(key_buf, 512, stdin)) {
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("cannot read input");
|
||||
}
|
||||
free(dst_fn);
|
||||
@@ -368,10 +398,11 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity == v_list) {
|
||||
if (listing && verbose) {
|
||||
printf(" -------- -------\n"
|
||||
"%9d %d files\n", total_size, total_entries);
|
||||
"%9d %d files\n",
|
||||
total_size, total_entries);
|
||||
}
|
||||
|
||||
return failed;
|
||||
return 0;
|
||||
}
|
||||
@@ -31,6 +31,12 @@ config DUMPKMAP
|
||||
This program dumps the kernel's keyboard translation table to
|
||||
stdout, in binary format. You can then use loadkmap to load it.
|
||||
|
||||
config KBD_MODE
|
||||
bool "kbd_mode"
|
||||
default n
|
||||
help
|
||||
This program reports and sets keyboard mode.
|
||||
|
||||
config LOADFONT
|
||||
bool "loadfont"
|
||||
default n
|
||||
@@ -66,7 +72,7 @@ config RESIZE
|
||||
terminal.
|
||||
|
||||
config FEATURE_RESIZE_PRINT
|
||||
bool "print environment variables"
|
||||
bool "Print environment variables"
|
||||
default n
|
||||
depends on RESIZE
|
||||
help
|
||||
|
||||
@@ -10,6 +10,7 @@ lib-$(CONFIG_CLEAR) += clear.o
|
||||
lib-$(CONFIG_DEALLOCVT) += deallocvt.o
|
||||
lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
|
||||
lib-$(CONFIG_SETCONSOLE) += setconsole.o
|
||||
lib-$(CONFIG_KBD_MODE) += kbd_mode.o
|
||||
lib-$(CONFIG_LOADFONT) += loadfont.o
|
||||
lib-$(CONFIG_LOADKMAP) += loadkmap.o
|
||||
lib-$(CONFIG_OPENVT) += openvt.o
|
||||
|
||||
+4
-12
@@ -9,25 +9,17 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
enum {
|
||||
VT_ACTIVATE = 0x5606, /* make vt active */
|
||||
VT_WAITACTIVE = 0x5607 /* wait for vt active */
|
||||
};
|
||||
|
||||
int chvt_main(int argc, char **argv);
|
||||
int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
int num;
|
||||
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
fd = get_console_fd();
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
/* double cast suppresses "cast to ptr from int of different size */
|
||||
xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num);
|
||||
xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num);
|
||||
/* double cast suppresses "cast to ptr from int of different size" */
|
||||
console_make_active(get_console_fd(), num);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int clear_main(int argc, char **argv);
|
||||
int clear_main(int argc, char **argv)
|
||||
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int clear_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return printf("\033[H\033[J") != 6;
|
||||
}
|
||||
@@ -15,23 +15,19 @@
|
||||
/* From <linux/vt.h> */
|
||||
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
|
||||
|
||||
int deallocvt_main(int argc, char **argv);
|
||||
int deallocvt_main(int argc, char **argv)
|
||||
int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int deallocvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
/* num = 0 deallocate all unused consoles */
|
||||
int num = 0;
|
||||
|
||||
switch (argc) {
|
||||
case 2:
|
||||
if (argv[1]) {
|
||||
if (argv[2])
|
||||
bb_show_usage();
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
/* Fallthrough */
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* double cast suppresses "cast to ptr from int of different size */
|
||||
/* double cast suppresses "cast to ptr from int of different size" */
|
||||
xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
/* no options, no getopt */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -22,19 +23,18 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int dumpkmap_main(int argc, char **argv);
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dumpkmap_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
|
||||
if (argc >= 2 && argv[1][0] == '-')
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argc>=2);*/
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, "bkeymap", 7);
|
||||
write(STDOUT_FILENO, "bkeymap", 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
@@ -43,7 +43,7 @@ int dumpkmap_main(int argc, char **argv)
|
||||
flags[3] = flags[7] = flags[11] = 0;
|
||||
|
||||
/* dump flags */
|
||||
write(1, flags, MAX_NR_KEYMAPS);
|
||||
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
@@ -56,11 +56,14 @@ int dumpkmap_main(int argc, char **argv)
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value)
|
||||
) {
|
||||
write(1, (void*)&ke.kb_value, 2);
|
||||
write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd);
|
||||
RELEASE_CONFIG_BUFFER(flags);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini kbd_mode implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
|
||||
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
|
||||
* console-utils v0.2.3, licensed under GNU GPLv2
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <linux/kd.h>
|
||||
|
||||
int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
unsigned opt;
|
||||
enum {
|
||||
SCANCODE = (1<<0),
|
||||
ASCII = (1<<1),
|
||||
MEDIUMRAW= (1<<2),
|
||||
UNICODE = (1<<3)
|
||||
};
|
||||
static const char KD_xxx[] ALIGN1 = "saku";
|
||||
opt = getopt32(argv, KD_xxx);
|
||||
fd = get_console_fd();
|
||||
/* if (fd < 0)
|
||||
return EXIT_FAILURE;
|
||||
*/
|
||||
if (!opt) { /* print current setting */
|
||||
const char *mode = "unknown";
|
||||
int m;
|
||||
|
||||
ioctl(fd, KDGKBMODE, &m);
|
||||
if (m == K_RAW)
|
||||
mode = "raw (scancode)";
|
||||
else if (m == K_XLATE)
|
||||
mode = "default (ASCII)";
|
||||
else if (m == K_MEDIUMRAW)
|
||||
mode = "mediumraw (keycode)";
|
||||
else if (m == K_UNICODE)
|
||||
mode = "Unicode (UTF-8)";
|
||||
printf("The keyboard is in %s mode\n", mode);
|
||||
} else {
|
||||
opt = opt & UNICODE ? 3 : opt >> 1;
|
||||
/* double cast prevents warnings about widening conversion */
|
||||
xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -166,8 +166,8 @@ static void loadnewfont(int fd)
|
||||
do_loadfont(fd, inbuf + offset, unit, 256);
|
||||
}
|
||||
|
||||
int loadfont_main(int argc, char **argv);
|
||||
int loadfont_main(int argc, char **argv)
|
||||
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int loadfont_main(int argc, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
||||
+14
-13
@@ -25,29 +25,27 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int loadkmap_main(int argc, char **argv);
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int loadkmap_main(int ATTRIBUTE_UNUSED argc, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
uint16_t ibuff[NR_KEYS];
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
char buff[7];
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
/* bb_warn_ignoring_args(argc>=2);*/
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
xread(0, buff, 7);
|
||||
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
||||
bb_error_msg_and_die("this is not a valid binary keymap");
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
|
||||
bb_error_msg_and_die("not a valid binary keymap");
|
||||
|
||||
xread(0, flags, MAX_NR_KEYMAPS);
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
@@ -57,6 +55,9 @@ int loadkmap_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) close(fd);
|
||||
return 0;
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd);
|
||||
RELEASE_CONFIG_BUFFER(flags);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+162
-16
@@ -8,28 +8,174 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <linux/vt.h>
|
||||
#include "libbb.h"
|
||||
|
||||
int openvt_main(int argc, char **argv);
|
||||
int openvt_main(int argc, char **argv)
|
||||
/* "Standard" openvt's man page (we do not support all of this):
|
||||
|
||||
openvt [-c NUM] [-fsulv] [--] [command [args]]
|
||||
|
||||
Find the first available VT, and run command on it. Stdio is directed
|
||||
to that VT. If no command is specified then $SHELL is used.
|
||||
|
||||
-c NUM
|
||||
Use the given VT number, not the first free one.
|
||||
-f
|
||||
Force opening a VT: don't try to check if VT is already in use.
|
||||
-s
|
||||
Switch to the new VT when starting the command.
|
||||
The VT of the new command will be made the new current VT.
|
||||
-u
|
||||
Figure out the owner of the current VT, and run login as that user.
|
||||
Suitable to be called by init. Shouldn't be used with -c or -l.
|
||||
-l
|
||||
Make the command a login shell: a "-" is prepended to the argv[0]
|
||||
when command is executed.
|
||||
-v
|
||||
Verbose.
|
||||
-w
|
||||
Wait for command to complete. If -w and -s are used together,
|
||||
switch back to the controlling terminal when the command completes.
|
||||
|
||||
bbox:
|
||||
-u: not implemented
|
||||
-f: always in effect
|
||||
-l: not implemented, ignored
|
||||
-v: ignored
|
||||
-ws: does NOT switch back
|
||||
*/
|
||||
|
||||
/* Helper: does this fd understand VT_xxx? */
|
||||
static int not_vt_fd(int fd)
|
||||
{
|
||||
char vtname[sizeof(VC_FORMAT) + 2];
|
||||
struct vt_stat vtstat;
|
||||
return ioctl(fd, VT_GETSTATE, &vtstat); /* !0: error, it's not VT fd */
|
||||
}
|
||||
|
||||
if (argc < 3)
|
||||
bb_show_usage();
|
||||
/* Helper: get a fd suitable for VT_xxx */
|
||||
static int get_vt_fd(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
/* check for illegal vt number: < 1 or > 63 */
|
||||
sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
|
||||
/* Do we, by chance, already have it? */
|
||||
for (fd = 0; fd < 3; fd++)
|
||||
if (!not_vt_fd(fd))
|
||||
return fd;
|
||||
/* _only_ O_NONBLOCK: ask for neither read nor write perms */
|
||||
/*FIXME: use? device_open(DEV_CONSOLE,0); */
|
||||
fd = open(DEV_CONSOLE, O_NONBLOCK);
|
||||
if (fd >= 0 && !not_vt_fd(fd))
|
||||
return fd;
|
||||
bb_error_msg_and_die("can't find open VT");
|
||||
}
|
||||
|
||||
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
|
||||
/* grab new one */
|
||||
close(0);
|
||||
static int find_free_vtno(void)
|
||||
{
|
||||
int vtno;
|
||||
int fd = get_vt_fd();
|
||||
|
||||
errno = 0;
|
||||
/*xfunc_error_retval = 3; - do we need compat? */
|
||||
if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
|
||||
bb_perror_msg_and_die("can't find open VT");
|
||||
// Not really needed, grep for DAEMON_ONLY_SANITIZE
|
||||
// if (fd > 2)
|
||||
// close(fd);
|
||||
return vtno;
|
||||
}
|
||||
|
||||
/* vfork scares gcc, it generates bigger code.
|
||||
* Keep it away from main program.
|
||||
* TODO: move to libbb; or adapt existing libbb's spawn().
|
||||
*/
|
||||
static NOINLINE void vfork_child(char **argv)
|
||||
{
|
||||
if (vfork() == 0) {
|
||||
/* CHILD */
|
||||
/* Try to make this VT our controlling tty */
|
||||
setsid(); /* lose old ctty */
|
||||
ioctl(STDIN_FILENO, TIOCSCTTY, 0 /* 0: don't forcibly steal */);
|
||||
//bb_error_msg("our sid %d", getsid(0));
|
||||
//bb_error_msg("our pgrp %d", getpgrp());
|
||||
//bb_error_msg("VT's sid %d", tcgetsid(0));
|
||||
//bb_error_msg("VT's pgrp %d", tcgetpgrp(0));
|
||||
BB_EXECVP(argv[0], argv);
|
||||
bb_perror_msg_and_die("exec %s", argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
|
||||
struct vt_stat vtstat;
|
||||
char *str_c;
|
||||
int vtno;
|
||||
int flags;
|
||||
enum {
|
||||
OPT_c = (1 << 0),
|
||||
OPT_w = (1 << 1),
|
||||
OPT_s = (1 << 2),
|
||||
OPT_l = (1 << 3),
|
||||
OPT_f = (1 << 4),
|
||||
OPT_v = (1 << 5),
|
||||
};
|
||||
|
||||
/* "+" - stop on first non-option */
|
||||
flags = getopt32(argv, "+c:wslfv", &str_c);
|
||||
argv += optind;
|
||||
|
||||
if (flags & OPT_c) {
|
||||
/* Check for illegal vt number: < 1 or > 63 */
|
||||
vtno = xatou_range(str_c, 1, 63);
|
||||
} else {
|
||||
vtno = find_free_vtno();
|
||||
}
|
||||
|
||||
/* Grab new VT */
|
||||
sprintf(vtname, VC_FORMAT, vtno);
|
||||
/* (Try to) clean up stray open fds above fd 2 */
|
||||
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
|
||||
close(STDIN_FILENO);
|
||||
/*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
|
||||
xopen(vtname, O_RDWR);
|
||||
dup2(0, STDOUT_FILENO);
|
||||
dup2(0, STDERR_FILENO);
|
||||
xioctl(STDIN_FILENO, VT_GETSTATE, &vtstat);
|
||||
|
||||
if (flags & OPT_s) {
|
||||
console_make_active(STDIN_FILENO, vtno);
|
||||
}
|
||||
|
||||
if (!argv[0]) {
|
||||
argv--;
|
||||
argv[0] = getenv("SHELL");
|
||||
if (!argv[0])
|
||||
argv[0] = (char *) DEFAULT_SHELL;
|
||||
/*argv[1] = NULL; - already is */
|
||||
}
|
||||
|
||||
xdup2(STDIN_FILENO, STDOUT_FILENO);
|
||||
xdup2(STDIN_FILENO, STDERR_FILENO);
|
||||
|
||||
#ifdef BLOAT
|
||||
{
|
||||
/* Handle -l (login shell) option */
|
||||
const char *prog = argv[0];
|
||||
if (flags & OPT_l)
|
||||
argv[0] = xasprintf("-%s", argv[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
BB_EXECVP(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
vfork_child(argv);
|
||||
if (flags & OPT_w) {
|
||||
/* We have only one child, wait for it */
|
||||
safe_waitpid(-1, NULL, 0); /* loops on EINTR */
|
||||
if (flags & OPT_s) {
|
||||
console_make_active(STDIN_FILENO, vtstat.v_active);
|
||||
// Compat: even with -c N (try to) disallocate:
|
||||
// # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5
|
||||
// openvt: could not deallocate console 9
|
||||
xioctl(STDIN_FILENO, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+23
-6
@@ -8,14 +8,25 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int reset_main(int argc, char **argv);
|
||||
int reset_main(int argc, char **argv)
|
||||
/* BTW, which "standard" package has this utility? It doesn't seem
|
||||
* to be ncurses, coreutils, console-tools... then what? */
|
||||
|
||||
#if ENABLE_STTY
|
||||
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
#endif
|
||||
|
||||
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int reset_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (isatty(1)) {
|
||||
static const char *const args[] = {
|
||||
"stty", "sane", NULL
|
||||
};
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
|
||||
/* See 'man 4 console_codes' for details:
|
||||
* "ESC c" -- Reset
|
||||
* "ESC ( K" -- Select user mapping
|
||||
@@ -24,7 +35,13 @@ int reset_main(int argc, char **argv)
|
||||
* "ESC [ ? 25 h" -- Make cursor visible.
|
||||
*/
|
||||
printf("\033c\033(K\033[J\033[0m\033[?25h");
|
||||
/* http://bugs.busybox.net/view.php?id=1414:
|
||||
* people want it to reset echo etc: */
|
||||
#if ENABLE_STTY
|
||||
return stty_main(2, (char**)args);
|
||||
#else
|
||||
execvp("stty", (char**)args);
|
||||
#endif
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+10
-8
@@ -17,14 +17,14 @@ static void
|
||||
onintr(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int resize_main(int argc, char **argv);
|
||||
int resize_main(int argc, char **argv)
|
||||
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int resize_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct termios new;
|
||||
struct winsize w = { 0,0,0,0 };
|
||||
struct winsize w = { 0, 0, 0, 0 };
|
||||
int ret;
|
||||
|
||||
/* We use _stderr_ in order to make resize usable
|
||||
@@ -37,10 +37,12 @@ int resize_main(int argc, char **argv)
|
||||
new = old_termios;
|
||||
new.c_cflag |= (CLOCAL | CREAD);
|
||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
signal(SIGINT, onintr);
|
||||
signal(SIGQUIT, onintr);
|
||||
signal(SIGTERM, onintr);
|
||||
signal(SIGALRM, onintr);
|
||||
bb_signals(0
|
||||
+ (1 << SIGINT)
|
||||
+ (1 << SIGQUIT)
|
||||
+ (1 << SIGTERM)
|
||||
+ (1 << SIGALRM)
|
||||
, onintr);
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||
|
||||
/* save_cursor_pos 7
|
||||
|
||||
+14
-21
@@ -3,41 +3,34 @@
|
||||
* setconsole.c - redirect system console output
|
||||
*
|
||||
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
|
||||
* Copyright (C) 2008 Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
static const char setconsole_longopts[] ALIGN1 =
|
||||
"reset\0" No_argument "r"
|
||||
;
|
||||
#endif
|
||||
|
||||
#define OPT_SETCONS_RESET 1
|
||||
|
||||
int setconsole_main(int argc, char **argv);
|
||||
int setconsole_main(int argc, char **argv)
|
||||
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
const char *device = CURRENT_TTY;
|
||||
bool reset;
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
static const char setconsole_longopts[] ALIGN1 =
|
||||
"reset\0" No_argument "r"
|
||||
;
|
||||
applet_long_options = setconsole_longopts;
|
||||
#endif
|
||||
flags = getopt32(argv, "r");
|
||||
/* at most one non-option argument */
|
||||
opt_complementary = "?1";
|
||||
reset = getopt32(argv, "r");
|
||||
|
||||
if (argc - optind > 1)
|
||||
bb_show_usage();
|
||||
|
||||
if (argc - optind == 1) {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
bb_show_usage();
|
||||
device = argv[optind];
|
||||
argv += 1 + reset;
|
||||
if (*argv) {
|
||||
device = *argv;
|
||||
} else {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
if (reset)
|
||||
device = DEV_CONSOLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbkeycode {
|
||||
unsigned int scancode, keycode;
|
||||
unsigned scancode, keycode;
|
||||
};
|
||||
enum {
|
||||
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
|
||||
};
|
||||
|
||||
int setkeycodes_main(int argc, char** argv);
|
||||
int setkeycodes_main(int argc, char** argv)
|
||||
int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setkeycodes_main(int argc, char **argv)
|
||||
{
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
@@ -33,7 +33,7 @@ int setkeycodes_main(int argc, char** argv)
|
||||
fd = get_console_fd();
|
||||
|
||||
while (argc > 2) {
|
||||
a.keycode = xatoul_range(argv[2], 0, 127);
|
||||
a.keycode = xatou_range(argv[2], 0, 127);
|
||||
a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
|
||||
if (a.scancode > 127) {
|
||||
a.scancode -= 0xe000;
|
||||
|
||||
@@ -11,21 +11,20 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int setlogcons_main(int argc, char **argv);
|
||||
int setlogcons_main(int argc, char **argv)
|
||||
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
struct {
|
||||
char fn;
|
||||
char subarg;
|
||||
} arg;
|
||||
} arg = { 11, /* redirect kernel messages */
|
||||
0 /* to specified console (current as default) */
|
||||
};
|
||||
|
||||
arg.fn = 11; /* redirect kernel messages */
|
||||
arg.subarg = 0; /* to specified console (current as default) */
|
||||
|
||||
if (argc == 2)
|
||||
arg.subarg = xatoul_range(argv[1], 0, 63);
|
||||
if (argv[1])
|
||||
arg.subarg = xatou_range(argv[1], 0, 63);
|
||||
|
||||
xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+24
-3
@@ -135,6 +135,13 @@ config DF
|
||||
df reports the amount of disk space used and available
|
||||
on filesystems.
|
||||
|
||||
config FEATURE_DF_INODE
|
||||
bool "Enable -i (inode information)"
|
||||
default n
|
||||
depends on DF
|
||||
help
|
||||
This option enables support for df -i.
|
||||
|
||||
config DIRNAME
|
||||
bool "dirname"
|
||||
default n
|
||||
@@ -481,6 +488,14 @@ config RMDIR
|
||||
help
|
||||
rmdir is used to remove empty directories.
|
||||
|
||||
config FEATURE_RMDIR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on RMDIR && GETOPT_LONG
|
||||
help
|
||||
Support long options for the rmdir applet, including
|
||||
--ignore-fail-on-non-empty for compatibility with GNU rmdir.
|
||||
|
||||
config SEQ
|
||||
bool "seq"
|
||||
default n
|
||||
@@ -513,7 +528,7 @@ config SORT
|
||||
sort is used to sort lines of text in specified files.
|
||||
|
||||
config FEATURE_SORT_BIG
|
||||
bool "full SuSv3 compliant sort (Support -ktcsbdfiozgM)"
|
||||
bool "Full SuSv3 compliant sort (support -ktcsbdfiozgM)"
|
||||
default y
|
||||
depends on SORT
|
||||
help
|
||||
@@ -531,7 +546,7 @@ config SPLIT
|
||||
split a file into pieces.
|
||||
|
||||
config FEATURE_SPLIT_FANCY
|
||||
bool "fancy extensions"
|
||||
bool "Fancy extensions"
|
||||
default n
|
||||
depends on SPLIT
|
||||
help
|
||||
@@ -572,6 +587,12 @@ config SYNC
|
||||
help
|
||||
sync is used to flush filesystem buffers.
|
||||
|
||||
config TAC
|
||||
bool "tac"
|
||||
default n
|
||||
help
|
||||
tac is used to concatenate and print files in reverse.
|
||||
|
||||
config TAIL
|
||||
bool "tail"
|
||||
default n
|
||||
@@ -595,7 +616,7 @@ config TEE
|
||||
to standard output and files.
|
||||
|
||||
config FEATURE_TEE_USE_BLOCK_IO
|
||||
bool "Enable block i/o (larger/faster) instead of byte i/o."
|
||||
bool "Enable block I/O (larger/faster) instead of byte I/O"
|
||||
default n
|
||||
depends on TEE
|
||||
help
|
||||
|
||||
+8
-2
@@ -12,6 +12,7 @@ lib-$(CONFIG_CAL) += cal.o
|
||||
lib-$(CONFIG_CAT) += cat.o
|
||||
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_LESS) += cat.o # less too
|
||||
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
|
||||
lib-$(CONFIG_CATV) += catv.o
|
||||
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
|
||||
lib-$(CONFIG_CHMOD) += chmod.o
|
||||
@@ -29,6 +30,7 @@ lib-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
lib-$(CONFIG_DU) += du.o
|
||||
lib-$(CONFIG_ECHO) += echo.o
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_ENV) += env.o
|
||||
lib-$(CONFIG_EXPR) += expr.o
|
||||
lib-$(CONFIG_EXPAND) += expand.o
|
||||
@@ -52,6 +54,7 @@ lib-$(CONFIG_NOHUP) += nohup.o
|
||||
lib-$(CONFIG_OD) += od.o
|
||||
lib-$(CONFIG_PRINTENV) += printenv.o
|
||||
lib-$(CONFIG_PRINTF) += printf.o
|
||||
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
|
||||
lib-$(CONFIG_PWD) += pwd.o
|
||||
lib-$(CONFIG_READLINK) += readlink.o
|
||||
lib-$(CONFIG_REALPATH) += realpath.o
|
||||
@@ -66,10 +69,13 @@ 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_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TEST) += test.o
|
||||
lib-$(CONFIG_ASH) += test.o # used by ash
|
||||
lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
|
||||
lib-$(CONFIG_ASH) += test.o test_ptr_hack.o # used by ash
|
||||
lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o # used by hush
|
||||
lib-$(CONFIG_MSH) += test.o test_ptr_hack.o # used by msh
|
||||
lib-$(CONFIG_TOUCH) += touch.o
|
||||
lib-$(CONFIG_TR) += tr.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int basename_main(int argc, char **argv);
|
||||
int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int basename_main(int argc, char **argv)
|
||||
{
|
||||
size_t m, n;
|
||||
@@ -34,17 +34,19 @@ int basename_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
s = bb_get_last_path_component(*++argv);
|
||||
/* It should strip slash: /abc/def/ -> def */
|
||||
s = bb_get_last_path_component_strip(*++argv);
|
||||
|
||||
m = strlen(s);
|
||||
if (*++argv) {
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) {
|
||||
s[m-n] = '\0';
|
||||
m -= n;
|
||||
/*s[m] = '\0'; - redundant */
|
||||
}
|
||||
}
|
||||
|
||||
puts(s);
|
||||
|
||||
return fflush(stdout);
|
||||
/* puts(s) will do, but we can do without stdio this way: */
|
||||
s[m++] = '\n';
|
||||
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
|
||||
}
|
||||
+3
-3
@@ -75,7 +75,7 @@ static char *build_row(char *p, unsigned *dp);
|
||||
#define J_WEEK_LEN (WEEK_LEN + 7)
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
|
||||
int cal_main(int argc, char **argv);
|
||||
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cal_main(int argc, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
@@ -167,7 +167,7 @@ int cal_main(int argc, char **argv)
|
||||
if (!julian) {
|
||||
printf("%*s%s", HEAD_SEP, "", day_headings);
|
||||
}
|
||||
putchar('\n');
|
||||
bb_putchar('\n');
|
||||
for (row = 0; row < (6*7); row += 7) {
|
||||
for (which_cal = 0; which_cal < 3-julian; which_cal++) {
|
||||
dp = days[month + which_cal] + row;
|
||||
@@ -179,7 +179,7 @@ int cal_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(0);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+5
-9
@@ -17,20 +17,16 @@
|
||||
|
||||
int bb_cat(char **argv)
|
||||
{
|
||||
static const char *const argv_dash[] = { "-", NULL };
|
||||
|
||||
int fd;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (!*argv)
|
||||
argv = (char**) &argv_dash;
|
||||
argv = (char**) &bb_argv_dash;
|
||||
|
||||
do {
|
||||
fd = STDIN_FILENO;
|
||||
if (!LONE_DASH(*argv))
|
||||
fd = open_or_warn(*argv, O_RDONLY);
|
||||
fd = open_or_warn_stdin(*argv);
|
||||
if (fd >= 0) {
|
||||
/* This is not an xfunc - never exits */
|
||||
/* This is not a xfunc - never exits */
|
||||
off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
@@ -43,8 +39,8 @@ int bb_cat(char **argv)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int cat_main(int argc, char **argv);
|
||||
int cat_main(int argc, char **argv)
|
||||
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cat_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
getopt32(argv, "u");
|
||||
argv += optind;
|
||||
|
||||
+7
-11
@@ -12,8 +12,8 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int catv_main(int argc, char **argv);
|
||||
int catv_main(int argc, char **argv)
|
||||
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int catv_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
@@ -27,18 +27,14 @@ int catv_main(int argc, char **argv)
|
||||
argv += optind;
|
||||
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
fd = 0;
|
||||
if (!argv[0]) {
|
||||
argv--;
|
||||
goto jump_in;
|
||||
}
|
||||
if (!argv[0])
|
||||
*--argv = (char*)"-";
|
||||
do {
|
||||
fd = open_or_warn(*argv, O_RDONLY);
|
||||
fd = open_or_warn_stdin(*argv);
|
||||
if (fd < 0) {
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
jump_in:
|
||||
for (;;) {
|
||||
int i, res;
|
||||
|
||||
@@ -62,13 +58,13 @@ int catv_main(int argc, char **argv)
|
||||
if (c < 32) {
|
||||
if (c == 10) {
|
||||
if (flags & CATV_OPT_e)
|
||||
putchar('$');
|
||||
bb_putchar('$');
|
||||
} else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
|
||||
printf("^%c", c+'@');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
bb_putchar(c);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP && fd)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int chgrp_main(int argc, char **argv);
|
||||
int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chgrp_main(int argc, char **argv)
|
||||
{
|
||||
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
|
||||
|
||||
+3
-3
@@ -63,12 +63,12 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
|
||||
}
|
||||
err:
|
||||
if (!OPT_QUIET)
|
||||
bb_perror_msg("%s", fileName);
|
||||
bb_simple_perror_msg(fileName);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chmod_main(int argc, char **argv);
|
||||
int chmod_main(int argc, char **argv)
|
||||
int chmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chmod_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
char *arg, **argp;
|
||||
|
||||
+3
-4
@@ -42,7 +42,7 @@ typedef int (*chown_fptr)(const char *, uid_t, gid_t);
|
||||
static struct bb_uidgid_t ugid = { -1, -1 };
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
void *cf, int depth)
|
||||
void *cf, int depth ATTRIBUTE_UNUSED)
|
||||
{
|
||||
uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
|
||||
gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
|
||||
@@ -57,12 +57,11 @@ static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
return TRUE;
|
||||
}
|
||||
if (!OPT_QUIET)
|
||||
bb_perror_msg("%s", fileName); /* A filename can have % in it... */
|
||||
bb_simple_perror_msg(fileName); /* A filename can have % in it... */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chown_main(int argc, char **argv);
|
||||
int chown_main(int argc, char **argv)
|
||||
int chown_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int flags;
|
||||
|
||||
+2
-4
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int chroot_main(int argc, char **argv);
|
||||
int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
@@ -19,9 +19,7 @@ int chroot_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
++argv;
|
||||
if (chroot(*argv)) {
|
||||
bb_perror_msg_and_die("cannot change root directory to %s", *argv);
|
||||
}
|
||||
xchroot(*argv);
|
||||
xchdir("/");
|
||||
|
||||
++argv;
|
||||
|
||||
+22
-20
@@ -8,47 +8,49 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int cksum_main(int argc, char **argv);
|
||||
int cksum_main(int argc, char **argv)
|
||||
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cksum_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, 1);
|
||||
|
||||
FILE *fp;
|
||||
uint32_t crc;
|
||||
long length, filesize;
|
||||
int bytes_read;
|
||||
char *cp;
|
||||
uint8_t *cp;
|
||||
|
||||
int inp_stdin = (argc == optind) ? 1 : 0;
|
||||
#if ENABLE_DESKTOP
|
||||
getopt32(argv, ""); /* coreutils 6.9 compat */
|
||||
argv += optind;
|
||||
#else
|
||||
argv++;
|
||||
#endif
|
||||
|
||||
do {
|
||||
fp = fopen_or_warn_stdin((inp_stdin) ? bb_msg_standard_input : *++argv);
|
||||
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
|
||||
|
||||
if (fd < 0)
|
||||
continue;
|
||||
crc = 0;
|
||||
length = 0;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
while ((bytes_read = fread(read_buf, 1, BUFSIZ, fp)) > 0) {
|
||||
cp = read_buf;
|
||||
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
|
||||
cp = (uint8_t *) read_buf;
|
||||
length += bytes_read;
|
||||
while (bytes_read--)
|
||||
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL];
|
||||
do {
|
||||
crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *cp++];
|
||||
} while (--bytes_read);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
filesize = length;
|
||||
|
||||
for (; length; length >>= 8)
|
||||
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xffL];
|
||||
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xff];
|
||||
crc ^= 0xffffffffL;
|
||||
|
||||
if (inp_stdin) {
|
||||
printf("%" PRIu32 " %li\n", crc, filesize);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%" PRIu32 " %li %s\n", crc, filesize, *argv);
|
||||
fclose(fp);
|
||||
} while (*(argv + 1));
|
||||
printf((*argv ? "%" PRIu32 " %li %s\n" : "%" PRIu32 " %li\n"),
|
||||
crc, filesize, *argv);
|
||||
} while (*argv && *++argv);
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+2
-2
@@ -35,8 +35,8 @@ static void writeline(char *line, int class, int flags)
|
||||
fputs(line, stdout);
|
||||
}
|
||||
|
||||
int comm_main(int argc, char **argv);
|
||||
int comm_main(int argc, char **argv)
|
||||
int comm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int comm_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
#define LINE_LEN 100
|
||||
#define BB_EOF_0 0x1
|
||||
|
||||
+28
-24
@@ -21,7 +21,7 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int cp_main(int argc, char **argv);
|
||||
int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cp_main(int argc, char **argv)
|
||||
{
|
||||
struct stat source_stat;
|
||||
@@ -37,20 +37,27 @@ int cp_main(int argc, char **argv)
|
||||
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
|
||||
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
|
||||
OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
OPT_L = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
|
||||
};
|
||||
|
||||
// Soft- and hardlinking don't mix
|
||||
// Need at least two arguments
|
||||
// Soft- and hardlinking doesn't mix
|
||||
// -P and -d are the same (-P is POSIX, -d is GNU)
|
||||
// -r and -R are the same
|
||||
// -R (and therefore -r) turns on -d (coreutils does this)
|
||||
// -a = -pdR
|
||||
opt_complementary = "l--s:s--l:Pd:rR:apdR";
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL");
|
||||
/* Default behavior of cp is to dereference, so we don't have to do
|
||||
* anything special when we are given -L.
|
||||
* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||
* just ignore it too for fun.
|
||||
if (flags & OPT_L) ...
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPH");
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
|
||||
/* coreutils 6.9 compat:
|
||||
* by default, "cp" derefs symlinks (creates regular dest files),
|
||||
* but "cp -R" does not. We switch off deref if -r or -R (see above).
|
||||
* However, "cp -RL" must still deref symlinks: */
|
||||
if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
|
||||
flags |= FILEUTILS_DEREFERENCE;
|
||||
/* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||
* just ignore it too for fun. TODO.
|
||||
if (flags & OPT_H) ... // deref command-line params only
|
||||
*/
|
||||
|
||||
@@ -60,17 +67,9 @@ int cp_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
||||
|
||||
if (optind + 2 > argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
last = argv[argc - 1];
|
||||
argv += optind;
|
||||
|
||||
/* If there are only two arguments and... */
|
||||
if (optind + 2 == argc) {
|
||||
if (argc == 2) {
|
||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
if (s_flags < 0)
|
||||
@@ -85,19 +84,24 @@ int cp_main(int argc, char **argv)
|
||||
((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
) {
|
||||
/* ...do a simple copy. */
|
||||
dest = xstrdup(last);
|
||||
goto DO_COPY; /* Note: optind+2==argc implies argv[1]==last below. */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
dest = concat_path_file(last, bb_get_last_path_component(*argv));
|
||||
while (1) {
|
||||
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
|
||||
DO_COPY:
|
||||
if (copy_file(*argv, dest, flags) < 0) {
|
||||
status = 1;
|
||||
}
|
||||
if (*++argv == last) {
|
||||
/* possibly leaking dest... */
|
||||
break;
|
||||
}
|
||||
free((void*)dest);
|
||||
} while (*++argv != last);
|
||||
}
|
||||
|
||||
/* Exit. We are NOEXEC, not NOFORK. We do exit at the end of main() */
|
||||
return status;
|
||||
}
|
||||
+38
-47
@@ -16,13 +16,11 @@
|
||||
|
||||
/* option vars */
|
||||
static const char optstring[] ALIGN1 = "b:c:f:d:sn";
|
||||
#define CUT_OPT_BYTE_FLGS (1<<0)
|
||||
#define CUT_OPT_CHAR_FLGS (1<<1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1<<2)
|
||||
#define CUT_OPT_DELIM_FLGS (1<<3)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1<<4)
|
||||
|
||||
static char delim = '\t'; /* delimiter, default is tab */
|
||||
#define CUT_OPT_BYTE_FLGS (1 << 0)
|
||||
#define CUT_OPT_CHAR_FLGS (1 << 1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1 << 2)
|
||||
#define CUT_OPT_DELIM_FLGS (1 << 3)
|
||||
#define CUT_OPT_SUPPRESS_FLGS (1 << 4)
|
||||
|
||||
struct cut_list {
|
||||
int startpos;
|
||||
@@ -47,13 +45,13 @@ static int cmpfunc(const void *a, const void *b)
|
||||
|
||||
}
|
||||
|
||||
static void cut_file(FILE * file)
|
||||
static void cut_file(FILE *file, char delim)
|
||||
{
|
||||
char *line = NULL;
|
||||
unsigned int linenum = 0; /* keep these zero-based to be consistent */
|
||||
|
||||
/* go through every line in the file */
|
||||
while ((line = xmalloc_getline(file)) != NULL) {
|
||||
while ((line = xmalloc_fgetline(file)) != NULL) {
|
||||
|
||||
/* set up a list so we can keep track of what's been printed */
|
||||
char * printed = xzalloc(strlen(line) * sizeof(char));
|
||||
@@ -66,7 +64,7 @@ static void cut_file(FILE * file)
|
||||
/* print the chars specified in each cut list */
|
||||
for (; cl_pos < nlists; cl_pos++) {
|
||||
spos = cut_lists[cl_pos].startpos;
|
||||
while (spos < strlen(line)) {
|
||||
while (spos < (int)strlen(line)) {
|
||||
if (!printed[spos]) {
|
||||
printed[spos] = 'X';
|
||||
putchar(line[spos]);
|
||||
@@ -82,12 +80,12 @@ static void cut_file(FILE * file)
|
||||
|
||||
/* get out if we have no more lists to process or if the lines
|
||||
* are lower than what we're interested in */
|
||||
if (linenum < spos || cl_pos >= nlists)
|
||||
if (((int)linenum < spos) || (cl_pos >= nlists))
|
||||
goto next_line;
|
||||
|
||||
/* if the line we're looking for is lower than the one we were
|
||||
* passed, it means we displayed it already, so move on */
|
||||
while (spos < linenum) {
|
||||
while (spos < (int)linenum) {
|
||||
spos++;
|
||||
/* go to the next list if we're at the end of this one */
|
||||
if (spos > cut_lists[cl_pos].endpos
|
||||
@@ -99,7 +97,7 @@ static void cut_file(FILE * file)
|
||||
spos = cut_lists[cl_pos].startpos;
|
||||
/* get out if the current line is lower than the one
|
||||
* we just became interested in */
|
||||
if (linenum < spos)
|
||||
if ((int)linenum < spos)
|
||||
goto next_line;
|
||||
}
|
||||
}
|
||||
@@ -163,11 +161,10 @@ static void cut_file(FILE * file)
|
||||
}
|
||||
}
|
||||
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
int cut_main(int argc, char **argv)
|
||||
int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cut_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
char delim = '\t'; /* delimiter, default is tab */
|
||||
char *sopt, *ltok;
|
||||
|
||||
opt_complementary = "b--bcf:c--bcf:f--bcf";
|
||||
@@ -178,7 +175,7 @@ int cut_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
|
||||
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
|
||||
if (strlen(ltok) > 1) {
|
||||
if (ltok[0] && ltok[1]) { /* more than 1 char? */
|
||||
bb_error_msg_and_die("the delimiter must be a single character");
|
||||
}
|
||||
delim = ltok[0];
|
||||
@@ -186,6 +183,8 @@ int cut_main(int argc, char **argv)
|
||||
|
||||
/* non-field (char or byte) cutting has some special handling */
|
||||
if (!(option_mask32 & CUT_OPT_FIELDS_FLGS)) {
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
|
||||
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS) {
|
||||
bb_error_msg_and_die
|
||||
("suppressing non-delimited lines makes sense%s",
|
||||
@@ -206,19 +205,16 @@ int cut_main(int argc, char **argv)
|
||||
char *ntok;
|
||||
int s = 0, e = 0;
|
||||
|
||||
/* take apart the lists, one by one (they are separated with commas */
|
||||
/* take apart the lists, one by one (they are separated with commas) */
|
||||
while ((ltok = strsep(&sopt, ",")) != NULL) {
|
||||
|
||||
/* it's actually legal to pass an empty list */
|
||||
if (strlen(ltok) == 0)
|
||||
if (!ltok[0])
|
||||
continue;
|
||||
|
||||
/* get the start pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
bb_error_msg
|
||||
("internal error: ntok is null for start pos!?\n");
|
||||
} else if (strlen(ntok) == 0) {
|
||||
if (!ntok[0]) {
|
||||
s = BOL;
|
||||
} else {
|
||||
s = xatoi_u(ntok);
|
||||
@@ -229,13 +225,12 @@ int cut_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* get the end pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
if (ltok == NULL) {
|
||||
e = NON_RANGE;
|
||||
} else if (strlen(ntok) == 0) {
|
||||
} else if (!ltok[0]) {
|
||||
e = EOL;
|
||||
} else {
|
||||
e = xatoi_u(ntok);
|
||||
e = xatoi_u(ltok);
|
||||
/* if the user specified and end position of 0, that means "til the
|
||||
* end of the line */
|
||||
if (e == 0)
|
||||
@@ -245,11 +240,6 @@ int cut_main(int argc, char **argv)
|
||||
e = NON_RANGE;
|
||||
}
|
||||
|
||||
/* if there's something left to tokenize, the user passed
|
||||
* an invalid list */
|
||||
if (ltok)
|
||||
bb_error_msg_and_die("invalid byte or field list");
|
||||
|
||||
/* add the new list */
|
||||
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
|
||||
cut_lists[nlists-1].startpos = s;
|
||||
@@ -266,23 +256,24 @@ int cut_main(int argc, char **argv)
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
}
|
||||
|
||||
/* argv[0..argc-1] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[0] == NULL || LONE_DASH(argv[0])) {
|
||||
cut_file(stdin);
|
||||
} else {
|
||||
FILE *file;
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (!*argv)
|
||||
*--argv = (char *)"-";
|
||||
|
||||
do {
|
||||
file = fopen_or_warn(argv[0], "r");
|
||||
if (file) {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
FILE *file = fopen_or_warn_stdin(*argv);
|
||||
if (!file) {
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
cut_file(file, delim);
|
||||
fclose_if_not_stdin(file);
|
||||
} while (*++argv);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
fflush_stdout_and_exit(retval);
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+109
-107
@@ -38,132 +38,136 @@ static void maybe_set_utc(int opt)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
}
|
||||
|
||||
int date_main(int argc, char **argv);
|
||||
int date_main(int argc, char **argv)
|
||||
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int date_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
time_t tm;
|
||||
unsigned opt;
|
||||
int ifmt = -1;
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *filename = NULL;
|
||||
char *isofmt_arg;
|
||||
char *hintfmt_arg;
|
||||
char *date_str;
|
||||
char *fmt_dt2str;
|
||||
char *fmt_str2dt;
|
||||
char *filename;
|
||||
char *isofmt_arg = NULL;
|
||||
|
||||
opt_complementary = "d--s:s--d"
|
||||
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
opt = getopt32(argv, "Rs:ud:r:"
|
||||
USE_FEATURE_DATE_ISOFMT("I::D:"),
|
||||
&date_str, &date_str, &filename
|
||||
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
|
||||
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
|
||||
argv += optind;
|
||||
maybe_set_utc(opt);
|
||||
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) {
|
||||
if (!isofmt_arg) {
|
||||
ifmt = 0; /* default is date */
|
||||
} else {
|
||||
static const char *const isoformats[] = {
|
||||
"date", "hours", "minutes", "seconds"
|
||||
};
|
||||
|
||||
for (ifmt = 0; ifmt < 4; ifmt++)
|
||||
if (!strcmp(isofmt_arg, isoformats[ifmt]))
|
||||
goto found;
|
||||
/* parse error */
|
||||
bb_show_usage();
|
||||
found: ;
|
||||
ifmt = 0; /* default is date */
|
||||
if (isofmt_arg) {
|
||||
static const char isoformats[] ALIGN1 =
|
||||
"date\0""hours\0""minutes\0""seconds\0";
|
||||
ifmt = index_in_strings(isoformats, isofmt_arg);
|
||||
if (ifmt < 0)
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX, date_fmt == NULL from this always */
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
} else if (date_str == NULL) {
|
||||
opt |= DATE_OPT_SET;
|
||||
date_str = argv[optind];
|
||||
fmt_dt2str = NULL;
|
||||
if (argv[0] && argv[0][0] == '+') {
|
||||
fmt_dt2str = &argv[0][1]; /* Skip over the '+' */
|
||||
argv++;
|
||||
}
|
||||
if (!(opt & (DATE_OPT_SET | DATE_OPT_DATE))) {
|
||||
opt |= DATE_OPT_SET;
|
||||
date_str = argv[0]; /* can be NULL */
|
||||
if (date_str)
|
||||
argv++;
|
||||
}
|
||||
if (*argv)
|
||||
bb_show_usage();
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
if (filename) {
|
||||
if (opt & DATE_OPT_REFERENCE) {
|
||||
struct stat statbuf;
|
||||
xstat(filename, &statbuf);
|
||||
tm = statbuf.st_mtime;
|
||||
} else
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
|
||||
/* If date string is given, update tm_time, and maybe set date */
|
||||
if (date_str != NULL) {
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_HINT)) {
|
||||
strptime(date_str, hintfmt_arg, &tm_time);
|
||||
} else if (strchr(date_str, ':') != NULL) {
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
} else {
|
||||
char end = '\0';
|
||||
const char *last_colon = strrchr(date_str, ':');
|
||||
|
||||
if (sscanf(date_str, "%d:%d:%d", &tm_time.tm_hour, &tm_time.tm_min,
|
||||
&tm_time.tm_sec) == 3) {
|
||||
/* no adjustments needed */
|
||||
} else if (sscanf(date_str, "%d:%d", &tm_time.tm_hour,
|
||||
&tm_time.tm_min) == 2) {
|
||||
/* no adjustments needed */
|
||||
} else if (sscanf(date_str, "%d.%d-%d:%d:%d", &tm_time.tm_mon,
|
||||
&tm_time.tm_mday, &tm_time.tm_hour,
|
||||
&tm_time.tm_min, &tm_time.tm_sec) == 5) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
tm_time.tm_mon -= 1;
|
||||
} else if (sscanf(date_str, "%d.%d-%d:%d", &tm_time.tm_mon,
|
||||
&tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min) == 4) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
tm_time.tm_mon -= 1;
|
||||
} else if (sscanf(date_str, "%d.%d.%d-%d:%d:%d", &tm_time.tm_year,
|
||||
if (last_colon != NULL) {
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (sscanf(date_str, "%u:%u%c",
|
||||
&tm_time.tm_hour,
|
||||
&tm_time.tm_min,
|
||||
&end) >= 2) {
|
||||
/* no adjustments needed */
|
||||
} else if (sscanf(date_str, "%u.%u-%u:%u%c",
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&tm_time.tm_sec) == 6) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
} else if (sscanf(date_str, "%d.%d.%d-%d:%d", &tm_time.tm_year,
|
||||
&end) >= 4) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
tm_time.tm_mon -= 1;
|
||||
} else if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &tm_time.tm_year,
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min) == 5) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
} else {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
} else {
|
||||
int nr;
|
||||
char *cp;
|
||||
|
||||
nr = sscanf(date_str, "%2d%2d%2d%2d%d", &tm_time.tm_mon,
|
||||
&tm_time.tm_mday, &tm_time.tm_hour, &tm_time.tm_min,
|
||||
&tm_time.tm_year);
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
|
||||
cp = strchr(date_str, '.');
|
||||
if (cp) {
|
||||
nr = sscanf(cp + 1, "%2d", &tm_time.tm_sec);
|
||||
if (nr != 1) {
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&end) >= 5) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
} else if (sscanf(date_str, "%u-%u-%u %u:%u%c", &tm_time.tm_year,
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&end) >= 5) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
//TODO: coreutils 6.9 also accepts "YYYY-MM-DD HH" (no minutes)
|
||||
} else {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
if (end == ':') {
|
||||
if (sscanf(last_colon + 1, "%u%c", &tm_time.tm_sec, &end) == 1)
|
||||
end = '\0';
|
||||
/* else end != NUL and we error out */
|
||||
}
|
||||
} else {
|
||||
if (sscanf(date_str, "%2u%2u%2u%2u%u%c", &tm_time.tm_mon,
|
||||
&tm_time.tm_mday, &tm_time.tm_hour, &tm_time.tm_min,
|
||||
&tm_time.tm_year, &end) < 4)
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time.tm_year >= 1900) {
|
||||
tm_time.tm_year -= 1900;
|
||||
}
|
||||
/* adjust date */
|
||||
tm_time.tm_mon -= 1;
|
||||
if (end == '.') {
|
||||
if (sscanf(strchr(date_str, '.') + 1, "%u%c",
|
||||
&tm_time.tm_sec, &end) == 1)
|
||||
end = '\0';
|
||||
/* else end != NUL and we error out */
|
||||
}
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time.tm_year >= 1900) {
|
||||
tm_time.tm_year -= 1900;
|
||||
if (end != '\0') {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
/* adjust date */
|
||||
tm_time.tm_mon -= 1;
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst. */
|
||||
tm = mktime(&tm_time);
|
||||
@@ -181,55 +185,53 @@ int date_main(int argc, char **argv)
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
|
||||
if (date_fmt == NULL) {
|
||||
if (fmt_dt2str == NULL) {
|
||||
int i;
|
||||
date_fmt = xzalloc(32);
|
||||
fmt_dt2str = xzalloc(32);
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
||||
strcpy(date_fmt, "%Y-%m-%d");
|
||||
strcpy(fmt_dt2str, "%Y-%m-%d");
|
||||
if (ifmt > 0) {
|
||||
i = 8;
|
||||
date_fmt[i++] = 'T';
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i++] = 'H';
|
||||
fmt_dt2str[i++] = 'T';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'H';
|
||||
if (ifmt > 1) {
|
||||
date_fmt[i++] = ':';
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i++] = 'M';
|
||||
}
|
||||
if (ifmt > 2) {
|
||||
date_fmt[i++] = ':';
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i++] = 'S';
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'M';
|
||||
if (ifmt > 2) {
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'S';
|
||||
}
|
||||
}
|
||||
format_utc:
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
||||
}
|
||||
} else if (opt & DATE_OPT_RFC2822) {
|
||||
/* Undo busybox.c for date -R */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
|
||||
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = 22;
|
||||
goto format_utc;
|
||||
} else /* default case */
|
||||
date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
|
||||
#define date_buf bb_common_bufsiz1
|
||||
if (*date_fmt == '\0') {
|
||||
if (*fmt_dt2str == '\0') {
|
||||
/* With no format string, just print a blank line */
|
||||
date_buf[0] = '\0';
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
strftime(date_buf, sizeof(date_buf), date_fmt, &tm_time);
|
||||
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
|
||||
}
|
||||
puts(date_buf);
|
||||
|
||||
|
||||
+126
-104
@@ -14,6 +14,11 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
enum {
|
||||
ifd = STDIN_FILENO,
|
||||
ofd = STDOUT_FILENO,
|
||||
};
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
@@ -45,22 +50,22 @@ static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
|
||||
G.out_full, G.out_part);
|
||||
}
|
||||
|
||||
static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
|
||||
static ssize_t full_write_or_warn(const void *buf, size_t len,
|
||||
const char *const filename)
|
||||
{
|
||||
ssize_t n = full_write(fd, buf, len);
|
||||
ssize_t n = full_write(ofd, buf, len);
|
||||
if (n < 0)
|
||||
bb_perror_msg("writing '%s'", filename);
|
||||
return n;
|
||||
}
|
||||
|
||||
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
|
||||
static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
const char *filename)
|
||||
{
|
||||
ssize_t n = full_write_or_warn(fd, buf, len, filename);
|
||||
ssize_t n = full_write_or_warn(buf, len, filename);
|
||||
if (n < 0)
|
||||
return 1;
|
||||
if (n == obs)
|
||||
if ((size_t)n == obs)
|
||||
G.out_full++;
|
||||
else if (n) /* > 0 */
|
||||
G.out_part++;
|
||||
@@ -73,24 +78,32 @@ static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
|
||||
#define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv);
|
||||
int dd_main(int argc, char **argv)
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
enum {
|
||||
FLAG_SYNC = 1 << 0,
|
||||
FLAG_NOERROR = 1 << 1,
|
||||
FLAG_NOTRUNC = 1 << 2,
|
||||
FLAG_TWOBUFS = 1 << 3,
|
||||
FLAG_COUNT = 1 << 4,
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = 1 << 0,
|
||||
FLAG_SYNC = 1 << 1,
|
||||
FLAG_NOERROR = 1 << 2,
|
||||
FLAG_FSYNC = 1 << 3,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = 1 << 4,
|
||||
FLAG_COUNT = 1 << 5,
|
||||
};
|
||||
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 ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0"
|
||||
"ibs\0""obs\0""conv\0"
|
||||
#endif
|
||||
;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 1,
|
||||
OP_bs = 0,
|
||||
OP_count,
|
||||
OP_seek,
|
||||
OP_skip,
|
||||
@@ -100,126 +113,132 @@ int dd_main(int argc, char **argv)
|
||||
OP_ibs,
|
||||
OP_obs,
|
||||
OP_conv,
|
||||
OP_conv_notrunc,
|
||||
/* Must be in the same order as FLAG_XXX! */
|
||||
OP_conv_notrunc = 0,
|
||||
OP_conv_sync,
|
||||
OP_conv_noerror,
|
||||
OP_conv_fsync,
|
||||
/* Unimplemented conv=XXX: */
|
||||
//nocreat do not create the output file
|
||||
//excl fail if the output file already exists
|
||||
//fdatasync physically write output file data before finishing
|
||||
//swab swap every pair of input bytes
|
||||
//lcase change upper case to lower case
|
||||
//ucase change lower case to upper case
|
||||
//block pad newline-terminated records with spaces to cbs-size
|
||||
//unblock replace trailing spaces in cbs-size records with newline
|
||||
//ascii from EBCDIC to ASCII
|
||||
//ebcdic from ASCII to EBCDIC
|
||||
//ibm from ASCII to alternate EBCDIC
|
||||
#endif
|
||||
};
|
||||
int exitcode = EXIT_FAILURE;
|
||||
size_t ibs = 512, obs = 512;
|
||||
ssize_t n, w;
|
||||
char *ibuf, *obuf;
|
||||
/* And these are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
int ifd, ofd;
|
||||
size_t oc;
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
struct sigaction sigact;
|
||||
#endif
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define ifd (Z.ifd )
|
||||
#define ofd (Z.ofd )
|
||||
#define oc (Z.oc )
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
#define skip (Z.skip )
|
||||
#define infile (Z.infile )
|
||||
#define outfile (Z.outfile)
|
||||
#define sigact (Z.sigact )
|
||||
|
||||
memset(&Z, 0, sizeof(Z));
|
||||
INIT_G();
|
||||
//fflush(NULL); - is this needed because of NOEXEC?
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
sigact.sa_handler = dd_output_status;
|
||||
sigact.sa_flags = SA_RESTART;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigaction(SIGUSR1, &sigact, NULL);
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
#endif
|
||||
|
||||
for (n = 1; n < argc; n++) {
|
||||
smalluint key_len;
|
||||
smalluint what;
|
||||
char *key;
|
||||
for (n = 1; argv[n]; n++) {
|
||||
int what;
|
||||
char *val;
|
||||
char *arg = argv[n];
|
||||
|
||||
//XXX:FIXME: we reject plain "dd --" This would cost ~20 bytes, so..
|
||||
//if (*arg == '-' && *++arg == '-' && !*++arg) continue;
|
||||
key = strstr(arg, "=");
|
||||
if (key == NULL)
|
||||
#if ENABLE_DESKTOP
|
||||
/* "dd --". NB: coreutils 6.9 will complain if they see
|
||||
* more than one of them. We wouldn't. */
|
||||
if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0')
|
||||
continue;
|
||||
#endif
|
||||
val = strchr(arg, '=');
|
||||
if (val == NULL)
|
||||
bb_show_usage();
|
||||
key_len = key - arg + 1;
|
||||
key = xstrndup(arg, key_len);
|
||||
what = index_in_strings(keywords, key) + 1;
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(key);
|
||||
if (what == 0)
|
||||
*val = '\0';
|
||||
what = index_in_strings(keywords, arg);
|
||||
if (what < 0)
|
||||
bb_show_usage();
|
||||
arg += key_len;
|
||||
/* Must fit into positive ssize_t */
|
||||
/* *val = '='; - to preserve ps listing? */
|
||||
val++;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (what == OP_ibs) {
|
||||
ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
while (1) {
|
||||
/* find ',', replace them with nil so we can use arg for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on arg being non-null, else strchr would fault.
|
||||
*/
|
||||
key = strchr(arg, ',');
|
||||
if (key)
|
||||
*key = '\0';
|
||||
what = index_in_strings(keywords, arg) + 1;
|
||||
if (what < OP_conv_notrunc)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
|
||||
if (what == OP_conv_notrunc)
|
||||
flags |= FLAG_NOTRUNC;
|
||||
if (what == OP_conv_sync)
|
||||
flags |= FLAG_SYNC;
|
||||
if (what == OP_conv_noerror)
|
||||
flags |= FLAG_NOERROR;
|
||||
if (!key) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
arg = key + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
continue;
|
||||
if (what == OP_ibs) {
|
||||
/* Must fit into positive ssize_t */
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
while (1) {
|
||||
/* find ',', replace them with NUL so we can use val for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on val being non-null, else strchr would fault.
|
||||
*/
|
||||
arg = strchr(val, ',');
|
||||
if (arg)
|
||||
*arg = '\0';
|
||||
what = index_in_strings(conv_words, val);
|
||||
if (what < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
flags |= (1 << what);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
val = arg + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
continue; /* we trashed 'what', can't fall through */
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
ibs = obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
if (what == OP_count) {
|
||||
flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
count = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_seek) {
|
||||
seek = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
seek = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_skip) {
|
||||
skip = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
skip = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_if) {
|
||||
infile = arg;
|
||||
continue;
|
||||
infile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_of)
|
||||
outfile = arg;
|
||||
}
|
||||
if (what == OP_of) {
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
} /* end of "for (argv[n])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
ibuf = obuf = xmalloc(ibs);
|
||||
if (ibs != obs) {
|
||||
@@ -227,9 +246,8 @@ int dd_main(int argc, char **argv)
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
if (infile != NULL)
|
||||
ifd = xopen(infile, O_RDONLY);
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
else {
|
||||
/* ifd = STDIN_FILENO; - it's zero and it's already there */
|
||||
infile = bb_msg_standard_input;
|
||||
}
|
||||
if (outfile != NULL) {
|
||||
@@ -238,7 +256,7 @@ int dd_main(int argc, char **argv)
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
ofd = xopen(outfile, oflag);
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
@@ -250,7 +268,6 @@ int dd_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ofd = STDOUT_FILENO;
|
||||
outfile = bb_msg_standard_output;
|
||||
}
|
||||
if (skip) {
|
||||
@@ -276,11 +293,10 @@ int dd_main(int argc, char **argv)
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
if (flags & FLAG_NOERROR) {
|
||||
n = ibs;
|
||||
bb_perror_msg("%s", infile);
|
||||
} else
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
n = ibs;
|
||||
bb_simple_perror_msg(infile);
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
@@ -296,39 +312,45 @@ int dd_main(int argc, char **argv)
|
||||
while (n) {
|
||||
size_t d = obs - oc;
|
||||
|
||||
if (d > n)
|
||||
if (d > (size_t)n)
|
||||
d = n;
|
||||
memcpy(obuf + oc, tmp, d);
|
||||
n -= d;
|
||||
tmp += d;
|
||||
oc += d;
|
||||
if (oc == obs) {
|
||||
if (write_and_stats(ofd, obuf, obs, obs, outfile))
|
||||
if (write_and_stats(obuf, obs, obs, outfile))
|
||||
goto out_status;
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else if (write_and_stats(ofd, ibuf, n, obs, outfile))
|
||||
} else if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
w = full_write_or_warn(ofd, obuf, oc, outfile);
|
||||
w = full_write_or_warn(obuf, oc, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w > 0)
|
||||
G.out_part++;
|
||||
if (w > 0) G.out_part++;
|
||||
}
|
||||
if (close(ifd) < 0) {
|
||||
die_infile:
|
||||
bb_perror_msg_and_die("%s", infile);
|
||||
bb_simple_perror_msg_and_die(infile);
|
||||
}
|
||||
|
||||
if (close(ofd) < 0) {
|
||||
die_outfile:
|
||||
bb_perror_msg_and_die("%s", outfile);
|
||||
bb_simple_perror_msg_and_die(outfile);
|
||||
}
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
out_status:
|
||||
dd_output_status(0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return exitcode;
|
||||
}
|
||||
+34
-10
@@ -29,7 +29,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
}
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv);
|
||||
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int df_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long blocks_used;
|
||||
@@ -45,23 +45,32 @@ int df_main(int argc, char **argv)
|
||||
/* default display is kilobytes */
|
||||
const char *disp_units_hdr = "1k-blocks";
|
||||
|
||||
enum {
|
||||
OPT_ALL = (1 << 0),
|
||||
OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 4) : (1 << 2))
|
||||
* ENABLE_FEATURE_DF_INODE
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk";
|
||||
opt = getopt32(argv, "hmk");
|
||||
if (opt & 1) {
|
||||
opt = getopt32(argv, "ahmk" USE_FEATURE_DF_INODE("i"));
|
||||
if (opt & (1 << 1)) { // -h
|
||||
df_disp_hr = 0;
|
||||
disp_units_hdr = " Size";
|
||||
}
|
||||
if (opt & 2) {
|
||||
if (opt & (1 << 2)) { // -m
|
||||
df_disp_hr = 1024*1024;
|
||||
disp_units_hdr = "1M-blocks";
|
||||
}
|
||||
if (opt & OPT_INODE) {
|
||||
disp_units_hdr = " Inodes";
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "k");
|
||||
opt = getopt32(argv, "ak" USE_FEATURE_DF_INODE("i"));
|
||||
#endif
|
||||
|
||||
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
|
||||
"", disp_units_hdr);
|
||||
printf("Filesystem %-15sUsed Available Use%% Mounted on\n",
|
||||
disp_units_hdr);
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -100,11 +109,20 @@ int df_main(int argc, char **argv)
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_perror_msg("%s", mount_point);
|
||||
bb_simple_perror_msg(mount_point);
|
||||
goto SET_ERROR;
|
||||
}
|
||||
|
||||
if ((s.f_blocks > 0) || !mount_table){
|
||||
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
|
||||
if (opt & OPT_INODE) {
|
||||
s.f_blocks = s.f_files;
|
||||
s.f_bavail = s.f_bfree = s.f_ffree;
|
||||
s.f_bsize = 1;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
if (df_disp_hr)
|
||||
df_disp_hr = 1;
|
||||
#endif
|
||||
}
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
if (blocks_used + s.f_bavail) {
|
||||
@@ -113,9 +131,14 @@ int df_main(int argc, char **argv)
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
|
||||
#ifdef WHY_IT_SHOULD_BE_HIDDEN
|
||||
if (strcmp(device, "rootfs") == 0) {
|
||||
continue;
|
||||
} else if (strcmp(device, "/dev/root") == 0) {
|
||||
}
|
||||
#endif
|
||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||
/* ... and also this is the only user of find_block_device */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
device = find_block_device("/");
|
||||
@@ -123,6 +146,7 @@ int df_main(int argc, char **argv)
|
||||
goto SET_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int dirname_main(int argc, char **argv);
|
||||
int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dirname_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
|
||||
+29
-42
@@ -20,74 +20,63 @@ enum {
|
||||
};
|
||||
|
||||
/* if fn is NULL then input is stdin and output is stdout */
|
||||
static int convert(char *fn, int conv_type)
|
||||
static void convert(char *fn, int conv_type)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int i;
|
||||
#define name_buf bb_common_bufsiz1
|
||||
char *temp_fn = temp_fn; /* for compiler */
|
||||
char *resolved_fn = resolved_fn;
|
||||
|
||||
in = stdin;
|
||||
out = stdout;
|
||||
if (fn != NULL) {
|
||||
in = xfopen(fn, "rw");
|
||||
/*
|
||||
The file is then created with mode read/write and
|
||||
permissions 0666 for glibc 2.0.6 and earlier or
|
||||
0600 for glibc 2.0.7 and later.
|
||||
*/
|
||||
snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn);
|
||||
i = mkstemp(&name_buf[0]);
|
||||
if (i == -1 || chmod(name_buf, 0600) == -1) {
|
||||
bb_perror_nomsg_and_die();
|
||||
}
|
||||
out = fdopen(i, "w+");
|
||||
if (!out) {
|
||||
close(i);
|
||||
remove(name_buf);
|
||||
return -2;
|
||||
struct stat st;
|
||||
|
||||
resolved_fn = xmalloc_follow_symlinks(fn);
|
||||
if (resolved_fn == NULL)
|
||||
bb_simple_perror_msg_and_die(fn);
|
||||
in = xfopen(resolved_fn, "r");
|
||||
fstat(fileno(in), &st);
|
||||
|
||||
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
|
||||
i = mkstemp(temp_fn);
|
||||
if (i == -1
|
||||
|| fchmod(i, st.st_mode) == -1
|
||||
|| !(out = fdopen(i, "w+"))
|
||||
) {
|
||||
bb_simple_perror_msg_and_die(temp_fn);
|
||||
}
|
||||
}
|
||||
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
if (i == '\r')
|
||||
continue;
|
||||
if (i == '\n') {
|
||||
if (i == '\n')
|
||||
if (conv_type == CT_UNIX2DOS)
|
||||
fputc('\r', out);
|
||||
fputc('\n', out);
|
||||
continue;
|
||||
}
|
||||
fputc(i, out);
|
||||
}
|
||||
|
||||
if (fn != NULL) {
|
||||
if (fclose(in) < 0 || fclose(out) < 0) {
|
||||
bb_perror_nomsg();
|
||||
remove(name_buf);
|
||||
return -2;
|
||||
}
|
||||
/* Assume they are both on the same filesystem (which
|
||||
* should be true since we put them into the same directory
|
||||
* so we _should_ be ok, but you never know... */
|
||||
if (rename(name_buf, fn) < 0) {
|
||||
bb_perror_msg("cannot rename '%s' as '%s'", name_buf, fn);
|
||||
return -1;
|
||||
unlink(temp_fn);
|
||||
bb_perror_nomsg_and_die();
|
||||
}
|
||||
xrename(temp_fn, resolved_fn);
|
||||
free(temp_fn);
|
||||
free(resolved_fn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char **argv);
|
||||
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dos2unix_main(int argc, char **argv)
|
||||
{
|
||||
int o, conv_type;
|
||||
|
||||
/* See if we are supposed to be doing dos2unix or unix2dos */
|
||||
conv_type = CT_UNIX2DOS;
|
||||
if (applet_name[0] == 'd') {
|
||||
conv_type = CT_DOS2UNIX; /* 2 */
|
||||
} else {
|
||||
conv_type = CT_UNIX2DOS; /* 1 */
|
||||
conv_type = CT_DOS2UNIX;
|
||||
}
|
||||
|
||||
/* -u convert to unix, -d convert to dos */
|
||||
@@ -101,11 +90,9 @@ int dos2unix_main(int argc, char **argv)
|
||||
|
||||
do {
|
||||
/* might be convert(NULL) if there is no filename given */
|
||||
o = convert(argv[optind], conv_type);
|
||||
if (o < 0)
|
||||
break;
|
||||
convert(argv[optind], conv_type);
|
||||
optind++;
|
||||
} while (optind < argc);
|
||||
|
||||
return o;
|
||||
return 0;
|
||||
}
|
||||
+71
-76
@@ -25,37 +25,34 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
struct globals {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned long disp_hr = 1024;
|
||||
# else
|
||||
static unsigned long disp_hr = 512;
|
||||
# endif
|
||||
#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned disp_k = 1;
|
||||
unsigned long disp_hr;
|
||||
#else
|
||||
static unsigned disp_k; /* bss inits to 0 */
|
||||
unsigned disp_k;
|
||||
#endif
|
||||
|
||||
static int max_print_depth = INT_MAX;
|
||||
static nlink_t count_hardlinks = 1;
|
||||
int max_print_depth;
|
||||
nlink_t count_hardlinks;
|
||||
|
||||
static int status;
|
||||
static int print_files;
|
||||
static int slink_depth;
|
||||
static int du_depth;
|
||||
static int one_file_system;
|
||||
static dev_t dir_dev;
|
||||
bool status;
|
||||
bool one_file_system;
|
||||
int print_files;
|
||||
int slink_depth;
|
||||
int du_depth;
|
||||
dev_t dir_dev;
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
|
||||
|
||||
static void print(long size, const char *const filename)
|
||||
static void print(unsigned long size, const char *filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr),
|
||||
filename);
|
||||
#else
|
||||
if (disp_k) {
|
||||
if (G.disp_k) {
|
||||
size++;
|
||||
size >>= 1;
|
||||
}
|
||||
@@ -64,21 +61,21 @@ static void print(long size, const char *const filename)
|
||||
}
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(const char *const filename)
|
||||
static unsigned long du(const char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
unsigned long sum;
|
||||
|
||||
if (lstat(filename, &statbuf) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
bb_simple_perror_msg(filename);
|
||||
G.status = EXIT_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (one_file_system) {
|
||||
if (du_depth == 0) {
|
||||
dir_dev = statbuf.st_dev;
|
||||
} else if (dir_dev != statbuf.st_dev) {
|
||||
if (G.one_file_system) {
|
||||
if (G.du_depth == 0) {
|
||||
G.dir_dev = statbuf.st_dev;
|
||||
} else if (G.dir_dev != statbuf.st_dev) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -86,20 +83,20 @@ static long du(const char *const filename)
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (slink_depth > du_depth) { /* -H or -L */
|
||||
if (G.slink_depth > G.du_depth) { /* -H or -L */
|
||||
if (stat(filename, &statbuf) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
bb_simple_perror_msg(filename);
|
||||
G.status = EXIT_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
sum = statbuf.st_blocks;
|
||||
if (slink_depth == 1) {
|
||||
slink_depth = INT_MAX; /* Convert -H to -L. */
|
||||
if (G.slink_depth == 1) {
|
||||
G.slink_depth = INT_MAX; /* Convert -H to -L. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (statbuf.st_nlink > count_hardlinks) {
|
||||
if (statbuf.st_nlink > G.count_hardlinks) {
|
||||
/* Add files/directories with links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf)) {
|
||||
return 0;
|
||||
@@ -114,7 +111,7 @@ static long du(const char *const filename)
|
||||
|
||||
dir = warn_opendir(filename);
|
||||
if (!dir) {
|
||||
status = EXIT_FAILURE;
|
||||
G.status = EXIT_FAILURE;
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -128,39 +125,40 @@ static long du(const char *const filename)
|
||||
newfile = concat_subpath_file(filename, name);
|
||||
if (newfile == NULL)
|
||||
continue;
|
||||
++du_depth;
|
||||
++G.du_depth;
|
||||
sum += du(newfile);
|
||||
--du_depth;
|
||||
--G.du_depth;
|
||||
free(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
} else if (du_depth > print_files) {
|
||||
} else if (G.du_depth > G.print_files) {
|
||||
return sum;
|
||||
}
|
||||
if (du_depth <= max_print_depth) {
|
||||
if (G.du_depth <= G.max_print_depth) {
|
||||
print(sum, filename);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int du_main(int argc, char **argv);
|
||||
int du_main(int argc, char **argv)
|
||||
int du_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
long total;
|
||||
unsigned long total;
|
||||
int slink_depth_save;
|
||||
int print_final_total;
|
||||
char *smax_print_depth;
|
||||
bool print_final_total;
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
disp_hr = 512;
|
||||
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
|
||||
SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
G.disp_hr = 512;
|
||||
#else
|
||||
disp_k = 0;
|
||||
#endif
|
||||
}
|
||||
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
|
||||
/* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
|
||||
#endif
|
||||
G.max_print_depth = INT_MAX;
|
||||
G.count_hardlinks = 1;
|
||||
|
||||
/* Note: SUSv3 specifies that -a and -s options cannot be used together
|
||||
* in strictly conforming applications. However, it also says that some
|
||||
@@ -169,77 +167,74 @@ int du_main(int argc, char **argv)
|
||||
* ignore -a. This is consistent with -s being equivalent to -d 0.
|
||||
*/
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
|
||||
argv += optind;
|
||||
if (opt & (1 << 9)) {
|
||||
/* -h opt */
|
||||
disp_hr = 0;
|
||||
G.disp_hr = 0;
|
||||
}
|
||||
if (opt & (1 << 10)) {
|
||||
/* -m opt */
|
||||
disp_hr = 1024*1024;
|
||||
G.disp_hr = 1024*1024;
|
||||
}
|
||||
if (opt & (1 << 2)) {
|
||||
/* -k opt */
|
||||
disp_hr = 1024;
|
||||
G.disp_hr = 1024;
|
||||
}
|
||||
#else
|
||||
opt_complementary = "H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
|
||||
opt_complementary = "H-L:L-H:s-d:d-s:d+";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
|
||||
argv += optind;
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & (1 << 2)) {
|
||||
/* -k opt */
|
||||
disp_k = 1;
|
||||
G.disp_k = 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (opt & (1 << 0)) {
|
||||
/* -a opt */
|
||||
print_files = INT_MAX;
|
||||
G.print_files = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 1)) {
|
||||
/* -H opt */
|
||||
slink_depth = 1;
|
||||
G.slink_depth = 1;
|
||||
}
|
||||
if (opt & (1 << 3)) {
|
||||
/* -L opt */
|
||||
slink_depth = INT_MAX;
|
||||
G.slink_depth = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 4)) {
|
||||
/* -s opt */
|
||||
max_print_depth = 0;
|
||||
}
|
||||
one_file_system = opt & (1 << 5); /* -x opt */
|
||||
if (opt & (1 << 6)) {
|
||||
/* -d opt */
|
||||
max_print_depth = xatoi_u(smax_print_depth);
|
||||
G.max_print_depth = 0;
|
||||
}
|
||||
G.one_file_system = opt & (1 << 5); /* -x opt */
|
||||
if (opt & (1 << 7)) {
|
||||
/* -l opt */
|
||||
count_hardlinks = MAXINT(nlink_t);
|
||||
G.count_hardlinks = MAXINT(nlink_t);
|
||||
}
|
||||
print_final_total = opt & (1 << 8); /* -c opt */
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
argv += optind;
|
||||
if (optind >= argc) {
|
||||
if (!*argv) {
|
||||
*--argv = (char*)".";
|
||||
if (slink_depth == 1) {
|
||||
slink_depth = 0;
|
||||
if (G.slink_depth == 1) {
|
||||
G.slink_depth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
slink_depth_save = slink_depth;
|
||||
slink_depth_save = G.slink_depth;
|
||||
total = 0;
|
||||
do {
|
||||
total += du(*argv);
|
||||
slink_depth = slink_depth_save;
|
||||
G.slink_depth = slink_depth_save;
|
||||
} while (*++argv);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
reset_ino_dev_hashtable();
|
||||
if (print_final_total) {
|
||||
if (print_final_total)
|
||||
print(total, "total");
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(status);
|
||||
fflush_stdout_and_exit(G.status);
|
||||
}
|
||||
+151
-16
@@ -25,7 +25,11 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int bb_echo(char **argv)
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
/* NB: can be used by shell even if not enabled as applet */
|
||||
|
||||
int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
const char *arg;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
@@ -33,6 +37,18 @@ int bb_echo(char **argv)
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
|
||||
/* We must check that stdout is not closed.
|
||||
* The reason for this is highly non-obvious.
|
||||
* echo_main is used from shell. Shell must correctly handle "echo foo"
|
||||
* if stdout is closed. With stdio, output gets shoveled into
|
||||
* stdout buffer, and even fflush cannot clear it out. It seems that
|
||||
* even if libc receives EBADF on write attempts, it feels determined
|
||||
* to output data no matter what. So it will try later,
|
||||
* and possibly will clobber future output. Not good. */
|
||||
if (dup2(1, 1) != 1)
|
||||
return -1;
|
||||
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
@@ -41,6 +57,10 @@ int bb_echo(char **argv)
|
||||
char nflag = 1;
|
||||
char eflag = 0;
|
||||
|
||||
/* We must check that stdout is not closed. */
|
||||
if (dup2(1, 1) != 1)
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
@@ -88,43 +108,39 @@ int bb_echo(char **argv)
|
||||
}
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
/* SUSv3 specifies that octal escapes must begin with '0'. */
|
||||
if ( (((unsigned char)*arg) - '1') >= 7)
|
||||
if ( ((int)(unsigned char)(*arg) - '0') >= 8) /* '8' or bigger */
|
||||
#endif
|
||||
{
|
||||
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
||||
* of the form \0### are accepted. */
|
||||
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
if (*arg == '0') {
|
||||
/* NB: don't turn "...\0" into "...\" */
|
||||
if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
}
|
||||
}
|
||||
/* bb_process_escape_sequence can handle nul correctly */
|
||||
/* bb_process_escape_sequence handles NUL correctly
|
||||
* ("...\" case). */
|
||||
c = bb_process_escape_sequence(&arg);
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
bb_putchar(c);
|
||||
}
|
||||
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
break;
|
||||
putchar(' ');
|
||||
bb_putchar(' ');
|
||||
}
|
||||
|
||||
newline_ret:
|
||||
if (nflag) {
|
||||
putchar('\n');
|
||||
bb_putchar('\n');
|
||||
}
|
||||
ret:
|
||||
return fflush(stdout);
|
||||
}
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int echo_main(int argc, char** argv);
|
||||
int echo_main(int argc, char** argv)
|
||||
{
|
||||
return bb_echo(argv);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@@ -163,3 +179,122 @@ int echo_main(int argc, char** argv)
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#ifdef VERSION_WITH_WRITEV
|
||||
/* We can't use stdio.
|
||||
* The reason for this is highly non-obvious.
|
||||
* echo_main is used from shell. Shell must correctly handle "echo foo"
|
||||
* if stdout is closed. With stdio, output gets shoveled into
|
||||
* stdout buffer, and even fflush cannot clear it out. It seems that
|
||||
* even if libc receives EBADF on write attempts, it feels determined
|
||||
* to output data no matter what. So it will try later,
|
||||
* and possibly will clobber future output. Not good.
|
||||
*
|
||||
* Using writev instead, with 'direct' conversion of argv vector.
|
||||
*/
|
||||
|
||||
int echo_main(int argc, char **argv)
|
||||
{
|
||||
struct iovec io[argc];
|
||||
struct iovec *cur_io = io;
|
||||
char *arg;
|
||||
char *p;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
#else
|
||||
char nflag = 1;
|
||||
char eflag = 0;
|
||||
|
||||
while (1) {
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
if (*arg != '-')
|
||||
break;
|
||||
|
||||
/* If it appears that we are handling options, then make sure
|
||||
* that all of the options specified are actually valid.
|
||||
* Otherwise, the string should just be echoed.
|
||||
*/
|
||||
p = arg + 1;
|
||||
if (!*p) /* A single '-', so echo it. */
|
||||
goto just_echo;
|
||||
|
||||
do {
|
||||
if (!strrchr("neE", *p))
|
||||
goto just_echo;
|
||||
} while (*++p);
|
||||
|
||||
/* All of the options in this arg are valid, so handle them. */
|
||||
p = arg + 1;
|
||||
do {
|
||||
if (*p == 'n')
|
||||
nflag = 0;
|
||||
if (*p == 'e')
|
||||
eflag = '\\';
|
||||
} while (*++p);
|
||||
}
|
||||
just_echo:
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
/* arg is already == *argv and isn't NULL */
|
||||
int c;
|
||||
|
||||
cur_io->iov_base = p = arg;
|
||||
|
||||
if (!eflag) {
|
||||
/* optimization for very common case */
|
||||
p += strlen(arg);
|
||||
} else while ((c = *arg++)) {
|
||||
if (c == eflag) { /* Check for escape seq. */
|
||||
if (*arg == 'c') {
|
||||
/* '\c' means cancel newline and
|
||||
* ignore all subsequent chars. */
|
||||
cur_io->iov_len = p - (char*)cur_io->iov_base;
|
||||
cur_io++;
|
||||
goto ret;
|
||||
}
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
/* SUSv3 specifies that octal escapes must begin with '0'. */
|
||||
if ( (((unsigned char)*arg) - '1') >= 7)
|
||||
#endif
|
||||
{
|
||||
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
||||
* of the form \0### are accepted. */
|
||||
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
}
|
||||
/* bb_process_escape_sequence can handle nul correctly */
|
||||
c = bb_process_escape_sequence( (void*) &arg);
|
||||
}
|
||||
}
|
||||
*p++ = c;
|
||||
}
|
||||
|
||||
arg = *++argv;
|
||||
if (arg)
|
||||
*p++ = ' ';
|
||||
cur_io->iov_len = p - (char*)cur_io->iov_base;
|
||||
cur_io++;
|
||||
if (!arg)
|
||||
break;
|
||||
}
|
||||
|
||||
newline_ret:
|
||||
if (nflag) {
|
||||
cur_io->iov_base = (char*)"\n";
|
||||
cur_io->iov_len = 1;
|
||||
cur_io++;
|
||||
}
|
||||
ret:
|
||||
/* TODO: implement and use full_writev? */
|
||||
return writev(1, io, (cur_io - io)) >= 0;
|
||||
}
|
||||
#endif
|
||||
+5
-9
@@ -29,9 +29,6 @@
|
||||
* - use xfunc_error_retval
|
||||
*/
|
||||
|
||||
#include <getopt.h> /* struct option */
|
||||
extern char **environ;
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
@@ -41,8 +38,8 @@ static const char env_longopts[] ALIGN1 =
|
||||
;
|
||||
#endif
|
||||
|
||||
int env_main(int argc, char** argv);
|
||||
int env_main(int argc, char** argv)
|
||||
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int env_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
/* cleanenv was static - why? */
|
||||
char *cleanenv[1];
|
||||
@@ -65,8 +62,7 @@ int env_main(int argc, char** argv)
|
||||
environ = cleanenv;
|
||||
} else {
|
||||
while (unset_env) {
|
||||
unsetenv(unset_env->data);
|
||||
unset_env = unset_env->link;
|
||||
unsetenv(llist_pop(&unset_env));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,14 +77,14 @@ int env_main(int argc, char** argv)
|
||||
BB_EXECVP(*argv, argv);
|
||||
/* SUSv3-mandated exit codes. */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
|
||||
bb_perror_msg_and_die("%s", *argv);
|
||||
bb_simple_perror_msg_and_die(*argv);
|
||||
}
|
||||
|
||||
for (ep = environ; *ep; ep++) {
|
||||
puts(*ep);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(0);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+12
-21
@@ -41,7 +41,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
char *line;
|
||||
char *ptr;
|
||||
int convert;
|
||||
int pos;
|
||||
unsigned pos;
|
||||
|
||||
/* Increment tab_size by 1 locally.*/
|
||||
tab_size++;
|
||||
@@ -80,7 +80,7 @@ static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
|
||||
int convert;
|
||||
int pos;
|
||||
int i = 0;
|
||||
int column = 0;
|
||||
unsigned column = 0;
|
||||
|
||||
while ((line = xmalloc_fgets(file)) != NULL) {
|
||||
convert = 1;
|
||||
@@ -125,8 +125,8 @@ static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
|
||||
}
|
||||
#endif
|
||||
|
||||
int expand_main(int argc, char **argv);
|
||||
int expand_main(int argc, char **argv)
|
||||
int expand_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int expand_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
/* Default 8 spaces for 1 tab */
|
||||
const char *opt_t = "8";
|
||||
@@ -154,7 +154,7 @@ int expand_main(int argc, char **argv)
|
||||
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
|
||||
USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
|
||||
opt = getopt32(argv, "it:", &opt_t);
|
||||
} else if (ENABLE_UNEXPAND) {
|
||||
} else {
|
||||
USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
|
||||
/* -t NUM sets also -a */
|
||||
opt_complementary = "ta";
|
||||
@@ -166,33 +166,24 @@ int expand_main(int argc, char **argv)
|
||||
|
||||
argv += optind;
|
||||
|
||||
/* If no args are given, read from stdin */
|
||||
if (!*argv) {
|
||||
*--argv = (char*)bb_msg_standard_input;
|
||||
goto use_stdin;
|
||||
}
|
||||
|
||||
do {
|
||||
if (NOT_LONE_CHAR(*argv, '-')) {
|
||||
file = fopen_or_warn(*argv, "r");
|
||||
if (!file) {
|
||||
exit_status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
use_stdin:
|
||||
file = stdin;
|
||||
file = fopen_or_warn_stdin(*argv);
|
||||
if (!file) {
|
||||
exit_status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e'))
|
||||
USE_EXPAND(expand(file, tab_size, opt));
|
||||
else if (ENABLE_UNEXPAND)
|
||||
else
|
||||
USE_UNEXPAND(unexpand(file, tab_size, opt));
|
||||
|
||||
/* Check and close the file */
|
||||
/* We do want all of them to execute, thus | instead of || */
|
||||
if (ferror(file) | fclose_if_not_stdin(file)) {
|
||||
bb_perror_msg("%s", *argv);
|
||||
if (fclose_if_not_stdin(file)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
exit_status = EXIT_FAILURE;
|
||||
}
|
||||
/* If stdin also clear EOF */
|
||||
|
||||
+85
-88
@@ -28,13 +28,6 @@
|
||||
#include "libbb.h"
|
||||
#include "xregex.h"
|
||||
|
||||
/* The kinds of value we can have. */
|
||||
enum valtype {
|
||||
integer,
|
||||
string
|
||||
};
|
||||
typedef enum valtype TYPE;
|
||||
|
||||
#if ENABLE_EXPR_MATH_SUPPORT_64
|
||||
typedef int64_t arith_t;
|
||||
|
||||
@@ -51,10 +44,16 @@ typedef long arith_t;
|
||||
|
||||
/* TODO: use bb_strtol[l]? It's easier to check for errors... */
|
||||
|
||||
/* The kinds of value we can have. */
|
||||
enum {
|
||||
INTEGER,
|
||||
STRING
|
||||
};
|
||||
|
||||
/* A value is.... */
|
||||
struct valinfo {
|
||||
TYPE type; /* Which kind. */
|
||||
union { /* The value itself. */
|
||||
smallint type; /* Which kind. */
|
||||
union { /* The value itself. */
|
||||
arith_t i;
|
||||
char *s;
|
||||
} u;
|
||||
@@ -77,8 +76,9 @@ static VALUE *int_value(arith_t i)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
v = xmalloc(sizeof(VALUE));
|
||||
v->type = integer;
|
||||
v = xzalloc(sizeof(VALUE));
|
||||
if (INTEGER) /* otherwise xzaaloc did it already */
|
||||
v->type = INTEGER;
|
||||
v->u.i = i;
|
||||
return v;
|
||||
}
|
||||
@@ -89,46 +89,47 @@ static VALUE *str_value(const char *s)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
v = xmalloc(sizeof(VALUE));
|
||||
v->type = string;
|
||||
v = xzalloc(sizeof(VALUE));
|
||||
if (STRING) /* otherwise xzaaloc did it already */
|
||||
v->type = STRING;
|
||||
v->u.s = xstrdup(s);
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Free VALUE V, including structure components. */
|
||||
|
||||
static void freev(VALUE * v)
|
||||
static void freev(VALUE *v)
|
||||
{
|
||||
if (v->type == string)
|
||||
if (v->type == STRING)
|
||||
free(v->u.s);
|
||||
free(v);
|
||||
}
|
||||
|
||||
/* Return nonzero if V is a null-string or zero-number. */
|
||||
|
||||
static int null(VALUE * v)
|
||||
static int null(VALUE *v)
|
||||
{
|
||||
if (v->type == integer)
|
||||
if (v->type == INTEGER)
|
||||
return v->u.i == 0;
|
||||
/* string: */
|
||||
/* STRING: */
|
||||
return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
|
||||
}
|
||||
|
||||
/* Coerce V to a string value (can't fail). */
|
||||
/* Coerce V to a STRING value (can't fail). */
|
||||
|
||||
static void tostring(VALUE * v)
|
||||
static void tostring(VALUE *v)
|
||||
{
|
||||
if (v->type == integer) {
|
||||
if (v->type == INTEGER) {
|
||||
v->u.s = xasprintf("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
|
||||
v->type = string;
|
||||
v->type = STRING;
|
||||
}
|
||||
}
|
||||
|
||||
/* Coerce V to an integer value. Return 1 on success, 0 on failure. */
|
||||
/* Coerce V to an INTEGER value. Return 1 on success, 0 on failure. */
|
||||
|
||||
static bool toarith(VALUE * v)
|
||||
static bool toarith(VALUE *v)
|
||||
{
|
||||
if (v->type == string) {
|
||||
if (v->type == STRING) {
|
||||
arith_t i;
|
||||
char *e;
|
||||
|
||||
@@ -139,50 +140,54 @@ static bool toarith(VALUE * v)
|
||||
return 0;
|
||||
free(v->u.s);
|
||||
v->u.i = i;
|
||||
v->type = integer;
|
||||
v->type = INTEGER;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return nonzero if the next token matches STR exactly.
|
||||
/* Return str[0]+str[1] if the next token matches STR exactly.
|
||||
STR must not be NULL. */
|
||||
|
||||
static bool nextarg(const char *str)
|
||||
static int nextarg(const char *str)
|
||||
{
|
||||
if (*G.args == NULL)
|
||||
if (*G.args == NULL || strcmp(*G.args, str) != 0)
|
||||
return 0;
|
||||
return strcmp(*G.args, str) == 0;
|
||||
return (unsigned char)str[0] + (unsigned char)str[1];
|
||||
}
|
||||
|
||||
/* The comparison operator handling functions. */
|
||||
|
||||
static int cmp_common(VALUE * l, VALUE * r, int op)
|
||||
static int cmp_common(VALUE *l, VALUE *r, int op)
|
||||
{
|
||||
int cmpval;
|
||||
arith_t ll, rr;
|
||||
|
||||
if (l->type == string || r->type == string) {
|
||||
ll = l->u.i;
|
||||
rr = r->u.i;
|
||||
if (l->type == STRING || r->type == STRING) {
|
||||
tostring(l);
|
||||
tostring(r);
|
||||
cmpval = strcmp(l->u.s, r->u.s);
|
||||
} else
|
||||
cmpval = l->u.i - r->u.i;
|
||||
ll = strcmp(l->u.s, r->u.s);
|
||||
rr = 0;
|
||||
}
|
||||
/* calculating ll - rr and checking the result is prone to overflows.
|
||||
* We'll do it differently: */
|
||||
if (op == '<')
|
||||
return cmpval < 0;
|
||||
if (op == ('L' + 'E'))
|
||||
return cmpval <= 0;
|
||||
if (op == '=')
|
||||
return cmpval == 0;
|
||||
if (op == '!')
|
||||
return cmpval != 0;
|
||||
return ll < rr;
|
||||
if (op == ('<' + '='))
|
||||
return ll <= rr;
|
||||
if (op == '=' || (op == '=' + '='))
|
||||
return ll == rr;
|
||||
if (op == '!' + '=')
|
||||
return ll != rr;
|
||||
if (op == '>')
|
||||
return cmpval > 0;
|
||||
return ll > rr;
|
||||
/* >= */
|
||||
return cmpval >= 0;
|
||||
return ll >= rr;
|
||||
}
|
||||
|
||||
/* The arithmetic operator handling functions. */
|
||||
|
||||
static arith_t arithmetic_common(VALUE * l, VALUE * r, int op)
|
||||
static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
|
||||
{
|
||||
arith_t li, ri;
|
||||
|
||||
@@ -190,25 +195,24 @@ static arith_t arithmetic_common(VALUE * l, VALUE * r, int op)
|
||||
bb_error_msg_and_die("non-numeric argument");
|
||||
li = l->u.i;
|
||||
ri = r->u.i;
|
||||
if ((op == '/' || op == '%') && ri == 0)
|
||||
bb_error_msg_and_die("division by zero");
|
||||
if (op == '+')
|
||||
return li + ri;
|
||||
else if (op == '-')
|
||||
if (op == '-')
|
||||
return li - ri;
|
||||
else if (op == '*')
|
||||
if (op == '*')
|
||||
return li * ri;
|
||||
else if (op == '/')
|
||||
if (ri == 0)
|
||||
bb_error_msg_and_die("division by zero");
|
||||
if (op == '/')
|
||||
return li / ri;
|
||||
else
|
||||
return li % ri;
|
||||
return li % ri;
|
||||
}
|
||||
|
||||
/* Do the : operator.
|
||||
SV is the VALUE for the lhs (the string),
|
||||
PV is the VALUE for the rhs (the pattern). */
|
||||
|
||||
static VALUE *docolon(VALUE * sv, VALUE * pv)
|
||||
static VALUE *docolon(VALUE *sv, VALUE *pv)
|
||||
{
|
||||
VALUE *v;
|
||||
regex_t re_buffer;
|
||||
@@ -230,14 +234,16 @@ of a basic regular expression is not portable; it is being ignored", pv->u.s);
|
||||
|
||||
/* expr uses an anchored pattern match, so check that there was a
|
||||
* match and that the match starts at offset 0. */
|
||||
if (regexec(&re_buffer, sv->u.s, NMATCH, re_regs, 0) != REG_NOMATCH &&
|
||||
re_regs[0].rm_so == 0) {
|
||||
if (regexec(&re_buffer, sv->u.s, NMATCH, re_regs, 0) != REG_NOMATCH
|
||||
&& re_regs[0].rm_so == 0
|
||||
) {
|
||||
/* Were \(...\) used? */
|
||||
if (re_buffer.re_nsub > 0) {
|
||||
sv->u.s[re_regs[1].rm_eo] = '\0';
|
||||
v = str_value(sv->u.s + re_regs[1].rm_so);
|
||||
} else
|
||||
} else {
|
||||
v = int_value(re_regs[0].rm_eo);
|
||||
}
|
||||
} else {
|
||||
/* Match failed -- return the right kind of null. */
|
||||
if (re_buffer.re_nsub > 0)
|
||||
@@ -327,7 +333,7 @@ static VALUE *eval6(void)
|
||||
v = str_value("");
|
||||
else {
|
||||
v = xmalloc(sizeof(VALUE));
|
||||
v->type = string;
|
||||
v->type = STRING;
|
||||
v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
|
||||
}
|
||||
freev(l);
|
||||
@@ -367,14 +373,11 @@ static VALUE *eval4(void)
|
||||
|
||||
l = eval5();
|
||||
while (1) {
|
||||
if (nextarg("*"))
|
||||
op = '*';
|
||||
else if (nextarg("/"))
|
||||
op = '/';
|
||||
else if (nextarg("%"))
|
||||
op = '%';
|
||||
else
|
||||
return l;
|
||||
op = nextarg("*");
|
||||
if (!op) { op = nextarg("/");
|
||||
if (!op) { op = nextarg("%");
|
||||
if (!op) return l;
|
||||
}}
|
||||
G.args++;
|
||||
r = eval5();
|
||||
val = arithmetic_common(l, r, op);
|
||||
@@ -394,12 +397,11 @@ static VALUE *eval3(void)
|
||||
|
||||
l = eval4();
|
||||
while (1) {
|
||||
if (nextarg("+"))
|
||||
op = '+';
|
||||
else if (nextarg("-"))
|
||||
op = '-';
|
||||
else
|
||||
return l;
|
||||
op = nextarg("+");
|
||||
if (!op) {
|
||||
op = nextarg("-");
|
||||
if (!op) return l;
|
||||
}
|
||||
G.args++;
|
||||
r = eval4();
|
||||
val = arithmetic_common(l, r, op);
|
||||
@@ -419,20 +421,15 @@ static VALUE *eval2(void)
|
||||
|
||||
l = eval3();
|
||||
while (1) {
|
||||
if (nextarg("<"))
|
||||
op = '<';
|
||||
else if (nextarg("<="))
|
||||
op = 'L' + 'E';
|
||||
else if (nextarg("=") || nextarg("=="))
|
||||
op = '=';
|
||||
else if (nextarg("!="))
|
||||
op = '!';
|
||||
else if (nextarg(">="))
|
||||
op = 'G' + 'E';
|
||||
else if (nextarg(">"))
|
||||
op = '>';
|
||||
else
|
||||
return l;
|
||||
op = nextarg("<");
|
||||
if (!op) { op = nextarg("<=");
|
||||
if (!op) { op = nextarg("=");
|
||||
if (!op) { op = nextarg("==");
|
||||
if (!op) { op = nextarg("!=");
|
||||
if (!op) { op = nextarg(">=");
|
||||
if (!op) { op = nextarg(">");
|
||||
if (!op) return l;
|
||||
}}}}}}
|
||||
G.args++;
|
||||
r = eval3();
|
||||
toarith(l);
|
||||
@@ -483,7 +480,7 @@ static VALUE *eval(void)
|
||||
return l;
|
||||
}
|
||||
|
||||
int expr_main(int argc, char **argv);
|
||||
int expr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int expr_main(int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
@@ -498,7 +495,7 @@ int expr_main(int argc, char **argv)
|
||||
if (*G.args)
|
||||
bb_error_msg_and_die("syntax error");
|
||||
|
||||
if (v->type == integer)
|
||||
if (v->type == INTEGER)
|
||||
printf("%" PF_REZ "d\n", PF_REZ_TYPE v->u.i);
|
||||
else
|
||||
puts(v->u.s);
|
||||
|
||||
+2
-2
@@ -8,13 +8,13 @@
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/false.html */
|
||||
/* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv);
|
||||
int false_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+17
-20
@@ -5,25 +5,24 @@
|
||||
Copyright (C) 91, 1995-2002 Free Software Foundation, Inc.
|
||||
|
||||
Modified for busybox based on coreutils v 5.0
|
||||
Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au>
|
||||
Copyright (C) 2003 Glenn McGrath
|
||||
|
||||
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static unsigned long flags;
|
||||
#define FLAG_COUNT_BYTES 1
|
||||
#define FLAG_BREAK_SPACES 2
|
||||
#define FLAG_WIDTH 4
|
||||
/* Must match getopt32 call */
|
||||
#define FLAG_COUNT_BYTES 1
|
||||
#define FLAG_BREAK_SPACES 2
|
||||
#define FLAG_WIDTH 4
|
||||
|
||||
/* Assuming the current column is COLUMN, return the column that
|
||||
printing C will move the cursor to.
|
||||
The first column is 0. */
|
||||
|
||||
static int adjust_column(int column, char c)
|
||||
{
|
||||
if (!(flags & FLAG_COUNT_BYTES)) {
|
||||
if (!(option_mask32 & FLAG_COUNT_BYTES)) {
|
||||
if (c == '\b') {
|
||||
if (column > 0)
|
||||
column--;
|
||||
@@ -38,7 +37,7 @@ static int adjust_column(int column, char c)
|
||||
return column;
|
||||
}
|
||||
|
||||
int fold_main(int argc, char **argv);
|
||||
int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int fold_main(int argc, char **argv)
|
||||
{
|
||||
char *line_out = NULL;
|
||||
@@ -54,29 +53,27 @@ int fold_main(int argc, char **argv)
|
||||
char const *a = argv[i];
|
||||
|
||||
if (*a++ == '-') {
|
||||
if (*a == '-' && !a[1])
|
||||
if (*a == '-' && !a[1]) /* "--" */
|
||||
break;
|
||||
if (isdigit(*a)) {
|
||||
if (isdigit(*a))
|
||||
argv[i] = xasprintf("-w%s", a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flags = getopt32(argv, "bsw:", &w_opt);
|
||||
if (flags & FLAG_WIDTH)
|
||||
getopt32(argv, "bsw:", &w_opt);
|
||||
if (option_mask32 & FLAG_WIDTH)
|
||||
width = xatoul_range(w_opt, 1, 10000);
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
if (!*argv)
|
||||
*--argv = (char*)"-";
|
||||
}
|
||||
|
||||
do {
|
||||
FILE *istream = fopen_or_warn_stdin(*argv);
|
||||
int c;
|
||||
int column = 0; /* Screen column where next char will go. */
|
||||
int offset_out = 0; /* Index in `line_out' for next char. */
|
||||
int offset_out = 0; /* Index in 'line_out' for next char. */
|
||||
|
||||
if (istream == NULL) {
|
||||
errs |= EXIT_FAILURE;
|
||||
@@ -102,7 +99,7 @@ int fold_main(int argc, char **argv)
|
||||
/* This character would make the line too long.
|
||||
Print the line plus a newline, and make this character
|
||||
start the next line. */
|
||||
if (flags & FLAG_BREAK_SPACES) {
|
||||
if (option_mask32 & FLAG_BREAK_SPACES) {
|
||||
/* Look for the last blank. */
|
||||
int logical_end;
|
||||
|
||||
@@ -115,7 +112,7 @@ int fold_main(int argc, char **argv)
|
||||
/* Found a blank. Don't output the part after it. */
|
||||
logical_end++;
|
||||
fwrite(line_out, sizeof(char), (size_t) logical_end, stdout);
|
||||
putchar('\n');
|
||||
bb_putchar('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
The areas being copied here might overlap. */
|
||||
memmove(line_out, line_out + logical_end, offset_out - logical_end);
|
||||
@@ -144,8 +141,8 @@ int fold_main(int argc, char **argv)
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
}
|
||||
|
||||
if (ferror(istream) || fclose_if_not_stdin(istream)) {
|
||||
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
|
||||
if (fclose_if_not_stdin(istream)) {
|
||||
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
|
||||
errs |= EXIT_FAILURE;
|
||||
}
|
||||
} while (*++argv);
|
||||
|
||||
Loaded 100 of 760 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user