4
0

list.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. /* List a tar archive, with support routines for reading a tar archive.
  2. Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000,
  3. 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
  4. Written by John Gilmore, on 1985-08-26.
  5. This program is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  12. Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #include <system.h>
  17. #include <inttostr.h>
  18. #include <quotearg.h>
  19. #include "common.h"
  20. #define max(a, b) ((a) < (b) ? (b) : (a))
  21. union block *current_header; /* points to current archive header */
  22. enum archive_format current_format; /* recognized format */
  23. union block *recent_long_name; /* recent long name header and contents */
  24. union block *recent_long_link; /* likewise, for long link */
  25. size_t recent_long_name_blocks; /* number of blocks in recent_long_name */
  26. size_t recent_long_link_blocks; /* likewise, for long link */
  27. static uintmax_t from_header (const char *, size_t, const char *,
  28. uintmax_t, uintmax_t, bool, bool);
  29. /* Base 64 digits; see Internet RFC 2045 Table 1. */
  30. static char const base_64_digits[64] =
  31. {
  32. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  33. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  34. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
  35. 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  36. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
  37. };
  38. /* Table of base-64 digit values indexed by unsigned chars.
  39. The value is 64 for unsigned chars that are not base-64 digits. */
  40. static char base64_map[UCHAR_MAX + 1];
  41. static void
  42. base64_init (void)
  43. {
  44. int i;
  45. memset (base64_map, 64, sizeof base64_map);
  46. for (i = 0; i < 64; i++)
  47. base64_map[(int) base_64_digits[i]] = i;
  48. }
  49. /* Main loop for reading an archive. */
  50. void
  51. read_and (void (*do_something) (void))
  52. {
  53. enum read_header status = HEADER_STILL_UNREAD;
  54. enum read_header prev_status;
  55. struct timespec mtime;
  56. base64_init ();
  57. name_gather ();
  58. open_archive (ACCESS_READ);
  59. do
  60. {
  61. prev_status = status;
  62. tar_stat_destroy (&current_stat_info);
  63. status = read_header (false);
  64. switch (status)
  65. {
  66. case HEADER_STILL_UNREAD:
  67. case HEADER_SUCCESS_EXTENDED:
  68. abort ();
  69. case HEADER_SUCCESS:
  70. /* Valid header. We should decode next field (mode) first.
  71. Ensure incoming names are null terminated. */
  72. if (! name_match (current_stat_info.file_name)
  73. || (NEWER_OPTION_INITIALIZED (newer_mtime_option)
  74. /* FIXME: We get mtime now, and again later; this causes
  75. duplicate diagnostics if header.mtime is bogus. */
  76. && ((mtime.tv_sec
  77. = TIME_FROM_HEADER (current_header->header.mtime)),
  78. /* FIXME: Grab fractional time stamps from
  79. extended header. */
  80. mtime.tv_nsec = 0,
  81. current_stat_info.mtime = mtime,
  82. OLDER_TAR_STAT_TIME (current_stat_info, m)))
  83. || excluded_name (current_stat_info.file_name))
  84. {
  85. switch (current_header->header.typeflag)
  86. {
  87. case GNUTYPE_VOLHDR:
  88. case GNUTYPE_MULTIVOL:
  89. break;
  90. case DIRTYPE:
  91. if (show_omitted_dirs_option)
  92. WARN ((0, 0, _("%s: Omitting"),
  93. quotearg_colon (current_stat_info.file_name)));
  94. /* Fall through. */
  95. default:
  96. decode_header (current_header,
  97. &current_stat_info, &current_format, 0);
  98. skip_member ();
  99. continue;
  100. }
  101. }
  102. (*do_something) ();
  103. continue;
  104. case HEADER_ZERO_BLOCK:
  105. if (block_number_option)
  106. {
  107. char buf[UINTMAX_STRSIZE_BOUND];
  108. fprintf (stdlis, _("block %s: ** Block of NULs **\n"),
  109. STRINGIFY_BIGINT (current_block_ordinal (), buf));
  110. }
  111. set_next_block_after (current_header);
  112. if (!ignore_zeros_option)
  113. {
  114. char buf[UINTMAX_STRSIZE_BOUND];
  115. status = read_header (false);
  116. if (status == HEADER_ZERO_BLOCK)
  117. break;
  118. WARN ((0, 0, _("A lone zero block at %s"),
  119. STRINGIFY_BIGINT (current_block_ordinal (), buf)));
  120. break;
  121. }
  122. status = prev_status;
  123. continue;
  124. case HEADER_END_OF_FILE:
  125. if (block_number_option)
  126. {
  127. char buf[UINTMAX_STRSIZE_BOUND];
  128. fprintf (stdlis, _("block %s: ** End of File **\n"),
  129. STRINGIFY_BIGINT (current_block_ordinal (), buf));
  130. }
  131. break;
  132. case HEADER_FAILURE:
  133. /* If the previous header was good, tell them that we are
  134. skipping bad ones. */
  135. set_next_block_after (current_header);
  136. switch (prev_status)
  137. {
  138. case HEADER_STILL_UNREAD:
  139. ERROR ((0, 0, _("This does not look like a tar archive")));
  140. /* Fall through. */
  141. case HEADER_ZERO_BLOCK:
  142. case HEADER_SUCCESS:
  143. if (block_number_option)
  144. {
  145. char buf[UINTMAX_STRSIZE_BOUND];
  146. off_t block_ordinal = current_block_ordinal ();
  147. block_ordinal -= recent_long_name_blocks;
  148. block_ordinal -= recent_long_link_blocks;
  149. fprintf (stdlis, _("block %s: "),
  150. STRINGIFY_BIGINT (block_ordinal, buf));
  151. }
  152. ERROR ((0, 0, _("Skipping to next header")));
  153. break;
  154. case HEADER_END_OF_FILE:
  155. case HEADER_FAILURE:
  156. /* We are in the middle of a cascade of errors. */
  157. break;
  158. case HEADER_SUCCESS_EXTENDED:
  159. abort ();
  160. }
  161. continue;
  162. }
  163. break;
  164. }
  165. while (!all_names_found (&current_stat_info));
  166. close_archive ();
  167. names_notfound (); /* print names not found */
  168. }
  169. /* Print a header block, based on tar options. */
  170. void
  171. list_archive (void)
  172. {
  173. off_t block_ordinal = current_block_ordinal ();
  174. /* Print the header block. */
  175. decode_header (current_header, &current_stat_info, &current_format, 0);
  176. if (verbose_option)
  177. print_header (&current_stat_info, block_ordinal);
  178. if (incremental_option)
  179. {
  180. if (verbose_option > 2)
  181. {
  182. if (is_dumpdir (&current_stat_info))
  183. list_dumpdir (current_stat_info.dumpdir,
  184. dumpdir_size (current_stat_info.dumpdir));
  185. }
  186. }
  187. skip_member ();
  188. }
  189. /* Check header checksum */
  190. /* The standard BSD tar sources create the checksum by adding up the
  191. bytes in the header as type char. I think the type char was unsigned
  192. on the PDP-11, but it's signed on the Next and Sun. It looks like the
  193. sources to BSD tar were never changed to compute the checksum
  194. correctly, so both the Sun and Next add the bytes of the header as
  195. signed chars. This doesn't cause a problem until you get a file with
  196. a name containing characters with the high bit set. So tar_checksum
  197. computes two checksums -- signed and unsigned. */
  198. enum read_header
  199. tar_checksum (union block *header, bool silent)
  200. {
  201. size_t i;
  202. int unsigned_sum = 0; /* the POSIX one :-) */
  203. int signed_sum = 0; /* the Sun one :-( */
  204. int recorded_sum;
  205. uintmax_t parsed_sum;
  206. char *p;
  207. p = header->buffer;
  208. for (i = sizeof *header; i-- != 0;)
  209. {
  210. unsigned_sum += (unsigned char) *p;
  211. signed_sum += (signed char) (*p++);
  212. }
  213. if (unsigned_sum == 0)
  214. return HEADER_ZERO_BLOCK;
  215. /* Adjust checksum to count the "chksum" field as blanks. */
  216. for (i = sizeof header->header.chksum; i-- != 0;)
  217. {
  218. unsigned_sum -= (unsigned char) header->header.chksum[i];
  219. signed_sum -= (signed char) (header->header.chksum[i]);
  220. }
  221. unsigned_sum += ' ' * sizeof header->header.chksum;
  222. signed_sum += ' ' * sizeof header->header.chksum;
  223. parsed_sum = from_header (header->header.chksum,
  224. sizeof header->header.chksum, 0,
  225. (uintmax_t) 0,
  226. (uintmax_t) TYPE_MAXIMUM (int), true, silent);
  227. if (parsed_sum == (uintmax_t) -1)
  228. return HEADER_FAILURE;
  229. recorded_sum = parsed_sum;
  230. if (unsigned_sum != recorded_sum && signed_sum != recorded_sum)
  231. return HEADER_FAILURE;
  232. return HEADER_SUCCESS;
  233. }
  234. /* Read a block that's supposed to be a header block. Return its
  235. address in "current_header", and if it is good, the file's size
  236. and names (file name, link name) in *info.
  237. Return 1 for success, 0 if the checksum is bad, EOF on eof, 2 for a
  238. block full of zeros (EOF marker).
  239. If RAW_EXTENDED_HEADERS is nonzero, do not automagically fold the
  240. GNU long name and link headers into later headers.
  241. You must always set_next_block_after(current_header) to skip past
  242. the header which this routine reads. */
  243. enum read_header
  244. read_header_primitive (bool raw_extended_headers, struct tar_stat_info *info)
  245. {
  246. union block *header;
  247. union block *header_copy;
  248. char *bp;
  249. union block *data_block;
  250. size_t size, written;
  251. union block *next_long_name = 0;
  252. union block *next_long_link = 0;
  253. size_t next_long_name_blocks = 0;
  254. size_t next_long_link_blocks = 0;
  255. while (1)
  256. {
  257. enum read_header status;
  258. header = find_next_block ();
  259. current_header = header;
  260. if (!header)
  261. return HEADER_END_OF_FILE;
  262. if ((status = tar_checksum (header, false)) != HEADER_SUCCESS)
  263. return status;
  264. /* Good block. Decode file size and return. */
  265. if (header->header.typeflag == LNKTYPE)
  266. info->stat.st_size = 0; /* links 0 size on tape */
  267. else
  268. info->stat.st_size = OFF_FROM_HEADER (header->header.size);
  269. if (header->header.typeflag == GNUTYPE_LONGNAME
  270. || header->header.typeflag == GNUTYPE_LONGLINK
  271. || header->header.typeflag == XHDTYPE
  272. || header->header.typeflag == XGLTYPE
  273. || header->header.typeflag == SOLARIS_XHDTYPE)
  274. {
  275. if (raw_extended_headers)
  276. return HEADER_SUCCESS_EXTENDED;
  277. else if (header->header.typeflag == GNUTYPE_LONGNAME
  278. || header->header.typeflag == GNUTYPE_LONGLINK)
  279. {
  280. size_t name_size = info->stat.st_size;
  281. size_t n = name_size % BLOCKSIZE;
  282. size = name_size + BLOCKSIZE;
  283. if (n)
  284. size += BLOCKSIZE - n;
  285. if (name_size != info->stat.st_size || size < name_size)
  286. xalloc_die ();
  287. header_copy = xmalloc (size + 1);
  288. if (header->header.typeflag == GNUTYPE_LONGNAME)
  289. {
  290. if (next_long_name)
  291. free (next_long_name);
  292. next_long_name = header_copy;
  293. next_long_name_blocks = size / BLOCKSIZE;
  294. }
  295. else
  296. {
  297. if (next_long_link)
  298. free (next_long_link);
  299. next_long_link = header_copy;
  300. next_long_link_blocks = size / BLOCKSIZE;
  301. }
  302. set_next_block_after (header);
  303. *header_copy = *header;
  304. bp = header_copy->buffer + BLOCKSIZE;
  305. for (size -= BLOCKSIZE; size > 0; size -= written)
  306. {
  307. data_block = find_next_block ();
  308. if (! data_block)
  309. {
  310. ERROR ((0, 0, _("Unexpected EOF in archive")));
  311. break;
  312. }
  313. written = available_space_after (data_block);
  314. if (written > size)
  315. written = size;
  316. memcpy (bp, data_block->buffer, written);
  317. bp += written;
  318. set_next_block_after ((union block *)
  319. (data_block->buffer + written - 1));
  320. }
  321. *bp = '\0';
  322. }
  323. else if (header->header.typeflag == XHDTYPE
  324. || header->header.typeflag == SOLARIS_XHDTYPE)
  325. xheader_read (&info->xhdr, header,
  326. OFF_FROM_HEADER (header->header.size));
  327. else if (header->header.typeflag == XGLTYPE)
  328. {
  329. struct xheader xhdr;
  330. memset (&xhdr, 0, sizeof xhdr);
  331. xheader_read (&xhdr, header,
  332. OFF_FROM_HEADER (header->header.size));
  333. xheader_decode_global (&xhdr);
  334. xheader_destroy (&xhdr);
  335. }
  336. /* Loop! */
  337. }
  338. else
  339. {
  340. char const *name;
  341. struct posix_header const *h = &current_header->header;
  342. char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
  343. if (recent_long_name)
  344. free (recent_long_name);
  345. if (next_long_name)
  346. {
  347. name = next_long_name->buffer + BLOCKSIZE;
  348. recent_long_name = next_long_name;
  349. recent_long_name_blocks = next_long_name_blocks;
  350. }
  351. else
  352. {
  353. /* Accept file names as specified by POSIX.1-1996
  354. section 10.1.1. */
  355. char *np = namebuf;
  356. if (h->prefix[0] && strcmp (h->magic, TMAGIC) == 0)
  357. {
  358. memcpy (np, h->prefix, sizeof h->prefix);
  359. np[sizeof h->prefix] = '\0';
  360. np += strlen (np);
  361. *np++ = '/';
  362. }
  363. memcpy (np, h->name, sizeof h->name);
  364. np[sizeof h->name] = '\0';
  365. name = namebuf;
  366. recent_long_name = 0;
  367. recent_long_name_blocks = 0;
  368. }
  369. assign_string (&info->orig_file_name, name);
  370. assign_string (&info->file_name, name);
  371. info->had_trailing_slash = strip_trailing_slashes (info->file_name);
  372. if (recent_long_link)
  373. free (recent_long_link);
  374. if (next_long_link)
  375. {
  376. name = next_long_link->buffer + BLOCKSIZE;
  377. recent_long_link = next_long_link;
  378. recent_long_link_blocks = next_long_link_blocks;
  379. }
  380. else
  381. {
  382. memcpy (namebuf, h->linkname, sizeof h->linkname);
  383. namebuf[sizeof h->linkname] = '\0';
  384. name = namebuf;
  385. recent_long_link = 0;
  386. recent_long_link_blocks = 0;
  387. }
  388. assign_string (&info->link_name, name);
  389. return HEADER_SUCCESS;
  390. }
  391. }
  392. }
  393. enum read_header
  394. read_header (bool raw_extended_headers)
  395. {
  396. return read_header_primitive (raw_extended_headers, &current_stat_info);
  397. }
  398. static char *
  399. decode_xform (char *file_name, void *data)
  400. {
  401. xform_type type = *(xform_type*)data;
  402. switch (type)
  403. {
  404. case xform_symlink:
  405. /* FIXME: It is not quite clear how and to which extent are the symbolic
  406. links subject to filename transformation. In the absence of another
  407. solution, symbolic links are exempt from component stripping and
  408. name suffix normalization, but subject to filename transformation
  409. proper. */
  410. return file_name;
  411. case xform_link:
  412. file_name = safer_name_suffix (file_name, true, absolute_names_option);
  413. break;
  414. case xform_regfile:
  415. file_name = safer_name_suffix (file_name, false, absolute_names_option);
  416. break;
  417. }
  418. if (strip_name_components)
  419. {
  420. size_t prefix_len = stripped_prefix_len (file_name,
  421. strip_name_components);
  422. if (prefix_len == (size_t) -1)
  423. prefix_len = strlen (file_name);
  424. file_name += prefix_len;
  425. }
  426. return file_name;
  427. }
  428. bool
  429. transform_member_name (char **pinput, xform_type type)
  430. {
  431. return transform_name_fp (pinput, decode_xform, &type);
  432. }
  433. #define ISOCTAL(c) ((c)>='0'&&(c)<='7')
  434. /* Decode things from a file HEADER block into STAT_INFO, also setting
  435. *FORMAT_POINTER depending on the header block format. If
  436. DO_USER_GROUP, decode the user/group information (this is useful
  437. for extraction, but waste time when merely listing).
  438. read_header() has already decoded the checksum and length, so we don't.
  439. This routine should *not* be called twice for the same block, since
  440. the two calls might use different DO_USER_GROUP values and thus
  441. might end up with different uid/gid for the two calls. If anybody
  442. wants the uid/gid they should decode it first, and other callers
  443. should decode it without uid/gid before calling a routine,
  444. e.g. print_header, that assumes decoded data. */
  445. void
  446. decode_header (union block *header, struct tar_stat_info *stat_info,
  447. enum archive_format *format_pointer, int do_user_group)
  448. {
  449. enum archive_format format;
  450. if (strcmp (header->header.magic, TMAGIC) == 0)
  451. {
  452. if (header->star_header.prefix[130] == 0
  453. && ISOCTAL (header->star_header.atime[0])
  454. && header->star_header.atime[11] == ' '
  455. && ISOCTAL (header->star_header.ctime[0])
  456. && header->star_header.ctime[11] == ' ')
  457. format = STAR_FORMAT;
  458. else if (stat_info->xhdr.size)
  459. format = POSIX_FORMAT;
  460. else
  461. format = USTAR_FORMAT;
  462. }
  463. else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0)
  464. format = OLDGNU_FORMAT;
  465. else
  466. format = V7_FORMAT;
  467. *format_pointer = format;
  468. stat_info->stat.st_mode = MODE_FROM_HEADER (header->header.mode);
  469. stat_info->mtime.tv_sec = TIME_FROM_HEADER (header->header.mtime);
  470. stat_info->mtime.tv_nsec = 0;
  471. assign_string (&stat_info->uname,
  472. header->header.uname[0] ? header->header.uname : NULL);
  473. assign_string (&stat_info->gname,
  474. header->header.gname[0] ? header->header.gname : NULL);
  475. if (format == OLDGNU_FORMAT && incremental_option)
  476. {
  477. stat_info->atime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.atime);
  478. stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.ctime);
  479. stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0;
  480. }
  481. else if (format == STAR_FORMAT)
  482. {
  483. stat_info->atime.tv_sec = TIME_FROM_HEADER (header->star_header.atime);
  484. stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->star_header.ctime);
  485. stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0;
  486. }
  487. else
  488. stat_info->atime = stat_info->ctime = start_time;
  489. if (format == V7_FORMAT)
  490. {
  491. stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid);
  492. stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid);
  493. stat_info->stat.st_rdev = 0;
  494. }
  495. else
  496. {
  497. if (do_user_group)
  498. {
  499. /* FIXME: Decide if this should somewhat depend on -p. */
  500. if (numeric_owner_option
  501. || !*header->header.uname
  502. || !uname_to_uid (header->header.uname, &stat_info->stat.st_uid))
  503. stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid);
  504. if (numeric_owner_option
  505. || !*header->header.gname
  506. || !gname_to_gid (header->header.gname, &stat_info->stat.st_gid))
  507. stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid);
  508. }
  509. switch (header->header.typeflag)
  510. {
  511. case BLKTYPE:
  512. case CHRTYPE:
  513. stat_info->stat.st_rdev =
  514. makedev (MAJOR_FROM_HEADER (header->header.devmajor),
  515. MINOR_FROM_HEADER (header->header.devminor));
  516. break;
  517. default:
  518. stat_info->stat.st_rdev = 0;
  519. }
  520. }
  521. stat_info->archive_file_size = stat_info->stat.st_size;
  522. xheader_decode (stat_info);
  523. if (sparse_member_p (stat_info))
  524. {
  525. sparse_fixup_header (stat_info);
  526. stat_info->is_sparse = true;
  527. }
  528. else
  529. {
  530. stat_info->is_sparse = false;
  531. if (((current_format == GNU_FORMAT
  532. || current_format == OLDGNU_FORMAT)
  533. && current_header->header.typeflag == GNUTYPE_DUMPDIR)
  534. || stat_info->dumpdir)
  535. stat_info->is_dumpdir = true;
  536. }
  537. transform_member_name (&stat_info->file_name, xform_regfile);
  538. }
  539. /* Convert buffer at WHERE0 of size DIGS from external format to
  540. uintmax_t. DIGS must be positive. If TYPE is nonnull, the data
  541. are of type TYPE. The buffer must represent a value in the range
  542. -MINUS_MINVAL through MAXVAL. If OCTAL_ONLY, allow only octal
  543. numbers instead of the other GNU extensions. Return -1 on error,
  544. diagnosing the error if TYPE is nonnull and if !SILENT. */
  545. static uintmax_t
  546. from_header (char const *where0, size_t digs, char const *type,
  547. uintmax_t minus_minval, uintmax_t maxval,
  548. bool octal_only, bool silent)
  549. {
  550. uintmax_t value;
  551. char const *where = where0;
  552. char const *lim = where + digs;
  553. int negative = 0;
  554. /* Accommodate buggy tar of unknown vintage, which outputs leading
  555. NUL if the previous field overflows. */
  556. where += !*where;
  557. /* Accommodate older tars, which output leading spaces. */
  558. for (;;)
  559. {
  560. if (where == lim)
  561. {
  562. if (type && !silent)
  563. ERROR ((0, 0,
  564. /* TRANSLATORS: %s is type of the value (gid_t, uid_t, etc.) */
  565. _("Blanks in header where numeric %s value expected"),
  566. type));
  567. return -1;
  568. }
  569. if (!ISSPACE ((unsigned char) *where))
  570. break;
  571. where++;
  572. }
  573. value = 0;
  574. if (ISODIGIT (*where))
  575. {
  576. char const *where1 = where;
  577. uintmax_t overflow = 0;
  578. for (;;)
  579. {
  580. value += *where++ - '0';
  581. if (where == lim || ! ISODIGIT (*where))
  582. break;
  583. overflow |= value ^ (value << LG_8 >> LG_8);
  584. value <<= LG_8;
  585. }
  586. /* Parse the output of older, unportable tars, which generate
  587. negative values in two's complement octal. If the leading
  588. nonzero digit is 1, we can't recover the original value
  589. reliably; so do this only if the digit is 2 or more. This
  590. catches the common case of 32-bit negative time stamps. */
  591. if ((overflow || maxval < value) && '2' <= *where1 && type)
  592. {
  593. /* Compute the negative of the input value, assuming two's
  594. complement. */
  595. int digit = (*where1 - '0') | 4;
  596. overflow = 0;
  597. value = 0;
  598. where = where1;
  599. for (;;)
  600. {
  601. value += 7 - digit;
  602. where++;
  603. if (where == lim || ! ISODIGIT (*where))
  604. break;
  605. digit = *where - '0';
  606. overflow |= value ^ (value << LG_8 >> LG_8);
  607. value <<= LG_8;
  608. }
  609. value++;
  610. overflow |= !value;
  611. if (!overflow && value <= minus_minval)
  612. {
  613. if (!silent)
  614. WARN ((0, 0,
  615. /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
  616. _("Archive octal value %.*s is out of %s range; assuming two's complement"),
  617. (int) (where - where1), where1, type));
  618. negative = 1;
  619. }
  620. }
  621. if (overflow)
  622. {
  623. if (type && !silent)
  624. ERROR ((0, 0,
  625. /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
  626. _("Archive octal value %.*s is out of %s range"),
  627. (int) (where - where1), where1, type));
  628. return -1;
  629. }
  630. }
  631. else if (octal_only)
  632. {
  633. /* Suppress the following extensions. */
  634. }
  635. else if (*where == '-' || *where == '+')
  636. {
  637. /* Parse base-64 output produced only by tar test versions
  638. 1.13.6 (1999-08-11) through 1.13.11 (1999-08-23).
  639. Support for this will be withdrawn in future releases. */
  640. int dig;
  641. if (!silent)
  642. {
  643. static bool warned_once;
  644. if (! warned_once)
  645. {
  646. warned_once = true;
  647. WARN ((0, 0, _("Archive contains obsolescent base-64 headers")));
  648. }
  649. }
  650. negative = *where++ == '-';
  651. while (where != lim
  652. && (dig = base64_map[(unsigned char) *where]) < 64)
  653. {
  654. if (value << LG_64 >> LG_64 != value)
  655. {
  656. char *string = alloca (digs + 1);
  657. memcpy (string, where0, digs);
  658. string[digs] = '\0';
  659. if (type && !silent)
  660. ERROR ((0, 0,
  661. _("Archive signed base-64 string %s is out of %s range"),
  662. quote (string), type));
  663. return -1;
  664. }
  665. value = (value << LG_64) | dig;
  666. where++;
  667. }
  668. }
  669. else if (*where == '\200' /* positive base-256 */
  670. || *where == '\377' /* negative base-256 */)
  671. {
  672. /* Parse base-256 output. A nonnegative number N is
  673. represented as (256**DIGS)/2 + N; a negative number -N is
  674. represented as (256**DIGS) - N, i.e. as two's complement.
  675. The representation guarantees that the leading bit is
  676. always on, so that we don't confuse this format with the
  677. others (assuming ASCII bytes of 8 bits or more). */
  678. int signbit = *where & (1 << (LG_256 - 2));
  679. uintmax_t topbits = (((uintmax_t) - signbit)
  680. << (CHAR_BIT * sizeof (uintmax_t)
  681. - LG_256 - (LG_256 - 2)));
  682. value = (*where++ & ((1 << (LG_256 - 2)) - 1)) - signbit;
  683. for (;;)
  684. {
  685. value = (value << LG_256) + (unsigned char) *where++;
  686. if (where == lim)
  687. break;
  688. if (((value << LG_256 >> LG_256) | topbits) != value)
  689. {
  690. if (type && !silent)
  691. ERROR ((0, 0,
  692. _("Archive base-256 value is out of %s range"),
  693. type));
  694. return -1;
  695. }
  696. }
  697. negative = signbit;
  698. if (negative)
  699. value = -value;
  700. }
  701. if (where != lim && *where && !ISSPACE ((unsigned char) *where))
  702. {
  703. if (type)
  704. {
  705. char buf[1000]; /* Big enough to represent any header. */
  706. static struct quoting_options *o;
  707. if (!o)
  708. {
  709. o = clone_quoting_options (0);
  710. set_quoting_style (o, locale_quoting_style);
  711. }
  712. while (where0 != lim && ! lim[-1])
  713. lim--;
  714. quotearg_buffer (buf, sizeof buf, where0, lim - where, o);
  715. if (!silent)
  716. ERROR ((0, 0,
  717. /* TRANSLATORS: Second %s is a type name (gid_t,uid_t,etc.) */
  718. _("Archive contains %.*s where numeric %s value expected"),
  719. (int) sizeof buf, buf, type));
  720. }
  721. return -1;
  722. }
  723. if (value <= (negative ? minus_minval : maxval))
  724. return negative ? -value : value;
  725. if (type && !silent)
  726. {
  727. char minval_buf[UINTMAX_STRSIZE_BOUND + 1];
  728. char maxval_buf[UINTMAX_STRSIZE_BOUND];
  729. char value_buf[UINTMAX_STRSIZE_BOUND + 1];
  730. char *minval_string = STRINGIFY_BIGINT (minus_minval, minval_buf + 1);
  731. char *value_string = STRINGIFY_BIGINT (value, value_buf + 1);
  732. if (negative)
  733. *--value_string = '-';
  734. if (minus_minval)
  735. *--minval_string = '-';
  736. /* TRANSLATORS: Second %s is type name (gid_t,uid_t,etc.) */
  737. ERROR ((0, 0, _("Archive value %s is out of %s range %s..%s"),
  738. value_string, type,
  739. minval_string, STRINGIFY_BIGINT (maxval, maxval_buf)));
  740. }
  741. return -1;
  742. }
  743. gid_t
  744. gid_from_header (const char *p, size_t s)
  745. {
  746. return from_header (p, s, "gid_t",
  747. - (uintmax_t) TYPE_MINIMUM (gid_t),
  748. (uintmax_t) TYPE_MAXIMUM (gid_t),
  749. false, false);
  750. }
  751. major_t
  752. major_from_header (const char *p, size_t s)
  753. {
  754. return from_header (p, s, "major_t",
  755. - (uintmax_t) TYPE_MINIMUM (major_t),
  756. (uintmax_t) TYPE_MAXIMUM (major_t), false, false);
  757. }
  758. minor_t
  759. minor_from_header (const char *p, size_t s)
  760. {
  761. return from_header (p, s, "minor_t",
  762. - (uintmax_t) TYPE_MINIMUM (minor_t),
  763. (uintmax_t) TYPE_MAXIMUM (minor_t), false, false);
  764. }
  765. mode_t
  766. mode_from_header (const char *p, size_t s)
  767. {
  768. /* Do not complain about unrecognized mode bits. */
  769. unsigned u = from_header (p, s, "mode_t",
  770. - (uintmax_t) TYPE_MINIMUM (mode_t),
  771. TYPE_MAXIMUM (uintmax_t), false, false);
  772. return ((u & TSUID ? S_ISUID : 0)
  773. | (u & TSGID ? S_ISGID : 0)
  774. | (u & TSVTX ? S_ISVTX : 0)
  775. | (u & TUREAD ? S_IRUSR : 0)
  776. | (u & TUWRITE ? S_IWUSR : 0)
  777. | (u & TUEXEC ? S_IXUSR : 0)
  778. | (u & TGREAD ? S_IRGRP : 0)
  779. | (u & TGWRITE ? S_IWGRP : 0)
  780. | (u & TGEXEC ? S_IXGRP : 0)
  781. | (u & TOREAD ? S_IROTH : 0)
  782. | (u & TOWRITE ? S_IWOTH : 0)
  783. | (u & TOEXEC ? S_IXOTH : 0));
  784. }
  785. off_t
  786. off_from_header (const char *p, size_t s)
  787. {
  788. /* Negative offsets are not allowed in tar files, so invoke
  789. from_header with minimum value 0, not TYPE_MINIMUM (off_t). */
  790. return from_header (p, s, "off_t", (uintmax_t) 0,
  791. (uintmax_t) TYPE_MAXIMUM (off_t), false, false);
  792. }
  793. size_t
  794. size_from_header (const char *p, size_t s)
  795. {
  796. return from_header (p, s, "size_t", (uintmax_t) 0,
  797. (uintmax_t) TYPE_MAXIMUM (size_t), false, false);
  798. }
  799. time_t
  800. time_from_header (const char *p, size_t s)
  801. {
  802. return from_header (p, s, "time_t",
  803. - (uintmax_t) TYPE_MINIMUM (time_t),
  804. (uintmax_t) TYPE_MAXIMUM (time_t), false, false);
  805. }
  806. uid_t
  807. uid_from_header (const char *p, size_t s)
  808. {
  809. return from_header (p, s, "uid_t",
  810. - (uintmax_t) TYPE_MINIMUM (uid_t),
  811. (uintmax_t) TYPE_MAXIMUM (uid_t), false, false);
  812. }
  813. uintmax_t
  814. uintmax_from_header (const char *p, size_t s)
  815. {
  816. return from_header (p, s, "uintmax_t", (uintmax_t) 0,
  817. TYPE_MAXIMUM (uintmax_t), false, false);
  818. }
  819. /* Return a printable representation of T. The result points to
  820. static storage that can be reused in the next call to this
  821. function, to ctime, or to asctime. If FULL_TIME, then output the
  822. time stamp to its full resolution; otherwise, just output it to
  823. 1-minute resolution. */
  824. char const *
  825. tartime (struct timespec t, bool full_time)
  826. {
  827. enum { fraclen = sizeof ".FFFFFFFFF" - 1 };
  828. static char buffer[max (UINTMAX_STRSIZE_BOUND + 1,
  829. INT_STRLEN_BOUND (int) + 16)
  830. + fraclen];
  831. struct tm *tm;
  832. time_t s = t.tv_sec;
  833. int ns = t.tv_nsec;
  834. bool negative = s < 0;
  835. char *p;
  836. if (negative && ns != 0)
  837. {
  838. s++;
  839. ns = 1000000000 - ns;
  840. }
  841. tm = utc_option ? gmtime (&s) : localtime (&s);
  842. if (tm)
  843. {
  844. if (full_time)
  845. {
  846. sprintf (buffer, "%04ld-%02d-%02d %02d:%02d:%02d",
  847. tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
  848. tm->tm_hour, tm->tm_min, tm->tm_sec);
  849. code_ns_fraction (ns, buffer + strlen (buffer));
  850. }
  851. else
  852. sprintf (buffer, "%04ld-%02d-%02d %02d:%02d",
  853. tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
  854. tm->tm_hour, tm->tm_min);
  855. return buffer;
  856. }
  857. /* The time stamp cannot be broken down, most likely because it
  858. is out of range. Convert it as an integer,
  859. right-adjusted in a field with the same width as the usual
  860. 4-year ISO time format. */
  861. p = umaxtostr (negative ? - (uintmax_t) s : s,
  862. buffer + sizeof buffer - UINTMAX_STRSIZE_BOUND - fraclen);
  863. if (negative)
  864. *--p = '-';
  865. while ((buffer + sizeof buffer - sizeof "YYYY-MM-DD HH:MM"
  866. + (full_time ? sizeof ":SS.FFFFFFFFF" - 1 : 0))
  867. < p)
  868. *--p = ' ';
  869. if (full_time)
  870. code_ns_fraction (ns, buffer + sizeof buffer - 1 - fraclen);
  871. return p;
  872. }
  873. /* Actually print it.
  874. Plain and fancy file header block logging. Non-verbose just prints
  875. the name, e.g. for "tar t" or "tar x". This should just contain
  876. file names, so it can be fed back into tar with xargs or the "-T"
  877. option. The verbose option can give a bunch of info, one line per
  878. file. I doubt anybody tries to parse its format, or if they do,
  879. they shouldn't. Unix tar is pretty random here anyway. */
  880. /* FIXME: Note that print_header uses the globals HEAD, HSTAT, and
  881. HEAD_STANDARD, which must be set up in advance. Not very clean.. */
  882. /* Width of "user/group size", with initial value chosen
  883. heuristically. This grows as needed, though this may cause some
  884. stairstepping in the output. Make it too small and the output will
  885. almost always look ragged. Make it too large and the output will
  886. be spaced out too far. */
  887. static int ugswidth = 19;
  888. /* Width of printed time stamps. It grows if longer time stamps are
  889. found (typically, those with nanosecond resolution). Like
  890. USGWIDTH, some stairstepping may occur. */
  891. static int datewidth = sizeof "YYYY-MM-DD HH:MM" - 1;
  892. void
  893. print_header (struct tar_stat_info *st, off_t block_ordinal)
  894. {
  895. char modes[11];
  896. char const *time_stamp;
  897. int time_stamp_len;
  898. char *temp_name;
  899. /* These hold formatted ints. */
  900. char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND];
  901. char *user, *group;
  902. char size[2 * UINTMAX_STRSIZE_BOUND];
  903. /* holds formatted size or major,minor */
  904. char uintbuf[UINTMAX_STRSIZE_BOUND];
  905. int pad;
  906. int sizelen;
  907. if (test_label_option && current_header->header.typeflag != GNUTYPE_VOLHDR)
  908. return;
  909. if (show_transformed_names_option)
  910. temp_name = st->file_name ? st->file_name : st->orig_file_name;
  911. else
  912. temp_name = st->orig_file_name ? st->orig_file_name : st->file_name;
  913. if (block_number_option)
  914. {
  915. char buf[UINTMAX_STRSIZE_BOUND];
  916. if (block_ordinal < 0)
  917. block_ordinal = current_block_ordinal ();
  918. block_ordinal -= recent_long_name_blocks;
  919. block_ordinal -= recent_long_link_blocks;
  920. fprintf (stdlis, _("block %s: "),
  921. STRINGIFY_BIGINT (block_ordinal, buf));
  922. }
  923. if (verbose_option <= 1)
  924. {
  925. /* Just the fax, mam. */
  926. fprintf (stdlis, "%s\n", quotearg (temp_name));
  927. }
  928. else
  929. {
  930. /* File type and modes. */
  931. modes[0] = '?';
  932. switch (current_header->header.typeflag)
  933. {
  934. case GNUTYPE_VOLHDR:
  935. modes[0] = 'V';
  936. break;
  937. case GNUTYPE_MULTIVOL:
  938. modes[0] = 'M';
  939. break;
  940. case GNUTYPE_LONGNAME:
  941. case GNUTYPE_LONGLINK:
  942. modes[0] = 'L';
  943. ERROR ((0, 0, _("Unexpected long name header")));
  944. break;
  945. case GNUTYPE_SPARSE:
  946. case REGTYPE:
  947. case AREGTYPE:
  948. modes[0] = '-';
  949. if (temp_name[strlen (temp_name) - 1] == '/')
  950. modes[0] = 'd';
  951. break;
  952. case LNKTYPE:
  953. modes[0] = 'h';
  954. break;
  955. case GNUTYPE_DUMPDIR:
  956. modes[0] = 'd';
  957. break;
  958. case DIRTYPE:
  959. modes[0] = 'd';
  960. break;
  961. case SYMTYPE:
  962. modes[0] = 'l';
  963. break;
  964. case BLKTYPE:
  965. modes[0] = 'b';
  966. break;
  967. case CHRTYPE:
  968. modes[0] = 'c';
  969. break;
  970. case FIFOTYPE:
  971. modes[0] = 'p';
  972. break;
  973. case CONTTYPE:
  974. modes[0] = 'C';
  975. break;
  976. }
  977. pax_decode_mode (st->stat.st_mode, modes + 1);
  978. /* Time stamp. */
  979. time_stamp = tartime (st->mtime, false);
  980. time_stamp_len = strlen (time_stamp);
  981. if (datewidth < time_stamp_len)
  982. datewidth = time_stamp_len;
  983. /* User and group names. */
  984. if (st->uname
  985. && st->uname[0]
  986. && current_format != V7_FORMAT
  987. && !numeric_owner_option)
  988. user = st->uname;
  989. else
  990. {
  991. /* Try parsing it as an unsigned integer first, and as a
  992. uid_t if that fails. This method can list positive user
  993. ids that are too large to fit in a uid_t. */
  994. uintmax_t u = from_header (current_header->header.uid,
  995. sizeof current_header->header.uid, 0,
  996. (uintmax_t) 0,
  997. (uintmax_t) TYPE_MAXIMUM (uintmax_t),
  998. false, false);
  999. if (u != -1)
  1000. user = STRINGIFY_BIGINT (u, uform);
  1001. else
  1002. {
  1003. sprintf (uform, "%ld",
  1004. (long) UID_FROM_HEADER (current_header->header.uid));
  1005. user = uform;
  1006. }
  1007. }
  1008. if (st->gname
  1009. && st->gname[0]
  1010. && current_format != V7_FORMAT
  1011. && !numeric_owner_option)
  1012. group = st->gname;
  1013. else
  1014. {
  1015. /* Try parsing it as an unsigned integer first, and as a
  1016. gid_t if that fails. This method can list positive group
  1017. ids that are too large to fit in a gid_t. */
  1018. uintmax_t g = from_header (current_header->header.gid,
  1019. sizeof current_header->header.gid, 0,
  1020. (uintmax_t) 0,
  1021. (uintmax_t) TYPE_MAXIMUM (uintmax_t),
  1022. false, false);
  1023. if (g != -1)
  1024. group = STRINGIFY_BIGINT (g, gform);
  1025. else
  1026. {
  1027. sprintf (gform, "%ld",
  1028. (long) GID_FROM_HEADER (current_header->header.gid));
  1029. group = gform;
  1030. }
  1031. }
  1032. /* Format the file size or major/minor device numbers. */
  1033. switch (current_header->header.typeflag)
  1034. {
  1035. case CHRTYPE:
  1036. case BLKTYPE:
  1037. strcpy (size,
  1038. STRINGIFY_BIGINT (major (st->stat.st_rdev), uintbuf));
  1039. strcat (size, ",");
  1040. strcat (size,
  1041. STRINGIFY_BIGINT (minor (st->stat.st_rdev), uintbuf));
  1042. break;
  1043. default:
  1044. /* st->stat.st_size keeps stored file size */
  1045. strcpy (size, STRINGIFY_BIGINT (st->stat.st_size, uintbuf));
  1046. break;
  1047. }
  1048. /* Figure out padding and print the whole line. */
  1049. sizelen = strlen (size);
  1050. pad = strlen (user) + 1 + strlen (group) + 1 + sizelen;
  1051. if (pad > ugswidth)
  1052. ugswidth = pad;
  1053. fprintf (stdlis, "%s %s/%s %*s %-*s",
  1054. modes, user, group, ugswidth - pad + sizelen, size,
  1055. datewidth, time_stamp);
  1056. fprintf (stdlis, " %s", quotearg (temp_name));
  1057. switch (current_header->header.typeflag)
  1058. {
  1059. case SYMTYPE:
  1060. fprintf (stdlis, " -> %s\n", quotearg (st->link_name));
  1061. break;
  1062. case LNKTYPE:
  1063. fprintf (stdlis, _(" link to %s\n"), quotearg (st->link_name));
  1064. break;
  1065. default:
  1066. {
  1067. char type_string[2];
  1068. type_string[0] = current_header->header.typeflag;
  1069. type_string[1] = '\0';
  1070. fprintf (stdlis, _(" unknown file type %s\n"),
  1071. quote (type_string));
  1072. }
  1073. break;
  1074. case AREGTYPE:
  1075. case REGTYPE:
  1076. case GNUTYPE_SPARSE:
  1077. case CHRTYPE:
  1078. case BLKTYPE:
  1079. case DIRTYPE:
  1080. case FIFOTYPE:
  1081. case CONTTYPE:
  1082. case GNUTYPE_DUMPDIR:
  1083. putc ('\n', stdlis);
  1084. break;
  1085. case GNUTYPE_LONGLINK:
  1086. fprintf (stdlis, _("--Long Link--\n"));
  1087. break;
  1088. case GNUTYPE_LONGNAME:
  1089. fprintf (stdlis, _("--Long Name--\n"));
  1090. break;
  1091. case GNUTYPE_VOLHDR:
  1092. fprintf (stdlis, _("--Volume Header--\n"));
  1093. break;
  1094. case GNUTYPE_MULTIVOL:
  1095. strcpy (size,
  1096. STRINGIFY_BIGINT
  1097. (UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset),
  1098. uintbuf));
  1099. fprintf (stdlis, _("--Continued at byte %s--\n"), size);
  1100. break;
  1101. }
  1102. }
  1103. fflush (stdlis);
  1104. }
  1105. /* Print a similar line when we make a directory automatically. */
  1106. void
  1107. print_for_mkdir (char *dirname, int length, mode_t mode)
  1108. {
  1109. char modes[11];
  1110. if (verbose_option > 1)
  1111. {
  1112. /* File type and modes. */
  1113. modes[0] = 'd';
  1114. pax_decode_mode (mode, modes + 1);
  1115. if (block_number_option)
  1116. {
  1117. char buf[UINTMAX_STRSIZE_BOUND];
  1118. fprintf (stdlis, _("block %s: "),
  1119. STRINGIFY_BIGINT (current_block_ordinal (), buf));
  1120. }
  1121. fprintf (stdlis, "%s %*s %.*s\n", modes, ugswidth + 1 + datewidth,
  1122. _("Creating directory:"), length, quotearg (dirname));
  1123. }
  1124. }
  1125. /* Skip over SIZE bytes of data in blocks in the archive. */
  1126. void
  1127. skip_file (off_t size)
  1128. {
  1129. union block *x;
  1130. /* FIXME: Make sure mv_begin is always called before it */
  1131. if (seekable_archive)
  1132. {
  1133. off_t nblk = seek_archive (size);
  1134. if (nblk >= 0)
  1135. size -= nblk * BLOCKSIZE;
  1136. else
  1137. seekable_archive = false;
  1138. }
  1139. mv_size_left (size);
  1140. while (size > 0)
  1141. {
  1142. x = find_next_block ();
  1143. if (! x)
  1144. FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
  1145. set_next_block_after (x);
  1146. size -= BLOCKSIZE;
  1147. mv_size_left (size);
  1148. }
  1149. }
  1150. /* Skip the current member in the archive.
  1151. NOTE: Current header must be decoded before calling this function. */
  1152. void
  1153. skip_member (void)
  1154. {
  1155. if (!current_stat_info.skipped)
  1156. {
  1157. char save_typeflag = current_header->header.typeflag;
  1158. set_next_block_after (current_header);
  1159. mv_begin (&current_stat_info);
  1160. if (current_stat_info.is_sparse)
  1161. sparse_skip_file (&current_stat_info);
  1162. else if (save_typeflag != DIRTYPE)
  1163. skip_file (current_stat_info.stat.st_size);
  1164. mv_end ();
  1165. }
  1166. }