Blame src/internal/tpax_driver_impl.h

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