+ return false; /* ERROR return */
+}
+
+/*
+ * Query Device command from Director
+ * Sends Storage Daemon's information on the device to the
+ * caller (presumably the Director).
+ * This command always returns "true" so that the line is
+ * not closed on an error.
+ *
+ */
+bool query_cmd(JCR *jcr)
+{
+ POOL_MEM dev_name;
+ BSOCK *dir = jcr->dir_bsock;
+ DEVRES *device;
+ bool ok;
+
+ Dmsg1(120, "Query: %s", dir->msg);
+
+ ok = sscanf(dir->msg, query_device, dev_name.c_str()) == 1;
+ if (ok) {
+ unbash_spaces(dev_name);
+ LockRes();
+ foreach_res(device, R_DEVICE) {
+ /* Find resource, and make sure we were able to open it */
+ if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0 &&
+ device->dev) {
+ DEVICE *dev = device->dev;
+ POOL_MEM VolumeName, MediaType;
+ UnlockRes();
+ if (dev->is_labeled()) {
+ pm_strcpy(VolumeName, dev->VolHdr.VolName);
+ } else {
+ pm_strcpy(VolumeName, "");
+ }
+ bash_spaces(VolumeName);
+ pm_strcpy(MediaType, device->media_type);
+ bash_spaces(MediaType);
+ return bnet_fsend(dir, OK_query, dev->can_append()!=0,
+ dev->can_read()!=0, dev->num_writers, dev->num_waiting,
+ dev->is_open()!=0, dev->use_count, dev->is_labeled()!=0,
+ MediaType.c_str(), VolumeName.c_str());
+ }
+ }
+ UnlockRes();
+ unbash_spaces(dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
+ bnet_fsend(dir, NO_device, dev_name.c_str());
+ } else {
+ unbash_spaces(dir->msg);
+ pm_strcpy(jcr->errmsg, dir->msg);
+ bnet_fsend(dir, BAD_query, jcr->errmsg);
+ }
+ return true;