]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/autochanger.c
- Require 5 arguments to mtx-changer except list and slots
[bacula/bacula] / bacula / src / stored / autochanger.c
index 6c8472fe7578bb568ce8a1f1bce61a8b5b50a491..f7b9619bcc4b1ed4b13f9c22628e88c9dbe66d3e 100644 (file)
@@ -11,7 +11,7 @@
 
    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 ammended with additional clauses defined in the
+   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,
@@ -25,7 +25,6 @@
 #include "stored.h"                   /* pull in Storage Deamon headers */
 
 /* Forward referenced functions */
-static int get_autochanger_loaded_slot(DCR *dcr);
 static void lock_changer(DCR *dcr);
 static void unlock_changer(DCR *dcr);
 
@@ -57,7 +56,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
     * Handle autoloaders here.  If we cannot autoload it, we
     *  will return 0 so that the sysop will be asked to load it.
     */
-   if (writing && dev_cap(dev, CAP_AUTOCHANGER) && slot <= 0) {
+   if (writing && dev->is_autochanger() && slot <= 0) {
       if (dir) {
          return 0;                    /* For user, bail out right now */
       }
@@ -80,7 +79,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
       if (loaded != slot) {
          offline_or_rewind_dev(dev);
          /* We are going to load a new tape, so close the device */
-         force_close_dev(dev);
+         force_close_device(dev);
          lock_changer(dcr);
          if (loaded != 0 && loaded != -1) {        /* must unload drive */
             Dmsg0(400, "Doing changer unload.\n");
@@ -147,13 +146,17 @@ bail_out:
 
 }
 
-static int get_autochanger_loaded_slot(DCR *dcr)
+/*
+ * Returns: -1 if error from changer command
+ *          slot otherwise
+ */
+int get_autochanger_loaded_slot(DCR *dcr)
 {
    JCR *jcr = dcr->jcr;
    POOLMEM *changer, *results;
    int status, loaded;
    uint32_t timeout = dcr->device->max_changer_wait;
-   int drive = dcr->device->drive_index;
+   int drive = dcr->dev->drive_index;
 
    results = get_pool_memory(PM_MESSAGE);
    changer = get_pool_memory(PM_FNAME);
@@ -163,10 +166,10 @@ static int get_autochanger_loaded_slot(DCR *dcr)
    /* Find out what is loaded, zero means device is unloaded */
    Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded drive %d\" command.\n"),
         drive);
-   changer = edit_device_codes(dcr, changer, 
-                dcr->device->changer_command, "loaded");
+   changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "loaded");
+   *results = 0;
    status = run_program(changer, timeout, results);
-   Dmsg3(50, "run_prog: %s stat=%d result=%s", changer, status, results);
+   Dmsg3(50, "run_prog: %s stat=%d result=%s\n", changer, status, results);
    if (status == 0) {
       loaded = atoi(results);
       if (loaded > 0) {
@@ -227,7 +230,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
    bool ok = false;
    int stat;
 
-   if (!dev_cap(dev, CAP_AUTOCHANGER) || !dcr->device->changer_name ||
+   if (!dev->is_autochanger() || !dcr->device->changer_name ||
        !dcr->device->changer_command) {
       bnet_fsend(dir, _("3993 Device %s not an autochanger device.\n"),
          dev->print_name());
@@ -241,7 +244,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
       /* Yes, to get a good listing, we unload any volumes */
       offline_or_rewind_dev(dev);
       /* We are going to load a new tape, so close the device */
-      force_close_dev(dev);
+      force_close_device(dev);
 
       /* First unload any tape */
       loaded = get_autochanger_loaded_slot(dcr);