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