xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_fdio.c (revision a576ab5b6e08c47732b3dedca9eaa8a8cbb85720)
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
57f4f06d2Spetede  * Common Development and Distribution License (the "License").
67f4f06d2Spetede  * 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*a576ab5bSrab  * Copyright 2008 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 /*
297c478bd9Sstevel@tonic-gate  * File Descriptor I/O Backend
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  * Simple backend to pass though io_ops to the corresponding system calls on
327c478bd9Sstevel@tonic-gate  * an underlying fd.  We provide functions to create fdio objects using file
337c478bd9Sstevel@tonic-gate  * descriptors, explicit file names, and path lookups.  We save the complete
347c478bd9Sstevel@tonic-gate  * filename so that mdb_iob_name can be used to report the complete filename
357c478bd9Sstevel@tonic-gate  * of an open macro file in syntax error messages.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/param.h>
397c478bd9Sstevel@tonic-gate #include <sys/stat.h>
407c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
417c478bd9Sstevel@tonic-gate #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <errno.h>
447c478bd9Sstevel@tonic-gate #include <fcntl.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
477c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h>
487c478bd9Sstevel@tonic-gate #include <mdb/mdb_io_impl.h>
497c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct fd_data {
527c478bd9Sstevel@tonic-gate 	char fd_name[MAXPATHLEN];	/* Save filename for error messages */
537c478bd9Sstevel@tonic-gate 	int fd_fd;			/* File descriptor */
547c478bd9Sstevel@tonic-gate } fd_data_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate static ssize_t
577c478bd9Sstevel@tonic-gate fdio_read(mdb_io_t *io, void *buf, size_t nbytes)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	if (io->io_next == NULL)
627c478bd9Sstevel@tonic-gate 		return (read(fdp->fd_fd, buf, nbytes));
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	return (IOP_READ(io->io_next, buf, nbytes));
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static ssize_t
687c478bd9Sstevel@tonic-gate fdio_write(mdb_io_t *io, const void *buf, size_t nbytes)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	if (io->io_next == NULL)
737c478bd9Sstevel@tonic-gate 		return (write(fdp->fd_fd, buf, nbytes));
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	return (IOP_WRITE(io->io_next, buf, nbytes));
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate static off64_t
797c478bd9Sstevel@tonic-gate fdio_seek(mdb_io_t *io, off64_t offset, int whence)
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	if (io->io_next == NULL)
847c478bd9Sstevel@tonic-gate 		return (lseek64(fdp->fd_fd, offset, whence));
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	return (IOP_SEEK(io->io_next, offset, whence));
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static int
907c478bd9Sstevel@tonic-gate fdio_ctl(mdb_io_t *io, int req, void *arg)
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	if (io->io_next != NULL)
957c478bd9Sstevel@tonic-gate 		return (IOP_CTL(io->io_next, req, arg));
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	if (req == MDB_IOC_GETFD)
987c478bd9Sstevel@tonic-gate 		return (fdp->fd_fd);
997c478bd9Sstevel@tonic-gate 	else
1007c478bd9Sstevel@tonic-gate 		return (ioctl(fdp->fd_fd, req, arg));
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static void
1047c478bd9Sstevel@tonic-gate fdio_close(mdb_io_t *io)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	(void) close(fdp->fd_fd);
1097c478bd9Sstevel@tonic-gate 	mdb_free(fdp, sizeof (fd_data_t));
1107c478bd9Sstevel@tonic-gate }
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static const char *
1137c478bd9Sstevel@tonic-gate fdio_name(mdb_io_t *io)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	if (io->io_next == NULL)
1187c478bd9Sstevel@tonic-gate 		return (fdp->fd_name);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	return (IOP_NAME(io->io_next));
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate mdb_io_t *
1247c478bd9Sstevel@tonic-gate mdb_fdio_create_path(const char *path[], const char *fname,
1257c478bd9Sstevel@tonic-gate     int flags, mode_t mode)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	int fd;
1287f4f06d2Spetede 	char buf[MAXPATHLEN];
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	if (path != NULL && strchr(fname, '/') == NULL) {
1317c478bd9Sstevel@tonic-gate 		int i;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 		for (fd = -1, i = 0; path[i] != NULL; i++) {
1347c478bd9Sstevel@tonic-gate 			(void) mdb_iob_snprintf(buf, MAXPATHLEN, "%s/%s",
1357c478bd9Sstevel@tonic-gate 			    path[i], fname);
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 			if (access(buf, F_OK) == 0) {
1387c478bd9Sstevel@tonic-gate 				fd = open64(buf, flags, mode);
1397c478bd9Sstevel@tonic-gate 				fname = buf;
1407c478bd9Sstevel@tonic-gate 				break;
1417c478bd9Sstevel@tonic-gate 			}
1427c478bd9Sstevel@tonic-gate 		}
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 		if (fd == -1)
1457c478bd9Sstevel@tonic-gate 			(void) set_errno(ENOENT);
1467c478bd9Sstevel@tonic-gate 	} else
1477c478bd9Sstevel@tonic-gate 		fd = open64(fname, flags, mode);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	if (fd >= 0)
1507c478bd9Sstevel@tonic-gate 		return (mdb_fdio_create_named(fd, fname));
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	return (NULL);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate static const mdb_io_ops_t fdio_file_ops = {
1567c478bd9Sstevel@tonic-gate 	fdio_read,
1577c478bd9Sstevel@tonic-gate 	fdio_write,
1587c478bd9Sstevel@tonic-gate 	fdio_seek,
1597c478bd9Sstevel@tonic-gate 	fdio_ctl,
1607c478bd9Sstevel@tonic-gate 	fdio_close,
1617c478bd9Sstevel@tonic-gate 	fdio_name,
1627c478bd9Sstevel@tonic-gate 	no_io_link,
1637c478bd9Sstevel@tonic-gate 	no_io_unlink,
1647c478bd9Sstevel@tonic-gate 	no_io_setattr,
1657c478bd9Sstevel@tonic-gate 	no_io_suspend,
1667c478bd9Sstevel@tonic-gate 	no_io_resume
1677c478bd9Sstevel@tonic-gate };
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * In order to read from a block-oriented device, we pick up the seek pointer,
1717c478bd9Sstevel@tonic-gate  * read each containing block, and then copy the desired range of bytes back
1727c478bd9Sstevel@tonic-gate  * into the caller's buffer.  Unfortunately Solaris hardcodes the notion of
1737c478bd9Sstevel@tonic-gate  * DEV_BSIZE as the transfer unit for such devices; no ioctl() to obtain the
1747c478bd9Sstevel@tonic-gate  * transfer unit dynamically is currently available.  At the end of the
1757c478bd9Sstevel@tonic-gate  * transfer we reset the seek pointer to where the caller thinks it should be.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate static ssize_t
1787c478bd9Sstevel@tonic-gate fdio_bdev_read(mdb_io_t *io, void *buf, size_t nbytes)
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
1817c478bd9Sstevel@tonic-gate 	ssize_t resid = nbytes;
1827c478bd9Sstevel@tonic-gate 	uchar_t blk[DEV_BSIZE];
1837c478bd9Sstevel@tonic-gate 	off64_t off;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (io->io_next != NULL)
1867c478bd9Sstevel@tonic-gate 		return (IOP_READ(io->io_next, buf, nbytes));
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if ((off = lseek64(fdp->fd_fd, 0, SEEK_CUR)) == -1)
1897c478bd9Sstevel@tonic-gate 		return (-1); /* errno is set for us */
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	while (resid != 0) {
1927c478bd9Sstevel@tonic-gate 		off64_t devoff = off & ~(DEV_BSIZE - 1);
1937c478bd9Sstevel@tonic-gate 		size_t blkoff = off & (DEV_BSIZE - 1);
1947c478bd9Sstevel@tonic-gate 		size_t len = MIN(resid, DEV_BSIZE - blkoff);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 		if (pread64(fdp->fd_fd, blk, DEV_BSIZE, devoff) != DEV_BSIZE)
1977c478bd9Sstevel@tonic-gate 			break; /* errno is set for us, unless EOF */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 		bcopy(&blk[blkoff], buf, len);
2007c478bd9Sstevel@tonic-gate 		resid -= len;
2017c478bd9Sstevel@tonic-gate 		off += len;
2027c478bd9Sstevel@tonic-gate 		buf = (char *)buf + len;
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	if (resid == nbytes && nbytes != 0)
2067c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_EOF));
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	(void) lseek64(fdp->fd_fd, off, SEEK_SET);
2097c478bd9Sstevel@tonic-gate 	return (nbytes - resid);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * To perform a write to a block-oriented device, we use the same basic
2147c478bd9Sstevel@tonic-gate  * algorithm as fdio_bdev_read(), above.  In the inner loop, we read an
2157c478bd9Sstevel@tonic-gate  * entire block, modify it using the data from the caller's buffer, and
2167c478bd9Sstevel@tonic-gate  * then write the entire block back to the device.
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate static ssize_t
2197c478bd9Sstevel@tonic-gate fdio_bdev_write(mdb_io_t *io, const void *buf, size_t nbytes)
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
2227c478bd9Sstevel@tonic-gate 	ssize_t resid = nbytes;
2237c478bd9Sstevel@tonic-gate 	uchar_t blk[DEV_BSIZE];
2247c478bd9Sstevel@tonic-gate 	off64_t off;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	if (io->io_next != NULL)
2277c478bd9Sstevel@tonic-gate 		return (IOP_WRITE(io->io_next, buf, nbytes));
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	if ((off = lseek64(fdp->fd_fd, 0, SEEK_CUR)) == -1)
2307c478bd9Sstevel@tonic-gate 		return (-1); /* errno is set for us */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	while (resid != 0) {
2337c478bd9Sstevel@tonic-gate 		off64_t devoff = off & ~(DEV_BSIZE - 1);
2347c478bd9Sstevel@tonic-gate 		size_t blkoff = off & (DEV_BSIZE - 1);
2357c478bd9Sstevel@tonic-gate 		size_t len = MIN(resid, DEV_BSIZE - blkoff);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 		if (pread64(fdp->fd_fd, blk, DEV_BSIZE, devoff) != DEV_BSIZE)
2387c478bd9Sstevel@tonic-gate 			break; /* errno is set for us, unless EOF */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 		bcopy(buf, &blk[blkoff], len);
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 		if (pwrite64(fdp->fd_fd, blk, DEV_BSIZE, devoff) != DEV_BSIZE)
2437c478bd9Sstevel@tonic-gate 			break; /* errno is set for us, unless EOF */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 		resid -= len;
2467c478bd9Sstevel@tonic-gate 		off += len;
2477c478bd9Sstevel@tonic-gate 		buf = (char *)buf + len;
2487c478bd9Sstevel@tonic-gate 	}
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	if (resid == nbytes && nbytes != 0)
2517c478bd9Sstevel@tonic-gate 		return (set_errno(EMDB_EOF));
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	(void) lseek64(fdp->fd_fd, off, SEEK_SET);
2547c478bd9Sstevel@tonic-gate 	return (nbytes - resid);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate static const mdb_io_ops_t fdio_bdev_ops = {
2587c478bd9Sstevel@tonic-gate 	fdio_bdev_read,
2597c478bd9Sstevel@tonic-gate 	fdio_bdev_write,
2607c478bd9Sstevel@tonic-gate 	fdio_seek,
2617c478bd9Sstevel@tonic-gate 	fdio_ctl,
2627c478bd9Sstevel@tonic-gate 	fdio_close,
2637c478bd9Sstevel@tonic-gate 	fdio_name,
2647c478bd9Sstevel@tonic-gate 	no_io_link,
2657c478bd9Sstevel@tonic-gate 	no_io_unlink,
2667c478bd9Sstevel@tonic-gate 	no_io_setattr,
2677c478bd9Sstevel@tonic-gate 	no_io_suspend,
2687c478bd9Sstevel@tonic-gate 	no_io_resume
2697c478bd9Sstevel@tonic-gate };
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate mdb_io_t *
2727c478bd9Sstevel@tonic-gate mdb_fdio_create(int fd)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	mdb_io_t *io = mdb_alloc(sizeof (mdb_io_t), UM_SLEEP);
2757c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = mdb_alloc(sizeof (fd_data_t), UM_SLEEP);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	struct dk_cinfo info;
2787c478bd9Sstevel@tonic-gate 	struct stat64 st;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	switch (fd) {
2817c478bd9Sstevel@tonic-gate 	case STDIN_FILENO:
2827c478bd9Sstevel@tonic-gate 		(void) strcpy(fdp->fd_name, "(stdin)");
2837c478bd9Sstevel@tonic-gate 		break;
2847c478bd9Sstevel@tonic-gate 	case STDOUT_FILENO:
2857c478bd9Sstevel@tonic-gate 		(void) strcpy(fdp->fd_name, "(stdout)");
2867c478bd9Sstevel@tonic-gate 		break;
2877c478bd9Sstevel@tonic-gate 	case STDERR_FILENO:
2887c478bd9Sstevel@tonic-gate 		(void) strcpy(fdp->fd_name, "(stderr)");
2897c478bd9Sstevel@tonic-gate 		break;
2907c478bd9Sstevel@tonic-gate 	default:
2917c478bd9Sstevel@tonic-gate 		(void) mdb_iob_snprintf(fdp->fd_name, MAXPATHLEN, "fd %d", fd);
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	fdp->fd_fd = fd;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	/*
2977c478bd9Sstevel@tonic-gate 	 * We determine if something is a raw block-oriented disk device by
2987c478bd9Sstevel@tonic-gate 	 * testing to see if it is a character device that supports DKIOCINFO.
2997c478bd9Sstevel@tonic-gate 	 * If we are operating on a disk in raw mode, we must do our own
3007c478bd9Sstevel@tonic-gate 	 * block-oriented i/o; otherwise we can just use read() and write().
3017c478bd9Sstevel@tonic-gate 	 */
3027c478bd9Sstevel@tonic-gate 	if (fstat64(fd, &st) == 0 && S_ISCHR(st.st_mode) &&
3037c478bd9Sstevel@tonic-gate 	    ioctl(fd, DKIOCINFO, &info) == 0)
3047c478bd9Sstevel@tonic-gate 		io->io_ops = &fdio_bdev_ops;
3057c478bd9Sstevel@tonic-gate 	else
3067c478bd9Sstevel@tonic-gate 		io->io_ops = &fdio_file_ops;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	io->io_data = fdp;
3097c478bd9Sstevel@tonic-gate 	io->io_next = NULL;
3107c478bd9Sstevel@tonic-gate 	io->io_refcnt = 0;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	return (io);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate mdb_io_t *
3167c478bd9Sstevel@tonic-gate mdb_fdio_create_named(int fd, const char *name)
3177c478bd9Sstevel@tonic-gate {
3187c478bd9Sstevel@tonic-gate 	mdb_io_t *io = mdb_fdio_create(fd);
3197c478bd9Sstevel@tonic-gate 	fd_data_t *fdp = io->io_data;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	(void) strncpy(fdp->fd_name, name, MAXPATHLEN);
3227c478bd9Sstevel@tonic-gate 	fdp->fd_name[MAXPATHLEN - 1] = '\0';
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	return (io);
3257c478bd9Sstevel@tonic-gate }
326*a576ab5bSrab 
327*a576ab5bSrab int
328*a576ab5bSrab mdb_fdio_fileno(mdb_io_t *io)
329*a576ab5bSrab {
330*a576ab5bSrab 	fd_data_t *fdp = io->io_data;
331*a576ab5bSrab 	return (fdp->fd_fd);
332*a576ab5bSrab }
333