#undef rewind_dev
int _rewind_dev(char *file, int line, DEVICE *dev)
{
- Dmsg2(000, "rewind_dev called from %s:%d\n", file, line);
+ Dmsg2(100, "rewind_dev called from %s:%d\n", file, line);
return rewind_dev(dev);
}
#endif
}
if (!(dev->state & ST_TAPE)) {
pos = lseek(dev->fd, (off_t)0, SEEK_END);
-// Dmsg1(000, "====== Seek to %lld\n", pos);
+// Dmsg1(100, "====== Seek to %lld\n", pos);
if (pos >= 0) {
update_pos_dev(dev);
dev->state |= ST_EOT;
if (!rewind_dev(dev)) {
return 0;
}
- while (!(dev->state & ST_EOT)) {
- Dmsg0(200, "Do fsf 1\n");
+ /*
+ * Move file by file to the end of the tape
+ */
+ int file_num;
+ for (file_num=dev->file; !(dev->state & ST_EOT); file_num++) {
+ Dmsg0(200, "eod_dev: doing fsf 1\n");
if (!fsf_dev(dev, 1)) {
Dmsg0(200, "fsf_dev error.\n");
return 0;
}
+ /*
+ * Avoid infinite loop. ***FIXME*** possibly add code
+ * to set EOD or to turn off CAP_FASTFSF if on.
+ */
+ if (file_num == (int)dev->file) {
+ struct mtget mt_stat;
+ Dmsg1(000, "fsf_dev did not advance from file %d\n", file_num);
+ if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 &&
+ mt_stat.mt_fileno >= 0) {
+ Dmsg2(000, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
+ dev->file = mt_stat.mt_fileno;
+ }
+ stat = 0;
+ break; /* we are not progressing, bail out */
+ }
}
}
/*
* the second EOF.
*/
if (dev_cap(dev, CAP_BSFATEOM)) {
- stat = bsf_dev(dev, 1);
- dev->file++; /* keep same file */
+ struct mtget mt_stat;
+ /* Backup over EOF */
+ stat = bsf_dev(dev, 1);
+ /* If BSF worked and fileno is known (not -1), set file */
+ if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 && mt_stat.mt_fileno >= 0) {
+ Dmsg2(000, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
+ dev->file = mt_stat.mt_fileno;
+ } else {
+ dev->file++; /* wing it -- not correct on all OSes */
+ }
} else {
update_pos_dev(dev); /* update position */
stat = 1;
}
if (dev->state & ST_TAPE) {
stat |= BMT_TAPE;
- Dmsg0(-20," Driver status:");
+ Dmsg0(-20," Bacula status:");
Dmsg2(-20," file=%d block=%d\n", dev->file, dev->block_num);
if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
dev->dev_errno = errno;
int
fsf_dev(DEVICE *dev, int num)
{
+ struct mtget mt_stat;
struct mtop mt_com;
int stat = 0;
if (dev->state & ST_EOF) {
Dmsg0(200, "ST_EOF set on entry to FSF\n");
}
- if (dev->state & ST_EOT) {
- Dmsg0(200, "ST_EOT set on entry to FSF\n");
- }
Dmsg0(29, "fsf_dev\n");
dev->block_num = 0;
- if (dev_cap(dev, CAP_FSF)) {
+ /*
+ * If Fast forward space file is set, then we
+ * use MTFSF to forward space and MTIOCGET
+ * to get the file position. We assume that
+ * the SCSI driver will ensure that we do not
+ * forward space over the end of data mark.
+ */
+ if (dev_cap(dev, CAP_FSF) && dev_cap(dev, CAP_FASTFSF)) {
+ mt_com.mt_op = MTFSF;
+ mt_com.mt_count = num;
+ stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
+ if (stat < 0 || ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
+ dev->state |= ST_EOT;
+ Dmsg0(200, "Set ST_EOT\n");
+ clrerror_dev(dev, MTFSF);
+ Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
+ dev->dev_name, strerror(dev->dev_errno));
+ Dmsg1(200, "%s", dev->errmsg);
+ return 0;
+ }
+ Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
+ dev->file = mt_stat.mt_fileno;
+ dev->state |= ST_EOF; /* just read EOF */
+ dev->file_addr = 0;
+ return 1;
+
+ /*
+ * Here if CAP_FSF is set, and virtually all drives
+ * these days support it, we read a record, then forward
+ * space one file. Using this procedure, which is slow,
+ * is the only way we can be sure that we don't read
+ * two consecutive EOF marks, which means End of Data.
+ */
+ } else if (dev_cap(dev, CAP_FSF)) {
POOLMEM *rbuf;
int rbuf_len;
Dmsg0(200, "FSF has cap_fsf\n");
return -1;
}
- if (!(dev->state & ST_TAPE)) {
+ if (!(dev_state(dev, ST_TAPE))) {
return 0;
}
dev->state &= ~(ST_EOT | ST_EOF); /* remove EOF/EOT flags */
{
/* Read and clear SCSI error status */
union mterrstat mt_errstat;
- Pmsg2(000, "Doing MTIOCERRSTAT errno=%d ERR=%s\n", dev->dev_errno,
+ Dmsg2(200, "Doing MTIOCERRSTAT errno=%d ERR=%s\n", dev->dev_errno,
strerror(dev->dev_errno));
ioctl(dev->fd, MTIOCERRSTAT, (char *)&mt_errstat);
}