]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BB03 recycle continuity
authorAlain Spineux <alain@baculasystems.com>
Fri, 18 Nov 2022 09:44:20 +0000 (10:44 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
bacula/src/stored/block_util.c
bacula/src/stored/dev.c
bacula/src/stored/label.c
bacula/src/stored/record.h
bacula/src/stored/record_read.c

index 5fda8b3f2f2372c0e6ba7f754bf70a8ab1f7172d..5028130cc2fd11d969f4da2dc59d6b0f363c5c60 100644 (file)
@@ -487,7 +487,8 @@ bool unser_block_header(DCR *dcr, DEVICE *dev, DEV_BLOCK *block)
    unser_bytes(Id, BLKHDR_ID_LENGTH);
    ASSERT(unser_length(block->buf) == BLKHDR1_LENGTH);
    Id[BLKHDR_ID_LENGTH] = 0;
-   block->CheckSum64 = CheckSumLo; // only for BB01 & BB02
+   block->CheckSum64 = CheckSumLo; /* only for BB01 & BB02 */
+   block->blkh_options = BLKHOPT_NONE; /* only in BB03 */
    if (Id[3] == '1') {
       bhl = BLKHDR1_LENGTH;
       block->BlockVer = 1;
@@ -527,12 +528,11 @@ bool unser_block_header(DCR *dcr, DEVICE *dev, DEV_BLOCK *block)
       }
    } else if (Id[3] == '3') {
       bhl = BLKHDR3_LENGTH;
-      uint32_t blkh_options = CheckSumLo; /* in BB03 blkh_options is stored at the checksum location */
+      block->blkh_options = CheckSumLo; /* in BB03 blkh_options is stored at the checksum location */
       unser_uint32(block->VolSessionId);
       unser_uint32(block->VolSessionTime);
-
       /* decrypt the block before to calculate the checksum */
-      if ((blkh_options & BLKHOPT_ENCRYPT_BLOCK) && block->dev->crypto_device_ctx)
+      if ((block->blkh_options & BLKHOPT_ENCRYPT_BLOCK) && block->dev->crypto_device_ctx)
       {
          block_cipher_init_iv_header(block->dev->crypto_device_ctx, BlockNumber, block->VolSessionId, block->VolSessionTime);
          block_cipher_decrypt(block->dev->crypto_device_ctx, block_len-bhl, block->buf+bhl, block->buf_enc);
index 5b1b8eb3d14d9e5aa04b5a2e0f2ab41abebc3ee3..9e3ab5dcb323b61e2afae484d04ba016284fa83c 100644 (file)
@@ -1194,7 +1194,7 @@ bool DEVICE::load_encryption_key(DCR *dcr, const char *operation,
    }
    /* don't use encryption if volume encryption is not enable or we are reading
     * (aka not recycling) a BB02 volume */
-   if (device->volume_encryption == ET_NONE || (op != op_label && VolHdr.BlockVer <= 2)) {
+   if (device->volume_encryption == ET_NONE || (op != op_label && !(VolHdr.blkh_options & BLKHOPT_ENCRYPT_VOL))) {
       return ok;
    }
    JCR *jcr = dcr->jcr;
index 06c843320da1787f11e0bad08e917f9c6e0da9aa..77412aaf92cad16034e92dc0bcdcd3025e06b06e 100644 (file)
@@ -1037,6 +1037,7 @@ bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec)
    dev->VolHdr.LabelType = rec->FileIndex;
    dev->VolHdr.LabelSize = rec->data_len;
    dev->VolHdr.BlockVer = rec->BlockVer;
+   dev->VolHdr.blkh_options = rec->blkh_options;
 
    /* Unserialize the record into the Volume Header */
    Dmsg2(100, "reclen=%d recdata=%s", rec->data_len, rec->data);
index dfb74ec3ec07bb614eb06b98c0091fe0b9cf2376..71da5620cddc0c7cf1ef7c5754f308cf0fc6a939 100644 (file)
@@ -121,7 +121,8 @@ struct DEV_RECORD {
    uint32_t extra_bytes;              /* the extra size that must be accounted in VolABytes */
    uint32_t state_bits;               /* state bits */
    uint32_t RecNum;                   /* Record number in the block */
-   int      BlockVer;                 /* 1, 2 or .. from BB01, BB02, ... */
+   int      BlockVer;                 /* from the block header: 1,2,3 from BB?? */
+   uint32_t blkh_options;             /* from the block header: about block encryption */
    uint32_t BlockNumber;              /* Block number for this record (used in read_records()) */
    bool     invalid;                  /* The record may be invalid if it was merged with a previous record */
    rec_state wstate;                  /* state of write_record_to_block */
@@ -173,6 +174,7 @@ struct Volume_Label {
 
   uint32_t VerNum;                    /* Label version number */
   int      BlockVer;                  /* 1, 2 or .. from BB01, BB02 from the FIRST block */
+  uint32_t blkh_options;              /* the block options bits from the FIRST block */
   /* VerNum <= 10 */
   float64_t label_date;               /* Date tape labeled */
   float64_t label_time;               /* Time tape labeled */
@@ -207,6 +209,7 @@ struct Volume_Label {
   uint64_t  MaxPartSize;              /* Maximum Part Size */
 
   /* For Volume encryption */
+  bool is_vol_encrypted;
   uint32_t EncCypherKeySize;
   uint32_t MasterKeyIdSize;
   unsigned char EncCypherKey[MAX_BLOCK_CIPHER_KEY_LEN]; /* The encryption key
index 0b925c9375cd9dd69a58a7113bf565ddb163ec90..96aac12fd4283a303256b9a602b42e4e155621c2 100644 (file)
@@ -253,6 +253,7 @@ bool read_record_from_block(DCR *dcr,  DEV_RECORD *rec)
       rec->Addr = rec->StartAddr = dcr->block->BlockAddr;
    }
    rec->BlockVer = dcr->block->BlockVer; /* needed for unser_volume_label() */
+   rec->blkh_options = dcr->block->blkh_options; /* needed for unser_volume_label() */
    /* We read the next record */
    dcr->block->RecNum++;