Add linux-next specific files for 20110831
[linux-2.6/next.git] / tools / kvm / disk / blk.c
blob59294e841dc168f52051dacbfa33490ee664d383
1 #include "kvm/disk-image.h"
3 /*
4 * raw image and blk dev are similar, so reuse raw image ops.
5 */
6 static struct disk_image_operations blk_dev_ops = {
7 .read_sector = raw_image__read_sector,
8 .write_sector = raw_image__write_sector,
9 .close = raw_image__close,
12 struct disk_image *blkdev__probe(const char *filename, struct stat *st)
14 u64 size;
15 int fd;
17 if (!S_ISBLK(st->st_mode))
18 return NULL;
21 * Be careful! We are opening host block device!
22 * Open it readonly since we do not want to break user's data on disk.
24 fd = open(filename, O_RDONLY);
25 if (fd < 0)
26 return NULL;
28 if (ioctl(fd, BLKGETSIZE64, &size) < 0) {
29 close(fd);
30 return NULL;
34 * FIXME: This will not work on 32-bit host because we can not
35 * mmap large disk. There is not enough virtual address space
36 * in 32-bit host. However, this works on 64-bit host.
38 return disk_image__new(fd, size, &blk_dev_ops, DISK_IMAGE_MMAP);