17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2bb1cb30Sbmc * Common Development and Distribution License (the "License"). 6*2bb1cb30Sbmc * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate/* 22*2bb1cb30Sbmc * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate#pragma D depends_on module unix 297c478bd9Sstevel@tonic-gate#pragma D depends_on provider io 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gateinline int B_BUSY = @B_BUSY@; 327c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_BUSY 337c478bd9Sstevel@tonic-gateinline int B_DONE = @B_DONE@; 347c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_DONE 357c478bd9Sstevel@tonic-gateinline int B_ERROR = @B_ERROR@; 367c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ERROR 377c478bd9Sstevel@tonic-gateinline int B_PAGEIO = @B_PAGEIO@; 387c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PAGEIO 397c478bd9Sstevel@tonic-gateinline int B_PHYS = @B_PHYS@; 407c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PHYS 417c478bd9Sstevel@tonic-gateinline int B_READ = @B_READ@; 427c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_READ 437c478bd9Sstevel@tonic-gateinline int B_WRITE = @B_WRITE@; 447c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_WRITE 457c478bd9Sstevel@tonic-gateinline int B_ASYNC = @B_ASYNC@; 467c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ASYNC 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gatetypedef struct bufinfo { 497c478bd9Sstevel@tonic-gate int b_flags; /* buffer status */ 507c478bd9Sstevel@tonic-gate size_t b_bcount; /* number of bytes */ 517c478bd9Sstevel@tonic-gate caddr_t b_addr; /* buffer address */ 527c478bd9Sstevel@tonic-gate uint64_t b_lblkno; /* block # on device */ 537c478bd9Sstevel@tonic-gate uint64_t b_blkno; /* expanded block # on device */ 547c478bd9Sstevel@tonic-gate size_t b_resid; /* # of bytes not transferred */ 557c478bd9Sstevel@tonic-gate size_t b_bufsize; /* size of allocated buffer */ 567c478bd9Sstevel@tonic-gate caddr_t b_iodone; /* I/O completion routine */ 577c478bd9Sstevel@tonic-gate int b_error; /* expanded error field */ 587c478bd9Sstevel@tonic-gate dev_t b_edev; /* extended device */ 597c478bd9Sstevel@tonic-gate} bufinfo_t; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 627c478bd9Sstevel@tonic-gatetranslator bufinfo_t < struct buf *B > { 637c478bd9Sstevel@tonic-gate b_flags = B->b_flags; 647c478bd9Sstevel@tonic-gate b_addr = B->b_un.b_addr; 657c478bd9Sstevel@tonic-gate b_bcount = B->b_bcount; 667c478bd9Sstevel@tonic-gate b_lblkno = B->_b_blkno._f; 677c478bd9Sstevel@tonic-gate b_blkno = sizeof (long) == 8 ? B->_b_blkno._f : B->_b_blkno._p._l; 687c478bd9Sstevel@tonic-gate b_resid = B->b_resid; 697c478bd9Sstevel@tonic-gate b_bufsize = B->b_bufsize; 707c478bd9Sstevel@tonic-gate b_iodone = (caddr_t)B->b_iodone; 717c478bd9Sstevel@tonic-gate b_error = B->b_error; 727c478bd9Sstevel@tonic-gate b_edev = B->b_edev; 737c478bd9Sstevel@tonic-gate}; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gatetypedef struct devinfo { 767c478bd9Sstevel@tonic-gate int dev_major; /* major number */ 777c478bd9Sstevel@tonic-gate int dev_minor; /* minor number */ 787c478bd9Sstevel@tonic-gate int dev_instance; /* instance number */ 797c478bd9Sstevel@tonic-gate string dev_name; /* name of device */ 807c478bd9Sstevel@tonic-gate string dev_statname; /* name of device + instance/minor */ 817c478bd9Sstevel@tonic-gate string dev_pathname; /* pathname of device */ 827c478bd9Sstevel@tonic-gate} devinfo_t; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 857c478bd9Sstevel@tonic-gatetranslator devinfo_t < struct buf *B > { 867c478bd9Sstevel@tonic-gate dev_major = B->b_dip != NULL ? getmajor(B->b_edev) : 877c478bd9Sstevel@tonic-gate getmajor(B->b_file->v_vfsp->vfs_dev); 887c478bd9Sstevel@tonic-gate dev_minor = B->b_dip != NULL ? getminor(B->b_edev) : 897c478bd9Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev); 907c478bd9Sstevel@tonic-gate dev_instance = B->b_dip == NULL ? 917c478bd9Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev) : 927c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance; 937c478bd9Sstevel@tonic-gate dev_name = B->b_dip == NULL ? "nfs" : 947c478bd9Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name); 957c478bd9Sstevel@tonic-gate dev_statname = strjoin(B->b_dip == NULL ? "nfs" : 967c478bd9Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name), 977c478bd9Sstevel@tonic-gate lltostr(B->b_dip == NULL ? getminor(B->b_file->v_vfsp->vfs_dev) : 987c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance == 0 && 997c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent != NULL && 1007c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent->devi_node_name == 1017c478bd9Sstevel@tonic-gate "pseudo" ? getminor(B->b_edev) : 1027c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance)); 1037c478bd9Sstevel@tonic-gate dev_pathname = B->b_dip == NULL ? "<nfs>" : 1047c478bd9Sstevel@tonic-gate ddi_pathname(B->b_dip, getminor(B->b_edev)); 1057c478bd9Sstevel@tonic-gate}; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gatetypedef struct fileinfo { 1087c478bd9Sstevel@tonic-gate string fi_name; /* name (basename of fi_pathname) */ 1097c478bd9Sstevel@tonic-gate string fi_dirname; /* directory (dirname of fi_pathname) */ 1107c478bd9Sstevel@tonic-gate string fi_pathname; /* full pathname */ 1117c478bd9Sstevel@tonic-gate offset_t fi_offset; /* offset within file */ 1127c478bd9Sstevel@tonic-gate string fi_fs; /* filesystem */ 1137c478bd9Sstevel@tonic-gate string fi_mount; /* mount point of file system */ 1147c478bd9Sstevel@tonic-gate int fi_oflags; /* open(2) flags for file descriptor */ 1157c478bd9Sstevel@tonic-gate} fileinfo_t; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 1187c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct buf *B > { 1197c478bd9Sstevel@tonic-gate fi_name = B->b_file == NULL ? "<none>" : 1207c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1217c478bd9Sstevel@tonic-gate basename(cleanpath(B->b_file->v_path)); 1227c478bd9Sstevel@tonic-gate fi_dirname = B->b_file == NULL ? "<none>" : 1237c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1247c478bd9Sstevel@tonic-gate dirname(cleanpath(B->b_file->v_path)); 1257c478bd9Sstevel@tonic-gate fi_pathname = B->b_file == NULL ? "<none>" : 1267c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1277c478bd9Sstevel@tonic-gate cleanpath(B->b_file->v_path); 1287c478bd9Sstevel@tonic-gate fi_offset = B->b_offset; 1297c478bd9Sstevel@tonic-gate fi_fs = B->b_file == NULL ? "<none>" : 1307c478bd9Sstevel@tonic-gate stringof(B->b_file->v_op->vnop_name); 1317c478bd9Sstevel@tonic-gate fi_mount = B->b_file == NULL ? "<none>" : 1327c478bd9Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1337c478bd9Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1347c478bd9Sstevel@tonic-gate cleanpath(B->b_file->v_vfsp->vfs_vnodecovered->v_path); 1357c478bd9Sstevel@tonic-gate fi_oflags = 0; 1367c478bd9Sstevel@tonic-gate}; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate/* 1397c478bd9Sstevel@tonic-gate * The following inline constants can be used to examine fi_oflags when using 1407c478bd9Sstevel@tonic-gate * the fds[] array or a translated fileinfo_t. Note that the various open 1417c478bd9Sstevel@tonic-gate * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR. 1427c478bd9Sstevel@tonic-gate * To test the open mode, you write code similar to that used with the fcntl(2) 1437c478bd9Sstevel@tonic-gate * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY). 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gateinline int O_ACCMODE = @O_ACCMODE@; 1467c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_ACCMODE 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gateinline int O_RDONLY = @O_RDONLY@; 1497c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDONLY 1507c478bd9Sstevel@tonic-gateinline int O_WRONLY = @O_WRONLY@; 1517c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_WRONLY 1527c478bd9Sstevel@tonic-gateinline int O_RDWR = @O_RDWR@; 1537c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDWR 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gateinline int O_APPEND = @O_APPEND@; 1567c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_APPEND 1577c478bd9Sstevel@tonic-gateinline int O_CREAT = @O_CREAT@; 1587c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_CREAT 1597c478bd9Sstevel@tonic-gateinline int O_DSYNC = @O_DSYNC@; 1607c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_DSYNC 1617c478bd9Sstevel@tonic-gateinline int O_EXCL = @O_EXCL@; 1627c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_EXCL 1637c478bd9Sstevel@tonic-gateinline int O_LARGEFILE = @O_LARGEFILE@; 1647c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_LARGEFILE 1657c478bd9Sstevel@tonic-gateinline int O_NOCTTY = @O_NOCTTY@; 1667c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NOCTTY 1677c478bd9Sstevel@tonic-gateinline int O_NONBLOCK = @O_NONBLOCK@; 1687c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NONBLOCK 1697c478bd9Sstevel@tonic-gateinline int O_NDELAY = @O_NDELAY@; 1707c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NDELAY 1717c478bd9Sstevel@tonic-gateinline int O_RSYNC = @O_RSYNC@; 1727c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RSYNC 1737c478bd9Sstevel@tonic-gateinline int O_SYNC = @O_SYNC@; 1747c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_SYNC 1757c478bd9Sstevel@tonic-gateinline int O_TRUNC = @O_TRUNC@; 1767c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_TRUNC 1777c478bd9Sstevel@tonic-gateinline int O_XATTR = @O_XATTR@; 1787c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_XATTR 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate#pragma D binding "1.1" translator 1817c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct file *F > { 1827c478bd9Sstevel@tonic-gate fi_name = F == NULL ? "<none>" : 1837c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1847c478bd9Sstevel@tonic-gate basename(cleanpath(F->f_vnode->v_path)); 1857c478bd9Sstevel@tonic-gate fi_dirname = F == NULL ? "<none>" : 1867c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1877c478bd9Sstevel@tonic-gate dirname(cleanpath(F->f_vnode->v_path)); 1887c478bd9Sstevel@tonic-gate fi_pathname = F == NULL ? "<none>" : 1897c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1907c478bd9Sstevel@tonic-gate cleanpath(F->f_vnode->v_path); 1917c478bd9Sstevel@tonic-gate fi_offset = F == NULL ? 0 : F->f_offset; 1927c478bd9Sstevel@tonic-gate fi_fs = F == NULL ? "<none>" : stringof(F->f_vnode->v_op->vnop_name); 1937c478bd9Sstevel@tonic-gate fi_mount = F == NULL ? "<none>" : 1947c478bd9Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1957c478bd9Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1967c478bd9Sstevel@tonic-gate cleanpath(F->f_vnode->v_vfsp->vfs_vnodecovered->v_path); 1977c478bd9Sstevel@tonic-gate fi_oflags = F == NULL ? 0 : F->f_flag + (int)@FOPEN@; 1987c478bd9Sstevel@tonic-gate}; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gateinline fileinfo_t fds[int fd] = xlate <fileinfo_t> ( 2017c478bd9Sstevel@tonic-gate fd >= 0 && fd < curthread->t_procp->p_user.u_finfo.fi_nfiles ? 2027c478bd9Sstevel@tonic-gate curthread->t_procp->p_user.u_finfo.fi_list[fd].uf_file : NULL); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common fds 2057c478bd9Sstevel@tonic-gate#pragma D binding "1.1" fds 206*2bb1cb30Sbmc 207*2bb1cb30Sbmc#pragma D binding "1.2" translator 208*2bb1cb30Sbmctranslator fileinfo_t < struct vnode *V > { 209*2bb1cb30Sbmc fi_name = V->v_path == NULL ? "<unknown>" : 210*2bb1cb30Sbmc basename(cleanpath(V->v_path)); 211*2bb1cb30Sbmc fi_dirname = V->v_path == NULL ? "<unknown>" : 212*2bb1cb30Sbmc dirname(cleanpath(V->v_path)); 213*2bb1cb30Sbmc fi_pathname = V->v_path == NULL ? "<unknown>" : cleanpath(V->v_path); 214*2bb1cb30Sbmc fi_fs = stringof(V->v_op->vnop_name); 215*2bb1cb30Sbmc fi_mount = V->v_vfsp->vfs_vnodecovered == NULL ? "/" : 216*2bb1cb30Sbmc V->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 217*2bb1cb30Sbmc cleanpath(V->v_vfsp->vfs_vnodecovered->v_path); 218*2bb1cb30Sbmc}; 219