]> Git Repo - qemu.git/blame - block/raw.c
block: use coroutine interface for raw format
[qemu.git] / block / raw.c
CommitLineData
84a12e66
CH
1
2#include "qemu-common.h"
3#include "block_int.h"
4#include "module.h"
5
66f82cee 6static int raw_open(BlockDriverState *bs, int flags)
84a12e66 7{
66f82cee
KW
8 bs->sg = bs->file->sg;
9 return 0;
84a12e66
CH
10}
11
d8b7e0ad
SH
12static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
13 int nb_sectors, QEMUIOVector *qiov)
84a12e66 14{
d8b7e0ad 15 return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
84a12e66
CH
16}
17
d8b7e0ad
SH
18static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
19 int nb_sectors, QEMUIOVector *qiov)
84a12e66 20{
d8b7e0ad 21 return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
84a12e66
CH
22}
23
24static void raw_close(BlockDriverState *bs)
25{
84a12e66
CH
26}
27
205ef796 28static int raw_flush(BlockDriverState *bs)
84a12e66 29{
205ef796 30 return bdrv_flush(bs->file);
84a12e66
CH
31}
32
33static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
34 BlockDriverCompletionFunc *cb, void *opaque)
35{
66f82cee 36 return bdrv_aio_flush(bs->file, cb, opaque);
84a12e66
CH
37}
38
39static int64_t raw_getlength(BlockDriverState *bs)
40{
66f82cee 41 return bdrv_getlength(bs->file);
84a12e66
CH
42}
43
44static int raw_truncate(BlockDriverState *bs, int64_t offset)
45{
66f82cee 46 return bdrv_truncate(bs->file, offset);
84a12e66
CH
47}
48
49static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
50{
51 return 1; /* everything can be opened as raw image */
52}
53
bb8bf76f
CH
54static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
55{
56 return bdrv_discard(bs->file, sector_num, nb_sectors);
57}
58
84a12e66
CH
59static int raw_is_inserted(BlockDriverState *bs)
60{
66f82cee 61 return bdrv_is_inserted(bs->file);
84a12e66
CH
62}
63
be32f75f
MA
64static int raw_media_changed(BlockDriverState *bs)
65{
66 return bdrv_media_changed(bs->file);
67}
68
822e1cd1 69static void raw_eject(BlockDriverState *bs, int eject_flag)
84a12e66 70{
822e1cd1 71 bdrv_eject(bs->file, eject_flag);
84a12e66
CH
72}
73
025e849a 74static void raw_lock_medium(BlockDriverState *bs, bool locked)
84a12e66 75{
025e849a 76 bdrv_lock_medium(bs->file, locked);
84a12e66
CH
77}
78
79static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
80{
66f82cee 81 return bdrv_ioctl(bs->file, req, buf);
84a12e66
CH
82}
83
84static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
85 unsigned long int req, void *buf,
86 BlockDriverCompletionFunc *cb, void *opaque)
87{
66f82cee 88 return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
84a12e66
CH
89}
90
91static int raw_create(const char *filename, QEMUOptionParameter *options)
92{
93 return bdrv_create_file(filename, options);
94}
95
96static QEMUOptionParameter raw_create_options[] = {
97 {
98 .name = BLOCK_OPT_SIZE,
99 .type = OPT_SIZE,
100 .help = "Virtual disk size"
101 },
102 { NULL }
103};
104
336c1c12
KW
105static int raw_has_zero_init(BlockDriverState *bs)
106{
107 return bdrv_has_zero_init(bs->file);
108}
109
84a12e66
CH
110static BlockDriver bdrv_raw = {
111 .format_name = "raw",
112
7267c094 113 /* It's really 0, but we need to make g_malloc() happy */
66f82cee 114 .instance_size = 1,
84a12e66
CH
115
116 .bdrv_open = raw_open,
117 .bdrv_close = raw_close,
d8b7e0ad
SH
118 .bdrv_co_readv = raw_co_readv,
119 .bdrv_co_writev = raw_co_writev,
84a12e66
CH
120 .bdrv_flush = raw_flush,
121 .bdrv_probe = raw_probe,
122 .bdrv_getlength = raw_getlength,
123 .bdrv_truncate = raw_truncate,
124
84a12e66 125 .bdrv_aio_flush = raw_aio_flush,
bb8bf76f 126 .bdrv_discard = raw_discard,
84a12e66
CH
127
128 .bdrv_is_inserted = raw_is_inserted,
be32f75f 129 .bdrv_media_changed = raw_media_changed,
84a12e66 130 .bdrv_eject = raw_eject,
025e849a 131 .bdrv_lock_medium = raw_lock_medium,
be32f75f 132
84a12e66
CH
133 .bdrv_ioctl = raw_ioctl,
134 .bdrv_aio_ioctl = raw_aio_ioctl,
135
136 .bdrv_create = raw_create,
137 .create_options = raw_create_options,
336c1c12 138 .bdrv_has_zero_init = raw_has_zero_init,
84a12e66
CH
139};
140
141static void bdrv_raw_init(void)
142{
143 bdrv_register(&bdrv_raw);
144}
145
146block_init(bdrv_raw_init);
This page took 0.172909 seconds and 4 git commands to generate.