10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1738Sbmc * Common Development and Distribution License (the "License"). 6*1738Sbmc * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate/* 22*1738Sbmc * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate#pragma D depends_on module unix 290Sstevel@tonic-gate#pragma D depends_on provider io 300Sstevel@tonic-gate 310Sstevel@tonic-gateinline int B_BUSY = @B_BUSY@; 320Sstevel@tonic-gate#pragma D binding "1.0" B_BUSY 330Sstevel@tonic-gateinline int B_DONE = @B_DONE@; 340Sstevel@tonic-gate#pragma D binding "1.0" B_DONE 350Sstevel@tonic-gateinline int B_ERROR = @B_ERROR@; 360Sstevel@tonic-gate#pragma D binding "1.0" B_ERROR 370Sstevel@tonic-gateinline int B_PAGEIO = @B_PAGEIO@; 380Sstevel@tonic-gate#pragma D binding "1.0" B_PAGEIO 390Sstevel@tonic-gateinline int B_PHYS = @B_PHYS@; 400Sstevel@tonic-gate#pragma D binding "1.0" B_PHYS 410Sstevel@tonic-gateinline int B_READ = @B_READ@; 420Sstevel@tonic-gate#pragma D binding "1.0" B_READ 430Sstevel@tonic-gateinline int B_WRITE = @B_WRITE@; 440Sstevel@tonic-gate#pragma D binding "1.0" B_WRITE 450Sstevel@tonic-gateinline int B_ASYNC = @B_ASYNC@; 460Sstevel@tonic-gate#pragma D binding "1.0" B_ASYNC 470Sstevel@tonic-gate 480Sstevel@tonic-gatetypedef struct bufinfo { 490Sstevel@tonic-gate int b_flags; /* buffer status */ 500Sstevel@tonic-gate size_t b_bcount; /* number of bytes */ 510Sstevel@tonic-gate caddr_t b_addr; /* buffer address */ 520Sstevel@tonic-gate uint64_t b_lblkno; /* block # on device */ 530Sstevel@tonic-gate uint64_t b_blkno; /* expanded block # on device */ 540Sstevel@tonic-gate size_t b_resid; /* # of bytes not transferred */ 550Sstevel@tonic-gate size_t b_bufsize; /* size of allocated buffer */ 560Sstevel@tonic-gate caddr_t b_iodone; /* I/O completion routine */ 570Sstevel@tonic-gate int b_error; /* expanded error field */ 580Sstevel@tonic-gate dev_t b_edev; /* extended device */ 590Sstevel@tonic-gate} bufinfo_t; 600Sstevel@tonic-gate 610Sstevel@tonic-gate#pragma D binding "1.0" translator 620Sstevel@tonic-gatetranslator bufinfo_t < struct buf *B > { 630Sstevel@tonic-gate b_flags = B->b_flags; 640Sstevel@tonic-gate b_addr = B->b_un.b_addr; 650Sstevel@tonic-gate b_bcount = B->b_bcount; 660Sstevel@tonic-gate b_lblkno = B->_b_blkno._f; 670Sstevel@tonic-gate b_blkno = sizeof (long) == 8 ? B->_b_blkno._f : B->_b_blkno._p._l; 680Sstevel@tonic-gate b_resid = B->b_resid; 690Sstevel@tonic-gate b_bufsize = B->b_bufsize; 700Sstevel@tonic-gate b_iodone = (caddr_t)B->b_iodone; 710Sstevel@tonic-gate b_error = B->b_error; 720Sstevel@tonic-gate b_edev = B->b_edev; 730Sstevel@tonic-gate}; 740Sstevel@tonic-gate 750Sstevel@tonic-gatetypedef struct devinfo { 760Sstevel@tonic-gate int dev_major; /* major number */ 770Sstevel@tonic-gate int dev_minor; /* minor number */ 780Sstevel@tonic-gate int dev_instance; /* instance number */ 790Sstevel@tonic-gate string dev_name; /* name of device */ 800Sstevel@tonic-gate string dev_statname; /* name of device + instance/minor */ 810Sstevel@tonic-gate string dev_pathname; /* pathname of device */ 820Sstevel@tonic-gate} devinfo_t; 830Sstevel@tonic-gate 840Sstevel@tonic-gate#pragma D binding "1.0" translator 850Sstevel@tonic-gatetranslator devinfo_t < struct buf *B > { 860Sstevel@tonic-gate dev_major = B->b_dip != NULL ? getmajor(B->b_edev) : 870Sstevel@tonic-gate getmajor(B->b_file->v_vfsp->vfs_dev); 880Sstevel@tonic-gate dev_minor = B->b_dip != NULL ? getminor(B->b_edev) : 890Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev); 900Sstevel@tonic-gate dev_instance = B->b_dip == NULL ? 910Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev) : 920Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance; 930Sstevel@tonic-gate dev_name = B->b_dip == NULL ? "nfs" : 940Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name); 950Sstevel@tonic-gate dev_statname = strjoin(B->b_dip == NULL ? "nfs" : 960Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name), 970Sstevel@tonic-gate lltostr(B->b_dip == NULL ? getminor(B->b_file->v_vfsp->vfs_dev) : 980Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance == 0 && 990Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent != NULL && 1000Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent->devi_node_name == 1010Sstevel@tonic-gate "pseudo" ? getminor(B->b_edev) : 1020Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance)); 1030Sstevel@tonic-gate dev_pathname = B->b_dip == NULL ? "<nfs>" : 1040Sstevel@tonic-gate ddi_pathname(B->b_dip, getminor(B->b_edev)); 1050Sstevel@tonic-gate}; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gatetypedef struct fileinfo { 1080Sstevel@tonic-gate string fi_name; /* name (basename of fi_pathname) */ 1090Sstevel@tonic-gate string fi_dirname; /* directory (dirname of fi_pathname) */ 1100Sstevel@tonic-gate string fi_pathname; /* full pathname */ 1110Sstevel@tonic-gate offset_t fi_offset; /* offset within file */ 1120Sstevel@tonic-gate string fi_fs; /* filesystem */ 1130Sstevel@tonic-gate string fi_mount; /* mount point of file system */ 1140Sstevel@tonic-gate int fi_oflags; /* open(2) flags for file descriptor */ 1150Sstevel@tonic-gate} fileinfo_t; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate#pragma D binding "1.0" translator 1180Sstevel@tonic-gatetranslator fileinfo_t < struct buf *B > { 1190Sstevel@tonic-gate fi_name = B->b_file == NULL ? "<none>" : 1200Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1210Sstevel@tonic-gate basename(cleanpath(B->b_file->v_path)); 1220Sstevel@tonic-gate fi_dirname = B->b_file == NULL ? "<none>" : 1230Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1240Sstevel@tonic-gate dirname(cleanpath(B->b_file->v_path)); 1250Sstevel@tonic-gate fi_pathname = B->b_file == NULL ? "<none>" : 1260Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1270Sstevel@tonic-gate cleanpath(B->b_file->v_path); 1280Sstevel@tonic-gate fi_offset = B->b_offset; 1290Sstevel@tonic-gate fi_fs = B->b_file == NULL ? "<none>" : 1300Sstevel@tonic-gate stringof(B->b_file->v_op->vnop_name); 1310Sstevel@tonic-gate fi_mount = B->b_file == NULL ? "<none>" : 1320Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1330Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1340Sstevel@tonic-gate cleanpath(B->b_file->v_vfsp->vfs_vnodecovered->v_path); 1350Sstevel@tonic-gate fi_oflags = 0; 1360Sstevel@tonic-gate}; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate/* 1390Sstevel@tonic-gate * The following inline constants can be used to examine fi_oflags when using 1400Sstevel@tonic-gate * the fds[] array or a translated fileinfo_t. Note that the various open 1410Sstevel@tonic-gate * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR. 1420Sstevel@tonic-gate * To test the open mode, you write code similar to that used with the fcntl(2) 1430Sstevel@tonic-gate * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY). 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gateinline int O_ACCMODE = @O_ACCMODE@; 1460Sstevel@tonic-gate#pragma D binding "1.1" O_ACCMODE 1470Sstevel@tonic-gate 1480Sstevel@tonic-gateinline int O_RDONLY = @O_RDONLY@; 1490Sstevel@tonic-gate#pragma D binding "1.1" O_RDONLY 1500Sstevel@tonic-gateinline int O_WRONLY = @O_WRONLY@; 1510Sstevel@tonic-gate#pragma D binding "1.1" O_WRONLY 1520Sstevel@tonic-gateinline int O_RDWR = @O_RDWR@; 1530Sstevel@tonic-gate#pragma D binding "1.1" O_RDWR 1540Sstevel@tonic-gate 1550Sstevel@tonic-gateinline int O_APPEND = @O_APPEND@; 1560Sstevel@tonic-gate#pragma D binding "1.1" O_APPEND 1570Sstevel@tonic-gateinline int O_CREAT = @O_CREAT@; 1580Sstevel@tonic-gate#pragma D binding "1.1" O_CREAT 1590Sstevel@tonic-gateinline int O_DSYNC = @O_DSYNC@; 1600Sstevel@tonic-gate#pragma D binding "1.1" O_DSYNC 1610Sstevel@tonic-gateinline int O_EXCL = @O_EXCL@; 1620Sstevel@tonic-gate#pragma D binding "1.1" O_EXCL 1630Sstevel@tonic-gateinline int O_LARGEFILE = @O_LARGEFILE@; 1640Sstevel@tonic-gate#pragma D binding "1.1" O_LARGEFILE 1650Sstevel@tonic-gateinline int O_NOCTTY = @O_NOCTTY@; 1660Sstevel@tonic-gate#pragma D binding "1.1" O_NOCTTY 1670Sstevel@tonic-gateinline int O_NONBLOCK = @O_NONBLOCK@; 1680Sstevel@tonic-gate#pragma D binding "1.1" O_NONBLOCK 1690Sstevel@tonic-gateinline int O_NDELAY = @O_NDELAY@; 1700Sstevel@tonic-gate#pragma D binding "1.1" O_NDELAY 1710Sstevel@tonic-gateinline int O_RSYNC = @O_RSYNC@; 1720Sstevel@tonic-gate#pragma D binding "1.1" O_RSYNC 1730Sstevel@tonic-gateinline int O_SYNC = @O_SYNC@; 1740Sstevel@tonic-gate#pragma D binding "1.1" O_SYNC 1750Sstevel@tonic-gateinline int O_TRUNC = @O_TRUNC@; 1760Sstevel@tonic-gate#pragma D binding "1.1" O_TRUNC 1770Sstevel@tonic-gateinline int O_XATTR = @O_XATTR@; 1780Sstevel@tonic-gate#pragma D binding "1.1" O_XATTR 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate#pragma D binding "1.1" translator 1810Sstevel@tonic-gatetranslator fileinfo_t < struct file *F > { 1820Sstevel@tonic-gate fi_name = F == NULL ? "<none>" : 1830Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1840Sstevel@tonic-gate basename(cleanpath(F->f_vnode->v_path)); 1850Sstevel@tonic-gate fi_dirname = F == NULL ? "<none>" : 1860Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1870Sstevel@tonic-gate dirname(cleanpath(F->f_vnode->v_path)); 1880Sstevel@tonic-gate fi_pathname = F == NULL ? "<none>" : 1890Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1900Sstevel@tonic-gate cleanpath(F->f_vnode->v_path); 1910Sstevel@tonic-gate fi_offset = F == NULL ? 0 : F->f_offset; 1920Sstevel@tonic-gate fi_fs = F == NULL ? "<none>" : stringof(F->f_vnode->v_op->vnop_name); 1930Sstevel@tonic-gate fi_mount = F == NULL ? "<none>" : 1940Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1950Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1960Sstevel@tonic-gate cleanpath(F->f_vnode->v_vfsp->vfs_vnodecovered->v_path); 1970Sstevel@tonic-gate fi_oflags = F == NULL ? 0 : F->f_flag + (int)@FOPEN@; 1980Sstevel@tonic-gate}; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gateinline fileinfo_t fds[int fd] = xlate <fileinfo_t> ( 2010Sstevel@tonic-gate fd >= 0 && fd < curthread->t_procp->p_user.u_finfo.fi_nfiles ? 2020Sstevel@tonic-gate curthread->t_procp->p_user.u_finfo.fi_list[fd].uf_file : NULL); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common fds 2050Sstevel@tonic-gate#pragma D binding "1.1" fds 206*1738Sbmc 207*1738Sbmc#pragma D binding "1.2" translator 208*1738Sbmctranslator fileinfo_t < struct vnode *V > { 209*1738Sbmc fi_name = V->v_path == NULL ? "<unknown>" : 210*1738Sbmc basename(cleanpath(V->v_path)); 211*1738Sbmc fi_dirname = V->v_path == NULL ? "<unknown>" : 212*1738Sbmc dirname(cleanpath(V->v_path)); 213*1738Sbmc fi_pathname = V->v_path == NULL ? "<unknown>" : cleanpath(V->v_path); 214*1738Sbmc fi_fs = stringof(V->v_op->vnop_name); 215*1738Sbmc fi_mount = V->v_vfsp->vfs_vnodecovered == NULL ? "/" : 216*1738Sbmc V->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 217*1738Sbmc cleanpath(V->v_vfsp->vfs_vnodecovered->v_path); 218*1738Sbmc}; 219