[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 10/44] fdc: Switch to byte-based block access
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v3 10/44] fdc: Switch to byte-based block access |
Date: |
Fri, 22 Apr 2016 17:40:18 -0600 |
Sector-based blk_write() should die; switch to byte-based
blk_pwrite() instead. Likewise for blk_read().
Signed-off-by: Eric Blake <address@hidden>
---
hw/block/fdc.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 3722275..f73af7d 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -223,6 +223,13 @@ static int fd_sector(FDrive *drv)
NUM_SIDES(drv));
}
+/* Returns current position, in bytes, for given drive */
+static int fd_offset(FDrive *drv)
+{
+ g_assert(fd_sector(drv) < INT_MAX >> BDRV_SECTOR_BITS);
+ return fd_sector(drv) << BDRV_SECTOR_BITS;
+}
+
/* Seek to a new position:
* returns 0 if already on right track
* returns 1 if track changed
@@ -1629,8 +1636,8 @@ static int fdctrl_transfer_handler (void *opaque, int
nchan,
if (fdctrl->data_dir != FD_DIR_WRITE ||
len < FD_SECTOR_LEN || rel_pos != 0) {
/* READ & SCAN commands and realign to a sector for WRITE */
- if (blk_read(cur_drv->blk, fd_sector(cur_drv),
- fdctrl->fifo, 1) < 0) {
+ if (blk_pread(cur_drv->blk, fd_offset(cur_drv),
+ fdctrl->fifo, BDRV_SECTOR_SIZE) < 0) {
FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
fd_sector(cur_drv));
/* Sure, image size is too small... */
@@ -1657,8 +1664,8 @@ static int fdctrl_transfer_handler (void *opaque, int
nchan,
k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
fdctrl->data_pos, len);
- if (blk_write(cur_drv->blk, fd_sector(cur_drv),
- fdctrl->fifo, 1) < 0) {
+ if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv),
+ fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK,
0x00, 0x00);
@@ -1741,7 +1748,8 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
fd_sector(cur_drv));
return 0;
}
- if (blk_read(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1)
+ if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
+ BDRV_SECTOR_SIZE)
< 0) {
FLOPPY_DPRINTF("error getting sector %d\n",
fd_sector(cur_drv));
@@ -1820,7 +1828,8 @@ static void fdctrl_format_sector(FDCtrl *fdctrl)
}
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
if (cur_drv->blk == NULL ||
- blk_write(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
+ blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
+ BDRV_SECTOR_SIZE, 0) < 0) {
FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
} else {
@@ -2243,8 +2252,8 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t
value)
if (pos == FD_SECTOR_LEN - 1 ||
fdctrl->data_pos == fdctrl->data_len) {
cur_drv = get_cur_drv(fdctrl);
- if (blk_write(cur_drv->blk, fd_sector(cur_drv), fdctrl->fifo, 1)
- < 0) {
+ if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
+ BDRV_SECTOR_SIZE, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv));
break;
--
2.5.5
- [Qemu-devel] [PATCH v3 03/44] nbd: Improve server handling of bogus commands, (continued)
- [Qemu-devel] [PATCH v3 03/44] nbd: Improve server handling of bogus commands, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 04/44] nbd: Reject unknown request flags, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 01/44] nbd: More debug typo fixes, use correct formats, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 02/44] nbd: Quit server after any write error, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 08/44] nbd: Add qemu-nbd -D for human-readable description, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 07/44] nbd: Limit nbdflags to 16 bits, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 10/44] fdc: Switch to byte-based block access,
Eric Blake <=
- [Qemu-devel] [PATCH v3 15/44] m25p80: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 14/44] sd: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 13/44] pflash: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 16/44] atapi: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 18/44] qemu-img: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 23/44] qemu-io: Add missing option documentation, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 29/44] nbd: Avoid magic number for NBD max name size, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 31/44] nbd: Share common reply-sending code in server, Eric Blake, 2016/04/22