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