1 /* Buffer management for tar.
3 Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
4 2003 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 */
44 /* FIXME: The following variables should ideally be static to this
45 module. However, this cannot be done yet. The cleanup continues! */
47 union block
*record_start
; /* start of record of archive */
48 union block
*record_end
; /* last+1 block of archive record */
49 union block
*current_block
; /* current block of archive */
50 enum access_mode access_mode
; /* how do we handle the archive */
51 off_t records_read
; /* number of records read from this archive */
52 off_t records_written
; /* likewise, for records written */
54 static off_t record_start_block
; /* block ordinal at record_start */
56 /* Where we write list messages (not errors, not interactions) to. */
59 static void backspace_output (void);
60 static int new_volume (enum access_mode
);
62 /* PID of child program, if compress_option or remote archive access. */
63 static pid_t child_pid
;
65 /* Error recovery stuff */
66 static int read_error_count
;
68 /* Have we hit EOF yet? */
71 /* Checkpointing counter */
72 static int checkpoint
;
74 /* We're reading, but we just read the last block and its time to update. */
75 /* As least EXTERN like this one as possible. FIXME! */
76 extern int time_to_start_writing
;
78 int file_to_switch_to
= -1; /* if remote update, close archive, and use
79 this descriptor to write to */
81 static int volno
= 1; /* which volume of a multi-volume tape we're
83 static int global_volno
= 1; /* volume number to print in external
86 /* The pointer save_name, which is set in function dump_file() of module
87 create.c, points to the original long filename instead of the new,
88 shorter mangled name that is set in start_header() of module create.c.
89 The pointer save_name is only used in multi-volume mode when the file
90 being processed is non-sparse; if a file is split between volumes, the
91 save_name is used in generating the LF_MULTIVOL record on the second
92 volume. (From Pierce Cantrell, 1991-08-13.) */
94 char *save_name
; /* name of the file we are currently writing */
95 off_t save_totsize
; /* total size of file we are writing, only
96 valid if save_name is nonzero */
97 off_t save_sizeleft
; /* where we are in the file we are writing,
98 only valid if save_name is nonzero */
100 bool write_archive_to_stdout
;
102 /* Used by flush_read and flush_write to store the real info about saved
104 static char *real_s_name
;
105 static off_t real_s_totsize
;
106 static off_t real_s_sizeleft
;
111 clear_read_error_count ()
113 read_error_count
= 0;
117 print_total_written (void)
119 tarlong written
= prev_written
+ bytes_written
;
120 char bytes
[sizeof (tarlong
) * CHAR_BIT
];
121 char abbr
[LONGEST_HUMAN_READABLE
+ 1];
122 char rate
[LONGEST_HUMAN_READABLE
+ 1];
124 int human_opts
= human_autoscale
| human_base_1024
| human_SI
| human_B
;
126 #if HAVE_CLOCK_GETTIME
128 if (clock_gettime (CLOCK_REALTIME
, &now
) == 0)
129 seconds
= ((now
.tv_sec
- start_timespec
.tv_sec
)
130 + (now
.tv_nsec
- start_timespec
.tv_nsec
) / 1e9
);
133 seconds
= time (0) - start_time
;
135 sprintf (bytes
, TARLONG_FORMAT
, written
);
137 /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
138 fprintf (stderr
, _("Total bytes written: %s (%s, %s/s)\n"), bytes
,
139 human_readable (written
, abbr
, human_opts
, 1, 1),
140 (0 < seconds
&& written
/ seconds
< (uintmax_t) -1
141 ? human_readable (written
/ seconds
, rate
, human_opts
, 1, 1)
145 /* Compute and return the block ordinal at current_block. */
147 current_block_ordinal (void)
149 return record_start_block
+ (current_block
- record_start
);
152 /* If the EOF flag is set, reset it, as well as current_block, etc. */
159 current_block
= record_start
;
160 record_end
= record_start
+ blocking_factor
;
161 access_mode
= ACCESS_WRITE
;
165 /* Return the location of the next available input or output block.
166 Return zero for EOF. Once we have returned zero, we just keep returning
167 it, to avoid accidentally going on to the next file on the tape. */
169 find_next_block (void)
171 if (current_block
== record_end
)
176 if (current_block
== record_end
)
182 return current_block
;
185 /* Indicate that we have used all blocks up thru BLOCK.
186 FIXME: should the arg have an off-by-1? */
188 set_next_block_after (union block
*block
)
190 while (block
>= current_block
)
193 /* Do *not* flush the archive here. If we do, the same argument to
194 set_next_block_after could mean the next block (if the input record
195 is exactly one block long), which is not what is intended. */
197 if (current_block
> record_end
)
201 /* Return the number of bytes comprising the space between POINTER
202 through the end of the current buffer of blocks. This space is
203 available for filling with data, or taking data from. POINTER is
204 usually (but not always) the result previous find_next_block call. */
206 available_space_after (union block
*pointer
)
208 return record_end
->buffer
- pointer
->buffer
;
211 /* Close file having descriptor FD, and abort if close unsuccessful. */
216 close_error (_("(pipe)"));
219 /* Check the LABEL block against the volume label, seen as a globbing
220 pattern. Return true if the pattern matches. In case of failure,
221 retry matching a volume sequence number before giving up in
222 multi-volume mode. */
224 check_label_pattern (union block
*label
)
229 if (! memchr (label
->header
.name
, '\0', sizeof label
->header
.name
))
232 if (fnmatch (volume_label_option
, label
->header
.name
, 0) == 0)
235 if (!multi_volume_option
)
238 string
= xmalloc (strlen (volume_label_option
)
239 + sizeof VOLUME_LABEL_APPEND
+ 1);
240 strcpy (string
, volume_label_option
);
241 strcat (string
, VOLUME_LABEL_APPEND
);
242 result
= fnmatch (string
, label
->header
.name
, 0) == 0;
247 /* Open an archive file. The argument specifies whether we are
248 reading or writing, or both. */
250 open_archive (enum access_mode wanted_access
)
252 int backed_up_flag
= 0;
256 stdlis
= fopen (index_file_name
, "w");
258 open_error (index_file_name
);
261 stdlis
= to_stdout_option
? stderr
: stdout
;
263 if (record_size
== 0)
264 FATAL_ERROR ((0, 0, _("Invalid value for record_size")));
266 if (archive_names
== 0)
267 FATAL_ERROR ((0, 0, _("No archive name given")));
269 tar_stat_destroy (¤t_stat_info
);
273 if (multi_volume_option
)
276 FATAL_ERROR ((0, 0, _("Cannot verify multi-volume archives")));
277 record_start
= valloc (record_size
+ (2 * BLOCKSIZE
));
282 record_start
= valloc (record_size
);
284 FATAL_ERROR ((0, 0, _("Cannot allocate memory for blocking factor %d"),
287 current_block
= record_start
;
288 record_end
= record_start
+ blocking_factor
;
289 /* When updating the archive, we start with reading. */
290 access_mode
= wanted_access
== ACCESS_UPDATE
? ACCESS_READ
: wanted_access
;
292 if (use_compress_program_option
)
294 if (multi_volume_option
)
295 FATAL_ERROR ((0, 0, _("Cannot use multi-volume compressed archives")));
297 FATAL_ERROR ((0, 0, _("Cannot verify compressed archives")));
299 switch (wanted_access
)
302 child_pid
= sys_child_open_for_uncompress ();
306 child_pid
= sys_child_open_for_compress ();
310 FATAL_ERROR ((0, 0, _("Cannot update compressed archives")));
314 if (wanted_access
== ACCESS_WRITE
315 && strcmp (archive_name_array
[0], "-") == 0)
318 else if (strcmp (archive_name_array
[0], "-") == 0)
320 read_full_records_option
= 1; /* could be a pipe, be safe */
322 FATAL_ERROR ((0, 0, _("Cannot verify stdin/stdout archive")));
324 switch (wanted_access
)
327 archive
= STDIN_FILENO
;
331 archive
= STDOUT_FILENO
;
336 archive
= STDIN_FILENO
;
338 write_archive_to_stdout
= 1;
342 else if (verify_option
)
343 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
344 MODE_RW
, rsh_command_option
);
346 switch (wanted_access
)
349 archive
= rmtopen (archive_name_array
[0], O_RDONLY
| O_BINARY
,
350 MODE_RW
, rsh_command_option
);
356 maybe_backup_file (archive_name_array
[0], 1);
359 archive
= rmtcreat (archive_name_array
[0], MODE_RW
,
364 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
365 MODE_RW
, rsh_command_option
);
370 || (! _isrmt (archive
) && !sys_get_archive_stat ()))
372 int saved_errno
= errno
;
377 open_fatal (archive_name_array
[0]);
380 sys_detect_dev_null_output ();
381 sys_save_archive_dev_ino ();
382 SET_BINARY_MODE (archive
);
384 switch (wanted_access
)
390 record_end
= record_start
; /* set up for 1st record = # 0 */
391 find_next_block (); /* read it in, check for EOF */
393 if (volume_label_option
)
395 union block
*label
= find_next_block ();
398 FATAL_ERROR ((0, 0, _("Archive not labeled to match %s"),
399 quote (volume_label_option
)));
400 if (!check_label_pattern (label
))
401 FATAL_ERROR ((0, 0, _("Volume %s does not match %s"),
402 quote_n (0, label
->header
.name
),
403 quote_n (1, volume_label_option
)));
409 if (volume_label_option
)
411 memset (record_start
, 0, BLOCKSIZE
);
412 if (multi_volume_option
)
413 sprintf (record_start
->header
.name
, "%s Volume 1",
414 volume_label_option
);
416 strcpy (record_start
->header
.name
, volume_label_option
);
418 assign_string (¤t_stat_info
.file_name
, record_start
->header
.name
);
419 current_stat_info
.had_trailing_slash
= strip_trailing_slashes (current_stat_info
.file_name
);
421 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
422 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
423 finish_header (¤t_stat_info
, record_start
, -1);
432 /* Perform a write to flush the buffer. */
439 if (checkpoint_option
&& !(++checkpoint
% 10))
440 WARN ((0, 0, _("Write checkpoint %d"), checkpoint
));
442 if (tape_length_option
&& tape_length_option
<= bytes_written
)
447 else if (dev_null_output
)
448 status
= record_size
;
450 status
= sys_write_archive_buffer ();
451 if (status
!= record_size
&& !multi_volume_option
)
452 archive_write_error (status
);
457 bytes_written
+= status
;
460 if (status
== record_size
)
462 if (multi_volume_option
)
466 assign_string (&real_s_name
, safer_name_suffix (save_name
, 0));
467 real_s_totsize
= save_totsize
;
468 real_s_sizeleft
= save_sizeleft
;
472 assign_string (&real_s_name
, 0);
480 /* We're multivol. Panic if we didn't get the right kind of response. */
482 /* ENXIO is for the UNIX PC. */
483 if (status
< 0 && errno
!= ENOSPC
&& errno
!= EIO
&& errno
!= ENXIO
)
484 archive_write_error (status
);
486 /* If error indicates a short write, we just move to the next tape. */
488 if (!new_volume (ACCESS_WRITE
))
492 prev_written
+= bytes_written
;
495 if (volume_label_option
&& real_s_name
)
500 else if (volume_label_option
|| real_s_name
)
508 if (volume_label_option
)
510 memset (record_start
, 0, BLOCKSIZE
);
511 sprintf (record_start
->header
.name
, "%s Volume %d",
512 volume_label_option
, volno
);
513 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
514 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
515 finish_header (¤t_stat_info
, record_start
, -1);
522 if (volume_label_option
)
525 memset (record_start
, 0, BLOCKSIZE
);
527 /* FIXME: Michael P Urban writes: [a long name file] is being written
528 when a new volume rolls around [...] Looks like the wrong value is
529 being preserved in real_s_name, though. */
531 strcpy (record_start
->header
.name
, real_s_name
);
532 record_start
->header
.typeflag
= GNUTYPE_MULTIVOL
;
533 OFF_TO_CHARS (real_s_sizeleft
, record_start
->header
.size
);
534 OFF_TO_CHARS (real_s_totsize
- real_s_sizeleft
,
535 record_start
->oldgnu_header
.offset
);
536 tmp
= verbose_option
;
538 finish_header (¤t_stat_info
, record_start
, -1);
539 verbose_option
= tmp
;
541 if (volume_label_option
)
545 status
= sys_write_archive_buffer ();
546 if (status
!= record_size
)
547 archive_write_error (status
);
549 bytes_written
+= status
;
553 record_start
+= copy_back
;
554 memcpy (current_block
,
555 record_start
+ blocking_factor
- copy_back
,
556 copy_back
* BLOCKSIZE
);
557 current_block
+= copy_back
;
559 if (real_s_sizeleft
>= copy_back
* BLOCKSIZE
)
560 real_s_sizeleft
-= copy_back
* BLOCKSIZE
;
561 else if ((real_s_sizeleft
+ BLOCKSIZE
- 1) / BLOCKSIZE
<= copy_back
)
562 assign_string (&real_s_name
, 0);
565 assign_string (&real_s_name
, safer_name_suffix (save_name
, 0));
566 real_s_sizeleft
= save_sizeleft
;
567 real_s_totsize
= save_totsize
;
573 /* Handle write errors on the archive. Write errors are always fatal.
574 Hitting the end of a volume does not cause a write error unless the
575 write was the first record of the volume. */
577 archive_write_error (ssize_t status
)
579 /* It might be useful to know how much was written before the error
584 print_total_written ();
588 write_fatal_details (*archive_name_cursor
, status
, record_size
);
591 /* Handle read errors on the archive. If the read should be retried,
592 return to the caller. */
594 archive_read_error (void)
596 read_error (*archive_name_cursor
);
598 if (record_start_block
== 0)
599 FATAL_ERROR ((0, 0, _("At beginning of tape, quitting now")));
601 /* Read error in mid archive. We retry up to READ_ERROR_MAX times and
602 then give up on reading the archive. */
604 if (read_error_count
++ > READ_ERROR_MAX
)
605 FATAL_ERROR ((0, 0, _("Too many errors, quitting")));
610 short_read (ssize_t status
)
612 size_t left
; /* bytes left */
613 char *more
; /* pointer to next byte to read */
615 more
= record_start
->buffer
+ status
;
616 left
= record_size
- status
;
618 while (left
% BLOCKSIZE
!= 0
619 || (left
&& status
&& read_full_records_option
))
622 while ((status
= rmtread (archive
, more
, left
)) < 0)
623 archive_read_error ();
627 char buf
[UINTMAX_STRSIZE_BOUND
];
629 WARN((0, 0, _("Read %s bytes from %s"),
630 STRINGIFY_BIGINT (record_size
- left
, buf
),
631 *archive_name_cursor
));
635 if (! read_full_records_option
)
637 unsigned long rest
= record_size
- left
;
640 ngettext ("Unaligned block (%lu byte) in archive",
641 "Unaligned block (%lu bytes) in archive",
646 /* User warned us about this. Fix up. */
652 /* FIXME: for size=0, multi-volume support. On the first record, warn
653 about the problem. */
655 if (!read_full_records_option
&& verbose_option
656 && record_start_block
== 0 && status
> 0)
658 unsigned long rsize
= (record_size
- left
) / BLOCKSIZE
;
660 ngettext ("Record size = %lu block",
661 "Record size = %lu blocks",
666 record_end
= record_start
+ (record_size
- left
) / BLOCKSIZE
;
670 /* Perform a read to flush the buffer. */
674 ssize_t status
; /* result from system call */
676 if (checkpoint_option
&& !(++checkpoint
% 10))
677 WARN ((0, 0, _("Read checkpoint %d"), checkpoint
));
679 /* Clear the count of errors. This only applies to a single call to
682 read_error_count
= 0; /* clear error count */
684 if (write_archive_to_stdout
&& record_start_block
!= 0)
686 archive
= STDOUT_FILENO
;
687 status
= sys_write_archive_buffer ();
688 archive
= STDIN_FILENO
;
689 if (status
!= record_size
)
690 archive_write_error (status
);
692 if (multi_volume_option
)
696 assign_string (&real_s_name
, safer_name_suffix (save_name
, 0));
697 real_s_sizeleft
= save_sizeleft
;
698 real_s_totsize
= save_totsize
;
702 assign_string (&real_s_name
, 0);
709 status
= rmtread (archive
, record_start
->buffer
, record_size
);
710 if (status
== record_size
)
717 || (status
< 0 && errno
== ENOSPC
)
718 || (status
> 0 && !read_full_records_option
))
719 && multi_volume_option
)
724 switch (subcommand_option
)
726 case APPEND_SUBCOMMAND
:
728 case UPDATE_SUBCOMMAND
:
729 if (!new_volume (ACCESS_UPDATE
))
734 if (!new_volume (ACCESS_READ
))
740 status
= rmtread (archive
, record_start
->buffer
, record_size
);
743 archive_read_error ();
746 if (status
!= record_size
)
749 cursor
= record_start
;
751 if (cursor
->header
.typeflag
== GNUTYPE_VOLHDR
)
753 if (volume_label_option
)
755 if (!check_label_pattern (cursor
))
757 WARN ((0, 0, _("Volume %s does not match %s"),
758 quote_n (0, cursor
->header
.name
),
759 quote_n (1, volume_label_option
)));
766 fprintf (stdlis
, _("Reading %s\n"), quote (cursor
->header
.name
));
769 else if (volume_label_option
)
770 WARN ((0, 0, _("WARNING: No volume header")));
775 if (cursor
->header
.typeflag
!= GNUTYPE_MULTIVOL
776 || strcmp (cursor
->header
.name
, real_s_name
))
778 WARN ((0, 0, _("%s is not continued on this volume"),
779 quote (real_s_name
)));
784 s1
= UINTMAX_FROM_HEADER (cursor
->header
.size
);
785 s2
= UINTMAX_FROM_HEADER (cursor
->oldgnu_header
.offset
);
786 if (real_s_totsize
!= s1
+ s2
|| s1
+ s2
< s2
)
788 char totsizebuf
[UINTMAX_STRSIZE_BOUND
];
789 char s1buf
[UINTMAX_STRSIZE_BOUND
];
790 char s2buf
[UINTMAX_STRSIZE_BOUND
];
792 WARN ((0, 0, _("%s is the wrong size (%s != %s + %s)"),
793 quote (cursor
->header
.name
),
794 STRINGIFY_BIGINT (save_totsize
, totsizebuf
),
795 STRINGIFY_BIGINT (s1
, s1buf
),
796 STRINGIFY_BIGINT (s2
, s2buf
)));
801 if (real_s_totsize
- real_s_sizeleft
802 != OFF_FROM_HEADER (cursor
->oldgnu_header
.offset
))
804 WARN ((0, 0, _("This volume is out of sequence")));
811 current_block
= cursor
;
817 archive_read_error ();
818 goto error_loop
; /* try again */
824 /* Flush the current buffer to/from the archive. */
828 record_start_block
+= record_end
- record_start
;
829 current_block
= record_start
;
830 record_end
= record_start
+ blocking_factor
;
832 if (access_mode
== ACCESS_READ
&& time_to_start_writing
)
834 access_mode
= ACCESS_WRITE
;
835 time_to_start_writing
= 0;
837 if (file_to_switch_to
>= 0)
839 if (rmtclose (archive
) != 0)
840 close_warn (*archive_name_cursor
);
842 archive
= file_to_switch_to
;
863 /* Backspace the archive descriptor by one record worth. If it's a
864 tape, MTIOCTOP will work. If it's something else, try to seek on
865 it. If we can't seek, we lose! */
867 backspace_output (void)
871 struct mtop operation
;
873 operation
.mt_op
= MTBSR
;
874 operation
.mt_count
= 1;
875 if (rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
877 if (errno
== EIO
&& rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
883 off_t position
= rmtlseek (archive
, (off_t
) 0, SEEK_CUR
);
885 /* Seek back to the beginning of this record and start writing there. */
887 position
-= record_size
;
890 if (rmtlseek (archive
, position
, SEEK_SET
) != position
)
892 /* Lseek failed. Try a different method. */
895 _("Cannot backspace archive file; it may be unreadable without -i")));
897 /* Replace the first part of the record with NULs. */
899 if (record_start
->buffer
!= output_start
)
900 memset (record_start
->buffer
, 0,
901 output_start
- record_start
->buffer
);
906 /* Close the archive file. */
910 if (time_to_start_writing
|| access_mode
== ACCESS_WRITE
)
913 sys_drain_input_pipe ();
918 if (rmtclose (archive
) != 0)
919 close_warn (*archive_name_cursor
);
921 sys_wait_for_child (child_pid
);
923 tar_stat_destroy (¤t_stat_info
);
928 free (multi_volume_option
? record_start
- 2 : record_start
);
931 /* Called to initialize the global volume number. */
933 init_volume_number (void)
935 FILE *file
= fopen (volno_file_option
, "r");
939 if (fscanf (file
, "%d", &global_volno
) != 1
941 FATAL_ERROR ((0, 0, _("%s: contains invalid volume number"),
942 quotearg_colon (volno_file_option
)));
944 read_error (volno_file_option
);
945 if (fclose (file
) != 0)
946 close_error (volno_file_option
);
948 else if (errno
!= ENOENT
)
949 open_error (volno_file_option
);
952 /* Called to write out the closing global volume number. */
954 closeout_volume_number (void)
956 FILE *file
= fopen (volno_file_option
, "w");
960 fprintf (file
, "%d\n", global_volno
);
962 write_error (volno_file_option
);
963 if (fclose (file
) != 0)
964 close_error (volno_file_option
);
967 open_error (volno_file_option
);
970 /* We've hit the end of the old volume. Close it and open the next one.
971 Return nonzero on success. */
973 new_volume (enum access_mode access
)
975 static FILE *read_file
;
978 if (!read_file
&& !info_script_option
)
979 /* FIXME: if fopen is used, it will never be closed. */
980 read_file
= archive
== STDIN_FILENO
? fopen (TTY_NAME
, "r") : stdin
;
987 if (rmtclose (archive
) != 0)
988 close_warn (*archive_name_cursor
);
991 if (global_volno
< 0)
992 FATAL_ERROR ((0, 0, _("Volume number overflow")));
994 archive_name_cursor
++;
995 if (archive_name_cursor
== archive_name_array
+ archive_names
)
997 archive_name_cursor
= archive_name_array
;
1004 /* We have to prompt from now on. */
1006 if (info_script_option
)
1008 if (volno_file_option
)
1009 closeout_volume_number ();
1010 if (system (info_script_option
) != 0)
1011 FATAL_ERROR ((0, 0, _("`%s' command failed"), info_script_option
));
1016 char input_buffer
[80];
1018 fputc ('\007', stderr
);
1020 _("Prepare volume #%d for %s and hit return: "),
1021 global_volno
, quote (*archive_name_cursor
));
1024 if (fgets (input_buffer
, sizeof input_buffer
, read_file
) == 0)
1026 WARN ((0, 0, _("EOF where user reply was expected")));
1028 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1029 && subcommand_option
!= LIST_SUBCOMMAND
1030 && subcommand_option
!= DIFF_SUBCOMMAND
)
1031 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1035 if (input_buffer
[0] == '\n'
1036 || input_buffer
[0] == 'y'
1037 || input_buffer
[0] == 'Y')
1040 switch (input_buffer
[0])
1044 fprintf (stderr
, _("\
1045 n [name] Give a new file name for the next (and subsequent) volume(s)\n\
1047 ! Spawn a subshell\n\
1048 ? Print this list\n"));
1055 WARN ((0, 0, _("No new volume; exiting.\n")));
1057 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1058 && subcommand_option
!= LIST_SUBCOMMAND
1059 && subcommand_option
!= DIFF_SUBCOMMAND
)
1060 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1065 /* Get new file name. */
1068 char *name
= &input_buffer
[1];
1071 while (*name
== ' ' || *name
== '\t')
1074 while (*cursor
&& *cursor
!= '\n')
1078 /* FIXME: the following allocation is never reclaimed. */
1079 *archive_name_cursor
= xstrdup (name
);
1090 if (strcmp (archive_name_cursor
[0], "-") == 0)
1092 read_full_records_option
= true;
1093 archive
= STDIN_FILENO
;
1095 else if (verify_option
)
1096 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1097 rsh_command_option
);
1102 archive
= rmtopen (*archive_name_cursor
, O_RDONLY
, MODE_RW
,
1103 rsh_command_option
);
1108 maybe_backup_file (*archive_name_cursor
, 1);
1109 archive
= rmtcreat (*archive_name_cursor
, MODE_RW
,
1110 rsh_command_option
);
1114 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1115 rsh_command_option
);
1121 open_warn (*archive_name_cursor
);
1122 if (!verify_option
&& access
== ACCESS_WRITE
&& backup_option
)
1123 undo_last_backup ();
1127 SET_BINARY_MODE (archive
);