X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbuffer.c;h=c1a88a3ee325245047c7dd62fce9c7adb19c4826;hb=320298c663ac4849226a2db820bee1bdb75d21ef;hp=f3cebc0aed908a5450a26404c927fd817164f2ae;hpb=2bda83b48d8a6807632312403561b11b79048443;p=chaz%2Ftar diff --git a/src/buffer.c b/src/buffer.c index f3cebc0..c1a88a3 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -40,6 +40,7 @@ static tarlong prev_written; /* bytes written on previous volumes */ static tarlong bytes_written; /* bytes written on this volume */ +static void *record_buffer; /* allocated memory */ /* FIXME: The following variables should ideally be static to this module. However, this cannot be done yet. The cleanup continues! */ @@ -270,17 +271,12 @@ open_archive (enum access_mode wanted_access) save_name = 0; real_s_name = 0; + record_start = + page_aligned_alloc (&record_buffer, + (record_size + + (multi_volume_option ? 2 * BLOCKSIZE : 0))); if (multi_volume_option) - { - record_start = valloc (record_size + (2 * BLOCKSIZE)); - if (record_start) - record_start += 2; - } - else - record_start = valloc (record_size); - if (!record_start) - FATAL_ERROR ((0, 0, _("Cannot allocate memory for blocking factor %d"), - blocking_factor)); + record_start += 2; current_block = record_start; record_end = record_start + blocking_factor; @@ -293,7 +289,6 @@ open_archive (enum access_mode wanted_access) { case ACCESS_READ: child_pid = sys_child_open_for_uncompress (); - read_full_records_option = false; break; case ACCESS_WRITE: @@ -889,6 +884,42 @@ backspace_output (void) } } +off_t +seek_archive (off_t size) +{ + off_t start = current_block_ordinal (); + off_t offset; + off_t nrec, nblk; + off_t skipped = (blocking_factor - (current_block - record_start)); + + size -= skipped * BLOCKSIZE; + + if (size < record_size) + return 0; + /* FIXME: flush? */ + + /* Compute number of records to skip */ + nrec = size / record_size; + offset = rmtlseek (archive, nrec * record_size, SEEK_CUR); + if (offset < 0) + return offset; + + if (offset % record_size) + FATAL_ERROR ((0, 0, _("rmtlseek not stopped at a record boundary"))); + + /* Convert to number of records */ + offset /= BLOCKSIZE; + /* Compute number of skipped blocks */ + nblk = offset - start; + + /* Update buffering info */ + records_read += nblk / blocking_factor; + record_start_block = offset - blocking_factor; + current_block = record_end; + + return nblk; +} + /* Close the archive file. */ void close_archive (void) @@ -911,7 +942,7 @@ close_archive (void) free (save_name); if (real_s_name) free (real_s_name); - free (multi_volume_option ? record_start - 2 : record_start); + free (record_buffer); } /* Called to initialize the global volume number. */