summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-05-27 01:19:40 +0000
committermidipix <writeonce@midipix.org>2024-05-27 01:30:14 +0000
commitcf351e2ca821a190e2dbe25875fea29168b92f72 (patch)
tree72d768dc5510a851b72c1b6571f43e974bed31cc
parent86604c6822f05f62aaf2cd4d9275f53e6ac9a70c (diff)
downloadtpax-cf351e2ca821a190e2dbe25875fea29168b92f72.tar.bz2
tpax-cf351e2ca821a190e2dbe25875fea29168b92f72.tar.xz
core api: implemented tpax_archive_reset().
-rw-r--r--include/tpax/tpax.h2
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/tpax_archive_reset.c59
3 files changed, 62 insertions, 0 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h
index 6a43415..8822ee1 100644
--- a/include/tpax/tpax.h
+++ b/include/tpax/tpax.h
@@ -155,6 +155,8 @@ tpax_api int tpax_archive_append (const struct tpax_driver_ctx *, con
tpax_api int tpax_archive_write (const struct tpax_driver_ctx *);
+tpax_api int tpax_archive_reset (const struct tpax_driver_ctx *);
+
tpax_api int tpax_archive_seal (const struct tpax_driver_ctx *);
/* utility helper interfaces */
diff --git a/project/common.mk b/project/common.mk
index a23c2ef..5ae4ea2 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -5,6 +5,7 @@ API_SRCS = \
src/io/tpax_create_memory_snapshot.c \
src/io/tpax_create_tmpfs_snapshot.c \
src/logic/tpax_archive_append.c \
+ src/logic/tpax_archive_reset.c \
src/logic/tpax_archive_write.c \
src/logic/tpax_queue_vector.c \
src/meta/tpax_init_ustar_header.c \
diff --git a/src/logic/tpax_archive_reset.c b/src/logic/tpax_archive_reset.c
new file mode 100644
index 0000000..52a9008
--- /dev/null
+++ b/src/logic/tpax_archive_reset.c
@@ -0,0 +1,59 @@
+/**************************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020--2024 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/**************************************************************/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+
+#include <tpax/tpax.h>
+#include "tpax_driver_impl.h"
+
+/**********************************************/
+/* release and reset the following objects: */
+/* */
+/* - item queue */
+/* - queue vector */
+/* - cached prefixes */
+/* - prefix vector */
+/* */
+/**********************************************/
+
+int tpax_archive_reset(const struct tpax_driver_ctx * dctx)
+{
+ struct tpax_driver_ctx_impl * ictx;
+ void * next;
+ size_t size;
+ char ** ppref;
+
+ ictx = tpax_get_driver_ictx(dctx);
+
+ for (; ictx->dirents; ) {
+ next = ictx->dirents->next;
+ size = ictx->dirents->size;
+
+ munmap(ictx->dirents,size);
+ ictx->dirents = (struct tpax_dirent_buffer *)next;
+ }
+
+ for (ppref=ictx->prefixv; *ppref; ppref++)
+ free(*ppref);
+
+ for (ppref=ictx->prefptr; ppref<ictx->prefcap; ppref++)
+ *ppref = 0;
+
+ if (ictx->prefixv != ictx->prefptr)
+ free(ictx->prefixv);
+
+ if (ictx->direntv)
+ free(ictx->direntv);
+
+ ictx->nqueued = 0;
+ ictx->dirents = 0;
+ ictx->direntv = 0;
+ ictx->prefixv = ictx->prefptr;
+
+ return 0;
+}