]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Write and read functions for ANSI labels.
authorhades <hades>
Thu, 18 May 2000 21:24:57 +0000 (21:24 +0000)
committerhades <hades>
Thu, 18 May 2000 21:24:57 +0000 (21:24 +0000)
hadaq/hwtapelabel.c [new file with mode: 0644]
hadaq/hwtapelabel.h [new file with mode: 0644]

diff --git a/hadaq/hwtapelabel.c b/hadaq/hwtapelabel.c
new file mode 100644 (file)
index 0000000..3f98ae6
--- /dev/null
@@ -0,0 +1,226 @@
+/* For msglog() */
+#include <hadesstd.h>
+#include <errno.h>
+/* For allocMem(), freeMem() */
+#include <hadesstd.h>
+/* For memcpy() */
+#include <string.h>
+
+/* For read(), write(), gethostname() */
+#include <unistd.h>
+
+/* For time() */
+#include <time.h>
+/* For getpwent() */
+#include <pwd.h>
+#include <sys/types.h>
+/* For getuid() */
+#include <unistd.h>
+#include <sys/types.h>
+
+#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 (file)
index 0000000..35184d8
--- /dev/null
@@ -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
+