xref: /titanic_50/usr/src/lib/libdtrace/common/io.d.in (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate#pragma D depends_on module unix
30*7c478bd9Sstevel@tonic-gate#pragma D depends_on provider io
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gateinline int B_BUSY = @B_BUSY@;
33*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_BUSY
34*7c478bd9Sstevel@tonic-gateinline int B_DONE = @B_DONE@;
35*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_DONE
36*7c478bd9Sstevel@tonic-gateinline int B_ERROR = @B_ERROR@;
37*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ERROR
38*7c478bd9Sstevel@tonic-gateinline int B_PAGEIO = @B_PAGEIO@;
39*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PAGEIO
40*7c478bd9Sstevel@tonic-gateinline int B_PHYS = @B_PHYS@;
41*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PHYS
42*7c478bd9Sstevel@tonic-gateinline int B_READ = @B_READ@;
43*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_READ
44*7c478bd9Sstevel@tonic-gateinline int B_WRITE = @B_WRITE@;
45*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_WRITE
46*7c478bd9Sstevel@tonic-gateinline int B_ASYNC = @B_ASYNC@;
47*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ASYNC
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gatetypedef struct bufinfo {
50*7c478bd9Sstevel@tonic-gate	int b_flags;			/* buffer status */
51*7c478bd9Sstevel@tonic-gate	size_t b_bcount;		/* number of bytes */
52*7c478bd9Sstevel@tonic-gate	caddr_t b_addr;			/* buffer address */
53*7c478bd9Sstevel@tonic-gate	uint64_t b_lblkno;		/* block # on device */
54*7c478bd9Sstevel@tonic-gate	uint64_t b_blkno;		/* expanded block # on device */
55*7c478bd9Sstevel@tonic-gate	size_t b_resid;			/* # of bytes not transferred */
56*7c478bd9Sstevel@tonic-gate	size_t b_bufsize;		/* size of allocated buffer */
57*7c478bd9Sstevel@tonic-gate	caddr_t b_iodone;		/* I/O completion routine */
58*7c478bd9Sstevel@tonic-gate	int b_error;			/* expanded error field */
59*7c478bd9Sstevel@tonic-gate	dev_t b_edev;			/* extended device */
60*7c478bd9Sstevel@tonic-gate} bufinfo_t;
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator
63*7c478bd9Sstevel@tonic-gatetranslator bufinfo_t < struct buf *B > {
64*7c478bd9Sstevel@tonic-gate	b_flags = B->b_flags;
65*7c478bd9Sstevel@tonic-gate	b_addr = B->b_un.b_addr;
66*7c478bd9Sstevel@tonic-gate	b_bcount = B->b_bcount;
67*7c478bd9Sstevel@tonic-gate	b_lblkno = B->_b_blkno._f;
68*7c478bd9Sstevel@tonic-gate	b_blkno = sizeof (long) == 8 ? B->_b_blkno._f : B->_b_blkno._p._l;
69*7c478bd9Sstevel@tonic-gate	b_resid = B->b_resid;
70*7c478bd9Sstevel@tonic-gate	b_bufsize = B->b_bufsize;
71*7c478bd9Sstevel@tonic-gate	b_iodone = (caddr_t)B->b_iodone;
72*7c478bd9Sstevel@tonic-gate	b_error = B->b_error;
73*7c478bd9Sstevel@tonic-gate	b_edev = B->b_edev;
74*7c478bd9Sstevel@tonic-gate};
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gatetypedef struct devinfo {
77*7c478bd9Sstevel@tonic-gate	int dev_major;			/* major number */
78*7c478bd9Sstevel@tonic-gate	int dev_minor;			/* minor number */
79*7c478bd9Sstevel@tonic-gate	int dev_instance;		/* instance number */
80*7c478bd9Sstevel@tonic-gate	string dev_name;		/* name of device */
81*7c478bd9Sstevel@tonic-gate	string dev_statname;		/* name of device + instance/minor */
82*7c478bd9Sstevel@tonic-gate	string dev_pathname;		/* pathname of device */
83*7c478bd9Sstevel@tonic-gate} devinfo_t;
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator
86*7c478bd9Sstevel@tonic-gatetranslator devinfo_t < struct buf *B > {
87*7c478bd9Sstevel@tonic-gate	dev_major = B->b_dip != NULL ? getmajor(B->b_edev) :
88*7c478bd9Sstevel@tonic-gate	    getmajor(B->b_file->v_vfsp->vfs_dev);
89*7c478bd9Sstevel@tonic-gate	dev_minor = B->b_dip != NULL ? getminor(B->b_edev) :
90*7c478bd9Sstevel@tonic-gate	    getminor(B->b_file->v_vfsp->vfs_dev);
91*7c478bd9Sstevel@tonic-gate	dev_instance = B->b_dip == NULL ?
92*7c478bd9Sstevel@tonic-gate	    getminor(B->b_file->v_vfsp->vfs_dev) :
93*7c478bd9Sstevel@tonic-gate	    ((struct dev_info *)B->b_dip)->devi_instance;
94*7c478bd9Sstevel@tonic-gate	dev_name = B->b_dip == NULL ? "nfs" :
95*7c478bd9Sstevel@tonic-gate	    stringof(`devnamesp[getmajor(B->b_edev)].dn_name);
96*7c478bd9Sstevel@tonic-gate	dev_statname = strjoin(B->b_dip == NULL ? "nfs" :
97*7c478bd9Sstevel@tonic-gate	    stringof(`devnamesp[getmajor(B->b_edev)].dn_name),
98*7c478bd9Sstevel@tonic-gate	    lltostr(B->b_dip == NULL ? getminor(B->b_file->v_vfsp->vfs_dev) :
99*7c478bd9Sstevel@tonic-gate	    ((struct dev_info *)B->b_dip)->devi_instance == 0 &&
100*7c478bd9Sstevel@tonic-gate	    ((struct dev_info *)B->b_dip)->devi_parent != NULL &&
101*7c478bd9Sstevel@tonic-gate	    ((struct dev_info *)B->b_dip)->devi_parent->devi_node_name ==
102*7c478bd9Sstevel@tonic-gate	    "pseudo" ? getminor(B->b_edev) :
103*7c478bd9Sstevel@tonic-gate	    ((struct dev_info *)B->b_dip)->devi_instance));
104*7c478bd9Sstevel@tonic-gate	dev_pathname = B->b_dip == NULL ? "<nfs>" :
105*7c478bd9Sstevel@tonic-gate	    ddi_pathname(B->b_dip, getminor(B->b_edev));
106*7c478bd9Sstevel@tonic-gate};
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gatetypedef struct fileinfo {
109*7c478bd9Sstevel@tonic-gate	string fi_name;			/* name (basename of fi_pathname) */
110*7c478bd9Sstevel@tonic-gate	string fi_dirname;		/* directory (dirname of fi_pathname) */
111*7c478bd9Sstevel@tonic-gate	string fi_pathname;		/* full pathname */
112*7c478bd9Sstevel@tonic-gate	offset_t fi_offset;		/* offset within file */
113*7c478bd9Sstevel@tonic-gate	string fi_fs;			/* filesystem */
114*7c478bd9Sstevel@tonic-gate	string fi_mount;		/* mount point of file system */
115*7c478bd9Sstevel@tonic-gate	int fi_oflags;			/* open(2) flags for file descriptor */
116*7c478bd9Sstevel@tonic-gate} fileinfo_t;
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator
119*7c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct buf *B > {
120*7c478bd9Sstevel@tonic-gate	fi_name = B->b_file == NULL ? "<none>" :
121*7c478bd9Sstevel@tonic-gate	    B->b_file->v_path == NULL ? "<unknown>" :
122*7c478bd9Sstevel@tonic-gate	    basename(cleanpath(B->b_file->v_path));
123*7c478bd9Sstevel@tonic-gate	fi_dirname = B->b_file == NULL ? "<none>" :
124*7c478bd9Sstevel@tonic-gate	    B->b_file->v_path == NULL ? "<unknown>" :
125*7c478bd9Sstevel@tonic-gate	    dirname(cleanpath(B->b_file->v_path));
126*7c478bd9Sstevel@tonic-gate	fi_pathname = B->b_file == NULL ? "<none>" :
127*7c478bd9Sstevel@tonic-gate	    B->b_file->v_path == NULL ? "<unknown>" :
128*7c478bd9Sstevel@tonic-gate	    cleanpath(B->b_file->v_path);
129*7c478bd9Sstevel@tonic-gate	fi_offset = B->b_offset;
130*7c478bd9Sstevel@tonic-gate	fi_fs = B->b_file == NULL ? "<none>" :
131*7c478bd9Sstevel@tonic-gate	    stringof(B->b_file->v_op->vnop_name);
132*7c478bd9Sstevel@tonic-gate	fi_mount = B->b_file == NULL ? "<none>" :
133*7c478bd9Sstevel@tonic-gate	    B->b_file->v_vfsp->vfs_vnodecovered == NULL ? "/" :
134*7c478bd9Sstevel@tonic-gate	    B->b_file->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" :
135*7c478bd9Sstevel@tonic-gate	    cleanpath(B->b_file->v_vfsp->vfs_vnodecovered->v_path);
136*7c478bd9Sstevel@tonic-gate	fi_oflags = 0;
137*7c478bd9Sstevel@tonic-gate};
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate/*
140*7c478bd9Sstevel@tonic-gate * The following inline constants can be used to examine fi_oflags when using
141*7c478bd9Sstevel@tonic-gate * the fds[] array or a translated fileinfo_t.  Note that the various open
142*7c478bd9Sstevel@tonic-gate * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR.
143*7c478bd9Sstevel@tonic-gate * To test the open mode, you write code similar to that used with the fcntl(2)
144*7c478bd9Sstevel@tonic-gate * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY).
145*7c478bd9Sstevel@tonic-gate */
146*7c478bd9Sstevel@tonic-gateinline int O_ACCMODE = @O_ACCMODE@;
147*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_ACCMODE
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gateinline int O_RDONLY = @O_RDONLY@;
150*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDONLY
151*7c478bd9Sstevel@tonic-gateinline int O_WRONLY = @O_WRONLY@;
152*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_WRONLY
153*7c478bd9Sstevel@tonic-gateinline int O_RDWR = @O_RDWR@;
154*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDWR
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gateinline int O_APPEND = @O_APPEND@;
157*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_APPEND
158*7c478bd9Sstevel@tonic-gateinline int O_CREAT = @O_CREAT@;
159*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_CREAT
160*7c478bd9Sstevel@tonic-gateinline int O_DSYNC = @O_DSYNC@;
161*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_DSYNC
162*7c478bd9Sstevel@tonic-gateinline int O_EXCL = @O_EXCL@;
163*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_EXCL
164*7c478bd9Sstevel@tonic-gateinline int O_LARGEFILE = @O_LARGEFILE@;
165*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_LARGEFILE
166*7c478bd9Sstevel@tonic-gateinline int O_NOCTTY = @O_NOCTTY@;
167*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NOCTTY
168*7c478bd9Sstevel@tonic-gateinline int O_NONBLOCK = @O_NONBLOCK@;
169*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NONBLOCK
170*7c478bd9Sstevel@tonic-gateinline int O_NDELAY = @O_NDELAY@;
171*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NDELAY
172*7c478bd9Sstevel@tonic-gateinline int O_RSYNC = @O_RSYNC@;
173*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RSYNC
174*7c478bd9Sstevel@tonic-gateinline int O_SYNC = @O_SYNC@;
175*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_SYNC
176*7c478bd9Sstevel@tonic-gateinline int O_TRUNC = @O_TRUNC@;
177*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_TRUNC
178*7c478bd9Sstevel@tonic-gateinline int O_XATTR = @O_XATTR@;
179*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_XATTR
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" translator
182*7c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct file *F > {
183*7c478bd9Sstevel@tonic-gate	fi_name = F == NULL ? "<none>" :
184*7c478bd9Sstevel@tonic-gate	    F->f_vnode->v_path == NULL ? "<unknown>" :
185*7c478bd9Sstevel@tonic-gate	    basename(cleanpath(F->f_vnode->v_path));
186*7c478bd9Sstevel@tonic-gate	fi_dirname = F == NULL ? "<none>" :
187*7c478bd9Sstevel@tonic-gate	    F->f_vnode->v_path == NULL ? "<unknown>" :
188*7c478bd9Sstevel@tonic-gate	    dirname(cleanpath(F->f_vnode->v_path));
189*7c478bd9Sstevel@tonic-gate	fi_pathname = F == NULL ? "<none>" :
190*7c478bd9Sstevel@tonic-gate	    F->f_vnode->v_path == NULL ? "<unknown>" :
191*7c478bd9Sstevel@tonic-gate	    cleanpath(F->f_vnode->v_path);
192*7c478bd9Sstevel@tonic-gate	fi_offset = F == NULL ? 0 : F->f_offset;
193*7c478bd9Sstevel@tonic-gate	fi_fs = F == NULL ? "<none>" : stringof(F->f_vnode->v_op->vnop_name);
194*7c478bd9Sstevel@tonic-gate	fi_mount = F == NULL ? "<none>" :
195*7c478bd9Sstevel@tonic-gate	    F->f_vnode->v_vfsp->vfs_vnodecovered == NULL ? "/" :
196*7c478bd9Sstevel@tonic-gate	    F->f_vnode->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" :
197*7c478bd9Sstevel@tonic-gate	    cleanpath(F->f_vnode->v_vfsp->vfs_vnodecovered->v_path);
198*7c478bd9Sstevel@tonic-gate	fi_oflags = F == NULL ? 0 : F->f_flag + (int)@FOPEN@;
199*7c478bd9Sstevel@tonic-gate};
200*7c478bd9Sstevel@tonic-gate
201*7c478bd9Sstevel@tonic-gateinline fileinfo_t fds[int fd] = xlate <fileinfo_t> (
202*7c478bd9Sstevel@tonic-gate    fd >= 0 && fd < curthread->t_procp->p_user.u_finfo.fi_nfiles ?
203*7c478bd9Sstevel@tonic-gate    curthread->t_procp->p_user.u_finfo.fi_list[fd].uf_file : NULL);
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common fds
206*7c478bd9Sstevel@tonic-gate#pragma D binding "1.1" fds
207