+/*
+ * Read a block from the spool file
+ *
+ * Returns RB_OK on success
+ * RB_EOT when file done
+ * RB_ERROR on error
+ */
+static int read_block_from_spool_file(DCR *dcr, DEV_BLOCK *block)
+{
+ uint32_t rlen;
+ ssize_t stat;
+ spool_hdr hdr;
+
+ rlen = sizeof(hdr);
+ stat = read(dcr->spool_fd, (char *)&hdr, (size_t)rlen);
+ if (stat == 0) {
+ Dmsg0(100, "EOT on spool read.\n");
+ return RB_EOT;
+ } else if (stat != (ssize_t)rlen) {
+ if (stat == -1) {
+ Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"), strerror(errno));
+ } else {
+ Dmsg2(000, "Spool read error. Wanted %u bytes, got %u\n", rlen, stat);
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %u\n"), rlen, stat);
+ }
+ return RB_ERROR;
+ }
+ rlen = hdr.len;
+ if (rlen > block->buf_len) {
+ Dmsg2(000, "Spool block too big. Max %u bytes, got %u\n", block->buf_len, rlen);
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool block too big. Max %u bytes, got %u\n"), block->buf_len, rlen);
+ return RB_ERROR;
+ }
+ stat = read(dcr->spool_fd, (char *)block->buf, (size_t)rlen);
+ if (stat != (ssize_t)rlen) {
+ Dmsg2(000, "Spool data read error. Wanted %u bytes, got %u\n", rlen, stat);
+ Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool data read error. Wanted %u bytes, got %u\n"), rlen, stat);
+ return RB_ERROR;
+ }
+ /* Setup write pointers */
+ block->binbuf = rlen;
+ block->bufp = block->buf + block->binbuf;
+ block->FirstIndex = hdr.FirstIndex;
+ block->LastIndex = hdr.LastIndex;
+ block->VolSessionId = dcr->jcr->VolSessionId;
+ block->VolSessionTime = dcr->jcr->VolSessionTime;
+ Dmsg2(100, "Read block FI=%d LI=%d\n", block->FirstIndex, block->LastIndex);
+ return RB_OK;
+}
+