summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-07-18 06:50:45 +0000
committermidipix <writeonce@midipix.org>2024-07-18 06:50:45 +0000
commit57abba86083cd65d73e0df3bc12bd9560c178f21 (patch)
tree6f3b8be7b71e80bcc355bddcf39f65a364a2cace /src
parent6a7e25a01553a02630daac61f06c4bdbbdc4180b (diff)
downloadtpax-57abba86083cd65d73e0df3bc12bd9560c178f21.tar.bz2
tpax-57abba86083cd65d73e0df3bc12bd9560c178f21.tar.xz
driver: allocate source data cache buffer as needed.
Diffstat (limited to 'src')
-rw-r--r--src/driver/tpax_driver_ctx.c46
-rw-r--r--src/internal/tpax_driver_impl.h3
2 files changed, 49 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);
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h
index bc3ffc2..02e0d84 100644
--- a/src/internal/tpax_driver_impl.h
+++ b/src/internal/tpax_driver_impl.h
@@ -120,6 +120,9 @@ struct tpax_driver_ctx_impl {
size_t bufsize;
void * mapaddr;
size_t mapsize;
+ char * cacheaddr;
+ char * cachemark;
+ char * cachecap;
size_t nqueued;
off_t cpos;
};