2 #include "qemu-common.h"
6 typedef struct RAWState
{
10 static int raw_open(BlockDriverState
*bs
, const char *filename
, int flags
)
12 RAWState
*s
= bs
->opaque
;
15 ret
= bdrv_file_open(&s
->hd
, filename
, flags
);
23 static int raw_read(BlockDriverState
*bs
, int64_t sector_num
,
24 uint8_t *buf
, int nb_sectors
)
26 RAWState
*s
= bs
->opaque
;
27 return bdrv_read(s
->hd
, sector_num
, buf
, nb_sectors
);
30 static int raw_write(BlockDriverState
*bs
, int64_t sector_num
,
31 const uint8_t *buf
, int nb_sectors
)
33 RAWState
*s
= bs
->opaque
;
34 return bdrv_write(s
->hd
, sector_num
, buf
, nb_sectors
);
37 static BlockDriverAIOCB
*raw_aio_readv(BlockDriverState
*bs
,
38 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
39 BlockDriverCompletionFunc
*cb
, void *opaque
)
41 RAWState
*s
= bs
->opaque
;
43 return bdrv_aio_readv(s
->hd
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
46 static BlockDriverAIOCB
*raw_aio_writev(BlockDriverState
*bs
,
47 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
48 BlockDriverCompletionFunc
*cb
, void *opaque
)
50 RAWState
*s
= bs
->opaque
;
52 return bdrv_aio_writev(s
->hd
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
55 static void raw_close(BlockDriverState
*bs
)
57 RAWState
*s
= bs
->opaque
;
61 static void raw_flush(BlockDriverState
*bs
)
63 RAWState
*s
= bs
->opaque
;
67 static BlockDriverAIOCB
*raw_aio_flush(BlockDriverState
*bs
,
68 BlockDriverCompletionFunc
*cb
, void *opaque
)
70 RAWState
*s
= bs
->opaque
;
71 return bdrv_aio_flush(s
->hd
, cb
, opaque
);
74 static int64_t raw_getlength(BlockDriverState
*bs
)
76 RAWState
*s
= bs
->opaque
;
77 return bdrv_getlength(s
->hd
);
80 static int raw_truncate(BlockDriverState
*bs
, int64_t offset
)
82 RAWState
*s
= bs
->opaque
;
83 return bdrv_truncate(s
->hd
, offset
);
86 static int raw_probe(const uint8_t *buf
, int buf_size
, const char *filename
)
88 return 1; /* everything can be opened as raw image */
91 static int raw_is_inserted(BlockDriverState
*bs
)
93 RAWState
*s
= bs
->opaque
;
94 return bdrv_is_inserted(s
->hd
);
97 static int raw_eject(BlockDriverState
*bs
, int eject_flag
)
99 RAWState
*s
= bs
->opaque
;
100 return bdrv_eject(s
->hd
, eject_flag
);
103 static int raw_set_locked(BlockDriverState
*bs
, int locked
)
105 RAWState
*s
= bs
->opaque
;
106 bdrv_set_locked(s
->hd
, locked
);
110 static int raw_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
112 RAWState
*s
= bs
->opaque
;
113 return bdrv_ioctl(s
->hd
, req
, buf
);
116 static BlockDriverAIOCB
*raw_aio_ioctl(BlockDriverState
*bs
,
117 unsigned long int req
, void *buf
,
118 BlockDriverCompletionFunc
*cb
, void *opaque
)
120 RAWState
*s
= bs
->opaque
;
121 return bdrv_aio_ioctl(s
->hd
, req
, buf
, cb
, opaque
);
124 static int raw_create(const char *filename
, QEMUOptionParameter
*options
)
126 return bdrv_create_file(filename
, options
);
129 static QEMUOptionParameter raw_create_options
[] = {
131 .name
= BLOCK_OPT_SIZE
,
133 .help
= "Virtual disk size"
138 static BlockDriver bdrv_raw
= {
139 .format_name
= "raw",
141 .instance_size
= sizeof(RAWState
),
143 .bdrv_open
= raw_open
,
144 .bdrv_close
= raw_close
,
145 .bdrv_read
= raw_read
,
146 .bdrv_write
= raw_write
,
147 .bdrv_flush
= raw_flush
,
148 .bdrv_probe
= raw_probe
,
149 .bdrv_getlength
= raw_getlength
,
150 .bdrv_truncate
= raw_truncate
,
152 .bdrv_aio_readv
= raw_aio_readv
,
153 .bdrv_aio_writev
= raw_aio_writev
,
154 .bdrv_aio_flush
= raw_aio_flush
,
156 .bdrv_is_inserted
= raw_is_inserted
,
157 .bdrv_eject
= raw_eject
,
158 .bdrv_set_locked
= raw_set_locked
,
159 .bdrv_ioctl
= raw_ioctl
,
160 .bdrv_aio_ioctl
= raw_aio_ioctl
,
162 .bdrv_create
= raw_create
,
163 .create_options
= raw_create_options
,
166 static void bdrv_raw_init(void)
168 bdrv_register(&bdrv_raw
);
171 block_init(bdrv_raw_init
);