Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 May 1999 21:13:10 +0930 (CST)
From:      Kris Kennaway <kkennawa@physics.adelaide.edu.au>
To:        stable@freebsd.org
Subject:   tcopy patch for large tapes
Message-ID:  <Pine.OSF.4.10.9905042108210.32078-200000@bragg>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Can someone with appropriate hardware test the following patch to
usr.bin/tcopy/tcopy.c:

----------------------------
revision 1.5
date: 1999/04/30 13:13:32;  author: phk;  state: Exp;  lines: +35 -15
Tcopy uses 32 bit unsigned to accumulate a count of bytes read/written.
That doesn't work well for tapes over 4G.

I use tcopy a lot to write images of a tape to tape as tape to tape
copying is terribly slow. Slower than it should be. Quickly found out
tcopy can not rewind a file when doing copy/verify.

PR:             11386
Submitted by:   David Kelly dkelly@hiwaay.net
Reviewed by:    phk
----------------------------

The patch should apply cleanly to -stable and looks like a good MFC candidate
for 3.2, providing it works.

Kris

-----
"That suit's sharper than a page of Oscar Wilde witticisms that's been
rolled up into a point, sprinkled with lemon juice and jabbed into
someone's eye"
"Wow, that's sharp!" - Ace Rimmer and the Cat, _Red Dwarf_

[-- Attachment #2 --]
--- tcopy.c.orig	Thu Aug 14 16:11:00 1997
+++ tcopy.c	Sat May  1 21:02:05 1999
@@ -42,7 +42,7 @@
 static char sccsid[] = "@(#)tcopy.c	8.2 (Berkeley) 4/17/94";
 #endif
 static const char rcsid[] =
-	"$Id: tcopy.c,v 1.4 1997/08/14 06:41:00 charnier Exp $";
+	"$Id: tcopy.c,v 1.5 1999/04/30 13:13:32 phk Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -65,7 +65,7 @@
 #define	NOCOUNT	(-2)
 
 int	filen, guesslen, maxblk = MAXREC;
-u_long	lastrec, record, size, tsize;
+u_int64_t	lastrec, record, size, tsize;
 FILE	*msg = stdout;
 
 void	*getspace __P((int));
@@ -73,6 +73,7 @@
 static void	 usage __P((void));
 void	 verify __P((int, int, char *));
 void	 writeop __P((int, int));
+void	rewind_tape(int);
 
 int
 main(argc, argv)
@@ -156,16 +157,16 @@
 				if (nread >= 0)
 					goto r1;
 			}
-			err(1, "read error, file %d, record %ld", filen, record);
+			err(1, "read error, file %d, record %qu", filen, record);
 		} else if (nread != lastnread) {
 			if (lastnread != 0 && lastnread != NOCOUNT) {
 				if (lastrec == 0 && nread == 0)
-					fprintf(msg, "%ld records\n", record);
+					fprintf(msg, "%qu records\n", record);
 				else if (record - lastrec > 1)
-					fprintf(msg, "records %ld to %ld\n",
+					fprintf(msg, "records %qu to %qu\n",
 					    lastrec, record);
 				else
-					fprintf(msg, "record %ld\n", lastrec);
+					fprintf(msg, "record %qu\n", lastrec);
 			}
 			if (nread != 0)
 				fprintf(msg, "file %d: block size %d: ",
@@ -183,9 +184,9 @@
 				nw = write(outp, buff, nread);
 				if (nw != nread) {
 					if (nw == -1) {
-					warn("write error, file %d, record %ld", filen, record);
+					warn("write error, file %d, record %qu", filen, record);
 					} else {
-					warnx("write error, file %d, record %ld", filen, record);
+					warnx("write error, file %d, record %qu", filen, record);
 					warnx("write (%d) != read (%d)", nw, nread);
 					}
 					errx(5, "copy aborted");
@@ -199,7 +200,7 @@
 				break;
 			}
 			fprintf(msg,
-			    "file %d: eof after %lu records: %lu bytes\n",
+			    "file %d: eof after %qu records: %qu bytes\n",
 			    filen, record, size);
 			needeof = 1;
 			filen++;
@@ -209,14 +210,14 @@
 		}
 		lastnread = nread;
 	}
-	fprintf(msg, "total length: %lu bytes\n", tsize);
+	fprintf(msg, "total length: %qu bytes\n", tsize);
 	(void)signal(SIGINT, oldsig);
 	if (op == COPY || op == COPYVERIFY) {
 		writeop(outp, MTWEOF);
 		writeop(outp, MTWEOF);
 		if (op == COPYVERIFY) {
-			writeop(outp, MTREW);
-			writeop(inp, MTREW);
+			rewind_tape(outp);
+			rewind_tape(inp);
 			verify(inp, outp, buff);
 		}
 	}
@@ -283,10 +284,10 @@
 {
 	if (record)
 		if (record - lastrec > 1)
-			fprintf(msg, "records %ld to %ld\n", lastrec, record);
+			fprintf(msg, "records %qu to %qu\n", lastrec, record);
 		else
-			fprintf(msg, "record %ld\n", lastrec);
-	fprintf(msg, "interrupt at file %d: record %ld\n", filen, record);
+			fprintf(msg, "record %qu\n", lastrec);
+	fprintf(msg, "interrupt at file %d: record %qu\n", filen, record);
 	fprintf(msg, "total length: %ld bytes\n", tsize + size);
 	exit(1);
 }
@@ -319,4 +320,23 @@
 {
 	fprintf(stderr, "usage: tcopy [-cvx] [-s maxblk] [src [dest]]\n");
 	exit(1);
+}
+
+void
+rewind_tape(int fd)
+{
+	struct stat sp;
+
+	if(fstat(fd, &sp))
+		errx(12, "fstat in rewind");
+
+	/*
+	 * don't want to do tape ioctl on regular files:
+	 */
+	if( S_ISREG(sp.st_mode) ) {
+		if( lseek(fd, 0, SEEK_SET) == -1 )
+			errx(13, "lseek");
+	} else
+		/*  assume its a tape	*/
+		writeop(fd, MTREW);
 }
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.OSF.4.10.9905042108210.32078-200000>