4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Portions Copyright 2018 Devin Teske dteske@freebsd.org
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #pragma D depends_on module kernel
29 #pragma D depends_on provider io
31 typedef struct devinfo {
32 int dev_major; /* major number */
33 int dev_minor; /* minor number */
34 int dev_instance; /* instance number */
35 int dev_type; /* type of device */
36 string dev_name; /* name of device */
37 string dev_statname; /* name of device + instance/minor */
38 string dev_pathname; /* pathname of device */
41 #pragma D binding "1.0" translator
42 translator devinfo_t < struct devstat *D > {
43 dev_major = D->device_number;
44 dev_minor = D->unit_number;
46 dev_type = D->device_type;
47 dev_name = stringof(D->device_name);
48 dev_statname = stringof(D->device_name);
49 dev_pathname = stringof(D->device_name);
52 typedef struct bufinfo {
53 int b_cmd; /* I/O operation */
54 int b_flags; /* flags */
55 long b_bcount; /* number of bytes */
56 caddr_t b_addr; /* buffer address */
57 uint64_t b_blkno; /* expanded block # on device */
58 uint64_t b_lblkno; /* block # on device */
59 size_t b_resid; /* # of bytes not transferred */
60 size_t b_bufsize; /* size of allocated buffer */
61 /* caddr_t b_iodone; I/O completion routine */
62 int b_error; /* expanded error field */
63 /* dev_t b_edev; extended device */
66 #pragma D binding "1.0" translator
67 translator bufinfo_t < struct bio *B > {
69 b_flags = B->bio_flags;
70 b_bcount = B->bio_bcount;
74 b_resid = B->bio_resid;
75 b_bufsize = 0; /* XXX gnn */
76 b_error = B->bio_error;
80 * The following inline constants can be used to examine fi_oflags when using
81 * the fds[] array or a translated fileinfo_t. Note that the various open
82 * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
83 * To test the open mode, you write code similar to that used with the fcntl(2)
84 * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
86 inline int O_ACCMODE = 0x0003;
87 #pragma D binding "1.1" O_ACCMODE
89 inline int O_RDONLY = 0x0000;
90 #pragma D binding "1.1" O_RDONLY
91 inline int O_WRONLY = 0x0001;
92 #pragma D binding "1.1" O_WRONLY
93 inline int O_RDWR = 0x0002;
94 #pragma D binding "1.1" O_RDWR
96 inline int O_APPEND = 0x0008;
97 #pragma D binding "1.1" O_APPEND
98 inline int O_CREAT = 0x0200;
99 #pragma D binding "1.1" O_CREAT
100 inline int O_EXCL = 0x0800;
101 #pragma D binding "1.1" O_EXCL
102 inline int O_NOCTTY = 0x8000;
103 #pragma D binding "1.1" O_NOCTTY
104 inline int O_NONBLOCK = 0x0004;
105 #pragma D binding "1.1" O_NONBLOCK
106 inline int O_NDELAY = 0x0004;
107 #pragma D binding "1.1" O_NDELAY
108 inline int O_SYNC = 0x0080;
109 #pragma D binding "1.1" O_SYNC
110 inline int O_TRUNC = 0x0400;
111 #pragma D binding "1.1" O_TRUNC
114 * The following inline constants can be used to examine bio_cmd of struct bio
115 * or a translated bufinfo_t.
117 inline int BIO_READ = 0x01;
118 #pragma D binding "1.13" BIO_READ
119 inline int BIO_WRITE = 0x02;
120 #pragma D binding "1.13" BIO_WRITE
121 inline int BIO_DELETE = 0x03;
122 #pragma D binding "1.13" BIO_DELETE
123 inline int BIO_GETATTR = 0x04;
124 #pragma D binding "1.13" BIO_GETATTR
125 inline int BIO_FLUSH = 0x05;
126 #pragma D binding "1.13" BIO_FLUSH
127 inline int BIO_CMD0 = 0x06;
128 #pragma D binding "1.13" BIO_CMD0
129 inline int BIO_CMD1 = 0x07;
130 #pragma D binding "1.13" BIO_CMD1
131 inline int BIO_CMD2 = 0x08;
132 #pragma D binding "1.13" BIO_CMD2
133 inline int BIO_ZONE = 0x09;
134 #pragma D binding "1.13" BIO_ZONE
137 * The following inline constants can be used to examine bio_flags of struct
138 * bio or a translated bufinfo_t.
140 inline int BIO_ERROR = 0x01;
141 #pragma D binding "1.13" BIO_ERROR
142 inline int BIO_DONE = 0x02;
143 #pragma D binding "1.13" BIO_DONE
144 inline int BIO_ONQUEUE = 0x04;
145 #pragma D binding "1.13" BIO_ONQUEUE
146 inline int BIO_ORDERED = 0x08;
147 #pragma D binding "1.13" BIO_ORDERED
148 inline int BIO_UNMAPPED = 0x10;
149 #pragma D binding "1.13" BIO_UNMAPPED
150 inline int BIO_TRANSIENT_MAPPING = 0x20;
151 #pragma D binding "1.13" BIO_TRANSIENT_MAPPING
152 inline int BIO_VLIST = 0x40;
153 #pragma D binding "1.13" BIO_VLIST
156 * The following inline constants can be used to examine device_type of struct
157 * devstat or a translated devinfo_t.
159 inline int DEVSTAT_TYPE_DIRECT = 0x000;
160 #pragma D binding "1.13" DEVSTAT_TYPE_DIRECT
161 inline int DEVSTAT_TYPE_SEQUENTIAL = 0x001;
162 #pragma D binding "1.13" DEVSTAT_TYPE_SEQUENTIAL
163 inline int DEVSTAT_TYPE_PRINTER = 0x002;
164 #pragma D binding "1.13" DEVSTAT_TYPE_PRINTER
165 inline int DEVSTAT_TYPE_PROCESSOR = 0x003;
166 #pragma D binding "1.13" DEVSTAT_TYPE_PROCESSOR
167 inline int DEVSTAT_TYPE_WORM = 0x004;
168 #pragma D binding "1.13" DEVSTAT_TYPE_WORM
169 inline int DEVSTAT_TYPE_CDROM = 0x005;
170 #pragma D binding "1.13" DEVSTAT_TYPE_CDROM
171 inline int DEVSTAT_TYPE_SCANNER = 0x006;
172 #pragma D binding "1.13" DEVSTAT_TYPE_SCANNER
173 inline int DEVSTAT_TYPE_OPTICAL = 0x007;
174 #pragma D binding "1.13" DEVSTAT_TYPE_OPTICAL
175 inline int DEVSTAT_TYPE_CHANGER = 0x008;
176 #pragma D binding "1.13" DEVSTAT_TYPE_CHANGER
177 inline int DEVSTAT_TYPE_COMM = 0x009;
178 #pragma D binding "1.13" DEVSTAT_TYPE_COMM
179 inline int DEVSTAT_TYPE_ASC0 = 0x00a;
180 #pragma D binding "1.13" DEVSTAT_TYPE_ASC0
181 inline int DEVSTAT_TYPE_ASC1 = 0x00b;
182 #pragma D binding "1.13" DEVSTAT_TYPE_ASC1
183 inline int DEVSTAT_TYPE_STORARRAY = 0x00c;
184 #pragma D binding "1.13" DEVSTAT_TYPE_STORARRAY
185 inline int DEVSTAT_TYPE_ENCLOSURE = 0x00d;
186 #pragma D binding "1.13" DEVSTAT_TYPE_ENCLOSURE
187 inline int DEVSTAT_TYPE_FLOPPY = 0x00e;
188 #pragma D binding "1.13" DEVSTAT_TYPE_FLOPPY
189 inline int DEVSTAT_TYPE_MASK = 0x00f;
190 #pragma D binding "1.13" DEVSTAT_TYPE_MASK
191 inline int DEVSTAT_TYPE_IF_SCSI = 0x010;
192 #pragma D binding "1.13" DEVSTAT_TYPE_IF_SCSI
193 inline int DEVSTAT_TYPE_IF_IDE = 0x020;
194 #pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
195 inline int DEVSTAT_TYPE_IF_OTHER = 0x030;
196 #pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
197 inline int DEVSTAT_TYPE_IF_MASK = 0x0f0;
198 #pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
199 inline int DEVSTAT_TYPE_PASS = 0x100;
200 #pragma D binding "1.13" DEVSTAT_TYPE_PASS
202 #pragma D binding "1.13" device_type_string
203 inline string device_type_string[int type] =
204 type == DEVSTAT_TYPE_DIRECT ? "DIRECT" :
205 type == DEVSTAT_TYPE_SEQUENTIAL ? "SEQUENTIAL" :
206 type == DEVSTAT_TYPE_PRINTER ? "PRINTER" :
207 type == DEVSTAT_TYPE_PROCESSOR ? "PROCESSOR" :
208 type == DEVSTAT_TYPE_WORM ? "WORM" :
209 type == DEVSTAT_TYPE_CDROM ? "CDROM" :
210 type == DEVSTAT_TYPE_SCANNER ? "SCANNER" :
211 type == DEVSTAT_TYPE_OPTICAL ? "OPTICAL" :
212 type == DEVSTAT_TYPE_CHANGER ? "CHANGER" :
213 type == DEVSTAT_TYPE_COMM ? "COMM" :
214 type == DEVSTAT_TYPE_ASC0 ? "ASC0" :
215 type == DEVSTAT_TYPE_ASC1 ? "ASC1" :
216 type == DEVSTAT_TYPE_STORARRAY ? "STORARRAY" :
217 type == DEVSTAT_TYPE_ENCLOSURE ? "ENCLOSURE" :
218 type == DEVSTAT_TYPE_FLOPPY ? "FLOPPY" :
219 strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
221 #pragma D binding "1.13" device_type
222 inline string device_type[int type] =
223 device_type_string[type & DEVSTAT_TYPE_MASK];
225 #pragma D binding "1.13" device_if_string
226 inline string device_if_string[int type] =
227 type == 0 ? "ACCESS" :
228 type == DEVSTAT_TYPE_IF_SCSI ? "SCSI" :
229 type == DEVSTAT_TYPE_IF_IDE ? "IDE" :
230 type == DEVSTAT_TYPE_IF_OTHER ? "OTHER" :
231 strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
233 #pragma D binding "1.13" device_if
234 inline string device_if[int type] =
235 device_if_string[type & DEVSTAT_TYPE_IF_MASK];
237 #pragma D binding "1.13" bio_cmd_string
238 inline string bio_cmd_string[int cmd] =
239 cmd == BIO_READ ? "READ" :
240 cmd == BIO_WRITE ? "WRITE" :
241 cmd == BIO_DELETE ? "DELETE" :
242 cmd == BIO_GETATTR ? "GETATTR" :
243 cmd == BIO_FLUSH ? "FLUSH" :
244 cmd == BIO_CMD0 ? "CMD0" :
245 cmd == BIO_CMD1 ? "CMD1" :
246 cmd == BIO_CMD2 ? "CMD2" :
247 cmd == BIO_ZONE ? "ZONE" :
248 strjoin("UNKNOWN(", strjoin(lltostr(cmd), ")"));
250 #pragma D binding "1.13" bio_flag_string
251 inline string bio_flag_string[int flag] =
252 flag == BIO_ERROR ? "ERROR" :
253 flag == BIO_DONE ? "DONE" :
254 flag == BIO_ONQUEUE ? "ONQUEUE" :
255 flag == BIO_ORDERED ? "ORDERED" :
256 flag == BIO_UNMAPPED ? "UNMAPPED" :
257 flag == BIO_TRANSIENT_MAPPING ? "TRANSIENT_MAPPING" :
258 flag == BIO_VLIST ? "VLIST" :