1 /* List a tar archive, with support routines for reading a tar archive.
3 Copyright 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000,
4 2001 Free Software Foundation, Inc.
6 Written by John Gilmore, on 1985-08-26.
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any later
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* $FreeBSD: src/contrib/tar/src/list.c,v 1.2.2.1 2002/07/14 13:19:44 sobomax Exp $ */
24 /* Define to non-zero for forcing old ctime format instead of ISO format. */
29 #ifdef HAVE_LANGINFO_CODESET
35 #define max(a, b) ((a) < (b) ? (b) : (a))
37 union block *current_header; /* points to current archive header */
38 struct stat current_stat; /* stat struct corresponding */
39 enum archive_format current_format; /* recognized format */
40 union block *recent_long_name; /* recent long name header and contents */
41 union block *recent_long_link; /* likewise, for long link */
42 size_t recent_long_name_blocks; /* number of blocks in recent_long_name */
43 size_t recent_long_link_blocks; /* likewise, for long link */
45 static uintmax_t from_header PARAMS ((const char *, size_t, const char *,
46 uintmax_t, uintmax_t));
48 /* Base 64 digits; see Internet RFC 2045 Table 1. */
49 static char const base_64_digits[64] =
51 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
52 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
53 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
54 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
55 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
58 /* Table of base-64 digit values indexed by unsigned chars.
59 The value is 64 for unsigned chars that are not base-64 digits. */
60 static char base64_map[UCHAR_MAX + 1];
66 memset (base64_map, 64, sizeof base64_map);
67 for (i = 0; i < 64; i++)
68 base64_map[(int) base_64_digits[i]] = i;
71 /* Main loop for reading an archive. */
73 read_and (void (*do_something) ())
75 enum read_header status = HEADER_STILL_UNREAD;
76 enum read_header prev_status;
80 open_archive (ACCESS_READ);
85 status = read_header (0);
86 /* check if the namelist got emptied during the course of reading */
87 /* the tape, if so stop by setting status to EOF */
89 status = HEADER_END_OF_FILE;
92 case HEADER_STILL_UNREAD:
97 /* Valid header. We should decode next field (mode) first.
98 Ensure incoming names are null terminated. */
100 if (! name_match (current_file_name)
101 || (newer_mtime_option != TYPE_MINIMUM (time_t)
102 /* FIXME: We get mtime now, and again later; this causes
103 duplicate diagnostics if header.mtime is bogus. */
104 && ((current_stat.st_mtime
105 = TIME_FROM_HEADER (current_header->header.mtime))
106 < newer_mtime_option))
107 || excluded_name (current_file_name))
109 switch (current_header->header.typeflag)
112 case GNUTYPE_MULTIVOL:
117 if (show_omitted_dirs_option)
118 WARN ((0, 0, _("%s: Omitting"),
119 quotearg_colon (current_file_name)));
130 case HEADER_ZERO_BLOCK:
131 if (block_number_option)
133 char buf[UINTMAX_STRSIZE_BOUND];
134 fprintf (stdlis, _("block %s: ** Block of NULs **\n"),
135 STRINGIFY_BIGINT (current_block_ordinal (), buf));
138 set_next_block_after (current_header);
139 status = prev_status;
140 if (ignore_zeros_option)
144 case HEADER_END_OF_FILE:
145 if (block_number_option)
147 char buf[UINTMAX_STRSIZE_BOUND];
148 fprintf (stdlis, _("block %s: ** End of File **\n"),
149 STRINGIFY_BIGINT (current_block_ordinal (), buf));
154 /* If the previous header was good, tell them that we are
155 skipping bad ones. */
156 set_next_block_after (current_header);
159 case HEADER_STILL_UNREAD:
160 ERROR ((0, 0, _("This does not look like a tar archive")));
163 case HEADER_ZERO_BLOCK:
165 ERROR ((0, 0, _("Skipping to next header")));
168 case HEADER_END_OF_FILE:
170 /* We are in the middle of a cascade of errors. */
179 names_notfound (); /* print names not found */
182 /* Print a header block, based on tar options. */
186 /* Print the header block. */
190 if (verbose_option > 1)
191 decode_header (current_header, ¤t_stat, ¤t_format, 0);
195 if (incremental_option && current_header->header.typeflag == GNUTYPE_DUMPDIR)
198 size_t written, check;
199 union block *data_block;
201 set_next_block_after (current_header);
202 if (multi_volume_option)
204 assign_string (&save_name, current_file_name);
205 save_totsize = current_stat.st_size;
207 for (size = current_stat.st_size; size > 0; size -= written)
209 if (multi_volume_option)
210 save_sizeleft = size;
211 data_block = find_next_block ();
214 ERROR ((0, 0, _("Unexpected EOF in archive")));
215 break; /* FIXME: What happens, then? */
217 written = available_space_after (data_block);
221 check = fwrite (data_block->buffer, sizeof (char), written, stdlis);
222 set_next_block_after ((union block *)
223 (data_block->buffer + written - 1));
224 if (check != written)
226 write_error_details (current_file_name, check, written);
227 skip_file (size - written);
231 if (multi_volume_option)
232 assign_string (&save_name, 0);
233 fputc ('\n', stdlis);
239 if (multi_volume_option)
240 assign_string (&save_name, current_file_name);
244 if (multi_volume_option)
245 assign_string (&save_name, 0);
248 /* Read a block that's supposed to be a header block. Return its
249 address in "current_header", and if it is good, the file's size in
250 current_stat.st_size.
252 Return 1 for success, 0 if the checksum is bad, EOF on eof, 2 for a
253 block full of zeros (EOF marker).
255 If RAW_EXTENDED_HEADERS is nonzero, do not automagically fold the
256 GNU long name and link headers into later headers.
258 You must always set_next_block_after(current_header) to skip past
259 the header which this routine reads. */
261 /* The standard BSD tar sources create the checksum by adding up the
262 bytes in the header as type char. I think the type char was unsigned
263 on the PDP-11, but it's signed on the Next and Sun. It looks like the
264 sources to BSD tar were never changed to compute the checksum
265 correctly, so both the Sun and Next add the bytes of the header as
266 signed chars. This doesn't cause a problem until you get a file with
267 a name containing characters with the high bit set. So read_header
268 computes two checksums -- signed and unsigned. */
271 read_header (bool raw_extended_headers)
274 int unsigned_sum; /* the POSIX one :-) */
275 int signed_sum; /* the Sun one :-( */
277 uintmax_t parsed_sum;
280 union block *header_copy;
282 union block *data_block;
283 size_t size, written;
284 union block *next_long_name = 0;
285 union block *next_long_link = 0;
286 size_t next_long_name_blocks;
287 size_t next_long_link_blocks;
291 header = find_next_block ();
292 current_header = header;
294 return HEADER_END_OF_FILE;
299 for (i = sizeof *header; i-- != 0;)
301 unsigned_sum += (unsigned char) *p;
302 signed_sum += (signed char) (*p++);
305 if (unsigned_sum == 0)
306 return HEADER_ZERO_BLOCK;
308 /* Adjust checksum to count the "chksum" field as blanks. */
310 for (i = sizeof header->header.chksum; i-- != 0;)
312 unsigned_sum -= (unsigned char) header->header.chksum[i];
313 signed_sum -= (signed char) (header->header.chksum[i]);
315 unsigned_sum += ' ' * sizeof header->header.chksum;
316 signed_sum += ' ' * sizeof header->header.chksum;
318 parsed_sum = from_header (header->header.chksum,
319 sizeof header->header.chksum, 0,
321 (uintmax_t) TYPE_MAXIMUM (int));
322 if (parsed_sum == (uintmax_t) -1)
323 return HEADER_FAILURE;
325 recorded_sum = parsed_sum;
327 if (unsigned_sum != recorded_sum && signed_sum != recorded_sum)
328 return HEADER_FAILURE;
330 /* Good block. Decode file size and return. */
332 if (header->header.typeflag == LNKTYPE)
333 current_stat.st_size = 0; /* links 0 size on tape */
335 current_stat.st_size = OFF_FROM_HEADER (header->header.size);
337 if (header->header.typeflag == GNUTYPE_LONGNAME
338 || header->header.typeflag == GNUTYPE_LONGLINK)
340 if (raw_extended_headers)
341 return HEADER_SUCCESS_EXTENDED;
344 size_t name_size = current_stat.st_size;
345 size = name_size - name_size % BLOCKSIZE + 2 * BLOCKSIZE;
346 if (name_size != current_stat.st_size || size < name_size)
350 header_copy = xmalloc (size + 1);
352 if (header->header.typeflag == GNUTYPE_LONGNAME)
355 free (next_long_name);
356 next_long_name = header_copy;
357 next_long_name_blocks = size / BLOCKSIZE;
362 free (next_long_link);
363 next_long_link = header_copy;
364 next_long_link_blocks = size / BLOCKSIZE;
367 set_next_block_after (header);
368 *header_copy = *header;
369 bp = header_copy->buffer + BLOCKSIZE;
371 for (size -= BLOCKSIZE; size > 0; size -= written)
373 data_block = find_next_block ();
376 ERROR ((0, 0, _("Unexpected EOF in archive")));
379 written = available_space_after (data_block);
383 memcpy (bp, data_block->buffer, written);
385 set_next_block_after ((union block *)
386 (data_block->buffer + written - 1));
397 struct posix_header const *h = ¤t_header->header;
398 char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
400 if (recent_long_name)
401 free (recent_long_name);
405 name = next_long_name->buffer + BLOCKSIZE;
406 recent_long_name = next_long_name;
407 recent_long_name_blocks = next_long_name_blocks;
411 /* Accept file names as specified by POSIX.1-1996
415 if (h->prefix[0] && strcmp (h->magic, TMAGIC) == 0)
417 memcpy (np, h->prefix, sizeof h->prefix);
418 np[sizeof h->prefix] = '\0';
422 /* Prevent later references to current_header from
423 mistakenly treating this as an old GNU header.
424 This assignment invalidates h->prefix. */
425 current_header->oldgnu_header.isextended = 0;
427 memcpy (np, h->name, sizeof h->name);
428 np[sizeof h->name] = '\0';
430 recent_long_name = 0;
431 recent_long_name_blocks = 0;
433 assign_string (¤t_file_name, name);
435 if (recent_long_link)
436 free (recent_long_link);
440 name = next_long_link->buffer + BLOCKSIZE;
441 recent_long_link = next_long_link;
442 recent_long_link_blocks = next_long_link_blocks;
446 memcpy (namebuf, h->linkname, sizeof h->linkname);
447 namebuf[sizeof h->linkname] = '\0';
449 recent_long_link = 0;
450 recent_long_link_blocks = 0;
452 assign_string (¤t_link_name, name);
454 return HEADER_SUCCESS;
459 /* Decode things from a file HEADER block into STAT_INFO, also setting
460 *FORMAT_POINTER depending on the header block format. If
461 DO_USER_GROUP, decode the user/group information (this is useful
462 for extraction, but waste time when merely listing).
464 read_header() has already decoded the checksum and length, so we don't.
466 This routine should *not* be called twice for the same block, since
467 the two calls might use different DO_USER_GROUP values and thus
468 might end up with different uid/gid for the two calls. If anybody
469 wants the uid/gid they should decode it first, and other callers
470 should decode it without uid/gid before calling a routine,
471 e.g. print_header, that assumes decoded data. */
473 decode_header (union block *header, struct stat *stat_info,
474 enum archive_format *format_pointer, int do_user_group)
476 enum archive_format format;
478 if (strcmp (header->header.magic, TMAGIC) == 0)
479 format = POSIX_FORMAT;
480 else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0)
481 format = OLDGNU_FORMAT;
484 *format_pointer = format;
486 stat_info->st_mode = MODE_FROM_HEADER (header->header.mode);
487 stat_info->st_mtime = TIME_FROM_HEADER (header->header.mtime);
489 if (format == OLDGNU_FORMAT && incremental_option)
491 stat_info->st_atime = TIME_FROM_HEADER (header->oldgnu_header.atime);
492 stat_info->st_ctime = TIME_FROM_HEADER (header->oldgnu_header.ctime);
495 if (format == V7_FORMAT)
497 stat_info->st_uid = UID_FROM_HEADER (header->header.uid);
498 stat_info->st_gid = GID_FROM_HEADER (header->header.gid);
499 stat_info->st_rdev = 0;
505 /* FIXME: Decide if this should somewhat depend on -p. */
507 if (numeric_owner_option
508 || !*header->header.uname
509 || !uname_to_uid (header->header.uname, &stat_info->st_uid))
510 stat_info->st_uid = UID_FROM_HEADER (header->header.uid);
512 if (numeric_owner_option
513 || !*header->header.gname
514 || !gname_to_gid (header->header.gname, &stat_info->st_gid))
515 stat_info->st_gid = GID_FROM_HEADER (header->header.gid);
517 switch (header->header.typeflag)
521 = makedev (MAJOR_FROM_HEADER (header->header.devmajor),
522 MINOR_FROM_HEADER (header->header.devminor));
527 = makedev (MAJOR_FROM_HEADER (header->header.devmajor),
528 MINOR_FROM_HEADER (header->header.devminor));
532 stat_info->st_rdev = 0;
537 /* Convert buffer at WHERE0 of size DIGS from external format to
538 uintmax_t. The data is of type TYPE. The buffer must represent a
539 value in the range -MINUS_MINVAL through MAXVAL. DIGS must be
540 positive. Return -1 on error, diagnosing the error if TYPE is
543 from_header (char const *where0, size_t digs, char const *type,
544 uintmax_t minus_minval, uintmax_t maxval)
547 char const *where = where0;
548 char const *lim = where + digs;
551 /* Accommodate buggy tar of unknown vintage, which outputs leading
552 NUL if the previous field overflows. */
555 /* Accommodate older tars, which output leading spaces. */
562 _("Blanks in header where numeric %s value expected"),
566 if (!ISSPACE ((unsigned char) *where))
572 if (ISODIGIT (*where))
574 char const *where1 = where;
575 uintmax_t overflow = 0;
579 value += *where++ - '0';
580 if (where == lim || ! ISODIGIT (*where))
582 overflow |= value ^ (value << LG_8 >> LG_8);
586 /* Parse the output of older, unportable tars, which generate
587 negative values in two's complement octal. If the leading
588 nonzero digit is 1, we can't recover the original value
589 reliably; so do this only if the digit is 2 or more. This
590 catches the common case of 32-bit negative time stamps. */
591 if ((overflow || maxval < value) && '2' <= *where1 && type)
593 /* Compute the negative of the input value, assuming two's
595 int digit = (*where1 - '0') | 4;
603 if (where == lim || ! ISODIGIT (*where))
605 digit = *where - '0';
606 overflow |= value ^ (value << LG_8 >> LG_8);
612 if (!overflow && value <= minus_minval)
615 _("Archive octal value %.*s is out of %s range; assuming two's complement"),
616 (int) (where - where1), where1, type));
625 _("Archive octal value %.*s is out of %s range"),
626 (int) (where - where1), where1, type));
630 else if (*where == '-' || *where == '+')
632 /* Parse base-64 output produced only by tar test versions
633 1.13.6 (1999-08-11) through 1.13.11 (1999-08-23).
634 Support for this will be withdrawn in future releases. */
636 static int warned_once;
641 _("Archive contains obsolescent base-64 headers")));
643 negative = *where++ == '-';
645 && (dig = base64_map[(unsigned char) *where]) < 64)
647 if (value << LG_64 >> LG_64 != value)
649 char *string = alloca (digs + 1);
650 memcpy (string, where0, digs);
654 _("Archive signed base-64 string %s is out of %s range"),
655 quote (string), type));
658 value = (value << LG_64) | dig;
662 else if (*where == '\200' /* positive base-256 */
663 || *where == '\377' /* negative base-256 */)
665 /* Parse base-256 output. A nonnegative number N is
666 represented as (256**DIGS)/2 + N; a negative number -N is
667 represented as (256**DIGS) - N, i.e. as two's complement.
668 The representation guarantees that the leading bit is
669 always on, so that we don't confuse this format with the
670 others (assuming ASCII bytes of 8 bits or more). */
671 int signbit = *where & (1 << (LG_256 - 2));
672 uintmax_t topbits = (((uintmax_t) - signbit)
673 << (CHAR_BIT * sizeof (uintmax_t)
674 - LG_256 - (LG_256 - 2)));
675 value = (*where++ & ((1 << (LG_256 - 2)) - 1)) - signbit;
678 value = (value << LG_256) + (unsigned char) *where++;
681 if (((value << LG_256 >> LG_256) | topbits) != value)
685 _("Archive base-256 value is out of %s range"),
695 if (where != lim && *where && !ISSPACE ((unsigned char) *where))
699 char buf[1000]; /* Big enough to represent any header. */
700 static struct quoting_options *o;
704 o = clone_quoting_options (0);
705 set_quoting_style (o, locale_quoting_style);
708 while (where0 != lim && ! lim[-1])
710 quotearg_buffer (buf, sizeof buf, where0, lim - where, o);
712 _("Archive contains %.*s where numeric %s value expected"),
713 (int) sizeof buf, buf, type));
719 if (value <= (negative ? minus_minval : maxval))
720 return negative ? -value : value;
724 char minval_buf[UINTMAX_STRSIZE_BOUND + 1];
725 char maxval_buf[UINTMAX_STRSIZE_BOUND];
726 char value_buf[UINTMAX_STRSIZE_BOUND + 1];
727 char *minval_string = STRINGIFY_BIGINT (minus_minval, minval_buf + 1);
728 char *value_string = STRINGIFY_BIGINT (value, value_buf + 1);
730 *--value_string = '-';
732 *--minval_string = '-';
733 ERROR ((0, 0, _("Archive value %s is out of %s range %s..%s"),
735 minval_string, STRINGIFY_BIGINT (maxval, maxval_buf)));
742 gid_from_header (const char *p, size_t s)
744 return from_header (p, s, "gid_t",
745 - (uintmax_t) TYPE_MINIMUM (gid_t),
746 (uintmax_t) TYPE_MAXIMUM (gid_t));
750 major_from_header (const char *p, size_t s)
752 return from_header (p, s, "major_t",
753 - (uintmax_t) TYPE_MINIMUM (major_t),
754 (uintmax_t) TYPE_MAXIMUM (major_t));
758 minor_from_header (const char *p, size_t s)
760 return from_header (p, s, "minor_t",
761 - (uintmax_t) TYPE_MINIMUM (minor_t),
762 (uintmax_t) TYPE_MAXIMUM (minor_t));
766 mode_from_header (const char *p, size_t s)
768 /* Do not complain about unrecognized mode bits. */
769 unsigned u = from_header (p, s, "mode_t",
770 - (uintmax_t) TYPE_MINIMUM (mode_t),
771 TYPE_MAXIMUM (uintmax_t));
772 return ((u & TSUID ? S_ISUID : 0)
773 | (u & TSGID ? S_ISGID : 0)
774 | (u & TSVTX ? S_ISVTX : 0)
775 | (u & TUREAD ? S_IRUSR : 0)
776 | (u & TUWRITE ? S_IWUSR : 0)
777 | (u & TUEXEC ? S_IXUSR : 0)
778 | (u & TGREAD ? S_IRGRP : 0)
779 | (u & TGWRITE ? S_IWGRP : 0)
780 | (u & TGEXEC ? S_IXGRP : 0)
781 | (u & TOREAD ? S_IROTH : 0)
782 | (u & TOWRITE ? S_IWOTH : 0)
783 | (u & TOEXEC ? S_IXOTH : 0));
787 off_from_header (const char *p, size_t s)
789 /* Negative offsets are not allowed in tar files, so invoke
790 from_header with minimum value 0, not TYPE_MINIMUM (off_t). */
791 return from_header (p, s, "off_t", (uintmax_t) 0,
792 (uintmax_t) TYPE_MAXIMUM (off_t));
796 size_from_header (const char *p, size_t s)
798 return from_header (p, s, "size_t", (uintmax_t) 0,
799 (uintmax_t) TYPE_MAXIMUM (size_t));
803 time_from_header (const char *p, size_t s)
805 return from_header (p, s, "time_t",
806 - (uintmax_t) TYPE_MINIMUM (time_t),
807 (uintmax_t) TYPE_MAXIMUM (time_t));
811 uid_from_header (const char *p, size_t s)
813 return from_header (p, s, "uid_t",
814 - (uintmax_t) TYPE_MINIMUM (uid_t),
815 (uintmax_t) TYPE_MAXIMUM (uid_t));
819 uintmax_from_header (const char *p, size_t s)
821 return from_header (p, s, "uintmax_t", (uintmax_t) 0,
822 TYPE_MAXIMUM (uintmax_t));
826 /* Format O as a null-terminated decimal string into BUF _backwards_;
827 return pointer to start of result. */
829 stringify_uintmax_t_backwards (uintmax_t o, char *buf)
833 *--buf = '0' + (int) (o % 10);
834 while ((o /= 10) != 0);
838 /* Return a printable representation of T. The result points to
839 static storage that can be reused in the next call to this
840 function, to ctime, or to asctime. */
844 #if !defined(__FreeBSD__) || !defined(HAVE_LANGINFO_CODESET)
845 static char buffer[max (UINTMAX_STRSIZE_BOUND + 1,
846 INT_STRLEN_BOUND (int) + 16)];
853 char const *time_stamp = p + 4;
854 for (p += 16; p[3] != '\n'; p++)
860 /* Use ISO 8610 format. See:
861 http://www.cl.cam.ac.uk/~mgk25/iso-time.html */
862 struct tm *tm = localtime (&t);
865 sprintf (buffer, "%04d-%02d-%02d %02d:%02d:%02d",
866 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
867 tm->tm_hour, tm->tm_min, tm->tm_sec);
872 /* The time stamp cannot be broken down, most likely because it
873 is out of range. Convert it as an integer,
874 right-adjusted in a field with the same width as the usual
875 19-byte 4-year ISO time format. */
876 p = stringify_uintmax_t_backwards (t < 0 ? - (uintmax_t) t : (uintmax_t) t,
877 buffer + sizeof buffer);
880 while (buffer + sizeof buffer - 19 - 1 < p)
883 #else /* __FreeBSD__ */
884 static char buffer[80];
885 static int d_first = -1;
888 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
889 strftime(buffer, sizeof(buffer), d_first ? "%e %b %R %Y" : "%b %e %R %Y",
892 #endif /* __FreeBSD__ */
895 /* Actually print it.
897 Plain and fancy file header block logging. Non-verbose just prints
898 the name, e.g. for "tar t" or "tar x". This should just contain
899 file names, so it can be fed back into tar with xargs or the "-T"
900 option. The verbose option can give a bunch of info, one line per
901 file. I doubt anybody tries to parse its format, or if they do,
902 they shouldn't. Unix tar is pretty random here anyway. */
905 /* FIXME: Note that print_header uses the globals HEAD, HSTAT, and
906 HEAD_STANDARD, which must be set up in advance. Not very clean... */
908 /* UGSWIDTH starts with 18, so with user and group names <= 8 chars, the
909 columns never shift during the listing. */
911 static int ugswidth = UGSWIDTH; /* maximum width encountered so far */
913 /* DATEWIDTH is the number of columns taken by the date and time fields. */
915 # define DATEWIDTH 19
917 # define DATEWIDTH 18
924 char const *time_stamp;
925 /* These hold formatted ints. */
926 char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND];
928 char size[2 * UINTMAX_STRSIZE_BOUND];
929 /* holds formatted size or major,minor */
930 char uintbuf[UINTMAX_STRSIZE_BOUND];
933 if (block_number_option)
935 char buf[UINTMAX_STRSIZE_BOUND];
936 fprintf (stdlis, _("block %s: "),
937 STRINGIFY_BIGINT (current_block_ordinal (), buf));
940 if (verbose_option <= 1)
942 /* Just the fax, mam. */
943 fprintf (stdlis, "%s\n", quotearg (current_file_name));
947 /* File type and modes. */
950 switch (current_header->header.typeflag)
956 case GNUTYPE_MULTIVOL:
964 case GNUTYPE_LONGNAME:
965 case GNUTYPE_LONGLINK:
966 ERROR ((0, 0, _("Visible longname error")));
974 if (current_file_name[strlen (current_file_name) - 1] == '/')
977 case GNUTYPE_DUMPDIR:
1000 decode_mode (current_stat.st_mode, modes + 1);
1004 time_stamp = tartime (current_stat.st_mtime);
1006 /* User and group names. */
1008 if (*current_header->header.uname && current_format != V7_FORMAT
1009 && !numeric_owner_option)
1010 user = current_header->header.uname;
1013 /* Try parsing it as an unsigned integer first, and as a
1014 uid_t if that fails. This method can list positive user
1015 ids that are too large to fit in a uid_t. */
1016 uintmax_t u = from_header (current_header->header.uid,
1017 sizeof current_header->header.uid, 0,
1019 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
1021 user = STRINGIFY_BIGINT (u, uform);
1024 sprintf (uform, "%ld",
1025 (long) UID_FROM_HEADER (current_header->header.uid));
1030 if (*current_header->header.gname && current_format != V7_FORMAT
1031 && !numeric_owner_option)
1032 group = current_header->header.gname;
1035 /* Try parsing it as an unsigned integer first, and as a
1036 gid_t if that fails. This method can list positive group
1037 ids that are too large to fit in a gid_t. */
1038 uintmax_t g = from_header (current_header->header.gid,
1039 sizeof current_header->header.gid, 0,
1041 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
1043 group = STRINGIFY_BIGINT (g, gform);
1046 sprintf (gform, "%ld",
1047 (long) GID_FROM_HEADER (current_header->header.gid));
1052 /* Format the file size or major/minor device numbers. */
1054 switch (current_header->header.typeflag)
1059 STRINGIFY_BIGINT (major (current_stat.st_rdev), uintbuf));
1062 STRINGIFY_BIGINT (minor (current_stat.st_rdev), uintbuf));
1064 case GNUTYPE_SPARSE:
1067 (UINTMAX_FROM_HEADER (current_header
1068 ->oldgnu_header.realsize),
1072 strcpy (size, STRINGIFY_BIGINT (current_stat.st_size, uintbuf));
1076 /* Figure out padding and print the whole line. */
1078 pad = strlen (user) + strlen (group) + strlen (size) + 1;
1082 fprintf (stdlis, "%s %s/%s %*s%s %s",
1083 modes, user, group, ugswidth - pad, "", size, time_stamp);
1085 fprintf (stdlis, " %s", quotearg (current_file_name));
1087 switch (current_header->header.typeflag)
1090 fprintf (stdlis, " -> %s\n", quotearg (current_link_name));
1094 fprintf (stdlis, _(" link to %s\n"), quotearg (current_link_name));
1099 char type_string[2];
1100 type_string[0] = current_header->header.typeflag;
1101 type_string[1] = '\0';
1102 fprintf (stdlis, _(" unknown file type %s\n"),
1103 quote (type_string));
1109 case GNUTYPE_SPARSE:
1115 case GNUTYPE_DUMPDIR:
1116 putc ('\n', stdlis);
1119 case GNUTYPE_VOLHDR:
1120 fprintf (stdlis, _("--Volume Header--\n"));
1123 case GNUTYPE_MULTIVOL:
1126 (UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset),
1128 fprintf (stdlis, _("--Continued at byte %s--\n"), size);
1132 fprintf (stdlis, _("--Mangled file names--\n"));
1139 /* Print a similar line when we make a directory automatically. */
1141 print_for_mkdir (char *pathname, int length, mode_t mode)
1145 if (verbose_option > 1)
1147 /* File type and modes. */
1150 decode_mode (mode, modes + 1);
1152 if (block_number_option)
1154 char buf[UINTMAX_STRSIZE_BOUND];
1155 fprintf (stdlis, _("block %s: "),
1156 STRINGIFY_BIGINT (current_block_ordinal (), buf));
1159 fprintf (stdlis, "%s %*s %.*s\n", modes, ugswidth + DATEWIDTH,
1160 _("Creating directory:"), length, quotearg (pathname));
1164 /* Skip over SIZE bytes of data in blocks in the archive. */
1166 skip_file (off_t size)
1170 if (multi_volume_option)
1172 save_totsize = size;
1173 save_sizeleft = size;
1178 x = find_next_block ();
1180 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1182 set_next_block_after (x);
1184 if (multi_volume_option)
1185 save_sizeleft -= BLOCKSIZE;
1189 /* Skip the current member in the archive. */
1193 char save_typeflag = current_header->header.typeflag;
1194 set_next_block_after (current_header);
1196 if (current_header->oldgnu_header.isextended)
1201 exhdr = find_next_block ();
1203 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1204 set_next_block_after (exhdr);
1206 while (exhdr->sparse_header.isextended);
1209 if (save_typeflag != DIRTYPE)
1210 skip_file (current_stat.st_size);