-/*
- * Label a tape
- *
- * label storage=xxx volume=vvv
- */
-static int labelcmd(UAContext *ua, char *cmd)
-{
- STORE *store;
- BSOCK *sd;
- char dev_name[MAX_NAME_LENGTH];
- MEDIA_DBR mr;
- POOL_DBR pr;
- int ok = FALSE;
- int mounted = FALSE;
- int i;
- int slot = 0;
- static char *keyword[] = {
- "volume",
- NULL};
-
- if (!open_db(ua)) {
- return 1;
- }
- store = get_storage_resource(ua, cmd);
- if (!store) {
- return 1;
- }
-
- i = find_arg_keyword(ua, keyword);
- if (i >=0 && ua->argv[i]) {
- strcpy(ua->cmd, ua->argv[i]);
- goto gotVol;
- }
-
-getVol:
- if (!get_cmd(ua, _("Enter new Volume name: "))) {
- return 1;
- }
-gotVol:
- if (strchr(ua->cmd, '|')) {
- bsendmsg(ua, _("Illegal character | in a volume name.\n"));
- goto getVol;
- }
- if (strlen(ua->cmd) >= MAX_NAME_LENGTH) {
- bsendmsg(ua, _("Volume name too long.\n"));
- goto getVol;
- }
- if (strlen(ua->cmd) == 0) {
- bsendmsg(ua, _("Volume name must be at least one character long.\n"));
- goto getVol;
- }
-
-
- memset(&mr, 0, sizeof(mr));
- strcpy(mr.VolumeName, ua->cmd);
- if (db_get_media_record(ua->db, &mr)) {
- bsendmsg(ua, _("Media record for Volume %s already exists.\n"),
- mr.VolumeName);
- return 1;
- }
-
- /* Do some more checking on slot ****FIXME**** */
- if (store->autochanger) {
- if (!get_cmd(ua, _("Enter slot (0 for none): "))) {
- return 1;
- }
- slot = atoi(ua->cmd);
- }
- strcpy(mr.MediaType, store->media_type);
- mr.Slot = slot;
-
- memset(&pr, 0, sizeof(pr));
- if (!select_pool_dbr(ua, &pr)) {
- return 1;
- }
- mr.PoolId = pr.PoolId;
- strcpy(mr.VolStatus, "Append");
- mr.Recycle = pr.Recycle;
- mr.VolRetention = pr.VolRetention;
-
- ua->jcr->store = store;
- 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 1;
- }
- sd = ua->jcr->store_bsock;
- strcpy(dev_name, store->dev_name);
- bash_spaces(dev_name);
- bash_spaces(mr.VolumeName);
- bash_spaces(mr.MediaType);
- bash_spaces(pr.Name);
- bnet_fsend(sd, _("label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d"),
- dev_name, mr.VolumeName, pr.Name, mr.MediaType, mr.Slot);
- bsendmsg(ua, "Sending label command ...\n");
- while (bget_msg(sd, 0) >= 0) {
- bsendmsg(ua, "%s", sd->msg);
- if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
- ok = TRUE;
- }
- }
- ua->jcr->store_bsock = NULL;
- unbash_spaces(dev_name);
- unbash_spaces(mr.VolumeName);
- unbash_spaces(mr.MediaType);
- unbash_spaces(pr.Name);
- if (ok) {
- if (db_create_media_record(ua->db, &mr)) {
- bsendmsg(ua, _("Media record for Volume=%s successfully created.\n"),
- mr.VolumeName);
- if (ua->automount) {
- bsendmsg(ua, _("Requesting mount %s ...\n"), dev_name);
- bash_spaces(dev_name);
- bnet_fsend(sd, "mount %s", dev_name);
- unbash_spaces(dev_name);
- while (bnet_recv(sd) >= 0) {
- bsendmsg(ua, "%s", sd->msg);
- /* Here we can get
- * 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
- */
- }
- }
- }
- } else {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- }
- }
- if (!mounted) {
- bsendmsg(ua, _("Do not forget to mount the drive!!!\n"));
- }
- bnet_sig(sd, BNET_TERMINATE);
- bnet_close(sd);
- return 1;
-}
-