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