blob: c746a71faec0f88bb42b573ba62df96f4482fd01 [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 *
13 */
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000014#include "libbb.h"
Denys Vlasenko833d4e72010-11-03 02:38:31 +010015#include "archive.h"
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +000016
Denys Vlasenko1f937d62010-12-26 02:22:51 +010017//usage:#define cpio_trivial_usage
18//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
19//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
20//usage: " [EXTR_FILE]..."
21//usage:#define cpio_full_usage "\n\n"
22//usage: "Extract or list files from a cpio archive"
23//usage: IF_FEATURE_CPIO_O(", or"
24//usage: "\ncreate an archive" IF_FEATURE_CPIO_P(" (-o) or copy files (-p)")
25//usage: " using file list on stdin"
26//usage: )
27//usage: "\n"
28//usage: "\nMain operation mode:"
29//usage: "\n -t List"
30//usage: "\n -i Extract EXTR_FILEs (or all)"
31//usage: IF_FEATURE_CPIO_O(
32//usage: "\n -o Create (requires -H newc)"
33//usage: )
34//usage: IF_FEATURE_CPIO_P(
35//usage: "\n -p DIR Copy files to DIR"
36//usage: )
37//usage: "\nOptions:"
38//usage: "\n -d Make leading directories"
39//usage: "\n -m Preserve mtime"
40//usage: "\n -v Verbose"
41//usage: "\n -u Overwrite"
42//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
43//usage: IF_FEATURE_CPIO_O(
44//usage: "\n -H newc Archive format"
45//usage: )
46
Denis Vlasenko05af8322009-03-20 23:01:48 +000047/* GNU cpio 2.9 --help (abridged):
48
49 Modes:
50 -t, --list List the archive
51 -i, --extract Extract files from an archive
52 -o, --create Create the archive
Denys Vlasenko1f937d62010-12-26 02:22:51 +010053 -p, --pass-through Copy-pass mode
Denis Vlasenko05af8322009-03-20 23:01:48 +000054
55 Options valid in any mode:
56 --block-size=SIZE I/O block size = SIZE * 512 bytes
57 -B I/O block size = 5120 bytes
58 -c Use the old portable (ASCII) archive format
59 -C, --io-size=NUMBER I/O block size in bytes
60 -f, --nonmatching Only copy files that do not match given pattern
61 -F, --file=FILE Use FILE instead of standard input or output
62 -H, --format=FORMAT Use given archive FORMAT
63 -M, --message=STRING Print STRING when the end of a volume of the
64 backup media is reached
65 -n, --numeric-uid-gid If -v, show numeric UID and GID
66 --quiet Do not print the number of blocks copied
67 --rsh-command=COMMAND Use remote COMMAND instead of rsh
68 -v, --verbose Verbosely list the files processed
69 -V, --dot Print a "." for each file processed
70 -W, --warning=FLAG Control warning display: 'none','truncate','all';
71 multiple options accumulate
72
73 Options valid only in --extract mode:
74 -b, --swap Swap both halfwords of words and bytes of
75 halfwords in the data (equivalent to -sS)
76 -r, --rename Interactively rename files
77 -s, --swap-bytes Swap the bytes of each halfword in the files
78 -S, --swap-halfwords Swap the halfwords of each word (4 bytes)
79 --to-stdout Extract files to standard output
80 -E, --pattern-file=FILE Read additional patterns specifying filenames to
81 extract or list from FILE
82 --only-verify-crc Verify CRC's, don't actually extract the files
83
84 Options valid only in --create mode:
85 -A, --append Append to an existing archive
86 -O FILE File to use instead of standard output
87
88 Options valid only in --pass-through mode:
89 -l, --link Link files instead of copying them, when possible
90
91 Options valid in --extract and --create modes:
92 --absolute-filenames Do not strip file system prefix components from
93 the file names
94 --no-absolute-filenames Create all files relative to the current dir
95
96 Options valid in --create and --pass-through modes:
97 -0, --null A list of filenames is terminated by a NUL
98 -a, --reset-access-time Reset the access times of files after reading them
99 -I FILE File to use instead of standard input
100 -L, --dereference Dereference symbolic links (copy the files
101 that they point to instead of copying the links)
102 -R, --owner=[USER][:.][GROUP] Set owner of created files
103
104 Options valid in --extract and --pass-through modes:
105 -d, --make-directories Create leading directories where needed
106 -m, --preserve-modification-time Retain mtime when creating files
107 --no-preserve-owner Do not change the ownership of the files
108 --sparse Write files with blocks of zeros as sparse files
109 -u, --unconditional Replace all files unconditionally
110 */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100111
Denis Vlasenko05af8322009-03-20 23:01:48 +0000112enum {
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100113 OPT_EXTRACT = (1 << 0),
114 OPT_TEST = (1 << 1),
115 OPT_NUL_TERMINATED = (1 << 2),
116 OPT_UNCONDITIONAL = (1 << 3),
117 OPT_VERBOSE = (1 << 4),
118 OPT_CREATE_LEADING_DIR = (1 << 5),
119 OPT_PRESERVE_MTIME = (1 << 6),
120 OPT_DEREF = (1 << 7),
121 OPT_FILE = (1 << 8),
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200122 OPTBIT_FILE = 8,
123 IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
124 IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
125 IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
126 IF_LONG_OPTS( OPTBIT_QUIET ,)
127 IF_LONG_OPTS( OPTBIT_2STDOUT ,)
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100128 OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
129 OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
130 OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
131 OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
132 OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
Denis Vlasenko05af8322009-03-20 23:01:48 +0000133};
134
135#define OPTION_STR "it0uvdmLF:"
136
Denis Vlasenko261f2372008-04-05 00:07:46 +0000137#if ENABLE_FEATURE_CPIO_O
138static off_t cpio_pad4(off_t size)
139{
140 int i;
141
142 i = (- size) & 3;
143 size += i;
144 while (--i >= 0)
145 bb_putchar('\0');
146 return size;
147}
148
149/* Return value will become exit code.
150 * It's ok to exit instead of return. */
Denys Vlasenkoa7bb3c12009-10-08 12:28:08 +0200151static NOINLINE int cpio_o(void)
Denis Vlasenko261f2372008-04-05 00:07:46 +0000152{
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000153 static const char trailer[] ALIGN1 = "TRAILER!!!";
Denis Vlasenko261f2372008-04-05 00:07:46 +0000154 struct name_s {
155 struct name_s *next;
156 char name[1];
157 };
158 struct inodes_s {
159 struct inodes_s *next;
160 struct name_s *names;
161 struct stat st;
162 };
163
164 struct inodes_s *links = NULL;
165 off_t bytes = 0; /* output bytes count */
166
167 while (1) {
168 const char *name;
169 char *line;
170 struct stat st;
171
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100172 line = (option_mask32 & OPT_NUL_TERMINATED)
Denis Vlasenko05af8322009-03-20 23:01:48 +0000173 ? bb_get_chunk_from_file(stdin, NULL)
174 : xmalloc_fgetline(stdin);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000175
176 if (line) {
177 /* Strip leading "./[./]..." from the filename */
178 name = line;
179 while (name[0] == '.' && name[1] == '/') {
180 while (*++name == '/')
181 continue;
182 }
183 if (!*name) { /* line is empty */
184 free(line);
185 continue;
186 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100187 if ((option_mask32 & OPT_DEREF)
Denis Vlasenko05af8322009-03-20 23:01:48 +0000188 ? stat(name, &st)
189 : lstat(name, &st)
190 ) {
Denis Vlasenko261f2372008-04-05 00:07:46 +0000191 abort_cpio_o:
192 bb_simple_perror_msg_and_die(name);
193 }
194
195 if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
196 st.st_size = 0; /* paranoia */
197
198 /* Store hardlinks for later processing, dont output them */
199 if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
200 struct name_s *n;
201 struct inodes_s *l;
202
203 /* Do we have this hardlink remembered? */
204 l = links;
205 while (1) {
206 if (l == NULL) {
207 /* Not found: add new item to "links" list */
208 l = xzalloc(sizeof(*l));
209 l->st = st;
210 l->next = links;
211 links = l;
212 break;
213 }
214 if (l->st.st_ino == st.st_ino) {
215 /* found */
216 break;
217 }
218 l = l->next;
219 }
220 /* Add new name to "l->names" list */
221 n = xmalloc(sizeof(*n) + strlen(name));
222 strcpy(n->name, name);
223 n->next = l->names;
224 l->names = n;
225
226 free(line);
227 continue;
228 }
229
230 } else { /* line == NULL: EOF */
231 next_link:
232 if (links) {
233 /* Output hardlink's data */
234 st = links->st;
235 name = links->names->name;
236 links->names = links->names->next;
237 /* GNU cpio is reported to emit file data
238 * only for the last instance. Mimic that. */
239 if (links->names == NULL)
240 links = links->next;
241 else
242 st.st_size = 0;
243 /* NB: we leak links->names and/or links,
244 * this is intended (we exit soon anyway) */
245 } else {
246 /* If no (more) hardlinks to output,
247 * output "trailer" entry */
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000248 name = trailer;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000249 /* st.st_size == 0 is a must, but for uniformity
250 * in the output, we zero out everything */
251 memset(&st, 0, sizeof(st));
252 /* st.st_nlink = 1; - GNU cpio does this */
253 }
254 }
255
256 bytes += printf("070701"
257 "%08X%08X%08X%08X%08X%08X%08X"
258 "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
259 /* strlen+1: */ "%08X"
260 /* chksum: */ "00000000" /* (only for "070702" files) */
261 /* name,NUL: */ "%s%c",
262 (unsigned)(uint32_t) st.st_ino,
263 (unsigned)(uint32_t) st.st_mode,
264 (unsigned)(uint32_t) st.st_uid,
265 (unsigned)(uint32_t) st.st_gid,
266 (unsigned)(uint32_t) st.st_nlink,
267 (unsigned)(uint32_t) st.st_mtime,
268 (unsigned)(uint32_t) st.st_size,
269 (unsigned)(uint32_t) major(st.st_dev),
270 (unsigned)(uint32_t) minor(st.st_dev),
271 (unsigned)(uint32_t) major(st.st_rdev),
272 (unsigned)(uint32_t) minor(st.st_rdev),
273 (unsigned)(strlen(name) + 1),
274 name, '\0');
275 bytes = cpio_pad4(bytes);
276
277 if (st.st_size) {
278 if (S_ISLNK(st.st_mode)) {
279 char *lpath = xmalloc_readlink_or_warn(name);
280 if (!lpath)
281 goto abort_cpio_o;
282 bytes += printf("%s", lpath);
283 free(lpath);
284 } else { /* S_ISREG */
285 int fd = xopen(name, O_RDONLY);
Denys Vlasenko8131eea2009-11-02 14:19:51 +0100286 fflush_all();
Denis Vlasenko261f2372008-04-05 00:07:46 +0000287 /* We must abort if file got shorter too! */
Denis Vlasenko1af00ed2008-04-05 02:44:30 +0000288 bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000289 bytes += st.st_size;
290 close(fd);
291 }
292 bytes = cpio_pad4(bytes);
293 }
294
295 if (!line) {
Denis Vlasenkoc503dde2008-10-26 19:55:20 +0000296 if (name != trailer)
Denis Vlasenko261f2372008-04-05 00:07:46 +0000297 goto next_link;
298 /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
299 return EXIT_SUCCESS;
300 }
301
302 free(line);
303 } /* end of "while (1)" */
304}
305#endif
Glenn L McGrath10b78132004-02-25 09:30:06 +0000306
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000307int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000308int cpio_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000309{
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000310 archive_handle_t *archive_handle;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000311 char *cpio_filename;
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000312 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
Denis Vlasenko67b23e62006-10-03 21:00:06 +0000313 unsigned opt;
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000314
Denys Vlasenkof3b92d32009-06-19 12:10:38 +0200315#if ENABLE_LONG_OPTS
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000316 applet_long_options =
317 "extract\0" No_argument "i"
318 "list\0" No_argument "t"
319#if ENABLE_FEATURE_CPIO_O
320 "create\0" No_argument "o"
321 "format\0" Required_argument "H"
Denis Vlasenko83518d12009-03-20 22:17:13 +0000322#if ENABLE_FEATURE_CPIO_P
323 "pass-through\0" No_argument "p"
324#endif
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000325#endif
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200326 "verbose\0" No_argument "v"
327 "quiet\0" No_argument "\xff"
328 "to-stdout\0" No_argument "\xfe"
Denis Vlasenko2b407b12008-07-11 21:42:12 +0000329 ;
330#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000331
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100332 archive_handle = init_handle();
333 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
334 archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
335
Denis Vlasenko83518d12009-03-20 22:17:13 +0000336 /* As of now we do not enforce this: */
337 /* -i,-t,-o,-p are mutually exclusive */
338 /* -u,-d,-m make sense only with -i or -p */
Denis Vlasenko05af8322009-03-20 23:01:48 +0000339 /* -L makes sense only with -o or -p */
340
Denis Vlasenko83518d12009-03-20 22:17:13 +0000341#if !ENABLE_FEATURE_CPIO_O
Denis Vlasenko05af8322009-03-20 23:01:48 +0000342 opt = getopt32(argv, OPTION_STR, &cpio_filename);
Denys Vlasenkoff0e8752010-05-10 04:16:43 +0200343 argv += optind;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100344 if (opt & OPT_FILE) { /* -F */
Denys Vlasenko02dd96f2010-01-09 20:25:42 +0100345 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100346 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000347#else
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000348 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100349 argv += optind;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100350 if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100351 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
352 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100353 if (opt & OPT_PASSTHROUGH) {
Denis Vlasenko83518d12009-03-20 22:17:13 +0000354 pid_t pid;
355 struct fd_pair pp;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000356
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100357 if (argv[0] == NULL)
Denis Vlasenko83518d12009-03-20 22:17:13 +0000358 bb_show_usage();
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100359 if (opt & OPT_CREATE_LEADING_DIR)
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100360 mkdir(argv[0], 0777);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000361 /* Crude existence check:
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100362 * close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
Denis Vlasenko83518d12009-03-20 22:17:13 +0000363 * We can also xopen, fstat, IS_DIR, later fchdir.
364 * This would check for existence earlier and cleaner.
365 * As it stands now, if we fail xchdir later,
366 * child dies on EPIPE, unless it caught
367 * a diffrerent problem earlier.
368 * This is good enough for now.
369 */
370#if !BB_MMU
371 pp.rd = 3;
372 pp.wr = 4;
373 if (!re_execed) {
374 close(3);
375 close(4);
376 xpiped_pair(pp);
377 }
378#else
379 xpiped_pair(pp);
380#endif
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100381 pid = fork_or_rexec(argv - optind);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000382 if (pid == 0) { /* child */
383 close(pp.rd);
384 xmove_fd(pp.wr, STDOUT_FILENO);
385 goto dump;
386 }
387 /* parent */
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100388 xchdir(*argv++);
Denis Vlasenko83518d12009-03-20 22:17:13 +0000389 close(pp.wr);
390 xmove_fd(pp.rd, STDIN_FILENO);
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100391 //opt &= ~OPT_PASSTHROUGH;
392 opt |= OPT_EXTRACT;
Denis Vlasenko83518d12009-03-20 22:17:13 +0000393 goto skip;
394 }
395 /* -o */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100396 if (opt & OPT_CREATE) {
Denys Vlasenko93ac7d82010-01-09 19:56:15 +0100397 if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
Denis Vlasenko261f2372008-04-05 00:07:46 +0000398 bb_show_usage();
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100399 if (opt & OPT_FILE) {
Denys Vlasenkoc05387d2010-10-18 02:38:27 +0200400 xmove_fd(xopen(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000401 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000402 dump:
Denis Vlasenko261f2372008-04-05 00:07:46 +0000403 return cpio_o();
404 }
Denis Vlasenko83518d12009-03-20 22:17:13 +0000405 skip:
Denis Vlasenko261f2372008-04-05 00:07:46 +0000406#endif
Glenn L McGrath10b78132004-02-25 09:30:06 +0000407
408 /* One of either extract or test options must be given */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100409 if ((opt & (OPT_TEST | OPT_EXTRACT)) == 0) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000410 bb_show_usage();
411 }
412
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100413 if (opt & OPT_TEST) {
Rob Landleyb7128c62005-09-11 01:05:30 +0000414 /* if both extract and test options are given, ignore extract option */
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100415 opt &= ~OPT_EXTRACT;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000416 archive_handle->action_header = header_list;
417 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100418 if (opt & OPT_EXTRACT) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000419 archive_handle->action_data = data_extract_all;
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100420 if (opt & OPT_2STDOUT)
Denys Vlasenkod30b89c2009-06-26 01:55:45 +0200421 archive_handle->action_data = data_extract_to_stdout;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000422 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100423 if (opt & OPT_UNCONDITIONAL) {
Denys Vlasenkod57d6262009-09-17 02:43:14 +0200424 archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
Denis Vlasenkoa60936d2008-06-28 05:04:09 +0000425 archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000426 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100427 if (opt & OPT_VERBOSE) {
Glenn L McGrath10b78132004-02-25 09:30:06 +0000428 if (archive_handle->action_header == header_list) {
429 archive_handle->action_header = header_verbose_list;
430 } else {
431 archive_handle->action_header = header_list;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000432 }
433 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100434 if (opt & OPT_CREATE_LEADING_DIR) {
Denis Vlasenkoa60936d2008-06-28 05:04:09 +0000435 archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
Glenn L McGrath10b78132004-02-25 09:30:06 +0000436 }
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100437 if (opt & OPT_PRESERVE_MTIME) {
Denys Vlasenkod57d6262009-09-17 02:43:14 +0200438 archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
Denis Vlasenkobbd55c92008-06-27 15:52:07 +0000439 }
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000440
Denis Vlasenko261f2372008-04-05 00:07:46 +0000441 while (*argv) {
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000442 archive_handle->filter = filter_accept_list;
Denys Vlasenko40e5a302010-01-04 14:30:37 +0100443 llist_add_to(&archive_handle->accept, *argv);
Denis Vlasenko261f2372008-04-05 00:07:46 +0000444 argv++;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000445 }
446
Denis Vlasenkocf4dd072008-10-17 14:11:04 +0000447 /* see get_header_cpio */
Denys Vlasenkoaa4977d2010-01-06 10:53:17 +0100448 archive_handle->cpio__blocks = (off_t)-1;
Denis Vlasenko261f2372008-04-05 00:07:46 +0000449 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
450 continue;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000451
Denys Vlasenkoaa4977d2010-01-06 10:53:17 +0100452 if (archive_handle->cpio__blocks != (off_t)-1
Denys Vlasenko1f937d62010-12-26 02:22:51 +0100453 && !(opt & OPT_QUIET)
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100454 ) {
Matheus Izvekov4640ccc2010-04-26 13:53:57 +0200455 fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
Denys Vlasenko607f65d2010-01-09 20:23:03 +0100456 }
Denis Vlasenkod83676e2008-10-17 14:03:56 +0000457
Denis Vlasenko079f8af2006-11-27 16:49:31 +0000458 return EXIT_SUCCESS;
Glenn L McGrath8f5b63e2001-06-22 09:22:06 +0000459}