Statistics
| Branch: | Revision:

root / block / raw.c @ 5c171afa

History | View | Annotate | Download (3.7 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 coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
13
                                     int nb_sectors, QEMUIOVector *qiov)
14
{
15
    BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
16
    return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
17
}
18

    
19
static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
20
                                      int nb_sectors, QEMUIOVector *qiov)
21
{
22
    BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
23
    return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
24
}
25

    
26
static void raw_close(BlockDriverState *bs)
27
{
28
}
29

    
30
static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
31
                                            int64_t sector_num,
32
                                            int nb_sectors, int *pnum)
33
{
34
    return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum);
35
}
36

    
37
static int64_t raw_getlength(BlockDriverState *bs)
38
{
39
    return bdrv_getlength(bs->file);
40
}
41

    
42
static int raw_truncate(BlockDriverState *bs, int64_t offset)
43
{
44
    return bdrv_truncate(bs->file, offset);
45
}
46

    
47
static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
48
{
49
   return 1; /* everything can be opened as raw image */
50
}
51

    
52
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
53
                                       int64_t sector_num, int nb_sectors)
54
{
55
    return bdrv_co_discard(bs->file, sector_num, nb_sectors);
56
}
57

    
58
static int raw_is_inserted(BlockDriverState *bs)
59
{
60
    return bdrv_is_inserted(bs->file);
61
}
62

    
63
static int raw_media_changed(BlockDriverState *bs)
64
{
65
    return bdrv_media_changed(bs->file);
66
}
67

    
68
static void raw_eject(BlockDriverState *bs, bool eject_flag)
69
{
70
    bdrv_eject(bs->file, eject_flag);
71
}
72

    
73
static void raw_lock_medium(BlockDriverState *bs, bool locked)
74
{
75
    bdrv_lock_medium(bs->file, locked);
76
}
77

    
78
static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
79
{
80
   return bdrv_ioctl(bs->file, req, buf);
81
}
82

    
83
static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
84
        unsigned long int req, void *buf,
85
        BlockDriverCompletionFunc *cb, void *opaque)
86
{
87
   return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
88
}
89

    
90
static int raw_create(const char *filename, QEMUOptionParameter *options)
91
{
92
    return bdrv_create_file(filename, options);
93
}
94

    
95
static QEMUOptionParameter raw_create_options[] = {
96
    {
97
        .name = BLOCK_OPT_SIZE,
98
        .type = OPT_SIZE,
99
        .help = "Virtual disk size"
100
    },
101
    { NULL }
102
};
103

    
104
static int raw_has_zero_init(BlockDriverState *bs)
105
{
106
    return bdrv_has_zero_init(bs->file);
107
}
108

    
109
static BlockDriver bdrv_raw = {
110
    .format_name        = "raw",
111

    
112
    /* It's really 0, but we need to make g_malloc() happy */
113
    .instance_size      = 1,
114

    
115
    .bdrv_open          = raw_open,
116
    .bdrv_close         = raw_close,
117

    
118
    .bdrv_co_readv          = raw_co_readv,
119
    .bdrv_co_writev         = raw_co_writev,
120
    .bdrv_co_is_allocated   = raw_co_is_allocated,
121
    .bdrv_co_discard        = raw_co_discard,
122

    
123
    .bdrv_probe         = raw_probe,
124
    .bdrv_getlength     = raw_getlength,
125
    .bdrv_truncate      = raw_truncate,
126

    
127
    .bdrv_is_inserted   = raw_is_inserted,
128
    .bdrv_media_changed = raw_media_changed,
129
    .bdrv_eject         = raw_eject,
130
    .bdrv_lock_medium   = raw_lock_medium,
131

    
132
    .bdrv_ioctl         = raw_ioctl,
133
    .bdrv_aio_ioctl     = raw_aio_ioctl,
134

    
135
    .bdrv_create        = raw_create,
136
    .create_options     = raw_create_options,
137
    .bdrv_has_zero_init = raw_has_zero_init,
138
};
139

    
140
static void bdrv_raw_init(void)
141
{
142
    bdrv_register(&bdrv_raw);
143
}
144

    
145
block_init(bdrv_raw_init);