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 52bb1cb30Sbmc * Common Development and Distribution License (the "License"). 62bb1cb30Sbmc * 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/* 222bb1cb30Sbmc * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 26*b0f673c4SBryan Cantrill/* 27*b0f673c4SBryan Cantrill * Copyright (c) 2012, Joyent, Inc. All rights reserved. 28*b0f673c4SBryan Cantrill */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate#pragma D depends_on module unix 317c478bd9Sstevel@tonic-gate#pragma D depends_on provider io 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gateinline int B_BUSY = @B_BUSY@; 347c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_BUSY 357c478bd9Sstevel@tonic-gateinline int B_DONE = @B_DONE@; 367c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_DONE 377c478bd9Sstevel@tonic-gateinline int B_ERROR = @B_ERROR@; 387c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ERROR 397c478bd9Sstevel@tonic-gateinline int B_PAGEIO = @B_PAGEIO@; 407c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PAGEIO 417c478bd9Sstevel@tonic-gateinline int B_PHYS = @B_PHYS@; 427c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_PHYS 437c478bd9Sstevel@tonic-gateinline int B_READ = @B_READ@; 447c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_READ 457c478bd9Sstevel@tonic-gateinline int B_WRITE = @B_WRITE@; 467c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_WRITE 477c478bd9Sstevel@tonic-gateinline int B_ASYNC = @B_ASYNC@; 487c478bd9Sstevel@tonic-gate#pragma D binding "1.0" B_ASYNC 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gatetypedef struct bufinfo { 517c478bd9Sstevel@tonic-gate int b_flags; /* buffer status */ 527c478bd9Sstevel@tonic-gate size_t b_bcount; /* number of bytes */ 537c478bd9Sstevel@tonic-gate caddr_t b_addr; /* buffer address */ 547c478bd9Sstevel@tonic-gate uint64_t b_lblkno; /* block # on device */ 557c478bd9Sstevel@tonic-gate uint64_t b_blkno; /* expanded block # on device */ 567c478bd9Sstevel@tonic-gate size_t b_resid; /* # of bytes not transferred */ 577c478bd9Sstevel@tonic-gate size_t b_bufsize; /* size of allocated buffer */ 587c478bd9Sstevel@tonic-gate caddr_t b_iodone; /* I/O completion routine */ 597c478bd9Sstevel@tonic-gate int b_error; /* expanded error field */ 607c478bd9Sstevel@tonic-gate dev_t b_edev; /* extended device */ 617c478bd9Sstevel@tonic-gate} bufinfo_t; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 647c478bd9Sstevel@tonic-gatetranslator bufinfo_t < struct buf *B > { 657c478bd9Sstevel@tonic-gate b_flags = B->b_flags; 667c478bd9Sstevel@tonic-gate b_addr = B->b_un.b_addr; 677c478bd9Sstevel@tonic-gate b_bcount = B->b_bcount; 687c478bd9Sstevel@tonic-gate b_lblkno = B->_b_blkno._f; 697c478bd9Sstevel@tonic-gate b_blkno = sizeof (long) == 8 ? B->_b_blkno._f : B->_b_blkno._p._l; 707c478bd9Sstevel@tonic-gate b_resid = B->b_resid; 717c478bd9Sstevel@tonic-gate b_bufsize = B->b_bufsize; 727c478bd9Sstevel@tonic-gate b_iodone = (caddr_t)B->b_iodone; 737c478bd9Sstevel@tonic-gate b_error = B->b_error; 747c478bd9Sstevel@tonic-gate b_edev = B->b_edev; 757c478bd9Sstevel@tonic-gate}; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gatetypedef struct devinfo { 787c478bd9Sstevel@tonic-gate int dev_major; /* major number */ 797c478bd9Sstevel@tonic-gate int dev_minor; /* minor number */ 807c478bd9Sstevel@tonic-gate int dev_instance; /* instance number */ 817c478bd9Sstevel@tonic-gate string dev_name; /* name of device */ 827c478bd9Sstevel@tonic-gate string dev_statname; /* name of device + instance/minor */ 837c478bd9Sstevel@tonic-gate string dev_pathname; /* pathname of device */ 847c478bd9Sstevel@tonic-gate} devinfo_t; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 877c478bd9Sstevel@tonic-gatetranslator devinfo_t < struct buf *B > { 887c478bd9Sstevel@tonic-gate dev_major = B->b_dip != NULL ? getmajor(B->b_edev) : 897c478bd9Sstevel@tonic-gate getmajor(B->b_file->v_vfsp->vfs_dev); 907c478bd9Sstevel@tonic-gate dev_minor = B->b_dip != NULL ? getminor(B->b_edev) : 917c478bd9Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev); 927c478bd9Sstevel@tonic-gate dev_instance = B->b_dip == NULL ? 937c478bd9Sstevel@tonic-gate getminor(B->b_file->v_vfsp->vfs_dev) : 947c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance; 957c478bd9Sstevel@tonic-gate dev_name = B->b_dip == NULL ? "nfs" : 967c478bd9Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name); 977c478bd9Sstevel@tonic-gate dev_statname = strjoin(B->b_dip == NULL ? "nfs" : 987c478bd9Sstevel@tonic-gate stringof(`devnamesp[getmajor(B->b_edev)].dn_name), 997c478bd9Sstevel@tonic-gate lltostr(B->b_dip == NULL ? getminor(B->b_file->v_vfsp->vfs_dev) : 1007c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance == 0 && 1017c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent != NULL && 1027c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_parent->devi_node_name == 1037c478bd9Sstevel@tonic-gate "pseudo" ? getminor(B->b_edev) : 1047c478bd9Sstevel@tonic-gate ((struct dev_info *)B->b_dip)->devi_instance)); 1057c478bd9Sstevel@tonic-gate dev_pathname = B->b_dip == NULL ? "<nfs>" : 1067c478bd9Sstevel@tonic-gate ddi_pathname(B->b_dip, getminor(B->b_edev)); 1077c478bd9Sstevel@tonic-gate}; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gatetypedef struct fileinfo { 1107c478bd9Sstevel@tonic-gate string fi_name; /* name (basename of fi_pathname) */ 1117c478bd9Sstevel@tonic-gate string fi_dirname; /* directory (dirname of fi_pathname) */ 1127c478bd9Sstevel@tonic-gate string fi_pathname; /* full pathname */ 1137c478bd9Sstevel@tonic-gate offset_t fi_offset; /* offset within file */ 1147c478bd9Sstevel@tonic-gate string fi_fs; /* filesystem */ 1157c478bd9Sstevel@tonic-gate string fi_mount; /* mount point of file system */ 1167c478bd9Sstevel@tonic-gate int fi_oflags; /* open(2) flags for file descriptor */ 1177c478bd9Sstevel@tonic-gate} fileinfo_t; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate#pragma D binding "1.0" translator 1207c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct buf *B > { 1217c478bd9Sstevel@tonic-gate fi_name = B->b_file == NULL ? "<none>" : 1227c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1237c478bd9Sstevel@tonic-gate basename(cleanpath(B->b_file->v_path)); 1247c478bd9Sstevel@tonic-gate fi_dirname = B->b_file == NULL ? "<none>" : 1257c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1267c478bd9Sstevel@tonic-gate dirname(cleanpath(B->b_file->v_path)); 1277c478bd9Sstevel@tonic-gate fi_pathname = B->b_file == NULL ? "<none>" : 1287c478bd9Sstevel@tonic-gate B->b_file->v_path == NULL ? "<unknown>" : 1297c478bd9Sstevel@tonic-gate cleanpath(B->b_file->v_path); 1307c478bd9Sstevel@tonic-gate fi_offset = B->b_offset; 1317c478bd9Sstevel@tonic-gate fi_fs = B->b_file == NULL ? "<none>" : 1327c478bd9Sstevel@tonic-gate stringof(B->b_file->v_op->vnop_name); 1337c478bd9Sstevel@tonic-gate fi_mount = B->b_file == NULL ? "<none>" : 1347c478bd9Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1357c478bd9Sstevel@tonic-gate B->b_file->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1367c478bd9Sstevel@tonic-gate cleanpath(B->b_file->v_vfsp->vfs_vnodecovered->v_path); 1377c478bd9Sstevel@tonic-gate fi_oflags = 0; 1387c478bd9Sstevel@tonic-gate}; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate/* 1417c478bd9Sstevel@tonic-gate * The following inline constants can be used to examine fi_oflags when using 1427c478bd9Sstevel@tonic-gate * the fds[] array or a translated fileinfo_t. Note that the various open 1437c478bd9Sstevel@tonic-gate * flags behave as a bit-field *except* for O_RDONLY, O_WRONLY, and O_RDWR. 1447c478bd9Sstevel@tonic-gate * To test the open mode, you write code similar to that used with the fcntl(2) 1457c478bd9Sstevel@tonic-gate * F_GET[X]FL command, such as: if ((fi_oflags & O_ACCMODE) == O_WRONLY). 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gateinline int O_ACCMODE = @O_ACCMODE@; 1487c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_ACCMODE 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gateinline int O_RDONLY = @O_RDONLY@; 1517c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDONLY 1527c478bd9Sstevel@tonic-gateinline int O_WRONLY = @O_WRONLY@; 1537c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_WRONLY 1547c478bd9Sstevel@tonic-gateinline int O_RDWR = @O_RDWR@; 1557c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RDWR 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gateinline int O_APPEND = @O_APPEND@; 1587c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_APPEND 1597c478bd9Sstevel@tonic-gateinline int O_CREAT = @O_CREAT@; 1607c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_CREAT 1617c478bd9Sstevel@tonic-gateinline int O_DSYNC = @O_DSYNC@; 1627c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_DSYNC 1637c478bd9Sstevel@tonic-gateinline int O_EXCL = @O_EXCL@; 1647c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_EXCL 1657c478bd9Sstevel@tonic-gateinline int O_LARGEFILE = @O_LARGEFILE@; 1667c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_LARGEFILE 1677c478bd9Sstevel@tonic-gateinline int O_NOCTTY = @O_NOCTTY@; 1687c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NOCTTY 1697c478bd9Sstevel@tonic-gateinline int O_NONBLOCK = @O_NONBLOCK@; 1707c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NONBLOCK 1717c478bd9Sstevel@tonic-gateinline int O_NDELAY = @O_NDELAY@; 1727c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_NDELAY 1737c478bd9Sstevel@tonic-gateinline int O_RSYNC = @O_RSYNC@; 1747c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_RSYNC 1757c478bd9Sstevel@tonic-gateinline int O_SYNC = @O_SYNC@; 1767c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_SYNC 1777c478bd9Sstevel@tonic-gateinline int O_TRUNC = @O_TRUNC@; 1787c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_TRUNC 1797c478bd9Sstevel@tonic-gateinline int O_XATTR = @O_XATTR@; 1807c478bd9Sstevel@tonic-gate#pragma D binding "1.1" O_XATTR 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate#pragma D binding "1.1" translator 1837c478bd9Sstevel@tonic-gatetranslator fileinfo_t < struct file *F > { 1847c478bd9Sstevel@tonic-gate fi_name = F == NULL ? "<none>" : 1857c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1867c478bd9Sstevel@tonic-gate basename(cleanpath(F->f_vnode->v_path)); 1877c478bd9Sstevel@tonic-gate fi_dirname = F == NULL ? "<none>" : 1887c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1897c478bd9Sstevel@tonic-gate dirname(cleanpath(F->f_vnode->v_path)); 1907c478bd9Sstevel@tonic-gate fi_pathname = F == NULL ? "<none>" : 1917c478bd9Sstevel@tonic-gate F->f_vnode->v_path == NULL ? "<unknown>" : 1927c478bd9Sstevel@tonic-gate cleanpath(F->f_vnode->v_path); 1937c478bd9Sstevel@tonic-gate fi_offset = F == NULL ? 0 : F->f_offset; 1947c478bd9Sstevel@tonic-gate fi_fs = F == NULL ? "<none>" : stringof(F->f_vnode->v_op->vnop_name); 1957c478bd9Sstevel@tonic-gate fi_mount = F == NULL ? "<none>" : 1967c478bd9Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered == NULL ? "/" : 1977c478bd9Sstevel@tonic-gate F->f_vnode->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 1987c478bd9Sstevel@tonic-gate cleanpath(F->f_vnode->v_vfsp->vfs_vnodecovered->v_path); 1997c478bd9Sstevel@tonic-gate fi_oflags = F == NULL ? 0 : F->f_flag + (int)@FOPEN@; 2007c478bd9Sstevel@tonic-gate}; 2017c478bd9Sstevel@tonic-gate 202*b0f673c4SBryan Cantrillinline fileinfo_t fds[int fd] = xlate <fileinfo_t> (getf(fd)); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate#pragma D attributes Stable/Stable/Common fds 2057c478bd9Sstevel@tonic-gate#pragma D binding "1.1" fds 2062bb1cb30Sbmc 2072bb1cb30Sbmc#pragma D binding "1.2" translator 2082bb1cb30Sbmctranslator fileinfo_t < struct vnode *V > { 2092bb1cb30Sbmc fi_name = V->v_path == NULL ? "<unknown>" : 2102bb1cb30Sbmc basename(cleanpath(V->v_path)); 2112bb1cb30Sbmc fi_dirname = V->v_path == NULL ? "<unknown>" : 2122bb1cb30Sbmc dirname(cleanpath(V->v_path)); 2132bb1cb30Sbmc fi_pathname = V->v_path == NULL ? "<unknown>" : cleanpath(V->v_path); 2142bb1cb30Sbmc fi_fs = stringof(V->v_op->vnop_name); 2152bb1cb30Sbmc fi_mount = V->v_vfsp->vfs_vnodecovered == NULL ? "/" : 2162bb1cb30Sbmc V->v_vfsp->vfs_vnodecovered->v_path == NULL ? "<unknown>" : 2172bb1cb30Sbmc cleanpath(V->v_vfsp->vfs_vnodecovered->v_path); 2182bb1cb30Sbmc}; 219