]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/bscan.c
Move reservations message lock to lock jcr only this
[bacula/bacula] / bacula / src / stored / bscan.c
index 5cc8781e4496cdd83e2769cd520a670c16f73919..f68ef0429607f8cde924751776783a4f06fe2129 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2001-2007 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.
+   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 and included
+   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.
+*/
 /*
  *
  *  Program to scan a Bacula Volume and compare it with
@@ -9,20 +36,6 @@
  *
  *   Version $Id$
  */
-/*
-   Copyright (C) 2001-2006 Kern Sibbald
-
-   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.
-
-   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.
-
- */
 
 #include "bacula.h"
 #include "stored.h"
@@ -98,7 +111,7 @@ pthread_cond_t wait_device_release = PTHREAD_COND_INITIALIZER;
 static void usage()
 {
    fprintf(stderr, _(
-"Copyright (C) 2001-%s Kern Sibbald.\n"
+PROG_COPYRIGHT
 "\nVersion: %s (%s)\n\n"
 "Usage: bscan [ options ] <bacula-archive>\n"
 "       -b bootstrap      specify a bootstrap file\n"
@@ -116,7 +129,7 @@ static void usage()
 "       -v                verbose\n"
 "       -V <Volumes>      specify Volume names (separated by |)\n"
 "       -w <dir>          specify working directory (default from conf file)\n"
-"       -?                print this message\n\n"), BYEAR, VERSION, BDATE);
+"       -?                print this message\n\n"), 2001, VERSION, BDATE);
    exit(1);
 }
 
@@ -134,6 +147,7 @@ int main (int argc, char *argv[])
    my_name_is(argc, argv, "bscan");
    init_msg(NULL, NULL);
 
+   OSDependentInit();
 
    while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsSu:vV:w:?")) != -1) {
       switch (ch) {
@@ -256,7 +270,7 @@ int main (int argc, char *argv[])
    if (showProgress) {
       char ed1[50];
       struct stat sb;
-      fstat(dev->fd, &sb);
+      fstat(dev->fd(), &sb);
       currentVolumeSize = sb.st_size;
       Pmsg1(000, _("First Volume Size = %sn"), 
          edit_uint64(currentVolumeSize, ed1));
@@ -301,25 +315,26 @@ static bool bscan_mount_next_read_volume(DCR *dcr)
    Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
    foreach_dlist(mdcr, dev->attached_dcrs) {
       JCR *mjcr = mdcr->jcr;
+      Dmsg1(000, "========== JobId=%u ========\n", mjcr->JobId);
       if (mjcr->JobId == 0) {
          continue;
       }
       if (verbose) {
          Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
       }
-      if (dev->is_tape()) {
-         mdcr->EndBlock = dcr->EndBlock;
-         mdcr->EndFile = dcr->EndFile;
-//    } else {
-//       mdcr->EndBlock = (uint32_t)dcr->file_addr;
-//       mdcr->EndFile = (uint32_t)(dcr->file_addr >> 32);
-      }
+      mdcr->StartBlock = dcr->StartBlock;
+      mdcr->StartFile = dcr->StartFile;
+      mdcr->EndBlock = dcr->EndBlock;
+      mdcr->EndFile = dcr->EndFile;
       mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
       if (!create_jobmedia_record(db, mjcr)) {
          Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
             dev->VolCatInfo.VolCatName, mjcr->Job);
       }
    }
+
+   update_media_record(db, &mr);
+
    /* Now let common read routine get up next tape. Note,
     * we call mount_next... with bscan's jcr because that is where we
     * have the Volume list, but we get attached.
@@ -329,7 +344,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr)
    if (showProgress) {
       char ed1[50];
       struct stat sb;
-      fstat(dev->fd, &sb);
+      fstat(dev->fd(), &sb);
       currentVolumeSize = sb.st_size;
       Pmsg1(000, _("First Volume Size = %sn"), 
          edit_uint64(currentVolumeSize, ed1));
@@ -352,6 +367,9 @@ static void do_scan()
 
    read_records(bjcr->read_dcr, record_cb, bscan_mount_next_read_volume);
 
+   if (update_db) {
+      db_write_batch_file_records(bjcr); /* used by bulk batch file insert */
+   }
    free_attr(attr);
 }
 
@@ -873,6 +891,12 @@ static int create_media_record(B_DB *db, MEDIA_DBR *mr, VOLUME_LABEL *vl)
       mr->LabelDate = mktime(&tm);
    }
    lasttime = mr->LabelDate;
+   if (mr->VolJobs == 0) {
+      mr->VolJobs = 1;
+   }
+   if (mr->VolMounts == 0) {
+      mr->VolMounts = 1;
+   }
 
    if (!update_db) {
       return 1;
@@ -1151,15 +1175,8 @@ static int create_jobmedia_record(B_DB *db, JCR *mjcr)
    JOBMEDIA_DBR jmr;
    DCR *dcr = mjcr->read_dcr;
 
-   if (dev->is_tape()) {
-      dcr->EndBlock = dev->EndBlock;
-      dcr->EndFile  = dev->EndFile;
-#ifdef needed
-   } else {
-      dcr->EndBlock = (uint32_t)dev->file_addr;
-      dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
-#endif
-   } 
+   dcr->EndBlock = dev->EndBlock;
+   dcr->EndFile  = dev->EndFile;
 
    memset(&jmr, 0, sizeof(jmr));
    jmr.JobId = mjcr->JobId;
@@ -1244,7 +1261,7 @@ static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId)
    jobjcr->VolSessionId = rec->VolSessionId;
    jobjcr->VolSessionTime = rec->VolSessionTime;
    jobjcr->ClientId = jr->ClientId;
-   jobjcr->read_dcr = new_dcr(jobjcr, dev);
+   jobjcr->dcr = jobjcr->read_dcr = new_dcr(jobjcr, NULL, dev);
 
    return jobjcr;
 }