root / block / raw-win32.c @ 5bc89ef6
History | View | Annotate | Download (11.1 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 | 223d4670 | ths | int access_flags, create_flags;
|
80 | 223d4670 | ths | DWORD overlapped; |
81 | 223d4670 | ths | |
82 | 223d4670 | ths | s->type = FTYPE_FILE; |
83 | 223d4670 | ths | |
84 | 223d4670 | ths | if ((flags & BDRV_O_ACCESS) == 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 | 223d4670 | ths | if (flags & BDRV_O_CREAT) {
|
90 | 223d4670 | ths | create_flags = CREATE_ALWAYS; |
91 | 223d4670 | ths | } else {
|
92 | 223d4670 | ths | create_flags = OPEN_EXISTING; |
93 | 223d4670 | ths | } |
94 | 03ff3ca3 | aliguori | overlapped = FILE_ATTRIBUTE_NORMAL; |
95 | 9f7965c7 | aliguori | if ((flags & BDRV_O_NOCACHE))
|
96 | 33f00271 | balrog | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; |
97 | 9f7965c7 | aliguori | else if (!(flags & BDRV_O_CACHE_WB)) |
98 | 9f7965c7 | aliguori | overlapped |= FILE_FLAG_WRITE_THROUGH; |
99 | 223d4670 | ths | s->hfile = CreateFile(filename, access_flags, |
100 | 223d4670 | ths | FILE_SHARE_READ, NULL,
|
101 | 223d4670 | ths | create_flags, overlapped, NULL);
|
102 | 223d4670 | ths | if (s->hfile == INVALID_HANDLE_VALUE) {
|
103 | 223d4670 | ths | int err = GetLastError();
|
104 | 223d4670 | ths | |
105 | 223d4670 | ths | if (err == ERROR_ACCESS_DENIED)
|
106 | 223d4670 | ths | return -EACCES;
|
107 | 223d4670 | ths | return -1; |
108 | 223d4670 | ths | } |
109 | 223d4670 | ths | return 0; |
110 | 223d4670 | ths | } |
111 | 223d4670 | ths | |
112 | eda578e5 | aliguori | static int raw_read(BlockDriverState *bs, int64_t sector_num, |
113 | eda578e5 | aliguori | uint8_t *buf, int nb_sectors)
|
114 | 223d4670 | ths | { |
115 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
116 | 223d4670 | ths | OVERLAPPED ov; |
117 | 223d4670 | ths | DWORD ret_count; |
118 | 223d4670 | ths | int ret;
|
119 | eda578e5 | aliguori | int64_t offset = sector_num * 512;
|
120 | eda578e5 | aliguori | int count = nb_sectors * 512; |
121 | 223d4670 | ths | |
122 | 223d4670 | ths | memset(&ov, 0, sizeof(ov)); |
123 | 223d4670 | ths | ov.Offset = offset; |
124 | 223d4670 | ths | ov.OffsetHigh = offset >> 32;
|
125 | 223d4670 | ths | ret = ReadFile(s->hfile, buf, count, &ret_count, &ov); |
126 | 9c39be47 | aliguori | if (!ret)
|
127 | 9c39be47 | aliguori | return ret_count;
|
128 | 537a1d4b | aliguori | if (ret_count == count)
|
129 | 537a1d4b | aliguori | ret_count = 0;
|
130 | 223d4670 | ths | return ret_count;
|
131 | 223d4670 | ths | } |
132 | 223d4670 | ths | |
133 | eda578e5 | aliguori | static int raw_write(BlockDriverState *bs, int64_t sector_num, |
134 | eda578e5 | aliguori | const uint8_t *buf, int nb_sectors) |
135 | 223d4670 | ths | { |
136 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
137 | 223d4670 | ths | OVERLAPPED ov; |
138 | 223d4670 | ths | DWORD ret_count; |
139 | 223d4670 | ths | int ret;
|
140 | eda578e5 | aliguori | int64_t offset = sector_num * 512;
|
141 | eda578e5 | aliguori | int count = nb_sectors * 512; |
142 | 223d4670 | ths | |
143 | 223d4670 | ths | memset(&ov, 0, sizeof(ov)); |
144 | 223d4670 | ths | ov.Offset = offset; |
145 | 223d4670 | ths | ov.OffsetHigh = offset >> 32;
|
146 | 223d4670 | ths | ret = WriteFile(s->hfile, buf, count, &ret_count, &ov); |
147 | 9c39be47 | aliguori | if (!ret)
|
148 | 9c39be47 | aliguori | return ret_count;
|
149 | 537a1d4b | aliguori | if (ret_count == count)
|
150 | 537a1d4b | aliguori | ret_count = 0;
|
151 | 223d4670 | ths | return ret_count;
|
152 | 223d4670 | ths | } |
153 | 223d4670 | ths | |
154 | 223d4670 | ths | static void raw_flush(BlockDriverState *bs) |
155 | 223d4670 | ths | { |
156 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
157 | 223d4670 | ths | FlushFileBuffers(s->hfile); |
158 | 223d4670 | ths | } |
159 | 223d4670 | ths | |
160 | 223d4670 | ths | static void raw_close(BlockDriverState *bs) |
161 | 223d4670 | ths | { |
162 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
163 | 223d4670 | ths | CloseHandle(s->hfile); |
164 | 223d4670 | ths | } |
165 | 223d4670 | ths | |
166 | 223d4670 | ths | static int raw_truncate(BlockDriverState *bs, int64_t offset) |
167 | 223d4670 | ths | { |
168 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
169 | b9e82a59 | blueswir1 | LONG low, high; |
170 | 223d4670 | ths | |
171 | 223d4670 | ths | low = offset; |
172 | 223d4670 | ths | high = offset >> 32;
|
173 | 223d4670 | ths | if (!SetFilePointer(s->hfile, low, &high, FILE_BEGIN))
|
174 | 223d4670 | ths | return -EIO;
|
175 | 223d4670 | ths | if (!SetEndOfFile(s->hfile))
|
176 | 223d4670 | ths | return -EIO;
|
177 | 223d4670 | ths | return 0; |
178 | 223d4670 | ths | } |
179 | 223d4670 | ths | |
180 | 223d4670 | ths | static int64_t raw_getlength(BlockDriverState *bs)
|
181 | 223d4670 | ths | { |
182 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
183 | 223d4670 | ths | LARGE_INTEGER l; |
184 | 223d4670 | ths | ULARGE_INTEGER available, total, total_free; |
185 | 223d4670 | ths | DISK_GEOMETRY_EX dg; |
186 | 223d4670 | ths | DWORD count; |
187 | 223d4670 | ths | BOOL status; |
188 | 223d4670 | ths | |
189 | 223d4670 | ths | switch(s->type) {
|
190 | 223d4670 | ths | case FTYPE_FILE:
|
191 | b9e82a59 | blueswir1 | l.LowPart = GetFileSize(s->hfile, (PDWORD)&l.HighPart); |
192 | 223d4670 | ths | if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR) |
193 | 223d4670 | ths | return -EIO;
|
194 | 223d4670 | ths | break;
|
195 | 223d4670 | ths | case FTYPE_CD:
|
196 | 223d4670 | ths | if (!GetDiskFreeSpaceEx(s->drive_path, &available, &total, &total_free))
|
197 | 223d4670 | ths | return -EIO;
|
198 | 223d4670 | ths | l.QuadPart = total.QuadPart; |
199 | 223d4670 | ths | break;
|
200 | 223d4670 | ths | case FTYPE_HARDDISK:
|
201 | 223d4670 | ths | status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, |
202 | 223d4670 | ths | NULL, 0, &dg, sizeof(dg), &count, NULL); |
203 | 223d4670 | ths | if (status != 0) { |
204 | 223d4670 | ths | l = dg.DiskSize; |
205 | 223d4670 | ths | } |
206 | 223d4670 | ths | break;
|
207 | 223d4670 | ths | default:
|
208 | 223d4670 | ths | return -EIO;
|
209 | 223d4670 | ths | } |
210 | 223d4670 | ths | return l.QuadPart;
|
211 | 223d4670 | ths | } |
212 | 223d4670 | ths | |
213 | 0e7e1989 | Kevin Wolf | static int raw_create(const char *filename, QEMUOptionParameter *options) |
214 | 223d4670 | ths | { |
215 | 223d4670 | ths | int fd;
|
216 | 0e7e1989 | Kevin Wolf | int64_t total_size = 0;
|
217 | 223d4670 | ths | |
218 | 0e7e1989 | Kevin Wolf | /* Read out options */
|
219 | 0e7e1989 | Kevin Wolf | while (options && options->name) {
|
220 | 0e7e1989 | Kevin Wolf | if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
221 | 0e7e1989 | Kevin Wolf | total_size = options->value.n / 512;
|
222 | 0e7e1989 | Kevin Wolf | } |
223 | 0e7e1989 | Kevin Wolf | options++; |
224 | 0e7e1989 | Kevin Wolf | } |
225 | 223d4670 | ths | |
226 | 223d4670 | ths | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
227 | 223d4670 | ths | 0644);
|
228 | 223d4670 | ths | if (fd < 0) |
229 | 223d4670 | ths | return -EIO;
|
230 | 223d4670 | ths | set_sparse(fd); |
231 | 223d4670 | ths | ftruncate(fd, total_size * 512);
|
232 | 223d4670 | ths | close(fd); |
233 | 223d4670 | ths | return 0; |
234 | 223d4670 | ths | } |
235 | 223d4670 | ths | |
236 | 0e7e1989 | Kevin Wolf | static QEMUOptionParameter raw_create_options[] = {
|
237 | db08adf5 | Kevin Wolf | { |
238 | db08adf5 | Kevin Wolf | .name = BLOCK_OPT_SIZE, |
239 | db08adf5 | Kevin Wolf | .type = OPT_SIZE, |
240 | db08adf5 | Kevin Wolf | .help = "Virtual disk size"
|
241 | db08adf5 | Kevin Wolf | }, |
242 | 0e7e1989 | Kevin Wolf | { NULL }
|
243 | 0e7e1989 | Kevin Wolf | }; |
244 | 0e7e1989 | Kevin Wolf | |
245 | 5efa9d5a | Anthony Liguori | static BlockDriver bdrv_raw = {
|
246 | f1b2f712 | aliguori | .format_name = "raw",
|
247 | f1b2f712 | aliguori | .instance_size = sizeof(BDRVRawState),
|
248 | f1b2f712 | aliguori | .bdrv_open = raw_open, |
249 | f1b2f712 | aliguori | .bdrv_close = raw_close, |
250 | f1b2f712 | aliguori | .bdrv_create = raw_create, |
251 | f1b2f712 | aliguori | .bdrv_flush = raw_flush, |
252 | f1b2f712 | aliguori | .bdrv_read = raw_read, |
253 | f1b2f712 | aliguori | .bdrv_write = raw_write, |
254 | f1b2f712 | aliguori | .bdrv_truncate = raw_truncate, |
255 | f1b2f712 | aliguori | .bdrv_getlength = raw_getlength, |
256 | 0e7e1989 | Kevin Wolf | |
257 | 0e7e1989 | Kevin Wolf | .create_options = raw_create_options, |
258 | 223d4670 | ths | }; |
259 | 223d4670 | ths | |
260 | 223d4670 | ths | /***********************************************/
|
261 | 223d4670 | ths | /* host device */
|
262 | 223d4670 | ths | |
263 | 223d4670 | ths | static int find_cdrom(char *cdrom_name, int cdrom_name_size) |
264 | 223d4670 | ths | { |
265 | 223d4670 | ths | char drives[256], *pdrv = drives; |
266 | 223d4670 | ths | UINT type; |
267 | 223d4670 | ths | |
268 | 223d4670 | ths | memset(drives, 0, sizeof(drives)); |
269 | 223d4670 | ths | GetLogicalDriveStrings(sizeof(drives), drives);
|
270 | 223d4670 | ths | while(pdrv[0] != '\0') { |
271 | 223d4670 | ths | type = GetDriveType(pdrv); |
272 | 223d4670 | ths | switch(type) {
|
273 | 223d4670 | ths | case DRIVE_CDROM:
|
274 | 223d4670 | ths | snprintf(cdrom_name, cdrom_name_size, "\\\\.\\%c:", pdrv[0]); |
275 | 223d4670 | ths | return 0; |
276 | 223d4670 | ths | break;
|
277 | 223d4670 | ths | } |
278 | 223d4670 | ths | pdrv += lstrlen(pdrv) + 1;
|
279 | 223d4670 | ths | } |
280 | 223d4670 | ths | return -1; |
281 | 223d4670 | ths | } |
282 | 223d4670 | ths | |
283 | 223d4670 | ths | static int find_device_type(BlockDriverState *bs, const char *filename) |
284 | 223d4670 | ths | { |
285 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
286 | 223d4670 | ths | UINT type; |
287 | 223d4670 | ths | const char *p; |
288 | 223d4670 | ths | |
289 | 223d4670 | ths | if (strstart(filename, "\\\\.\\", &p) || |
290 | 223d4670 | ths | strstart(filename, "//./", &p)) {
|
291 | 223d4670 | ths | if (stristart(p, "PhysicalDrive", NULL)) |
292 | 223d4670 | ths | return FTYPE_HARDDISK;
|
293 | 223d4670 | ths | snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]); |
294 | 223d4670 | ths | type = GetDriveType(s->drive_path); |
295 | 3060cd14 | aliguori | switch (type) {
|
296 | 3060cd14 | aliguori | case DRIVE_REMOVABLE:
|
297 | 3060cd14 | aliguori | case DRIVE_FIXED:
|
298 | 3060cd14 | aliguori | return FTYPE_HARDDISK;
|
299 | 3060cd14 | aliguori | case DRIVE_CDROM:
|
300 | 223d4670 | ths | return FTYPE_CD;
|
301 | 3060cd14 | aliguori | default:
|
302 | 223d4670 | ths | return FTYPE_FILE;
|
303 | 3060cd14 | aliguori | } |
304 | 223d4670 | ths | } else {
|
305 | 223d4670 | ths | return FTYPE_FILE;
|
306 | 223d4670 | ths | } |
307 | 223d4670 | ths | } |
308 | 223d4670 | ths | |
309 | 508c7cb3 | Christoph Hellwig | static int hdev_probe_device(const char *filename) |
310 | 508c7cb3 | Christoph Hellwig | { |
311 | 508c7cb3 | Christoph Hellwig | if (strstart(filename, "/dev/cdrom", NULL)) |
312 | 508c7cb3 | Christoph Hellwig | return 100; |
313 | 508c7cb3 | Christoph Hellwig | if (is_windows_drive(filename))
|
314 | 508c7cb3 | Christoph Hellwig | return 100; |
315 | 508c7cb3 | Christoph Hellwig | return 0; |
316 | 508c7cb3 | Christoph Hellwig | } |
317 | 508c7cb3 | Christoph Hellwig | |
318 | 223d4670 | ths | static int hdev_open(BlockDriverState *bs, const char *filename, int flags) |
319 | 223d4670 | ths | { |
320 | 223d4670 | ths | BDRVRawState *s = bs->opaque; |
321 | 223d4670 | ths | int access_flags, create_flags;
|
322 | 223d4670 | ths | DWORD overlapped; |
323 | 223d4670 | ths | char device_name[64]; |
324 | 223d4670 | ths | |
325 | 223d4670 | ths | if (strstart(filename, "/dev/cdrom", NULL)) { |
326 | 223d4670 | ths | if (find_cdrom(device_name, sizeof(device_name)) < 0) |
327 | 223d4670 | ths | return -ENOENT;
|
328 | 223d4670 | ths | filename = device_name; |
329 | 223d4670 | ths | } else {
|
330 | 223d4670 | ths | /* transform drive letters into device name */
|
331 | 223d4670 | ths | if (((filename[0] >= 'a' && filename[0] <= 'z') || |
332 | 223d4670 | ths | (filename[0] >= 'A' && filename[0] <= 'Z')) && |
333 | 223d4670 | ths | filename[1] == ':' && filename[2] == '\0') { |
334 | 223d4670 | ths | snprintf(device_name, sizeof(device_name), "\\\\.\\%c:", filename[0]); |
335 | 223d4670 | ths | filename = device_name; |
336 | 223d4670 | ths | } |
337 | 223d4670 | ths | } |
338 | 223d4670 | ths | s->type = find_device_type(bs, filename); |
339 | 223d4670 | ths | |
340 | 223d4670 | ths | if ((flags & BDRV_O_ACCESS) == O_RDWR) {
|
341 | 223d4670 | ths | access_flags = GENERIC_READ | GENERIC_WRITE; |
342 | 223d4670 | ths | } else {
|
343 | 223d4670 | ths | access_flags = GENERIC_READ; |
344 | 223d4670 | ths | } |
345 | 223d4670 | ths | create_flags = OPEN_EXISTING; |
346 | 223d4670 | ths | |
347 | 03ff3ca3 | aliguori | overlapped = FILE_ATTRIBUTE_NORMAL; |
348 | 9f7965c7 | aliguori | if ((flags & BDRV_O_NOCACHE))
|
349 | 33f00271 | balrog | overlapped |= FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; |
350 | 9f7965c7 | aliguori | else if (!(flags & BDRV_O_CACHE_WB)) |
351 | 9f7965c7 | aliguori | overlapped |= FILE_FLAG_WRITE_THROUGH; |
352 | 223d4670 | ths | s->hfile = CreateFile(filename, access_flags, |
353 | 223d4670 | ths | FILE_SHARE_READ, NULL,
|
354 | 223d4670 | ths | create_flags, overlapped, NULL);
|
355 | 223d4670 | ths | if (s->hfile == INVALID_HANDLE_VALUE) {
|
356 | 223d4670 | ths | int err = GetLastError();
|
357 | 223d4670 | ths | |
358 | 223d4670 | ths | if (err == ERROR_ACCESS_DENIED)
|
359 | 223d4670 | ths | return -EACCES;
|
360 | 223d4670 | ths | return -1; |
361 | 223d4670 | ths | } |
362 | 223d4670 | ths | return 0; |
363 | 223d4670 | ths | } |
364 | 223d4670 | ths | |
365 | 223d4670 | ths | #if 0
|
366 | 223d4670 | ths | /***********************************************/
|
367 | 223d4670 | ths | /* removable device additional commands */
|
368 | 223d4670 | ths | |
369 | 223d4670 | ths | static int raw_is_inserted(BlockDriverState *bs)
|
370 | 223d4670 | ths | {
|
371 | 223d4670 | ths | return 1;
|
372 | 223d4670 | ths | }
|
373 | 223d4670 | ths | |
374 | 223d4670 | ths | static int raw_media_changed(BlockDriverState *bs)
|
375 | 223d4670 | ths | {
|
376 | 223d4670 | ths | return -ENOTSUP;
|
377 | 223d4670 | ths | }
|
378 | 223d4670 | ths | |
379 | 223d4670 | ths | static int raw_eject(BlockDriverState *bs, int eject_flag)
|
380 | 223d4670 | ths | {
|
381 | 223d4670 | ths | DWORD ret_count;
|
382 | 223d4670 | ths | |
383 | 223d4670 | ths | if (s->type == FTYPE_FILE)
|
384 | 223d4670 | ths | return -ENOTSUP;
|
385 | 223d4670 | ths | if (eject_flag) {
|
386 | 223d4670 | ths | DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
|
387 | 223d4670 | ths | NULL, 0, NULL, 0, &lpBytesReturned, NULL);
|
388 | 223d4670 | ths | } else {
|
389 | 223d4670 | ths | DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
|
390 | 223d4670 | ths | NULL, 0, NULL, 0, &lpBytesReturned, NULL);
|
391 | 223d4670 | ths | }
|
392 | 223d4670 | ths | }
|
393 | 223d4670 | ths | |
394 | 223d4670 | ths | static int raw_set_locked(BlockDriverState *bs, int locked)
|
395 | 223d4670 | ths | {
|
396 | 223d4670 | ths | return -ENOTSUP;
|
397 | 223d4670 | ths | }
|
398 | 223d4670 | ths | #endif
|
399 | 223d4670 | ths | |
400 | 5efa9d5a | Anthony Liguori | static BlockDriver bdrv_host_device = {
|
401 | e60f469c | aurel32 | .format_name = "host_device",
|
402 | e60f469c | aurel32 | .instance_size = sizeof(BDRVRawState),
|
403 | 508c7cb3 | Christoph Hellwig | .bdrv_probe_device = hdev_probe_device, |
404 | e60f469c | aurel32 | .bdrv_open = hdev_open, |
405 | e60f469c | aurel32 | .bdrv_close = raw_close, |
406 | e60f469c | aurel32 | .bdrv_flush = raw_flush, |
407 | 223d4670 | ths | |
408 | eda578e5 | aliguori | .bdrv_read = raw_read, |
409 | eda578e5 | aliguori | .bdrv_write = raw_write, |
410 | e60f469c | aurel32 | .bdrv_getlength = raw_getlength, |
411 | 223d4670 | ths | }; |
412 | 5efa9d5a | Anthony Liguori | |
413 | 5efa9d5a | Anthony Liguori | static void bdrv_raw_init(void) |
414 | 5efa9d5a | Anthony Liguori | { |
415 | 5efa9d5a | Anthony Liguori | bdrv_register(&bdrv_raw); |
416 | 5efa9d5a | Anthony Liguori | bdrv_register(&bdrv_host_device); |
417 | 5efa9d5a | Anthony Liguori | } |
418 | 5efa9d5a | Anthony Liguori | |
419 | 5efa9d5a | Anthony Liguori | block_init(bdrv_raw_init); |