]> git.sur5r.net Git - bacula/bacula/commitdiff
- Fix the same state variable problem in open_next_part().
authorKern Sibbald <kern@sibbald.com>
Tue, 14 Jun 2005 13:18:43 +0000 (13:18 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 14 Jun 2005 13:18:43 +0000 (13:18 +0000)
- C++ify the SD code a bit more.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2124 91ce42f0-d328-0410-95d8-f526ca767f89

19 files changed:
bacula/kes-1.37
bacula/src/stored/acquire.c
bacula/src/stored/ansi_label.c
bacula/src/stored/block.c
bacula/src/stored/bls.c
bacula/src/stored/butil.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/device.c
bacula/src/stored/dircmd.c
bacula/src/stored/dvd.c
bacula/src/stored/job.c
bacula/src/stored/label.c
bacula/src/stored/mount.c
bacula/src/stored/protos.h
bacula/src/stored/read_record.c
bacula/src/stored/reserve.c
bacula/src/stored/stored.c
bacula/src/stored/wait.c

index 12aec23491d79c707ae3ea7e1cce767ad7eb323e..06179ac46fb524d4a44d0c4524950f4320170cb2 100644 (file)
@@ -4,6 +4,9 @@
 General:
 
 Changes to 1.37.22:
+14Jun05
+- Fix the same state variable problem in open_next_part().
+- C++ify the SD code a bit more.
 13Jun05
 - Add more debug code and clarify debug code for DVDs.
 - Do not save and restore state in open_first_part() 
index a9e676dcdc3641671ffc013419b90fdeeb1deb27..33b72883690a72bda40b6194fe49fe157adc9cc5 100644 (file)
@@ -212,7 +212,7 @@ DCR *acquire_device_for_read(DCR *dcr)
       }
       
       if (dev->is_dvd()) {
-         vol_label_status = read_dev_volume_label_guess(dcr, 0);
+         vol_label_status = read_dvd_volume_label(dcr, /*read*/false);
       } else {
          vol_label_status = read_dev_volume_label(dcr);
       }
index 09370935d8d42cfc2d2e3cb5e37fd02add4250b2..e47f6645faf199840acb27bcfbcaeb92f5adf4b8 100644 (file)
@@ -88,12 +88,12 @@ int read_ansi_ibm_label(DCR *dcr)
       }
       if (stat == 0) {
          if (dev->at_eof()) {
-            dev->state |= ST_EOT;
+            dev->set_eot();           /* second eof, set eot bit */
             Dmsg0(100, "EOM on ANSI label\n");
             Mmsg0(jcr->errmsg, _("Insane! End of tape while reading ANSI label.\n"));
             return VOL_LABEL_ERROR;   /* at EOM this shouldn't happen */
          } else {
-            dev->set_eof();
+            dev->set_ateof();        /* set eof state */
          }
       }
       switch (i) {
index 4bab4b0a78e007af32a659421f2ec25dd4a05e3c..f69dc097e62b936aae153d29156e2bb2b05f5441 100644 (file)
@@ -403,7 +403,7 @@ bool write_block_to_dev(DCR *dcr)
    ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf)));
 
    /* dump_block(block, "before write"); */
-   if (dev->state & ST_WEOT) {
+   if (dev->at_weot()) {
       Dmsg0(100, "return write_block_to_dev with ST_WEOT\n");
       dev->dev_errno = ENOSPC;
       Jmsg(jcr, M_FATAL, 0,  _("Cannot write block. Device at EOM.\n"));
@@ -718,7 +718,7 @@ static bool terminate_writing_volume(DCR *dcr)
       Jmsg(dcr->jcr, M_ERROR, 0, "%s", dev->errmsg);
    }
 bail_out:
-   dev->set_eot();                    /* no more writing this tape */
+   dev->set_ateot();                  /* no more writing this tape */
    Dmsg1(100, "Leave terminate_writing_volume -- %s\n", ok?"OK":"ERROR");
    return ok;
 }
@@ -777,8 +777,10 @@ static bool do_dvd_size_checks(DCR *dcr)
    JCR *jcr = dcr->jcr;
    DEV_BLOCK *block = dcr->block;
 
-   /* Limit maximum part size to value specified by user (not applicable to tapes/fifos) */
-   if (!(dev->state & (ST_TAPE|ST_FIFO)) && dev->max_part_size > 0 &&
+   /* Limit maximum part size to value specified by user 
+    * (not applicable to tapes/fifos)   
+    */
+   if (!(dev->is_tape() || dev->is_fifo()) && dev->max_part_size > 0 &&
         (dev->part_size + block->binbuf) >= dev->max_part_size) {
       if (dev->part < dev->num_parts) {
          Jmsg3(dcr->jcr, M_FATAL, 0, _("Error while writing, current part number is less than the total number of parts (%d/%d, device=%s)\n"),
@@ -921,7 +923,7 @@ reread:
          dev->file, dev->block_num, dev->dev_name, be.strerror());
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       if (dev->at_eof()) {        /* EOF just seen? */
-         dev->state |= ST_EOT;    /* yes, error => EOT */
+         dev->set_eot();          /* yes, error => EOT */
       }
       return false;
    }
@@ -933,10 +935,10 @@ reread:
       Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
          dev->file, dev->block_num, dev->dev_name);
       if (dev->at_eof()) {       /* EOF already read? */
-         dev->state |= ST_EOT;  /* yes, 2 EOFs => EOT */
+         dev->set_eot();         /* yes, 2 EOFs => EOT */
          return 0;
       }
-      dev->set_eof();
+      dev->set_ateof();
       return false;             /* return eof */
    }
    /* Continue here for successful read */
@@ -946,7 +948,7 @@ reread:
       Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"),
          dev->file, dev->block_num, block->read_len, dev->dev_name);
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
-      dev->state |= ST_SHORT;   /* set short block */
+      dev->set_short_block();   
       block->read_len = block->binbuf = 0;
       return false;             /* return error */
    }
@@ -1005,12 +1007,13 @@ reread:
       Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Short block of %d bytes on device %s discarded.\n"),
          dev->file, dev->block_num, block->read_len, dev->dev_name);
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
-      dev->state |= ST_SHORT;   /* set short block */
+      dev->set_short_block();
       block->read_len = block->binbuf = 0;
       return false;             /* return error */
    }
 
-   dev->state &= ~(ST_EOF|ST_SHORT); /* clear EOF and short block */
+   dev->clear_short_block();
+   dev->clear_eof();
    dev->VolCatInfo.VolCatReads++;
    dev->VolCatInfo.VolCatRBytes += block->read_len;
 
index 9a72866e4c79d0e187d848903c6081c13831b0c1..4363a7c7f7ead3d215ea6929691cf955b36be53e 100644 (file)
@@ -278,7 +278,7 @@ static void do_blocks(char *infname)
                dev->file, dev->print_name(), dcr->VolumeName);
             Dmsg0(20, "read_record got eof. try again\n");
             continue;
-         } else if (dev->state & ST_SHORT) {
+         } else if (dev->is_short_block()) {
             Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
             continue;
          } else {
index 786b6bdad1b4471d487dcb0c908cb1967a484588..eaa36462a45c4da692dc9b95c552e41467e20f2a 100644 (file)
@@ -147,7 +147,7 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name,
       return NULL;
    }
 
-   dev = init_dev(jcr, NULL, device);
+   dev = init_dev(jcr, device);
    if (!dev) {
       Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name);
       return NULL;
index d173a932ea30722a72c17abf90757fd9a03f2efb..62e74eb9a4dab8681732235eec41a5f1a194d6e4 100644 (file)
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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 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., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -109,19 +104,17 @@ static void open_file_device(DEVICE *dev, int mode);
  *
  */
 DEVICE *
-init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
+init_dev(JCR *jcr, DEVRES *device)
 {
    struct stat statp;
    bool tape, fifo;
    int errstat;
    DCR *dcr = NULL;
+   DEVICE *dev;
 
    /* Check that device is available */
    if (stat(device->device_name, &statp) < 0) {
       berrno be;
-      if (dev) {
-         dev->dev_errno = errno;
-      }
       Jmsg2(jcr, M_ERROR, 0, _("Unable to stat device %s: ERR=%s\n"), 
          device->device_name, be.strerror());
       return NULL;
@@ -137,20 +130,14 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
    } else if (S_ISFIFO(statp.st_mode)) {
       fifo = true;
    } else if (!(device->cap_bits & CAP_REQMOUNT)) {
-      if (dev) {
-         dev->dev_errno = ENODEV;
-      }
       Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory. st_mode=%x\n"),
          device->device_name, statp.st_mode);
       return NULL;
    }
-   if (!dev) {
-      dev = (DEVICE *)get_memory(sizeof(DEVICE));
-      memset(dev, 0, sizeof(DEVICE));
-      dev->state = ST_MALLOC;
-   } else {
-      memset(dev, 0, sizeof(DEVICE));
-   }
+
+   dev = (DEVICE *)get_memory(sizeof(DEVICE));
+   memset(dev, 0, sizeof(DEVICE));
+   dev->state = ST_MALLOC;
 
    /* Copy user supplied device parameters from Resource */
    dev->dev_name = get_memory(strlen(device->device_name)+1);
@@ -566,9 +553,9 @@ void DEVICE::unblock()
  * Called to indicate that we have just read an
  *  EOF from the device.
  */
-void DEVICE::set_eof() 
+void DEVICE::set_ateof() 
 { 
-   state |= ST_EOF;
+   set_eof();
    file++;
    file_addr = 0;
    file_size = 0;
@@ -579,10 +566,11 @@ void DEVICE::set_eof()
  * Called to indicate we are now at the end of the tape, and
  *   writing is not possible.
  */
-void DEVICE::set_eot() 
+void DEVICE::set_ateot() 
 {
+   /* Make tape effectively read-only */
    state |= (ST_EOF|ST_EOT|ST_WEOT);
-   state &= ~ST_APPEND;          /* make tape read-only */
+   clear_append();
 }
 
 /*
@@ -679,7 +667,7 @@ eod_dev(DEVICE *dev)
          return false;
       }
       Dmsg2(100, "EOD file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
-      dev->set_eof();
+      dev->set_ateof();
       dev->file = mt_stat.mt_fileno;
    } else {
 #else
@@ -710,7 +698,7 @@ eod_dev(DEVICE *dev)
             Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num);
             if (dev_get_os_pos(dev, &mt_stat)) {
                Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
-               dev->set_eof();
+               dev->set_ateof();
                dev->file = mt_stat.mt_fileno;
             }
             return false;
@@ -1025,7 +1013,7 @@ fsf_dev(DEVICE *dev, int num)
          return false;
       }
       Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
-      dev->set_eof();
+      dev->set_ateof();
       dev->file = mt_stat.mt_fileno;
       return true;
 
@@ -1074,7 +1062,7 @@ fsf_dev(DEVICE *dev, int num)
                Dmsg0(100, "Set ST_EOT\n");
                break;
             } else {
-               dev->set_eof();
+               dev->set_ateof();
                continue;
             }
          } else {                        /* Got data */
@@ -1093,7 +1081,7 @@ fsf_dev(DEVICE *dev, int num)
             Dmsg0(100, "Got < 0 for MTFSF\n");
             Dmsg1(100, "%s", dev->errmsg);
          } else {
-            dev->set_eof();
+            dev->set_ateof();
          }
       }
       free_memory(rbuf);
@@ -1210,9 +1198,9 @@ bool DEVICE::fsr(int num)
          block_num = mt_stat.mt_blkno;
       } else {
          if (at_eof()) {
-            state |= ST_EOT;
+            set_eot();
          } else {
-            set_eof();
+            set_ateof();
          }
       }
       Mmsg3(errmsg, _("ioctl MTFSR %d error on %s. ERR=%s.\n"),
index 689f1a40b66cd53b710cfe432ed1c72de86b5922..7c2c32838211e165966c9ccbb3fb414cadce4348 100644 (file)
@@ -254,6 +254,8 @@ public:
    int is_open() const { return state & ST_OPENED; }
    int is_offline() const { return state & ST_OFFLINE; }
    int is_labeled() const { return state & ST_LABEL; }
+   int is_mounted() const { return state & ST_MOUNTED; }
+   int is_short_block() const { return state & ST_SHORT; }
    int is_busy() const { return state & ST_READ || num_writers || reserved_device; }
    int at_eof() const { return state & ST_EOF; }
    int at_eot() const { return state & ST_EOT; }
@@ -282,21 +284,34 @@ public:
    const char *archive_name() const;
    const char *name() const;
    const char *print_name() const;    /* Name for display purposes */
-   void set_eof(); /* in dev.c */
-   void set_eot(); /* in dev.c */
+   void set_ateof(); /* in dev.c */
+   void set_ateot(); /* in dev.c */
+   void set_eot() { state |= ST_EOT; };
+   void set_eof() { state |= ST_EOF; };
    void set_append() { state |= ST_APPEND; };
    void set_labeled() { state |= ST_LABEL; };
    void set_read() { state |= ST_READ; };
    void set_offline() { state |= ST_OFFLINE; };
+   void set_opened() { state |= ST_OPENED; };
+   void set_mounted() { state |= ST_MOUNTED; };
+   void set_short_block() { state |= ST_SHORT; };
+   void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
+          else state &= ~ST_MOUNTED; };
    void clear_append() { state &= ~ST_APPEND; };
    void clear_read() { state &= ~ST_READ; };
    void clear_labeled() { state &= ~ST_LABEL; };
    void clear_offline() { state &= ~ST_OFFLINE; };
    void clear_eot() { state &= ~ST_EOT; };
    void clear_eof() { state &= ~ST_EOF; };
+   void clear_opened() { state &= ~ST_OPENED; };
+   void clear_mounted() { state &= ~ST_MOUNTED; };
+   void clear_short_block() { state &= ~ST_SHORT; };
    void block(int why); /* in dev.c */
    void unblock();      /* in dev.c */
    void close();        /* in dev.c */
+
+   void set_blocked(int block) { dev_blocked = block; };
+   int  get_blocked() const { return dev_blocked; };
 };
 
 /* Note, these return int not bool! */
index 097c353d443cacfffdd8db57ead696ce0afc15a9..eb4055e70b5bb3c406dfc2aa7e2f145f0d1d4a64 100644 (file)
@@ -188,7 +188,7 @@ void set_new_volume_parameters(DCR *dcr)
       Jmsg1(jcr, M_ERROR, 0, "%s", jcr->errmsg);
    }
    /* Set new start/end positions */
-   if (dev_state(dev, ST_TAPE)) {
+   if (dev->is_tape()) {
       dcr->StartBlock = dev->block_num;
       dcr->StartFile = dev->file;
    } else {
@@ -213,7 +213,7 @@ void set_new_file_parameters(DCR *dcr)
    DEVICE *dev = dcr->dev;
 
    /* Set new start/end positions */
-   if (dev_state(dev, ST_TAPE)) {
+   if (dev->is_tape()) {
       dcr->StartBlock = dev->block_num;
       dcr->StartFile = dev->file;
    } else {
@@ -425,8 +425,8 @@ void _unlock_device(const char *file, int line, DEVICE *dev)
 void _block_device(const char *file, int line, DEVICE *dev, int state)
 {
    Dmsg3(500, "block set %d from %s:%d\n", state, file, line);
-   ASSERT(dev->dev_blocked == BST_NOT_BLOCKED);
-   dev->dev_blocked = state;          /* make other threads wait */
+   ASSERT(dev->get_blocked() == BST_NOT_BLOCKED);
+   dev->set_blocked(state);           /* make other threads wait */
    dev->no_wait_id = pthread_self();  /* allow us to continue */
 }
 
@@ -439,7 +439,7 @@ void _unblock_device(const char *file, int line, DEVICE *dev)
 {
    Dmsg3(500, "unblock %d from %s:%d\n", dev->dev_blocked, file, line);
    ASSERT(dev->dev_blocked);
-   dev->dev_blocked = BST_NOT_BLOCKED;
+   dev->set_blocked(BST_NOT_BLOCKED);
    dev->no_wait_id = 0;
    if (dev->num_waiting > 0) {
       pthread_cond_broadcast(&dev->wait); /* wake them up */
@@ -454,10 +454,10 @@ void _steal_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *
 {
    Dmsg4(500, "steal lock. old=%d new=%d from %s:%d\n", dev->dev_blocked, state,
       file, line);
-   hold->dev_blocked = dev->dev_blocked;
+   hold->dev_blocked = dev->get_blocked();
    hold->dev_prev_blocked = dev->dev_prev_blocked;
    hold->no_wait_id = dev->no_wait_id;
-   dev->dev_blocked = state;
+   dev->set_blocked(state);
    dev->no_wait_id = pthread_self();
    V(dev->mutex);
 }
index 258773ed20a553999d292a397f25da13f1697b82..762e54ab49d1c13f891b370925a0f6454c15f8b9 100644 (file)
@@ -380,7 +380,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
 
    /* See what we have for a Volume */
    if (dev->is_dvd()) {
-      label_status = read_dev_volume_label_guess(dcr, 1);
+      label_status = read_dvd_volume_label(dcr, /*write*/true);
    } else {
       label_status = read_dev_volume_label(dcr);
    }
@@ -476,7 +476,7 @@ static DEVICE *find_device(JCR *jcr, POOL_MEM &devname)
       /* Find resource, and make sure we were able to open it */
       if (fnmatch(device->hdr.name, devname.c_str(), 0) == 0) {
          if (!device->dev) {
-            device->dev = init_dev(jcr, NULL, device);
+            device->dev = init_dev(jcr, device);
          }
          if (!device->dev) {
             Jmsg(jcr, M_WARNING, 0, _("\n"
@@ -496,7 +496,7 @@ static DEVICE *find_device(JCR *jcr, POOL_MEM &devname)
          foreach_alist(device, changer->device) {
             Dmsg1(100, "Try changer device %s\n", device->hdr.name);
             if (!device->dev) {
-               device->dev = init_dev(jcr, NULL, device);
+               device->dev = init_dev(jcr, device);
             }
             if (!device->dev) {
                Dmsg1(100, "Device %s could not be opened. Skipped\n", devname.c_str());
index 85848208626059aab442170995f7b011a7576fef..221772af683e48bba910fe7053831e9dfe6b03a3 100644 (file)
@@ -78,7 +78,7 @@ void get_filename(DEVICE *dev, char *VolName, POOL_MEM& archive_name)
  */
 int mount_dev(DEVICE* dev, int timeout) 
 {
-   if (dev->state & ST_MOUNTED) {
+   if (dev->is_mounted()) {
       Dmsg0(100, "mount_dev: Device already mounted\n");
       return 0;
    } else if (dev_cap(dev, CAP_REQMOUNT)) {
@@ -93,7 +93,7 @@ int mount_dev(DEVICE* dev, int timeout)
  */
 int unmount_dev(DEVICE *dev, int timeout) 
 {
-   if (dev->state & ST_MOUNTED) {
+   if (dev->is_mounted()) {
       return do_mount_dev(dev, 0, timeout);
    }
    Dmsg0(100, "mount_dev: Device already unmounted\n");
@@ -101,7 +101,8 @@ int unmount_dev(DEVICE *dev, int timeout)
 }
 
 /* (Un)mount the device */
-static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
+static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) 
+{
    POOL_MEM ocmd(PM_FNAME);
    POOLMEM* results;
    results = get_pool_memory(PM_MESSAGE);
@@ -117,7 +118,7 @@ static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
    
    edit_device_codes_dev(dev, ocmd.c_str(), icmd);
    
-   Dmsg2(29, "do_mount_dev: cmd=%s state=%d\n", ocmd.c_str(), dev->state & ST_MOUNTED);
+   Dmsg2(29, "do_mount_dev: cmd=%s state=%d\n", ocmd.c_str(), dev->is_mounted());
 
    if (dotimeout) {
       /* Try at most 5 times to (un)mount the device. This should perhaps be configurable. */
@@ -127,7 +128,8 @@ static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
       timeout = 0;
    }
    /* If busy retry each second */
-   while ((status = run_program_full_output(ocmd.c_str(), dev->max_open_wait/2, results)) != 0) {
+   while ((status = run_program_full_output(ocmd.c_str(), 
+                       dev->max_open_wait/2, results)) != 0) {
       if (--timeout > 0) {
          Dmsg2(40, "Device %s cannot be (un)mounted. Retrying... ERR=%s\n", dev->dev_name, results);
          /* Sometimes the device cannot be mounted because it is already mounted.
@@ -144,28 +146,28 @@ static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
       return -1;
    }
    
-   if (mount) {
-     dev->state |= ST_MOUNTED;
-   } else {
-     dev->state &= ~ST_MOUNTED;
-   }
+   dev->set_mounted(mount);              /* set/clear mounted flag */
+
    free_pool_memory(results);
    
-   Dmsg1(29, "do_mount_dev: end_state=%d\n", dev->state & ST_MOUNTED);
+   Dmsg1(29, "do_mount_dev: end_state=%d\n", dev->is_mounted());
    return 0;
 }
 
 /* Only for devices that require a mount.
- * Try to find the volume name of the loaded device, and open the
+ * Try to find the Volume name of the loaded device, and open the
  * first part of this volume. 
  *
  * Returns 0 if read_dev_volume_label can now read the label,
- * -1 if an error occured, and read_dev_volume_label_guess must abort with an IO_ERROR.
+ *        -1 if an error occured,  and read_dvd_volume_label
+ *            must abort with an IO_ERROR.
+ *
+ * To find the Volume name, it lists all the files on the DVD,
+ * and searches for a file which has a minimum size (500 bytes).
+ * If this file has a numeric extension, like part files, try to
+ * open the file which has no extension (e.g.  the first part
+ * file).
  *
- * To guess the device name, it lists all the files on the DVD, and searches for a 
- * file which has a minimum size (500 bytes). If this file has a numeric extension,
- * like part files, try to open the file which has no extension (e.g. the first
- * part file).
  * So, if the DVD does not contains a Bacula volume, a random file is opened,
  * and no valid label could be read from this file.
  *
@@ -173,12 +175,12 @@ static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
  * the label name of the current volume. We can also check that the currently
  * mounted disk is writable. (See also read_dev_volume_label_guess in label.c).
  *
- * Note that if the right volume is mounted, open_guess_name_dev returns the same
- * result as an usual open_dev.
+ * Note that if the right volume is mounted, open_mounted_dev returns 
+ *  the same result as an usual open_dev.
  */
-int open_guess_name_dev(DEVICE *dev) 
+int open_mounted_dev(DEVICE *dev) 
 {
-   Dmsg1(29, "open_guess_name_dev: dev=%s\n", dev->dev_name);
+   Dmsg1(29, "open_mounted_dev: dev=%s\n", dev->dev_name);
    POOL_MEM guessedname(PM_FNAME);
    DIR* dp;
    struct dirent *entry, *result;
@@ -187,12 +189,12 @@ int open_guess_name_dev(DEVICE *dev)
    int name_max;
    
    if (!dev->is_dvd()) {
-      Dmsg1(100, "open_guess_name_dev: device does not require mount, returning 0. dev=%s\n", dev->dev_name);
+      Dmsg1(100, "open_mounted_dev: device does not require mount, returning 0. dev=%s\n", dev->dev_name);
       return 0;
    }
 
 #ifndef HAVE_DIRENT_H
-   Dmsg0(29, "open_guess_name_dev: readdir not available, cannot guess volume name\n");
+   Dmsg0(29, "open_mounted_dev: readdir not available, cannot guess volume name\n");
    return 0; 
 #endif
    
@@ -201,10 +203,10 @@ int open_guess_name_dev(DEVICE *dev)
    if (mount_dev(dev, 1) < 0) {
       /* If the device cannot be mounted, check if it is writable */
       if (dev->free_space_errno >= 0) {
-         Dmsg1(100, "open_guess_name_dev: device cannot be mounted, but it seems to be writable, returning 0. dev=%s\n", dev->dev_name);
+         Dmsg1(100, "open_mounted_dev: device cannot be mounted, but it seems to be writable, returning 0. dev=%s\n", dev->dev_name);
          return 0;
       } else {
-         Dmsg1(100, "open_guess_name_dev: device cannot be mounted, and is not writable, returning -1. dev=%s\n", dev->dev_name);
+         Dmsg1(100, "open_mounted_dev: device cannot be mounted, and is not writable, returning -1. dev=%s\n", dev->dev_name);
          return -1;
       }
    }
@@ -217,7 +219,7 @@ int open_guess_name_dev(DEVICE *dev)
    if (!(dp = opendir(dev->device->mount_point))) {
       berrno be;
       dev->dev_errno = errno;
-      Dmsg3(29, "open_guess_name_dev: failed to open dir %s (dev=%s), ERR=%s\n", dev->device->mount_point, dev->dev_name, be.strerror());
+      Dmsg3(29, "open_mounted_dev: failed to open dir %s (dev=%s), ERR=%s\n", dev->device->mount_point, dev->dev_name, be.strerror());
       return -1;
    }
    
@@ -225,7 +227,7 @@ int open_guess_name_dev(DEVICE *dev)
    while (1) {
       if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
          dev->dev_errno = ENOENT;
-         Dmsg2(29, "open_guess_name_dev: failed to find suitable file in dir %s (dev=%s)\n", dev->device->mount_point, dev->dev_name);
+         Dmsg2(29, "open_mounted_dev: failed to find suitable file in dir %s (dev=%s)\n", dev->device->mount_point, dev->dev_name);
          closedir(dp);
          return -1;
       }
@@ -244,13 +246,13 @@ int open_guess_name_dev(DEVICE *dev)
       
       if (stat(guessedname.c_str(), &statp) < 0) {
          berrno be;
-         Dmsg3(29, "open_guess_name_dev: failed to stat %s (dev=%s), ERR=%s\n",
+         Dmsg3(29, "open_mounted_dev: failed to stat %s (dev=%s), ERR=%s\n",
                guessedname.c_str(), dev->dev_name, be.strerror());
          continue;
       }
       
       if (!S_ISREG(statp.st_mode) || (statp.st_size < 500)) {
-         Dmsg2(100, "open_guess_name_dev: %s is not a regular file, or less than 500 bytes (dev=%s)\n", 
+         Dmsg2(100, "open_mounted_dev: %s is not a regular file, or less than 500 bytes (dev=%s)\n", 
                guessedname.c_str(), dev->dev_name);
          continue;
       }
@@ -271,7 +273,7 @@ int open_guess_name_dev(DEVICE *dev)
       if ((stat(guessedname.c_str(), &statp) < 0) || (statp.st_size < 500)) {
          /* The file with extension truncated does not exists or is too small, so use it with its extension. */
          berrno be;
-         Dmsg3(100, "open_guess_name_dev: failed to stat %s (dev=%s), using the file with its extension, ERR=%s\n", 
+         Dmsg3(100, "open_mounted_dev: failed to stat %s (dev=%s), using the file with its extension, ERR=%s\n", 
                guessedname.c_str(), dev->dev_name, be.strerror());
          pm_strcpy(guessedname, dev->device->mount_point);
          if (guessedname.c_str()[strlen(guessedname.c_str())-1] != '/') {
@@ -292,7 +294,7 @@ int open_guess_name_dev(DEVICE *dev)
    if ((dev->fd = open(guessedname.c_str(), O_RDONLY | O_BINARY)) < 0) {
       berrno be;
       dev->dev_errno = errno;
-      Dmsg3(29, "open_guess_name_dev: failed to open %s (dev=%s), ERR=%s\n", 
+      Dmsg3(29, "open_mounted_dev: failed to open %s (dev=%s), ERR=%s\n", 
             guessedname.c_str(), dev->dev_name, be.strerror());
       if (open_first_part(dev) < 0) {
          berrno be;
@@ -305,10 +307,10 @@ int open_guess_name_dev(DEVICE *dev)
    dev->part_start = 0;
    dev->part_size = statp.st_size;
    dev->part = 0;
-   dev->state |= ST_OPENED;
+   dev->set_opened();
    dev->use_count = 1;
    
-   Dmsg2(29, "open_guess_name_dev: %s opened (dev=%s)\n", guessedname.c_str(), dev->dev_name);
+   Dmsg2(29, "open_mounted_dev: %s opened (dev=%s)\n", guessedname.c_str(), dev->dev_name);
    
    return 0;
 }
@@ -428,8 +430,8 @@ static int dvd_write_part(DEVICE *dev)
  *  - Increment part number 
  *  - Reopen the device
  */
-int open_next_part(DEVICE *dev) {
-   int state;
+int open_next_part(DEVICE *dev)
+{
       
    Dmsg3(29, "open_next_part %s %s %d\n", dev->dev_name, dev->VolCatInfo.VolCatName, dev->openmode);
    /* When appending, do not open a new part if the current is empty */
@@ -444,9 +446,7 @@ int open_next_part(DEVICE *dev) {
    }
    
    dev->fd = -1;
-   
-   state = dev->state;
-   dev->state &= ~ST_OPENED;
+   dev->clear_opened();
    
    if (dev->is_dvd() && (dev->part == dev->num_parts) && dev->can_append()) {
       if (dvd_write_part(dev) < 0) {
@@ -493,10 +493,11 @@ int open_next_part(DEVICE *dev) {
       }
    }
    
+   Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d", dev->VolCatInfo.VolCatName, 
+         dev->openmode);
    if (open_dev(dev, dev->VolCatInfo.VolCatName, dev->openmode) < 0) {
       return -1;
    } 
-   dev->state = state;
    return dev->fd;
 }
 
@@ -511,13 +512,13 @@ int open_first_part(DEVICE *dev)
       close(dev->fd);
    }
    dev->fd = -1;
-   dev->state &= ~ST_OPENED;
+   dev->clear_opened();
    
    dev->part_start = 0;
    dev->part = 0;
    
-   Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d",
-        dev->VolCatInfo.VolCatName, dev->openmode);
+   Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d", dev->VolCatInfo.VolCatName, 
+         dev->openmode);
    if (open_dev(dev, dev->VolCatInfo.VolCatName, dev->openmode) < 0) {
       Dmsg0(50, "open_dev() failed\n");
       return -1;
@@ -683,28 +684,28 @@ static char *edit_device_codes_dev(DEVICE* dev, char *omsg, const char *imsg)
    for (p=imsg; *p; p++) {
       if (*p == '%') {
          switch (*++p) {
-            case '%':
-               str = "%";
-               break;
-            case 'n':
-               bsnprintf(add, sizeof(add), "%d", dev->part);
-               str = add;
-               break;
-            case 'a':
-               str = dev->dev_name;
-               break;
-            case 'm':
-               str = dev->device->mount_point;
-               break;
-            case 'v':
-               str = archive_name.c_str();
-               break;
-            default:
-               add[0] = '%';
-               add[1] = *p;
-               add[2] = 0;
-               str = add;
-               break;
+         case '%':
+            str = "%";
+            break;
+         case 'n':
+            bsnprintf(add, sizeof(add), "%d", dev->part);
+            str = add;
+            break;
+         case 'a':
+            str = dev->dev_name;
+            break;
+         case 'm':
+            str = dev->device->mount_point;
+            break;
+         case 'v':
+            str = archive_name.c_str();
+            break;
+         default:
+            add[0] = '%';
+            add[1] = *p;
+            add[2] = 0;
+            str = add;
+            break;
          }
       } else {
          add[0] = *p;
index e4300d8dbd8729b0e11ff3d15b642df8c6bf550e..b271fc5adbaa683d64d7bad28045bde591e27851 100644 (file)
@@ -252,7 +252,7 @@ bool query_cmd(JCR *jcr)
          /* Find resource, and make sure we were able to open it */
          if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0) {
             if (!device->dev) {
-               device->dev = init_dev(jcr, NULL, device);
+               device->dev = init_dev(jcr, device);
             }
             if (!device->dev) {
                break;
index c296e39ff77d6ffca48c642072c23129e41e69ea..cf915ce92c102453719004ddfedd3c89266a6431 100644 (file)
@@ -89,7 +89,9 @@ int read_dev_volume_label(DCR *dcr)
       return VOL_OK;       /* label already read */
    }
 
-   dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ);  /* set no label, no append */
+   dev->clear_labeled();
+   dev->clear_append();
+   dev->clear_read();
    dev->label_type = B_BACULA_LABEL;
 
    if (!rewind_dev(dev)) {
@@ -230,55 +232,60 @@ int read_dev_volume_label(DCR *dcr)
  *  Writing : returns the label of the current file (on the harddisk).
  *  Reading : returns an error
  */
-int read_dev_volume_label_guess(DCR *dcr, bool write) 
+int read_dvd_volume_label(DCR *dcr, bool write) 
 {
    int vol_label_status;
    DEVICE *dev = dcr->dev;
    JCR *jcr = dcr->jcr;
-   Dmsg3(100, "Enter read_dev_volume_label_guess device=%s vol=%s dev_Vol=%s\n",
+   Dmsg3(100, "Enter read_dvd_volume_label device=%s vol=%s dev_Vol=%s\n",
          dev->print_name(), dcr->VolumeName, dev->VolHdr.VolName);
    
-   if (!dev->is_dvd()) {
-      Dmsg0(100, "Leave read_dev_volume_label_guess !CAP_REQMOUNT\n");
-      return read_dev_volume_label(dcr);
+   if (!dev->is_dvd()) {  
+      Jmsg1(jcr, M_ABORT, 0, _("Device %s is not a DVD.\n"), dev->print_name());
+      return -1;    /* for compiler, won't get here */
    }
    
    if (!write && (dcr->VolCatInfo.VolCatParts == 0)) {
-      Dmsg0(100, "Leave read_dev_volume_label_guess !writing, and VolCatParts == 0\n");
+      Dmsg0(100, "Leave read_dvd_volume_label !writing, and VolCatParts == 0\n");
       return read_dev_volume_label(dcr);
    }
    
-   /* For mounted devices, tries to guess the volume name, and read the label if possible.
-   */
-   if (open_guess_name_dev(dev) < 0) {     
+   /*
+    * For mounted devices, try to guess the Volume name
+    * and read the label if possible.
+    */
+   if (open_mounted_dev(dev) < 0) {     
       if (!write || dcr->VolCatInfo.VolCatParts > 0) {
          Mmsg2(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula labeled Volume."),
                dev->print_name(), dcr->VolumeName);
-         Dmsg0(100, "Leave read_dev_volume_label_guess VOL_NO_LABEL (!open_guess_name_dev)\n");
+         Dmsg0(100, "Leave read_dvd_volume_label VOL_NO_LABEL (!open_mounted_dev)\n");
          return VOL_NO_LABEL;
       }
       
       if (write && dev->free_space_errno < 0) {
-         Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
+         Dmsg0(100, "Leave read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
          Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
                dev->print_name(), dev->errmsg);
          return VOL_NO_MEDIA;
       }
       
-      /* If we can't guess the name, and we are writing, just reopen the right file with open_first_part. */
+      /* 
+       * If we can't guess the name, and we are writing, 
+       * just reopen the right file with open_first_part.
+       */
       if (open_first_part(dev) < 0) {
          berrno be;
          Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
                dev->print_name(), be.strerror());
-         Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (!open_guess_name_dev && !open_first_part)\n");
+         Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (!open_mounted_dev && !open_first_part)\n");
          return VOL_IO_ERROR;
       }
       
-      Dmsg0(100, "Leave read_dev_volume_label_guess !open_guess_name_dev\n");
+      Dmsg0(100, "Leave read_dvd_volume_label !open_mounted_dev\n");
       return read_dev_volume_label(dcr);
    } else {
       if (write && dcr->dev->free_space_errno < 0) {
-         Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
+         Dmsg0(100, "Leave read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
          Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
                dev->print_name(), dev->errmsg);
          return VOL_NO_MEDIA;
@@ -287,7 +294,7 @@ int read_dev_volume_label_guess(DCR *dcr, bool write)
       vol_label_status = read_dev_volume_label(dcr);
 
       if (!write || dcr->VolCatInfo.VolCatParts > 0) {
-         Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
+         Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
          return vol_label_status;
       }
       
@@ -295,19 +302,19 @@ int read_dev_volume_label_guess(DCR *dcr, bool write)
          berrno be;
          Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
                dev->print_name(), be.strerror());
-         Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (open_guess_name_dev && !open_first_part)\n");
+         Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (open_mounted_dev && !open_first_part)\n");
          return VOL_IO_ERROR;
       }
       
-      /* When writing, if the guessed volume name is no the right volume name, 
+      /* When writing, if the guessed volume name is not the right volume name, 
        * report the error, otherwise, just continue with the right file.
        */
       if (vol_label_status != VOL_NAME_ERROR) {
-         Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && !VOL_NAME_ERROR)\n");
+         Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && !VOL_NAME_ERROR)\n");
          dev->clear_labeled();   
          return read_dev_volume_label(dcr);
       } else {
-         Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && VOL_NAME_ERROR)\n");
+         Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && VOL_NAME_ERROR)\n");
          return vol_label_status;
       }
    }
@@ -475,7 +482,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle)
             rewind_dev(dev);
             return false;
          }
-      } else if (!write_ansi_ibm_labels (dcr, ANSI_VOL_LABEL, dev->VolHdr.VolName)) {
+      } else if (!write_ansi_ibm_labels(dcr, ANSI_VOL_LABEL, dev->VolHdr.VolName)) {
          return false;
       }
 
index 94d6781e9ed9a4dacd2d39c3a2df3eff210be615..7de971cf35c15424a64ac860c17935281fba4c3c 100644 (file)
@@ -182,7 +182,7 @@ read_volume:
       create_volume_label(dev, dcr->VolumeName, "Default");
       dev->VolHdr.LabelType = PRE_LABEL;
    } else if (dev->is_dvd()) {
-      vol_label_status = read_dev_volume_label_guess(dcr, 1);
+      vol_label_status = read_dvd_volume_label(dcr, /*write*/true);
    } else {
       vol_label_status = read_dev_volume_label(dcr);
    }
@@ -434,7 +434,9 @@ void release_volume(DCR *dcr)
    free_volume(dev);
    memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
    /* Force re-read of label */
-   dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
+   dev->clear_labeled();
+   dev->clear_read();
+   dev->clear_append();
    dev->label_type = B_BACULA_LABEL;
    dcr->VolumeName[0] = 0;
 
index 445d947e9319c15699375921768169f5e3798bcb..656fbaef7ec233731a20a6c990ab62cd01fcc116 100644 (file)
@@ -78,12 +78,12 @@ void    display_tape_error_status(JCR *jcr, DEVICE *dev);
 
 
 /* From dev.c */
-DEVICE  *init_dev(JCR *jcr, DEVICE *dev, DEVRES *device);
+DEVICE  *init_dev(JCR *jcr, DEVRES *device);
 int      open_dev(DEVICE *dev, char *VolName, int mode);
 off_t    lseek_dev(DEVICE *dev, off_t offset, int whence);
 int      open_first_part(DEVICE *dev);
 int      open_next_part(DEVICE *dev);
-int      open_guess_name_dev(DEVICE *dev);
+int      open_mounted_dev(DEVICE *dev);
 bool     truncate_dev(DEVICE *dev);
 void     term_dev(DEVICE *dev);
 char *   strerror_dev(DEVICE *dev);
@@ -152,7 +152,7 @@ void     handle_filed_connection(BSOCK *fd, char *job_name);
 
 /* From label.c */
 int      read_dev_volume_label(DCR *dcr);
-int      read_dev_volume_label_guess(DCR *dcr, bool write);
+int      read_dvd_volume_label(DCR *dcr, bool write);
 void     create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
 void     create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName);
 bool     write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName);
index dbf5a6c49c078e268400775de74676731e46ee6e..98242e83fa36f5e1eaedcb839b72e6405181b895 100644 (file)
@@ -113,7 +113,7 @@ bool read_records(DCR *dcr,
             Dmsg3(200, "Got EOF at file %u  on device %s, Volume \"%s\"\n",
                   dev->file, dev->print_name(), dcr->VolumeName);
             continue;
-         } else if (dev_state(dev, ST_SHORT)) {
+         } else if (dev->is_short_block()) {
             Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg);
             continue;
          } else {
@@ -270,7 +270,7 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev)
       if (!dev->at_eot()) {
          /* Set EOT flag to force mount of next Volume */
          jcr->mount_next_volume = true;
-         dev->state |= ST_EOT;
+         dev->set_eot();
       }
       rec->Block = 0;
       return true;
index 8ce61cdcd72648b27e20f90c92223e22dba64edc..ef645737395d975f826eaae16f84c173e46fa67c 100644 (file)
@@ -459,7 +459,7 @@ static int reserve_device(RCTX &rctx)
    DCR *dcr;
    const int name_len = MAX_NAME_LENGTH;
    if (!rctx.device->dev) {
-      rctx.device->dev = init_dev(rctx.jcr, NULL, rctx.device);
+      rctx.device->dev = init_dev(rctx.jcr, rctx.device);
    }
    if (!rctx.device->dev) {
       if (rctx.device->changer_res) {
index cd21d9cd104d30a87da319cebbb7c8c4249b867f..42ec7a7803edff88562b0970193186356bf5ab13 100644 (file)
@@ -467,7 +467,7 @@ void *device_initialization(void *arg)
 
    foreach_res(device, R_DEVICE) {
       Dmsg1(90, "calling init_dev %s\n", device->device_name);
-      device->dev = init_dev(NULL, NULL, device);
+      device->dev = init_dev(NULL, device);
       Dmsg1(10, "SD init done %s\n", device->device_name);
       if (!device->dev) {
          Jmsg1(NULL, M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
index ddd4aaf83273d6f468fa624beeb1147d18ad0476..d95f3852e260a0f69a751a8d26185a138aa53d8b 100644 (file)
@@ -71,7 +71,7 @@ int wait_for_sysop(DCR *dcr)
 
    if (!unmounted) {
       dev->dev_prev_blocked = dev->dev_blocked;
-      dev->dev_blocked = BST_WAITING_FOR_SYSOP; /* indicate waiting for mount */
+      dev->set_blocked(BST_WAITING_FOR_SYSOP); /* indicate waiting for mount */
    }
 
    for ( ; !job_canceled(jcr); ) {
@@ -144,7 +144,7 @@ int wait_for_sysop(DCR *dcr)
    }
 
    if (!unmounted) {
-      dev->dev_blocked = dev->dev_prev_blocked;    /* restore entry state */
+      dev->set_blocked(dev->dev_prev_blocked);    /* restore entry state */
    }
    V(dev->mutex);
    return stat;