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