/* Forward referenced functions */
-static int do_label(UAContext *ua, char *cmd, int relabel);
+static int do_label(UAContext *ua, const char *cmd, int relabel);
static void label_from_barcodes(UAContext *ua);
-static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
+static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel, bool media_record_exits);
static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan);
static void free_vol_list(vol_list_t *vol_list);
*
* label storage=xxx volume=vvv
*/
-int label_cmd(UAContext *ua, char *cmd)
+int label_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, 0); /* standard label */
}
-int relabel_cmd(UAContext *ua, char *cmd)
+int relabel_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, 1); /* relabel tape */
}
static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
{
int i;
- char *msg;
+ const char *msg;
for (int i=0; i<num_slots; i++) {
slot_list[i] = 0;
/* Walk through the list updating the media records */
for (vl=vol_list; vl; vl=vl->next) {
+ if (vl->Slot >= max_slots) {
+ bsendmsg(ua, _("Slot %d larger than max %d ignored.\n"));
+ continue;
+ }
/* Check if user wants us to look at this slot */
if (!slot_list[vl->Slot]) {
Dmsg1(100, "Skipping slot=%d\n", vl->Slot);
vl->VolName = get_volume_name_from_SD(ua, vl->Slot);
Dmsg2(100, "Got Vol=%s from SD for Slot=%d\n", vl->VolName, vl->Slot);
}
+ slot_list[vl->Slot] = 0; /* clear Slot */
if (!vl->VolName) {
- Dmsg1(100, "No VolName for Slot=%d skipping.\n", vl->Slot);
+ Dmsg1(100, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
+ memset(&mr, 0, sizeof(mr));
+ mr.Slot = vl->Slot;
+ mr.InChanger = 1;
+ /* Set InChanger to zero for this Slot */
+ db_lock(ua->db);
+ db_make_inchanger_unique(ua->jcr, ua->db, &mr);
+ db_unlock(ua->db);
+ bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
continue;
}
memset(&mr, 0, sizeof(mr));
mr.Slot = vl->Slot;
mr.InChanger = 1;
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
- bsendmsg(ua, _("%s\n"), db_strerror(ua->db));
+ bsendmsg(ua, "%s", db_strerror(ua->db));
} else {
bsendmsg(ua, _(
"Catalog record for Volume \"%s\" updated to reference slot %d.\n"),
}
db_unlock(ua->db);
}
-
-
+ memset(&mr, 0, sizeof(mr));
+ mr.InChanger = 1;
+ for (int i=1; i<max_slots; i++) {
+ if (slot_list[i]) {
+ mr.Slot = i;
+ /* Set InChanger to zero for this Slot */
+ db_lock(ua->db);
+ db_make_inchanger_unique(ua->jcr, ua->db, &mr);
+ db_unlock(ua->db);
+ bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), i);
+ }
+ }
+
bail_out:
free_vol_list(vol_list);
/*
* Common routine for both label and relabel
*/
-static int do_label(UAContext *ua, char *cmd, int relabel)
+static int do_label(UAContext *ua, const char *cmd, int relabel)
{
STORE *store;
BSOCK *sd;
int ok = FALSE;
int i;
bool media_record_exists = false;
- static char *barcode_keyword[] = {
+ static const char *barcode_keyword[] = {
"barcode",
"barcodes",
NULL};
if (ok) {
sd = ua->jcr->store_bsock;
if (relabel) {
+ /* Delete the old media record */
if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
omr.VolumeName, db_strerror(ua->db));
} else {
bsendmsg(ua, _("Old volume \"%s\" deleted from catalog.\n"),
omr.VolumeName);
+ /* Update the number of Volumes in the pool */
+ pr.NumVols--;
+ if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
+ bsendmsg(ua, "%s", db_strerror(ua->db));
+ }
}
}
if (ua->automount) {
slot_list = (char *)malloc(max_slots);
if (!get_user_slot_list(ua, slot_list, max_slots)) {
- free(slot_list);
- return;
+ goto bail_out;
}
vol_list = get_vol_list_from_SD(ua, false /*no scan*/);
if (db_create_media_record(ua->jcr, ua->db, &mr)) {
bsendmsg(ua, _("Catalog record for cleaning tape \"%s\" successfully created.\n"),
mr.VolumeName);
+ pr.NumVols++; /* this is a bit suspect */
+ if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
+ bsendmsg(ua, "%s", db_strerror(ua->db));
+ }
} else {
bsendmsg(ua, "Catalog error on cleaning tape: %s", db_strerror(ua->db));
}
bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
mr.Slot = vl->Slot;
- if (!send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists)) {
- goto bail_out;
- }
+ send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists);
}
bail_out:
+ free(slot_list);
free_vol_list(vol_list);
close_sd_bsock(ua);
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
-bool is_volume_name_legal(UAContext *ua, char *name)
+bool is_volume_name_legal(UAContext *ua, const char *name)
{
int len;
- char *p;
- char *accept = ":.-_";
+ const char *p;
+ const char *accept = ":.-_";
/* Restrict the characters permitted in the Volume name */
for (p=name; *p; p++) {
/*
* NOTE! This routine opens the SD socket but leaves it open
*/
-static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
- POOL_DBR *pr, int relabel, bool media_record_exists)
+static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
+ POOL_DBR *pr, int relabel, bool media_record_exists)
{
BSOCK *sd;
char dev_name[MAX_NAME_LENGTH];
- int ok = FALSE;
+ bool ok = false;
if (!(sd=open_sd_bsock(ua))) {
- return 0;
+ return false;
}
bstrncpy(dev_name, ua->jcr->store->dev_name, sizeof(dev_name));
bash_spaces(dev_name);
while (bnet_recv(sd) >= 0) {
bsendmsg(ua, "%s", sd->msg);
if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
- ok = TRUE;
+ ok = true;
}
}
unbash_spaces(mr->VolumeName);
mr->InChanger = 1;
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
- ok = FALSE;
+ ok = false;
}
} else { /* create the media record */
set_pool_dbr_defaults_in_media_dbr(mr, pr);
if (db_create_media_record(ua->jcr, ua->db, mr)) {
bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
mr->VolumeName, mr->Slot);
+ /* Update number of volumes in pool */
+ pr->NumVols++;
+ if (!db_update_pool_record(ua->jcr, ua->db, pr)) {
+ bsendmsg(ua, "%s", db_strerror(ua->db));
+ }
} else {
bsendmsg(ua, "%s", db_strerror(ua->db));
- ok = FALSE;
+ ok = false;
}
}
} else {
- bsendmsg(ua, _("Label command failed.\n"));
+ bsendmsg(ua, _("Label command failed for Volume %s.\n"), mr->VolumeName);
}
return ok;
}
static void free_vol_list(vol_list_t *vol_list)
{
vol_list_t *vl;
+
/* Free list */
for (vl=vol_list; vl; ) {
vol_list_t *ovl;