list.c 36 KB

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