- if (head->header.linkflag != LF_MULTIVOL || strcmp (head->header.arch_name, real_s_name))
- {
- msg ("%s is not continued on this volume!", real_s_name);
- --volno;
- --global_volno;
- goto try_volume;
- }
- if (real_s_totsize != from_oct (1 + 12, head->header.size) + from_oct (1 + 12, head->header.offset))
- {
- msg ("%s is the wrong size (%ld!=%ld+%ld)",
- head->header.arch_name, save_totsize,
- from_oct (1 + 12, head->header.size),
- from_oct (1 + 12, head->header.offset));
- --volno;
- --global_volno;
- goto try_volume;
- }
- if (real_s_totsize - real_s_sizeleft != from_oct (1 + 12, head->header.offset))
- {
- msg ("This volume is out of sequence");
- --volno;
- --global_volno;
- goto try_volume;
- }
- head++;
- }
- ar_record = head;
- return;
+static bool
+try_new_volume (void)
+{
+ size_t status;
+ union block *header;
+ enum access_mode acc;
+
+ switch (subcommand_option)
+ {
+ case APPEND_SUBCOMMAND:
+ case CAT_SUBCOMMAND:
+ case UPDATE_SUBCOMMAND:
+ acc = ACCESS_UPDATE;
+ break;
+
+ default:
+ acc = ACCESS_READ;
+ break;
+ }
+
+ if (!new_volume (acc))
+ return true;
+
+ while ((status = rmtread (archive, record_start->buffer, record_size))
+ == SAFE_READ_ERROR)
+ archive_read_error ();
+
+ if (status != record_size)
+ short_read (status);
+
+ header = find_next_block ();
+ if (!header)
+ return false;
+
+ switch (header->header.typeflag)
+ {
+ case XGLTYPE:
+ {
+ tar_stat_init (&dummy);
+ if (read_header (&header, &dummy, read_header_x_global)
+ != HEADER_SUCCESS_EXTENDED)
+ {
+ ERROR ((0, 0, _("This does not look like a tar archive")));
+ return false;
+ }
+
+ xheader_decode (&dummy); /* decodes values from the global header */
+ tar_stat_destroy (&dummy);
+
+ /* The initial global header must be immediately followed by
+ an extended PAX header for the first member in this volume.
+ However, in some cases tar may split volumes in the middle
+ of a PAX header. This is incorrect, and should be fixed
+ in the future versions. In the meantime we must be
+ prepared to correctly list and extract such archives.
+
+ If this happens, the following call to read_header returns
+ HEADER_FAILURE, which is ignored.
+
+ See also tests/multiv07.at */
+
+ switch (read_header (&header, &dummy, read_header_auto))
+ {
+ case HEADER_SUCCESS:
+ set_next_block_after (header);
+ break;
+
+ case HEADER_FAILURE:
+ break;
+
+ default:
+ ERROR ((0, 0, _("This does not look like a tar archive")));
+ return false;
+ }
+ break;
+ }
+
+ case GNUTYPE_VOLHDR:
+ if (!read_header0 (&dummy))
+ return false;
+ tar_stat_destroy (&dummy);
+ assign_string (&volume_label, current_header->header.name);
+ set_next_block_after (header);
+ header = find_next_block ();
+ if (header->header.typeflag != GNUTYPE_MULTIVOL)
+ break;
+ /* FALL THROUGH */
+
+ case GNUTYPE_MULTIVOL:
+ if (!read_header0 (&dummy))
+ return false;
+ tar_stat_destroy (&dummy);
+ assign_string (&continued_file_name, current_header->header.name);
+ continued_file_size =
+ UINTMAX_FROM_HEADER (current_header->header.size);
+ continued_file_offset =
+ UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset);
+ break;
+
+ default:
+ break;