[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 5/7] ios: Change from getchar to pread device interface.

From: Eric Blake
Subject: Re: [PATCH 5/7] ios: Change from getchar to pread device interface.
Date: Sat, 29 Feb 2020 05:28:35 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/29/20 5:12 AM, Eric Blake wrote:
Now that we are passing an offset to every I/O operation, it is not
that much harder to switch from an interface that operates on one byte
at a time to one that operates on a buffer at an offset: pread/pwrite.
For the file driver, there is not pread counterpart in stdio, so we
still have to fseeko before fread, but as argued in the previous
patch, we're still probably better off sticking to stdio buffers than
additional syscalls were we to rewrite to use pread/pwrite on fds.

The caller, ios.c, still performs most operations one byte at a time,
but that will be cleaned up in subsequent patches.

* src/ios-dev.h (struct ios_dev_if): Replace get_c/put_c with
(ios_read_string, ios_write_string): Use the new interface.
* src/ios-dev-file.c (ios_dev_file_getc, ios_dev_file_putc):
Rewrite to...
(ios_dev_file_pread, ios_dev_file_pwrite): ...this.
* src/ios-dev-mem.c (ios_dev_mem_getc, ios_dev_mem_putc): Rewrite
(ios_dev_mem_pread, ios_dev_mem_pwrite): ...this.

+++ b/src/ios-dev-mem.c

@@ -78,28 +79,30 @@ ios_dev_mem_get_flags  (void *iod)

  static int
-ios_dev_mem_getc (void *iod, ios_dev_off offset)
+ios_dev_mem_pread (void *iod, void *buf, size_t count, ios_dev_off offset)
    struct ios_dev_mem *mio = iod;

-  if (offset >= mio->size)
+  if (offset + count >= mio->size)
      return IOD_EOF;

Off-by-one, this should be (offset + count > mio->size).

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]