1 #ifndef KVM__DISK_IMAGE_H
2 #define KVM__DISK_IMAGE_H
4 #include "kvm/read-write.h"
7 #include <linux/types.h>
8 #include <linux/fs.h> /* for BLKGETSIZE64 */
10 #include <sys/types.h>
21 #define SECTOR_SHIFT 9
22 #define SECTOR_SIZE (1UL << SECTOR_SHIFT)
24 #define DISK_IMAGE_MMAP 0
25 #define DISK_IMAGE_NOMMAP 1
26 #define MAX_DISK_IMAGES 4
30 struct disk_image_operations
{
32 * The following two are used for reading or writing with a single buffer.
33 * The implentation can use readv/writev or memcpy.
35 ssize_t (*read_sector
)(struct disk_image
*disk
, u64 sector
, void *dst
, u32 dst_len
);
36 ssize_t (*write_sector
)(struct disk_image
*disk
, u64 sector
, void *src
, u32 src_len
);
38 * The following two are used for reading or writing with multiple buffers.
39 * The implentation can use readv/writev or memcpy.
41 ssize_t (*read_sector_iov
)(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
42 ssize_t (*write_sector_iov
)(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
43 int (*flush
)(struct disk_image
*disk
);
44 int (*close
)(struct disk_image
*disk
);
50 struct disk_image_operations
*ops
;
54 struct disk_image
*disk_image__open(const char *filename
, bool readonly
);
55 struct disk_image
**disk_image__open_all(const char **filenames
, bool *readonly
, int count
);
56 struct disk_image
*disk_image__new(int fd
, u64 size
, struct disk_image_operations
*ops
, int mmap
);
57 int disk_image__close(struct disk_image
*disk
);
58 void disk_image__close_all(struct disk_image
**disks
, int count
);
59 int disk_image__flush(struct disk_image
*disk
);
60 ssize_t
disk_image__read(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
61 ssize_t
disk_image__write(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
62 ssize_t
disk_image__get_serial(struct disk_image
*disk
, void *buffer
, ssize_t
*len
);
64 struct disk_image
*raw_image__probe(int fd
, struct stat
*st
, bool readonly
);
65 struct disk_image
*blkdev__probe(const char *filename
, struct stat
*st
);
67 ssize_t
raw_image__read_sector_iov(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
68 ssize_t
raw_image__write_sector_iov(struct disk_image
*disk
, u64 sector
, const struct iovec
*iov
, int iovcount
);
69 ssize_t
raw_image__read_sector(struct disk_image
*disk
, u64 sector
, void *dst
, u32 dst_len
);
70 ssize_t
raw_image__write_sector(struct disk_image
*disk
, u64 sector
, void *src
, u32 src_len
);
71 int raw_image__close(struct disk_image
*disk
);
73 #endif /* KVM__DISK_IMAGE_H */