1 #include <sys/param.h>
2 #include <sys/ioctl.h>
3 #include <sys/disklabel.h>
4 #include <errno.h>
5 #include <inttypes.h>
6 #include "tapdisk.h"
7 #include "blk.h"
8 
blk_getimagesize(int fd,uint64_t * size)9 int blk_getimagesize(int fd, uint64_t *size)
10 {
11 	int rc;
12 	struct disklabel dl;
13 
14 	*size = 0;
15 	rc = ioctl(fd, DIOCGDINFO, &dl);
16 	if (rc) {
17 		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
18 		return -EINVAL;
19 	}
20 
21 	*size = dl.d_secsize * dl.d_secpercyl;
22 
23 	return 0;
24 }
25 
blk_getsectorsize(int fd,uint64_t * sector_size)26 int blk_getsectorsize(int fd, uint64_t *sector_size)
27 {
28 	int rc;
29 	struct disklabel dl;
30 
31 	*sector_size = DEV_BSIZE;
32 	rc = ioctl(fd, DIOCGDINFO, &dl);
33 	if (rc) {
34 		DPRINTF("ERR: DIOCGDINFO failed, couldn't stat image");
35 		return 0; /* fallback to DEV_BSIZE */
36 	}
37 
38 	*sector_size = dl.d_secsize;
39 	return 0;
40 }
41 
42