pkgsrc/sysutils/xentools46/files/blk_netbsd.c
jnemeth 2ccc347bbb The Xen virtual machine monitor allows running several virtual machines
on a single physical machine.  The xentools46 package contains the
tools to create, destroy and control the virtual machines.

This package contains the tools for Xen 4.6.x
2016-07-04 07:30:47 +00:00

38 lines
686 B
C

#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;
}