00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef BLOCK_INT_H
00025 #define BLOCK_INT_H
00026
00027 #include "block.h"
00028
00029 #define BLOCK_FLAG_ENCRYPT 1
00030 #define BLOCK_FLAG_COMPRESS 2
00031 #define BLOCK_FLAG_COMPAT6 4
00032
00033 typedef struct AIOPool {
00034 void (*cancel)(BlockDriverAIOCB *acb);
00035 int aiocb_size;
00036 BlockDriverAIOCB *free_aiocb;
00037 } AIOPool;
00038
00039 struct BlockDriver {
00040 const char *format_name;
00041 int instance_size;
00042 int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
00043 int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags);
00044 int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
00045 uint8_t *buf, int nb_sectors);
00046 int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
00047 const uint8_t *buf, int nb_sectors);
00048 void (*bdrv_close)(BlockDriverState *bs);
00049 int (*bdrv_create)(const char *filename, int64_t total_sectors,
00050 const char *backing_file, int flags);
00051 void (*bdrv_flush)(BlockDriverState *bs);
00052 int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
00053 int nb_sectors, int *pnum);
00054 int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
00055 int (*bdrv_make_empty)(BlockDriverState *bs);
00056
00057 BlockDriverAIOCB *(*bdrv_aio_read)(BlockDriverState *bs,
00058 int64_t sector_num, uint8_t *buf, int nb_sectors,
00059 BlockDriverCompletionFunc *cb, void *opaque);
00060 BlockDriverAIOCB *(*bdrv_aio_write)(BlockDriverState *bs,
00061 int64_t sector_num, const uint8_t *buf, int nb_sectors,
00062 BlockDriverCompletionFunc *cb, void *opaque);
00063 void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);
00064 int aiocb_size;
00065
00066 const char *protocol_name;
00067 int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
00068 uint8_t *buf, int count);
00069 int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
00070 const uint8_t *buf, int count);
00071 int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
00072 int64_t (*bdrv_getlength)(BlockDriverState *bs);
00073 int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
00074 const uint8_t *buf, int nb_sectors);
00075
00076 int (*bdrv_snapshot_create)(BlockDriverState *bs,
00077 QEMUSnapshotInfo *sn_info);
00078 int (*bdrv_snapshot_goto)(BlockDriverState *bs,
00079 const char *snapshot_id);
00080 int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
00081 int (*bdrv_snapshot_list)(BlockDriverState *bs,
00082 QEMUSnapshotInfo **psn_info);
00083 int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
00084
00085 int (*bdrv_put_buffer)(BlockDriverState *bs, const uint8_t *buf,
00086 int64_t pos, int size);
00087 int (*bdrv_get_buffer)(BlockDriverState *bs, uint8_t *buf,
00088 int64_t pos, int size);
00089
00090
00091 int (*bdrv_is_inserted)(BlockDriverState *bs);
00092 int (*bdrv_media_changed)(BlockDriverState *bs);
00093 int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
00094 int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
00095
00096
00097 int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
00098
00099 AIOPool aio_pool;
00100 struct BlockDriver *next;
00101 };
00102
00103 struct BlockDriverState {
00104 int64_t total_sectors;
00105
00106 int read_only;
00107 int removable;
00108 int locked;
00109 int encrypted;
00110 int valid_key;
00111 int sg;
00112
00113 void (*change_cb)(void *opaque);
00114 void *change_opaque;
00115
00116 BlockDriver *drv;
00117 void *opaque;
00118
00119 char filename[1024];
00120 char backing_file[1024];
00121
00122 int is_temporary;
00123 int media_changed;
00124
00125 BlockDriverState *backing_hd;
00126
00127
00128 void *sync_aiocb;
00129
00130
00131 uint64_t rd_bytes;
00132 uint64_t wr_bytes;
00133 uint64_t rd_ops;
00134 uint64_t wr_ops;
00135
00136
00137 int growable;
00138
00139
00140
00141 int cyls, heads, secs, translation;
00142 int type;
00143 char device_name[32];
00144 BlockDriverState *next;
00145 void *private;
00146 };
00147
00148 struct BlockDriverAIOCB {
00149 AIOPool *pool;
00150 BlockDriverState *bs;
00151 BlockDriverCompletionFunc *cb;
00152 void *opaque;
00153 BlockDriverAIOCB *next;
00154 };
00155
00156 void get_tmp_filename(char *filename, int size);
00157
00158 void aio_pool_init(AIOPool *pool, int aiocb_size,
00159 void (*cancel)(BlockDriverAIOCB *acb));
00160
00161 void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
00162 void *opaque);
00163 void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
00164 BlockDriverCompletionFunc *cb, void *opaque);
00165 void qemu_aio_release(void *p);
00166
00167 extern BlockDriverState *bdrv_first;
00168
00169 #endif