summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2020-02-25 22:49:56 -0500
committermidipix <writeonce@midipix.org>2020-05-23 05:59:02 +0000
commit76f8c51055cb1b69d087b113453764227160bc05 (patch)
tree8aa11368b3d06d53642a9ca9fc90fcef64f81d0a /src/driver
parent8fb8f962f58680a040390d42ab412e27f5e93a3d (diff)
downloadtpax-76f8c51055cb1b69d087b113453764227160bc05.tar.bz2
tpax-76f8c51055cb1b69d087b113453764227160bc05.tar.xz
driver: write & copy modes: pre-allocate a robust-file-copy memory region.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/tpax_driver_ctx.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index c27ce90..926eb07 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -4,12 +4,15 @@
/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
/******************************************************/
+#define _DEFAULT_SOURCE 1
+
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
+#include <sys/mman.h>
#define ARGV_DRIVER
@@ -279,6 +282,16 @@ static struct tpax_driver_ctx_impl * tpax_driver_ctx_alloc(
if (!entry->fopt)
*units++ = entry->arg;
+ if (cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) {
+ ictx->ctx.bufsize = 64 * 1024;
+ ictx->ctx.bufaddr = mmap(0,ictx->ctx.bufsize,PROT_READ|PROT_WRITE,MAP_ANONYMOUS,-1,0);
+ }
+
+ if (ictx->ctx.bufaddr == MAP_FAILED) {
+ ictx->ctx.bufaddr = 0;
+ ictx->ctx.bufsize = 0;
+ }
+
ictx->ctx.ctx.units = ictx->units;
ictx->ctx.ctx.errv = ictx->ctx.errinfp;
return &ictx->ctx;
@@ -539,6 +552,9 @@ int tpax_get_driver_ctx(
static void tpax_free_driver_ctx_impl(struct tpax_driver_ctx_alloc * ictx)
{
+ if (ictx->ctx.bufaddr)
+ munmap(ictx->ctx.bufaddr,ictx->ctx.bufsize);
+
argv_free(ictx->meta);
free(ictx);
}