summaryrefslogtreecommitdiff
path: root/sysutils/xentools46/files/blk_netbsd.c
blob: 7ba8d407db3c9937c9aa321e33d84acc08a753e2 (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
#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;
}