]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/read_record.c
dhb Added comments for each function. There are questions above
[bacula/bacula] / bacula / src / stored / read_record.c
index 9ca1a1f4ea016c43be800ff3f7e14af18ee39c4e..cb5d026cf4a9aa561c0fb6dbb4e9f6927027c318 100644 (file)
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2002-2006 Free Software Foundation Europe e.V.
 
-   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 
-   the file LICENSE for additional details.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
 
- */
+   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 Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 #include "bacula.h"
 #include "stored.h"
 
 /* Forward referenced functions */
 static void handle_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec);
-static BSR *position_to_first_file(JCR *jcr, DEVICE *dev);
-static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev);
+static BSR *position_to_first_file(JCR *jcr, DCR *dcr);
+static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr);
 #ifdef DEBUG
 static char *rec_state_to_str(DEV_RECORD *rec);
 #endif
@@ -56,7 +69,7 @@ bool read_records(DCR *dcr,
    dlist *recs;                         /* linked list of rec packets open */
 
    recs = New(dlist(rec, &rec->link));
-   position_to_first_file(jcr, dev);
+   position_to_first_file(jcr, dcr);
    jcr->mount_next_volume = false;
 
    for ( ; ok && !done; ) {
@@ -99,24 +112,27 @@ bool read_records(DCR *dcr,
              *  most likely reading the previous record.
              */
             read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK);
-            read_record_from_block(block, trec);
+            read_record_from_block(dcr, block, trec);
             handle_session_record(dev, trec, &sessrec);
             ok = record_cb(dcr, trec);
             free_record(trec);
-            position_to_first_file(jcr, dev);
+            position_to_first_file(jcr, dcr);
             /* After reading label, we must read first data block */
             continue;
 
          } else if (dev->at_eof()) {
             if (verbose) {
-               char dvdpart[100];
+               char *fp;
+               uint32_t fp_num;
                if (dev->is_dvd()) {
-                  bsnprintf(dvdpart, sizeof(dvdpart), _("part %d "), dev->part);
+                  fp = _("part");
+                  fp_num = dev->part;
                } else {
-                  dvdpart[0] = 0;
+                  fp = _("file");
+                  fp_num = dev->file;
                }
-               Jmsg(jcr, M_INFO, 0, _("End of file %u %son device %s, Volume \"%s\"\n"),
-                  dev->file, dvdpart, dev->print_name(), dcr->VolumeName);
+               Jmsg(jcr, M_INFO, 0, _("End of %s %u on device %s, Volume \"%s\"\n"),
+                  fp, fp_num, dev->print_name(), dcr->VolumeName);
             }
             Dmsg3(200, "End of file %u  on device %s, Volume \"%s\"\n",
                   dev->file, dev->print_name(), dcr->VolumeName);
@@ -129,7 +145,7 @@ bool read_records(DCR *dcr,
             display_tape_error_status(jcr, dev);
             if (forge_on || jcr->ignore_label_errors) {
                dev->fsr(1);       /* try skipping bad record */
-               Pmsg0(000, _("Did fsr\n"));
+               Pmsg0(000, _("Did fsr in attemp to skip bad record.\n"));
                continue;              /* try to continue */
             }
             ok = false;               /* stop everything */
@@ -140,7 +156,7 @@ bool read_records(DCR *dcr,
 #ifdef if_and_when_FAST_BLOCK_REJECTION_is_working
       /* this does not stop when file/block are too big */
       if (!match_bsr_block(jcr->bsr, block)) {
-         if (try_repositioning(jcr, rec, dev)) {
+         if (try_repositioning(jcr, rec, dcr)) {
             break;                    /* get next volume */
          }
          continue;                    /* skip this record */
@@ -172,7 +188,7 @@ bool read_records(DCR *dcr,
       rec->state = 0;
       Dmsg1(dbglvl, "Block %s empty\n", is_block_empty(rec)?"is":"NOT");
       for (rec->state=0; ok && !is_block_empty(rec); ) {
-         if (!read_record_from_block(block, rec)) {
+         if (!read_record_from_block(dcr, block, rec)) {
             Dmsg3(400, "!read-break. state=%s blk=%d rem=%d\n", rec_state_to_str(rec),
                   block->BlockNumber, rec->remainder);
             break;
@@ -239,7 +255,7 @@ bool read_records(DCR *dcr,
                   rec->remainder, rec->FileIndex, dev->file, dev->block_num);
                rec->remainder = 0;
                rec->state &= ~REC_PARTIAL_RECORD;
-               if (try_repositioning(jcr, rec, dev)) {
+               if (try_repositioning(jcr, rec, dcr)) {
                   break;
                }
                continue;              /* we don't want record, read next one */
@@ -259,12 +275,12 @@ bool read_records(DCR *dcr,
          /*
           * If we have a digest stream, we check to see if we have 
           *  finished the current bsr, and if so, repositioning will
-          *  be truned on.
+          *  be turned on.
           */
          if (crypto_digest_stream_type(rec->Stream) != CRYPTO_DIGEST_NONE) {
             Dmsg3(dbglvl, "Have digest FI=%u before bsr check pos %u:%u\n", rec->FileIndex,
                   dev->file, dev->block_num);
-            if (is_this_bsr_done(jcr->bsr, rec) && try_repositioning(jcr, rec, dev)) {
+            if (is_this_bsr_done(jcr->bsr, rec) && try_repositioning(jcr, rec, dcr)) {
                Dmsg2(dbglvl, "This bsr done, break pos %u:%u\n",
                      dev->file, dev->block_num);
                break;
@@ -292,9 +308,11 @@ bool read_records(DCR *dcr,
  *   Returns:  true  if at end of volume
  *             false otherwise
  */
-static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev)
+static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr)
 {
    BSR *bsr;
+   DEVICE *dev = dcr->dev;
+
    bsr = find_next_bsr(jcr->bsr, dev);
    if (bsr == NULL && jcr->bsr->mount_next_volume) {
       Dmsg0(dbglvl, "Would mount next volume here\n");
@@ -310,15 +328,24 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev)
       return true;
    }
    if (bsr) {
+      /*
+       * ***FIXME*** gross kludge to make disk seeking work.  Remove
+       *   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)) {
+         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(dbglvl, "Try_Reposition from (file:block) %u:%u to %u:%u\n",
+      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(bsr->volfile->sfile, bsr->volblock->sblock);
+      dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
       rec->Block = 0;
    }
    return false;
@@ -327,9 +354,10 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev)
 /*
  * Position to the first file on this volume
  */
-static BSR *position_to_first_file(JCR *jcr, DEVICE *dev)
+static BSR *position_to_first_file(JCR *jcr, DCR *dcr)
 {
    BSR *bsr = NULL;
+   DEVICE *dev = dcr->dev;
    /*
     * Now find and position to first file and block
     *   on this tape.
@@ -338,11 +366,10 @@ static BSR *position_to_first_file(JCR *jcr, DEVICE *dev)
       jcr->bsr->reposition = true;    /* force repositioning */
       bsr = find_next_bsr(jcr->bsr, dev);
       if (bsr && (bsr->volfile->sfile != 0 || bsr->volblock->sblock != 0)) {
-         Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"),
-            bsr->volfile->sfile, bsr->volblock->sblock);
-         Dmsg2(dbglvl, "Forward spacing to file:block %u:%u.\n",
+         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(bsr->volfile->sfile, bsr->volblock->sblock);
+         dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
       }
    }
    return bsr;