]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/read_record.c
Add V: to bextract and bscan
[bacula/bacula] / bacula / src / stored / read_record.c
index 4720fce987206b1abad5d478a7bea1728ede3fa5..92930f15629bb334f6d3acbf51dc2267d997ead7 100644 (file)
@@ -6,10 +6,12 @@
  *    as well as a callback for mounting the next tape.  It takes
  *    care of reading blocks, applying the bsr, ...
  *
+ *    Kern E. Sibbald, August MMII
+ *
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 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
@@ -32,8 +34,9 @@
 #include "stored.h"
 
 static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec);
+#ifdef DEBUG
 static char *rec_state_to_str(DEV_RECORD *rec);
-
+#endif
 
 int read_records(JCR *jcr,  DEVICE *dev, 
        void record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec),
@@ -42,27 +45,41 @@ int read_records(JCR *jcr,  DEVICE *dev,
    DEV_BLOCK *block;
    DEV_RECORD *rec;
    uint32_t record, num_files = 0;
-   int verbose = FALSE;
    int ok = TRUE;
+   int done = FALSE;
    SESSION_LABEL sessrec;
 
    block = new_block(dev);
    rec = new_record();
-   for ( ;ok; ) {
-      if (job_cancelled(jcr)) {
+   for ( ; ok && !done; ) {
+      if (job_canceled(jcr)) {
         ok = FALSE;
         break;
       }
-      if (!read_block_from_device(dev, block)) {
+      if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) {
          Dmsg0(20, "!read_record()\n");
         if (dev->state & ST_EOT) {
-           DEV_RECORD *record;
+           DEV_RECORD *trec = new_record();
+
             Dmsg3(100, "EOT. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
                  block->BlockNumber, rec->remainder);
+            Jmsg(jcr, M_INFO, 0, "Got EOM at file %u  on device %s, Volume \"%s\"\n", 
+                dev->file, dev_name(dev), jcr->VolumeName);
            if (!mount_cb(jcr, dev, block)) {
+               Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
                Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
                  block->BlockNumber, rec->remainder);
               ok = FALSE;
+              /*
+               * Create EOT Label so that Media record may
+               *  be properly updated because this is the last
+               *  tape.
+               */
+              trec->FileIndex = EOT_LABEL;
+              trec->File = dev->file;
+              trec->Block = rec->Block; /* return block last read */
+              record_cb(jcr, dev, block, trec);
+              free_record(trec);
               break;
            }
             Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
@@ -72,29 +89,37 @@ int read_records(JCR *jcr,  DEVICE *dev,
             *  and pass it off to the callback routine, then continue
             *  most likely reading the previous record.
             */
-           record = new_record();
-           read_block_from_device(dev, block);
-           read_record_from_block(block, record);
-           get_session_record(dev, record, &sessrec);
-           record_cb(jcr, dev, block, record);
-           free_record(record);
-           goto next_record;
-        }
-        if (dev->state & ST_EOF) {
-            Emsg1(M_INFO, 0, "Got EOF on device %s\n", dev_name(dev));
+           read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK);
+           read_record_from_block(block, trec);
+           get_session_record(dev, trec, &sessrec);
+           record_cb(jcr, dev, block, trec);
+           free_record(trec);
+           goto next_record;         /* go read new tape */
+
+        } else if (dev->state & ST_EOF) {
+            Jmsg(jcr, M_INFO, 0, "Got EOF at file %u  on device %s, Volume \"%s\"\n", 
+                 dev->file, dev_name(dev), jcr->VolumeName);
             Dmsg0(20, "read_record got eof. try again\n");
            continue;
-        }
-        if (dev->state & ST_SHORT) {
-           Emsg0(M_INFO, 0, dev->errmsg);
+        } else if (dev->state & ST_SHORT) {
+            Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
            continue;
+        } else {
+           /* I/O error or strange end of tape */
+           display_tape_error_status(jcr, dev);
+           ok = FALSE;
+           break;
         }
-//      display_error_status();
-        ok = FALSE;
-        break;
+      }
+      if (!match_bsr_block(jcr->bsr, block)) {
+         Dmsg5(100, "reject Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
+           block->BlockNumber, block->block_len, block->BlockVer,
+           block->VolSessionId, block->VolSessionTime);
+        continue;
       }
       if (verbose) {
-         Dmsg2(10, "Block: %d blen=%d\n", block->BlockNumber, block->block_len);
+         Dmsg4(000, "Block: %d VI=%u VT=%u blen=%d\n", block->BlockNumber, 
+           block->VolSessionId, block->VolSessionTime, block->block_len);
       }
 
 next_record:
@@ -121,7 +146,8 @@ next_record:
         }
         if (debug_level >= 30) {
             Dmsg4(30, "VolSId=%ld FI=%s Strm=%s Size=%ld\n", rec->VolSessionId,
-                 FI_to_ascii(rec->FileIndex), stream_to_ascii(rec->Stream), 
+                 FI_to_ascii(rec->FileIndex), 
+                 stream_to_ascii(rec->Stream, rec->FileIndex), 
                  rec->data_len);
         }
 
@@ -141,14 +167,20 @@ next_record:
         /* 
          * Apply BSR filter
          */
-        if (jcr->bsr && !match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec)) {
-           if (verbose) {
-               Dmsg5(10, "BSR no match rec=%d block=%d SessId=%d SessTime=%d FI=%d\n",
-                 record, block->BlockNumber, rec->VolSessionId, rec->VolSessionTime, 
-                 rec->FileIndex);
+        if (jcr->bsr) {
+           int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
+           if (stat == -1) { /* no more possible matches */
+              done = TRUE;   /* all items found, stop */
+              break;
+           } else if (stat == 0) {  /* no match */
+              if (verbose) {
+                  Dmsg5(10, "BSR no match rec=%d block=%d SessId=%d SessTime=%d FI=%d\n",
+                    record, block->BlockNumber, rec->VolSessionId, rec->VolSessionTime, 
+                    rec->FileIndex);
+              }
+              rec->remainder = 0;
+               continue;              /* we don't want record, read next one */
            }
-           rec->remainder = 0;
-            continue;              /* we don't want record, read next one */
         }
         if (is_partial_record(rec)) {
             Dmsg6(10, "Partial, break. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
@@ -157,7 +189,6 @@ next_record:
            break;                    /* read second part of record */
         }
         record_cb(jcr, dev, block, rec);
-
       }
    }
    if (verbose) {
@@ -199,6 +230,7 @@ static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sess
         rtype, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len);
 }
 
+#ifdef DEBUG
 static char *rec_state_to_str(DEV_RECORD *rec)
 {
    static char buf[200]; 
@@ -223,3 +255,4 @@ static char *rec_state_to_str(DEV_RECORD *rec)
    }
    return buf;
 }
+#endif