X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbuffer.c;h=cd70c732aa1493c0be8a959bf5fe0fc50ce713bf;hb=9dfad74683d23094732a36429aeac720210a0c1d;hp=81efe323eff270b531b486584ff12554068fe355;hpb=476019d08388d0db5c0cf1aeec5e8e32ebed073d;p=chaz%2Ftar diff --git a/src/buffer.c b/src/buffer.c index 81efe32..cd70c73 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -20,11 +20,13 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include +#include #include #include #include +#include #include #include @@ -42,6 +44,7 @@ static tarlong prev_written; /* bytes written on previous volumes */ static tarlong bytes_written; /* bytes written on this volume */ static void *record_buffer[2]; /* allocated memory */ +union block *record_buffer_aligned[2]; static int record_index; /* FIXME: The following variables should ideally be static to this @@ -367,10 +370,11 @@ xclose (int fd) static void init_buffer () { - if (!record_buffer[record_index]) - page_aligned_alloc (&record_buffer[record_index], record_size); + if (! record_buffer_aligned[record_index]) + record_buffer_aligned[record_index] = + page_aligned_alloc (&record_buffer[record_index], record_size); - record_start = record_buffer[record_index]; + record_start = record_buffer_aligned[record_index]; current_block = record_start; record_end = record_start + blocking_factor; } @@ -449,7 +453,7 @@ _open_archive (enum access_mode wanted_access) archive = STDIN_FILENO; - type = check_compressed_archive (archive); + type = check_compressed_archive (); if (type != ct_none) FATAL_ERROR ((0, 0, _("Archive is compressed. Use %s option"), @@ -870,8 +874,9 @@ change_tape_menu (FILE *read_file) { char *input_buffer = NULL; size_t size = 0; - - while (1) + bool stop = false; + + while (!stop) { fputc ('\007', stderr); fprintf (stderr, @@ -901,7 +906,7 @@ change_tape_menu (FILE *read_file) case '?': { fprintf (stderr, _("\ - n [name] Give a new file name for the next (and subsequent) volume(s)\n\ + n name Give a new file name for the next (and subsequent) volume(s)\n\ q Abort tar\n\ y or newline Continue operation\n")); if (!restrict_option) @@ -938,8 +943,15 @@ change_tape_menu (FILE *read_file) ; *cursor = '\0'; - /* FIXME: the following allocation is never reclaimed. */ - *archive_name_cursor = xstrdup (name); + if (name[0]) + { + /* FIXME: the following allocation is never reclaimed. */ + *archive_name_cursor = xstrdup (name); + stop = true; + } + else + fprintf (stderr, "%s", + _("File name not specified. Try again.\n")); } break; @@ -967,7 +979,7 @@ new_volume (enum access_mode mode) static FILE *read_file; static int looped; int prompt; - + if (!read_file && !info_script_option) /* FIXME: if fopen is used, it will never be closed. */ read_file = archive == STDIN_FILENO ? fopen (TTY_NAME, "r") : stdin; @@ -991,7 +1003,7 @@ new_volume (enum access_mode mode) looped = 1; } prompt = looped; - + tryagain: if (prompt) { @@ -1053,10 +1065,12 @@ new_volume (enum access_mode mode) } static bool -read_header0 () +read_header0 (struct tar_stat_info *info) { - enum read_header rc = read_header (false); + enum read_header rc; + tar_stat_init (info); + rc = read_header_primitive (false, info); if (rc == HEADER_SUCCESS) { set_next_block_after (current_header); @@ -1071,7 +1085,8 @@ try_new_volume () { size_t status; union block *header; - + struct tar_stat_info dummy; + switch (subcommand_option) { case APPEND_SUBCOMMAND: @@ -1097,14 +1112,13 @@ try_new_volume () header = find_next_block (); if (!header) return false; + switch (header->header.typeflag) { case XGLTYPE: { - struct tar_stat_info dummy; - if (!read_header0 ()) + if (!read_header0 (&dummy)) return false; - tar_stat_init (&dummy); xheader_decode (&dummy); /* decodes values from the global header */ tar_stat_destroy (&dummy); if (!real_s_name) @@ -1118,8 +1132,9 @@ try_new_volume () } case GNUTYPE_VOLHDR: - if (!read_header0 ()) + if (!read_header0 (&dummy)) return false; + tar_stat_destroy (&dummy); assign_string (&volume_label, current_header->header.name); set_next_block_after (header); header = find_next_block (); @@ -1128,8 +1143,9 @@ try_new_volume () /* FALL THROUGH */ case GNUTYPE_MULTIVOL: - if (!read_header0 ()) + if (!read_header0 (&dummy)) return false; + tar_stat_destroy (&dummy); assign_string (&continued_file_name, current_header->header.name); continued_file_size = UINTMAX_FROM_HEADER (current_header->header.size); @@ -1147,9 +1163,19 @@ try_new_volume () if (!continued_file_name || strcmp (continued_file_name, real_s_name)) { - WARN ((0, 0, _("%s is not continued on this volume"), - quote (real_s_name))); - return false; + if ((archive_format == GNU_FORMAT || archive_format == OLDGNU_FORMAT) + && strlen (real_s_name) >= NAME_FIELD_SIZE + && strncmp (continued_file_name, real_s_name, + NAME_FIELD_SIZE) == 0) + WARN ((0, 0, + _("%s is possibly continued on this volume: header contains truncated name"), + quote (real_s_name))); + else + { + WARN ((0, 0, _("%s is not continued on this volume"), + quote (real_s_name))); + return false; + } } s = continued_file_size + continued_file_offset;