]> git.proxmox.com Git - qemu.git/blame - block/raw.c
raw-posix: remove bdrv_read()/bdrv_write()
[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
12static int raw_read(BlockDriverState *bs, int64_t sector_num,
13 uint8_t *buf, int nb_sectors)
14{
66f82cee 15 return bdrv_read(bs->file, sector_num, buf, nb_sectors);
84a12e66
CH
16}
17
18static int raw_write(BlockDriverState *bs, int64_t sector_num,
19 const uint8_t *buf, int nb_sectors)
20{
66f82cee 21 return bdrv_write(bs->file, sector_num, buf, nb_sectors);
84a12e66
CH
22}
23
24static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
25 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
26 BlockDriverCompletionFunc *cb, void *opaque)
27{
66f82cee 28 return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
84a12e66
CH
29}
30
31static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
32 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
33 BlockDriverCompletionFunc *cb, void *opaque)
34{
66f82cee 35 return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
84a12e66
CH
36}
37
38static void raw_close(BlockDriverState *bs)
39{
84a12e66
CH
40}
41
205ef796 42static int raw_flush(BlockDriverState *bs)
84a12e66 43{
205ef796 44 return bdrv_flush(bs->file);
84a12e66
CH
45}
46
47static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
48 BlockDriverCompletionFunc *cb, void *opaque)
49{
66f82cee 50 return bdrv_aio_flush(bs->file, cb, opaque);
84a12e66
CH
51}
52
53static int64_t raw_getlength(BlockDriverState *bs)
54{
66f82cee 55 return bdrv_getlength(bs->file);
84a12e66
CH
56}
57
58static int raw_truncate(BlockDriverState *bs, int64_t offset)
59{
66f82cee 60 return bdrv_truncate(bs->file, offset);
84a12e66
CH
61}
62
63static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
64{
65 return 1; /* everything can be opened as raw image */
66}
67
bb8bf76f
CH
68static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
69{
70 return bdrv_discard(bs->file, sector_num, nb_sectors);
71}
72
84a12e66
CH
73static int raw_is_inserted(BlockDriverState *bs)
74{
66f82cee 75 return bdrv_is_inserted(bs->file);
84a12e66
CH
76}
77
be32f75f
MA
78static int raw_media_changed(BlockDriverState *bs)
79{
80 return bdrv_media_changed(bs->file);
81}
82
822e1cd1 83static void raw_eject(BlockDriverState *bs, int eject_flag)
84a12e66 84{
822e1cd1 85 bdrv_eject(bs->file, eject_flag);
84a12e66
CH
86}
87
025e849a 88static void raw_lock_medium(BlockDriverState *bs, bool locked)
84a12e66 89{
025e849a 90 bdrv_lock_medium(bs->file, locked);
84a12e66
CH
91}
92
93static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
94{
66f82cee 95 return bdrv_ioctl(bs->file, req, buf);
84a12e66
CH
96}
97
98static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
99 unsigned long int req, void *buf,
100 BlockDriverCompletionFunc *cb, void *opaque)
101{
66f82cee 102 return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
84a12e66
CH
103}
104
105static int raw_create(const char *filename, QEMUOptionParameter *options)
106{
107 return bdrv_create_file(filename, options);
108}
109
110static QEMUOptionParameter raw_create_options[] = {
111 {
112 .name = BLOCK_OPT_SIZE,
113 .type = OPT_SIZE,
114 .help = "Virtual disk size"
115 },
116 { NULL }
117};
118
336c1c12
KW
119static int raw_has_zero_init(BlockDriverState *bs)
120{
121 return bdrv_has_zero_init(bs->file);
122}
123
84a12e66
CH
124static BlockDriver bdrv_raw = {
125 .format_name = "raw",
126
7267c094 127 /* It's really 0, but we need to make g_malloc() happy */
66f82cee 128 .instance_size = 1,
84a12e66
CH
129
130 .bdrv_open = raw_open,
131 .bdrv_close = raw_close,
132 .bdrv_read = raw_read,
133 .bdrv_write = raw_write,
134 .bdrv_flush = raw_flush,
135 .bdrv_probe = raw_probe,
136 .bdrv_getlength = raw_getlength,
137 .bdrv_truncate = raw_truncate,
138
139 .bdrv_aio_readv = raw_aio_readv,
140 .bdrv_aio_writev = raw_aio_writev,
141 .bdrv_aio_flush = raw_aio_flush,
bb8bf76f 142 .bdrv_discard = raw_discard,
84a12e66
CH
143
144 .bdrv_is_inserted = raw_is_inserted,
be32f75f 145 .bdrv_media_changed = raw_media_changed,
84a12e66 146 .bdrv_eject = raw_eject,
025e849a 147 .bdrv_lock_medium = raw_lock_medium,
be32f75f 148
84a12e66
CH
149 .bdrv_ioctl = raw_ioctl,
150 .bdrv_aio_ioctl = raw_aio_ioctl,
151
152 .bdrv_create = raw_create,
153 .create_options = raw_create_options,
336c1c12 154 .bdrv_has_zero_init = raw_has_zero_init,
84a12e66
CH
155};
156
157static void bdrv_raw_init(void)
158{
159 bdrv_register(&bdrv_raw);
160}
161
162block_init(bdrv_raw_init);