root / block_int.h @ 94909d9f
History | View | Annotate | Download (6.8 kB)
1 | ea2384d3 | bellard | /*
|
---|---|---|---|
2 | ea2384d3 | bellard | * QEMU System Emulator block driver
|
3 | 5fafdf24 | ths | *
|
4 | ea2384d3 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | ea2384d3 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | ea2384d3 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | ea2384d3 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | ea2384d3 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | ea2384d3 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | ea2384d3 | bellard | * furnished to do so, subject to the following conditions:
|
12 | ea2384d3 | bellard | *
|
13 | ea2384d3 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | ea2384d3 | bellard | * all copies or substantial portions of the Software.
|
15 | ea2384d3 | bellard | *
|
16 | ea2384d3 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | ea2384d3 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | ea2384d3 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | ea2384d3 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | ea2384d3 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | ea2384d3 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | ea2384d3 | bellard | * THE SOFTWARE.
|
23 | ea2384d3 | bellard | */
|
24 | ea2384d3 | bellard | #ifndef BLOCK_INT_H
|
25 | ea2384d3 | bellard | #define BLOCK_INT_H
|
26 | ea2384d3 | bellard | |
27 | faf07963 | pbrook | #include "block.h" |
28 | faf07963 | pbrook | |
29 | ec36ba14 | ths | #define BLOCK_FLAG_ENCRYPT 1 |
30 | ec36ba14 | ths | #define BLOCK_FLAG_COMPRESS 2 |
31 | ec36ba14 | ths | #define BLOCK_FLAG_COMPAT6 4 |
32 | ec36ba14 | ths | |
33 | 6bbff9a0 | aliguori | typedef struct AIOPool { |
34 | 6bbff9a0 | aliguori | void (*cancel)(BlockDriverAIOCB *acb);
|
35 | 6bbff9a0 | aliguori | int aiocb_size;
|
36 | 6bbff9a0 | aliguori | BlockDriverAIOCB *free_aiocb; |
37 | 6bbff9a0 | aliguori | } AIOPool; |
38 | 6bbff9a0 | aliguori | |
39 | ea2384d3 | bellard | struct BlockDriver {
|
40 | ea2384d3 | bellard | const char *format_name; |
41 | ea2384d3 | bellard | int instance_size;
|
42 | ea2384d3 | bellard | int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); |
43 | 83f64091 | bellard | int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags); |
44 | 5fafdf24 | ths | int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
45 | ea2384d3 | bellard | uint8_t *buf, int nb_sectors);
|
46 | 5fafdf24 | ths | int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
47 | ea2384d3 | bellard | const uint8_t *buf, int nb_sectors); |
48 | e2731add | bellard | void (*bdrv_close)(BlockDriverState *bs);
|
49 | 5fafdf24 | ths | int (*bdrv_create)(const char *filename, int64_t total_sectors, |
50 | ea2384d3 | bellard | const char *backing_file, int flags); |
51 | 7a6cba61 | pbrook | void (*bdrv_flush)(BlockDriverState *bs);
|
52 | ea2384d3 | bellard | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
|
53 | ea2384d3 | bellard | int nb_sectors, int *pnum); |
54 | ea2384d3 | bellard | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); |
55 | 95389c86 | bellard | int (*bdrv_make_empty)(BlockDriverState *bs);
|
56 | 83f64091 | bellard | /* aio */
|
57 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, |
58 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
59 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
60 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs, |
61 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
62 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
63 | 83f64091 | bellard | void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);
|
64 | ce1a14dc | pbrook | int aiocb_size;
|
65 | 83f64091 | bellard | |
66 | 83f64091 | bellard | const char *protocol_name; |
67 | 83f64091 | bellard | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
|
68 | 83f64091 | bellard | int64_t (*bdrv_getlength)(BlockDriverState *bs); |
69 | 5fafdf24 | ths | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
70 | faea38e7 | bellard | const uint8_t *buf, int nb_sectors); |
71 | faea38e7 | bellard | |
72 | 5fafdf24 | ths | int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
73 | faea38e7 | bellard | QEMUSnapshotInfo *sn_info); |
74 | 5fafdf24 | ths | int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
75 | faea38e7 | bellard | const char *snapshot_id); |
76 | faea38e7 | bellard | int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id); |
77 | 5fafdf24 | ths | int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
78 | faea38e7 | bellard | QEMUSnapshotInfo **psn_info); |
79 | faea38e7 | bellard | int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
80 | 83f64091 | bellard | |
81 | 178e08a5 | aliguori | int (*bdrv_put_buffer)(BlockDriverState *bs, const uint8_t *buf, |
82 | 178e08a5 | aliguori | int64_t pos, int size);
|
83 | 178e08a5 | aliguori | int (*bdrv_get_buffer)(BlockDriverState *bs, uint8_t *buf,
|
84 | 178e08a5 | aliguori | int64_t pos, int size);
|
85 | 178e08a5 | aliguori | |
86 | 19cb3738 | bellard | /* removable device specific */
|
87 | 19cb3738 | bellard | int (*bdrv_is_inserted)(BlockDriverState *bs);
|
88 | 19cb3738 | bellard | int (*bdrv_media_changed)(BlockDriverState *bs);
|
89 | 19cb3738 | bellard | int (*bdrv_eject)(BlockDriverState *bs, int eject_flag); |
90 | 19cb3738 | bellard | int (*bdrv_set_locked)(BlockDriverState *bs, int locked); |
91 | 3b46e624 | ths | |
92 | 985a03b0 | ths | /* to control generic scsi devices */
|
93 | 985a03b0 | ths | int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf); |
94 | 221f715d | aliguori | BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, |
95 | 221f715d | aliguori | unsigned long int req, void *buf, |
96 | 221f715d | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
97 | 985a03b0 | ths | |
98 | 6bbff9a0 | aliguori | AIOPool aio_pool; |
99 | 5eb45639 | aliguori | |
100 | 5eb45639 | aliguori | /* new create with backing file format */
|
101 | 5eb45639 | aliguori | int (*bdrv_create2)(const char *filename, int64_t total_sectors, |
102 | 5eb45639 | aliguori | const char *backing_file, const char *backing_format, |
103 | 5eb45639 | aliguori | int flags);
|
104 | 5eb45639 | aliguori | |
105 | e97fc193 | aliguori | /* Returns number of errors in image, -errno for internal errors */
|
106 | e97fc193 | aliguori | int (*bdrv_check)(BlockDriverState* bs);
|
107 | e97fc193 | aliguori | |
108 | ea2384d3 | bellard | struct BlockDriver *next;
|
109 | ea2384d3 | bellard | }; |
110 | ea2384d3 | bellard | |
111 | ea2384d3 | bellard | struct BlockDriverState {
|
112 | d15a771d | bellard | int64_t total_sectors; /* if we are reading a disk image, give its
|
113 | d15a771d | bellard | size in sectors */
|
114 | ea2384d3 | bellard | int read_only; /* if true, the media is read only */ |
115 | ea2384d3 | bellard | int removable; /* if true, the media can be removed */ |
116 | ea2384d3 | bellard | int locked; /* if true, the media cannot temporarily be ejected */ |
117 | ea2384d3 | bellard | int encrypted; /* if true, the media is encrypted */ |
118 | c0f4ce77 | aliguori | int valid_key; /* if true, a valid encryption key has been set */ |
119 | 985a03b0 | ths | int sg; /* if true, the device is a /dev/sg* */ |
120 | ea2384d3 | bellard | /* event callback when inserting/removing */
|
121 | ea2384d3 | bellard | void (*change_cb)(void *opaque); |
122 | ea2384d3 | bellard | void *change_opaque;
|
123 | ea2384d3 | bellard | |
124 | 19cb3738 | bellard | BlockDriver *drv; /* NULL means no media */
|
125 | ea2384d3 | bellard | void *opaque;
|
126 | ea2384d3 | bellard | |
127 | ea2384d3 | bellard | char filename[1024]; |
128 | ea2384d3 | bellard | char backing_file[1024]; /* if non zero, the image is a diff of |
129 | ea2384d3 | bellard | this file image */
|
130 | 5eb45639 | aliguori | char backing_format[16]; /* if non-zero and backing_file exists */ |
131 | ea2384d3 | bellard | int is_temporary;
|
132 | 19cb3738 | bellard | int media_changed;
|
133 | 19cb3738 | bellard | |
134 | ea2384d3 | bellard | BlockDriverState *backing_hd; |
135 | ce1a14dc | pbrook | /* async read/write emulation */
|
136 | 83f64091 | bellard | |
137 | ce1a14dc | pbrook | void *sync_aiocb;
|
138 | 3b46e624 | ths | |
139 | a36e69dd | ths | /* I/O stats (display with "info blockstats"). */
|
140 | a36e69dd | ths | uint64_t rd_bytes; |
141 | a36e69dd | ths | uint64_t wr_bytes; |
142 | a36e69dd | ths | uint64_t rd_ops; |
143 | a36e69dd | ths | uint64_t wr_ops; |
144 | a36e69dd | ths | |
145 | 71d0770c | aliguori | /* Whether the disk can expand beyond total_sectors */
|
146 | 71d0770c | aliguori | int growable;
|
147 | 71d0770c | aliguori | |
148 | ea2384d3 | bellard | /* NOTE: the following infos are only hints for real hardware
|
149 | ea2384d3 | bellard | drivers. They are not used by the block driver */
|
150 | 46d4767d | bellard | int cyls, heads, secs, translation;
|
151 | ea2384d3 | bellard | int type;
|
152 | ea2384d3 | bellard | char device_name[32]; |
153 | ea2384d3 | bellard | BlockDriverState *next; |
154 | b0a7b120 | aliguori | void *private;
|
155 | ea2384d3 | bellard | }; |
156 | ea2384d3 | bellard | |
157 | 83f64091 | bellard | struct BlockDriverAIOCB {
|
158 | 6bbff9a0 | aliguori | AIOPool *pool; |
159 | 83f64091 | bellard | BlockDriverState *bs; |
160 | 83f64091 | bellard | BlockDriverCompletionFunc *cb; |
161 | ce1a14dc | pbrook | void *opaque;
|
162 | ce1a14dc | pbrook | BlockDriverAIOCB *next; |
163 | 83f64091 | bellard | }; |
164 | 83f64091 | bellard | |
165 | 95389c86 | bellard | void get_tmp_filename(char *filename, int size); |
166 | 95389c86 | bellard | |
167 | 6bbff9a0 | aliguori | void aio_pool_init(AIOPool *pool, int aiocb_size, |
168 | 6bbff9a0 | aliguori | void (*cancel)(BlockDriverAIOCB *acb));
|
169 | 6bbff9a0 | aliguori | |
170 | ce1a14dc | pbrook | void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
|
171 | ce1a14dc | pbrook | void *opaque);
|
172 | 6bbff9a0 | aliguori | void *qemu_aio_get_pool(AIOPool *pool, BlockDriverState *bs,
|
173 | 6bbff9a0 | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
174 | ce1a14dc | pbrook | void qemu_aio_release(void *p); |
175 | ce1a14dc | pbrook | |
176 | 7ee930d0 | blueswir1 | extern BlockDriverState *bdrv_first;
|
177 | faf07963 | pbrook | |
178 | ea2384d3 | bellard | #endif /* BLOCK_INT_H */ |