2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 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.
30 #define MAX_BLOCK_LENGTH 20000000 /* this is a sort of sanity check */
31 #define DEFAULT_BLOCK_SIZE (512 * 126) /* 64,512 N.B. do not use 65,636 here */
33 /* Block Header definitions. */
34 #define BLKHDR1_ID "BB01"
35 #define BLKHDR2_ID "BB02"
36 #define BLKHDR_ID_LENGTH 4
37 #define BLKHDR_CS_LENGTH 4 /* checksum length */
38 #define BLKHDR1_LENGTH 16 /* Total length */
39 #define BLKHDR2_LENGTH 24 /* Total length */
41 #define WRITE_BLKHDR_ID BLKHDR2_ID
42 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
45 /* Record header definitions */
46 #define RECHDR1_LENGTH 20
48 * Record header consists of:
51 * uint32_t data_length
53 #define RECHDR2_LENGTH (3*sizeof(int32_t))
54 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
56 /* Tape label and version definitions */
57 #define BaculaId "Bacula 1.0 immortal\n"
58 #define OldBaculaId "Bacula 0.9 mortal\n"
59 #define BaculaTapeVersion 11
60 #define OldCompatibleBaculaTapeVersion1 10
61 #define OldCompatibleBaculaTapeVersion2 9
64 * This is the Media structure for a block header
65 * Note, when written, it is serialized.
71 char Id[BLKHDR_ID_LENGTH];
73 * for BB02 block, we have
79 char Id[BLKHDR_ID_LENGTH];
80 uint32_t VolSessionId;
81 uint32_t VolSessionTime;
85 class DEVICE; /* for forward reference */
88 * DEV_BLOCK for reading and writing blocks.
89 * This is the basic unit that is written to the device, and
90 * it contains a Block Header followd by Records. Note,
91 * at times (when reading a file), this block may contain
94 * This is the memory structure for a device block.
97 DEV_BLOCK *next; /* pointer to next one */
98 DEVICE *dev; /* pointer to device */
99 /* binbuf is the number of bytes remaining in the buffer.
100 * For writes, it is bytes not yet written.
101 * For reads, it is remaining bytes not yet read.
103 uint64_t BlockAddr; /* Block address */
104 uint32_t File; /* Block address on volume */
105 uint32_t Block; /* Block address on volume */
106 uint32_t binbuf; /* bytes in buffer */
107 uint32_t block_len; /* length of current block read */
108 uint32_t buf_len; /* max/default block length */
109 uint32_t reclen; /* Last record length put in block */
110 uint32_t BlockNumber; /* sequential Bacula block number */
111 uint32_t read_len; /* bytes read into buffer, if zero, block empty */
112 uint32_t VolSessionId; /* */
113 uint32_t VolSessionTime; /* */
114 uint32_t read_errors; /* block errors (checksum, header, ...) */
115 uint32_t CheckSum; /* Block checksum */
116 uint32_t RecNum; /* Number of records read from the current block */
117 int BlockVer; /* block version 1 or 2 */
118 bool write_failed; /* set if write failed */
119 bool block_read; /* set when block read */
120 bool needs_write; /* block must be written */
121 bool adata; /* adata block */
122 bool no_header; /* Set if no block header */
123 bool new_fi; /* New FI arrived */
124 int32_t FirstIndex; /* first index this block */
125 int32_t LastIndex; /* last index this block */
126 int32_t rechdr_items; /* number of items in rechdr queue */
127 char *bufp; /* pointer into buffer */
128 char ser_buf[BLKHDR2_LENGTH]; /* Serial buffer for data */
129 POOLMEM *buf; /* actual data buffer */
132 #define block_is_empty(block) ((block)->read_len == 0)