]> git.proxmox.com Git - mirror_qemu.git/blame - block/raw.c
block: Open the underlying image file in generic code
[mirror_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
42static void raw_flush(BlockDriverState *bs)
43{
66f82cee 44 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
68static int raw_is_inserted(BlockDriverState *bs)
69{
66f82cee 70 return bdrv_is_inserted(bs->file);
84a12e66
CH
71}
72
73static int raw_eject(BlockDriverState *bs, int eject_flag)
74{
66f82cee 75 return bdrv_eject(bs->file, eject_flag);
84a12e66
CH
76}
77
78static int raw_set_locked(BlockDriverState *bs, int locked)
79{
66f82cee 80 bdrv_set_locked(bs->file, locked);
84a12e66
CH
81 return 0;
82}
83
84static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
85{
66f82cee 86 return bdrv_ioctl(bs->file, req, buf);
84a12e66
CH
87}
88
89static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
90 unsigned long int req, void *buf,
91 BlockDriverCompletionFunc *cb, void *opaque)
92{
66f82cee 93 return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
84a12e66
CH
94}
95
96static int raw_create(const char *filename, QEMUOptionParameter *options)
97{
98 return bdrv_create_file(filename, options);
99}
100
101static QEMUOptionParameter raw_create_options[] = {
102 {
103 .name = BLOCK_OPT_SIZE,
104 .type = OPT_SIZE,
105 .help = "Virtual disk size"
106 },
107 { NULL }
108};
109
110static BlockDriver bdrv_raw = {
111 .format_name = "raw",
112
66f82cee
KW
113 /* It's really 0, but we need to make qemu_malloc() happy */
114 .instance_size = 1,
84a12e66
CH
115
116 .bdrv_open = raw_open,
117 .bdrv_close = raw_close,
118 .bdrv_read = raw_read,
119 .bdrv_write = raw_write,
120 .bdrv_flush = raw_flush,
121 .bdrv_probe = raw_probe,
122 .bdrv_getlength = raw_getlength,
123 .bdrv_truncate = raw_truncate,
124
125 .bdrv_aio_readv = raw_aio_readv,
126 .bdrv_aio_writev = raw_aio_writev,
127 .bdrv_aio_flush = raw_aio_flush,
128
129 .bdrv_is_inserted = raw_is_inserted,
130 .bdrv_eject = raw_eject,
131 .bdrv_set_locked = raw_set_locked,
132 .bdrv_ioctl = raw_ioctl,
133 .bdrv_aio_ioctl = raw_aio_ioctl,
134
135 .bdrv_create = raw_create,
136 .create_options = raw_create_options,
137};
138
139static void bdrv_raw_init(void)
140{
141 bdrv_register(&bdrv_raw);
142}
143
144block_init(bdrv_raw_init);