]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
Make btape fill/unfill work
[bacula/bacula] / bacula / src / stored / dircmd.c
index 961c8bd2a12605fa8abf576d481c053841d0425b..433940f7a2f109397b1504365c9231b125322e09 100644 (file)
@@ -59,17 +59,20 @@ static char OKsetdebug[]   = "3000 OK setdebug=%d\n";
 /* Imported functions */
 extern void terminate_child();
 extern int job_cmd(JCR *jcr);
+extern int status_cmd(JCR *sjcr);
 
 /* Forward referenced functions */
 static int label_cmd(JCR *jcr);
+static int relabel_cmd(JCR *jcr);
 static int setdebug_cmd(JCR *jcr);
 static int cancel_cmd(JCR *cjcr);
 static int mount_cmd(JCR *jcr);
 static int unmount_cmd(JCR *jcr);
-static int status_cmd(JCR *sjcr);
-static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolname, 
-                              int Slot);
-static void send_blocked_status(JCR *jcr, DEVICE *dev);
+static int autochanger_cmd(JCR *sjcr);
+static int do_label(JCR *jcr, int relabel);
+static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
+                              char *newname, char *poolname, 
+                              int Slot, int relabel);
 
 struct s_cmds {
    char *cmd;
@@ -84,9 +87,11 @@ static struct s_cmds cmds[] = {
    {"setdebug=", setdebug_cmd},       /* set debug level */
    {"cancel",    cancel_cmd},
    {"label",     label_cmd},          /* label a tape */
+   {"relabel",   relabel_cmd},        /* relabel a tape */
    {"mount",     mount_cmd},
    {"unmount",   unmount_cmd},
    {"status",    status_cmd},
+   {"autochanger", autochanger_cmd},
    {NULL,       NULL}                /* list terminator */
 };
 
@@ -106,7 +111,7 @@ static struct s_cmds cmds[] = {
  *  - We execute the command
  *  - We continue or exit depending on the return status
  */
-void connection_request(void *arg)
+void *connection_request(void *arg)
 {
    BSOCK *bs = (BSOCK *)arg;
    JCR *jcr;
@@ -115,16 +120,19 @@ void connection_request(void *arg)
    char name[MAX_NAME_LENGTH];
 
    if (bnet_recv(bs) <= 0) {
-      Emsg0(M_ERROR, 0, "Connection request failed.\n");
-      return;
+      Emsg0(M_ERROR, 0, _("Connection request failed.\n"));
+      return NULL;
    }
 
    /* 
     * See if this is a File daemon connection
     */
+   if (bs->msglen < 25 || bs->msglen > (int)sizeof(name)+25) {
+      Emsg1(M_ERROR, 0, _("Invalid Dir connection. Len=%d\n"), bs->msglen);
+   }
    if (sscanf(bs->msg, "Hello Start Job %127s calling\n", name) == 1) {
       handle_filed_connection(bs, name);
-      return;
+      return NULL;
    }
    
    jcr = new_jcr(sizeof(JCR), stored_free_jcr);     /* create Job Control Record */
@@ -138,12 +146,11 @@ void connection_request(void *arg)
    if (!authenticate_director(jcr)) {
       Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Director\n"));
       free_jcr(jcr);
-      return;
+      return NULL;
    }
    Dmsg0(90, "Message channel init completed.\n");
 
    for (quit=0; !quit;) {
-
       /* Read command */
       if ((bnet_stat = bnet_recv(bs)) <= 0) {
         break;                       /* connection terminated */
@@ -170,7 +177,7 @@ void connection_request(void *arg)
       bnet_sig(bs, BNET_TERMINATE);
    }
    free_jcr(jcr);
-   return;
+   return NULL;
 }
 
 /*
@@ -208,7 +215,7 @@ static int cancel_cmd(JCR *cjcr)
       } else {
         P(jcr->mutex);
         oldStatus = jcr->JobStatus;
-        set_jcr_job_status(jcr, JS_Cancelled);
+        set_jcr_job_status(jcr, JS_Canceled);
         if (!jcr->authenticated && oldStatus == JS_WaitFD) {
            pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */
         }
@@ -216,7 +223,14 @@ static int cancel_cmd(JCR *cjcr)
         if (jcr->file_bsock) {
            bnet_sig(jcr->file_bsock, BNET_TERMINATE);
         }
-         bnet_fsend(dir, _("3000 Job %s marked to be cancelled.\n"), jcr->Job);
+        /* If thread waiting on mount, wake him */
+        if (jcr->device && jcr->device->dev &&      
+             (jcr->device->dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
+              jcr->device->dev->dev_blocked == BST_UNMOUNTED ||
+              jcr->device->dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
+            pthread_cond_signal(&jcr->device->dev->wait_next_vol);
+        }
+         bnet_fsend(dir, _("3000 Job %s marked to be canceled.\n"), jcr->Job);
         free_jcr(jcr);
       }
    } else {
@@ -232,21 +246,44 @@ static int cancel_cmd(JCR *cjcr)
  */
 static int label_cmd(JCR *jcr) 
 {
-   POOLMEM *dname, *volname, *poolname, *mtype;
+   return do_label(jcr, 0);
+}
+
+static int relabel_cmd(JCR *jcr) 
+{
+   return do_label(jcr, 1);
+}
+
+static int do_label(JCR *jcr, int relabel)  
+{
+   POOLMEM *dname, *newname, *oldname, *poolname, *mtype;
    BSOCK *dir = jcr->dir_bsock;
    DEVRES *device;
    DEVICE *dev;
-   int found = 0;
+   int found = 0, ok = 0;
    int slot;   
 
    dname = get_memory(dir->msglen+1);
-   volname = get_memory(dir->msglen+1);
+   newname = get_memory(dir->msglen+1);
+   oldname = get_memory(dir->msglen+1);
    poolname = get_memory(dir->msglen+1);
    mtype = get_memory(dir->msglen+1);
-   if (sscanf(dir->msg, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d",
-       dname, volname, poolname, mtype, &slot) == 5) {
+   if (relabel) {
+      if (sscanf(dir->msg, "relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d",
+         dname, oldname, newname, poolname, mtype, &slot) == 6) {
+        ok = 1;
+      }
+   } else {
+      *oldname = 0;
+      if (sscanf(dir->msg, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d",
+         dname, newname, poolname, mtype, &slot) == 5) {
+        ok = 1;
+      }
+   }
+   if (ok) {
       unbash_spaces(dname);
-      unbash_spaces(volname);
+      unbash_spaces(newname);
+      unbash_spaces(oldname);
       unbash_spaces(poolname);
       unbash_spaces(mtype);
       device = NULL;
@@ -267,10 +304,10 @@ static int label_cmd(JCR *jcr)
 
         P(dev->mutex);               /* Use P to avoid indefinite block */
         if (!(dev->state & ST_OPENED)) {
-           if (open_dev(dev, volname, READ_WRITE) < 0) {
+           if (open_dev(dev, newname, READ_WRITE) < 0) {
                bnet_fsend(dir, _("3994 Connot open device: %s\n"), strerror_dev(dev));
            } else {
-              label_volume_if_ok(jcr, dev, volname, poolname, slot);
+              label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
               force_close_dev(dev);
            }
          /* Under certain "safe" conditions, we can steal the lock */
@@ -278,7 +315,7 @@ static int label_cmd(JCR *jcr)
                    (dev->dev_blocked == BST_UNMOUNTED ||
                     dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
                     dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
-           label_volume_if_ok(jcr, dev, volname, poolname, slot);
+           label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
         } else if (dev->state & ST_READ || dev->num_writers) {
            if (dev->state & ST_READ) {
                 bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"),
@@ -288,7 +325,7 @@ static int label_cmd(JCR *jcr)
                   dev_name(dev), dev->num_writers);
            }
         } else {                     /* device not being used */
-           label_volume_if_ok(jcr, dev, volname, poolname, slot);
+           label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
         }
         V(dev->mutex);
       } else {
@@ -296,11 +333,12 @@ static int label_cmd(JCR *jcr)
       }
    } else {
       /* NB dir->msg gets clobbered in bnet_fsend, so save command */
-      strcpy(dname, dir->msg);
-      bnet_fsend(dir, _("3903 Error scanning label command: %s\n"), dname);
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      bnet_fsend(dir, _("3903 Error scanning label command: %s\n"), jcr->errmsg);
    }
    free_memory(dname);
-   free_memory(volname);
+   free_memory(oldname);
+   free_memory(newname);
    free_memory(poolname);
    free_memory(mtype);
    bnet_sig(dir, BNET_EOD);
@@ -313,8 +351,9 @@ static int label_cmd(JCR *jcr)
  *
  *  Enter with the mutex set
  */
-static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolname,
-                              int slot) 
+static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname, 
+                              char *newname, char *poolname,
+                              int slot, int relabel)
 {
    BSOCK *dir = jcr->dir_bsock;
    DEV_BLOCK *block;
@@ -322,7 +361,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolnam
    
    steal_device_lock(dev, &hold, BST_WRITING_LABEL);
    
-   strcpy(jcr->VolumeName, vname);
+   strcpy(jcr->VolumeName, newname);
    jcr->VolCatInfo.Slot = slot;
    autoload_device(jcr, dev, 0, dir);     /* autoload if possible */
    block = new_block(dev);
@@ -331,9 +370,9 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolnam
    for ( ; !(dev->state & ST_OPENED); ) {
        if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
          if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) {
-            sleep(30);
+            bmicrosleep(30, 0);
          }
-          bnet_fsend(dir, _("3903 Unable to open device %s. ERR=%s\n"), 
+          bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"), 
             dev_name(dev), strerror_dev(dev));
          goto bail_out;
        }
@@ -345,21 +384,33 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolnam
       case VOL_VERSION_ERROR:
       case VOL_LABEL_ERROR:
       case VOL_OK:
-         bnet_fsend(dir, _("3901 Cannot label Volume because it is \
-already labeled: %s\n"), dev->VolHdr.VolName);
-        break;
+        if (!relabel) {
+           bnet_fsend(dir, _(
+               "3911 Cannot label Volume because it is already labeled: %s\n"), 
+               dev->VolHdr.VolName);
+           break;
+        }
+        /* Relabel request. If oldname matches, continue */
+        if (strcmp(oldname, dev->VolHdr.VolName) != 0) {
+            bnet_fsend(dir, _("Wrong volume mounted.\n"));
+           break;
+        }
+        /* Fall through wanted! */
       case VOL_IO_ERROR:
       case VOL_NO_LABEL:
-        if (!write_volume_label_to_dev(jcr, jcr->device, vname, poolname)) {
-            bnet_fsend(dir, _("3903 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
+        if (!write_volume_label_to_dev(jcr, jcr->device, newname, poolname)) {
+            bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
            break;
         }
-        strcpy(jcr->VolumeName, vname);
+        strcpy(jcr->VolumeName, newname);
          bnet_fsend(dir, _("3000 OK label. Volume=%s Device=%s\n"), 
-           vname, dev->dev_name);
+           newname, dev->dev_name);
+        break;
+      case VOL_NO_MEDIA:
+         bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
         break;
       default:
-         bnet_fsend(dir, _("3902 Cannot label Volume. \
+         bnet_fsend(dir, _("3913 Cannot label Volume. \
 Unknown status %d from read_volume_label()\n"), jcr->label_status);
         break;
    }
@@ -379,11 +430,9 @@ static int read_label(JCR *jcr, DEVICE *dev)
    int stat;
    BSOCK *dir = jcr->dir_bsock;
    DEV_BLOCK *block;
-#ifndef NEW_LOCK
    bsteal_lock_t hold;
    
    steal_device_lock(dev, &hold, BST_DOING_ACQUIRE);
-#endif
    
    jcr->VolumeName[0] = 0;
    block = new_block(dev);
@@ -400,9 +449,7 @@ static int read_label(JCR *jcr, DEVICE *dev)
         break;
    }
    free_block(block);
-#ifndef NEW_LOCK
    return_device_lock(dev, &hold);
-#endif
    return stat;
 }
 
@@ -411,13 +458,13 @@ static int read_label(JCR *jcr, DEVICE *dev)
  */
 static int mount_cmd(JCR *jcr)
 {
-   char *dev_name;
+   POOLMEM *dev_name;
    BSOCK *dir = jcr->dir_bsock;
    DEVRES *device;
    DEVICE *dev;
    int found = 0;
 
-   dev_name = (char *) get_memory(dir->msglen);
+   dev_name = get_memory(dir->msglen+1);
    if (sscanf(dir->msg, "mount %s", dev_name) == 1) {
       unbash_spaces(dev_name);
       device = NULL;
@@ -439,7 +486,8 @@ static int mount_cmd(JCR *jcr)
            DEV_BLOCK *block;
            case BST_WAITING_FOR_SYSOP:
               /* Someone is waiting, wake him */
-               Dmsg0(90, "Waiting for mount attempt to wake thread\n");
+               Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
+              dev->dev_blocked = BST_MOUNT;
               pthread_cond_signal(&dev->wait_next_vol);
                bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev->dev_name);
               break;
@@ -456,19 +504,20 @@ static int mount_cmd(JCR *jcr)
               read_dev_volume_label(jcr, dev, block);
               free_block(block);
               if (dev->dev_blocked == BST_UNMOUNTED) {
-                  Dmsg0(90, "Unmounted unblocking device\n");
+                  Dmsg0(100, "Unmounted. Unblocking device\n");
                  read_label(jcr, dev);
                  unblock_device(dev);
               } else {
-                  Dmsg0(90, "Unmounted waiting for mount attempt to wake thread\n");
-                 dev->dev_blocked = BST_WAITING_FOR_SYSOP;
+                  Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
+                 dev->dev_blocked = BST_MOUNT;
                  pthread_cond_signal(&dev->wait_next_vol);
               }
               if (dev->state & ST_LABEL) {
-                  bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"), 
+                  bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"), 
                     dev->dev_name, dev->VolHdr.VolName);
               } else {
-                  bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                  bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+                                    "Try unmounting and remounting the Volume.\n"),
                             dev->dev_name);
               }
               break;
@@ -485,10 +534,11 @@ static int mount_cmd(JCR *jcr)
            case BST_NOT_BLOCKED:
               if (dev->state & ST_OPENED) {
                  if (dev->state & ST_LABEL) {
-                     bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"),
+                     bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
                        dev->dev_name, dev->VolHdr.VolName);
                  } else {
-                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"   
+                                    "Try unmounting and remounting the Volume.\n"),
                                dev->dev_name);
                  }
               } else {
@@ -503,10 +553,11 @@ static int mount_cmd(JCR *jcr)
                  }
                  read_label(jcr, dev);
                  if (dev->state & ST_LABEL) {
-                     bnet_fsend(dir, _("3001 Device %s is mounted with Volume %s\n"), 
+                     bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"), 
                        dev->dev_name, dev->VolHdr.VolName);
                  } else {
-                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"), 
+                     bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
+                                       "Try unmounting and remounting the Volume.\n"),
                                dev->dev_name);
                  }
               }
@@ -521,8 +572,8 @@ static int mount_cmd(JCR *jcr)
          bnet_fsend(dir, _("3999 Device %s not found\n"), dev_name);
       }
    } else {
-      strcpy(dev_name, dir->msg);
-      bnet_fsend(dir, _("3906 Error scanning mount command: %s\n"), dev_name);
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      bnet_fsend(dir, _("3906 Error scanning mount command: %s\n"), jcr->errmsg);
    }
    free_memory(dev_name);
    bnet_sig(dir, BNET_EOD);
@@ -534,13 +585,13 @@ static int mount_cmd(JCR *jcr)
  */
 static int unmount_cmd(JCR *jcr)
 {
-   char *dname;
+   POOLMEM *dname;
    BSOCK *dir = jcr->dir_bsock;
    DEVRES *device;
    DEVICE *dev;
    int found = 0;
 
-   dname = (char *) get_memory(dir->msglen+1);
+   dname = get_memory(dir->msglen+1);
    if (sscanf(dir->msg, "unmount %s", dname) == 1) {
       unbash_spaces(dname);
       device = NULL;
@@ -606,150 +657,78 @@ static int unmount_cmd(JCR *jcr)
       }
    } else {
       /* NB dir->msg gets clobbered in bnet_fsend, so save command */
-      strcpy(dname, dir->msg);
-      bnet_fsend(dir, _("3907 Error scanning unmount command: %s\n"), dname);
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      bnet_fsend(dir, _("3907 Error scanning unmount command: %s\n"), jcr->errmsg);
    }
    free_memory(dname);
    bnet_sig(dir, BNET_EOD);
    return 1;
 }
 
+
 /*
- * Status command from Director
+ * Autochanger command from Director
  */
-static int status_cmd(JCR *jcr)
+static int autochanger_cmd(JCR *jcr)
 {
+   POOLMEM *devname;
+   BSOCK *dir = jcr->dir_bsock;
    DEVRES *device;
    DEVICE *dev;
-   int found, bps, sec, bpb;
-   BSOCK *user = jcr->dir_bsock;
-   char dt[MAX_TIME_LENGTH];
-   char b1[30], b2[30], b3[30];
-
-   bnet_fsend(user, "\n%s Version: " VERSION " (" DATE ")\n", my_name);
-   bstrftime(dt, sizeof(dt), daemon_start_time);
-   bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
-        last_job.NumJobs == 1 ? "" : "s");
-   if (last_job.NumJobs > 0) {
-      char termstat[30];
-
-      bstrftime(dt, sizeof(dt), last_job.end_time);
-      bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
-
-      jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
-      bnet_fsend(user, _("  Files=%s Bytes=%s Termination Status=%s\n"), 
-          edit_uint64_with_commas(last_job.JobFiles, b1),
-          edit_uint64_with_commas(last_job.JobBytes, b2),
-          termstat);
-   }
+   int found = 0;
 
-   LockRes();
-   for (device=NULL;  (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
-      dev = device->dev;
-      if (dev) {
-        if (dev->state & ST_OPENED) {
-           if (dev->state & ST_LABEL) {
-               bnet_fsend(user, _("Device %s is mounted with Volume %s\n"), 
-                 dev_name(dev), dev->VolHdr.VolName);
+   devname = get_memory(dir->msglen+1);
+   if (sscanf(dir->msg, "autochanger list %s ", devname) == 1) {
+      unbash_spaces(devname);
+      device = NULL;
+      LockRes();
+      while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
+        /* Find resource, and make sure we were able to open it */
+        if (strcmp(device->hdr.name, devname) == 0 && device->dev) {
+            Dmsg1(20, "Found device %s\n", device->hdr.name);
+           found = 1;
+           break;
+        }
+      }
+      UnlockRes();
+      if (found) {
+        jcr->device = device;
+        dev = device->dev;
+        P(dev->mutex);               /* Use P to avoid indefinite block */
+        if (!(dev->state & ST_OPENED)) {
+           if (open_dev(dev, NULL, READ_WRITE) < 0) {
+               bnet_fsend(dir, _("3994 Connot open device: %s\n"), strerror_dev(dev));
            } else {
-               bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
+              autochanger_list(jcr, dev, dir);
+              force_close_dev(dev);
            }
-           send_blocked_status(jcr, dev);
-           bpb = dev->VolCatInfo.VolCatBlocks;
-           if (bpb <= 0) {
-              bpb = 1;
+         /* Under certain "safe" conditions, we can steal the lock */
+        } else if (dev->dev_blocked && 
+                   (dev->dev_blocked == BST_UNMOUNTED ||
+                    dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
+                    dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
+           autochanger_list(jcr, dev, dir);
+        } else if (dev->state & ST_READ || dev->num_writers) {
+           if (dev->state & ST_READ) {
+                bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"),
+                  dev_name(dev));
+           } else {
+                bnet_fsend(dir, _("3902 Device %s is busy with %d writer(s).\n"),
+                  dev_name(dev), dev->num_writers);
            }
-           bpb = dev->VolCatInfo.VolCatBytes / bpb;
-            bnet_fsend(user, _("    Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
-              edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
-              edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), 
-              edit_uint64_with_commas(bpb, b3));
-            bnet_fsend(user, _("    Positioned at File=%s Block=%s\n"), 
-              edit_uint64_with_commas(dev->file, b1),
-              edit_uint64_with_commas(dev->block_num, b2));
-
-        } else {
-            bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
-           send_blocked_status(jcr, dev);
-        }
-      }
-   }
-   UnlockRes();
-
-   found = 0;
-   lock_jcr_chain();
-   /* NOTE, we reuse a calling argument jcr. Be warned! */ 
-   for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
-      if (jcr->JobStatus == JS_WaitFD) {
-         bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
-           job_type_to_str(jcr->JobType), jcr->Job);
-      }
-      if (jcr->device) {
-         bnet_fsend(user, _("%s %s job %s is using device %s\n"), 
-                  job_level_to_str(jcr->JobLevel),
-                  job_type_to_str(jcr->JobType),
-                  jcr->Job, jcr->device->device_name);
-        sec = time(NULL) - jcr->run_time;
-        if (sec <= 0) {
-           sec = 1;
-        }
-        bps = jcr->JobBytes / sec;
-         bnet_fsend(user, _("    Files=%s Bytes=%s Bytes/sec=%s\n"), 
-           edit_uint64_with_commas(jcr->JobFiles, b1),
-           edit_uint64_with_commas(jcr->JobBytes, b2),
-           edit_uint64_with_commas(bps, b3));
-        found = 1;
-#ifdef DEBUG
-        if (jcr->file_bsock) {
-            bnet_fsend(user, "    FDReadSeqNo=%" lld " fd=%d\n", 
-              jcr->file_bsock->read_seqno, jcr->file_bsock->fd);
-        } else {
-            bnet_fsend(user, "    FDSocket closed\n");
+        } else {                     /* device not being used */
+           autochanger_list(jcr, dev, dir);
         }
-#endif
+        V(dev->mutex);
+      } else {
+         bnet_fsend(dir, _("3999 Device %s not found\n"), devname);
       }
-      free_locked_jcr(jcr);
-   }
-   unlock_jcr_chain();
-   if (!found) {
-      bnet_fsend(user, _("No jobs running.\n"));
+   } else {
+      pm_strcpy(&jcr->errmsg, dir->msg);
+      bnet_fsend(dir, _("3907 Error scanning autocharger list command: %s\n"),
+        jcr->errmsg);
    }
-
-#ifdef full_status
-   bnet_fsend(user, "\n\n");
-   dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
-#endif
-   bnet_fsend(user, "====\n");
-
-   bnet_sig(user, BNET_EOD);
+   free_memory(devname);
+   bnet_sig(dir, BNET_EOD);
    return 1;
 }
-
-static void send_blocked_status(JCR *jcr, DEVICE *dev) 
-{
-   BSOCK *user = jcr->dir_bsock;
-
-   switch (dev->dev_blocked) {
-      case BST_UNMOUNTED:
-         bnet_fsend(user, _("    Device is BLOCKED. User unmounted.\n"));
-        break;
-      case BST_UNMOUNTED_WAITING_FOR_SYSOP:
-         bnet_fsend(user, _("    Device is BLOCKED. User unmounted during wait for media/mount.\n"));
-        break;
-      case BST_WAITING_FOR_SYSOP:
-        if (jcr->JobStatus == JS_WaitMount) {
-            bnet_fsend(user, _("    Device is BLOCKED waiting for mount.\n"));
-        } else {
-            bnet_fsend(user, _("    Device is BLOCKED waiting for appendable media.\n"));
-        }
-        break;
-      case BST_DOING_ACQUIRE:
-         bnet_fsend(user, _("    Device is being initialized.\n"));
-        break;
-      case BST_WRITING_LABEL:
-         bnet_fsend(user, _("    Device is blocked labeling a Volume.\n"));
-        break;
-      default:
-        break;
-   }
-}