+ int copy_back;
+ ssize_t status;
+
+ if (checkpoint_option && !(++checkpoint % 10))
+ WARN ((0, 0, _("Write checkpoint %d"), checkpoint));
+
+ if (tape_length_option && tape_length_option <= bytes_written)
+ {
+ errno = ENOSPC;
+ status = 0;
+ }
+ else if (dev_null_output)
+ status = record_size;
+ else
+ status = write_archive_buffer ();
+ if (status != record_size && !multi_volume_option)
+ archive_write_error (status);
+
+ if (status > 0)
+ {
+ records_written++;
+ bytes_written += status;
+ }
+
+ if (status == record_size)
+ {
+ if (multi_volume_option)
+ {
+ char *cursor;
+
+ if (!save_name)
+ {
+ assign_string (&real_s_name, 0);
+ real_s_totsize = 0;
+ real_s_sizeleft = 0;
+ return;
+ }
+
+ cursor = save_name + FILESYSTEM_PREFIX_LEN (save_name);
+ while (ISSLASH (*cursor))
+ cursor++;
+
+ assign_string (&real_s_name, cursor);
+ real_s_totsize = save_totsize;
+ real_s_sizeleft = save_sizeleft;
+ }
+ return;
+ }
+
+ /* We're multivol. Panic if we didn't get the right kind of response. */
+
+ /* ENXIO is for the UNIX PC. */
+ if (status < 0 && errno != ENOSPC && errno != EIO && errno != ENXIO)
+ archive_write_error (status);
+
+ /* If error indicates a short write, we just move to the next tape. */
+
+ if (!new_volume (ACCESS_WRITE))
+ return;
+
+ if (totals_option)
+ prev_written += bytes_written;
+ bytes_written = 0;
+
+ if (volume_label_option && real_s_name)
+ {
+ copy_back = 2;
+ record_start -= 2;
+ }
+ else if (volume_label_option || real_s_name)
+ {
+ copy_back = 1;
+ record_start--;
+ }
+ else
+ copy_back = 0;
+
+ if (volume_label_option)
+ {
+ memset (record_start, 0, BLOCKSIZE);
+ sprintf (record_start->header.name, "%s Volume %d",
+ volume_label_option, volno);
+ TIME_TO_CHARS (start_time, record_start->header.mtime);
+ record_start->header.typeflag = GNUTYPE_VOLHDR;
+ finish_header (record_start);
+ }
+
+ if (real_s_name)
+ {
+ int tmp;
+
+ if (volume_label_option)
+ record_start++;
+
+ memset (record_start, 0, BLOCKSIZE);
+
+ /* FIXME: Michael P Urban writes: [a long name file] is being written
+ when a new volume rolls around [...] Looks like the wrong value is
+ being preserved in real_s_name, though. */
+
+ strcpy (record_start->header.name, real_s_name);
+ record_start->header.typeflag = GNUTYPE_MULTIVOL;
+ OFF_TO_CHARS (real_s_sizeleft, record_start->header.size);
+ OFF_TO_CHARS (real_s_totsize - real_s_sizeleft,
+ record_start->oldgnu_header.offset);
+ tmp = verbose_option;
+ verbose_option = 0;
+ finish_header (record_start);
+ verbose_option = tmp;
+
+ if (volume_label_option)
+ record_start--;
+ }
+
+ status = write_archive_buffer ();
+ if (status != record_size)
+ archive_write_error (status);
+
+ bytes_written += status;
+
+ if (copy_back)
+ {
+ record_start += copy_back;
+ memcpy (current_block,
+ record_start + blocking_factor - copy_back,
+ copy_back * BLOCKSIZE);
+ current_block += copy_back;
+
+ if (real_s_sizeleft >= copy_back * BLOCKSIZE)
+ real_s_sizeleft -= copy_back * BLOCKSIZE;
+ else if ((real_s_sizeleft + BLOCKSIZE - 1) / BLOCKSIZE <= copy_back)
+ assign_string (&real_s_name, 0);
+ else
+ {
+ char *cursor = save_name + FILESYSTEM_PREFIX_LEN (save_name);
+
+ while (ISSLASH (*cursor))
+ cursor++;
+
+ assign_string (&real_s_name, cursor);
+ real_s_sizeleft = save_sizeleft;
+ real_s_totsize = save_totsize;