14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * Phong Vo <kpv@research.att.com> *
204887Schin * *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin * local device pathname for portable tape unit specification is returned
254887Schin * if e is non-null then it is set to the next unused char in s
264887Schin *
274887Schin * <unit><density>[<no-rewind>]
284887Schin * {0-7}[l,m,h,u,c][n]
294887Schin */
304887Schin
314887Schin #include <ast.h>
324887Schin
334887Schin char*
strtape(register const char * s,register char ** e)344887Schin strtape(register const char* s, register char** e)
354887Schin {
364887Schin int mtunit = '0';
374887Schin int mtdensity = 0;
384887Schin char mtrewind[2];
394887Schin char mtbehavior[2];
404887Schin
414887Schin static char tapefile[sizeof("/dev/Xrmt/123456789")];
424887Schin
434887Schin mtrewind[0] = mtrewind[1] = mtbehavior[0] = mtbehavior[1] = 0;
444887Schin for (;;)
454887Schin {
464887Schin switch (*s)
474887Schin {
484887Schin case '0':
494887Schin case '1':
504887Schin case '2':
514887Schin case '3':
524887Schin case '4':
534887Schin case '5':
544887Schin case '6':
554887Schin case '7':
564887Schin mtunit = *s++;
574887Schin continue;
584887Schin case 'b':
594887Schin case 'v':
604887Schin mtbehavior[0] = *s++;
614887Schin continue;
624887Schin case 'l':
634887Schin case 'm':
644887Schin case 'h':
654887Schin case 'u':
664887Schin case 'c':
674887Schin mtdensity = *s++;
684887Schin continue;
694887Schin case 'n':
704887Schin mtrewind[0] = *s++;
714887Schin continue;
724887Schin }
734887Schin break;
744887Schin }
754887Schin if (e) *e = (char*)s;
764887Schin if (!access("/dev/rmt/.", F_OK))
774887Schin {
784887Schin /*
794887Schin * system V
804887Schin */
814887Schin
824887Schin if (!mtdensity) mtdensity = 'm';
834887Schin sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/ctape%c%s", mtunit, mtrewind);
844887Schin if (!access(tapefile, F_OK)) return(tapefile);
854887Schin for (;;)
864887Schin {
874887Schin sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt/%c%c%s%s", mtunit, mtdensity, mtbehavior, mtrewind);
884887Schin if (!access(tapefile, F_OK)) return(tapefile);
894887Schin if (!mtbehavior[0]) break;
904887Schin mtbehavior[0] = 0;
914887Schin }
924887Schin }
934887Schin else if (!access("/dev/nst0", F_OK))
944887Schin {
954887Schin /*
964887Schin * linux
974887Schin */
984887Schin
994887Schin sfsprintf(tapefile, sizeof(tapefile), "/dev/%sst%c", mtrewind, mtunit);
1004887Schin }
1014887Schin else if (!access("/dev/nrmt0", F_OK))
1024887Schin {
1034887Schin /*
1044887Schin * 9th edition
1054887Schin */
1064887Schin
1074887Schin switch (mtdensity)
1084887Schin {
1094887Schin case 'l':
1104887Schin mtunit = '0';
1114887Schin break;
1124887Schin case 'm':
1134887Schin mtunit = '1';
1144887Schin break;
1154887Schin case 'h':
1164887Schin mtunit = '2';
1174887Schin break;
1184887Schin }
1194887Schin sfsprintf(tapefile, sizeof(tapefile), "/dev/%srmt%c", mtrewind, mtunit);
1204887Schin }
1214887Schin else
1224887Schin {
1234887Schin /*
1244887Schin * BSD
1254887Schin */
1264887Schin
1274887Schin mtunit -= '0';
1284887Schin switch (mtdensity)
1294887Schin {
1304887Schin case 'l':
1314887Schin break;
1324887Schin case 'h':
1334887Schin mtunit |= 020;
1344887Schin break;
1354887Schin default:
1364887Schin mtunit |= 010;
1374887Schin break;
1384887Schin }
1394887Schin switch (mtrewind[0])
1404887Schin {
1414887Schin case 'n':
1424887Schin mtunit |= 040;
1434887Schin break;
1444887Schin }
1454887Schin sfsprintf(tapefile, sizeof(tapefile), "/dev/rmt%d", mtunit);
1464887Schin }
1474887Schin return(tapefile);
1484887Schin }
149