From 4f1ea8d4a7c9f004945c497c3c5d3afd3b8d41f1 Mon Sep 17 00:00:00 2001 From: hades Date: Sun, 21 May 2000 10:20:24 +0000 Subject: [PATCH] *** empty log message *** --- hadaq/tape.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/hadaq/tape.c b/hadaq/tape.c index 7b8fcbd..cefee9c 100644 --- a/hadaq/tape.c +++ b/hadaq/tape.c @@ -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); } -- 2.43.0