summaryrefslogtreecommitdiff
path: root/block/raw-posix.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2010-04-06 19:13:44 +0200
committerKevin Wolf <kwolf@redhat.com>2010-04-23 16:08:46 +0200
commit50779cc264aa1abd75aa5afa34740d4fd8481f1d (patch)
tree6489782c15486ff9d7d7325513890554d6d00888 /block/raw-posix.c
parent6db956039db8a6333265d458be561dc1bc2b4481 (diff)
downloadqemu-50779cc264aa1abd75aa5afa34740d4fd8481f1d.tar.gz
block: split raw_getlength
Split up the raw_getlength into separate generic, solaris and BSD versions to reduce the ifdef maze a bit. The BSD variant still is a complete maze, but to clean it up properly we'd need some people using the BSD variants to figure out what code is used for what variant. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/raw-posix.c')
-rw-r--r--block/raw-posix.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 6521ca442a..4cda9c1f85 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -627,29 +627,48 @@ static int64_t raw_getlength(BlockDriverState *bs)
} else
return st.st_size;
}
-#else /* !__OpenBSD__ */
-static int64_t raw_getlength(BlockDriverState *bs)
+#elif defined(__sun__)
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ struct dk_minfo minfo;
+ int ret;
+
+ ret = fd_open(bs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ /*
+ * Use the DKIOCGMEDIAINFO ioctl to read the size.
+ */
+ ret = ioctl(s->fd, DKIOCGMEDIAINFO, &minfo);
+ if (ret != -1) {
+ return minfo.dki_lbsize * minfo.dki_capacity;
+ }
+
+ /*
+ * There are reports that lseek on some devices fails, but
+ * irc discussion said that contingency on contingency was overkill.
+ */
+ return lseek(s->fd, 0, SEEK_END);
+}
+#elif defined(CONFIG_BSD)
+static int64_t raw_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int fd = s->fd;
int64_t size;
-#ifdef CONFIG_BSD
struct stat sb;
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
int reopened = 0;
#endif
-#endif
-#ifdef __sun__
- struct dk_minfo minfo;
- int rv;
-#endif
int ret;
ret = fd_open(bs);
if (ret < 0)
return ret;
-#ifdef CONFIG_BSD
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
again:
#endif
@@ -684,24 +703,24 @@ again:
}
}
#endif
- } else
-#endif
-#ifdef __sun__
- /*
- * use the DKIOCGMEDIAINFO ioctl to read the size.
- */
- rv = ioctl ( fd, DKIOCGMEDIAINFO, &minfo );
- if ( rv != -1 ) {
- size = minfo.dki_lbsize * minfo.dki_capacity;
- } else /* there are reports that lseek on some devices
- fails, but irc discussion said that contingency
- on contingency was overkill */
-#endif
- {
+ } else {
size = lseek(fd, 0, SEEK_END);
}
return size;
}
+#else
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ int ret;
+
+ ret = fd_open(bs);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return lseek(s->fd, 0, SEEK_END);
+}
#endif
static int raw_create(const char *filename, QEMUOptionParameter *options)