]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/block.h
2217662205b29dd9bd77097ac5cac4445d2ec40c
[bacula/bacula] / bacula / src / stored / block.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 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
27 #ifndef __BLOCK_H
28 #define __BLOCK_H 1
29
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 */
32
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 */
40
41 #define WRITE_BLKHDR_ID     BLKHDR2_ID
42 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
43 #define BLOCK_VER               2
44
45 /* Record header definitions */
46 #define RECHDR1_LENGTH      20
47 /*
48  * Record header consists of:
49  *  int32_t FileIndex
50  *  int32_t Stream
51  *  uint32_t data_length
52  */
53 #define RECHDR2_LENGTH  (3*sizeof(int32_t))
54 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
55
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
62
63 /*
64  * This is the Media structure for a block header
65  *  Note, when written, it is serialized.
66    16 bytes
67
68    uint32_t CheckSum;
69    uint32_t block_len;
70    uint32_t BlockNumber;
71    char     Id[BLKHDR_ID_LENGTH];
72
73  * for BB02 block, we have
74    24 bytes
75
76    uint32_t CheckSum;
77    uint32_t block_len;
78    uint32_t BlockNumber;
79    char     Id[BLKHDR_ID_LENGTH];
80    uint32_t VolSessionId;
81    uint32_t VolSessionTime;
82
83  */
84
85 class DEVICE;                         /* for forward reference */
86
87 /*
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
92  * multiple blocks.
93  *
94  *  This is the memory structure for a device block.
95  */
96 struct DEV_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.
102     */
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 */
130 };
131
132 #define block_is_empty(block) ((block)->read_len == 0)
133
134 #endif