On Sat, May 27, 2017 at 07:24:30PM -0400, Ted Unangst wrote: > using pread and pwrite is a little shorter and half the syscalls. >
ok mlarkin. thanks! > Index: virtio.c > =================================================================== > RCS file: /cvs/src/usr.sbin/vmd/virtio.c,v > retrieving revision 1.46 > diff -u -p -r1.46 virtio.c > --- virtio.c 11 May 2017 07:31:20 -0000 1.46 > +++ virtio.c 27 May 2017 23:20:23 -0000 > @@ -335,14 +335,7 @@ vioblk_do_read(struct vioblk_dev *dev, o > return (NULL); > } > > - if (lseek(dev->fd, sector * VIRTIO_BLK_SECTOR_SIZE, > - SEEK_SET) == -1) { > - log_warn("seek error in vioblk read"); > - free(buf); > - return (NULL); > - } > - > - if (read(dev->fd, buf, sz) != sz) { > + if (pread(dev->fd, buf, sz, sector * VIRTIO_BLK_SECTOR_SIZE) != sz) { > log_warn("vioblk read error"); > free(buf); > return (NULL); > @@ -354,13 +347,7 @@ vioblk_do_read(struct vioblk_dev *dev, o > static int > vioblk_do_write(struct vioblk_dev *dev, off_t sector, char *buf, ssize_t sz) > { > - if (lseek(dev->fd, sector * VIRTIO_BLK_SECTOR_SIZE, > - SEEK_SET) == -1) { > - log_warn("seek error in vioblk write"); > - return (1); > - } > - > - if (write(dev->fd, buf, sz) != sz) { > + if (pwrite(dev->fd, buf, sz, sector * VIRTIO_BLK_SECTOR_SIZE) != sz) { > log_warn("vioblk write error"); > return (1); > } >