X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-nbd.c;h=5a0300eb0725ed658cf4fc43bed33b9ca7e40ed4;hb=d195325b05199038b5907fa791729425b9720d21;hp=19cfb04d966cf731adc03b6284b8ba6f62bfc79f;hpb=fc19f8a02e45c4d8ad24dd7eb374330b03dfc28e;p=qemu.git diff --git a/qemu-nbd.c b/qemu-nbd.c index 19cfb04d9..5a0300eb0 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -17,7 +17,7 @@ */ #include "qemu-common.h" -#include "block_int.h" +#include "block.h" #include "nbd.h" #include @@ -126,8 +126,7 @@ static int find_partition(BlockDriverState *bs, int partition, } if (data[510] != 0x55 || data[511] != 0xaa) { - errno = -EINVAL; - return -1; + return -EINVAL; } for (i = 0; i < 4; i++) { @@ -165,8 +164,7 @@ static int find_partition(BlockDriverState *bs, int partition, } } - errno = -ENOENT; - return -1; + return -ENOENT; } static void termsig_handler(int signum) @@ -489,11 +487,14 @@ int main(int argc, char **argv) err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]); } - fd_size = bs->total_sectors * 512; + fd_size = bdrv_getlength(bs); - if (partition != -1 && - find_partition(bs, partition, &dev_offset, &fd_size)) { - err(EXIT_FAILURE, "Could not find partition %d", partition); + if (partition != -1) { + ret = find_partition(bs, partition, &dev_offset, &fd_size); + if (ret < 0) { + errno = -ret; + err(EXIT_FAILURE, "Could not find partition %d", partition); + } } exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags);