1 /* Buffer management for tar.
3 Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
4 2003, 2004 Free Software Foundation, Inc.
6 Written by John Gilmore, on 1985-08-25.
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any later
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 /* Number of retries before giving up on read. */
34 #define READ_ERROR_MAX 10
36 /* Globbing pattern to append to volume label if initial match failed. */
37 #define VOLUME_LABEL_APPEND " Volume [1-9]*"
41 static tarlong prev_written
; /* bytes written on previous volumes */
42 static tarlong bytes_written
; /* bytes written on this volume */
43 static void *record_buffer
; /* allocated memory */
45 /* FIXME: The following variables should ideally be static to this
46 module. However, this cannot be done yet. The cleanup continues! */
48 union block
*record_start
; /* start of record of archive */
49 union block
*record_end
; /* last+1 block of archive record */
50 union block
*current_block
; /* current block of archive */
51 enum access_mode access_mode
; /* how do we handle the archive */
52 off_t records_read
; /* number of records read from this archive */
53 off_t records_written
; /* likewise, for records written */
55 static off_t record_start_block
; /* block ordinal at record_start */
57 /* Where we write list messages (not errors, not interactions) to. */
60 static void backspace_output (void);
61 static bool new_volume (enum access_mode
);
63 /* PID of child program, if compress_option or remote archive access. */
64 static pid_t child_pid
;
66 /* Error recovery stuff */
67 static int read_error_count
;
69 /* Have we hit EOF yet? */
72 /* Checkpointing counter */
73 static int checkpoint
;
75 /* We're reading, but we just read the last block and it's time to update.
78 As least EXTERN like this one as possible. (?? --gray)
79 FIXME: Either eliminate it or move it to common.h.
81 extern bool time_to_start_writing
;
83 static int volno
= 1; /* which volume of a multi-volume tape we're
85 static int global_volno
= 1; /* volume number to print in external
88 /* The pointer save_name, which is set in function dump_file() of module
89 create.c, points to the original long filename instead of the new,
90 shorter mangled name that is set in start_header() of module create.c.
91 The pointer save_name is only used in multi-volume mode when the file
92 being processed is non-sparse; if a file is split between volumes, the
93 save_name is used in generating the LF_MULTIVOL record on the second
94 volume. (From Pierce Cantrell, 1991-08-13.) */
96 char *save_name
; /* name of the file we are currently writing */
97 off_t save_totsize
; /* total size of file we are writing, only
98 valid if save_name is nonzero */
99 off_t save_sizeleft
; /* where we are in the file we are writing,
100 only valid if save_name is nonzero */
102 bool write_archive_to_stdout
;
104 /* Used by flush_read and flush_write to store the real info about saved
106 static char *real_s_name
;
107 static off_t real_s_totsize
;
108 static off_t real_s_sizeleft
;
113 clear_read_error_count (void)
115 read_error_count
= 0;
119 print_total_written (void)
121 tarlong written
= prev_written
+ bytes_written
;
122 char bytes
[sizeof (tarlong
) * CHAR_BIT
];
123 char abbr
[LONGEST_HUMAN_READABLE
+ 1];
124 char rate
[LONGEST_HUMAN_READABLE
+ 1];
126 int human_opts
= human_autoscale
| human_base_1024
| human_SI
| human_B
;
128 #if HAVE_CLOCK_GETTIME
130 if (clock_gettime (CLOCK_REALTIME
, &now
) == 0)
131 seconds
= ((now
.tv_sec
- start_timespec
.tv_sec
)
132 + (now
.tv_nsec
- start_timespec
.tv_nsec
) / 1e9
);
135 seconds
= time (0) - start_time
;
137 sprintf (bytes
, TARLONG_FORMAT
, written
);
139 /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
140 fprintf (stderr
, _("Total bytes written: %s (%s, %s/s)\n"), bytes
,
141 human_readable (written
, abbr
, human_opts
, 1, 1),
142 (0 < seconds
&& written
/ seconds
< (uintmax_t) -1
143 ? human_readable (written
/ seconds
, rate
, human_opts
, 1, 1)
147 /* Compute and return the block ordinal at current_block. */
149 current_block_ordinal (void)
151 return record_start_block
+ (current_block
- record_start
);
154 /* If the EOF flag is set, reset it, as well as current_block, etc. */
161 current_block
= record_start
;
162 record_end
= record_start
+ blocking_factor
;
163 access_mode
= ACCESS_WRITE
;
167 /* Return the location of the next available input or output block.
168 Return zero for EOF. Once we have returned zero, we just keep returning
169 it, to avoid accidentally going on to the next file on the tape. */
171 find_next_block (void)
173 if (current_block
== record_end
)
178 if (current_block
== record_end
)
184 return current_block
;
187 /* Indicate that we have used all blocks up thru BLOCK. */
189 set_next_block_after (union block
*block
)
191 while (block
>= current_block
)
194 /* Do *not* flush the archive here. If we do, the same argument to
195 set_next_block_after could mean the next block (if the input record
196 is exactly one block long), which is not what is intended. */
198 if (current_block
> record_end
)
202 /* Return the number of bytes comprising the space between POINTER
203 through the end of the current buffer of blocks. This space is
204 available for filling with data, or taking data from. POINTER is
205 usually (but not always) the result of previous find_next_block call. */
207 available_space_after (union block
*pointer
)
209 return record_end
->buffer
- pointer
->buffer
;
212 /* Close file having descriptor FD, and abort if close unsuccessful. */
217 close_error (_("(pipe)"));
220 /* Check the LABEL block against the volume label, seen as a globbing
221 pattern. Return true if the pattern matches. In case of failure,
222 retry matching a volume sequence number before giving up in
223 multi-volume mode. */
225 check_label_pattern (union block
*label
)
230 if (! memchr (label
->header
.name
, '\0', sizeof label
->header
.name
))
233 if (fnmatch (volume_label_option
, label
->header
.name
, 0) == 0)
236 if (!multi_volume_option
)
239 string
= xmalloc (strlen (volume_label_option
)
240 + sizeof VOLUME_LABEL_APPEND
+ 1);
241 strcpy (string
, volume_label_option
);
242 strcat (string
, VOLUME_LABEL_APPEND
);
243 result
= fnmatch (string
, label
->header
.name
, 0) == 0;
248 /* Open an archive file. The argument specifies whether we are
249 reading or writing, or both. */
251 open_archive (enum access_mode wanted_access
)
253 int backed_up_flag
= 0;
257 stdlis
= fopen (index_file_name
, "w");
259 open_error (index_file_name
);
262 stdlis
= to_stdout_option
? stderr
: stdout
;
264 if (record_size
== 0)
265 FATAL_ERROR ((0, 0, _("Invalid value for record_size")));
267 if (archive_names
== 0)
268 FATAL_ERROR ((0, 0, _("No archive name given")));
270 tar_stat_destroy (¤t_stat_info
);
275 page_aligned_alloc (&record_buffer
,
277 + (multi_volume_option
? 2 * BLOCKSIZE
: 0)));
278 if (multi_volume_option
)
281 current_block
= record_start
;
282 record_end
= record_start
+ blocking_factor
;
283 /* When updating the archive, we start with reading. */
284 access_mode
= wanted_access
== ACCESS_UPDATE
? ACCESS_READ
: wanted_access
;
286 if (use_compress_program_option
)
288 switch (wanted_access
)
291 child_pid
= sys_child_open_for_uncompress ();
295 child_pid
= sys_child_open_for_compress ();
299 abort (); /* Should not happen */
303 if (wanted_access
== ACCESS_WRITE
304 && strcmp (archive_name_array
[0], "-") == 0)
307 else if (strcmp (archive_name_array
[0], "-") == 0)
309 read_full_records_option
= true; /* could be a pipe, be safe */
311 FATAL_ERROR ((0, 0, _("Cannot verify stdin/stdout archive")));
313 switch (wanted_access
)
316 archive
= STDIN_FILENO
;
320 archive
= STDOUT_FILENO
;
325 archive
= STDIN_FILENO
;
327 write_archive_to_stdout
= true;
331 else if (verify_option
)
332 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
333 MODE_RW
, rsh_command_option
);
335 switch (wanted_access
)
338 archive
= rmtopen (archive_name_array
[0], O_RDONLY
| O_BINARY
,
339 MODE_RW
, rsh_command_option
);
345 maybe_backup_file (archive_name_array
[0], 1);
348 archive
= rmtcreat (archive_name_array
[0], MODE_RW
,
353 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
354 MODE_RW
, rsh_command_option
);
359 || (! _isrmt (archive
) && !sys_get_archive_stat ()))
361 int saved_errno
= errno
;
366 open_fatal (archive_name_array
[0]);
369 sys_detect_dev_null_output ();
370 sys_save_archive_dev_ino ();
371 SET_BINARY_MODE (archive
);
373 switch (wanted_access
)
379 record_end
= record_start
; /* set up for 1st record = # 0 */
380 find_next_block (); /* read it in, check for EOF */
382 if (volume_label_option
)
384 union block
*label
= find_next_block ();
387 FATAL_ERROR ((0, 0, _("Archive not labeled to match %s"),
388 quote (volume_label_option
)));
389 if (!check_label_pattern (label
))
390 FATAL_ERROR ((0, 0, _("Volume %s does not match %s"),
391 quote_n (0, label
->header
.name
),
392 quote_n (1, volume_label_option
)));
398 if (volume_label_option
)
400 memset (record_start
, 0, BLOCKSIZE
);
401 if (multi_volume_option
)
402 sprintf (record_start
->header
.name
, "%s Volume 1",
403 volume_label_option
);
405 strcpy (record_start
->header
.name
, volume_label_option
);
407 assign_string (¤t_stat_info
.file_name
,
408 record_start
->header
.name
);
409 current_stat_info
.had_trailing_slash
=
410 strip_trailing_slashes (current_stat_info
.file_name
);
412 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
413 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
414 finish_header (¤t_stat_info
, record_start
, -1);
420 /* Perform a write to flush the buffer. */
427 if (checkpoint_option
&& !(++checkpoint
% 10))
428 WARN ((0, 0, _("Write checkpoint %d"), checkpoint
));
430 if (tape_length_option
&& tape_length_option
<= bytes_written
)
435 else if (dev_null_output
)
436 status
= record_size
;
438 status
= sys_write_archive_buffer ();
439 if (status
!= record_size
&& !multi_volume_option
)
440 archive_write_error (status
);
445 bytes_written
+= status
;
448 if (status
== record_size
)
450 if (multi_volume_option
)
454 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
455 real_s_totsize
= save_totsize
;
456 real_s_sizeleft
= save_sizeleft
;
460 assign_string (&real_s_name
, 0);
468 /* We're multivol. Panic if we didn't get the right kind of response. */
470 /* ENXIO is for the UNIX PC. */
471 if (status
< 0 && errno
!= ENOSPC
&& errno
!= EIO
&& errno
!= ENXIO
)
472 archive_write_error (status
);
474 /* If error indicates a short write, we just move to the next tape. */
476 if (!new_volume (ACCESS_WRITE
))
480 prev_written
+= bytes_written
;
483 if (volume_label_option
&& real_s_name
)
488 else if (volume_label_option
|| real_s_name
)
496 if (volume_label_option
)
498 memset (record_start
, 0, BLOCKSIZE
);
499 sprintf (record_start
->header
.name
, "%s Volume %d",
500 volume_label_option
, volno
);
501 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
502 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
503 finish_header (¤t_stat_info
, record_start
, -1);
510 if (volume_label_option
)
513 if (strlen (real_s_name
) > NAME_FIELD_SIZE
)
515 _("%s: file name too long to be stored in a GNU multivolume header"),
516 quotearg_colon (real_s_name
)));
518 memset (record_start
, 0, BLOCKSIZE
);
520 /* FIXME: Michael P Urban writes: [a long name file] is being written
521 when a new volume rolls around [...] Looks like the wrong value is
522 being preserved in real_s_name, though. */
524 strncpy (record_start
->header
.name
, real_s_name
, NAME_FIELD_SIZE
);
525 record_start
->header
.typeflag
= GNUTYPE_MULTIVOL
;
526 OFF_TO_CHARS (real_s_sizeleft
, record_start
->header
.size
);
527 OFF_TO_CHARS (real_s_totsize
- real_s_sizeleft
,
528 record_start
->oldgnu_header
.offset
);
529 tmp
= verbose_option
;
531 finish_header (¤t_stat_info
, record_start
, -1);
532 verbose_option
= tmp
;
534 if (volume_label_option
)
538 status
= sys_write_archive_buffer ();
539 if (status
!= record_size
)
540 archive_write_error (status
);
542 bytes_written
+= status
;
546 record_start
+= copy_back
;
547 memcpy (current_block
,
548 record_start
+ blocking_factor
- copy_back
,
549 copy_back
* BLOCKSIZE
);
550 current_block
+= copy_back
;
552 if (real_s_sizeleft
>= copy_back
* BLOCKSIZE
)
553 real_s_sizeleft
-= copy_back
* BLOCKSIZE
;
554 else if ((real_s_sizeleft
+ BLOCKSIZE
- 1) / BLOCKSIZE
<= copy_back
)
555 assign_string (&real_s_name
, 0);
558 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
559 real_s_sizeleft
= save_sizeleft
;
560 real_s_totsize
= save_totsize
;
566 /* Handle write errors on the archive. Write errors are always fatal.
567 Hitting the end of a volume does not cause a write error unless the
568 write was the first record of the volume. */
570 archive_write_error (ssize_t status
)
572 /* It might be useful to know how much was written before the error
577 print_total_written ();
581 write_fatal_details (*archive_name_cursor
, status
, record_size
);
584 /* Handle read errors on the archive. If the read should be retried,
585 return to the caller. */
587 archive_read_error (void)
589 read_error (*archive_name_cursor
);
591 if (record_start_block
== 0)
592 FATAL_ERROR ((0, 0, _("At beginning of tape, quitting now")));
594 /* Read error in mid archive. We retry up to READ_ERROR_MAX times and
595 then give up on reading the archive. */
597 if (read_error_count
++ > READ_ERROR_MAX
)
598 FATAL_ERROR ((0, 0, _("Too many errors, quitting")));
603 short_read (size_t status
)
605 size_t left
; /* bytes left */
606 char *more
; /* pointer to next byte to read */
608 more
= record_start
->buffer
+ status
;
609 left
= record_size
- status
;
611 while (left
% BLOCKSIZE
!= 0
612 || (left
&& status
&& read_full_records_option
))
615 while ((status
= rmtread (archive
, more
, left
)) == SAFE_READ_ERROR
)
616 archive_read_error ();
620 char buf
[UINTMAX_STRSIZE_BOUND
];
622 WARN((0, 0, _("Read %s bytes from %s"),
623 STRINGIFY_BIGINT (record_size
- left
, buf
),
624 *archive_name_cursor
));
628 if (! read_full_records_option
)
630 unsigned long rest
= record_size
- left
;
633 ngettext ("Unaligned block (%lu byte) in archive",
634 "Unaligned block (%lu bytes) in archive",
639 /* User warned us about this. Fix up. */
645 /* FIXME: for size=0, multi-volume support. On the first record, warn
646 about the problem. */
648 if (!read_full_records_option
&& verbose_option
> 1
649 && record_start_block
== 0 && status
!= 0)
651 unsigned long rsize
= (record_size
- left
) / BLOCKSIZE
;
653 ngettext ("Record size = %lu block",
654 "Record size = %lu blocks",
659 record_end
= record_start
+ (record_size
- left
) / BLOCKSIZE
;
663 /* Perform a read to flush the buffer. */
667 size_t status
; /* result from system call */
669 if (checkpoint_option
&& !(++checkpoint
% 10))
670 WARN ((0, 0, _("Read checkpoint %d"), checkpoint
));
672 /* Clear the count of errors. This only applies to a single call to
675 read_error_count
= 0; /* clear error count */
677 if (write_archive_to_stdout
&& record_start_block
!= 0)
679 archive
= STDOUT_FILENO
;
680 status
= sys_write_archive_buffer ();
681 archive
= STDIN_FILENO
;
682 if (status
!= record_size
)
683 archive_write_error (status
);
685 if (multi_volume_option
)
689 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
690 real_s_sizeleft
= save_sizeleft
;
691 real_s_totsize
= save_totsize
;
695 assign_string (&real_s_name
, 0);
702 status
= rmtread (archive
, record_start
->buffer
, record_size
);
703 if (status
== record_size
)
709 /* The condition below used to include
710 || (status > 0 && !read_full_records_option)
711 This is incorrect since even if new_volume() succeeds, the
712 subsequent call to rmtread will overwrite the chunk of data
713 already read in the buffer, so the processing will fail */
716 || (status
== SAFE_READ_ERROR
&& errno
== ENOSPC
))
717 && multi_volume_option
)
722 switch (subcommand_option
)
724 case APPEND_SUBCOMMAND
:
726 case UPDATE_SUBCOMMAND
:
727 if (!new_volume (ACCESS_UPDATE
))
732 if (!new_volume (ACCESS_READ
))
737 while ((status
= rmtread (archive
, record_start
->buffer
, record_size
))
739 archive_read_error ();
741 if (status
!= record_size
)
744 cursor
= record_start
;
746 if (cursor
->header
.typeflag
== GNUTYPE_VOLHDR
)
748 if (volume_label_option
)
750 if (!check_label_pattern (cursor
))
752 WARN ((0, 0, _("Volume %s does not match %s"),
753 quote_n (0, cursor
->header
.name
),
754 quote_n (1, volume_label_option
)));
761 fprintf (stdlis
, _("Reading %s\n"), quote (cursor
->header
.name
));
764 else if (volume_label_option
)
765 WARN ((0, 0, _("WARNING: No volume header")));
770 if (cursor
->header
.typeflag
!= GNUTYPE_MULTIVOL
771 || strncmp (cursor
->header
.name
, real_s_name
, NAME_FIELD_SIZE
))
773 WARN ((0, 0, _("%s is not continued on this volume"),
774 quote (real_s_name
)));
779 s1
= UINTMAX_FROM_HEADER (cursor
->header
.size
);
780 s2
= UINTMAX_FROM_HEADER (cursor
->oldgnu_header
.offset
);
781 if (real_s_totsize
!= s1
+ s2
|| s1
+ s2
< s2
)
783 char totsizebuf
[UINTMAX_STRSIZE_BOUND
];
784 char s1buf
[UINTMAX_STRSIZE_BOUND
];
785 char s2buf
[UINTMAX_STRSIZE_BOUND
];
787 WARN ((0, 0, _("%s is the wrong size (%s != %s + %s)"),
788 quote (cursor
->header
.name
),
789 STRINGIFY_BIGINT (save_totsize
, totsizebuf
),
790 STRINGIFY_BIGINT (s1
, s1buf
),
791 STRINGIFY_BIGINT (s2
, s2buf
)));
796 if (real_s_totsize
- real_s_sizeleft
797 != OFF_FROM_HEADER (cursor
->oldgnu_header
.offset
))
799 WARN ((0, 0, _("This volume is out of sequence")));
806 current_block
= cursor
;
810 else if (status
== SAFE_READ_ERROR
)
812 archive_read_error ();
813 goto error_loop
; /* try again */
819 /* Flush the current buffer to/from the archive. */
823 record_start_block
+= record_end
- record_start
;
824 current_block
= record_start
;
825 record_end
= record_start
+ blocking_factor
;
827 if (access_mode
== ACCESS_READ
&& time_to_start_writing
)
829 access_mode
= ACCESS_WRITE
;
830 time_to_start_writing
= false;
849 /* Backspace the archive descriptor by one record worth. If it's a
850 tape, MTIOCTOP will work. If it's something else, try to seek on
851 it. If we can't seek, we lose! */
853 backspace_output (void)
857 struct mtop operation
;
859 operation
.mt_op
= MTBSR
;
860 operation
.mt_count
= 1;
861 if (rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
863 if (errno
== EIO
&& rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
869 off_t position
= rmtlseek (archive
, (off_t
) 0, SEEK_CUR
);
871 /* Seek back to the beginning of this record and start writing there. */
873 position
-= record_size
;
876 if (rmtlseek (archive
, position
, SEEK_SET
) != position
)
878 /* Lseek failed. Try a different method. */
881 _("Cannot backspace archive file; it may be unreadable without -i")));
883 /* Replace the first part of the record with NULs. */
885 if (record_start
->buffer
!= output_start
)
886 memset (record_start
->buffer
, 0,
887 output_start
- record_start
->buffer
);
893 seek_archive (off_t size
)
895 off_t start
= current_block_ordinal ();
898 off_t skipped
= (blocking_factor
- (current_block
- record_start
));
900 size
-= skipped
* BLOCKSIZE
;
902 if (size
< record_size
)
906 /* Compute number of records to skip */
907 nrec
= size
/ record_size
;
908 offset
= rmtlseek (archive
, nrec
* record_size
, SEEK_CUR
);
912 if (offset
% record_size
)
913 FATAL_ERROR ((0, 0, _("rmtlseek not stopped at a record boundary")));
915 /* Convert to number of records */
917 /* Compute number of skipped blocks */
918 nblk
= offset
- start
;
920 /* Update buffering info */
921 records_read
+= nblk
/ blocking_factor
;
922 record_start_block
= offset
- blocking_factor
;
923 current_block
= record_end
;
928 /* Close the archive file. */
932 if (time_to_start_writing
|| access_mode
== ACCESS_WRITE
)
935 sys_drain_input_pipe ();
940 if (rmtclose (archive
) != 0)
941 close_warn (*archive_name_cursor
);
943 sys_wait_for_child (child_pid
);
945 tar_stat_destroy (¤t_stat_info
);
950 free (record_buffer
);
953 /* Called to initialize the global volume number. */
955 init_volume_number (void)
957 FILE *file
= fopen (volno_file_option
, "r");
961 if (fscanf (file
, "%d", &global_volno
) != 1
963 FATAL_ERROR ((0, 0, _("%s: contains invalid volume number"),
964 quotearg_colon (volno_file_option
)));
966 read_error (volno_file_option
);
967 if (fclose (file
) != 0)
968 close_error (volno_file_option
);
970 else if (errno
!= ENOENT
)
971 open_error (volno_file_option
);
974 /* Called to write out the closing global volume number. */
976 closeout_volume_number (void)
978 FILE *file
= fopen (volno_file_option
, "w");
982 fprintf (file
, "%d\n", global_volno
);
984 write_error (volno_file_option
);
985 if (fclose (file
) != 0)
986 close_error (volno_file_option
);
989 open_error (volno_file_option
);
992 /* We've hit the end of the old volume. Close it and open the next one.
993 Return nonzero on success.
996 new_volume (enum access_mode mode
)
998 static FILE *read_file
;
1001 if (!read_file
&& !info_script_option
)
1002 /* FIXME: if fopen is used, it will never be closed. */
1003 read_file
= archive
== STDIN_FILENO
? fopen (TTY_NAME
, "r") : stdin
;
1010 if (rmtclose (archive
) != 0)
1011 close_warn (*archive_name_cursor
);
1014 if (global_volno
< 0)
1015 FATAL_ERROR ((0, 0, _("Volume number overflow")));
1017 archive_name_cursor
++;
1018 if (archive_name_cursor
== archive_name_array
+ archive_names
)
1020 archive_name_cursor
= archive_name_array
;
1027 /* We have to prompt from now on. */
1029 if (info_script_option
)
1031 if (volno_file_option
)
1032 closeout_volume_number ();
1033 if (system (info_script_option
) != 0)
1034 FATAL_ERROR ((0, 0, _("`%s' command failed"), info_script_option
));
1039 char input_buffer
[80];
1041 fputc ('\007', stderr
);
1043 _("Prepare volume #%d for %s and hit return: "),
1044 global_volno
, quote (*archive_name_cursor
));
1047 if (fgets (input_buffer
, sizeof input_buffer
, read_file
) == 0)
1049 WARN ((0, 0, _("EOF where user reply was expected")));
1051 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1052 && subcommand_option
!= LIST_SUBCOMMAND
1053 && subcommand_option
!= DIFF_SUBCOMMAND
)
1054 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1058 if (input_buffer
[0] == '\n'
1059 || input_buffer
[0] == 'y'
1060 || input_buffer
[0] == 'Y')
1063 switch (input_buffer
[0])
1067 /* FIXME: Might it be useful to disable the '!' command? */
1068 fprintf (stderr
, _("\
1069 n [name] Give a new file name for the next (and subsequent) volume(s)\n\
1071 ! Spawn a subshell\n\
1072 ? Print this list\n"));
1079 WARN ((0, 0, _("No new volume; exiting.\n")));
1081 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1082 && subcommand_option
!= LIST_SUBCOMMAND
1083 && subcommand_option
!= DIFF_SUBCOMMAND
)
1084 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1089 /* Get new file name. */
1092 char *name
= &input_buffer
[1];
1095 for (name
= input_buffer
+ 1;
1096 *name
== ' ' || *name
== '\t';
1100 for (cursor
= name
; *cursor
&& *cursor
!= '\n'; cursor
++)
1104 /* FIXME: the following allocation is never reclaimed. */
1105 *archive_name_cursor
= xstrdup (name
);
1116 if (strcmp (archive_name_cursor
[0], "-") == 0)
1118 read_full_records_option
= true;
1119 archive
= STDIN_FILENO
;
1121 else if (verify_option
)
1122 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1123 rsh_command_option
);
1128 archive
= rmtopen (*archive_name_cursor
, O_RDONLY
, MODE_RW
,
1129 rsh_command_option
);
1134 maybe_backup_file (*archive_name_cursor
, 1);
1135 archive
= rmtcreat (*archive_name_cursor
, MODE_RW
,
1136 rsh_command_option
);
1140 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1141 rsh_command_option
);
1147 open_warn (*archive_name_cursor
);
1148 if (!verify_option
&& mode
== ACCESS_WRITE
&& backup_option
)
1149 undo_last_backup ();
1153 SET_BINARY_MODE (archive
);