mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
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.
This commit is contained in:
parent
70a310e2dd
commit
e3edab4a91
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=133762
@ -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 },
|
||||
@ -223,6 +225,16 @@ f_files(char *arg)
|
||||
errx(1, "files must be between 1 and %jd", (uintmax_t)-1);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
11
bin/dd/dd.1
11
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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user