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