aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap/drivers/block-ram.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/blktap/drivers/block-ram.c')
-rw-r--r--tools/blktap/drivers/block-ram.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/tools/blktap/drivers/block-ram.c b/tools/blktap/drivers/block-ram.c
index 3b4ef7ceb5..f39d6422b2 100644
--- a/tools/blktap/drivers/block-ram.c
+++ b/tools/blktap/drivers/block-ram.c
@@ -33,16 +33,22 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <linux/fs.h>
#include <string.h>
#include "tapdisk.h"
+#include "blk.h"
#define MAX_DISK_SIZE 1024000 /*500MB disk limit*/
+/* *BSD has no O_LARGEFILE */
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
char *img;
long int disksector_size;
long int disksize;
@@ -71,11 +77,8 @@ static int get_image_info(struct td_state *s, int fd)
if (S_ISBLK(stat.st_mode)) {
/*Accessing block device directly*/
- s->size = 0;
- if (ioctl(fd,BLKGETSIZE,&s->size)!=0) {
- DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+ if (blk_getimagesize(fd, &s->size) != 0)
return -EINVAL;
- }
DPRINTF("Image size: \n\tpre sector_shift [%llu]\n\tpost "
"sector_shift [%llu]\n",
@@ -83,19 +86,8 @@ static int get_image_info(struct td_state *s, int fd)
(long long unsigned)s->size);
/*Get the sector size*/
-#if defined(BLKSSZGET)
- {
- int arg;
+ if (blk_getsectorsize(fd, &s->sector_size) != 0)
s->sector_size = DEFAULT_SECTOR_SIZE;
- ioctl(fd, BLKSSZGET, &s->sector_size);
-
- if (s->sector_size != DEFAULT_SECTOR_SIZE)
- DPRINTF("Note: sector size is %ld (not %d)\n",
- s->sector_size, DEFAULT_SECTOR_SIZE);
- }
-#else
- s->sector_size = DEFAULT_SECTOR_SIZE;
-#endif
} else {
/*Local file? try fstat instead*/
@@ -117,7 +109,7 @@ static int get_image_info(struct td_state *s, int fd)
disksector_size = s->sector_size;
disksize = s->size;
diskinfo = s->info;
- DPRINTF("Image sector_size: \n\t[%lu]\n",
+ DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
s->sector_size);
return 0;
@@ -159,7 +151,7 @@ int tdram_open (struct disk_driver *dd, const char *name, td_flag_t flags)
"sector_shift [%llu]\n",
(long long unsigned)(s->size << SECTOR_SHIFT),
(long long unsigned)s->size);
- DPRINTF("Image sector_size: \n\t[%lu]\n",
+ DPRINTF("Image sector_size: \n\t[%"PRIu64"]\n",
s->sector_size);
prv->fd = -1;