]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/block.h
1e126823db58c583fe8fe76dfd11637c688139c0
[bacula/bacula] / bacula / src / stored / block.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
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.
8
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.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * Block definitions for Bacula media data format.
21  *
22  *    Kern Sibbald, MM
23  */
24
25
26 #ifndef __BLOCK_H
27 #define __BLOCK_H 1
28
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 */
32
33 #define DEDUP_BLOCK_SIZE (512 * 128)    /* For now use a fixed dedup block size */
34
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 */
42
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))
46 #define BLOCK_VER               2
47
48 /* Record header definitions */
49 #define RECHDR1_LENGTH      20
50 /*
51  * Record header consists of:
52  *  int32_t FileIndex
53  *  int32_t Stream
54  *  uint32_t data_length
55  */
56 #define RECHDR2_LENGTH  (3*sizeof(int32_t))
57 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
58
59 /*
60  * An adata record header includes:
61  *  int32_t FileIndex
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)
66  */
67 #define WRITE_ADATA_RECHDR_LENGTH  (5*sizeof(int32_t))
68
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
75
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
80
81 #define BaculaDedupMetaDataId "Bacula 1.0 Dedup Metadata\n"
82 #define BaculaDedupMetaDataVersion    30000
83
84 #define BaculaS3CloudId "Bacula 1.0 S3 Cloud Data\n"
85 #define BaculaS3CloudVersion          40000
86
87 /*
88  * This is the Media structure for a block header
89  *  Note, when written, it is serialized.
90    16 bytes
91
92    uint32_t CheckSum;
93    uint32_t block_len;
94    uint32_t BlockNumber;
95    char     Id[BLKHDR_ID_LENGTH];
96
97  * for BB02 block, we have
98    24 bytes
99
100    uint32_t CheckSum;
101    uint32_t block_len;
102    uint32_t BlockNumber;
103    char     Id[BLKHDR_ID_LENGTH];
104    uint32_t VolSessionId;
105    uint32_t VolSessionTime;
106
107  * for an adata block header (in ameta file), we have
108    32 bytes
109
110    uint32_t BlockNumber;
111    int32_t  Stream;   STREAM_ADATA_BLOCK_HEADER
112    uint32_t block_len;
113    uint32_t CheckSum;
114    uint32_t VolSessionId;
115    uint32_t VolSessionTime;
116    uint64_t BlockAddr;
117
118  */
119
120 class DEVICE;                         /* for forward reference */
121
122 /*
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
127  * multiple blocks.
128  *
129  *  This is the memory structure for a device block.
130  */
131 struct DEV_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.
137     */
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 */
164 };
165
166 #define block_is_empty(block) ((block)->read_len == 0)
167
168 #endif