diff options
Diffstat (limited to 'src/driver/tpax_unit_ctx.c')
-rw-r--r-- | src/driver/tpax_unit_ctx.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/driver/tpax_unit_ctx.c b/src/driver/tpax_unit_ctx.c new file mode 100644 index 0000000..a6a91b6 --- /dev/null +++ b/src/driver/tpax_unit_ctx.c @@ -0,0 +1,61 @@ +/******************************************************/ +/* tpax: a topological pax implementation */ +/* Copyright (C) 2020 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ +/******************************************************/ + +#include <stdint.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> + +#include <tpax/tpax.h> +#include "tpax_driver_impl.h" +#include "tpax_errinfo_impl.h" + +static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret) +{ + if (ctx) { + free(ctx); + } + + return ret; +} + +int tpax_get_unit_ctx( + const struct tpax_driver_ctx * dctx, + const char * path, + struct tpax_unit_ctx ** pctx) +{ + struct tpax_unit_ctx_impl * ctx; + + if (!dctx) + return TPAX_CUSTOM_ERROR( + dctx,TPAX_ERR_NULL_CONTEXT); + + else if (!(ctx = calloc(1,sizeof(*ctx)))) + return TPAX_BUFFER_ERROR(dctx); + + tpax_driver_set_ectx( + dctx,0,path); + + ctx->path = path; + ctx->uctx.path = &ctx->path; + + *pctx = &ctx->uctx; + + return 0; +} + +void tpax_free_unit_ctx(struct tpax_unit_ctx * ctx) +{ + struct tpax_unit_ctx_impl * ictx; + uintptr_t addr; + + if (ctx) { + addr = (uintptr_t)ctx - offsetof(struct tpax_unit_ctx_impl,uctx); + ictx = (struct tpax_unit_ctx_impl *)addr; + tpax_free_unit_ctx_impl(ictx,0); + } +} |