2 #include "qemu-common.h"
3 #include "block/block_int.h"
4 #include "qemu/module.h"
6 static int raw_open(BlockDriverState
*bs
, QDict
*options
, int flags
)
12 /* We have nothing to do for raw reopen, stubs just return
14 static int raw_reopen_prepare(BDRVReopenState
*state
,
15 BlockReopenQueue
*queue
, Error
**errp
)
20 static int coroutine_fn
raw_co_readv(BlockDriverState
*bs
, int64_t sector_num
,
21 int nb_sectors
, QEMUIOVector
*qiov
)
23 BLKDBG_EVENT(bs
->file
, BLKDBG_READ_AIO
);
24 return bdrv_co_readv(bs
->file
, sector_num
, nb_sectors
, qiov
);
27 static int coroutine_fn
raw_co_writev(BlockDriverState
*bs
, int64_t sector_num
,
28 int nb_sectors
, QEMUIOVector
*qiov
)
30 BLKDBG_EVENT(bs
->file
, BLKDBG_WRITE_AIO
);
31 return bdrv_co_writev(bs
->file
, sector_num
, nb_sectors
, qiov
);
34 static void raw_close(BlockDriverState
*bs
)
38 static int coroutine_fn
raw_co_is_allocated(BlockDriverState
*bs
,
40 int nb_sectors
, int *pnum
)
42 return bdrv_co_is_allocated(bs
->file
, sector_num
, nb_sectors
, pnum
);
45 static int64_t raw_getlength(BlockDriverState
*bs
)
47 return bdrv_getlength(bs
->file
);
50 static int raw_truncate(BlockDriverState
*bs
, int64_t offset
)
52 return bdrv_truncate(bs
->file
, offset
);
55 static int raw_probe(const uint8_t *buf
, int buf_size
, const char *filename
)
57 return 1; /* everything can be opened as raw image */
60 static int coroutine_fn
raw_co_discard(BlockDriverState
*bs
,
61 int64_t sector_num
, int nb_sectors
)
63 return bdrv_co_discard(bs
->file
, sector_num
, nb_sectors
);
66 static int raw_is_inserted(BlockDriverState
*bs
)
68 return bdrv_is_inserted(bs
->file
);
71 static int raw_media_changed(BlockDriverState
*bs
)
73 return bdrv_media_changed(bs
->file
);
76 static void raw_eject(BlockDriverState
*bs
, bool eject_flag
)
78 bdrv_eject(bs
->file
, eject_flag
);
81 static void raw_lock_medium(BlockDriverState
*bs
, bool locked
)
83 bdrv_lock_medium(bs
->file
, locked
);
86 static int raw_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
88 return bdrv_ioctl(bs
->file
, req
, buf
);
91 static BlockDriverAIOCB
*raw_aio_ioctl(BlockDriverState
*bs
,
92 unsigned long int req
, void *buf
,
93 BlockDriverCompletionFunc
*cb
, void *opaque
)
95 return bdrv_aio_ioctl(bs
->file
, req
, buf
, cb
, opaque
);
98 static int raw_create(const char *filename
, QEMUOptionParameter
*options
)
100 return bdrv_create_file(filename
, options
);
103 static QEMUOptionParameter raw_create_options
[] = {
105 .name
= BLOCK_OPT_SIZE
,
107 .help
= "Virtual disk size"
112 static int raw_has_zero_init(BlockDriverState
*bs
)
114 return bdrv_has_zero_init(bs
->file
);
117 static BlockDriver bdrv_raw
= {
118 .format_name
= "raw",
120 /* It's really 0, but we need to make g_malloc() happy */
123 .bdrv_open
= raw_open
,
124 .bdrv_close
= raw_close
,
126 .bdrv_reopen_prepare
= raw_reopen_prepare
,
128 .bdrv_co_readv
= raw_co_readv
,
129 .bdrv_co_writev
= raw_co_writev
,
130 .bdrv_co_is_allocated
= raw_co_is_allocated
,
131 .bdrv_co_discard
= raw_co_discard
,
133 .bdrv_probe
= raw_probe
,
134 .bdrv_getlength
= raw_getlength
,
135 .bdrv_truncate
= raw_truncate
,
137 .bdrv_is_inserted
= raw_is_inserted
,
138 .bdrv_media_changed
= raw_media_changed
,
139 .bdrv_eject
= raw_eject
,
140 .bdrv_lock_medium
= raw_lock_medium
,
142 .bdrv_ioctl
= raw_ioctl
,
143 .bdrv_aio_ioctl
= raw_aio_ioctl
,
145 .bdrv_create
= raw_create
,
146 .create_options
= raw_create_options
,
147 .bdrv_has_zero_init
= raw_has_zero_init
,
150 static void bdrv_raw_init(void)
152 bdrv_register(&bdrv_raw
);
155 block_init(bdrv_raw_init
);