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