diff options
author | midipix <writeonce@midipix.org> | 2020-01-30 18:34:27 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2020-05-23 05:59:01 +0000 |
commit | 54c29f3214d9ad43bd0eeab1ff025af8bfbf1309 (patch) | |
tree | 9a1e737e852d24ef51d06e03b7899d4671e3e342 | |
parent | 8aa3fcd31f72b70bf2ad23bb285f9675e2f17bca (diff) | |
download | tpax-54c29f3214d9ad43bd0eeab1ff025af8bfbf1309.tar.bz2 tpax-54c29f3214d9ad43bd0eeab1ff025af8bfbf1309.tar.xz |
driver: implemented block-size logic.
-rw-r--r-- | include/tpax/tpax.h | 1 | ||||
-rw-r--r-- | src/driver/tpax_driver_ctx.c | 63 | ||||
-rw-r--r-- | src/internal/tpax_driver_impl.h | 1 | ||||
-rw-r--r-- | src/skin/tpax_skin_default.c | 8 |
4 files changed, 72 insertions, 1 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h index 7c8404b..0be10f9 100644 --- a/include/tpax/tpax.h +++ b/include/tpax/tpax.h @@ -101,6 +101,7 @@ struct tpax_common_ctx { uint64_t drvflags; uint64_t actflags; uint64_t fmtflags; + uint32_t blksize; }; struct tpax_driver_ctx { diff --git a/src/driver/tpax_driver_ctx.c b/src/driver/tpax_driver_ctx.c index 675d836..81c4e34 100644 --- a/src/driver/tpax_driver_ctx.c +++ b/src/driver/tpax_driver_ctx.c @@ -5,6 +5,7 @@ /******************************************************/ #include <stdint.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> @@ -84,7 +85,7 @@ static int tpax_driver_usage( "Synopsis:\n" " %s\n" " %s -r\n" - " %s -w [−x format]\n" + " %s -w [−x format] [-b blocksize]\n" " %s -r -w\n\n" "Options:\n", program,program,program,program,program); @@ -192,6 +193,44 @@ static int tpax_driver_usage_write_format( return TPAX_USAGE; } +static int tpax_driver_usage_block_size( + 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, + "`%s' is not a valid positive decimal integer.\n", + arg); + + return TPAX_USAGE; +} + +static int tpax_driver_usage_block_size_range( + 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, + "`%s' is outside the specified range of 512 to 32256.\n", + arg); + + return TPAX_USAGE; +} + static int tpax_driver_error_not_implemented( int fdout, const char * program, @@ -267,6 +306,7 @@ int tpax_get_driver_ctx( size_t nunits; const char * program; int fddst; + const char * ch; (void)envp; @@ -334,6 +374,27 @@ int tpax_get_driver_ctx( cctx.drvflags |= TPAX_DRIVER_WRITE_FORMAT_RUSTAR; break; + + case TAG_BLKSIZE: + ch = (entry->arg[0] == '+') + ? &entry->arg[1] + : entry->arg; + + for (; *ch; ch++) + if ((*ch < '0') || (*ch > '9')) + return tpax_driver_usage_block_size( + fdctx->fdout, + program,entry->arg, + optv,meta); + + cctx.blksize = atoi(entry->arg); + + if ((cctx.blksize < 512) || (cctx.blksize > 32256)) + return tpax_driver_usage_block_size_range( + fdctx->fdout, + program,entry->arg, + optv,meta); + break; } } else { operand = entry; diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h index d061474..0a5c583 100644 --- a/src/internal/tpax_driver_impl.h +++ b/src/internal/tpax_driver_impl.h @@ -27,6 +27,7 @@ enum app_tags { TAG_WRITE, TAG_COPY, TAG_FORMAT, + TAG_BLKSIZE, }; struct tpax_driver_ctx_impl { diff --git a/src/skin/tpax_skin_default.c b/src/skin/tpax_skin_default.c index 69179be..dacc9d8 100644 --- a/src/skin/tpax_skin_default.c +++ b/src/skin/tpax_skin_default.c @@ -26,5 +26,13 @@ const struct argv_option tpax_default_options[] = { "pax|cpio|ustar|rustar",0, "archive format [%s]"}, + {"blksize", 'b',TAG_BLKSIZE,ARGV_OPTARG_REQUIRED,0,0,0, + "(non-default) block-size; valid values are " + "in the range of 512 to 32256; keeping " + "the default format-specific block size " + "(5120 for the pax and cpio formats," + " 10240 for the ustar format) " + "is strongly recommended."}, + {0,0,0,0,0,0,0,0} }; |