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 /* Define to non-zero for forcing old ctime format instead of ISO format. */
30 #define max(a, b) ((a) < (b) ? (b) : (a))
32 union block
*current_header
; /* points to current archive header */
33 struct stat current_stat
; /* stat struct corresponding */
34 enum archive_format current_format
; /* recognized format */
36 static uintmax_t from_header
PARAMS ((const char *, size_t, const char *,
37 uintmax_t, uintmax_t));
39 /* Base 64 digits; see Internet RFC 2045 Table 1. */
40 static char const base_64_digits
[64] =
42 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
43 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
44 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
45 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
46 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
49 /* Table of base-64 digit values indexed by unsigned chars.
50 The value is 64 for unsigned chars that are not base-64 digits. */
51 static char base64_map
[UCHAR_MAX
+ 1];
57 memset (base64_map
, 64, sizeof base64_map
);
58 for (i
= 0; i
< 64; i
++)
59 base64_map
[(int) base_64_digits
[i
]] = i
;
62 /* Main loop for reading an archive. */
64 read_and (void (*do_something
) ())
66 enum read_header status
= HEADER_STILL_UNREAD
;
67 enum read_header prev_status
;
71 open_archive (ACCESS_READ
);
76 status
= read_header ();
79 case HEADER_STILL_UNREAD
:
84 /* Valid header. We should decode next field (mode) first.
85 Ensure incoming names are null terminated. */
87 if (! name_match (current_file_name
)
88 || (newer_mtime_option
!= TYPE_MINIMUM (time_t)
89 /* FIXME: We get mtime now, and again later; this causes
90 duplicate diagnostics if header.mtime is bogus. */
91 && ((current_stat
.st_mtime
92 = TIME_FROM_HEADER (current_header
->header
.mtime
))
93 < newer_mtime_option
))
94 || excluded_name (current_file_name
))
96 switch (current_header
->header
.typeflag
)
99 case GNUTYPE_MULTIVOL
:
104 if (show_omitted_dirs_option
)
105 WARN ((0, 0, _("%s: Omitting"),
106 quotearg_colon (current_file_name
)));
117 case HEADER_ZERO_BLOCK
:
118 if (block_number_option
)
120 char buf
[UINTMAX_STRSIZE_BOUND
];
121 fprintf (stdlis
, _("block %s: ** Block of NULs **\n"),
122 STRINGIFY_BIGINT (current_block_ordinal (), buf
));
125 set_next_block_after (current_header
);
126 status
= prev_status
;
127 if (ignore_zeros_option
)
131 case HEADER_END_OF_FILE
:
132 if (block_number_option
)
134 char buf
[UINTMAX_STRSIZE_BOUND
];
135 fprintf (stdlis
, _("block %s: ** End of File **\n"),
136 STRINGIFY_BIGINT (current_block_ordinal (), buf
));
141 /* If the previous header was good, tell them that we are
142 skipping bad ones. */
143 set_next_block_after (current_header
);
146 case HEADER_STILL_UNREAD
:
147 ERROR ((0, 0, _("This does not look like a tar archive")));
150 case HEADER_ZERO_BLOCK
:
152 ERROR ((0, 0, _("Skipping to next header")));
155 case HEADER_END_OF_FILE
:
157 /* We are in the middle of a cascade of errors. */
166 names_notfound (); /* print names not found */
169 /* Print a header block, based on tar options. */
173 /* Print the header block. */
177 if (verbose_option
> 1)
178 decode_header (current_header
, ¤t_stat
, ¤t_format
, 0);
182 if (incremental_option
&& current_header
->header
.typeflag
== GNUTYPE_DUMPDIR
)
185 size_t written
, check
;
186 union block
*data_block
;
188 set_next_block_after (current_header
);
189 if (multi_volume_option
)
191 assign_string (&save_name
, current_file_name
);
192 save_totsize
= current_stat
.st_size
;
194 for (size
= current_stat
.st_size
; size
> 0; size
-= written
)
196 if (multi_volume_option
)
197 save_sizeleft
= size
;
198 data_block
= find_next_block ();
201 ERROR ((0, 0, _("Unexpected EOF in archive")));
202 break; /* FIXME: What happens, then? */
204 written
= available_space_after (data_block
);
208 check
= fwrite (data_block
->buffer
, sizeof (char), written
, stdlis
);
209 set_next_block_after ((union block
*)
210 (data_block
->buffer
+ written
- 1));
211 if (check
!= written
)
213 write_error_details (current_file_name
, check
, written
);
214 skip_file (size
- written
);
218 if (multi_volume_option
)
219 assign_string (&save_name
, 0);
220 fputc ('\n', stdlis
);
226 if (multi_volume_option
)
227 assign_string (&save_name
, current_file_name
);
231 if (multi_volume_option
)
232 assign_string (&save_name
, 0);
235 /* Read a block that's supposed to be a header block. Return its
236 address in "current_header", and if it is good, the file's size in
237 current_stat.st_size.
239 Return 1 for success, 0 if the checksum is bad, EOF on eof, 2 for a
240 block full of zeros (EOF marker).
242 You must always set_next_block_after(current_header) to skip past
243 the header which this routine reads. */
245 /* The standard BSD tar sources create the checksum by adding up the
246 bytes in the header as type char. I think the type char was unsigned
247 on the PDP-11, but it's signed on the Next and Sun. It looks like the
248 sources to BSD tar were never changed to compute the checksum
249 correctly, so both the Sun and Next add the bytes of the header as
250 signed chars. This doesn't cause a problem until you get a file with
251 a name containing characters with the high bit set. So read_header
252 computes two checksums -- signed and unsigned. */
258 int unsigned_sum
; /* the POSIX one :-) */
259 int signed_sum
; /* the Sun one :-( */
261 uintmax_t parsed_sum
;
266 union block
*data_block
;
267 size_t size
, written
;
268 static char *next_long_name
, *next_long_link
;
272 header
= find_next_block ();
273 current_header
= header
;
275 return HEADER_END_OF_FILE
;
280 for (i
= sizeof *header
; i
-- != 0;)
282 unsigned_sum
+= (unsigned char) *p
;
283 signed_sum
+= (signed char) (*p
++);
286 if (unsigned_sum
== 0)
287 return HEADER_ZERO_BLOCK
;
289 /* Adjust checksum to count the "chksum" field as blanks. */
291 for (i
= sizeof header
->header
.chksum
; i
-- != 0;)
293 unsigned_sum
-= (unsigned char) header
->header
.chksum
[i
];
294 signed_sum
-= (signed char) (header
->header
.chksum
[i
]);
296 unsigned_sum
+= ' ' * sizeof header
->header
.chksum
;
297 signed_sum
+= ' ' * sizeof header
->header
.chksum
;
299 parsed_sum
= from_header (header
->header
.chksum
,
300 sizeof header
->header
.chksum
, 0,
302 (uintmax_t) TYPE_MAXIMUM (int));
303 if (parsed_sum
== (uintmax_t) -1)
304 return HEADER_FAILURE
;
306 recorded_sum
= parsed_sum
;
308 if (unsigned_sum
!= recorded_sum
&& signed_sum
!= recorded_sum
)
309 return HEADER_FAILURE
;
311 /* Good block. Decode file size and return. */
313 if (header
->header
.typeflag
== LNKTYPE
)
314 current_stat
.st_size
= 0; /* links 0 size on tape */
316 current_stat
.st_size
= OFF_FROM_HEADER (header
->header
.size
);
318 if (header
->header
.typeflag
== GNUTYPE_LONGNAME
319 || header
->header
.typeflag
== GNUTYPE_LONGLINK
)
321 longp
= ((header
->header
.typeflag
== GNUTYPE_LONGNAME
)
325 set_next_block_after (header
);
328 size
= current_stat
.st_size
;
329 if (size
!= current_stat
.st_size
)
331 bp
= *longp
= xmalloc (size
);
333 for (; size
> 0; size
-= written
)
335 data_block
= find_next_block ();
338 ERROR ((0, 0, _("Unexpected EOF in archive")));
341 written
= available_space_after (data_block
);
345 memcpy (bp
, data_block
->buffer
, written
);
347 set_next_block_after ((union block
*)
348 (data_block
->buffer
+ written
- 1));
357 struct posix_header
const *h
= ¤t_header
->header
;
358 char namebuf
[sizeof h
->prefix
+ 1 + NAME_FIELD_SIZE
+ 1];
360 name
= next_long_name
;
363 /* Accept file names as specified by POSIX.1-1996
367 if (h
->prefix
[0] && strcmp (h
->magic
, TMAGIC
) == 0)
369 memcpy (np
, h
->prefix
, sizeof h
->prefix
);
370 np
[sizeof h
->prefix
] = '\0';
374 /* Prevent later references to current_header from
375 mistakenly treating this as an old GNU header.
376 This assignment invalidates h->prefix. */
377 current_header
->oldgnu_header
.isextended
= 0;
379 memcpy (np
, h
->name
, sizeof h
->name
);
380 np
[sizeof h
->name
] = '\0';
383 assign_string (¤t_file_name
, name
);
386 free (next_long_name
);
390 name
= next_long_link
;
393 memcpy (namebuf
, h
->linkname
, sizeof h
->linkname
);
394 namebuf
[sizeof h
->linkname
] = '\0';
397 assign_string (¤t_link_name
, name
);
400 free (next_long_link
);
404 return HEADER_SUCCESS
;
409 /* Decode things from a file HEADER block into STAT_INFO, also setting
410 *FORMAT_POINTER depending on the header block format. If
411 DO_USER_GROUP, decode the user/group information (this is useful
412 for extraction, but waste time when merely listing).
414 read_header() has already decoded the checksum and length, so we don't.
416 This routine should *not* be called twice for the same block, since
417 the two calls might use different DO_USER_GROUP values and thus
418 might end up with different uid/gid for the two calls. If anybody
419 wants the uid/gid they should decode it first, and other callers
420 should decode it without uid/gid before calling a routine,
421 e.g. print_header, that assumes decoded data. */
423 decode_header (union block
*header
, struct stat
*stat_info
,
424 enum archive_format
*format_pointer
, int do_user_group
)
426 enum archive_format format
;
428 if (strcmp (header
->header
.magic
, TMAGIC
) == 0)
429 format
= POSIX_FORMAT
;
430 else if (strcmp (header
->header
.magic
, OLDGNU_MAGIC
) == 0)
431 format
= OLDGNU_FORMAT
;
434 *format_pointer
= format
;
436 stat_info
->st_mode
= MODE_FROM_HEADER (header
->header
.mode
);
437 stat_info
->st_mtime
= TIME_FROM_HEADER (header
->header
.mtime
);
439 if (format
== OLDGNU_FORMAT
&& incremental_option
)
441 stat_info
->st_atime
= TIME_FROM_HEADER (header
->oldgnu_header
.atime
);
442 stat_info
->st_ctime
= TIME_FROM_HEADER (header
->oldgnu_header
.ctime
);
445 if (format
== V7_FORMAT
)
447 stat_info
->st_uid
= UID_FROM_HEADER (header
->header
.uid
);
448 stat_info
->st_gid
= GID_FROM_HEADER (header
->header
.gid
);
449 stat_info
->st_rdev
= 0;
455 /* FIXME: Decide if this should somewhat depend on -p. */
457 if (numeric_owner_option
458 || !*header
->header
.uname
459 || !uname_to_uid (header
->header
.uname
, &stat_info
->st_uid
))
460 stat_info
->st_uid
= UID_FROM_HEADER (header
->header
.uid
);
462 if (numeric_owner_option
463 || !*header
->header
.gname
464 || !gname_to_gid (header
->header
.gname
, &stat_info
->st_gid
))
465 stat_info
->st_gid
= GID_FROM_HEADER (header
->header
.gid
);
467 switch (header
->header
.typeflag
)
471 = makedev (MAJOR_FROM_HEADER (header
->header
.devmajor
),
472 MINOR_FROM_HEADER (header
->header
.devminor
));
477 = makedev (MAJOR_FROM_HEADER (header
->header
.devmajor
),
478 MINOR_FROM_HEADER (header
->header
.devminor
));
482 stat_info
->st_rdev
= 0;
487 /* Convert buffer at WHERE0 of size DIGS from external format to
488 uintmax_t. The data is of type TYPE. The buffer must represent a
489 value in the range -MINUS_MINVAL through MAXVAL. DIGS must be
490 positive. Return -1 on error, diagnosing the error if TYPE is
493 from_header (char const *where0
, size_t digs
, char const *type
,
494 uintmax_t minus_minval
, uintmax_t maxval
)
497 char const *where
= where0
;
498 char const *lim
= where
+ digs
;
501 /* Accommodate buggy tar of unknown vintage, which outputs leading
502 NUL if the previous field overflows. */
505 /* Accommodate older tars, which output leading spaces. */
512 _("Blanks in header where numeric %s value expected"),
516 if (!ISSPACE ((unsigned char) *where
))
522 if (ISODIGIT (*where
))
524 char const *where1
= where
;
525 uintmax_t overflow
= 0;
529 value
+= *where
++ - '0';
530 if (where
== lim
|| ! ISODIGIT (*where
))
532 overflow
|= value
^ (value
<< LG_8
>> LG_8
);
536 /* Parse the output of older, unportable tars, which generate
537 negative values in two's complement octal. If the leading
538 nonzero digit is 1, we can't recover the original value
539 reliably; so do this only if the digit is 2 or more. This
540 catches the common case of 32-bit negative time stamps. */
541 if ((overflow
|| maxval
< value
) && '2' <= *where1
&& type
)
543 /* Compute the negative of the input value, assuming two's
545 int digit
= (*where1
- '0') | 4;
553 if (where
== lim
|| ! ISODIGIT (*where
))
555 digit
= *where
- '0';
556 overflow
|= value
^ (value
<< LG_8
>> LG_8
);
562 if (!overflow
&& value
<= minus_minval
)
565 _("Archive octal value %.*s is out of %s range; assuming two's complement"),
566 (int) (where
- where1
), where1
, type
));
575 _("Archive octal value %.*s is out of %s range"),
576 (int) (where
- where1
), where1
, type
));
580 else if (*where
== '-' || *where
== '+')
582 /* Parse base-64 output produced only by tar test versions
583 1.13.6 (1999-08-11) through 1.13.11 (1999-08-23).
584 Support for this will be withdrawn in future releases. */
586 static int warned_once
;
591 _("Archive contains obsolescent base-64 headers")));
593 negative
= *where
++ == '-';
595 && (dig
= base64_map
[(unsigned char) *where
]) < 64)
597 if (value
<< LG_64
>> LG_64
!= value
)
599 char *string
= alloca (digs
+ 1);
600 memcpy (string
, where0
, digs
);
604 _("Archive signed base-64 string %s is out of %s range"),
605 quote (string
), type
));
608 value
= (value
<< LG_64
) | dig
;
612 else if (*where
== '\200' /* positive base-256 */
613 || *where
== '\377' /* negative base-256 */)
615 /* Parse base-256 output. A nonnegative number N is
616 represented as (256**DIGS)/2 + N; a negative number -N is
617 represented as (256**DIGS) - N, i.e. as two's complement.
618 The representation guarantees that the leading bit is
619 always on, so that we don't confuse this format with the
620 others (assuming ASCII bytes of 8 bits or more). */
621 int signbit
= *where
& (1 << (LG_256
- 2));
622 uintmax_t topbits
= (((uintmax_t) - signbit
)
623 << (CHAR_BIT
* sizeof (uintmax_t)
624 - LG_256
- (LG_256
- 2)));
625 value
= (*where
++ & ((1 << (LG_256
- 2)) - 1)) - signbit
;
628 value
= (value
<< LG_256
) + (unsigned char) *where
++;
631 if (((value
<< LG_256
>> LG_256
) | topbits
) != value
)
635 _("Archive base-256 value is out of %s range"),
645 if (where
!= lim
&& *where
&& !ISSPACE ((unsigned char) *where
))
649 char buf
[1000]; /* Big enough to represent any header. */
650 static struct quoting_options
*o
;
654 o
= clone_quoting_options (0);
655 set_quoting_style (o
, locale_quoting_style
);
658 while (where0
!= lim
&& ! lim
[-1])
660 quotearg_buffer (buf
, sizeof buf
, where0
, lim
- where
, o
);
662 _("Archive contains %.*s where numeric %s value expected"),
663 (int) sizeof buf
, buf
, type
));
669 if (value
<= (negative
? minus_minval
: maxval
))
670 return negative
? -value
: value
;
674 char minval_buf
[UINTMAX_STRSIZE_BOUND
+ 1];
675 char maxval_buf
[UINTMAX_STRSIZE_BOUND
];
676 char value_buf
[UINTMAX_STRSIZE_BOUND
+ 1];
677 char *minval_string
= STRINGIFY_BIGINT (minus_minval
, minval_buf
+ 1);
678 char *value_string
= STRINGIFY_BIGINT (value
, value_buf
+ 1);
680 *--value_string
= '-';
682 *--minval_string
= '-';
683 ERROR ((0, 0, _("Archive value %s is out of %s range %s..%s"),
685 minval_string
, STRINGIFY_BIGINT (maxval
, maxval_buf
)));
692 gid_from_header (const char *p
, size_t s
)
694 return from_header (p
, s
, "gid_t",
695 - (uintmax_t) TYPE_MINIMUM (gid_t
),
696 (uintmax_t) TYPE_MAXIMUM (gid_t
));
700 major_from_header (const char *p
, size_t s
)
702 return from_header (p
, s
, "major_t",
703 - (uintmax_t) TYPE_MINIMUM (major_t
),
704 (uintmax_t) TYPE_MAXIMUM (major_t
));
708 minor_from_header (const char *p
, size_t s
)
710 return from_header (p
, s
, "minor_t",
711 - (uintmax_t) TYPE_MINIMUM (minor_t
),
712 (uintmax_t) TYPE_MAXIMUM (minor_t
));
716 mode_from_header (const char *p
, size_t s
)
718 /* Do not complain about unrecognized mode bits. */
719 unsigned u
= from_header (p
, s
, "mode_t",
720 - (uintmax_t) TYPE_MINIMUM (mode_t
),
721 TYPE_MAXIMUM (uintmax_t));
722 return ((u
& TSUID
? S_ISUID
: 0)
723 | (u
& TSGID
? S_ISGID
: 0)
724 | (u
& TSVTX
? S_ISVTX
: 0)
725 | (u
& TUREAD
? S_IRUSR
: 0)
726 | (u
& TUWRITE
? S_IWUSR
: 0)
727 | (u
& TUEXEC
? S_IXUSR
: 0)
728 | (u
& TGREAD
? S_IRGRP
: 0)
729 | (u
& TGWRITE
? S_IWGRP
: 0)
730 | (u
& TGEXEC
? S_IXGRP
: 0)
731 | (u
& TOREAD
? S_IROTH
: 0)
732 | (u
& TOWRITE
? S_IWOTH
: 0)
733 | (u
& TOEXEC
? S_IXOTH
: 0));
737 off_from_header (const char *p
, size_t s
)
739 /* Negative offsets are not allowed in tar files, so invoke
740 from_header with minimum value 0, not TYPE_MINIMUM (off_t). */
741 return from_header (p
, s
, "off_t", (uintmax_t) 0,
742 (uintmax_t) TYPE_MAXIMUM (off_t
));
746 size_from_header (const char *p
, size_t s
)
748 return from_header (p
, s
, "size_t", (uintmax_t) 0,
749 (uintmax_t) TYPE_MAXIMUM (size_t));
753 time_from_header (const char *p
, size_t s
)
755 return from_header (p
, s
, "time_t",
756 - (uintmax_t) TYPE_MINIMUM (time_t),
757 (uintmax_t) TYPE_MAXIMUM (time_t));
761 uid_from_header (const char *p
, size_t s
)
763 return from_header (p
, s
, "uid_t",
764 - (uintmax_t) TYPE_MINIMUM (uid_t
),
765 (uintmax_t) TYPE_MAXIMUM (uid_t
));
769 uintmax_from_header (const char *p
, size_t s
)
771 return from_header (p
, s
, "uintmax_t", (uintmax_t) 0,
772 TYPE_MAXIMUM (uintmax_t));
776 /* Format O as a null-terminated decimal string into BUF _backwards_;
777 return pointer to start of result. */
779 stringify_uintmax_t_backwards (uintmax_t o
, char *buf
)
783 *--buf
= '0' + (int) (o
% 10);
784 while ((o
/= 10) != 0);
788 /* Return a printable representation of T. The result points to
789 static storage that can be reused in the next call to this
790 function, to ctime, or to asctime. */
794 static char buffer
[max (UINTMAX_STRSIZE_BOUND
+ 1,
795 INT_STRLEN_BOUND (int) + 16)];
802 char const *time_stamp
= p
+ 4;
803 for (p
+= 16; p
[3] != '\n'; p
++)
809 /* Use ISO 8610 format. See:
810 http://www.cl.cam.ac.uk/~mgk25/iso-time.html */
811 struct tm
*tm
= localtime (&t
);
814 sprintf (buffer
, "%04d-%02d-%02d %02d:%02d:%02d",
815 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
816 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
821 /* The time stamp cannot be broken down, most likely because it
822 is out of range. Convert it as an integer,
823 right-adjusted in a field with the same width as the usual
824 19-byte 4-year ISO time format. */
825 p
= stringify_uintmax_t_backwards (t
< 0 ? - (uintmax_t) t
: (uintmax_t) t
,
826 buffer
+ sizeof buffer
);
829 while (buffer
+ sizeof buffer
- 19 - 1 < p
)
834 /* Actually print it.
836 Plain and fancy file header block logging. Non-verbose just prints
837 the name, e.g. for "tar t" or "tar x". This should just contain
838 file names, so it can be fed back into tar with xargs or the "-T"
839 option. The verbose option can give a bunch of info, one line per
840 file. I doubt anybody tries to parse its format, or if they do,
841 they shouldn't. Unix tar is pretty random here anyway. */
844 /* FIXME: Note that print_header uses the globals HEAD, HSTAT, and
845 HEAD_STANDARD, which must be set up in advance. Not very clean... */
847 /* UGSWIDTH starts with 18, so with user and group names <= 8 chars, the
848 columns never shift during the listing. */
850 static int ugswidth
= UGSWIDTH
; /* maximum width encountered so far */
852 /* DATEWIDTH is the number of columns taken by the date and time fields. */
854 # define DATEWIDTH 19
856 # define DATEWIDTH 18
863 char const *time_stamp
;
864 /* These hold formatted ints. */
865 char uform
[UINTMAX_STRSIZE_BOUND
], gform
[UINTMAX_STRSIZE_BOUND
];
867 char size
[2 * UINTMAX_STRSIZE_BOUND
];
868 /* holds formatted size or major,minor */
869 char uintbuf
[UINTMAX_STRSIZE_BOUND
];
872 if (block_number_option
)
874 char buf
[UINTMAX_STRSIZE_BOUND
];
875 fprintf (stdlis
, _("block %s: "),
876 STRINGIFY_BIGINT (current_block_ordinal (), buf
));
879 if (verbose_option
<= 1)
881 /* Just the fax, mam. */
882 fprintf (stdlis
, "%s\n", quotearg (current_file_name
));
886 /* File type and modes. */
889 switch (current_header
->header
.typeflag
)
895 case GNUTYPE_MULTIVOL
:
903 case GNUTYPE_LONGNAME
:
904 case GNUTYPE_LONGLINK
:
905 ERROR ((0, 0, _("Visible longname error")));
913 if (current_file_name
[strlen (current_file_name
) - 1] == '/')
916 case GNUTYPE_DUMPDIR
:
939 decode_mode (current_stat
.st_mode
, modes
+ 1);
943 time_stamp
= tartime (current_stat
.st_mtime
);
945 /* User and group names. */
947 if (*current_header
->header
.uname
&& current_format
!= V7_FORMAT
948 && !numeric_owner_option
)
949 user
= current_header
->header
.uname
;
952 /* Try parsing it as an unsigned integer first, and as a
953 uid_t if that fails. This method can list positive user
954 ids that are too large to fit in a uid_t. */
955 uintmax_t u
= from_header (current_header
->header
.uid
,
956 sizeof current_header
->header
.uid
, 0,
958 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
960 user
= STRINGIFY_BIGINT (u
, uform
);
963 sprintf (uform
, "%ld",
964 (long) UID_FROM_HEADER (current_header
->header
.uid
));
969 if (*current_header
->header
.gname
&& current_format
!= V7_FORMAT
970 && !numeric_owner_option
)
971 group
= current_header
->header
.gname
;
974 /* Try parsing it as an unsigned integer first, and as a
975 gid_t if that fails. This method can list positive group
976 ids that are too large to fit in a gid_t. */
977 uintmax_t g
= from_header (current_header
->header
.gid
,
978 sizeof current_header
->header
.gid
, 0,
980 (uintmax_t) TYPE_MAXIMUM (uintmax_t));
982 group
= STRINGIFY_BIGINT (g
, gform
);
985 sprintf (gform
, "%ld",
986 (long) GID_FROM_HEADER (current_header
->header
.gid
));
991 /* Format the file size or major/minor device numbers. */
993 switch (current_header
->header
.typeflag
)
998 STRINGIFY_BIGINT (major (current_stat
.st_rdev
), uintbuf
));
1001 STRINGIFY_BIGINT (minor (current_stat
.st_rdev
), uintbuf
));
1003 case GNUTYPE_SPARSE
:
1006 (UINTMAX_FROM_HEADER (current_header
1007 ->oldgnu_header
.realsize
),
1011 strcpy (size
, STRINGIFY_BIGINT (current_stat
.st_size
, uintbuf
));
1015 /* Figure out padding and print the whole line. */
1017 pad
= strlen (user
) + strlen (group
) + strlen (size
) + 1;
1021 fprintf (stdlis
, "%s %s/%s %*s%s %s",
1022 modes
, user
, group
, ugswidth
- pad
, "", size
, time_stamp
);
1024 fprintf (stdlis
, " %s", quotearg (current_file_name
));
1026 switch (current_header
->header
.typeflag
)
1029 fprintf (stdlis
, " -> %s\n", quotearg (current_link_name
));
1033 fprintf (stdlis
, _(" link to %s\n"), quotearg (current_link_name
));
1038 char type_string
[2];
1039 type_string
[0] = current_header
->header
.typeflag
;
1040 type_string
[1] = '\0';
1041 fprintf (stdlis
, _(" unknown file type %s\n"),
1042 quote (type_string
));
1048 case GNUTYPE_SPARSE
:
1054 case GNUTYPE_DUMPDIR
:
1055 putc ('\n', stdlis
);
1058 case GNUTYPE_VOLHDR
:
1059 fprintf (stdlis
, _("--Volume Header--\n"));
1062 case GNUTYPE_MULTIVOL
:
1065 (UINTMAX_FROM_HEADER (current_header
->oldgnu_header
.offset
),
1067 fprintf (stdlis
, _("--Continued at byte %s--\n"), size
);
1071 fprintf (stdlis
, _("--Mangled file names--\n"));
1078 /* Print a similar line when we make a directory automatically. */
1080 print_for_mkdir (char *pathname
, int length
, mode_t mode
)
1084 if (verbose_option
> 1)
1086 /* File type and modes. */
1089 decode_mode (mode
, modes
+ 1);
1091 if (block_number_option
)
1093 char buf
[UINTMAX_STRSIZE_BOUND
];
1094 fprintf (stdlis
, _("block %s: "),
1095 STRINGIFY_BIGINT (current_block_ordinal (), buf
));
1098 fprintf (stdlis
, "%s %*s %.*s\n", modes
, ugswidth
+ DATEWIDTH
,
1099 _("Creating directory:"), length
, quotearg (pathname
));
1103 /* Skip over SIZE bytes of data in blocks in the archive. */
1105 skip_file (off_t size
)
1109 if (multi_volume_option
)
1111 save_totsize
= size
;
1112 save_sizeleft
= size
;
1117 x
= find_next_block ();
1119 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1121 set_next_block_after (x
);
1123 if (multi_volume_option
)
1124 save_sizeleft
-= BLOCKSIZE
;
1128 /* Skip the current member in the archive. */
1132 char save_typeflag
= current_header
->header
.typeflag
;
1133 set_next_block_after (current_header
);
1135 if (current_header
->oldgnu_header
.isextended
)
1140 exhdr
= find_next_block ();
1142 FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
1143 set_next_block_after (exhdr
);
1145 while (exhdr
->sparse_header
.isextended
);
1148 if (save_typeflag
!= DIRTYPE
)
1149 skip_file (current_stat
.st_size
);