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
42 * Media Entry (medent)
44 * [LABEL][+FILEMARKS][/NBYTES][@SLOT]
46 * LABEL is simple text and must be first.
48 * +FILEMARKS, /NBYTES, and @SLOT may occur in any order.
50 * FILEMARKS is a small decimal number and indicates
51 * how many filemarks to skip when using the media.
52 * 0 means begining of tape. If no +FILEMARKS is given,
53 * 1 is used if LABEL is given, 0 otherwise.
55 * NBYTES indicates the maximum amount of data on the
56 * media. This is a decimal number optionally followed
57 * by a scale character (k, m, g).
59 * SLOT is the slot address in the tape robot. It is
60 * the element address, not relative to the first
65 ndmmedia_from_str (struct ndmmedia *me, char *str)
71 NDMOS_MACRO_ZEROFILL (me);
78 if (c == '+' || c == '@' || c == '/')
81 if (q < &me->label[NDMMEDIA_LABEL_MAX])
93 return -1; /* what is this? */
99 me->slot_addr = strtol (p+1, &p, 0);
104 if (me->valid_filemark)
107 me->file_mark_offset = strtol (p+1, &p, 0);
108 me->valid_filemark = 1;
112 if (me->valid_n_bytes)
115 me->n_bytes = ndmmedia_strtoll (p+1, &p, 0);
116 me->valid_n_bytes = 1;
125 ndmmedia_to_str (struct ndmmedia *me, char *str)
131 if (me->valid_label) {
132 strcpy (q, me->label);
136 if (me->valid_filemark) {
137 sprintf (q, "+%d", me->file_mark_offset);
141 if (me->valid_n_bytes) {
142 if (me->n_bytes == 0)
144 else if (me->n_bytes % (1024*1024*1024) == 0)
145 sprintf (q, "/%lldG", me->n_bytes/(1024*1024*1024));
146 else if (me->n_bytes % (1024*1024) == 0)
147 sprintf (q, "/%lldM", me->n_bytes/(1024*1024));
148 else if (me->n_bytes % (1024) == 0)
149 sprintf (q, "/%lldK", me->n_bytes/(1024));
151 sprintf (q, "/%lld", me->n_bytes);
155 if (me->valid_slot) {
156 sprintf (q, "@%d", me->slot_addr);
164 static char *flag_yes_or_no (int f) { return (f) ? "Y" : "N"; }
167 ndmmedia_pp (struct ndmmedia *me, int lineno, char *buf)
171 ndmmedia_to_str (me, buf);
175 sprintf (buf, "valid label=%s filemark=%s n_bytes=%s slot=%s",
176 flag_yes_or_no (me->valid_label),
177 flag_yes_or_no (me->valid_filemark),
178 flag_yes_or_no (me->valid_n_bytes),
179 flag_yes_or_no (me->valid_slot));
183 sprintf (buf, "media used=%s written=%s eof=%s eom=%s io_error=%s",
184 flag_yes_or_no (me->media_used),
185 flag_yes_or_no (me->media_written),
186 flag_yes_or_no (me->media_eof),
187 flag_yes_or_no (me->media_eom),
188 flag_yes_or_no (me->media_io_error));
192 sprintf (buf, "label read=%s written=%s io_error=%s mismatch=%s",
193 flag_yes_or_no (me->label_read),
194 flag_yes_or_no (me->label_written),
195 flag_yes_or_no (me->label_io_error),
196 flag_yes_or_no (me->label_mismatch));
200 sprintf (buf, "fm_error=%s nb_determined=%s nb_aligned=%s",
201 flag_yes_or_no (me->fmark_error),
202 flag_yes_or_no (me->nb_determined),
203 flag_yes_or_no (me->nb_aligned));
207 sprintf (buf, "slot empty=%s bad=%s missing=%s",
208 flag_yes_or_no (me->slot_empty),
209 flag_yes_or_no (me->slot_bad),
210 flag_yes_or_no (me->slot_missing));
214 strcpy (buf, "<<INVALID>>");
222 ndmmedia_strtoll (char *str, char **tailp, int defbase)
229 if (c < '0' || '9' < c)
251 val *= 1024*1024*1024LL;
256 if (tailp) *tailp = str;