From: Erik van der Kouwe Date: Wed, 27 Jan 2010 07:48:06 +0000 (+0000) Subject: Add notrunc conversion for dd tool X-Git-Tag: v3.1.6~23 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=d8b8e10ba48a4fc30db487ec05fb75efb79782bf;p=minix.git Add notrunc conversion for dd tool --- diff --git a/commands/simple/dd.c b/commands/simple/dd.c index 0f7874b86..dc6a9eca1 100644 --- a/commands/simple/dd.c +++ b/commands/simple/dd.c @@ -82,6 +82,7 @@ int num() #define NOERROR 0x0008 #define SYNC 0x0010 #define SILENT 0x0020 +#define NOTRUNC 0x0040 #define BLANK ' ' #define DEFAULT 512 @@ -142,7 +143,7 @@ char *argv[]; void (*convert) (); #endif char *iptr; - int i, j; + int i, j, oflags; convert = null; argc--; @@ -213,6 +214,10 @@ char *argv[]; convflag |= NOERROR; continue; } + if (is("notrunc")) { + convflag |= NOTRUNC; + continue; + } if (is("sync")) { convflag |= SYNC; continue; @@ -241,8 +246,10 @@ char *argv[]; (ifilename) ? ifilename : "stdin", strerror(errno)); exit(1); } - if ((ofd = ((ofilename) ? open(ofilename, seekseen ? O_WRONLY | O_CREAT - : O_WRONLY | O_CREAT | O_TRUNC, 0666) + oflags = O_WRONLY | O_CREAT; + if (!seekseen && (convflag & NOTRUNC) != NOTRUNC) + oflags |= O_TRUNC; + if ((ofd = ((ofilename) ? open(ofilename, oflags, 0666) : dup(1))) < 0) { fprintf(stderr, "dd: Can't open %s: %s\n", (ofilename) ? ofilename : "stdout", strerror(errno)); diff --git a/man/man1/dd.1 b/man/man1/dd.1 index 756ab0eb2..afdad2b8f 100644 --- a/man/man1/dd.1 +++ b/man/man1/dd.1 @@ -48,6 +48,8 @@ The options are: \fBconv = swab\fR \- Swap every pair of bytes .br \fBconv = noerror\fR \- Ignore errors and just keep going +.br + \fBconv = notrunc\fR \- Do not truncate unmodified blocks .br \fBconv = silent\fR \- Suppress statistics (MINIX 3 specific flag) .PP