]> Dogcows Code - chaz/tar/blob - src/buffer.c
(magic): Add an entry for new lzma format. Proposed by Lasse Collin
[chaz/tar] / src / buffer.c
1 /* Buffer management for tar.
2
3 Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1999, 2000, 2001,
4 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 Written by John Gilmore, on 1985-08-25.
7
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 3, or (at your option) any later
11 version.
12
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.
17
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 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21
22 #include <system.h>
23 #include <system-ioctl.h>
24
25 #include <signal.h>
26
27 #include <closeout.h>
28 #include <fnmatch.h>
29 #include <human.h>
30 #include <quotearg.h>
31
32 #include "common.h"
33 #include <rmt.h>
34
35 /* Number of retries before giving up on read. */
36 #define READ_ERROR_MAX 10
37
38 /* Globbing pattern to append to volume label if initial match failed. */
39 #define VOLUME_LABEL_APPEND " Volume [1-9]*"
40
41 /* Variables. */
42
43 static tarlong prev_written; /* bytes written on previous volumes */
44 static tarlong bytes_written; /* bytes written on this volume */
45 static void *record_buffer[2]; /* allocated memory */
46 union block *record_buffer_aligned[2];
47 static int record_index;
48
49 /* FIXME: The following variables should ideally be static to this
50 module. However, this cannot be done yet. The cleanup continues! */
51
52 union block *record_start; /* start of record of archive */
53 union block *record_end; /* last+1 block of archive record */
54 union block *current_block; /* current block of archive */
55 enum access_mode access_mode; /* how do we handle the archive */
56 off_t records_read; /* number of records read from this archive */
57 off_t records_written; /* likewise, for records written */
58 extern off_t records_skipped; /* number of records skipped at the start
59 of the archive, defined in delete.c */
60
61 static off_t record_start_block; /* block ordinal at record_start */
62
63 /* Where we write list messages (not errors, not interactions) to. */
64 FILE *stdlis;
65
66 static void backspace_output (void);
67
68 /* PID of child program, if compress_option or remote archive access. */
69 static pid_t child_pid;
70
71 /* Error recovery stuff */
72 static int read_error_count;
73
74 /* Have we hit EOF yet? */
75 static bool hit_eof;
76
77 /* Checkpointing counter */
78 static unsigned checkpoint;
79
80 static bool read_full_records = false;
81
82 /* We're reading, but we just read the last block and it's time to update.
83 Declared in update.c
84
85 As least EXTERN like this one as possible. (?? --gray)
86 FIXME: Either eliminate it or move it to common.h.
87 */
88 extern bool time_to_start_writing;
89
90 bool write_archive_to_stdout;
91
92 void (*flush_write_ptr) (size_t);
93 void (*flush_read_ptr) (void);
94
95 \f
96 char *volume_label;
97 char *continued_file_name;
98 uintmax_t continued_file_size;
99 uintmax_t continued_file_offset;
100
101 \f
102 static int volno = 1; /* which volume of a multi-volume tape we're
103 on */
104 static int global_volno = 1; /* volume number to print in external
105 messages */
106
107 bool write_archive_to_stdout;
108
109 /* Used by flush_read and flush_write to store the real info about saved
110 names. */
111 static char *real_s_name;
112 static off_t real_s_totsize;
113 static off_t real_s_sizeleft;
114
115 \f
116 /* Multi-volume tracking support */
117 static char *save_name; /* name of the file we are currently writing */
118 static off_t save_totsize; /* total size of file we are writing, only
119 valid if save_name is nonzero */
120 static off_t save_sizeleft; /* where we are in the file we are writing,
121 only valid if save_name is nonzero */
122
123 \f
124 static struct tar_stat_info dummy;
125
126 void
127 buffer_write_global_xheader ()
128 {
129 xheader_write_global (&dummy.xhdr);
130 }
131
132 void
133 mv_begin (struct tar_stat_info *st)
134 {
135 if (multi_volume_option)
136 {
137 assign_string (&save_name, st->orig_file_name);
138 save_totsize = save_sizeleft = st->stat.st_size;
139 }
140 }
141
142 void
143 mv_end ()
144 {
145 if (multi_volume_option)
146 assign_string (&save_name, 0);
147 }
148
149 void
150 mv_total_size (off_t size)
151 {
152 save_totsize = size;
153 }
154
155 void
156 mv_size_left (off_t size)
157 {
158 save_sizeleft = size;
159 }
160
161 \f
162 /* Functions. */
163
164 void
165 clear_read_error_count (void)
166 {
167 read_error_count = 0;
168 }
169
170 \f
171 /* Time-related functions */
172
173 double duration;
174
175 void
176 set_start_time ()
177 {
178 gettime (&start_time);
179 volume_start_time = start_time;
180 last_stat_time = start_time;
181 }
182
183 void
184 set_volume_start_time ()
185 {
186 gettime (&volume_start_time);
187 last_stat_time = volume_start_time;
188 }
189
190 void
191 compute_duration ()
192 {
193 struct timespec now;
194 gettime (&now);
195 duration += ((now.tv_sec - last_stat_time.tv_sec)
196 + (now.tv_nsec - last_stat_time.tv_nsec) / 1e9);
197 gettime (&last_stat_time);
198 }
199
200 \f
201 /* Compression detection */
202
203 enum compress_type {
204 ct_none,
205 ct_compress,
206 ct_gzip,
207 ct_bzip2,
208 ct_lzma
209 };
210
211 struct zip_magic
212 {
213 enum compress_type type;
214 size_t length;
215 char *magic;
216 char *program;
217 char *option;
218 };
219
220 static struct zip_magic const magic[] = {
221 { ct_none, },
222 { ct_compress, 2, "\037\235", "compress", "-Z" },
223 { ct_gzip, 2, "\037\213", "gzip", "-z" },
224 { ct_bzip2, 3, "BZh", "bzip2", "-j" },
225 { ct_lzma, 6, "\xFFLZMA", "lzma", "-a" }, /* FIXME: ???? */
226 };
227
228 #define NMAGIC (sizeof(magic)/sizeof(magic[0]))
229
230 #define compress_option(t) magic[t].option
231 #define compress_program(t) magic[t].program
232
233 /* Check if the file ARCHIVE is a compressed archive. */
234 enum compress_type
235 check_compressed_archive ()
236 {
237 struct zip_magic const *p;
238 bool sfr;
239 bool short_file = false;
240
241 /* Prepare global data needed for find_next_block: */
242 record_end = record_start; /* set up for 1st record = # 0 */
243 sfr = read_full_records;
244 read_full_records = true; /* Suppress fatal error on reading a partial
245 record */
246 if (find_next_block () == 0)
247 short_file = true;
248
249 /* Restore global values */
250 read_full_records = sfr;
251
252 if (tar_checksum (record_start, true) == HEADER_SUCCESS)
253 /* Probably a valid header */
254 return ct_none;
255
256 for (p = magic + 1; p < magic + NMAGIC; p++)
257 if (memcmp (record_start->buffer, p->magic, p->length) == 0)
258 return p->type;
259
260 if (short_file)
261 ERROR ((0, 0, _("This does not look like a tar archive")));
262
263 return ct_none;
264 }
265
266 /* Open an archive named archive_name_array[0]. Detect if it is
267 a compressed archive of known type and use corresponding decompression
268 program if so */
269 int
270 open_compressed_archive ()
271 {
272 archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
273 MODE_RW, rsh_command_option);
274 if (archive == -1)
275 return archive;
276
277 if (!multi_volume_option)
278 {
279 enum compress_type type = check_compressed_archive ();
280
281 if (type == ct_none)
282 return archive;
283
284 /* FD is not needed any more */
285 rmtclose (archive);
286
287 hit_eof = false; /* It might have been set by find_next_block in
288 check_compressed_archive */
289
290 /* Open compressed archive */
291 use_compress_program_option = compress_program (type);
292 child_pid = sys_child_open_for_uncompress ();
293 read_full_records = true;
294 }
295
296 records_read = 0;
297 record_end = record_start; /* set up for 1st record = # 0 */
298
299 return archive;
300 }
301 \f
302
303 static void
304 print_stats (FILE *fp, const char *text, tarlong numbytes)
305 {
306 char bytes[sizeof (tarlong) * CHAR_BIT];
307 char abbr[LONGEST_HUMAN_READABLE + 1];
308 char rate[LONGEST_HUMAN_READABLE + 1];
309
310 int human_opts = human_autoscale | human_base_1024 | human_SI | human_B;
311
312 sprintf (bytes, TARLONG_FORMAT, numbytes);
313
314 fprintf (fp, "%s: %s (%s, %s/s)\n",
315 text, bytes,
316 human_readable (numbytes, abbr, human_opts, 1, 1),
317 (0 < duration && numbytes / duration < (uintmax_t) -1
318 ? human_readable (numbytes / duration, rate, human_opts, 1, 1)
319 : "?"));
320 }
321
322 void
323 print_total_stats ()
324 {
325 switch (subcommand_option)
326 {
327 case CREATE_SUBCOMMAND:
328 case CAT_SUBCOMMAND:
329 case UPDATE_SUBCOMMAND:
330 case APPEND_SUBCOMMAND:
331 /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
332 print_stats (stderr, _("Total bytes written"),
333 prev_written + bytes_written);
334 break;
335
336 case DELETE_SUBCOMMAND:
337 {
338 char buf[UINTMAX_STRSIZE_BOUND];
339 print_stats (stderr, _("Total bytes read"),
340 records_read * record_size);
341 print_stats (stderr, _("Total bytes written"),
342 prev_written + bytes_written);
343 fprintf (stderr, _("Total bytes deleted: %s\n"),
344 STRINGIFY_BIGINT ((records_read - records_skipped)
345 * record_size
346 - (prev_written + bytes_written), buf));
347 }
348 break;
349
350 case EXTRACT_SUBCOMMAND:
351 case LIST_SUBCOMMAND:
352 case DIFF_SUBCOMMAND:
353 print_stats (stderr, _("Total bytes read"),
354 records_read * record_size);
355 break;
356
357 default:
358 abort ();
359 }
360 }
361
362 /* Compute and return the block ordinal at current_block. */
363 off_t
364 current_block_ordinal (void)
365 {
366 return record_start_block + (current_block - record_start);
367 }
368
369 /* If the EOF flag is set, reset it, as well as current_block, etc. */
370 void
371 reset_eof (void)
372 {
373 if (hit_eof)
374 {
375 hit_eof = false;
376 current_block = record_start;
377 record_end = record_start + blocking_factor;
378 access_mode = ACCESS_WRITE;
379 }
380 }
381
382 /* Return the location of the next available input or output block.
383 Return zero for EOF. Once we have returned zero, we just keep returning
384 it, to avoid accidentally going on to the next file on the tape. */
385 union block *
386 find_next_block (void)
387 {
388 if (current_block == record_end)
389 {
390 if (hit_eof)
391 return 0;
392 flush_archive ();
393 if (current_block == record_end)
394 {
395 hit_eof = true;
396 return 0;
397 }
398 }
399 return current_block;
400 }
401
402 /* Indicate that we have used all blocks up thru BLOCK. */
403 void
404 set_next_block_after (union block *block)
405 {
406 while (block >= current_block)
407 current_block++;
408
409 /* Do *not* flush the archive here. If we do, the same argument to
410 set_next_block_after could mean the next block (if the input record
411 is exactly one block long), which is not what is intended. */
412
413 if (current_block > record_end)
414 abort ();
415 }
416
417 /* Return the number of bytes comprising the space between POINTER
418 through the end of the current buffer of blocks. This space is
419 available for filling with data, or taking data from. POINTER is
420 usually (but not always) the result of previous find_next_block call. */
421 size_t
422 available_space_after (union block *pointer)
423 {
424 return record_end->buffer - pointer->buffer;
425 }
426
427 /* Close file having descriptor FD, and abort if close unsuccessful. */
428 void
429 xclose (int fd)
430 {
431 if (close (fd) != 0)
432 close_error (_("(pipe)"));
433 }
434
435 static void
436 init_buffer ()
437 {
438 if (! record_buffer_aligned[record_index])
439 record_buffer_aligned[record_index] =
440 page_aligned_alloc (&record_buffer[record_index], record_size);
441
442 record_start = record_buffer_aligned[record_index];
443 current_block = record_start;
444 record_end = record_start + blocking_factor;
445 }
446
447 /* Open an archive file. The argument specifies whether we are
448 reading or writing, or both. */
449 static void
450 _open_archive (enum access_mode wanted_access)
451 {
452 int backed_up_flag = 0;
453
454 if (record_size == 0)
455 FATAL_ERROR ((0, 0, _("Invalid value for record_size")));
456
457 if (archive_names == 0)
458 FATAL_ERROR ((0, 0, _("No archive name given")));
459
460 tar_stat_destroy (&current_stat_info);
461 save_name = 0;
462 real_s_name = 0;
463
464 record_index = 0;
465 init_buffer ();
466
467 /* When updating the archive, we start with reading. */
468 access_mode = wanted_access == ACCESS_UPDATE ? ACCESS_READ : wanted_access;
469
470 read_full_records = read_full_records_option;
471
472 records_read = 0;
473
474 if (use_compress_program_option)
475 {
476 switch (wanted_access)
477 {
478 case ACCESS_READ:
479 child_pid = sys_child_open_for_uncompress ();
480 read_full_records = true;
481 record_end = record_start; /* set up for 1st record = # 0 */
482 break;
483
484 case ACCESS_WRITE:
485 child_pid = sys_child_open_for_compress ();
486 break;
487
488 case ACCESS_UPDATE:
489 abort (); /* Should not happen */
490 break;
491 }
492
493 if (!index_file_name
494 && wanted_access == ACCESS_WRITE
495 && strcmp (archive_name_array[0], "-") == 0)
496 stdlis = stderr;
497 }
498 else if (strcmp (archive_name_array[0], "-") == 0)
499 {
500 read_full_records = true; /* could be a pipe, be safe */
501 if (verify_option)
502 FATAL_ERROR ((0, 0, _("Cannot verify stdin/stdout archive")));
503
504 switch (wanted_access)
505 {
506 case ACCESS_READ:
507 {
508 enum compress_type type;
509
510 archive = STDIN_FILENO;
511
512 type = check_compressed_archive ();
513 if (type != ct_none)
514 FATAL_ERROR ((0, 0,
515 _("Archive is compressed. Use %s option"),
516 compress_option (type)));
517 }
518 break;
519
520 case ACCESS_WRITE:
521 archive = STDOUT_FILENO;
522 if (!index_file_name)
523 stdlis = stderr;
524 break;
525
526 case ACCESS_UPDATE:
527 archive = STDIN_FILENO;
528 write_archive_to_stdout = true;
529 record_end = record_start; /* set up for 1st record = # 0 */
530 if (!index_file_name)
531 stdlis = stderr;
532 break;
533 }
534 }
535 else if (verify_option)
536 archive = rmtopen (archive_name_array[0], O_RDWR | O_CREAT | O_BINARY,
537 MODE_RW, rsh_command_option);
538 else
539 switch (wanted_access)
540 {
541 case ACCESS_READ:
542 archive = open_compressed_archive ();
543 break;
544
545 case ACCESS_WRITE:
546 if (backup_option)
547 {
548 maybe_backup_file (archive_name_array[0], 1);
549 backed_up_flag = 1;
550 }
551 archive = rmtcreat (archive_name_array[0], MODE_RW,
552 rsh_command_option);
553 break;
554
555 case ACCESS_UPDATE:
556 archive = rmtopen (archive_name_array[0],
557 O_RDWR | O_CREAT | O_BINARY,
558 MODE_RW, rsh_command_option);
559
560 if (check_compressed_archive () != ct_none)
561 FATAL_ERROR ((0, 0,
562 _("Cannot update compressed archives")));
563 break;
564 }
565
566 if (archive < 0
567 || (! _isrmt (archive) && !sys_get_archive_stat ()))
568 {
569 int saved_errno = errno;
570
571 if (backed_up_flag)
572 undo_last_backup ();
573 errno = saved_errno;
574 open_fatal (archive_name_array[0]);
575 }
576
577 sys_detect_dev_null_output ();
578 sys_save_archive_dev_ino ();
579 SET_BINARY_MODE (archive);
580
581 switch (wanted_access)
582 {
583 case ACCESS_READ:
584 find_next_block (); /* read it in, check for EOF */
585 break;
586
587 case ACCESS_UPDATE:
588 case ACCESS_WRITE:
589 records_written = 0;
590 break;
591 }
592 }
593
594 static void
595 do_checkpoint (bool do_write)
596 {
597 if (checkpoint_option && !(++checkpoint % checkpoint_option))
598 {
599 switch (checkpoint_style)
600 {
601 case checkpoint_dot:
602 fputc ('.', stdlis);
603 fflush (stdlis);
604 break;
605
606 case checkpoint_text:
607 if (do_write)
608 /* TRANSLATORS: This is a ``checkpoint of write operation'',
609 *not* ``Writing a checkpoint''.
610 E.g. in Spanish ``Punto de comprobaci@'on de escritura'',
611 *not* ``Escribiendo un punto de comprobaci@'on'' */
612 WARN ((0, 0, _("Write checkpoint %u"), checkpoint));
613 else
614 /* TRANSLATORS: This is a ``checkpoint of read operation'',
615 *not* ``Reading a checkpoint''.
616 E.g. in Spanish ``Punto de comprobaci@'on de lectura'',
617 *not* ``Leyendo un punto de comprobaci@'on'' */
618 WARN ((0, 0, _("Read checkpoint %u"), checkpoint));
619 break;
620 }
621 }
622 }
623
624 /* Perform a write to flush the buffer. */
625 ssize_t
626 _flush_write (void)
627 {
628 ssize_t status;
629
630 do_checkpoint (true);
631 if (tape_length_option && tape_length_option <= bytes_written)
632 {
633 errno = ENOSPC;
634 status = 0;
635 }
636 else if (dev_null_output)
637 status = record_size;
638 else
639 status = sys_write_archive_buffer ();
640
641 return status;
642 }
643
644 /* Handle write errors on the archive. Write errors are always fatal.
645 Hitting the end of a volume does not cause a write error unless the
646 write was the first record of the volume. */
647 void
648 archive_write_error (ssize_t status)
649 {
650 /* It might be useful to know how much was written before the error
651 occurred. */
652 if (totals_option)
653 {
654 int e = errno;
655 print_total_stats ();
656 errno = e;
657 }
658
659 write_fatal_details (*archive_name_cursor, status, record_size);
660 }
661
662 /* Handle read errors on the archive. If the read should be retried,
663 return to the caller. */
664 void
665 archive_read_error (void)
666 {
667 read_error (*archive_name_cursor);
668
669 if (record_start_block == 0)
670 FATAL_ERROR ((0, 0, _("At beginning of tape, quitting now")));
671
672 /* Read error in mid archive. We retry up to READ_ERROR_MAX times and
673 then give up on reading the archive. */
674
675 if (read_error_count++ > READ_ERROR_MAX)
676 FATAL_ERROR ((0, 0, _("Too many errors, quitting")));
677 return;
678 }
679
680 static void
681 short_read (size_t status)
682 {
683 size_t left; /* bytes left */
684 char *more; /* pointer to next byte to read */
685
686 more = record_start->buffer + status;
687 left = record_size - status;
688
689 while (left % BLOCKSIZE != 0
690 || (left && status && read_full_records))
691 {
692 if (status)
693 while ((status = rmtread (archive, more, left)) == SAFE_READ_ERROR)
694 archive_read_error ();
695
696 if (status == 0)
697 break;
698
699 if (! read_full_records)
700 {
701 unsigned long rest = record_size - left;
702
703 FATAL_ERROR ((0, 0,
704 ngettext ("Unaligned block (%lu byte) in archive",
705 "Unaligned block (%lu bytes) in archive",
706 rest),
707 rest));
708 }
709
710 /* User warned us about this. Fix up. */
711
712 left -= status;
713 more += status;
714 }
715
716 /* FIXME: for size=0, multi-volume support. On the first record, warn
717 about the problem. */
718
719 if (!read_full_records && verbose_option > 1
720 && record_start_block == 0 && status != 0)
721 {
722 unsigned long rsize = (record_size - left) / BLOCKSIZE;
723 WARN ((0, 0,
724 ngettext ("Record size = %lu block",
725 "Record size = %lu blocks",
726 rsize),
727 rsize));
728 }
729
730 record_end = record_start + (record_size - left) / BLOCKSIZE;
731 records_read++;
732 }
733
734 /* Flush the current buffer to/from the archive. */
735 void
736 flush_archive (void)
737 {
738 size_t buffer_level = current_block->buffer - record_start->buffer;
739 record_start_block += record_end - record_start;
740 current_block = record_start;
741 record_end = record_start + blocking_factor;
742
743 if (access_mode == ACCESS_READ && time_to_start_writing)
744 {
745 access_mode = ACCESS_WRITE;
746 time_to_start_writing = false;
747 backspace_output ();
748 }
749
750 switch (access_mode)
751 {
752 case ACCESS_READ:
753 flush_read ();
754 break;
755
756 case ACCESS_WRITE:
757 flush_write_ptr (buffer_level);
758 break;
759
760 case ACCESS_UPDATE:
761 abort ();
762 }
763 }
764
765 /* Backspace the archive descriptor by one record worth. If it's a
766 tape, MTIOCTOP will work. If it's something else, try to seek on
767 it. If we can't seek, we lose! */
768 static void
769 backspace_output (void)
770 {
771 #ifdef MTIOCTOP
772 {
773 struct mtop operation;
774
775 operation.mt_op = MTBSR;
776 operation.mt_count = 1;
777 if (rmtioctl (archive, MTIOCTOP, (char *) &operation) >= 0)
778 return;
779 if (errno == EIO && rmtioctl (archive, MTIOCTOP, (char *) &operation) >= 0)
780 return;
781 }
782 #endif
783
784 {
785 off_t position = rmtlseek (archive, (off_t) 0, SEEK_CUR);
786
787 /* Seek back to the beginning of this record and start writing there. */
788
789 position -= record_size;
790 if (position < 0)
791 position = 0;
792 if (rmtlseek (archive, position, SEEK_SET) != position)
793 {
794 /* Lseek failed. Try a different method. */
795
796 WARN ((0, 0,
797 _("Cannot backspace archive file; it may be unreadable without -i")));
798
799 /* Replace the first part of the record with NULs. */
800
801 if (record_start->buffer != output_start)
802 memset (record_start->buffer, 0,
803 output_start - record_start->buffer);
804 }
805 }
806 }
807
808 off_t
809 seek_archive (off_t size)
810 {
811 off_t start = current_block_ordinal ();
812 off_t offset;
813 off_t nrec, nblk;
814 off_t skipped = (blocking_factor - (current_block - record_start));
815
816 size -= skipped * BLOCKSIZE;
817
818 if (size < record_size)
819 return 0;
820 /* FIXME: flush? */
821
822 /* Compute number of records to skip */
823 nrec = size / record_size;
824 offset = rmtlseek (archive, nrec * record_size, SEEK_CUR);
825 if (offset < 0)
826 return offset;
827
828 if (offset % record_size)
829 FATAL_ERROR ((0, 0, _("rmtlseek not stopped at a record boundary")));
830
831 /* Convert to number of records */
832 offset /= BLOCKSIZE;
833 /* Compute number of skipped blocks */
834 nblk = offset - start;
835
836 /* Update buffering info */
837 records_read += nblk / blocking_factor;
838 record_start_block = offset - blocking_factor;
839 current_block = record_end;
840
841 return nblk;
842 }
843
844 /* Close the archive file. */
845 void
846 close_archive (void)
847 {
848 if (time_to_start_writing || access_mode == ACCESS_WRITE)
849 {
850 flush_archive ();
851 if (current_block > record_start)
852 flush_archive ();
853 }
854
855 sys_drain_input_pipe ();
856
857 compute_duration ();
858 if (verify_option)
859 verify_volume ();
860
861 if (rmtclose (archive) != 0)
862 close_warn (*archive_name_cursor);
863
864 sys_wait_for_child (child_pid);
865
866 tar_stat_destroy (&current_stat_info);
867 if (save_name)
868 free (save_name);
869 if (real_s_name)
870 free (real_s_name);
871 free (record_buffer[0]);
872 free (record_buffer[1]);
873 }
874
875 /* Called to initialize the global volume number. */
876 void
877 init_volume_number (void)
878 {
879 FILE *file = fopen (volno_file_option, "r");
880
881 if (file)
882 {
883 if (fscanf (file, "%d", &global_volno) != 1
884 || global_volno < 0)
885 FATAL_ERROR ((0, 0, _("%s: contains invalid volume number"),
886 quotearg_colon (volno_file_option)));
887 if (ferror (file))
888 read_error (volno_file_option);
889 if (fclose (file) != 0)
890 close_error (volno_file_option);
891 }
892 else if (errno != ENOENT)
893 open_error (volno_file_option);
894 }
895
896 /* Called to write out the closing global volume number. */
897 void
898 closeout_volume_number (void)
899 {
900 FILE *file = fopen (volno_file_option, "w");
901
902 if (file)
903 {
904 fprintf (file, "%d\n", global_volno);
905 if (ferror (file))
906 write_error (volno_file_option);
907 if (fclose (file) != 0)
908 close_error (volno_file_option);
909 }
910 else
911 open_error (volno_file_option);
912 }
913
914 \f
915 static void
916 increase_volume_number ()
917 {
918 global_volno++;
919 if (global_volno < 0)
920 FATAL_ERROR ((0, 0, _("Volume number overflow")));
921 volno++;
922 }
923
924 void
925 change_tape_menu (FILE *read_file)
926 {
927 char *input_buffer = NULL;
928 size_t size = 0;
929 bool stop = false;
930
931 while (!stop)
932 {
933 fputc ('\007', stderr);
934 fprintf (stderr,
935 _("Prepare volume #%d for %s and hit return: "),
936 global_volno + 1, quote (*archive_name_cursor));
937 fflush (stderr);
938
939 if (getline (&input_buffer, &size, read_file) <= 0)
940 {
941 WARN ((0, 0, _("EOF where user reply was expected")));
942
943 if (subcommand_option != EXTRACT_SUBCOMMAND
944 && subcommand_option != LIST_SUBCOMMAND
945 && subcommand_option != DIFF_SUBCOMMAND)
946 WARN ((0, 0, _("WARNING: Archive is incomplete")));
947
948 fatal_exit ();
949 }
950
951 if (input_buffer[0] == '\n'
952 || input_buffer[0] == 'y'
953 || input_buffer[0] == 'Y')
954 break;
955
956 switch (input_buffer[0])
957 {
958 case '?':
959 {
960 fprintf (stderr, _("\
961 n name Give a new file name for the next (and subsequent) volume(s)\n\
962 q Abort tar\n\
963 y or newline Continue operation\n"));
964 if (!restrict_option)
965 fprintf (stderr, _(" ! Spawn a subshell\n"));
966 fprintf (stderr, _(" ? Print this list\n"));
967 }
968 break;
969
970 case 'q':
971 /* Quit. */
972
973 WARN ((0, 0, _("No new volume; exiting.\n")));
974
975 if (subcommand_option != EXTRACT_SUBCOMMAND
976 && subcommand_option != LIST_SUBCOMMAND
977 && subcommand_option != DIFF_SUBCOMMAND)
978 WARN ((0, 0, _("WARNING: Archive is incomplete")));
979
980 fatal_exit ();
981
982 case 'n':
983 /* Get new file name. */
984
985 {
986 char *name;
987 char *cursor;
988
989 for (name = input_buffer + 1;
990 *name == ' ' || *name == '\t';
991 name++)
992 ;
993
994 for (cursor = name; *cursor && *cursor != '\n'; cursor++)
995 ;
996 *cursor = '\0';
997
998 if (name[0])
999 {
1000 /* FIXME: the following allocation is never reclaimed. */
1001 *archive_name_cursor = xstrdup (name);
1002 stop = true;
1003 }
1004 else
1005 fprintf (stderr, "%s",
1006 _("File name not specified. Try again.\n"));
1007 }
1008 break;
1009
1010 case '!':
1011 if (!restrict_option)
1012 {
1013 sys_spawn_shell ();
1014 break;
1015 }
1016 /* FALL THROUGH */
1017
1018 default:
1019 fprintf (stderr, _("Invalid input. Type ? for help.\n"));
1020 }
1021 }
1022 free (input_buffer);
1023 }
1024
1025 /* We've hit the end of the old volume. Close it and open the next one.
1026 Return nonzero on success.
1027 */
1028 static bool
1029 new_volume (enum access_mode mode)
1030 {
1031 static FILE *read_file;
1032 static int looped;
1033 int prompt;
1034
1035 if (!read_file && !info_script_option)
1036 /* FIXME: if fopen is used, it will never be closed. */
1037 read_file = archive == STDIN_FILENO ? fopen (TTY_NAME, "r") : stdin;
1038
1039 if (now_verifying)
1040 return false;
1041 if (verify_option)
1042 verify_volume ();
1043
1044 assign_string (&volume_label, NULL);
1045 assign_string (&continued_file_name, NULL);
1046 continued_file_size = continued_file_offset = 0;
1047 current_block = record_start;
1048
1049 if (rmtclose (archive) != 0)
1050 close_warn (*archive_name_cursor);
1051
1052 archive_name_cursor++;
1053 if (archive_name_cursor == archive_name_array + archive_names)
1054 {
1055 archive_name_cursor = archive_name_array;
1056 looped = 1;
1057 }
1058 prompt = looped;
1059
1060 tryagain:
1061 if (prompt)
1062 {
1063 /* We have to prompt from now on. */
1064
1065 if (info_script_option)
1066 {
1067 if (volno_file_option)
1068 closeout_volume_number ();
1069 if (sys_exec_info_script (archive_name_cursor, global_volno+1))
1070 FATAL_ERROR ((0, 0, _("%s command failed"),
1071 quote (info_script_option)));
1072 }
1073 else
1074 change_tape_menu (read_file);
1075 }
1076
1077 if (strcmp (archive_name_cursor[0], "-") == 0)
1078 {
1079 read_full_records = true;
1080 archive = STDIN_FILENO;
1081 }
1082 else if (verify_option)
1083 archive = rmtopen (*archive_name_cursor, O_RDWR | O_CREAT, MODE_RW,
1084 rsh_command_option);
1085 else
1086 switch (mode)
1087 {
1088 case ACCESS_READ:
1089 archive = rmtopen (*archive_name_cursor, O_RDONLY, MODE_RW,
1090 rsh_command_option);
1091 break;
1092
1093 case ACCESS_WRITE:
1094 if (backup_option)
1095 maybe_backup_file (*archive_name_cursor, 1);
1096 archive = rmtcreat (*archive_name_cursor, MODE_RW,
1097 rsh_command_option);
1098 break;
1099
1100 case ACCESS_UPDATE:
1101 archive = rmtopen (*archive_name_cursor, O_RDWR | O_CREAT, MODE_RW,
1102 rsh_command_option);
1103 break;
1104 }
1105
1106 if (archive < 0)
1107 {
1108 open_warn (*archive_name_cursor);
1109 if (!verify_option && mode == ACCESS_WRITE && backup_option)
1110 undo_last_backup ();
1111 prompt = 1;
1112 goto tryagain;
1113 }
1114
1115 SET_BINARY_MODE (archive);
1116
1117 return true;
1118 }
1119
1120 static bool
1121 read_header0 (struct tar_stat_info *info)
1122 {
1123 enum read_header rc;
1124
1125 tar_stat_init (info);
1126 rc = read_header_primitive (false, info);
1127 if (rc == HEADER_SUCCESS)
1128 {
1129 set_next_block_after (current_header);
1130 return true;
1131 }
1132 ERROR ((0, 0, _("This does not look like a tar archive")));
1133 return false;
1134 }
1135
1136 bool
1137 try_new_volume ()
1138 {
1139 size_t status;
1140 union block *header;
1141 enum access_mode acc;
1142
1143 switch (subcommand_option)
1144 {
1145 case APPEND_SUBCOMMAND:
1146 case CAT_SUBCOMMAND:
1147 case UPDATE_SUBCOMMAND:
1148 acc = ACCESS_UPDATE;
1149 break;
1150
1151 default:
1152 acc = ACCESS_READ;
1153 break;
1154 }
1155
1156 if (!new_volume (acc))
1157 return true;
1158
1159 while ((status = rmtread (archive, record_start->buffer, record_size))
1160 == SAFE_READ_ERROR)
1161 archive_read_error ();
1162
1163 if (status != record_size)
1164 short_read (status);
1165
1166 header = find_next_block ();
1167 if (!header)
1168 return false;
1169
1170 switch (header->header.typeflag)
1171 {
1172 case XGLTYPE:
1173 {
1174 if (!read_header0 (&dummy))
1175 return false;
1176 xheader_decode (&dummy); /* decodes values from the global header */
1177 tar_stat_destroy (&dummy);
1178 if (!real_s_name)
1179 {
1180 /* We have read the extended header of the first member in
1181 this volume. Put it back, so next read_header works as
1182 expected. */
1183 current_block = record_start;
1184 }
1185 break;
1186 }
1187
1188 case GNUTYPE_VOLHDR:
1189 if (!read_header0 (&dummy))
1190 return false;
1191 tar_stat_destroy (&dummy);
1192 assign_string (&volume_label, current_header->header.name);
1193 set_next_block_after (header);
1194 header = find_next_block ();
1195 if (header->header.typeflag != GNUTYPE_MULTIVOL)
1196 break;
1197 /* FALL THROUGH */
1198
1199 case GNUTYPE_MULTIVOL:
1200 if (!read_header0 (&dummy))
1201 return false;
1202 tar_stat_destroy (&dummy);
1203 assign_string (&continued_file_name, current_header->header.name);
1204 continued_file_size =
1205 UINTMAX_FROM_HEADER (current_header->header.size);
1206 continued_file_offset =
1207 UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset);
1208 break;
1209
1210 default:
1211 break;
1212 }
1213
1214 if (real_s_name)
1215 {
1216 uintmax_t s;
1217 if (!continued_file_name
1218 || strcmp (continued_file_name, real_s_name))
1219 {
1220 if ((archive_format == GNU_FORMAT || archive_format == OLDGNU_FORMAT)
1221 && strlen (real_s_name) >= NAME_FIELD_SIZE
1222 && strncmp (continued_file_name, real_s_name,
1223 NAME_FIELD_SIZE) == 0)
1224 WARN ((0, 0,
1225 _("%s is possibly continued on this volume: header contains truncated name"),
1226 quote (real_s_name)));
1227 else
1228 {
1229 WARN ((0, 0, _("%s is not continued on this volume"),
1230 quote (real_s_name)));
1231 return false;
1232 }
1233 }
1234
1235 s = continued_file_size + continued_file_offset;
1236
1237 if (real_s_totsize != s || s < continued_file_offset)
1238 {
1239 char totsizebuf[UINTMAX_STRSIZE_BOUND];
1240 char s1buf[UINTMAX_STRSIZE_BOUND];
1241 char s2buf[UINTMAX_STRSIZE_BOUND];
1242
1243 WARN ((0, 0, _("%s is the wrong size (%s != %s + %s)"),
1244 quote (continued_file_name),
1245 STRINGIFY_BIGINT (save_totsize, totsizebuf),
1246 STRINGIFY_BIGINT (continued_file_size, s1buf),
1247 STRINGIFY_BIGINT (continued_file_offset, s2buf)));
1248 return false;
1249 }
1250
1251 if (real_s_totsize - real_s_sizeleft != continued_file_offset)
1252 {
1253 WARN ((0, 0, _("This volume is out of sequence")));
1254 return false;
1255 }
1256 }
1257
1258 increase_volume_number ();
1259 return true;
1260 }
1261
1262 \f
1263 /* Check the LABEL block against the volume label, seen as a globbing
1264 pattern. Return true if the pattern matches. In case of failure,
1265 retry matching a volume sequence number before giving up in
1266 multi-volume mode. */
1267 static bool
1268 check_label_pattern (union block *label)
1269 {
1270 char *string;
1271 bool result;
1272
1273 if (! memchr (label->header.name, '\0', sizeof label->header.name))
1274 return false;
1275
1276 if (fnmatch (volume_label_option, label->header.name, 0) == 0)
1277 return true;
1278
1279 if (!multi_volume_option)
1280 return false;
1281
1282 string = xmalloc (strlen (volume_label_option)
1283 + sizeof VOLUME_LABEL_APPEND + 1);
1284 strcpy (string, volume_label_option);
1285 strcat (string, VOLUME_LABEL_APPEND);
1286 result = fnmatch (string, label->header.name, 0) == 0;
1287 free (string);
1288 return result;
1289 }
1290
1291 /* Check if the next block contains a volume label and if this matches
1292 the one given in the command line */
1293 static void
1294 match_volume_label (void)
1295 {
1296 union block *label = find_next_block ();
1297
1298 if (!label)
1299 FATAL_ERROR ((0, 0, _("Archive not labeled to match %s"),
1300 quote (volume_label_option)));
1301 if (!check_label_pattern (label))
1302 FATAL_ERROR ((0, 0, _("Volume %s does not match %s"),
1303 quote_n (0, label->header.name),
1304 quote_n (1, volume_label_option)));
1305 }
1306
1307 /* Mark the archive with volume label STR. */
1308 static void
1309 _write_volume_label (const char *str)
1310 {
1311 if (archive_format == POSIX_FORMAT)
1312 xheader_store ("GNU.volume.label", &dummy, str);
1313 else
1314 {
1315 union block *label = find_next_block ();
1316
1317 memset (label, 0, BLOCKSIZE);
1318
1319 strcpy (label->header.name, volume_label_option);
1320 assign_string (&current_stat_info.file_name,
1321 label->header.name);
1322 current_stat_info.had_trailing_slash =
1323 strip_trailing_slashes (current_stat_info.file_name);
1324
1325 label->header.typeflag = GNUTYPE_VOLHDR;
1326 TIME_TO_CHARS (start_time.tv_sec, label->header.mtime);
1327 finish_header (&current_stat_info, label, -1);
1328 set_next_block_after (label);
1329 }
1330 }
1331
1332 #define VOL_SUFFIX "Volume"
1333
1334 /* Add a volume label to a part of multi-volume archive */
1335 static void
1336 add_volume_label (void)
1337 {
1338 char buf[UINTMAX_STRSIZE_BOUND];
1339 char *p = STRINGIFY_BIGINT (volno, buf);
1340 char *s = xmalloc (strlen (volume_label_option) + sizeof VOL_SUFFIX
1341 + strlen (p) + 2);
1342 sprintf (s, "%s %s %s", volume_label_option, VOL_SUFFIX, p);
1343 _write_volume_label (s);
1344 free (s);
1345 }
1346
1347 static void
1348 add_chunk_header ()
1349 {
1350 if (archive_format == POSIX_FORMAT)
1351 {
1352 off_t block_ordinal;
1353 union block *blk;
1354 struct tar_stat_info st;
1355 static size_t real_s_part_no; /* FIXME */
1356
1357 real_s_part_no++;
1358 memset (&st, 0, sizeof st);
1359 st.orig_file_name = st.file_name = real_s_name;
1360 st.stat.st_mode = S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
1361 st.stat.st_uid = getuid ();
1362 st.stat.st_gid = getgid ();
1363 st.orig_file_name = xheader_format_name (&st,
1364 "%d/GNUFileParts.%p/%f.%n",
1365 real_s_part_no);
1366 st.file_name = st.orig_file_name;
1367 st.archive_file_size = st.stat.st_size = real_s_sizeleft;
1368
1369 block_ordinal = current_block_ordinal ();
1370 blk = start_header (&st);
1371 if (!blk)
1372 abort (); /* FIXME */
1373 finish_header (&st, blk, block_ordinal);
1374 free (st.orig_file_name);
1375 }
1376 }
1377
1378
1379 /* Add a volume label to the current archive */
1380 static void
1381 write_volume_label (void)
1382 {
1383 if (multi_volume_option)
1384 add_volume_label ();
1385 else
1386 _write_volume_label (volume_label_option);
1387 }
1388
1389 /* Write GNU multi-volume header */
1390 static void
1391 gnu_add_multi_volume_header (void)
1392 {
1393 int tmp;
1394 union block *block = find_next_block ();
1395
1396 if (strlen (real_s_name) > NAME_FIELD_SIZE)
1397 WARN ((0, 0,
1398 _("%s: file name too long to be stored in a GNU multivolume header, truncated"),
1399 quotearg_colon (real_s_name)));
1400
1401 memset (block, 0, BLOCKSIZE);
1402
1403 /* FIXME: Michael P Urban writes: [a long name file] is being written
1404 when a new volume rolls around [...] Looks like the wrong value is
1405 being preserved in real_s_name, though. */
1406
1407 strncpy (block->header.name, real_s_name, NAME_FIELD_SIZE);
1408 block->header.typeflag = GNUTYPE_MULTIVOL;
1409
1410 OFF_TO_CHARS (real_s_sizeleft, block->header.size);
1411 OFF_TO_CHARS (real_s_totsize - real_s_sizeleft,
1412 block->oldgnu_header.offset);
1413
1414 tmp = verbose_option;
1415 verbose_option = 0;
1416 finish_header (&current_stat_info, block, -1);
1417 verbose_option = tmp;
1418 set_next_block_after (block);
1419 }
1420
1421 /* Add a multi volume header to the current archive. The exact header format
1422 depends on the archive format. */
1423 static void
1424 add_multi_volume_header (void)
1425 {
1426 if (archive_format == POSIX_FORMAT)
1427 {
1428 off_t d = real_s_totsize - real_s_sizeleft;
1429 xheader_store ("GNU.volume.filename", &dummy, real_s_name);
1430 xheader_store ("GNU.volume.size", &dummy, &real_s_sizeleft);
1431 xheader_store ("GNU.volume.offset", &dummy, &d);
1432 }
1433 else
1434 gnu_add_multi_volume_header ();
1435 }
1436
1437 /* Synchronize multi-volume globals */
1438 static void
1439 multi_volume_sync ()
1440 {
1441 if (multi_volume_option)
1442 {
1443 if (save_name)
1444 {
1445 assign_string (&real_s_name,
1446 safer_name_suffix (save_name, false,
1447 absolute_names_option));
1448 real_s_totsize = save_totsize;
1449 real_s_sizeleft = save_sizeleft;
1450 }
1451 else
1452 {
1453 assign_string (&real_s_name, 0);
1454 real_s_totsize = 0;
1455 real_s_sizeleft = 0;
1456 }
1457 }
1458 }
1459
1460 \f
1461 /* Low-level flush functions */
1462
1463 /* Simple flush read (no multi-volume or label extensions) */
1464 static void
1465 simple_flush_read (void)
1466 {
1467 size_t status; /* result from system call */
1468
1469 do_checkpoint (false);
1470
1471 /* Clear the count of errors. This only applies to a single call to
1472 flush_read. */
1473
1474 read_error_count = 0; /* clear error count */
1475
1476 if (write_archive_to_stdout && record_start_block != 0)
1477 {
1478 archive = STDOUT_FILENO;
1479 status = sys_write_archive_buffer ();
1480 archive = STDIN_FILENO;
1481 if (status != record_size)
1482 archive_write_error (status);
1483 }
1484
1485 for (;;)
1486 {
1487 status = rmtread (archive, record_start->buffer, record_size);
1488 if (status == record_size)
1489 {
1490 records_read++;
1491 return;
1492 }
1493 if (status == SAFE_READ_ERROR)
1494 {
1495 archive_read_error ();
1496 continue; /* try again */
1497 }
1498 break;
1499 }
1500 short_read (status);
1501 }
1502
1503 /* Simple flush write (no multi-volume or label extensions) */
1504 static void
1505 simple_flush_write (size_t level __attribute__((unused)))
1506 {
1507 ssize_t status;
1508
1509 status = _flush_write ();
1510 if (status != record_size)
1511 archive_write_error (status);
1512 else
1513 {
1514 records_written++;
1515 bytes_written += status;
1516 }
1517 }
1518
1519 \f
1520 /* GNU flush functions. These support multi-volume and archive labels in
1521 GNU and PAX archive formats. */
1522
1523 static void
1524 _gnu_flush_read (void)
1525 {
1526 size_t status; /* result from system call */
1527
1528 do_checkpoint (false);
1529
1530 /* Clear the count of errors. This only applies to a single call to
1531 flush_read. */
1532
1533 read_error_count = 0; /* clear error count */
1534
1535 if (write_archive_to_stdout && record_start_block != 0)
1536 {
1537 archive = STDOUT_FILENO;
1538 status = sys_write_archive_buffer ();
1539 archive = STDIN_FILENO;
1540 if (status != record_size)
1541 archive_write_error (status);
1542 }
1543
1544 multi_volume_sync ();
1545
1546 for (;;)
1547 {
1548 status = rmtread (archive, record_start->buffer, record_size);
1549 if (status == record_size)
1550 {
1551 records_read++;
1552 return;
1553 }
1554
1555 /* The condition below used to include
1556 || (status > 0 && !read_full_records)
1557 This is incorrect since even if new_volume() succeeds, the
1558 subsequent call to rmtread will overwrite the chunk of data
1559 already read in the buffer, so the processing will fail */
1560 if ((status == 0
1561 || (status == SAFE_READ_ERROR && errno == ENOSPC))
1562 && multi_volume_option)
1563 {
1564 while (!try_new_volume ())
1565 ;
1566 return;
1567 }
1568 else if (status == SAFE_READ_ERROR)
1569 {
1570 archive_read_error ();
1571 continue;
1572 }
1573 break;
1574 }
1575 short_read (status);
1576 }
1577
1578 static void
1579 gnu_flush_read (void)
1580 {
1581 flush_read_ptr = simple_flush_read; /* Avoid recursion */
1582 _gnu_flush_read ();
1583 flush_read_ptr = gnu_flush_read;
1584 }
1585
1586 static void
1587 _gnu_flush_write (size_t buffer_level)
1588 {
1589 ssize_t status;
1590 union block *header;
1591 char *copy_ptr;
1592 size_t copy_size;
1593 size_t bufsize;
1594
1595 status = _flush_write ();
1596 if (status != record_size && !multi_volume_option)
1597 archive_write_error (status);
1598 else
1599 {
1600 records_written++;
1601 bytes_written += status;
1602 }
1603
1604 if (status == record_size)
1605 {
1606 multi_volume_sync ();
1607 return;
1608 }
1609
1610 /* In multi-volume mode. */
1611 /* ENXIO is for the UNIX PC. */
1612 if (status < 0 && errno != ENOSPC && errno != EIO && errno != ENXIO)
1613 archive_write_error (status);
1614
1615 if (!new_volume (ACCESS_WRITE))
1616 return;
1617
1618 tar_stat_destroy (&dummy);
1619
1620 increase_volume_number ();
1621 prev_written += bytes_written;
1622 bytes_written = 0;
1623
1624 copy_ptr = record_start->buffer + status;
1625 copy_size = buffer_level - status;
1626 /* Switch to the next buffer */
1627 record_index = !record_index;
1628 init_buffer ();
1629
1630 if (volume_label_option)
1631 add_volume_label ();
1632
1633 if (real_s_name)
1634 add_multi_volume_header ();
1635
1636 write_extended (true, &dummy, find_next_block ());
1637 tar_stat_destroy (&dummy);
1638
1639 if (real_s_name)
1640 add_chunk_header ();
1641 header = find_next_block ();
1642 bufsize = available_space_after (header);
1643 while (bufsize < copy_size)
1644 {
1645 memcpy (header->buffer, copy_ptr, bufsize);
1646 copy_ptr += bufsize;
1647 copy_size -= bufsize;
1648 set_next_block_after (header + (bufsize - 1) / BLOCKSIZE);
1649 header = find_next_block ();
1650 bufsize = available_space_after (header);
1651 }
1652 memcpy (header->buffer, copy_ptr, copy_size);
1653 memset (header->buffer + copy_size, 0, bufsize - copy_size);
1654 set_next_block_after (header + (copy_size - 1) / BLOCKSIZE);
1655 find_next_block ();
1656 }
1657
1658 static void
1659 gnu_flush_write (size_t buffer_level)
1660 {
1661 flush_write_ptr = simple_flush_write; /* Avoid recursion */
1662 _gnu_flush_write (buffer_level);
1663 flush_write_ptr = gnu_flush_write;
1664 }
1665
1666 void
1667 flush_read ()
1668 {
1669 flush_read_ptr ();
1670 }
1671
1672 void
1673 flush_write ()
1674 {
1675 flush_write_ptr (record_size);
1676 }
1677
1678 void
1679 open_archive (enum access_mode wanted_access)
1680 {
1681 flush_read_ptr = gnu_flush_read;
1682 flush_write_ptr = gnu_flush_write;
1683
1684 _open_archive (wanted_access);
1685 switch (wanted_access)
1686 {
1687 case ACCESS_READ:
1688 if (volume_label_option)
1689 match_volume_label ();
1690 break;
1691
1692 case ACCESS_WRITE:
1693 records_written = 0;
1694 if (volume_label_option)
1695 write_volume_label ();
1696 break;
1697
1698 default:
1699 break;
1700 }
1701 set_volume_start_time ();
1702 }
This page took 0.115653 seconds and 5 git commands to generate.