block.c (221f715d90ec5fec569a19119887445c037bca86) | block.c (5eb456396d20554a6b9637b23519579f083aa992) |
---|---|
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 --- 167 unchanged lines hidden (view full) --- 176 BlockDriver *drv1; 177 for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) { 178 if (!strcmp(drv1->format_name, format_name)) 179 return drv1; 180 } 181 return NULL; 182} 183 | 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 --- 167 unchanged lines hidden (view full) --- 176 BlockDriver *drv1; 177 for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) { 178 if (!strcmp(drv1->format_name, format_name)) 179 return drv1; 180 } 181 return NULL; 182} 183 |
184int bdrv_create2(BlockDriver *drv, 185 const char *filename, int64_t size_in_sectors, 186 const char *backing_file, const char *backing_format, 187 int flags) 188{ 189 if (drv->bdrv_create2) 190 return drv->bdrv_create2(filename, size_in_sectors, backing_file, 191 backing_format, flags); 192 if (drv->bdrv_create) 193 return drv->bdrv_create(filename, size_in_sectors, backing_file, 194 flags); 195 return -ENOTSUP; 196} 197 |
|
184int bdrv_create(BlockDriver *drv, 185 const char *filename, int64_t size_in_sectors, 186 const char *backing_file, int flags) 187{ 188 if (!drv->bdrv_create) 189 return -ENOTSUP; 190 return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); 191} --- 160 unchanged lines hidden (view full) --- 352 int64_t total_size; 353 int is_protocol = 0; 354 355 /* if snapshot, we create a temporary backing file and open it 356 instead of opening 'filename' directly */ 357 358 /* if there is a backing file, use it */ 359 bs1 = bdrv_new(""); | 198int bdrv_create(BlockDriver *drv, 199 const char *filename, int64_t size_in_sectors, 200 const char *backing_file, int flags) 201{ 202 if (!drv->bdrv_create) 203 return -ENOTSUP; 204 return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); 205} --- 160 unchanged lines hidden (view full) --- 366 int64_t total_size; 367 int is_protocol = 0; 368 369 /* if snapshot, we create a temporary backing file and open it 370 instead of opening 'filename' directly */ 371 372 /* if there is a backing file, use it */ 373 bs1 = bdrv_new(""); |
360 ret = bdrv_open(bs1, filename, 0); | 374 ret = bdrv_open2(bs1, filename, 0, drv); |
361 if (ret < 0) { 362 bdrv_delete(bs1); 363 return ret; 364 } 365 total_size = bdrv_getlength(bs1) >> SECTOR_BITS; 366 367 if (bs1->drv && bs1->drv->protocol_name) 368 is_protocol = 1; --- 4 unchanged lines hidden (view full) --- 373 374 /* Real path is meaningless for protocols */ 375 if (is_protocol) 376 snprintf(backing_filename, sizeof(backing_filename), 377 "%s", filename); 378 else 379 realpath(filename, backing_filename); 380 | 375 if (ret < 0) { 376 bdrv_delete(bs1); 377 return ret; 378 } 379 total_size = bdrv_getlength(bs1) >> SECTOR_BITS; 380 381 if (bs1->drv && bs1->drv->protocol_name) 382 is_protocol = 1; --- 4 unchanged lines hidden (view full) --- 387 388 /* Real path is meaningless for protocols */ 389 if (is_protocol) 390 snprintf(backing_filename, sizeof(backing_filename), 391 "%s", filename); 392 else 393 realpath(filename, backing_filename); 394 |
381 ret = bdrv_create(&bdrv_qcow2, tmp_filename, 382 total_size, backing_filename, 0); | 395 ret = bdrv_create2(&bdrv_qcow2, tmp_filename, 396 total_size, backing_filename, 397 (drv ? drv->format_name : NULL), 0); |
383 if (ret < 0) { 384 return ret; 385 } 386 filename = tmp_filename; | 398 if (ret < 0) { 399 return ret; 400 } 401 filename = tmp_filename; |
402 drv = &bdrv_qcow2; |
|
387 bs->is_temporary = 1; 388 } 389 390 pstrcpy(bs->filename, sizeof(bs->filename), filename); 391 if (flags & BDRV_O_FILE) { 392 drv = find_protocol(filename); 393 } else if (!drv) { 394 drv = find_image_format(filename); --- 29 unchanged lines hidden (view full) --- 424 } 425#ifndef _WIN32 426 if (bs->is_temporary) { 427 unlink(filename); 428 } 429#endif 430 if (bs->backing_file[0] != '\0') { 431 /* if there is a backing file, use it */ | 403 bs->is_temporary = 1; 404 } 405 406 pstrcpy(bs->filename, sizeof(bs->filename), filename); 407 if (flags & BDRV_O_FILE) { 408 drv = find_protocol(filename); 409 } else if (!drv) { 410 drv = find_image_format(filename); --- 29 unchanged lines hidden (view full) --- 440 } 441#ifndef _WIN32 442 if (bs->is_temporary) { 443 unlink(filename); 444 } 445#endif 446 if (bs->backing_file[0] != '\0') { 447 /* if there is a backing file, use it */ |
448 BlockDriver *back_drv = NULL; |
|
432 bs->backing_hd = bdrv_new(""); 433 path_combine(backing_filename, sizeof(backing_filename), 434 filename, bs->backing_file); | 449 bs->backing_hd = bdrv_new(""); 450 path_combine(backing_filename, sizeof(backing_filename), 451 filename, bs->backing_file); |
435 ret = bdrv_open(bs->backing_hd, backing_filename, open_flags); | 452 if (bs->backing_format[0] != '\0') 453 back_drv = bdrv_find_format(bs->backing_format); 454 ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags, 455 back_drv); |
436 if (ret < 0) { 437 bdrv_close(bs); 438 return ret; 439 } 440 } 441 442 if (!bdrv_key_required(bs)) { 443 /* call the change callback */ --- 1202 unchanged lines hidden --- | 456 if (ret < 0) { 457 bdrv_close(bs); 458 return ret; 459 } 460 } 461 462 if (!bdrv_key_required(bs)) { 463 /* call the change callback */ --- 1202 unchanged lines hidden --- |