block.c (3d815ac82b0a3e816fd7a6d2561a73e780c3b685) block.c (b65a5e12a4136b20f9d06675d597b52d64ac903c)
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

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

503}
504
505int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
506{
507 BlockDriver *drv;
508 Error *local_err = NULL;
509 int ret;
510
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

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

503}
504
505int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
506{
507 BlockDriver *drv;
508 Error *local_err = NULL;
509 int ret;
510
511 drv = bdrv_find_protocol(filename, true);
511 drv = bdrv_find_protocol(filename, true, errp);
512 if (drv == NULL) {
512 if (drv == NULL) {
513 error_setg(errp, "Could not find protocol for file '%s'", filename);
514 return -ENOENT;
515 }
516
517 ret = bdrv_create(drv, filename, opts, &local_err);
518 if (local_err) {
519 error_propagate(errp, local_err);
520 }
521 return ret;

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

623 }
624 }
625 }
626
627 return drv;
628}
629
630BlockDriver *bdrv_find_protocol(const char *filename,
513 return -ENOENT;
514 }
515
516 ret = bdrv_create(drv, filename, opts, &local_err);
517 if (local_err) {
518 error_propagate(errp, local_err);
519 }
520 return ret;

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

622 }
623 }
624 }
625
626 return drv;
627}
628
629BlockDriver *bdrv_find_protocol(const char *filename,
631 bool allow_protocol_prefix)
630 bool allow_protocol_prefix,
631 Error **errp)
632{
633 BlockDriver *drv1;
634 char protocol[128];
635 int len;
636 const char *p;
637
638 /* TODO Drivers without bdrv_file_open must be specified explicitly */
639

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

661 memcpy(protocol, filename, len);
662 protocol[len] = '\0';
663 QLIST_FOREACH(drv1, &bdrv_drivers, list) {
664 if (drv1->protocol_name &&
665 !strcmp(drv1->protocol_name, protocol)) {
666 return drv1;
667 }
668 }
632{
633 BlockDriver *drv1;
634 char protocol[128];
635 int len;
636 const char *p;
637
638 /* TODO Drivers without bdrv_file_open must be specified explicitly */
639

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

661 memcpy(protocol, filename, len);
662 protocol[len] = '\0';
663 QLIST_FOREACH(drv1, &bdrv_drivers, list) {
664 if (drv1->protocol_name &&
665 !strcmp(drv1->protocol_name, protocol)) {
666 return drv1;
667 }
668 }
669
670 error_setg(errp, "Unknown protocol '%s'", protocol);
669 return NULL;
670}
671
672/*
673 * Guess image format by probing its contents.
674 * This is not a good idea when your image is raw (CVE-2008-2004), but
675 * we do it anyway for backward compatibility.
676 *

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

1131 error_setg(errp, "Driver specified twice");
1132 return -EINVAL;
1133 }
1134 drvname = drv->format_name;
1135 qdict_put(*options, "driver", qstring_from_str(drvname));
1136 } else {
1137 if (!drvname && protocol) {
1138 if (filename) {
671 return NULL;
672}
673
674/*
675 * Guess image format by probing its contents.
676 * This is not a good idea when your image is raw (CVE-2008-2004), but
677 * we do it anyway for backward compatibility.
678 *

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

1133 error_setg(errp, "Driver specified twice");
1134 return -EINVAL;
1135 }
1136 drvname = drv->format_name;
1137 qdict_put(*options, "driver", qstring_from_str(drvname));
1138 } else {
1139 if (!drvname && protocol) {
1140 if (filename) {
1139 drv = bdrv_find_protocol(filename, parse_filename);
1141 drv = bdrv_find_protocol(filename, parse_filename, errp);
1140 if (!drv) {
1142 if (!drv) {
1141 error_setg(errp, "Unknown protocol");
1142 return -EINVAL;
1143 }
1144
1145 drvname = drv->format_name;
1146 qdict_put(*options, "driver", qstring_from_str(drvname));
1147 } else {
1148 error_setg(errp, "Must specify either driver or file");
1149 return -EINVAL;

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

5618
5619 /* Find driver and parse its options */
5620 drv = bdrv_find_format(fmt);
5621 if (!drv) {
5622 error_setg(errp, "Unknown file format '%s'", fmt);
5623 return;
5624 }
5625
1143 return -EINVAL;
1144 }
1145
1146 drvname = drv->format_name;
1147 qdict_put(*options, "driver", qstring_from_str(drvname));
1148 } else {
1149 error_setg(errp, "Must specify either driver or file");
1150 return -EINVAL;

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

5619
5620 /* Find driver and parse its options */
5621 drv = bdrv_find_format(fmt);
5622 if (!drv) {
5623 error_setg(errp, "Unknown file format '%s'", fmt);
5624 return;
5625 }
5626
5626 proto_drv = bdrv_find_protocol(filename, true);
5627 proto_drv = bdrv_find_protocol(filename, true, errp);
5627 if (!proto_drv) {
5628 if (!proto_drv) {
5628 error_setg(errp, "Unknown protocol '%s'", filename);
5629 return;
5630 }
5631
5632 if (!drv->create_opts) {
5633 error_setg(errp, "Format driver '%s' does not support image creation",
5634 drv->format_name);
5635 return;
5636 }

--- 522 unchanged lines hidden ---
5629 return;
5630 }
5631
5632 if (!drv->create_opts) {
5633 error_setg(errp, "Format driver '%s' does not support image creation",
5634 drv->format_name);
5635 return;
5636 }

--- 522 unchanged lines hidden ---