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