xref: /original-bsd/sys/luna68k/stand/conf.c (revision 3705696b)
1 /*
2  * Copyright (c) 1992 OMRON Corporation.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * OMRON Corporation.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)conf.c	8.1 (Berkeley) 06/10/93
12  */
13 
14 #include <luna68k/stand/saio.h>
15 
16 devread(io)
17 	register struct iob *io;
18 {
19 	int cc;
20 
21 	io->i_flgs |= F_RDDATA;
22 	io->i_error = 0;
23 	cc = (*devsw[io->i_dev].dv_strategy)(io, READ);
24 	io->i_flgs &= ~F_TYPEMASK;
25 	return (cc);
26 }
27 
28 devwrite(io)
29 	register struct iob *io;
30 {
31 	int cc;
32 
33 	io->i_flgs |= F_WRDATA;
34 	io->i_error = 0;
35 	cc = (*devsw[io->i_dev].dv_strategy)(io, WRITE);
36 	io->i_flgs &= ~F_TYPEMASK;
37 	return (cc);
38 }
39 
40 devopen(io)
41 	register struct iob *io;
42 {
43 
44 	(*devsw[io->i_dev].dv_open)(io);
45 }
46 
47 devclose(io)
48 	register struct iob *io;
49 {
50 
51 	(*devsw[io->i_dev].dv_close)(io);
52 }
53 
54 devioctl(io, cmd, arg)
55 	register struct iob *io;
56 	int cmd;
57 	caddr_t arg;
58 {
59 
60 	return ((*devsw[io->i_dev].dv_ioctl)(io, cmd, arg));
61 }
62 
63 /*ARGSUSED*/
64 nullsys(io)
65 	struct iob *io;
66 {
67 
68 	;
69 }
70 
71 /*ARGSUSED*/
72 nullioctl(io, cmd, arg)
73 	struct iob *io;
74 	int cmd;
75 	caddr_t arg;
76 {
77 
78 	return (ECMD);
79 }
80 
81 int	nullsys(), nullioctl();
82 int	sdstrategy(), sdopen(), sdioctl();
83 
84 struct devsw devsw[] = {
85 	{ "sd",	sdstrategy,	sdopen,		nullsys,	nullioctl },
86 	{ 0, 0, 0, 0, 0 },
87 };
88 
89 dev_t
90 make_device(str)
91 	char *str;
92 {
93 	char *cp;
94 	struct devsw *dp;
95 	int major, unit, part;
96 
97 	/*
98 	 * parse path strings
99 	 */
100 							/* find end of dev type name */
101 	for (cp = str; *cp && *cp != '('; cp++)
102 			;
103 	if (*cp != '(') {
104 		return (-1);
105 	}
106 							/* compare dev type name */
107 	*cp = '\0';
108 	for (dp = devsw; dp->dv_name; dp++)
109 		if (!strcmp(str, dp->dv_name))
110 			break;
111 	*cp++ = '(';
112 	if (dp->dv_name == NULL) {
113 		return (-1);
114 	}
115 	major = dp - devsw;
116 							/* get unit number */
117 	unit = *cp++ - '0';
118 	if (*cp >= '0' && *cp <= '9')
119 		unit = unit * 10 + *cp++ - '0';
120 	if (unit < 0 || unit > 63) {
121 		return (-1);
122 	}
123 							/* get partition offset */
124 	if (*cp++ != ',') {
125 		return (-1);
126 	}
127 	part = *cp - '0';
128 							/* check out end of dev spec */
129 	for (;;) {
130 		if (*cp == ')')
131 			break;
132 		if (*cp++)
133 			continue;
134 		return (-1);
135 	}
136 
137 	return(major << 8 | unit << 3 | part);
138 }
139