+ }
+ return current_block;
+}
+
+/* Indicate that we have used all blocks up thru BLOCK. */
+void
+set_next_block_after (union block *block)
+{
+ while (block >= current_block)
+ current_block++;
+
+ /* Do *not* flush the archive here. If we do, the same argument to
+ set_next_block_after could mean the next block (if the input record
+ is exactly one block long), which is not what is intended. */
+
+ if (current_block > record_end)
+ abort ();
+}
+
+/* Return the number of bytes comprising the space between POINTER
+ through the end of the current buffer of blocks. This space is
+ available for filling with data, or taking data from. POINTER is
+ usually (but not always) the result of previous find_next_block call. */
+size_t
+available_space_after (union block *pointer)
+{
+ return record_end->buffer - pointer->buffer;
+}
+
+/* Close file having descriptor FD, and abort if close unsuccessful. */
+void
+xclose (int fd)
+{
+ if (close (fd) != 0)
+ close_error (_("(pipe)"));
+}
+
+static void
+init_buffer ()
+{
+ if (! record_buffer_aligned[record_index])
+ record_buffer_aligned[record_index] =
+ page_aligned_alloc (&record_buffer[record_index], record_size);
+
+ record_start = record_buffer_aligned[record_index];
+ current_block = record_start;
+ record_end = record_start + blocking_factor;
+}
+
+/* Open an archive file. The argument specifies whether we are
+ reading or writing, or both. */
+static void
+_open_archive (enum access_mode wanted_access)
+{
+ int backed_up_flag = 0;
+
+ if (record_size == 0)
+ FATAL_ERROR ((0, 0, _("Invalid value for record_size")));
+
+ if (archive_names == 0)
+ FATAL_ERROR ((0, 0, _("No archive name given")));
+
+ tar_stat_destroy (¤t_stat_info);
+ save_name = 0;
+ real_s_name = 0;
+
+ record_index = 0;
+ init_buffer ();
+
+ /* When updating the archive, we start with reading. */
+ access_mode = wanted_access == ACCESS_UPDATE ? ACCESS_READ : wanted_access;
+
+ read_full_records = read_full_records_option;
+
+ records_read = 0;
+
+ if (use_compress_program_option)
+ {
+ switch (wanted_access)