2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include "ndmagents.h"
41 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
45 ndmca_op_init_labels (struct ndm_session *sess)
47 struct ndm_control_agent *ca = &sess->control_acb;
48 struct ndm_job_param * job = &ca->job;
49 struct ndm_media_table *mtab = &job->media_tab;
50 int n_media = mtab->n_media;
54 ca->tape_mode = NDMP9_TAPE_RDWR_MODE;
58 ndmalogf (sess, 0, 0, "No media entries in table");
63 for (i = 0; i < n_media; i++) {
69 ndmalogf (sess, 0, 0, "media #%d missing a label", i+1);
75 rc = ndmca_op_robot_startup (sess, 1);
76 if (rc) return rc; /* already tattled */
78 rc = ndmca_connect_tape_agent (sess);
80 ndmconn_destruct (sess->plumb.tape);
81 return rc; /* already tattled */
84 for (i = 0; i < n_media; i++) {
89 rc = ndmca_media_load_current (sess);
95 rc = ndmca_media_write_label (sess, 'm', me->label);
97 ndmalogf (sess, 0, 0, "failed label write");
100 ndmca_media_write_filemarks(sess);
101 ndmca_media_unload_current (sess);
108 ndmca_op_list_labels (struct ndm_session *sess)
110 struct ndm_control_agent *ca = &sess->control_acb;
111 struct ndm_job_param * job = &ca->job;
112 struct ndm_media_table *mtab = &job->media_tab;
114 char labbuf[NDMMEDIA_LABEL_MAX];
116 struct ndmmedia * me;
119 ca->tape_mode = NDMP9_TAPE_READ_MODE;
122 rc = ndmca_op_robot_startup (sess, 0);
123 if (rc) return rc; /* already tattled */
125 if (job->media_tab.n_media == 0) {
126 if (job->have_robot) {
127 rc = ndmca_robot_synthesize_media (sess);
128 if (rc) return rc; /* already tattled */
131 * No fixup. Should be done by now.
132 * See ndma_job_auto_adjust()
137 if ((rc = ndmca_connect_tape_agent (sess)) != 0) {
138 ndmconn_destruct (sess->plumb.tape);
139 return rc; /* already tattled */
142 n_media = mtab->n_media;
144 for (i = 0; i < n_media; i++) {
145 ca->cur_media_ix = i;
147 me = &mtab->media[i];
149 rc = ndmca_media_load_current (sess);
151 /* already tattled */
155 rc = ndmca_media_read_label (sess, labbuf);
156 if (rc == 'm' || rc == 'V') {
157 strcpy (me->label, labbuf);
159 ndmmedia_to_str (me, buf);
160 ndmalogf (sess, "ME", 0, "%s", buf);
162 ndmalogf (sess, 0, 0, "failed label read");
164 ndmca_media_unload_current (sess);
170 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */