summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/tpax/tpax.h5
-rw-r--r--src/driver/tpax_driver_ctx.c70
-rw-r--r--src/internal/tpax_driver_impl.h1
-rw-r--r--src/skin/tpax_skin_default.c5
4 files changed, 80 insertions, 1 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h
index c649058..7c8404b 100644
--- a/include/tpax/tpax.h
+++ b/include/tpax/tpax.h
@@ -43,6 +43,11 @@ extern "C" {
#define TPAX_DRIVER_ANNOTATE_NEVER 0x2000
#define TPAX_DRIVER_ANNOTATE_FULL 0x4000
+#define TPAX_DRIVER_WRITE_FORMAT_PAX 0x10000
+#define TPAX_DRIVER_WRITE_FORMAT_CPIO 0x20000
+#define TPAX_DRIVER_WRITE_FORMAT_USTAR 0x40000
+#define TPAX_DRIVER_WRITE_FORMAT_RUSTAR 0x80000
+
/* error flags */
#define TPAX_ERROR_TOP_LEVEL 0x0001
#define TPAX_ERROR_NESTED 0x0002
diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c
index b43d129..675d836 100644
--- a/src/driver/tpax_driver_ctx.c
+++ b/src/driver/tpax_driver_ctx.c
@@ -23,6 +23,12 @@
| TPAX_DRIVER_EXEC_MODE_WRITE \
| TPAX_DRIVER_EXEC_MODE_COPY)
+#define TPAX_DRIVER_WRITE_FORMAT_MASK \
+ (TPAX_DRIVER_WRITE_FORMAT_PAX \
+ | TPAX_DRIVER_WRITE_FORMAT_CPIO \
+ | TPAX_DRIVER_WRITE_FORMAT_USTAR \
+ | TPAX_DRIVER_WRITE_FORMAT_RUSTAR)
+
/* package info */
static const struct tpax_source_version tpax_src_version = {
TPAX_TAG_VER_MAJOR,
@@ -78,7 +84,7 @@ static int tpax_driver_usage(
"Synopsis:\n"
" %s\n"
" %s -r\n"
- " %s -w\n"
+ " %s -w [−x format]\n"
" %s -r -w\n\n"
"Options:\n",
program,program,program,program,program);
@@ -167,6 +173,25 @@ static int tpax_driver_usage_copy_mode(
return TPAX_USAGE;
}
+static int tpax_driver_usage_write_format(
+ int fdout,
+ const char * program,
+ const char * arg,
+ const struct argv_option ** optv,
+ struct argv_meta * meta)
+{
+ tpax_driver_usage(
+ fdout,program,
+ arg,optv,meta);
+
+ tpax_dprintf(
+ fdout,
+ "\nArchive format may only be specified "
+ "in write mode.\n");
+
+ return TPAX_USAGE;
+}
+
static int tpax_driver_error_not_implemented(
int fdout,
const char * program,
@@ -295,6 +320,20 @@ int tpax_get_driver_ctx(
case TAG_COPY:
cctx.drvflags |= TPAX_DRIVER_EXEC_MODE_COPY;
break;
+
+ case TAG_FORMAT:
+ cctx.drvflags &= ~(uint64_t)(TPAX_DRIVER_WRITE_FORMAT_MASK);
+
+ if (!strcmp(entry->arg,"pax"))
+ cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_PAX;
+ else if (!strcmp(entry->arg,"cpio"))
+ cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_CPIO;
+ else if (!strcmp(entry->arg,"ustar"))
+ cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_USTAR;
+ else if (!strcmp(entry->arg,"rustar"))
+ cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_RUSTAR;
+
+ break;
}
} else {
operand = entry;
@@ -372,6 +411,35 @@ int tpax_get_driver_ctx(
break;
}
+ /* archive format vs. execution mode*/
+ switch (cctx.drvflags & TPAX_DRIVER_EXEC_MODE_MASK) {
+ case TPAX_DRIVER_EXEC_MODE_WRITE:
+ if (!(cctx.drvflags & TPAX_DRIVER_WRITE_FORMAT_MASK))
+ cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_USTAR;
+ break;
+
+ default:
+ if (cctx.drvflags & TPAX_DRIVER_WRITE_FORMAT_MASK)
+ return tpax_driver_usage_write_format(
+ fdctx->fderr,program,
+ entry->arg,optv,meta);
+ }
+
+ /* not implemented archive format(s) */
+ switch (cctx.drvflags & TPAX_DRIVER_WRITE_FORMAT_MASK) {
+ case TPAX_DRIVER_WRITE_FORMAT_PAX:
+ return tpax_driver_error_not_implemented(
+ fdctx->fderr,program,"the pax format",meta);
+
+ case TPAX_DRIVER_WRITE_FORMAT_CPIO:
+ return tpax_driver_error_not_implemented(
+ fdctx->fderr,program,"the cpio format",meta);
+
+ default:
+ break;
+ }
+
+ /* driver ctx */
if (!(ctx = tpax_driver_ctx_alloc(meta,fdctx,&cctx,nunits))) {
if (cctx.drvflags & TPAX_DRIVER_EXEC_MODE_COPY)
close(fddst);
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h
index 6d749b5..d061474 100644
--- a/src/internal/tpax_driver_impl.h
+++ b/src/internal/tpax_driver_impl.h
@@ -26,6 +26,7 @@ enum app_tags {
TAG_READ,
TAG_WRITE,
TAG_COPY,
+ TAG_FORMAT,
};
struct tpax_driver_ctx_impl {
diff --git a/src/skin/tpax_skin_default.c b/src/skin/tpax_skin_default.c
index eb7e363..69179be 100644
--- a/src/skin/tpax_skin_default.c
+++ b/src/skin/tpax_skin_default.c
@@ -21,5 +21,10 @@ const struct argv_option tpax_default_options[] = {
"copy mode (copy specified files "
"to a specified destination directory)"},
+
+ {"format", 'x',TAG_FORMAT,ARGV_OPTARG_REQUIRED,0,
+ "pax|cpio|ustar|rustar",0,
+ "archive format [%s]"},
+
{0,0,0,0,0,0,0,0}
};