Statistics
| Branch: | Revision:

root / block_int.h @ bb6f6792

History | View | Annotate | Download (5.4 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 ec36ba14 ths
#define BLOCK_FLAG_ENCRYPT        1
28 ec36ba14 ths
#define BLOCK_FLAG_COMPRESS        2
29 ec36ba14 ths
#define BLOCK_FLAG_COMPAT6        4
30 ec36ba14 ths
31 ea2384d3 bellard
struct BlockDriver {
32 ea2384d3 bellard
    const char *format_name;
33 ea2384d3 bellard
    int instance_size;
34 ea2384d3 bellard
    int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
35 83f64091 bellard
    int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags);
36 5fafdf24 ths
    int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
37 ea2384d3 bellard
                     uint8_t *buf, int nb_sectors);
38 5fafdf24 ths
    int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
39 ea2384d3 bellard
                      const uint8_t *buf, int nb_sectors);
40 e2731add bellard
    void (*bdrv_close)(BlockDriverState *bs);
41 5fafdf24 ths
    int (*bdrv_create)(const char *filename, int64_t total_sectors,
42 ea2384d3 bellard
                       const char *backing_file, int flags);
43 7a6cba61 pbrook
    void (*bdrv_flush)(BlockDriverState *bs);
44 ea2384d3 bellard
    int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
45 ea2384d3 bellard
                             int nb_sectors, int *pnum);
46 ea2384d3 bellard
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
47 95389c86 bellard
    int (*bdrv_make_empty)(BlockDriverState *bs);
48 83f64091 bellard
    /* aio */
49 ce1a14dc pbrook
    BlockDriverAIOCB *(*bdrv_aio_read)(BlockDriverState *bs,
50 ce1a14dc pbrook
        int64_t sector_num, uint8_t *buf, int nb_sectors,
51 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
52 ce1a14dc pbrook
    BlockDriverAIOCB *(*bdrv_aio_write)(BlockDriverState *bs,
53 ce1a14dc pbrook
        int64_t sector_num, const uint8_t *buf, int nb_sectors,
54 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
55 83f64091 bellard
    void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);
56 ce1a14dc pbrook
    int aiocb_size;
57 83f64091 bellard
58 83f64091 bellard
    const char *protocol_name;
59 5fafdf24 ths
    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
60 83f64091 bellard
                      uint8_t *buf, int count);
61 5fafdf24 ths
    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
62 83f64091 bellard
                       const uint8_t *buf, int count);
63 83f64091 bellard
    int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
64 83f64091 bellard
    int64_t (*bdrv_getlength)(BlockDriverState *bs);
65 5fafdf24 ths
    int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
66 faea38e7 bellard
                                 const uint8_t *buf, int nb_sectors);
67 faea38e7 bellard
68 5fafdf24 ths
    int (*bdrv_snapshot_create)(BlockDriverState *bs,
69 faea38e7 bellard
                                QEMUSnapshotInfo *sn_info);
70 5fafdf24 ths
    int (*bdrv_snapshot_goto)(BlockDriverState *bs,
71 faea38e7 bellard
                              const char *snapshot_id);
72 faea38e7 bellard
    int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
73 5fafdf24 ths
    int (*bdrv_snapshot_list)(BlockDriverState *bs,
74 faea38e7 bellard
                              QEMUSnapshotInfo **psn_info);
75 faea38e7 bellard
    int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
76 83f64091 bellard
77 19cb3738 bellard
    /* removable device specific */
78 19cb3738 bellard
    int (*bdrv_is_inserted)(BlockDriverState *bs);
79 19cb3738 bellard
    int (*bdrv_media_changed)(BlockDriverState *bs);
80 19cb3738 bellard
    int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
81 19cb3738 bellard
    int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
82 3b46e624 ths
83 ce1a14dc pbrook
    BlockDriverAIOCB *free_aiocb;
84 ea2384d3 bellard
    struct BlockDriver *next;
85 ea2384d3 bellard
};
86 ea2384d3 bellard
87 ea2384d3 bellard
struct BlockDriverState {
88 d15a771d bellard
    int64_t total_sectors; /* if we are reading a disk image, give its
89 d15a771d bellard
                              size in sectors */
90 ea2384d3 bellard
    int read_only; /* if true, the media is read only */
91 ea2384d3 bellard
    int removable; /* if true, the media can be removed */
92 ea2384d3 bellard
    int locked;    /* if true, the media cannot temporarily be ejected */
93 ea2384d3 bellard
    int encrypted; /* if true, the media is encrypted */
94 ea2384d3 bellard
    /* event callback when inserting/removing */
95 ea2384d3 bellard
    void (*change_cb)(void *opaque);
96 ea2384d3 bellard
    void *change_opaque;
97 ea2384d3 bellard
98 19cb3738 bellard
    BlockDriver *drv; /* NULL means no media */
99 ea2384d3 bellard
    void *opaque;
100 ea2384d3 bellard
101 ea2384d3 bellard
    int boot_sector_enabled;
102 ea2384d3 bellard
    uint8_t boot_sector_data[512];
103 ea2384d3 bellard
104 ea2384d3 bellard
    char filename[1024];
105 ea2384d3 bellard
    char backing_file[1024]; /* if non zero, the image is a diff of
106 ea2384d3 bellard
                                this file image */
107 ea2384d3 bellard
    int is_temporary;
108 19cb3738 bellard
    int media_changed;
109 19cb3738 bellard
110 ea2384d3 bellard
    BlockDriverState *backing_hd;
111 ce1a14dc pbrook
    /* async read/write emulation */
112 83f64091 bellard
113 ce1a14dc pbrook
    void *sync_aiocb;
114 3b46e624 ths
115 ea2384d3 bellard
    /* NOTE: the following infos are only hints for real hardware
116 ea2384d3 bellard
       drivers. They are not used by the block driver */
117 46d4767d bellard
    int cyls, heads, secs, translation;
118 ea2384d3 bellard
    int type;
119 ea2384d3 bellard
    char device_name[32];
120 ea2384d3 bellard
    BlockDriverState *next;
121 ea2384d3 bellard
};
122 ea2384d3 bellard
123 83f64091 bellard
struct BlockDriverAIOCB {
124 83f64091 bellard
    BlockDriverState *bs;
125 83f64091 bellard
    BlockDriverCompletionFunc *cb;
126 ce1a14dc pbrook
    void *opaque;
127 ce1a14dc pbrook
    BlockDriverAIOCB *next;
128 83f64091 bellard
};
129 83f64091 bellard
130 95389c86 bellard
void get_tmp_filename(char *filename, int size);
131 95389c86 bellard
132 ce1a14dc pbrook
void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
133 ce1a14dc pbrook
                   void *opaque);
134 ce1a14dc pbrook
void qemu_aio_release(void *p);
135 ce1a14dc pbrook
136 ea2384d3 bellard
#endif /* BLOCK_INT_H */