2 * Match Bootstrap Records (used for restores) against
5 * Kern Sibbald, June MMII
11 Copyright (C) 2000-2003 Kern Sibbald and John Walker
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.
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.
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,
34 /* Forward references */
35 static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done);
36 static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, bool done);
37 static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec);
38 static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bool done);
39 static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done);
40 static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, bool done);
41 static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, bool done);
42 static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool done);
43 static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done);
44 static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool done);
45 static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done);
46 static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec, bool done);
47 static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *block);
48 static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block);
50 /*********************************************************************
52 * If possible, position the archive device (tape) to read the
55 void position_bsr_block(BSR *bsr, DEV_BLOCK *block)
57 /* To be implemented */
60 /*********************************************************************
62 * Do fast block rejection based on bootstrap records.
63 * use_fast_rejection will be set if we have VolSessionId and VolSessTime
64 * in each record. When BlockVer is >= 2, we have those in the block header
65 * so can do fast rejection.
67 * returns: 1 if block may contain valid records
68 * 0 if block may be skipped (i.e. it contains no records of
69 * that can match the bsr).
72 int match_bsr_block(BSR *bsr, DEV_BLOCK *block)
74 if (!bsr || !bsr->use_fast_rejection || (block->BlockVer < 2)) {
75 return 1; /* cannot fast reject */
78 if (match_block_sesstime(bsr, bsr->sesstime, block)) {
81 return match_block_sessid(bsr, bsr->sessid, block);
84 static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *block)
87 return 1; /* no specification matches all */
89 if (sesstime->sesstime == block->VolSessionTime) {
93 return match_block_sesstime(bsr, sesstime->next, block);
98 static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block)
101 return 1; /* no specification matches all */
103 if (sessid->sessid <= block->VolSessionId && sessid->sessid2 >= block->VolSessionId) {
107 return match_block_sessid(bsr, sessid->next, block);
113 /*********************************************************************
115 * Match Bootstrap records
118 * returns -1 no additional matches possible
120 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
125 stat = match_all(bsr, rec, volrec, sessrec, true);
129 // Dmsg1(000, "BSR returning %d\n", stat);
134 * Match all the components of current record
137 * returns -1 no additional matches possible
139 static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
140 SESSION_LABEL *sessrec, bool done)
145 if (bsr->count && bsr->count <= bsr->found) {
149 if (!match_volume(bsr, bsr->volume, volrec, 1)) {
152 if (!match_volfile(bsr, bsr->volfile, rec, 1)) {
155 if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) {
159 /* NOTE!! This test MUST come after the sesstime test */
160 if (!match_sessid(bsr, bsr->sessid, rec)) {
164 /* NOTE!! This test MUST come after sesstime and sessid tests */
165 if (!match_findex(bsr, bsr->FileIndex, rec, 1)) {
168 if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) {
171 if (!match_job(bsr, bsr->job, sessrec, 1)) {
174 if (!match_client(bsr, bsr->client, sessrec, 1)) {
177 if (!match_job_type(bsr, bsr->JobType, sessrec, 1)) {
180 if (!match_job_level(bsr, bsr->JobLevel, sessrec, 1)) {
183 if (!match_stream(bsr, bsr->stream, rec, 1)) {
191 return match_all(bsr->next, rec, volrec, sessrec, bsr->done && done);
193 if (bsr->done && done) {
199 static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done)
202 return 0; /* Volume must match */
204 if (strcmp(volume->VolumeName, volrec->VolName) == 0) {
208 return match_volume(bsr, volume->next, volrec, 1);
213 static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bool done)
216 return 1; /* no specification matches all */
218 if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) {
222 return match_client(bsr, client->next, sessrec, 1);
227 static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done)
230 return 1; /* no specification matches all */
232 if (fnmatch(job->Job, sessrec->Job, 0) == 0) {
236 return match_job(bsr, job->next, sessrec, 1);
241 static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, bool done)
244 return 1; /* no specification matches all */
246 if (job_type->JobType == sessrec->JobType) {
249 if (job_type->next) {
250 return match_job_type(bsr, job_type->next, sessrec, 1);
255 static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, bool done)
258 return 1; /* no specification matches all */
260 if (job_level->JobLevel == sessrec->JobLevel) {
263 if (job_level->next) {
264 return match_job_level(bsr, job_level->next, sessrec, 1);
269 static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool done)
272 return 1; /* no specification matches all */
274 if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
278 return match_jobid(bsr, jobid->next, sessrec, 1);
283 static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool done)
286 return 1; /* no specification matches all */
288 /* For the moment, these tests work only with tapes. */
289 if (!(rec->state & REC_ISTAPE)) {
290 return 1; /* All File records OK for this match */
292 // Dmsg3(000, "match_volfile: sfile=%d efile=%d recfile=%d\n",
293 // volfile->sfile, volfile->efile, rec->File);
294 if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
297 /* Once we get past last efile, we are done */
298 if (rec->File > volfile->efile) {
299 volfile->done = true; /* set local done */
302 return match_volfile(bsr, volfile->next, rec, volfile->done && done);
305 /* If we are done and all prior matches are done, this bsr is finished */
306 if (volfile->done && done) {
312 static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done)
315 return 1; /* no specification matches all */
317 if (stream->stream == rec->Stream) {
321 return match_stream(bsr, stream->next, rec, 1);
326 static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, bool done)
329 return 1; /* no specification matches all */
331 if (sesstime->sesstime == rec->VolSessionTime) {
334 if (rec->VolSessionTime > sesstime->sesstime) {
335 sesstime->done = true;
337 if (sesstime->next) {
338 return match_sesstime(bsr, sesstime->next, rec, sesstime->done && done);
340 if (sesstime->done && done) {
346 static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec)
349 return 1; /* no specification matches all */
351 if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
355 return match_sessid(bsr, sessid->next, rec);
360 static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done)
363 return 1; /* no specification matches all */
365 if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
368 if (rec->FileIndex > findex->findex2) {
372 return match_findex(bsr, findex->next, rec, findex->done && done);
374 if (findex->done && done) {