4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Do not include sys/conf.h- it isn't in the compatibility include dirs.
37 #include <sys/types.h>
38 #include <sys/ioccom.h>
39 #include <sys/stropts.h>
41 #include <sys/fcntl.h>
42 #include <sys/filio.h>
43 #include <sys/termios.h>
44 #include <sys/termio.h>
45 #include <sys/ttold.h>
46 #include <sys/ttycom.h>
48 #include <sys/errno.h>
49 #include <nettli/tihdr.h>
50 #include <nettli/timod.h>
51 #include <nettli/tiuser.h>
53 #include <scsi/impl/uscsi.h>
59 * parameter for windows ioctls
62 int wc_blockbytes
; /* size of wc_block */
63 int wc_clipid
; /* Current clip id of clipping */
64 short wc_screenrect
[4]; /* Screen relatived (used when paint) */
65 char *wc_block
; /* Block where RectList is copied. */
69 * Ioctl control packet
72 tcflag_t c_iflag
; /* input modes */
73 tcflag_t c_oflag
; /* output modes */
74 tcflag_t c_cflag
; /* control modes */
75 tcflag_t c_lflag
; /* line discipline modes */
76 cc_t c_cc
[19]; /* control chars */
80 #define N_I_FIND ('S'<<8)|013
81 #define N_I_PUSH ('S'<<8)|02
82 #define WINGETEXPOSEDRL _IOWR('g',31,struct winclip)
83 #define WINGETDAMAGEDRL _IOWR('g',32,struct winclip)
86 char sg_ispeed
; /* input speed */
87 char sg_ospeed
; /* output speed */
88 char sg_erase
; /* erase character */
89 char sg_kill
; /* kill character */
90 int sg_flags
; /* mode flags */
93 static int handle_dkio_partitions(int, int, int);
94 static int tcget(int, int, int);
95 static int tcset(int, int, int);
96 static int _bc_ioctl(int, int, int);
99 ioctl(int des
, int request
, int arg
)
103 if ((ret
= _bc_ioctl(des
, request
, arg
)) == -1)
109 bc_ioctl(int des
, int request
, int arg
)
113 if ((ret
= _bc_ioctl(des
, request
, arg
)) == -1)
119 _bc_ioctl(int des
, int request
, int arg
)
122 int nreq
= (request
>> 8) & 0xFF;
124 struct s5_dk_cinfo newArgs
;
125 struct dk_info
*infoArgs
;
126 struct dk_conf
*confArgs
;
129 /* not all mappings for 'm' have been performed */
132 if (_ioctl(des
, N_I_FIND
, "ttcompat") == 0)
133 if (_ioctl(des
, N_I_PUSH
, "ttcompat") == -1)
134 perror("ioctl/I_PUSH");
137 /* added for sunview */
139 case TIOCREMOTE
: request
= ('t'<<8)|30;
144 case TIOCGPGRP
: request
= ('t'<<8)|20;
151 request
= ('t'<<8)|21;
152 ret
= _ioctl(des
, request
, arg
);
155 * SunOS4.x allows this to succeed
156 * even if the process group does
157 * not exist yet. We emulate the 4.x
158 * bug by creating the process group
159 * and reissuing the ioctl().
162 if (ret
!= 0 && errno
== EPERM
&&
163 (pgid
= *((pid_t
*)arg
)) != 0 &&
165 setpgid(0, pgid
) == 0) {
167 sigaddset(&set
, SIGTSTP
);
168 sigaddset(&set
, SIGTTIN
);
169 sigaddset(&set
, SIGTTOU
);
170 sigprocmask(SIG_BLOCK
,
174 sigprocmask(SIG_SETMASK
,
179 case TIOCSTI
: request
= ('t'<<8)|23;
181 case TIOCSIGNAL
: request
= ('t'<<8)|31;
183 case TIOCCONS
: request
= ('t'<<8)|36;
185 case TIOCSWINSZ
: request
= ('T'<<8)|103;
187 case TIOCGWINSZ
: request
= ('T'<<8)|104;
192 struct sgttyb
*sg
= (struct sgttyb
*)arg
;
193 nsg
.sg_ispeed
= sg
->sg_ispeed
;
194 nsg
.sg_ospeed
= sg
->sg_ospeed
;
195 nsg
.sg_erase
= sg
->sg_erase
;
196 nsg
.sg_kill
= sg
->sg_kill
;
197 nsg
.sg_flags
= (int)sg
->sg_flags
;
199 request
= request
& 0x0FFFF;
205 struct sgttyb
*sg
= (struct sgttyb
*)arg
;
207 ret
= _ioctl(des
, request
&0xFFFF, &nsg
);
209 sg
->sg_ispeed
= nsg
.sg_ispeed
;
210 sg
->sg_ospeed
= nsg
.sg_ospeed
;
211 sg
->sg_erase
= nsg
.sg_erase
;
212 sg
->sg_kill
= nsg
.sg_kill
;
213 sg
->sg_flags
= (short)nsg
.sg_flags
& 0x0FFFF;
227 default: request
= request
& 0x0FFFF;
234 request
= ('T'<<8)|13;
235 return(tcget(des
, request
, arg
));
238 request
= ('T'<<8)|14;
239 return(tcset(des
, request
, arg
));
242 request
= ('T'<<8)|15;
243 return(tcset(des
, request
, arg
));
246 request
= ('T'<<8)|16;
247 return(tcset(des
, request
, arg
));
254 request
= request
& 0x0FFFF;
260 case I_PLINK
: request
= ('S'<<8)|026;
262 case I_PUNLINK
: request
= ('S'<<8)|027;
265 struct strioctl
*iarg
=
266 (struct strioctl
*)arg
;
267 int cmd
= iarg
->ic_cmd
;
272 * The T_info_ack structure
273 * has one additional word
274 * added to it in 5.x.
275 * To prevent the module from
276 * overwritting user memory we
277 * use an internal buffer for
278 * the transfer and copy out
279 * the results to the caller.
282 struct T_info_ack info
;
285 char *dp
= iarg
->ic_dp
;
287 memcpy(&args
.info
, iarg
->ic_dp
,
288 sizeof(struct T_info_ack
));
291 iarg
->ic_cmd
= (TIMOD
| 140);
293 request
& 0xffff, arg
);
297 sizeof(struct T_info_ack
);
298 memcpy(iarg
->ic_dp
, &args
.info
,
304 iarg
->ic_cmd
= (TIMOD
| 141);
307 iarg
->ic_cmd
= (TIMOD
| 142);
310 iarg
->ic_cmd
= (TIMOD
| 143);
314 request
& 0xffff, arg
);
318 default: request
= request
& 0x0FFFF;
324 case MSIOGETPARMS
: request
= ('m'<<8)|1;
326 case MSIOSETPARMS
: request
= ('m'<<8)|2;
328 default: request
= request
& 0x0FFFF;
335 request
= S5DKIOCGGEOM
;
338 request
= S5DKIOCSGEOM
;
341 request
= S5DKIOCSAPART
;
344 request
= S5DKIOCGAPART
;
347 request
= S5HDKIOCSTYPE
;
350 request
= S5HDKIOCGTYPE
;
353 request
= S5HDKIOCSBAD
;
356 request
= S5HDKIOCGBAD
;
359 request
= S5HDKIOCSCMD
;
362 request
= S5HDKIOCGDIAG
;
365 request
= S5FDIOGCHAR
;
368 request
= S5FDIOSCHAR
;
374 request
= S5FDGETCHANGE
;
376 case FDKGETDRIVECHAR
:
377 request
= S5FDGETDRIVECHAR
;
379 case FDKSETDRIVECHAR
:
380 request
= S5FDSETDRIVECHAR
;
383 request
= S5FDGETSEARCH
;
386 request
= S5FDSETSEARCH
;
395 ret
= _ioctl(des
, S5DKIOCINFO
, &newArgs
);
397 infoArgs
= (struct dk_info
*)arg
;
402 infoArgs
->dki_ctype
=
404 infoArgs
->dki_flags
=
410 ret
= _ioctl(des
, S5DKIOCINFO
, &newArgs
);
412 confArgs
= (struct dk_conf
*)arg
;
413 strncpy(confArgs
->dkc_cname
,
416 strncpy(confArgs
->dkc_dname
,
419 confArgs
->dkc_ctype
=
420 (u_short
)newArgs
.dki_ctype
;
421 confArgs
->dkc_flags
=
422 (u_short
)newArgs
.dki_flags
;
427 confArgs
->dkc_space
=
428 (u_int
)newArgs
.dki_space
;
435 confArgs
->dkc_slave
=
442 * This is unsupported in SVR4. It
443 * turns on verify-after-write for
444 * the floppy. I don't think the
445 * system call should fail, however.
451 return (handle_dkio_partitions(des
,
460 break; /* no change for these two */
462 request
= request
& 0x0FFFF; /* try */
469 request
= S5CDROMPAUSE
;
472 request
= S5CDROMRESUME
;
475 request
= S5CDROMPLAYMSF
;
477 case CDROMPLAYTRKIND
:
478 request
= S5CDROMPLAYTRKIND
;
480 case CDROMREADTOCHDR
:
481 request
= S5CDROMREADTOCHDR
;
483 case CDROMREADTOCENTRY
:
484 request
= S5CDROMREADTOCENTRY
;
487 request
= S5CDROMSTOP
;
490 request
= S5CDROMSTART
;
493 request
= S5CDROMEJECT
;
496 request
= S5CDROMVOLCTRL
;
499 request
= S5CDROMSUBCHNL
;
502 request
= S5CDROMREADMODE1
;
505 request
= S5CDROMREADMODE2
;
513 struct s5_uscsi_cmd s5_cmd
;
514 struct uscsi_cmd
*cmd
=
515 (struct uscsi_cmd
*) arg
;
516 request
= S5USCSICMD
;
517 s5_cmd
.uscsi_cdb
= cmd
->uscsi_cdb
;
518 s5_cmd
.uscsi_cdblen
=
520 s5_cmd
.uscsi_bufaddr
=
522 s5_cmd
.uscsi_buflen
=
526 ret
= _ioctl(des
, request
, &s5_cmd
);
527 cmd
->uscsi_status
= s5_cmd
.uscsi_status
;
538 request
= request
& 0x0FFFF;
541 if ((request
== FIOCLEX
) || (request
== FIONCLEX
))
542 return(fcntl(des
, F_SETFD
,
543 ((request
== FIOCLEX
) ? 1 : 0)));
546 /* Treat the following 2 ioctls specially for
548 if (request
== WINGETEXPOSEDRL
||
549 request
== WINGETDAMAGEDRL
) {
550 ret
= _ioctl(des
, request
, arg
);
551 if (errno
== N_ENOMSG
)
557 return (_ioctl(des
, request
, arg
));
562 handle_dkio_partitions(int des
, int request
, int arg
)
564 struct s5_dk_cinfo cinfo
;
565 struct dk_allmap map
;
570 part
= (struct dk_map
*) arg
;
572 ret
= _ioctl(des
, S5DKIOCINFO
, &cinfo
);
574 if ((cinfo
.dki_partition
< 0) || (cinfo
.dki_partition
>= NDKMAP
)) {
580 ret
= _ioctl(des
, S5DKIOCGAPART
, &map
);
582 if (request
== DKIOCGPART
) {
584 map
.dka_map
[cinfo
.dki_partition
].dkl_cylno
;
586 map
.dka_map
[cinfo
.dki_partition
].dkl_nblk
;
588 map
.dka_map
[cinfo
.dki_partition
].dkl_cylno
=
590 map
.dka_map
[cinfo
.dki_partition
].dkl_nblk
=
592 ret
= _ioctl(des
, S5DKIOCSAPART
, &map
);
600 tcset(des
, request
, arg
)
602 register int request
;
605 struct s5termios s5termios
;
606 struct termios
*termios
;
608 termios
= (struct termios
*)arg
;
610 if (termios
!= NULL
) {
611 s5termios
.c_iflag
= termios
->c_iflag
;
612 s5termios
.c_oflag
= termios
->c_oflag
;
613 s5termios
.c_cflag
= termios
->c_cflag
;
614 s5termios
.c_lflag
= termios
->c_lflag
;
615 memcpy(s5termios
.c_cc
, termios
->c_cc
, NCCS
);
616 return (_ioctl(des
, request
, &s5termios
));
618 return (_ioctl(des
, request
, NULL
));
623 tcget(des
, request
, arg
)
625 register int request
;
628 struct s5termios s5termios
;
629 struct termios
*termios
;
632 termios
= (struct termios
*)arg
;
634 ret
= _ioctl(des
, request
, &s5termios
);
636 if (termios
!= NULL
) {
637 termios
->c_iflag
= s5termios
.c_iflag
;
638 termios
->c_oflag
= s5termios
.c_oflag
;
639 termios
->c_cflag
= s5termios
.c_cflag
;
640 termios
->c_lflag
= s5termios
.c_lflag
;
641 memcpy(termios
->c_cc
, s5termios
.c_cc
, NCCS
);