00001 #ifndef BLOCK_H
00002 #define BLOCK_H
00003
00004 #include "qemu-aio.h"
00005 #include "qemu-common.h"
00006
00007
00008 typedef struct BlockDriver BlockDriver;
00009
00010 extern BlockDriver bdrv_raw;
00011 extern BlockDriver bdrv_host_device;
00012 extern BlockDriver bdrv_cow;
00013 extern BlockDriver bdrv_qcow;
00014 extern BlockDriver bdrv_vmdk;
00015 extern BlockDriver bdrv_cloop;
00016 extern BlockDriver bdrv_dmg;
00017 extern BlockDriver bdrv_bochs;
00018 extern BlockDriver bdrv_vpc;
00019 extern BlockDriver bdrv_vvfat;
00020 extern BlockDriver bdrv_qcow2;
00021 extern BlockDriver bdrv_parallels;
00022 extern BlockDriver bdrv_nbd;
00023
00024 typedef struct BlockDriverInfo {
00025
00026 int cluster_size;
00027
00028 int64_t vm_state_offset;
00029 } BlockDriverInfo;
00030
00031 typedef struct QEMUSnapshotInfo {
00032 char id_str[128];
00033
00034
00035 char name[256];
00036 uint32_t vm_state_size;
00037 uint32_t date_sec;
00038 uint32_t date_nsec;
00039 uint64_t vm_clock_nsec;
00040 } QEMUSnapshotInfo;
00041
00042 #define BDRV_O_RDONLY 0x0000
00043 #define BDRV_O_RDWR 0x0002
00044 #define BDRV_O_ACCESS 0x0003
00045 #define BDRV_O_CREAT 0x0004
00046 #define BDRV_O_SNAPSHOT 0x0008
00047 #define BDRV_O_FILE 0x0010
00048
00049
00050
00051 #define BDRV_O_NOCACHE 0x0020
00052 #define BDRV_O_CACHE_WB 0x0040
00053 #define BDRV_O_CACHE_DEF 0x0080
00054
00055 #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)
00056
00057 void bdrv_info(void);
00058 void bdrv_info_stats(void);
00059
00060 void bdrv_init(void);
00061 BlockDriver *bdrv_find_format(const char *format_name);
00062 int bdrv_create(BlockDriver *drv,
00063 const char *filename, int64_t size_in_sectors,
00064 const char *backing_file, int flags);
00065 BlockDriverState *bdrv_new(const char *device_name);
00066 void bdrv_delete(BlockDriverState *bs);
00067 int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
00068 int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
00069 int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
00070 BlockDriver *drv);
00071 void bdrv_close(BlockDriverState *bs);
00072 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
00073 uint8_t *buf, int nb_sectors);
00074 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
00075 const uint8_t *buf, int nb_sectors);
00076 int bdrv_pread(BlockDriverState *bs, int64_t offset,
00077 void *buf, int count);
00078 int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
00079 const void *buf, int count);
00080 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
00081 int64_t bdrv_getlength(BlockDriverState *bs);
00082 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
00083 void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
00084 int bdrv_commit(BlockDriverState *bs);
00085
00086 typedef struct BlockDriverAIOCB BlockDriverAIOCB;
00087 typedef void BlockDriverCompletionFunc(void *opaque, int ret);
00088
00089 BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
00090 QEMUIOVector *iov, int nb_sectors,
00091 BlockDriverCompletionFunc *cb, void *opaque);
00092 BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
00093 QEMUIOVector *iov, int nb_sectors,
00094 BlockDriverCompletionFunc *cb, void *opaque);
00095
00096 BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
00097 uint8_t *buf, int nb_sectors,
00098 BlockDriverCompletionFunc *cb, void *opaque);
00099 BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
00100 const uint8_t *buf, int nb_sectors,
00101 BlockDriverCompletionFunc *cb, void *opaque);
00102 void bdrv_aio_cancel(BlockDriverAIOCB *acb);
00103
00104
00105 void bdrv_flush(BlockDriverState *bs);
00106 void bdrv_flush_all(void);
00107
00108 int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
00109 int *pnum);
00110
00111 #define BDRV_TYPE_HD 0
00112 #define BDRV_TYPE_CDROM 1
00113 #define BDRV_TYPE_FLOPPY 2
00114 #define BIOS_ATA_TRANSLATION_AUTO 0
00115 #define BIOS_ATA_TRANSLATION_NONE 1
00116 #define BIOS_ATA_TRANSLATION_LBA 2
00117 #define BIOS_ATA_TRANSLATION_LARGE 3
00118 #define BIOS_ATA_TRANSLATION_RECHS 4
00119
00120 void bdrv_set_geometry_hint(BlockDriverState *bs,
00121 int cyls, int heads, int secs);
00122 void bdrv_set_type_hint(BlockDriverState *bs, int type);
00123 void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
00124 void bdrv_get_geometry_hint(BlockDriverState *bs,
00125 int *pcyls, int *pheads, int *psecs);
00126 int bdrv_get_type_hint(BlockDriverState *bs);
00127 int bdrv_get_translation_hint(BlockDriverState *bs);
00128 int bdrv_is_removable(BlockDriverState *bs);
00129 int bdrv_is_read_only(BlockDriverState *bs);
00130 int bdrv_is_sg(BlockDriverState *bs);
00131 int bdrv_is_inserted(BlockDriverState *bs);
00132 int bdrv_media_changed(BlockDriverState *bs);
00133 int bdrv_is_locked(BlockDriverState *bs);
00134 void bdrv_set_locked(BlockDriverState *bs, int locked);
00135 void bdrv_eject(BlockDriverState *bs, int eject_flag);
00136 void bdrv_set_change_cb(BlockDriverState *bs,
00137 void (*change_cb)(void *opaque), void *opaque);
00138 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
00139 BlockDriverState *bdrv_find(const char *name);
00140 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
00141 void *opaque);
00142 int bdrv_is_encrypted(BlockDriverState *bs);
00143 int bdrv_key_required(BlockDriverState *bs);
00144 int bdrv_set_key(BlockDriverState *bs, const char *key);
00145 int bdrv_query_missing_keys(void);
00146 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
00147 void *opaque);
00148 const char *bdrv_get_device_name(BlockDriverState *bs);
00149 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
00150 const uint8_t *buf, int nb_sectors);
00151 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
00152
00153 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
00154 void bdrv_get_backing_filename(BlockDriverState *bs,
00155 char *filename, int filename_size);
00156 int bdrv_snapshot_create(BlockDriverState *bs,
00157 QEMUSnapshotInfo *sn_info);
00158 int bdrv_snapshot_goto(BlockDriverState *bs,
00159 const char *snapshot_id);
00160 int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
00161 int bdrv_snapshot_list(BlockDriverState *bs,
00162 QEMUSnapshotInfo **psn_info);
00163 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
00164 int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
00165
00166 char *get_human_readable_size(char *buf, int buf_size, int64_t size);
00167 int path_is_absolute(const char *path);
00168 void path_combine(char *dest, int dest_size,
00169 const char *base_path,
00170 const char *filename);
00171
00172 int bdrv_put_buffer(BlockDriverState *bs, const uint8_t *buf,
00173 int64_t pos, int size);
00174
00175 int bdrv_get_buffer(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size);
00176
00177 #endif