blob: bb5271705053df4726d523b44c924da9501c3c95 (
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
42
|
#include <inttypes.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include "tapdisk.h"
#include "blk.h"
int blk_getimagesize(int fd, uint64_t *size)
{
int rc;
*size = 0;
rc = ioctl(fd, BLKGETSIZE, size);
if (rc) {
DPRINTF("ERR: BLKGETSIZE failed, couldn't stat image");
return -EINVAL;
}
return 0;
}
int blk_getsectorsize(int fd, uint64_t *sector_size)
{
#if defined(BLKSSZGET)
int rc;
*sector_size = DEFAULT_SECTOR_SIZE;
rc = ioctl(fd, BLKSSZGET, sector_size);
if (rc) {
DPRINTF("ERR: BLKSSZGET failed. Falling back to use default sector size");
*sector_size = DEFAULT_SECTOR_SIZE;
}
if (*sector_size != DEFAULT_SECTOR_SIZE)
DPRINTF("Note: sector size is %"PRIu64" (not %u)\n",
*sector_size, DEFAULT_SECTOR_SIZE);
#else
*sector_size = DEFAULT_SECTOR_SIZE;
#endif
return 0;
}
|