]> git.proxmox.com Git - qemu.git/blob - block/raw.c
Merge branch 's390-for-upstream' of git://repo.or.cz/qemu/agraf
[qemu.git] / block / raw.c
1
2 #include "qemu-common.h"
3 #include "block_int.h"
4 #include "module.h"
5
6 static int raw_open(BlockDriverState *bs, int flags)
7 {
8 bs->sg = bs->file->sg;
9 return 0;
10 }
11
12 static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
13 int nb_sectors, QEMUIOVector *qiov)
14 {
15 return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
16 }
17
18 static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
19 int nb_sectors, QEMUIOVector *qiov)
20 {
21 return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
22 }
23
24 static void raw_close(BlockDriverState *bs)
25 {
26 }
27
28 static 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
35 static int64_t raw_getlength(BlockDriverState *bs)
36 {
37 return bdrv_getlength(bs->file);
38 }
39
40 static int raw_truncate(BlockDriverState *bs, int64_t offset)
41 {
42 return bdrv_truncate(bs->file, offset);
43 }
44
45 static 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
50 static int coroutine_fn raw_co_discard(BlockDriverState *bs,
51 int64_t sector_num, int nb_sectors)
52 {
53 return bdrv_co_discard(bs->file, sector_num, nb_sectors);
54 }
55
56 static int raw_is_inserted(BlockDriverState *bs)
57 {
58 return bdrv_is_inserted(bs->file);
59 }
60
61 static int raw_media_changed(BlockDriverState *bs)
62 {
63 return bdrv_media_changed(bs->file);
64 }
65
66 static void raw_eject(BlockDriverState *bs, bool eject_flag)
67 {
68 bdrv_eject(bs->file, eject_flag);
69 }
70
71 static void raw_lock_medium(BlockDriverState *bs, bool locked)
72 {
73 bdrv_lock_medium(bs->file, locked);
74 }
75
76 static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
77 {
78 return bdrv_ioctl(bs->file, req, buf);
79 }
80
81 static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
82 unsigned long int req, void *buf,
83 BlockDriverCompletionFunc *cb, void *opaque)
84 {
85 return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
86 }
87
88 static int raw_create(const char *filename, QEMUOptionParameter *options)
89 {
90 return bdrv_create_file(filename, options);
91 }
92
93 static QEMUOptionParameter raw_create_options[] = {
94 {
95 .name = BLOCK_OPT_SIZE,
96 .type = OPT_SIZE,
97 .help = "Virtual disk size"
98 },
99 { NULL }
100 };
101
102 static int raw_has_zero_init(BlockDriverState *bs)
103 {
104 return bdrv_has_zero_init(bs->file);
105 }
106
107 static BlockDriver bdrv_raw = {
108 .format_name = "raw",
109
110 /* It's really 0, but we need to make g_malloc() happy */
111 .instance_size = 1,
112
113 .bdrv_open = raw_open,
114 .bdrv_close = raw_close,
115
116 .bdrv_co_readv = raw_co_readv,
117 .bdrv_co_writev = raw_co_writev,
118 .bdrv_co_is_allocated = raw_co_is_allocated,
119 .bdrv_co_discard = raw_co_discard,
120
121 .bdrv_probe = raw_probe,
122 .bdrv_getlength = raw_getlength,
123 .bdrv_truncate = raw_truncate,
124
125 .bdrv_is_inserted = raw_is_inserted,
126 .bdrv_media_changed = raw_media_changed,
127 .bdrv_eject = raw_eject,
128 .bdrv_lock_medium = raw_lock_medium,
129
130 .bdrv_ioctl = raw_ioctl,
131 .bdrv_aio_ioctl = raw_aio_ioctl,
132
133 .bdrv_create = raw_create,
134 .create_options = raw_create_options,
135 .bdrv_has_zero_init = raw_has_zero_init,
136 };
137
138 static void bdrv_raw_init(void)
139 {
140 bdrv_register(&bdrv_raw);
141 }
142
143 block_init(bdrv_raw_init);