xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Christoph Egger <Christoph.Egger@amd.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 2/2] qemu-xen-trad/block: get right partition size
Date: Wed, 30 May 2012 14:45:22 +0100	[thread overview]
Message-ID: <1338385522-21949-3-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1338385522-21949-1-git-send-email-roger.pau@citrix.com>

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>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 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;
-- 
1.7.7.5 (Apple Git-26)

  parent reply	other threads:[~2012-05-30 13:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
2012-05-30 13:45 ` [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given Roger Pau Monne
2012-05-30 13:45 ` Roger Pau Monne [this message]
2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
2012-05-30 16:13   ` Roger Pau Monne
2012-06-07 18:39   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338385522-21949-3-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=Christoph.Egger@amd.com \
    --cc=kwolf@redhat.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).