2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
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.
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.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Record, and label definitions for Bacula
32 /* Return codes from read_device_volume_label() */
34 VOL_NOT_READ = 1, /* Volume label not read */
35 VOL_OK, /* volume name OK */
36 VOL_NO_LABEL, /* volume not labeled */
37 VOL_IO_ERROR, /* volume I/O error */
38 VOL_NAME_ERROR, /* Volume name mismatch */
39 VOL_CREATE_ERROR, /* Error creating label */
40 VOL_VERSION_ERROR, /* Bacula version error */
41 VOL_LABEL_ERROR, /* Bad label type */
42 VOL_NO_MEDIA, /* Hard error -- no media present */
43 VOL_TYPE_ERROR /* Volume type (aligned/non-aligned) error */
47 st_none, /* No state */
48 st_header, /* Write header */
49 st_cont_header, /* Write continuation header */
50 st_data /* Write data record */
54 /* See block.h for RECHDR_LENGTH */
57 * This is the Media structure for a record header.
58 * NB: when it is written it is serialized.
60 uint32_t VolSessionId;
61 uint32_t VolSessionTime;
63 * The above 8 bytes are only written in a BB01 block, BB02
64 * and later blocks contain these values in the block header
65 * rather than the record header.
73 /* Record state bit definitions */
74 #define REC_NO_HEADER (1<<0) /* No header read */
75 #define REC_PARTIAL_RECORD (1<<1) /* returning partial record */
76 #define REC_BLOCK_EMPTY (1<<2) /* Not enough data in block */
77 #define REC_NO_MATCH (1<<3) /* No match on continuation data */
78 #define REC_CONTINUATION (1<<4) /* Continuation record found */
79 #define REC_ISTAPE (1<<5) /* Set if device is tape */
81 #define is_partial_record(r) ((r)->state_bits & REC_PARTIAL_RECORD)
82 #define is_block_marked_empty(r) ((r)->state_bits & (REC_BLOCK_EMPTY))
85 * DEV_RECORD for reading and writing records.
86 * It consists of a Record Header, and the Record Data
88 * This is the memory structure for the record header.
90 struct BSR; /* satisfy forward reference */
92 dlink link; /* link for chaining in read_record.c */
93 /* File and Block are always returned during reading
94 * and writing records.
96 uint64_t StreamLen; /* Expected data stream length */
97 uint32_t File; /* File number */
98 uint32_t Block; /* Block number */
99 uint32_t VolSessionId; /* sequential id within this session */
100 uint32_t VolSessionTime; /* session start time */
101 int32_t FileIndex; /* sequential file number */
102 int32_t Stream; /* Full Stream number with high bits */
103 int32_t last_FI; /* previous fi for adata */
104 int32_t last_Stream; /* previous stream for adata */
105 int32_t maskedStream; /* Masked Stream without high bits */
106 uint32_t data_len; /* current record length */
107 uint32_t remainder; /* remaining bytes to read/write */
108 uint32_t adata_remainder; /* remaining adata bytes to read/write */
109 uint32_t remlen; /* temp remainder bytes */
110 uint32_t data_bytes; /* data_bytes */
111 uint32_t state_bits; /* state bits */
112 rec_state wstate; /* state of write_record_to_block */
113 rec_state rstate; /* state of read_record_from_block */
114 BSR *bsr; /* pointer to bsr that matched */
115 POOLMEM *data; /* Record data. This MUST be a memory pool item */
116 int32_t match_stat; /* bsr match status */
117 uint32_t last_VolSessionId; /* used in sequencing FI for Vbackup */
118 uint32_t last_VolSessionTime;
119 int32_t last_FileIndex;
124 * Values for LabelType that are put into the FileIndex field
125 * Note, these values are negative to distinguish them
126 * from user records where the FileIndex is forced positive.
128 #define PRE_LABEL -1 /* Vol label on unwritten tape */
129 #define VOL_LABEL -2 /* Volume label first file */
130 #define EOM_LABEL -3 /* Writen at end of tape */
131 #define SOS_LABEL -4 /* Start of Session */
132 #define EOS_LABEL -5 /* End of Session */
133 #define EOT_LABEL -6 /* End of physical tape (2 eofs) */
134 #define SOB_LABEL -7 /* Start of object -- file/directory */
135 #define EOB_LABEL -8 /* End of object (after all streams) */
138 * Volume Label Record. This is the in-memory definition. The
139 * tape definition is defined in the serialization code itself
140 * ser_volume_label() and unser_volume_label() and is slightly different.
144 struct Volume_Label {
146 * The first items in this structure are saved
147 * in the DEVICE buffer, but are not actually written
150 int32_t LabelType; /* This is written in header only */
151 uint32_t LabelSize; /* length of serialized label */
153 * The items below this line are stored on
156 char Id[32]; /* Bacula Immortal ... */
158 uint32_t VerNum; /* Label version number */
161 float64_t label_date; /* Date tape labeled */
162 float64_t label_time; /* Time tape labeled */
165 btime_t label_btime; /* tdate tape labeled */
166 btime_t write_btime; /* tdate tape written */
168 /* Unused with VerNum >= 11 */
169 float64_t write_date; /* Date this label written */
170 float64_t write_time; /* Time this label written */
172 char VolumeName[MAX_NAME_LENGTH]; /* Volume name */
173 char PrevVolumeName[MAX_NAME_LENGTH]; /* Previous Volume Name */
174 char PoolName[MAX_NAME_LENGTH]; /* Pool name */
175 char PoolType[MAX_NAME_LENGTH]; /* Pool type */
176 char MediaType[MAX_NAME_LENGTH]; /* Type of this media */
178 char HostName[MAX_NAME_LENGTH]; /* Host name of writing computer */
179 char LabelProg[50]; /* Label program name */
180 char ProgVersion[50]; /* Program version */
181 char ProgDate[50]; /* Program build date/time */
184 #define SER_LENGTH_Volume_Label 1024 /* max serialised length of volume label */
185 #define SER_LENGTH_Session_Label 1024 /* max serialised length of session label */
187 typedef struct Volume_Label VOLUME_LABEL;
190 * Session Start/End Label
191 * This record is at the beginning and end of each session
193 struct Session_Label {
194 char Id[32]; /* Bacula Immortal ... */
196 uint32_t VerNum; /* Label version number */
198 uint32_t JobId; /* Job id */
199 uint32_t VolumeIndex; /* Sequence no of volume for this job */
202 btime_t write_btime; /* Tdate this label written */
205 float64_t write_date; /* Date this label written */
207 /* Unused VerNum >= 11 */
208 float64_t write_time; /* Time this label written */
210 char PoolName[MAX_NAME_LENGTH]; /* Pool name */
211 char PoolType[MAX_NAME_LENGTH]; /* Pool type */
212 char JobName[MAX_NAME_LENGTH]; /* base Job name */
213 char ClientName[MAX_NAME_LENGTH];
214 char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */
215 char FileSetName[MAX_NAME_LENGTH];
216 char FileSetMD5[MAX_NAME_LENGTH];
219 /* The remainder are part of EOS label only */
227 uint32_t JobStatus; /* Job status */
230 typedef struct Session_Label SESSION_LABEL;
232 #define SERIAL_BUFSIZE 1024 /* volume serialisation buffer size */