diff --git a/block.c b/block.c index 58f804228c..86f2faa266 100644 --- a/block.c +++ b/block.c @@ -303,13 +303,21 @@ void path_combine(char *dest, int dest_size, } } +void bdrv_get_full_backing_filename_from_filename(const char *backed, + const char *backing, + char *dest, size_t sz) +{ + if (backing[0] == '\0' || path_has_protocol(backing)) { + pstrcpy(dest, sz, backing); + } else { + path_combine(dest, sz, backed, backing); + } +} + void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz) { - if (bs->backing_file[0] == '\0' || path_has_protocol(bs->backing_file)) { - pstrcpy(dest, sz, bs->backing_file); - } else { - path_combine(dest, sz, bs->filename, bs->backing_file); - } + bdrv_get_full_backing_filename_from_filename(bs->filename, bs->backing_file, + dest, sz); } void bdrv_register(BlockDriver *bdrv) diff --git a/include/block/block.h b/include/block/block.h index 6e7275d95b..eac9bb0957 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -397,6 +397,9 @@ void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz); +void bdrv_get_full_backing_filename_from_filename(const char *backed, + const char *backing, + char *dest, size_t sz); int bdrv_is_snapshot(BlockDriverState *bs); int path_has_protocol(const char *path);