|
|
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>
|
|
|
239ac5 |
#include <sys/stat.h>
|
|
|
88751e |
#include <sys/types.h>
|
|
|
88751e |
|
|
|
88751e |
#include <tpax/tpax.h>
|
|
|
239ac5 |
#include <tpax/tpax_specs.h>
|
|
|
88751e |
#include "tpax_dprintf_impl.h"
|
|
|
88751e |
#include "argv/argv.h"
|
|
|
88751e |
|
|
|
88751e |
#define TPAX_OPTV_ELEMENTS 64
|
|
|
88751e |
|
|
|
239ac5 |
#define TPAX_DRIVER_EXEC_MODE_WRITE_COPY \
|
|
|
239ac5 |
(TPAX_DRIVER_EXEC_MODE_WRITE | \
|
|
|
239ac5 |
TPAX_DRIVER_EXEC_MODE_COPY)
|
|
|
239ac5 |
|
|
|
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,
|
|
|
efbaf8 |
TAG_STRICT_PATH,
|
|
|
efbaf8 |
TAG_PURE_PATH,
|
|
|
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];
|
|
|
76f8c5 |
void * bufaddr;
|
|
|
76f8c5 |
size_t bufsize;
|
|
|
409008 |
off_t cpos;
|
|
|
88751e |
};
|
|
|
88751e |
|
|
|
88751e |
struct tpax_unit_ctx_impl {
|
|
|
88751e |
const char * path;
|
|
|
88751e |
struct tpax_unit_ctx uctx;
|
|
|
239ac5 |
struct stat st;
|
|
|
409008 |
off_t hpos;
|
|
|
409008 |
off_t dpos;
|
|
|
239ac5 |
const char * link;
|
|
|
239ac5 |
char linkbuf[1024];
|
|
|
239ac5 |
union {
|
|
|
239ac5 |
struct tpax_ustar_header uhdr;
|
|
|
239ac5 |
struct tpax_cpio_header chdr;
|
|
|
239ac5 |
} hdrbufs;
|
|
|
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 |
|
|
|
409008 |
static inline struct tpax_unit_ctx_impl * tpax_get_unit_ictx(
|
|
|
409008 |
const struct tpax_unit_ctx * uctx)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_unit_ctx_impl * ictx;
|
|
|
409008 |
uintptr_t addr;
|
|
|
409008 |
|
|
|
409008 |
addr = (uintptr_t)uctx - offsetof(struct tpax_unit_ctx_impl,uctx);
|
|
|
409008 |
ictx = (struct tpax_unit_ctx_impl *)addr;
|
|
|
409008 |
return ictx;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
e407b8 |
static inline void * tpax_get_driver_anon_map_addr(
|
|
|
e407b8 |
const struct tpax_driver_ctx * dctx,
|
|
|
e407b8 |
size_t * size)
|
|
|
e407b8 |
{
|
|
|
e407b8 |
struct tpax_driver_ctx_impl * ictx = tpax_get_driver_ictx(dctx);
|
|
|
e407b8 |
*size = ictx->bufsize;
|
|
|
e407b8 |
return ictx->bufaddr;
|
|
|
e407b8 |
}
|
|
|
e407b8 |
|
|
|
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 |
|
|
|
409008 |
static inline off_t tpax_get_driver_cpos(const struct tpax_driver_ctx * dctx)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_driver_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_driver_ictx(dctx);
|
|
|
409008 |
return ictx->cpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline void tpax_set_driver_cpos(const struct tpax_driver_ctx * dctx, off_t cpos)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_driver_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_driver_ictx(dctx);
|
|
|
409008 |
ictx->cpos = cpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline off_t tpax_get_unit_hpos(const struct tpax_unit_ctx * uctx)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_unit_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_unit_ictx(uctx);
|
|
|
409008 |
return ictx->hpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline void tpax_set_unit_hpos(const struct tpax_unit_ctx * uctx, off_t hpos)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_unit_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_unit_ictx(uctx);
|
|
|
409008 |
ictx->hpos = hpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline off_t tpax_get_unit_dpos(const struct tpax_unit_ctx * uctx)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_unit_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_unit_ictx(uctx);
|
|
|
409008 |
return ictx->dpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline void tpax_set_unit_dpos(const struct tpax_unit_ctx * uctx, off_t dpos)
|
|
|
409008 |
{
|
|
|
409008 |
struct tpax_unit_ctx_impl * ictx;
|
|
|
409008 |
ictx = tpax_get_unit_ictx(uctx);
|
|
|
409008 |
ictx->dpos = dpos;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
409008 |
static inline ssize_t tpax_get_archive_block_size(const struct tpax_driver_ctx * dctx)
|
|
|
409008 |
{
|
|
|
409008 |
if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_PAX)
|
|
|
409008 |
return TPAX_PAX_BLOCK_SIZE;
|
|
|
409008 |
|
|
|
409008 |
else if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_CPIO)
|
|
|
409008 |
return TPAX_CPIO_BLOCK_SIZE;
|
|
|
409008 |
|
|
|
409008 |
else if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_USTAR)
|
|
|
409008 |
return TPAX_USTAR_BLOCK_SIZE;
|
|
|
409008 |
|
|
|
409008 |
else if (dctx->cctx->drvflags & TPAX_DRIVER_WRITE_FORMAT_RUSTAR)
|
|
|
409008 |
return TPAX_USTAR_BLOCK_SIZE;
|
|
|
409008 |
|
|
|
409008 |
else
|
|
|
409008 |
return 0;
|
|
|
409008 |
}
|
|
|
409008 |
|
|
|
88751e |
#endif
|