]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/device.c
Make btape fill/unfill work
[bacula/bacula] / bacula / src / stored / device.c
index 794c32178644a6d64c3446bb253ecd45290d4f58..c7a355b00dc8fe5817f1dbb6e1c40dbc70c48946 100644 (file)
@@ -29,7 +29,7 @@
  *   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
@@ -79,7 +79,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
 
    wait_time = time(NULL);
    status_dev(dev, &stat);
-   if (stat & MT_EOD) {
+   if (stat & BMT_EOD) {
       Dmsg0(100, "======= Got EOD ========\n");
 
       block_device(dev, BST_DOING_ACQUIRE);
@@ -93,8 +93,9 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
          Dmsg1(100, "create JobMedia for Job %s\n", mjcr->Job);
         if (dev->state & ST_TAPE) {
-           mjcr->EndBlock = dev->block_num;
-           mjcr->EndFile = dev->file;
+           mjcr->EndBlock = dev->EndBlock;
+           mjcr->EndFile  = dev->EndFile;
+            Dmsg2(200, "Fixup EndFile=%u EndBlock=%u\n", mjcr->EndFile, mjcr->EndBlock);
         } else {
            mjcr->EndBlock = (uint32_t)dev->file_addr;
            mjcr->EndFile = (uint32_t)(dev->file_addr >> 32);
@@ -106,27 +107,26 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
            unblock_device(dev);
            return 0;
         }
+        mjcr->VolFirstIndex = 0;      /* prevent writing jobmedia second time */
       }
 
       strcpy(dev->VolCatInfo.VolCatStatus, "Full");
-      Dmsg2(100, "Call update_vol_info Stat=%s Vol=%s\n", 
+      Dmsg2(200, "Call update_vol_info Stat=%s Vol=%s\n", 
         dev->VolCatInfo.VolCatStatus, dev->VolCatInfo.VolCatName);
       if (!dir_update_volume_info(jcr, &dev->VolCatInfo, 0)) {   /* send Volume info to Director */
-         Jmsg(jcr, M_ERROR, 0, _("Could not update Volume info Volume=%s Job=%s\n"),
-           dev->VolCatInfo.VolCatName, jcr->Job);
         P(dev->mutex);
         unblock_device(dev);
         return 0;                    /* device locked */
       }
       Dmsg0(100, "Back from update_vol_info\n");
 
-      strcpy(PrevVolName, dev->VolCatInfo.VolCatName);
-      strcpy(dev->VolHdr.PrevVolName, PrevVolName);
+      bstrncpy(PrevVolName, dev->VolCatInfo.VolCatName, sizeof(PrevVolName));
+      bstrncpy(dev->VolHdr.PrevVolName, PrevVolName, sizeof(dev->VolHdr.PrevVolName));
 
       label_blk = new_block(dev);
 
-      /* Inform User about end of media */
-      Jmsg(jcr, M_INFO, 0, _("End of media on Volume %s Bytes=%s Blocks=%s.\n"), 
+      /* Inform User about end of medium */
+      Jmsg(jcr, M_INFO, 0, _("End of medium on Volume \"%s\" Bytes=%s Blocks=%s.\n"), 
           PrevVolName, edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
           edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2));
 
@@ -137,7 +137,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       }
       P(dev->mutex);                 /* lock again */
 
-      Jmsg(jcr, M_INFO, 0, _("New volume %s mounted on device %s\n"),
+      Jmsg(jcr, M_INFO, 0, _("New volume \"%s\" mounted on device %s\n"),
         jcr->VolumeName, dev_name(dev));
 
       /* 
@@ -147,7 +147,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
        *  empty label_blk, and nothing will be written.
        */
       Dmsg0(190, "write label block to dev\n");
-      if (!write_block_to_dev(dev, label_blk)) {
+      if (!write_block_to_dev(jcr, dev, label_blk)) {
          Pmsg1(0, "write_block_to_device Volume label failed. ERR=%s",
           strerror_dev(dev));
         free_block(label_blk);
@@ -157,7 +157,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
 
       /* Write overflow block to tape */
       Dmsg0(190, "Write overflow block to dev\n");
-      if (!write_block_to_dev(dev, block)) {
+      if (!write_block_to_dev(jcr, dev, block)) {
          Pmsg1(0, "write_block_to_device overflow block failed. ERR=%s",
           strerror_dev(dev));
         free_block(label_blk);
@@ -177,7 +177,8 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
            mjcr->StartBlock = (uint32_t)dev->file_addr;
            mjcr->StartFile  = (uint32_t)(dev->file_addr >> 32);
         }
-        mjcr->VolFirstFile = mjcr->JobFiles;
+        /* Set first FirstIndex for new Volume */
+        mjcr->VolFirstIndex = mjcr->JobFiles;
         mjcr->run_time += time(NULL) - wait_time; /* correct run time */
       }
       unblock_device(dev);