1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1990-1998 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_STRREDIR_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_STRREDIR_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * strredir.h: Declarations for the redirection driver and its matching 38*7c478bd9Sstevel@tonic-gate * STREAMS module. 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* 42*7c478bd9Sstevel@tonic-gate * The module's module id. 43*7c478bd9Sstevel@tonic-gate * 44*7c478bd9Sstevel@tonic-gate * XXX: Since there's no authority responsible for administering this name 45*7c478bd9Sstevel@tonic-gate * space, there's no guarantee that this value is unique. That wouldn't 46*7c478bd9Sstevel@tonic-gate * be so bad except that the DKI now suggests that ioctl cookie values 47*7c478bd9Sstevel@tonic-gate * should be based on module id to make them unique... 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate #define _STRREDIR_MODID 7326 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * Redirection ioctls: 53*7c478bd9Sstevel@tonic-gate */ 54*7c478bd9Sstevel@tonic-gate #define SRIOCSREDIR ((_STRREDIR_MODID<<16) | 1) /* set redir target */ 55*7c478bd9Sstevel@tonic-gate #define SRIOCISREDIR ((_STRREDIR_MODID<<16) | 2) /* is redir target? */ 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Everything from here on is of interest only to the kernel. 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 64*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 65*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* 68*7c478bd9Sstevel@tonic-gate * Per-open instance driver state information. 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * The underlying device potentially can be opened through (at least) two 71*7c478bd9Sstevel@tonic-gate * paths: through this driver and through the underlying device's driver. To 72*7c478bd9Sstevel@tonic-gate * ensure that reference counts are meaningful and therefore that close 73*7c478bd9Sstevel@tonic-gate * routines are called at the right time, it's important to make sure that the 74*7c478bd9Sstevel@tonic-gate * snode for the underlying device instance never has a contribution of more 75*7c478bd9Sstevel@tonic-gate * than one through this driver, regardless of how many times this driver's 76*7c478bd9Sstevel@tonic-gate * been opened. The wd_wsconsopen field keeps track of the necessary 77*7c478bd9Sstevel@tonic-gate * information to ensure this property. 78*7c478bd9Sstevel@tonic-gate * 79*7c478bd9Sstevel@tonic-gate * The structure also contains copies of the flag and cred values supplied 80*7c478bd9Sstevel@tonic-gate * when the device instance was first opened, so that it's possible to reopen 81*7c478bd9Sstevel@tonic-gate * the underlying device in srreset. 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate typedef struct wcd_data { 84*7c478bd9Sstevel@tonic-gate struct wcd_data *wd_next; /* link to next open instance */ 85*7c478bd9Sstevel@tonic-gate minor_t wd_unit; /* minor device # for this instance */ 86*7c478bd9Sstevel@tonic-gate struct wcrlist *wd_list; /* the head of the redirection list */ 87*7c478bd9Sstevel@tonic-gate vnode_t *wd_vp; /* underlying device instance vnode */ 88*7c478bd9Sstevel@tonic-gate int wd_wsconsopen; /* see above */ 89*7c478bd9Sstevel@tonic-gate int wd_flag; /* see above */ 90*7c478bd9Sstevel@tonic-gate cred_t *wd_cred; /* see above */ 91*7c478bd9Sstevel@tonic-gate } wcd_data_t; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate /* 94*7c478bd9Sstevel@tonic-gate * Per-open instance module state information. 95*7c478bd9Sstevel@tonic-gate * 96*7c478bd9Sstevel@tonic-gate * An invariant: when wm_wd is non-NULL, wm_entry is also non-NULL and is on 97*7c478bd9Sstevel@tonic-gate * the list rooted at wm_wd->wd_list. 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate typedef struct wcm_data { 100*7c478bd9Sstevel@tonic-gate struct wcd_data *wm_wd; /* Xref to redir driver data */ 101*7c478bd9Sstevel@tonic-gate struct wcrlist *wm_entry; /* Redir entry that refers to us */ 102*7c478bd9Sstevel@tonic-gate } wcm_data_t; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* 105*7c478bd9Sstevel@tonic-gate * We record the list of redirections as a linked list of wcrlist 106*7c478bd9Sstevel@tonic-gate * structures. 107*7c478bd9Sstevel@tonic-gate * 108*7c478bd9Sstevel@tonic-gate * We need to keep track of: 109*7c478bd9Sstevel@tonic-gate * 1) The target's vp, so that we can vector reads, writes, etc. off to the 110*7c478bd9Sstevel@tonic-gate * current designee. 111*7c478bd9Sstevel@tonic-gate * 2) The per-open instance private data structure of the redirmod module 112*7c478bd9Sstevel@tonic-gate * instance we push onto the target stream, so that we can clean up there 113*7c478bd9Sstevel@tonic-gate * when we go away. (I'm not sure that this is actually necessary.) 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate typedef struct wcrlist { 116*7c478bd9Sstevel@tonic-gate struct wcrlist *wl_next; /* next entry */ 117*7c478bd9Sstevel@tonic-gate vnode_t *wl_vp; /* target's vnode */ 118*7c478bd9Sstevel@tonic-gate struct wcm_data *wl_data; /* target's redirmod private data */ 119*7c478bd9Sstevel@tonic-gate } wcrlist_t; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * A given instance of the redirection driver must be able to open the 123*7c478bd9Sstevel@tonic-gate * corresponding instance of the underlying device when the redirection list 124*7c478bd9Sstevel@tonic-gate * empties. To do so it needs a vnode for the underlying instance. The 125*7c478bd9Sstevel@tonic-gate * underlying driver is responsible for supplying routines for producing and 126*7c478bd9Sstevel@tonic-gate * disposing of this vnode. The get routine must return a held vnode, so that 127*7c478bd9Sstevel@tonic-gate * it can't vanish while the redirecting driver is using it. 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate typedef struct srvnops { 130*7c478bd9Sstevel@tonic-gate int (*svn_get)(); /* (minor #, vpp) --> errno value */ 131*7c478bd9Sstevel@tonic-gate void (*svn_rele)(); /* (minor #, vp) */ 132*7c478bd9Sstevel@tonic-gate } srvnops_t; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate extern void srpop(wcm_data_t *, int, cred_t *); 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 139*7c478bd9Sstevel@tonic-gate } 140*7c478bd9Sstevel@tonic-gate #endif 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate #endif /* _SYS_STRREDIR_H */ 143