Statistics
| Branch: | Revision:

root / block_int.h @ 83f64091

History | View | Annotate | Download (4.2 kB)

1 ea2384d3 bellard
/*
2 ea2384d3 bellard
 * QEMU System Emulator block driver
3 ea2384d3 bellard
 * 
4 ea2384d3 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 ea2384d3 bellard
 * 
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 ea2384d3 bellard
struct BlockDriver {
28 ea2384d3 bellard
    const char *format_name;
29 ea2384d3 bellard
    int instance_size;
30 ea2384d3 bellard
    int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
31 83f64091 bellard
    int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags);
32 ea2384d3 bellard
    int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, 
33 ea2384d3 bellard
                     uint8_t *buf, int nb_sectors);
34 ea2384d3 bellard
    int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, 
35 ea2384d3 bellard
                      const uint8_t *buf, int nb_sectors);
36 e2731add bellard
    void (*bdrv_close)(BlockDriverState *bs);
37 ea2384d3 bellard
    int (*bdrv_create)(const char *filename, int64_t total_sectors, 
38 ea2384d3 bellard
                       const char *backing_file, int flags);
39 7a6cba61 pbrook
    void (*bdrv_flush)(BlockDriverState *bs);
40 ea2384d3 bellard
    int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
41 ea2384d3 bellard
                             int nb_sectors, int *pnum);
42 ea2384d3 bellard
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
43 95389c86 bellard
    int (*bdrv_make_empty)(BlockDriverState *bs);
44 83f64091 bellard
    /* aio */
45 83f64091 bellard
    int (*bdrv_aio_new)(BlockDriverAIOCB *acb);
46 83f64091 bellard
    int (*bdrv_aio_read)(BlockDriverAIOCB *acb, int64_t sector_num,
47 83f64091 bellard
                              uint8_t *buf, int nb_sectors);
48 83f64091 bellard
    int (*bdrv_aio_write)(BlockDriverAIOCB *acb, int64_t sector_num,
49 83f64091 bellard
                          const uint8_t *buf, int nb_sectors);
50 83f64091 bellard
    void (*bdrv_aio_cancel)(BlockDriverAIOCB *acb);
51 83f64091 bellard
    void (*bdrv_aio_delete)(BlockDriverAIOCB *acb);
52 83f64091 bellard
53 83f64091 bellard
    const char *protocol_name;
54 83f64091 bellard
    int (*bdrv_pread)(BlockDriverState *bs, int64_t offset, 
55 83f64091 bellard
                      uint8_t *buf, int count);
56 83f64091 bellard
    int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset, 
57 83f64091 bellard
                       const uint8_t *buf, int count);
58 83f64091 bellard
    int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
59 83f64091 bellard
    int64_t (*bdrv_getlength)(BlockDriverState *bs);
60 83f64091 bellard
61 ea2384d3 bellard
    struct BlockDriver *next;
62 ea2384d3 bellard
};
63 ea2384d3 bellard
64 ea2384d3 bellard
struct BlockDriverState {
65 83f64091 bellard
    int64_t total_sectors; /* XXX: will be suppressed */
66 ea2384d3 bellard
    int read_only; /* if true, the media is read only */
67 ea2384d3 bellard
    int inserted; /* if true, the media is present */
68 ea2384d3 bellard
    int removable; /* if true, the media can be removed */
69 ea2384d3 bellard
    int locked;    /* if true, the media cannot temporarily be ejected */
70 ea2384d3 bellard
    int encrypted; /* if true, the media is encrypted */
71 ea2384d3 bellard
    /* event callback when inserting/removing */
72 ea2384d3 bellard
    void (*change_cb)(void *opaque);
73 ea2384d3 bellard
    void *change_opaque;
74 ea2384d3 bellard
75 ea2384d3 bellard
    BlockDriver *drv;
76 ea2384d3 bellard
    void *opaque;
77 ea2384d3 bellard
78 ea2384d3 bellard
    int boot_sector_enabled;
79 ea2384d3 bellard
    uint8_t boot_sector_data[512];
80 ea2384d3 bellard
81 ea2384d3 bellard
    char filename[1024];
82 ea2384d3 bellard
    char backing_file[1024]; /* if non zero, the image is a diff of
83 ea2384d3 bellard
                                this file image */
84 ea2384d3 bellard
    int is_temporary;
85 ea2384d3 bellard
    
86 ea2384d3 bellard
    BlockDriverState *backing_hd;
87 83f64091 bellard
    /* sync read/write emulation */
88 83f64091 bellard
89 83f64091 bellard
    BlockDriverAIOCB *sync_aiocb;
90 ea2384d3 bellard
    
91 ea2384d3 bellard
    /* NOTE: the following infos are only hints for real hardware
92 ea2384d3 bellard
       drivers. They are not used by the block driver */
93 46d4767d bellard
    int cyls, heads, secs, translation;
94 ea2384d3 bellard
    int type;
95 ea2384d3 bellard
    char device_name[32];
96 ea2384d3 bellard
    BlockDriverState *next;
97 ea2384d3 bellard
};
98 ea2384d3 bellard
99 83f64091 bellard
struct BlockDriverAIOCB {
100 83f64091 bellard
    BlockDriverState *bs;
101 83f64091 bellard
    BlockDriverCompletionFunc *cb;
102 83f64091 bellard
    void *cb_opaque;
103 83f64091 bellard
    
104 83f64091 bellard
    void *opaque; /* driver opaque */
105 83f64091 bellard
};
106 83f64091 bellard
107 95389c86 bellard
void get_tmp_filename(char *filename, int size);
108 95389c86 bellard
109 ea2384d3 bellard
#endif /* BLOCK_INT_H */