1. Fix bugs
 - Tape xxx in drive 0, requested in drive 1
 - Multi-drive changer seems to only use drive 0
+  Multiple drives don't seem to be opened.
+- Why isn't the DEVICE structure defined when doing
+  a reservation?
+- The mount command does not work with drives other than 0.
+
 -  --without-openssl breaks at least on Solaris.
 9. Run the regression scripts on Solaris and FreeBSD
 -  Figure out how to package gui, and rescue programs.
 
 General:
 
 Changes to 1.37.32:
+03Aug03
+- Require 5 arguments to mtx-changer except list and slots
+- Turn -EPIPE status returns from bpipe to ETIME
+- Include Slot in SD status output 
+- Do not term_dev() during initialization in SD if the device
+  could not be opened.  In the case of a tape drive, there may
+  be no tape in the drive.
 02Aug05
 - Correct PostgreSQL database scripts as suggested by a user.
 - Add additional info to FATAL message generated when a device
 
 cmd="$2"
 slot=$3
 device=$4
-# If drive not given, default to 0
-if test $# = 5 ; then
-  drive=$5
-else
-  drive=0
-fi
+drive=$5
 
 #
 # Check for special cases where only 2 arguments are needed, 
 #  all others are a minimum of 3
 case $cmd in
-   loaded)
-     ;;
-   unload)
-     ;;
    list)
      ;;
    slots)
      ;;
    *)
-     if test $# -lt 3; then
+     if test $# -lt 5; then
        echo "usage: mtx-changer ctl-device command slot archive-device drive"
        echo "  Insufficient number of arguments arguments given."
-       echo "  Mimimum usage is first three arguments ..."
        exit 1
      fi
      ;;
 #
 # enable the following line if you need to eject the cartridge
 #     mt -f $device offline
-      if test x$slot = x; then
-        ${MTX} -f $ctl unload
-      else
-        ${MTX} -f $ctl unload $slot $drive
-      fi
+      ${MTX} -f $ctl unload $slot $drive
       ;;
 
    load)
 
              * following lines run_program would not detect if the program was killed
              * by the watchdog. */
             if (bpipe->timer_id->killed) {
-               stat1 = -EPIPE;
+               stat1 = ETIME;
                pm_strcat(results, "Program killed by Bacula watchdog (timeout)\n");
             }
          }
             Dmsg1(100, "Run program fgets killed=%d\n", bpipe->timer_id->killed);
             if (bpipe->timer_id->killed) {
                pm_strcat(tmp, "Program killed by Bacula watchdog (timeout)\n");
-               stat1 = -EPIPE;
+               stat1 = ETIME;
                break;
             }
          }
 
       }
       lf->line_no++;
       lf->col_no = 0;
-      Dmsg2(400, "fget line=%d %s", lf->line_no, lf->line);
+      Dmsg2(1000, "fget line=%d %s", lf->line_no, lf->line);
    }
    lf->ch = (uint8_t)lf->line[lf->col_no];
    if (lf->ch == 0) {
 
 #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);
 
 
 }
 
-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);
    /* 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) {
 
 int      autoload_device(DCR *dcr, int writing, BSOCK *dir);
 bool     autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
 char    *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
+int      get_autochanger_loaded_slot(DCR *dcr);
 
 /* From block.c */
 void    dump_block(DEV_BLOCK *b, const char *msg);
 
    int Copy, Stripe;
    DIRSTORE *store;
    RCTX rctx;
-   rctx.jcr = jcr;
 #ifdef implemented
    char *error;
 #endif
 
+   memset(&rctx, 0, sizeof(RCTX));
+   rctx.jcr = jcr;
    /*
     * If there are multiple devices, the director sends us
     *   use_device for each device that it wants to use.
 
             edit_uint64_with_commas(dev->block_num, b2));
 
       } else {
-         bnet_fsend(user, _("Archive \"%s\" is not open or does not exist.\n"), device->hdr.name);
+         if (dev) {
+            bnet_fsend(user, _("Device %s is not open or does not exist.\n"), dev->print_name());
+         } else {
+            bnet_fsend(user, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name);
+         }
          send_blocked_status(jcr, dev);
       }
    }
    default:
       break;
    }
+   /* Send autochanger slot status */
+   if (dev->is_autochanger()) {
+      if (dev->Slot) {
+         bnet_fsend(user, _("    Slot %d is loaded in drive %d.\n"), 
+            dev->Slot, dev->drive_index);
+      } else {
+         bnet_fsend(user, _("    Drive %d is not loaded.\n"), dev->drive_index);
+      }
+   }
    if (debug_level > 1) {
       bnet_fsend(user, _("Configured device capabilities:\n"));
       bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
 
       }
 
       dcr = new_dcr(jcr, dev);
+      if (dev->is_autochanger()) {
+         /* If autochanger set slot in dev sturcture */
+         get_autochanger_loaded_slot(dcr);
+      }
 
       if (device->cap_bits & CAP_ALWAYSOPEN) {
          Dmsg1(20, "calling first_open_device %s\n", dev->print_name());
          if (!first_open_device(dcr)) {
             Jmsg1(NULL, M_ERROR, 0, _("Could not open device %s\n"), dev->print_name());
             Dmsg1(20, "Could not open device %s\n", dev->print_name());
+
+#ifdef xxx
             term_dev(dev);
             device->dev = NULL;
+#endif
             free_dcr(dcr);
             continue;
          }
 
 /* */
 #undef  VERSION
-#define VERSION "1.37.32"
-#define BDATE   "30 July 2005"
-#define LSMDATE "30Jul05"
+#define VERSION "1.37.33"
+#define BDATE   "03 August 2005"
+#define LSMDATE "03Aug05"
 
 /* Debug flags */
 #undef  DEBUG