1 #include <inttypes.h>
2 #include <errno.h>
3 #include <sys/ioctl.h>
4 #include <sys/mount.h>
5 #include "tapdisk.h"
6 #include "blk.h"
7 
blk_getimagesize(int fd,uint64_t * size)8 int blk_getimagesize(int fd, uint64_t *size)
9 {
10 	int rc;
11 
12 	*size = 0;
13 	rc = ioctl(fd, BLKGETSIZE, size);
14 	if (rc) {
15 		DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
16 		return -EINVAL;
17 	}
18 
19 	return 0;
20 }
21 
blk_getsectorsize(int fd,uint64_t * sector_size)22 int blk_getsectorsize(int fd, uint64_t *sector_size)
23 {
24 #if defined(BLKSSZGET)
25 	int rc;
26 
27 	*sector_size = DEFAULT_SECTOR_SIZE;
28 	rc = ioctl(fd, BLKSSZGET, sector_size);
29 	if (rc) {
30 		DPRINTF("ERR: BLKSSZGET failed. Falling back to use default sector size");
31 		*sector_size = DEFAULT_SECTOR_SIZE;
32 	}
33 
34 	if (*sector_size != DEFAULT_SECTOR_SIZE)
35 		DPRINTF("Note: sector size is %"PRIu64" (not %u)\n",
36 			*sector_size, DEFAULT_SECTOR_SIZE);
37 #else
38 	*sector_size = DEFAULT_SECTOR_SIZE;
39 #endif
40 
41 	return 0;
42 }
43 
44