bin/57715: tcopy enhancement

ob at breuninger.org ob at breuninger.org
Tue Oct 7 12:50:11 PDT 2003


>Number:         57715
>Category:       bin
>Synopsis:       tcopy enhancement
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 07 12:50:07 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Oliver Breuninger
>Release:        FreeBSD 4.8-RELEASE i386
>Organization:
>Environment:
System: FreeBSD bs-tosh.breuninger.org 4.8-RELEASE FreeBSD 4.8-RELEASE #12: Thu Oct 2 18:42:17 CEST 2003 root at bs-tosh.breuninger.org:/usr/src/sys/compile/TOSHIBA i386


	

>Description:

tcopy can be used to copy tape's from streamer to streamer.
This modification enable you to copy from a tape to disk, with
information of blocksizes:

	tcopy /dev/nsa0 .

This produces files like:

	file-000.32768
	file-001.32768
	file-002.32768
	file-003.32768
	file-004.32768
	file-005.32768
	file-006.32768
	file-007.32768
 
In this case is '.32768' the used blocksize on this tape.

You can copy each file with dd to a other tape:

	dd if=file-000.32768 obs=64k conv=osync of=/dev/nsa0

This modification is helpful for recompilation of tapes and
changing the blocksizes.

>How-To-Repeat:
	

>Fix:

--- tcopy.c.orig	Thu Nov  7 18:54:42 2002
+++ tcopy.c	Tue Oct  7 15:14:07 2003
@@ -32,4 +32,8 @@
  */
 
+/*
+   Modification 2000 Daniel Mack, Oliver Breuninger
+*/
+
 #ifndef lint
 static const char copyright[] =
@@ -86,5 +90,10 @@
 	int ch, needeof;
 	char *buff, *inf;
+        struct stat statbuf;
+        char Dirname[0xff], FileName[0xff];
+        int BlockSize;
 
+	bzero (Dirname, sizeof (Dirname));
+	bzero (FileName, sizeof (FileName));
 	msg = stdout;
 	guesslen = 1;
@@ -130,7 +139,16 @@
 			op = COPY;
 		inf = argv[0];
-		if ((outp = open(argv[1], op == VERIFY ? O_RDONLY :
-		    op == COPY ? O_WRONLY : O_RDWR, DEFFILEMODE)) < 0)
-			err(3, "%s", argv[1]);
+
+		/* create file */
+		if ((!stat (argv[1], &statbuf)) && (statbuf.st_mode & S_IFDIR)) {
+			sprintf (Dirname, "%s/tcopy.tmp", argv[1]);
+			if ((outp = open (Dirname, O_CREAT | O_RDWR, DEFFILEMODE)) < 0)
+				err (3, "%s", Dirname);
+			}
+		else {
+			if ((outp = open(argv[1], op == VERIFY ? O_RDONLY :
+			    op == COPY ? O_WRONLY : O_RDWR, DEFFILEMODE)) < 0)
+				err(3, "%s", argv[1]);
+			}
 		break;
 	default:
@@ -171,4 +189,5 @@
 			}
 			if (nread != 0)
+				BlockSize = nread;
 				fprintf(msg, "file %d: block size %d: ",
 				    filen, nread);
@@ -180,7 +199,12 @@
 			if (op == COPY || op == COPYVERIFY) {
 				if (needeof) {
-					writeop(outp, MTWEOF);
-					needeof = 0;
-				}
+					if (! strlen (Dirname)) {
+						writeop(outp, MTWEOF);
+						needeof = 0;
+						}
+					}
+
+			/*	fprintf(msg, "tcopy: block %qu\n", record); */
+
 				nw = write(outp, buff, nread);
 				if (nw != nread) {
@@ -197,4 +221,14 @@
 			record++;
 		} else {
+			if (strlen (Dirname)) {
+				nw = write(outp, buff, nread);
+
+				sprintf (FileName, "%s/file-%03d.%d", argv[1], filen, BlockSize);
+				close (outp);
+				rename (Dirname, FileName);
+				if ((outp = open (Dirname, O_CREAT | O_RDWR, DEFFILEMODE)) < 0)
+					err (3, "%s", Dirname);
+				}
+
 			if (lastnread <= 0 && lastnread != NOCOUNT) {
 				fprintf(msg, "eot\n");
@@ -211,10 +245,19 @@
 		}
 		lastnread = nread;
+
 	}
 	fprintf(msg, "total length: %qu bytes\n", tsize);
 	(void)signal(SIGINT, oldsig);
 	if (op == COPY || op == COPYVERIFY) {
-		writeop(outp, MTWEOF);
-		writeop(outp, MTWEOF);
+		if (strlen (Dirname)) {
+			close (outp);
+			remove (FileName);
+			remove (Dirname);
+			}
+		else {
+			writeop(outp, MTWEOF);
+			writeop(outp, MTWEOF);
+			}
+
 		if (op == COPYVERIFY) {
 			rewind_tape(outp);

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list