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 1987-2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 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 * Indirect console driver for Sun. 31*0Sstevel@tonic-gate * 32*0Sstevel@tonic-gate * Redirects all I/O to the device designated as the underlying "hardware" 33*0Sstevel@tonic-gate * console, as given by the value of rconsvp. The implementation assumes that 34*0Sstevel@tonic-gate * rconsvp denotes a STREAMS device; the assumption is justified since 35*0Sstevel@tonic-gate * consoles must be capable of effecting tty semantics. 36*0Sstevel@tonic-gate * 37*0Sstevel@tonic-gate * rconsvp is set in autoconf.c:consconfig(), based on information obtained 38*0Sstevel@tonic-gate * from the EEPROM. 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * XXX: The driver still needs to be converted to use ANSI C consistently 41*0Sstevel@tonic-gate * throughout. 42*0Sstevel@tonic-gate */ 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate #include <sys/types.h> 45*0Sstevel@tonic-gate #include <sys/open.h> 46*0Sstevel@tonic-gate #include <sys/param.h> 47*0Sstevel@tonic-gate #include <sys/systm.h> 48*0Sstevel@tonic-gate #include <sys/signal.h> 49*0Sstevel@tonic-gate #include <sys/cred.h> 50*0Sstevel@tonic-gate #include <sys/user.h> 51*0Sstevel@tonic-gate #include <sys/proc.h> 52*0Sstevel@tonic-gate #include <sys/disp.h> 53*0Sstevel@tonic-gate #include <sys/file.h> 54*0Sstevel@tonic-gate #include <sys/taskq.h> 55*0Sstevel@tonic-gate #include <sys/log.h> 56*0Sstevel@tonic-gate #include <sys/vnode.h> 57*0Sstevel@tonic-gate #include <sys/uio.h> 58*0Sstevel@tonic-gate #include <sys/stat.h> 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate #include <sys/console.h> 61*0Sstevel@tonic-gate #include <sys/consdev.h> 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate #include <sys/stream.h> 64*0Sstevel@tonic-gate #include <sys/strsubr.h> 65*0Sstevel@tonic-gate #include <sys/poll.h> 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate #include <sys/debug.h> 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate #include <sys/conf.h> 70*0Sstevel@tonic-gate #include <sys/ddi.h> 71*0Sstevel@tonic-gate #include <sys/sunddi.h> 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate static int cnopen(dev_t *, int, int, struct cred *); 74*0Sstevel@tonic-gate static int cnclose(dev_t, int, int, struct cred *); 75*0Sstevel@tonic-gate static int cnread(dev_t, struct uio *, struct cred *); 76*0Sstevel@tonic-gate static int cnwrite(dev_t, struct uio *, struct cred *); 77*0Sstevel@tonic-gate static int cnioctl(dev_t, int, intptr_t, int, struct cred *, int *); 78*0Sstevel@tonic-gate static int cnpoll(dev_t, short, int, short *, struct pollhead **); 79*0Sstevel@tonic-gate static int cn_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 80*0Sstevel@tonic-gate static int cn_attach(dev_info_t *, ddi_attach_cmd_t); 81*0Sstevel@tonic-gate static int cn_detach(dev_info_t *, ddi_detach_cmd_t); 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate static dev_info_t *cn_dip; /* private copy of devinfo pointer */ 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate static struct cb_ops cn_cb_ops = { 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate cnopen, /* open */ 88*0Sstevel@tonic-gate cnclose, /* close */ 89*0Sstevel@tonic-gate nodev, /* strategy */ 90*0Sstevel@tonic-gate nodev, /* print */ 91*0Sstevel@tonic-gate nodev, /* dump */ 92*0Sstevel@tonic-gate cnread, /* read */ 93*0Sstevel@tonic-gate cnwrite, /* write */ 94*0Sstevel@tonic-gate cnioctl, /* ioctl */ 95*0Sstevel@tonic-gate nodev, /* devmap */ 96*0Sstevel@tonic-gate nodev, /* mmap */ 97*0Sstevel@tonic-gate nodev, /* segmap */ 98*0Sstevel@tonic-gate cnpoll, /* poll */ 99*0Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 100*0Sstevel@tonic-gate 0, /* streamtab */ 101*0Sstevel@tonic-gate D_NEW | D_MP /* Driver compatibility flag */ 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate }; 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate static struct dev_ops cn_ops = { 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 108*0Sstevel@tonic-gate 0, /* refcnt */ 109*0Sstevel@tonic-gate cn_info, /* info */ 110*0Sstevel@tonic-gate nulldev, /* identify */ 111*0Sstevel@tonic-gate nulldev, /* probe */ 112*0Sstevel@tonic-gate cn_attach, /* attach */ 113*0Sstevel@tonic-gate cn_detach, /* detach */ 114*0Sstevel@tonic-gate nodev, /* reset */ 115*0Sstevel@tonic-gate &cn_cb_ops, /* driver operations */ 116*0Sstevel@tonic-gate (struct bus_ops *)0 /* bus operations */ 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate }; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate /* 121*0Sstevel@tonic-gate * Global variables associated with the console device: 122*0Sstevel@tonic-gate * 123*0Sstevel@tonic-gate * XXX: There are too many of these! 124*0Sstevel@tonic-gate * moved to space.c to becone resident in the kernel so that cons 125*0Sstevel@tonic-gate * can be loadable. 126*0Sstevel@tonic-gate */ 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate extern dev_t rconsdev; /* "hardware" console */ 129*0Sstevel@tonic-gate extern vnode_t *rconsvp; /* pointer to vnode for that device */ 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate /* 132*0Sstevel@tonic-gate * XXX: consulted in prsubr.c, for /proc entry point for obtaining ps info. 133*0Sstevel@tonic-gate */ 134*0Sstevel@tonic-gate extern dev_t uconsdev; /* What the user thinks is the console device */ 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate /* 137*0Sstevel@tonic-gate * Private driver state: 138*0Sstevel@tonic-gate */ 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate /* 141*0Sstevel@tonic-gate * The underlying console device potentially can be opened through (at least) 142*0Sstevel@tonic-gate * two paths: through this driver and through the underlying device's driver. 143*0Sstevel@tonic-gate * To ensure that reference counts are meaningful and therefore that close 144*0Sstevel@tonic-gate * routines are called at the right time, it's important to make sure that 145*0Sstevel@tonic-gate * rconsvp's s_count field (i.e., the count on the underlying device) never 146*0Sstevel@tonic-gate * has a contribution of more than one through this driver, regardless of how 147*0Sstevel@tonic-gate * many times this driver's been opened. rconsopen keeps track of the 148*0Sstevel@tonic-gate * necessary information to ensure this property. 149*0Sstevel@tonic-gate */ 150*0Sstevel@tonic-gate static uint_t rconsopen; 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate #include <sys/types.h> 154*0Sstevel@tonic-gate #include <sys/conf.h> 155*0Sstevel@tonic-gate #include <sys/param.h> 156*0Sstevel@tonic-gate #include <sys/systm.h> 157*0Sstevel@tonic-gate #include <sys/errno.h> 158*0Sstevel@tonic-gate #include <sys/modctl.h> 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate extern int nodev(), nulldev(); 162*0Sstevel@tonic-gate extern int dseekneg_flag; 163*0Sstevel@tonic-gate extern struct mod_ops mod_driverops; 164*0Sstevel@tonic-gate extern struct dev_ops cn_ops; 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate /* 167*0Sstevel@tonic-gate * Module linkage information for the kernel. 168*0Sstevel@tonic-gate */ 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate static struct modldrv modldrv = { 171*0Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 172*0Sstevel@tonic-gate "Console redirection driver %I%", 173*0Sstevel@tonic-gate &cn_ops, /* driver ops */ 174*0Sstevel@tonic-gate }; 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate static struct modlinkage modlinkage = { 177*0Sstevel@tonic-gate MODREV_1, 178*0Sstevel@tonic-gate &modldrv, 179*0Sstevel@tonic-gate NULL 180*0Sstevel@tonic-gate }; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate int 183*0Sstevel@tonic-gate _init(void) 184*0Sstevel@tonic-gate { 185*0Sstevel@tonic-gate return (mod_install(&modlinkage)); 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate int 189*0Sstevel@tonic-gate _fini(void) 190*0Sstevel@tonic-gate { 191*0Sstevel@tonic-gate return (EBUSY); 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate int 195*0Sstevel@tonic-gate _info(struct modinfo *modinfop) 196*0Sstevel@tonic-gate { 197*0Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate /* 201*0Sstevel@tonic-gate * DDI glue routines 202*0Sstevel@tonic-gate */ 203*0Sstevel@tonic-gate static int 204*0Sstevel@tonic-gate cn_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 205*0Sstevel@tonic-gate { 206*0Sstevel@tonic-gate if (cmd != DDI_ATTACH) 207*0Sstevel@tonic-gate return (DDI_FAILURE); 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate if (ddi_create_minor_node(devi, "syscon", S_IFCHR, 210*0Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 211*0Sstevel@tonic-gate return (DDI_FAILURE); 212*0Sstevel@tonic-gate } 213*0Sstevel@tonic-gate if (ddi_create_minor_node(devi, "systty", S_IFCHR, 214*0Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 215*0Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 216*0Sstevel@tonic-gate return (DDI_FAILURE); 217*0Sstevel@tonic-gate } 218*0Sstevel@tonic-gate if (ddi_create_minor_node(devi, "console", S_IFCHR, 219*0Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 220*0Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 221*0Sstevel@tonic-gate return (DDI_FAILURE); 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate cn_dip = devi; 224*0Sstevel@tonic-gate return (DDI_SUCCESS); 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate static int 228*0Sstevel@tonic-gate cn_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 229*0Sstevel@tonic-gate { 230*0Sstevel@tonic-gate if (cmd != DDI_DETACH) 231*0Sstevel@tonic-gate return (DDI_FAILURE); 232*0Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 233*0Sstevel@tonic-gate uconsdev = NODEV; 234*0Sstevel@tonic-gate return (DDI_SUCCESS); 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate /* ARGSUSED */ 238*0Sstevel@tonic-gate static int 239*0Sstevel@tonic-gate cn_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 240*0Sstevel@tonic-gate { 241*0Sstevel@tonic-gate int error = DDI_FAILURE; 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate switch (infocmd) { 244*0Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 245*0Sstevel@tonic-gate if (getminor((dev_t)arg) == 0 && cn_dip != NULL) { 246*0Sstevel@tonic-gate *result = (void *) cn_dip; 247*0Sstevel@tonic-gate error = DDI_SUCCESS; 248*0Sstevel@tonic-gate } 249*0Sstevel@tonic-gate break; 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 252*0Sstevel@tonic-gate if (getminor((dev_t)arg) == 0) { 253*0Sstevel@tonic-gate *result = (void *)0; 254*0Sstevel@tonic-gate error = DDI_SUCCESS; 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate break; 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate default: 259*0Sstevel@tonic-gate break; 260*0Sstevel@tonic-gate } 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate return (error); 263*0Sstevel@tonic-gate } 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate /* 266*0Sstevel@tonic-gate * XXX Caution: before allowing more than 256 minor devices on the 267*0Sstevel@tonic-gate * console, make sure you understand the 'compatibility' hack 268*0Sstevel@tonic-gate * in ufs_iget() that translates old dev_t's to new dev_t's. 269*0Sstevel@tonic-gate * See bugid 1098104 for the sordid details. 270*0Sstevel@tonic-gate */ 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate /* ARGSUSED */ 273*0Sstevel@tonic-gate static int 274*0Sstevel@tonic-gate cnopen(dev_t *dev, int flag, int state, struct cred *cred) 275*0Sstevel@tonic-gate { 276*0Sstevel@tonic-gate int err; 277*0Sstevel@tonic-gate static int been_here; 278*0Sstevel@tonic-gate vnode_t *vp = rconsvp; 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate ASSERT(cred != NULL); 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate if (rconsvp == NULL) 283*0Sstevel@tonic-gate return (0); 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate 286*0Sstevel@tonic-gate /* 287*0Sstevel@tonic-gate * XXX: Clean up inactive PIDs from previous opens if any. 288*0Sstevel@tonic-gate * These would have been created as a result of an I_SETSIG 289*0Sstevel@tonic-gate * issued against console. This is a workaround, and 290*0Sstevel@tonic-gate * console driver must be correctly redesigned not to need 291*0Sstevel@tonic-gate * this hook. 292*0Sstevel@tonic-gate */ 293*0Sstevel@tonic-gate if (vp->v_stream) { 294*0Sstevel@tonic-gate str_cn_clean(vp); 295*0Sstevel@tonic-gate } 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate /* 298*0Sstevel@tonic-gate * XXX: Set hook to tell /proc about underlying console. (There's 299*0Sstevel@tonic-gate * gotta be a better way...) 300*0Sstevel@tonic-gate */ 301*0Sstevel@tonic-gate if (state != OTYP_CHR || getminor(*dev) != 0) 302*0Sstevel@tonic-gate return (ENXIO); 303*0Sstevel@tonic-gate if (been_here == 0) { 304*0Sstevel@tonic-gate uconsdev = *dev; 305*0Sstevel@tonic-gate been_here = 1; 306*0Sstevel@tonic-gate if (vn_open("/dev/console", UIO_SYSSPACE, FWRITE | FNOCTTY, 307*0Sstevel@tonic-gate 0, &console_vnode, 0, 0) == 0) 308*0Sstevel@tonic-gate console_taskq = taskq_create("console_taskq", 309*0Sstevel@tonic-gate 1, maxclsyspri - 1, LOG_LOWAT / LOG_MSGSIZE, 310*0Sstevel@tonic-gate LOG_HIWAT / LOG_MSGSIZE, TASKQ_PREPOPULATE); 311*0Sstevel@tonic-gate } 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate if ((err = VOP_OPEN(&vp, flag, cred)) != 0) 314*0Sstevel@tonic-gate return (err); 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate /* 317*0Sstevel@tonic-gate * The underlying driver is not allowed to have cloned itself 318*0Sstevel@tonic-gate * for this open. 319*0Sstevel@tonic-gate */ 320*0Sstevel@tonic-gate if (vp != rconsvp) { 321*0Sstevel@tonic-gate /* 322*0Sstevel@tonic-gate * It might happen that someone set rconsvp to NULL 323*0Sstevel@tonic-gate * whilst we were in the middle of the open. 324*0Sstevel@tonic-gate */ 325*0Sstevel@tonic-gate if (rconsvp == NULL) { 326*0Sstevel@tonic-gate (void) VOP_CLOSE(vp, flag, 1, (offset_t)0, cred); 327*0Sstevel@tonic-gate return (0); 328*0Sstevel@tonic-gate } 329*0Sstevel@tonic-gate cmn_err(CE_PANIC, "cnopen: cloned open"); 330*0Sstevel@tonic-gate } 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gate rconsopen++; 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate return (0); 335*0Sstevel@tonic-gate } 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gate /* ARGSUSED */ 338*0Sstevel@tonic-gate static int 339*0Sstevel@tonic-gate cnclose(dev_t dev, int flag, int state, struct cred *cred) 340*0Sstevel@tonic-gate { 341*0Sstevel@tonic-gate int err = 0; 342*0Sstevel@tonic-gate vnode_t *vp; 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate /* 345*0Sstevel@tonic-gate * Since this is the _last_ close, it's our last chance to close the 346*0Sstevel@tonic-gate * underlying device. (Note that if someone else has the underlying 347*0Sstevel@tonic-gate * hardware console device open, we won't get here, since spec_close 348*0Sstevel@tonic-gate * will see s_count > 1.) 349*0Sstevel@tonic-gate */ 350*0Sstevel@tonic-gate if (state != OTYP_CHR) 351*0Sstevel@tonic-gate return (ENXIO); 352*0Sstevel@tonic-gate 353*0Sstevel@tonic-gate if (rconsvp == NULL) 354*0Sstevel@tonic-gate return (0); 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gate while ((rconsopen != 0) && ((vp = rconsvp) != NULL)) { 357*0Sstevel@tonic-gate err = VOP_CLOSE(vp, flag, 1, (offset_t)0, cred); 358*0Sstevel@tonic-gate if (!err) { 359*0Sstevel@tonic-gate vp->v_stream = NULL; 360*0Sstevel@tonic-gate rconsopen--; 361*0Sstevel@tonic-gate } 362*0Sstevel@tonic-gate } 363*0Sstevel@tonic-gate return (err); 364*0Sstevel@tonic-gate } 365*0Sstevel@tonic-gate 366*0Sstevel@tonic-gate /* ARGSUSED */ 367*0Sstevel@tonic-gate static int 368*0Sstevel@tonic-gate cnread(dev_t dev, struct uio *uio, struct cred *cred) 369*0Sstevel@tonic-gate { 370*0Sstevel@tonic-gate kcondvar_t sleep_forever; 371*0Sstevel@tonic-gate kmutex_t sleep_forever_mutex; 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate if (rconsvp == NULL) { 374*0Sstevel@tonic-gate /* 375*0Sstevel@tonic-gate * Go to sleep forever. This seems like the least 376*0Sstevel@tonic-gate * harmful thing to do if there's no console. 377*0Sstevel@tonic-gate * EOF might be better if we're ending up single-user 378*0Sstevel@tonic-gate * mode. 379*0Sstevel@tonic-gate */ 380*0Sstevel@tonic-gate cv_init(&sleep_forever, NULL, CV_DRIVER, NULL); 381*0Sstevel@tonic-gate mutex_init(&sleep_forever_mutex, NULL, MUTEX_DRIVER, NULL); 382*0Sstevel@tonic-gate mutex_enter(&sleep_forever_mutex); 383*0Sstevel@tonic-gate (void) cv_wait_sig(&sleep_forever, &sleep_forever_mutex); 384*0Sstevel@tonic-gate mutex_exit(&sleep_forever_mutex); 385*0Sstevel@tonic-gate return (EIO); 386*0Sstevel@tonic-gate } 387*0Sstevel@tonic-gate 388*0Sstevel@tonic-gate if (rconsvp->v_stream != NULL) 389*0Sstevel@tonic-gate return (strread(rconsvp, uio, cred)); 390*0Sstevel@tonic-gate else 391*0Sstevel@tonic-gate return (cdev_read(rconsdev, uio, cred)); 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate /* ARGSUSED */ 395*0Sstevel@tonic-gate static int 396*0Sstevel@tonic-gate cnwrite(dev_t dev, struct uio *uio, struct cred *cred) 397*0Sstevel@tonic-gate { 398*0Sstevel@tonic-gate if (rconsvp == NULL) { 399*0Sstevel@tonic-gate uio->uio_resid = 0; 400*0Sstevel@tonic-gate return (0); 401*0Sstevel@tonic-gate } 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate if (rconsvp->v_stream != NULL) 404*0Sstevel@tonic-gate return (strwrite(rconsvp, uio, cred)); 405*0Sstevel@tonic-gate else 406*0Sstevel@tonic-gate return (cdev_write(rconsdev, uio, cred)); 407*0Sstevel@tonic-gate } 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gate /* ARGSUSED */ 410*0Sstevel@tonic-gate static int 411*0Sstevel@tonic-gate cnioctl(dev_t dev, int cmd, intptr_t arg, int flag, struct cred *cred, 412*0Sstevel@tonic-gate int *rvalp) 413*0Sstevel@tonic-gate { 414*0Sstevel@tonic-gate if (rconsvp == NULL) 415*0Sstevel@tonic-gate return (0); 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gate if (rconsvp->v_stream != NULL) 418*0Sstevel@tonic-gate return (strioctl(rconsvp, cmd, arg, flag, U_TO_K, cred, 419*0Sstevel@tonic-gate rvalp)); 420*0Sstevel@tonic-gate else 421*0Sstevel@tonic-gate return (cdev_ioctl(rconsdev, cmd, arg, flag, cred, rvalp)); 422*0Sstevel@tonic-gate } 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate /* ARGSUSED */ 425*0Sstevel@tonic-gate static int 426*0Sstevel@tonic-gate cnpoll(dev_t dev, short events, int anyyet, short *reventsp, 427*0Sstevel@tonic-gate struct pollhead **phpp) 428*0Sstevel@tonic-gate { 429*0Sstevel@tonic-gate if (rconsvp == NULL) 430*0Sstevel@tonic-gate return (nochpoll(dev, events, anyyet, reventsp, phpp)); 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate if (rconsvp->v_stream != NULL) 433*0Sstevel@tonic-gate return (strpoll(rconsvp->v_stream, events, anyyet, reventsp, 434*0Sstevel@tonic-gate phpp)); 435*0Sstevel@tonic-gate else 436*0Sstevel@tonic-gate return (cdev_poll(rconsdev, events, anyyet, reventsp, phpp)); 437*0Sstevel@tonic-gate } 438