]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block.c
First cut SIGHUM + misc
[bacula/bacula] / bacula / src / stored / block.c
index 218c655e91e810af57b9519567b69b02d31387ca..832da0ee2542fc18d5e4226e214c16c1c09f7f68 100644 (file)
@@ -38,7 +38,7 @@ extern int debug_level;
  * Dump the block header, then walk through
  * the block printing out the record headers.
  */
-void dump_block(DEV_BLOCK *b, char *msg)
+void dump_block(DEV_BLOCK *b, const char *msg)
 {
    ser_declare;
    char *p;
@@ -239,7 +239,9 @@ static int unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
             Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
         }
         block->read_errors++;
-        return 0;
+        if (!forge_on) {
+           return 0;
+        }
       }
    } else if (Id[3] == '2') {
       unser_uint32(block->VolSessionId);
@@ -255,7 +257,9 @@ static int unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
             Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
         }
         block->read_errors++;
-        return 0;
+        if (!forge_on) {
+           return 0;
+        }
       }
    } else {
       dev->dev_errno = EIO;
@@ -264,7 +268,14 @@ static int unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
          Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       }
       block->read_errors++;
-      return 0;
+      if (!forge_on) {
+        return 0;
+      }
+      unser_uint32(block->VolSessionId);
+      unser_uint32(block->VolSessionTime);
+      bhl = BLKHDR2_LENGTH;
+      block->BlockVer = 2;
+      block->bufp = block->buf + bhl;
    }
 
    /* Sanity check */
@@ -276,7 +287,9 @@ static int unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
          Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       }
       block->read_errors++;
-      return 0;
+      if (!forge_on) {
+        return 0;
+      }
    }
 
    Dmsg1(190, "unser_block_header block_len=%d\n", block_len);
@@ -302,7 +315,9 @@ static int unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
             Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
         }
         block->read_errors++;
-        return 0;
+        if (!forge_on) {
+           return 0;
+        }
       }
    }
    return 1;
@@ -412,12 +427,15 @@ int write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
 
       /* Adjust write size to min/max for tapes only */
       if (dev->state & ST_TAPE) {
-        if (wlen < dev->min_block_size) {
-           wlen =  ((dev->min_block_size + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE;
-        }
         /* check for fixed block size */
         if (dev->min_block_size == dev->max_block_size) {
            wlen = block->buf_len;    /* fixed block size already rounded */
+        /* Check for min block size */
+        } else if (wlen < dev->min_block_size) {
+           wlen =  ((dev->min_block_size + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE;
+        /* Ensure size is rounded */
+        } else {
+           wlen = ((wlen + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE;
         }
       }
       if (wlen-blen > 0) {
@@ -486,7 +504,9 @@ int write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
         dev->dev_errno = EIO;
           Jmsg(jcr, M_ERROR, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
               dcr->VolCatInfo.VolCatName, jcr->Job);
-         return 0;
+         if (!forge_on) {
+            return 0;
+         }
       }
       dev->file_size = 0;            /* reset file size */
       /* 
@@ -503,7 +523,7 @@ int write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
    }
 
    dev->VolCatInfo.VolCatWrites++;
-   Dmsg1(300, "Write block of %u bytes\n", wlen);      
+   Dmsg1(200, "Write block of %u bytes\n", wlen);      
    stat = write(dev->fd, block->buf, (size_t)wlen);
    if (stat != (ssize_t)wlen) {
       /* We should check for errno == ENOSPC, BUT many 
@@ -525,7 +545,7 @@ int write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
         if (dev->dev_errno == 0) {
            dev->dev_errno = ENOSPC;        /* out of space */
         }
-         Jmsg(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"), 
+         Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"), 
            dev->file, dev->block_num, dev->dev_name, strerror(dev->dev_errno));
       } else {
        dev->dev_errno = ENOSPC;            /* out of space */
@@ -668,6 +688,9 @@ int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_bloc
    int retry;
    DCR *dcr = jcr->dcr;
 
+   if (!dcr) {
+      Jmsg0(jcr, M_ABORT, 0, _("DCR is NULL!\n"));
+   }
    if (dev_state(dev, ST_EOT)) {
       return 0;
    }