diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 23:01:48 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-20 23:01:48 +0000 |
commit | 05af832097848cbc0656e687fc4a07525c2de513 (patch) | |
tree | 3bcf8b387b684fe83d1b7598f96b8af0aa18d1ed | |
parent | 83518d18a34a3ddfcaac1739930d8469f5bc2442 (diff) | |
download | busybox-w32-05af832097848cbc0656e687fc4a07525c2de513.tar.gz busybox-w32-05af832097848cbc0656e687fc4a07525c2de513.tar.bz2 busybox-w32-05af832097848cbc0656e687fc4a07525c2de513.zip |
cpio: more compat: -0 and -L options
function old new delta
cpio_main 1417 1473 +56
-rw-r--r-- | archival/cpio.c | 174 |
1 files changed, 92 insertions, 82 deletions
diff --git a/archival/cpio.c b/archival/cpio.c index 929d544ff..11b22e478 100644 --- a/archival/cpio.c +++ b/archival/cpio.c | |||
@@ -14,6 +14,87 @@ | |||
14 | #include "libbb.h" | 14 | #include "libbb.h" |
15 | #include "unarchive.h" | 15 | #include "unarchive.h" |
16 | 16 | ||
17 | /* GNU cpio 2.9 --help (abridged): | ||
18 | |||
19 | Modes: | ||
20 | -t, --list List the archive | ||
21 | -i, --extract Extract files from an archive | ||
22 | -o, --create Create the archive | ||
23 | -p, --pass-through Copy-pass mode [was ist das?!] | ||
24 | |||
25 | Options valid in any mode: | ||
26 | --block-size=SIZE I/O block size = SIZE * 512 bytes | ||
27 | -B I/O block size = 5120 bytes | ||
28 | -c Use the old portable (ASCII) archive format | ||
29 | -C, --io-size=NUMBER I/O block size in bytes | ||
30 | -f, --nonmatching Only copy files that do not match given pattern | ||
31 | -F, --file=FILE Use FILE instead of standard input or output | ||
32 | -H, --format=FORMAT Use given archive FORMAT | ||
33 | -M, --message=STRING Print STRING when the end of a volume of the | ||
34 | backup media is reached | ||
35 | -n, --numeric-uid-gid If -v, show numeric UID and GID | ||
36 | --quiet Do not print the number of blocks copied | ||
37 | --rsh-command=COMMAND Use remote COMMAND instead of rsh | ||
38 | -v, --verbose Verbosely list the files processed | ||
39 | -V, --dot Print a "." for each file processed | ||
40 | -W, --warning=FLAG Control warning display: 'none','truncate','all'; | ||
41 | multiple options accumulate | ||
42 | |||
43 | Options valid only in --extract mode: | ||
44 | -b, --swap Swap both halfwords of words and bytes of | ||
45 | halfwords in the data (equivalent to -sS) | ||
46 | -r, --rename Interactively rename files | ||
47 | -s, --swap-bytes Swap the bytes of each halfword in the files | ||
48 | -S, --swap-halfwords Swap the halfwords of each word (4 bytes) | ||
49 | --to-stdout Extract files to standard output | ||
50 | -E, --pattern-file=FILE Read additional patterns specifying filenames to | ||
51 | extract or list from FILE | ||
52 | --only-verify-crc Verify CRC's, don't actually extract the files | ||
53 | |||
54 | Options valid only in --create mode: | ||
55 | -A, --append Append to an existing archive | ||
56 | -O FILE File to use instead of standard output | ||
57 | |||
58 | Options valid only in --pass-through mode: | ||
59 | -l, --link Link files instead of copying them, when possible | ||
60 | |||
61 | Options valid in --extract and --create modes: | ||
62 | --absolute-filenames Do not strip file system prefix components from | ||
63 | the file names | ||
64 | --no-absolute-filenames Create all files relative to the current dir | ||
65 | |||
66 | Options valid in --create and --pass-through modes: | ||
67 | -0, --null A list of filenames is terminated by a NUL | ||
68 | -a, --reset-access-time Reset the access times of files after reading them | ||
69 | -I FILE File to use instead of standard input | ||
70 | -L, --dereference Dereference symbolic links (copy the files | ||
71 | that they point to instead of copying the links) | ||
72 | -R, --owner=[USER][:.][GROUP] Set owner of created files | ||
73 | |||
74 | Options valid in --extract and --pass-through modes: | ||
75 | -d, --make-directories Create leading directories where needed | ||
76 | -m, --preserve-modification-time Retain mtime when creating files | ||
77 | --no-preserve-owner Do not change the ownership of the files | ||
78 | --sparse Write files with blocks of zeros as sparse files | ||
79 | -u, --unconditional Replace all files unconditionally | ||
80 | */ | ||
81 | enum { | ||
82 | CPIO_OPT_EXTRACT = (1 << 0), | ||
83 | CPIO_OPT_TEST = (1 << 1), | ||
84 | CPIO_OPT_NUL_TERMINATED = (1 << 2), | ||
85 | CPIO_OPT_UNCONDITIONAL = (1 << 3), | ||
86 | CPIO_OPT_VERBOSE = (1 << 4), | ||
87 | CPIO_OPT_CREATE_LEADING_DIR = (1 << 5), | ||
88 | CPIO_OPT_PRESERVE_MTIME = (1 << 6), | ||
89 | CPIO_OPT_DEREF = (1 << 7), | ||
90 | CPIO_OPT_FILE = (1 << 8), | ||
91 | CPIO_OPT_CREATE = (1 << 9) * ENABLE_FEATURE_CPIO_O, | ||
92 | CPIO_OPT_FORMAT = (1 << 10) * ENABLE_FEATURE_CPIO_O, | ||
93 | CPIO_OPT_PASSTHROUGH = (1 << 11) * ENABLE_FEATURE_CPIO_P, | ||
94 | }; | ||
95 | |||
96 | #define OPTION_STR "it0uvdmLF:" | ||
97 | |||
17 | #if ENABLE_FEATURE_CPIO_O | 98 | #if ENABLE_FEATURE_CPIO_O |
18 | static off_t cpio_pad4(off_t size) | 99 | static off_t cpio_pad4(off_t size) |
19 | { | 100 | { |
@@ -49,7 +130,9 @@ static int cpio_o(void) | |||
49 | char *line; | 130 | char *line; |
50 | struct stat st; | 131 | struct stat st; |
51 | 132 | ||
52 | line = xmalloc_fgetline(stdin); | 133 | line = (option_mask32 & CPIO_OPT_NUL_TERMINATED) |
134 | ? bb_get_chunk_from_file(stdin, NULL) | ||
135 | : xmalloc_fgetline(stdin); | ||
53 | 136 | ||
54 | if (line) { | 137 | if (line) { |
55 | /* Strip leading "./[./]..." from the filename */ | 138 | /* Strip leading "./[./]..." from the filename */ |
@@ -62,7 +145,10 @@ static int cpio_o(void) | |||
62 | free(line); | 145 | free(line); |
63 | continue; | 146 | continue; |
64 | } | 147 | } |
65 | if (lstat(name, &st)) { | 148 | if ((option_mask32 & CPIO_OPT_DEREF) |
149 | ? stat(name, &st) | ||
150 | : lstat(name, &st) | ||
151 | ) { | ||
66 | abort_cpio_o: | 152 | abort_cpio_o: |
67 | bb_simple_perror_msg_and_die(name); | 153 | bb_simple_perror_msg_and_die(name); |
68 | } | 154 | } |
@@ -179,71 +265,6 @@ static int cpio_o(void) | |||
179 | } | 265 | } |
180 | #endif | 266 | #endif |
181 | 267 | ||
182 | /* GNU cpio 2.9 --help (abridged): | ||
183 | |||
184 | Modes: | ||
185 | -i, --extract Extract files from an archive | ||
186 | -o, --create Create the archive | ||
187 | -p, --pass-through Copy-pass mode [was ist das?!] | ||
188 | -t, --list List the archive | ||
189 | |||
190 | Options valid in any mode: | ||
191 | --block-size=SIZE I/O block size = SIZE * 512 bytes | ||
192 | -B I/O block size = 5120 bytes | ||
193 | -c Use the old portable (ASCII) archive format | ||
194 | -C, --io-size=NUMBER I/O block size in bytes | ||
195 | -f, --nonmatching Only copy files that do not match given pattern | ||
196 | -F, --file=FILE Use FILE instead of standard input or output | ||
197 | -H, --format=FORMAT Use given archive FORMAT | ||
198 | -M, --message=STRING Print STRING when the end of a volume of the | ||
199 | backup media is reached | ||
200 | -n, --numeric-uid-gid If -v, show numeric UID and GID | ||
201 | --quiet Do not print the number of blocks copied | ||
202 | --rsh-command=COMMAND Use remote COMMAND instead of rsh | ||
203 | -v, --verbose Verbosely list the files processed | ||
204 | -V, --dot Print a "." for each file processed | ||
205 | -W, --warning=FLAG Control warning display: 'none','truncate','all'; | ||
206 | multiple options accumulate | ||
207 | |||
208 | Options valid only in --extract mode: | ||
209 | -b, --swap Swap both halfwords of words and bytes of | ||
210 | halfwords in the data (equivalent to -sS) | ||
211 | -r, --rename Interactively rename files | ||
212 | -s, --swap-bytes Swap the bytes of each halfword in the files | ||
213 | -S, --swap-halfwords Swap the halfwords of each word (4 bytes) | ||
214 | --to-stdout Extract files to standard output | ||
215 | -E, --pattern-file=FILE Read additional patterns specifying filenames to | ||
216 | extract or list from FILE | ||
217 | --only-verify-crc Verify CRC's, don't actually extract the files | ||
218 | |||
219 | Options valid only in --create mode: | ||
220 | -A, --append Append to an existing archive | ||
221 | -O FILE File to use instead of standard output | ||
222 | |||
223 | Options valid only in --pass-through mode: | ||
224 | -l, --link Link files instead of copying them, when possible | ||
225 | |||
226 | Options valid in --extract and --create modes: | ||
227 | --absolute-filenames Do not strip file system prefix components from | ||
228 | the file names | ||
229 | --no-absolute-filenames Create all files relative to the current dir | ||
230 | |||
231 | Options valid in --create and --pass-through modes: | ||
232 | -0, --null A list of filenames is terminated by a NUL | ||
233 | -a, --reset-access-time Reset the access times of files after reading them | ||
234 | -I FILE File to use instead of standard input | ||
235 | -L, --dereference Dereference symbolic links (copy the files | ||
236 | that they point to instead of copying the links) | ||
237 | -R, --owner=[USER][:.][GROUP] Set owner of created files | ||
238 | |||
239 | Options valid in --extract and --pass-through modes: | ||
240 | -d, --make-directories Create leading directories where needed | ||
241 | -m, --preserve-modification-time Retain mtime when creating files | ||
242 | --no-preserve-owner Do not change the ownership of the files | ||
243 | --sparse Write files with blocks of zeros as sparse files | ||
244 | -u, --unconditional Replace all files unconditionally | ||
245 | */ | ||
246 | |||
247 | int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 268 | int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
248 | int cpio_main(int argc UNUSED_PARAM, char **argv) | 269 | int cpio_main(int argc UNUSED_PARAM, char **argv) |
249 | { | 270 | { |
@@ -251,18 +272,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) | |||
251 | char *cpio_filename; | 272 | char *cpio_filename; |
252 | USE_FEATURE_CPIO_O(const char *cpio_fmt = "";) | 273 | USE_FEATURE_CPIO_O(const char *cpio_fmt = "";) |
253 | unsigned opt; | 274 | unsigned opt; |
254 | enum { | ||
255 | CPIO_OPT_EXTRACT = (1 << 0), | ||
256 | CPIO_OPT_TEST = (1 << 1), | ||
257 | CPIO_OPT_UNCONDITIONAL = (1 << 2), | ||
258 | CPIO_OPT_VERBOSE = (1 << 3), | ||
259 | CPIO_OPT_FILE = (1 << 4), | ||
260 | CPIO_OPT_CREATE_LEADING_DIR = (1 << 5), | ||
261 | CPIO_OPT_PRESERVE_MTIME = (1 << 6), | ||
262 | CPIO_OPT_CREATE = (1 << 7) * ENABLE_FEATURE_CPIO_O, | ||
263 | CPIO_OPT_FORMAT = (1 << 8) * ENABLE_FEATURE_CPIO_O, | ||
264 | CPIO_OPT_PASSTHROUGH = (1 << 9) * ENABLE_FEATURE_CPIO_P, | ||
265 | }; | ||
266 | 275 | ||
267 | #if ENABLE_GETOPT_LONG | 276 | #if ENABLE_GETOPT_LONG |
268 | applet_long_options = | 277 | applet_long_options = |
@@ -281,11 +290,12 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) | |||
281 | /* As of now we do not enforce this: */ | 290 | /* As of now we do not enforce this: */ |
282 | /* -i,-t,-o,-p are mutually exclusive */ | 291 | /* -i,-t,-o,-p are mutually exclusive */ |
283 | /* -u,-d,-m make sense only with -i or -p */ | 292 | /* -u,-d,-m make sense only with -i or -p */ |
284 | /* -F makes sense only with -o */ | 293 | /* -L makes sense only with -o or -p */ |
294 | |||
285 | #if !ENABLE_FEATURE_CPIO_O | 295 | #if !ENABLE_FEATURE_CPIO_O |
286 | opt = getopt32(argv, "ituvF:dm", &cpio_filename); | 296 | opt = getopt32(argv, OPTION_STR, &cpio_filename); |
287 | #else | 297 | #else |
288 | opt = getopt32(argv, "ituvF:dmoH:" USE_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); | 298 | opt = getopt32(argv, OPTION_STR "oH:" USE_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); |
289 | if (opt & CPIO_OPT_PASSTHROUGH) { | 299 | if (opt & CPIO_OPT_PASSTHROUGH) { |
290 | pid_t pid; | 300 | pid_t pid; |
291 | struct fd_pair pp; | 301 | struct fd_pair pp; |