debuggers.hg

view tools/blktap2/drivers/blk_linux.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 0dbad563a659
children
line source
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"
8 int blk_getimagesize(int fd, uint64_t *size)
9 {
10 int rc;
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 }
19 return 0;
20 }
22 int blk_getsectorsize(int fd, uint64_t *sector_size)
23 {
24 #if defined(BLKSSZGET)
25 int rc;
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 }
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
41 return 0;
42 }