]> xenbits.xensource.com Git - qemu-xen-4.2-testing.git/commitdiff
qemu-xen-trad/block: get right partition size
authorAdam Hamsik <haad@netbsd.org>
Thu, 7 Jun 2012 18:36:26 +0000 (19:36 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 7 Jun 2012 18:37:55 +0000 (19:37 +0100)
use the correct way to get the size of a disk device or partition

This this a backport of d1f6fd8d1400ab356aee776b1ecc3ed1e89dbeaa.

From: Adam Hamsik <haad@netbsd.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Backport-requested-by: Roger Pau Monne <roger.pau@citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
block-raw-posix.c

index e7d745787218105a25277a32d6576f508f2746b2..795cd5b782f67118a5dcfa4002a1bbcb9c5cff6f 100644 (file)
 #include <signal.h>
 #include <sys/disk.h>
 #endif
+#ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#include <sys/disk.h>
+#endif
 
 #ifdef __OpenBSD__
 #include <sys/ioctl.h>
@@ -811,7 +817,32 @@ static int64_t raw_getlength(BlockDriverState *bs)
     } else
         return st.st_size;
 }
-#else /* !__OpenBSD__ */
+#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;
+}
+#else /* !__OpenBSD__ && !__NetBSD__ */
 static int64_t  raw_getlength(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;