From: hades Date: Sun, 21 May 2000 18:08:44 +0000 (+0000) Subject: Replaced by Files called ansiTape*.[ch]. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=459da0c714887ec61acc3301ad34d927276a281f;p=daqdata.git Replaced by Files called ansiTape*.[ch]. --- diff --git a/hadaq/tape.c b/hadaq/tape.c deleted file mode 100644 index cefee9c..0000000 --- a/hadaq/tape.c +++ /dev/null @@ -1,170 +0,0 @@ -/* For allocMem(), freeMem() */ -#include -/* For msglog() */ -#include -#include - -/* For fdopen(), fclose(), sscanf(), printf() */ -#include -/* For open() */ -#include -#include -#include -/* For read(), close() */ -#include - -/* For st */ -#include -#include - -#include "tapelabel.h" -#include "tape.h" - -FILE *openTape(const char* filename) { -#ifdef MTIOCTOP - int tape; - int fileSeqNum; - int stat; - int i = 0; - - char *vol; - char *label; - - FILE *outFile; - - struct mtop mtoperS, *mtoper = &mtoperS; - - tape = open("/dev/tape", O_RDWR); - if(tape == -1) { - msglog(LOG_ERR, "Could not open tape!\n"); - exit(-2); - } - - mtoper->mt_op = MTEOM; - mtoper->mt_count = 1; - stat = ioctl(tape, MTIOCTOP, mtoper); - if (stat == -1) { - msglog(LOG_ERR, "Could not go to the eon of the tape!\n"); - perror("What went wrong going to the EOM via ioctl?"); - exit(-2); - } - - mtoper->mt_op = MTBSF; - mtoper->mt_count = 3; - stat = ioctl(tape, MTIOCTOP, mtoper); - if (stat == -1) { - - mtoper->mt_op = MTREW; - mtoper->mt_count = 1; - stat = ioctl(tape, MTIOCTOP, mtoper); - if (stat == -1) { - msglog(LOG_ERR, "Could not rewind tape!\n"); - exit(-2); - } - - vol = readVolumeLabel(tape); - - stat = ioctl(tape, MTIOCTOP, mtoper); - if (stat == -1) { - msglog(LOG_ERR, "Could not rewind tape!\n"); - exit(-2); - } - - writeVolumeLabel(vol, tape); - fileSeqNum = 1; - } else { - mtoper->mt_op = MTFSF; - mtoper->mt_count = 1; - stat = ioctl(tape, MTIOCTOP, mtoper); - if (stat == -1) { - msglog(LOG_ERR, "Could not jump over the filemark!\n"); - exit(-2); - } - label = allocMem(80*sizeof(char)); - do { - stat = read(tape, label, 80); - if (i == 0) { - sscanf(label, "%*31c%4d", &fileSeqNum); - printf("File Sequence Number: %04i\n", fileSeqNum); - } - i++; - } while (stat != -1); - freeMem(label); - } - - writeHeader(tape, fileSeqNum, filename); - - 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 set the correct blocksize!\n"); - exit(-2); - } - - if (NULL == (outFile = fdopen(tape, "wb"))) { - msglog(LOG_ERR, "fdopen: %\n", strerror(errno)); - exit(-2); - } - - setvbuf(outFile, 0, _IOFBF, BLOCKSIZE); - - return outFile; -#else - return NULL; -#endif -} - -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); - } - 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 = 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 = fclose(openTape); - if (stat == -1) { - msglog(LOG_ERR, "Could not close file on tape, stat return %d!\n", stat); - exit(-2); - } - - return 0; -#else - return -1; -#endif -} - diff --git a/hadaq/tape.h b/hadaq/tape.h deleted file mode 100644 index e56e3cd..0000000 --- a/hadaq/tape.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef HWTAPE_H -#define HWTAPE_H - -/* For FILE */ -#include - -FILE *openTape(const char *); - -int closeTape(FILE *, unsigned long, const char *); - -#endif - diff --git a/hadaq/tapechar.c b/hadaq/tapechar.c deleted file mode 100644 index 250b07b..0000000 --- a/hadaq/tapechar.c +++ /dev/null @@ -1,70 +0,0 @@ -#include - -#include "tapechar.h" - -char *ansichar(char *s, int length) { - int i, end = 0; - for(i=0 ; i'): - case ('?'): - break; - case ('\0'): - s[i] = ' '; - end = 1; - break; - default: - s[i] = 'Z'; - break; - } - } - } else { - s[i] = ' '; - } - } - s[length] = '\0'; - - return s; -} - -char *unixchar(char *s, int length) { - int i, end = 0; - for(i=0 ; i -#include -/* For allocMem(), freeMem() */ -#include -/* For memcpy() */ -#include - -/* For read(), write(), gethostname() */ -#include - -/* For time() */ -#include -/* For getpwent() */ -#include -#include -/* For getuid() */ -#include -#include - -#include "tapechar.h" -#include "tapelabel.h" - -/* Functions concerning the volume label */ - -char *readVolumeLabel(int tape) { - char *vol; - int stat; - vol = allocMem(80*sizeof(char)); - stat = read(tape, vol, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not read volume label from tape!\n"); - exit(-3); - } - - return vol; - freeMem(vol); -} - -int writeVolumeLabel(const char *vol, int tape) { - char *v; - int stat; - v = allocMem(80*sizeof(char)); - memcpy(v, vol, 80); - stat = write(tape, v, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not write volume label to tape!\n"); - exit(-3); - } - - freeMem(v); - return 0; -} - -int writeNewVolumeLabel(const char *volId, const char *ownerId, int tape) { - char *vol, *oid; - int stat; - -#ifdef LINUX - const char *impId = "LINUXHADAQ023"; -#endif -#ifdef UNIX - const char *impId = "UNIXHADAQ0023"; -#endif -#ifndef LINUX -#ifndef UNIX - const char *impId = " HADAQ0023"; -#endif -#endif - - vol = allocMem(80*sizeof(char)); - - oid = allocMem(15*sizeof(char)); - if (80 != sprintf(vol, "VOL1HADAQ %s%s 4", impId, ansichar(oid, 14))) { - msglog(LOG_ERR, "LabelV not 80 char!\n"); - exit(-3); - } - freeMem(oid); - - stat = write(tape, vol, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not write volume label to tape!\n"); - exit(-3); - } - - freeMem(vol); - return 0; -} - -/* Functions concerning the hdr-label and the eof-label */ - -int writeLabel(const char *hdreof, int tape, int fileSeqNum, int bytes, const char *filename) { - int stat; - int i; - int blockSize = BLOCKSIZE; - char hostname[21]; - char *creaCent; - char label[81]; - char fn[37]; -#ifdef LINUX - const char *impId = "LINUXHADAQ023"; -#endif -#ifdef UNIX - const char *impId = "UNIXHADAQ0023"; -#endif -#ifndef LINUX - #ifndef UNIX - const char *impId = " HADAQ0023"; - #endif -#endif - uid_t uid; - char *user; - time_t tim; - struct passwd pwentryS, *pwentry = &pwentryS; - struct tm cdS, *cd = &cdS; - - tim = time(0); - cd = gmtime(&tim); - if ((cd->tm_year)/100 == 19) { - creaCent = " "; - } else { - creaCent = "0"; - } - - strcpy(fn, filename); - if (80 != sprintf(label, "%-3s%1d%-17s%06d%04d%04d%04d%02d%1s%02d%03d%6d%1s%06d%-13s%-7s", - hdreof, - 1, - ansichar(fn, 17), - 1, - 1, - fileSeqNum, - 1, - 0, - creaCent, (cd->tm_year)%100, cd->tm_yday, - 99366, - " ", - (bytes + BLOCKSIZE -1) / BLOCKSIZE, - impId, - "") - ) { - msglog(LOG_ERR, "Label1 not 80 char!\n"); - exit(-3); - } - - stat = write(tape, label, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); - exit(-3); - } - - if (80 != sprintf(label, "%-3s%1d%1s%05d%05d%-21s%1s%010d%-3s%02d%28s", - hdreof, - 2, - "F", - blockSize, - blockSize, - "", - "M", - bytes, - "", - 0, - "") - ) { - msglog(LOG_ERR, "Label2 not 80 char!\n"); - exit(-3); - } - stat = write(tape, label, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); - exit(-3); - } - - uid = getuid(); - while (NULL != (pwentry = getpwent()) && pwentry->pw_uid != uid) { - } - - if (NULL != pwentry) { - user = pwentry->pw_name; - } else { - user = "hades"; - } - - gethostname(hostname, 20); - - if (80 != sprintf(label, "%-3s%1d%010d%-10s%-20s%-36s", - hdreof, - 3, - tim, - user, - hostname, - filename) - ) { - msglog(LOG_ERR, "Label3 not 80 char!\n"); - exit(-3); - } - - stat = write(tape, label, 80); - if(stat == -1) { - msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); - exit(-3); - } - return 0; -} - -int writeHeader(int tape, int fileSeqNum, const char *filename) { - return writeLabel("HDR", tape, fileSeqNum, 0, filename); -} - -int writeTrailer(int tape, int fileSeqNum, unsigned long numBytes, const char *filename) { - return writeLabel("EOF", tape, fileSeqNum, numBytes, filename); -} diff --git a/hadaq/tapelabel.h b/hadaq/tapelabel.h deleted file mode 100644 index 9f36d78..0000000 --- a/hadaq/tapelabel.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef HWTAPELABEL_H -#define HWTAPELABEL_H - -#define BLOCKSIZE 8192 - -char *readVolumeLabel(int); -int writeVolumeLabel(const char *, int); -int writeNewVolumeLabel(const char *, const char *, int); - -int writeHeader(int, int, const char *); -int writeTrailer(int, int, unsigned long, const char *); - -#endif -