} 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;
#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);
}