]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
*** empty log message ***
authorhades <hades>
Sun, 21 May 2000 10:20:24 +0000 (10:20 +0000)
committerhades <hades>
Sun, 21 May 2000 10:20:24 +0000 (10:20 +0000)
hadaq/tape.c

index 7b8fcbd6af87f0f64c899cf544cd2f7623df3a8a..cefee9cad60b1ef692042c71f0897ae33420fc1f 100644 (file)
@@ -91,20 +91,29 @@ FILE *openTape(const char* filename) {
                } while (stat != -1);
                freeMem(label);
        }
-       msglog(LOG_INFO, "Been after all the tape moving operations, now trying to write the Header.\n");
 
        writeHeader(tape, fileSeqNum, filename);
-       msglog(LOG_INFO, "Wrote Header.\n");
 
+       mtoper->mt_op = MTWEOF;
+       mtoper->mt_count = 1;
+       stat = ioctl(tape, MTIOCTOP, mtoper);
+       if (stat == -1) {
+                       msglog(LOG_ERR, "Could not write tapemark!\n");
+               exit(-2);
+       }
        mtoper->mt_op = MTSETBLK;
        mtoper->mt_count = BLOCKSIZE;
        stat = ioctl(tape, MTIOCTOP, mtoper);
        if (stat == -1) {
-                       msglog(LOG_ERR, "Could not go to the eon of the tape!\n");
+                       msglog(LOG_ERR, "Could not set the correct blocksize!\n");
+               exit(-2);
+       }
+
+       if (NULL == (outFile = fdopen(tape, "wb"))) {
+               msglog(LOG_ERR, "fdopen: %\n", strerror(errno));
                exit(-2);
        }
 
-       outFile = fdopen(tape, "wb");
        setvbuf(outFile, 0, _IOFBF, BLOCKSIZE);
 
        return outFile;
@@ -117,22 +126,39 @@ int closeTape(FILE *openTape, unsigned long numBytes, const char *filename) {
 #ifdef MTIOCTOP
        int stat;
        int tape;
+       struct mtop mtoperS, *mtoper = &mtoperS;
+
+       stat = fflush(openTape);
+       if (stat != 0) {
+               msglog(LOG_ERR, "Could not flush file on tape!\n");
+               exit(-2);
+       }
        tape = fileno(openTape);
        if (tape == -1) {
                msglog(LOG_ERR, "Could not get file file descriptor of file opened on tape!\n");
                exit(-2);
        }
-       stat = fclose(openTape);
+       mtoper->mt_op = MTWEOF;
+       mtoper->mt_count = 1;
+       stat = ioctl(tape, MTIOCTOP, mtoper);
        if (stat == -1) {
-               msglog(LOG_ERR, "Could not close file on tape!\n");
+                       msglog(LOG_ERR, "Could not write tapemark!\n");
+               exit(-2);
+       }
+       mtoper->mt_op = MTSETBLK;
+       mtoper->mt_count = 80;
+       stat = ioctl(tape, MTIOCTOP, mtoper);
+       if (stat == -1) {
+                       msglog(LOG_ERR, "Could not set blocksize to 80!\n");
                exit(-2);
        }
 
+
        writeTrailer(tape, 0, numBytes, filename);
 
-       stat = close(tape);
+       stat = fclose(openTape);
        if (stat == -1) {
-               msglog(LOG_ERR, "Could not close tape!\n");
+               msglog(LOG_ERR, "Could not close file on tape, stat return %d!\n", stat);
                exit(-2);
        }