cpio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini cpio implementation for busybox
  4. *
  5. * Copyright (C) 2001 by Glenn McGrath
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. *
  9. * Limitations:
  10. * Doesn't check CRC's
  11. * Only supports new ASCII and CRC formats
  12. */
  13. //config:config CPIO
  14. //config: bool "cpio (15 kb)"
  15. //config: default y
  16. //config: help
  17. //config: cpio is an archival utility program used to create, modify, and
  18. //config: extract contents from archives.
  19. //config: cpio has 110 bytes of overheads for every stored file.
  20. //config:
  21. //config: This implementation of cpio can extract cpio archives created in the
  22. //config: "newc" or "crc" format.
  23. //config:
  24. //config: Unless you have a specific application which requires cpio, you
  25. //config: should probably say N here.
  26. //config:
  27. //config:config FEATURE_CPIO_O
  28. //config: bool "Support archive creation"
  29. //config: default y
  30. //config: depends on CPIO
  31. //config: help
  32. //config: This implementation of cpio can create cpio archives in the "newc"
  33. //config: format only.
  34. //config:
  35. //config:config FEATURE_CPIO_P
  36. //config: bool "Support passthrough mode"
  37. //config: default y
  38. //config: depends on FEATURE_CPIO_O
  39. //config: help
  40. //config: Passthrough mode. Rarely used.
  41. //config:
  42. //config:config FEATURE_CPIO_IGNORE_DEVNO
  43. //config: bool "Support --ignore-devno like GNU cpio"
  44. //config: default y
  45. //config: depends on FEATURE_CPIO_O && LONG_OPTS
  46. //config: help
  47. //config: Optionally ignore device numbers when creating archives.
  48. //config:
  49. //config:config FEATURE_CPIO_RENUMBER_INODES
  50. //config: bool "Support --renumber-inodes like GNU cpio"
  51. //config: default y
  52. //config: depends on FEATURE_CPIO_O && LONG_OPTS
  53. //config: help
  54. //config: Optionally renumber inodes when creating archives.
  55. //applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP))
  56. //kbuild:lib-$(CONFIG_CPIO) += cpio.o
  57. //usage:#define cpio_trivial_usage
  58. //usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
  59. //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
  60. //usage: " [EXTR_FILE]..."
  61. //usage:#define cpio_full_usage "\n\n"
  62. //usage: "Extract (-i) or list (-t) files from a cpio archive on stdin"
  63. //usage: IF_FEATURE_CPIO_O(", or"
  64. //usage: "\ntake file list from stdin and create an archive (-o)"
  65. //usage: IF_FEATURE_CPIO_P(" or copy files (-p)")
  66. //usage: )
  67. //usage: "\n"
  68. //usage: "\nMain operation mode:"
  69. //usage: "\n -t List"
  70. //usage: "\n -i Extract EXTR_FILEs (or all)"
  71. //usage: IF_FEATURE_CPIO_O(
  72. //usage: "\n -o Create (requires -H newc)"
  73. //usage: )
  74. //usage: IF_FEATURE_CPIO_P(
  75. //usage: "\n -p DIR Copy files to DIR"
  76. //usage: )
  77. //usage: "\nOptions:"
  78. //usage: IF_FEATURE_CPIO_O(
  79. //usage: "\n -H newc Archive format"
  80. //usage: )
  81. //usage: "\n -d Make leading directories"
  82. //usage: "\n -m Restore mtime"
  83. //usage: "\n -v Verbose"
  84. //usage: "\n -u Overwrite"
  85. //usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
  86. //usage: "\n -R USER[:GRP] Set owner of created files"
  87. //usage: "\n -L Dereference symlinks"
  88. //usage: "\n -0 NUL terminated input"
  89. //usage: IF_FEATURE_CPIO_IGNORE_DEVNO(
  90. //usage: "\n --ignore-devno"
  91. //usage: )
  92. //usage: IF_FEATURE_CPIO_RENUMBER_INODES(
  93. //usage: "\n --renumber-inodes"
  94. //usage: )
  95. /* GNU cpio 2.9 --help (abridged):
  96. Modes:
  97. -t, --list List the archive
  98. -i, --extract Extract files from an archive
  99. -o, --create Create the archive
  100. -p, --pass-through Copy-pass mode
  101. Options valid in any mode:
  102. --block-size=SIZE I/O block size = SIZE * 512 bytes
  103. -B I/O block size = 5120 bytes
  104. -c Use the old portable (ASCII) archive format
  105. -C, --io-size=NUMBER I/O block size in bytes
  106. -f, --nonmatching Only copy files that do not match given pattern
  107. -F, --file=FILE Use FILE instead of standard input or output
  108. -H, --format=FORMAT Use given archive FORMAT
  109. -M, --message=STRING Print STRING when the end of a volume of the
  110. backup media is reached
  111. -n, --numeric-uid-gid If -v, show numeric UID and GID
  112. --quiet Do not print the number of blocks copied
  113. --rsh-command=COMMAND Use remote COMMAND instead of rsh
  114. -v, --verbose Verbosely list the files processed
  115. -V, --dot Print a "." for each file processed
  116. -W, --warning=FLAG Control warning display: 'none','truncate','all';
  117. multiple options accumulate
  118. Options valid only in --extract mode:
  119. -b, --swap Swap both halfwords of words and bytes of
  120. halfwords in the data (equivalent to -sS)
  121. -r, --rename Interactively rename files
  122. -s, --swap-bytes Swap the bytes of each halfword in the files
  123. -S, --swap-halfwords Swap the halfwords of each word (4 bytes)
  124. --to-stdout Extract files to standard output
  125. -E, --pattern-file=FILE Read additional patterns specifying filenames to
  126. extract or list from FILE
  127. --only-verify-crc Verify CRC's, don't actually extract the files
  128. Options valid only in --create mode:
  129. -A, --append Append to an existing archive
  130. -O FILE File to use instead of standard output
  131. Options valid only in --pass-through mode:
  132. -l, --link Link files instead of copying them, when possible
  133. Options valid in --extract and --create modes:
  134. --absolute-filenames Do not strip file system prefix components from
  135. the file names
  136. --no-absolute-filenames Create all files relative to the current dir
  137. Options valid in --create and --pass-through modes:
  138. -0, --null A list of filenames is terminated by a NUL
  139. -a, --reset-access-time Reset the access times of files after reading them
  140. -I FILE File to use instead of standard input
  141. -L, --dereference Dereference symbolic links (copy the files
  142. that they point to instead of copying the links)
  143. -R, --owner=[USER][:.][GRP] Set owner of created files
  144. Options valid in --extract and --pass-through modes:
  145. -d, --make-directories Create leading directories where needed
  146. -m, --preserve-modification-time Retain mtime when creating files
  147. --no-preserve-owner Do not change the ownership of the files
  148. --sparse Write files with blocks of zeros as sparse files
  149. -u, --unconditional Replace all files unconditionally
  150. */
  151. #include "libbb.h"
  152. #include "common_bufsiz.h"
  153. #include "bb_archive.h"
  154. enum {
  155. OPT_EXTRACT = (1 << 0),
  156. OPT_TEST = (1 << 1),
  157. OPT_NUL_TERMINATED = (1 << 2),
  158. OPT_UNCONDITIONAL = (1 << 3),
  159. OPT_VERBOSE = (1 << 4),
  160. OPT_CREATE_LEADING_DIR = (1 << 5),
  161. OPT_PRESERVE_MTIME = (1 << 6),
  162. OPT_DEREF = (1 << 7),
  163. OPT_FILE = (1 << 8),
  164. OPT_OWNER = (1 << 9),
  165. OPTBIT_OWNER = 9,
  166. IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
  167. IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
  168. IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
  169. IF_LONG_OPTS( OPTBIT_QUIET ,)
  170. IF_LONG_OPTS( OPTBIT_2STDOUT ,)
  171. IF_FEATURE_CPIO_IGNORE_DEVNO(OPTBIT_IGNORE_DEVNO,)
  172. IF_FEATURE_CPIO_RENUMBER_INODES(OPTBIT_RENUMBER_INODES,)
  173. OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
  174. OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
  175. OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
  176. OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
  177. OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
  178. OPT_IGNORE_DEVNO = IF_FEATURE_CPIO_IGNORE_DEVNO((1 << OPTBIT_IGNORE_DEVNO)) + 0,
  179. OPT_RENUMBER_INODES = IF_FEATURE_CPIO_RENUMBER_INODES((1 << OPTBIT_RENUMBER_INODES)) + 0,
  180. };
  181. #define OPTION_STR "it0uvdmLF:R:"
  182. struct globals {
  183. struct bb_uidgid_t owner_ugid;
  184. ino_t next_inode;
  185. } FIX_ALIASING;
  186. #define G (*(struct globals*)bb_common_bufsiz1)
  187. void BUG_cpio_globals_too_big(void);
  188. #define INIT_G() do { \
  189. setup_common_bufsiz(); \
  190. G.owner_ugid.uid = -1L; \
  191. G.owner_ugid.gid = -1L; \
  192. } while (0)
  193. #if ENABLE_FEATURE_CPIO_O
  194. static off_t cpio_pad4(off_t size)
  195. {
  196. int i;
  197. i = (- size) & 3;
  198. size += i;
  199. while (--i >= 0)
  200. bb_putchar('\0');
  201. return size;
  202. }
  203. /* Return value will become exit code.
  204. * It's ok to exit instead of return. */
  205. static NOINLINE int cpio_o(void)
  206. {
  207. struct name_s {
  208. struct name_s *next;
  209. char name[1];
  210. };
  211. struct inodes_s {
  212. struct inodes_s *next;
  213. struct name_s *names;
  214. struct stat st;
  215. #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
  216. ino_t mapped_inode;
  217. #endif
  218. };
  219. struct inodes_s *links = NULL;
  220. off_t bytes = 0; /* output bytes count */
  221. while (1) {
  222. const char *name;
  223. char *line;
  224. struct stat st;
  225. line = (option_mask32 & OPT_NUL_TERMINATED)
  226. ? bb_get_chunk_from_file(stdin, NULL)
  227. : xmalloc_fgetline(stdin);
  228. if (line) {
  229. /* Strip leading "./[./]..." from the filename */
  230. name = line;
  231. while (name[0] == '.' && name[1] == '/') {
  232. while (*++name == '/')
  233. continue;
  234. }
  235. if (!*name) { /* line is empty */
  236. free(line);
  237. continue;
  238. }
  239. if ((option_mask32 & OPT_DEREF)
  240. ? stat(name, &st)
  241. : lstat(name, &st)
  242. ) {
  243. abort_cpio_o:
  244. bb_simple_perror_msg_and_die(name);
  245. }
  246. if (G.owner_ugid.uid != (uid_t)-1L)
  247. st.st_uid = G.owner_ugid.uid;
  248. if (G.owner_ugid.gid != (gid_t)-1L)
  249. st.st_gid = G.owner_ugid.gid;
  250. if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
  251. st.st_size = 0; /* paranoia */
  252. /* Store hardlinks for later processing, dont output them */
  253. if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
  254. struct name_s *n;
  255. struct inodes_s *l;
  256. /* Do we have this hardlink remembered? */
  257. l = links;
  258. while (1) {
  259. if (l == NULL) {
  260. /* Not found: add new item to "links" list */
  261. l = xzalloc(sizeof(*l));
  262. l->st = st;
  263. l->next = links;
  264. #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
  265. if (option_mask32 & OPT_RENUMBER_INODES)
  266. l->mapped_inode = ++G.next_inode;
  267. #endif
  268. links = l;
  269. break;
  270. }
  271. if (l->st.st_ino == st.st_ino) {
  272. /* found */
  273. break;
  274. }
  275. l = l->next;
  276. }
  277. /* Add new name to "l->names" list */
  278. n = xmalloc(sizeof(*n) + strlen(name));
  279. strcpy(n->name, name);
  280. n->next = l->names;
  281. l->names = n;
  282. free(line);
  283. continue;
  284. }
  285. #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
  286. else if (option_mask32 & OPT_RENUMBER_INODES) {
  287. st.st_ino = ++G.next_inode;
  288. }
  289. #endif
  290. } else { /* line == NULL: EOF */
  291. next_link:
  292. if (links) {
  293. /* Output hardlink's data */
  294. st = links->st;
  295. name = links->names->name;
  296. links->names = links->names->next;
  297. #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
  298. if (links->mapped_inode)
  299. st.st_ino = links->mapped_inode;
  300. #endif
  301. /* GNU cpio is reported to emit file data
  302. * only for the last instance. Mimic that. */
  303. if (links->names == NULL)
  304. links = links->next;
  305. else
  306. st.st_size = 0;
  307. /* NB: we leak links->names and/or links,
  308. * this is intended (we exit soon anyway) */
  309. } else {
  310. /* If no (more) hardlinks to output,
  311. * output "trailer" entry */
  312. name = cpio_TRAILER;
  313. /* st.st_size == 0 is a must, but for uniformity
  314. * in the output, we zero out everything */
  315. memset(&st, 0, sizeof(st));
  316. /* st.st_nlink = 1; - GNU cpio does this */
  317. }
  318. }
  319. #if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
  320. if (option_mask32 & OPT_IGNORE_DEVNO)
  321. st.st_dev = st.st_rdev = 0;
  322. #endif
  323. bytes += printf("070701"
  324. "%08X%08X%08X%08X%08X%08X%08X"
  325. "%08X%08X%08X%08X" /* GNU cpio uses uppercase hex */
  326. /* strlen+1: */ "%08X"
  327. /* chksum: */ "00000000" /* (only for "070702" files) */
  328. /* name,NUL: */ "%s%c",
  329. (unsigned)(uint32_t) st.st_ino,
  330. (unsigned)(uint32_t) st.st_mode,
  331. (unsigned)(uint32_t) st.st_uid,
  332. (unsigned)(uint32_t) st.st_gid,
  333. (unsigned)(uint32_t) st.st_nlink,
  334. (unsigned)(uint32_t) st.st_mtime,
  335. (unsigned)(uint32_t) st.st_size,
  336. (unsigned)(uint32_t) major(st.st_dev),
  337. (unsigned)(uint32_t) minor(st.st_dev),
  338. (unsigned)(uint32_t) major(st.st_rdev),
  339. (unsigned)(uint32_t) minor(st.st_rdev),
  340. (unsigned)(strlen(name) + 1),
  341. name, '\0');
  342. bytes = cpio_pad4(bytes);
  343. if (st.st_size) {
  344. if (S_ISLNK(st.st_mode)) {
  345. char *lpath = xmalloc_readlink_or_warn(name);
  346. if (!lpath)
  347. goto abort_cpio_o;
  348. bytes += printf("%s", lpath);
  349. free(lpath);
  350. } else { /* S_ISREG */
  351. int fd = xopen(name, O_RDONLY);
  352. fflush_all();
  353. /* We must abort if file got shorter too! */
  354. bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
  355. bytes += st.st_size;
  356. close(fd);
  357. }
  358. bytes = cpio_pad4(bytes);
  359. }
  360. if (!line) {
  361. if (name != cpio_TRAILER)
  362. goto next_link;
  363. /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
  364. return EXIT_SUCCESS;
  365. }
  366. free(line);
  367. } /* end of "while (1)" */
  368. }
  369. #endif
  370. int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  371. int cpio_main(int argc UNUSED_PARAM, char **argv)
  372. {
  373. archive_handle_t *archive_handle;
  374. char *cpio_filename;
  375. char *cpio_owner;
  376. IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
  377. unsigned opt;
  378. #if ENABLE_LONG_OPTS
  379. const char *long_opts =
  380. "extract\0" No_argument "i"
  381. "list\0" No_argument "t"
  382. #if ENABLE_FEATURE_CPIO_O
  383. "create\0" No_argument "o"
  384. "format\0" Required_argument "H"
  385. #if ENABLE_FEATURE_CPIO_P
  386. "pass-through\0" No_argument "p"
  387. #endif
  388. #endif
  389. "owner\0" Required_argument "R"
  390. "verbose\0" No_argument "v"
  391. "null\0" No_argument "0"
  392. "quiet\0" No_argument "\xff"
  393. "to-stdout\0" No_argument "\xfe"
  394. #if ENABLE_FEATURE_CPIO_IGNORE_DEVNO
  395. "ignore-devno\0" No_argument "\xfd"
  396. #endif
  397. #if ENABLE_FEATURE_CPIO_RENUMBER_INODES
  398. "renumber-inodes\0" No_argument "\xfc"
  399. #endif
  400. ;
  401. #endif
  402. INIT_G();
  403. archive_handle = init_handle();
  404. /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
  405. archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
  406. /* As of now we do not enforce this: */
  407. /* -i,-t,-o,-p are mutually exclusive */
  408. /* -u,-d,-m make sense only with -i or -p */
  409. /* -L makes sense only with -o or -p */
  410. #if !ENABLE_FEATURE_CPIO_O
  411. opt = getopt32long(argv, OPTION_STR, long_opts, &cpio_filename, &cpio_owner);
  412. #else
  413. opt = getopt32long(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), long_opts,
  414. &cpio_filename, &cpio_owner, &cpio_fmt);
  415. #endif
  416. argv += optind;
  417. if (opt & OPT_OWNER) { /* -R */
  418. parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
  419. archive_handle->cpio__owner = G.owner_ugid;
  420. }
  421. #if !ENABLE_FEATURE_CPIO_O
  422. if (opt & OPT_FILE) { /* -F */
  423. xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
  424. }
  425. #else
  426. if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
  427. xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
  428. }
  429. if (opt & OPT_PASSTHROUGH) {
  430. pid_t pid;
  431. struct fd_pair pp;
  432. if (argv[0] == NULL)
  433. bb_show_usage();
  434. if (opt & OPT_CREATE_LEADING_DIR)
  435. /* GNU cpio 2.13: "cpio -d -p a/b/c" works */
  436. bb_make_directory(argv[0], -1, FILEUTILS_RECUR);
  437. /* Crude existence check:
  438. * close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
  439. * We can also xopen, fstat, IS_DIR, later fchdir.
  440. * This would check for existence earlier and cleaner.
  441. * As it stands now, if we fail xchdir later,
  442. * child dies on EPIPE, unless it caught
  443. * a diffrerent problem earlier.
  444. * This is good enough for now.
  445. */
  446. //FIXME: GNU cpio -d -p DIR does not immediately create DIR -
  447. //it just prepends "DIR/" to the names of files to be created.
  448. //The first file (fails to) be copied, and then the -d logic
  449. //triggers and creates all necessary directories.
  450. //IOW: bare "cpio -d -p DIR" + ^C shouldn't create anything.
  451. #if !BB_MMU
  452. pp.rd = 3;
  453. pp.wr = 4;
  454. if (!re_execed) {
  455. close(3);
  456. close(4);
  457. xpiped_pair(pp);
  458. }
  459. #else
  460. xpiped_pair(pp);
  461. #endif
  462. pid = fork_or_rexec(argv - optind);
  463. if (pid == 0) { /* child */
  464. close(pp.rd);
  465. xmove_fd(pp.wr, STDOUT_FILENO);
  466. goto dump;
  467. }
  468. /* parent */
  469. xchdir(*argv++);
  470. close(pp.wr);
  471. xmove_fd(pp.rd, STDIN_FILENO);
  472. //opt &= ~OPT_PASSTHROUGH;
  473. opt |= OPT_EXTRACT;
  474. goto skip;
  475. }
  476. /* -o */
  477. if (opt & OPT_CREATE) {
  478. if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
  479. bb_show_usage();
  480. if (opt & OPT_FILE) {
  481. xmove_fd(xopen(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
  482. }
  483. dump:
  484. return cpio_o();
  485. }
  486. skip:
  487. #endif
  488. /* One of either extract or test options must be given */
  489. if ((opt & (OPT_TEST | OPT_EXTRACT)) == 0) {
  490. bb_show_usage();
  491. }
  492. if (opt & OPT_TEST) {
  493. /* if both extract and test options are given, ignore extract option */
  494. opt &= ~OPT_EXTRACT;
  495. archive_handle->action_header = header_list;
  496. }
  497. if (opt & OPT_EXTRACT) {
  498. archive_handle->action_data = data_extract_all;
  499. if (opt & OPT_2STDOUT)
  500. archive_handle->action_data = data_extract_to_stdout;
  501. }
  502. if (opt & OPT_UNCONDITIONAL) {
  503. archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
  504. archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
  505. }
  506. if (opt & OPT_VERBOSE) {
  507. if (archive_handle->action_header == header_list) {
  508. archive_handle->action_header = header_verbose_list;
  509. } else {
  510. archive_handle->action_header = header_list;
  511. }
  512. }
  513. if (opt & OPT_CREATE_LEADING_DIR) {
  514. archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
  515. }
  516. if (opt & OPT_PRESERVE_MTIME) {
  517. archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
  518. }
  519. while (*argv) {
  520. archive_handle->filter = filter_accept_list;
  521. llist_add_to(&archive_handle->accept, *argv);
  522. argv++;
  523. }
  524. /* see get_header_cpio */
  525. archive_handle->cpio__blocks = (off_t)-1;
  526. while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
  527. continue;
  528. create_links_from_list(archive_handle->link_placeholders);
  529. if (archive_handle->cpio__blocks != (off_t)-1
  530. && !(opt & OPT_QUIET)
  531. ) {
  532. fflush_all();
  533. fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
  534. }
  535. return EXIT_SUCCESS;
  536. }