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