-/*
- * Parse a Bootstrap Records (used for restores)
- *
+/*
+ * Parse a Bootstrap Records (used for restores)
+ *
* Kern Sibbald, June MMII
*
* Version $Id$
*/
/*
- Copyright (C) 2002 Kern Sibbald and John Walker
+ Copyright (C) 2002-2005 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as ammended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
typedef BSR * (ITEM_HANDLER)(LEX *lc, BSR *bsr);
static BSR *store_vol(LEX *lc, BSR *bsr);
+static BSR *store_mediatype(LEX *lc, BSR *bsr);
static BSR *store_client(LEX *lc, BSR *bsr);
static BSR *store_job(LEX *lc, BSR *bsr);
static BSR *store_jobid(LEX *lc, BSR *bsr);
static BSR *store_exclude(LEX *lc, BSR *bsr);
static BSR *store_stream(LEX *lc, BSR *bsr);
static BSR *store_slot(LEX *lc, BSR *bsr);
+static bool is_fast_rejection_ok(BSR *bsr);
+static bool is_positioning_ok(BSR *bsr);
struct kw_items {
- char *name;
+ const char *name;
ITEM_HANDLER *handler;
};
*/
struct kw_items items[] = {
{"volume", store_vol},
+ {"mediatype", store_mediatype},
{"client", store_client},
{"job", store_job},
{"jobid", store_jobid},
};
-/*
+/*
* Create a BSR record
*/
-static BSR *new_bsr()
+static BSR *new_bsr()
{
BSR *bsr = (BSR *)malloc(sizeof(BSR));
memset(bsr, 0, sizeof(BSR));
}
/*
- * Format a scanner error message
+ * Format a scanner error message
*/
-static void s_err(char *file, int line, LEX *lc, char *msg, ...)
+static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
{
JCR *jcr = (JCR *)(lc->caller_ctx);
va_list arg_ptr;
va_start(arg_ptr, msg);
bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
va_end(arg_ptr);
-
+
if (jcr) {
- Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n\
- : Line %d, col %d of file %s\n%s\n"),
+ Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n"
+" : Line %d, col %d of file %s\n%s\n"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line);
} else {
- e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n\
- : Line %d, col %d of file %s\n%s\n"),
+ e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n"
+" : Line %d, col %d of file %s\n%s\n"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line);
}
}
* Parse Bootstrap file
*
*/
-BSR *parse_bsr(JCR *jcr, char *cf)
+BSR *parse_bsr(JCR *jcr, char *fname)
{
LEX *lc = NULL;
int token, i;
BSR *root_bsr = new_bsr();
BSR *bsr = root_bsr;
- Dmsg1(200, "Enter parse_bsf %s\n", cf);
- lc = lex_open_file(lc, cf, s_err);
+ Dmsg1(200, "Enter parse_bsf %s\n", fname);
+ if ((lc = lex_open_file(lc, fname, s_err)) == NULL) {
+ berrno be;
+ Emsg2(M_ERROR_TERM, 0, _("Cannot open bootstrap file %s: %s\n"),
+ fname, be.strerror());
+ }
lc->caller_ctx = (void *)jcr;
while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
Dmsg1(200, "parse got token=%s\n", lex_tok_to_str(token));
free_bsr(root_bsr);
root_bsr = NULL;
}
+ if (root_bsr) {
+ root_bsr->use_fast_rejection = is_fast_rejection_ok(root_bsr);
+ root_bsr->use_positioning = is_positioning_ok(root_bsr);
+ }
+ for (bsr=root_bsr; bsr; bsr=bsr->next) {
+ bsr->root = root_bsr;
+ }
return root_bsr;
}
+static bool is_fast_rejection_ok(BSR *bsr)
+{
+ /*
+ * Although, this can be optimized, for the moment, require
+ * all bsrs to have both sesstime and sessid set before
+ * we do fast rejection.
+ */
+ for ( ; bsr; bsr=bsr->next) {
+ if (!(bsr->sesstime && bsr->sessid)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+static bool is_positioning_ok(BSR *bsr)
+{
+ /*
+ * Every bsr should have a volfile entry and a volblock entry
+ * if we are going to use positioning
+ */
+ for ( ; bsr; bsr=bsr->next) {
+ if (!bsr->volfile || !bsr->volblock) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
static BSR *store_vol(LEX *lc, BSR *bsr)
{
int token;
BSR_VOLUME *volume;
char *p, *n;
-
+
token = lex_get_token(lc, T_STRING);
if (token == T_ERROR) {
return NULL;
bsr->next = new_bsr();
bsr = bsr->next;
}
- /* This may actually be more than one volume separated by a |
+ /* This may actually be more than one volume separated by a |
* If so, separate them.
*/
for (p=lc->str; p && *p; ) {
}
volume = (BSR_VOLUME *)malloc(sizeof(BSR_VOLUME));
memset(volume, 0, sizeof(BSR_VOLUME));
- strcpy(volume->VolumeName, p);
+ bstrncpy(volume->VolumeName, p, sizeof(volume->VolumeName));
/* Add it to the end of the volume chain */
if (!bsr->volume) {
bsr->volume = volume;
} else {
BSR_VOLUME *bc = bsr->volume;
- for ( ;bc->next; bc=bc->next)
+ for ( ;bc->next; bc=bc->next)
{ }
bc->next = volume;
}
return bsr;
}
+/* Shove the MediaType in each Volume in the current bsr */
+static BSR *store_mediatype(LEX *lc, BSR *bsr)
+{
+ int token;
+
+ token = lex_get_token(lc, T_STRING);
+ if (token == T_ERROR) {
+ return NULL;
+ }
+ if (!bsr->volume) {
+ Emsg1(M_ERROR,0, _("MediaType %s in bsr at inappropriate place.\n"),
+ lc->str);
+ return bsr;
+ }
+ BSR_VOLUME *bv;
+ for (bv=bsr->volume; bv; bv=bv->next) {
+ bstrncpy(bv->MediaType, lc->str, sizeof(bv->MediaType));
+ }
+ return bsr;
+}
+
+
static BSR *store_client(LEX *lc, BSR *bsr)
{
int token;
BSR_CLIENT *client;
-
+
for (;;) {
token = lex_get_token(lc, T_NAME);
if (token == T_ERROR) {
}
client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT));
memset(client, 0, sizeof(BSR_CLIENT));
- strcpy(client->ClientName, lc->str);
+ bstrncpy(client->ClientName, lc->str, sizeof(client->ClientName));
/* Add it to the end of the client chain */
if (!bsr->client) {
bsr->client = client;
} else {
BSR_CLIENT *bc = bsr->client;
- for ( ;bc->next; bc=bc->next)
+ for ( ;bc->next; bc=bc->next)
{ }
bc->next = client;
}
{
int token;
BSR_JOB *job;
-
+
for (;;) {
token = lex_get_token(lc, T_NAME);
if (token == T_ERROR) {
}
job = (BSR_JOB *)malloc(sizeof(BSR_JOB));
memset(job, 0, sizeof(BSR_JOB));
- strcpy(job->Job, lc->str);
+ bstrncpy(job->Job, lc->str, sizeof(job->Job));
/* Add it to the end of the client chain */
if (!bsr->job) {
bsr->job = job;
static BSR *store_jobtype(LEX *lc, BSR *bsr)
{
/* *****FIXME****** */
- Dmsg0(-1, "JobType not yet implemented\n");
+ Pmsg0(-1, "JobType not yet implemented\n");
return bsr;
}
static BSR *store_joblevel(LEX *lc, BSR *bsr)
{
/* *****FIXME****** */
- Dmsg0(-1, "JobLevel not yet implemented\n");
+ Pmsg0(-1, "JobLevel not yet implemented\n");
return bsr;
}
/*
- * Routine to handle Volume start/end file
+ * Routine to handle Volume start/end file
*/
static BSR *store_volfile(LEX *lc, BSR *bsr)
{
/*
- * Routine to handle Volume start/end Block
+ * Routine to handle Volume start/end Block
*/
static BSR *store_volblock(LEX *lc, BSR *bsr)
{
void dump_volfile(BSR_VOLFILE *volfile)
{
if (volfile) {
- Dmsg2(-1, "VolFile : %u-%u\n", volfile->sfile, volfile->efile);
+ Pmsg2(-1, "VolFile : %u-%u\n", volfile->sfile, volfile->efile);
dump_volfile(volfile->next);
}
}
void dump_volblock(BSR_VOLBLOCK *volblock)
{
if (volblock) {
- Dmsg2(-1, "VolBlock : %u-%u\n", volblock->sblock, volblock->eblock);
+ Pmsg2(-1, "VolBlock : %u-%u\n", volblock->sblock, volblock->eblock);
dump_volblock(volblock->next);
}
}
{
if (FileIndex) {
if (FileIndex->findex == FileIndex->findex2) {
- Dmsg1(-1, "FileIndex : %u\n", FileIndex->findex);
+ Pmsg1(-1, "FileIndex : %u\n", FileIndex->findex);
} else {
- Dmsg2(-1, "FileIndex : %u-%u\n", FileIndex->findex, FileIndex->findex2);
+ Pmsg2(-1, "FileIndex : %u-%u\n", FileIndex->findex, FileIndex->findex2);
}
dump_findex(FileIndex->next);
}
{
if (jobid) {
if (jobid->JobId == jobid->JobId2) {
- Dmsg1(-1, "JobId : %u\n", jobid->JobId);
+ Pmsg1(-1, "JobId : %u\n", jobid->JobId);
} else {
- Dmsg2(-1, "JobId : %u-%u\n", jobid->JobId, jobid->JobId2);
+ Pmsg2(-1, "JobId : %u-%u\n", jobid->JobId, jobid->JobId2);
}
dump_jobid(jobid->next);
}
{
if (sessid) {
if (sessid->sessid == sessid->sessid2) {
- Dmsg1(-1, "SessId : %u\n", sessid->sessid);
+ Pmsg1(-1, "SessId : %u\n", sessid->sessid);
} else {
- Dmsg2(-1, "SessId : %u-%u\n", sessid->sessid, sessid->sessid2);
+ Pmsg2(-1, "SessId : %u-%u\n", sessid->sessid, sessid->sessid2);
}
dump_sessid(sessid->next);
}
void dump_volume(BSR_VOLUME *volume)
{
if (volume) {
- Dmsg1(-1, "VolumeName : %s\n", volume->VolumeName);
+ Pmsg1(-1, "VolumeName : %s\n", volume->VolumeName);
dump_volume(volume->next);
}
}
void dump_client(BSR_CLIENT *client)
{
if (client) {
- Dmsg1(-1, "Client : %s\n", client->ClientName);
+ Pmsg1(-1, "Client : %s\n", client->ClientName);
dump_client(client->next);
}
}
void dump_job(BSR_JOB *job)
{
if (job) {
- Dmsg1(-1, "Job : %s\n", job->Job);
+ Pmsg1(-1, "Job : %s\n", job->Job);
dump_job(job->next);
}
}
void dump_sesstime(BSR_SESSTIME *sesstime)
{
if (sesstime) {
- Dmsg1(-1, "SessTime : %u\n", sesstime->sesstime);
+ Pmsg1(-1, "SessTime : %u\n", sesstime->sesstime);
dump_sesstime(sesstime->next);
}
}
-void dump_bsr(BSR *bsr)
+void dump_bsr(BSR *bsr, bool recurse)
{
+ int save_debug = debug_level;
+ debug_level = 1;
if (!bsr) {
- Dmsg0(-1, "BSR is NULL\n");
+ Pmsg0(-1, "BSR is NULL\n");
+ debug_level = save_debug;
return;
}
- Dmsg1(-1,
-"Next : 0x%x\n", bsr->next);
+ Pmsg1(-1, "Next : 0x%x\n", bsr->next);
+ Pmsg1(-1, "Root bsr : 0x%x\n", bsr->root);
dump_volume(bsr->volume);
dump_sessid(bsr->sessid);
dump_sesstime(bsr->sesstime);
dump_job(bsr->job);
dump_findex(bsr->FileIndex);
if (bsr->Slot) {
- Dmsg1(-1, "Slot : %u\n", bsr->Slot);
+ Pmsg1(-1, "Slot : %u\n", bsr->Slot);
}
if (bsr->count) {
- Dmsg1(-1, "count : %u\n", bsr->count);
+ Pmsg1(-1, "count : %u\n", bsr->count);
+ Pmsg1(-1, "found : %u\n", bsr->found);
}
- if (bsr->next) {
- Dmsg0(-1, "\n");
- dump_bsr(bsr->next);
+
+ Pmsg1(-1, "done : %s\n", bsr->done?"yes":"no");
+ Pmsg1(-1, "positioning : %d\n", bsr->use_positioning);
+ Pmsg1(-1, "fast_reject : %d\n", bsr->use_fast_rejection);
+ if (recurse && bsr->next) {
+ Pmsg0(-1, "\n");
+ dump_bsr(bsr->next, true);
}
+ debug_level = save_debug;
}
}
/*****************************************************************
- * Routines for handling volumes
+ * Routines for handling volumes
*/
VOL_LIST *new_vol()
{
return vol;
}
-/*
+/*
* Add current volume to end of list, only if the Volume
* is not already in the list.
*
char *p, *n;
VOL_LIST *vol;
- /*
+ /*
* Build a list of volumes to be processed
*/
jcr->NumVolumes = 0;
/* Now add volumes for this bsr */
for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) {
vol = new_vol();
- strcpy(vol->VolumeName, bsrvol->VolumeName);
+ bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->VolumeName));
+ bstrncpy(vol->MediaType, bsrvol->MediaType, sizeof(vol->MediaType));
vol->start_file = sfile;
if (add_vol(jcr, vol)) {
jcr->NumVolumes++;
- Dmsg1(400, "Added volume %s\n", vol->VolumeName);
+ Dmsg2(400, "Added volume=%s mediatype=%s\n", vol->VolumeName,
+ vol->MediaType);
} else {
Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
free((char *)vol);
}
}
} else {
- /* This is the old way -- deprecated */
- for (p = jcr->VolumeName; p && *p; ) {
+ /* This is the old way -- deprecated */
+ for (p = jcr->dcr->VolumeName; p && *p; ) {
n = strchr(p, '|'); /* volume name separator */
if (n) {
*n++ = 0; /* Terminate name */
}
vol = new_vol();
- strcpy(vol->VolumeName, p);
+ bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName));
+ bstrncpy(vol->MediaType, jcr->dcr->media_type, sizeof(vol->MediaType));
if (add_vol(jcr, vol)) {
jcr->NumVolumes++;
} else {