/******************************************************/
/* tpax: a topological pax implementation */
/* Copyright (C) 2020 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
/******************************************************/
#ifndef TPAX_DRIVER_IMPL_H
#define TPAX_DRIVER_IMPL_H
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <tpax/tpax.h>
#include "tpax_dprintf_impl.h"
#include "argv/argv.h"
#define TPAX_OPTV_ELEMENTS 64
extern const struct argv_option tpax_default_options[];
enum app_tags {
TAG_HELP,
TAG_VERSION,
TAG_LIST,
TAG_READ,
TAG_WRITE,
TAG_COPY,
TAG_FORMAT,
TAG_BLKSIZE,
TAG_RECURSE,
TAG_NORECURSE,
};
struct tpax_driver_ctx_impl {
struct tpax_common_ctx cctx;
struct tpax_driver_ctx ctx;
struct tpax_fd_ctx fdctx;
const struct tpax_unit_ctx * euctx;
const char * eunit;
struct tpax_error_info ** errinfp;
struct tpax_error_info ** erricap;
struct tpax_error_info * erriptr[64];
struct tpax_error_info erribuf[64];
};
struct tpax_unit_ctx_impl {
const char * path;
struct tpax_unit_ctx uctx;
};
static inline struct tpax_driver_ctx_impl * tpax_get_driver_ictx(
const struct tpax_driver_ctx * dctx)
{
uintptr_t addr;
if (dctx) {
addr = (uintptr_t)dctx - offsetof(struct tpax_driver_ctx_impl,ctx);
return (struct tpax_driver_ctx_impl *)addr;
}
return 0;
}
static inline void tpax_driver_set_ectx(
const struct tpax_driver_ctx * dctx,
const struct tpax_unit_ctx * uctx,
const char * unit)
{
struct tpax_driver_ctx_impl * ictx;
ictx = tpax_get_driver_ictx(dctx);
ictx->euctx = uctx;
ictx->eunit = unit;
}
static inline int tpax_driver_fdin(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fdin;
}
static inline int tpax_driver_fdout(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fdout;
}
static inline int tpax_driver_fderr(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fderr;
}
static inline int tpax_driver_fdlog(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fdlog;
}
static inline int tpax_driver_fdcwd(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fdcwd;
}
static inline int tpax_driver_fddst(const struct tpax_driver_ctx * dctx)
{
struct tpax_fd_ctx fdctx;
tpax_get_driver_fdctx(dctx,&fdctx);
return fdctx.fddst;
}
#endif