xref: /freebsd/cddl/lib/libdtrace/io.d (revision a5921bc3653e2e286715e6fe8d473ec0d02da38c)
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  * $FreeBSD$
22  */
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma D depends_on module kernel
29 #pragma D depends_on provider io
30 
31 typedef struct devinfo {
32         int dev_major;                  /* major number */
33         int dev_minor;                  /* minor number */
34         int dev_instance;               /* instance number */
35         string dev_name;                /* name of device */
36         string dev_statname;            /* name of device + instance/minor */
37         string dev_pathname;            /* pathname of device */
38 } devinfo_t;
39 
40 #pragma D binding "1.0" translator
41 translator devinfo_t < struct devstat *D > {
42            dev_major = D->device_number;
43            dev_minor = D->unit_number;
44            dev_instance = 0;
45            dev_name = stringof(D->device_name);
46            dev_statname = stringof(D->device_name);
47            dev_pathname = stringof(D->device_name);
48 };
49 
50 typedef struct bufinfo {
51         int b_flags;                    /* flags */
52         long b_bcount;                /* number of bytes */
53         caddr_t b_addr;                 /* buffer address */
54         uint64_t b_blkno;               /* expanded block # on device */
55         uint64_t b_lblkno;              /* block # on device */
56         size_t b_resid;                 /* # of bytes not transferred */
57         size_t b_bufsize;               /* size of allocated buffer */
58 /*        caddr_t b_iodone;              I/O completion routine */
59         int b_error;                    /* expanded error field */
60 /*        dev_t b_edev;                  extended device */
61 } bufinfo_t;
62 
63 #pragma D binding "1.0" translator
64 translator bufinfo_t < struct bio *B > {
65            b_flags = B->bio_flags;
66            b_bcount = B->bio_bcount;
67            b_addr = B->bio_data;
68            b_blkno = 0;
69            b_lblkno = 0;
70            b_resid = B->bio_resid;
71            b_bufsize = 0; /* XXX gnn */
72            b_error = B->bio_error;
73 };
74 
75 /*
76  * The following inline constants can be used to examine fi_oflags when using
77  * the fds[] array or a translated fileinfo_t.  Note that the various open
78  * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
79  * To test the open mode, you write code similar to that used with the fcntl(2)
80  * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
81  */
82 inline int O_ACCMODE = 0x0003;
83 #pragma D binding "1.1" O_ACCMODE
84 
85 inline int O_RDONLY = 0x0000;
86 #pragma D binding "1.1" O_RDONLY
87 inline int O_WRONLY = 0x0001;
88 #pragma D binding "1.1" O_WRONLY
89 inline int O_RDWR = 0x0002;
90 #pragma D binding "1.1" O_RDWR
91 
92 inline int O_APPEND = 0x0008;
93 #pragma D binding "1.1" O_APPEND
94 inline int O_CREAT = 0x0200;
95 #pragma D binding "1.1" O_CREAT
96 inline int O_EXCL = 0x0800;
97 #pragma D binding "1.1" O_EXCL
98 inline int O_NOCTTY = 0x8000;
99 #pragma D binding "1.1" O_NOCTTY
100 inline int O_NONBLOCK = 0x0004;
101 #pragma D binding "1.1" O_NONBLOCK
102 inline int O_NDELAY = 0x0004;
103 #pragma D binding "1.1" O_NDELAY
104 inline int O_SYNC = 0x0080;
105 #pragma D binding "1.1" O_SYNC
106 inline int O_TRUNC = 0x0400;
107 #pragma D binding "1.1" O_TRUNC
108 
109 
110