From 9e69bea9f10d447d337c54d6f5378346f998434f Mon Sep 17 00:00:00 2001 From: rwatson Date: Sun, 15 Aug 2004 19:10:05 +0000 Subject: Add a "fillchar" command line argument to dd(1) that permits the user to specify an alternative padding character when using a conversion mode, or when using noerror with sync and an input error occurs. This facilities reading old and error-prone media by allowing the user to more effectively mark error blocks in the output stream. --- bin/dd/args.c | 12 ++++++++++++ bin/dd/dd.1 | 11 +++++++++++ bin/dd/dd.c | 9 +++++++-- bin/dd/dd.h | 1 + bin/dd/extern.h | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) (limited to 'bin/dd') diff --git a/bin/dd/args.c b/bin/dd/args.c index c4d418b..161fbfc 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -58,6 +58,7 @@ static void f_cbs(char *); static void f_conv(char *); static void f_count(char *); static void f_files(char *); +static void f_fillchar(char *); static void f_ibs(char *); static void f_if(char *); static void f_obs(char *); @@ -77,6 +78,7 @@ static const struct arg { { "conv", f_conv, 0, 0 }, { "count", f_count, C_COUNT, C_COUNT }, { "files", f_files, C_FILES, C_FILES }, + { "fillchar", f_fillchar, C_FILL, C_FILL }, { "ibs", f_ibs, C_IBS, C_BS|C_IBS }, { "if", f_if, C_IF, C_IF }, { "iseek", f_skip, C_SKIP, C_SKIP }, @@ -224,6 +226,16 @@ f_files(char *arg) } static void +f_fillchar(char *arg) +{ + + if (strlen(arg) != 1) + errx(1, "need exactly one fill char"); + + fill_char = arg[0]; +} + +static void f_ibs(char *arg) { uintmax_t res; diff --git a/bin/dd/dd.1 b/bin/dd/dd.1 index 1cbe499..6f3298e 100644 --- a/bin/dd/dd.1 +++ b/bin/dd/dd.1 @@ -84,6 +84,13 @@ Copy .Ar n input files before terminating. This operand is only applicable when the input device is a tape. +.It Cm fillchar Ns = Ns Ar c +When padding a block in conversion mode or due to use of +.Cm noerror +and +.Cm sync +modes, fill with the specified ASCII character, rather than using a space +or nul. .It Cm ibs Ns = Ns Ar n Set the input block size to .Ar n @@ -247,6 +254,10 @@ with bytes (or with spaces if a block oriented conversion value was specified) and processed as a normal input buffer. If the +.Cm fillchar +option is specified, the fill char provided on the command line will override +the automatic selection of fill character. +If the .Cm sync conversion is not specified, the input block is omitted from the output. On input files which are not tapes or pipes, the file offset diff --git a/bin/dd/dd.c b/bin/dd/dd.c index 678f138..0bb43f7 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -80,6 +80,7 @@ u_int ddflags = 0; /* conversion options */ size_t cbsz; /* conversion block size */ uintmax_t files_cnt = 1; /* # of files to copy */ const u_char *ctab; /* conversion table */ +char fill_char; /* Character to fill with if defined */ int main(int argc __unused, char *argv[]) @@ -287,7 +288,9 @@ dd_in(void) * use spaces. */ if (ddflags & C_SYNC) { - if (ddflags & (C_BLOCK | C_UNBLOCK)) + if (ddflags & C_FILL) + memset(in.dbp, fill_char, in.dbsz); + else if (ddflags & (C_BLOCK | C_UNBLOCK)) memset(in.dbp, ' ', in.dbsz); else memset(in.dbp, 0, in.dbsz); @@ -382,7 +385,9 @@ dd_close(void) else if (cfunc == unblock) unblock_close(); if (ddflags & C_OSYNC && out.dbcnt && out.dbcnt < out.dbsz) { - if (ddflags & (C_BLOCK | C_UNBLOCK)) + if (ddflags & C_FILL) + memset(out.dbp, fill_char, out.dbsz - out.dbcnt); + else if (ddflags & (C_BLOCK | C_UNBLOCK)) memset(out.dbp, ' ', out.dbsz - out.dbcnt); else memset(out.dbp, 0, out.dbsz - out.dbcnt); diff --git a/bin/dd/dd.h b/bin/dd/dd.h index b89335b..ad283fd 100644 --- a/bin/dd/dd.h +++ b/bin/dd/dd.h @@ -94,5 +94,6 @@ typedef struct { #define C_SYNC 0x8000000 #define C_UCASE 0x10000000 #define C_UNBLOCK 0x20000000 +#define C_FILL 0x40000000 #define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET) diff --git a/bin/dd/extern.h b/bin/dd/extern.h index 8b3ca09..9c540ad 100644 --- a/bin/dd/extern.h +++ b/bin/dd/extern.h @@ -60,3 +60,4 @@ extern const u_char a2e_32V[], a2e_POSIX[]; extern const u_char e2a_32V[], e2a_POSIX[]; extern const u_char a2ibm_32V[], a2ibm_POSIX[]; extern u_char casetab[]; +extern char fill_char; -- cgit v1.1