]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block_util.c
Ensure that zero JobMedias are written for labelling
[bacula/bacula] / bacula / src / stored / block_util.c
index 7fc45d21181410234210a836a6e9ad4f2688a237..3d67de92086f20bf44cebdb85c22701dcb2c32ff 100644 (file)
@@ -1,8 +1,7 @@
 /*
    Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2000-2015 Kern Sibbald
-   Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2016 Kern Sibbald
 
    The original author of Bacula is Kern Sibbald, with contributions
    from many others, a complete list can be found in the file AUTHORS.
@@ -82,8 +81,11 @@ void dump_block(DEV_BLOCK *b, const char *msg)
       rhl = RECHDR1_LENGTH;
    }
 
-   if (block_len > 4000000) {
-      Dmsg3(20, "!!!Dump block %s 0x%x blocksize too big %u\n", msg, b, block_len);
+   if (block_len > 4000000 || block_len < BLKHDR_CS_LENGTH) {
+      Dmsg4(20, "!!!Dump block %s %p blocksize too %s %lu\n",
+            msg, b,
+            (block_len < BLKHDR_CS_LENGTH)?"small":"big",
+            block_len);
       return;
    }
 
@@ -135,7 +137,6 @@ DEV_BLOCK *new_block(DEVICE *dev)
     */
    block->buf_len = len;
    block->buf = get_memory(block->buf_len);
-   block->rechdr_queue = get_memory(block->buf_len);
    block->rechdr_items = 0;
    empty_block(block);
    block->BlockVer = BLOCK_VER;       /* default write version */
@@ -184,10 +185,9 @@ void DCR::free_blocks()
  */
 void free_block(DEV_BLOCK *block)
 {
-   if (block) {
+   if (block && block->buf) {
       Dmsg1(999, "free_block buffer %x\n", block->buf);
       free_memory(block->buf);
-      free_memory(block->rechdr_queue);
       Dmsg1(999, "free_block block %x\n", block);
       free_memory((POOLMEM *)block);
    }
@@ -273,8 +273,8 @@ bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    unser_uint32(BlockNumber);
    unser_bytes(Id, BLKHDR_ID_LENGTH);
    ASSERT(unser_length(block->buf) == BLKHDR1_LENGTH);
-
    Id[BLKHDR_ID_LENGTH] = 0;
+
    if (Id[3] == '1') {
       bhl = BLKHDR1_LENGTH;
       block->BlockVer = 1;
@@ -621,8 +621,8 @@ bool check_for_newvol_or_newfile(DCR *dcr)
          Dmsg0(100, "Canceled\n");
          return false;
       }
-      /* Create a jobmedia record for this job */
-      if (!dir_create_jobmedia_record(dcr)) {
+      /* If we wrote on Volume create a last jobmedia record for this job */
+      if (dcr->VolFirstIndex && !dir_create_jobmedia_record(dcr)) {
          dcr->dev->dev_errno = EIO;
          Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
             dcr->getVolCatName(), jcr->Job);