]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/record.h
fe6f41cea1505a8c16d754059ee021038dd64d5c
[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 /* Length of Record Header (5 * 4 bytes) */
44 #define RECHDR_LENGTH 20
45
46 /*
47  * This is the Media structure for a record header.
48  *  NB: when it is written it is serialized.
49  */
50 typedef struct s_record_hdr {
51    uint32_t VolSessionId;
52    uint32_t VolSessionTime;
53    int32_t  FileIndex;
54    int32_t  Stream;
55    uint32_t data_len;
56 } RECORD_HDR;
57
58 #define REC_NO_HEADER        0x01     /* No header read */
59 #define REC_PARTIAL_RECORD   0x02     /* returning partial record */
60 #define REC_BLOCK_EMPTY      0x04     /* not enough data in block */
61 #define REC_NO_MATCH         0x08     /* No match on continuation data */
62 #define REC_CONTINUATION     0x10     /* Continuation record found */
63
64 /*
65  * DEV_RECORD for reading and writing records.
66  * It consists of a Record Header, and the Record Data
67  * 
68  *  This is the memory structure for the record header.
69  */
70 typedef struct s_dev_rec {
71    int      sync;                     /* synchronous */
72    /* File and Block are always returned on reading records, but
73     *  only returned on writing if sync is set (obviously).
74     */
75    uint32_t File;                     /* File number */
76    uint32_t Block;                    /* Block number */
77    uint32_t VolSessionId;             /* sequential id within this session */
78    uint32_t VolSessionTime;           /* session start time */
79    int32_t  FileIndex;                /* sequential file number */
80    int32_t  Stream;                   /* stream number */
81    uint32_t data_len;                 /* current record length */
82    uint32_t remainder;                /* remaining bytes to read/write */
83    uint32_t state;                    /* state bits */
84    uint8_t  ser_buf[RECHDR_LENGTH];   /* serialized record header goes here */
85    POOLMEM *data;                     /* Record data. This MUST be a memory pool item */
86 } DEV_RECORD;
87
88
89 /*
90  * Values for LabelType that are put into the FileIndex field
91  * Note, these values are negative to distinguish them
92  * from user records where the FileIndex is forced positive.
93  */
94 #define PRE_LABEL   -1                /* Vol label on unwritten tape */
95 #define VOL_LABEL   -2                /* Volume label first file */
96 #define EOM_LABEL   -3                /* Writen at end of tape */        
97 #define SOS_LABEL   -4                /* Start of Session */
98 #define EOS_LABEL   -5                /* End of Session */
99  
100
101 /* 
102  *   Volume Label Record
103  */
104 struct Volume_Label {
105   /*  
106    * The first items in this structure are saved
107    * in the DEVICE buffer, but are not actually written
108    * to the tape.
109    */
110   int32_t LabelType;                  /* This is written in header only */
111   uint32_t LabelSize;                 /* length of serialized label */
112   /*
113    * The items below this line are stored on 
114    * the tape
115    */
116   char Id[32];                        /* Bacula Immortal ... */
117
118   uint32_t VerNum;                    /* Label version number */
119
120   float64_t label_date;               /* Date tape labeled */
121   float64_t label_time;               /* Time tape labeled */
122   float64_t write_date;               /* Date this label written */
123   float64_t write_time;               /* Time this label written */
124
125   char VolName[MAX_NAME_LENGTH];      /* Volume name */
126   char PrevVolName[MAX_NAME_LENGTH];  /* Previous Volume Name */
127   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
128   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
129   char MediaType[MAX_NAME_LENGTH];    /* Type of this media */
130
131   char HostName[MAX_NAME_LENGTH];     /* Host name of writing computer */
132   char LabelProg[32];                 /* Label program name */
133   char ProgVersion[32];               /* Program version */
134   char ProgDate[32];                  /* Program build date/time */
135 };
136
137 #define SER_LENGTH_Volume_Label 1024   /* max serialised length of volume label */
138 #define SER_LENGTH_Session_Label 1024  /* max serialised length of session label */
139
140 typedef struct Volume_Label VOLUME_LABEL;
141
142 /*
143  * Session Start/End Label
144  *  This record is at the beginning and end of each session
145  */
146 struct Session_Label {
147   char Id[32];                        /* Bacula Immortal ... */
148
149   uint32_t VerNum;                    /* Label version number */
150
151   uint32_t JobId;                     /* Job id */
152   uint32_t VolumeIndex;               /* Sequence no of volume for this job */
153
154   float64_t write_date;               /* Date this label written */
155   float64_t write_time;               /* Time this label written */
156
157   char PoolName[MAX_NAME_LENGTH];     /* Pool name */
158   char PoolType[MAX_NAME_LENGTH];     /* Pool type */
159   char JobName[MAX_NAME_LENGTH];      /* base Job name */
160   char ClientName[MAX_NAME_LENGTH];
161   char Job[MAX_NAME_LENGTH];          /* Unique name of this Job */
162   char FileSetName[MAX_NAME_LENGTH];
163   uint32_t JobType;
164   uint32_t JobLevel;
165   /* The remainder are part of EOS label only */
166   uint32_t JobFiles;
167   uint64_t JobBytes;
168   uint32_t start_block;
169   uint32_t end_block;
170   uint32_t start_file;
171   uint32_t end_file;
172   uint32_t JobErrors;
173
174 };
175 typedef struct Session_Label SESSION_LABEL;
176
177 #define SERIAL_BUFSIZE  1024          /* volume serialisation buffer size */
178
179 #endif