1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1995, by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma	ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate  * Do not include sys/conf.h- it isn't in the compatibility include dirs.
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate #ifdef	THIS_IS_AVAIL
33*0Sstevel@tonic-gate #include <sys/conf.h>
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate #include <stdio.h>
36*0Sstevel@tonic-gate #include <signal.h>
37*0Sstevel@tonic-gate #include <sys/types.h>
38*0Sstevel@tonic-gate #include <sys/ioccom.h>
39*0Sstevel@tonic-gate #include <sys/stropts.h>
40*0Sstevel@tonic-gate #include <sys/des.h>
41*0Sstevel@tonic-gate #include <sys/fcntl.h>
42*0Sstevel@tonic-gate #include <sys/filio.h>
43*0Sstevel@tonic-gate #include <sys/termios.h>
44*0Sstevel@tonic-gate #include <sys/termio.h>
45*0Sstevel@tonic-gate #include <sys/ttold.h>
46*0Sstevel@tonic-gate #include <sys/ttycom.h>
47*0Sstevel@tonic-gate #include <sys/msio.h>
48*0Sstevel@tonic-gate #include <sys/errno.h>
49*0Sstevel@tonic-gate #include <nettli/tihdr.h>
50*0Sstevel@tonic-gate #include <nettli/timod.h>
51*0Sstevel@tonic-gate #include <nettli/tiuser.h>
52*0Sstevel@tonic-gate #include <sun/dkio.h>
53*0Sstevel@tonic-gate #include <scsi/impl/uscsi.h>
54*0Sstevel@tonic-gate #include "cdioctl.h"
55*0Sstevel@tonic-gate #include "s5dkio.h"
56*0Sstevel@tonic-gate #include "s5fdio.h"
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate /*
59*0Sstevel@tonic-gate  * parameter for windows ioctls
60*0Sstevel@tonic-gate  */
61*0Sstevel@tonic-gate struct winclip {
62*0Sstevel@tonic-gate         int     wc_blockbytes;          /* size of wc_block */
63*0Sstevel@tonic-gate         int     wc_clipid;              /* Current clip id of clipping */
64*0Sstevel@tonic-gate         short   wc_screenrect[4];       /* Screen relatived (used when paint) */
65*0Sstevel@tonic-gate         char    *wc_block;              /* Block where RectList is copied. */
66*0Sstevel@tonic-gate };
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * Ioctl control packet
70*0Sstevel@tonic-gate  */
71*0Sstevel@tonic-gate struct s5termios {
72*0Sstevel@tonic-gate 	tcflag_t	c_iflag;	/* input modes */
73*0Sstevel@tonic-gate 	tcflag_t	c_oflag;	/* output modes */
74*0Sstevel@tonic-gate 	tcflag_t	c_cflag;	/* control modes */
75*0Sstevel@tonic-gate 	tcflag_t	c_lflag;	/* line discipline modes */
76*0Sstevel@tonic-gate 	cc_t		c_cc[19];	/* control chars */
77*0Sstevel@tonic-gate };
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate #define N_ENOMSG	35
80*0Sstevel@tonic-gate #define N_I_FIND	('S'<<8)|013
81*0Sstevel@tonic-gate #define N_I_PUSH	('S'<<8)|02
82*0Sstevel@tonic-gate #define WINGETEXPOSEDRL	_IOWR(g,31,struct winclip)
83*0Sstevel@tonic-gate #define WINGETDAMAGEDRL _IOWR(g,32,struct winclip)
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate struct n_sgttyb {
86*0Sstevel@tonic-gate 	char    sg_ispeed;              /* input speed */
87*0Sstevel@tonic-gate 	char    sg_ospeed;              /* output speed */
88*0Sstevel@tonic-gate 	char    sg_erase;               /* erase character */
89*0Sstevel@tonic-gate 	char    sg_kill;                /* kill character */
90*0Sstevel@tonic-gate 	int     sg_flags;               /* mode flags */
91*0Sstevel@tonic-gate };
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate static int handle_dkio_partitions(int, int, int);
94*0Sstevel@tonic-gate static int tcget(int, int, int);
95*0Sstevel@tonic-gate static int tcset(int, int, int);
96*0Sstevel@tonic-gate static int _bc_ioctl(int, int, int);
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate int
99*0Sstevel@tonic-gate ioctl(int des, int request, int arg)
100*0Sstevel@tonic-gate {
101*0Sstevel@tonic-gate 	int ret;
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate 	if ((ret = _bc_ioctl(des, request, arg)) == -1)
104*0Sstevel@tonic-gate 		maperror();
105*0Sstevel@tonic-gate 	return (ret);
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate int
109*0Sstevel@tonic-gate bc_ioctl(int des, int request, int arg)
110*0Sstevel@tonic-gate {
111*0Sstevel@tonic-gate 	int ret;
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	if ((ret = _bc_ioctl(des, request, arg)) == -1)
114*0Sstevel@tonic-gate 		maperror();
115*0Sstevel@tonic-gate 	return (ret);
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate static int
119*0Sstevel@tonic-gate _bc_ioctl(int des, int request, int arg)
120*0Sstevel@tonic-gate {
121*0Sstevel@tonic-gate 	int ret;
122*0Sstevel@tonic-gate 	int nreq = (request >> 8) & 0xFF;
123*0Sstevel@tonic-gate 	struct n_sgttyb nsg;
124*0Sstevel@tonic-gate 	struct s5_dk_cinfo newArgs;
125*0Sstevel@tonic-gate 	struct dk_info *infoArgs;
126*0Sstevel@tonic-gate 	struct dk_conf *confArgs;
127*0Sstevel@tonic-gate 	extern int errno;
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	/* not all mappings for 'm' have been performed */
130*0Sstevel@tonic-gate 	switch (nreq) {
131*0Sstevel@tonic-gate 		case ((int) 't'):
132*0Sstevel@tonic-gate 			if (_ioctl(des, N_I_FIND, "ttcompat") == 0)
133*0Sstevel@tonic-gate 				if (_ioctl(des, N_I_PUSH, "ttcompat") == -1)
134*0Sstevel@tonic-gate 					perror("ioctl/I_PUSH");
135*0Sstevel@tonic-gate 			switch(request) {
136*0Sstevel@tonic-gate 				case TIOCSETD:
137*0Sstevel@tonic-gate 					     /* added for sunview */
138*0Sstevel@tonic-gate 					     return(0);
139*0Sstevel@tonic-gate 				case TIOCREMOTE: request = ('t'<<8)|30;
140*0Sstevel@tonic-gate 					     break;
141*0Sstevel@tonic-gate 				case TIOCNOTTY:
142*0Sstevel@tonic-gate 					     bc_setsid();
143*0Sstevel@tonic-gate 					     return(0);
144*0Sstevel@tonic-gate 				case TIOCGPGRP: request = ('t'<<8)|20;
145*0Sstevel@tonic-gate 					     break;
146*0Sstevel@tonic-gate 				case TIOCSPGRP:
147*0Sstevel@tonic-gate 				    {
148*0Sstevel@tonic-gate 					pid_t pgid;
149*0Sstevel@tonic-gate 					sigset_t set, oset;
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate 					request = ('t'<<8)|21;
152*0Sstevel@tonic-gate 					ret = _ioctl(des, request, arg);
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate 					/*
155*0Sstevel@tonic-gate 					 * SunOS4.x allows this to succeed
156*0Sstevel@tonic-gate 					 * even if the process group does
157*0Sstevel@tonic-gate 					 * not exist yet.  We emulate the 4.x
158*0Sstevel@tonic-gate 					 * bug by creating the process group
159*0Sstevel@tonic-gate 					 * and reissuing the ioctl().
160*0Sstevel@tonic-gate 					 * See bugid 1175044.
161*0Sstevel@tonic-gate 					 */
162*0Sstevel@tonic-gate 					if (ret != 0 && errno == EPERM &&
163*0Sstevel@tonic-gate 					    (pgid = *((pid_t *)arg)) != 0 &&
164*0Sstevel@tonic-gate 					    pgid == getpid() &&
165*0Sstevel@tonic-gate 					    setpgid(0, pgid) == 0) {
166*0Sstevel@tonic-gate 						sigemptyset(&set);
167*0Sstevel@tonic-gate 						sigaddset(&set, SIGTSTP);
168*0Sstevel@tonic-gate 						sigaddset(&set, SIGTTIN);
169*0Sstevel@tonic-gate 						sigaddset(&set, SIGTTOU);
170*0Sstevel@tonic-gate 						sigprocmask(SIG_BLOCK,
171*0Sstevel@tonic-gate 							&set, &oset);
172*0Sstevel@tonic-gate 						ret = _ioctl(des,
173*0Sstevel@tonic-gate 							request, arg);
174*0Sstevel@tonic-gate 						sigprocmask(SIG_SETMASK,
175*0Sstevel@tonic-gate 							&oset, NULL);
176*0Sstevel@tonic-gate 					}
177*0Sstevel@tonic-gate 					return(ret);
178*0Sstevel@tonic-gate 				    }
179*0Sstevel@tonic-gate 				case TIOCSTI: request = ('t'<<8)|23;
180*0Sstevel@tonic-gate 					     break;
181*0Sstevel@tonic-gate 				case TIOCSIGNAL: request = ('t'<<8)|31;
182*0Sstevel@tonic-gate 					     break;
183*0Sstevel@tonic-gate 				case TIOCCONS: request = ('t'<<8)|36;
184*0Sstevel@tonic-gate 					     break;
185*0Sstevel@tonic-gate 				case TIOCSWINSZ: request = ('T'<<8)|103;
186*0Sstevel@tonic-gate 					     break;
187*0Sstevel@tonic-gate 				case TIOCGWINSZ: request = ('T'<<8)|104;
188*0Sstevel@tonic-gate 					     break;
189*0Sstevel@tonic-gate 				case TIOCSETP:
190*0Sstevel@tonic-gate 				case TIOCSETN:
191*0Sstevel@tonic-gate 			  	    {
192*0Sstevel@tonic-gate 					struct sgttyb *sg = (struct sgttyb *)arg;
193*0Sstevel@tonic-gate 					nsg.sg_ispeed = sg->sg_ispeed;
194*0Sstevel@tonic-gate 					nsg.sg_ospeed = sg->sg_ospeed;
195*0Sstevel@tonic-gate 					nsg.sg_erase = sg->sg_erase;
196*0Sstevel@tonic-gate 					nsg.sg_kill = sg->sg_kill;
197*0Sstevel@tonic-gate 					nsg.sg_flags = (int)sg->sg_flags;
198*0Sstevel@tonic-gate 					arg = (int)&nsg;
199*0Sstevel@tonic-gate 				        request = request & 0x0FFFF;
200*0Sstevel@tonic-gate 					break;
201*0Sstevel@tonic-gate 				    }
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 				case TIOCGETP:
204*0Sstevel@tonic-gate 				    {
205*0Sstevel@tonic-gate 					struct sgttyb *sg = (struct sgttyb *)arg;
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate 					ret = _ioctl(des, request&0xFFFF, &nsg);
208*0Sstevel@tonic-gate 					if (ret != -1) {
209*0Sstevel@tonic-gate 						sg->sg_ispeed = nsg.sg_ispeed;
210*0Sstevel@tonic-gate 						sg->sg_ospeed = nsg.sg_ospeed;
211*0Sstevel@tonic-gate 						sg->sg_erase = nsg.sg_erase;
212*0Sstevel@tonic-gate 						sg->sg_kill = nsg.sg_kill;
213*0Sstevel@tonic-gate 						sg->sg_flags = (short)nsg.sg_flags & 0x0FFFF;
214*0Sstevel@tonic-gate 					}
215*0Sstevel@tonic-gate 					return(ret);
216*0Sstevel@tonic-gate 				    }
217*0Sstevel@tonic-gate 				case TIOCPKT:
218*0Sstevel@tonic-gate 				case TIOCUCNTL:
219*0Sstevel@tonic-gate 				case TIOCTCNTL:
220*0Sstevel@tonic-gate 				case TIOCSSOFTCAR:
221*0Sstevel@tonic-gate 				case TIOCGSOFTCAR:
222*0Sstevel@tonic-gate 				case TIOCISPACE:
223*0Sstevel@tonic-gate 				case TIOCISIZE:
224*0Sstevel@tonic-gate 				case TIOCSSIZE:
225*0Sstevel@tonic-gate 				case TIOCGSIZE:
226*0Sstevel@tonic-gate 				    	     break;
227*0Sstevel@tonic-gate 				default:     request = request & 0x0FFFF;
228*0Sstevel@tonic-gate 				 	     break;
229*0Sstevel@tonic-gate 			}
230*0Sstevel@tonic-gate 			break;
231*0Sstevel@tonic-gate 		case ((int) 'T'):
232*0Sstevel@tonic-gate 			switch(request) {
233*0Sstevel@tonic-gate 				case TCGETS:
234*0Sstevel@tonic-gate 					request = ('T'<<8)|13;
235*0Sstevel@tonic-gate 					return(tcget(des, request, arg));
236*0Sstevel@tonic-gate 					break;
237*0Sstevel@tonic-gate 				case TCSETS:
238*0Sstevel@tonic-gate 					request = ('T'<<8)|14;
239*0Sstevel@tonic-gate 					return(tcset(des, request, arg));
240*0Sstevel@tonic-gate 					break;
241*0Sstevel@tonic-gate 				case TCSETSW:
242*0Sstevel@tonic-gate 					request = ('T'<<8)|15;
243*0Sstevel@tonic-gate 					return(tcset(des, request, arg));
244*0Sstevel@tonic-gate 					break;
245*0Sstevel@tonic-gate 				case TCSETSF:
246*0Sstevel@tonic-gate 					request = ('T'<<8)|16;
247*0Sstevel@tonic-gate 					return(tcset(des, request, arg));
248*0Sstevel@tonic-gate 					break;
249*0Sstevel@tonic-gate 				case TCGETA:
250*0Sstevel@tonic-gate 				case TCSETA:
251*0Sstevel@tonic-gate 				case TCSETAW:
252*0Sstevel@tonic-gate 				case TCSETAF:
253*0Sstevel@tonic-gate 				default:
254*0Sstevel@tonic-gate 					request = request & 0x0FFFF;
255*0Sstevel@tonic-gate 					break;
256*0Sstevel@tonic-gate 			}
257*0Sstevel@tonic-gate 			break;
258*0Sstevel@tonic-gate 		case ((int) 'S'):
259*0Sstevel@tonic-gate 			switch (request) {
260*0Sstevel@tonic-gate  				case I_PLINK: request = ('S'<<8)|026;
261*0Sstevel@tonic-gate 					      break;
262*0Sstevel@tonic-gate  				case I_PUNLINK: request = ('S'<<8)|027;
263*0Sstevel@tonic-gate 					      break;
264*0Sstevel@tonic-gate  				case I_STR: {
265*0Sstevel@tonic-gate 					struct strioctl *iarg =
266*0Sstevel@tonic-gate 					    (struct strioctl *)arg;
267*0Sstevel@tonic-gate 					int cmd = iarg->ic_cmd;
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 					switch (cmd) {
270*0Sstevel@tonic-gate 					case TI_GETINFO: {
271*0Sstevel@tonic-gate 						/*
272*0Sstevel@tonic-gate 						 * The T_info_ack structure
273*0Sstevel@tonic-gate 						 * has one additional word
274*0Sstevel@tonic-gate 						 * added to it in 5.x.
275*0Sstevel@tonic-gate 						 * To prevent the module from
276*0Sstevel@tonic-gate 						 * overwritting user memory we
277*0Sstevel@tonic-gate 						 * use an internal buffer for
278*0Sstevel@tonic-gate 						 * the transfer and copy out
279*0Sstevel@tonic-gate 						 * the results to the caller.
280*0Sstevel@tonic-gate 						 */
281*0Sstevel@tonic-gate 						struct {
282*0Sstevel@tonic-gate 							struct T_info_ack info;
283*0Sstevel@tonic-gate 							long		pad[16];
284*0Sstevel@tonic-gate 						} args;
285*0Sstevel@tonic-gate 						char *dp = iarg->ic_dp;
286*0Sstevel@tonic-gate 
287*0Sstevel@tonic-gate 						memcpy(&args.info, iarg->ic_dp,
288*0Sstevel@tonic-gate 						    sizeof(struct T_info_ack));
289*0Sstevel@tonic-gate 						iarg->ic_dp =
290*0Sstevel@tonic-gate 						    (char *) &args.info;
291*0Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 140);
292*0Sstevel@tonic-gate 						ret = _ioctl(des,
293*0Sstevel@tonic-gate 						    request & 0xffff, arg);
294*0Sstevel@tonic-gate 						iarg->ic_cmd = cmd;
295*0Sstevel@tonic-gate 						iarg->ic_dp = dp;
296*0Sstevel@tonic-gate 						iarg->ic_len =
297*0Sstevel@tonic-gate 						    sizeof(struct T_info_ack);
298*0Sstevel@tonic-gate 						memcpy(iarg->ic_dp, &args.info,
299*0Sstevel@tonic-gate 						    iarg->ic_len);
300*0Sstevel@tonic-gate 						return (ret);
301*0Sstevel@tonic-gate 						break;
302*0Sstevel@tonic-gate 					}
303*0Sstevel@tonic-gate 					case TI_OPTMGMT:
304*0Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 141);
305*0Sstevel@tonic-gate 						break;
306*0Sstevel@tonic-gate 					case TI_BIND:
307*0Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 142);
308*0Sstevel@tonic-gate 						break;
309*0Sstevel@tonic-gate 					case TI_UNBIND:
310*0Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 143);
311*0Sstevel@tonic-gate 						break;
312*0Sstevel@tonic-gate 					}
313*0Sstevel@tonic-gate 					ret = _ioctl(des,
314*0Sstevel@tonic-gate 					    request & 0xffff, arg);
315*0Sstevel@tonic-gate 					iarg->ic_cmd = cmd;
316*0Sstevel@tonic-gate 					return ret;
317*0Sstevel@tonic-gate 				}
318*0Sstevel@tonic-gate 				default:      request = request & 0x0FFFF;
319*0Sstevel@tonic-gate 				  	      break;
320*0Sstevel@tonic-gate 			}
321*0Sstevel@tonic-gate 			break;
322*0Sstevel@tonic-gate 		case ((int) 'm'):
323*0Sstevel@tonic-gate 			switch (request) {
324*0Sstevel@tonic-gate 				case MSIOGETPARMS: request = ('m'<<8)|1;
325*0Sstevel@tonic-gate 					      break;
326*0Sstevel@tonic-gate 				case MSIOSETPARMS: request = ('m'<<8)|2;
327*0Sstevel@tonic-gate 					      break;
328*0Sstevel@tonic-gate 				default:      request = request & 0x0FFFF;
329*0Sstevel@tonic-gate 				  	      break;
330*0Sstevel@tonic-gate 			}
331*0Sstevel@tonic-gate 			break;
332*0Sstevel@tonic-gate 		case ((int) 'd'):
333*0Sstevel@tonic-gate 			switch (request) {
334*0Sstevel@tonic-gate 				case DKIOCGGEOM:
335*0Sstevel@tonic-gate 					request = S5DKIOCGGEOM;
336*0Sstevel@tonic-gate 					break;
337*0Sstevel@tonic-gate 				case DKIOCSGEOM:
338*0Sstevel@tonic-gate 					request = S5DKIOCSGEOM;
339*0Sstevel@tonic-gate 					break;
340*0Sstevel@tonic-gate 				case DKIOCSAPART:
341*0Sstevel@tonic-gate 					request = S5DKIOCSAPART;
342*0Sstevel@tonic-gate 					break;
343*0Sstevel@tonic-gate 				case DKIOCGAPART:
344*0Sstevel@tonic-gate 					request = S5DKIOCGAPART;
345*0Sstevel@tonic-gate 					break;
346*0Sstevel@tonic-gate 				case DKIOCSTYPE:
347*0Sstevel@tonic-gate 					request = S5HDKIOCSTYPE;
348*0Sstevel@tonic-gate 					break;
349*0Sstevel@tonic-gate 				case DKIOCGTYPE:
350*0Sstevel@tonic-gate 					request = S5HDKIOCGTYPE;
351*0Sstevel@tonic-gate 					break;
352*0Sstevel@tonic-gate 				case DKIOCSBAD:
353*0Sstevel@tonic-gate 					request = S5HDKIOCSBAD;
354*0Sstevel@tonic-gate 					break;
355*0Sstevel@tonic-gate 				case DKIOCGBAD:
356*0Sstevel@tonic-gate 					request = S5HDKIOCGBAD;
357*0Sstevel@tonic-gate 					break;
358*0Sstevel@tonic-gate 				case DKIOCSCMD:
359*0Sstevel@tonic-gate 					request = S5HDKIOCSCMD;
360*0Sstevel@tonic-gate 					break;
361*0Sstevel@tonic-gate 				case DKIOCGDIAG:
362*0Sstevel@tonic-gate 					request = S5HDKIOCGDIAG;
363*0Sstevel@tonic-gate 					break;
364*0Sstevel@tonic-gate 				case FDKIOGCHAR:
365*0Sstevel@tonic-gate 					request = S5FDIOGCHAR;
366*0Sstevel@tonic-gate 					break;
367*0Sstevel@tonic-gate 				case FDKIOSCHAR:
368*0Sstevel@tonic-gate 					request = S5FDIOSCHAR;
369*0Sstevel@tonic-gate 					break;
370*0Sstevel@tonic-gate 				case FDKEJECT:
371*0Sstevel@tonic-gate 					request = S5FDEJECT;
372*0Sstevel@tonic-gate 					break;
373*0Sstevel@tonic-gate 				case FDKGETCHANGE:
374*0Sstevel@tonic-gate 					request = S5FDGETCHANGE;
375*0Sstevel@tonic-gate 					break;
376*0Sstevel@tonic-gate 				case FDKGETDRIVECHAR:
377*0Sstevel@tonic-gate 					request = S5FDGETDRIVECHAR;
378*0Sstevel@tonic-gate 					break;
379*0Sstevel@tonic-gate 				case FDKSETDRIVECHAR:
380*0Sstevel@tonic-gate 					request = S5FDSETDRIVECHAR;
381*0Sstevel@tonic-gate 					break;
382*0Sstevel@tonic-gate 				case FDKGETSEARCH:
383*0Sstevel@tonic-gate 					request = S5FDGETSEARCH;
384*0Sstevel@tonic-gate 					break;
385*0Sstevel@tonic-gate 				case FDKSETSEARCH:
386*0Sstevel@tonic-gate 					request = S5FDSETSEARCH;
387*0Sstevel@tonic-gate 					break;
388*0Sstevel@tonic-gate 				case FDKIOCSCMD:
389*0Sstevel@tonic-gate 					request = S5FDIOCMD;
390*0Sstevel@tonic-gate 					break;
391*0Sstevel@tonic-gate 				case F_RAW:
392*0Sstevel@tonic-gate 					request = S5FDRAW;
393*0Sstevel@tonic-gate 					break;
394*0Sstevel@tonic-gate 				case DKIOCINFO:
395*0Sstevel@tonic-gate 					ret = _ioctl(des, S5DKIOCINFO, &newArgs);
396*0Sstevel@tonic-gate 					if (ret != -1) {
397*0Sstevel@tonic-gate 						infoArgs = (struct dk_info *)arg;
398*0Sstevel@tonic-gate 						infoArgs->dki_ctlr =
399*0Sstevel@tonic-gate 							newArgs.dki_addr;
400*0Sstevel@tonic-gate 						infoArgs->dki_unit =
401*0Sstevel@tonic-gate 							newArgs.dki_unit;
402*0Sstevel@tonic-gate 						infoArgs->dki_ctype =
403*0Sstevel@tonic-gate 							newArgs.dki_ctype;
404*0Sstevel@tonic-gate 						infoArgs->dki_flags =
405*0Sstevel@tonic-gate 							newArgs.dki_flags;
406*0Sstevel@tonic-gate 					}
407*0Sstevel@tonic-gate 					return ret;
408*0Sstevel@tonic-gate 					break;
409*0Sstevel@tonic-gate 				case DKIOCGCONF:
410*0Sstevel@tonic-gate 					ret = _ioctl(des, S5DKIOCINFO, &newArgs);
411*0Sstevel@tonic-gate 					if (ret != -1) {
412*0Sstevel@tonic-gate 						confArgs = (struct dk_conf *)arg;
413*0Sstevel@tonic-gate 						strncpy(confArgs->dkc_cname,
414*0Sstevel@tonic-gate 							newArgs.dki_cname,
415*0Sstevel@tonic-gate 							DK_DEVLEN);
416*0Sstevel@tonic-gate 						strncpy(confArgs->dkc_dname,
417*0Sstevel@tonic-gate 							newArgs.dki_dname,
418*0Sstevel@tonic-gate 							DK_DEVLEN);
419*0Sstevel@tonic-gate 						confArgs->dkc_ctype =
420*0Sstevel@tonic-gate 							(u_short)newArgs.dki_ctype;
421*0Sstevel@tonic-gate 						confArgs->dkc_flags =
422*0Sstevel@tonic-gate 							(u_short)newArgs.dki_flags;
423*0Sstevel@tonic-gate 						confArgs->dkc_cnum =
424*0Sstevel@tonic-gate 							newArgs.dki_cnum;
425*0Sstevel@tonic-gate 						confArgs->dkc_addr =
426*0Sstevel@tonic-gate 							newArgs.dki_addr;
427*0Sstevel@tonic-gate 						confArgs->dkc_space =
428*0Sstevel@tonic-gate 							(u_int)newArgs.dki_space;
429*0Sstevel@tonic-gate 						confArgs->dkc_prio =
430*0Sstevel@tonic-gate 							newArgs.dki_prio;
431*0Sstevel@tonic-gate 						confArgs->dkc_vec =
432*0Sstevel@tonic-gate 							newArgs.dki_vec;
433*0Sstevel@tonic-gate 						confArgs->dkc_unit =
434*0Sstevel@tonic-gate 							newArgs.dki_unit;
435*0Sstevel@tonic-gate 						confArgs->dkc_slave =
436*0Sstevel@tonic-gate 							newArgs.dki_slave;
437*0Sstevel@tonic-gate 					}
438*0Sstevel@tonic-gate 					return ret;
439*0Sstevel@tonic-gate 					break;
440*0Sstevel@tonic-gate 				case DKIOCWCHK:
441*0Sstevel@tonic-gate 					/*
442*0Sstevel@tonic-gate 					 * This is unsupported in SVR4. It
443*0Sstevel@tonic-gate 					 * turns on verify-after-write for
444*0Sstevel@tonic-gate 					 * the floppy. I don't think the
445*0Sstevel@tonic-gate 					 * system call should fail, however.
446*0Sstevel@tonic-gate 					 */
447*0Sstevel@tonic-gate 					return 0;
448*0Sstevel@tonic-gate 					break;
449*0Sstevel@tonic-gate 				case DKIOCGPART:
450*0Sstevel@tonic-gate 				case DKIOCSPART:
451*0Sstevel@tonic-gate 					return (handle_dkio_partitions(des,
452*0Sstevel@tonic-gate 					       request, arg));
453*0Sstevel@tonic-gate 				case DKIOCGLOG:
454*0Sstevel@tonic-gate 					/* unsupported */
455*0Sstevel@tonic-gate 					errno = EINVAL;
456*0Sstevel@tonic-gate 					return -1;
457*0Sstevel@tonic-gate 					break;
458*0Sstevel@tonic-gate 				case DESIOCBLOCK:
459*0Sstevel@tonic-gate 				case DESIOCQUICK:
460*0Sstevel@tonic-gate 					break; /* no change for these two */
461*0Sstevel@tonic-gate 				default:
462*0Sstevel@tonic-gate 					request = request & 0x0FFFF; /* try */
463*0Sstevel@tonic-gate 					break;
464*0Sstevel@tonic-gate 			}
465*0Sstevel@tonic-gate 			break;
466*0Sstevel@tonic-gate 		case ((int) 'c'):
467*0Sstevel@tonic-gate 			switch (request) {
468*0Sstevel@tonic-gate 				case CDROMPAUSE:
469*0Sstevel@tonic-gate 					request = S5CDROMPAUSE;
470*0Sstevel@tonic-gate 					break;
471*0Sstevel@tonic-gate 				case CDROMRESUME:
472*0Sstevel@tonic-gate 					request = S5CDROMRESUME;
473*0Sstevel@tonic-gate 					break;
474*0Sstevel@tonic-gate 				case CDROMPLAYMSF:
475*0Sstevel@tonic-gate 					request = S5CDROMPLAYMSF;
476*0Sstevel@tonic-gate 					break;
477*0Sstevel@tonic-gate 				case CDROMPLAYTRKIND:
478*0Sstevel@tonic-gate 					request = S5CDROMPLAYTRKIND;
479*0Sstevel@tonic-gate 					break;
480*0Sstevel@tonic-gate 				case CDROMREADTOCHDR:
481*0Sstevel@tonic-gate 					request = S5CDROMREADTOCHDR;
482*0Sstevel@tonic-gate 					break;
483*0Sstevel@tonic-gate 				case CDROMREADTOCENTRY:
484*0Sstevel@tonic-gate 					request = S5CDROMREADTOCENTRY;
485*0Sstevel@tonic-gate 					break;
486*0Sstevel@tonic-gate 				case CDROMSTOP:
487*0Sstevel@tonic-gate 					request = S5CDROMSTOP;
488*0Sstevel@tonic-gate 					break;
489*0Sstevel@tonic-gate 				case CDROMSTART:
490*0Sstevel@tonic-gate 					request = S5CDROMSTART;
491*0Sstevel@tonic-gate 					break;
492*0Sstevel@tonic-gate 				case CDROMEJECT:
493*0Sstevel@tonic-gate 					request = S5CDROMEJECT;
494*0Sstevel@tonic-gate 					break;
495*0Sstevel@tonic-gate 				case CDROMVOLCTRL:
496*0Sstevel@tonic-gate 					request = S5CDROMVOLCTRL;
497*0Sstevel@tonic-gate 					break;
498*0Sstevel@tonic-gate 				case CDROMSUBCHNL:
499*0Sstevel@tonic-gate 					request = S5CDROMSUBCHNL;
500*0Sstevel@tonic-gate 					break;
501*0Sstevel@tonic-gate 				case CDROMREADMODE1:
502*0Sstevel@tonic-gate 					request = S5CDROMREADMODE1;
503*0Sstevel@tonic-gate 					break;
504*0Sstevel@tonic-gate 				case CDROMREADMODE2:
505*0Sstevel@tonic-gate 					request = S5CDROMREADMODE2;
506*0Sstevel@tonic-gate 					break;
507*0Sstevel@tonic-gate 			}
508*0Sstevel@tonic-gate 			break;
509*0Sstevel@tonic-gate 		case ((int) 'u'):
510*0Sstevel@tonic-gate 			switch (request) {
511*0Sstevel@tonic-gate 				case USCSICMD:
512*0Sstevel@tonic-gate 				    {
513*0Sstevel@tonic-gate 					struct s5_uscsi_cmd s5_cmd;
514*0Sstevel@tonic-gate 					struct uscsi_cmd *cmd =
515*0Sstevel@tonic-gate 						(struct uscsi_cmd *) arg;
516*0Sstevel@tonic-gate 					request = S5USCSICMD;
517*0Sstevel@tonic-gate 					s5_cmd.uscsi_cdb = cmd->uscsi_cdb;
518*0Sstevel@tonic-gate 					s5_cmd.uscsi_cdblen =
519*0Sstevel@tonic-gate 						cmd->uscsi_cdblen;
520*0Sstevel@tonic-gate 					s5_cmd.uscsi_bufaddr =
521*0Sstevel@tonic-gate 						cmd->uscsi_bufaddr;
522*0Sstevel@tonic-gate 					s5_cmd.uscsi_buflen =
523*0Sstevel@tonic-gate 						cmd->uscsi_buflen;
524*0Sstevel@tonic-gate 					s5_cmd.uscsi_flags =
525*0Sstevel@tonic-gate 						cmd->uscsi_flags;
526*0Sstevel@tonic-gate 					ret = _ioctl(des, request, &s5_cmd);
527*0Sstevel@tonic-gate 					cmd->uscsi_status = s5_cmd.uscsi_status;
528*0Sstevel@tonic-gate 					return(ret);
529*0Sstevel@tonic-gate 				    }
530*0Sstevel@tonic-gate 			}
531*0Sstevel@tonic-gate 			break;
532*0Sstevel@tonic-gate 		case ((int) 'k'):
533*0Sstevel@tonic-gate 		case ((int) 'v'):
534*0Sstevel@tonic-gate 		case ((int) 'F'):
535*0Sstevel@tonic-gate 		case ((int) 'G'):
536*0Sstevel@tonic-gate 		case ((int) 'X'):
537*0Sstevel@tonic-gate 		case ((int) 'L'):
538*0Sstevel@tonic-gate 			request = request & 0x0FFFF;
539*0Sstevel@tonic-gate 			break;
540*0Sstevel@tonic-gate 		case ((int) 'f'):
541*0Sstevel@tonic-gate 			if ((request == FIOCLEX) || (request == FIONCLEX))
542*0Sstevel@tonic-gate 				return(fcntl(des, F_SETFD,
543*0Sstevel@tonic-gate 				    ((request == FIOCLEX) ? 1 : 0)));
544*0Sstevel@tonic-gate 			break;
545*0Sstevel@tonic-gate 		case ((int) 'g'):
546*0Sstevel@tonic-gate 			/* Treat the following 2 ioctls specially for
547*0Sstevel@tonic-gate 			 * sunview. */
548*0Sstevel@tonic-gate 			if (request == WINGETEXPOSEDRL ||
549*0Sstevel@tonic-gate 				request == WINGETDAMAGEDRL) {
550*0Sstevel@tonic-gate 				ret = _ioctl(des, request, arg);
551*0Sstevel@tonic-gate 				if (errno == N_ENOMSG)
552*0Sstevel@tonic-gate 					errno = EFBIG;
553*0Sstevel@tonic-gate 				return(ret);
554*0Sstevel@tonic-gate 			}
555*0Sstevel@tonic-gate 			break;
556*0Sstevel@tonic-gate 	}
557*0Sstevel@tonic-gate 	return (_ioctl(des, request, arg));
558*0Sstevel@tonic-gate }
559*0Sstevel@tonic-gate 
560*0Sstevel@tonic-gate 
561*0Sstevel@tonic-gate static int
562*0Sstevel@tonic-gate handle_dkio_partitions(int des, int request, int arg)
563*0Sstevel@tonic-gate {
564*0Sstevel@tonic-gate 	struct s5_dk_cinfo	cinfo;
565*0Sstevel@tonic-gate 	struct dk_allmap	map;
566*0Sstevel@tonic-gate 	struct dk_map		*part;
567*0Sstevel@tonic-gate 	int			ret;
568*0Sstevel@tonic-gate 	extern int		errno;
569*0Sstevel@tonic-gate 
570*0Sstevel@tonic-gate 	part = (struct dk_map *) arg;
571*0Sstevel@tonic-gate 
572*0Sstevel@tonic-gate 	ret = _ioctl(des, S5DKIOCINFO, &cinfo);
573*0Sstevel@tonic-gate 
574*0Sstevel@tonic-gate 	if ((cinfo.dki_partition < 0) || (cinfo.dki_partition >= NDKMAP)) {
575*0Sstevel@tonic-gate 		errno = EINVAL;
576*0Sstevel@tonic-gate 		return (-1);
577*0Sstevel@tonic-gate 	}
578*0Sstevel@tonic-gate 
579*0Sstevel@tonic-gate 	if (ret != -1) {
580*0Sstevel@tonic-gate 		ret = _ioctl(des, S5DKIOCGAPART, &map);
581*0Sstevel@tonic-gate 		if (ret != -1) {
582*0Sstevel@tonic-gate 			if (request == DKIOCGPART) {
583*0Sstevel@tonic-gate 				part->dkl_cylno =
584*0Sstevel@tonic-gate 				    map.dka_map[cinfo.dki_partition].dkl_cylno;
585*0Sstevel@tonic-gate 				part->dkl_nblk =
586*0Sstevel@tonic-gate 				    map.dka_map[cinfo.dki_partition].dkl_nblk;
587*0Sstevel@tonic-gate 			} else {
588*0Sstevel@tonic-gate 				map.dka_map[cinfo.dki_partition].dkl_cylno =
589*0Sstevel@tonic-gate 					part->dkl_cylno;
590*0Sstevel@tonic-gate 				map.dka_map[cinfo.dki_partition].dkl_nblk =
591*0Sstevel@tonic-gate 					part->dkl_nblk;
592*0Sstevel@tonic-gate 				ret = _ioctl(des, S5DKIOCSAPART, &map);
593*0Sstevel@tonic-gate 			}
594*0Sstevel@tonic-gate 		}
595*0Sstevel@tonic-gate 	}
596*0Sstevel@tonic-gate 	return (ret);
597*0Sstevel@tonic-gate }
598*0Sstevel@tonic-gate 
599*0Sstevel@tonic-gate static int
600*0Sstevel@tonic-gate tcset(des, request, arg)
601*0Sstevel@tonic-gate 	register int	des;
602*0Sstevel@tonic-gate 	register int	request;
603*0Sstevel@tonic-gate 	int		arg;
604*0Sstevel@tonic-gate {
605*0Sstevel@tonic-gate 	struct s5termios	s5termios;
606*0Sstevel@tonic-gate 	struct termios		*termios;
607*0Sstevel@tonic-gate 
608*0Sstevel@tonic-gate 	termios = (struct termios *)arg;
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate 	if (termios != NULL) {
611*0Sstevel@tonic-gate 		s5termios.c_iflag = termios->c_iflag;
612*0Sstevel@tonic-gate 		s5termios.c_oflag = termios->c_oflag;
613*0Sstevel@tonic-gate 		s5termios.c_cflag = termios->c_cflag;
614*0Sstevel@tonic-gate 		s5termios.c_lflag = termios->c_lflag;
615*0Sstevel@tonic-gate 		memcpy(s5termios.c_cc, termios->c_cc, NCCS);
616*0Sstevel@tonic-gate 		return (_ioctl(des, request, &s5termios));
617*0Sstevel@tonic-gate 	} else
618*0Sstevel@tonic-gate 		return (_ioctl(des, request, NULL));
619*0Sstevel@tonic-gate 
620*0Sstevel@tonic-gate }
621*0Sstevel@tonic-gate 
622*0Sstevel@tonic-gate static int
623*0Sstevel@tonic-gate tcget(des, request, arg)
624*0Sstevel@tonic-gate 	register int	des;
625*0Sstevel@tonic-gate 	register int	request;
626*0Sstevel@tonic-gate 	int		arg;
627*0Sstevel@tonic-gate {
628*0Sstevel@tonic-gate 	struct s5termios	s5termios;
629*0Sstevel@tonic-gate 	struct termios		*termios;
630*0Sstevel@tonic-gate 	int			ret;
631*0Sstevel@tonic-gate 
632*0Sstevel@tonic-gate 	termios = (struct termios *)arg;
633*0Sstevel@tonic-gate 
634*0Sstevel@tonic-gate 	ret = _ioctl(des, request, &s5termios);
635*0Sstevel@tonic-gate 
636*0Sstevel@tonic-gate 	if (termios != NULL) {
637*0Sstevel@tonic-gate 		termios->c_iflag = s5termios.c_iflag;
638*0Sstevel@tonic-gate 		termios->c_oflag = s5termios.c_oflag;
639*0Sstevel@tonic-gate 		termios->c_cflag = s5termios.c_cflag;
640*0Sstevel@tonic-gate 		termios->c_lflag = s5termios.c_lflag;
641*0Sstevel@tonic-gate 		memcpy(termios->c_cc, s5termios.c_cc, NCCS);
642*0Sstevel@tonic-gate 	}
643*0Sstevel@tonic-gate 
644*0Sstevel@tonic-gate 	return (ret);
645*0Sstevel@tonic-gate }
646