Revision 84a12e66 block.c

b/block.c
54 54
                        uint8_t *buf, int nb_sectors);
55 55
static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
56 56
                         const uint8_t *buf, int nb_sectors);
57
static BlockDriver *find_protocol(const char *filename);
57 58

  
58 59
static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
59 60
    QTAILQ_HEAD_INITIALIZER(bdrv_states);
......
203 204
    return drv->bdrv_create(filename, options);
204 205
}
205 206

  
207
int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
208
{
209
    BlockDriver *drv;
210

  
211
    drv = find_protocol(filename);
212
    if (drv == NULL) {
213
        drv = bdrv_find_format("file");
214
    }
215

  
216
    return bdrv_create(drv, filename, options);
217
}
218

  
206 219
#ifdef _WIN32
207 220
void get_tmp_filename(char *filename, int size)
208 221
{
......
246 259
}
247 260
#endif
248 261

  
262
/*
263
 * Detect host devices. By convention, /dev/cdrom[N] is always
264
 * recognized as a host CDROM.
265
 */
266
static BlockDriver *find_hdev_driver(const char *filename)
267
{
268
    int score_max = 0, score;
269
    BlockDriver *drv = NULL, *d;
270

  
271
    QLIST_FOREACH(d, &bdrv_drivers, list) {
272
        if (d->bdrv_probe_device) {
273
            score = d->bdrv_probe_device(filename);
274
            if (score > score_max) {
275
                score_max = score;
276
                drv = d;
277
            }
278
        }
279
    }
280

  
281
    return drv;
282
}
283

  
249 284
static BlockDriver *find_protocol(const char *filename)
250 285
{
251 286
    BlockDriver *drv1;
......
256 291
#ifdef _WIN32
257 292
    if (is_windows_drive(filename) ||
258 293
        is_windows_drive_prefix(filename))
259
        return bdrv_find_format("raw");
294
        return bdrv_find_format("file");
260 295
#endif
261 296
    p = strchr(filename, ':');
262
    if (!p)
263
        return bdrv_find_format("raw");
297
    if (!p) {
298
        drv1 = find_hdev_driver(filename);
299
        if (!drv1) {
300
            drv1 = bdrv_find_format("file");
301
        }
302
        return drv1;
303
    }
264 304
    len = p - filename;
265 305
    if (len > sizeof(protocol) - 1)
266 306
        len = sizeof(protocol) - 1;
......
275 315
    return NULL;
276 316
}
277 317

  
278
/*
279
 * Detect host devices. By convention, /dev/cdrom[N] is always
280
 * recognized as a host CDROM.
281
 */
282
static BlockDriver *find_hdev_driver(const char *filename)
283
{
284
    int score_max = 0, score;
285
    BlockDriver *drv = NULL, *d;
286

  
287
    QLIST_FOREACH(d, &bdrv_drivers, list) {
288
        if (d->bdrv_probe_device) {
289
            score = d->bdrv_probe_device(filename);
290
            if (score > score_max) {
291
                score_max = score;
292
                drv = d;
293
            }
294
        }
295
    }
296

  
297
    return drv;
298
}
299

  
300 318
static BlockDriver *find_image_format(const char *filename)
301 319
{
302 320
    int ret, score, score_max;
......
319 337
    }
320 338

  
321 339
    score_max = 0;
340
    drv = NULL;
322 341
    QLIST_FOREACH(drv1, &bdrv_drivers, list) {
323 342
        if (drv1->bdrv_probe) {
324 343
            score = drv1->bdrv_probe(buf, ret, filename);
......
423 442
    pstrcpy(bs->filename, sizeof(bs->filename), filename);
424 443

  
425 444
    if (!drv) {
426
        drv = find_hdev_driver(filename);
427
        if (!drv) {
428
            drv = find_image_format(filename);
429
        }
445
        drv = find_image_format(filename);
430 446
    }
431 447

  
432 448
    if (!drv) {

Also available in: Unified diff