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 $ */
23 /* $DragonFly: src/contrib/tar/src/Attic/list.c,v 1.2 2003/06/17 04:24:06 dillon Exp $ */
25 /* Define to non-zero for forcing old ctime format instead of ISO format. */
30 #ifdef HAVE_LANGINFO_CODESET
36 #define max(a, b) ((a) < (b) ? (b) : (a))
38 union block *current_header; /* points to current archive header */
39 struct stat current_stat; /* stat struct corresponding */
40 enum archive_format current_format; /* recognized format */
41 union block *recent_long_name; /* recent long name header and contents */
42 union block *recent_long_link; /* likewise, for long link */
43 size_t recent_long_name_blocks; /* number of blocks in recent_long_name */
44 size_t recent_long_link_blocks; /* likewise, for long link */
46 static uintmax_t from_header PARAMS ((const char *, size_t, const char *,
47 uintmax_t, uintmax_t));
49 /* Base 64 digits; see Internet RFC 2045 Table 1. */
50 static char const base_64_digits[64] =
52 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
53 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
54 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
55 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
56 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
59 /* Table of base-64 digit values indexed by unsigned chars.
60 The value is 64 for unsigned chars that are not base-64 digits. */
61 static char base64_map[UCHAR_MAX + 1];
67 memset (base64_map, 64, sizeof base64_map);
68 for (i = 0; i < 64; i++)
69 base64_map[(int) base_64_digits[i]] = i;
72 /* Main loop for reading an archive. */
74 read_and (void (*do_something) ())
76 enum read_header status = HEADER_STILL_UNREAD;
77 enum read_header prev_status;
81 open_archive (ACCESS_READ);
86 status = read_header (0);
87 /* check if the namelist got emptied during the course of reading */
88 /* the tape, if so stop by setting status to EOF */
90 status = HEADER_END_OF_FILE;
93 case HEADER_STILL_UNREAD:
98 /* Valid header. We should decode next field (mode) first.
99 Ensure incoming names are null terminated. */
101 if (! name_match (current_file_name)
102 || (newer_mtime_option != TYPE_MINIMUM (time_t)
103 /* FIXME: We get mtime now, and again later; this causes
104 duplicate diagnostics if header.mtime is bogus. */
105 && ((current_stat.st_mtime
106 = TIME_FROM_HEADER (current_header->header.mtime))
107 < newer_mtime_option))
108 || excluded_name (current_file_name))
110 switch (current_header->header.typeflag)
113 case GNUTYPE_MULTIVOL:
118 if (show_omitted_dirs_option)
119 WARN ((0, 0, _("%s: Omitting"),
120 quotearg_colon (current_file_name)));
131 case HEADER_ZERO_BLOCK:
132 if (block_number_option)
134 char buf[UINTMAX_STRSIZE_BOUND];
135 fprintf (stdlis, _("block %s: ** Block of NULs **\n"),
136 STRINGIFY_BIGINT (current_block_ordinal (), buf));
139 set_next_block_after (current_header);
140 status = prev_status;
141 if (ignore_zeros_option)
145 case HEADER_END_OF_FILE:
146 if (block_number_option)
148 char buf[UINTMAX_STRSIZE_BOUND];
149 fprintf (stdlis, _("block %s: ** End of File **\n"),
150 STRINGIFY_BIGINT (current_block_ordinal (), buf));
155 /* If the previous header was good, tell them that we are
156 skipping bad ones. */
157 set_next_block_after (current_header);
160 case HEADER_STILL_UNREAD:
161 ERROR ((0, 0, _("This does not look like a tar archive")));
164 case HEADER_ZERO_BLOCK:
166 ERROR ((0, 0, _("Skipping to next header")));
169 case HEADER_END_OF_FILE:
171 /* We are in the middle of a cascade of errors. */
180 names_notfound (); /* print names not found */
183 /* Print a header block, based on tar options. */
187 /* Print the header block. */
191 if (verbose_option > 1)
192 decode_header (current_header, ¤t_stat, ¤t_format, 0);
196 if (incremental_option && current_header->header.typeflag == GNUTYPE_DUMPDIR)
199 size_t written, check;
200 union block *data_block;
202 set_next_block_after (current_header);
203 if (multi_volume_option)
205 assign_string (&save_name, current_file_name);
206 save_totsize = current_stat.st_size;
208 for (size = current_stat.st_size; size > 0; size -= written)
210 if (multi_volume_option)
211 save_sizeleft = size;
212 data_block = find_next_block ();
215 ERROR ((0, 0, _("Unexpected EOF in archive")));
216 break; /* FIXME: What happens, then? */
218 written = available_space_after (data_block);
222 check = fwrite (data_block->buffer, sizeof (char), written, stdlis);
223 set_next_block_after ((union block *)
224 (data_block->buffer + written - 1));
225 if (check != written)
227 write_error_details (current_file_name, check, written);
228 skip_file (size - written);
232 if (multi_volume_option)
233 assign_string (&save_name, 0);
234 fputc ('\n', stdlis);
240 if (multi_volume_option)
241 assign_string (&save_name, current_file_name);
245 if (multi_volume_option)
246 assign_string (&save_name, 0);
249 /* Read a block that's supposed to be a header block. Return its
250 address in "current_header", and if it is good, the file's size in
251 current_stat.st_size.
253 Return 1 for success, 0 if the checksum is bad, EOF on eof, 2 for a
254 block full of zeros (EOF marker).
256 If RAW_EXTENDED_HEADERS is nonzero, do not automagically fold the
257 GNU long name and link headers into later headers.
259 You must always set_next_block_after(current_header) to skip past
260 the header which this routine reads. */
262 /* The standard BSD tar sources create the checksum by adding up the
263 bytes in the header as type char. I think the type char was unsigned
264 on the PDP-11, but it's signed on the Next and Sun. It looks like the
265 sources to BSD tar were never changed to compute the checksum
266 correctly, so both the Sun and Next add the bytes of the header as
267 signed chars. This doesn't cause a problem until you get a file with
268 a name containing characters with the high bit set. So read_header
269 computes two checksums -- signed and unsigned. */
272 read_header (bool raw_extended_headers)
275 int unsigned_sum; /* the POSIX one :-) */
276 int signed_sum; /* the Sun one :-( */
278 uintmax_t parsed_sum;
281 union block *header_copy;
283 union block *data_block;
284 size_t size, written;
285 union block *next_long_name = 0;
286 union block *next_long_link = 0;
287 size_t next_long_name_blocks;
288 size_t next_long_link_blocks;
292 header = find_next_block ();
293 current_header = header;
295 return HEADER_END_OF_FILE;
300 for (i = sizeof *header; i-- != 0;)
302 unsigned_sum += (unsigned char) *p;
303 signed_sum += (signed char) (*p++);
306 if (unsigned_sum == 0)
307 return HEADER_ZERO_BLOCK;
309 /* Adjust checksum to count the "chksum" field as blanks. */
311 for (i = sizeof header->header.chksum; i-- != 0;)
313 unsigned_sum -= (unsigned char) header->header.chksum[i];
314 signed_sum -= (signed char) (header->header.chksum[i]);
316 unsigned_sum += ' ' * sizeof header->header.chksum;
317 signed_sum += ' ' * sizeof header->header.chksum;
319 parsed_sum = from_header (header->header.chksum,
320 sizeof header->header.chksum, 0,
322 (uintmax_t) TYPE_MAXIMUM (int));
323 if (parsed_sum == (uintmax_t) -1)
324 return HEADER_FAILURE;
326 recorded_sum = parsed_sum;
328 if (unsigned_sum != recorded_sum && signed_sum != recorded_sum)
329 return HEADER_FAILURE;
331 /* Good block. Decode file size and return. */
333 if (header->header.typeflag == LNKTYPE)
334 current_stat.st_size = 0; /* links 0 size on tape */
336 current_stat.st_size = OFF_FROM_HEADER (header->header.size);
338 if (header->header.typeflag == GNUTYPE_LONGNAME
339 || header->header.typeflag == GNUTYPE_LONGLINK)
341 if (raw_extended_headers)
342 return HEADER_SUCCESS_EXTENDED;
345 size_t name_size = current_stat.st_size;
346 size = name_size - name_size % BLOCKSIZE + 2 * BLOCKSIZE;
347 if (name_size != current_stat.st_size || size < name_size)
351 header_copy = xmalloc (size + 1);
353 if (header->header.typeflag == GNUTYPE_LONGNAME)
356 free (next_long_name);
357 next_long_name = header_copy;
358 next_long_name_blocks = size / BLOCKSIZE;
363 free (next_long_link);
364 next_long_link = header_copy;
365 next_long_link_blocks = size / BLOCKSIZE;
368 set_next_block_after (header);
369 *header_copy = *header;
370 bp = header_copy->buffer + BLOCKSIZE;
372 for (size -= BLOCKSIZE; size > 0; size -= written)
374 data_block = find_next_block ();
377 ERROR ((0, 0, _("Unexpected EOF in archive")));
380 written = available_space_after (data_block);
384 memcpy (bp, data_block->buffer, written);
386 set_next_block_after ((union block *)
387 (data_block->buffer + written - 1));
398 struct posix_header const *h = ¤t_header->header;
399 char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
401 if (recent_long_name)
402 free (recent_long_name);
406 name = next_long_name->buffer + BLOCKSIZE;
407 recent_long_name = next_long_name;
408 recent_long_name_blocks = next_long_name_blocks;
412 /* Accept file names as specified by POSIX.1-1996
416 if (h->prefix[0] && strcmp (h->magic, TMAGIC) == 0)
418 memcpy (np, h->prefix, sizeof h->prefix);
419 np[sizeof h->prefix] = '\0';
423 /* Prevent later references to current_header from
424 mistakenly treating this as an old GNU header.
425 This assignment invalidates h->prefix. */
426 current_header->oldgnu_header.isextended = 0;
428 memcpy (np, h->name, sizeof h->name);
429 np[sizeof h->name] = '\0';
431 recent_long_name = 0;
432 recent_long_name_blocks = 0;
434 assign_string (¤t_file_name, name);
436 if (recent_long_link)
437 free (recent_long_link);
441 name = next_long_link->buffer + BLOCKSIZE;
442 recent_long_link = next_long_link;
443 recent_long_link_blocks = next_long_link_blocks;
447 memcpy (namebuf, h->linkname, sizeof h->linkname);
448 namebuf[sizeof h->linkname] = '\0';
450 recent_long_link = 0;
451 recent_long_link_blocks = 0;
453 assign_string (¤t_link_name, name);
455 return HEADER_SUCCESS;
460 /* Decode things from a file HEADER block into STAT_INFO, also setting
461 *FORMAT_POINTER depending on the header block format. If
462 DO_USER_GROUP, decode the user/group information (this is useful
463 for extraction, but waste time when merely listing).
465 read_header() has already decoded the checksum and length, so we don't.
467 This routine should *not* be called twice for the same block, since
468 the two calls might use different DO_USER_GROUP values and thus
469 might end up with different uid/gid for the two calls. If anybody
470 wants the uid/gid they should decode it first, and other callers
471 should decode it without uid/gid before calling a routine,
472 e.g. print_header, that assumes decoded data. */
474 decode_header (union block *header, struct stat *stat_info,
475 enum archive_format *format_pointer, int do_user_group)
477 enum archive_format format;
479 if (strcmp (header->header.magic, TMAGIC) == 0)
480 format = POSIX_FORMAT;
481 else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0)
482 format = OLDGNU_FORMAT;
485 *format_pointer = format;
487 stat_info->st_mode = MODE_FROM_HEADER (header->header.mode);
488 stat_info->st_mtime = TIME_FROM_HEADER (header->header.mtime);
490 if (format == OLDGNU_FORMAT && incremental_option)
492 stat_info->st_atime = TIME_FROM_HEADER (header->oldgnu_header.atime);
493 stat_info->st_ctime = TIME_FROM_HEADER (header->oldgnu_header.ctime);
496 if (format == V7_FORMAT)
498 stat_info->st_uid = UID_FROM_HEADER (header->header.uid);
499 stat_info->st_gid = GID_FROM_HEADER (header->header.gid);
500 stat_info->st_rdev = 0;
506 /* FIXME: Decide if this should somewhat depend on -p. */
508 if (numeric_owner_option
509 || !*header->header.uname
510 || !uname_to_uid (header->header.uname, &stat_info->st_uid))
511 stat_info->st_uid = UID_FROM_HEADER (header->header.uid);
513 if (numeric_owner_option
514 || !*header->header.gname
515 || !gname_to_gid (header->header.gname, &stat_info->st_gid))
516 stat_info->st_gid = GID_FROM_HEADER (header->header.gid);
518 switch (header->header.typeflag)
522 = makedev (MAJOR_FROM_HEADER (header->header.devmajor),
523 MINOR_FROM_HEADER (header->header.devminor));
528 = makedev (MAJOR_FROM_HEADER (header->header.devmajor),
529 MINOR_FROM_HEADER (header->header.devminor));
533 stat_info->st_rdev = 0;
538 /* Convert buffer at WHERE0 of size DIGS from external format to
539 uintmax_t. The data is of type TYPE. The buffer must represent a
540 value in the range -MINUS_MINVAL through MAXVAL. DIGS must be
541 positive. Return -1 on error, diagnosing the error if TYPE is
544 from_header (char const *where0, size_t digs, char const *type,
545 uintmax_t minus_minval, uintmax_t maxval)
548 char const *where = where0;
549 char const *lim = where + digs;
552 /* Accommodate buggy tar of unknown vintage, which outputs leading
553 NUL if the previous field overflows. */
556 /* Accommodate older tars, which output leading spaces. */
563 _("Blanks in header where numeric %s value expected"),
567 if (!ISSPACE ((unsigned char) *where))
573 if (ISODIGIT (*where))
575 char const *where1 = where;
576 uintmax_t overflow = 0;
580 value += *where++ - '0';
581 if (where == lim || ! ISODIGIT (*where))
583 overflow |= value ^ (value << LG_8 >> LG_8);
587 /* Parse the output of older, unportable tars, which generate
588 negative values in two's complement octal. If the leading
589 nonzero digit is 1, we can't recover the original value
590 reliably; so do this only if the digit is 2 or more. This
591 catches the common case of 32-bit negative time stamps. */
592 if ((overflow || maxval < value) && '2' <= *where1 && type)
594 /* Compute the negative of the input value, assuming two's
596 int digit = (*where1 - '0') | 4;
604 if (where == lim || ! ISODIGIT (*where))
606 digit = *where - '0';
607 overflow |= value ^ (value << LG_8 >> LG_8);
613 if (!overflow && value <= minus_minval)
616 _("Archive octal value %.*s is out of %s range; assuming two's complement"),
617 (int) (where - where1), where1, type));
626 _("Archive octal value %.*s is out of %s range"),
627 (int) (where - where1), where1, type));
631 else if (*where == '-' || *where == '+')
633 /* Parse base-64 output produced only by tar test versions
634 1.13.6 (1999-08-11) through 1.13.11 (1999-08-23).
635 Support for this will be withdrawn in future releases. */
637 static int warned_once;
642 _("Archive contains obsolescent base-64 headers")));
644 negative = *where++ == '-';
646 && (dig = base64_map[(unsigned char) *where]) < 64)
648 if (value << LG_64 >> LG_64 != value)
650 char *string = alloca (digs + 1);
651 memcpy (string, where0, digs);
655 _("Archive signed base-64 string %s is out of %s range"),
656 quote (string), type));
659 value = (value << LG_64) | dig;
663 else if (*where == '\200' /* positive base-256 */
664 || *where == '\377' /* negative base-256 */)
666 /* Parse base-256 output. A nonnegative number N is
667 represented as (256**DIGS)/2 + N; a negative number -N is
668 represented as (256**DIGS) - N, i.e. as two's complement.
669 The representation guarantees that the leading bit is
670 always on, so that we don't confuse this format with the
671 others (assuming ASCII bytes of 8 bits or more). */
672 int signbit = *where & (1 << (LG_256 - 2));
673 uintmax_t topbits = (((uintmax_t) - signbit)
674 << (CHAR_BIT * sizeof (uintmax_t)
675 - LG_256 - (LG_256 - 2)));
676 value = (*where++ & ((1 << (LG_256 - 2)) - 1)) - signbit;
679 value = (value << LG_256) + (unsigned char) *where++;
682 if (((value << LG_256 >> LG_256) | topbits) != value)
686 _("Archive base-256 value is out of %s range"),
696 if (where != lim && *where && !ISSPACE ((unsigned char) *where))
700 char buf[1000]; /* Big enough to represent any header. */
701 static struct quoting_options *o;
705 o = clone_quoting_options (0);
706 set_quoting_style (o, locale_quoting_style);
709 while (where0 != lim && ! lim[-1])
711 quotearg_buffer (buf, sizeof buf, where0, lim - where, o);
713 _("Archive contains %.*s where numeric %s value expected"),
714 (int) sizeof buf, buf, type));
720 if (value <= (negative ? minus_minval : maxval))
721 return negative ? -value : value;
725 char minval_buf[UINTMAX_STRSIZE_BOUND + 1];
726 char maxval_buf[UINTMAX_STRSIZE_BOUND];
727 char value_buf[UINTMAX_STRSIZE_BOUND + 1];
728 char *minval_string = STRINGIFY_BIGINT (minus_minval, minval_buf + 1);
729 char *value_string = STRINGIFY_BIGINT (value, value_buf + 1);
731 *--value_string = '-';
733 *--minval_string = '-';
734 ERROR ((0, 0, _("Archive value %s is out of %s range %s..%s"),
736 minval_string, STRINGIFY_BIGINT (maxval, maxval_buf)));
743 gid_from_header (const char *p, size_t s)
745 return from_header (p, s, "gid_t",
746 - (uintmax_t) TYPE_MINIMUM (gid_t),
747 (uintmax_t) TYPE_MAXIMUM (gid_t));
751 major_from_header (const char *p, size_t s)
753 return from_header (p, s, "major_t",
754 - (uintmax_t) TYPE_MINIMUM (major_t),
755 (uintmax_t) TYPE_MAXIMUM (major_t));
759 minor_from_header (const char *p, size_t s)
761 return from_header (p, s, "minor_t",
762 - (uintmax_t) TYPE_MINIMUM (minor_t),
763 (uintmax_t) TYPE_MAXIMUM (minor_t));
767 mode_from_header (const char *p, size_t s)
769 /* Do not complain about unrecognized mode bits. */
770 unsigned u = from_header (p, s, "mode_t",
771 - (uintmax_t) TYPE_MINIMUM (mode_t),
772 TYPE_MAXIMUM (uintmax_t));
773 return ((u & TSUID ? S_ISUID : 0)
774 | (u & TSGID ? S_ISGID : 0)
775 | (u & TSVTX ? S_ISVTX : 0)
776 | (u & TUREAD ? S_IRUSR : 0)
777 | (u & TUWRITE ? S_IWUSR : 0)
778 | (u & TUEXEC ? S_IXUSR : 0)
779 | (u & TGREAD ? S_IRGRP : 0)
780 | (u & TGWRITE ? S_IWGRP : 0)
781 | (u & TGEXEC ? S_IXGRP : 0)
782 | (u & TOREAD ? S_IROTH : 0)
783 | (u & TOWRITE ? S_IWOTH : 0)
784 | (u & TOEXEC ? S_IXOTH : 0));
788 off_from_header (const char *p, size_t s)
790 /* Negative offsets are not allowed in tar files, so invoke
791 from_header with minimum value 0, not TYPE_MINIMUM (off_t). */
792 return from_header (p, s, "off_t", (uintmax_t) 0,
793 (uintmax_t) TYPE_MAXIMUM (off_t));
797 size_from_header (const char *p, size_t s)
799 return from_header (p, s, "size_t", (uintmax_t) 0,
800 (uintmax_t) TYPE_MAXIMUM (size_t));
804 time_from_header (const char *p, size_t s)
806 return from_header (p, s, "time_t",
807 - (uintmax_t) TYPE_MINIMUM (time_t),
808 (uintmax_t) TYPE_MAXIMUM (time_t));
812 uid_from_header (const char *p, size_t s)
814 return from_header (p, s, "uid_t",
815 - (uintmax_t) TYPE_MINIMUM (uid_t),
816 (uintmax_t) TYPE_MAXIMUM (uid_t));
820 uintmax_from_header (const char *p, size_t s)
822 return from_header (p, s, "uintmax_t", (uintmax_t) 0,
823 TYPE_MAXIMUM (uintmax_t));
827 /* Format O as a null-terminated decimal string into BUF _backwards_;
828 return pointer to start of result. */
830 stringify_uintmax_t_backwards (uintmax_t o, char *buf)
834 *--buf = '0' + (int) (o % 10);
835 while ((o /= 10) != 0);
839 /* Return a printable representation of T. The result points to
840 static storage that can be reused in the next call to this
841 function, to ctime, or to asctime. */
845 #if !defined(__FreeBSD__) || !defined(HAVE_LANGINFO_CODESET)
846 static char buffer[max (UINTMAX_STRSIZE_BOUND + 1,
847 INT_STRLEN_BOUND (int) + 16)];
854 char const *time_stamp = p + 4;
855 for (p += 16; p[3] != '\n'; p++)
861 /* Use ISO 8610 format. See:
862 http://www.cl.cam.ac.uk/~mgk25/iso-time.html */
863 struct tm *tm = localtime (&t);
866 sprintf (buffer, "%04d-%02d-%02d %02d:%02d:%02d",
867 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
868 tm->tm_hour, tm->tm_min, tm->tm_sec);
873 /* The time stamp cannot be broken down, most likely because it
874 is out of range. Convert it as an integer,
875 right-adjusted in a field with the same width as the usual
876 19-byte 4-year ISO time format. */
877 p = stringify_uintmax_t_backwards (t < 0 ? - (uintmax_t) t : (uintmax_t) t,
878 buffer + sizeof buffer);
881 while (buffer + sizeof buffer - 19 - 1 < p)
884 #else /* __FreeBSD__ */
885 static char buffer[80];
886 static int d_first = -1;
889 d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
890 strftime(buffer, sizeof(buffer), d_first ? "%e %b %R %Y" : "%b %e %R %Y",
893 #endif /* __FreeBSD__ */
896 /* Actually print it.
898 Plain and fancy file header block logging. Non-verbose just prints
899 the name, e.g. for "tar t" or "tar x". This should just contain
900 file names, so it can be fed back into tar with xargs or the "-T"
901 option. The verbose option can give a bunch of info, one line per
902 file. I doubt anybody tries to parse its format, or if they do,
903 they shouldn't. Unix tar is pretty random here anyway. */
906 /* FIXME: Note that print_header uses the globals HEAD, HSTAT, and
907 HEAD_STANDARD, which must be set up in advance. Not very clean... */
909 /* UGSWIDTH starts with 18, so with user and group names <= 8 chars, the
910 columns never shift during the listing. */
912 static int ugswidth = UGSWIDTH; /* maximum width encountered so far */
914 /* DATEWIDTH is the number of columns taken by the date and time fields. */
916 # define DATEWIDTH 19
918 # define DATEWIDTH 18
925 char const *time_stamp;
926 /* These hold formatted ints. */
927 char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND];
929 char size[2 * UINTMAX_STRSIZE_BOUND];
930 /* holds formatted size or major,minor */
931 char uintbuf[UINTMAX_STRSIZE_BOUND];
934 if (block_number_option)
936 char buf[UINTMAX_STRSIZE_BOUND];
937 fprintf (stdlis, _("block %s: "),
938 STRINGIFY_BIGINT (current_block_ordinal (), buf));
941 if (verbose_option <= 1)
943 /* Just the fax, mam. */
944 fprintf (stdlis, "%s\n", quotearg (current_file_name));
948 /* File type and modes. */
951 switch (current_header->header.typeflag)
957 case GNUTYPE_MULTIVOL:
965 case GNUTYPE_LONGNAME:
966 case GNUTYPE_LONGLINK:
967 ERROR ((0, 0, _("Visible longname error")));
975 if (current_file_name[strlen (current_file_name) - 1] == '/')
978 case GNUTYPE_DUMPDIR:
1001 decode_mode (current_stat.st_mode, modes + 1);
1005 time_stamp = tartime (current_stat.st_mtime);
1007 /* User and group names. */
1009 if (*current_header->header.uname && current_format != V7_FORMAT
1010 && !numeric_owner_option)
1011 user = current_header->header.uname;
1014 /* Try parsing it as an unsigned integer first, and as a
1015 uid_t if that fails. This method can list positive user
1016 ids that are too large to fit in a uid_t. */
1017 uintmax_t u = from_header (current_header->header.uid,
1018 sizeof current_header->header.uid, 0,
1020 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
1022 user = STRINGIFY_BIGINT (u, uform);
1025 sprintf (uform, "%ld",
1026 (long) UID_FROM_HEADER (current_header->header.uid));
1031 if (*current_header->header.gname && current_format != V7_FORMAT
1032 && !numeric_owner_option)
1033 group = current_header->header.gname;
1036 /* Try parsing it as an unsigned integer first, and as a
1037 gid_t if that fails. This method can list positive group
1038 ids that are too large to fit in a gid_t. */
1039 uintmax_t g = from_header (current_header->header.gid,
1040 sizeof current_header->header.gid, 0,
1042 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
1044 group = STRINGIFY_BIGINT (g, gform);
1047 sprintf (gform, "%ld",
1048 (long) GID_FROM_HEADER (current_header->header.gid));
1053 /* Format the file size or major/minor device numbers. */
1055 switch (current_header->header.typeflag)
1060 STRINGIFY_BIGINT (major (current_stat.st_rdev), uintbuf));
1063 STRINGIFY_BIGINT (minor (current_stat.st_rdev), uintbuf));
1065 case GNUTYPE_SPARSE:
1068 (UINTMAX_FROM_HEADER (current_header
1069 ->oldgnu_header.realsize),
1073 strcpy (size, STRINGIFY_BIGINT (current_stat.st_size, uintbuf));
1077 /* Figure out padding and print the whole line. */
1079 pad = strlen (user) + strlen (group) + strlen (size) + 1;
1083 fprintf (stdlis, "%s %s/%s %*s%s %s",
1084 modes, user, group, ugswidth - pad, "", size, time_stamp);
1086 fprintf (stdlis, " %s", quotearg (current_file_name));
1088 switch (current_header->header.typeflag)
1091 fprintf (stdlis, " -> %s\n", quotearg (current_link_name));
1095 fprintf (stdlis, _(" link to %s\n"), quotearg (current_link_name));
1100 char type_string[2];
1101 type_string[0] = current_header->header.typeflag;
1102 type_string[1] = '\0';
1103 fprintf (stdlis, _(" unknown file type %s\n"),
1104 quote (type_string));
1110 case GNUTYPE_SPARSE:
1116 case GNUTYPE_DUMPDIR:
1117 putc ('\n', stdlis);
1120 case GNUTYPE_VOLHDR:
1121 fprintf (stdlis, _("--Volume Header--\n"));
1124 case GNUTYPE_MULTIVOL:
1127 (UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset),
1129 fprintf (stdlis, _("--Continued at byte %s--\n"), size);
1133 fprintf (stdlis, _("--Mangled file names--\n"));
1140 /* Print a similar line when we make a directory automatically. */
1142 print_for_mkdir (char *pathname, int length, mode_t mode)
1146 if (verbose_option > 1)
1148 /* File type and modes. */
1151 decode_mode (mode, modes + 1);
1153 if (block_number_option)
1155 char buf[UINTMAX_STRSIZE_BOUND];
1156 fprintf (stdlis, _("block %s: "),
1157 STRINGIFY_BIGINT (current_block_ordinal (), buf));
1160 fprintf (stdlis, "%s %*s %.*s\n", modes, ugswidth + DATEWIDTH,
1161 _("Creating directory:"), length, quotearg (pathname));
1165 /* Skip over SIZE bytes of data in blocks in the archive. */
1167 skip_file (off_t size)
1171 if (multi_volume_option)
1173 save_totsize = size;
1174 save_sizeleft = size;
1179 x = find_next_block ();
1181 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1183 set_next_block_after (x);
1185 if (multi_volume_option)
1186 save_sizeleft -= BLOCKSIZE;
1190 /* Skip the current member in the archive. */
1194 char save_typeflag = current_header->header.typeflag;
1195 set_next_block_after (current_header);
1197 if (current_header->oldgnu_header.isextended)
1202 exhdr = find_next_block ();
1204 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1205 set_next_block_after (exhdr);
1207 while (exhdr->sparse_header.isextended);
1210 if (save_typeflag != DIRTYPE)
1211 skip_file (current_stat.st_size);