|
|
5874a9 |
/**************************************************************/
|
|
|
5874a9 |
/* tpax: a topological pax implementation */
|
|
|
bef28d |
/* Copyright (C) 2020--2024 SysDeer Technologies, LLC */
|
|
|
5874a9 |
/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
|
|
|
5874a9 |
/**************************************************************/
|
|
|
88751e |
|
|
|
88751e |
#include <stdint.h>
|
|
|
88751e |
#include <stddef.h>
|
|
|
88751e |
#include <stdlib.h>
|
|
|
88751e |
#include <string.h>
|
|
|
239ac5 |
#include <fcntl.h>
|
|
|
239ac5 |
#include <sys/stat.h>
|
|
|
88751e |
|
|
|
88751e |
#include <tpax/tpax.h>
|
|
|
88751e |
#include "tpax_driver_impl.h"
|
|
|
88751e |
#include "tpax_errinfo_impl.h"
|
|
|
239ac5 |
#include "tpax_readlink_impl.h"
|
|
|
88751e |
|
|
|
88751e |
static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret)
|
|
|
88751e |
{
|
|
|
88751e |
if (ctx) {
|
|
|
88751e |
free(ctx);
|
|
|
88751e |
}
|
|
|
88751e |
|
|
|
88751e |
return ret;
|
|
|
88751e |
}
|
|
|
88751e |
|
|
|
c9eeca |
int tpax_lib_get_unit_ctx(
|
|
|
88751e |
const struct tpax_driver_ctx * dctx,
|
|
|
00bc9c |
int fdat,
|
|
|
88751e |
const char * path,
|
|
|
88751e |
struct tpax_unit_ctx ** pctx)
|
|
|
88751e |
{
|
|
|
239ac5 |
int ret;
|
|
|
88751e |
struct tpax_unit_ctx_impl * ctx;
|
|
|
88751e |
|
|
|
88751e |
if (!dctx)
|
|
|
88751e |
return TPAX_CUSTOM_ERROR(
|
|
|
88751e |
dctx,TPAX_ERR_NULL_CONTEXT);
|
|
|
88751e |
|
|
|
88751e |
else if (!(ctx = calloc(1,sizeof(*ctx))))
|
|
|
88751e |
return TPAX_BUFFER_ERROR(dctx);
|
|
|
88751e |
|
|
|
88751e |
tpax_driver_set_ectx(
|
|
|
88751e |
dctx,0,path);
|
|
|
88751e |
|
|
|
239ac5 |
if (dctx->cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) {
|
|
|
239ac5 |
ret = fstatat(
|
|
|
00bc9c |
fdat,path,&ctx->st,
|
|
|
00bc9c |
AT_SYMLINK_NOFOLLOW);
|
|
|
239ac5 |
|
|
|
239ac5 |
if (ret < 0) {
|
|
|
239ac5 |
free(ctx);
|
|
|
239ac5 |
return TPAX_SYSTEM_ERROR(dctx);
|
|
|
239ac5 |
}
|
|
|
239ac5 |
}
|
|
|
239ac5 |
|
|
|
239ac5 |
if (S_ISLNK(ctx->st.st_mode)) {
|
|
|
25a377 |
if (tpax_readlinkat(
|
|
|
00bc9c |
fdat,path,ctx->linkbuf,
|
|
|
239ac5 |
sizeof(ctx->linkbuf)) < 0) {
|
|
|
239ac5 |
free(ctx);
|
|
|
239ac5 |
return TPAX_SYSTEM_ERROR(dctx);
|
|
|
239ac5 |
}
|
|
|
239ac5 |
}
|
|
|
239ac5 |
|
|
|
88751e |
ctx->path = path;
|
|
|
594da7 |
ctx->link = ctx->linkbuf[0] ? ctx->linkbuf : 0;
|
|
|
239ac5 |
|
|
|
88751e |
ctx->uctx.path = &ctx->path;
|
|
|
239ac5 |
ctx->uctx.link = &ctx->link;
|
|
|
239ac5 |
ctx->uctx.st = &ctx->st;
|
|
|
88751e |
|
|
|
88751e |
*pctx = &ctx->uctx;
|
|
|
88751e |
|
|
|
88751e |
return 0;
|
|
|
88751e |
}
|
|
|
88751e |
|
|
|
c9eeca |
void tpax_lib_free_unit_ctx(struct tpax_unit_ctx * ctx)
|
|
|
88751e |
{
|
|
|
88751e |
struct tpax_unit_ctx_impl * ictx;
|
|
|
88751e |
uintptr_t addr;
|
|
|
88751e |
|
|
|
88751e |
if (ctx) {
|
|
|
88751e |
addr = (uintptr_t)ctx - offsetof(struct tpax_unit_ctx_impl,uctx);
|
|
|
88751e |
ictx = (struct tpax_unit_ctx_impl *)addr;
|
|
|
88751e |
tpax_free_unit_ctx_impl(ictx,0);
|
|
|
88751e |
}
|
|
|
88751e |
}
|