aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap/drivers/blk_linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/blktap/drivers/blk_linux.c')
-rw-r--r--tools/blktap/drivers/blk_linux.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/blktap/drivers/blk_linux.c b/tools/blktap/drivers/blk_linux.c
new file mode 100644
index 0000000000..f1b14bd6e8
--- /dev/null
+++ b/tools/blktap/drivers/blk_linux.c
@@ -0,0 +1,42 @@
+#include <inttypes.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+#include "tapdisk.h"
+#include "blk.h"
+
+int blk_getimagesize(int fd, uint64_t *size)
+{
+ int rc;
+
+ *size = 0;
+ rc = ioctl(fd, BLKGETSIZE, size);
+ if (rc) {
+ DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int blk_getsectorsize(int fd, uint64_t *sector_size)
+{
+#if defined(BLKSSZGET)
+ int rc;
+
+ *sector_size = DEFAULT_SECTOR_SIZE;
+ rc = ioctl(fd, BLKSSZGET, sector_size);
+ if (rc) {
+ DPRINTF("ERR: BLKSSZGET failed. Falling back to use default sector size");
+ *sector_size = DEFAULT_SECTOR_SIZE;
+ }
+
+ if (*sector_size != DEFAULT_SECTOR_SIZE)
+ DPRINTF("Note: sector size is %"PRIu64" (not %u)\n",
+ *sector_size, DEFAULT_SECTOR_SIZE);
+#else
+ *sector_size = DEFAULT_SECTOR_SIZE;
+#endif
+
+ return 0;
+}
+