xref: /freebsd-src/cddl/lib/libdtrace/io.d (revision 2ac9cecac6add7de497d85b072b727d82f1e8ee6)
1c5069a47SGeorge V. Neville-Neil /*
2c5069a47SGeorge V. Neville-Neil  * CDDL HEADER START
3c5069a47SGeorge V. Neville-Neil  *
4c5069a47SGeorge V. Neville-Neil  * The contents of this file are subject to the terms of the
5c5069a47SGeorge V. Neville-Neil  * Common Development and Distribution License (the "License").
6c5069a47SGeorge V. Neville-Neil  * You may not use this file except in compliance with the License.
7c5069a47SGeorge V. Neville-Neil  *
8c5069a47SGeorge V. Neville-Neil  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5069a47SGeorge V. Neville-Neil  * or http://www.opensolaris.org/os/licensing.
10c5069a47SGeorge V. Neville-Neil  * See the License for the specific language governing permissions
11c5069a47SGeorge V. Neville-Neil  * and limitations under the License.
12c5069a47SGeorge V. Neville-Neil  *
13c5069a47SGeorge V. Neville-Neil  * When distributing Covered Code, include this CDDL HEADER in each
14c5069a47SGeorge V. Neville-Neil  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5069a47SGeorge V. Neville-Neil  * If applicable, add the following below this CDDL HEADER, with the
16c5069a47SGeorge V. Neville-Neil  * fields enclosed by brackets "[]" replaced with your own identifying
17c5069a47SGeorge V. Neville-Neil  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5069a47SGeorge V. Neville-Neil  *
19c5069a47SGeorge V. Neville-Neil  * CDDL HEADER END
20c5069a47SGeorge V. Neville-Neil  *
2103a3981bSDevin Teske  * Portions Copyright 2018 Devin Teske dteske@freebsd.org
22c5069a47SGeorge V. Neville-Neil  */
23c5069a47SGeorge V. Neville-Neil /*
24c5069a47SGeorge V. Neville-Neil  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25c5069a47SGeorge V. Neville-Neil  * Use is subject to license terms.
26c5069a47SGeorge V. Neville-Neil  */
27c5069a47SGeorge V. Neville-Neil 
287e518a66SMark Johnston #pragma D depends_on module kernel
2902b39067SGeorge V. Neville-Neil #pragma D depends_on provider io
3002b39067SGeorge V. Neville-Neil 
31c5069a47SGeorge V. Neville-Neil typedef struct devinfo {
32c5069a47SGeorge V. Neville-Neil 	int dev_major;			/* major number */
33c5069a47SGeorge V. Neville-Neil 	int dev_minor;			/* minor number */
34c5069a47SGeorge V. Neville-Neil 	int dev_instance;		/* instance number */
3503a3981bSDevin Teske 	int dev_type;			/* type of device */
36c5069a47SGeorge V. Neville-Neil 	string dev_name;		/* name of device */
37c5069a47SGeorge V. Neville-Neil 	string dev_statname;		/* name of device + instance/minor */
38c5069a47SGeorge V. Neville-Neil 	string dev_pathname;		/* pathname of device */
39c5069a47SGeorge V. Neville-Neil } devinfo_t;
40c5069a47SGeorge V. Neville-Neil 
41c5069a47SGeorge V. Neville-Neil #pragma D binding "1.0" translator
423fac94baSGeorge V. Neville-Neil translator devinfo_t < struct devstat *D > {
433fac94baSGeorge V. Neville-Neil 	dev_major = D->device_number;
443fac94baSGeorge V. Neville-Neil 	dev_minor = D->unit_number;
453fac94baSGeorge V. Neville-Neil 	dev_instance = 0;
4603a3981bSDevin Teske 	dev_type = D->device_type;
473fac94baSGeorge V. Neville-Neil 	dev_name = stringof(D->device_name);
483fac94baSGeorge V. Neville-Neil 	dev_statname = stringof(D->device_name);
493fac94baSGeorge V. Neville-Neil 	dev_pathname = stringof(D->device_name);
50c5069a47SGeorge V. Neville-Neil };
51c5069a47SGeorge V. Neville-Neil 
523fac94baSGeorge V. Neville-Neil typedef struct bufinfo {
5303a3981bSDevin Teske 	int b_cmd;			/* I/O operation */
543fac94baSGeorge V. Neville-Neil 	int b_flags;			/* flags */
553fac94baSGeorge V. Neville-Neil 	long b_bcount;			/* number of bytes */
563fac94baSGeorge V. Neville-Neil 	caddr_t b_addr;			/* buffer address */
573fac94baSGeorge V. Neville-Neil 	uint64_t b_blkno;		/* expanded block # on device */
583fac94baSGeorge V. Neville-Neil 	uint64_t b_lblkno;		/* block # on device */
593fac94baSGeorge V. Neville-Neil 	size_t b_resid;			/* # of bytes not transferred */
603fac94baSGeorge V. Neville-Neil 	size_t b_bufsize;		/* size of allocated buffer */
613fac94baSGeorge V. Neville-Neil /*	caddr_t b_iodone;		I/O completion routine */
623fac94baSGeorge V. Neville-Neil 	int b_error;			/* expanded error field */
633fac94baSGeorge V. Neville-Neil /*	dev_t b_edev;			extended device */
643fac94baSGeorge V. Neville-Neil } bufinfo_t;
65c5069a47SGeorge V. Neville-Neil 
66c5069a47SGeorge V. Neville-Neil #pragma D binding "1.0" translator
673fac94baSGeorge V. Neville-Neil translator bufinfo_t < struct bio *B > {
6803a3981bSDevin Teske 	b_cmd = B->bio_cmd;
693fac94baSGeorge V. Neville-Neil 	b_flags = B->bio_flags;
703fac94baSGeorge V. Neville-Neil 	b_bcount = B->bio_bcount;
713fac94baSGeorge V. Neville-Neil 	b_addr = B->bio_data;
723fac94baSGeorge V. Neville-Neil 	b_blkno = 0;
733fac94baSGeorge V. Neville-Neil 	b_lblkno = 0;
743fac94baSGeorge V. Neville-Neil 	b_resid = B->bio_resid;
753fac94baSGeorge V. Neville-Neil 	b_bufsize = 0; /* XXX gnn */
763fac94baSGeorge V. Neville-Neil 	b_error = B->bio_error;
77c5069a47SGeorge V. Neville-Neil };
78c5069a47SGeorge V. Neville-Neil 
79c5069a47SGeorge V. Neville-Neil /*
80c5069a47SGeorge V. Neville-Neil  * The following inline constants can be used to examine fi_oflags when using
81c5069a47SGeorge V. Neville-Neil  * the fds[] array or a translated fileinfo_t.  Note that the various open
82c5069a47SGeorge V. Neville-Neil  * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
83c5069a47SGeorge V. Neville-Neil  * To test the open mode, you write code similar to that used with the fcntl(2)
84c5069a47SGeorge V. Neville-Neil  * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
85c5069a47SGeorge V. Neville-Neil  */
86c5069a47SGeorge V. Neville-Neil inline int O_ACCMODE = 0x0003;
87c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_ACCMODE
88c5069a47SGeorge V. Neville-Neil 
89c5069a47SGeorge V. Neville-Neil inline int O_RDONLY = 0x0000;
90c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_RDONLY
91c5069a47SGeorge V. Neville-Neil inline int O_WRONLY = 0x0001;
92c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_WRONLY
93c5069a47SGeorge V. Neville-Neil inline int O_RDWR = 0x0002;
94c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_RDWR
95c5069a47SGeorge V. Neville-Neil 
96c5069a47SGeorge V. Neville-Neil inline int O_APPEND = 0x0008;
97c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_APPEND
98c5069a47SGeorge V. Neville-Neil inline int O_CREAT = 0x0200;
99c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_CREAT
100c5069a47SGeorge V. Neville-Neil inline int O_EXCL = 0x0800;
101c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_EXCL
102c5069a47SGeorge V. Neville-Neil inline int O_NOCTTY = 0x8000;
103c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_NOCTTY
104c5069a47SGeorge V. Neville-Neil inline int O_NONBLOCK = 0x0004;
105c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_NONBLOCK
106c5069a47SGeorge V. Neville-Neil inline int O_NDELAY = 0x0004;
107c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_NDELAY
108c5069a47SGeorge V. Neville-Neil inline int O_SYNC = 0x0080;
109c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_SYNC
110c5069a47SGeorge V. Neville-Neil inline int O_TRUNC = 0x0400;
111c5069a47SGeorge V. Neville-Neil #pragma D binding "1.1" O_TRUNC
11203a3981bSDevin Teske 
11303a3981bSDevin Teske /*
11403a3981bSDevin Teske  * The following inline constants can be used to examine bio_cmd of struct bio
11503a3981bSDevin Teske  * or a translated bufinfo_t.
11603a3981bSDevin Teske  */
11703a3981bSDevin Teske inline int BIO_READ =		0x01;
11803a3981bSDevin Teske #pragma D binding "1.13" BIO_READ
11903a3981bSDevin Teske inline int BIO_WRITE =		0x02;
12003a3981bSDevin Teske #pragma D binding "1.13" BIO_WRITE
12103a3981bSDevin Teske inline int BIO_DELETE =		0x03;
12203a3981bSDevin Teske #pragma D binding "1.13" BIO_DELETE
12303a3981bSDevin Teske inline int BIO_GETATTR =	0x04;
12403a3981bSDevin Teske #pragma D binding "1.13" BIO_GETATTR
12503a3981bSDevin Teske inline int BIO_FLUSH =		0x05;
12603a3981bSDevin Teske #pragma D binding "1.13" BIO_FLUSH
12703a3981bSDevin Teske inline int BIO_CMD0 =		0x06;
12803a3981bSDevin Teske #pragma D binding "1.13" BIO_CMD0
12903a3981bSDevin Teske inline int BIO_CMD1 =		0x07;
13003a3981bSDevin Teske #pragma D binding "1.13" BIO_CMD1
13103a3981bSDevin Teske inline int BIO_CMD2 =		0x08;
13203a3981bSDevin Teske #pragma D binding "1.13" BIO_CMD2
13303a3981bSDevin Teske inline int BIO_ZONE =		0x09;
13403a3981bSDevin Teske #pragma D binding "1.13" BIO_ZONE
13503a3981bSDevin Teske 
13603a3981bSDevin Teske /*
13703a3981bSDevin Teske  * The following inline constants can be used to examine bio_flags of struct
13803a3981bSDevin Teske  * bio or a translated bufinfo_t.
13903a3981bSDevin Teske  */
14003a3981bSDevin Teske inline int BIO_ERROR =			0x01;
14103a3981bSDevin Teske #pragma D binding "1.13" BIO_ERROR
14203a3981bSDevin Teske inline int BIO_DONE =			0x02;
14303a3981bSDevin Teske #pragma D binding "1.13" BIO_DONE
14403a3981bSDevin Teske inline int BIO_ONQUEUE =		0x04;
14503a3981bSDevin Teske #pragma D binding "1.13" BIO_ONQUEUE
14603a3981bSDevin Teske inline int BIO_ORDERED =		0x08;
14703a3981bSDevin Teske #pragma D binding "1.13" BIO_ORDERED
14803a3981bSDevin Teske inline int BIO_UNMAPPED =		0x10;
14903a3981bSDevin Teske #pragma D binding "1.13" BIO_UNMAPPED
15003a3981bSDevin Teske inline int BIO_TRANSIENT_MAPPING =	0x20;
15103a3981bSDevin Teske #pragma D binding "1.13" BIO_TRANSIENT_MAPPING
15203a3981bSDevin Teske inline int BIO_VLIST =			0x40;
15303a3981bSDevin Teske #pragma D binding "1.13" BIO_VLIST
15403a3981bSDevin Teske 
15503a3981bSDevin Teske /*
15603a3981bSDevin Teske  * The following inline constants can be used to examine device_type of struct
15703a3981bSDevin Teske  * devstat or a translated devinfo_t.
15803a3981bSDevin Teske  */
15903a3981bSDevin Teske inline int DEVSTAT_TYPE_DIRECT =	0x000;
16003a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_DIRECT
16103a3981bSDevin Teske inline int DEVSTAT_TYPE_SEQUENTIAL =	0x001;
16203a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_SEQUENTIAL
16303a3981bSDevin Teske inline int DEVSTAT_TYPE_PRINTER =	0x002;
16403a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_PRINTER
16503a3981bSDevin Teske inline int DEVSTAT_TYPE_PROCESSOR =	0x003;
16603a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_PROCESSOR
16703a3981bSDevin Teske inline int DEVSTAT_TYPE_WORM =		0x004;
16803a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_WORM
16903a3981bSDevin Teske inline int DEVSTAT_TYPE_CDROM =		0x005;
17003a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_CDROM
17103a3981bSDevin Teske inline int DEVSTAT_TYPE_SCANNER =	0x006;
17203a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_SCANNER
17303a3981bSDevin Teske inline int DEVSTAT_TYPE_OPTICAL =	0x007;
17403a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_OPTICAL
17503a3981bSDevin Teske inline int DEVSTAT_TYPE_CHANGER =	0x008;
17603a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_CHANGER
17703a3981bSDevin Teske inline int DEVSTAT_TYPE_COMM =		0x009;
17803a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_COMM
17903a3981bSDevin Teske inline int DEVSTAT_TYPE_ASC0 =		0x00a;
18003a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_ASC0
18103a3981bSDevin Teske inline int DEVSTAT_TYPE_ASC1 =		0x00b;
18203a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_ASC1
18303a3981bSDevin Teske inline int DEVSTAT_TYPE_STORARRAY =	0x00c;
18403a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_STORARRAY
18503a3981bSDevin Teske inline int DEVSTAT_TYPE_ENCLOSURE =	0x00d;
18603a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_ENCLOSURE
18703a3981bSDevin Teske inline int DEVSTAT_TYPE_FLOPPY =	0x00e;
18803a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_FLOPPY
18903a3981bSDevin Teske inline int DEVSTAT_TYPE_MASK =		0x00f;
19003a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_MASK
19103a3981bSDevin Teske inline int DEVSTAT_TYPE_IF_SCSI =	0x010;
19203a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_IF_SCSI
19303a3981bSDevin Teske inline int DEVSTAT_TYPE_IF_IDE =	0x020;
19403a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
19503a3981bSDevin Teske inline int DEVSTAT_TYPE_IF_OTHER =	0x030;
19603a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
197*2ac9cecaSAlexander Motin inline int DEVSTAT_TYPE_IF_NVME =	0x040;
198d282baddSAlexander Motin #pragma D binding "1.13" DEVSTAT_TYPE_IF_NVME
19903a3981bSDevin Teske inline int DEVSTAT_TYPE_IF_MASK =	0x0f0;
20003a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
20103a3981bSDevin Teske inline int DEVSTAT_TYPE_PASS =		0x100;
20203a3981bSDevin Teske #pragma D binding "1.13" DEVSTAT_TYPE_PASS
20303a3981bSDevin Teske 
20403a3981bSDevin Teske #pragma D binding "1.13" device_type_string
20503a3981bSDevin Teske inline string device_type_string[int type] =
20603a3981bSDevin Teske 	type == DEVSTAT_TYPE_DIRECT ?		"DIRECT" :
20703a3981bSDevin Teske 	type == DEVSTAT_TYPE_SEQUENTIAL ?	"SEQUENTIAL" :
20803a3981bSDevin Teske 	type == DEVSTAT_TYPE_PRINTER ?		"PRINTER" :
20903a3981bSDevin Teske 	type == DEVSTAT_TYPE_PROCESSOR ?	"PROCESSOR" :
21003a3981bSDevin Teske 	type == DEVSTAT_TYPE_WORM ?		"WORM" :
21103a3981bSDevin Teske 	type == DEVSTAT_TYPE_CDROM ?		"CDROM" :
21203a3981bSDevin Teske 	type == DEVSTAT_TYPE_SCANNER ?		"SCANNER" :
21303a3981bSDevin Teske 	type == DEVSTAT_TYPE_OPTICAL ?		"OPTICAL" :
21403a3981bSDevin Teske 	type == DEVSTAT_TYPE_CHANGER ?		"CHANGER" :
21503a3981bSDevin Teske 	type == DEVSTAT_TYPE_COMM ?		"COMM" :
21603a3981bSDevin Teske 	type == DEVSTAT_TYPE_ASC0 ?		"ASC0" :
21703a3981bSDevin Teske 	type == DEVSTAT_TYPE_ASC1 ?		"ASC1" :
21803a3981bSDevin Teske 	type == DEVSTAT_TYPE_STORARRAY ?	"STORARRAY" :
21903a3981bSDevin Teske 	type == DEVSTAT_TYPE_ENCLOSURE ?	"ENCLOSURE" :
22003a3981bSDevin Teske 	type == DEVSTAT_TYPE_FLOPPY ?		"FLOPPY" :
22103a3981bSDevin Teske 	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
22203a3981bSDevin Teske 
22303a3981bSDevin Teske #pragma D binding "1.13" device_type
22403a3981bSDevin Teske inline string device_type[int type] =
22503a3981bSDevin Teske 	device_type_string[type & DEVSTAT_TYPE_MASK];
22603a3981bSDevin Teske 
22703a3981bSDevin Teske #pragma D binding "1.13" device_if_string
22803a3981bSDevin Teske inline string device_if_string[int type] =
22903a3981bSDevin Teske 	type == 0 ?			"ACCESS" :
23003a3981bSDevin Teske 	type == DEVSTAT_TYPE_IF_SCSI ?	"SCSI" :
23103a3981bSDevin Teske 	type == DEVSTAT_TYPE_IF_IDE ?	"IDE" :
23203a3981bSDevin Teske 	type == DEVSTAT_TYPE_IF_OTHER ?	"OTHER" :
233d282baddSAlexander Motin 	type == DEVSTAT_TYPE_IF_NVME ?	"NVME" :
23403a3981bSDevin Teske 	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
23503a3981bSDevin Teske 
23603a3981bSDevin Teske #pragma D binding "1.13" device_if
23703a3981bSDevin Teske inline string device_if[int type] =
23803a3981bSDevin Teske 	device_if_string[type & DEVSTAT_TYPE_IF_MASK];
23903a3981bSDevin Teske 
24003a3981bSDevin Teske #pragma D binding "1.13" bio_cmd_string
24103a3981bSDevin Teske inline string bio_cmd_string[int cmd] =
24203a3981bSDevin Teske 	cmd == BIO_READ ?	"READ" :
24303a3981bSDevin Teske 	cmd == BIO_WRITE ?	"WRITE" :
24403a3981bSDevin Teske 	cmd == BIO_DELETE ?	"DELETE" :
24503a3981bSDevin Teske 	cmd == BIO_GETATTR ?	"GETATTR" :
24603a3981bSDevin Teske 	cmd == BIO_FLUSH ?	"FLUSH" :
24703a3981bSDevin Teske 	cmd == BIO_CMD0 ?	"CMD0" :
24803a3981bSDevin Teske 	cmd == BIO_CMD1 ?	"CMD1" :
24903a3981bSDevin Teske 	cmd == BIO_CMD2 ?	"CMD2" :
25003a3981bSDevin Teske 	cmd == BIO_ZONE ?	"ZONE" :
25103a3981bSDevin Teske 	strjoin("UNKNOWN(", strjoin(lltostr(cmd), ")"));
25203a3981bSDevin Teske 
25303a3981bSDevin Teske #pragma D binding "1.13" bio_flag_string
25403a3981bSDevin Teske inline string bio_flag_string[int flag] =
25503a3981bSDevin Teske 	flag == BIO_ERROR ?		"ERROR" :
25603a3981bSDevin Teske 	flag == BIO_DONE ?		"DONE" :
25703a3981bSDevin Teske 	flag == BIO_ONQUEUE ?		"ONQUEUE" :
25803a3981bSDevin Teske 	flag == BIO_ORDERED ?		"ORDERED" :
25903a3981bSDevin Teske 	flag == BIO_UNMAPPED ?		"UNMAPPED" :
26003a3981bSDevin Teske 	flag == BIO_TRANSIENT_MAPPING ?	"TRANSIENT_MAPPING" :
26103a3981bSDevin Teske 	flag == BIO_VLIST ?		"VLIST" :
26203a3981bSDevin Teske 	"";
263