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