root / block / raw.c @ 7267c094
History | View | Annotate | Download (3.8 kB)
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 raw_read(BlockDriverState *bs, int64_t sector_num, |
13 |
uint8_t *buf, int nb_sectors)
|
14 |
{ |
15 |
return bdrv_read(bs->file, sector_num, buf, nb_sectors);
|
16 |
} |
17 |
|
18 |
static int raw_write(BlockDriverState *bs, int64_t sector_num, |
19 |
const uint8_t *buf, int nb_sectors) |
20 |
{ |
21 |
return bdrv_write(bs->file, sector_num, buf, nb_sectors);
|
22 |
} |
23 |
|
24 |
static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs,
|
25 |
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
26 |
BlockDriverCompletionFunc *cb, void *opaque)
|
27 |
{ |
28 |
return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
29 |
} |
30 |
|
31 |
static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs,
|
32 |
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
33 |
BlockDriverCompletionFunc *cb, void *opaque)
|
34 |
{ |
35 |
return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
36 |
} |
37 |
|
38 |
static void raw_close(BlockDriverState *bs) |
39 |
{ |
40 |
} |
41 |
|
42 |
static int raw_flush(BlockDriverState *bs) |
43 |
{ |
44 |
return bdrv_flush(bs->file);
|
45 |
} |
46 |
|
47 |
static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs,
|
48 |
BlockDriverCompletionFunc *cb, void *opaque)
|
49 |
{ |
50 |
return bdrv_aio_flush(bs->file, cb, opaque);
|
51 |
} |
52 |
|
53 |
static int64_t raw_getlength(BlockDriverState *bs)
|
54 |
{ |
55 |
return bdrv_getlength(bs->file);
|
56 |
} |
57 |
|
58 |
static int raw_truncate(BlockDriverState *bs, int64_t offset) |
59 |
{ |
60 |
return bdrv_truncate(bs->file, offset);
|
61 |
} |
62 |
|
63 |
static 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 |
|
68 |
static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) |
69 |
{ |
70 |
return bdrv_discard(bs->file, sector_num, nb_sectors);
|
71 |
} |
72 |
|
73 |
static int raw_is_inserted(BlockDriverState *bs) |
74 |
{ |
75 |
return bdrv_is_inserted(bs->file);
|
76 |
} |
77 |
|
78 |
static void raw_eject(BlockDriverState *bs, int eject_flag) |
79 |
{ |
80 |
bdrv_eject(bs->file, eject_flag); |
81 |
} |
82 |
|
83 |
static void raw_set_locked(BlockDriverState *bs, int locked) |
84 |
{ |
85 |
bdrv_set_locked(bs->file, locked); |
86 |
} |
87 |
|
88 |
static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
89 |
{ |
90 |
return bdrv_ioctl(bs->file, req, buf);
|
91 |
} |
92 |
|
93 |
static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
|
94 |
unsigned long int req, void *buf, |
95 |
BlockDriverCompletionFunc *cb, void *opaque)
|
96 |
{ |
97 |
return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
|
98 |
} |
99 |
|
100 |
static int raw_create(const char *filename, QEMUOptionParameter *options) |
101 |
{ |
102 |
return bdrv_create_file(filename, options);
|
103 |
} |
104 |
|
105 |
static QEMUOptionParameter raw_create_options[] = {
|
106 |
{ |
107 |
.name = BLOCK_OPT_SIZE, |
108 |
.type = OPT_SIZE, |
109 |
.help = "Virtual disk size"
|
110 |
}, |
111 |
{ NULL }
|
112 |
}; |
113 |
|
114 |
static int raw_has_zero_init(BlockDriverState *bs) |
115 |
{ |
116 |
return bdrv_has_zero_init(bs->file);
|
117 |
} |
118 |
|
119 |
static BlockDriver bdrv_raw = {
|
120 |
.format_name = "raw",
|
121 |
|
122 |
/* It's really 0, but we need to make g_malloc() happy */
|
123 |
.instance_size = 1,
|
124 |
|
125 |
.bdrv_open = raw_open, |
126 |
.bdrv_close = raw_close, |
127 |
.bdrv_read = raw_read, |
128 |
.bdrv_write = raw_write, |
129 |
.bdrv_flush = raw_flush, |
130 |
.bdrv_probe = raw_probe, |
131 |
.bdrv_getlength = raw_getlength, |
132 |
.bdrv_truncate = raw_truncate, |
133 |
|
134 |
.bdrv_aio_readv = raw_aio_readv, |
135 |
.bdrv_aio_writev = raw_aio_writev, |
136 |
.bdrv_aio_flush = raw_aio_flush, |
137 |
.bdrv_discard = raw_discard, |
138 |
|
139 |
.bdrv_is_inserted = raw_is_inserted, |
140 |
.bdrv_eject = raw_eject, |
141 |
.bdrv_set_locked = raw_set_locked, |
142 |
.bdrv_ioctl = raw_ioctl, |
143 |
.bdrv_aio_ioctl = raw_aio_ioctl, |
144 |
|
145 |
.bdrv_create = raw_create, |
146 |
.create_options = raw_create_options, |
147 |
.bdrv_has_zero_init = raw_has_zero_init, |
148 |
}; |
149 |
|
150 |
static void bdrv_raw_init(void) |
151 |
{ |
152 |
bdrv_register(&bdrv_raw); |
153 |
} |
154 |
|
155 |
block_init(bdrv_raw_init); |