blob: 41eb6f659f3d7a55ea88877219a62a37b919840a [file] [log] [blame]
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Mini cpio implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 2001 by Glenn McGrath
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +00008 *
9 * Limitations:
Denis Vlasenko261f2372008-04-05 00:07:46 +000010 * Doesn't check CRC's
11 * Only supports new ASCII and CRC formats
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000012 */
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000013#include "libbb.h"
Denys Vlasenkod184a722011-09-22 12:45:14 +020014#include "bb_archive.h"
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000015
Denys Vlasenko36184a42013-11-14 09:54:24 +010016//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
Denys Vlasenko66620fa2013-11-14 09:53:52 +010017//kbuild:lib-$(CONFIG_CPIO) += cpio.o
18
Denys Vlasenko1f937d62010-12-26 02:22:51 +010019//usage:#define cpio_trivial_usage
20//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
21//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
22//usage: " [EXTR_FILE]..."
23//usage:#define cpio_full_usage "\n\n"
24//usage: "Extract or list files from a cpio archive"
25//usage: IF_FEATURE_CPIO_O(", or"
26//usage: "\ncreate an archive" IF_FEATURE_CPIO_P(" (-o) or copy files (-p)")
27//usage: " using file list on stdin"
28//usage: )
29//usage: "\n"
30//usage: "\nMain operation mode:"
31//usage: "\n -t List"
32//usage: "\n -i Extract EXTR_FILEs (or all)"
33//usage: IF_FEATURE_CPIO_O(
34//usage: "\n -o Create (requires -H newc)"
35//usage: )
36//usage: IF_FEATURE_CPIO_P(
37//usage: "\n -p DIR Copy files to DIR"
38//usage: )
Denys Vlasenko1f937d62010-12-26 02:22:51 +010039//usage: "\n -d Make leading directories"
40//usage: "\n -m Preserve mtime"
41//usage: "\n -v Verbose"
42//usage: "\n -u Overwrite"
43//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
44//usage: IF_FEATURE_CPIO_O(
45//usage: "\n -H newc Archive format"
46//usage: )
47
Denis Vlasenko05af8322009-03-20 23:01:48 +000048/* GNU cpio 2.9 --help (abridged):
49
50 Modes:
51 -t, --list List the archive
52 -i, --extract Extract files from an archive
53 -o, --create Create the archive
Denys Vlasenko1f937d62010-12-26 02:22:51 +010054 -p, --pass-through Copy-pass mode
Denis Vlasenko05af8322009-03-20 23:01:48 +000055
56 Options valid in any mode:
57 --block-size=SIZE I/O block size = SIZE * 512 bytes
58 -B I/O block size = 5120 bytes
59 -c Use the old portable (ASCII) archive format
60 -C, --io-size=NUMBER I/O block size in bytes
61 -f, --nonmatching Only copy files that do not match given pattern
62 -F, --file=FILE Use FILE instead of standard input or output
63 -H, --format=FORMAT Use given archive FORMAT
64 -M, --message=STRING Print STRING when the end of a volume of the
65 backup media is reached
66 -n, --numeric-uid-gid If -v, show numeric UID and GID
67 --quiet Do not print the number of blocks copied
68 --rsh-command=COMMAND Use remote COMMAND instead of rsh
69 -v, --verbose Verbosely list the files processed
70 -V, --dot Print a "." for each file processed
71 -W, --warning=FLAG Control warning display: 'none','truncate','all';
72 multiple options accumulate
73
74 Options valid only in --extract mode:
75 -b, --swap Swap both halfwords of words and bytes of
76 halfwords in the data (equivalent to -sS)
77 -r, --rename Interactively rename files
78 -s, --swap-bytes Swap the bytes of each halfword in the files
79 -S, --swap-halfwords Swap the halfwords of each word (4 bytes)
80 --to-stdout Extract files to standard output
81 -E, --pattern-file=FILE Read additional patterns specifying filenames to
82 extract or list from FILE
83 --only-verify-crc Verify CRC's, don't actually extract the files
84
85 Options valid only in --create mode:
86 -A, --append Append to an existing archive
87 -O FILE File to use instead of standard output
88
89 Options valid only in --pass-through mode:
90 -l, --link Link files instead of copying them, when possible
91
92 Options valid in --extract and --create modes:
93 --absolute-filenames Do not strip file system prefix components from
94 the file names
95 --no-absolute-filenames Create all files relative to the current dir
96
97 Options valid in --create and --pass-through modes:
98 -0, --null A list of filenames is terminated by a NUL
99 -a, --reset-access-time Reset the access times of files after reading them
100 -I FILE File to use instead of standard input
101 -L, --dereference Dereference symbolic links (copy the files
102 that they point to instead of copying the links)
103 -R, --owner=[USER][:.][GROUP] Set owner of created files
104
105 Options valid in --extract and --pass-through modes:
106 -d, --make-directories Create leading directories where needed
107 -m, --preserve-modification-time Retain mtime when creating files
108 --no-preserve-owner Do not change the ownership of the files
109 --sparse Write files with blocks of zeros as sparse files
110 -u, --unconditional Replace all files unconditionally
111 */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100112
Denis Vlasenko05af8322009-03-20 23:01:48 +0000113enum {
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100114 OPT_EXTRACT = (1 << 0),
115 OPT_TEST = (1 << 1),
116 OPT_NUL_TERMINATED = (1 << 2),
117 OPT_UNCONDITIONAL = (1 << 3),
118 OPT_VERBOSE = (1 << 4),
119 OPT_CREATE_LEADING_DIR = (1 << 5),
120 OPT_PRESERVE_MTIME = (1 << 6),
121 OPT_DEREF = (1 << 7),
122 OPT_FILE = (1 << 8),
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200123 OPTBIT_FILE = 8,
124 IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
125 IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
126 IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
127 IF_LONG_OPTS( OPTBIT_QUIET ,)
128 IF_LONG_OPTS( OPTBIT_2STDOUT ,)
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100129 OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
130 OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
131 OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
132 OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
133 OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
Denis Vlasenko05af8322009-03-20 23:01:48 +0000134};
135
136#define OPTION_STR "it0uvdmLF:"
137
Denis Vlasenko261f2372008-04-05 00:07:46 +0000138#if ENABLE_FEATURE_CPIO_O
139static off_t cpio_pad4(off_t size)
140{
141 int i;
142
143 i = (- size) & 3;
144 size += i;
145 while (--i >= 0)
146 bb_putchar('\0');
147 return size;
148}
149
150/* Return value will become exit code.
151 * It's ok to exit instead of return. */
Denys Vlasenkoa7bb3c12009-10-08 12:28:08 +0200152static NOINLINE int cpio_o(void)
Denis Vlasenko261f2372008-04-05 00:07:46 +0000153{
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000154 static const char trailer[] ALIGN1 = "TRAILER!!!";
Denis Vlasenko261f2372008-04-05 00:07:46 +0000155 struct name_s {
156 struct name_s *next;
157 char name[1];
158 };
159 struct inodes_s {
160 struct inodes_s *next;
161 struct name_s *names;
162 struct stat st;
163 };
164
165 struct inodes_s *links = NULL;
166 off_t bytes = 0; /* output bytes count */
167
168 while (1) {
169 const char *name;
170 char *line;
171 struct stat st;
172
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100173 line = (option_mask32 & OPT_NUL_TERMINATED)
Denis Vlasenko05af8322009-03-20 23:01:48 +0000174 ? bb_get_chunk_from_file(stdin, NULL)
175 : xmalloc_fgetline(stdin);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000176
177 if (line) {
178 /* Strip leading "./[./]..." from the filename */
179 name = line;
180 while (name[0] == '.' && name[1] == '/') {
181 while (*++name == '/')
182 continue;
183 }
184 if (!*name) { /* line is empty */
185 free(line);
186 continue;
187 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100188 if ((option_mask32 & OPT_DEREF)
Denis Vlasenko05af8322009-03-20 23:01:48 +0000189 ? stat(name, &st)
190 : lstat(name, &st)
191 ) {
Denis Vlasenko261f2372008-04-05 00:07:46 +0000192 abort_cpio_o:
193 bb_simple_perror_msg_and_die(name);
194 }
195
196 if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
197 st.st_size = 0; /* paranoia */
198
199 /* Store hardlinks for later processing, dont output them */
200 if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
201 struct name_s *n;
202 struct inodes_s *l;
203
204 /* Do we have this hardlink remembered? */
205 l = links;
206 while (1) {
207 if (l == NULL) {
208 /* Not found: add new item to "links" list */
209 l = xzalloc(sizeof(*l));
210 l->st = st;
211 l->next = links;
212 links = l;
213 break;
214 }
215 if (l->st.st_ino == st.st_ino) {
216 /* found */
217 break;
218 }
219 l = l->next;
220 }
221 /* Add new name to "l->names" list */
222 n = xmalloc(sizeof(*n) + strlen(name));
223 strcpy(n->name, name);
224 n->next = l->names;
225 l->names = n;
226
227 free(line);
228 continue;
229 }
230
231 } else { /* line == NULL: EOF */
232 next_link:
233 if (links) {
234 /* Output hardlink's data */
235 st = links->st;
236 name = links->names->name;
237 links->names = links->names->next;
238 /* GNU cpio is reported to emit file data
239 * only for the last instance. Mimic that. */
240 if (links->names == NULL)
241 links = links->next;
242 else
243 st.st_size = 0;
244 /* NB: we leak links->names and/or links,
245 * this is intended (we exit soon anyway) */
246 } else {
247 /* If no (more) hardlinks to output,
248 * output "trailer" entry */
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000249 name = trailer;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000250 /* st.st_size == 0 is a must, but for uniformity
251 * in the output, we zero out everything */
252 memset(&st, 0, sizeof(st));
253 /* st.st_nlink = 1; - GNU cpio does this */
254 }
255 }
256
257 bytes += printf("070701"
Denys Vlasenko60cb48c2013-01-14 15:57:44 +0100258 "%08X%08X%08X%08X%08X%08X%08X"
259 "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
Denis Vlasenko261f2372008-04-05 00:07:46 +0000260 /* strlen+1: */ "%08X"
261 /* chksum: */ "00000000" /* (only for "070702" files) */
262 /* name,NUL: */ "%s%c",
Denys Vlasenko60cb48c2013-01-14 15:57:44 +0100263 (unsigned)(uint32_t) st.st_ino,
264 (unsigned)(uint32_t) st.st_mode,
265 (unsigned)(uint32_t) st.st_uid,
266 (unsigned)(uint32_t) st.st_gid,
267 (unsigned)(uint32_t) st.st_nlink,
268 (unsigned)(uint32_t) st.st_mtime,
269 (unsigned)(uint32_t) st.st_size,
270 (unsigned)(uint32_t) major(st.st_dev),
271 (unsigned)(uint32_t) minor(st.st_dev),
272 (unsigned)(uint32_t) major(st.st_rdev),
273 (unsigned)(uint32_t) minor(st.st_rdev),
274 (unsigned)(strlen(name) + 1),
275 name, '\0');
Denis Vlasenko261f2372008-04-05 00:07:46 +0000276 bytes = cpio_pad4(bytes);
277
278 if (st.st_size) {
279 if (S_ISLNK(st.st_mode)) {
280 char *lpath = xmalloc_readlink_or_warn(name);
281 if (!lpath)
282 goto abort_cpio_o;
283 bytes += printf("%s", lpath);
284 free(lpath);
285 } else { /* S_ISREG */
286 int fd = xopen(name, O_RDONLY);
Denys Vlasenko8131eea2009-11-02 14:19:51 +0100287 fflush_all();
Denis Vlasenko261f2372008-04-05 00:07:46 +0000288 /* We must abort if file got shorter too! */
Denis Vlasenko1af00ed2008-04-05 02:44:30 +0000289 bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000290 bytes += st.st_size;
291 close(fd);
292 }
293 bytes = cpio_pad4(bytes);
294 }
295
296 if (!line) {
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000297 if (name != trailer)
Denis Vlasenko261f2372008-04-05 00:07:46 +0000298 goto next_link;
299 /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
300 return EXIT_SUCCESS;
301 }
302
303 free(line);
304 } /* end of "while (1)" */
305}
306#endif
Glenn L McGrath10b78132004-02-25 09:30:06 +0000307
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000308int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000309int cpio_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000310{
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000311 archive_handle_t *archive_handle;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000312 char *cpio_filename;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000313 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000314 unsigned opt;
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000315
Denys Vlasenkof3b92d32009-06-19 12:10:38 +0200316#if ENABLE_LONG_OPTS
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000317 applet_long_options =
318 "extract\0" No_argument "i"
319 "list\0" No_argument "t"
320#if ENABLE_FEATURE_CPIO_O
321 "create\0" No_argument "o"
322 "format\0" Required_argument "H"
Denis Vlasenko83518d12009-03-20 22:17:13 +0000323#if ENABLE_FEATURE_CPIO_P
324 "pass-through\0" No_argument "p"
325#endif
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000326#endif
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200327 "verbose\0" No_argument "v"
328 "quiet\0" No_argument "\xff"
329 "to-stdout\0" No_argument "\xfe"
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000330 ;
331#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000332
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100333 archive_handle = init_handle();
334 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
335 archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
336
Denis Vlasenko83518d12009-03-20 22:17:13 +0000337 /* As of now we do not enforce this: */
338 /* -i,-t,-o,-p are mutually exclusive */
339 /* -u,-d,-m make sense only with -i or -p */
Denis Vlasenko05af8322009-03-20 23:01:48 +0000340 /* -L makes sense only with -o or -p */
341
Denis Vlasenko83518d12009-03-20 22:17:13 +0000342#if !ENABLE_FEATURE_CPIO_O
Denis Vlasenko05af8322009-03-20 23:01:48 +0000343 opt = getopt32(argv, OPTION_STR, &cpio_filename);
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200344 argv += optind;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100345 if (opt & OPT_FILE) { /* -F */
Denys Vlasenko02dd96f2010-01-09 20:25:42 +0100346 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100347 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000348#else
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000349 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100350 argv += optind;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100351 if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100352 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
353 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100354 if (opt & OPT_PASSTHROUGH) {
Denis Vlasenko83518d12009-03-20 22:17:13 +0000355 pid_t pid;
356 struct fd_pair pp;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000357
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100358 if (argv[0] == NULL)
Denis Vlasenko83518d12009-03-20 22:17:13 +0000359 bb_show_usage();
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100360 if (opt & OPT_CREATE_LEADING_DIR)
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100361 mkdir(argv[0], 0777);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000362 /* Crude existence check:
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100363 * close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
Denis Vlasenko83518d12009-03-20 22:17:13 +0000364 * We can also xopen, fstat, IS_DIR, later fchdir.
365 * This would check for existence earlier and cleaner.
366 * As it stands now, if we fail xchdir later,
367 * child dies on EPIPE, unless it caught
368 * a diffrerent problem earlier.
369 * This is good enough for now.
370 */
371#if !BB_MMU
372 pp.rd = 3;
373 pp.wr = 4;
374 if (!re_execed) {
375 close(3);
376 close(4);
377 xpiped_pair(pp);
378 }
379#else
380 xpiped_pair(pp);
381#endif
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100382 pid = fork_or_rexec(argv - optind);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000383 if (pid == 0) { /* child */
384 close(pp.rd);
385 xmove_fd(pp.wr, STDOUT_FILENO);
386 goto dump;
387 }
388 /* parent */
Denys Vlasenkod2277e22011-11-22 17:19:26 +0100389 USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100390 xchdir(*argv++);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000391 close(pp.wr);
392 xmove_fd(pp.rd, STDIN_FILENO);
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100393 //opt &= ~OPT_PASSTHROUGH;
394 opt |= OPT_EXTRACT;
Denis Vlasenko83518d12009-03-20 22:17:13 +0000395 goto skip;
396 }
397 /* -o */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100398 if (opt & OPT_CREATE) {
Denys Vlasenko93ac7d82010-01-09 19:56:15 +0100399 if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
Denis Vlasenko261f2372008-04-05 00:07:46 +0000400 bb_show_usage();
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100401 if (opt & OPT_FILE) {
Denys Vlasenkoc05387d2010-10-18 02:38:27 +0200402 xmove_fd(xopen(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000403 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000404 dump:
Denis Vlasenko261f2372008-04-05 00:07:46 +0000405 return cpio_o();
406 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000407 skip:
Denis Vlasenko261f2372008-04-05 00:07:46 +0000408#endif
Glenn L McGrath10b78132004-02-25 09:30:06 +0000409
410 /* One of either extract or test options must be given */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100411 if ((opt & (OPT_TEST | OPT_EXTRACT)) == 0) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000412 bb_show_usage();
413 }
414
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100415 if (opt & OPT_TEST) {
Rob Landleyb7128c62005-09-11 01:05:30 +0000416 /* if both extract and test options are given, ignore extract option */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100417 opt &= ~OPT_EXTRACT;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000418 archive_handle->action_header = header_list;
419 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100420 if (opt & OPT_EXTRACT) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000421 archive_handle->action_data = data_extract_all;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100422 if (opt & OPT_2STDOUT)
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200423 archive_handle->action_data = data_extract_to_stdout;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000424 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100425 if (opt & OPT_UNCONDITIONAL) {
Denys Vlasenkod57d6262009-09-17 02:43:14 +0200426 archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
Denis Vlasenkoa60936d2008-06-28 05:04:09 +0000427 archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000428 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100429 if (opt & OPT_VERBOSE) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000430 if (archive_handle->action_header == header_list) {
431 archive_handle->action_header = header_verbose_list;
432 } else {
433 archive_handle->action_header = header_list;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000434 }
435 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100436 if (opt & OPT_CREATE_LEADING_DIR) {
Denis Vlasenkoa60936d2008-06-28 05:04:09 +0000437 archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000438 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100439 if (opt & OPT_PRESERVE_MTIME) {
Denys Vlasenkod57d6262009-09-17 02:43:14 +0200440 archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
Denis Vlasenkobbd55c92008-06-27 15:52:07 +0000441 }
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000442
Denis Vlasenko261f2372008-04-05 00:07:46 +0000443 while (*argv) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000444 archive_handle->filter = filter_accept_list;
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100445 llist_add_to(&archive_handle->accept, *argv);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000446 argv++;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000447 }
448
Denis Vlasenkocf4dd072008-10-17 14:11:04 +0000449 /* see get_header_cpio */
Denys Vlasenkoaa4977d2010-01-06 10:53:17 +0100450 archive_handle->cpio__blocks = (off_t)-1;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000451 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
452 continue;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000453
Denys Vlasenkoaa4977d2010-01-06 10:53:17 +0100454 if (archive_handle->cpio__blocks != (off_t)-1
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100455 && !(opt & OPT_QUIET)
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100456 ) {
Matheus Izvekov4640ccc2010-04-26 13:53:57 +0200457 fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100458 }
Denis Vlasenkod83676e2008-10-17 14:03:56 +0000459
Denis Vlasenko079f8af2006-11-27 16:49:31 +0000460 return EXIT_SUCCESS;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000461}