]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/block.h
a8552b0defa4cd9deeb8b49c4ddf10b5a3953155
[bacula/bacula] / bacula / src / stored / block.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Block definitions for Bacula media data format.
22  *
23  *    Kern Sibbald, MM
24  *
25  */
26
27
28 #ifndef __BLOCK_H
29 #define __BLOCK_H 1
30
31 #define MAX_BLOCK_LENGTH  20000000      /* this is a sort of sanity check */
32 #define DEFAULT_BLOCK_SIZE (512 * 126)  /* 64,512 N.B. do not use 65,636 here */
33
34 /* Block Header definitions. */
35 #define BLKHDR1_ID       "BB01"
36 #define BLKHDR2_ID       "BB02"
37 #define BLKHDR_ID_LENGTH  4
38 #define BLKHDR_CS_LENGTH  4             /* checksum length */
39 #define BLKHDR1_LENGTH   16             /* Total length */
40 #define BLKHDR2_LENGTH   24             /* Total length */
41
42 #define WRITE_BLKHDR_ID     BLKHDR2_ID
43 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
44 #define BLOCK_VER               2
45
46 /* Record header definitions */
47 #define RECHDR1_LENGTH      20
48 /*
49  * Record header consists of:
50  *  int32_t FileIndex
51  *  int32_t Stream
52  *  uint32_t data_length
53  */
54 #define RECHDR2_LENGTH  (3*sizeof(int32_t))
55 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
56
57 /* Tape label and version definitions */
58 #define BaculaId         "Bacula 1.0 immortal\n"
59 #define OldBaculaId      "Bacula 0.9 mortal\n"
60 #define BaculaTapeVersion                11
61 #define OldCompatibleBaculaTapeVersion1  10
62 #define OldCompatibleBaculaTapeVersion2   9
63
64 /*
65  * This is the Media structure for a block header
66  *  Note, when written, it is serialized.
67    16 bytes
68
69    uint32_t CheckSum;
70    uint32_t block_len;
71    uint32_t BlockNumber;
72    char     Id[BLKHDR_ID_LENGTH];
73
74  * for BB02 block, we have
75    24 bytes
76
77    uint32_t CheckSum;
78    uint32_t block_len;
79    uint32_t BlockNumber;
80    char     Id[BLKHDR_ID_LENGTH];
81    uint32_t VolSessionId;
82    uint32_t VolSessionTime;
83
84  */
85
86 class DEVICE;                         /* for forward reference */
87
88 /*
89  * DEV_BLOCK for reading and writing blocks.
90  * This is the basic unit that is written to the device, and
91  * it contains a Block Header followd by Records.  Note,
92  * at times (when reading a file), this block may contain
93  * multiple blocks.
94  *
95  *  This is the memory structure for a device block.
96  */
97 struct DEV_BLOCK {
98    DEV_BLOCK *next;                   /* pointer to next one */
99    DEVICE    *dev;                    /* pointer to device */
100    /* binbuf is the number of bytes remaining in the buffer.
101     *   For writes, it is bytes not yet written.
102     *   For reads, it is remaining bytes not yet read.
103     */
104    uint64_t BlockAddr;                /* Block address */
105    uint32_t File;                     /* Block address on volume */
106    uint32_t Block;                    /* Block address on volume */
107    uint32_t binbuf;                   /* bytes in buffer */
108    uint32_t block_len;                /* length of current block read */
109    uint32_t buf_len;                  /* max/default block length */
110    uint32_t reclen;                   /* Last record length put in block */
111    uint32_t BlockNumber;              /* sequential Bacula block number */
112    uint32_t read_len;                 /* bytes read into buffer, if zero, block empty */
113    uint32_t VolSessionId;             /* */
114    uint32_t VolSessionTime;           /* */
115    uint32_t read_errors;              /* block errors (checksum, header, ...) */
116    uint32_t CheckSum;                 /* Block checksum */
117    uint32_t RecNum;                   /* Number of records read from the current block */
118    int      BlockVer;                 /* block version 1 or 2 */
119    bool     write_failed;             /* set if write failed */
120    bool     block_read;               /* set when block read */
121    bool     needs_write;              /* block must be written */
122    bool     adata;                    /* adata block */
123    bool     no_header;                /* Set if no block header */
124    bool     new_fi;                   /* New FI arrived */
125    int32_t  FirstIndex;               /* first index this block */
126    int32_t  LastIndex;                /* last index this block */
127    int32_t  rechdr_items;             /* number of items in rechdr queue */
128    char    *bufp;                     /* pointer into buffer */
129    char     ser_buf[BLKHDR2_LENGTH];  /* Serial buffer for data */
130    POOLMEM *buf;                      /* actual data buffer */
131 };
132
133 #define block_is_empty(block) ((block)->read_len == 0)
134
135 #endif