2 * Match Bootstrap Records (used for restores) against
5 * Kern Sibbald, June MMII
11 Copyright (C) 2002 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,
35 /* Forward references */
36 static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, int done);
37 static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, int done);
38 static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec, int done);
39 static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, int done);
40 static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, int done);
41 static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, int done);
42 static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, int done);
43 static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, int done);
44 static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, int done);
45 static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, int done);
46 static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, int done);
47 static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec, int done);
49 /*********************************************************************
51 * Match Bootstrap records
54 * returns -1 no additional matches possible
56 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
61 stat = match_all(bsr, rec, volrec, sessrec, 1);
65 // Dmsg1(000, "BSR returning %d\n", stat);
70 * Match all the components of current record
73 * returns -1 no additional matches possible
75 static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
76 SESSION_LABEL *sessrec, int done)
81 if (bsr->count && bsr->count <= bsr->found) {
85 if (!match_volume(bsr, bsr->volume, volrec, 1)) {
88 if (!match_volfile(bsr, bsr->volfile, rec, 1)) {
91 if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) {
95 /* NOTE!! This test MUST come after the sesstime test */
96 if (!match_sessid(bsr, bsr->sessid, rec, 1)) {
100 /* NOTE!! This test MUST come after sesstime and sessid tests */
101 if (!match_findex(bsr, bsr->FileIndex, rec, 1)) {
104 if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) {
107 if (!match_job(bsr, bsr->job, sessrec, 1)) {
110 if (!match_client(bsr, bsr->client, sessrec, 1)) {
113 if (!match_job_type(bsr, bsr->JobType, sessrec, 1)) {
116 if (!match_job_level(bsr, bsr->JobLevel, sessrec, 1)) {
119 if (!match_stream(bsr, bsr->stream, rec, 1)) {
127 return match_all(bsr->next, rec, volrec, sessrec, bsr->done && done);
129 if (bsr->done && done) {
135 static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, int done)
138 return 0; /* Volume must match */
140 if (strcmp(volume->VolumeName, volrec->VolName) == 0) {
144 return match_volume(bsr, volume->next, volrec, 1);
149 static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, int done)
152 return 1; /* no specification matches all */
154 if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) {
158 return match_client(bsr, client->next, sessrec, 1);
163 static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, int done)
166 return 1; /* no specification matches all */
168 if (fnmatch(job->Job, sessrec->Job, 0) == 0) {
172 return match_job(bsr, job->next, sessrec, 1);
177 static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, int done)
180 return 1; /* no specification matches all */
182 if (job_type->JobType == sessrec->JobType) {
185 if (job_type->next) {
186 return match_job_type(bsr, job_type->next, sessrec, 1);
191 static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, int done)
194 return 1; /* no specification matches all */
196 if (job_level->JobLevel == sessrec->JobLevel) {
199 if (job_level->next) {
200 return match_job_level(bsr, job_level->next, sessrec, 1);
205 static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, int done)
208 return 1; /* no specification matches all */
210 if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
214 return match_jobid(bsr, jobid->next, sessrec, 1);
219 static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, int done)
222 return 1; /* no specification matches all */
224 /* For the moment, these tests work only with tapes. */
225 if (!(rec->state & REC_ISTAPE)) {
226 return 1; /* All File records OK for this match */
228 // Dmsg3(000, "match_volfile: sfile=%d efile=%d recfile=%d\n",
229 // volfile->sfile, volfile->efile, rec->File);
230 if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
233 /* Once we get past last efile, we are done */
234 if (rec->File > volfile->efile) {
235 volfile->done = 1; /* set local done */
238 return match_volfile(bsr, volfile->next, rec, volfile->done && done);
241 /* If we are done and all prior matches are done, this bsr is finished */
242 if (volfile->done && done) {
248 static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, int done)
251 return 1; /* no specification matches all */
253 if (stream->stream == rec->Stream) {
257 return match_stream(bsr, stream->next, rec, 1);
262 static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, int done)
265 return 1; /* no specification matches all */
267 if (sesstime->sesstime == rec->VolSessionTime) {
270 if (rec->VolSessionTime > sesstime->sesstime) {
273 if (sesstime->next) {
274 return match_sesstime(bsr, sesstime->next, rec, sesstime->done && done);
276 if (sesstime->done && done) {
282 static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec, int done)
285 return 1; /* no specification matches all */
287 if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
290 if (rec->VolSessionId > sessid->sessid2) {
294 return match_sessid(bsr, sessid->next, rec, sessid->done && done);
296 if (sessid->done && done) {
302 static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, int done)
305 return 1; /* no specification matches all */
307 if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
310 if (rec->FileIndex > findex->findex2) {
314 return match_findex(bsr, findex->next, rec, findex->done && done);
316 if (findex->done && done) {