summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-07-18 05:13:52 +0000
committermidipix <writeonce@midipix.org>2024-07-18 05:45:24 +0000
commit6a7e25a01553a02630daac61f06c4bdbbdc4180b (patch)
tree8a1029209bfc6f192a1807404187cece59d5198a /src
parent88391942aae898d9d7b58bb130dccef44d57634c (diff)
downloadtpax-6a7e25a01553a02630daac61f06c4bdbbdc4180b.tar.bz2
tpax-6a7e25a01553a02630daac61f06c4bdbbdc4180b.tar.xz
driver: list, read, and copy modes: attempt mapping the source archive.
Diffstat (limited to 'src')
-rw-r--r--src/driver/tpax_driver_ctx.c56
-rw-r--r--src/internal/tpax_driver_impl.h3
2 files changed, 59 insertions, 0 deletions
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index d926631..aaaea59 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -576,6 +576,38 @@ static int tpax_driver_keyval_error(
return TPAX_ERROR;
}
+static int tpax_driver_srcstat_error(
+ struct tpax_driver_ctx_impl * ctx,
+ const struct argv_entry * archive,
+ const char * program)
+{
+ int lerrno;
+ const char * errstr;
+
+ lerrno = errno;
+ errno = 0;
+
+ errstr = strerror(lerrno);
+ errstr = errno ? "" : errstr;
+ errno = lerrno;
+
+ if (archive) {
+ tpax_dprintf(
+ ctx->fdctx.fderr,
+ "%s: could not stat archive file '%s' (%s).\n",
+ program,archive->arg,errstr);
+ } else {
+ tpax_dprintf(
+ ctx->fdctx.fderr,
+ "%s: could not stat input source file <fd=%d> (%s).\n",
+ program,ctx->fdctx.fdin,errstr);
+ }
+
+ tpax_lib_free_driver_ctx(&ctx->ctx);
+
+ return TPAX_ERROR;
+}
+
int tpax_lib_get_driver_ctx(
char ** argv,
char ** envp,
@@ -905,6 +937,27 @@ int tpax_lib_get_driver_ctx(
if (!tpax_driver_is_valid_keyval(*pkeyval))
return tpax_driver_keyval_error(ctx,*pkeyval,program);
+ /* source data mapping (non-critical) */
+ if (cctx.srcflags) {
+ if (fstat(fdctx->fdin,&ctx->srcstat) < 0)
+ return tpax_driver_srcstat_error(ctx,archive,program);
+
+ ctx->mapsize = ctx->srcstat.st_size;
+ ctx->mapaddr = mmap(
+ 0,ctx->mapsize,
+ PROT_READ,MAP_PRIVATE,
+ fdctx->fdin,0);
+
+ if (ctx->mapaddr == MAP_FAILED) {
+ ctx->cctx.srcflags = TPAX_SOURCE_DATA_FILEIO;
+ ctx->mapaddr = 0;
+ ctx->mapsize = 0;
+ } else {
+ ctx->cctx.srcflags = TPAX_SOURCE_DATA_MAPPED;
+ }
+ }
+
+ /* all done */
if (archive) {
ctx->file = archive->arg;
ctx->ctx.file = &ctx->file;
@@ -945,6 +998,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.mapaddr)
+ munmap(ictx->ctx.mapaddr,ictx->ctx.mapsize);
+
if (ictx->ctx.bufaddr)
munmap(ictx->ctx.bufaddr,ictx->ctx.bufsize);
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h
index a7350d7..bc3ffc2 100644
--- a/src/internal/tpax_driver_impl.h
+++ b/src/internal/tpax_driver_impl.h
@@ -99,6 +99,7 @@ struct tpax_driver_ctx_impl {
struct tpax_fd_ctx fdctx;
const struct tpax_unit_ctx * euctx;
const char * eunit;
+ struct stat srcstat;
struct argv_keyval ** keyvalv;
struct tpax_replstr * replstrv;
char * replstrs;
@@ -117,6 +118,8 @@ struct tpax_driver_ctx_impl {
void * dirbuff;
void * bufaddr;
size_t bufsize;
+ void * mapaddr;
+ size_t mapsize;
size_t nqueued;
off_t cpos;
};