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