7054 dmu_tx_hold_t should use refcount_t to track space
[unleashed.git] / usr / src / uts / common / ktli / t_kgtstate.c
blobd3413c0e002afe2aa934cc9649f8aefe7acf0597
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * Kernel TLI-like function to get the state of an
44 * endpoint.
46 * Returns:
47 * 0 on success and "state" is set to the current state,
48 * or a positive error code.
51 #include <sys/param.h>
52 #include <sys/types.h>
53 #include <sys/proc.h>
54 #include <sys/file.h>
55 #include <sys/user.h>
56 #include <sys/vnode.h>
57 #include <sys/errno.h>
58 #include <sys/stream.h>
59 #include <sys/ioctl.h>
60 #include <sys/stropts.h>
61 #include <sys/strsubr.h>
62 #include <sys/tihdr.h>
63 #include <sys/timod.h>
64 #include <sys/tiuser.h>
65 #include <sys/t_kuser.h>
68 int
69 t_kgetstate(TIUSER *tiptr, int *state)
71 struct T_info_ack inforeq;
72 struct strioctl strioc;
73 int retval;
74 vnode_t *vp;
75 file_t *fp;
76 int error;
78 error = 0;
79 retval = 0;
80 fp = tiptr->fp;
81 vp = fp->f_vnode;
83 if (state == NULL)
84 return (EINVAL);
86 inforeq.PRIM_type = T_INFO_REQ;
87 strioc.ic_cmd = TI_GETINFO;
88 strioc.ic_timout = 0;
89 strioc.ic_dp = (char *)&inforeq;
90 strioc.ic_len = (int)sizeof (struct T_info_req);
92 error = strdoioctl(vp->v_stream, &strioc, FNATIVE, K_TO_K, CRED(),
93 &retval);
94 if (error)
95 return (error);
97 if (retval) {
98 if ((retval & 0xff) == TSYSERR)
99 error = (retval >> 8) & 0xff;
100 else
101 error = t_tlitosyserr(retval & 0xff);
102 return (error);
105 if (strioc.ic_len != sizeof (struct T_info_ack))
106 return (EPROTO);
108 switch (inforeq.CURRENT_state) {
109 case TS_UNBND:
110 *state = T_UNBND;
111 break;
113 case TS_IDLE:
114 *state = T_IDLE;
115 break;
117 case TS_WRES_CIND:
118 *state = T_INCON;
119 break;
121 case TS_WCON_CREQ:
122 *state = T_OUTCON;
123 break;
125 case TS_DATA_XFER:
126 *state = T_DATAXFER;
127 break;
129 case TS_WIND_ORDREL:
130 *state = T_OUTREL;
131 break;
133 case TS_WREQ_ORDREL:
134 *state = T_INREL;
135 break;
137 default:
138 error = EPROTO;
139 break;
141 return (error);