#include "bacula.h"
#include "dird.h"
-/* Imported subroutines */
-
-/* Imported variables */
-
-
-/* Imported functions */
-
/* Forward referenced functions */
static int do_label(UAContext *ua, char *cmd, int relabel);
static void label_from_barcodes(UAContext *ua);
+static int is_legal_volume_name(UAContext *ua, char *name);
/*
* Label a tape
return 1;
}
checkName:
- /* Restrict the characters permitted in the Volume name */
- if (strpbrk(ua->cmd, "`~!@#$%^&*()[]{}|\\;'\"<>?,/")) {
- bsendmsg(ua, _("Illegal character | in a volume name.\n"));
- continue;
- }
- if (strlen(ua->cmd) >= MAX_NAME_LENGTH) {
- bsendmsg(ua, _("Volume name too long.\n"));
- continue;
- }
- if (strlen(ua->cmd) == 0) {
- bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+ if (!is_legal_volume_name(ua, ua->cmd)) {
continue;
}
break; /* Got it */
}
- /* Do some more checking on slot ****FIXME**** */
+ /* If autochanger, request slot */
if (store->autochanger) {
for ( ;; ) {
if (!get_cmd(ua, _("Enter slot (0 for none): "))) {
* 3001 OK mount. Device=xxx or
* 3001 Mounted Volume vvvv
*/
- if (strncmp(sd->msg, "3001 ", 5) == 0) {
- mounted = TRUE;
- /***** ****FIXME***** find job waiting for
- ***** mount, and change to waiting for SD
- */
- }
+ mounted = strncmp(sd->msg, "3001 ", 5) == 0;
}
}
} else {
bsendmsg(ua, "%s", db_strerror(ua->db));
}
- 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, _("Volume \"%s\" deleted from catalog.\n"));
+ if (relabel) {
+ 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);
+ }
}
}
if (!mounted) {
return 1;
}
+/*
+ * Request SD to send us the slot:barcodes, then wiffle
+ * through them all labeling them.
+ */
static void label_from_barcodes(UAContext *ua)
{
STORE *store = ua->jcr->store;
sd = ua->jcr->store_bsock;
bnet_fsend(sd, _("autochanger list %s \n"), dev_name);
while (bget_msg(sd, 0) >= 0) {
- bsendmsg(ua, "%s", sd->msg);
+ char *p;
+ int slot;
+ strip_trailing_junk(sd->msg);
+ if (strncmp(sd->msg, "3902 Issuing", 12) == 0 ||
+ strncmp(sd->msg, "3903 Issuing", 12) == 0) {
+ bsendmsg(ua, "%s\n", sd->msg);
+ continue;
+ }
+ p = strchr(sd->msg, ':');
+ if (p && strlen(p) > 1) {
+ *p++ = 0;
+ if (!is_an_integer(sd->msg)) {
+ continue;
+ }
+ } else {
+ continue;
+ }
+ slot = atoi(sd->msg);
+ bsendmsg(ua, "Got slot=%d label: %s\n", slot, p);
}
bnet_sig(sd, BNET_TERMINATE);
bnet_close(sd);
ua->jcr->store_bsock = NULL;
+ return;
+
memset(&pr, 0, sizeof(pr));
if (!select_pool_dbr(ua, &pr)) {
return;
return;
}
+
+static int is_legal_volume_name(UAContext *ua, char *name)
+{
+ int len;
+ /* Restrict the characters permitted in the Volume name */
+ if (strpbrk(name, "`~!@#$%^&*()[]{}|\\;'\"<>?,/")) {
+ bsendmsg(ua, _("Illegal character | in a volume name.\n"));
+ return 0;
+ }
+ len = strlen(name);
+ if (len >= MAX_NAME_LENGTH) {
+ bsendmsg(ua, _("Volume name too long.\n"));
+ return 0;
+ }
+ if (len == 0) {
+ bsendmsg(ua, _("Volume name must be at least one character long.\n"));
+ return 0;
+ }
+ return 1;
+}
* Free the current file, and retrieve the contents
* of the previous packet if any.
*/
-LEX *
-lex_close_file(LEX *lf)
+LEX *lex_close_file(LEX *lf)
{
LEX *of;
* the next field.
*
*/
-LEX *
-lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error)
+LEX *lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error)
{
LEX *nf;
* L_EOF if end of file
* L_EOL if end of line
*/
-int
-lex_get_char(LEX *lf)
+int lex_get_char(LEX *lf)
{
if (lf->ch == L_EOF) {
Emsg0(M_ABORT, 0, "get_char: called after EOF\n");
return lf->ch;
}
-void
-lex_unget_char(LEX *lf)
+void lex_unget_char(LEX *lf)
{
lf->col_no--;
if (lf->ch == L_EOL)
}
#ifdef DEBUG
-static char *
-lex_state_to_str(int state)
+static char *lex_state_to_str(int state)
{
switch (state) {
case lex_none: return "none";
* Convert a lex token to a string
* used for debug/error printing.
*/
-char *
-lex_tok_to_str(int token)
+char *lex_tok_to_str(int token)
{
switch(token) {
case L_EOF: return "L_EOF";