Example #1
0
/*
 * type is either 'm' or 'V', see above
 */
int
ndmca_media_check_label (struct ndm_session *sess, int type, char labbuf[])
{
	int		rc;
	char		mylabbuf[NDMMEDIA_LABEL_MAX];

	ndmalogf (sess, 0, 1, "Checking tape label, expect '%s'", labbuf);

	rc = ndmca_media_read_label (sess, mylabbuf);
	if (rc < 0) {
		ndmalogf (sess, 0, 0, "Label read error");
		return -1;
	}

	if (rc != type || strcmp (labbuf, mylabbuf) != 0) {
		ndmalogf (sess, 0, 0,
			"Label mismatch, expected -%c'%s', got -%c'%s'",
			type, labbuf, rc, mylabbuf);
		return -2;
	}

	return 0;
}
Example #2
0
int
ndmca_op_list_labels (struct ndm_session *sess)
{
    struct ndm_control_agent *ca = sess->control_acb;
    struct ndm_job_param *	job = &ca->job;
    struct ndm_media_table *mtab = &job->media_tab;
    int			n_media;
    char			labbuf[NDMMEDIA_LABEL_MAX];
    char			buf[200];
    struct ndmmedia *	me;
    int			rc;

    ca->tape_mode = NDMP9_TAPE_READ_MODE;
    ca->is_label_op = 1;

    rc = ndmca_op_robot_startup (sess, 0);
    if (rc) return rc;	/* already tattled */

    if (job->media_tab.n_media == 0) {
        if (job->have_robot) {
            rc = ndmca_robot_synthesize_media (sess);
            if (rc) return rc;	/* already tattled */
        } else {
            /*
             * No fixup. Should be done by now.
             * See ndma_job_auto_adjust()
             */
        }
    }

    if ((rc = ndmca_connect_tape_agent (sess)) != 0) {
        ndmconn_destruct (sess->plumb.tape);
        sess->plumb.tape = NULL;
        return rc;	/* already tattled */
    }

    n_media = mtab->n_media;

    for (me = mtab->head; me; me = me->next) {
        ca->cur_media_ix = me->index;

        rc = ndmca_media_load_current (sess);
        if (rc) {
            /* already tattled */
            continue;
        }

        rc = ndmca_media_read_label (sess, labbuf);
        if (rc == 'm' || rc == 'V') {
            strcpy (me->label, labbuf);
            me->valid_label = 1;
            ndmmedia_to_str (me, buf);
            ndmalogf (sess, "ME", 0, "%s", buf);
        } else {
            ndmalogf (sess, 0, 0, "failed label read");
        }
        ndmca_media_unload_current (sess);
    }

    return rc;
}