]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/btape.c
Extend idea of Prefer Mounted Volumes to mean a volume about
[bacula/bacula] / bacula / src / stored / btape.c
index 3bdae65350f146e1967ecd2679068b5545da9857..4f4560475dde3aaf8829076c7e702e3224d26464 100644 (file)
@@ -1,22 +1,7 @@
-/*
- *
- *   Bacula Tape manipulation program
- *
- *    Has various tape manipulation commands -- mostly for
- *    use in determining how tapes really work.
- *
- *     Kern Sibbald, April MM
- *
- *   Note, this program reads stored.conf, and will only
- *     talk to devices that are configured.
- *
- *   Version $Id$
- *
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-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.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Tape manipulation program
+ *
+ *    Has various tape manipulation commands -- mostly for
+ *    use in determining how tapes really work.
+ *
+ *     Kern Sibbald, April MM
+ *
+ *   Note, this program reads stored.conf, and will only
+ *     talk to devices that are configured.
+ *
+ *   Version $Id$
+ *
+ */
 
 #include "bacula.h"
 #include "stored.h"
@@ -355,21 +355,23 @@ static void terminate_btape(int stat)
 static bool open_the_device()
 {
    DEV_BLOCK *block;
+   bool ok = true;
 
    block = new_block(dev);
-   lock_device(dev);
+   dev->r_dlock();
    Dmsg1(200, "Opening device %s\n", dcr->VolumeName);
    if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
       Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
-      unlock_device(dev);
-      free_block(block);
-      return false;
+      ok = false;
+      goto bail_out;
    }
    Pmsg1(000, _("open device %s: OK\n"), dev->print_name());
    dev->set_append();                 /* put volume in append mode */
-   unlock_device(dev);
+
+bail_out:
+   dev->dunlock();
    free_block(block);
-   return true;
+   return ok;
 }
 
 
@@ -1594,7 +1596,7 @@ static void rrcmd()
       len = 1024;
    }
    buf = (char *)malloc(len);
-   stat = read(dev->fd, buf, len);
+   stat = read(dev->fd(), buf, len);
    if (stat > 0 && stat <= len) {
       errno = 0;
    }
@@ -1629,7 +1631,7 @@ static void scancmd()
    tot_files = dev->file;
    Pmsg1(0, _("Starting scan at file %u\n"), dev->file);
    for (;;) {
-      if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) {
+      if ((stat = read(dev->fd(), buf, sizeof(buf))) < 0) {
          berrno be;
          dev->clrerror(-1);
          Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
@@ -2328,7 +2330,7 @@ static int flush_block(DEV_BLOCK *block, int dump)
    DEV_BLOCK *tblock;
    uint32_t this_file, this_block_num;
 
-   lock_device(dev);
+   dev->r_dlock();
    if (!this_block) {
       this_block = new_block(dev);
    }
@@ -2383,12 +2385,12 @@ static int flush_block(DEV_BLOCK *block, int dump)
          if (!fixup_device_block_write_error(jcr->dcr)) {
             Pmsg1(000, _("Cannot fixup device error. %s\n"), dev->bstrerror());
             ok = false;
-            unlock_device(dev);
+            dev->dunlock();
             return 0;
          }
          BlockNumber = 0;             /* start counting for second tape */
       }
-      unlock_device(dev);
+      dev->dunlock();
       return 1;                       /* end of tape reached */
    }
 
@@ -2407,7 +2409,7 @@ static int flush_block(DEV_BLOCK *block, int dump)
    last_file = this_file;
    last_block_num = this_block_num;
 
-   unlock_device(dev);
+   dev->dunlock();
    return 1;
 }
 
@@ -2495,9 +2497,9 @@ static void rawfill_cmd()
    for ( ;; ) {
       *p = block_num;
       if (dev->is_tape()) {
-         stat = tape_write(dev->fd, block->buf, block->buf_len);
+         stat = tape_write(dev->fd(), block->buf, block->buf_len);
       } else {
-         stat = write(dev->fd, block->buf, block->buf_len);
+         stat = write(dev->fd(), block->buf, block->buf_len);
       }
       if (stat == (int)block->buf_len) {
          if ((block_num++ % 100) == 0) {