aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2/drivers/blk_netbsd.c
blob: f394fdf00803334ff8ddc11f75530c1fcb119209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h>
#include <errno.h>
#include <inttypes.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;
}