aboutsummaryrefslogtreecommitdiff
path: root/cddl/lib/libdtrace/io.d
blob: d643ad732a94ae8aa1ab380b643d7a31b765754d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 * Portions Copyright 2018 Devin Teske dteske@freebsd.org
 *
 * $FreeBSD$
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma D depends_on module kernel
#pragma D depends_on provider io

typedef struct devinfo {
	int dev_major;			/* major number */
	int dev_minor;			/* minor number */
	int dev_instance;		/* instance number */
	int dev_type;			/* type of device */
	string dev_name;		/* name of device */
	string dev_statname;		/* name of device + instance/minor */
	string dev_pathname;		/* pathname of device */
} devinfo_t;

#pragma D binding "1.0" translator
translator devinfo_t < struct devstat *D > {
	dev_major = D->device_number;
	dev_minor = D->unit_number;
	dev_instance = 0;
	dev_type = D->device_type;
	dev_name = stringof(D->device_name);
	dev_statname = stringof(D->device_name);
	dev_pathname = stringof(D->device_name);
};

typedef struct bufinfo {
	int b_cmd;			/* I/O operation */
	int b_flags;			/* flags */
	long b_bcount;			/* number of bytes */
	caddr_t b_addr;			/* buffer address */
	uint64_t b_blkno;		/* expanded block # on device */
	uint64_t b_lblkno;		/* block # on device */
	size_t b_resid;			/* # of bytes not transferred */
	size_t b_bufsize;		/* size of allocated buffer */
/*	caddr_t b_iodone;		I/O completion routine */
	int b_error;			/* expanded error field */
/*	dev_t b_edev;			extended device */
} bufinfo_t;

#pragma D binding "1.0" translator
translator bufinfo_t < struct bio *B > {
	b_cmd = B->bio_cmd;
	b_flags = B->bio_flags;
	b_bcount = B->bio_bcount;
	b_addr = B->bio_data;
	b_blkno = 0;
	b_lblkno = 0;
	b_resid = B->bio_resid;
	b_bufsize = 0; /* XXX gnn */
	b_error = B->bio_error;
};

/*
 * The following inline constants can be used to examine fi_oflags when using
 * the fds[] array or a translated fileinfo_t.  Note that the various open
 * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
 * To test the open mode, you write code similar to that used with the fcntl(2)
 * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
 */
inline int O_ACCMODE = 0x0003;
#pragma D binding "1.1" O_ACCMODE

inline int O_RDONLY = 0x0000;
#pragma D binding "1.1" O_RDONLY
inline int O_WRONLY = 0x0001;
#pragma D binding "1.1" O_WRONLY
inline int O_RDWR = 0x0002;
#pragma D binding "1.1" O_RDWR

inline int O_APPEND = 0x0008;
#pragma D binding "1.1" O_APPEND
inline int O_CREAT = 0x0200;
#pragma D binding "1.1" O_CREAT
inline int O_EXCL = 0x0800;
#pragma D binding "1.1" O_EXCL
inline int O_NOCTTY = 0x8000;
#pragma D binding "1.1" O_NOCTTY
inline int O_NONBLOCK = 0x0004;
#pragma D binding "1.1" O_NONBLOCK
inline int O_NDELAY = 0x0004;
#pragma D binding "1.1" O_NDELAY
inline int O_SYNC = 0x0080;
#pragma D binding "1.1" O_SYNC
inline int O_TRUNC = 0x0400;
#pragma D binding "1.1" O_TRUNC

/*
 * The following inline constants can be used to examine bio_cmd of struct bio
 * or a translated bufinfo_t.
 */
inline int BIO_READ =		0x01;
#pragma D binding "1.13" BIO_READ
inline int BIO_WRITE =		0x02;
#pragma D binding "1.13" BIO_WRITE
inline int BIO_DELETE =		0x03;
#pragma D binding "1.13" BIO_DELETE
inline int BIO_GETATTR =	0x04;
#pragma D binding "1.13" BIO_GETATTR
inline int BIO_FLUSH =		0x05;
#pragma D binding "1.13" BIO_FLUSH
inline int BIO_CMD0 =		0x06;
#pragma D binding "1.13" BIO_CMD0
inline int BIO_CMD1 =		0x07;
#pragma D binding "1.13" BIO_CMD1
inline int BIO_CMD2 =		0x08;
#pragma D binding "1.13" BIO_CMD2
inline int BIO_ZONE =		0x09;
#pragma D binding "1.13" BIO_ZONE

/*
 * The following inline constants can be used to examine bio_flags of struct
 * bio or a translated bufinfo_t.
 */
inline int BIO_ERROR =			0x01;
#pragma D binding "1.13" BIO_ERROR
inline int BIO_DONE =			0x02;
#pragma D binding "1.13" BIO_DONE
inline int BIO_ONQUEUE =		0x04;
#pragma D binding "1.13" BIO_ONQUEUE
inline int BIO_ORDERED =		0x08;
#pragma D binding "1.13" BIO_ORDERED
inline int BIO_UNMAPPED =		0x10;
#pragma D binding "1.13" BIO_UNMAPPED
inline int BIO_TRANSIENT_MAPPING =	0x20;
#pragma D binding "1.13" BIO_TRANSIENT_MAPPING
inline int BIO_VLIST =			0x40;
#pragma D binding "1.13" BIO_VLIST

/*
 * The following inline constants can be used to examine device_type of struct
 * devstat or a translated devinfo_t.
 */
inline int DEVSTAT_TYPE_DIRECT =	0x000;
#pragma D binding "1.13" DEVSTAT_TYPE_DIRECT
inline int DEVSTAT_TYPE_SEQUENTIAL =	0x001;
#pragma D binding "1.13" DEVSTAT_TYPE_SEQUENTIAL
inline int DEVSTAT_TYPE_PRINTER =	0x002;
#pragma D binding "1.13" DEVSTAT_TYPE_PRINTER
inline int DEVSTAT_TYPE_PROCESSOR =	0x003;
#pragma D binding "1.13" DEVSTAT_TYPE_PROCESSOR
inline int DEVSTAT_TYPE_WORM =		0x004;
#pragma D binding "1.13" DEVSTAT_TYPE_WORM
inline int DEVSTAT_TYPE_CDROM =		0x005;
#pragma D binding "1.13" DEVSTAT_TYPE_CDROM
inline int DEVSTAT_TYPE_SCANNER =	0x006;
#pragma D binding "1.13" DEVSTAT_TYPE_SCANNER
inline int DEVSTAT_TYPE_OPTICAL =	0x007;
#pragma D binding "1.13" DEVSTAT_TYPE_OPTICAL
inline int DEVSTAT_TYPE_CHANGER =	0x008;
#pragma D binding "1.13" DEVSTAT_TYPE_CHANGER
inline int DEVSTAT_TYPE_COMM =		0x009;
#pragma D binding "1.13" DEVSTAT_TYPE_COMM
inline int DEVSTAT_TYPE_ASC0 =		0x00a;
#pragma D binding "1.13" DEVSTAT_TYPE_ASC0
inline int DEVSTAT_TYPE_ASC1 =		0x00b;
#pragma D binding "1.13" DEVSTAT_TYPE_ASC1
inline int DEVSTAT_TYPE_STORARRAY =	0x00c;
#pragma D binding "1.13" DEVSTAT_TYPE_STORARRAY
inline int DEVSTAT_TYPE_ENCLOSURE =	0x00d;
#pragma D binding "1.13" DEVSTAT_TYPE_ENCLOSURE
inline int DEVSTAT_TYPE_FLOPPY =	0x00e;
#pragma D binding "1.13" DEVSTAT_TYPE_FLOPPY
inline int DEVSTAT_TYPE_MASK =		0x00f;
#pragma D binding "1.13" DEVSTAT_TYPE_MASK
inline int DEVSTAT_TYPE_IF_SCSI =	0x010;
#pragma D binding "1.13" DEVSTAT_TYPE_IF_SCSI
inline int DEVSTAT_TYPE_IF_IDE =	0x020;
#pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
inline int DEVSTAT_TYPE_IF_OTHER =	0x030;
#pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
inline int DEVSTAT_TYPE_IF_MASK =	0x0f0;
#pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
inline int DEVSTAT_TYPE_PASS =		0x100;
#pragma D binding "1.13" DEVSTAT_TYPE_PASS

#pragma D binding "1.13" device_type_string
inline string device_type_string[int type] =
	type == DEVSTAT_TYPE_DIRECT ?		"DIRECT" :
	type == DEVSTAT_TYPE_SEQUENTIAL ?	"SEQUENTIAL" :
	type == DEVSTAT_TYPE_PRINTER ?		"PRINTER" :
	type == DEVSTAT_TYPE_PROCESSOR ?	"PROCESSOR" :
	type == DEVSTAT_TYPE_WORM ?		"WORM" :
	type == DEVSTAT_TYPE_CDROM ?		"CDROM" :
	type == DEVSTAT_TYPE_SCANNER ?		"SCANNER" :
	type == DEVSTAT_TYPE_OPTICAL ?		"OPTICAL" :
	type == DEVSTAT_TYPE_CHANGER ?		"CHANGER" :
	type == DEVSTAT_TYPE_COMM ?		"COMM" :
	type == DEVSTAT_TYPE_ASC0 ?		"ASC0" :
	type == DEVSTAT_TYPE_ASC1 ?		"ASC1" :
	type == DEVSTAT_TYPE_STORARRAY ?	"STORARRAY" :
	type == DEVSTAT_TYPE_ENCLOSURE ?	"ENCLOSURE" :
	type == DEVSTAT_TYPE_FLOPPY ?		"FLOPPY" :
	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));

#pragma D binding "1.13" device_type
inline string device_type[int type] =
	device_type_string[type & DEVSTAT_TYPE_MASK];

#pragma D binding "1.13" device_if_string
inline string device_if_string[int type] =
	type == 0 ?			"ACCESS" :
	type == DEVSTAT_TYPE_IF_SCSI ?	"SCSI" :
	type == DEVSTAT_TYPE_IF_IDE ?	"IDE" :
	type == DEVSTAT_TYPE_IF_OTHER ?	"OTHER" :
	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));

#pragma D binding "1.13" device_if
inline string device_if[int type] =
	device_if_string[type & DEVSTAT_TYPE_IF_MASK];

#pragma D binding "1.13" bio_cmd_string
inline string bio_cmd_string[int cmd] =
	cmd == BIO_READ ?	"READ" :
	cmd == BIO_WRITE ?	"WRITE" :
	cmd == BIO_DELETE ?	"DELETE" :
	cmd == BIO_GETATTR ?	"GETATTR" :
	cmd == BIO_FLUSH ?	"FLUSH" :
	cmd == BIO_CMD0 ?	"CMD0" :
	cmd == BIO_CMD1 ?	"CMD1" :
	cmd == BIO_CMD2 ?	"CMD2" :
	cmd == BIO_ZONE ?	"ZONE" :
	strjoin("UNKNOWN(", strjoin(lltostr(cmd), ")"));

#pragma D binding "1.13" bio_flag_string
inline string bio_flag_string[int flag] =
	flag == BIO_ERROR ?		"ERROR" :
	flag == BIO_DONE ?		"DONE" :
	flag == BIO_ONQUEUE ?		"ONQUEUE" :
	flag == BIO_ORDERED ?		"ORDERED" :
	flag == BIO_UNMAPPED ?		"UNMAPPED" :
	flag == BIO_TRANSIENT_MAPPING ?	"TRANSIENT_MAPPING" :
	flag == BIO_VLIST ?		"VLIST" :
	"";