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