[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] block/raw-posix: get right partition size
From: |
Christoph Egger |
Subject: |
[Qemu-devel] [PATCH] block/raw-posix: get right partition size |
Date: |
Mon, 23 May 2011 14:31:17 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; NetBSD amd64; en-US; rv:1.9.2.13) Gecko/20110202 Lightning/1.0b3pre Thunderbird/3.1.7 |
use the correct way to get the size of a disk device or partition
From: Adam Hamsik <address@hidden>
Signed-off-by: Christoph Egger <address@hidden>
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6b72470..d05f373 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -64,6 +64,13 @@
#include <sys/dkio.h>
#endif
+#ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#include <sys/disk.h>
+#endif
+
#ifdef __DragonFly__
#include <sys/ioctl.h>
#include <sys/diskslice.h>
@@ -622,6 +663,31 @@ static int64_t raw_getlength(BlockDriverState *bs)
} else
return st.st_size;
}
+#elif defined(__NetBSD__)
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ int fd = s->fd;
+ struct stat st;
+
+ if (fstat(fd, &st))
+ return -1;
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
+ struct dkwedge_info dkw;
+
+ if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) {
+ return dkw.dkw_size * 512;
+ } else {
+ struct disklabel dl;
+
+ if (ioctl(fd, DIOCGDINFO, &dl))
+ return -1;
+ return (uint64_t)dl.d_secsize *
+ dl.d_partitions[DISKPART(st.st_rdev)].p_size;
+ }
+ } else
+ return st.st_size;
+}
#elif defined(__sun__)
static int64_t raw_getlength(BlockDriverState *bs)
{
--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632