2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Block definitions for Bacula media data format.
29 #define MAX_BLOCK_LENGTH 20000000 /* this is a sort of sanity check */
30 #define DEFAULT_BLOCK_SIZE (512 * 126) /* 64,512 N.B. do not use 65,636 here */
31 #define MIN_DEDUP_BLOCK_SIZE (512 * 2) /* Minimum block (bucket) size */
33 #define DEDUP_BLOCK_SIZE (512 * 128) /* For now use a fixed dedup block size */
35 /* Block Header definitions. */
36 #define BLKHDR1_ID "BB01"
37 #define BLKHDR2_ID "BB02"
38 #define BLKHDR_ID_LENGTH 4
39 #define BLKHDR_CS_LENGTH 4 /* checksum length */
40 #define BLKHDR1_LENGTH 16 /* Total length */
41 #define BLKHDR2_LENGTH 24 /* Total length */
43 #define WRITE_BLKHDR_ID BLKHDR2_ID
44 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
45 #define WRITE_ADATA_BLKHDR_LENGTH (6*sizeof(int32_t)+sizeof(uint64_t))
48 /* Record header definitions */
49 #define RECHDR1_LENGTH 20
51 * Record header consists of:
54 * uint32_t data_length
56 #define RECHDR2_LENGTH (3*sizeof(int32_t))
57 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
60 * An adata record header includes:
62 * int32_t Stream STREAM_ADATA_RECORD_HEADER
63 * uint32_t data_length
64 * uint32_t block length (binbuf to that point in time)
65 * int32_t Stream (original stream)
67 #define WRITE_ADATA_RECHDR_LENGTH (5*sizeof(int32_t))
69 /* Tape label and version definitions */
70 #define BaculaId "Bacula 1.0 immortal\n"
71 #define OldBaculaId "Bacula 0.9 mortal\n"
72 #define BaculaTapeVersion 11
73 #define OldCompatibleBaculaTapeVersion1 10
74 #define OldCompatibleBaculaTapeVersion2 9
76 #define BaculaMetaDataId "Bacula 1.0 Metadata\n"
77 #define BaculaAlignedDataId "Bacula 1.0 Aligned Data\n"
78 #define BaculaMetaDataVersion 10000
79 #define BaculaAlignedDataVersion 20000
81 #define BaculaDedupMetaDataId "Bacula 1.0 Dedup Metadata\n"
82 #define BaculaDedupMetaDataVersion 30000
84 #define BaculaS3CloudId "Bacula 1.0 S3 Cloud Data\n"
85 #define BaculaS3CloudVersion 40000
88 * This is the Media structure for a block header
89 * Note, when written, it is serialized.
95 char Id[BLKHDR_ID_LENGTH];
97 * for BB02 block, we have
102 uint32_t BlockNumber;
103 char Id[BLKHDR_ID_LENGTH];
104 uint32_t VolSessionId;
105 uint32_t VolSessionTime;
107 * for an adata block header (in ameta file), we have
110 uint32_t BlockNumber;
111 int32_t Stream; STREAM_ADATA_BLOCK_HEADER
114 uint32_t VolSessionId;
115 uint32_t VolSessionTime;
120 class DEVICE; /* for forward reference */
123 * DEV_BLOCK for reading and writing blocks.
124 * This is the basic unit that is written to the device, and
125 * it contains a Block Header followd by Records. Note,
126 * at times (when reading a file), this block may contain
129 * This is the memory structure for a device block.
132 DEV_BLOCK *next; /* pointer to next one */
133 DEVICE *dev; /* pointer to device */
134 /* binbuf is the number of bytes remaining in the buffer.
135 * For writes, it is bytes not yet written.
136 * For reads, it is remaining bytes not yet read.
138 uint64_t BlockAddr; /* Block address */
139 uint32_t binbuf; /* bytes in buffer */
140 uint32_t block_len; /* length of current block read */
141 uint32_t buf_len; /* max/default block length */
142 uint32_t reclen; /* Last record length put in adata block */
143 uint32_t BlockNumber; /* sequential Bacula block number */
144 uint32_t read_len; /* bytes read into buffer, if zero, block empty */
145 uint32_t VolSessionId; /* */
146 uint32_t VolSessionTime; /* */
147 uint32_t read_errors; /* block errors (checksum, header, ...) */
148 uint32_t CheckSum; /* Block checksum */
149 uint32_t RecNum; /* Number of records read from the current block */
150 int BlockVer; /* block version 1 or 2 */
151 bool write_failed; /* set if write failed */
152 bool block_read; /* set when block read */
153 bool needs_write; /* block must be written */
154 bool adata; /* adata block */
155 bool no_header; /* Set if no block header */
156 bool new_fi; /* New FI arrived */
157 int32_t FirstIndex; /* first index this block */
158 int32_t LastIndex; /* last index this block */
159 int32_t rechdr_items; /* number of items in rechdr queue */
160 char *bufp; /* pointer into buffer */
161 char ser_buf[BLKHDR2_LENGTH]; /* Serial buffer for adata */
162 POOLMEM *rechdr_queue; /* record header queue */
163 POOLMEM *buf; /* actual data buffer */
166 #define block_is_empty(block) ((block)->read_len == 0)