+ enum compress_type type = check_compressed_archive ();
+
+ if (type == ct_none)
+ return archive;
+
+ /* FD is not needed any more */
+ rmtclose (archive);
+
+ hit_eof = false; /* It might have been set by find_next_block in
+ check_compressed_archive */
+
+ /* Open compressed archive */
+ use_compress_program_option = compress_program (type);
+ child_pid = sys_child_open_for_uncompress ();
+ read_full_records = true;
+ }
+
+ records_read = 0;
+ record_end = record_start; /* set up for 1st record = # 0 */
+
+ return archive;
+}
+\f
+
+void
+print_total_written (void)
+{
+ tarlong written = prev_written + bytes_written;
+ char bytes[sizeof (tarlong) * CHAR_BIT];
+ char abbr[LONGEST_HUMAN_READABLE + 1];
+ char rate[LONGEST_HUMAN_READABLE + 1];
+
+ int human_opts = human_autoscale | human_base_1024 | human_SI | human_B;
+
+ sprintf (bytes, TARLONG_FORMAT, written);
+
+ /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
+ fprintf (stderr, _("Total bytes written: %s (%s, %s/s)\n"), bytes,
+ human_readable (written, abbr, human_opts, 1, 1),
+ (0 < duration && written / duration < (uintmax_t) -1
+ ? human_readable (written / duration, rate, human_opts, 1, 1)
+ : "?"));
+}
+
+/* Compute and return the block ordinal at current_block. */
+off_t
+current_block_ordinal (void)
+{
+ return record_start_block + (current_block - record_start);
+}
+
+/* If the EOF flag is set, reset it, as well as current_block, etc. */
+void
+reset_eof (void)
+{
+ if (hit_eof)
+ {
+ hit_eof = false;
+ current_block = record_start;
+ record_end = record_start + blocking_factor;
+ access_mode = ACCESS_WRITE;
+ }
+}
+
+/* Return the location of the next available input or output block.
+ Return zero for EOF. Once we have returned zero, we just keep returning
+ it, to avoid accidentally going on to the next file on the tape. */
+union block *
+find_next_block (void)
+{
+ if (current_block == record_end)
+ {
+ if (hit_eof)
+ return 0;
+ flush_archive ();
+ if (current_block == record_end)