block.c (579153325158d944be544ced96c6218e7d48802a) block.c (66f82ceed6781261c09e65fb440ca76842fd0500)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 274 unchanged lines hidden (view full) ---

283
284static BlockDriver *find_protocol(const char *filename)
285{
286 BlockDriver *drv1;
287 char protocol[128];
288 int len;
289 const char *p;
290
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 274 unchanged lines hidden (view full) ---

283
284static BlockDriver *find_protocol(const char *filename)
285{
286 BlockDriver *drv1;
287 char protocol[128];
288 int len;
289 const char *p;
290
291 /* TODO Drivers without bdrv_file_open must be specified explicitly */
292
291#ifdef _WIN32
292 if (is_windows_drive(filename) ||
293 is_windows_drive_prefix(filename))
294 return bdrv_find_format("file");
295#endif
296 p = strchr(filename, ':');
297 if (!p) {
298 drv1 = find_hdev_driver(filename);

--- 56 unchanged lines hidden (view full) ---

355 */
356static int bdrv_open_common(BlockDriverState *bs, const char *filename,
357 int flags, BlockDriver *drv)
358{
359 int ret, open_flags;
360
361 assert(drv != NULL);
362
293#ifdef _WIN32
294 if (is_windows_drive(filename) ||
295 is_windows_drive_prefix(filename))
296 return bdrv_find_format("file");
297#endif
298 p = strchr(filename, ':');
299 if (!p) {
300 drv1 = find_hdev_driver(filename);

--- 56 unchanged lines hidden (view full) ---

357 */
358static int bdrv_open_common(BlockDriverState *bs, const char *filename,
359 int flags, BlockDriver *drv)
360{
361 int ret, open_flags;
362
363 assert(drv != NULL);
364
365 bs->file = NULL;
363 bs->is_temporary = 0;
364 bs->encrypted = 0;
365 bs->valid_key = 0;
366 bs->open_flags = flags;
367 /* buffer_alignment defaulted to 512, drivers can change this value */
368 bs->buffer_alignment = 512;
369
370 pstrcpy(bs->filename, sizeof(bs->filename), filename);

--- 22 unchanged lines hidden (view full) ---

393
394 /*
395 * Snapshots should be writeable.
396 */
397 if (bs->is_temporary) {
398 open_flags |= BDRV_O_RDWR;
399 }
400
366 bs->is_temporary = 0;
367 bs->encrypted = 0;
368 bs->valid_key = 0;
369 bs->open_flags = flags;
370 /* buffer_alignment defaulted to 512, drivers can change this value */
371 bs->buffer_alignment = 512;
372
373 pstrcpy(bs->filename, sizeof(bs->filename), filename);

--- 22 unchanged lines hidden (view full) ---

396
397 /*
398 * Snapshots should be writeable.
399 */
400 if (bs->is_temporary) {
401 open_flags |= BDRV_O_RDWR;
402 }
403
401 ret = drv->bdrv_open(bs, filename, open_flags);
404 /* Open the image, either directly or using a protocol */
405 if (drv->bdrv_file_open) {
406 ret = drv->bdrv_file_open(bs, filename, open_flags);
407 } else {
408 ret = bdrv_file_open(&bs->file, filename, open_flags);
409 if (ret >= 0) {
410 ret = drv->bdrv_open(bs, open_flags);
411 }
412 }
413
402 if (ret < 0) {
403 goto free_and_fail;
404 }
405
406 bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
407 if (drv->bdrv_getlength) {
408 bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
409 }
410#ifndef _WIN32
411 if (bs->is_temporary) {
412 unlink(filename);
413 }
414#endif
415 return 0;
416
417free_and_fail:
414 if (ret < 0) {
415 goto free_and_fail;
416 }
417
418 bs->keep_read_only = bs->read_only = !(open_flags & BDRV_O_RDWR);
419 if (drv->bdrv_getlength) {
420 bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
421 }
422#ifndef _WIN32
423 if (bs->is_temporary) {
424 unlink(filename);
425 }
426#endif
427 return 0;
428
429free_and_fail:
430 if (bs->file) {
431 bdrv_delete(bs->file);
432 bs->file = NULL;
433 }
418 qemu_free(bs->opaque);
419 bs->opaque = NULL;
420 bs->drv = NULL;
421 return ret;
422}
423
424/*
425 * Opens a file using a protocol (file, host_device, nbd, ...)

--- 154 unchanged lines hidden (view full) ---

580#ifdef _WIN32
581 if (bs->is_temporary) {
582 unlink(bs->filename);
583 }
584#endif
585 bs->opaque = NULL;
586 bs->drv = NULL;
587
434 qemu_free(bs->opaque);
435 bs->opaque = NULL;
436 bs->drv = NULL;
437 return ret;
438}
439
440/*
441 * Opens a file using a protocol (file, host_device, nbd, ...)

--- 154 unchanged lines hidden (view full) ---

596#ifdef _WIN32
597 if (bs->is_temporary) {
598 unlink(bs->filename);
599 }
600#endif
601 bs->opaque = NULL;
602 bs->drv = NULL;
603
604 if (bs->file != NULL) {
605 bdrv_close(bs->file);
606 }
607
588 /* call the change callback */
589 bs->media_changed = 1;
590 if (bs->change_cb)
591 bs->change_cb(bs->change_opaque);
592 }
593}
594
595void bdrv_delete(BlockDriverState *bs)
596{
597 /* remove from list, if necessary */
598 if (bs->device_name[0] != '\0') {
599 QTAILQ_REMOVE(&bdrv_states, bs, list);
600 }
601
602 bdrv_close(bs);
608 /* call the change callback */
609 bs->media_changed = 1;
610 if (bs->change_cb)
611 bs->change_cb(bs->change_opaque);
612 }
613}
614
615void bdrv_delete(BlockDriverState *bs)
616{
617 /* remove from list, if necessary */
618 if (bs->device_name[0] != '\0') {
619 QTAILQ_REMOVE(&bdrv_states, bs, list);
620 }
621
622 bdrv_close(bs);
623 if (bs->file != NULL) {
624 bdrv_delete(bs->file);
625 }
626
603 qemu_free(bs);
604}
605
606/*
607 * Run consistency checks on an image
608 *
609 * Returns the number of errors or -errno when an internal error occurs
610 */

--- 1734 unchanged lines hidden ---
627 qemu_free(bs);
628}
629
630/*
631 * Run consistency checks on an image
632 *
633 * Returns the number of errors or -errno when an internal error occurs
634 */

--- 1734 unchanged lines hidden ---