root / block_int.h @ 8686c490
History | View | Annotate | Download (5.7 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 | ea2384d3 | bellard | struct BlockDriver {
|
34 | ea2384d3 | bellard | const char *format_name; |
35 | ea2384d3 | bellard | int instance_size;
|
36 | ea2384d3 | bellard | int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); |
37 | 83f64091 | bellard | int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags); |
38 | 5fafdf24 | ths | int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
39 | ea2384d3 | bellard | uint8_t *buf, int nb_sectors);
|
40 | 5fafdf24 | ths | int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
41 | ea2384d3 | bellard | const uint8_t *buf, int nb_sectors); |
42 | e2731add | bellard | void (*bdrv_close)(BlockDriverState *bs);
|
43 | 5fafdf24 | ths | int (*bdrv_create)(const char *filename, int64_t total_sectors, |
44 | ea2384d3 | bellard | const char *backing_file, int flags); |
45 | 7a6cba61 | pbrook | void (*bdrv_flush)(BlockDriverState *bs);
|
46 | ea2384d3 | bellard | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
|
47 | ea2384d3 | bellard | int nb_sectors, int *pnum); |
48 | ea2384d3 | bellard | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); |
49 | 95389c86 | bellard | int (*bdrv_make_empty)(BlockDriverState *bs);
|
50 | 83f64091 | bellard | /* aio */
|
51 | ce1a14dc | pbrook | BlockDriverAIOCB *(*bdrv_aio_read)(BlockDriverState *bs, |
52 | ce1a14dc | pbrook | int64_t sector_num, uint8_t *buf, int nb_sectors,
|
53 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
54 | ce1a14dc | pbrook | BlockDriverAIOCB *(*bdrv_aio_write)(BlockDriverState *bs, |
55 | ce1a14dc | pbrook | int64_t sector_num, const uint8_t *buf, int nb_sectors, |
56 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
57 | 83f64091 | bellard | void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);
|
58 | ce1a14dc | pbrook | int aiocb_size;
|
59 | 83f64091 | bellard | |
60 | 83f64091 | bellard | const char *protocol_name; |
61 | 5fafdf24 | ths | int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
|
62 | 83f64091 | bellard | uint8_t *buf, int count);
|
63 | 5fafdf24 | ths | int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
|
64 | 83f64091 | bellard | const uint8_t *buf, int count); |
65 | 83f64091 | bellard | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
|
66 | 83f64091 | bellard | int64_t (*bdrv_getlength)(BlockDriverState *bs); |
67 | 5fafdf24 | ths | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
68 | faea38e7 | bellard | const uint8_t *buf, int nb_sectors); |
69 | faea38e7 | bellard | |
70 | 5fafdf24 | ths | int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
71 | faea38e7 | bellard | QEMUSnapshotInfo *sn_info); |
72 | 5fafdf24 | ths | int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
73 | faea38e7 | bellard | const char *snapshot_id); |
74 | faea38e7 | bellard | int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id); |
75 | 5fafdf24 | ths | int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
76 | faea38e7 | bellard | QEMUSnapshotInfo **psn_info); |
77 | faea38e7 | bellard | int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
78 | 83f64091 | bellard | |
79 | 19cb3738 | bellard | /* removable device specific */
|
80 | 19cb3738 | bellard | int (*bdrv_is_inserted)(BlockDriverState *bs);
|
81 | 19cb3738 | bellard | int (*bdrv_media_changed)(BlockDriverState *bs);
|
82 | 19cb3738 | bellard | int (*bdrv_eject)(BlockDriverState *bs, int eject_flag); |
83 | 19cb3738 | bellard | int (*bdrv_set_locked)(BlockDriverState *bs, int locked); |
84 | 3b46e624 | ths | |
85 | 985a03b0 | ths | /* to control generic scsi devices */
|
86 | 985a03b0 | ths | int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf); |
87 | 985a03b0 | ths | |
88 | ce1a14dc | pbrook | BlockDriverAIOCB *free_aiocb; |
89 | ea2384d3 | bellard | struct BlockDriver *next;
|
90 | ea2384d3 | bellard | }; |
91 | ea2384d3 | bellard | |
92 | ea2384d3 | bellard | struct BlockDriverState {
|
93 | d15a771d | bellard | int64_t total_sectors; /* if we are reading a disk image, give its
|
94 | d15a771d | bellard | size in sectors */
|
95 | ea2384d3 | bellard | int read_only; /* if true, the media is read only */ |
96 | ea2384d3 | bellard | int removable; /* if true, the media can be removed */ |
97 | ea2384d3 | bellard | int locked; /* if true, the media cannot temporarily be ejected */ |
98 | ea2384d3 | bellard | int encrypted; /* if true, the media is encrypted */ |
99 | 985a03b0 | ths | int sg; /* if true, the device is a /dev/sg* */ |
100 | ea2384d3 | bellard | /* event callback when inserting/removing */
|
101 | ea2384d3 | bellard | void (*change_cb)(void *opaque); |
102 | ea2384d3 | bellard | void *change_opaque;
|
103 | ea2384d3 | bellard | |
104 | 19cb3738 | bellard | BlockDriver *drv; /* NULL means no media */
|
105 | ea2384d3 | bellard | void *opaque;
|
106 | ea2384d3 | bellard | |
107 | ea2384d3 | bellard | int boot_sector_enabled;
|
108 | ea2384d3 | bellard | uint8_t boot_sector_data[512];
|
109 | ea2384d3 | bellard | |
110 | ea2384d3 | bellard | char filename[1024]; |
111 | ea2384d3 | bellard | char backing_file[1024]; /* if non zero, the image is a diff of |
112 | ea2384d3 | bellard | this file image */
|
113 | ea2384d3 | bellard | int is_temporary;
|
114 | 19cb3738 | bellard | int media_changed;
|
115 | 19cb3738 | bellard | |
116 | ea2384d3 | bellard | BlockDriverState *backing_hd; |
117 | ce1a14dc | pbrook | /* async read/write emulation */
|
118 | 83f64091 | bellard | |
119 | ce1a14dc | pbrook | void *sync_aiocb;
|
120 | 3b46e624 | ths | |
121 | a36e69dd | ths | /* I/O stats (display with "info blockstats"). */
|
122 | a36e69dd | ths | uint64_t rd_bytes; |
123 | a36e69dd | ths | uint64_t wr_bytes; |
124 | a36e69dd | ths | uint64_t rd_ops; |
125 | a36e69dd | ths | uint64_t wr_ops; |
126 | a36e69dd | ths | |
127 | ea2384d3 | bellard | /* NOTE: the following infos are only hints for real hardware
|
128 | ea2384d3 | bellard | drivers. They are not used by the block driver */
|
129 | 46d4767d | bellard | int cyls, heads, secs, translation;
|
130 | ea2384d3 | bellard | int type;
|
131 | ea2384d3 | bellard | char device_name[32]; |
132 | ea2384d3 | bellard | BlockDriverState *next; |
133 | ea2384d3 | bellard | }; |
134 | ea2384d3 | bellard | |
135 | 83f64091 | bellard | struct BlockDriverAIOCB {
|
136 | 83f64091 | bellard | BlockDriverState *bs; |
137 | 83f64091 | bellard | BlockDriverCompletionFunc *cb; |
138 | ce1a14dc | pbrook | void *opaque;
|
139 | ce1a14dc | pbrook | BlockDriverAIOCB *next; |
140 | 83f64091 | bellard | }; |
141 | 83f64091 | bellard | |
142 | 95389c86 | bellard | void get_tmp_filename(char *filename, int size); |
143 | 95389c86 | bellard | |
144 | ce1a14dc | pbrook | void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
|
145 | ce1a14dc | pbrook | void *opaque);
|
146 | ce1a14dc | pbrook | void qemu_aio_release(void *p); |
147 | ce1a14dc | pbrook | |
148 | faf07963 | pbrook | BlockDriverState *bdrv_first; |
149 | faf07963 | pbrook | |
150 | ea2384d3 | bellard | #endif /* BLOCK_INT_H */ |