2 * Record, and label definitions for Bacula
9 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
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.
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.
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,
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 */
43 /* Length of Record Header (5 * 4 bytes) */
44 #define RECHDR_LENGTH 20
47 * This is the Media structure for a record header.
48 * NB: when it is written it is serialized.
50 typedef struct s_record_hdr {
51 uint32_t VolSessionId;
52 uint32_t VolSessionTime;
58 /* Record state bit definitions */
59 #define REC_NO_HEADER 0x01 /* No header read */
60 #define REC_PARTIAL_RECORD 0x02 /* returning partial record */
61 #define REC_BLOCK_EMPTY 0x04 /* not enough data in block */
62 #define REC_NO_MATCH 0x08 /* No match on continuation data */
63 #define REC_CONTINUATION 0x10 /* Continuation record found */
65 #define is_partial_record(r) ((r)->state & REC_PARTIAL_RECORD)
66 #define is_block_empty(r) ((r)->state & REC_BLOCK_EMPTY)
69 * DEV_RECORD for reading and writing records.
70 * It consists of a Record Header, and the Record Data
72 * This is the memory structure for the record header.
74 typedef struct s_dev_rec {
75 int sync; /* synchronous */
76 /* File and Block are always returned on reading records, but
77 * only returned on writing if sync is set (obviously).
79 uint32_t File; /* File number */
80 uint32_t Block; /* Block number */
81 uint32_t VolSessionId; /* sequential id within this session */
82 uint32_t VolSessionTime; /* session start time */
83 int32_t FileIndex; /* sequential file number */
84 int32_t Stream; /* stream number */
85 uint32_t data_len; /* current record length */
86 uint32_t remainder; /* remaining bytes to read/write */
87 uint32_t state; /* state bits */
88 uint8_t ser_buf[RECHDR_LENGTH]; /* serialized record header goes here */
89 POOLMEM *data; /* Record data. This MUST be a memory pool item */
94 * Values for LabelType that are put into the FileIndex field
95 * Note, these values are negative to distinguish them
96 * from user records where the FileIndex is forced positive.
98 #define PRE_LABEL -1 /* Vol label on unwritten tape */
99 #define VOL_LABEL -2 /* Volume label first file */
100 #define EOM_LABEL -3 /* Writen at end of tape */
101 #define SOS_LABEL -4 /* Start of Session */
102 #define EOS_LABEL -5 /* End of Session */
106 * Volume Label Record
108 struct Volume_Label {
110 * The first items in this structure are saved
111 * in the DEVICE buffer, but are not actually written
114 int32_t LabelType; /* This is written in header only */
115 uint32_t LabelSize; /* length of serialized label */
117 * The items below this line are stored on
120 char Id[32]; /* Bacula Immortal ... */
122 uint32_t VerNum; /* Label version number */
124 float64_t label_date; /* Date tape labeled */
125 float64_t label_time; /* Time tape labeled */
126 float64_t write_date; /* Date this label written */
127 float64_t write_time; /* Time this label written */
129 char VolName[MAX_NAME_LENGTH]; /* Volume name */
130 char PrevVolName[MAX_NAME_LENGTH]; /* Previous Volume Name */
131 char PoolName[MAX_NAME_LENGTH]; /* Pool name */
132 char PoolType[MAX_NAME_LENGTH]; /* Pool type */
133 char MediaType[MAX_NAME_LENGTH]; /* Type of this media */
135 char HostName[MAX_NAME_LENGTH]; /* Host name of writing computer */
136 char LabelProg[32]; /* Label program name */
137 char ProgVersion[32]; /* Program version */
138 char ProgDate[32]; /* Program build date/time */
141 #define SER_LENGTH_Volume_Label 1024 /* max serialised length of volume label */
142 #define SER_LENGTH_Session_Label 1024 /* max serialised length of session label */
144 typedef struct Volume_Label VOLUME_LABEL;
147 * Session Start/End Label
148 * This record is at the beginning and end of each session
150 struct Session_Label {
151 char Id[32]; /* Bacula Immortal ... */
153 uint32_t VerNum; /* Label version number */
155 uint32_t JobId; /* Job id */
156 uint32_t VolumeIndex; /* Sequence no of volume for this job */
158 float64_t write_date; /* Date this label written */
159 float64_t write_time; /* Time this label written */
161 char PoolName[MAX_NAME_LENGTH]; /* Pool name */
162 char PoolType[MAX_NAME_LENGTH]; /* Pool type */
163 char JobName[MAX_NAME_LENGTH]; /* base Job name */
164 char ClientName[MAX_NAME_LENGTH];
165 char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */
166 char FileSetName[MAX_NAME_LENGTH];
169 /* The remainder are part of EOS label only */
172 uint32_t start_block;
179 typedef struct Session_Label SESSION_LABEL;
181 #define SERIAL_BUFSIZE 1024 /* volume serialisation buffer size */