]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/record.h
Big backport from Enterprise
[bacula/bacula] / bacula / src / stored / record.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many 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    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * Record, and label definitions for Bacula
21  *  media data format.
22  *
23  *   Kern Sibbald, MM
24  *
25  */
26
27
28 #ifndef __RECORD_H
29 #define __RECORD_H 1
30
31 /* Return codes from read_device_volume_label() */
32 enum {
33    VOL_NOT_READ      = 1,                 /* Volume label not read */
34    VOL_OK            = 2,                 /* volume name OK */
35    VOL_NO_LABEL      = 3,                 /* volume not labeled */
36    VOL_IO_ERROR      = 4,                 /* volume I/O error */
37    VOL_NAME_ERROR    = 5,                 /* Volume name mismatch */
38    VOL_CREATE_ERROR  = 6,                 /* Error creating label */
39    VOL_VERSION_ERROR = 7,                 /* Bacula version error */
40    VOL_LABEL_ERROR   = 8,                 /* Bad label type */
41    VOL_NO_MEDIA      = 9,                 /* Hard error -- no media present */
42    VOL_TYPE_ERROR    = 10                 /* Volume type (aligned/non-aligned) error */
43 };
44
45 enum rec_state {
46    st_none,                               /* No state */
47    st_header,                             /* Write header */
48    st_cont_header,                        /* Write continuation header */
49    st_data,                               /* Write data record */
50    st_adata_blkhdr,                       /* Adata block header */
51    st_adata_rechdr,                       /* Adata record header */
52    st_cont_adata_rechdr,                  /* Adata continuation rechdr */
53    st_adata,                              /* Write aligned data */
54    st_cont_adata,                         /* Write more aligned data */
55    st_adata_label                         /* Writing adata vol label */
56 };
57
58
59 /*  See block.h for RECHDR_LENGTH */
60
61 /*
62  * This is the Media structure for a record header.
63  *  NB: when it is written it is serialized.
64
65    uint32_t VolSessionId;
66    uint32_t VolSessionTime;
67
68  * The above 8 bytes are only written in a BB01 block, BB02
69  *  and later blocks contain these values in the block header
70  *  rather than the record header.
71
72    int32_t  FileIndex;
73    int32_t  Stream;
74    uint32_t data_len;
75
76  */
77
78 /* Record state bit definitions */
79 #define REC_NO_HEADER        (1<<0)   /* No header read */
80 #define REC_PARTIAL_RECORD   (1<<1)   /* returning partial record */
81 #define REC_BLOCK_EMPTY      (1<<2)   /* Not enough data in block */
82 #define REC_NO_MATCH         (1<<3)   /* No match on continuation data */
83 #define REC_CONTINUATION     (1<<4)   /* Continuation record found */
84 #define REC_ISTAPE           (1<<5)   /* Set if device is tape */
85 #define REC_ADATA_EMPTY      (1<<6)   /* Not endough adata in block */
86 #define REC_NO_SPLIT         (1<<7)   /* Do not split this record */
87
88 #define is_partial_record(r) ((r)->state_bits & REC_PARTIAL_RECORD)
89 #define is_block_marked_empty(r) ((r)->state_bits & (REC_BLOCK_EMPTY|REC_ADATA_EMPTY))
90
91 /*
92  * DEV_RECORD for reading and writing records.
93  * It consists of a Record Header, and the Record Data
94  *
95  *  This is the memory structure for the record header.
96  */
97 struct BSR;                           /* satisfy forward reference */
98 struct VOL_LIST;
99 struct DEV_RECORD {
100    dlink link;                        /* link for chaining in read_record.c */
101    /* File and Block are always returned during reading
102     *  and writing records.
103     */
104    uint64_t StreamLen;                /* Expected data stream length */
105    uint64_t FileOffset;               /* Offset of this record inside the file */
106    uint64_t StartAddr;                /* Start address (when the record is partial) */
107    uint64_t Addr;                     /* Record address */
108    uint32_t VolSessionId;             /* sequential id within this session */
109    uint32_t VolSessionTime;           /* session start time */
110    int32_t  FileIndex;                /* sequential file number */
111    int32_t  Stream;                   /* Full Stream number with high bits */
112    int32_t  last_FI;                  /* previous fi for adata */
113    int32_t  last_Stream;              /* previous stream for adata */
114    int32_t  maskedStream;             /* Masked Stream without high bits */
115    uint32_t data_len;                 /* current record length */
116    uint32_t remainder;                /* remaining bytes to read/write */
117    uint32_t adata_remainder;          /* remaining adata bytes to read/write */
118    uint32_t remlen;                   /* temp remainder bytes */
119    uint32_t data_bytes;               /* data_bytes */
120    uint32_t state_bits;               /* state bits */
121    uint32_t RecNum;                   /* Record number in the block */
122    uint32_t BlockNumber;              /* Block number for this record (used in read_records()) */
123    bool     invalid;                  /* The record may be invalid if it was merged with a previous record */
124    rec_state wstate;                  /* state of write_record_to_block */
125    rec_state rstate;                  /* state of read_record_from_block */
126    BSR *bsr;                          /* pointer to bsr that matched */
127    POOLMEM *data;                     /* Record data. This MUST be a memory pool item */
128    const char *VolumeName;            /* From JCR::VolList::VolumeName, freed at the end */
129    int32_t match_stat;                /* bsr match status */
130    uint32_t last_VolSessionId;        /* used in sequencing FI for Vbackup */
131    uint32_t last_VolSessionTime;
132    int32_t  last_FileIndex;
133 };
134
135
136 /*
137  * Values for LabelType that are put into the FileIndex field
138  * Note, these values are negative to distinguish them
139  * from user records where the FileIndex is forced positive.
140  */
141 #define PRE_LABEL   -1                /* Vol label on unwritten tape */
142 #define VOL_LABEL   -2                /* Volume label first file */
143 #define EOM_LABEL   -3                /* Writen at end of tape */
144 #define SOS_LABEL   -4                /* Start of Session */
145 #define EOS_LABEL   -5                /* End of Session */
146 #define EOT_LABEL   -6                /* End of physical tape (2 eofs) */
147 #define SOB_LABEL   -7                /* Start of object -- file/directory */
148 #define EOB_LABEL   -8                /* End of object (after all streams) */
149
150 /*
151  *   Volume Label Record.  This is the in-memory definition. The
152  *     tape definition is defined in the serialization code itself
153  *     ser_volume_label() and unser_volume_label() and is slightly different.
154  */
155
156
157 struct Volume_Label {
158   /*
159    * The first items in this structure are saved
160    * in the DEVICE buffer, but are not actually written
161    * to the tape.
162    */
163   int32_t LabelType;                  /* This is written in header only */
164   uint32_t LabelSize;                 /* length of serialized label */
165   /*
166    * The items below this line are stored on
167    * the tape
168    */
169   char Id[32];                        /* Bacula Immortal ... */
170
171   uint32_t VerNum;                    /* Label version number */
172
173   /* VerNum <= 10 */
174   float64_t label_date;               /* Date tape labeled */
175   float64_t label_time;               /* Time tape labeled */
176
177   /* VerNum >= 11 */
178   btime_t   label_btime;              /* tdate tape labeled */
179   btime_t   write_btime;              /* tdate tape written */
180
181   /* Unused with VerNum >= 11 */
182   float64_t write_date;               /* Date this label written */
183   float64_t write_time;               /* Time this label written */
184
185   char VolumeName[MAX_NAME_LENGTH];   /* Volume name */
186   char PrevVolumeName[MAX_NAME_LENGTH]; /* Previous Volume Name */
187   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
188   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
189   char MediaType[MAX_NAME_LENGTH];    /* Type of this media */
190
191   char HostName[MAX_NAME_LENGTH];     /* Host name of writing computer */
192   char LabelProg[50];                 /* Label program name */
193   char ProgVersion[50];               /* Program version */
194   char ProgDate[50];                  /* Program build date/time */
195
196   /* Mostly for aligned volumes, BlockSize also used for dedup volumes */
197   char AlignedVolumeName[MAX_NAME_LENGTH+4]; /* Aligned block volume name */
198   uint64_t  FirstData;                /* Offset to first data address */
199   uint32_t  FileAlignment;            /* File alignment factor */
200   uint32_t  PaddingSize;              /* Block padding */
201   uint32_t  BlockSize;                /* Basic block size */
202
203   /* For Cloud */
204   uint64_t  ChunkSize;                /* Basic chunk size */
205
206 };
207
208 #define SER_LENGTH_Volume_Label 1024   /* max serialised length of volume label */
209 #define SER_LENGTH_Session_Label 1024  /* max serialised length of session label */
210
211 typedef struct Volume_Label VOLUME_LABEL;
212
213 /*
214  * Session Start/End Label
215  *  This record is at the beginning and end of each session
216  */
217 struct Session_Label {
218   char Id[32];                        /* Bacula Immortal ... */
219
220   uint32_t VerNum;                    /* Label version number */
221
222   uint32_t JobId;                     /* Job id */
223   uint32_t VolumeIndex;               /* Sequence no of volume for this job */
224
225   /* VerNum >= 11 */
226   btime_t   write_btime;              /* Tdate this label written */
227
228   /* VerNum < 11 */
229   float64_t write_date;               /* Date this label written */
230
231   /* Unused VerNum >= 11 */
232   float64_t write_time;               /* Time this label written */
233
234   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
235   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
236   char JobName[MAX_NAME_LENGTH];      /* base Job name */
237   char ClientName[MAX_NAME_LENGTH];
238   char Job[MAX_NAME_LENGTH];          /* Unique name of this Job */
239   char FileSetName[MAX_NAME_LENGTH];
240   char FileSetMD5[MAX_NAME_LENGTH];
241   uint32_t JobType;
242   uint32_t JobLevel;
243   /* The remainder are part of EOS label only */
244   uint32_t JobFiles;
245   uint64_t JobBytes;
246   uint32_t StartBlock;
247   uint32_t EndBlock;
248   uint32_t StartFile;
249   uint32_t EndFile;
250   uint32_t JobErrors;
251   uint32_t JobStatus;                 /* Job status */
252
253 };
254 typedef struct Session_Label SESSION_LABEL;
255
256 #define SERIAL_BUFSIZE  1024          /* volume serialisation buffer size */
257
258 #endif