static ssize_t logio_write(mdb_io_t *io, const void *buf, size_t nbytes) { mdb_io_t *logio = io->io_data; ssize_t wbytes; if (io->io_next != NULL) { wbytes = IOP_WRITE(io->io_next, buf, nbytes); if (wbytes > 0) (void) IOP_WRITE(logio, buf, wbytes); return (wbytes); } return (-1); }
static ssize_t logio_read(mdb_io_t *io, void *buf, size_t nbytes) { mdb_io_t *logio = io->io_data; ssize_t rbytes; if (io->io_next != NULL) { rbytes = IOP_READ(io->io_next, buf, nbytes); if (rbytes > 0) { (void) IOP_WRITE(logio, mdb.m_prompt, mdb.m_promptlen); (void) IOP_WRITE(logio, buf, rbytes); } return (rbytes); } return (-1); }
static ssize_t pio_write(mdb_io_t *io, const void *buf, size_t nbytes) { pio_data_t *pdp = io->io_data; if (io->io_next == NULL) return (kmdb_prom_write(buf, nbytes, &pdp->pio_ti)); return (IOP_WRITE(io->io_next, buf, nbytes)); }
static ssize_t fdio_write(mdb_io_t *io, const void *buf, size_t nbytes) { fd_data_t *fdp = io->io_data; if (io->io_next == NULL) return (write(fdp->fd_fd, buf, nbytes)); return (IOP_WRITE(io->io_next, buf, nbytes)); }
static ssize_t rf_write(mdb_io_t *io, const void *buf, size_t nbytes, uint64_t addr) { if (io == NULL) return (set_errno(EMDB_NOMAP)); if (IOP_SEEK(io, addr, SEEK_SET) == -1) return (-1); /* errno is set for us */ return (IOP_WRITE(io, buf, nbytes)); }
/* * To perform a write to a block-oriented device, we use the same basic * algorithm as fdio_bdev_read(), above. In the inner loop, we read an * entire block, modify it using the data from the caller's buffer, and * then write the entire block back to the device. */ static ssize_t fdio_bdev_write(mdb_io_t *io, const void *buf, size_t nbytes) { fd_data_t *fdp = io->io_data; ssize_t resid = nbytes; uchar_t blk[DEV_BSIZE]; off64_t off; if (io->io_next != NULL) return (IOP_WRITE(io->io_next, buf, nbytes)); if ((off = lseek64(fdp->fd_fd, 0, SEEK_CUR)) == -1) return (-1); /* errno is set for us */ while (resid != 0) { off64_t devoff = off & ~(DEV_BSIZE - 1); size_t blkoff = off & (DEV_BSIZE - 1); size_t len = MIN(resid, DEV_BSIZE - blkoff); if (pread64(fdp->fd_fd, blk, DEV_BSIZE, devoff) != DEV_BSIZE) break; /* errno is set for us, unless EOF */ bcopy(buf, &blk[blkoff], len); if (pwrite64(fdp->fd_fd, blk, DEV_BSIZE, devoff) != DEV_BSIZE) break; /* errno is set for us, unless EOF */ resid -= len; off += len; buf = (char *)buf + len; } if (resid == nbytes && nbytes != 0) return (set_errno(EMDB_EOF)); (void) lseek64(fdp->fd_fd, off, SEEK_SET); return (nbytes - resid); }