block.c (009b03aaa233ccf5bd3014404995540158d7dc93) | block.c (645ae7d88e5393a2a67ebe325f4456ecd49e33e5) |
---|---|
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 --- 298 unchanged lines hidden (view full) --- 307 308 return 0; 309 310fail: 311 error_setg(errp, "%s", errmsg ?: "Image is read-only"); 312 return -EACCES; 313} 314 | 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 --- 298 unchanged lines hidden (view full) --- 307 308 return 0; 309 310fail: 311 error_setg(errp, "%s", errmsg ?: "Image is read-only"); 312 return -EACCES; 313} 314 |
315void bdrv_get_full_backing_filename_from_filename(const char *backed, 316 const char *backing, 317 char *dest, size_t sz, 318 Error **errp) | 315/* 316 * If @backing is empty, this function returns NULL without setting 317 * @errp. In all other cases, NULL will only be returned with @errp 318 * set. 319 * 320 * Therefore, a return value of NULL without @errp set means that 321 * there is no backing file; if @errp is set, there is one but its 322 * absolute filename cannot be generated. 323 */ 324char *bdrv_get_full_backing_filename_from_filename(const char *backed, 325 const char *backing, 326 Error **errp) |
319{ | 327{ |
320 if (backing[0] == '\0' || path_has_protocol(backing) || 321 path_is_absolute(backing)) 322 { 323 pstrcpy(dest, sz, backing); | 328 if (backing[0] == '\0') { 329 return NULL; 330 } else if (path_has_protocol(backing) || path_is_absolute(backing)) { 331 return g_strdup(backing); |
324 } else if (backed[0] == '\0' || strstart(backed, "json:", NULL)) { 325 error_setg(errp, "Cannot use relative backing file names for '%s'", 326 backed); | 332 } else if (backed[0] == '\0' || strstart(backed, "json:", NULL)) { 333 error_setg(errp, "Cannot use relative backing file names for '%s'", 334 backed); |
335 return NULL; |
|
327 } else { | 336 } else { |
328 path_combine_deprecated(dest, sz, backed, backing); | 337 return path_combine(backed, backing); |
329 } 330} 331 332void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz, 333 Error **errp) 334{ 335 char *backed; | 338 } 339} 340 341void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz, 342 Error **errp) 343{ 344 char *backed; |
345 char *full_name; 346 Error *local_error = NULL; |
|
336 337 bdrv_refresh_filename(bs); 338 339 backed = bs->exact_filename[0] ? bs->exact_filename : bs->filename; | 347 348 bdrv_refresh_filename(bs); 349 350 backed = bs->exact_filename[0] ? bs->exact_filename : bs->filename; |
340 bdrv_get_full_backing_filename_from_filename(backed, bs->backing_file, 341 dest, sz, errp); | 351 352 full_name = bdrv_get_full_backing_filename_from_filename(backed, 353 bs->backing_file, 354 &local_error); 355 if (full_name) { 356 pstrcpy(dest, sz, full_name); 357 g_free(full_name); 358 } else if (local_error) { 359 error_propagate(errp, local_error); 360 } else if (sz > 0) { 361 *dest = '\0'; 362 } |
342} 343 344void bdrv_register(BlockDriver *bdrv) 345{ 346 QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list); 347} 348 349BlockDriverState *bdrv_new(void) --- 4824 unchanged lines hidden (view full) --- 5174 5175 backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT); 5176 5177 /* The size for the image must always be specified, unless we have a backing 5178 * file and we have not been forbidden from opening it. */ 5179 size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, img_size); 5180 if (backing_file && !(flags & BDRV_O_NO_BACKING)) { 5181 BlockDriverState *bs; | 363} 364 365void bdrv_register(BlockDriver *bdrv) 366{ 367 QLIST_INSERT_HEAD(&bdrv_drivers, bdrv, list); 368} 369 370BlockDriverState *bdrv_new(void) --- 4824 unchanged lines hidden (view full) --- 5195 5196 backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT); 5197 5198 /* The size for the image must always be specified, unless we have a backing 5199 * file and we have not been forbidden from opening it. */ 5200 size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, img_size); 5201 if (backing_file && !(flags & BDRV_O_NO_BACKING)) { 5202 BlockDriverState *bs; |
5182 char *full_backing = g_new0(char, PATH_MAX); | 5203 char *full_backing; |
5183 int back_flags; 5184 QDict *backing_options = NULL; 5185 | 5204 int back_flags; 5205 QDict *backing_options = NULL; 5206 |
5186 bdrv_get_full_backing_filename_from_filename(filename, backing_file, 5187 full_backing, PATH_MAX, 5188 &local_err); | 5207 full_backing = 5208 bdrv_get_full_backing_filename_from_filename(filename, backing_file, 5209 &local_err); |
5189 if (local_err) { | 5210 if (local_err) { |
5190 g_free(full_backing); | |
5191 goto out; 5192 } | 5211 goto out; 5212 } |
5213 assert(full_backing); |
|
5193 5194 /* backing files always opened read-only */ 5195 back_flags = flags; 5196 back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); 5197 5198 backing_options = qdict_new(); 5199 if (backing_fmt) { 5200 qdict_put_str(backing_options, "driver", backing_fmt); --- 580 unchanged lines hidden --- | 5214 5215 /* backing files always opened read-only */ 5216 back_flags = flags; 5217 back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); 5218 5219 backing_options = qdict_new(); 5220 if (backing_fmt) { 5221 qdict_put_str(backing_options, "driver", backing_fmt); --- 580 unchanged lines hidden --- |