summaryrefslogtreecommitdiff
path: root/sysutils/xentools42/files/blk_netbsd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysutils/xentools42/files/blk_netbsd.c')
-rw-r--r--sysutils/xentools42/files/blk_netbsd.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/sysutils/xentools42/files/blk_netbsd.c b/sysutils/xentools42/files/blk_netbsd.c
new file mode 100644
index 00000000000..7ba8d407db3
--- /dev/null
+++ b/sysutils/xentools42/files/blk_netbsd.c
@@ -0,0 +1,38 @@
+#include <inttypes.h>
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include "tapdisk.h"
+#include "blk.h"
+
+int blk_getimagesize(int fd, uint64_t *size)
+{
+ int rc;
+ struct disklabel dl;
+
+ *size = 0;
+ rc = ioctl(fd, DIOCGDINFO, &dl);
+ if (rc) {
+ DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
+ return -EINVAL;
+ }
+
+ *size = dl.d_secsize * dl.d_secpercyl;
+
+ return 0;
+}
+
+int blk_getsectorsize(int fd, uint64_t *sector_size)
+{
+ int rc;
+ struct disklabel dl;
+
+ *sector_size = DEV_BSIZE;
+ rc = ioctl(fd, DIOCGDINFO, &dl);
+ if (rc) {
+ DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
+ return 0; /* fallback to DEV_BSIZE */
+ }
+
+ *sector_size = dl.d_secsize;
+ return 0;
+}