xref: /freebsd/cddl/lib/libdtrace/io.d (revision c697fb7f)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  *
21  * Portions Copyright 2018 Devin Teske dteske@freebsd.org
22  *
23  * $FreeBSD$
24  */
25 /*
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #pragma D depends_on module kernel
31 #pragma D depends_on provider io
32 
33 typedef struct devinfo {
34 	int dev_major;			/* major number */
35 	int dev_minor;			/* minor number */
36 	int dev_instance;		/* instance number */
37 	int dev_type;			/* type of device */
38 	string dev_name;		/* name of device */
39 	string dev_statname;		/* name of device + instance/minor */
40 	string dev_pathname;		/* pathname of device */
41 } devinfo_t;
42 
43 #pragma D binding "1.0" translator
44 translator devinfo_t < struct devstat *D > {
45 	dev_major = D->device_number;
46 	dev_minor = D->unit_number;
47 	dev_instance = 0;
48 	dev_type = D->device_type;
49 	dev_name = stringof(D->device_name);
50 	dev_statname = stringof(D->device_name);
51 	dev_pathname = stringof(D->device_name);
52 };
53 
54 typedef struct bufinfo {
55 	int b_cmd;			/* I/O operation */
56 	int b_flags;			/* flags */
57 	long b_bcount;			/* number of bytes */
58 	caddr_t b_addr;			/* buffer address */
59 	uint64_t b_blkno;		/* expanded block # on device */
60 	uint64_t b_lblkno;		/* block # on device */
61 	size_t b_resid;			/* # of bytes not transferred */
62 	size_t b_bufsize;		/* size of allocated buffer */
63 /*	caddr_t b_iodone;		I/O completion routine */
64 	int b_error;			/* expanded error field */
65 /*	dev_t b_edev;			extended device */
66 } bufinfo_t;
67 
68 #pragma D binding "1.0" translator
69 translator bufinfo_t < struct bio *B > {
70 	b_cmd = B->bio_cmd;
71 	b_flags = B->bio_flags;
72 	b_bcount = B->bio_bcount;
73 	b_addr = B->bio_data;
74 	b_blkno = 0;
75 	b_lblkno = 0;
76 	b_resid = B->bio_resid;
77 	b_bufsize = 0; /* XXX gnn */
78 	b_error = B->bio_error;
79 };
80 
81 /*
82  * The following inline constants can be used to examine fi_oflags when using
83  * the fds[] array or a translated fileinfo_t.  Note that the various open
84  * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
85  * To test the open mode, you write code similar to that used with the fcntl(2)
86  * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
87  */
88 inline int O_ACCMODE = 0x0003;
89 #pragma D binding "1.1" O_ACCMODE
90 
91 inline int O_RDONLY = 0x0000;
92 #pragma D binding "1.1" O_RDONLY
93 inline int O_WRONLY = 0x0001;
94 #pragma D binding "1.1" O_WRONLY
95 inline int O_RDWR = 0x0002;
96 #pragma D binding "1.1" O_RDWR
97 
98 inline int O_APPEND = 0x0008;
99 #pragma D binding "1.1" O_APPEND
100 inline int O_CREAT = 0x0200;
101 #pragma D binding "1.1" O_CREAT
102 inline int O_EXCL = 0x0800;
103 #pragma D binding "1.1" O_EXCL
104 inline int O_NOCTTY = 0x8000;
105 #pragma D binding "1.1" O_NOCTTY
106 inline int O_NONBLOCK = 0x0004;
107 #pragma D binding "1.1" O_NONBLOCK
108 inline int O_NDELAY = 0x0004;
109 #pragma D binding "1.1" O_NDELAY
110 inline int O_SYNC = 0x0080;
111 #pragma D binding "1.1" O_SYNC
112 inline int O_TRUNC = 0x0400;
113 #pragma D binding "1.1" O_TRUNC
114 
115 /*
116  * The following inline constants can be used to examine bio_cmd of struct bio
117  * or a translated bufinfo_t.
118  */
119 inline int BIO_READ =		0x01;
120 #pragma D binding "1.13" BIO_READ
121 inline int BIO_WRITE =		0x02;
122 #pragma D binding "1.13" BIO_WRITE
123 inline int BIO_DELETE =		0x03;
124 #pragma D binding "1.13" BIO_DELETE
125 inline int BIO_GETATTR =	0x04;
126 #pragma D binding "1.13" BIO_GETATTR
127 inline int BIO_FLUSH =		0x05;
128 #pragma D binding "1.13" BIO_FLUSH
129 inline int BIO_CMD0 =		0x06;
130 #pragma D binding "1.13" BIO_CMD0
131 inline int BIO_CMD1 =		0x07;
132 #pragma D binding "1.13" BIO_CMD1
133 inline int BIO_CMD2 =		0x08;
134 #pragma D binding "1.13" BIO_CMD2
135 inline int BIO_ZONE =		0x09;
136 #pragma D binding "1.13" BIO_ZONE
137 
138 /*
139  * The following inline constants can be used to examine bio_flags of struct
140  * bio or a translated bufinfo_t.
141  */
142 inline int BIO_ERROR =			0x01;
143 #pragma D binding "1.13" BIO_ERROR
144 inline int BIO_DONE =			0x02;
145 #pragma D binding "1.13" BIO_DONE
146 inline int BIO_ONQUEUE =		0x04;
147 #pragma D binding "1.13" BIO_ONQUEUE
148 inline int BIO_ORDERED =		0x08;
149 #pragma D binding "1.13" BIO_ORDERED
150 inline int BIO_UNMAPPED =		0x10;
151 #pragma D binding "1.13" BIO_UNMAPPED
152 inline int BIO_TRANSIENT_MAPPING =	0x20;
153 #pragma D binding "1.13" BIO_TRANSIENT_MAPPING
154 inline int BIO_VLIST =			0x40;
155 #pragma D binding "1.13" BIO_VLIST
156 
157 /*
158  * The following inline constants can be used to examine device_type of struct
159  * devstat or a translated devinfo_t.
160  */
161 inline int DEVSTAT_TYPE_DIRECT =	0x000;
162 #pragma D binding "1.13" DEVSTAT_TYPE_DIRECT
163 inline int DEVSTAT_TYPE_SEQUENTIAL =	0x001;
164 #pragma D binding "1.13" DEVSTAT_TYPE_SEQUENTIAL
165 inline int DEVSTAT_TYPE_PRINTER =	0x002;
166 #pragma D binding "1.13" DEVSTAT_TYPE_PRINTER
167 inline int DEVSTAT_TYPE_PROCESSOR =	0x003;
168 #pragma D binding "1.13" DEVSTAT_TYPE_PROCESSOR
169 inline int DEVSTAT_TYPE_WORM =		0x004;
170 #pragma D binding "1.13" DEVSTAT_TYPE_WORM
171 inline int DEVSTAT_TYPE_CDROM =		0x005;
172 #pragma D binding "1.13" DEVSTAT_TYPE_CDROM
173 inline int DEVSTAT_TYPE_SCANNER =	0x006;
174 #pragma D binding "1.13" DEVSTAT_TYPE_SCANNER
175 inline int DEVSTAT_TYPE_OPTICAL =	0x007;
176 #pragma D binding "1.13" DEVSTAT_TYPE_OPTICAL
177 inline int DEVSTAT_TYPE_CHANGER =	0x008;
178 #pragma D binding "1.13" DEVSTAT_TYPE_CHANGER
179 inline int DEVSTAT_TYPE_COMM =		0x009;
180 #pragma D binding "1.13" DEVSTAT_TYPE_COMM
181 inline int DEVSTAT_TYPE_ASC0 =		0x00a;
182 #pragma D binding "1.13" DEVSTAT_TYPE_ASC0
183 inline int DEVSTAT_TYPE_ASC1 =		0x00b;
184 #pragma D binding "1.13" DEVSTAT_TYPE_ASC1
185 inline int DEVSTAT_TYPE_STORARRAY =	0x00c;
186 #pragma D binding "1.13" DEVSTAT_TYPE_STORARRAY
187 inline int DEVSTAT_TYPE_ENCLOSURE =	0x00d;
188 #pragma D binding "1.13" DEVSTAT_TYPE_ENCLOSURE
189 inline int DEVSTAT_TYPE_FLOPPY =	0x00e;
190 #pragma D binding "1.13" DEVSTAT_TYPE_FLOPPY
191 inline int DEVSTAT_TYPE_MASK =		0x00f;
192 #pragma D binding "1.13" DEVSTAT_TYPE_MASK
193 inline int DEVSTAT_TYPE_IF_SCSI =	0x010;
194 #pragma D binding "1.13" DEVSTAT_TYPE_IF_SCSI
195 inline int DEVSTAT_TYPE_IF_IDE =	0x020;
196 #pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
197 inline int DEVSTAT_TYPE_IF_OTHER =	0x030;
198 #pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
199 inline int DEVSTAT_TYPE_IF_MASK =	0x0f0;
200 #pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
201 inline int DEVSTAT_TYPE_PASS =		0x100;
202 #pragma D binding "1.13" DEVSTAT_TYPE_PASS
203 
204 #pragma D binding "1.13" device_type_string
205 inline string device_type_string[int type] =
206 	type == DEVSTAT_TYPE_DIRECT ?		"DIRECT" :
207 	type == DEVSTAT_TYPE_SEQUENTIAL ?	"SEQUENTIAL" :
208 	type == DEVSTAT_TYPE_PRINTER ?		"PRINTER" :
209 	type == DEVSTAT_TYPE_PROCESSOR ?	"PROCESSOR" :
210 	type == DEVSTAT_TYPE_WORM ?		"WORM" :
211 	type == DEVSTAT_TYPE_CDROM ?		"CDROM" :
212 	type == DEVSTAT_TYPE_SCANNER ?		"SCANNER" :
213 	type == DEVSTAT_TYPE_OPTICAL ?		"OPTICAL" :
214 	type == DEVSTAT_TYPE_CHANGER ?		"CHANGER" :
215 	type == DEVSTAT_TYPE_COMM ?		"COMM" :
216 	type == DEVSTAT_TYPE_ASC0 ?		"ASC0" :
217 	type == DEVSTAT_TYPE_ASC1 ?		"ASC1" :
218 	type == DEVSTAT_TYPE_STORARRAY ?	"STORARRAY" :
219 	type == DEVSTAT_TYPE_ENCLOSURE ?	"ENCLOSURE" :
220 	type == DEVSTAT_TYPE_FLOPPY ?		"FLOPPY" :
221 	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
222 
223 #pragma D binding "1.13" device_type
224 inline string device_type[int type] =
225 	device_type_string[type & DEVSTAT_TYPE_MASK];
226 
227 #pragma D binding "1.13" device_if_string
228 inline string device_if_string[int type] =
229 	type == 0 ?			"ACCESS" :
230 	type == DEVSTAT_TYPE_IF_SCSI ?	"SCSI" :
231 	type == DEVSTAT_TYPE_IF_IDE ?	"IDE" :
232 	type == DEVSTAT_TYPE_IF_OTHER ?	"OTHER" :
233 	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
234 
235 #pragma D binding "1.13" device_if
236 inline string device_if[int type] =
237 	device_if_string[type & DEVSTAT_TYPE_IF_MASK];
238 
239 #pragma D binding "1.13" bio_cmd_string
240 inline string bio_cmd_string[int cmd] =
241 	cmd == BIO_READ ?	"READ" :
242 	cmd == BIO_WRITE ?	"WRITE" :
243 	cmd == BIO_DELETE ?	"DELETE" :
244 	cmd == BIO_GETATTR ?	"GETATTR" :
245 	cmd == BIO_FLUSH ?	"FLUSH" :
246 	cmd == BIO_CMD0 ?	"CMD0" :
247 	cmd == BIO_CMD1 ?	"CMD1" :
248 	cmd == BIO_CMD2 ?	"CMD2" :
249 	cmd == BIO_ZONE ?	"ZONE" :
250 	strjoin("UNKNOWN(", strjoin(lltostr(cmd), ")"));
251 
252 #pragma D binding "1.13" bio_flag_string
253 inline string bio_flag_string[int flag] =
254 	flag == BIO_ERROR ?		"ERROR" :
255 	flag == BIO_DONE ?		"DONE" :
256 	flag == BIO_ONQUEUE ?		"ONQUEUE" :
257 	flag == BIO_ORDERED ?		"ORDERED" :
258 	flag == BIO_UNMAPPED ?		"UNMAPPED" :
259 	flag == BIO_TRANSIENT_MAPPING ?	"TRANSIENT_MAPPING" :
260 	flag == BIO_VLIST ?		"VLIST" :
261 	"";
262