[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [qemu-xen-unstable] qemu-xen-trad/block: get right partition size



commit cbf0f291d4f1d40c59f56b8bd73292b8ad4f84b5
Author: Adam Hamsik <haad@xxxxxxxxxx>
Date:   Thu Jun 7 19:36:26 2012 +0100

    qemu-xen-trad/block: get right partition size
    
    use the correct way to get the size of a disk device or partition
    
    This this a backport of d1f6fd8d1400ab356aee776b1ecc3ed1e89dbeaa.
    
    From: Adam Hamsik <haad@xxxxxxxxxx>
    Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
    Signed-off-by: Kevin Wolf <kwolf@xxxxxxxxxx>
    
    Backport-requested-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
    Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
---
 block-raw-posix.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index e7d7457..795cd5b 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -60,6 +60,12 @@
 #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;
--
generated by git-patchbot for /home/xen/git/qemu-xen-unstable.git

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.