1*b30d1939SAndy Fiddaman /***********************************************************************
2*b30d1939SAndy Fiddaman * *
3*b30d1939SAndy Fiddaman * This software is part of the ast package *
4*b30d1939SAndy Fiddaman * Copyright (c) 1985-2011 AT&T Intellectual Property *
5*b30d1939SAndy Fiddaman * and is licensed under the *
6*b30d1939SAndy Fiddaman * Eclipse Public License, Version 1.0 *
7*b30d1939SAndy Fiddaman * by AT&T Intellectual Property *
8*b30d1939SAndy Fiddaman * *
9*b30d1939SAndy Fiddaman * A copy of the License is available at *
10*b30d1939SAndy Fiddaman * http://www.eclipse.org/org/documents/epl-v10.html *
11*b30d1939SAndy Fiddaman * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12*b30d1939SAndy Fiddaman * *
13*b30d1939SAndy Fiddaman * Information and Software Systems Research *
14*b30d1939SAndy Fiddaman * AT&T Research *
15*b30d1939SAndy Fiddaman * Florham Park NJ *
16*b30d1939SAndy Fiddaman * *
17*b30d1939SAndy Fiddaman * Glenn Fowler <gsf@research.att.com> *
18*b30d1939SAndy Fiddaman * David Korn <dgk@research.att.com> *
19*b30d1939SAndy Fiddaman * Phong Vo <kpv@research.att.com> *
20*b30d1939SAndy Fiddaman * *
21*b30d1939SAndy Fiddaman ***********************************************************************/
22*b30d1939SAndy Fiddaman #pragma prototyped
23*b30d1939SAndy Fiddaman /*
24*b30d1939SAndy Fiddaman * local device pathname for portable tape unit specification is returned
25*b30d1939SAndy Fiddaman * if e is non-null then it is set to the next unused char in s
26*b30d1939SAndy Fiddaman *
27*b30d1939SAndy Fiddaman * <unit><density>[<no-rewind>]
28*b30d1939SAndy Fiddaman * {0-7}[l,m,h,u,c][n]
29*b30d1939SAndy Fiddaman */
30*b30d1939SAndy Fiddaman
31*b30d1939SAndy Fiddaman #include <ast.h>
32*b30d1939SAndy Fiddaman
33*b30d1939SAndy Fiddaman char*
strtape(register const char * s,register char ** e)34*b30d1939SAndy Fiddaman strtape(register const char* s, register char** e)
35*b30d1939SAndy Fiddaman {
36*b30d1939SAndy Fiddaman int mtunit = '0';
37*b30d1939SAndy Fiddaman int mtdensity = 0;
38*b30d1939SAndy Fiddaman char mtrewind[2];
39*b30d1939SAndy Fiddaman char mtbehavior[2];
40*b30d1939SAndy Fiddaman
41*b30d1939SAndy Fiddaman static char tapefile[sizeof("/dev/Xrmt/123456789")];
42*b30d1939SAndy Fiddaman
43*b30d1939SAndy Fiddaman mtrewind[0] = mtrewind[1] = mtbehavior[0] = mtbehavior[1] = 0;
44*b30d1939SAndy Fiddaman for (;;)
45*b30d1939SAndy Fiddaman {
46*b30d1939SAndy Fiddaman switch (*s)
47*b30d1939SAndy Fiddaman {
48*b30d1939SAndy Fiddaman case '0':
49*b30d1939SAndy Fiddaman case '1':
50*b30d1939SAndy Fiddaman case '2':
51*b30d1939SAndy Fiddaman case '3':
52*b30d1939SAndy Fiddaman case '4':
53*b30d1939SAndy Fiddaman case '5':
54*b30d1939SAndy Fiddaman case '6':
55*b30d1939SAndy Fiddaman case '7':
56*b30d1939SAndy Fiddaman mtunit = *s++;
57*b30d1939SAndy Fiddaman continue;
58*b30d1939SAndy Fiddaman case 'b':
59*b30d1939SAndy Fiddaman case 'v':
60*b30d1939SAndy Fiddaman mtbehavior[0] = *s++;
61*b30d1939SAndy Fiddaman continue;
62*b30d1939SAndy Fiddaman case 'l':
63*b30d1939SAndy Fiddaman case 'm':
64*b30d1939SAndy Fiddaman case 'h':
65*b30d1939SAndy Fiddaman case 'u':
66*b30d1939SAndy Fiddaman case 'c':
67*b30d1939SAndy Fiddaman mtdensity = *s++;
68*b30d1939SAndy Fiddaman continue;
69*b30d1939SAndy Fiddaman case 'n':
70*b30d1939SAndy Fiddaman mtrewind[0] = *s++;
71*b30d1939SAndy Fiddaman continue;
72*b30d1939SAndy Fiddaman }
73*b30d1939SAndy Fiddaman break;
74*b30d1939SAndy Fiddaman }
75*b30d1939SAndy Fiddaman if (e) *e = (char*)s;
76*b30d1939SAndy Fiddaman if (!access("/dev/rmt/.", F_OK))
77*b30d1939SAndy Fiddaman {
78*b30d1939SAndy Fiddaman /*
79*b30d1939SAndy Fiddaman * system V
80*b30d1939SAndy Fiddaman */
81*b30d1939SAndy Fiddaman
82*b30d1939SAndy Fiddaman if (!mtdensity) mtdensity = 'm';
83*b30d1939SAndy Fiddaman sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/ctape%c%s", mtunit, mtrewind);
84*b30d1939SAndy Fiddaman if (!access(tapefile, F_OK)) return(tapefile);
85*b30d1939SAndy Fiddaman for (;;)
86*b30d1939SAndy Fiddaman {
87*b30d1939SAndy Fiddaman sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/%c%c%s%s", mtunit, mtdensity, mtbehavior, mtrewind);
88*b30d1939SAndy Fiddaman if (!access(tapefile, F_OK)) return(tapefile);
89*b30d1939SAndy Fiddaman if (!mtbehavior[0]) break;
90*b30d1939SAndy Fiddaman mtbehavior[0] = 0;
91*b30d1939SAndy Fiddaman }
92*b30d1939SAndy Fiddaman }
93*b30d1939SAndy Fiddaman else if (!access("/dev/nst0", F_OK))
94*b30d1939SAndy Fiddaman {
95*b30d1939SAndy Fiddaman /*
96*b30d1939SAndy Fiddaman * linux
97*b30d1939SAndy Fiddaman */
98*b30d1939SAndy Fiddaman
99*b30d1939SAndy Fiddaman sfsprintf(tapefile, sizeof(tapefile), "/dev/%sst%c", mtrewind, mtunit);
100*b30d1939SAndy Fiddaman }
101*b30d1939SAndy Fiddaman else if (!access("/dev/nrmt0", F_OK))
102*b30d1939SAndy Fiddaman {
103*b30d1939SAndy Fiddaman /*
104*b30d1939SAndy Fiddaman * 9th edition
105*b30d1939SAndy Fiddaman */
106*b30d1939SAndy Fiddaman
107*b30d1939SAndy Fiddaman switch (mtdensity)
108*b30d1939SAndy Fiddaman {
109*b30d1939SAndy Fiddaman case 'l':
110*b30d1939SAndy Fiddaman mtunit = '0';
111*b30d1939SAndy Fiddaman break;
112*b30d1939SAndy Fiddaman case 'm':
113*b30d1939SAndy Fiddaman mtunit = '1';
114*b30d1939SAndy Fiddaman break;
115*b30d1939SAndy Fiddaman case 'h':
116*b30d1939SAndy Fiddaman mtunit = '2';
117*b30d1939SAndy Fiddaman break;
118*b30d1939SAndy Fiddaman }
119*b30d1939SAndy Fiddaman sfsprintf(tapefile, sizeof(tapefile), "/dev/%srmt%c", mtrewind, mtunit);
120*b30d1939SAndy Fiddaman }
121*b30d1939SAndy Fiddaman else
122*b30d1939SAndy Fiddaman {
123*b30d1939SAndy Fiddaman /*
124*b30d1939SAndy Fiddaman * BSD
125*b30d1939SAndy Fiddaman */
126*b30d1939SAndy Fiddaman
127*b30d1939SAndy Fiddaman mtunit -= '0';
128*b30d1939SAndy Fiddaman switch (mtdensity)
129*b30d1939SAndy Fiddaman {
130*b30d1939SAndy Fiddaman case 'l':
131*b30d1939SAndy Fiddaman break;
132*b30d1939SAndy Fiddaman case 'h':
133*b30d1939SAndy Fiddaman mtunit |= 020;
134*b30d1939SAndy Fiddaman break;
135*b30d1939SAndy Fiddaman default:
136*b30d1939SAndy Fiddaman mtunit |= 010;
137*b30d1939SAndy Fiddaman break;
138*b30d1939SAndy Fiddaman }
139*b30d1939SAndy Fiddaman switch (mtrewind[0])
140*b30d1939SAndy Fiddaman {
141*b30d1939SAndy Fiddaman case 'n':
142*b30d1939SAndy Fiddaman mtunit |= 040;
143*b30d1939SAndy Fiddaman break;
144*b30d1939SAndy Fiddaman }
145*b30d1939SAndy Fiddaman sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt%d", mtunit);
146*b30d1939SAndy Fiddaman }
147*b30d1939SAndy Fiddaman return(tapefile);
148*b30d1939SAndy Fiddaman }
149