Lines Matching defs:tar

51  * Layout of POSIX 'ustar' tar header.
73 * Structure of GNU tar header
119 struct tar {
158 static int gnu_add_sparse_entry(struct archive_read *, struct tar *,
161 static void gnu_clear_sparse_list(struct tar *);
162 static int gnu_sparse_old_read(struct archive_read *, struct tar *,
164 static int gnu_sparse_old_parse(struct archive_read *, struct tar *,
166 static int gnu_sparse_01_parse(struct archive_read *, struct tar *,
168 static ssize_t gnu_sparse_10_read(struct archive_read *, struct tar *,
170 static int header_Solaris_ACL(struct archive_read *, struct tar *,
172 static int header_common(struct archive_read *, struct tar *,
174 static int header_old_tar(struct archive_read *, struct tar *,
176 static int header_pax_extensions(struct archive_read *, struct tar *,
178 static int header_pax_global(struct archive_read *, struct tar *,
180 static int header_longlink(struct archive_read *, struct tar *,
182 static int header_longname(struct archive_read *, struct tar *,
184 static int read_mac_metadata_blob(struct archive_read *, struct tar *,
186 static int header_volume(struct archive_read *, struct tar *,
188 static int header_ustar(struct archive_read *, struct tar *,
190 static int header_gnutar(struct archive_read *, struct tar *,
202 static int pax_attribute(struct archive_read *, struct tar *,
204 static int pax_header(struct archive_read *, struct tar *,
207 static ssize_t readline(struct archive_read *, struct tar *, const char **,
209 static int read_body_to_string(struct archive_read *, struct tar *,
211 static int solaris_sparse_parse(struct archive_read *, struct tar *,
217 static int tar_read_header(struct archive_read *, struct tar *,
237 struct tar *tar;
243 tar = (struct tar *)calloc(1, sizeof(*tar));
244 if (tar == NULL) {
246 "Can't allocate tar data");
250 r = __archive_read_register_format(a, tar, "tar",
260 free(tar);
267 struct tar *tar;
269 tar = (struct tar *)(a->format->data);
270 gnu_clear_sparse_list(tar);
271 archive_string_free(&tar->acl_text);
272 archive_string_free(&tar->entry_pathname);
273 archive_string_free(&tar->entry_pathname_override);
274 archive_string_free(&tar->entry_linkpath);
275 archive_string_free(&tar->entry_uname);
276 archive_string_free(&tar->entry_gname);
277 archive_string_free(&tar->line);
278 archive_string_free(&tar->pax_global);
279 archive_string_free(&tar->pax_header);
280 archive_string_free(&tar->longname);
281 archive_string_free(&tar->longlink);
282 archive_string_free(&tar->localname);
283 free(tar);
327 /* Recognize GNU tar format. */
365 struct tar *tar;
368 tar = (struct tar *)(a->format->data);
371 tar->compat_2x = (val != NULL)?1:0;
372 tar->init_default_conversion = tar->compat_2x;
377 "tar: hdrcharset option needs a character-set name");
379 tar->opt_sconv =
382 if (tar->opt_sconv != NULL)
428 * When converting tar archives to cpio archives, it is
431 * assign fake dev/inode numbers to each tar entry. Note that
439 * obscure tar->cpio conversion case.
443 struct tar *tar;
457 tar = (struct tar *)(a->format->data);
458 tar->entry_offset = 0;
459 gnu_clear_sparse_list(tar);
460 tar->realsize = -1; /* Mark this as "unset" */
463 tar->sconv = tar->opt_sconv;
464 if (tar->sconv == NULL) {
465 if (!tar->init_default_conversion) {
466 tar->sconv_default =
468 tar->init_default_conversion = 1;
470 tar->sconv = tar->sconv_default;
473 r = tar_read_header(a, tar, entry, &unconsumed);
481 if (tar->sparse_list == NULL) {
482 if (gnu_add_sparse_entry(a, tar, 0, tar->entry_bytes_remaining)
488 for (sb = tar->sparse_list; sb != NULL; sb = sb->next) {
498 * directory: This is needed for certain old tar
526 struct tar *tar;
529 tar = (struct tar *)(a->format->data);
533 while (tar->sparse_list != NULL &&
534 tar->sparse_list->remaining == 0) {
535 p = tar->sparse_list;
536 tar->sparse_list = p->next;
540 if (tar->entry_bytes_unconsumed) {
541 __archive_read_consume(a, tar->entry_bytes_unconsumed);
542 tar->entry_bytes_unconsumed = 0;
546 if (tar->sparse_list == NULL ||
547 tar->entry_bytes_remaining == 0) {
548 if (__archive_read_consume(a, tar->entry_padding) < 0)
550 tar->entry_padding = 0;
553 *offset = tar->realsize;
562 "Truncated tar archive");
565 if (bytes_read > tar->entry_bytes_remaining)
566 bytes_read = (ssize_t)tar->entry_bytes_remaining;
569 if (tar->sparse_list->remaining < bytes_read)
570 bytes_read = (ssize_t)tar->sparse_list->remaining;
572 *offset = tar->sparse_list->offset;
573 tar->sparse_list->remaining -= bytes_read;
574 tar->sparse_list->offset += bytes_read;
575 tar->entry_bytes_remaining -= bytes_read;
576 tar->entry_bytes_unconsumed = bytes_read;
578 if (!tar->sparse_list->hole)
588 struct tar* tar;
590 tar = (struct tar *)(a->format->data);
593 tar->entry_bytes_remaining + tar->entry_padding +
594 tar->entry_bytes_unconsumed);
598 tar->entry_bytes_remaining = 0;
599 tar->entry_bytes_unconsumed = 0;
600 tar->entry_padding = 0;
603 gnu_clear_sparse_list(tar);
613 tar_read_header(struct archive_read *a, struct tar *tar,
634 "Truncated tar archive");
649 a->archive.archive_format_name = "tar";
663 archive_set_error(&a->archive, EINVAL, "Damaged tar archive");
667 if (++tar->header_recursion_depth > 32) {
677 case 'A': /* Solaris tar ACL */
679 a->archive.archive_format_name = "Solaris tar";
680 err = header_Solaris_ACL(a, tar, entry, h, unconsumed);
685 err = header_pax_global(a, tar, entry, h, unconsumed);
687 case 'K': /* Long link name (GNU tar, others) */
688 err = header_longlink(a, tar, entry, h, unconsumed);
690 case 'L': /* Long filename (GNU tar, others) */
691 err = header_longname(a, tar, entry, h, unconsumed);
694 err = header_volume(a, tar, entry, h, unconsumed);
696 case 'X': /* Used by SUN tar; same as 'x'. */
700 err = header_pax_extensions(a, tar, entry, h, unconsumed);
705 err = header_pax_extensions(a, tar, entry, h, unconsumed);
711 a->archive.archive_format_name = "GNU tar format";
712 err = header_gnutar(a, tar, entry, h, unconsumed);
718 err = header_ustar(a, tar, entry, h);
721 a->archive.archive_format_name = "tar (non-POSIX)";
722 err = header_old_tar(a, tar, entry, h);
733 --tar->header_recursion_depth;
740 tar->header_recursion_depth == 0) {
741 int err2 = read_mac_metadata_blob(a, tar, entry, h, unconsumed);
748 if (tar->sparse_gnu_pending) {
749 if (tar->sparse_gnu_major == 1 &&
750 tar->sparse_gnu_minor == 0) {
753 tar->sparse_gnu_pending = 0;
755 bytes_read = gnu_sparse_10_read(a, tar, unconsumed);
756 tar->entry_bytes_remaining -= bytes_read;
765 tar->sparse_gnu_pending = 0;
771 archive_set_error(&a->archive, EINVAL, "Damaged tar archive");
806 * was created by an old BSD, Solaris, or HP-UX tar with a
840 header_Solaris_ACL(struct archive_read *a, struct tar *tar,
855 err = read_body_to_string(a, tar, &(tar->acl_text), h, unconsumed);
860 err = tar_read_header(a, tar, entry, unconsumed);
870 p = acl = tar->acl_text.s;
916 if (tar->sconv_acl == NULL) {
917 tar->sconv_acl = archive_string_conversion_from_charset(
919 if (tar->sconv_acl == NULL)
922 archive_strncpy(&(tar->localname), acl, p - acl);
924 tar->localname.s, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, tar->sconv_acl);
940 header_longlink(struct archive_read *a, struct tar *tar,
945 err = read_body_to_string(a, tar, &(tar->longlink), h, unconsumed);
948 err = tar_read_header(a, tar, entry, unconsumed);
952 archive_entry_copy_link(entry, tar->longlink.s);
975 header_longname(struct archive_read *a, struct tar *tar,
980 err = read_body_to_string(a, tar, &(tar->longname), h, unconsumed);
984 err = tar_read_header(a, tar, entry, unconsumed);
987 if (archive_entry_copy_pathname_l(entry, tar->longname.s,
988 archive_strlen(&(tar->longname)), tar->sconv) != 0)
989 err = set_conversion_failed_error(a, tar->sconv, "Pathname");
995 * Interpret 'V' GNU tar volume header.
998 header_volume(struct archive_read *a, struct tar *tar,
1004 return (tar_read_header(a, tar, entry, unconsumed));
1011 read_body_to_string(struct archive_read *a, struct tar *tar,
1018 (void)tar; /* UNUSED */
1060 header_common(struct archive_read *a, struct tar *tar,
1069 archive_strncpy(&(tar->entry_linkpath),
1072 archive_string_empty(&(tar->entry_linkpath));
1079 tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size));
1080 if (tar->entry_bytes_remaining < 0) {
1081 tar->entry_bytes_remaining = 0;
1086 tar->realsize = tar->entry_bytes_remaining;
1087 archive_entry_set_size(entry, tar->entry_bytes_remaining);
1090 /* Handle the tar type flag appropriately. */
1095 if (archive_entry_copy_hardlink_l(entry, tar->entry_linkpath.s,
1096 archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) {
1097 err = set_conversion_failed_error(a, tar->sconv,
1103 * The following may seem odd, but: Technically, tar
1115 * A tricky point: Traditionally, tar readers have
1135 /* Old-style or GNU tar: we must ignore the size. */
1137 tar->entry_bytes_remaining = 0;
1146 tar->entry_bytes_remaining = 0;
1154 * a body containing an uncompressed tar archive.
1162 tar->entry_bytes_remaining = 0;
1163 if (archive_entry_copy_symlink_l(entry, tar->entry_linkpath.s,
1164 archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) {
1165 err = set_conversion_failed_error(a, tar->sconv,
1174 tar->entry_bytes_remaining = 0;
1179 tar->entry_bytes_remaining = 0;
1184 tar->entry_bytes_remaining = 0;
1189 tar->entry_bytes_remaining = 0;
1231 * Parse out header elements for "old-style" tar archives.
1234 header_old_tar(struct archive_read *a, struct tar *tar,
1243 header->name, sizeof(header->name), tar->sconv) != 0) {
1244 err = set_conversion_failed_error(a, tar->sconv, "Pathname");
1250 err2 = header_common(a, tar, entry, h);
1254 tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
1263 read_mac_metadata_blob(struct archive_read *a, struct tar *tar,
1326 return (tar_read_header(a, tar, entry, unconsumed));
1333 header_pax_global(struct archive_read *a, struct tar *tar,
1338 err = read_body_to_string(a, tar, &(tar->pax_global), h, unconsumed);
1341 err = tar_read_header(a, tar, entry, unconsumed);
1346 header_pax_extensions(struct archive_read *a, struct tar *tar,
1351 err = read_body_to_string(a, tar, &(tar->pax_header), h, unconsumed);
1356 err = tar_read_header(a, tar, entry, unconsumed);
1370 err2 = pax_header(a, tar, entry, tar->pax_header.s);
1372 tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
1382 header_ustar(struct archive_read *a, struct tar *tar,
1392 as = &(tar->entry_pathname);
1402 tar->sconv) != 0) {
1403 err = set_conversion_failed_error(a, tar->sconv, "Pathname");
1409 r = header_common(a, tar, entry, h);
1417 header->uname, sizeof(header->uname), tar->sconv) != 0) {
1418 err = set_conversion_failed_error(a, tar->sconv, "Uname");
1424 header->gname, sizeof(header->gname), tar->sconv) != 0) {
1425 err = set_conversion_failed_error(a, tar->sconv, "Gname");
1438 tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
1450 pax_header(struct archive_read *a, struct tar *tar,
1461 tar->pax_hdrcharset_binary = 0;
1462 archive_string_empty(&(tar->entry_gname));
1463 archive_string_empty(&(tar->entry_linkpath));
1464 archive_string_empty(&(tar->entry_pathname));
1465 archive_string_empty(&(tar->entry_pathname_override));
1466 archive_string_empty(&(tar->entry_uname));
1529 err2 = pax_attribute(a, tar, entry, key, value);
1548 if (tar->pax_hdrcharset_binary)
1549 sconv = tar->opt_sconv;
1555 if (tar->compat_2x)
1560 if (archive_strlen(&(tar->entry_gname)) > 0) {
1561 if (archive_entry_copy_gname_l(entry, tar->entry_gname.s,
1562 archive_strlen(&(tar->entry_gname)), sconv) != 0) {
1567 archive_entry_copy_gname(entry, tar->entry_gname.s);
1570 if (archive_strlen(&(tar->entry_linkpath)) > 0) {
1571 if (archive_entry_copy_link_l(entry, tar->entry_linkpath.s,
1572 archive_strlen(&(tar->entry_linkpath)), sconv) != 0) {
1577 archive_entry_copy_link(entry, tar->entry_linkpath.s);
1590 if (archive_strlen(&(tar->entry_pathname_override)) > 0)
1591 as = &(tar->entry_pathname_override);
1592 else if (archive_strlen(&(tar->entry_pathname)) > 0)
1593 as = &(tar->entry_pathname);
1604 if (archive_strlen(&(tar->entry_uname)) > 0) {
1605 if (archive_entry_copy_uname_l(entry, tar->entry_uname.s,
1606 archive_strlen(&(tar->entry_uname)), sconv) != 0) {
1611 archive_entry_copy_uname(entry, tar->entry_uname.s);
1664 pax_attribute(struct archive_read *a, struct tar *tar,
1680 tar->sparse_offset = -1;
1681 tar->sparse_numbytes = -1;
1682 tar->sparse_gnu_major = 0;
1683 tar->sparse_gnu_minor = 0;
1686 tar->sparse_offset = tar_atol10(value, strlen(value));
1687 if (tar->sparse_numbytes != -1) {
1688 if (gnu_add_sparse_entry(a, tar,
1689 tar->sparse_offset, tar->sparse_numbytes)
1692 tar->sparse_offset = -1;
1693 tar->sparse_numbytes = -1;
1697 tar->sparse_numbytes = tar_atol10(value, strlen(value));
1698 if (tar->sparse_numbytes != -1) {
1699 if (gnu_add_sparse_entry(a, tar,
1700 tar->sparse_offset, tar->sparse_numbytes)
1703 tar->sparse_offset = -1;
1704 tar->sparse_numbytes = -1;
1708 tar->realsize = tar_atol10(value, strlen(value));
1709 archive_entry_set_size(entry, tar->realsize);
1714 tar->sparse_gnu_major = 0;
1715 tar->sparse_gnu_minor = 1;
1716 if (gnu_sparse_01_parse(a, tar, value) != ARCHIVE_OK)
1722 tar->sparse_gnu_major = (int)tar_atol10(value, strlen(value));
1723 tar->sparse_gnu_pending = 1;
1726 tar->sparse_gnu_minor = (int)tar_atol10(value, strlen(value));
1727 tar->sparse_gnu_pending = 1;
1732 * files, GNU tar puts a synthesized name into
1736 archive_strcpy(&(tar->entry_pathname_override), value);
1739 tar->realsize = tar_atol10(value, strlen(value));
1740 archive_entry_set_size(entry, tar->realsize);
1760 if (tar->sconv_acl == NULL) {
1761 tar->sconv_acl =
1764 if (tar->sconv_acl == NULL)
1770 tar->sconv_acl);
1784 if (tar->sconv_acl == NULL) {
1785 tar->sconv_acl =
1788 if (tar->sconv_acl == NULL)
1794 tar->sconv_acl);
1825 tar->realsize = tar_atol10(value, strlen(value));
1826 archive_entry_set_size(entry, tar->realsize);
1829 r = solaris_sparse_parse(a, tar, entry, value);
1861 archive_strcpy(&(tar->entry_gname), value);
1868 tar->pax_hdrcharset_binary = 1;
1870 tar->pax_hdrcharset_binary = 0;
1876 archive_strcpy(&(tar->entry_linkpath), value);
1887 archive_strcpy(&(tar->entry_pathname), value);
1898 tar->entry_bytes_remaining
1908 if (tar->realsize < 0) {
1910 tar->entry_bytes_remaining);
1911 tar->realsize
1912 = tar->entry_bytes_remaining;
1921 archive_strcpy(&(tar->entry_uname), value);
1981 * Parse GNU tar header
1984 header_gnutar(struct archive_read *a, struct tar *tar,
1997 /* Grab fields common to all tar variants. */
1998 err = header_common(a, tar, entry, h);
2005 header->name, sizeof(header->name), tar->sconv) != 0) {
2006 err = set_conversion_failed_error(a, tar->sconv, "Pathname");
2013 * to ustar and gnu tar? Is it okay to move it down into
2016 header->uname, sizeof(header->uname), tar->sconv) != 0) {
2017 err = set_conversion_failed_error(a, tar->sconv, "Uname");
2023 header->gname, sizeof(header->gname), tar->sconv) != 0) {
2024 err = set_conversion_failed_error(a, tar->sconv, "Gname");
2038 tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining);
2049 tar->realsize
2051 archive_entry_set_size(entry, tar->realsize);
2055 if (gnu_sparse_old_read(a, tar, header, unconsumed)
2068 gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
2079 if (tar->sparse_last != NULL)
2080 tar->sparse_last->next = p;
2082 tar->sparse_list = p;
2083 tar->sparse_last = p;
2090 gnu_clear_sparse_list(struct tar *tar)
2094 while (tar->sparse_list != NULL) {
2095 p = tar->sparse_list;
2096 tar->sparse_list = p->next;
2099 tar->sparse_last = NULL;
2103 * GNU tar old-format sparse data.
2110 * severe POSIX violation; this design has earned GNU tar a
2115 gnu_sparse_old_read(struct archive_read *a, struct tar *tar,
2127 if (gnu_sparse_old_parse(a, tar, header->sparse, 4) != ARCHIVE_OK)
2139 "Truncated tar archive "
2145 if (gnu_sparse_old_parse(a, tar, ext->sparse, 21) != ARCHIVE_OK)
2148 if (tar->sparse_list != NULL)
2149 tar->entry_offset = tar->sparse_list->offset;
2154 gnu_sparse_old_parse(struct archive_read *a, struct tar *tar,
2158 if (gnu_add_sparse_entry(a, tar,
2170 * GNU tar sparse format 0.0
2172 * Beginning with GNU tar 1.15, sparse files are stored using
2173 * information in the pax extended header. The GNU tar maintainers
2185 * GNU tar sparse format 0.1
2196 gnu_sparse_01_parse(struct archive_read *a, struct tar *tar, const char *p)
2216 if (gnu_add_sparse_entry(a, tar, offset, size)
2228 * GNU tar sparse format 1.0
2235 * Unfortunately, GNU tar 1.16 had a bug that added unnecessary
2236 * padding to the body of the file when using this format. GNU tar
2251 gnu_sparse_10_atol(struct archive_read *a, struct tar *tar,
2264 * Skip any lines starting with '#'; GNU tar specs
2268 bytes_read = readline(a, tar, &p,
2298 gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed)
2305 gnu_clear_sparse_list(tar);
2307 remaining = tar->entry_bytes_remaining;
2310 entries = (int)gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
2316 offset = gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
2319 size = gnu_sparse_10_atol(a, tar, &remaining, unconsumed);
2323 if (gnu_add_sparse_entry(a, tar, offset, size) != ARCHIVE_OK)
2328 bytes_read = (ssize_t)(tar->entry_bytes_remaining - remaining);
2342 solaris_sparse_parse(struct archive_read *a, struct tar *tar,
2368 if (gnu_add_sparse_entry(a, tar, start,
2371 tar->sparse_last->hole = hole;
2383 * Traditional tar formats (including POSIX) specify base-8 for
2392 * = GNU tar and STAR both allow either base-8 or base-256 in
2401 * Technically, GNU tar considers a field to be in base-256
2506 readline(struct archive_read *a, struct tar *tar, const char **start,
2544 if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) {
2549 memcpy(tar->line.s + total_size, t, bytes_read);
2554 *start = tar->line.s;