xref: /titanic_53/usr/src/cmd/allocate/mkdevalloc.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1992-2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * scan /dev directory for mountable objects and construct device_allocate
31*7c478bd9Sstevel@tonic-gate  * file for allocate....
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * devices are:
34*7c478bd9Sstevel@tonic-gate  *	tape (cartridge)
35*7c478bd9Sstevel@tonic-gate  *		/dev/rst*
36*7c478bd9Sstevel@tonic-gate  *		/dev/nrst*
37*7c478bd9Sstevel@tonic-gate  *		/dev/rmt/...
38*7c478bd9Sstevel@tonic-gate  *	audio
39*7c478bd9Sstevel@tonic-gate  *		/dev/audio
40*7c478bd9Sstevel@tonic-gate  *		/dev/audioctl
41*7c478bd9Sstevel@tonic-gate  *		/dev/sound/...
42*7c478bd9Sstevel@tonic-gate  *	floppy
43*7c478bd9Sstevel@tonic-gate  *		/dev/diskette
44*7c478bd9Sstevel@tonic-gate  *		/dev/fd*
45*7c478bd9Sstevel@tonic-gate  *		/dev/rdiskette
46*7c478bd9Sstevel@tonic-gate  *		/dev/rfd*
47*7c478bd9Sstevel@tonic-gate  *	CD
48*7c478bd9Sstevel@tonic-gate  *		/dev/sr*
49*7c478bd9Sstevel@tonic-gate  *		/dev/nsr*
50*7c478bd9Sstevel@tonic-gate  *		/dev/dsk/c?t?d0s?
51*7c478bd9Sstevel@tonic-gate  *		/dev/rdsk/c?t?d0s?
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #include <sys/types.h>	/* for stat(2), etc. */
55*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
56*7c478bd9Sstevel@tonic-gate #include <dirent.h>	/* for readdir(3), etc. */
57*7c478bd9Sstevel@tonic-gate #include <unistd.h>	/* for readlink(2) */
58*7c478bd9Sstevel@tonic-gate #include <string.h>	/* for strcpy(3), etc. */
59*7c478bd9Sstevel@tonic-gate #include <strings.h>	/* for bcopy(3C), etc. */
60*7c478bd9Sstevel@tonic-gate #include <stdio.h>	/* for perror(3) */
61*7c478bd9Sstevel@tonic-gate #include <stdlib.h>	/* for atoi(3) */
62*7c478bd9Sstevel@tonic-gate #include <locale.h>
63*7c478bd9Sstevel@tonic-gate #include <libintl.h>
64*7c478bd9Sstevel@tonic-gate #include <auth_attr.h>
65*7c478bd9Sstevel@tonic-gate #include <auth_list.h>
66*7c478bd9Sstevel@tonic-gate #include "allocate.h"   /* for SECLIB */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN
69*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SUNW_OST_OSCMD"
70*7c478bd9Sstevel@tonic-gate #endif
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #define	DELTA	5	/* array size delta when full */
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate /* "/dev/rst...", "/dev/nrst...", "/dev/rmt/..." */
75*7c478bd9Sstevel@tonic-gate struct tape {
76*7c478bd9Sstevel@tonic-gate 	char	*name;
77*7c478bd9Sstevel@tonic-gate 	char	*device;
78*7c478bd9Sstevel@tonic-gate 	int	number;
79*7c478bd9Sstevel@tonic-gate } *tape;
80*7c478bd9Sstevel@tonic-gate #define	DFLT_NTAPE  10		/* size of initial array */
81*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_RST  3		/* |rmt| */
82*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_NRST 4		/* |nrmt| */
83*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_TMP  4		/* |/tmp| */
84*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_RMT  8		/* |/dev/rmt| */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /* "/dev/audio", "/dev/audioctl", "/dev/sound/..." */
87*7c478bd9Sstevel@tonic-gate struct audio {
88*7c478bd9Sstevel@tonic-gate 	char	*name;
89*7c478bd9Sstevel@tonic-gate 	char	*device;
90*7c478bd9Sstevel@tonic-gate 	int	number;
91*7c478bd9Sstevel@tonic-gate } *audio;
92*7c478bd9Sstevel@tonic-gate #define	DFLT_NAUDIO   10	/* size of initial array */
93*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_SOUND 10	/* |/dev/sound| */
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate /* "/dev/sr", "/dev/nsr", "/dev/dsk/c?t?d0s?", "/dev/rdsk/c?t?d0s?" */
96*7c478bd9Sstevel@tonic-gate struct cd {
97*7c478bd9Sstevel@tonic-gate 	char	*name;
98*7c478bd9Sstevel@tonic-gate 	char	*device;
99*7c478bd9Sstevel@tonic-gate 	int	id;
100*7c478bd9Sstevel@tonic-gate 	int	controller;
101*7c478bd9Sstevel@tonic-gate 	int	number;
102*7c478bd9Sstevel@tonic-gate } *cd;
103*7c478bd9Sstevel@tonic-gate #define	DFLT_NCD    10		/* size of initial array */
104*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_SR   2		/* |sr| */
105*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_RSR  3		/* |rsr| */
106*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_DSK  8		/* |/dev/dsk| */
107*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_RDSK 9		/* |/dev/rdsk| */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /* "/dev/fd0*", "/dev/rfd0*", "/dev/fd1*", "/dev/rfd1*" */
111*7c478bd9Sstevel@tonic-gate struct fp {
112*7c478bd9Sstevel@tonic-gate 	char *name;
113*7c478bd9Sstevel@tonic-gate 	char *device;
114*7c478bd9Sstevel@tonic-gate 	int number;
115*7c478bd9Sstevel@tonic-gate } *fp;
116*7c478bd9Sstevel@tonic-gate #define	DFLT_NFP    10		/* size of initial array */
117*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_FD0  3		/* |fd0| */
118*7c478bd9Sstevel@tonic-gate #define	SIZE_OF_RFD0 4		/* |rfd0| */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate static void dotape();
121*7c478bd9Sstevel@tonic-gate static void doaudio();
122*7c478bd9Sstevel@tonic-gate static void dofloppy();
123*7c478bd9Sstevel@tonic-gate static void docd();
124*7c478bd9Sstevel@tonic-gate static void initmem();
125*7c478bd9Sstevel@tonic-gate static int  expandmem(int, void **, int);
126*7c478bd9Sstevel@tonic-gate static void no_memory(void);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate void
129*7c478bd9Sstevel@tonic-gate main()
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
132*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	initmem();		/* initialize memory */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	dotape();		/* do tape */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	doaudio();		/* do audio */
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	dofloppy();		/* do floppy */
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	docd();			/* do cd */
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate static void
146*7c478bd9Sstevel@tonic-gate dotape()
147*7c478bd9Sstevel@tonic-gate {
148*7c478bd9Sstevel@tonic-gate 	DIR *dirp;
149*7c478bd9Sstevel@tonic-gate 	struct dirent *dep;	/* directory entry pointer */
150*7c478bd9Sstevel@tonic-gate 	int	i, j, n;
151*7c478bd9Sstevel@tonic-gate 	char	*nm;		/* name/device of special device */
152*7c478bd9Sstevel@tonic-gate 	char	linkvalue[2048];	/* symlink value */
153*7c478bd9Sstevel@tonic-gate 	struct stat stat;	/* determine if it's a symlink */
154*7c478bd9Sstevel@tonic-gate 	int	sz;		/* size of symlink value */
155*7c478bd9Sstevel@tonic-gate 	char	*cp;		/* pointer into string */
156*7c478bd9Sstevel@tonic-gate 	int	ntape;		/* max array size */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	ntape = DFLT_NTAPE;
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	/*
161*7c478bd9Sstevel@tonic-gate 	 * look for rst* and nrst*
162*7c478bd9Sstevel@tonic-gate 	 */
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev")) == NULL) {
165*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev failure"));
166*7c478bd9Sstevel@tonic-gate 		exit(1);
167*7c478bd9Sstevel@tonic-gate 	}
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	i = 0;
170*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
171*7c478bd9Sstevel@tonic-gate 		/* ignore if neither rst* nor nrst* */
172*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, "rst", SIZE_OF_RST) &&
173*7c478bd9Sstevel@tonic-gate 		    strncmp(dep->d_name, "nrst", SIZE_OF_NRST))
174*7c478bd9Sstevel@tonic-gate 			continue;
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
177*7c478bd9Sstevel@tonic-gate 		if (i == ntape) {
178*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
179*7c478bd9Sstevel@tonic-gate 			ntape = expandmem(i, (void **)&tape,
180*7c478bd9Sstevel@tonic-gate 					sizeof (struct tape));
181*7c478bd9Sstevel@tonic-gate 		}
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 		/* save name (/dev + / + d_name + \0) */
184*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_TMP + 1 + strlen(dep->d_name) + 1);
185*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
186*7c478bd9Sstevel@tonic-gate 			no_memory();
187*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/");
188*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
189*7c478bd9Sstevel@tonic-gate 		tape[i].name = nm;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 		/* ignore if not symbolic link (note i not incremented) */
192*7c478bd9Sstevel@tonic-gate 		if (lstat(tape[i].name, &stat) < 0) {
193*7c478bd9Sstevel@tonic-gate 			perror("stat(2) failed ");
194*7c478bd9Sstevel@tonic-gate 			exit(1);
195*7c478bd9Sstevel@tonic-gate 		}
196*7c478bd9Sstevel@tonic-gate 		if ((stat.st_mode & S_IFMT) != S_IFLNK)
197*7c478bd9Sstevel@tonic-gate 			continue;
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 		/* get name from symbolic link */
200*7c478bd9Sstevel@tonic-gate 		if ((sz = readlink(tape[i].name, linkvalue,
201*7c478bd9Sstevel@tonic-gate 				sizeof (linkvalue))) < 0)
202*7c478bd9Sstevel@tonic-gate 			continue;
203*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(sz + 1);
204*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
205*7c478bd9Sstevel@tonic-gate 			no_memory();
206*7c478bd9Sstevel@tonic-gate 		(void) strncpy(nm, linkvalue, sz);
207*7c478bd9Sstevel@tonic-gate 		nm[sz] = '\0';
208*7c478bd9Sstevel@tonic-gate 		tape[i].device = nm;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 		/* get device number */
211*7c478bd9Sstevel@tonic-gate 		cp = strrchr(tape[i].device, '/');
212*7c478bd9Sstevel@tonic-gate 		cp++;				/* advance to device # */
213*7c478bd9Sstevel@tonic-gate 		(void) sscanf(cp, "%d", &tape[i].number);
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 		i++;
216*7c478bd9Sstevel@tonic-gate 	}
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate 	/*
221*7c478bd9Sstevel@tonic-gate 	 * scan /dev/rmt and add entry to table
222*7c478bd9Sstevel@tonic-gate 	 */
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev/rmt")) == NULL) {
225*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev failure"));
226*7c478bd9Sstevel@tonic-gate 		exit(1);
227*7c478bd9Sstevel@tonic-gate 	}
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
230*7c478bd9Sstevel@tonic-gate 		/* skip . .. etc... */
231*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, ".", 1) == NULL)
232*7c478bd9Sstevel@tonic-gate 			continue;
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
235*7c478bd9Sstevel@tonic-gate 		if (i == ntape) {
236*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
237*7c478bd9Sstevel@tonic-gate 			ntape = expandmem(i, (void **)&tape,
238*7c478bd9Sstevel@tonic-gate 					sizeof (struct tape));
239*7c478bd9Sstevel@tonic-gate 		}
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 		/* save name (/dev/rmt + / + d_name + \0) */
242*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_RMT + 1 + strlen(dep->d_name) + 1);
243*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
244*7c478bd9Sstevel@tonic-gate 			no_memory();
245*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/rmt/");
246*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
247*7c478bd9Sstevel@tonic-gate 		tape[i].name = nm;
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate 		/* save device name (rmt/ + d_name + \0) */
250*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_TMP + strlen(dep->d_name) + 1);
251*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
252*7c478bd9Sstevel@tonic-gate 			no_memory();
253*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "rmt/");
254*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
255*7c478bd9Sstevel@tonic-gate 		tape[i].device = nm;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 		(void) sscanf(dep->d_name, "%d", &tape[i].number);
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 		i++;
260*7c478bd9Sstevel@tonic-gate 	}
261*7c478bd9Sstevel@tonic-gate 	n = i;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	/* remove duplicate entries */
266*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < n - 1; i++) {
267*7c478bd9Sstevel@tonic-gate 		for (j = i + 1; j < n; j++) {
268*7c478bd9Sstevel@tonic-gate 			if (strcmp(tape[i].device, tape[j].device))
269*7c478bd9Sstevel@tonic-gate 				continue;
270*7c478bd9Sstevel@tonic-gate 			tape[j].number = -1;
271*7c478bd9Sstevel@tonic-gate 		}
272*7c478bd9Sstevel@tonic-gate 	}
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 	/* print out device_allocate entries for tape devices */
275*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
276*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < n; j++) {
277*7c478bd9Sstevel@tonic-gate 			if (tape[j].number == i) {
278*7c478bd9Sstevel@tonic-gate 				(void) printf(
279*7c478bd9Sstevel@tonic-gate 					"st%d;st;reserved;reserved;%s;",
280*7c478bd9Sstevel@tonic-gate 					i, DEFAULT_DEV_ALLOC_AUTH);
281*7c478bd9Sstevel@tonic-gate 				(void) printf("%s%s\n", SECLIB, "/st_clean");
282*7c478bd9Sstevel@tonic-gate 				break;
283*7c478bd9Sstevel@tonic-gate 			}
284*7c478bd9Sstevel@tonic-gate 		}
285*7c478bd9Sstevel@tonic-gate 	}
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate static void
289*7c478bd9Sstevel@tonic-gate doaudio()
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate 	DIR *dirp;
292*7c478bd9Sstevel@tonic-gate 	struct dirent *dep;	/* directory entry pointer */
293*7c478bd9Sstevel@tonic-gate 	int	i, j, n;
294*7c478bd9Sstevel@tonic-gate 	char	*nm;		/* name/device of special device */
295*7c478bd9Sstevel@tonic-gate 	char	linkvalue[2048];	/* symlink value */
296*7c478bd9Sstevel@tonic-gate 	struct stat stat;	/* determine if it's a symlink */
297*7c478bd9Sstevel@tonic-gate 	int	sz;		/* size of symlink value */
298*7c478bd9Sstevel@tonic-gate 	char	*cp;		/* pointer into string */
299*7c478bd9Sstevel@tonic-gate 	int	naudio;		/* max array size */
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 	naudio = DFLT_NAUDIO;
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev")) == NULL) {
304*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev failure"));
305*7c478bd9Sstevel@tonic-gate 		exit(1);
306*7c478bd9Sstevel@tonic-gate 	}
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 	i = 0;
309*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
310*7c478bd9Sstevel@tonic-gate 		if (strcmp(dep->d_name, "audio") &&
311*7c478bd9Sstevel@tonic-gate 		    strcmp(dep->d_name, "audioctl"))
312*7c478bd9Sstevel@tonic-gate 			continue;
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
315*7c478bd9Sstevel@tonic-gate 		if (i == naudio) {
316*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
317*7c478bd9Sstevel@tonic-gate 			naudio = expandmem(i, (void **)&audio,
318*7c478bd9Sstevel@tonic-gate 					sizeof (struct audio));
319*7c478bd9Sstevel@tonic-gate 		}
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 		/* save name (/dev + 1 + d_name + \0) */
322*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_TMP + 1 + strlen(dep->d_name) + 1);
323*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
324*7c478bd9Sstevel@tonic-gate 			no_memory();
325*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/");
326*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
327*7c478bd9Sstevel@tonic-gate 		audio[i].name = nm;
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate 		/* ignore if not symbolic link (note i not incremented) */
330*7c478bd9Sstevel@tonic-gate 		if (lstat(audio[i].name, &stat) < 0) {
331*7c478bd9Sstevel@tonic-gate 			perror(gettext("stat(2) failed "));
332*7c478bd9Sstevel@tonic-gate 			exit(1);
333*7c478bd9Sstevel@tonic-gate 		}
334*7c478bd9Sstevel@tonic-gate 		if ((stat.st_mode & S_IFMT) != S_IFLNK)
335*7c478bd9Sstevel@tonic-gate 			continue;
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 		/* get name from symbolic link */
338*7c478bd9Sstevel@tonic-gate 		if ((sz = readlink(audio[i].name, linkvalue,
339*7c478bd9Sstevel@tonic-gate 				sizeof (linkvalue))) < 0)
340*7c478bd9Sstevel@tonic-gate 			continue;
341*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(sz + 1);
342*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
343*7c478bd9Sstevel@tonic-gate 			no_memory();
344*7c478bd9Sstevel@tonic-gate 		(void) strncpy(nm, linkvalue, sz);
345*7c478bd9Sstevel@tonic-gate 		nm[sz] = '\0';
346*7c478bd9Sstevel@tonic-gate 		audio[i].device = nm;
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 		cp = strrchr(audio[i].device, '/');
349*7c478bd9Sstevel@tonic-gate 		cp++;				/* advance to device # */
350*7c478bd9Sstevel@tonic-gate 		(void) sscanf(cp, "%d", &audio[i].number);
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate 		i++;
353*7c478bd9Sstevel@tonic-gate 	}
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev/sound")) == NULL) {
358*7c478bd9Sstevel@tonic-gate 		goto skip;
359*7c478bd9Sstevel@tonic-gate 	}
360*7c478bd9Sstevel@tonic-gate 
361*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
362*7c478bd9Sstevel@tonic-gate 		/* skip . .. etc... */
363*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, ".", 1) == NULL)
364*7c478bd9Sstevel@tonic-gate 			continue;
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
367*7c478bd9Sstevel@tonic-gate 		if (i == naudio) {
368*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
369*7c478bd9Sstevel@tonic-gate 			naudio = expandmem(i, (void **)&audio,
370*7c478bd9Sstevel@tonic-gate 					sizeof (struct audio));
371*7c478bd9Sstevel@tonic-gate 		}
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 		/* save name (/dev/sound + / + d_name + \0) */
374*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_SOUND + 1 +
375*7c478bd9Sstevel@tonic-gate 		    strlen(dep->d_name) + 1);
376*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
377*7c478bd9Sstevel@tonic-gate 			no_memory();
378*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/sound/");
379*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
380*7c478bd9Sstevel@tonic-gate 		audio[i].name = nm;
381*7c478bd9Sstevel@tonic-gate 
382*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_SOUND + 1 +
383*7c478bd9Sstevel@tonic-gate 		    strlen(dep->d_name) + 1);
384*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
385*7c478bd9Sstevel@tonic-gate 			no_memory();
386*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/sound/");
387*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
388*7c478bd9Sstevel@tonic-gate 		audio[i].device = nm;
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate 		(void) sscanf(dep->d_name, "%d", &audio[i].number);
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 		i++;
393*7c478bd9Sstevel@tonic-gate 	}
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate skip:
398*7c478bd9Sstevel@tonic-gate 	n = i;
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 	/* remove duplicate entries */
401*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < n - 1; i++) {
402*7c478bd9Sstevel@tonic-gate 		for (j = i + 1; j < n; j++) {
403*7c478bd9Sstevel@tonic-gate 			if (strcmp(audio[i].device, audio[j].device))
404*7c478bd9Sstevel@tonic-gate 				continue;
405*7c478bd9Sstevel@tonic-gate 			audio[j].number = -1;
406*7c478bd9Sstevel@tonic-gate 		}
407*7c478bd9Sstevel@tonic-gate 	}
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate 	/* print out device_allocate entries for tape devices */
410*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
411*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < n; j++) {
412*7c478bd9Sstevel@tonic-gate 			if (audio[j].number == i) {
413*7c478bd9Sstevel@tonic-gate 				(void) printf("audio;audio;");
414*7c478bd9Sstevel@tonic-gate 				(void) printf("reserved;reserved;%s;",
415*7c478bd9Sstevel@tonic-gate 				    DEFAULT_DEV_ALLOC_AUTH);
416*7c478bd9Sstevel@tonic-gate 				(void) printf("%s%s\n", SECLIB, "/audio_clean");
417*7c478bd9Sstevel@tonic-gate 				break;
418*7c478bd9Sstevel@tonic-gate 			}
419*7c478bd9Sstevel@tonic-gate 		}
420*7c478bd9Sstevel@tonic-gate 	}
421*7c478bd9Sstevel@tonic-gate }
422*7c478bd9Sstevel@tonic-gate 
423*7c478bd9Sstevel@tonic-gate static void
424*7c478bd9Sstevel@tonic-gate dofloppy()
425*7c478bd9Sstevel@tonic-gate {
426*7c478bd9Sstevel@tonic-gate 	DIR *dirp;
427*7c478bd9Sstevel@tonic-gate 	struct dirent *dep;	/* directory entry pointer */
428*7c478bd9Sstevel@tonic-gate 	int i, j, n;
429*7c478bd9Sstevel@tonic-gate 	char *nm;		/* name/device of special device */
430*7c478bd9Sstevel@tonic-gate 	char linkvalue[2048];	/* symlink value */
431*7c478bd9Sstevel@tonic-gate 	struct stat stat;	/* determine if it's a symlink */
432*7c478bd9Sstevel@tonic-gate 	int sz;			/* size of symlink value */
433*7c478bd9Sstevel@tonic-gate 	char *cp;		/* pointer into string */
434*7c478bd9Sstevel@tonic-gate 	int nfp;		/* max array size */
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 	nfp = DFLT_NFP;
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate 	/*
439*7c478bd9Sstevel@tonic-gate 	 * look for fd* and rfd*
440*7c478bd9Sstevel@tonic-gate 	 */
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev")) == NULL) {
443*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev failure"));
444*7c478bd9Sstevel@tonic-gate 		exit(1);
445*7c478bd9Sstevel@tonic-gate 	}
446*7c478bd9Sstevel@tonic-gate 
447*7c478bd9Sstevel@tonic-gate 	i = 0;
448*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
449*7c478bd9Sstevel@tonic-gate 		/* ignore if neither rst* nor nrst* */
450*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, "fd0", SIZE_OF_FD0) &&
451*7c478bd9Sstevel@tonic-gate 		    strncmp(dep->d_name, "rfd0", SIZE_OF_RFD0) &&
452*7c478bd9Sstevel@tonic-gate 		    strncmp(dep->d_name, "fd1", SIZE_OF_FD0) &&
453*7c478bd9Sstevel@tonic-gate 		    strncmp(dep->d_name, "rfd0", SIZE_OF_RFD0))
454*7c478bd9Sstevel@tonic-gate 			continue;
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
457*7c478bd9Sstevel@tonic-gate 		if (i == nfp) {
458*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
459*7c478bd9Sstevel@tonic-gate 			nfp = expandmem(i, (void **)&fp, sizeof (struct fp));
460*7c478bd9Sstevel@tonic-gate 		}
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate 		/* save name (/dev + 1 + d_name + \0) */
463*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_TMP + 1 + strlen(dep->d_name) + 1);
464*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
465*7c478bd9Sstevel@tonic-gate 			no_memory();
466*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/");
467*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
468*7c478bd9Sstevel@tonic-gate 		fp[i].name = nm;
469*7c478bd9Sstevel@tonic-gate 
470*7c478bd9Sstevel@tonic-gate 		/* ignore if not symbolic link (note i not incremented) */
471*7c478bd9Sstevel@tonic-gate 		if (lstat(fp[i].name, &stat) < 0) {
472*7c478bd9Sstevel@tonic-gate 			perror(gettext("stat(2) failed "));
473*7c478bd9Sstevel@tonic-gate 			exit(1);
474*7c478bd9Sstevel@tonic-gate 		}
475*7c478bd9Sstevel@tonic-gate 		if ((stat.st_mode&S_IFMT) != S_IFLNK)
476*7c478bd9Sstevel@tonic-gate 			continue;
477*7c478bd9Sstevel@tonic-gate 
478*7c478bd9Sstevel@tonic-gate 		/* get name from symbolic link */
479*7c478bd9Sstevel@tonic-gate 		if ((sz = readlink(fp[i].name, linkvalue,
480*7c478bd9Sstevel@tonic-gate 		    sizeof (linkvalue))) < 0)
481*7c478bd9Sstevel@tonic-gate 			continue;
482*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(sz+1);
483*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
484*7c478bd9Sstevel@tonic-gate 			no_memory();
485*7c478bd9Sstevel@tonic-gate 		(void) strncpy(nm, linkvalue, sz);
486*7c478bd9Sstevel@tonic-gate 		nm[sz] = '\0';
487*7c478bd9Sstevel@tonic-gate 		fp[i].device = nm;
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 		/* get device number */
490*7c478bd9Sstevel@tonic-gate 		cp = strchr(fp[i].name, 'd');
491*7c478bd9Sstevel@tonic-gate 		cp++;				/* advance to device # */
492*7c478bd9Sstevel@tonic-gate 		cp = strchr(cp, 'd');
493*7c478bd9Sstevel@tonic-gate 		cp++;				/* advance to device # */
494*7c478bd9Sstevel@tonic-gate 		(void) sscanf(cp, "%d", &fp[i].number);
495*7c478bd9Sstevel@tonic-gate 
496*7c478bd9Sstevel@tonic-gate 		i++;
497*7c478bd9Sstevel@tonic-gate 	}
498*7c478bd9Sstevel@tonic-gate 
499*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
500*7c478bd9Sstevel@tonic-gate 
501*7c478bd9Sstevel@tonic-gate 	n = i;
502*7c478bd9Sstevel@tonic-gate 
503*7c478bd9Sstevel@tonic-gate 	/* print out device_allocate entries for tape devices */
504*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
505*7c478bd9Sstevel@tonic-gate 	    for (j = 0; j < n; j++) {
506*7c478bd9Sstevel@tonic-gate 		if (fp[j].number == i) {
507*7c478bd9Sstevel@tonic-gate 		    (void) printf("fd%d;fd;reserved;reserved;%s;",
508*7c478bd9Sstevel@tonic-gate 			i, DEFAULT_DEV_ALLOC_AUTH);
509*7c478bd9Sstevel@tonic-gate 		    (void) printf("/etc/security/lib/fd_clean\n");
510*7c478bd9Sstevel@tonic-gate 		    break;
511*7c478bd9Sstevel@tonic-gate 		}
512*7c478bd9Sstevel@tonic-gate 	    }
513*7c478bd9Sstevel@tonic-gate 	}
514*7c478bd9Sstevel@tonic-gate }
515*7c478bd9Sstevel@tonic-gate 
516*7c478bd9Sstevel@tonic-gate static void
517*7c478bd9Sstevel@tonic-gate docd()
518*7c478bd9Sstevel@tonic-gate {
519*7c478bd9Sstevel@tonic-gate 	DIR *dirp;
520*7c478bd9Sstevel@tonic-gate 	struct dirent *dep;	/* directory entry pointer */
521*7c478bd9Sstevel@tonic-gate 	int	i, j, n;
522*7c478bd9Sstevel@tonic-gate 	char	*nm;		/* name/device of special device */
523*7c478bd9Sstevel@tonic-gate 	char	linkvalue[2048];	/* symlink value */
524*7c478bd9Sstevel@tonic-gate 	struct stat stat;	/* determine if it's a symlink */
525*7c478bd9Sstevel@tonic-gate 	int	sz;		/* size of symlink value */
526*7c478bd9Sstevel@tonic-gate 	char	*cp;		/* pointer into string */
527*7c478bd9Sstevel@tonic-gate 	int	id;		/* disk id */
528*7c478bd9Sstevel@tonic-gate 	int	ctrl;		/* disk controller */
529*7c478bd9Sstevel@tonic-gate 	int	ncd;		/* max array size */
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate 	ncd = DFLT_NCD;
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate 	/*
534*7c478bd9Sstevel@tonic-gate 	 * look for sr* and rsr*
535*7c478bd9Sstevel@tonic-gate 	 */
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev")) == NULL) {
538*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev failure"));
539*7c478bd9Sstevel@tonic-gate 		exit(1);
540*7c478bd9Sstevel@tonic-gate 	}
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 	i = 0;
543*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
544*7c478bd9Sstevel@tonic-gate 		/* ignore if neither sr* nor rsr* */
545*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, "sr", SIZE_OF_SR) &&
546*7c478bd9Sstevel@tonic-gate 		    strncmp(dep->d_name, "rsr", SIZE_OF_RSR))
547*7c478bd9Sstevel@tonic-gate 			continue;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
550*7c478bd9Sstevel@tonic-gate 		if (i == ncd) {
551*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
552*7c478bd9Sstevel@tonic-gate 			ncd = expandmem(i, (void **)&cd, sizeof (struct cd));
553*7c478bd9Sstevel@tonic-gate 		}
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate 		/* save name (/dev + / + d_name + \0) */
556*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_TMP + 1 + strlen(dep->d_name) + 1);
557*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
558*7c478bd9Sstevel@tonic-gate 			no_memory();
559*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/");
560*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
561*7c478bd9Sstevel@tonic-gate 		cd[i].name = nm;
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate 		/* save id # */
564*7c478bd9Sstevel@tonic-gate 		if (dep->d_name[0] == 'r')
565*7c478bd9Sstevel@tonic-gate 			(void) sscanf(dep->d_name, "rsr%d", &cd[i].id);
566*7c478bd9Sstevel@tonic-gate 		else
567*7c478bd9Sstevel@tonic-gate 			(void) sscanf(dep->d_name, "sr%d", &cd[i].id);
568*7c478bd9Sstevel@tonic-gate 
569*7c478bd9Sstevel@tonic-gate 		/* ignore if not symbolic link (note i not incremented) */
570*7c478bd9Sstevel@tonic-gate 		if (lstat(cd[i].name, &stat) < 0) {
571*7c478bd9Sstevel@tonic-gate 			perror(gettext("stat(2) failed "));
572*7c478bd9Sstevel@tonic-gate 			exit(1);
573*7c478bd9Sstevel@tonic-gate 		}
574*7c478bd9Sstevel@tonic-gate 		if ((stat.st_mode & S_IFMT) != S_IFLNK)
575*7c478bd9Sstevel@tonic-gate 			continue;
576*7c478bd9Sstevel@tonic-gate 
577*7c478bd9Sstevel@tonic-gate 		/* get name from symbolic link */
578*7c478bd9Sstevel@tonic-gate 		if ((sz = readlink(cd[i].name, linkvalue, sizeof (linkvalue))) <
579*7c478bd9Sstevel@tonic-gate 		    0)
580*7c478bd9Sstevel@tonic-gate 			continue;
581*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(sz + 1);
582*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
583*7c478bd9Sstevel@tonic-gate 			no_memory();
584*7c478bd9Sstevel@tonic-gate 		(void) strncpy(nm, linkvalue, sz);
585*7c478bd9Sstevel@tonic-gate 		nm[sz] = '\0';
586*7c478bd9Sstevel@tonic-gate 		cd[i].device = nm;
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 		cp = strrchr(cd[i].device, '/');
589*7c478bd9Sstevel@tonic-gate 		cp++;				/* advance to device # */
590*7c478bd9Sstevel@tonic-gate 		(void) sscanf(cp, "c%dt%d", &cd[i].controller, &cd[i].number);
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate 		i++;
593*7c478bd9Sstevel@tonic-gate 	}
594*7c478bd9Sstevel@tonic-gate 	n = i;
595*7c478bd9Sstevel@tonic-gate 
596*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
597*7c478bd9Sstevel@tonic-gate 
598*7c478bd9Sstevel@tonic-gate 	/*
599*7c478bd9Sstevel@tonic-gate 	 * scan /dev/dsk for cd devices
600*7c478bd9Sstevel@tonic-gate 	 */
601*7c478bd9Sstevel@tonic-gate 
602*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev/dsk")) == NULL) {
603*7c478bd9Sstevel@tonic-gate 		perror("gettext(open /dev/dsk failure)");
604*7c478bd9Sstevel@tonic-gate 		exit(1);
605*7c478bd9Sstevel@tonic-gate 	}
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
608*7c478bd9Sstevel@tonic-gate 		/* skip . .. etc... */
609*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, ".", 1) == NULL)
610*7c478bd9Sstevel@tonic-gate 			continue;
611*7c478bd9Sstevel@tonic-gate 
612*7c478bd9Sstevel@tonic-gate 		/* get device # (disk #) */
613*7c478bd9Sstevel@tonic-gate 		if (sscanf(dep->d_name, "c%dt%d", &ctrl, &id) <= 0)
614*7c478bd9Sstevel@tonic-gate 			continue;
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 		/* see if this is one of the cd special devices */
617*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < n; j++) {
618*7c478bd9Sstevel@tonic-gate 			if (cd[j].number == id && cd[j].controller == ctrl)
619*7c478bd9Sstevel@tonic-gate 				goto found;
620*7c478bd9Sstevel@tonic-gate 		}
621*7c478bd9Sstevel@tonic-gate 		continue;
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 		/* add new entry to table (/dev/dsk + / + d_name + \0) */
624*7c478bd9Sstevel@tonic-gate found:
625*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
626*7c478bd9Sstevel@tonic-gate 		if (i == ncd) {
627*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
628*7c478bd9Sstevel@tonic-gate 			ncd = expandmem(i, (void **)&cd, sizeof (struct cd));
629*7c478bd9Sstevel@tonic-gate 		}
630*7c478bd9Sstevel@tonic-gate 
631*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_DSK + 1 + strlen(dep->d_name) + 1);
632*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
633*7c478bd9Sstevel@tonic-gate 			no_memory();
634*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/dsk/");
635*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
636*7c478bd9Sstevel@tonic-gate 		cd[i].name = nm;
637*7c478bd9Sstevel@tonic-gate 
638*7c478bd9Sstevel@tonic-gate 		cd[i].id = cd[j].id;
639*7c478bd9Sstevel@tonic-gate 
640*7c478bd9Sstevel@tonic-gate 		cd[i].device = "";
641*7c478bd9Sstevel@tonic-gate 
642*7c478bd9Sstevel@tonic-gate 		cd[i].number = id;
643*7c478bd9Sstevel@tonic-gate 
644*7c478bd9Sstevel@tonic-gate 		i++;
645*7c478bd9Sstevel@tonic-gate 	}
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 	/*
650*7c478bd9Sstevel@tonic-gate 	 * scan /dev/rdsk for cd devices
651*7c478bd9Sstevel@tonic-gate 	 */
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 	if ((dirp = opendir("/dev/rdsk")) == NULL) {
654*7c478bd9Sstevel@tonic-gate 		perror(gettext("open /dev/dsk failure"));
655*7c478bd9Sstevel@tonic-gate 		exit(1);
656*7c478bd9Sstevel@tonic-gate 	}
657*7c478bd9Sstevel@tonic-gate 
658*7c478bd9Sstevel@tonic-gate 	while (dep = readdir(dirp)) {
659*7c478bd9Sstevel@tonic-gate 		/* skip . .. etc... */
660*7c478bd9Sstevel@tonic-gate 		if (strncmp(dep->d_name, ".", 1) == NULL)
661*7c478bd9Sstevel@tonic-gate 			continue;
662*7c478bd9Sstevel@tonic-gate 
663*7c478bd9Sstevel@tonic-gate 		/* get device # (disk #) */
664*7c478bd9Sstevel@tonic-gate 		if (sscanf(dep->d_name, "c%dt%d", &ctrl, &id) != 2)
665*7c478bd9Sstevel@tonic-gate 			continue;
666*7c478bd9Sstevel@tonic-gate 
667*7c478bd9Sstevel@tonic-gate 		/* see if this is one of the cd special devices */
668*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < n; j++) {
669*7c478bd9Sstevel@tonic-gate 			if (cd[j].number == id && cd[j].controller == ctrl)
670*7c478bd9Sstevel@tonic-gate 				goto found1;
671*7c478bd9Sstevel@tonic-gate 		}
672*7c478bd9Sstevel@tonic-gate 		continue;
673*7c478bd9Sstevel@tonic-gate 
674*7c478bd9Sstevel@tonic-gate 		/* add new entry to table (/dev/rdsk + / + d_name + \0) */
675*7c478bd9Sstevel@tonic-gate found1:
676*7c478bd9Sstevel@tonic-gate 		/* if array full, then expand it */
677*7c478bd9Sstevel@tonic-gate 		if (i == ncd) {
678*7c478bd9Sstevel@tonic-gate 			/* will exit(1) if insufficient memory */
679*7c478bd9Sstevel@tonic-gate 			ncd = expandmem(i, (void **)&cd, sizeof (struct cd));
680*7c478bd9Sstevel@tonic-gate 		}
681*7c478bd9Sstevel@tonic-gate 
682*7c478bd9Sstevel@tonic-gate 		nm = (char *)malloc(SIZE_OF_RDSK + 1 + strlen(dep->d_name) + 1);
683*7c478bd9Sstevel@tonic-gate 		if (nm == NULL)
684*7c478bd9Sstevel@tonic-gate 			no_memory();
685*7c478bd9Sstevel@tonic-gate 		(void) strcpy(nm, "/dev/rdsk/");
686*7c478bd9Sstevel@tonic-gate 		(void) strcat(nm, dep->d_name);
687*7c478bd9Sstevel@tonic-gate 		cd[i].name = nm;
688*7c478bd9Sstevel@tonic-gate 
689*7c478bd9Sstevel@tonic-gate 		cd[i].id = cd[j].id;
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate 		cd[i].device = "";
692*7c478bd9Sstevel@tonic-gate 
693*7c478bd9Sstevel@tonic-gate 		cd[i].number = id;
694*7c478bd9Sstevel@tonic-gate 
695*7c478bd9Sstevel@tonic-gate 		cd[i].controller = ctrl;
696*7c478bd9Sstevel@tonic-gate 
697*7c478bd9Sstevel@tonic-gate 		i++;
698*7c478bd9Sstevel@tonic-gate 	}
699*7c478bd9Sstevel@tonic-gate 
700*7c478bd9Sstevel@tonic-gate 	(void) closedir(dirp);
701*7c478bd9Sstevel@tonic-gate 
702*7c478bd9Sstevel@tonic-gate 	n = i;
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate 	/* print out device_maps entries for tape devices */
705*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; i++) {
706*7c478bd9Sstevel@tonic-gate 		for (j = 0; j < n; j++) {
707*7c478bd9Sstevel@tonic-gate 			if (cd[j].id == i) {
708*7c478bd9Sstevel@tonic-gate 				(void) printf(
709*7c478bd9Sstevel@tonic-gate 					"sr%d;sr;reserved;reserved;%s;",
710*7c478bd9Sstevel@tonic-gate 					i, DEFAULT_DEV_ALLOC_AUTH);
711*7c478bd9Sstevel@tonic-gate 				(void) printf("%s%s\n", SECLIB, "/sr_clean");
712*7c478bd9Sstevel@tonic-gate 				break;
713*7c478bd9Sstevel@tonic-gate 			}
714*7c478bd9Sstevel@tonic-gate 		}
715*7c478bd9Sstevel@tonic-gate 	}
716*7c478bd9Sstevel@tonic-gate }
717*7c478bd9Sstevel@tonic-gate 
718*7c478bd9Sstevel@tonic-gate /* set default array sizes */
719*7c478bd9Sstevel@tonic-gate static void
720*7c478bd9Sstevel@tonic-gate initmem()
721*7c478bd9Sstevel@tonic-gate {
722*7c478bd9Sstevel@tonic-gate 	tape  = (struct tape *)calloc(DFLT_NTAPE, sizeof (struct tape));
723*7c478bd9Sstevel@tonic-gate 	audio = (struct audio *)calloc(DFLT_NAUDIO, sizeof (struct audio));
724*7c478bd9Sstevel@tonic-gate 	cd    = (struct cd *)calloc(DFLT_NCD, sizeof (struct cd));
725*7c478bd9Sstevel@tonic-gate 	fp    = (struct fp *)calloc(DFLT_NFP, sizeof (struct fp));
726*7c478bd9Sstevel@tonic-gate 
727*7c478bd9Sstevel@tonic-gate 	if (tape == NULL || audio == NULL || cd == NULL || fp == NULL)
728*7c478bd9Sstevel@tonic-gate 		no_memory();
729*7c478bd9Sstevel@tonic-gate }
730*7c478bd9Sstevel@tonic-gate 
731*7c478bd9Sstevel@tonic-gate /* note n will be # elments in array (and could be 0) */
732*7c478bd9Sstevel@tonic-gate static int
733*7c478bd9Sstevel@tonic-gate expandmem(int n, void **array, int size)
734*7c478bd9Sstevel@tonic-gate {
735*7c478bd9Sstevel@tonic-gate 	void *old = *array;
736*7c478bd9Sstevel@tonic-gate 	void *new;
737*7c478bd9Sstevel@tonic-gate 
738*7c478bd9Sstevel@tonic-gate 	/* get new array space (n + DELTA) */
739*7c478bd9Sstevel@tonic-gate 	new = (void *)calloc(n + DELTA,  size);
740*7c478bd9Sstevel@tonic-gate 
741*7c478bd9Sstevel@tonic-gate 	if (new == NULL) {
742*7c478bd9Sstevel@tonic-gate 		perror("memory allocation failed");
743*7c478bd9Sstevel@tonic-gate 		exit(1);
744*7c478bd9Sstevel@tonic-gate 	}
745*7c478bd9Sstevel@tonic-gate 
746*7c478bd9Sstevel@tonic-gate 	/* copy old array into new space */
747*7c478bd9Sstevel@tonic-gate 	bcopy(old, new, n * size);
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate 	/* now release old arrary */
750*7c478bd9Sstevel@tonic-gate 	free(old);
751*7c478bd9Sstevel@tonic-gate 
752*7c478bd9Sstevel@tonic-gate 	*array = new;
753*7c478bd9Sstevel@tonic-gate 
754*7c478bd9Sstevel@tonic-gate 	return (n + DELTA);
755*7c478bd9Sstevel@tonic-gate }
756*7c478bd9Sstevel@tonic-gate 
757*7c478bd9Sstevel@tonic-gate static void
758*7c478bd9Sstevel@tonic-gate no_memory(void)
759*7c478bd9Sstevel@tonic-gate {
760*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: %s\n", "mkdevalloc",
761*7c478bd9Sstevel@tonic-gate 	    gettext("out of memory"));
762*7c478bd9Sstevel@tonic-gate 	exit(1);
763*7c478bd9Sstevel@tonic-gate 	/* NOT REACHED */
764*7c478bd9Sstevel@tonic-gate }
765