summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2020-01-31 19:42:07 -0500
committermidipix <writeonce@midipix.org>2020-05-23 05:59:02 +0000
commit239ac5c3f246a737d7b70817319a37d6cece8a69 (patch)
tree73f811b95a22759acee5c72127a66e36d5ce0a13 /src/driver
parent7a9a40611a0e20eb40b15aefdd3de2e12e9cc9de (diff)
downloadtpax-239ac5c3f246a737d7b70817319a37d6cece8a69.tar.bz2
tpax-239ac5c3f246a737d7b70817319a37d6cece8a69.tar.xz
driver: tpax_get_unit_ctx(): implemented the non-recursive bits.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/tpax_unit_ctx.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/driver/tpax_unit_ctx.c b/src/driver/tpax_unit_ctx.c
index a6a91b6..a94bf05 100644
--- a/src/driver/tpax_unit_ctx.c
+++ b/src/driver/tpax_unit_ctx.c
@@ -8,11 +8,13 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/mman.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#include <tpax/tpax.h>
#include "tpax_driver_impl.h"
#include "tpax_errinfo_impl.h"
+#include "tpax_readlink_impl.h"
static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret)
{
@@ -28,6 +30,7 @@ int tpax_get_unit_ctx(
const char * path,
struct tpax_unit_ctx ** pctx)
{
+ int ret;
struct tpax_unit_ctx_impl * ctx;
if (!dctx)
@@ -40,8 +43,32 @@ int tpax_get_unit_ctx(
tpax_driver_set_ectx(
dctx,0,path);
+ if (dctx->cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) {
+ ret = fstatat(
+ tpax_driver_fdcwd(dctx),path,
+ &ctx->st,AT_SYMLINK_NOFOLLOW);
+
+ if (ret < 0) {
+ free(ctx);
+ return TPAX_SYSTEM_ERROR(dctx);
+ }
+ }
+
+ if (S_ISLNK(ctx->st.st_mode)) {
+ if (tpax_readlink(
+ path,ctx->linkbuf,
+ sizeof(ctx->linkbuf)) < 0) {
+ free(ctx);
+ return TPAX_SYSTEM_ERROR(dctx);
+ }
+ }
+
ctx->path = path;
+ ctx->link = ctx->linkbuf;
+
ctx->uctx.path = &ctx->path;
+ ctx->uctx.link = &ctx->link;
+ ctx->uctx.st = &ctx->st;
*pctx = &ctx->uctx;