Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Apr 1999 12:07:09 -0400 (EDT)
From:      Brian Feldman <green@unixhelp.org>
To:        hackers@freebsd.org
Subject:   more dd(1) weirdness
Message-ID:  <Pine.BSF.4.05.9904051204510.36419-100000@janus.syracuse.net>

next in thread | raw e-mail | index | archive | help
  I think I've fixed all of the dd(1) weirdness, and these patches should be
committed (except for the part about block device lseeking, that should be
better thought out now).

 Brian Feldman                _ __ ___ ____  ___ ___ ___  
 green@unixhelp.org                _ __ ___ | _ ) __|   \ 
     FreeBSD: The Power to Serve!      _ __ | _ \__ \ |) |
         http://www.freebsd.org           _ |___/___/___/ 

diff -u src/bin/dd/args.c ./args.c
--- src/bin/dd/args.c	Wed May 13 03:33:36 1998
+++ ./args.c	Fri Apr  2 12:23:09 1999
@@ -67,7 +67,7 @@
 static void	f_of __P((char *));
 static void	f_seek __P((char *));
 static void	f_skip __P((char *));
-static u_long	get_bsz __P((char *));
+static u_quad_t	get_bsz __P((char *));
 
 static struct arg {
 	char *name;
@@ -173,8 +173,6 @@
 	 */
 	if (in.dbsz > INT_MAX || out.dbsz > INT_MAX)
 		errx(1, "buffer sizes cannot be greater than %d", INT_MAX);
-	if (in.offset > INT_MAX / in.dbsz || out.offset > INT_MAX / out.dbsz)
-		errx(1, "seek offsets cannot be larger than %d", INT_MAX);
 }
 
 static int
@@ -321,7 +319,7 @@
 }
 
 /*
- * Convert an expression of the following forms to an unsigned long.
+ * Convert an expression of the following forms to an unsigned quad_t.
  * 	1) A positive decimal number.
  *	2) A positive decimal number followed by a b (mult by 512).
  *	3) A positive decimal number followed by a k (mult by 1024).
@@ -331,15 +329,15 @@
  *	   seperated by x (also * for backwards compatibility), specifying
  *	   the product of the indicated values.
  */
-static u_long
+static u_quad_t
 get_bsz(val)
 	char *val;
 {
-	u_long num, t;
+	u_quad_t num, t;
 	char *expr;
 
-	num = strtoul(val, &expr, 0);
-	if (num == ULONG_MAX)			/* Overflow. */
+	num = strtouq(val, &expr, 0);
+	if (num == UQUAD_MAX)			/* Overflow. */
 		err(1, "%s", oper);
 	if (expr == val)			/* No digits. */
 		errx(1, "%s: illegal numeric value", oper);
diff -u src/bin/dd/dd.h ./dd.h
--- src/bin/dd/dd.h	Tue Feb 10 21:23:31 1998
+++ ./dd.h	Fri Apr  2 12:09:03 1999
@@ -69,7 +69,7 @@
 	u_long	out_part;		/* # of partial output blocks */
 	u_long	trunc;			/* # of truncated records */
 	u_long	swab;			/* # of odd-length swab blocks */
-	u_int64_t	bytes;		/* # of bytes written */
+	u_quad_t	bytes;		/* # of bytes written */
 	double	start; 			/* start time of dd */
 } STAT;
 
diff -u src/bin/dd/misc.c ./misc.c
--- src/bin/dd/misc.c	Mon Jan 18 11:04:13 1999
+++ ./misc.c	Fri Apr  2 11:20:24 1999
@@ -58,7 +58,7 @@
 {
 	struct timeval tv;
 	double secs;
-	char buf[100];
+	char buf[120];
 
 	(void)gettimeofday(&tv, (struct timezone *)NULL);
 	secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
@@ -81,7 +81,7 @@
 	}
 	(void)snprintf(buf, sizeof(buf),
 	    "%qu bytes transferred in %.6f secs (%.0f bytes/sec)\n",
-	    st.bytes, secs, st.bytes / secs);
+	    st.bytes, secs, (double)st.bytes / secs);
 	(void)write(STDERR_FILENO, buf, strlen(buf));
 }
 
--- src/bin/dd/position.c.orig	Sat Apr  3 09:51:26 1999
+++ src/bin/dd/position.c	Sat Apr  3 09:49:27 1999
@@ -64,7 +64,7 @@
 	int bcnt, cnt, nr, warned;
 
 	/* If not a character, pipe or tape device, try to seek on it. */
-	if (!(in.flags & (ISCHR|ISPIPE|ISTAPE))) {
+	if (!(in.flags & (ISPIPE|ISTAPE))) {
 		if (lseek(in.fd, (off_t)in.offset * in.dbsz, SEEK_CUR) == -1)
 			err(1, "%s", in.name);
 		return;
--- src/bin/dd/dd.c	Mon Apr  5 12:03:25 1999
+++ src/bin/dd/dd.c.new	Mon Apr  5 11:57:09 1999
@@ -178,8 +178,8 @@
 	 * table that does both at once.  If just converting case, use the
 	 * built-in tables.
 	 */
-	if (ddflags & (C_LCASE|C_UCASE))
-		if (ddflags & C_ASCII)
+	if (ddflags & (C_LCASE|C_UCASE)) {
+		if (ddflags & C_ASCII) {
 			if (ddflags & C_LCASE) {
 				for (cnt = 0; cnt <= 0377; ++cnt)
 					if (isupper(ctab[cnt]))
@@ -189,7 +189,7 @@
 					if (islower(ctab[cnt]))
 						ctab[cnt] = toupper(ctab[cnt]);
 			}
-		else if (ddflags & C_EBCDIC)
+		} else if (ddflags & C_EBCDIC) {
 			if (ddflags & C_LCASE) {
 				for (cnt = 0; cnt <= 0377; ++cnt)
 					if (isupper(cnt))
@@ -199,7 +199,7 @@
 					if (islower(cnt))
 						ctab[cnt] = ctab[toupper(cnt)];
 			}
-		else {
+		} else {
 			ctab = ddflags & C_LCASE ? u2l : l2u;
 			if (ddflags & C_LCASE) {
 				for (cnt = 0; cnt <= 0377; ++cnt)
@@ -215,6 +215,7 @@
 						ctab[cnt] = cnt;
 			}
 		}
+	}
 	(void)gettimeofday(&tv, (struct timezone *)NULL);
 	st.start = tv.tv_sec + tv.tv_usec * 1e-6; 
 }
@@ -247,11 +248,12 @@
 		 * Zero the buffer first if sync; If doing block operations
 		 * use spaces.
 		 */
-		if (ddflags & C_SYNC)
+		if (ddflags & C_SYNC) {
 			if (ddflags & (C_BLOCK|C_UNBLOCK))
 				memset(in.dbp, ' ', in.dbsz);
 			else
 				memset(in.dbp, 0, in.dbsz);
+		}
 
 		n = read(in.fd, in.dbp, in.dbsz);
 		if (n == 0) {




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9904051204510.36419-100000>