+ return stat == 0;
+}
+
+/*
+ * Reposition the device to file, block
+ * Returns: false on failure
+ * true on success
+ */
+bool
+reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
+{
+ if (dev->fd < 0) {
+ dev->dev_errno = EBADF;
+ Mmsg0(dev->errmsg, _("Bad call to reposition_dev. Archive not open\n"));
+ Emsg0(M_FATAL, 0, dev->errmsg);
+ return false;
+ }
+
+ if (!(dev_state(dev, ST_TAPE))) {
+ off_t pos = (((off_t)file)<<32) + block;
+ Dmsg1(100, "===== lseek to %d\n", (int)pos);
+ if (lseek(dev->fd, pos, SEEK_SET) == (off_t)-1) {
+ dev->dev_errno = errno;
+ Mmsg2(dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
+ dev->dev_name, strerror(dev->dev_errno));
+ return false;
+ }
+ dev->file = file;
+ dev->block_num = block;
+ dev->file_addr = pos;
+ return true;
+ }
+ Dmsg4(100, "reposition_dev from %u:%u to %u:%u\n",
+ dev->file, dev->block_num, file, block);
+ if (file < dev->file) {
+ Dmsg0(100, "Rewind_dev\n");
+ if (!rewind_dev(dev)) {
+ return false;
+ }
+ }
+ if (file > dev->file) {
+ Dmsg1(100, "fsf %d\n", file-dev->file);
+ if (!fsf_dev(dev, file-dev->file)) {
+ return false;
+ }
+ }
+ if (block < dev->block_num) {
+ bsf_dev(dev, 1);
+ fsf_dev(dev, 1);
+ }
+ if (dev_cap(dev, CAP_POSITIONBLOCKS) && block > dev->block_num) {
+ /* Ignore errors as Bacula can read to the correct block */
+ Dmsg1(100, "fsr %d\n", block-dev->block_num);
+ return fsr_dev(dev, block-dev->block_num);
+ }
+ return true;