block: Change blk_{pread,pwrite}() param order

Swap 'buf' and 'bytes' around for consistency with
blk_co_{pread,pwrite}(), and in preparation to implement these functions
using generated_co_wrapper.

Callers were updated using this Coccinelle script:

    @@ expression blk, offset, buf, bytes, flags; @@
    - blk_pread(blk, offset, buf, bytes, flags)
    + blk_pread(blk, offset, bytes, buf, flags)

    @@ expression blk, offset, buf, bytes, flags; @@
    - blk_pwrite(blk, offset, buf, bytes, flags)
    + blk_pwrite(blk, offset, bytes, buf, flags)

It had no effect on hw/block/nand.c, presumably due to the #if, so that
file was updated manually.

Overly-long lines were then fixed by hand.

Signed-off-by: Alberto Faria <afaria@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220705161527.1054072-4-afaria@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
master
Alberto Faria 2022-07-05 17:15:11 +01:00 committed by Hanna Reitz
parent 3b35d4542c
commit a9262f551e
38 changed files with 150 additions and 149 deletions

View File

@ -1037,7 +1037,7 @@ static int find_image_format(BlockBackend *file, const char *filename,
return ret; return ret;
} }
ret = blk_pread(file, 0, buf, sizeof(buf), 0); ret = blk_pread(file, 0, sizeof(buf), buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read image for determining its " error_setg_errno(errp, -ret, "Could not read image for determining its "
"format"); "format");

View File

@ -1563,7 +1563,7 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
flags | BDRV_REQ_ZERO_WRITE, cb, opaque); flags | BDRV_REQ_ZERO_WRITE, cb, opaque);
} }
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
int ret; int ret;
@ -1577,7 +1577,7 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes,
return ret; return ret;
} }
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
BdrvRequestFlags flags) BdrvRequestFlags flags)
{ {
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);

View File

@ -527,12 +527,12 @@ int bdrv_commit(BlockDriverState *bs)
goto ro_cleanup; goto ro_cleanup;
} }
if (ret) { if (ret) {
ret = blk_pread(src, offset, buf, n, 0); ret = blk_pread(src, offset, n, buf, 0);
if (ret < 0) { if (ret < 0) {
goto ro_cleanup; goto ro_cleanup;
} }
ret = blk_pwrite(backing, offset, buf, n, 0); ret = blk_pwrite(backing, offset, n, buf, 0);
if (ret < 0) { if (ret < 0) {
goto ro_cleanup; goto ro_cleanup;
} }

View File

@ -109,7 +109,7 @@ static int block_crypto_create_write_func(QCryptoBlock *block,
struct BlockCryptoCreateData *data = opaque; struct BlockCryptoCreateData *data = opaque;
ssize_t ret; ssize_t ret;
ret = blk_pwrite(data->blk, offset, buf, buflen, 0); ret = blk_pwrite(data->blk, offset, buflen, buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write encryption header"); error_setg_errno(errp, -ret, "Could not write encryption header");
return ret; return ret;

View File

@ -554,7 +554,7 @@ static void fuse_read(fuse_req_t req, fuse_ino_t inode,
return; return;
} }
ret = blk_pread(exp->common.blk, offset, buf, size, 0); ret = blk_pread(exp->common.blk, offset, size, buf, 0);
if (ret >= 0) { if (ret >= 0) {
fuse_reply_buf(req, buf, size); fuse_reply_buf(req, buf, size);
} else { } else {
@ -607,7 +607,7 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf,
} }
} }
ret = blk_pwrite(exp->common.blk, offset, buf, size, 0); ret = blk_pwrite(exp->common.blk, offset, size, buf, 0);
if (ret >= 0) { if (ret >= 0) {
fuse_reply_write(req, size); fuse_reply_write(req, size);
} else { } else {

View File

@ -599,7 +599,7 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
memset(tmp, 0, sizeof(tmp)); memset(tmp, 0, sizeof(tmp));
memcpy(tmp, &header, sizeof(header)); memcpy(tmp, &header, sizeof(header));
ret = blk_pwrite(blk, 0, tmp, BDRV_SECTOR_SIZE, 0); ret = blk_pwrite(blk, 0, BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }

View File

@ -890,14 +890,14 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
} }
/* write all the data */ /* write all the data */
ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0); ret = blk_pwrite(qcow_blk, 0, sizeof(header), &header, 0);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }
if (qcow_opts->has_backing_file) { if (qcow_opts->has_backing_file) {
ret = blk_pwrite(qcow_blk, sizeof(header), ret = blk_pwrite(qcow_blk, sizeof(header), backing_filename_len,
qcow_opts->backing_file, backing_filename_len, 0); qcow_opts->backing_file, 0);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }
@ -907,7 +907,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE); for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE);
i++) { i++) {
ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i, ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
tmp, BDRV_SECTOR_SIZE, 0); BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) { if (ret < 0) {
g_free(tmp); g_free(tmp);
goto exit; goto exit;

View File

@ -3666,7 +3666,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
cpu_to_be64(QCOW2_INCOMPAT_EXTL2); cpu_to_be64(QCOW2_INCOMPAT_EXTL2);
} }
ret = blk_pwrite(blk, 0, header, cluster_size, 0); ret = blk_pwrite(blk, 0, cluster_size, header, 0);
g_free(header); g_free(header);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write qcow2 header"); error_setg_errno(errp, -ret, "Could not write qcow2 header");
@ -3676,7 +3676,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
/* Write a refcount table with one refcount block */ /* Write a refcount table with one refcount block */
refcount_table = g_malloc0(2 * cluster_size); refcount_table = g_malloc0(2 * cluster_size);
refcount_table[0] = cpu_to_be64(2 * cluster_size); refcount_table[0] = cpu_to_be64(2 * cluster_size);
ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size, 0); ret = blk_pwrite(blk, cluster_size, 2 * cluster_size, refcount_table, 0);
g_free(refcount_table); g_free(refcount_table);
if (ret < 0) { if (ret < 0) {

View File

@ -705,18 +705,18 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
} }
qed_header_cpu_to_le(&header, &le_header); qed_header_cpu_to_le(&header, &le_header);
ret = blk_pwrite(blk, 0, &le_header, sizeof(le_header), 0); ret = blk_pwrite(blk, 0, sizeof(le_header), &le_header, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
ret = blk_pwrite(blk, sizeof(le_header), qed_opts->backing_file, ret = blk_pwrite(blk, sizeof(le_header), header.backing_filename_size,
header.backing_filename_size, 0); qed_opts->backing_file, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
l1_table = g_malloc0(l1_size); l1_table = g_malloc0(l1_size);
ret = blk_pwrite(blk, header.l1_table_offset, l1_table, l1_size, 0); ret = blk_pwrite(blk, header.l1_table_offset, l1_size, l1_table, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }

View File

@ -845,7 +845,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
vdi_header_print(&header); vdi_header_print(&header);
} }
vdi_header_to_le(&header); vdi_header_to_le(&header);
ret = blk_pwrite(blk, offset, &header, sizeof(header), 0); ret = blk_pwrite(blk, offset, sizeof(header), &header, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, "Error writing header"); error_setg(errp, "Error writing header");
goto exit; goto exit;
@ -866,7 +866,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
bmap[i] = VDI_UNALLOCATED; bmap[i] = VDI_UNALLOCATED;
} }
} }
ret = blk_pwrite(blk, offset, bmap, bmap_size, 0); ret = blk_pwrite(blk, offset, bmap_size, bmap, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, "Error writing bmap"); error_setg(errp, "Error writing bmap");
goto exit; goto exit;

View File

@ -1665,13 +1665,13 @@ static int vhdx_create_new_metadata(BlockBackend *blk,
VHDX_META_FLAGS_IS_VIRTUAL_DISK; VHDX_META_FLAGS_IS_VIRTUAL_DISK;
vhdx_metadata_entry_le_export(&md_table_entry[4]); vhdx_metadata_entry_le_export(&md_table_entry[4]);
ret = blk_pwrite(blk, metadata_offset, buffer, VHDX_HEADER_BLOCK_SIZE, 0); ret = blk_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }
ret = blk_pwrite(blk, metadata_offset + (64 * KiB), entry_buffer, ret = blk_pwrite(blk, metadata_offset + (64 * KiB),
VHDX_METADATA_ENTRY_BUFFER_SIZE, 0); VHDX_METADATA_ENTRY_BUFFER_SIZE, entry_buffer, 0);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
} }
@ -1756,7 +1756,7 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]); s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]);
sector_num += s->sectors_per_block; sector_num += s->sectors_per_block;
} }
ret = blk_pwrite(blk, file_offset, s->bat, length, 0); ret = blk_pwrite(blk, file_offset, length, s->bat, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write the BAT"); error_setg_errno(errp, -ret, "Failed to write the BAT");
goto exit; goto exit;
@ -1860,15 +1860,15 @@ static int vhdx_create_new_region_table(BlockBackend *blk,
} }
/* Now write out the region headers to disk */ /* Now write out the region headers to disk */
ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer, ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, VHDX_HEADER_BLOCK_SIZE,
VHDX_HEADER_BLOCK_SIZE, 0); buffer, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write first region table"); error_setg_errno(errp, -ret, "Failed to write first region table");
goto exit; goto exit;
} }
ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer, ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, VHDX_HEADER_BLOCK_SIZE,
VHDX_HEADER_BLOCK_SIZE, 0); buffer, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write second region table"); error_setg_errno(errp, -ret, "Failed to write second region table");
goto exit; goto exit;
@ -2012,7 +2012,7 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL, creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
&creator_items, NULL); &creator_items, NULL);
signature = cpu_to_le64(VHDX_FILE_SIGNATURE); signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature), ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, sizeof(signature), &signature,
0); 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write file signature"); error_setg_errno(errp, -ret, "Failed to write file signature");
@ -2020,7 +2020,7 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
} }
if (creator) { if (creator) {
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature), ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
creator, creator_items * sizeof(gunichar2), 0); creator_items * sizeof(gunichar2), creator, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write creator field"); error_setg_errno(errp, -ret, "Failed to write creator field");
goto delete_and_exit; goto delete_and_exit;

View File

@ -2236,12 +2236,12 @@ static int vmdk_init_extent(BlockBackend *blk,
header.check_bytes[3] = 0xa; header.check_bytes[3] = 0xa;
/* write all the data */ /* write all the data */
ret = blk_pwrite(blk, 0, &magic, sizeof(magic), 0); ret = blk_pwrite(blk, 0, sizeof(magic), &magic, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, QERR_IO_ERROR); error_setg(errp, QERR_IO_ERROR);
goto exit; goto exit;
} }
ret = blk_pwrite(blk, sizeof(magic), &header, sizeof(header), 0); ret = blk_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, QERR_IO_ERROR); error_setg(errp, QERR_IO_ERROR);
goto exit; goto exit;
@ -2261,7 +2261,7 @@ static int vmdk_init_extent(BlockBackend *blk,
gd_buf[i] = cpu_to_le32(tmp); gd_buf[i] = cpu_to_le32(tmp);
} }
ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE, ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
gd_buf, gd_buf_size, 0); gd_buf_size, gd_buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, QERR_IO_ERROR); error_setg(errp, QERR_IO_ERROR);
goto exit; goto exit;
@ -2273,7 +2273,7 @@ static int vmdk_init_extent(BlockBackend *blk,
gd_buf[i] = cpu_to_le32(tmp); gd_buf[i] = cpu_to_le32(tmp);
} }
ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE, ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE,
gd_buf, gd_buf_size, 0); gd_buf_size, gd_buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, QERR_IO_ERROR); error_setg(errp, QERR_IO_ERROR);
} }
@ -2584,7 +2584,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
desc_offset = 0x200; desc_offset = 0x200;
} }
ret = blk_pwrite(blk, desc_offset, desc, desc_len, 0); ret = blk_pwrite(blk, desc_offset, desc_len, desc, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write description"); error_setg_errno(errp, -ret, "Could not write description");
goto exit; goto exit;

View File

@ -834,13 +834,13 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
block_size = 0x200000; block_size = 0x200000;
num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512); num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512);
ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
offset = 1536 + ((num_bat_entries * 4 + 511) & ~511); offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -850,7 +850,7 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
memset(bat_sector, 0xFF, 512); memset(bat_sector, 0xFF, 512);
for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) { for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) {
ret = blk_pwrite(blk, offset, bat_sector, 512, 0); ret = blk_pwrite(blk, offset, 512, bat_sector, 0);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -878,7 +878,7 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
/* Write the header */ /* Write the header */
offset = 512; offset = 512;
ret = blk_pwrite(blk, offset, &dyndisk_header, sizeof(dyndisk_header), 0); ret = blk_pwrite(blk, offset, sizeof(dyndisk_header), &dyndisk_header, 0);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -901,8 +901,8 @@ static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer,
return ret; return ret;
} }
ret = blk_pwrite(blk, total_size - sizeof(*footer), ret = blk_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
footer, sizeof(*footer), 0); footer, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Unable to write VHD header"); error_setg_errno(errp, -ret, "Unable to write VHD header");
return ret; return ret;

View File

@ -174,7 +174,7 @@ void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
const int64_t rom_size = 32 * KiB; const int64_t rom_size = 32 * KiB;
g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size); g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
if (blk_pread(blk, 8 * KiB, buffer, rom_size, 0) < 0) { if (blk_pread(blk, 8 * KiB, rom_size, buffer, 0) < 0) {
error_setg(&error_fatal, "%s: failed to read BlockBackend data", error_setg(&error_fatal, "%s: failed to read BlockBackend data",
__func__); __func__);
return; return;

View File

@ -253,7 +253,7 @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
} }
storage = g_malloc0(rom_size); storage = g_malloc0(rom_size);
if (blk_pread(blk, 0, storage, rom_size, 0) < 0) { if (blk_pread(blk, 0, rom_size, storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content"); error_setg(errp, "failed to read the initial flash content");
return; return;
} }

View File

@ -53,7 +53,7 @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
* block device and read only on demand. * block device and read only on demand.
*/ */
assert(size <= BDRV_REQUEST_MAX_BYTES); assert(size <= BDRV_REQUEST_MAX_BYTES);
ret = blk_pread(blk, 0, buf, size, 0); ret = blk_pread(blk, 0, size, buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "can't read block backend"); error_setg_errno(errp, -ret, "can't read block backend");
return false; return false;

View File

@ -1628,8 +1628,8 @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len)
if (fdctrl->data_dir != FD_DIR_WRITE || if (fdctrl->data_dir != FD_DIR_WRITE ||
len < FD_SECTOR_LEN || rel_pos != 0) { len < FD_SECTOR_LEN || rel_pos != 0) {
/* READ & SCAN commands and realign to a sector for WRITE */ /* READ & SCAN commands and realign to a sector for WRITE */
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
BDRV_SECTOR_SIZE, 0) < 0) { fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("Floppy: error getting sector %d\n", FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
/* Sure, image size is too small... */ /* Sure, image size is too small... */
@ -1656,8 +1656,8 @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len)
k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos, k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
fdctrl->data_pos, len); fdctrl->data_pos, len);
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) { fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n", FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
@ -1740,8 +1740,8 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
fd_sector(cur_drv)); fd_sector(cur_drv));
return 0; return 0;
} }
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
BDRV_SECTOR_SIZE, 0) fdctrl->fifo, 0)
< 0) { < 0) {
FLOPPY_DPRINTF("error getting sector %d\n", FLOPPY_DPRINTF("error getting sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
@ -1820,8 +1820,8 @@ static void fdctrl_format_sector(FDCtrl *fdctrl)
} }
memset(fdctrl->fifo, 0, FD_SECTOR_LEN); memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
if (cur_drv->blk == NULL || if (cur_drv->blk == NULL ||
blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
BDRV_SECTOR_SIZE, 0) < 0) { fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv)); FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
} else { } else {
@ -2244,8 +2244,8 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
if (pos == FD_SECTOR_LEN - 1 || if (pos == FD_SECTOR_LEN - 1 ||
fdctrl->data_pos == fdctrl->data_len) { fdctrl->data_pos == fdctrl->data_len) {
cur_drv = get_cur_drv(fdctrl); cur_drv = get_cur_drv(fdctrl);
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
BDRV_SECTOR_SIZE, 0) < 0) { fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n", FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
break; break;

View File

@ -63,7 +63,7 @@ static int guess_disk_lchs(BlockBackend *blk,
blk_get_geometry(blk, &nb_sectors); blk_get_geometry(blk, &nb_sectors);
if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE, 0) < 0) { if (blk_pread(blk, 0, BDRV_SECTOR_SIZE, buf, 0) < 0) {
return -1; return -1;
} }
/* test msdos magic */ /* test msdos magic */

View File

@ -1532,7 +1532,7 @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp)
trace_m25p80_binding(s); trace_m25p80_binding(s);
s->storage = blk_blockalign(s->blk, s->size); s->storage = blk_blockalign(s->blk, s->size);
if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content"); error_setg(errp, "failed to read the initial flash content");
return; return;
} }

View File

@ -666,8 +666,8 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
sector = SECTOR(s->addr); sector = SECTOR(s->addr);
off = (s->addr & PAGE_MASK) + s->offset; off = (s->addr & PAGE_MASK) + s->offset;
soff = SECTOR_OFFSET(s->addr); soff = SECTOR_OFFSET(s->addr);
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return; return;
} }
@ -679,24 +679,24 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE)); MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE));
} }
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); printf("%s: write error in sector %" PRIu64 "\n", __func__, sector);
} }
} else { } else {
off = PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset; off = PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset;
sector = off >> 9; sector = off >> 9;
soff = off & 0x1ff; soff = off & 0x1ff;
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return; return;
} }
mem_and(iobuf + soff, s->io, s->iolen); mem_and(iobuf + soff, s->io, s->iolen);
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); printf("%s: write error in sector %" PRIu64 "\n", __func__, sector);
} }
} }
@ -723,20 +723,20 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
i = SECTOR(addr); i = SECTOR(addr);
page = SECTOR(addr + (1 << (ADDR_SHIFT + s->erase_shift))); page = SECTOR(addr + (1 << (ADDR_SHIFT + s->erase_shift)));
for (; i < page; i ++) for (; i < page; i ++)
if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS, iobuf, if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, i); printf("%s: write error in sector %" PRIu64 "\n", __func__, i);
} }
} else { } else {
addr = PAGE_START(addr); addr = PAGE_START(addr);
page = addr >> 9; page = addr >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, if (blk_pread(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page); printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
} }
memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1); memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1);
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf, if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, page); printf("%s: write error in sector %" PRIu64 "\n", __func__, page);
} }
@ -744,20 +744,20 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
i = (addr & ~0x1ff) + 0x200; i = (addr & ~0x1ff) + 0x200;
for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200;
i < addr; i += 0x200) { i < addr; i += 0x200) {
if (blk_pwrite(s->blk, i, iobuf, BDRV_SECTOR_SIZE, 0) < 0) { if (blk_pwrite(s->blk, i, BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", printf("%s: write error in sector %" PRIu64 "\n",
__func__, i >> 9); __func__, i >> 9);
} }
} }
page = i >> 9; page = i >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, if (blk_pread(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page); printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
} }
memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1); memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1);
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf, if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, page); printf("%s: write error in sector %" PRIu64 "\n", __func__, page);
} }
} }
@ -772,8 +772,8 @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s,
if (s->blk) { if (s->blk) {
if (s->mem_oob) { if (s->mem_oob) {
if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS, s->io, if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { PAGE_SECTORS << BDRV_SECTOR_BITS, s->io, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", printf("%s: read error in sector %" PRIu64 "\n",
__func__, SECTOR(addr)); __func__, SECTOR(addr));
} }
@ -782,8 +782,9 @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s,
OOB_SIZE); OOB_SIZE);
s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset;
} else { } else {
if (blk_pread(s->blk, PAGE_START(addr), s->io, if (blk_pread(s->blk, PAGE_START(addr),
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, s->io, 0)
< 0) {
printf("%s: read error in sector %" PRIu64 "\n", printf("%s: read error in sector %" PRIu64 "\n",
__func__, PAGE_START(addr) >> 9); __func__, PAGE_START(addr) >> 9);
} }

View File

@ -229,8 +229,8 @@ static void onenand_reset(OneNANDState *s, int cold)
/* Lock the whole flash */ /* Lock the whole flash */
memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks);
if (s->blk_cur && blk_pread(s->blk_cur, 0, s->boot[0], if (s->blk_cur && blk_pread(s->blk_cur, 0, 8 << BDRV_SECTOR_BITS,
8 << BDRV_SECTOR_BITS, 0) < 0) { s->boot[0], 0) < 0) {
hw_error("%s: Loading the BootRAM failed.\n", __func__); hw_error("%s: Loading the BootRAM failed.\n", __func__);
} }
} }
@ -249,8 +249,8 @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn,
assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec); assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec);
assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn); assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn);
if (s->blk_cur) { if (s->blk_cur) {
return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, dest, return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS,
secn << BDRV_SECTOR_BITS, 0) < 0; secn << BDRV_SECTOR_BITS, dest, 0) < 0;
} else if (sec + secn > s->secs_cur) { } else if (sec + secn > s->secs_cur) {
return 1; return 1;
} }
@ -274,7 +274,7 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,
uint8_t *dp = 0; uint8_t *dp = 0;
if (s->blk_cur) { if (s->blk_cur) {
dp = g_malloc(size); dp = g_malloc(size);
if (!dp || blk_pread(s->blk_cur, offset, dp, size, 0) < 0) { if (!dp || blk_pread(s->blk_cur, offset, size, dp, 0) < 0) {
result = 1; result = 1;
} }
} else { } else {
@ -290,7 +290,7 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,
dp[i] &= sp[i]; dp[i] &= sp[i];
} }
if (s->blk_cur) { if (s->blk_cur) {
result = blk_pwrite(s->blk_cur, offset, dp, size, 0) < 0; result = blk_pwrite(s->blk_cur, offset, size, dp, 0) < 0;
} }
} }
if (dp && s->blk_cur) { if (dp && s->blk_cur) {
@ -308,7 +308,7 @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn,
if (s->blk_cur) { if (s->blk_cur) {
uint32_t offset = (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS; uint32_t offset = (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS;
if (blk_pread(s->blk_cur, offset, buf, BDRV_SECTOR_SIZE, 0) < 0) { if (blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, buf, 0) < 0) {
return 1; return 1;
} }
memcpy(dest, buf + ((sec & 31) << 4), secn << 4); memcpy(dest, buf + ((sec & 31) << 4), secn << 4);
@ -333,7 +333,7 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn,
if (s->blk_cur) { if (s->blk_cur) {
dp = g_malloc(512); dp = g_malloc(512);
if (!dp if (!dp
|| blk_pread(s->blk_cur, offset, dp, BDRV_SECTOR_SIZE, 0) < 0) { || blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp, 0) < 0) {
result = 1; result = 1;
} else { } else {
dpp = dp + ((sec & 31) << 4); dpp = dp + ((sec & 31) << 4);
@ -351,8 +351,8 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn,
dpp[i] &= sp[i]; dpp[i] &= sp[i];
} }
if (s->blk_cur) { if (s->blk_cur) {
result = blk_pwrite(s->blk_cur, offset, dp, result = blk_pwrite(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp,
BDRV_SECTOR_SIZE, 0) < 0; 0) < 0;
} }
} }
g_free(dp); g_free(dp);
@ -370,17 +370,17 @@ static inline int onenand_erase(OneNANDState *s, int sec, int num)
for (; num > 0; num--, sec++) { for (; num > 0; num--, sec++) {
if (s->blk_cur) { if (s->blk_cur) {
int erasesec = s->secs_cur + (sec >> 5); int erasesec = s->secs_cur + (sec >> 5);
if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS, blankbuf, if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, blankbuf, 0) < 0) {
goto fail; goto fail;
} }
if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf, if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) {
goto fail; goto fail;
} }
memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4);
if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf, if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, 0) < 0) { BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) {
goto fail; goto fail;
} }
} else { } else {

View File

@ -392,8 +392,8 @@ static void pflash_update(PFlashCFI01 *pfl, int offset,
/* widen to sector boundaries */ /* widen to sector boundaries */
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset, ret = blk_pwrite(pfl->blk, offset, offset_end - offset,
offset_end - offset, 0); pfl->storage + offset, 0);
if (ret < 0) { if (ret < 0) {
/* TODO set error bit in status */ /* TODO set error bit in status */
error_report("Could not update PFLASH: %s", strerror(-ret)); error_report("Could not update PFLASH: %s", strerror(-ret));

View File

@ -400,8 +400,8 @@ static void pflash_update(PFlashCFI02 *pfl, int offset, int size)
/* widen to sector boundaries */ /* widen to sector boundaries */
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset, ret = blk_pwrite(pfl->blk, offset, offset_end - offset,
offset_end - offset, 0); pfl->storage + offset, 0);
if (ret < 0) { if (ret < 0) {
/* TODO set error bit in status */ /* TODO set error bit in status */
error_report("Could not update PFLASH: %s", strerror(-ret)); error_report("Could not update PFLASH: %s", strerror(-ret));

View File

@ -98,11 +98,11 @@ cd_read_sector_sync(IDEState *s)
switch (s->cd_sector_size) { switch (s->cd_sector_size) {
case 2048: case 2048:
ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS,
s->io_buffer, ATAPI_SECTOR_SIZE, 0); ATAPI_SECTOR_SIZE, s->io_buffer, 0);
break; break;
case 2352: case 2352:
ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS,
s->io_buffer + 16, ATAPI_SECTOR_SIZE, 0); ATAPI_SECTOR_SIZE, s->io_buffer + 16, 0);
if (ret >= 0) { if (ret >= 0) {
cd_data_to_raw(s->io_buffer, s->lba); cd_data_to_raw(s->io_buffer, s->lba);
} }

View File

@ -351,7 +351,7 @@ static void via1_one_second(void *opaque)
static void pram_update(MOS6522Q800VIA1State *v1s) static void pram_update(MOS6522Q800VIA1State *v1s)
{ {
if (v1s->blk) { if (v1s->blk) {
if (blk_pwrite(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0) < 0) { if (blk_pwrite(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0) < 0) {
qemu_log("pram_update: cannot write to file\n"); qemu_log("pram_update: cannot write to file\n");
} }
} }
@ -1029,7 +1029,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
return; return;
} }
ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0); ret = blk_pread(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, "can't read PRAM contents"); error_setg(errp, "can't read PRAM contents");
return; return;

View File

@ -64,8 +64,8 @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size)
if (s->blk) { if (s->blk) {
int32_t buf; int32_t buf;
if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf, if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { SIFIVE_U_OTP_FUSE_WORD, &buf, 0) < 0) {
error_report("read error index<%d>", s->pa); error_report("read error index<%d>", s->pa);
return 0xff; return 0xff;
} }
@ -167,8 +167,8 @@ static void sifive_u_otp_write(void *opaque, hwaddr addr,
/* write to backend */ /* write to backend */
if (s->blk) { if (s->blk) {
if (blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, if (blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
&s->fuse[s->pa], SIFIVE_U_OTP_FUSE_WORD, SIFIVE_U_OTP_FUSE_WORD, &s->fuse[s->pa], 0)
0) < 0) { < 0) {
error_report("write error index<%d>", s->pa); error_report("write error index<%d>", s->pa);
} }
} }
@ -240,7 +240,7 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
return; return;
} }
if (blk_pread(s->blk, 0, s->fuse, filesize, 0) < 0) { if (blk_pread(s->blk, 0, filesize, s->fuse, 0) < 0) {
error_setg(errp, "failed to read the initial flash content"); error_setg(errp, "failed to read the initial flash content");
return; return;
} }
@ -261,14 +261,14 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
serial_data = s->serial; serial_data = s->serial;
if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD, if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) {
error_setg(errp, "failed to write index<%d>", index); error_setg(errp, "failed to write index<%d>", index);
return; return;
} }
serial_data = ~(s->serial); serial_data = ~(s->serial);
if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD, if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) {
error_setg(errp, "failed to write index<%d>", index + 1); error_setg(errp, "failed to write index<%d>", index + 1);
return; return;
} }

View File

@ -64,7 +64,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
case I2C_START_RECV: case I2C_START_RECV:
DPRINTK("clear\n"); DPRINTK("clear\n");
if (ee->blk && ee->changed) { if (ee->blk && ee->changed) {
int ret = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0); int ret = blk_pwrite(ee->blk, 0, ee->rsize, ee->mem, 0);
if (ret < 0) { if (ret < 0) {
ERR(TYPE_AT24C_EE ERR(TYPE_AT24C_EE
" : failed to write backing file\n"); " : failed to write backing file\n");
@ -165,7 +165,7 @@ void at24c_eeprom_reset(DeviceState *state)
memset(ee->mem, 0, ee->rsize); memset(ee->mem, 0, ee->rsize);
if (ee->blk) { if (ee->blk) {
int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0); int ret = blk_pread(ee->blk, 0, ee->rsize, ee->mem, 0);
if (ret < 0) { if (ret < 0) {
ERR(TYPE_AT24C_EE ERR(TYPE_AT24C_EE

View File

@ -130,7 +130,7 @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr,
ret = 0; ret = 0;
if (nvram->blk) { if (nvram->blk) {
ret = blk_pwrite(nvram->blk, offset, membuf, len, 0); ret = blk_pwrite(nvram->blk, offset, len, membuf, 0);
} }
assert(nvram->buf); assert(nvram->buf);
@ -179,7 +179,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
} }
if (nvram->blk) { if (nvram->blk) {
ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0); ret = blk_pread(nvram->blk, 0, nvram->size, nvram->buf, 0);
if (ret < 0) { if (ret < 0) {
error_setg(errp, "can't read spapr-nvram contents"); error_setg(errp, "can't read spapr-nvram contents");
@ -224,7 +224,7 @@ static void postload_update_cb(void *opaque, bool running, RunState state)
qemu_del_vm_change_state_handler(nvram->vmstate); qemu_del_vm_change_state_handler(nvram->vmstate);
nvram->vmstate = NULL; nvram->vmstate = NULL;
blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0); blk_pwrite(nvram->blk, 0, nvram->size, nvram->buf, 0);
} }
static int spapr_nvram_post_load(void *opaque, int version_id) static int spapr_nvram_post_load(void *opaque, int version_id)

View File

@ -124,7 +124,7 @@ static void bbram_bdrv_read(XlnxBBRam *s, Error **errp)
blk_name(s->blk)); blk_name(s->blk));
} }
if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { if (blk_pread(s->blk, 0, nr, ram, 0) < 0) {
error_setg(errp, error_setg(errp,
"%s: Failed to read %u bytes from BBRAM backstore.", "%s: Failed to read %u bytes from BBRAM backstore.",
blk_name(s->blk), nr); blk_name(s->blk), nr);
@ -159,7 +159,7 @@ static void bbram_bdrv_sync(XlnxBBRam *s, uint64_t hwaddr)
} }
offset = hwaddr - A_BBRAM_0; offset = hwaddr - A_BBRAM_0;
rc = blk_pwrite(s->blk, offset, &le32, 4, 0); rc = blk_pwrite(s->blk, offset, 4, &le32, 0);
if (rc < 0) { if (rc < 0) {
bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offset)); bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offset));
} }

View File

@ -77,7 +77,7 @@ static int efuse_bdrv_read(XlnxEFuse *s, Error **errp)
blk_name(s->blk)); blk_name(s->blk));
} }
if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { if (blk_pread(s->blk, 0, nr, ram, 0) < 0) {
error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.", error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.",
blk_name(s->blk), nr); blk_name(s->blk), nr);
return -1; return -1;
@ -105,7 +105,7 @@ static void efuse_bdrv_sync(XlnxEFuse *s, unsigned int bit)
le32 = cpu_to_le32(xlnx_efuse_get_row(s, bit)); le32 = cpu_to_le32(xlnx_efuse_get_row(s, bit));
row_offset = (bit / 32) * 4; row_offset = (bit / 32) * 4;
if (blk_pwrite(s->blk, row_offset, &le32, 4, 0) < 0) { if (blk_pwrite(s->blk, row_offset, 4, &le32, 0) < 0) {
error_report("%s: Failed to write offset %u of eFUSE backstore.", error_report("%s: Failed to write offset %u of eFUSE backstore.",
blk_name(s->blk), row_offset); blk_name(s->blk), row_offset);
} }

View File

@ -44,8 +44,8 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size)
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(s->blk, offset, s->storage + offset, ret = blk_pwrite(s->blk, offset, offset_end - offset, s->storage + offset,
offset_end - offset, 0); 0);
if (ret < 0) { if (ret < 0) {
error_report("Could not update PNOR offset=0x%" PRIx32" : %s", offset, error_report("Could not update PNOR offset=0x%" PRIx32" : %s", offset,
strerror(-ret)); strerror(-ret));
@ -99,7 +99,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp)
s->storage = blk_blockalign(s->blk, s->size); s->storage = blk_blockalign(s->blk, s->size);
if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content"); error_setg(errp, "failed to read the initial flash content");
return; return;
} }

View File

@ -752,7 +752,7 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len)
{ {
trace_sdcard_read_block(addr, len); trace_sdcard_read_block(addr, len);
if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len, 0) < 0) { if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) {
fprintf(stderr, "sd_blk_read: read error on host side\n"); fprintf(stderr, "sd_blk_read: read error on host side\n");
} }
} }
@ -760,7 +760,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len)
static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len)
{ {
trace_sdcard_write_block(addr, len); trace_sdcard_write_block(addr, len);
if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) { if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) {
fprintf(stderr, "sd_blk_write: write error on host side\n"); fprintf(stderr, "sd_blk_write: write error on host side\n");
} }
} }

View File

@ -101,9 +101,9 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
* the "I/O or GS" API. * the "I/O or GS" API.
*/ */
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf,
BdrvRequestFlags flags); BdrvRequestFlags flags);
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
BdrvRequestFlags flags); BdrvRequestFlags flags);
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov, int64_t bytes, QEMUIOVector *qiov,

View File

@ -569,7 +569,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
blk_mig_unlock(); blk_mig_unlock();
} else { } else {
ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE,
blk->buf, nr_sectors * BDRV_SECTOR_SIZE, 0); nr_sectors * BDRV_SECTOR_SIZE, blk->buf, 0);
if (ret < 0) { if (ret < 0) {
goto error; goto error;
} }
@ -976,8 +976,8 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
cluster_size, cluster_size,
BDRV_REQ_MAY_UNMAP); BDRV_REQ_MAY_UNMAP);
} else { } else {
ret = blk_pwrite(blk, cur_addr, cur_buf, ret = blk_pwrite(blk, cur_addr, cluster_size, cur_buf,
cluster_size, 0); 0);
} }
if (ret < 0) { if (ret < 0) {
break; break;

View File

@ -2039,8 +2039,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client,
stl_be_p(&chunk.length, pnum); stl_be_p(&chunk.length, pnum);
ret = nbd_co_send_iov(client, iov, 1, errp); ret = nbd_co_send_iov(client, iov, 1, errp);
} else { } else {
ret = blk_pread(exp->common.blk, offset + progress, ret = blk_pread(exp->common.blk, offset + progress, pnum,
data + progress, pnum, 0); data + progress, 0);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "reading from file failed"); error_setg_errno(errp, -ret, "reading from file failed");
break; break;
@ -2444,7 +2444,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
data, request->len, errp); data, request->len, errp);
} }
ret = blk_pread(exp->common.blk, request->from, data, request->len, 0); ret = blk_pread(exp->common.blk, request->from, request->len, data, 0);
if (ret < 0) { if (ret < 0) {
return nbd_send_generic_reply(client, request->handle, ret, return nbd_send_generic_reply(client, request->handle, ret,
"reading from file failed", errp); "reading from file failed", errp);
@ -2511,7 +2511,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
if (request->flags & NBD_CMD_FLAG_FUA) { if (request->flags & NBD_CMD_FLAG_FUA) {
flags |= BDRV_REQ_FUA; flags |= BDRV_REQ_FUA;
} }
ret = blk_pwrite(exp->common.blk, request->from, data, request->len, ret = blk_pwrite(exp->common.blk, request->from, request->len, data,
flags); flags);
return nbd_send_generic_reply(client, request->handle, ret, return nbd_send_generic_reply(client, request->handle, ret,
"writing to file failed", errp); "writing to file failed", errp);

View File

@ -1309,7 +1309,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset,
int ret = 0; int ret = 0;
int64_t idx; int64_t idx;
ret = blk_pread(blk, offset, buffer, bytes, 0); ret = blk_pread(blk, offset, bytes, buffer, 0);
if (ret < 0) { if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s", error_report("Error while reading offset %" PRId64 " of %s: %s",
offset, filename, strerror(-ret)); offset, filename, strerror(-ret));
@ -1526,7 +1526,7 @@ static int img_compare(int argc, char **argv)
int64_t pnum; int64_t pnum;
chunk = MIN(chunk, IO_BUF_SIZE); chunk = MIN(chunk, IO_BUF_SIZE);
ret = blk_pread(blk1, offset, buf1, chunk, 0); ret = blk_pread(blk1, offset, chunk, buf1, 0);
if (ret < 0) { if (ret < 0) {
error_report("Error while reading offset %" PRId64 error_report("Error while reading offset %" PRId64
" of %s: %s", " of %s: %s",
@ -1534,7 +1534,7 @@ static int img_compare(int argc, char **argv)
ret = 4; ret = 4;
goto out; goto out;
} }
ret = blk_pread(blk2, offset, buf2, chunk, 0); ret = blk_pread(blk2, offset, chunk, buf2, 0);
if (ret < 0) { if (ret < 0) {
error_report("Error while reading offset %" PRId64 error_report("Error while reading offset %" PRId64
" of %s: %s", " of %s: %s",
@ -3779,7 +3779,7 @@ static int img_rebase(int argc, char **argv)
n = old_backing_size - offset; n = old_backing_size - offset;
} }
ret = blk_pread(blk_old_backing, offset, buf_old, n, 0); ret = blk_pread(blk_old_backing, offset, n, buf_old, 0);
if (ret < 0) { if (ret < 0) {
error_report("error while reading from old backing file"); error_report("error while reading from old backing file");
goto out; goto out;
@ -3793,7 +3793,7 @@ static int img_rebase(int argc, char **argv)
n = new_backing_size - offset; n = new_backing_size - offset;
} }
ret = blk_pread(blk_new_backing, offset, buf_new, n, 0); ret = blk_pread(blk_new_backing, offset, n, buf_new, 0);
if (ret < 0) { if (ret < 0) {
error_report("error while reading from new backing file"); error_report("error while reading from new backing file");
goto out; goto out;
@ -3812,8 +3812,8 @@ static int img_rebase(int argc, char **argv)
if (buf_old_is_zero) { if (buf_old_is_zero) {
ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0); ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0);
} else { } else {
ret = blk_pwrite(blk, offset + written, ret = blk_pwrite(blk, offset + written, pnum,
buf_old + written, pnum, 0); buf_old + written, 0);
} }
if (ret < 0) { if (ret < 0) {
error_report("Error while writing to COW image: %s", error_report("Error while writing to COW image: %s",
@ -5122,7 +5122,7 @@ static int img_dd(int argc, char **argv)
for (out_pos = 0; in_pos < size; block_count++) { for (out_pos = 0; in_pos < size; block_count++) {
int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
ret = blk_pread(blk1, in_pos, in.buf, bytes, 0); ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
if (ret < 0) { if (ret < 0) {
error_report("error while reading from input image file: %s", error_report("error while reading from input image file: %s",
strerror(-ret)); strerror(-ret));
@ -5130,7 +5130,7 @@ static int img_dd(int argc, char **argv)
} }
in_pos += bytes; in_pos += bytes;
ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0); ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0);
if (ret < 0) { if (ret < 0) {
error_report("error while writing to output image file: %s", error_report("error while writing to output image file: %s",
strerror(-ret)); strerror(-ret));

View File

@ -547,7 +547,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
return -ERANGE; return -ERANGE;
} }
ret = blk_pread(blk, offset, (uint8_t *)buf, bytes, 0); ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, 0);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
@ -564,7 +564,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
return -ERANGE; return -ERANGE;
} }
ret = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags); ret = blk_pwrite(blk, offset, bytes, (uint8_t *)buf, flags);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }

View File

@ -116,11 +116,11 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
int ret; int ret;
/* Success */ /* Success */
ret = blk_pread(blk, 0, buf, sizeof(buf), 0); ret = blk_pread(blk, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0); g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */ /* Early error: Negative offset */
ret = blk_pread(blk, -2, buf, sizeof(buf), 0); ret = blk_pread(blk, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO); g_assert_cmpint(ret, ==, -EIO);
} }
@ -130,11 +130,11 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
int ret; int ret;
/* Success */ /* Success */
ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0); ret = blk_pwrite(blk, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0); g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */ /* Early error: Negative offset */
ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0); ret = blk_pwrite(blk, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO); g_assert_cmpint(ret, ==, -EIO);
} }