From 5a98025be00746c357b68c027b95888f0fbe7d6e Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Fri, 21 Apr 2017 22:42:48 -0700 Subject: [PATCH] get proper size for raw block devices. This will let you pass through raw block devices to the guest, like this: "-s 5,virtio-blk,/dev/disk4" --- src/block_if.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/block_if.c b/src/block_if.c index 4d5df95..60534e9 100644 --- a/src/block_if.c +++ b/src/block_if.c @@ -512,8 +512,20 @@ blockif_open(const char *optstr, UNUSED const char *ident) // candelete = arg.value.i; // if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0) // geom = 1; - } else + } else if (S_ISBLK(sbuf.st_mode)) { + uint64_t num_blocks; + uint32_t block_size; + if (ioctl(fd, DKIOCGETBLOCKSIZE, (void*)&block_size) < 0) { + perror("DKIOCGETBLOCKSIZE"); + } + if (ioctl(fd, DKIOCGETBLOCKCOUNT, (void*)&num_blocks) < 0) { + perror("DKIOCGETBLOCKCOUNT"); + } + size = (off_t) (num_blocks * block_size); + sectsz = (int) block_size; + } else { psectsz = sbuf.st_blksize; + } if (ssopt != 0) { if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 ||