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 */
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 bool 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 it's time to update.
77 As least EXTERN like this one as possible. (?? --gray)
78 FIXME: Either eliminate it or move it to common.h.
80 extern bool time_to_start_writing
;
82 static int volno
= 1; /* which volume of a multi-volume tape we're
84 static int global_volno
= 1; /* volume number to print in external
87 /* The pointer save_name, which is set in function dump_file() of module
88 create.c, points to the original long filename instead of the new,
89 shorter mangled name that is set in start_header() of module create.c.
90 The pointer save_name is only used in multi-volume mode when the file
91 being processed is non-sparse; if a file is split between volumes, the
92 save_name is used in generating the LF_MULTIVOL record on the second
93 volume. (From Pierce Cantrell, 1991-08-13.) */
95 char *save_name
; /* name of the file we are currently writing */
96 off_t save_totsize
; /* total size of file we are writing, only
97 valid if save_name is nonzero */
98 off_t save_sizeleft
; /* where we are in the file we are writing,
99 only valid if save_name is nonzero */
101 bool write_archive_to_stdout
;
103 /* Used by flush_read and flush_write to store the real info about saved
105 static char *real_s_name
;
106 static off_t real_s_totsize
;
107 static off_t real_s_sizeleft
;
112 clear_read_error_count ()
114 read_error_count
= 0;
118 print_total_written (void)
120 tarlong written
= prev_written
+ bytes_written
;
121 char bytes
[sizeof (tarlong
) * CHAR_BIT
];
122 char abbr
[LONGEST_HUMAN_READABLE
+ 1];
123 char rate
[LONGEST_HUMAN_READABLE
+ 1];
125 int human_opts
= human_autoscale
| human_base_1024
| human_SI
| human_B
;
127 #if HAVE_CLOCK_GETTIME
129 if (clock_gettime (CLOCK_REALTIME
, &now
) == 0)
130 seconds
= ((now
.tv_sec
- start_timespec
.tv_sec
)
131 + (now
.tv_nsec
- start_timespec
.tv_nsec
) / 1e9
);
134 seconds
= time (0) - start_time
;
136 sprintf (bytes
, TARLONG_FORMAT
, written
);
138 /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
139 fprintf (stderr
, _("Total bytes written: %s (%s, %s/s)\n"), bytes
,
140 human_readable (written
, abbr
, human_opts
, 1, 1),
141 (0 < seconds
&& written
/ seconds
< (uintmax_t) -1
142 ? human_readable (written
/ seconds
, rate
, human_opts
, 1, 1)
146 /* Compute and return the block ordinal at current_block. */
148 current_block_ordinal (void)
150 return record_start_block
+ (current_block
- record_start
);
153 /* If the EOF flag is set, reset it, as well as current_block, etc. */
160 current_block
= record_start
;
161 record_end
= record_start
+ blocking_factor
;
162 access_mode
= ACCESS_WRITE
;
166 /* Return the location of the next available input or output block.
167 Return zero for EOF. Once we have returned zero, we just keep returning
168 it, to avoid accidentally going on to the next file on the tape. */
170 find_next_block (void)
172 if (current_block
== record_end
)
177 if (current_block
== record_end
)
183 return current_block
;
186 /* Indicate that we have used all blocks up thru BLOCK. */
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 of 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
)
275 record_start
= valloc (record_size
+ (2 * BLOCKSIZE
));
280 record_start
= valloc (record_size
);
282 FATAL_ERROR ((0, 0, _("Cannot allocate memory for blocking factor %d"),
285 current_block
= record_start
;
286 record_end
= record_start
+ blocking_factor
;
287 /* When updating the archive, we start with reading. */
288 access_mode
= wanted_access
== ACCESS_UPDATE
? ACCESS_READ
: wanted_access
;
290 if (use_compress_program_option
)
292 switch (wanted_access
)
295 child_pid
= sys_child_open_for_uncompress ();
299 child_pid
= sys_child_open_for_compress ();
303 abort (); /* Should not happen */
307 if (wanted_access
== ACCESS_WRITE
308 && strcmp (archive_name_array
[0], "-") == 0)
311 else if (strcmp (archive_name_array
[0], "-") == 0)
313 read_full_records_option
= 1; /* could be a pipe, be safe */
315 FATAL_ERROR ((0, 0, _("Cannot verify stdin/stdout archive")));
317 switch (wanted_access
)
320 archive
= STDIN_FILENO
;
324 archive
= STDOUT_FILENO
;
329 archive
= STDIN_FILENO
;
331 write_archive_to_stdout
= true;
335 else if (verify_option
)
336 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
337 MODE_RW
, rsh_command_option
);
339 switch (wanted_access
)
342 archive
= rmtopen (archive_name_array
[0], O_RDONLY
| O_BINARY
,
343 MODE_RW
, rsh_command_option
);
349 maybe_backup_file (archive_name_array
[0], 1);
352 archive
= rmtcreat (archive_name_array
[0], MODE_RW
,
357 archive
= rmtopen (archive_name_array
[0], O_RDWR
| O_CREAT
| O_BINARY
,
358 MODE_RW
, rsh_command_option
);
363 || (! _isrmt (archive
) && !sys_get_archive_stat ()))
365 int saved_errno
= errno
;
370 open_fatal (archive_name_array
[0]);
373 sys_detect_dev_null_output ();
374 sys_save_archive_dev_ino ();
375 SET_BINARY_MODE (archive
);
377 switch (wanted_access
)
383 record_end
= record_start
; /* set up for 1st record = # 0 */
384 find_next_block (); /* read it in, check for EOF */
386 if (volume_label_option
)
388 union block
*label
= find_next_block ();
391 FATAL_ERROR ((0, 0, _("Archive not labeled to match %s"),
392 quote (volume_label_option
)));
393 if (!check_label_pattern (label
))
394 FATAL_ERROR ((0, 0, _("Volume %s does not match %s"),
395 quote_n (0, label
->header
.name
),
396 quote_n (1, volume_label_option
)));
402 if (volume_label_option
)
404 memset (record_start
, 0, BLOCKSIZE
);
405 if (multi_volume_option
)
406 sprintf (record_start
->header
.name
, "%s Volume 1",
407 volume_label_option
);
409 strcpy (record_start
->header
.name
, volume_label_option
);
411 assign_string (¤t_stat_info
.file_name
, record_start
->header
.name
);
412 current_stat_info
.had_trailing_slash
= strip_trailing_slashes (current_stat_info
.file_name
);
414 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
415 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
416 finish_header (¤t_stat_info
, record_start
, -1);
422 /* Perform a write to flush the buffer. */
429 if (checkpoint_option
&& !(++checkpoint
% 10))
430 WARN ((0, 0, _("Write checkpoint %d"), checkpoint
));
432 if (tape_length_option
&& tape_length_option
<= bytes_written
)
437 else if (dev_null_output
)
438 status
= record_size
;
440 status
= sys_write_archive_buffer ();
441 if (status
!= record_size
&& !multi_volume_option
)
442 archive_write_error (status
);
447 bytes_written
+= status
;
450 if (status
== record_size
)
452 if (multi_volume_option
)
456 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
457 real_s_totsize
= save_totsize
;
458 real_s_sizeleft
= save_sizeleft
;
462 assign_string (&real_s_name
, 0);
470 /* We're multivol. Panic if we didn't get the right kind of response. */
472 /* ENXIO is for the UNIX PC. */
473 if (status
< 0 && errno
!= ENOSPC
&& errno
!= EIO
&& errno
!= ENXIO
)
474 archive_write_error (status
);
476 /* If error indicates a short write, we just move to the next tape. */
478 if (!new_volume (ACCESS_WRITE
))
482 prev_written
+= bytes_written
;
485 if (volume_label_option
&& real_s_name
)
490 else if (volume_label_option
|| real_s_name
)
498 if (volume_label_option
)
500 memset (record_start
, 0, BLOCKSIZE
);
501 sprintf (record_start
->header
.name
, "%s Volume %d",
502 volume_label_option
, volno
);
503 TIME_TO_CHARS (start_time
, record_start
->header
.mtime
);
504 record_start
->header
.typeflag
= GNUTYPE_VOLHDR
;
505 finish_header (¤t_stat_info
, record_start
, -1);
512 if (volume_label_option
)
515 memset (record_start
, 0, BLOCKSIZE
);
517 /* FIXME: Michael P Urban writes: [a long name file] is being written
518 when a new volume rolls around [...] Looks like the wrong value is
519 being preserved in real_s_name, though. */
521 strcpy (record_start
->header
.name
, real_s_name
);
522 record_start
->header
.typeflag
= GNUTYPE_MULTIVOL
;
523 OFF_TO_CHARS (real_s_sizeleft
, record_start
->header
.size
);
524 OFF_TO_CHARS (real_s_totsize
- real_s_sizeleft
,
525 record_start
->oldgnu_header
.offset
);
526 tmp
= verbose_option
;
528 finish_header (¤t_stat_info
, record_start
, -1);
529 verbose_option
= tmp
;
531 if (volume_label_option
)
535 status
= sys_write_archive_buffer ();
536 if (status
!= record_size
)
537 archive_write_error (status
);
539 bytes_written
+= status
;
543 record_start
+= copy_back
;
544 memcpy (current_block
,
545 record_start
+ blocking_factor
- copy_back
,
546 copy_back
* BLOCKSIZE
);
547 current_block
+= copy_back
;
549 if (real_s_sizeleft
>= copy_back
* BLOCKSIZE
)
550 real_s_sizeleft
-= copy_back
* BLOCKSIZE
;
551 else if ((real_s_sizeleft
+ BLOCKSIZE
- 1) / BLOCKSIZE
<= copy_back
)
552 assign_string (&real_s_name
, 0);
555 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
556 real_s_sizeleft
= save_sizeleft
;
557 real_s_totsize
= save_totsize
;
563 /* Handle write errors on the archive. Write errors are always fatal.
564 Hitting the end of a volume does not cause a write error unless the
565 write was the first record of the volume. */
567 archive_write_error (ssize_t status
)
569 /* It might be useful to know how much was written before the error
574 print_total_written ();
578 write_fatal_details (*archive_name_cursor
, status
, record_size
);
581 /* Handle read errors on the archive. If the read should be retried,
582 return to the caller. */
584 archive_read_error (void)
586 read_error (*archive_name_cursor
);
588 if (record_start_block
== 0)
589 FATAL_ERROR ((0, 0, _("At beginning of tape, quitting now")));
591 /* Read error in mid archive. We retry up to READ_ERROR_MAX times and
592 then give up on reading the archive. */
594 if (read_error_count
++ > READ_ERROR_MAX
)
595 FATAL_ERROR ((0, 0, _("Too many errors, quitting")));
600 short_read (ssize_t status
)
602 size_t left
; /* bytes left */
603 char *more
; /* pointer to next byte to read */
605 more
= record_start
->buffer
+ status
;
606 left
= record_size
- status
;
608 while (left
% BLOCKSIZE
!= 0
609 || (left
&& status
&& read_full_records_option
))
612 while ((status
= rmtread (archive
, more
, left
)) < 0)
613 archive_read_error ();
617 char buf
[UINTMAX_STRSIZE_BOUND
];
619 WARN((0, 0, _("Read %s bytes from %s"),
620 STRINGIFY_BIGINT (record_size
- left
, buf
),
621 *archive_name_cursor
));
625 if (! read_full_records_option
)
627 unsigned long rest
= record_size
- left
;
630 ngettext ("Unaligned block (%lu byte) in archive",
631 "Unaligned block (%lu bytes) in archive",
636 /* User warned us about this. Fix up. */
642 /* FIXME: for size=0, multi-volume support. On the first record, warn
643 about the problem. */
645 if (!read_full_records_option
&& verbose_option
646 && record_start_block
== 0 && status
> 0)
648 unsigned long rsize
= (record_size
- left
) / BLOCKSIZE
;
650 ngettext ("Record size = %lu block",
651 "Record size = %lu blocks",
656 record_end
= record_start
+ (record_size
- left
) / BLOCKSIZE
;
660 /* Perform a read to flush the buffer. */
664 ssize_t status
; /* result from system call */
666 if (checkpoint_option
&& !(++checkpoint
% 10))
667 WARN ((0, 0, _("Read checkpoint %d"), checkpoint
));
669 /* Clear the count of errors. This only applies to a single call to
672 read_error_count
= 0; /* clear error count */
674 if (write_archive_to_stdout
&& record_start_block
!= 0)
676 archive
= STDOUT_FILENO
;
677 status
= sys_write_archive_buffer ();
678 archive
= STDIN_FILENO
;
679 if (status
!= record_size
)
680 archive_write_error (status
);
682 if (multi_volume_option
)
686 assign_string (&real_s_name
, safer_name_suffix (save_name
, false));
687 real_s_sizeleft
= save_sizeleft
;
688 real_s_totsize
= save_totsize
;
692 assign_string (&real_s_name
, 0);
699 status
= rmtread (archive
, record_start
->buffer
, record_size
);
700 if (status
== record_size
)
707 || (status
< 0 && errno
== ENOSPC
)
708 || (status
> 0 && !read_full_records_option
))
709 && multi_volume_option
)
714 switch (subcommand_option
)
716 case APPEND_SUBCOMMAND
:
718 case UPDATE_SUBCOMMAND
:
719 if (!new_volume (ACCESS_UPDATE
))
724 if (!new_volume (ACCESS_READ
))
730 rmtread (archive
, record_start
->buffer
, record_size
)) < 0)
731 archive_read_error ();
733 if (status
!= record_size
)
736 cursor
= record_start
;
738 if (cursor
->header
.typeflag
== GNUTYPE_VOLHDR
)
740 if (volume_label_option
)
742 if (!check_label_pattern (cursor
))
744 WARN ((0, 0, _("Volume %s does not match %s"),
745 quote_n (0, cursor
->header
.name
),
746 quote_n (1, volume_label_option
)));
753 fprintf (stdlis
, _("Reading %s\n"), quote (cursor
->header
.name
));
756 else if (volume_label_option
)
757 WARN ((0, 0, _("WARNING: No volume header")));
762 if (cursor
->header
.typeflag
!= GNUTYPE_MULTIVOL
763 || strcmp (cursor
->header
.name
, real_s_name
))
765 WARN ((0, 0, _("%s is not continued on this volume"),
766 quote (real_s_name
)));
771 s1
= UINTMAX_FROM_HEADER (cursor
->header
.size
);
772 s2
= UINTMAX_FROM_HEADER (cursor
->oldgnu_header
.offset
);
773 if (real_s_totsize
!= s1
+ s2
|| s1
+ s2
< s2
)
775 char totsizebuf
[UINTMAX_STRSIZE_BOUND
];
776 char s1buf
[UINTMAX_STRSIZE_BOUND
];
777 char s2buf
[UINTMAX_STRSIZE_BOUND
];
779 WARN ((0, 0, _("%s is the wrong size (%s != %s + %s)"),
780 quote (cursor
->header
.name
),
781 STRINGIFY_BIGINT (save_totsize
, totsizebuf
),
782 STRINGIFY_BIGINT (s1
, s1buf
),
783 STRINGIFY_BIGINT (s2
, s2buf
)));
788 if (real_s_totsize
- real_s_sizeleft
789 != OFF_FROM_HEADER (cursor
->oldgnu_header
.offset
))
791 WARN ((0, 0, _("This volume is out of sequence")));
798 current_block
= cursor
;
804 archive_read_error ();
805 goto error_loop
; /* try again */
811 /* Flush the current buffer to/from the archive. */
815 record_start_block
+= record_end
- record_start
;
816 current_block
= record_start
;
817 record_end
= record_start
+ blocking_factor
;
819 if (access_mode
== ACCESS_READ
&& time_to_start_writing
)
821 access_mode
= ACCESS_WRITE
;
822 time_to_start_writing
= false;
841 /* Backspace the archive descriptor by one record worth. If it's a
842 tape, MTIOCTOP will work. If it's something else, try to seek on
843 it. If we can't seek, we lose! */
845 backspace_output (void)
849 struct mtop operation
;
851 operation
.mt_op
= MTBSR
;
852 operation
.mt_count
= 1;
853 if (rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
855 if (errno
== EIO
&& rmtioctl (archive
, MTIOCTOP
, (char *) &operation
) >= 0)
861 off_t position
= rmtlseek (archive
, (off_t
) 0, SEEK_CUR
);
863 /* Seek back to the beginning of this record and start writing there. */
865 position
-= record_size
;
868 if (rmtlseek (archive
, position
, SEEK_SET
) != position
)
870 /* Lseek failed. Try a different method. */
873 _("Cannot backspace archive file; it may be unreadable without -i")));
875 /* Replace the first part of the record with NULs. */
877 if (record_start
->buffer
!= output_start
)
878 memset (record_start
->buffer
, 0,
879 output_start
- record_start
->buffer
);
884 /* Close the archive file. */
888 if (time_to_start_writing
|| access_mode
== ACCESS_WRITE
)
891 sys_drain_input_pipe ();
896 if (rmtclose (archive
) != 0)
897 close_warn (*archive_name_cursor
);
899 sys_wait_for_child (child_pid
);
901 tar_stat_destroy (¤t_stat_info
);
906 free (multi_volume_option
? record_start
- 2 : record_start
);
909 /* Called to initialize the global volume number. */
911 init_volume_number (void)
913 FILE *file
= fopen (volno_file_option
, "r");
917 if (fscanf (file
, "%d", &global_volno
) != 1
919 FATAL_ERROR ((0, 0, _("%s: contains invalid volume number"),
920 quotearg_colon (volno_file_option
)));
922 read_error (volno_file_option
);
923 if (fclose (file
) != 0)
924 close_error (volno_file_option
);
926 else if (errno
!= ENOENT
)
927 open_error (volno_file_option
);
930 /* Called to write out the closing global volume number. */
932 closeout_volume_number (void)
934 FILE *file
= fopen (volno_file_option
, "w");
938 fprintf (file
, "%d\n", global_volno
);
940 write_error (volno_file_option
);
941 if (fclose (file
) != 0)
942 close_error (volno_file_option
);
945 open_error (volno_file_option
);
948 /* We've hit the end of the old volume. Close it and open the next one.
949 Return nonzero on success.
952 new_volume (enum access_mode access
)
954 static FILE *read_file
;
957 if (!read_file
&& !info_script_option
)
958 /* FIXME: if fopen is used, it will never be closed. */
959 read_file
= archive
== STDIN_FILENO
? fopen (TTY_NAME
, "r") : stdin
;
966 if (rmtclose (archive
) != 0)
967 close_warn (*archive_name_cursor
);
970 if (global_volno
< 0)
971 FATAL_ERROR ((0, 0, _("Volume number overflow")));
973 archive_name_cursor
++;
974 if (archive_name_cursor
== archive_name_array
+ archive_names
)
976 archive_name_cursor
= archive_name_array
;
983 /* We have to prompt from now on. */
985 if (info_script_option
)
987 if (volno_file_option
)
988 closeout_volume_number ();
989 if (system (info_script_option
) != 0)
990 FATAL_ERROR ((0, 0, _("`%s' command failed"), info_script_option
));
995 char input_buffer
[80];
997 fputc ('\007', stderr
);
999 _("Prepare volume #%d for %s and hit return: "),
1000 global_volno
, quote (*archive_name_cursor
));
1003 if (fgets (input_buffer
, sizeof input_buffer
, read_file
) == 0)
1005 WARN ((0, 0, _("EOF where user reply was expected")));
1007 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1008 && subcommand_option
!= LIST_SUBCOMMAND
1009 && subcommand_option
!= DIFF_SUBCOMMAND
)
1010 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1014 if (input_buffer
[0] == '\n'
1015 || input_buffer
[0] == 'y'
1016 || input_buffer
[0] == 'Y')
1019 switch (input_buffer
[0])
1023 /* FIXME: Might it be useful to disable the '!' command? */
1024 fprintf (stderr
, _("\
1025 n [name] Give a new file name for the next (and subsequent) volume(s)\n\
1027 ! Spawn a subshell\n\
1028 ? Print this list\n"));
1035 WARN ((0, 0, _("No new volume; exiting.\n")));
1037 if (subcommand_option
!= EXTRACT_SUBCOMMAND
1038 && subcommand_option
!= LIST_SUBCOMMAND
1039 && subcommand_option
!= DIFF_SUBCOMMAND
)
1040 WARN ((0, 0, _("WARNING: Archive is incomplete")));
1045 /* Get new file name. */
1048 char *name
= &input_buffer
[1];
1051 for (name
= input_buffer
+ 1;
1052 *name
== ' ' || *name
== '\t';
1056 for (cursor
= name
; *cursor
&& *cursor
!= '\n'; cursor
++)
1060 /* FIXME: the following allocation is never reclaimed. */
1061 *archive_name_cursor
= xstrdup (name
);
1072 if (strcmp (archive_name_cursor
[0], "-") == 0)
1074 read_full_records_option
= true;
1075 archive
= STDIN_FILENO
;
1077 else if (verify_option
)
1078 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1079 rsh_command_option
);
1084 archive
= rmtopen (*archive_name_cursor
, O_RDONLY
, MODE_RW
,
1085 rsh_command_option
);
1090 maybe_backup_file (*archive_name_cursor
, 1);
1091 archive
= rmtcreat (*archive_name_cursor
, MODE_RW
,
1092 rsh_command_option
);
1096 archive
= rmtopen (*archive_name_cursor
, O_RDWR
| O_CREAT
, MODE_RW
,
1097 rsh_command_option
);
1103 open_warn (*archive_name_cursor
);
1104 if (!verify_option
&& access
== ACCESS_WRITE
&& backup_option
)
1105 undo_last_backup ();
1109 SET_BINARY_MODE (archive
);