Statistics
| Branch: | Revision:

root / block / raw-win32.c @ 205ef796

History | View | Annotate | Download (11.2 kB)

1 223d4670 ths
/*
2 223d4670 ths
 * Block driver for RAW files (win32)
3 223d4670 ths
 *
4 223d4670 ths
 * Copyright (c) 2006 Fabrice Bellard
5 223d4670 ths
 *
6 223d4670 ths
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 223d4670 ths
 * of this software and associated documentation files (the "Software"), to deal
8 223d4670 ths
 * in the Software without restriction, including without limitation the rights
9 223d4670 ths
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 223d4670 ths
 * copies of the Software, and to permit persons to whom the Software is
11 223d4670 ths
 * furnished to do so, subject to the following conditions:
12 223d4670 ths
 *
13 223d4670 ths
 * The above copyright notice and this permission notice shall be included in
14 223d4670 ths
 * all copies or substantial portions of the Software.
15 223d4670 ths
 *
16 223d4670 ths
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 223d4670 ths
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 223d4670 ths
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 223d4670 ths
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 223d4670 ths
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 223d4670 ths
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 223d4670 ths
 * THE SOFTWARE.
23 223d4670 ths
 */
24 223d4670 ths
#include "qemu-common.h"
25 223d4670 ths
#include "qemu-timer.h"
26 223d4670 ths
#include "block_int.h"
27 5efa9d5a Anthony Liguori
#include "module.h"
28 49dc768d aliguori
#include <windows.h>
29 223d4670 ths
#include <winioctl.h>
30 223d4670 ths
31 223d4670 ths
#define FTYPE_FILE 0
32 223d4670 ths
#define FTYPE_CD     1
33 223d4670 ths
#define FTYPE_HARDDISK 2
34 223d4670 ths
35 223d4670 ths
typedef struct BDRVRawState {
36 223d4670 ths
    HANDLE hfile;
37 223d4670 ths
    int type;
38 223d4670 ths
    char drive_path[16]; /* format: "d:\" */
39 223d4670 ths
} BDRVRawState;
40 223d4670 ths
41 223d4670 ths
int qemu_ftruncate64(int fd, int64_t length)
42 223d4670 ths
{
43 223d4670 ths
    LARGE_INTEGER li;
44 223d4670 ths
    LONG high;
45 223d4670 ths
    HANDLE h;
46 223d4670 ths
    BOOL res;
47 223d4670 ths
48 223d4670 ths
    if ((GetVersion() & 0x80000000UL) && (length >> 32) != 0)
49 223d4670 ths
        return -1;
50 223d4670 ths
51 223d4670 ths
    h = (HANDLE)_get_osfhandle(fd);
52 223d4670 ths
53 223d4670 ths
    /* get current position, ftruncate do not change position */
54 223d4670 ths
    li.HighPart = 0;
55 223d4670 ths
    li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
56 223d4670 ths
    if (li.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
57 223d4670 ths
        return -1;
58 223d4670 ths
59 223d4670 ths
    high = length >> 32;
60 223d4670 ths
    if (!SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN))
61 223d4670 ths
        return -1;
62 223d4670 ths
    res = SetEndOfFile(h);
63 223d4670 ths
64 223d4670 ths
    /* back to old position */
65 223d4670 ths
    SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN);
66 223d4670 ths
    return res ? 0 : -1;
67 223d4670 ths
}
68 223d4670 ths
69 223d4670 ths
static int set_sparse(int fd)
70 223d4670 ths
{
71 223d4670 ths
    DWORD returned;
72 223d4670 ths
    return (int) DeviceIoControl((HANDLE)_get_osfhandle(fd), FSCTL_SET_SPARSE,
73 223d4670 ths
                                 NULL, 0, NULL, 0, &returned, NULL);
74 223d4670 ths
}
75 223d4670 ths
76 223d4670 ths
static int raw_open(BlockDriverState *bs, const char *filename, int flags)
77 223d4670 ths
{
78 223d4670 ths
    BDRVRawState *s = bs->opaque;
79 9a2d77ad Christoph Hellwig
    int access_flags;
80 223d4670 ths
    DWORD overlapped;
81 223d4670 ths
82 223d4670 ths
    s->type = FTYPE_FILE;
83 223d4670 ths
84 f5edb014 Naphtali Sprei
    if (flags & BDRV_O_RDWR) {
85 223d4670 ths
        access_flags = GENERIC_READ | GENERIC_WRITE;
86 223d4670 ths
    } else {
87 223d4670 ths
        access_flags = GENERIC_READ;
88 223d4670 ths
    }
89 9a2d77ad Christoph Hellwig
90 03ff3ca3 aliguori
    overlapped = FILE_ATTRIBUTE_NORMAL;
91 9f7965c7 aliguori
    if ((flags & BDRV_O_NOCACHE))
92 33f00271 balrog
        overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
93 9f7965c7 aliguori
    else if (!(flags & BDRV_O_CACHE_WB))
94 9f7965c7 aliguori
        overlapped |= FILE_FLAG_WRITE_THROUGH;
95 223d4670 ths
    s->hfile = CreateFile(filename, access_flags,
96 223d4670 ths
                          FILE_SHARE_READ, NULL,
97 9a2d77ad Christoph Hellwig
                          OPEN_EXISTING, overlapped, NULL);
98 223d4670 ths
    if (s->hfile == INVALID_HANDLE_VALUE) {
99 223d4670 ths
        int err = GetLastError();
100 223d4670 ths
101 223d4670 ths
        if (err == ERROR_ACCESS_DENIED)
102 223d4670 ths
            return -EACCES;
103 223d4670 ths
        return -1;
104 223d4670 ths
    }
105 223d4670 ths
    return 0;
106 223d4670 ths
}
107 223d4670 ths
108 eda578e5 aliguori
static int raw_read(BlockDriverState *bs, int64_t sector_num,
109 eda578e5 aliguori
                    uint8_t *buf, int nb_sectors)
110 223d4670 ths
{
111 223d4670 ths
    BDRVRawState *s = bs->opaque;
112 223d4670 ths
    OVERLAPPED ov;
113 223d4670 ths
    DWORD ret_count;
114 223d4670 ths
    int ret;
115 eda578e5 aliguori
    int64_t offset = sector_num * 512;
116 eda578e5 aliguori
    int count = nb_sectors * 512;
117 223d4670 ths
118 223d4670 ths
    memset(&ov, 0, sizeof(ov));
119 223d4670 ths
    ov.Offset = offset;
120 223d4670 ths
    ov.OffsetHigh = offset >> 32;
121 223d4670 ths
    ret = ReadFile(s->hfile, buf, count, &ret_count, &ov);
122 9c39be47 aliguori
    if (!ret)
123 9c39be47 aliguori
        return ret_count;
124 537a1d4b aliguori
    if (ret_count == count)
125 537a1d4b aliguori
        ret_count = 0;
126 223d4670 ths
    return ret_count;
127 223d4670 ths
}
128 223d4670 ths
129 eda578e5 aliguori
static int raw_write(BlockDriverState *bs, int64_t sector_num,
130 eda578e5 aliguori
                     const uint8_t *buf, int nb_sectors)
131 223d4670 ths
{
132 223d4670 ths
    BDRVRawState *s = bs->opaque;
133 223d4670 ths
    OVERLAPPED ov;
134 223d4670 ths
    DWORD ret_count;
135 223d4670 ths
    int ret;
136 eda578e5 aliguori
    int64_t offset = sector_num * 512;
137 eda578e5 aliguori
    int count = nb_sectors * 512;
138 223d4670 ths
139 223d4670 ths
    memset(&ov, 0, sizeof(ov));
140 223d4670 ths
    ov.Offset = offset;
141 223d4670 ths
    ov.OffsetHigh = offset >> 32;
142 223d4670 ths
    ret = WriteFile(s->hfile, buf, count, &ret_count, &ov);
143 9c39be47 aliguori
    if (!ret)
144 9c39be47 aliguori
        return ret_count;
145 537a1d4b aliguori
    if (ret_count == count)
146 537a1d4b aliguori
        ret_count = 0;
147 223d4670 ths
    return ret_count;
148 223d4670 ths
}
149 223d4670 ths
150 223d4670 ths
static void raw_flush(BlockDriverState *bs)
151 223d4670 ths
{
152 223d4670 ths
    BDRVRawState *s = bs->opaque;
153 205ef796 Kevin Wolf
    int ret;
154 205ef796 Kevin Wolf
155 205ef796 Kevin Wolf
    ret = FlushFileBuffers(s->hfile);
156 205ef796 Kevin Wolf
    if (ret != 0) {
157 205ef796 Kevin Wolf
        return -EIO;
158 205ef796 Kevin Wolf
    }
159 205ef796 Kevin Wolf
160 205ef796 Kevin Wolf
    return 0;
161 223d4670 ths
}
162 223d4670 ths
163 223d4670 ths
static void raw_close(BlockDriverState *bs)
164 223d4670 ths
{
165 223d4670 ths
    BDRVRawState *s = bs->opaque;
166 223d4670 ths
    CloseHandle(s->hfile);
167 223d4670 ths
}
168 223d4670 ths
169 223d4670 ths
static int raw_truncate(BlockDriverState *bs, int64_t offset)
170 223d4670 ths
{
171 223d4670 ths
    BDRVRawState *s = bs->opaque;
172 b9e82a59 blueswir1
    LONG low, high;
173 223d4670 ths
174 223d4670 ths
    low = offset;
175 223d4670 ths
    high = offset >> 32;
176 223d4670 ths
    if (!SetFilePointer(s->hfile, low, &high, FILE_BEGIN))
177 223d4670 ths
        return -EIO;
178 223d4670 ths
    if (!SetEndOfFile(s->hfile))
179 223d4670 ths
        return -EIO;
180 223d4670 ths
    return 0;
181 223d4670 ths
}
182 223d4670 ths
183 223d4670 ths
static int64_t raw_getlength(BlockDriverState *bs)
184 223d4670 ths
{
185 223d4670 ths
    BDRVRawState *s = bs->opaque;
186 223d4670 ths
    LARGE_INTEGER l;
187 223d4670 ths
    ULARGE_INTEGER available, total, total_free;
188 223d4670 ths
    DISK_GEOMETRY_EX dg;
189 223d4670 ths
    DWORD count;
190 223d4670 ths
    BOOL status;
191 223d4670 ths
192 223d4670 ths
    switch(s->type) {
193 223d4670 ths
    case FTYPE_FILE:
194 b9e82a59 blueswir1
        l.LowPart = GetFileSize(s->hfile, (PDWORD)&l.HighPart);
195 223d4670 ths
        if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
196 223d4670 ths
            return -EIO;
197 223d4670 ths
        break;
198 223d4670 ths
    case FTYPE_CD:
199 223d4670 ths
        if (!GetDiskFreeSpaceEx(s->drive_path, &available, &total, &total_free))
200 223d4670 ths
            return -EIO;
201 223d4670 ths
        l.QuadPart = total.QuadPart;
202 223d4670 ths
        break;
203 223d4670 ths
    case FTYPE_HARDDISK:
204 223d4670 ths
        status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
205 223d4670 ths
                                 NULL, 0, &dg, sizeof(dg), &count, NULL);
206 223d4670 ths
        if (status != 0) {
207 223d4670 ths
            l = dg.DiskSize;
208 223d4670 ths
        }
209 223d4670 ths
        break;
210 223d4670 ths
    default:
211 223d4670 ths
        return -EIO;
212 223d4670 ths
    }
213 223d4670 ths
    return l.QuadPart;
214 223d4670 ths
}
215 223d4670 ths
216 0e7e1989 Kevin Wolf
static int raw_create(const char *filename, QEMUOptionParameter *options)
217 223d4670 ths
{
218 223d4670 ths
    int fd;
219 0e7e1989 Kevin Wolf
    int64_t total_size = 0;
220 223d4670 ths
221 0e7e1989 Kevin Wolf
    /* Read out options */
222 0e7e1989 Kevin Wolf
    while (options && options->name) {
223 0e7e1989 Kevin Wolf
        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
224 0e7e1989 Kevin Wolf
            total_size = options->value.n / 512;
225 0e7e1989 Kevin Wolf
        }
226 0e7e1989 Kevin Wolf
        options++;
227 0e7e1989 Kevin Wolf
    }
228 223d4670 ths
229 223d4670 ths
    fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
230 223d4670 ths
              0644);
231 223d4670 ths
    if (fd < 0)
232 223d4670 ths
        return -EIO;
233 223d4670 ths
    set_sparse(fd);
234 223d4670 ths
    ftruncate(fd, total_size * 512);
235 223d4670 ths
    close(fd);
236 223d4670 ths
    return 0;
237 223d4670 ths
}
238 223d4670 ths
239 0e7e1989 Kevin Wolf
static QEMUOptionParameter raw_create_options[] = {
240 db08adf5 Kevin Wolf
    {
241 db08adf5 Kevin Wolf
        .name = BLOCK_OPT_SIZE,
242 db08adf5 Kevin Wolf
        .type = OPT_SIZE,
243 db08adf5 Kevin Wolf
        .help = "Virtual disk size"
244 db08adf5 Kevin Wolf
    },
245 0e7e1989 Kevin Wolf
    { NULL }
246 0e7e1989 Kevin Wolf
};
247 0e7e1989 Kevin Wolf
248 84a12e66 Christoph Hellwig
static BlockDriver bdrv_file = {
249 84a12e66 Christoph Hellwig
    .format_name        = "file",
250 84a12e66 Christoph Hellwig
    .protocol_name        = "file",
251 f1b2f712 aliguori
    .instance_size        = sizeof(BDRVRawState),
252 66f82cee Kevin Wolf
    .bdrv_file_open        = raw_open,
253 f1b2f712 aliguori
    .bdrv_close                = raw_close,
254 f1b2f712 aliguori
    .bdrv_create        = raw_create,
255 f1b2f712 aliguori
    .bdrv_flush                = raw_flush,
256 f1b2f712 aliguori
    .bdrv_read                = raw_read,
257 f1b2f712 aliguori
    .bdrv_write                = raw_write,
258 f1b2f712 aliguori
    .bdrv_truncate        = raw_truncate,
259 f1b2f712 aliguori
    .bdrv_getlength        = raw_getlength,
260 0e7e1989 Kevin Wolf
261 0e7e1989 Kevin Wolf
    .create_options = raw_create_options,
262 223d4670 ths
};
263 223d4670 ths
264 223d4670 ths
/***********************************************/
265 223d4670 ths
/* host device */
266 223d4670 ths
267 223d4670 ths
static int find_cdrom(char *cdrom_name, int cdrom_name_size)
268 223d4670 ths
{
269 223d4670 ths
    char drives[256], *pdrv = drives;
270 223d4670 ths
    UINT type;
271 223d4670 ths
272 223d4670 ths
    memset(drives, 0, sizeof(drives));
273 223d4670 ths
    GetLogicalDriveStrings(sizeof(drives), drives);
274 223d4670 ths
    while(pdrv[0] != '\0') {
275 223d4670 ths
        type = GetDriveType(pdrv);
276 223d4670 ths
        switch(type) {
277 223d4670 ths
        case DRIVE_CDROM:
278 223d4670 ths
            snprintf(cdrom_name, cdrom_name_size, "\\\\.\\%c:", pdrv[0]);
279 223d4670 ths
            return 0;
280 223d4670 ths
            break;
281 223d4670 ths
        }
282 223d4670 ths
        pdrv += lstrlen(pdrv) + 1;
283 223d4670 ths
    }
284 223d4670 ths
    return -1;
285 223d4670 ths
}
286 223d4670 ths
287 223d4670 ths
static int find_device_type(BlockDriverState *bs, const char *filename)
288 223d4670 ths
{
289 223d4670 ths
    BDRVRawState *s = bs->opaque;
290 223d4670 ths
    UINT type;
291 223d4670 ths
    const char *p;
292 223d4670 ths
293 223d4670 ths
    if (strstart(filename, "\\\\.\\", &p) ||
294 223d4670 ths
        strstart(filename, "//./", &p)) {
295 223d4670 ths
        if (stristart(p, "PhysicalDrive", NULL))
296 223d4670 ths
            return FTYPE_HARDDISK;
297 223d4670 ths
        snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]);
298 223d4670 ths
        type = GetDriveType(s->drive_path);
299 3060cd14 aliguori
        switch (type) {
300 3060cd14 aliguori
        case DRIVE_REMOVABLE:
301 3060cd14 aliguori
        case DRIVE_FIXED:
302 3060cd14 aliguori
            return FTYPE_HARDDISK;
303 3060cd14 aliguori
        case DRIVE_CDROM:
304 223d4670 ths
            return FTYPE_CD;
305 3060cd14 aliguori
        default:
306 223d4670 ths
            return FTYPE_FILE;
307 3060cd14 aliguori
        }
308 223d4670 ths
    } else {
309 223d4670 ths
        return FTYPE_FILE;
310 223d4670 ths
    }
311 223d4670 ths
}
312 223d4670 ths
313 508c7cb3 Christoph Hellwig
static int hdev_probe_device(const char *filename)
314 508c7cb3 Christoph Hellwig
{
315 508c7cb3 Christoph Hellwig
    if (strstart(filename, "/dev/cdrom", NULL))
316 508c7cb3 Christoph Hellwig
        return 100;
317 508c7cb3 Christoph Hellwig
    if (is_windows_drive(filename))
318 508c7cb3 Christoph Hellwig
        return 100;
319 508c7cb3 Christoph Hellwig
    return 0;
320 508c7cb3 Christoph Hellwig
}
321 508c7cb3 Christoph Hellwig
322 223d4670 ths
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
323 223d4670 ths
{
324 223d4670 ths
    BDRVRawState *s = bs->opaque;
325 223d4670 ths
    int access_flags, create_flags;
326 223d4670 ths
    DWORD overlapped;
327 223d4670 ths
    char device_name[64];
328 223d4670 ths
329 223d4670 ths
    if (strstart(filename, "/dev/cdrom", NULL)) {
330 223d4670 ths
        if (find_cdrom(device_name, sizeof(device_name)) < 0)
331 223d4670 ths
            return -ENOENT;
332 223d4670 ths
        filename = device_name;
333 223d4670 ths
    } else {
334 223d4670 ths
        /* transform drive letters into device name */
335 223d4670 ths
        if (((filename[0] >= 'a' && filename[0] <= 'z') ||
336 223d4670 ths
             (filename[0] >= 'A' && filename[0] <= 'Z')) &&
337 223d4670 ths
            filename[1] == ':' && filename[2] == '\0') {
338 223d4670 ths
            snprintf(device_name, sizeof(device_name), "\\\\.\\%c:", filename[0]);
339 223d4670 ths
            filename = device_name;
340 223d4670 ths
        }
341 223d4670 ths
    }
342 223d4670 ths
    s->type = find_device_type(bs, filename);
343 223d4670 ths
344 f5edb014 Naphtali Sprei
    if (flags & BDRV_O_RDWR) {
345 223d4670 ths
        access_flags = GENERIC_READ | GENERIC_WRITE;
346 223d4670 ths
    } else {
347 223d4670 ths
        access_flags = GENERIC_READ;
348 223d4670 ths
    }
349 223d4670 ths
    create_flags = OPEN_EXISTING;
350 223d4670 ths
351 03ff3ca3 aliguori
    overlapped = FILE_ATTRIBUTE_NORMAL;
352 9f7965c7 aliguori
    if ((flags & BDRV_O_NOCACHE))
353 33f00271 balrog
        overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
354 9f7965c7 aliguori
    else if (!(flags & BDRV_O_CACHE_WB))
355 9f7965c7 aliguori
        overlapped |= FILE_FLAG_WRITE_THROUGH;
356 223d4670 ths
    s->hfile = CreateFile(filename, access_flags,
357 223d4670 ths
                          FILE_SHARE_READ, NULL,
358 223d4670 ths
                          create_flags, overlapped, NULL);
359 223d4670 ths
    if (s->hfile == INVALID_HANDLE_VALUE) {
360 223d4670 ths
        int err = GetLastError();
361 223d4670 ths
362 223d4670 ths
        if (err == ERROR_ACCESS_DENIED)
363 223d4670 ths
            return -EACCES;
364 223d4670 ths
        return -1;
365 223d4670 ths
    }
366 223d4670 ths
    return 0;
367 223d4670 ths
}
368 223d4670 ths
369 223d4670 ths
#if 0
370 223d4670 ths
/***********************************************/
371 223d4670 ths
/* removable device additional commands */
372 223d4670 ths

373 223d4670 ths
static int raw_is_inserted(BlockDriverState *bs)
374 223d4670 ths
{
375 223d4670 ths
    return 1;
376 223d4670 ths
}
377 223d4670 ths

378 223d4670 ths
static int raw_media_changed(BlockDriverState *bs)
379 223d4670 ths
{
380 223d4670 ths
    return -ENOTSUP;
381 223d4670 ths
}
382 223d4670 ths

383 223d4670 ths
static int raw_eject(BlockDriverState *bs, int eject_flag)
384 223d4670 ths
{
385 223d4670 ths
    DWORD ret_count;
386 223d4670 ths

387 223d4670 ths
    if (s->type == FTYPE_FILE)
388 223d4670 ths
        return -ENOTSUP;
389 223d4670 ths
    if (eject_flag) {
390 223d4670 ths
        DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
391 223d4670 ths
                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
392 223d4670 ths
    } else {
393 223d4670 ths
        DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
394 223d4670 ths
                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
395 223d4670 ths
    }
396 223d4670 ths
}
397 223d4670 ths

398 223d4670 ths
static int raw_set_locked(BlockDriverState *bs, int locked)
399 223d4670 ths
{
400 223d4670 ths
    return -ENOTSUP;
401 223d4670 ths
}
402 223d4670 ths
#endif
403 223d4670 ths
404 336c1c12 Kevin Wolf
static int hdev_has_zero_init(BlockDriverState *bs)
405 336c1c12 Kevin Wolf
{
406 336c1c12 Kevin Wolf
    return 0;
407 336c1c12 Kevin Wolf
}
408 336c1c12 Kevin Wolf
409 5efa9d5a Anthony Liguori
static BlockDriver bdrv_host_device = {
410 e60f469c aurel32
    .format_name        = "host_device",
411 84a12e66 Christoph Hellwig
    .protocol_name        = "host_device",
412 e60f469c aurel32
    .instance_size        = sizeof(BDRVRawState),
413 508c7cb3 Christoph Hellwig
    .bdrv_probe_device        = hdev_probe_device,
414 66f82cee Kevin Wolf
    .bdrv_file_open        = hdev_open,
415 e60f469c aurel32
    .bdrv_close                = raw_close,
416 e60f469c aurel32
    .bdrv_flush                = raw_flush,
417 336c1c12 Kevin Wolf
    .bdrv_has_zero_init = hdev_has_zero_init,
418 223d4670 ths
419 eda578e5 aliguori
    .bdrv_read                = raw_read,
420 eda578e5 aliguori
    .bdrv_write                = raw_write,
421 e60f469c aurel32
    .bdrv_getlength        = raw_getlength,
422 223d4670 ths
};
423 5efa9d5a Anthony Liguori
424 84a12e66 Christoph Hellwig
static void bdrv_file_init(void)
425 5efa9d5a Anthony Liguori
{
426 84a12e66 Christoph Hellwig
    bdrv_register(&bdrv_file);
427 5efa9d5a Anthony Liguori
    bdrv_register(&bdrv_host_device);
428 5efa9d5a Anthony Liguori
}
429 5efa9d5a Anthony Liguori
430 84a12e66 Christoph Hellwig
block_init(bdrv_file_init);