]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/parse_bsr.c
- Fix ANSI labels to put EOF1 and EOF2 after each file mark.
[bacula/bacula] / bacula / src / stored / parse_bsr.c
index 83343dcb7a19c5b1ed118572f2ab7c6c6f1863a5..654232632cf5f297b63910d80ec32969a56d14a8 100755 (executable)
@@ -1,13 +1,13 @@
-/*     
- *   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
@@ -21,7 +21,7 @@
 
    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.
+   MA 02111-1307, USA. 
 
  */
 
@@ -32,6 +32,7 @@
 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);
@@ -51,7 +52,7 @@ 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;
 };
 
@@ -60,6 +61,7 @@ struct kw_items {
  */
 struct kw_items items[] = {
    {"volume", store_vol},
+   {"mediatype", store_mediatype},
    {"client", store_client},
    {"job", store_job},
    {"jobid", store_jobid},
@@ -79,7 +81,7 @@ struct kw_items items[] = {
 
 };
 
-/* 
+/*
  * Create a BSR record
  */
 static BSR *new_bsr()
@@ -90,9 +92,9 @@ static BSR *new_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;
@@ -101,14 +103,14 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...)
    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);
    }
 }
@@ -125,7 +127,7 @@ BSR *parse_bsr(JCR *jcr, char *fname)
    int token, i;
    BSR *root_bsr = new_bsr();
    BSR *bsr = root_bsr;
-     
+
    Dmsg1(200, "Enter parse_bsf %s\n", fname);
    lc = lex_open_file(lc, fname, s_err);
    lc->caller_ctx = (void *)jcr;
@@ -213,7 +215,7 @@ 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;
@@ -222,7 +224,7 @@ static BSR *store_vol(LEX *lc, BSR *bsr)
       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; ) {
@@ -238,7 +240,7 @@ static BSR *store_vol(LEX *lc, BSR *bsr)
         bsr->volume = volume;
       } else {
         BSR_VOLUME *bc = bsr->volume;
-        for ( ;bc->next; bc=bc->next)  
+        for ( ;bc->next; bc=bc->next)
            { }
         bc->next = volume;
       }
@@ -247,11 +249,33 @@ static BSR *store_vol(LEX *lc, BSR *bsr)
    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) {
@@ -265,7 +289,7 @@ static BSR *store_client(LEX *lc, BSR *bsr)
         bsr->client = client;
       } else {
         BSR_CLIENT *bc = bsr->client;
-        for ( ;bc->next; bc=bc->next)  
+        for ( ;bc->next; bc=bc->next)
            { }
         bc->next = client;
       }
@@ -281,7 +305,7 @@ static BSR *store_job(LEX *lc, BSR *bsr)
 {
    int token;
    BSR_JOB *job;
-    
+
    for (;;) {
       token = lex_get_token(lc, T_NAME);
       if (token == T_ERROR) {
@@ -407,7 +431,7 @@ static BSR *store_joblevel(LEX *lc, BSR *bsr)
 
 
 /*
- * Routine to handle Volume start/end file   
+ * Routine to handle Volume start/end file
  */
 static BSR *store_volfile(LEX *lc, BSR *bsr)
 {
@@ -443,7 +467,7 @@ 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)
 {
@@ -713,9 +737,12 @@ void dump_bsr(BSR *bsr, bool recurse)
    }
    if (bsr->count) {
       Dmsg1(-1, "count       : %u\n", bsr->count);
+      Dmsg1(-1, "found       : %u\n", bsr->found);
    }
+
    Dmsg1(-1,    "done        : %s\n", bsr->done?"yes":"no");
    Dmsg1(-1,    "positioning : %d\n", bsr->use_positioning);
+   Dmsg1(-1,    "fast_reject : %d\n", bsr->use_fast_rejection);
    if (recurse && bsr->next) {
       Dmsg0(-1, "\n");
       dump_bsr(bsr->next, true);
@@ -759,7 +786,7 @@ void free_bsr(BSR *bsr)
 }
 
 /*****************************************************************
- * Routines for handling volumes     
+ * Routines for handling volumes
  */
 VOL_LIST *new_vol()
 {
@@ -769,7 +796,7 @@ VOL_LIST *new_vol()
    return vol;
 }
 
-/* 
+/*
  * Add current volume to end of list, only if the Volume
  * is not already in the list.
  *
@@ -824,7 +851,7 @@ void create_vol_list(JCR *jcr)
    char *p, *n;
    VOL_LIST *vol;
 
-   /* 
+   /*
     * Build a list of volumes to be processed
     */
    jcr->NumVolumes = 0;
@@ -849,10 +876,12 @@ void create_vol_list(JCR *jcr)
         for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) {
            vol = new_vol();
            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);
@@ -861,14 +890,15 @@ void create_vol_list(JCR *jcr)
         }
       }
    } 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();
         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 {