/
record.h
296 lines (247 loc) · 9.95 KB
/
record.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Kern Sibbald, MM
*/
/**
* @file
* Record, and label definitions for Bareos media data format.
*/
#ifndef BAREOS_STORED_RECORD_H_
#define BAREOS_STORED_RECORD_H_ 1
#include "lib/dlist.h"
class dlist;
namespace storagedaemon {
/**
* Return codes from read_device_volume_label()
*/
enum
{
VOL_NOT_READ = 1, /**< Volume label not read */
VOL_OK, /**< volume name OK */
VOL_NO_LABEL, /**< volume not labeled */
VOL_IO_ERROR, /**< volume I/O error */
VOL_NAME_ERROR, /**< Volume name mismatch */
VOL_CREATE_ERROR, /**< Error creating label */
VOL_VERSION_ERROR, /**< Bareos version error */
VOL_LABEL_ERROR, /**< Bad label type */
VOL_NO_MEDIA /**< Hard error -- no media present */
};
enum rec_state
{
st_none, /**< No state */
st_header, /**< Write header */
st_header_cont,
st_data
};
/* See block.h for RECHDR_LENGTH */
/*
* This is the Media structure for a record header.
* NB: when it is written it is serialized.
uint32_t VolSessionId;
uint32_t VolSessionTime;
* The above 8 bytes are only written in a BB01 block, BB02
* and later blocks contain these values in the block header
* rather than the record header.
int32_t FileIndex;
int32_t Stream;
uint32_t data_len;
*/
/**
* Record state bit definitions
*/
enum
{
REC_NO_HEADER = 0, /**< No header read */
REC_PARTIAL_RECORD = 1, /**< Returning partial record */
REC_BLOCK_EMPTY = 2, /**< Not enough data in block */
REC_NO_MATCH = 3, /**< No match on continuation data */
REC_CONTINUATION = 4, /**< Continuation record found */
REC_ISTAPE = 5 /**< Set if device is tape */
};
/*
* Keep this set to the last entry in the enum.
*/
#define REC_STATE_MAX REC_ISTAPE
/*
* Make sure you have enough bits to store all above bit fields.
*/
#define REC_STATE_BYTES NbytesForBits(REC_STATE_MAX + 1)
#define IsPartialRecord(r) (BitIsSet(REC_PARTIAL_RECORD, (r)->state_bits))
#define IsBlockEmpty(r) (BitIsSet(REC_BLOCK_EMPTY, (r)->state_bits))
/*
* DeviceRecord for reading and writing records.
* It consists of a Record Header, and the Record Data
*
* This is the memory structure for the record header.
*/
struct BootStrapRecord; /* satisfy forward reference */
struct DeviceRecord {
dlink link; /**< link for chaining in read_record.c */
/**<
* File and Block are always returned during reading and writing records.
*/
uint32_t File{0}; /**< File number */
uint32_t Block{0}; /**< Block number */
uint32_t VolSessionId{0}; /**< Sequential id within this session */
uint32_t VolSessionTime{0}; /**< Session start time */
int32_t FileIndex{0}; /**< Sequential file number */
int32_t Stream{0}; /**< Full Stream number with high bits */
int32_t maskedStream{0}; /**< Masked Stream without high bits */
uint32_t data_len{0}; /**< Current record length */
uint32_t remainder{0}; /**< Remaining bytes to read/write */
char state_bits[REC_STATE_BYTES]{}; /**< State bits */
rec_state state{st_none}; /**< State of WriteRecordToBlock */
BootStrapRecord* bsr{nullptr}; /**< Pointer to bsr that matched */
POOLMEM* data{nullptr}; /**< Record data. This MUST be a memory pool item */
int32_t match_stat{0}; /**< BootStrapRecord match status */
uint32_t last_VolSessionId{0}; /**< Used in sequencing FI for Vbackup */
uint32_t last_VolSessionTime{0};
int32_t last_FileIndex{0};
int32_t last_Stream{0}; /**< Used in SD-SD replication */
bool own_mempool{false}; /**< Do we own the POOLMEM pointed to in data ? */
};
/*
* Values for LabelType that are put into the FileIndex field
* Note, these values are negative to distinguish them
* from user records where the FileIndex is forced positive.
*/
#define PRE_LABEL -1 /**< Vol label on unwritten tape */
#define VOL_LABEL -2 /**< Volume label first file */
#define EOM_LABEL -3 /**< Writen at end of tape */
#define SOS_LABEL -4 /**< Start of Session */
#define EOS_LABEL -5 /**< End of Session */
#define EOT_LABEL -6 /**< End of physical tape (2 eofs) */
#define SOB_LABEL -7 /**< Start of object -- file/directory */
#define EOB_LABEL -8 /**< End of object (after all streams) */
/*
* Volume Label Record. This is the in-memory definition. The
* tape definition is defined in the serialization code itself
* ser_volume_label() and UnserVolumeLabel() and is slightly different.
*/
struct Volume_Label {
/*
* The first items in this structure are saved
* in the Device buffer, but are not actually written
* to the tape.
*/
int32_t LabelType = 0; /**< This is written in header only */
uint32_t LabelSize = 0; /**< length of serialized label */
/*
* The items below this line are stored on
* the tape
*/
char Id[32]{0}; /**< Bareos Immortal ... */
uint32_t VerNum = 0; /**< Label version number */
/* VerNum <= 10 */
float64_t label_date = 0.0; /**< Date tape labeled */
float64_t label_time = 0.0; /**< Time tape labeled */
/* VerNum >= 11 */
btime_t label_btime = 0; /**< tdate tape labeled */
btime_t write_btime = 0; /**< tdate tape written */
/* Unused with VerNum >= 11 */
float64_t write_date = 0.0; /**< Date this label written */
float64_t write_time = 0.0; /**< Time this label written */
char VolumeName[MAX_NAME_LENGTH]{0}; /**< Volume name */
char PrevVolumeName[MAX_NAME_LENGTH]{0}; /**< Previous Volume Name */
char PoolName[MAX_NAME_LENGTH]{0}; /**< Pool name */
char PoolType[MAX_NAME_LENGTH]{0}; /**< Pool type */
char MediaType[MAX_NAME_LENGTH]{0}; /**< Type of this media */
char HostName[MAX_NAME_LENGTH]{0}; /**< Host name of writing computer */
char LabelProg[50]{0}; /**< Label program name */
char ProgVersion[50]{0}; /**< Program version */
char ProgDate[50]{0}; /**< Program build date/time */
};
#define SER_LENGTH_Volume_Label \
1024 /**< max serialised length of volume label */
#define SER_LENGTH_Session_Label \
1024 /**< max serialised length of session label */
typedef struct Volume_Label VOLUME_LABEL;
/**
* Session Start/End Label
* This record is at the beginning and end of each session
*/
struct Session_Label {
char Id[32]{0}; /**< Bareos Immortal ... */
uint32_t VerNum{0}; /**< Label version number */
uint32_t JobId{0}; /**< Job id */
uint32_t VolumeIndex{0}; /**< Sequence no of volume for this job */
/* VerNum >= 11 */
btime_t write_btime{0}; /**< Tdate this label written */
/* VerNum < 11 */
float64_t write_date = 0.0; /**< Date this label written */
/* Unused VerNum >= 11 */
float64_t write_time = 0.0; /**< Time this label written */
char PoolName[MAX_NAME_LENGTH]{0}; /**< Pool name */
char PoolType[MAX_NAME_LENGTH]{0}; /**< Pool type */
char JobName[MAX_NAME_LENGTH]{0}; /**< base Job name */
char ClientName[MAX_NAME_LENGTH]{0};
char Job[MAX_NAME_LENGTH]{0}; /**< Unique name of this Job */
char FileSetName[MAX_NAME_LENGTH]{0};
char FileSetMD5[MAX_NAME_LENGTH]{0};
uint32_t JobType{0};
uint32_t JobLevel{0};
/* The remainder are part of EOS label only */
uint32_t JobFiles{0};
uint64_t JobBytes{0};
uint32_t StartBlock{0};
uint32_t EndBlock{0};
uint32_t StartFile{0};
uint32_t EndFile{0};
uint32_t JobErrors{0};
uint32_t JobStatus{0}; /**< Job status */
};
typedef struct Session_Label SESSION_LABEL;
#define SERIAL_BUFSIZE 1024 /**< Volume serialisation buffer size */
/**
* Read context used to keep track of what is processed or not.
*/
struct Read_Context {
DeviceRecord* rec = nullptr; /**< Record currently being processed */
dlist* recs = nullptr; /**< Linked list of record packets open */
SESSION_LABEL sessrec; /**< Start Of Session record info */
uint32_t records_processed =
0; /**< Number of records processed from this block */
int32_t lastFileIndex = 0; /**< Last File Index processed */
};
struct DelayedDataStream {
int32_t stream = 0; /**< stream less new bits */
char* content = nullptr; /**< stream data */
uint32_t content_length = 0; /**< stream length */
};
#define READ_NO_FILEINDEX -999999
#include "lib/mem_pool.h"
class DeviceControlRecord; /* Forward Reference */
struct DeviceBlock; /* Forward Reference */
const char* FI_to_ascii(char* buf, int fi);
const char* stream_to_ascii(char* buf, int stream, int fi);
const char* record_to_str(PoolMem& resultbuffer,
JobControlRecord* jcr,
const DeviceRecord* rec);
void DumpRecord(const char* tag, const DeviceRecord* rec);
bool WriteRecordToBlock(DeviceControlRecord* dcr, DeviceRecord* rec);
bool CanWriteRecordToBlock(DeviceBlock* block, const DeviceRecord* rec);
bool ReadRecordFromBlock(DeviceControlRecord* dcr, DeviceRecord* rec);
DeviceRecord* new_record(bool with_data = true);
void EmptyRecord(DeviceRecord* rec);
void CopyRecordState(DeviceRecord* dst, DeviceRecord* src);
void FreeRecord(DeviceRecord* rec);
uint64_t GetRecordAddress(const DeviceRecord* rec);
} /* namespace storagedaemon */
#endif