+#endif
+
+void
+RequestVol(long tnum)
+{
+ FLUSHTAPEBUF();
+ getvol(tnum);
+}
+
+#ifdef USE_QFA
+#ifdef sunos
+extern int fdsmtc;
+
+struct uscsi_cmd {
+ int uscsi_flags; /* read, write, etc. see below */
+ short uscsi_status; /* resulting status */
+ short uscsi_timeout; /* Command Timeout */
+ caddr_t uscsi_cdb; /* cdb to send to target */
+ caddr_t uscsi_bufaddr; /* i/o source/destination */
+ u_int uscsi_buflen; /* size of i/o to take place */
+ u_int uscsi_resid; /* resid from i/o operation */
+ u_char uscsi_cdblen; /* # of valid cdb bytes */
+ u_char uscsi_rqlen; /* size of uscsi_rqbuf */
+ u_char uscsi_rqstatus; /* status of request sense cmd */
+ u_char uscsi_rqresid; /* resid of request sense cmd */
+ caddr_t uscsi_rqbuf; /* request sense buffer */
+ void *uscsi_reserved_5; /* Reserved for Future Use */
+};
+
+#define CDB_GROUP0 6 /* 6-byte cdb's */
+#define CDB_GROUP1 10 /* 10-byte cdb's */
+#define CDB_GROUP2 10 /* 10-byte cdb's */
+#define CDB_GROUP3 0 /* reserved */
+#define CDB_GROUP4 16 /* 16-byte cdb's */
+#define CDB_GROUP5 12 /* 12-byte cdb's */
+#define CDB_GROUP6 0 /* reserved */
+#define CDB_GROUP7 0 /* reserved */
+
+#define USCSI_WRITE 0x00000 /* send data to device */
+#define USCSI_SILENT 0x00001 /* no error messages */
+#define USCSI_DIAGNOSE 0x00002 /* fail if any error occurs */
+#define USCSI_ISOLATE 0x00004 /* isolate from normal commands */
+#define USCSI_READ 0x00008 /* get data from device */
+#define USCSI_RESET 0x04000 /* Reset target */
+#define USCSI_RESET_ALL 0x08000 /* Reset all targets */
+#define USCSI_RQENABLE 0x10000 /* Enable Request Sense extensions */
+
+#define USCSIIOC (0x04 << 8)
+#define USCSICMD (USCSIIOC|201) /* user scsi command */
+
+#define USCSI_TIMEOUT 30
+#define USCSI_SHORT_TIMEOUT 900
+#define USCSI_LONG_TIMEOUT 14000
+
+#define B(s,i) ((unsigned char)((s) >> i))
+#define B1(s) ((unsigned char)(s))
+
+#define MSB4(s,v) *(s)=B(v,24),(s)[1]=B(v,16), (s)[2]=B(v,8), (s)[3]=B1(v)
+
+
+int
+GetTapePos(long long *pos)
+{
+ int err = 0;
+ struct uscsi_cmd scmd;
+ char buf[512];
+ char parm[512 * 8];
+ long lpos;
+
+ (void)memset((void *)buf, 0, sizeof(buf));
+ (void)memset((void *)&scmd, 0, sizeof(scmd));
+ scmd.uscsi_flags = USCSI_READ|USCSI_SILENT;
+ scmd.uscsi_timeout = USCSI_TIMEOUT;
+ scmd.uscsi_cdb = buf;
+ scmd.uscsi_cdblen = CDB_GROUP1;
+ buf[0] = 0x34; /* read position */
+ buf[1] = 0;
+ (void)memset((void *)parm, 0, 512);
+ scmd.uscsi_bufaddr = parm;
+ scmd.uscsi_buflen = 56;
+ if (ioctl(fdsmtc, USCSICMD, &scmd) == -1) {
+ err = errno;
+ return err;
+ }
+ (void)memcpy(&lpos, &parm[4], sizeof(long));
+ *pos = lpos;
+ return err;
+}
+
+int
+GotoTapePos(long long pos)
+{
+ int err = 0;
+ struct uscsi_cmd scmd;
+ char buf[512];
+ char parm[512 * 8];
+ long lpos = (long)pos;
+
+ (void)memset((void *)buf, 0, sizeof(buf));
+ (void)memset((void *)&scmd, 0, sizeof(scmd));
+ scmd.uscsi_flags = USCSI_WRITE|USCSI_SILENT;
+ scmd.uscsi_timeout = 360; /* 5 Minutes */
+ scmd.uscsi_cdb = buf;
+ scmd.uscsi_cdblen = CDB_GROUP1;
+ buf[0] = 0x2b; /* locate */
+ buf[1] = 0;
+ MSB4(&buf[3], lpos);
+ (void)memset((void *)parm, 0, 512);
+ scmd.uscsi_bufaddr = NULL;
+ scmd.uscsi_buflen = 0;
+ if (ioctl(fdsmtc, USCSICMD, &scmd) == -1) {
+ err = errno;
+ return err;
+ }
+ return err;
+}
+#endif
+
+#define LSEEK_GET_TAPEPOS 10
+#define LSEEK_GO2_TAPEPOS 11
+
+#ifdef __linux__
+typedef struct mt_pos {
+ short mt_op;
+ int mt_count;
+} MTPosRec, *MTPosPtr;
+
+
+/*
+ * get the current position of the tape
+ */
+int
+GetTapePos(long long *pos)
+{
+ int err = 0;
+
+#ifdef RDUMP
+ if (host) {
+ *pos = (long long) rmtseek((OFF_T)0, (int)LSEEK_GET_TAPEPOS);
+ err = *pos < 0;
+ }
+ else
+#endif
+ {
+ if (magtapein) {
+ long mtpos;
+ *pos = 0;
+ err = (ioctl(mt, MTIOCPOS, &mtpos) < 0);
+ *pos = (long long)mtpos;
+ }
+ else {
+ *pos = LSEEK(mt, 0, SEEK_CUR);
+ err = (*pos < 0);
+ }
+ }
+ if (err) {
+ err = errno;
+ fprintf(stdout, "[%ld] error: %d (getting tapepos: %lld)\n",
+ (unsigned long)getpid(), err, *pos);
+ return err;
+ }
+ return err;
+}
+
+/*
+ * go to specified position on tape
+ */
+int
+GotoTapePos(long long pos)
+{
+ int err = 0;
+
+#ifdef RDUMP
+ if (host)
+ err = (rmtseek((OFF_T)pos, (int)LSEEK_GO2_TAPEPOS) < 0);
+ else
+#endif
+ {
+ if (magtapein) {
+ struct mt_pos buf;
+ buf.mt_op = MTSEEK;
+ buf.mt_count = (int) pos;
+ err = (ioctl(mt, MTIOCTOP, &buf) < 0);
+ }
+ else {
+ pos = LSEEK(mt, pos, SEEK_SET);
+ err = (pos < 0);
+ }
+ }
+ if (err) {
+ err = errno;
+ fprintf(stdout, "[%ld] error: %d (setting tapepos: %lld)\n",
+ (unsigned long)getpid(), err, pos);
+ return err;
+ }
+ return err;
+}
+#endif /* __linux__ */
+
+/*
+ * read next data from tape to re-sync
+ */
+void
+ReReadFromTape(void)
+{
+ FLUSHTAPEBUF();
+ noresyncmesg = 1;
+ if (gethead(&spcl) == FAIL) {
+#ifdef DEBUG_QFA
+ fprintf(stdout, "DEBUG 1 gethead failed\n");
+#endif
+ }
+ findinode(&spcl);
+ noresyncmesg = 0;
+}
+
+void
+ReReadInodeFromTape(dump_ino_t theino)
+{
+ long cntloop = 0;
+
+ FLUSHTAPEBUF();
+ noresyncmesg = 1;
+ do {
+ cntloop++;
+ gethead(&spcl);
+ } while (!(spcl.c_inumber == theino && spcl.c_type == TS_INODE && spcl.c_date == dumpdate));
+#ifdef DEBUG_QFA
+ fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
+ fprintf(stderr, "DEBUG: bufsize %ld\n", bufsize);
+ fprintf(stderr, "DEBUG: ntrec %ld\n", ntrec);
+ fprintf(stderr, "DEBUG: %ld reads\n", cntloop);
+#endif
+ findinode(&spcl);
+ noresyncmesg = 0;
+}
+
+#ifdef sunos
+int
+OpenSMTCmt(char *themagtape)
+{
+ if (GetSCSIIDFromPath(themagtape, &scsiid)) {
+ fprintf(stderr, "can't get SCSI-ID for %s\n", themagtape);
+ return -1;
+ }
+ if (scsiid < 0) {
+ fprintf(stderr, "can't get SCSI-ID for %s\n", themagtape);
+ return -1;
+ }
+ sprintf(smtcpath, "/dev/rsmtc%ld,0", scsiid);
+ if ((fdsmtc = open(smtcpath, O_RDWR)) == -1) {
+ fprintf(stderr, "can't open smtc device: %s, %d\n", smtcpath, errno);
+ return -1;
+ }
+ return 0;
+}
+#endif /* sunos */
+#endif /* USE_QFA */