1 /*
2 BAREOS® - Backup Archiving REcovery Open Sourced
3
4 Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
5 Copyright (C) 2016-2016 Bareos GmbH & Co. KG
6
7 This program is Free Software; you can redistribute it and/or
8 modify it under the terms of version three of the GNU Affero General Public
9 License as published by the Free Software Foundation and included
10 in the file LICENSE.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Affero General Public License for more details.
16
17 You should have received a copy of the GNU Affero General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.
21 */
22 /*
23 * Kern Sibbald, MM
24 */
25 /**
26 * @file
27 * Block definitions for Bareos media data format.
28 */
29 #ifndef BAREOS_STORED_BLOCK_H_
30 #define BAREOS_STORED_BLOCK_H_ 1
31
32 namespace storagedaemon {
33
34 class Device; /* for forward reference */
35
36 #define MAX_BLOCK_LENGTH 20000000 /**< this is a sort of sanity check */
37 #define DEFAULT_BLOCK_SIZE \
38 (512 * 126) /**< 64,512 N.B. do not use 65,536 here \
39 the POSIX standard defaults the size of a \
40 tape record to 126 blocks (63k). */
41
42 /* Block Header definitions. */
43 #define BLKHDR1_ID "BB01"
44 #define BLKHDR2_ID "BB02"
45 #define BLKHDR_ID_LENGTH 4
46 #define BLKHDR_CS_LENGTH 4 /**< checksum length */
47 #define BLKHDR1_LENGTH 16 /**< Total length */
48 #define BLKHDR2_LENGTH 24 /**< Total length */
49
50 #define WRITE_BLKHDR_ID BLKHDR2_ID
51 #define WRITE_BLKHDR_LENGTH BLKHDR2_LENGTH
52 #define BLOCK_VER 2
53
54 /* Record header definitions */
55 #define RECHDR1_LENGTH 20
56 #define RECHDR2_LENGTH 12
57 #define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
58
59 /* Tape label and version definitions */
60 #define BareosId "Bareos 2.0 immortal\n"
61 #define OldBaculaId "Bacula 1.0 immortal\n"
62 #define OlderBaculaId "Bacula 0.9 mortal\n"
63 #define BareosTapeVersion 20
64 #define OldCompatibleBareosTapeVersion1 11
65 #define OldCompatibleBareosTapeVersion2 10
66 #define OldCompatibleBareosTapeVersion3 9
67
68 /**
69 * This is the Media structure for a block header
70 * Note, when written, it is serialized.
71
72 uint32_t CheckSum;
73 uint32_t block_len;
74 uint32_t BlockNumber;
75 char Id[BLKHDR_ID_LENGTH];
76
77 * for BB02 block, we also have
78
79 uint32_t VolSessionId;
80 uint32_t VolSessionTime;
81 */
82
83 /**
84 * DeviceBlock for reading and writing blocks.
85 * This is the basic unit that is written to the device, and
86 * it contains a Block Header followd by Records. Note,
87 * at times (when reading a file), this block may contain
88 * multiple blocks.
89 *
90 * This is the memory structure for a device block.
91 */
92 struct DeviceBlock {
93 DeviceBlock* next; /* pointer to next one */
94 Device* dev; /* pointer to device */
95 /* binbuf is the number of bytes remaining in the buffer.
96 * For writes, it is bytes not yet written.
97 * For reads, it is remaining bytes not yet read.
98 */
99 uint32_t binbuf; /* bytes in buffer */
100 uint32_t block_len; /* length of current block read */
101 uint32_t buf_len; /* max/default block length */
102 uint32_t BlockNumber; /* sequential Bareos block number */
103 uint32_t read_len; /* bytes read into buffer, if zero, block empty */
104 uint32_t VolSessionId; /* */
105 uint32_t VolSessionTime; /* */
106 uint32_t read_errors; /* block errors (checksum, header, ...) */
107 int BlockVer; /* block version 1 or 2 */
108 bool write_failed; /* set if write failed */
109 bool block_read; /* set when block read */
110 int32_t FirstIndex; /* first index this block */
111 int32_t LastIndex; /* last index this block */
112 char* bufp; /* pointer into buffer */
113 POOLMEM* buf; /* actual data buffer */
114 };
115
BlockWriteNavail(DeviceBlock * block)116 inline uint32_t BlockWriteNavail(DeviceBlock* block)
117 {
118 return ((block)->buf_len - (block)->binbuf);
119 }
120
block_is_empty(DeviceBlock * block)121 inline bool block_is_empty(DeviceBlock* block)
122 {
123 return ((block)->read_len == 0);
124 }
125
126 void DumpBlock(DeviceBlock* b, const char* msg);
127 DeviceBlock* new_block(Device* dev);
128 DeviceBlock* dup_block(DeviceBlock* eblock);
129 void InitBlockWrite(DeviceBlock* block);
130 void EmptyBlock(DeviceBlock* block);
131 void FreeBlock(DeviceBlock* block);
132 void PrintBlockReadErrors(JobControlRecord* jcr, DeviceBlock* block);
133 void SerBlockHeader(DeviceBlock* block);
134
135 } /* namespace storagedaemon */
136
137 #endif
138