]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/bsr.c
- Apply Peter Eriksson's patch to configure.in fixes finding
[bacula/bacula] / bacula / src / dird / bsr.c
index 2a362192c15f9176c230bb24135460ff6f8cd51c..6baab0f9acb2151f3fc3c62df241223d52fb2bbd 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 /*
-   Copyright (C) 2002-2003 Kern Sibbald and John Walker
+   Copyright (C) 2002-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -34,7 +34,7 @@
 #include "dird.h"
 
 /* Forward referenced functions */
-static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd);
+static int write_bsr(UAContext *ua, RBSR *bsr, FILE *fd);
 void print_bsr(UAContext *ua, RBSR *bsr);
 
 
@@ -67,9 +67,10 @@ static void free_findex(RBSR_FINDEX *fi)
  * We are called here once for each JobMedia record
  *  for each Volume.
  */
-static void write_findex(UAContext *ua, RBSR_FINDEX *fi, 
+static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi, 
              int32_t FirstIndex, int32_t LastIndex, FILE *fd) 
 {
+   uint32_t count = 0;
    for ( ; fi; fi=fi->next) {
       int32_t findex, findex2;
       if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
@@ -79,11 +80,14 @@ static void write_findex(UAContext *ua, RBSR_FINDEX *fi,
         findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
         if (findex == findex2) {
             fprintf(fd, "FileIndex=%d\n", findex);
+           count++;
         } else {
             fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
+           count += findex2 - findex + 1;
         }
       }
    }
+   return count;
 }
 
 /*
@@ -108,14 +112,14 @@ static bool is_volume_selected(RBSR_FINDEX *fi,
 
 static void print_findex(UAContext *ua, RBSR_FINDEX *fi)
 {
-   bsendmsg(ua, "fi=0x%x\n", (unsigned)fi);
+   bsendmsg(ua, "fi=0x%lx\n", fi);
    for ( ; fi; fi=fi->next) {
       if (fi->findex == fi->findex2) {
          bsendmsg(ua, "FileIndex=%d\n", fi->findex);
-//       Dmsg1(000, "FileIndex=%d\n", fi->findex);
+//       Dmsg1(100, "FileIndex=%d\n", fi->findex);
       } else {
          bsendmsg(ua, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
-//       Dmsg2(000, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
+//       Dmsg2(100, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
       }
    }
 }
@@ -133,10 +137,10 @@ void free_bsr(RBSR *bsr)
 {
    if (bsr) {
       free_findex(bsr->fi);
-      free_bsr(bsr->next);
       if (bsr->VolParams) {
         free(bsr->VolParams);
       }
+      free_bsr(bsr->next);
       free(bsr);
    }
 }
@@ -172,31 +176,39 @@ int complete_bsr(UAContext *ua, RBSR *bsr)
 }
 
 /*
- * Write the bootstrap record to file
+ * Write the bootstrap records to file
  */
 int write_bsr_file(UAContext *ua, RBSR *bsr)
 {
    FILE *fd;
    POOLMEM *fname = get_pool_memory(PM_MESSAGE);
-   int stat;
+   int count = 0;;
+   bool err;
 
-   Mmsg(&fname, "%s/restore.bsr", working_directory);
+   Mmsg(fname, "%s/restore.bsr", working_directory);
    fd = fopen(fname, "w+");
    if (!fd) {
+      berrno be;
       bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"), 
-        fname, strerror(errno));
-      free_pool_memory(fname);
-      return 0;
+        fname, be.strerror());
+      goto bail_out;
    }
    /* Write them to file */
-   write_bsr(ua, bsr, fd);
-   stat = !ferror(fd);
+   count = write_bsr(ua, bsr, fd);
+   err = ferror(fd);
    fclose(fd);
+   if (err) {
+      bsendmsg(ua, _("Error writing bsr file.\n"));
+      count = 0;
+      goto bail_out;
+   }
+
+
    bsendmsg(ua, _("Bootstrap records written to %s\n"), fname);
 
    /* Tell the user what he will need to mount */
    bsendmsg(ua, "\n");
-   bsendmsg(ua, _("The restore job will require the following Volumes:\n"));
+   bsendmsg(ua, _("The job will require the following Volumes:\n"));
    /* Create Unique list of Volumes using prompt list */
    start_prompt(ua, "");
    for (RBSR *nbsr=bsr; nbsr; nbsr=nbsr->next) {
@@ -210,14 +222,21 @@ int write_bsr_file(UAContext *ua, RBSR *bsr)
       bsendmsg(ua, "   %s\n", ua->prompt[i]);
       free(ua->prompt[i]);
    }
+   if (ua->num_prompts == 0) {
+      bsendmsg(ua, _("No Volumes found to restore.\n"));
+      count = 0;
+   }
    ua->num_prompts = 0;
    bsendmsg(ua, "\n");
+
+bail_out:
    free_pool_memory(fname);
-   return stat;
+   return count;
 }
 
-static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
+static int write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
 {
+   uint32_t count = 0;
    if (bsr) {
       /*
        * For a given volume, loop over all the JobMedia records.
@@ -232,18 +251,30 @@ static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
          fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
          fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
          fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
-         fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile, 
-                bsr->VolParams[i].EndFile);
-         fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
-                bsr->VolParams[i].EndBlock);
-
-//       Dmsg2(000, "bsr VolParam FI=%u LI=%u\n",
+        if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) {
+            fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile);
+        } else {
+            fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile, 
+                   bsr->VolParams[i].EndFile);
+        }
+        if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) {
+            fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock);
+        } else {
+            fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
+                   bsr->VolParams[i].EndBlock);
+        }
+//       Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
 //         bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
-        write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
-           bsr->VolParams[i].LastIndex, fd);
+
+        count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
+                             bsr->VolParams[i].LastIndex, fd);
+        if (count) {
+            fprintf(fd, "Count=%u\n", count);
+        }
       }
       write_bsr(ua, bsr->next, fd);
    }
+   return count;
 }
 
 void print_bsr(UAContext *ua, RBSR *bsr)