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 /src/driver | |
parent | 8aa3fcd31f72b70bf2ad23bb285f9675e2f17bca (diff) | |
download | tpax-54c29f3214d9ad43bd0eeab1ff025af8bfbf1309.tar.bz2 tpax-54c29f3214d9ad43bd0eeab1ff025af8bfbf1309.tar.xz |
driver: implemented block-size logic.
Diffstat (limited to 'src/driver')
-rw-r--r-- | src/driver/tpax_driver_ctx.c | 63 |
1 files changed, 62 insertions, 1 deletions
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; |