]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/block.h
Convert to pure GPL v2 license.
[bacula/bacula] / bacula / src / stored / block.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Block definitions for Bacula media data format.
30  *
31  *    Kern Sibbald, MM
32  *
33  *   Version $Id$
34  *
35  */
36
37
38 #ifndef __BLOCK_H
39 #define __BLOCK_H 1
40
41 #define MAX_BLOCK_LENGTH  (1024*1024 + 1) /* this is a sort of sanity check */
42 #define DEFAULT_BLOCK_SIZE (512 * 126)  /* 64,512 N.B. do not use 65,636 here */
43
44 /* Block Header definitions. */
45 #define BLKHDR1_ID       "BB01"
46 #define BLKHDR2_ID       "BB02"
47 #define BLKHDR_ID_LENGTH  4
48 #define BLKHDR_CS_LENGTH  4             /* checksum length */
49 #define BLKHDR1_LENGTH   16             /* Total length */
50 #define BLKHDR2_LENGTH   24             /* Total length */
51
52 #define WRITE_BLKHDR_ID     BLKHDR2_ID
53 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
54 #define BLOCK_VER               2
55
56 /* Record header definitions */
57 #define RECHDR1_LENGTH      20
58 #define RECHDR2_LENGTH      12
59 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
60
61 /* Tape label and version definitions */
62 #define BaculaId    "Bacula 1.0 immortal\n"
63 #define OldBaculaId "Bacula 0.9 mortal\n"
64 #define BaculaTapeVersion 11
65 #define OldCompatibleBaculaTapeVersion1  10
66 #define OldCompatibleBaculaTapeVersion2   9
67
68
69 /*
70  * This is the Media structure for a block header
71  *  Note, when written, it is serialized.
72
73    uint32_t CheckSum;
74    uint32_t block_len;
75    uint32_t BlockNumber;
76    char     Id[BLKHDR_ID_LENGTH];
77
78  * for BB02 block, we also have
79
80    uint32_t VolSessionId;
81    uint32_t VolSessionTime;
82  */
83
84 class DEVICE;                         /* for forward reference */
85
86 /*
87  * DEV_BLOCK for reading and writing blocks.
88  * This is the basic unit that is written to the device, and
89  * it contains a Block Header followd by Records.  Note,
90  * at times (when reading a file), this block may contain
91  * multiple blocks.
92  *
93  *  This is the memory structure for a device block.
94  */
95 struct DEV_BLOCK {
96    DEV_BLOCK *next;                   /* pointer to next one */
97    DEVICE *dev;                       /* pointer to device */
98    /* binbuf is the number of bytes remaining in the buffer.
99     *   For writes, it is bytes not yet written.
100     *   For reads, it is remaining bytes not yet read.
101     */
102    uint32_t binbuf;                   /* bytes in buffer */
103    uint32_t block_len;                /* length of current block read */
104    uint32_t buf_len;                  /* max/default block length */
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    int      BlockVer;                 /* block version 1 or 2 */
111    bool     write_failed;             /* set if write failed */
112    bool     block_read;               /* set when block read */
113    int32_t  FirstIndex;               /* first index this block */
114    int32_t  LastIndex;                /* last index this block */
115    char    *bufp;                     /* pointer into buffer */
116    POOLMEM *buf;                      /* actual data buffer */
117 };
118
119 #define block_is_empty(block) ((block)->read_len == 0)
120
121 #endif