]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/record.h
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / stored / record.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6
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.
9
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.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Record, and label definitions for Bacula
22  *  media data format.
23  *
24  *   Kern Sibbald, MM
25  *
26  */
27
28
29 #ifndef __RECORD_H
30 #define __RECORD_H 1
31
32 /* Return codes from read_device_volume_label() */
33 enum {
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 */
44 };
45
46 enum rec_state {
47    st_none,                               /* No state */
48    st_header,                             /* Write header */
49    st_cont_header,                        /* Write continuation header */
50    st_data                                /* Write data record */
51 };
52
53
54 /*  See block.h for RECHDR_LENGTH */
55
56 /*
57  * This is the Media structure for a record header.
58  *  NB: when it is written it is serialized.
59
60    uint32_t VolSessionId;
61    uint32_t VolSessionTime;
62
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.
66
67    int32_t  FileIndex;
68    int32_t  Stream;
69    uint32_t data_len;
70
71  */
72
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 */
80
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))
83
84 /*
85  * DEV_RECORD for reading and writing records.
86  * It consists of a Record Header, and the Record Data
87  *
88  *  This is the memory structure for the record header.
89  */
90 struct BSR;                           /* satisfy forward reference */
91 struct DEV_RECORD {
92    dlink link;                        /* link for chaining in read_record.c */
93    /* File and Block are always returned during reading
94     *  and writing records.
95     */
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;
120 };
121
122
123 /*
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.
127  */
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) */
136
137 /*
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.
141  */
142
143
144 struct Volume_Label {
145   /*
146    * The first items in this structure are saved
147    * in the DEVICE buffer, but are not actually written
148    * to the tape.
149    */
150   int32_t LabelType;                  /* This is written in header only */
151   uint32_t LabelSize;                 /* length of serialized label */
152   /*
153    * The items below this line are stored on
154    * the tape
155    */
156   char Id[32];                        /* Bacula Immortal ... */
157
158   uint32_t VerNum;                    /* Label version number */
159
160   /* VerNum <= 10 */
161   float64_t label_date;               /* Date tape labeled */
162   float64_t label_time;               /* Time tape labeled */
163
164   /* VerNum >= 11 */
165   btime_t   label_btime;              /* tdate tape labeled */
166   btime_t   write_btime;              /* tdate tape written */
167
168   /* Unused with VerNum >= 11 */
169   float64_t write_date;               /* Date this label written */
170   float64_t write_time;               /* Time this label written */
171
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 */
177
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 */
182 };
183
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 */
186
187 typedef struct Volume_Label VOLUME_LABEL;
188
189 /*
190  * Session Start/End Label
191  *  This record is at the beginning and end of each session
192  */
193 struct Session_Label {
194   char Id[32];                        /* Bacula Immortal ... */
195
196   uint32_t VerNum;                    /* Label version number */
197
198   uint32_t JobId;                     /* Job id */
199   uint32_t VolumeIndex;               /* Sequence no of volume for this job */
200
201   /* VerNum >= 11 */
202   btime_t   write_btime;              /* Tdate this label written */
203
204   /* VerNum < 11 */
205   float64_t write_date;               /* Date this label written */
206
207   /* Unused VerNum >= 11 */
208   float64_t write_time;               /* Time this label written */
209
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];
217   uint32_t JobType;
218   uint32_t JobLevel;
219   /* The remainder are part of EOS label only */
220   uint32_t JobFiles;
221   uint64_t JobBytes;
222   uint32_t StartBlock;
223   uint32_t EndBlock;
224   uint32_t StartFile;
225   uint32_t EndFile;
226   uint32_t JobErrors;
227   uint32_t JobStatus;                 /* Job status */
228
229 };
230 typedef struct Session_Label SESSION_LABEL;
231
232 #define SERIAL_BUFSIZE  1024          /* volume serialisation buffer size */
233
234 #endif