1 /* Create a tar archive.
3 Copyright (C) 1985, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
4 2003 Free Software Foundation, Inc.
6 Written by John Gilmore, on 1985-08-25.
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. */
47 /* The maximum uintmax_t value that can be represented with DIGITS digits,
48 assuming that each digit is BITS_PER_DIGIT wide. */
49 #define MAX_VAL_WITH_DIGITS(digits, bits_per_digit) \
50 ((digits) * (bits_per_digit) < sizeof (uintmax_t) * CHAR_BIT \
51 ? ((uintmax_t) 1 << ((digits) * (bits_per_digit))) - 1 \
54 /* Convert VALUE to an octal representation suitable for tar headers.
55 Output to buffer WHERE with size SIZE.
56 The result is undefined if SIZE is 0 or if VALUE is too large to fit. */
59 to_octal (uintmax_t value
, char *where
, size_t size
)
66 where
[--i
] = '0' + (v
& ((1 << LG_8
) - 1));
72 /* Convert NEGATIVE VALUE to a base-256 representation suitable for
73 tar headers. NEGATIVE is 1 if VALUE was negative before being cast
74 to uintmax_t, 0 otherwise. Output to buffer WHERE with size SIZE.
75 The result is undefined if SIZE is 0 or if VALUE is too large to
79 to_base256 (int negative
, uintmax_t value
, char *where
, size_t size
)
82 uintmax_t propagated_sign_bits
=
83 ((uintmax_t) - negative
<< (CHAR_BIT
* sizeof v
- LG_256
));
88 where
[--i
] = v
& ((1 << LG_256
) - 1);
89 v
= propagated_sign_bits
| (v
>> LG_256
);
94 /* Convert NEGATIVE VALUE (which was originally of size VALSIZE) to
95 external form, using SUBSTITUTE (...) if VALUE won't fit. Output
96 to buffer WHERE with size SIZE. NEGATIVE is 1 iff VALUE was
97 negative before being cast to uintmax_t; its original bitpattern
98 can be deduced from VALSIZE, its original size before casting.
99 TYPE is the kind of value being output (useful for diagnostics).
100 Prefer the POSIX format of SIZE - 1 octal digits (with leading zero
101 digits), followed by '\0'. If this won't work, and if GNU or
102 OLDGNU format is allowed, use '\200' followed by base-256, or (if
103 NEGATIVE is nonzero) '\377' followed by two's complement base-256.
104 If neither format works, use SUBSTITUTE (...) instead. Pass to
105 SUBSTITUTE the address of an 0-or-1 flag recording whether the
106 substitute value is negative. */
109 to_chars (int negative
, uintmax_t value
, size_t valsize
,
110 uintmax_t (*substitute
) (int *),
111 char *where
, size_t size
, const char *type
)
113 int base256_allowed
= (archive_format
== GNU_FORMAT
114 || archive_format
== OLDGNU_FORMAT
);
116 /* Generate the POSIX octal representation if the number fits. */
117 if (! negative
&& value
<= MAX_VAL_WITH_DIGITS (size
- 1, LG_8
))
119 where
[size
- 1] = '\0';
120 to_octal (value
, where
, size
- 1);
123 /* Otherwise, generate the base-256 representation if we are
124 generating an old or new GNU format and if the number fits. */
125 else if (((negative
? -1 - value
: value
)
126 <= MAX_VAL_WITH_DIGITS (size
- 1, LG_256
))
129 where
[0] = negative
? -1 : 1 << (LG_256
- 1);
130 to_base256 (negative
, value
, where
+ 1, size
- 1);
133 /* Otherwise, if the number is negative, and if it would not cause
134 ambiguity on this host by confusing positive with negative
135 values, then generate the POSIX octal representation of the value
136 modulo 2**(field bits). The resulting tar file is
137 machine-dependent, since it depends on the host word size. Yuck!
138 But this is the traditional behavior. */
139 else if (negative
&& valsize
* CHAR_BIT
<= (size
- 1) * LG_8
)
141 static int warned_once
;
145 WARN ((0, 0, _("Generating negative octal headers")));
147 where
[size
- 1] = '\0';
148 to_octal (value
& MAX_VAL_WITH_DIGITS (valsize
* CHAR_BIT
, 1),
152 /* Otherwise, output a substitute value if possible (with a
153 warning), and an error message if not. */
156 uintmax_t maxval
= (base256_allowed
157 ? MAX_VAL_WITH_DIGITS (size
- 1, LG_256
)
158 : MAX_VAL_WITH_DIGITS (size
- 1, LG_8
));
159 char valbuf
[UINTMAX_STRSIZE_BOUND
+ 1];
160 char maxbuf
[UINTMAX_STRSIZE_BOUND
];
161 char minbuf
[UINTMAX_STRSIZE_BOUND
+ 1];
162 char const *minval_string
;
163 char const *maxval_string
= STRINGIFY_BIGINT (maxval
, maxbuf
);
164 char const *value_string
;
168 uintmax_t m
= maxval
+ 1 ? maxval
+ 1 : maxval
/ 2 + 1;
169 char *p
= STRINGIFY_BIGINT (m
, minbuf
+ 1);
178 char *p
= STRINGIFY_BIGINT (- value
, valbuf
+ 1);
183 value_string
= STRINGIFY_BIGINT (value
, valbuf
);
188 uintmax_t sub
= substitute (&negsub
) & maxval
;
189 uintmax_t s
= (negsub
&= archive_format
== GNU_FORMAT
) ? - sub
: sub
;
190 char subbuf
[UINTMAX_STRSIZE_BOUND
+ 1];
191 char *sub_string
= STRINGIFY_BIGINT (s
, subbuf
+ 1);
194 WARN ((0, 0, _("value %s out of %s range %s..%s; substituting %s"),
195 value_string
, type
, minval_string
, maxval_string
,
197 to_chars (negsub
, s
, valsize
, 0, where
, size
, type
);
200 ERROR ((0, 0, _("value %s out of %s range %s..%s"),
201 value_string
, type
, minval_string
, maxval_string
));
206 gid_substitute (int *negative
)
212 static gid_t gid_nobody
;
213 if (!gid_nobody
&& !gname_to_gid ("nobody", &gid_nobody
))
222 gid_to_chars (gid_t v
, char *p
, size_t s
)
224 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, gid_substitute
, p
, s
, "gid_t");
228 major_to_chars (major_t v
, char *p
, size_t s
)
230 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, 0, p
, s
, "major_t");
234 minor_to_chars (minor_t v
, char *p
, size_t s
)
236 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, 0, p
, s
, "minor_t");
240 mode_to_chars (mode_t v
, char *p
, size_t s
)
242 /* In the common case where the internal and external mode bits are the same,
243 and we are not using POSIX or GNU format,
244 propagate all unknown bits to the external mode.
245 This matches historical practice.
246 Otherwise, just copy the bits we know about. */
249 if (S_ISUID
== TSUID
&& S_ISGID
== TSGID
&& S_ISVTX
== TSVTX
250 && S_IRUSR
== TUREAD
&& S_IWUSR
== TUWRITE
&& S_IXUSR
== TUEXEC
251 && S_IRGRP
== TGREAD
&& S_IWGRP
== TGWRITE
&& S_IXGRP
== TGEXEC
252 && S_IROTH
== TOREAD
&& S_IWOTH
== TOWRITE
&& S_IXOTH
== TOEXEC
253 && archive_format
!= POSIX_FORMAT
254 && archive_format
!= GNU_FORMAT
)
262 u
= ((v
& S_ISUID
? TSUID
: 0)
263 | (v
& S_ISGID
? TSGID
: 0)
264 | (v
& S_ISVTX
? TSVTX
: 0)
265 | (v
& S_IRUSR
? TUREAD
: 0)
266 | (v
& S_IWUSR
? TUWRITE
: 0)
267 | (v
& S_IXUSR
? TUEXEC
: 0)
268 | (v
& S_IRGRP
? TGREAD
: 0)
269 | (v
& S_IWGRP
? TGWRITE
: 0)
270 | (v
& S_IXGRP
? TGEXEC
: 0)
271 | (v
& S_IROTH
? TOREAD
: 0)
272 | (v
& S_IWOTH
? TOWRITE
: 0)
273 | (v
& S_IXOTH
? TOEXEC
: 0));
275 to_chars (negative
, u
, sizeof v
, 0, p
, s
, "mode_t");
279 off_to_chars (off_t v
, char *p
, size_t s
)
281 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, 0, p
, s
, "off_t");
285 size_to_chars (size_t v
, char *p
, size_t s
)
287 to_chars (0, (uintmax_t) v
, sizeof v
, 0, p
, s
, "size_t");
291 time_to_chars (time_t v
, char *p
, size_t s
)
293 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, 0, p
, s
, "time_t");
297 uid_substitute (int *negative
)
303 static uid_t uid_nobody
;
304 if (!uid_nobody
&& !uname_to_uid ("nobody", &uid_nobody
))
313 uid_to_chars (uid_t v
, char *p
, size_t s
)
315 to_chars (v
< 0, (uintmax_t) v
, sizeof v
, uid_substitute
, p
, s
, "uid_t");
319 uintmax_to_chars (uintmax_t v
, char *p
, size_t s
)
321 to_chars (0, v
, sizeof v
, 0, p
, s
, "uintmax_t");
325 string_to_chars (char *str
, char *p
, size_t s
)
332 /* Writing routines. */
334 /* Zero out the buffer so we don't confuse ourselves with leftover
337 clear_buffer (char *buffer
)
339 memset (buffer
, 0, BLOCKSIZE
);
342 /* Write the EOT block(s). Zero at least two blocks, through the end
343 of the record. Old tar, as previous versions of GNU tar, writes
344 garbage after two zeroed blocks. */
348 union block
*pointer
= find_next_block ();
349 memset (pointer
->buffer
, 0, BLOCKSIZE
);
350 set_next_block_after (pointer
);
351 pointer
= find_next_block ();
352 memset (pointer
->buffer
, 0, available_space_after (pointer
));
353 set_next_block_after (pointer
);
356 /* Write a "private" header */
358 start_private_header (const char *name
, size_t size
)
361 union block
*header
= find_next_block ();
363 memset (header
->buffer
, 0, sizeof (union block
));
365 strncpy (header
->header
.name
, name
, NAME_FIELD_SIZE
);
366 header
->header
.name
[NAME_FIELD_SIZE
- 1] = '\0';
367 OFF_TO_CHARS (size
, header
->header
.size
);
370 TIME_TO_CHARS (t
, header
->header
.mtime
);
371 MODE_TO_CHARS (S_IFREG
|S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
, header
->header
.mode
);
372 UID_TO_CHARS (getuid (), header
->header
.uid
);
373 GID_TO_CHARS (getgid (), header
->header
.gid
);
374 MAJOR_TO_CHARS (0, header
->header
.devmajor
);
375 MAJOR_TO_CHARS (0, header
->header
.devminor
);
376 strncpy (header
->header
.magic
, TMAGIC
, TMAGLEN
);
377 strncpy (header
->header
.version
, TVERSION
, TVERSLEN
);
381 /* Create a new header and store there at most NAME_FIELD_SIZE bytes of
385 write_short_name (struct tar_stat_info
*st
)
387 union block
*header
= find_next_block ();
388 memset (header
->buffer
, 0, sizeof (union block
));
390 strncpy (header
->header
.name
, st
->file_name
, NAME_FIELD_SIZE
);
391 header
->header
.name
[NAME_FIELD_SIZE
- 1] = '\0';
395 /* Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block. */
397 write_gnu_long_link (const char *p
, char type
)
399 size_t size
= strlen (p
) + 1;
403 header
= start_private_header ("././@LongLink", size
);
404 header
->header
.typeflag
= type
;
405 finish_header (header
, -1);
407 header
= find_next_block ();
409 bufsize
= available_space_after (header
);
411 while (bufsize
< size
)
413 memcpy (header
->buffer
, p
, bufsize
);
416 set_next_block_after (header
+ (bufsize
- 1) / BLOCKSIZE
);
417 header
= find_next_block ();
418 bufsize
= available_space_after (header
);
420 memcpy (header
->buffer
, p
, size
);
421 memset (header
->buffer
+ size
, 0, bufsize
- size
);
422 set_next_block_after (header
+ (size
- 1) / BLOCKSIZE
);
426 split_long_name (const char *name
, size_t length
)
430 if (length
> PREFIX_FIELD_SIZE
)
431 length
= PREFIX_FIELD_SIZE
+2;
432 for (i
= length
- 1; i
> 0; i
--)
433 if (ISSLASH (name
[i
]))
439 write_ustar_long_name (const char *name
)
441 size_t length
= strlen (name
);
445 if (length
> PREFIX_FIELD_SIZE
+ NAME_FIELD_SIZE
+ 1)
447 WARN ((0, 0, _("%s: file name is too long (max %d); not dumped"),
448 quotearg_colon (name
),
449 PREFIX_FIELD_SIZE
+ NAME_FIELD_SIZE
+ 1));
453 i
= split_long_name (name
, length
);
457 _("%s: file name is too long (cannot be split); not dumped"),
458 quotearg_colon (name
),
459 PREFIX_FIELD_SIZE
+ NAME_FIELD_SIZE
+ 1));
463 header
= find_next_block ();
464 memset (header
->buffer
, 0, sizeof (header
->buffer
));
465 memcpy (header
->header
.prefix
, name
, i
);
466 memcpy (header
->header
.name
, name
+ i
+ 1, length
- i
);
471 /* Write a long link name, depending on the current archive format */
473 write_long_link (struct tar_stat_info
*st
)
475 switch (archive_format
)
478 xheader_store ("linkpath", st
);
481 case V7_FORMAT
: /* old V7 tar format */
485 _("%s: link name is too long; not dumped"),
486 quotearg_colon (st
->link_name
)));
491 write_gnu_long_link (st
->link_name
, GNUTYPE_LONGLINK
);
500 write_long_name (struct tar_stat_info
*st
)
502 switch (archive_format
)
505 xheader_store ("path", st
);
511 return write_ustar_long_name (st
->file_name
);
515 write_gnu_long_link (st
->file_name
, GNUTYPE_LONGNAME
);
521 return write_short_name (st
);
525 write_extended (union block
*old_header
, char type
)
527 union block
*header
, hp
;
528 struct tar_stat_info foo
;
532 if (extended_header
.buffer
|| extended_header
.stk
== NULL
)
535 xheader_finish (&extended_header
);
536 size
= extended_header
.size
;
538 memcpy (hp
.buffer
, old_header
, sizeof (hp
));
540 header
= start_private_header ("././@PaxHeader", size
);
541 header
->header
.typeflag
= type
;
543 finish_header (header
, -1);
545 p
= extended_header
.buffer
;
551 header
= find_next_block ();
555 memcpy (header
->buffer
, p
, len
);
557 memset (header
->buffer
+ len
, 0, BLOCKSIZE
- len
);
560 set_next_block_after (header
);
564 xheader_destroy (&extended_header
);
565 header
= find_next_block ();
566 memcpy (header
, &hp
.buffer
, sizeof (hp
.buffer
));
571 write_header_name (struct tar_stat_info
*st
)
573 if (NAME_FIELD_SIZE
<= strlen (st
->file_name
))
574 return write_long_name (st
);
576 return write_short_name (st
);
580 /* Header handling. */
582 /* Make a header block for the file whose stat info is st,
583 and return its address. */
586 start_header (const char *name
, struct tar_stat_info
*st
)
590 name
= safer_name_suffix (name
, 0);
591 assign_string (&st
->file_name
, name
);
593 header
= write_header_name (st
);
597 assign_string (¤t_stat_info
.file_name
, name
);
599 /* Override some stat fields, if requested to do so. */
601 if (owner_option
!= (uid_t
) -1)
602 st
->stat
.st_uid
= owner_option
;
603 if (group_option
!= (gid_t
) -1)
604 st
->stat
.st_gid
= group_option
;
606 st
->stat
.st_mode
= ((st
->stat
.st_mode
& ~MODE_ALL
)
607 | mode_adjust (st
->stat
.st_mode
, mode_option
));
609 /* Paul Eggert tried the trivial test ($WRITER cf a b; $READER tvf a)
610 for a few tars and came up with the following interoperability
614 1 2 3 4 5 6 7 8 9 READER
615 . . . . . . . . . 1 = SunOS 4.2 tar
616 # . . # # . . # # 2 = NEC SVR4.0.2 tar
617 . . . # # . . # . 3 = Solaris 2.1 tar
618 . . . . . . . . . 4 = GNU tar 1.11.1
619 . . . . . . . . . 5 = HP-UX 8.07 tar
620 . . . . . . . . . 6 = Ultrix 4.1
621 . . . . . . . . . 7 = AIX 3.2
622 . . . . . . . . . 8 = Hitachi HI-UX 1.03
623 . . . . . . . . . 9 = Omron UNIOS-B 4.3BSD 1.60Beta
626 # = ``impossible file type''
628 The following mask for old archive removes the `#'s in column 4
629 above, thus making GNU tar both a universal donor and a universal
630 acceptor for Paul's test. */
632 if (archive_format
== V7_FORMAT
|| archive_format
== USTAR_FORMAT
)
633 MODE_TO_CHARS (st
->stat
.st_mode
& MODE_ALL
, header
->header
.mode
);
635 MODE_TO_CHARS (st
->stat
.st_mode
, header
->header
.mode
);
637 if (st
->stat
.st_uid
> MAXOCTAL7
&& archive_format
== POSIX_FORMAT
)
638 xheader_store ("uid", st
);
640 UID_TO_CHARS (st
->stat
.st_uid
, header
->header
.uid
);
642 if (st
->stat
.st_gid
> MAXOCTAL7
&& archive_format
== POSIX_FORMAT
)
643 xheader_store ("gid", st
);
645 GID_TO_CHARS (st
->stat
.st_gid
, header
->header
.gid
);
647 if (st
->stat
.st_size
> MAXOCTAL11
&& archive_format
== POSIX_FORMAT
)
648 xheader_store ("size", st
);
650 OFF_TO_CHARS (st
->stat
.st_size
, header
->header
.size
);
652 TIME_TO_CHARS (st
->stat
.st_mtime
, header
->header
.mtime
);
655 if (S_ISCHR (st
->stat
.st_mode
)
656 || S_ISBLK (st
->stat
.st_mode
))
658 st
->devmajor
= major (st
->stat
.st_rdev
);
659 st
->devminor
= minor (st
->stat
.st_rdev
);
661 if (st
->devmajor
> MAXOCTAL7
&& archive_format
== POSIX_FORMAT
)
662 xheader_store ("devmajor", st
);
664 MAJOR_TO_CHARS (st
->devmajor
, header
->header
.devmajor
);
666 if (st
->devminor
> MAXOCTAL7
&& archive_format
== POSIX_FORMAT
)
667 xheader_store ("devminor", st
);
669 MAJOR_TO_CHARS (st
->devminor
, header
->header
.devminor
);
673 MAJOR_TO_CHARS (0, header
->header
.devmajor
);
674 MINOR_TO_CHARS (0, header
->header
.devminor
);
677 if (archive_format
== POSIX_FORMAT
)
679 xheader_store ("atime", st
);
680 xheader_store ("ctime", st
);
682 else if (incremental_option
)
683 if (archive_format
== OLDGNU_FORMAT
)
685 TIME_TO_CHARS (st
->stat
.st_atime
, header
->oldgnu_header
.atime
);
686 TIME_TO_CHARS (st
->stat
.st_ctime
, header
->oldgnu_header
.ctime
);
689 header
->header
.typeflag
= archive_format
== V7_FORMAT
? AREGTYPE
: REGTYPE
;
691 switch (archive_format
)
697 /* Overwrite header->header.magic and header.version in one blow. */
698 strcpy (header
->header
.magic
, OLDGNU_MAGIC
);
703 case GNU_FORMAT
: /*FIXME?*/
704 strncpy (header
->header
.magic
, TMAGIC
, TMAGLEN
);
705 strncpy (header
->header
.version
, TVERSION
, TVERSLEN
);
712 if (archive_format
== V7_FORMAT
|| numeric_owner_option
)
714 /* header->header.[ug]name are left as the empty string. */
718 uid_to_uname (st
->stat
.st_uid
, &st
->uname
);
719 gid_to_gname (st
->stat
.st_gid
, &st
->gname
);
721 if (archive_format
== POSIX_FORMAT
722 && strlen (st
->uname
) > UNAME_FIELD_SIZE
)
723 xheader_store ("uname", st
);
725 UNAME_TO_CHARS (st
->uname
, header
->header
.uname
);
727 if (archive_format
== POSIX_FORMAT
728 && strlen (st
->gname
) > GNAME_FIELD_SIZE
)
729 xheader_store ("gname", st
);
731 GNAME_TO_CHARS (st
->gname
, header
->header
.gname
);
737 /* Finish off a filled-in header block and write it out. We also
738 print the file name and/or full info if verbose is on. If BLOCK_ORDINAL
739 is not negative, is the block ordinal of the first record for this
740 file, which may be a preceding long name or long link record. */
742 finish_header (union block
*header
, off_t block_ordinal
)
748 /* Note: It is important to do this before the call to write_extended(),
749 so that the actual ustar header is printed */
751 && header
->header
.typeflag
!= GNUTYPE_LONGLINK
752 && header
->header
.typeflag
!= GNUTYPE_LONGNAME
753 && header
->header
.typeflag
!= XHDTYPE
754 && header
->header
.typeflag
!= XGLTYPE
)
756 /* These globals are parameters to print_header, sigh. */
758 current_header
= header
;
759 /* current_stat_info is already set up. */
760 current_format
= archive_format
;
761 print_header (block_ordinal
);
764 header
= write_extended (header
, XHDTYPE
);
766 memcpy (header
->header
.chksum
, CHKBLANKS
, sizeof header
->header
.chksum
);
770 for (i
= sizeof *header
; i
-- != 0; )
771 /* We can't use unsigned char here because of old compilers, e.g. V7. */
774 /* Fill in the checksum field. It's formatted differently from the
775 other fields: it has [6] digits, a null, then a space -- rather than
776 digits, then a null. We use to_chars.
777 The final space is already there, from
778 checksumming, and to_chars doesn't modify it.
780 This is a fast way to do:
782 sprintf(header->header.chksum, "%6o", sum); */
784 uintmax_to_chars ((uintmax_t) sum
, header
->header
.chksum
, 7);
786 set_next_block_after (header
);
789 /* Sparse file processing. */
791 /* Takes a blockful of data and basically cruises through it to see if
792 it's made *entirely* of zeros, returning a 0 the instant it finds
793 something that is a nonzero, i.e., useful data. */
795 zero_block_p (char *buffer
)
799 for (counter
= 0; counter
< BLOCKSIZE
; counter
++)
800 if (buffer
[counter
] != '\0')
806 init_sparsearray (void)
809 sp_array_size
= SPARSES_IN_OLDGNU_HEADER
;
810 sparsearray
= xmalloc (sp_array_size
* sizeof *sparsearray
);
814 find_new_file_size (int sparses
)
818 for (i
= 0; i
< sparses
; i
++)
819 s
+= sparsearray
[i
].numbytes
;
823 /* Make one pass over the file NAME, studying where any non-zero data
824 is, that is, how far into the file each instance of data is, and
825 how many bytes are there. Save this information in the
826 sparsearray, which will later be translated into header
829 /* There is little point in trimming small amounts of null data at the head
830 and tail of blocks, only avoid dumping full null blocks. */
832 /* FIXME: this routine might accept bits of algorithmic cleanup, it is
833 too kludgey for my taste... */
836 deal_with_sparse (char *name
, union block
*header
)
843 char buffer
[BLOCKSIZE
];
845 if (archive_format
== OLDGNU_FORMAT
)
846 header
->oldgnu_header
.isextended
= 0;
848 if (file
= open (name
, O_RDONLY
), file
< 0)
849 /* This problem will be caught later on, so just return. */
853 clear_buffer (buffer
);
857 /* Realloc the scratch area as necessary. FIXME: should reallocate
858 only at beginning of a new instance of non-zero data. */
860 if (sp_array_size
<= sparses
)
863 xrealloc (sparsearray
,
864 2 * sp_array_size
* sizeof (struct sp_array
));
868 count
= safe_read (file
, buffer
, sizeof buffer
);
872 /* Process one block. */
874 if (count
== sizeof buffer
)
876 if (zero_block_p (buffer
))
880 sparsearray
[sparses
++].numbytes
= numbytes
;
887 sparsearray
[sparses
].offset
= offset
;
893 /* Since count < sizeof buffer, we have the last bit of the file. */
895 if (!zero_block_p (buffer
))
898 sparsearray
[sparses
].offset
= offset
;
902 /* The next two lines are suggested by Andreas Degert, who says
903 they are required for trailing full blocks to be written to the
904 archive, when all zeroed. Yet, it seems to me that the case
905 does not apply. Further, at restore time, the file is not as
906 sparse as it should. So, some serious cleanup is *also* needed
907 in this area. Just one more... :-(. FIXME. */
911 /* Prepare for next block. */
914 /* FIXME: do not clear unless necessary. */
915 clear_buffer (buffer
);
919 sparsearray
[sparses
++].numbytes
= numbytes
;
922 sparsearray
[sparses
].offset
= offset
- 1;
923 sparsearray
[sparses
++].numbytes
= 1;
926 return close (file
) == 0 && 0 <= count
? sparses
: 0;
930 finish_sparse_file (int file
, off_t
*sizeleft
, off_t fullsize
, char *name
)
937 while (*sizeleft
> 0)
939 start
= find_next_block ();
940 memset (start
->buffer
, 0, BLOCKSIZE
);
941 bufsize
= sparsearray
[sparses
].numbytes
;
945 if (lseek (file
, sparsearray
[sparses
++].offset
, SEEK_SET
) < 0)
947 (ignore_failed_read_option
? seek_warn_details
: seek_error_details
)
948 (name
, sparsearray
[sparses
- 1].offset
);
952 /* If the number of bytes to be written here exceeds the size of
953 the temporary buffer, do it in steps. */
955 while (bufsize
> BLOCKSIZE
)
957 count
= safe_read (file
, start
->buffer
, BLOCKSIZE
);
960 (ignore_failed_read_option
962 : read_error_details
)
963 (name
, fullsize
- *sizeleft
, bufsize
);
968 set_next_block_after (start
);
969 start
= find_next_block ();
970 memset (start
->buffer
, 0, BLOCKSIZE
);
974 char buffer
[BLOCKSIZE
];
976 clear_buffer (buffer
);
977 count
= safe_read (file
, buffer
, bufsize
);
978 memcpy (start
->buffer
, buffer
, BLOCKSIZE
);
983 (ignore_failed_read_option
985 : read_error_details
)
986 (name
, fullsize
- *sizeleft
, bufsize
);
991 set_next_block_after (start
);
995 set_next_block_after (start
+ (count
- 1) / BLOCKSIZE
);
1000 /* Main functions of this module. */
1003 create_archive (void)
1007 open_archive (ACCESS_WRITE
);
1009 if (incremental_option
)
1011 size_t buffer_size
= 1000;
1012 char *buffer
= xmalloc (buffer_size
);
1015 collect_and_sort_names ();
1017 while (p
= name_from_list (), p
)
1018 if (!excluded_name (p
))
1019 dump_file (p
, -1, (dev_t
) 0);
1022 while (p
= name_from_list (), p
)
1023 if (!excluded_name (p
))
1025 size_t plen
= strlen (p
);
1026 if (buffer_size
<= plen
)
1028 while ((buffer_size
*= 2) <= plen
)
1030 buffer
= xrealloc (buffer
, buffer_size
);
1032 memcpy (buffer
, p
, plen
);
1033 if (! ISSLASH (buffer
[plen
- 1]))
1034 buffer
[plen
++] = '/';
1035 q
= gnu_list_name
->dir_contents
;
1039 size_t qlen
= strlen (q
);
1042 if (buffer_size
< plen
+ qlen
)
1044 while ((buffer_size
*=2 ) < plen
+ qlen
)
1046 buffer
= xrealloc (buffer
, buffer_size
);
1048 strcpy (buffer
+ plen
, q
+ 1);
1049 dump_file (buffer
, -1, (dev_t
) 0);
1058 while (p
= name_next (1), p
)
1059 if (!excluded_name (p
))
1060 dump_file (p
, 1, (dev_t
) 0);
1066 if (listed_incremental_option
)
1067 write_directory_file ();
1071 /* Calculate the hash of a link. */
1073 hash_link (void const *entry
, unsigned n_buckets
)
1075 struct link
const *link
= entry
;
1076 return (uintmax_t) (link
->dev
^ link
->ino
) % n_buckets
;
1079 /* Compare two links for equality. */
1081 compare_links (void const *entry1
, void const *entry2
)
1083 struct link
const *link1
= entry1
;
1084 struct link
const *link2
= entry2
;
1085 return ((link1
->dev
^ link2
->dev
) | (link1
->ino
^ link2
->ino
)) == 0;
1088 /* Copy at most LEN bytes from SRC to DST. Terminate with NUL unless
1089 SRC is LEN characters long */
1091 tar_copy_str (char *dst
, const char *src
, size_t len
)
1094 strncpy (dst
, src
, len
);
1097 /* Table of all non-directories that we've written so far. Any time
1098 we see another, we check the table and avoid dumping the data
1099 again if we've done it once already. */
1100 static Hash_table
*link_table
;
1102 /* Dump a single file, recursing on directories. P is the file name
1103 to dump. TOP_LEVEL tells whether this is a top-level call; zero
1104 means no, positive means yes, and negative means the top level
1105 of an incremental dump. PARENT_DEVICE is the device of P's
1106 parent directory; it is examined only if TOP_LEVEL is zero.
1108 Set global CURRENT_STAT_INFO to stat output for this file. */
1110 /* FIXME: One should make sure that for *every* path leading to setting
1111 exit_status to failure, a clear diagnostic has been issued. */
1114 dump_file (char *p
, int top_level
, dev_t parent_device
)
1116 union block
*header
;
1120 time_t original_ctime
;
1121 struct utimbuf restore_times
;
1122 off_t block_ordinal
= -1;
1124 /* FIXME: `header' might be used uninitialized in this
1125 function. Reported by Bruno Haible. */
1127 if (interactive_option
&& !confirm ("add", p
))
1130 if (deref_stat (dereference_option
, p
, ¤t_stat_info
.stat
) != 0)
1132 if (ignore_failed_read_option
)
1139 original_ctime
= current_stat_info
.stat
.st_ctime
;
1140 restore_times
.actime
= current_stat_info
.stat
.st_atime
;
1141 restore_times
.modtime
= current_stat_info
.stat
.st_mtime
;
1144 if (S_ISHIDDEN (current_stat_info
.stat
.st_mode
))
1146 char *new = (char *) alloca (strlen (p
) + 2);
1156 /* See if we want only new files, and check if this one is too old to
1157 put in the archive. */
1159 if ((0 < top_level
|| !incremental_option
)
1160 && !S_ISDIR (current_stat_info
.stat
.st_mode
)
1161 && current_stat_info
.stat
.st_mtime
< newer_mtime_option
1162 && (!after_date_option
|| current_stat_info
.stat
.st_ctime
< newer_ctime_option
))
1165 WARN ((0, 0, _("%s: file is unchanged; not dumped"),
1166 quotearg_colon (p
)));
1167 /* FIXME: recheck this return. */
1171 /* See if we are trying to dump the archive. */
1172 if (sys_file_is_archive (¤t_stat_info
))
1174 WARN ((0, 0, _("%s: file is the archive; not dumped"),
1175 quotearg_colon (p
)));
1179 if (S_ISDIR (current_stat_info
.stat
.st_mode
))
1187 dev_t our_device
= current_stat_info
.stat
.st_dev
;
1191 directory
= savedir (p
);
1194 if (ignore_failed_read_option
)
1201 /* Build new prototype name. Ensure exactly one trailing slash. */
1204 buflen
= len
+ NAME_FIELD_SIZE
;
1205 namebuf
= xmalloc (buflen
+ 1);
1206 memcpy (namebuf
, p
, len
);
1207 while (len
>= 1 && ISSLASH (namebuf
[len
- 1]))
1209 namebuf
[len
++] = '/';
1210 namebuf
[len
] = '\0';
1212 if (! is_avoided_name (namebuf
))
1214 /* The condition above used to be "archive_format != V7_FORMAT".
1215 GNU tar was not writing directory blocks at all. Daniel Trinkle
1216 writes: ``All old versions of tar I have ever seen have
1217 correctly archived an empty directory. The really old ones I
1218 checked included HP-UX 7 and Mt. Xinu More/BSD. There may be
1219 some subtle reason for the exclusion that I don't know, but the
1220 current behavior is broken.'' I do not know those subtle
1221 reasons either, so until these are reported (anew?), just allow
1222 directory blocks to be written even with old archives. */
1224 block_ordinal
= current_block_ordinal ();
1225 current_stat_info
.stat
.st_size
= 0; /* force 0 size on dir */
1227 /* FIXME: If people could really read standard archives, this
1231 = start_header (standard_option ? p : namebuf, ¤t_stat_info);
1233 but since they'd interpret DIRTYPE blocks as regular
1234 files, we'd better put the / on the name. */
1236 header
= start_header (namebuf
, ¤t_stat_info
);
1240 if (incremental_option
)
1241 header
->header
.typeflag
= GNUTYPE_DUMPDIR
;
1242 else /* if (standard_option) */
1243 header
->header
.typeflag
= DIRTYPE
;
1245 /* If we're gnudumping, we aren't done yet so don't close it. */
1247 if (!incremental_option
)
1248 finish_header (header
, block_ordinal
);
1251 if (incremental_option
&& gnu_list_name
->dir_contents
)
1258 const char *buffer
, *p_buffer
;
1260 buffer
= gnu_list_name
->dir_contents
; /* FOO */
1263 for (p_buffer
= buffer
; *p_buffer
; )
1265 size_t size
= strlen (p_buffer
) + 1;
1270 OFF_TO_CHARS (totsize
, header
->header
.size
);
1271 finish_header (header
, block_ordinal
);
1274 while (sizeleft
> 0)
1276 if (multi_volume_option
)
1278 assign_string (&save_name
, p
);
1279 save_sizeleft
= sizeleft
;
1280 save_totsize
= totsize
;
1282 start
= find_next_block ();
1283 bufsize
= available_space_after (start
);
1284 if (sizeleft
< bufsize
)
1287 count
= bufsize
% BLOCKSIZE
;
1289 memset (start
->buffer
+ sizeleft
, 0, BLOCKSIZE
- count
);
1291 memcpy (start
->buffer
, p_buffer
, bufsize
);
1292 sizeleft
-= bufsize
;
1293 p_buffer
+= bufsize
;
1294 set_next_block_after (start
+ (bufsize
- 1) / BLOCKSIZE
);
1296 if (multi_volume_option
)
1297 assign_string (&save_name
, 0);
1301 /* See if we are about to recurse into a directory, and avoid doing
1302 so if the user wants that we do not descend into directories. */
1304 if (! recursion_option
)
1307 /* See if we are crossing from one file system to another, and
1308 avoid doing so if the user only wants to dump one file system. */
1310 if (one_file_system_option
&& !top_level
1311 && parent_device
!= current_stat_info
.stat
.st_dev
)
1315 _("%s: file is on a different filesystem; not dumped"),
1316 quotearg_colon (p
)));
1320 /* Now output all the files in the directory. */
1322 /* FIXME: Should speed this up by cd-ing into the dir. */
1324 for (entry
= directory
;
1325 (entrylen
= strlen (entry
)) != 0;
1326 entry
+= entrylen
+ 1)
1328 if (buflen
< len
+ entrylen
)
1330 buflen
= len
+ entrylen
;
1331 namebuf
= xrealloc (namebuf
, buflen
+ 1);
1333 strcpy (namebuf
+ len
, entry
);
1334 if (!excluded_name (namebuf
))
1335 dump_file (namebuf
, 0, our_device
);
1342 if (atime_preserve_option
)
1343 utime (p
, &restore_times
);
1346 else if (is_avoided_name (p
))
1350 /* Check for multiple links. */
1352 if (1 < current_stat_info
.stat
.st_nlink
&& link_table
)
1356 lp
.ino
= current_stat_info
.stat
.st_ino
;
1357 lp
.dev
= current_stat_info
.stat
.st_dev
;
1359 if ((dup
= hash_lookup (link_table
, &lp
)))
1361 /* We found a link. */
1362 char const *link_name
= safer_name_suffix (dup
->name
, 1);
1366 block_ordinal
= current_block_ordinal ();
1367 assign_string (¤t_stat_info
.link_name
, link_name
);
1368 if (NAME_FIELD_SIZE
< strlen (link_name
))
1369 write_long_link (¤t_stat_info
);
1371 current_stat_info
.stat
.st_size
= 0;
1372 header
= start_header (p
, ¤t_stat_info
);
1375 tar_copy_str (header
->header
.linkname
, link_name
,
1378 header
->header
.typeflag
= LNKTYPE
;
1379 finish_header (header
, block_ordinal
);
1381 /* FIXME: Maybe remove from table after all links found? */
1383 if (remove_files_option
&& unlink (p
) != 0)
1386 /* We dumped it, and we don't need to put it in the
1392 /* This is not a link to a previously dumped file, so dump it. */
1394 if (S_ISREG (current_stat_info
.stat
.st_mode
)
1395 || S_ISCTG (current_stat_info
.stat
.st_mode
))
1397 int f
; /* file descriptor */
1403 char isextended
= 0;
1410 /* Check the size of the file against the number of blocks
1411 allocated for it, counting both data and indirect blocks.
1412 If there is a smaller number of blocks than would be
1413 necessary to accommodate a file of this size, this is safe
1414 to say that we have a sparse file: at least one of those
1415 blocks in the file is just a useless hole. For sparse
1416 files not having more hole blocks than indirect blocks, the
1417 sparseness will go undetected. */
1419 /* Bruno Haible sent me these statistics for Linux. It seems
1420 that some filesystems count indirect blocks in st_blocks,
1421 while others do not seem to:
1423 minix-fs tar: size=7205, st_blocks=18 and ST_NBLOCKS=18
1424 extfs tar: size=7205, st_blocks=18 and ST_NBLOCKS=18
1425 ext2fs tar: size=7205, st_blocks=16 and ST_NBLOCKS=16
1426 msdos-fs tar: size=7205, st_blocks=16 and ST_NBLOCKS=16
1428 Dick Streefland reports the previous numbers as misleading,
1429 because ext2fs use 12 direct blocks, while minix-fs uses only
1430 6 direct blocks. Dick gets:
1432 ext2 size=20480 ls listed blocks=21
1433 minix size=20480 ls listed blocks=21
1434 msdos size=20480 ls listed blocks=20
1436 It seems that indirect blocks *are* included in st_blocks.
1437 The minix filesystem does not account for phantom blocks in
1438 st_blocks, so `du' and `ls -s' give wrong results. So, the
1439 --sparse option would not work on a minix filesystem. */
1441 if (ST_NBLOCKS (current_stat_info
.stat
)
1442 < (current_stat_info
.stat
.st_size
/ ST_NBLOCKSIZE
1443 + (current_stat_info
.stat
.st_size
% ST_NBLOCKSIZE
!= 0)))
1447 block_ordinal
= current_block_ordinal ();
1448 header
= start_header (p
, ¤t_stat_info
);
1451 header
->header
.typeflag
= GNUTYPE_SPARSE
;
1454 /* Call the routine that figures out the layout of the
1455 sparse file in question. SPARSES is the index of the
1456 first unused element of the "sparsearray," i.e.,
1457 the number of elements it needed to describe the file. */
1459 sparses
= deal_with_sparse (p
, header
);
1461 /* See if we'll need an extended header later. */
1463 if (SPARSES_IN_OLDGNU_HEADER
< sparses
)
1464 header
->oldgnu_header
.isextended
= 1;
1466 /* We store the "real" file size so we can show that in
1467 case someone wants to list the archive, i.e., tar tvf
1468 <file>. It might be kind of disconcerting if the
1469 shrunken file size was the one that showed up. */
1471 OFF_TO_CHARS (current_stat_info
.stat
.st_size
,
1472 header
->oldgnu_header
.realsize
);
1474 /* This will be the new "size" of the file, i.e., the size
1475 of the file minus the blocks of holes that we're
1478 current_stat_info
.stat
.st_size
= find_new_file_size (sparses
);
1479 OFF_TO_CHARS (current_stat_info
.stat
.st_size
, header
->header
.size
);
1482 counter
< sparses
&& counter
< SPARSES_IN_OLDGNU_HEADER
;
1485 OFF_TO_CHARS (sparsearray
[counter
].offset
,
1486 header
->oldgnu_header
.sp
[counter
].offset
);
1487 SIZE_TO_CHARS (sparsearray
[counter
].numbytes
,
1488 header
->oldgnu_header
.sp
[counter
].numbytes
);
1493 sizeleft
= current_stat_info
.stat
.st_size
;
1495 /* Don't bother opening empty, world readable files. Also do not open
1496 files when archive is meant for /dev/null. */
1500 && MODE_R
== (MODE_R
& current_stat_info
.stat
.st_mode
)))
1504 f
= open (p
, O_RDONLY
| O_BINARY
);
1507 if (! top_level
&& errno
== ENOENT
)
1508 WARN ((0, 0, _("%s: File removed before we read it"),
1509 quotearg_colon (p
)));
1511 (ignore_failed_read_option
? open_warn
: open_error
) (p
);
1516 /* If the file is sparse, we've already taken care of this. */
1520 block_ordinal
= current_block_ordinal ();
1521 header
= start_header (p
, ¤t_stat_info
);
1526 /* Mark contiguous files, if we support them. */
1528 if (archive_format
!= V7_FORMAT
1529 && S_ISCTG (current_stat_info
.stat
.st_mode
))
1530 header
->header
.typeflag
= CONTTYPE
;
1532 if (archive_format
== GNU_FORMAT
|| archive_format
== OLDGNU_FORMAT
)
1533 isextended
= header
->oldgnu_header
.isextended
;
1538 save_typeflag
= header
->header
.typeflag
;
1539 finish_header (header
, block_ordinal
);
1542 int sparses_emitted
= SPARSES_IN_OLDGNU_HEADER
;
1547 exhdr
= find_next_block ();
1548 memset (exhdr
->buffer
, 0, BLOCKSIZE
);
1550 (i
< SPARSES_IN_SPARSE_HEADER
1551 && sparses_emitted
+ i
< sparses
);
1554 SIZE_TO_CHARS (sparsearray
[sparses_emitted
+ i
].numbytes
,
1555 exhdr
->sparse_header
.sp
[i
].numbytes
);
1556 OFF_TO_CHARS (sparsearray
[sparses_emitted
+ i
].offset
,
1557 exhdr
->sparse_header
.sp
[i
].offset
);
1559 set_next_block_after (exhdr
);
1560 sparses_emitted
+= i
;
1561 if (sparses
== sparses_emitted
)
1563 exhdr
->sparse_header
.isextended
= 1;
1566 if (save_typeflag
== GNUTYPE_SPARSE
)
1569 || finish_sparse_file (f
, &sizeleft
,
1570 current_stat_info
.stat
.st_size
, p
))
1574 while (sizeleft
> 0)
1576 if (multi_volume_option
)
1578 assign_string (&save_name
, p
);
1579 save_sizeleft
= sizeleft
;
1580 save_totsize
= current_stat_info
.stat
.st_size
;
1582 start
= find_next_block ();
1584 bufsize
= available_space_after (start
);
1586 if (sizeleft
< bufsize
)
1588 /* Last read -- zero out area beyond. */
1591 count
= bufsize
% BLOCKSIZE
;
1593 memset (start
->buffer
+ sizeleft
, 0, BLOCKSIZE
- count
);
1598 count
= safe_read (f
, start
->buffer
, bufsize
);
1601 (ignore_failed_read_option
1603 : read_error_details
)
1604 (p
, current_stat_info
.stat
.st_size
- sizeleft
, bufsize
);
1609 /* This is nonportable (the type of set_next_block_after's arg). */
1611 set_next_block_after (start
+ (bufsize
- 1) / BLOCKSIZE
);
1614 if (count
!= bufsize
)
1616 char buf
[UINTMAX_STRSIZE_BOUND
];
1617 memset (start
->buffer
+ count
, 0, bufsize
- count
);
1619 ngettext ("%s: File shrank by %s byte; padding with zeros",
1620 "%s: File shrank by %s bytes; padding with zeros",
1623 STRINGIFY_BIGINT (sizeleft
, buf
)));
1624 if (! ignore_failed_read_option
)
1625 exit_status
= TAREXIT_FAILURE
;
1626 goto padit
; /* short read */
1630 if (multi_volume_option
)
1631 assign_string (&save_name
, 0);
1635 struct stat final_stat
;
1636 if (fstat (f
, &final_stat
) != 0)
1638 if (ignore_failed_read_option
)
1643 else if (final_stat
.st_ctime
!= original_ctime
)
1645 char const *qp
= quotearg_colon (p
);
1646 WARN ((0, 0, _("%s: file changed as we read it"), qp
));
1650 if (ignore_failed_read_option
)
1655 if (atime_preserve_option
)
1656 utime (p
, &restore_times
);
1658 if (remove_files_option
)
1660 if (unlink (p
) == -1)
1663 goto file_was_dumped
;
1665 /* File shrunk or gave error, pad out tape to match the size we
1666 specified in the header. */
1669 while (sizeleft
> 0)
1671 save_sizeleft
= sizeleft
;
1672 start
= find_next_block ();
1673 memset (start
->buffer
, 0, BLOCKSIZE
);
1674 set_next_block_after (start
);
1675 sizeleft
-= BLOCKSIZE
;
1677 if (multi_volume_option
)
1678 assign_string (&save_name
, 0);
1682 if (atime_preserve_option
)
1683 utime (p
, &restore_times
);
1685 goto file_was_dumped
;
1687 #ifdef HAVE_READLINK
1688 else if (S_ISLNK (current_stat_info
.stat
.st_mode
))
1692 size_t linklen
= current_stat_info
.stat
.st_size
;
1693 if (linklen
!= current_stat_info
.stat
.st_size
|| linklen
+ 1 == 0)
1695 buffer
= (char *) alloca (linklen
+ 1);
1696 size
= readlink (p
, buffer
, linklen
+ 1);
1699 if (ignore_failed_read_option
)
1705 buffer
[size
] = '\0';
1706 assign_string (¤t_stat_info
.link_name
, buffer
);
1707 if (size
> NAME_FIELD_SIZE
)
1708 write_long_link (¤t_stat_info
);
1710 block_ordinal
= current_block_ordinal ();
1711 current_stat_info
.stat
.st_size
= 0; /* force 0 size on symlink */
1712 header
= start_header (p
, ¤t_stat_info
);
1715 tar_copy_str (header
->header
.linkname
, buffer
, NAME_FIELD_SIZE
);
1716 header
->header
.typeflag
= SYMTYPE
;
1717 finish_header (header
, block_ordinal
);
1718 /* nothing more to do to it */
1720 if (remove_files_option
)
1722 if (unlink (p
) == -1)
1725 goto file_was_dumped
;
1728 else if (S_ISCHR (current_stat_info
.stat
.st_mode
))
1730 else if (S_ISBLK (current_stat_info
.stat
.st_mode
))
1732 else if (S_ISFIFO (current_stat_info
.stat
.st_mode
))
1734 else if (S_ISSOCK (current_stat_info
.stat
.st_mode
))
1736 WARN ((0, 0, _("%s: socket ignored"), quotearg_colon (p
)));
1739 else if (S_ISDOOR (current_stat_info
.stat
.st_mode
))
1741 WARN ((0, 0, _("%s: door ignored"), quotearg_colon (p
)));
1748 if (archive_format
== V7_FORMAT
)
1751 block_ordinal
= current_block_ordinal ();
1752 current_stat_info
.stat
.st_size
= 0; /* force 0 size */
1753 header
= start_header (p
, ¤t_stat_info
);
1756 header
->header
.typeflag
= type
;
1758 if (type
!= FIFOTYPE
)
1760 MAJOR_TO_CHARS (major (current_stat_info
.stat
.st_rdev
), header
->header
.devmajor
);
1761 MINOR_TO_CHARS (minor (current_stat_info
.stat
.st_rdev
), header
->header
.devminor
);
1764 finish_header (header
, block_ordinal
);
1765 if (remove_files_option
)
1767 if (unlink (p
) == -1)
1770 goto file_was_dumped
;
1773 WARN ((0, 0, _("%s: Unknown file type; file ignored"),
1774 quotearg_colon (p
)));
1775 if (! ignore_failed_read_option
)
1776 exit_status
= TAREXIT_FAILURE
;
1780 if (1 < current_stat_info
.stat
.st_nlink
)
1783 struct link
*lp
= xmalloc (offsetof (struct link
, name
)
1785 lp
->ino
= current_stat_info
.stat
.st_ino
;
1786 lp
->dev
= current_stat_info
.stat
.st_dev
;
1787 lp
->nlink
= current_stat_info
.stat
.st_nlink
;
1788 strcpy (lp
->name
, p
);
1791 || (link_table
= hash_initialize (0, 0, hash_link
,
1793 && (dup
= hash_insert (link_table
, lp
))))
1803 /* For each dumped file, check if all its links were dumped. Emit
1804 warnings if it is not so. */
1813 for (lp
= hash_get_first (link_table
); lp
;
1814 lp
= hash_get_next (link_table
, lp
))
1818 WARN ((0, 0, _("Missing links to '%s'.\n"), lp
->name
));