]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/record.h
kes Merge patch from Sergey Svishchev <svs@ropnet.ru> that preserves
[bacula/bacula] / bacula / src / stored / record.h
1 /*
2  * Record, and label definitions for Bacula
3  *  media data format.
4  *
5  *   Kern Sibbald, MM
6  *
7  *   Version $Id$
8  *
9  */
10 /*
11    Bacula® - The Network Backup Solution
12
13    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
14
15    The main author of Bacula is Kern Sibbald, with contributions from
16    many others, a complete list can be found in the file AUTHORS.
17    This program is Free Software; you can redistribute it and/or
18    modify it under the terms of version two of the GNU General Public
19    License as published by the Free Software Foundation plus additions
20    that are listed in the file LICENSE.
21
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25    General Public License for more details.
26
27    You should have received a copy of the GNU General Public License
28    along with this program; if not, write to the Free Software
29    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30    02110-1301, USA.
31
32    Bacula® is a registered trademark of John Walker.
33    The licensor of Bacula is the Free Software Foundation Europe
34    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
35    Switzerland, email:ftf@fsfeurope.org.
36 */
37
38
39 #ifndef __RECORD_H
40 #define __RECORD_H 1
41
42 /* Return codes from read_device_volume_label() */
43 enum {
44    VOL_NOT_READ = 1,                      /* Volume label not read */
45    VOL_OK,                                /* volume name OK */
46    VOL_NO_LABEL,                          /* volume not labeled */
47    VOL_IO_ERROR,                          /* volume I/O error */
48    VOL_NAME_ERROR,                        /* Volume name mismatch */
49    VOL_CREATE_ERROR,                      /* Error creating label */
50    VOL_VERSION_ERROR,                     /* Bacula version error */
51    VOL_LABEL_ERROR,                       /* Bad label type */
52    VOL_NO_MEDIA                           /* Hard error -- no media present */
53 };
54
55
56 /*  See block.h for RECHDR_LENGTH */
57
58 /*
59  * This is the Media structure for a record header.
60  *  NB: when it is written it is serialized.
61
62    uint32_t VolSessionId;
63    uint32_t VolSessionTime;
64
65  * The above 8 bytes are only written in a BB01 block, BB02
66  *  and later blocks contain these values in the block header
67  *  rather than the record header.
68
69    int32_t  FileIndex;
70    int32_t  Stream;
71    uint32_t data_len;
72
73  */
74
75 /* Record state bit definitions */
76 #define REC_NO_HEADER        (1<<0)   /* No header read */
77 #define REC_PARTIAL_RECORD   (1<<1)   /* returning partial record */
78 #define REC_BLOCK_EMPTY      (1<<2)   /* not enough data in block */
79 #define REC_NO_MATCH         (1<<3)   /* No match on continuation data */
80 #define REC_CONTINUATION     (1<<4)   /* Continuation record found */
81 #define REC_ISTAPE           (1<<5)   /* Set if device is tape */
82
83 #define is_partial_record(r) ((r)->state & REC_PARTIAL_RECORD)
84 #define is_block_empty(r)    ((r)->state & REC_BLOCK_EMPTY)
85
86 /*
87  * DEV_RECORD for reading and writing records.
88  * It consists of a Record Header, and the Record Data
89  *
90  *  This is the memory structure for the record header.
91  */
92 struct BSR;                           /* satisfy forward reference */
93 struct DEV_RECORD {
94    dlink link;                        /* link for chaining in read_record.c */
95    /* File and Block are always returned during reading
96     *  and writing records.
97     */
98    uint32_t File;                     /* File number */
99    uint32_t Block;                    /* Block number */
100    uint32_t VolSessionId;             /* sequential id within this session */
101    uint32_t VolSessionTime;           /* session start time */
102    int32_t  FileIndex;                /* sequential file number */
103    int32_t  Stream;                   /* stream number */
104    uint32_t data_len;                 /* current record length */
105    uint32_t remainder;                /* remaining bytes to read/write */
106    uint32_t state;                    /* state bits */
107    BSR *bsr;                          /* pointer to bsr that matched */
108    uint8_t  ser_buf[WRITE_RECHDR_LENGTH];   /* serialized record header goes here */
109    POOLMEM *data;                     /* Record data. This MUST be a memory pool item */
110    int32_t match_stat;                /* bsr match status */
111 };
112
113
114 /*
115  * Values for LabelType that are put into the FileIndex field
116  * Note, these values are negative to distinguish them
117  * from user records where the FileIndex is forced positive.
118  */
119 #define PRE_LABEL   -1                /* Vol label on unwritten tape */
120 #define VOL_LABEL   -2                /* Volume label first file */
121 #define EOM_LABEL   -3                /* Writen at end of tape */
122 #define SOS_LABEL   -4                /* Start of Session */
123 #define EOS_LABEL   -5                /* End of Session */
124 #define EOT_LABEL   -6                /* End of physical tape (2 eofs) */
125
126 /*
127  *   Volume Label Record.  This is the in-memory definition. The
128  *     tape definition is defined in the serialization code itself
129  *     ser_volume_label() and unser_volume_label() and is slightly different.
130  */
131
132
133 struct Volume_Label {
134   /*
135    * The first items in this structure are saved
136    * in the DEVICE buffer, but are not actually written
137    * to the tape.
138    */
139   int32_t LabelType;                  /* This is written in header only */
140   uint32_t LabelSize;                 /* length of serialized label */
141   /*
142    * The items below this line are stored on
143    * the tape
144    */
145   char Id[32];                        /* Bacula Immortal ... */
146
147   uint32_t VerNum;                    /* Label version number */
148
149   /* VerNum <= 10 */
150   float64_t label_date;               /* Date tape labeled */
151   float64_t label_time;               /* Time tape labeled */
152
153   /* VerNum >= 11 */
154   btime_t   label_btime;              /* tdate tape labeled */
155   btime_t   write_btime;              /* tdate tape written */
156
157   /* Unused with VerNum >= 11 */
158   float64_t write_date;               /* Date this label written */
159   float64_t write_time;               /* Time this label written */
160
161   char VolumeName[MAX_NAME_LENGTH];   /* Volume name */
162   char PrevVolumeName[MAX_NAME_LENGTH]; /* Previous Volume Name */
163   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
164   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
165   char MediaType[MAX_NAME_LENGTH];    /* Type of this media */
166
167   char HostName[MAX_NAME_LENGTH];     /* Host name of writing computer */
168   char LabelProg[50];                 /* Label program name */
169   char ProgVersion[50];               /* Program version */
170   char ProgDate[50];                  /* Program build date/time */
171 };
172
173 #define SER_LENGTH_Volume_Label 1024   /* max serialised length of volume label */
174 #define SER_LENGTH_Session_Label 1024  /* max serialised length of session label */
175
176 typedef struct Volume_Label VOLUME_LABEL;
177
178 /*
179  * Session Start/End Label
180  *  This record is at the beginning and end of each session
181  */
182 struct Session_Label {
183   char Id[32];                        /* Bacula Immortal ... */
184
185   uint32_t VerNum;                    /* Label version number */
186
187   uint32_t JobId;                     /* Job id */
188   uint32_t VolumeIndex;               /* Sequence no of volume for this job */
189
190   /* VerNum >= 11 */
191   btime_t   write_btime;              /* Tdate this label written */
192
193   /* VerNum < 11 */
194   float64_t write_date;               /* Date this label written */
195
196   /* Unused VerNum >= 11 */
197   float64_t write_time;               /* Time this label written */
198
199   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
200   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
201   char JobName[MAX_NAME_LENGTH];      /* base Job name */
202   char ClientName[MAX_NAME_LENGTH];
203   char Job[MAX_NAME_LENGTH];          /* Unique name of this Job */
204   char FileSetName[MAX_NAME_LENGTH];
205   char FileSetMD5[MAX_NAME_LENGTH];
206   uint32_t JobType;
207   uint32_t JobLevel;
208   /* The remainder are part of EOS label only */
209   uint32_t JobFiles;
210   uint64_t JobBytes;
211   uint32_t StartBlock;
212   uint32_t EndBlock;
213   uint32_t StartFile;
214   uint32_t EndFile;
215   uint32_t JobErrors;
216   uint32_t JobStatus;                 /* Job status */
217
218 };
219 typedef struct Session_Label SESSION_LABEL;
220
221 #define SERIAL_BUFSIZE  1024          /* volume serialisation buffer size */
222
223 #endif