+static BSOCK *open_sd_bsock(UAContext *ua)
+{
+ STORE *store = ua->jcr->store;
+
+ if (!ua->jcr->store_bsock) {
+ bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d ...\n"),
+ store->hdr.name, store->address, store->SDport);
+ if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
+ bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
+ return NULL;
+ }
+ }
+ return ua->jcr->store_bsock;
+}
+
+static void close_sd_bsock(UAContext *ua)
+{
+ if (ua->jcr->store_bsock) {
+ bnet_sig(ua->jcr->store_bsock, BNET_TERMINATE);
+ bnet_close(ua->jcr->store_bsock);
+ ua->jcr->store_bsock = NULL;
+ }
+}
+
+static char *get_volume_name_from_SD(UAContext *ua, int Slot)
+{
+ STORE *store = ua->jcr->store;
+ BSOCK *sd;
+ char dev_name[MAX_NAME_LENGTH];
+ char *VolName = NULL;
+ int rtn_slot;
+
+ if (!(sd=open_sd_bsock(ua))) {
+ return NULL;
+ }
+ bstrncpy(dev_name, store->dev_name, sizeof(dev_name));
+ bash_spaces(dev_name);
+ /* Ask for autochanger list of volumes */
+ bnet_fsend(sd, _("readlabel %s Slot=%d\n"), dev_name, Slot);
+ Dmsg1(100, "Sent: %s", sd->msg);
+
+ /* Get Volume name in this Slot */
+ while (bnet_recv(sd) >= 0) {
+ bsendmsg(ua, "%s", sd->msg);
+ if (strncmp(sd->msg, "3001 Volume=", 12) == 0) {
+ VolName = (char *)malloc(sd->msglen);
+ if (sscanf(sd->msg, "3001 Volume=%s Slot=%d", VolName, &rtn_slot) == 2) {
+ break;
+ }
+ free(VolName);
+ VolName = NULL;
+ }
+ }
+ Dmsg1(200, "get_vol_name=%s\n", NPRT(VolName));
+ return VolName;
+}
+
+/*
+ * We get the slot list from the Storage daemon.
+ * If scan is set, we return all slots found,
+ * otherwise, we return only slots with valid barcodes (Volume names)
+ */
+static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan)