root / block / raw.c @ 5b50e790
History | View | Annotate | Download (4.4 kB)
1 |
|
---|---|
2 |
#include "qemu-common.h" |
3 |
#include "block/block_int.h" |
4 |
#include "qemu/module.h" |
5 |
|
6 |
static int raw_open(BlockDriverState *bs, QDict *options, int flags) |
7 |
{ |
8 |
bs->sg = bs->file->sg; |
9 |
return 0; |
10 |
} |
11 |
|
12 |
/* We have nothing to do for raw reopen, stubs just return
|
13 |
* success */
|
14 |
static int raw_reopen_prepare(BDRVReopenState *state, |
15 |
BlockReopenQueue *queue, Error **errp) |
16 |
{ |
17 |
return 0; |
18 |
} |
19 |
|
20 |
static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num, |
21 |
int nb_sectors, QEMUIOVector *qiov)
|
22 |
{ |
23 |
BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); |
24 |
return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
|
25 |
} |
26 |
|
27 |
static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num, |
28 |
int nb_sectors, QEMUIOVector *qiov)
|
29 |
{ |
30 |
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); |
31 |
return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
|
32 |
} |
33 |
|
34 |
static void raw_close(BlockDriverState *bs) |
35 |
{ |
36 |
} |
37 |
|
38 |
static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs, |
39 |
int64_t sector_num, |
40 |
int nb_sectors, int *pnum) |
41 |
{ |
42 |
return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum);
|
43 |
} |
44 |
|
45 |
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs, |
46 |
int64_t sector_num, |
47 |
int nb_sectors)
|
48 |
{ |
49 |
return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors);
|
50 |
} |
51 |
|
52 |
static int64_t raw_getlength(BlockDriverState *bs)
|
53 |
{ |
54 |
return bdrv_getlength(bs->file);
|
55 |
} |
56 |
|
57 |
static int raw_truncate(BlockDriverState *bs, int64_t offset) |
58 |
{ |
59 |
return bdrv_truncate(bs->file, offset);
|
60 |
} |
61 |
|
62 |
static int raw_probe(const uint8_t *buf, int buf_size, const char *filename) |
63 |
{ |
64 |
return 1; /* everything can be opened as raw image */ |
65 |
} |
66 |
|
67 |
static int coroutine_fn raw_co_discard(BlockDriverState *bs, |
68 |
int64_t sector_num, int nb_sectors)
|
69 |
{ |
70 |
return bdrv_co_discard(bs->file, sector_num, nb_sectors);
|
71 |
} |
72 |
|
73 |
static int raw_is_inserted(BlockDriverState *bs) |
74 |
{ |
75 |
return bdrv_is_inserted(bs->file);
|
76 |
} |
77 |
|
78 |
static int raw_media_changed(BlockDriverState *bs) |
79 |
{ |
80 |
return bdrv_media_changed(bs->file);
|
81 |
} |
82 |
|
83 |
static void raw_eject(BlockDriverState *bs, bool eject_flag) |
84 |
{ |
85 |
bdrv_eject(bs->file, eject_flag); |
86 |
} |
87 |
|
88 |
static void raw_lock_medium(BlockDriverState *bs, bool locked) |
89 |
{ |
90 |
bdrv_lock_medium(bs->file, locked); |
91 |
} |
92 |
|
93 |
static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
94 |
{ |
95 |
return bdrv_ioctl(bs->file, req, buf);
|
96 |
} |
97 |
|
98 |
static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
|
99 |
unsigned long int req, void *buf, |
100 |
BlockDriverCompletionFunc *cb, void *opaque)
|
101 |
{ |
102 |
return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
|
103 |
} |
104 |
|
105 |
static int raw_create(const char *filename, QEMUOptionParameter *options) |
106 |
{ |
107 |
return bdrv_create_file(filename, options);
|
108 |
} |
109 |
|
110 |
static QEMUOptionParameter raw_create_options[] = {
|
111 |
{ |
112 |
.name = BLOCK_OPT_SIZE, |
113 |
.type = OPT_SIZE, |
114 |
.help = "Virtual disk size"
|
115 |
}, |
116 |
{ NULL }
|
117 |
}; |
118 |
|
119 |
static int raw_has_zero_init(BlockDriverState *bs) |
120 |
{ |
121 |
return bdrv_has_zero_init(bs->file);
|
122 |
} |
123 |
|
124 |
static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) |
125 |
{ |
126 |
return bdrv_get_info(bs->file, bdi);
|
127 |
} |
128 |
|
129 |
static BlockDriver bdrv_raw = {
|
130 |
.format_name = "raw",
|
131 |
|
132 |
/* It's really 0, but we need to make g_malloc() happy */
|
133 |
.instance_size = 1,
|
134 |
|
135 |
.bdrv_open = raw_open, |
136 |
.bdrv_close = raw_close, |
137 |
|
138 |
.bdrv_reopen_prepare = raw_reopen_prepare, |
139 |
|
140 |
.bdrv_co_readv = raw_co_readv, |
141 |
.bdrv_co_writev = raw_co_writev, |
142 |
.bdrv_co_is_allocated = raw_co_is_allocated, |
143 |
.bdrv_co_write_zeroes = raw_co_write_zeroes, |
144 |
.bdrv_co_discard = raw_co_discard, |
145 |
|
146 |
.bdrv_probe = raw_probe, |
147 |
.bdrv_getlength = raw_getlength, |
148 |
.bdrv_get_info = raw_get_info, |
149 |
.bdrv_truncate = raw_truncate, |
150 |
|
151 |
.bdrv_is_inserted = raw_is_inserted, |
152 |
.bdrv_media_changed = raw_media_changed, |
153 |
.bdrv_eject = raw_eject, |
154 |
.bdrv_lock_medium = raw_lock_medium, |
155 |
|
156 |
.bdrv_ioctl = raw_ioctl, |
157 |
.bdrv_aio_ioctl = raw_aio_ioctl, |
158 |
|
159 |
.bdrv_create = raw_create, |
160 |
.create_options = raw_create_options, |
161 |
.bdrv_has_zero_init = raw_has_zero_init, |
162 |
}; |
163 |
|
164 |
static void bdrv_raw_init(void) |
165 |
{ |
166 |
bdrv_register(&bdrv_raw); |
167 |
} |
168 |
|
169 |
block_init(bdrv_raw_init); |