static ssize_t block_crypto_init_func(QCryptoBlock *block, size_t headerlen, Error **errp, void *opaque) { struct BlockCryptoCreateData *data = opaque; int ret; /* User provided size should reflect amount of space made * available to the guest, so we must take account of that * which will be used by the crypto header */ data->size += headerlen; qemu_opt_set_number(data->opts, BLOCK_OPT_SIZE, data->size, &error_abort); ret = bdrv_create_file(data->filename, data->opts, errp); if (ret < 0) { return -1; } data->blk = blk_new_open(data->filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp); if (!data->blk) { return -1; } return 0; }
static int raw_create(const char *filename, QemuOpts *opts, Error **errp) { Error *local_err = NULL; int ret; ret = bdrv_create_file(filename, opts, &local_err); if (local_err) { error_propagate(errp, local_err); } return ret; }
static int raw_create(const char *filename, QEMUOptionParameter *options, Error **errp) { Error *local_err = NULL; int ret; ret = bdrv_create_file(filename, options, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); } return ret; }
static int raw_create(const char *filename, QEMUOptionParameter *options, Error **errp) { Error *local_err = NULL; int ret; ret = bdrv_create_file(filename, options, &local_err); if (error_is_set(&local_err)) { qerror_report_err(local_err); error_free(local_err); } return ret; }
.cluster_size = cluster_size, .table_size = table_size, .header_size = 1, .features = 0, .compat_features = 0, .l1_table_offset = cluster_size, .image_size = image_size, }; QEDHeader le_header; uint8_t *l1_table = NULL; size_t l1_size = header.cluster_size * header.table_size; Error *local_err = NULL; int ret = 0; BlockDriverState *bs; ret = bdrv_create_file(filename, opts, &local_err); if (ret < 0) { error_propagate(errp, local_err); return ret; } bs = NULL; ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, NULL, &local_err); if (ret < 0) { error_propagate(errp, local_err); return ret; } /* File must start empty and grow, check truncate is supported */
static int raw_create(const char *filename, QEMUOptionParameter *options) { return bdrv_create_file(filename, options); }
.cluster_size = cluster_size, .table_size = table_size, .header_size = 1, .features = 0, .compat_features = 0, .l1_table_offset = cluster_size, .image_size = image_size, }; QEDHeader le_header; uint8_t *l1_table = NULL; size_t l1_size = header.cluster_size * header.table_size; Error *local_err = NULL; int ret = 0; BlockDriverState *bs; ret = bdrv_create_file(filename, NULL, &local_err); if (ret < 0) { error_propagate(errp, local_err); return ret; } bs = NULL; ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, NULL, &local_err); if (ret < 0) { error_propagate(errp, local_err); return ret; } /* File must start empty and grow, check truncate is supported */
.magic = QED_MAGIC, .cluster_size = cluster_size, .table_size = table_size, .header_size = 1, .features = 0, .compat_features = 0, .l1_table_offset = cluster_size, .image_size = image_size, }; QEDHeader le_header; uint8_t *l1_table = NULL; size_t l1_size = header.cluster_size * header.table_size; int ret = 0; BlockDriverState *bs = NULL; ret = bdrv_create_file(filename, NULL); if (ret < 0) { return ret; } ret = bdrv_file_open(&bs, filename, BDRV_O_RDWR | BDRV_O_CACHE_WB); if (ret < 0) { return ret; } /* File must start empty and grow, check truncate is supported */ ret = bdrv_truncate(bs, 0); if (ret < 0) { goto out; }
static int vpc_create(const char *filename, QemuOpts *opts, Error **errp) { uint8_t buf[1024]; VHDFooter *footer = (VHDFooter *) buf; char *disk_type_param; int i; uint16_t cyls = 0; uint8_t heads = 0; uint8_t secs_per_cyl = 0; int64_t total_sectors; int64_t total_size; int disk_type; int ret = -EIO; Error *local_err = NULL; BlockDriverState *bs = NULL; /* Read out options */ total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT); if (disk_type_param) { if (!strcmp(disk_type_param, "dynamic")) { disk_type = VHD_DYNAMIC; } else if (!strcmp(disk_type_param, "fixed")) { disk_type = VHD_FIXED; } else { ret = -EINVAL; goto out; } } else { disk_type = VHD_DYNAMIC; } ret = bdrv_create_file(filename, opts, &local_err); if (ret < 0) { error_propagate(errp, local_err); goto out; } ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err); if (ret < 0) { error_propagate(errp, local_err); goto out; } /* * Calculate matching total_size and geometry. Increase the number of * sectors requested until we get enough (or fail). This ensures that * qemu-img convert doesn't truncate images, but rather rounds up. * * If the image size can't be represented by a spec conform CHS geometry, * we set the geometry to 65535 x 16 x 255 (CxHxS) sectors and use * the image size from the VHD footer to calculate total_sectors. */ total_sectors = MIN(VHD_MAX_GEOMETRY, total_size / BDRV_SECTOR_SIZE); for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) { calculate_geometry(total_sectors + i, &cyls, &heads, &secs_per_cyl); } if ((int64_t)cyls * heads * secs_per_cyl == VHD_MAX_GEOMETRY) { total_sectors = total_size / BDRV_SECTOR_SIZE; /* Allow a maximum disk size of approximately 2 TB */ if (total_sectors > VHD_MAX_SECTORS) { ret = -EFBIG; goto out; } } else { total_sectors = (int64_t)cyls * heads * secs_per_cyl; total_size = total_sectors * BDRV_SECTOR_SIZE; } /* Prepare the Hard Disk Footer */ memset(buf, 0, 1024); memcpy(footer->creator, "conectix", 8); /* TODO Check if "qemu" creator_app is ok for VPC */ memcpy(footer->creator_app, "qemu", 4); memcpy(footer->creator_os, "Wi2k", 4); footer->features = cpu_to_be32(0x02); footer->version = cpu_to_be32(0x00010000); if (disk_type == VHD_DYNAMIC) { footer->data_offset = cpu_to_be64(HEADER_SIZE); } else { footer->data_offset = cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); } footer->timestamp = cpu_to_be32(time(NULL) - VHD_TIMESTAMP_BASE); /* Version of Virtual PC 2007 */ footer->major = cpu_to_be16(0x0005); footer->minor = cpu_to_be16(0x0003); footer->orig_size = cpu_to_be64(total_size); footer->current_size = cpu_to_be64(total_size); footer->cyls = cpu_to_be16(cyls); footer->heads = heads; footer->secs_per_cyl = secs_per_cyl; footer->type = cpu_to_be32(disk_type); #if defined(CONFIG_UUID) uuid_generate(footer->uuid); #endif footer->checksum = cpu_to_be32(vpc_checksum(buf, HEADER_SIZE)); if (disk_type == VHD_DYNAMIC) { ret = create_dynamic_disk(bs, buf, total_sectors); } else { ret = create_fixed_disk(bs, buf, total_size); } out: bdrv_unref(bs); g_free(disk_type_param); return ret; }