raw.c 3.9 KB
Newer Older
1 2 3 4 5

#include "qemu-common.h"
#include "block_int.h"
#include "module.h"

6
static int raw_open(BlockDriverState *bs, int flags)
7
{
8 9
    bs->sg = bs->file->sg;
    return 0;
10 11
}

J
Jeff Cody 已提交
12 13 14 15 16 17 18 19
/* We have nothing to do for raw reopen, stubs just return
 * success */
static int raw_reopen_prepare(BDRVReopenState *state,
                              BlockReopenQueue *queue,  Error **errp)
{
    return 0;
}

20 21
static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
                                     int nb_sectors, QEMUIOVector *qiov)
22
{
P
Paolo Bonzini 已提交
23
    BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
24
    return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
25 26
}

27 28
static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
                                      int nb_sectors, QEMUIOVector *qiov)
29
{
P
Paolo Bonzini 已提交
30
    BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
31
    return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
32 33 34 35 36 37
}

static void raw_close(BlockDriverState *bs)
{
}

38 39 40 41 42 43 44
static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
                                            int64_t sector_num,
                                            int nb_sectors, int *pnum)
{
    return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum);
}

45 46
static int64_t raw_getlength(BlockDriverState *bs)
{
47
    return bdrv_getlength(bs->file);
48 49 50 51
}

static int raw_truncate(BlockDriverState *bs, int64_t offset)
{
52
    return bdrv_truncate(bs->file, offset);
53 54 55 56 57 58 59
}

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

60 61
static int coroutine_fn raw_co_discard(BlockDriverState *bs,
                                       int64_t sector_num, int nb_sectors)
C
Christoph Hellwig 已提交
62
{
63
    return bdrv_co_discard(bs->file, sector_num, nb_sectors);
C
Christoph Hellwig 已提交
64 65
}

66 67
static int raw_is_inserted(BlockDriverState *bs)
{
68
    return bdrv_is_inserted(bs->file);
69 70
}

71 72 73 74 75
static int raw_media_changed(BlockDriverState *bs)
{
    return bdrv_media_changed(bs->file);
}

76
static void raw_eject(BlockDriverState *bs, bool eject_flag)
77
{
78
    bdrv_eject(bs->file, eject_flag);
79 80
}

81
static void raw_lock_medium(BlockDriverState *bs, bool locked)
82
{
83
    bdrv_lock_medium(bs->file, locked);
84 85 86 87
}

static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
{
88
   return bdrv_ioctl(bs->file, req, buf);
89 90 91 92 93 94
}

static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
        unsigned long int req, void *buf,
        BlockDriverCompletionFunc *cb, void *opaque)
{
95
   return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
}

static int raw_create(const char *filename, QEMUOptionParameter *options)
{
    return bdrv_create_file(filename, options);
}

static QEMUOptionParameter raw_create_options[] = {
    {
        .name = BLOCK_OPT_SIZE,
        .type = OPT_SIZE,
        .help = "Virtual disk size"
    },
    { NULL }
};

K
Kevin Wolf 已提交
112 113 114 115 116
static int raw_has_zero_init(BlockDriverState *bs)
{
    return bdrv_has_zero_init(bs->file);
}

117 118 119
static BlockDriver bdrv_raw = {
    .format_name        = "raw",

120
    /* It's really 0, but we need to make g_malloc() happy */
121
    .instance_size      = 1,
122 123 124

    .bdrv_open          = raw_open,
    .bdrv_close         = raw_close,
125

J
Jeff Cody 已提交
126 127
    .bdrv_reopen_prepare  = raw_reopen_prepare,

128 129
    .bdrv_co_readv          = raw_co_readv,
    .bdrv_co_writev         = raw_co_writev,
130
    .bdrv_co_is_allocated   = raw_co_is_allocated,
131
    .bdrv_co_discard        = raw_co_discard,
132

133 134 135 136 137
    .bdrv_probe         = raw_probe,
    .bdrv_getlength     = raw_getlength,
    .bdrv_truncate      = raw_truncate,

    .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,
141

142 143 144 145 146
    .bdrv_ioctl         = raw_ioctl,
    .bdrv_aio_ioctl     = raw_aio_ioctl,

    .bdrv_create        = raw_create,
    .create_options     = raw_create_options,
K
Kevin Wolf 已提交
147
    .bdrv_has_zero_init = raw_has_zero_init,
148 149 150 151 152 153 154 155
};

static void bdrv_raw_init(void)
{
    bdrv_register(&bdrv_raw);
}

block_init(bdrv_raw_init);