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