]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/read_record.c
Enhance FD status to have level
[bacula/bacula] / bacula / src / stored / read_record.c
index 6c2b52fe3cfd642dbbc3de776e3350c913777ae6..2c411aac093f49c46108e09f61e485111e83bb8f 100644 (file)
@@ -1,22 +1,7 @@
-/*
- *
- *  This routine provides a routine that will handle all
- *    the gory little details of reading a record from a Bacula
- *    archive. It uses a callback to pass you each record in turn,
- *    as well as a callback for mounting the next tape.  It takes
- *    care of reading blocks, applying the bsr, ...
- *    Note, this routine is really the heart of the restore routines,
- *    and we are *really* bit pushing here so be careful about making
- *    any modifications.
- *
- *    Kern E. Sibbald, August MMII
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *  This routine provides a routine that will handle all
+ *    the gory little details of reading a record from a Bacula
+ *    archive. It uses a callback to pass you each record in turn,
+ *    as well as a callback for mounting the next tape.  It takes
+ *    care of reading blocks, applying the bsr, ...
+ *    Note, this routine is really the heart of the restore routines,
+ *    and we are *really* bit pushing here so be careful about making
+ *    any modifications.
+ *
+ *    Kern E. Sibbald, August MMII
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #include "stored.h"
@@ -52,8 +52,13 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr);
 static char *rec_state_to_str(DEV_RECORD *rec);
 #endif
 
-static const int dbglvl = 1000;
+static const int dbglvl = 500;
 
+/*
+ * This subroutine reads all the records and passes them back to your
+ *  callback routine (also mount routine at EOM).
+ * You must not change any values in the DEV_RECORD packet
+ */
 bool read_records(DCR *dcr,
        bool record_cb(DCR *dcr, DEV_RECORD *rec),
        bool mount_cb(DCR *dcr))
@@ -82,6 +87,7 @@ bool read_records(DCR *dcr,
             DEV_RECORD *trec = new_record();
             Jmsg(jcr, M_INFO, 0, _("End of Volume at file %u on device %s, Volume \"%s\"\n"),
                  dev->file, dev->print_name(), dcr->VolumeName);
+            volume_unused(dcr);       /* mark volume unused */
             if (!mount_cb(dcr)) {
                Jmsg(jcr, M_INFO, 0, _("End of all volumes.\n"));
                ok = false;            /* Stop everything */
@@ -103,9 +109,10 @@ bool read_records(DCR *dcr,
             jcr->mount_next_volume = false;
             /*  
              * The Device can change at the end of a tape, so refresh it
-             *   from the dcr.
+             *   and the block from the dcr.
              */
             dev = dcr->dev;
+            block = dcr->block;
             /*
              * We just have a new tape up, now read the label (first record)
              *  and pass it off to the callback routine, then continue
@@ -121,6 +128,7 @@ bool read_records(DCR *dcr,
             continue;
 
          } else if (dev->at_eof()) {
+#ifdef neeeded_xxx
             if (verbose) {
                char *fp;
                uint32_t fp_num;
@@ -132,8 +140,9 @@ bool read_records(DCR *dcr,
                   fp_num = dev->file;
                }
                Jmsg(jcr, M_INFO, 0, _("End of %s %u on device %s, Volume \"%s\"\n"),
-                  fp, fp_num, dev->print_name(), dcr->VolumeName);
+                    fp, fp_num, dev->print_name(), dcr->VolumeName);
             }
+#endif
             Dmsg3(200, "End of file %u  on device %s, Volume \"%s\"\n",
                   dev->file, dev->print_name(), dcr->VolumeName);
             continue;
@@ -226,11 +235,13 @@ bool read_records(DCR *dcr,
              *  he wants to know if they matched the bsr, then he must
              *  check the match_stat in the record */
             ok = record_cb(dcr, rec);
+#ifdef xxx
             /*
              * If this is the end of the Session (EOS) for this record
              *  we can remove the record.  Note, there is a separate
              *  record to read each session. If a new session is seen
              *  a new record will be created at approx line 157 above.
+             * However, it seg faults in the for line at lineno 196.
              */
             if (rec->FileIndex == EOS_LABEL) {
                Dmsg2(dbglvl, "Remove EOS rec. SI=%d ST=%d\n", rec->VolSessionId,
@@ -238,6 +249,7 @@ bool read_records(DCR *dcr,
                recs->remove(rec);
                free_record(rec);
             }
+#endif
             continue;
          } /* end if label record */
 
@@ -245,7 +257,7 @@ bool read_records(DCR *dcr,
           * Apply BSR filter
           */
          if (jcr->bsr) {
-            rec->match_stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
+            rec->match_stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec, jcr);
             if (rec->match_stat == -1) { /* no more possible matches */
                done = true;   /* all items found, stop */
                Dmsg2(dbglvl, "All done=(file:block) %u:%u\n", dev->file, dev->block_num);
@@ -268,6 +280,7 @@ bool read_records(DCR *dcr,
                rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
             break;                    /* read second part of record */
          }
+
          Dmsg6(dbglvl, "OK callback. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
                rec_state_to_str(rec), block->BlockNumber,
                rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
@@ -333,19 +346,17 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr)
        *   when find_next_bsr() is fixed not to return a bsr already
        *   completed.
        */
-      if (dev->file > bsr->volfile->sfile ||             
-         (dev->file == bsr->volfile->sfile && dev->block_num > bsr->volblock->sblock)) {
+      uint32_t block, file;
+      /* TODO: use dev->file_addr ? */
+      uint64_t dev_addr = (((uint64_t) dev->file)<<32) | dev->block_num;
+      uint64_t bsr_addr = get_bsr_start_addr(bsr, &file, &block);
+
+      if (dev_addr > bsr_addr) {
          return false;
       }
-      if (verbose) {
-         Jmsg(jcr, M_INFO, 0, _("Reposition from (file:block) %u:%u to %u:%u\n"),
-            dev->file, dev->block_num, bsr->volfile->sfile,
-            bsr->volblock->sblock);
-      }
       Dmsg4(10, "Try_Reposition from (file:block) %u:%u to %u:%u\n",
-            dev->file, dev->block_num, bsr->volfile->sfile,
-            bsr->volblock->sblock);
-      dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
+            dev->file, dev->block_num, file, block);
+      dev->reposition(dcr, file, block);
       rec->Block = 0;
    }
    return false;
@@ -358,6 +369,7 @@ static BSR *position_to_first_file(JCR *jcr, DCR *dcr)
 {
    BSR *bsr = NULL;
    DEVICE *dev = dcr->dev;
+   uint32_t file, block;
    /*
     * Now find and position to first file and block
     *   on this tape.
@@ -365,11 +377,11 @@ static BSR *position_to_first_file(JCR *jcr, DCR *dcr)
    if (jcr->bsr) {
       jcr->bsr->reposition = true;    /* force repositioning */
       bsr = find_next_bsr(jcr->bsr, dev);
-      if (bsr && (bsr->volfile->sfile != 0 || bsr->volblock->sblock != 0)) {
+      
+      if (get_bsr_start_addr(bsr, &file, &block) > 0) {
          Jmsg(jcr, M_INFO, 0, _("Forward spacing Volume \"%s\" to file:block %u:%u.\n"),
-            dev->VolHdr.VolumeName,
-            bsr->volfile->sfile, bsr->volblock->sblock);
-         dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
+              dev->VolHdr.VolumeName, file, block);
+         dev->reposition(dcr, file, block);
       }
    }
    return bsr;