From: hades Date: Thu, 18 May 2000 21:24:57 +0000 (+0000) Subject: Write and read functions for ANSI labels. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=119b0ee30b1151d0d7defc6aff74fa80fdaa240b;p=daqdata.git Write and read functions for ANSI labels. --- diff --git a/hadaq/hwtapelabel.c b/hadaq/hwtapelabel.c new file mode 100644 index 0000000..3f98ae6 --- /dev/null +++ b/hadaq/hwtapelabel.c @@ -0,0 +1,226 @@ +/* For msglog() */ +#include +#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 "hwtapelabel.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; + 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)); + + sprintf(vol, "VOL1HADAQ %s%s 4", impId, ansichar(ownerId, 14)); + + 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 writeHeader(int tape, int fileSeqNum, const char *filename) { + int stat; + int i; + int blockSize = BLOCKSIZE; + char *hostname; + char *creaCent; + char *label; +#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, first_uid; + time_t tim; + struct passwd *pwentry; + struct tm *cd; + + gethostname(hostname, 20); + + tim = time(0); + cd = gmtime(&tim); + if ((cd->tm_year)/100 == 19) { + *creaCent = ' '; + } else { + *creaCent = '0'; + } + + label = allocMem(80*sizeof(char)); + + sprintf(label, "HDR1 %s0000010001%04d000100%s%02d%03d 99366 000000%s ", ansichar(filename, 17), fileSeqNum, creaCent, (cd->tm_year)%100, cd->tm_yday, impId); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + sprintf(label, "HDR2F%05d%05d010664 bin 33000 ", blockSize, blockSize); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + uid = getuid(); + pwentry = getpwent(); + first_uid = pwentry->pw_uid; + do { + pwentry = getpwent(); + } while (pwentry->pw_uid != uid && pwentry->pw_uid != first_uid); + + if (pwentry->pw_name == "root") { + pwentry->pw_name = "hades"; + } + + sprintf(label, "HDR3%010d%s%s%s", tim, unixchar(pwentry->pw_name, 10), unixchar(hostname, 20), unixchar(filename, 36)); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + freeMem(label); + return 0; +} + + +int writeTrailer(int tape, int fileSeqNum, int numBlocks, const char *filename) { + int stat; + int i; + int blockSize = BLOCKSIZE; + char *hostname; + char *creaCent; + char *label; +#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, first_uid; + time_t tim; + struct passwd *pwentry; + struct tm *cd; + + gethostname(hostname, 20); + + tim = time(0); + cd = gmtime(&tim); + if ((cd->tm_year)/100 == 19) { + *creaCent = ' '; + } else { + *creaCent = '0'; + } + + label = allocMem(80*sizeof(char)); + + sprintf(label, "EOF1 %s0000010001%04d000100%s%02d%03d 99366 %06d%s ", ansichar(filename, 17), fileSeqNum, creaCent, (cd->tm_year)%100, cd->tm_yday, numBlocks, impId); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + sprintf(label, "EOF2F%05d%05d010664 bin %010d33000 ", blockSize, blockSize, numBlocks*blockSize); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + uid = getuid(); + pwentry = getpwent(); + first_uid = pwentry->pw_uid; + do { + pwentry = getpwent(); + } while (pwentry->pw_uid != uid && pwentry->pw_uid != first_uid); + + if (pwentry->pw_name == "root") { + pwentry->pw_name = "hades"; + } + + sprintf(label, "EOF3%010d%s%s%s", tim, unixchar(pwentry->pw_name, 10), unixchar(hostname, 20), unixchar(filename, 36)); + stat = write(tape, label, 80); + if(stat == -1) { + msglog(LOG_ERR, "Could not write ANSI label on tape!\n"); + exit(-3); + } + + freeMem(label); + return 0; +} + diff --git a/hadaq/hwtapelabel.h b/hadaq/hwtapelabel.h new file mode 100644 index 0000000..35184d8 --- /dev/null +++ b/hadaq/hwtapelabel.h @@ -0,0 +1,14 @@ +#ifndef HWTAPELABEL_H +#define HWTAPELABEL_H + +#define BLOCKSIZE 8192 + +int writeHeader(int, int, const char *); +int writeTrailer(int, int, int, const char *); + +char *readVolumeLabel(int); +int writeVolumeLabel(const char *, int); +int writeNewVolumeLabel(const char *, const char *, int); + +#endif +