On Tue, Mar 02, 2021 at 08:44:04AM -0600, Eric Blake wrote:
Previously, attempts to use nbdkit without -r in order to visit a read-only image failed to open the image (in fact, a single read-only file in an otherwise usable directory makes "nbdkit file dir=. --run 'nbdinfo --list'" fail to print anything in libnbd 1.6). But a saner approach is to try a fallback to a readonly fd if a read-write fd fails.
The windows code compiles, but I wasn't able to test it as thoroughly as the Unix code.
+static int +wintfile_can_write (void *handle) +{ + struct handle *h = handle; + return !h->is_readonly; +}
Actually it doesn't because there's a misspelling. I modified the patch s/wintfile/winfile/, but the newly added test still fails on Wine with: nbdkit: file[1]: debug: file: flush nbdkit: file[1]: error: Z:\home\rjones\d\nbdkit-windows\tests\file-readonly.img: FlushFileBuffers: 5 nbdkit: file[1]: debug: sending error reply: Input/output error ... libnbd: debug: nbdsh: nbd_flush: leave: error="nbd_flush: flush: command failed: Input/output error" ... Traceback (most recent call last): File "/usr/lib64/python3.9/site-packages/nbdsh.py", line 119, in shell exec(c, d, d) File "<string>", line 9, in <module> File "/usr/lib64/python3.9/site-packages/nbd.py", line 1608, in flush return libnbdmod.flush(self._o, flags) nbd.Error: nbd_flush: flush: command failed: Input/output error (EIO) My guess is that Win32 doesn't let you flush a read-only file! The actual error is ERROR_ACCESS_DENIED (== 5). The attached patch fixes both issues. Rest of the patch is fine, so ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/