Statistics
| Branch: | Revision:

root / block_int.h @ e325775b

History | View | Annotate | Download (6.9 kB)

1 ea2384d3 bellard
/*
2 ea2384d3 bellard
 * QEMU System Emulator block driver
3 5fafdf24 ths
 *
4 ea2384d3 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 5fafdf24 ths
 *
6 ea2384d3 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 ea2384d3 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 ea2384d3 bellard
 * in the Software without restriction, including without limitation the rights
9 ea2384d3 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 ea2384d3 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 ea2384d3 bellard
 * furnished to do so, subject to the following conditions:
12 ea2384d3 bellard
 *
13 ea2384d3 bellard
 * The above copyright notice and this permission notice shall be included in
14 ea2384d3 bellard
 * all copies or substantial portions of the Software.
15 ea2384d3 bellard
 *
16 ea2384d3 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 ea2384d3 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 ea2384d3 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 ea2384d3 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 ea2384d3 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 ea2384d3 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 ea2384d3 bellard
 * THE SOFTWARE.
23 ea2384d3 bellard
 */
24 ea2384d3 bellard
#ifndef BLOCK_INT_H
25 ea2384d3 bellard
#define BLOCK_INT_H
26 ea2384d3 bellard
27 faf07963 pbrook
#include "block.h"
28 0e7e1989 Kevin Wolf
#include "qemu-option.h"
29 faf07963 pbrook
30 ec36ba14 ths
#define BLOCK_FLAG_ENCRYPT        1
31 ec36ba14 ths
#define BLOCK_FLAG_COMPRESS        2
32 ec36ba14 ths
#define BLOCK_FLAG_COMPAT6        4
33 ec36ba14 ths
34 0e7e1989 Kevin Wolf
#define BLOCK_OPT_SIZE          "size"
35 0e7e1989 Kevin Wolf
#define BLOCK_OPT_ENCRYPT       "encryption"
36 0e7e1989 Kevin Wolf
#define BLOCK_OPT_COMPAT6       "compat6"
37 0e7e1989 Kevin Wolf
#define BLOCK_OPT_BACKING_FILE  "backing_file"
38 0e7e1989 Kevin Wolf
#define BLOCK_OPT_BACKING_FMT   "backing_fmt"
39 73c632ed Kevin Wolf
#define BLOCK_OPT_CLUSTER_SIZE  "cluster_size"
40 0e7e1989 Kevin Wolf
41 6bbff9a0 aliguori
typedef struct AIOPool {
42 6bbff9a0 aliguori
    void (*cancel)(BlockDriverAIOCB *acb);
43 6bbff9a0 aliguori
    int aiocb_size;
44 6bbff9a0 aliguori
    BlockDriverAIOCB *free_aiocb;
45 6bbff9a0 aliguori
} AIOPool;
46 6bbff9a0 aliguori
47 ea2384d3 bellard
struct BlockDriver {
48 ea2384d3 bellard
    const char *format_name;
49 ea2384d3 bellard
    int instance_size;
50 ea2384d3 bellard
    int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
51 508c7cb3 Christoph Hellwig
    int (*bdrv_probe_device)(const char *filename);
52 83f64091 bellard
    int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags);
53 5fafdf24 ths
    int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
54 ea2384d3 bellard
                     uint8_t *buf, int nb_sectors);
55 5fafdf24 ths
    int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
56 ea2384d3 bellard
                      const uint8_t *buf, int nb_sectors);
57 e2731add bellard
    void (*bdrv_close)(BlockDriverState *bs);
58 0e7e1989 Kevin Wolf
    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
59 7a6cba61 pbrook
    void (*bdrv_flush)(BlockDriverState *bs);
60 ea2384d3 bellard
    int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
61 ea2384d3 bellard
                             int nb_sectors, int *pnum);
62 ea2384d3 bellard
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
63 95389c86 bellard
    int (*bdrv_make_empty)(BlockDriverState *bs);
64 83f64091 bellard
    /* aio */
65 f141eafe aliguori
    BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
66 f141eafe aliguori
        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
67 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
68 f141eafe aliguori
    BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
69 f141eafe aliguori
        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
70 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
71 83f64091 bellard
72 83f64091 bellard
    const char *protocol_name;
73 83f64091 bellard
    int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
74 83f64091 bellard
    int64_t (*bdrv_getlength)(BlockDriverState *bs);
75 5fafdf24 ths
    int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
76 faea38e7 bellard
                                 const uint8_t *buf, int nb_sectors);
77 faea38e7 bellard
78 5fafdf24 ths
    int (*bdrv_snapshot_create)(BlockDriverState *bs,
79 faea38e7 bellard
                                QEMUSnapshotInfo *sn_info);
80 5fafdf24 ths
    int (*bdrv_snapshot_goto)(BlockDriverState *bs,
81 faea38e7 bellard
                              const char *snapshot_id);
82 faea38e7 bellard
    int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
83 5fafdf24 ths
    int (*bdrv_snapshot_list)(BlockDriverState *bs,
84 faea38e7 bellard
                              QEMUSnapshotInfo **psn_info);
85 faea38e7 bellard
    int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
86 83f64091 bellard
87 45566e9c Christoph Hellwig
    int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf,
88 45566e9c Christoph Hellwig
                             int64_t pos, int size);
89 45566e9c Christoph Hellwig
    int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf,
90 45566e9c Christoph Hellwig
                             int64_t pos, int size);
91 178e08a5 aliguori
92 19cb3738 bellard
    /* removable device specific */
93 19cb3738 bellard
    int (*bdrv_is_inserted)(BlockDriverState *bs);
94 19cb3738 bellard
    int (*bdrv_media_changed)(BlockDriverState *bs);
95 19cb3738 bellard
    int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
96 19cb3738 bellard
    int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
97 3b46e624 ths
98 985a03b0 ths
    /* to control generic scsi devices */
99 985a03b0 ths
    int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
100 221f715d aliguori
    BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs,
101 221f715d aliguori
        unsigned long int req, void *buf,
102 221f715d aliguori
        BlockDriverCompletionFunc *cb, void *opaque);
103 985a03b0 ths
104 0e7e1989 Kevin Wolf
    /* List of options for creating images, terminated by name == NULL */
105 0e7e1989 Kevin Wolf
    QEMUOptionParameter *create_options;
106 0e7e1989 Kevin Wolf
107 5eb45639 aliguori
108 e97fc193 aliguori
    /* Returns number of errors in image, -errno for internal errors */
109 e97fc193 aliguori
    int (*bdrv_check)(BlockDriverState* bs);
110 e97fc193 aliguori
111 ea2384d3 bellard
    struct BlockDriver *next;
112 ea2384d3 bellard
};
113 ea2384d3 bellard
114 ea2384d3 bellard
struct BlockDriverState {
115 d15a771d bellard
    int64_t total_sectors; /* if we are reading a disk image, give its
116 d15a771d bellard
                              size in sectors */
117 ea2384d3 bellard
    int read_only; /* if true, the media is read only */
118 ea2384d3 bellard
    int removable; /* if true, the media can be removed */
119 ea2384d3 bellard
    int locked;    /* if true, the media cannot temporarily be ejected */
120 ea2384d3 bellard
    int encrypted; /* if true, the media is encrypted */
121 c0f4ce77 aliguori
    int valid_key; /* if true, a valid encryption key has been set */
122 985a03b0 ths
    int sg;        /* if true, the device is a /dev/sg* */
123 ea2384d3 bellard
    /* event callback when inserting/removing */
124 ea2384d3 bellard
    void (*change_cb)(void *opaque);
125 ea2384d3 bellard
    void *change_opaque;
126 ea2384d3 bellard
127 19cb3738 bellard
    BlockDriver *drv; /* NULL means no media */
128 ea2384d3 bellard
    void *opaque;
129 ea2384d3 bellard
130 ea2384d3 bellard
    char filename[1024];
131 ea2384d3 bellard
    char backing_file[1024]; /* if non zero, the image is a diff of
132 ea2384d3 bellard
                                this file image */
133 5eb45639 aliguori
    char backing_format[16]; /* if non-zero and backing_file exists */
134 ea2384d3 bellard
    int is_temporary;
135 19cb3738 bellard
    int media_changed;
136 19cb3738 bellard
137 ea2384d3 bellard
    BlockDriverState *backing_hd;
138 ce1a14dc pbrook
    /* async read/write emulation */
139 83f64091 bellard
140 ce1a14dc pbrook
    void *sync_aiocb;
141 3b46e624 ths
142 a36e69dd ths
    /* I/O stats (display with "info blockstats"). */
143 a36e69dd ths
    uint64_t rd_bytes;
144 a36e69dd ths
    uint64_t wr_bytes;
145 a36e69dd ths
    uint64_t rd_ops;
146 a36e69dd ths
    uint64_t wr_ops;
147 a36e69dd ths
148 71d0770c aliguori
    /* Whether the disk can expand beyond total_sectors */
149 71d0770c aliguori
    int growable;
150 71d0770c aliguori
151 e268ca52 aliguori
    /* the memory alignment required for the buffers handled by this driver */
152 e268ca52 aliguori
    int buffer_alignment;
153 e268ca52 aliguori
154 ea2384d3 bellard
    /* NOTE: the following infos are only hints for real hardware
155 ea2384d3 bellard
       drivers. They are not used by the block driver */
156 46d4767d bellard
    int cyls, heads, secs, translation;
157 ea2384d3 bellard
    int type;
158 ea2384d3 bellard
    char device_name[32];
159 ea2384d3 bellard
    BlockDriverState *next;
160 b0a7b120 aliguori
    void *private;
161 ea2384d3 bellard
};
162 ea2384d3 bellard
163 83f64091 bellard
struct BlockDriverAIOCB {
164 6bbff9a0 aliguori
    AIOPool *pool;
165 83f64091 bellard
    BlockDriverState *bs;
166 83f64091 bellard
    BlockDriverCompletionFunc *cb;
167 ce1a14dc pbrook
    void *opaque;
168 ce1a14dc pbrook
    BlockDriverAIOCB *next;
169 83f64091 bellard
};
170 83f64091 bellard
171 95389c86 bellard
void get_tmp_filename(char *filename, int size);
172 95389c86 bellard
173 c16b5a2c Christoph Hellwig
void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
174 c16b5a2c Christoph Hellwig
                   BlockDriverCompletionFunc *cb, void *opaque);
175 ce1a14dc pbrook
void qemu_aio_release(void *p);
176 ce1a14dc pbrook
177 e268ca52 aliguori
void *qemu_blockalign(BlockDriverState *bs, size_t size);
178 e268ca52 aliguori
179 7ee930d0 blueswir1
extern BlockDriverState *bdrv_first;
180 faf07963 pbrook
181 508c7cb3 Christoph Hellwig
#ifdef _WIN32
182 508c7cb3 Christoph Hellwig
int is_windows_drive(const char *filename);
183 508c7cb3 Christoph Hellwig
#endif
184 508c7cb3 Christoph Hellwig
185 ea2384d3 bellard
#endif /* BLOCK_INT_H */