summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/tpax_driver_ctx.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index aaaea59..4348ebc 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -34,6 +34,9 @@
| TPAX_DRIVER_WRITE_FORMAT_USTAR \
| TPAX_DRIVER_WRITE_FORMAT_RUSTAR)
+#define TPAX_CACHE_MIN (1 << 12)
+#define TPAX_CACHE_MAX (1 << 24)
+
/* package info */
static const struct tpax_source_version tpax_src_version = {
TPAX_TAG_VER_MAJOR,
@@ -608,6 +611,30 @@ static int tpax_driver_srcstat_error(
return TPAX_ERROR;
}
+static int tpax_driver_cache_error(
+ struct tpax_driver_ctx_impl * ctx,
+ const char * program)
+{
+ int lerrno;
+ const char * errstr;
+
+ lerrno = errno;
+ errno = 0;
+
+ errstr = strerror(lerrno);
+ errstr = errno ? tpax_null_errdesc : errstr;
+ errno = lerrno;
+
+ tpax_dprintf(
+ ctx->fdctx.fderr,
+ "%s: failed to allocate source data cache (%s).\n",
+ program,errstr);
+
+ tpax_lib_free_driver_ctx(&ctx->ctx);
+
+ return TPAX_ERROR;
+}
+
int tpax_lib_get_driver_ctx(
char ** argv,
char ** envp,
@@ -627,6 +654,7 @@ int tpax_lib_get_driver_ctx(
size_t nunits;
size_t nreplstr;
size_t sreplstr;
+ size_t cachesize;
const char * program;
int fddst;
const char * ch;
@@ -957,6 +985,21 @@ int tpax_lib_get_driver_ctx(
}
}
+ /* allocate source data cache as needed */
+ if (ctx->cctx.srcflags == TPAX_SOURCE_DATA_FILEIO) {
+ cachesize = TPAX_CACHE_MAX;
+
+ for (; !ctx->cacheaddr && (cachesize >= TPAX_CACHE_MIN); )
+ if (!(ctx->cacheaddr = calloc(cachesize,1)))
+ cachesize >>= 1;
+
+ if (!ctx->cacheaddr)
+ return tpax_driver_cache_error(ctx,program);
+
+ ctx->cachemark = ctx->cacheaddr;
+ ctx->cachecap = &ctx->cacheaddr[cachesize];
+ }
+
/* all done */
if (archive) {
ctx->file = archive->arg;
@@ -998,6 +1041,9 @@ static void tpax_free_driver_ctx_impl(struct tpax_driver_ctx_alloc * ictx)
if (ictx->ctx.keyvalv)
free(ictx->ctx.keyvalv);
+ if (ictx->ctx.cacheaddr)
+ free(ictx->ctx.cacheaddr);
+
if (ictx->ctx.mapaddr)
munmap(ictx->ctx.mapaddr,ictx->ctx.mapsize);