xref: /onnv-gate/usr/src/lib/libbc/libc/sys/common/ioctl.c (revision 722:636b850d4ee9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*722Smuffin  * Copyright 1995 Sun Microsystems, Inc.  All rights reserved.
24*722Smuffin  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
27*722Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Do not include sys/conf.h- it isn't in the compatibility include dirs.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate #ifdef	THIS_IS_AVAIL
330Sstevel@tonic-gate #include <sys/conf.h>
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate #include <signal.h>
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/ioccom.h>
390Sstevel@tonic-gate #include <sys/stropts.h>
400Sstevel@tonic-gate #include <sys/des.h>
410Sstevel@tonic-gate #include <sys/fcntl.h>
420Sstevel@tonic-gate #include <sys/filio.h>
430Sstevel@tonic-gate #include <sys/termios.h>
440Sstevel@tonic-gate #include <sys/termio.h>
450Sstevel@tonic-gate #include <sys/ttold.h>
460Sstevel@tonic-gate #include <sys/ttycom.h>
470Sstevel@tonic-gate #include <sys/msio.h>
480Sstevel@tonic-gate #include <sys/errno.h>
490Sstevel@tonic-gate #include <nettli/tihdr.h>
500Sstevel@tonic-gate #include <nettli/timod.h>
510Sstevel@tonic-gate #include <nettli/tiuser.h>
520Sstevel@tonic-gate #include <sun/dkio.h>
530Sstevel@tonic-gate #include <scsi/impl/uscsi.h>
540Sstevel@tonic-gate #include "cdioctl.h"
550Sstevel@tonic-gate #include "s5dkio.h"
560Sstevel@tonic-gate #include "s5fdio.h"
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * parameter for windows ioctls
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate struct winclip {
620Sstevel@tonic-gate         int     wc_blockbytes;          /* size of wc_block */
630Sstevel@tonic-gate         int     wc_clipid;              /* Current clip id of clipping */
640Sstevel@tonic-gate         short   wc_screenrect[4];       /* Screen relatived (used when paint) */
650Sstevel@tonic-gate         char    *wc_block;              /* Block where RectList is copied. */
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * Ioctl control packet
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate struct s5termios {
720Sstevel@tonic-gate 	tcflag_t	c_iflag;	/* input modes */
730Sstevel@tonic-gate 	tcflag_t	c_oflag;	/* output modes */
740Sstevel@tonic-gate 	tcflag_t	c_cflag;	/* control modes */
750Sstevel@tonic-gate 	tcflag_t	c_lflag;	/* line discipline modes */
760Sstevel@tonic-gate 	cc_t		c_cc[19];	/* control chars */
770Sstevel@tonic-gate };
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define N_ENOMSG	35
800Sstevel@tonic-gate #define N_I_FIND	('S'<<8)|013
810Sstevel@tonic-gate #define N_I_PUSH	('S'<<8)|02
82*722Smuffin #define WINGETEXPOSEDRL	_IOWR('g',31,struct winclip)
83*722Smuffin #define WINGETDAMAGEDRL _IOWR('g',32,struct winclip)
840Sstevel@tonic-gate 
850Sstevel@tonic-gate struct n_sgttyb {
860Sstevel@tonic-gate 	char    sg_ispeed;              /* input speed */
870Sstevel@tonic-gate 	char    sg_ospeed;              /* output speed */
880Sstevel@tonic-gate 	char    sg_erase;               /* erase character */
890Sstevel@tonic-gate 	char    sg_kill;                /* kill character */
900Sstevel@tonic-gate 	int     sg_flags;               /* mode flags */
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate static int handle_dkio_partitions(int, int, int);
940Sstevel@tonic-gate static int tcget(int, int, int);
950Sstevel@tonic-gate static int tcset(int, int, int);
960Sstevel@tonic-gate static int _bc_ioctl(int, int, int);
970Sstevel@tonic-gate 
980Sstevel@tonic-gate int
ioctl(int des,int request,int arg)990Sstevel@tonic-gate ioctl(int des, int request, int arg)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate 	int ret;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	if ((ret = _bc_ioctl(des, request, arg)) == -1)
1040Sstevel@tonic-gate 		maperror();
1050Sstevel@tonic-gate 	return (ret);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate int
bc_ioctl(int des,int request,int arg)1090Sstevel@tonic-gate bc_ioctl(int des, int request, int arg)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate 	int ret;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	if ((ret = _bc_ioctl(des, request, arg)) == -1)
1140Sstevel@tonic-gate 		maperror();
1150Sstevel@tonic-gate 	return (ret);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate static int
_bc_ioctl(int des,int request,int arg)1190Sstevel@tonic-gate _bc_ioctl(int des, int request, int arg)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate 	int ret;
1220Sstevel@tonic-gate 	int nreq = (request >> 8) & 0xFF;
1230Sstevel@tonic-gate 	struct n_sgttyb nsg;
1240Sstevel@tonic-gate 	struct s5_dk_cinfo newArgs;
1250Sstevel@tonic-gate 	struct dk_info *infoArgs;
1260Sstevel@tonic-gate 	struct dk_conf *confArgs;
1270Sstevel@tonic-gate 	extern int errno;
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	/* not all mappings for 'm' have been performed */
1300Sstevel@tonic-gate 	switch (nreq) {
1310Sstevel@tonic-gate 		case ((int) 't'):
1320Sstevel@tonic-gate 			if (_ioctl(des, N_I_FIND, "ttcompat") == 0)
1330Sstevel@tonic-gate 				if (_ioctl(des, N_I_PUSH, "ttcompat") == -1)
1340Sstevel@tonic-gate 					perror("ioctl/I_PUSH");
1350Sstevel@tonic-gate 			switch(request) {
1360Sstevel@tonic-gate 				case TIOCSETD:
1370Sstevel@tonic-gate 					     /* added for sunview */
1380Sstevel@tonic-gate 					     return(0);
1390Sstevel@tonic-gate 				case TIOCREMOTE: request = ('t'<<8)|30;
1400Sstevel@tonic-gate 					     break;
1410Sstevel@tonic-gate 				case TIOCNOTTY:
1420Sstevel@tonic-gate 					     bc_setsid();
1430Sstevel@tonic-gate 					     return(0);
1440Sstevel@tonic-gate 				case TIOCGPGRP: request = ('t'<<8)|20;
1450Sstevel@tonic-gate 					     break;
1460Sstevel@tonic-gate 				case TIOCSPGRP:
1470Sstevel@tonic-gate 				    {
1480Sstevel@tonic-gate 					pid_t pgid;
1490Sstevel@tonic-gate 					sigset_t set, oset;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 					request = ('t'<<8)|21;
1520Sstevel@tonic-gate 					ret = _ioctl(des, request, arg);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 					/*
1550Sstevel@tonic-gate 					 * SunOS4.x allows this to succeed
1560Sstevel@tonic-gate 					 * even if the process group does
1570Sstevel@tonic-gate 					 * not exist yet.  We emulate the 4.x
1580Sstevel@tonic-gate 					 * bug by creating the process group
1590Sstevel@tonic-gate 					 * and reissuing the ioctl().
1600Sstevel@tonic-gate 					 * See bugid 1175044.
1610Sstevel@tonic-gate 					 */
1620Sstevel@tonic-gate 					if (ret != 0 && errno == EPERM &&
1630Sstevel@tonic-gate 					    (pgid = *((pid_t *)arg)) != 0 &&
1640Sstevel@tonic-gate 					    pgid == getpid() &&
1650Sstevel@tonic-gate 					    setpgid(0, pgid) == 0) {
1660Sstevel@tonic-gate 						sigemptyset(&set);
1670Sstevel@tonic-gate 						sigaddset(&set, SIGTSTP);
1680Sstevel@tonic-gate 						sigaddset(&set, SIGTTIN);
1690Sstevel@tonic-gate 						sigaddset(&set, SIGTTOU);
1700Sstevel@tonic-gate 						sigprocmask(SIG_BLOCK,
1710Sstevel@tonic-gate 							&set, &oset);
1720Sstevel@tonic-gate 						ret = _ioctl(des,
1730Sstevel@tonic-gate 							request, arg);
1740Sstevel@tonic-gate 						sigprocmask(SIG_SETMASK,
1750Sstevel@tonic-gate 							&oset, NULL);
1760Sstevel@tonic-gate 					}
1770Sstevel@tonic-gate 					return(ret);
1780Sstevel@tonic-gate 				    }
1790Sstevel@tonic-gate 				case TIOCSTI: request = ('t'<<8)|23;
1800Sstevel@tonic-gate 					     break;
1810Sstevel@tonic-gate 				case TIOCSIGNAL: request = ('t'<<8)|31;
1820Sstevel@tonic-gate 					     break;
1830Sstevel@tonic-gate 				case TIOCCONS: request = ('t'<<8)|36;
1840Sstevel@tonic-gate 					     break;
1850Sstevel@tonic-gate 				case TIOCSWINSZ: request = ('T'<<8)|103;
1860Sstevel@tonic-gate 					     break;
1870Sstevel@tonic-gate 				case TIOCGWINSZ: request = ('T'<<8)|104;
1880Sstevel@tonic-gate 					     break;
1890Sstevel@tonic-gate 				case TIOCSETP:
1900Sstevel@tonic-gate 				case TIOCSETN:
1910Sstevel@tonic-gate 			  	    {
1920Sstevel@tonic-gate 					struct sgttyb *sg = (struct sgttyb *)arg;
1930Sstevel@tonic-gate 					nsg.sg_ispeed = sg->sg_ispeed;
1940Sstevel@tonic-gate 					nsg.sg_ospeed = sg->sg_ospeed;
1950Sstevel@tonic-gate 					nsg.sg_erase = sg->sg_erase;
1960Sstevel@tonic-gate 					nsg.sg_kill = sg->sg_kill;
1970Sstevel@tonic-gate 					nsg.sg_flags = (int)sg->sg_flags;
1980Sstevel@tonic-gate 					arg = (int)&nsg;
1990Sstevel@tonic-gate 				        request = request & 0x0FFFF;
2000Sstevel@tonic-gate 					break;
2010Sstevel@tonic-gate 				    }
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 				case TIOCGETP:
2040Sstevel@tonic-gate 				    {
2050Sstevel@tonic-gate 					struct sgttyb *sg = (struct sgttyb *)arg;
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 					ret = _ioctl(des, request&0xFFFF, &nsg);
2080Sstevel@tonic-gate 					if (ret != -1) {
2090Sstevel@tonic-gate 						sg->sg_ispeed = nsg.sg_ispeed;
2100Sstevel@tonic-gate 						sg->sg_ospeed = nsg.sg_ospeed;
2110Sstevel@tonic-gate 						sg->sg_erase = nsg.sg_erase;
2120Sstevel@tonic-gate 						sg->sg_kill = nsg.sg_kill;
2130Sstevel@tonic-gate 						sg->sg_flags = (short)nsg.sg_flags & 0x0FFFF;
2140Sstevel@tonic-gate 					}
2150Sstevel@tonic-gate 					return(ret);
2160Sstevel@tonic-gate 				    }
2170Sstevel@tonic-gate 				case TIOCPKT:
2180Sstevel@tonic-gate 				case TIOCUCNTL:
2190Sstevel@tonic-gate 				case TIOCTCNTL:
2200Sstevel@tonic-gate 				case TIOCSSOFTCAR:
2210Sstevel@tonic-gate 				case TIOCGSOFTCAR:
2220Sstevel@tonic-gate 				case TIOCISPACE:
2230Sstevel@tonic-gate 				case TIOCISIZE:
2240Sstevel@tonic-gate 				case TIOCSSIZE:
2250Sstevel@tonic-gate 				case TIOCGSIZE:
2260Sstevel@tonic-gate 				    	     break;
2270Sstevel@tonic-gate 				default:     request = request & 0x0FFFF;
2280Sstevel@tonic-gate 				 	     break;
2290Sstevel@tonic-gate 			}
2300Sstevel@tonic-gate 			break;
2310Sstevel@tonic-gate 		case ((int) 'T'):
2320Sstevel@tonic-gate 			switch(request) {
2330Sstevel@tonic-gate 				case TCGETS:
2340Sstevel@tonic-gate 					request = ('T'<<8)|13;
2350Sstevel@tonic-gate 					return(tcget(des, request, arg));
2360Sstevel@tonic-gate 					break;
2370Sstevel@tonic-gate 				case TCSETS:
2380Sstevel@tonic-gate 					request = ('T'<<8)|14;
2390Sstevel@tonic-gate 					return(tcset(des, request, arg));
2400Sstevel@tonic-gate 					break;
2410Sstevel@tonic-gate 				case TCSETSW:
2420Sstevel@tonic-gate 					request = ('T'<<8)|15;
2430Sstevel@tonic-gate 					return(tcset(des, request, arg));
2440Sstevel@tonic-gate 					break;
2450Sstevel@tonic-gate 				case TCSETSF:
2460Sstevel@tonic-gate 					request = ('T'<<8)|16;
2470Sstevel@tonic-gate 					return(tcset(des, request, arg));
2480Sstevel@tonic-gate 					break;
2490Sstevel@tonic-gate 				case TCGETA:
2500Sstevel@tonic-gate 				case TCSETA:
2510Sstevel@tonic-gate 				case TCSETAW:
2520Sstevel@tonic-gate 				case TCSETAF:
2530Sstevel@tonic-gate 				default:
2540Sstevel@tonic-gate 					request = request & 0x0FFFF;
2550Sstevel@tonic-gate 					break;
2560Sstevel@tonic-gate 			}
2570Sstevel@tonic-gate 			break;
2580Sstevel@tonic-gate 		case ((int) 'S'):
2590Sstevel@tonic-gate 			switch (request) {
2600Sstevel@tonic-gate  				case I_PLINK: request = ('S'<<8)|026;
2610Sstevel@tonic-gate 					      break;
2620Sstevel@tonic-gate  				case I_PUNLINK: request = ('S'<<8)|027;
2630Sstevel@tonic-gate 					      break;
2640Sstevel@tonic-gate  				case I_STR: {
2650Sstevel@tonic-gate 					struct strioctl *iarg =
2660Sstevel@tonic-gate 					    (struct strioctl *)arg;
2670Sstevel@tonic-gate 					int cmd = iarg->ic_cmd;
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 					switch (cmd) {
2700Sstevel@tonic-gate 					case TI_GETINFO: {
2710Sstevel@tonic-gate 						/*
2720Sstevel@tonic-gate 						 * The T_info_ack structure
2730Sstevel@tonic-gate 						 * has one additional word
2740Sstevel@tonic-gate 						 * added to it in 5.x.
2750Sstevel@tonic-gate 						 * To prevent the module from
2760Sstevel@tonic-gate 						 * overwritting user memory we
2770Sstevel@tonic-gate 						 * use an internal buffer for
2780Sstevel@tonic-gate 						 * the transfer and copy out
2790Sstevel@tonic-gate 						 * the results to the caller.
2800Sstevel@tonic-gate 						 */
2810Sstevel@tonic-gate 						struct {
2820Sstevel@tonic-gate 							struct T_info_ack info;
2830Sstevel@tonic-gate 							long		pad[16];
2840Sstevel@tonic-gate 						} args;
2850Sstevel@tonic-gate 						char *dp = iarg->ic_dp;
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 						memcpy(&args.info, iarg->ic_dp,
2880Sstevel@tonic-gate 						    sizeof(struct T_info_ack));
2890Sstevel@tonic-gate 						iarg->ic_dp =
2900Sstevel@tonic-gate 						    (char *) &args.info;
2910Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 140);
2920Sstevel@tonic-gate 						ret = _ioctl(des,
2930Sstevel@tonic-gate 						    request & 0xffff, arg);
2940Sstevel@tonic-gate 						iarg->ic_cmd = cmd;
2950Sstevel@tonic-gate 						iarg->ic_dp = dp;
2960Sstevel@tonic-gate 						iarg->ic_len =
2970Sstevel@tonic-gate 						    sizeof(struct T_info_ack);
2980Sstevel@tonic-gate 						memcpy(iarg->ic_dp, &args.info,
2990Sstevel@tonic-gate 						    iarg->ic_len);
3000Sstevel@tonic-gate 						return (ret);
3010Sstevel@tonic-gate 						break;
3020Sstevel@tonic-gate 					}
3030Sstevel@tonic-gate 					case TI_OPTMGMT:
3040Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 141);
3050Sstevel@tonic-gate 						break;
3060Sstevel@tonic-gate 					case TI_BIND:
3070Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 142);
3080Sstevel@tonic-gate 						break;
3090Sstevel@tonic-gate 					case TI_UNBIND:
3100Sstevel@tonic-gate 						iarg->ic_cmd = (TIMOD | 143);
3110Sstevel@tonic-gate 						break;
3120Sstevel@tonic-gate 					}
3130Sstevel@tonic-gate 					ret = _ioctl(des,
3140Sstevel@tonic-gate 					    request & 0xffff, arg);
3150Sstevel@tonic-gate 					iarg->ic_cmd = cmd;
3160Sstevel@tonic-gate 					return ret;
3170Sstevel@tonic-gate 				}
3180Sstevel@tonic-gate 				default:      request = request & 0x0FFFF;
3190Sstevel@tonic-gate 				  	      break;
3200Sstevel@tonic-gate 			}
3210Sstevel@tonic-gate 			break;
3220Sstevel@tonic-gate 		case ((int) 'm'):
3230Sstevel@tonic-gate 			switch (request) {
3240Sstevel@tonic-gate 				case MSIOGETPARMS: request = ('m'<<8)|1;
3250Sstevel@tonic-gate 					      break;
3260Sstevel@tonic-gate 				case MSIOSETPARMS: request = ('m'<<8)|2;
3270Sstevel@tonic-gate 					      break;
3280Sstevel@tonic-gate 				default:      request = request & 0x0FFFF;
3290Sstevel@tonic-gate 				  	      break;
3300Sstevel@tonic-gate 			}
3310Sstevel@tonic-gate 			break;
3320Sstevel@tonic-gate 		case ((int) 'd'):
3330Sstevel@tonic-gate 			switch (request) {
3340Sstevel@tonic-gate 				case DKIOCGGEOM:
3350Sstevel@tonic-gate 					request = S5DKIOCGGEOM;
3360Sstevel@tonic-gate 					break;
3370Sstevel@tonic-gate 				case DKIOCSGEOM:
3380Sstevel@tonic-gate 					request = S5DKIOCSGEOM;
3390Sstevel@tonic-gate 					break;
3400Sstevel@tonic-gate 				case DKIOCSAPART:
3410Sstevel@tonic-gate 					request = S5DKIOCSAPART;
3420Sstevel@tonic-gate 					break;
3430Sstevel@tonic-gate 				case DKIOCGAPART:
3440Sstevel@tonic-gate 					request = S5DKIOCGAPART;
3450Sstevel@tonic-gate 					break;
3460Sstevel@tonic-gate 				case DKIOCSTYPE:
3470Sstevel@tonic-gate 					request = S5HDKIOCSTYPE;
3480Sstevel@tonic-gate 					break;
3490Sstevel@tonic-gate 				case DKIOCGTYPE:
3500Sstevel@tonic-gate 					request = S5HDKIOCGTYPE;
3510Sstevel@tonic-gate 					break;
3520Sstevel@tonic-gate 				case DKIOCSBAD:
3530Sstevel@tonic-gate 					request = S5HDKIOCSBAD;
3540Sstevel@tonic-gate 					break;
3550Sstevel@tonic-gate 				case DKIOCGBAD:
3560Sstevel@tonic-gate 					request = S5HDKIOCGBAD;
3570Sstevel@tonic-gate 					break;
3580Sstevel@tonic-gate 				case DKIOCSCMD:
3590Sstevel@tonic-gate 					request = S5HDKIOCSCMD;
3600Sstevel@tonic-gate 					break;
3610Sstevel@tonic-gate 				case DKIOCGDIAG:
3620Sstevel@tonic-gate 					request = S5HDKIOCGDIAG;
3630Sstevel@tonic-gate 					break;
3640Sstevel@tonic-gate 				case FDKIOGCHAR:
3650Sstevel@tonic-gate 					request = S5FDIOGCHAR;
3660Sstevel@tonic-gate 					break;
3670Sstevel@tonic-gate 				case FDKIOSCHAR:
3680Sstevel@tonic-gate 					request = S5FDIOSCHAR;
3690Sstevel@tonic-gate 					break;
3700Sstevel@tonic-gate 				case FDKEJECT:
3710Sstevel@tonic-gate 					request = S5FDEJECT;
3720Sstevel@tonic-gate 					break;
3730Sstevel@tonic-gate 				case FDKGETCHANGE:
3740Sstevel@tonic-gate 					request = S5FDGETCHANGE;
3750Sstevel@tonic-gate 					break;
3760Sstevel@tonic-gate 				case FDKGETDRIVECHAR:
3770Sstevel@tonic-gate 					request = S5FDGETDRIVECHAR;
3780Sstevel@tonic-gate 					break;
3790Sstevel@tonic-gate 				case FDKSETDRIVECHAR:
3800Sstevel@tonic-gate 					request = S5FDSETDRIVECHAR;
3810Sstevel@tonic-gate 					break;
3820Sstevel@tonic-gate 				case FDKGETSEARCH:
3830Sstevel@tonic-gate 					request = S5FDGETSEARCH;
3840Sstevel@tonic-gate 					break;
3850Sstevel@tonic-gate 				case FDKSETSEARCH:
3860Sstevel@tonic-gate 					request = S5FDSETSEARCH;
3870Sstevel@tonic-gate 					break;
3880Sstevel@tonic-gate 				case FDKIOCSCMD:
3890Sstevel@tonic-gate 					request = S5FDIOCMD;
3900Sstevel@tonic-gate 					break;
3910Sstevel@tonic-gate 				case F_RAW:
3920Sstevel@tonic-gate 					request = S5FDRAW;
3930Sstevel@tonic-gate 					break;
3940Sstevel@tonic-gate 				case DKIOCINFO:
3950Sstevel@tonic-gate 					ret = _ioctl(des, S5DKIOCINFO, &newArgs);
3960Sstevel@tonic-gate 					if (ret != -1) {
3970Sstevel@tonic-gate 						infoArgs = (struct dk_info *)arg;
3980Sstevel@tonic-gate 						infoArgs->dki_ctlr =
3990Sstevel@tonic-gate 							newArgs.dki_addr;
4000Sstevel@tonic-gate 						infoArgs->dki_unit =
4010Sstevel@tonic-gate 							newArgs.dki_unit;
4020Sstevel@tonic-gate 						infoArgs->dki_ctype =
4030Sstevel@tonic-gate 							newArgs.dki_ctype;
4040Sstevel@tonic-gate 						infoArgs->dki_flags =
4050Sstevel@tonic-gate 							newArgs.dki_flags;
4060Sstevel@tonic-gate 					}
4070Sstevel@tonic-gate 					return ret;
4080Sstevel@tonic-gate 					break;
4090Sstevel@tonic-gate 				case DKIOCGCONF:
4100Sstevel@tonic-gate 					ret = _ioctl(des, S5DKIOCINFO, &newArgs);
4110Sstevel@tonic-gate 					if (ret != -1) {
4120Sstevel@tonic-gate 						confArgs = (struct dk_conf *)arg;
4130Sstevel@tonic-gate 						strncpy(confArgs->dkc_cname,
4140Sstevel@tonic-gate 							newArgs.dki_cname,
4150Sstevel@tonic-gate 							DK_DEVLEN);
4160Sstevel@tonic-gate 						strncpy(confArgs->dkc_dname,
4170Sstevel@tonic-gate 							newArgs.dki_dname,
4180Sstevel@tonic-gate 							DK_DEVLEN);
4190Sstevel@tonic-gate 						confArgs->dkc_ctype =
4200Sstevel@tonic-gate 							(u_short)newArgs.dki_ctype;
4210Sstevel@tonic-gate 						confArgs->dkc_flags =
4220Sstevel@tonic-gate 							(u_short)newArgs.dki_flags;
4230Sstevel@tonic-gate 						confArgs->dkc_cnum =
4240Sstevel@tonic-gate 							newArgs.dki_cnum;
4250Sstevel@tonic-gate 						confArgs->dkc_addr =
4260Sstevel@tonic-gate 							newArgs.dki_addr;
4270Sstevel@tonic-gate 						confArgs->dkc_space =
4280Sstevel@tonic-gate 							(u_int)newArgs.dki_space;
4290Sstevel@tonic-gate 						confArgs->dkc_prio =
4300Sstevel@tonic-gate 							newArgs.dki_prio;
4310Sstevel@tonic-gate 						confArgs->dkc_vec =
4320Sstevel@tonic-gate 							newArgs.dki_vec;
4330Sstevel@tonic-gate 						confArgs->dkc_unit =
4340Sstevel@tonic-gate 							newArgs.dki_unit;
4350Sstevel@tonic-gate 						confArgs->dkc_slave =
4360Sstevel@tonic-gate 							newArgs.dki_slave;
4370Sstevel@tonic-gate 					}
4380Sstevel@tonic-gate 					return ret;
4390Sstevel@tonic-gate 					break;
4400Sstevel@tonic-gate 				case DKIOCWCHK:
4410Sstevel@tonic-gate 					/*
4420Sstevel@tonic-gate 					 * This is unsupported in SVR4. It
4430Sstevel@tonic-gate 					 * turns on verify-after-write for
4440Sstevel@tonic-gate 					 * the floppy. I don't think the
4450Sstevel@tonic-gate 					 * system call should fail, however.
4460Sstevel@tonic-gate 					 */
4470Sstevel@tonic-gate 					return 0;
4480Sstevel@tonic-gate 					break;
4490Sstevel@tonic-gate 				case DKIOCGPART:
4500Sstevel@tonic-gate 				case DKIOCSPART:
4510Sstevel@tonic-gate 					return (handle_dkio_partitions(des,
4520Sstevel@tonic-gate 					       request, arg));
4530Sstevel@tonic-gate 				case DKIOCGLOG:
4540Sstevel@tonic-gate 					/* unsupported */
4550Sstevel@tonic-gate 					errno = EINVAL;
4560Sstevel@tonic-gate 					return -1;
4570Sstevel@tonic-gate 					break;
4580Sstevel@tonic-gate 				case DESIOCBLOCK:
4590Sstevel@tonic-gate 				case DESIOCQUICK:
4600Sstevel@tonic-gate 					break; /* no change for these two */
4610Sstevel@tonic-gate 				default:
4620Sstevel@tonic-gate 					request = request & 0x0FFFF; /* try */
4630Sstevel@tonic-gate 					break;
4640Sstevel@tonic-gate 			}
4650Sstevel@tonic-gate 			break;
4660Sstevel@tonic-gate 		case ((int) 'c'):
4670Sstevel@tonic-gate 			switch (request) {
4680Sstevel@tonic-gate 				case CDROMPAUSE:
4690Sstevel@tonic-gate 					request = S5CDROMPAUSE;
4700Sstevel@tonic-gate 					break;
4710Sstevel@tonic-gate 				case CDROMRESUME:
4720Sstevel@tonic-gate 					request = S5CDROMRESUME;
4730Sstevel@tonic-gate 					break;
4740Sstevel@tonic-gate 				case CDROMPLAYMSF:
4750Sstevel@tonic-gate 					request = S5CDROMPLAYMSF;
4760Sstevel@tonic-gate 					break;
4770Sstevel@tonic-gate 				case CDROMPLAYTRKIND:
4780Sstevel@tonic-gate 					request = S5CDROMPLAYTRKIND;
4790Sstevel@tonic-gate 					break;
4800Sstevel@tonic-gate 				case CDROMREADTOCHDR:
4810Sstevel@tonic-gate 					request = S5CDROMREADTOCHDR;
4820Sstevel@tonic-gate 					break;
4830Sstevel@tonic-gate 				case CDROMREADTOCENTRY:
4840Sstevel@tonic-gate 					request = S5CDROMREADTOCENTRY;
4850Sstevel@tonic-gate 					break;
4860Sstevel@tonic-gate 				case CDROMSTOP:
4870Sstevel@tonic-gate 					request = S5CDROMSTOP;
4880Sstevel@tonic-gate 					break;
4890Sstevel@tonic-gate 				case CDROMSTART:
4900Sstevel@tonic-gate 					request = S5CDROMSTART;
4910Sstevel@tonic-gate 					break;
4920Sstevel@tonic-gate 				case CDROMEJECT:
4930Sstevel@tonic-gate 					request = S5CDROMEJECT;
4940Sstevel@tonic-gate 					break;
4950Sstevel@tonic-gate 				case CDROMVOLCTRL:
4960Sstevel@tonic-gate 					request = S5CDROMVOLCTRL;
4970Sstevel@tonic-gate 					break;
4980Sstevel@tonic-gate 				case CDROMSUBCHNL:
4990Sstevel@tonic-gate 					request = S5CDROMSUBCHNL;
5000Sstevel@tonic-gate 					break;
5010Sstevel@tonic-gate 				case CDROMREADMODE1:
5020Sstevel@tonic-gate 					request = S5CDROMREADMODE1;
5030Sstevel@tonic-gate 					break;
5040Sstevel@tonic-gate 				case CDROMREADMODE2:
5050Sstevel@tonic-gate 					request = S5CDROMREADMODE2;
5060Sstevel@tonic-gate 					break;
5070Sstevel@tonic-gate 			}
5080Sstevel@tonic-gate 			break;
5090Sstevel@tonic-gate 		case ((int) 'u'):
5100Sstevel@tonic-gate 			switch (request) {
5110Sstevel@tonic-gate 				case USCSICMD:
5120Sstevel@tonic-gate 				    {
5130Sstevel@tonic-gate 					struct s5_uscsi_cmd s5_cmd;
5140Sstevel@tonic-gate 					struct uscsi_cmd *cmd =
5150Sstevel@tonic-gate 						(struct uscsi_cmd *) arg;
5160Sstevel@tonic-gate 					request = S5USCSICMD;
5170Sstevel@tonic-gate 					s5_cmd.uscsi_cdb = cmd->uscsi_cdb;
5180Sstevel@tonic-gate 					s5_cmd.uscsi_cdblen =
5190Sstevel@tonic-gate 						cmd->uscsi_cdblen;
5200Sstevel@tonic-gate 					s5_cmd.uscsi_bufaddr =
5210Sstevel@tonic-gate 						cmd->uscsi_bufaddr;
5220Sstevel@tonic-gate 					s5_cmd.uscsi_buflen =
5230Sstevel@tonic-gate 						cmd->uscsi_buflen;
5240Sstevel@tonic-gate 					s5_cmd.uscsi_flags =
5250Sstevel@tonic-gate 						cmd->uscsi_flags;
5260Sstevel@tonic-gate 					ret = _ioctl(des, request, &s5_cmd);
5270Sstevel@tonic-gate 					cmd->uscsi_status = s5_cmd.uscsi_status;
5280Sstevel@tonic-gate 					return(ret);
5290Sstevel@tonic-gate 				    }
5300Sstevel@tonic-gate 			}
5310Sstevel@tonic-gate 			break;
5320Sstevel@tonic-gate 		case ((int) 'k'):
5330Sstevel@tonic-gate 		case ((int) 'v'):
5340Sstevel@tonic-gate 		case ((int) 'F'):
5350Sstevel@tonic-gate 		case ((int) 'G'):
5360Sstevel@tonic-gate 		case ((int) 'X'):
5370Sstevel@tonic-gate 		case ((int) 'L'):
5380Sstevel@tonic-gate 			request = request & 0x0FFFF;
5390Sstevel@tonic-gate 			break;
5400Sstevel@tonic-gate 		case ((int) 'f'):
5410Sstevel@tonic-gate 			if ((request == FIOCLEX) || (request == FIONCLEX))
5420Sstevel@tonic-gate 				return(fcntl(des, F_SETFD,
5430Sstevel@tonic-gate 				    ((request == FIOCLEX) ? 1 : 0)));
5440Sstevel@tonic-gate 			break;
5450Sstevel@tonic-gate 		case ((int) 'g'):
5460Sstevel@tonic-gate 			/* Treat the following 2 ioctls specially for
5470Sstevel@tonic-gate 			 * sunview. */
5480Sstevel@tonic-gate 			if (request == WINGETEXPOSEDRL ||
5490Sstevel@tonic-gate 				request == WINGETDAMAGEDRL) {
5500Sstevel@tonic-gate 				ret = _ioctl(des, request, arg);
5510Sstevel@tonic-gate 				if (errno == N_ENOMSG)
5520Sstevel@tonic-gate 					errno = EFBIG;
5530Sstevel@tonic-gate 				return(ret);
5540Sstevel@tonic-gate 			}
5550Sstevel@tonic-gate 			break;
5560Sstevel@tonic-gate 	}
5570Sstevel@tonic-gate 	return (_ioctl(des, request, arg));
5580Sstevel@tonic-gate }
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate static int
handle_dkio_partitions(int des,int request,int arg)5620Sstevel@tonic-gate handle_dkio_partitions(int des, int request, int arg)
5630Sstevel@tonic-gate {
5640Sstevel@tonic-gate 	struct s5_dk_cinfo	cinfo;
5650Sstevel@tonic-gate 	struct dk_allmap	map;
5660Sstevel@tonic-gate 	struct dk_map		*part;
5670Sstevel@tonic-gate 	int			ret;
5680Sstevel@tonic-gate 	extern int		errno;
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate 	part = (struct dk_map *) arg;
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate 	ret = _ioctl(des, S5DKIOCINFO, &cinfo);
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate 	if ((cinfo.dki_partition < 0) || (cinfo.dki_partition >= NDKMAP)) {
5750Sstevel@tonic-gate 		errno = EINVAL;
5760Sstevel@tonic-gate 		return (-1);
5770Sstevel@tonic-gate 	}
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 	if (ret != -1) {
5800Sstevel@tonic-gate 		ret = _ioctl(des, S5DKIOCGAPART, &map);
5810Sstevel@tonic-gate 		if (ret != -1) {
5820Sstevel@tonic-gate 			if (request == DKIOCGPART) {
5830Sstevel@tonic-gate 				part->dkl_cylno =
5840Sstevel@tonic-gate 				    map.dka_map[cinfo.dki_partition].dkl_cylno;
5850Sstevel@tonic-gate 				part->dkl_nblk =
5860Sstevel@tonic-gate 				    map.dka_map[cinfo.dki_partition].dkl_nblk;
5870Sstevel@tonic-gate 			} else {
5880Sstevel@tonic-gate 				map.dka_map[cinfo.dki_partition].dkl_cylno =
5890Sstevel@tonic-gate 					part->dkl_cylno;
5900Sstevel@tonic-gate 				map.dka_map[cinfo.dki_partition].dkl_nblk =
5910Sstevel@tonic-gate 					part->dkl_nblk;
5920Sstevel@tonic-gate 				ret = _ioctl(des, S5DKIOCSAPART, &map);
5930Sstevel@tonic-gate 			}
5940Sstevel@tonic-gate 		}
5950Sstevel@tonic-gate 	}
5960Sstevel@tonic-gate 	return (ret);
5970Sstevel@tonic-gate }
5980Sstevel@tonic-gate 
5990Sstevel@tonic-gate static int
tcset(des,request,arg)6000Sstevel@tonic-gate tcset(des, request, arg)
6010Sstevel@tonic-gate 	register int	des;
6020Sstevel@tonic-gate 	register int	request;
6030Sstevel@tonic-gate 	int		arg;
6040Sstevel@tonic-gate {
6050Sstevel@tonic-gate 	struct s5termios	s5termios;
6060Sstevel@tonic-gate 	struct termios		*termios;
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate 	termios = (struct termios *)arg;
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	if (termios != NULL) {
6110Sstevel@tonic-gate 		s5termios.c_iflag = termios->c_iflag;
6120Sstevel@tonic-gate 		s5termios.c_oflag = termios->c_oflag;
6130Sstevel@tonic-gate 		s5termios.c_cflag = termios->c_cflag;
6140Sstevel@tonic-gate 		s5termios.c_lflag = termios->c_lflag;
6150Sstevel@tonic-gate 		memcpy(s5termios.c_cc, termios->c_cc, NCCS);
6160Sstevel@tonic-gate 		return (_ioctl(des, request, &s5termios));
6170Sstevel@tonic-gate 	} else
6180Sstevel@tonic-gate 		return (_ioctl(des, request, NULL));
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate static int
tcget(des,request,arg)6230Sstevel@tonic-gate tcget(des, request, arg)
6240Sstevel@tonic-gate 	register int	des;
6250Sstevel@tonic-gate 	register int	request;
6260Sstevel@tonic-gate 	int		arg;
6270Sstevel@tonic-gate {
6280Sstevel@tonic-gate 	struct s5termios	s5termios;
6290Sstevel@tonic-gate 	struct termios		*termios;
6300Sstevel@tonic-gate 	int			ret;
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate 	termios = (struct termios *)arg;
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate 	ret = _ioctl(des, request, &s5termios);
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	if (termios != NULL) {
6370Sstevel@tonic-gate 		termios->c_iflag = s5termios.c_iflag;
6380Sstevel@tonic-gate 		termios->c_oflag = s5termios.c_oflag;
6390Sstevel@tonic-gate 		termios->c_cflag = s5termios.c_cflag;
6400Sstevel@tonic-gate 		termios->c_lflag = s5termios.c_lflag;
6410Sstevel@tonic-gate 		memcpy(termios->c_cc, s5termios.c_cc, NCCS);
6420Sstevel@tonic-gate 	}
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	return (ret);
6450Sstevel@tonic-gate }
646