blob: 4406b8c06b8dbe2bdf6aefaa0f958d5dc4cf85ce [file] [log] [blame]
Christoph Hellwig84a12e62010-04-07 22:30:24 +02001
2#include "qemu-common.h"
3#include "block_int.h"
4#include "module.h"
5
Kevin Wolf66f82ce2010-04-14 14:17:38 +02006static int raw_open(BlockDriverState *bs, int flags)
Christoph Hellwig84a12e62010-04-07 22:30:24 +02007{
Kevin Wolf66f82ce2010-04-14 14:17:38 +02008 bs->sg = bs->file->sg;
9 return 0;
Christoph Hellwig84a12e62010-04-07 22:30:24 +020010}
11
12static int raw_read(BlockDriverState *bs, int64_t sector_num,
13 uint8_t *buf, int nb_sectors)
14{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020015 return bdrv_read(bs->file, sector_num, buf, nb_sectors);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020016}
17
18static int raw_write(BlockDriverState *bs, int64_t sector_num,
19 const uint8_t *buf, int nb_sectors)
20{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020021 return bdrv_write(bs->file, sector_num, buf, nb_sectors);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020022}
23
24static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
25 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
26 BlockDriverCompletionFunc *cb, void *opaque)
27{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020028 return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020029}
30
31static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
32 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
33 BlockDriverCompletionFunc *cb, void *opaque)
34{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020035 return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020036}
37
38static void raw_close(BlockDriverState *bs)
39{
Christoph Hellwig84a12e62010-04-07 22:30:24 +020040}
41
42static void raw_flush(BlockDriverState *bs)
43{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020044 bdrv_flush(bs->file);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020045}
46
47static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
48 BlockDriverCompletionFunc *cb, void *opaque)
49{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020050 return bdrv_aio_flush(bs->file, cb, opaque);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020051}
52
53static int64_t raw_getlength(BlockDriverState *bs)
54{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020055 return bdrv_getlength(bs->file);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020056}
57
58static int raw_truncate(BlockDriverState *bs, int64_t offset)
59{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020060 return bdrv_truncate(bs->file, offset);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020061}
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{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020070 return bdrv_is_inserted(bs->file);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020071}
72
73static int raw_eject(BlockDriverState *bs, int eject_flag)
74{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020075 return bdrv_eject(bs->file, eject_flag);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020076}
77
78static int raw_set_locked(BlockDriverState *bs, int locked)
79{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020080 bdrv_set_locked(bs->file, locked);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020081 return 0;
82}
83
84static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
85{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020086 return bdrv_ioctl(bs->file, req, buf);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020087}
88
89static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
90 unsigned long int req, void *buf,
91 BlockDriverCompletionFunc *cb, void *opaque)
92{
Kevin Wolf66f82ce2010-04-14 14:17:38 +020093 return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
Christoph Hellwig84a12e62010-04-07 22:30:24 +020094}
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
Kevin Wolf66f82ce2010-04-14 14:17:38 +0200113 /* It's really 0, but we need to make qemu_malloc() happy */
114 .instance_size = 1,
Christoph Hellwig84a12e62010-04-07 22:30:24 +0200115
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);