summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2021-04-20 22:15:00 +0000
committermidipix <writeonce@midipix.org>2021-04-20 19:27:27 +0000
commitd7918a23986d28fe85d4ecb6021b40969036557c (patch)
tree7752d7b43cf40137aea6f7085031b90f197ad97b /src
parent7cf11212eec657dde9d67cdc7665da0a76786a85 (diff)
downloadtpax-d7918a23986d28fe85d4ecb6021b40969036557c.tar.bz2
tpax-d7918a23986d28fe85d4ecb6021b40969036557c.tar.xz
driver: support directory recursion (in write and copy mode).
Diffstat (limited to 'src')
-rw-r--r--src/driver/tpax_driver_ctx.c35
-rw-r--r--src/internal/tpax_driver_impl.h34
2 files changed, 65 insertions, 4 deletions
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index 7557ace..fa3a930 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -289,11 +289,24 @@ static struct tpax_driver_ctx_impl * tpax_driver_ctx_alloc(
PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS,
-1,0);
- }
- if (ictx->ctx.bufaddr == MAP_FAILED) {
- ictx->ctx.bufaddr = 0;
- ictx->ctx.bufsize = 0;
+ if (ictx->ctx.bufaddr == MAP_FAILED) {
+ free(ictx);
+ return 0;
+ }
+
+ if (cctx->drvflags & TPAX_DRIVER_DIR_MEMBER_RECURSE)
+ ictx->ctx.dirbuff = mmap(
+ 0,TPAX_DIRENT_BUFLEN,
+ PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS,
+ -1,0);
+
+ if (ictx->ctx.dirbuff == MAP_FAILED) {
+ munmap(ictx->ctx.bufaddr,ictx->ctx.bufsize);
+ free(ictx);
+ return 0;
+ }
}
ictx->ctx.ctx.units = ictx->units;
@@ -552,9 +565,23 @@ int tpax_get_driver_ctx(
static void tpax_free_driver_ctx_impl(struct tpax_driver_ctx_alloc * ictx)
{
+ void * next;
+ size_t size;
+
+ for (; ictx->ctx.dirents; ) {
+ next = ictx->ctx.dirents->next;
+ size = ictx->ctx.dirents->size;
+
+ munmap(ictx->ctx.dirents,size);
+ ictx->ctx.dirents = (struct tpax_dirent_buffer *)next;
+ }
+
if (ictx->ctx.bufaddr)
munmap(ictx->ctx.bufaddr,ictx->ctx.bufsize);
+ if (ictx->ctx.dirbuff)
+ munmap(ictx->ctx.dirbuff,TPAX_DIRENT_BUFLEN);
+
argv_free(ictx->meta);
free(ictx);
}
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h
index 4003305..47d8fd5 100644
--- a/src/internal/tpax_driver_impl.h
+++ b/src/internal/tpax_driver_impl.h
@@ -8,6 +8,7 @@
#define TPAX_DRIVER_IMPL_H
#include <stdint.h>
+#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -18,6 +19,7 @@
#include "argv/argv.h"
#define TPAX_OPTV_ELEMENTS 64
+#define TPAX_DIRENT_BUFLEN 65536
#define TPAX_DRIVER_EXEC_MODE_WRITE_COPY \
(TPAX_DRIVER_EXEC_MODE_WRITE | \
@@ -40,6 +42,22 @@ enum app_tags {
TAG_PURE_PATH,
};
+struct tpax_dirent {
+ int fdat;
+ int depth;
+ size_t nsize;
+ const struct tpax_dirent * parent;
+ struct dirent dirent;
+};
+
+struct tpax_dirent_buffer {
+ struct tpax_dirent_buffer * next;
+ size_t size;
+ size_t nfree;
+ struct tpax_dirent * cdent;
+ struct tpax_dirent dbuf[];
+};
+
struct tpax_driver_ctx_impl {
struct tpax_common_ctx cctx;
struct tpax_driver_ctx ctx;
@@ -50,6 +68,8 @@ struct tpax_driver_ctx_impl {
struct tpax_error_info ** erricap;
struct tpax_error_info * erriptr[64];
struct tpax_error_info erribuf[64];
+ struct tpax_dirent_buffer * dirents;
+ void * dirbuff;
void * bufaddr;
size_t bufsize;
off_t cpos;
@@ -103,6 +123,13 @@ static inline void * tpax_get_driver_anon_map_addr(
return ictx->bufaddr;
}
+static inline void * tpax_get_driver_getdents_buffer(
+ const struct tpax_driver_ctx * dctx)
+{
+ struct tpax_driver_ctx_impl * ictx = tpax_get_driver_ictx(dctx);
+ return ictx->dirbuff;
+}
+
static inline void tpax_driver_set_ectx(
const struct tpax_driver_ctx * dctx,
const struct tpax_unit_ctx * uctx,
@@ -171,6 +198,13 @@ static inline void tpax_set_driver_cpos(const struct tpax_driver_ctx * dctx, off
ictx->cpos = cpos;
}
+static inline struct tpax_dirent_buffer * tpax_get_driver_dirents(const struct tpax_driver_ctx * dctx)
+{
+ struct tpax_driver_ctx_impl * ictx;
+ ictx = tpax_get_driver_ictx(dctx);
+ return ictx->dirents;
+}
+
static inline off_t tpax_get_unit_hpos(const struct tpax_unit_ctx * uctx)
{
struct tpax_unit_ctx_impl * ictx;